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

public class Main {
    static List<Integer> list = new ArrayList<Integer>();
    static int x = 0;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        x = sc.nextInt();
        int n = sc.nextInt();

        for (int i = 0; i < n; i++) {
            list.add(sc.nextInt());
        }
        if (!(list.contains(x))) {
            System.out.println(x);
        } else {
            System.out.println(dfs(1));
        }
    }

    private static int dfs(int n) {
        if (!(list.contains(x - n))) {
            return x - n;
        } else if (!(list.contains(x + n))) {
            return x + n;
        }
        return dfs(++n);
    }
}

Measured memory_bytes: 35896
a,b = gets.split.map(&:to_i)
count = 0
(a..b).each do |i|
  check = 0
  s = i.to_s.split('')
  2.times do |j|
    if s[j] == s[4-j]
      check += 1
    else
      next
    end
  end
  if check == 2
    count += 1
  end
end
puts count

Measured memory_bytes: 2044
INPUT = input().split()
N = int(INPUT[0])
M = int(INPUT[1])
score_list = input().split()
score_list_int =  [int(n) for n in score_list]

border = sum(score_list_int)/4/M

answer = "Yes"

for i in score_list_int:
    if i < border:
        N -= 1

if N < M:
    answer = "No"
    
print(answer)

Measured memory_bytes: 3064
N = int(input())
A = list(map(int, input().split()))
arai = sum(A)
sunuke = 0

ans = 10**10
for i in range(0, N-1):
    sunuke += A[i]
    arai -= A[i]
    ans = min(ans, abs(sunuke - arai))

print(ans)

Measured memory_bytes: 24824
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) a.begin(), a.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

int main(){

    string s;
    cin >> s;

    cout << s.substr(0, 4) << ' ' << s.substr(4, 8) << endl;
    return 0;
    
}

Measured memory_bytes: 256
N = int(input())
hstr = input().split()
h = [int(n) for n in hstr]

dp = [0 for i in range(N)]

dp[0] = 0
dp[1] = abs(h[0] - h[1])

for i in range(2, N):
    dif1 = abs(h[i] - h[i-1])
    dif2 = abs(h[i] - h[i-2])
    dp[i] = min(dp[i-1] + dif1, dp[i-2] + dif2)

print(dp[N-1])



Measured memory_bytes: 17892
import bisect
inf=10**20+10

def slove(ss,tt):
    if ss*tt<0:
        return min(abs(ss),abs(tt))*2+max(abs(ss),abs(tt))
    else:
        return max(abs(ss),abs(tt))

a,b,q=map(int,input().split())
s,t,x=[-inf],[-inf],[]
for _ in range(a):
    s.append(int(input()))
for _ in range(b):
    t.append(int(input()))
for _ in range(q):
    x.append(int(input()))

s.sort()
t.sort()
s.append(inf)
t.append(inf)

for xx in x:
    s_in=bisect.bisect_left(s,xx)
    t_in=bisect.bisect_left(t,xx)
    sl,sr=s[s_in-1]-xx,s[s_in]-xx
    tl,tr=t[t_in-1]-xx,t[t_in]-xx
    ans=inf
    ans=min(slove(sl,tl),slove(sl,tr),slove(sr,tl),slove(sr,tr))
    print(ans)
    

Measured memory_bytes: 16160
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
typedef long long ll;
//typedef pair<ll,ll> P;

using namespace std;


int main(){
  string s;
  cin>>s;
  int a=s.size();
  if (s[0]==s[a-1])a++;
  a%=2;
  if (a==0)cout<<"Second";
  if (a==1)cout<<"First";

}


Measured memory_bytes: 512
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using INT=mp::cpp_int;
using namespace std;
using ll=long long;
using vec=vector<ll>;
using vect=vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n;i>=0;i--)
#define Pool(i, m, n) for(ll i=n;i>=m;i--)
#define MAX 99999999999ll
#define MIN -99999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1<<x)
#define flagadd(bit,x) bit|=flag(x)
#define flagpop(bit,x) bit&=~flag(x) 
#define flagon(bit,i) bit&flag(i)
#define flagoff(bit,i) !(bit & (1<<i))
#define all(v) v.begin(),v.end()
#define low2way(v,x) lower_bound(all(v),x)
#define high2way(v,x) upper_bound(all(v),x)
#define count2way(v,x) high2way(v,x)-low2way(v,x)
#define lower(v,x) low2way(v,x)-v.begin() //1番左が0、もし見つから無いならｎを出力
#define higher(v,x) high2way(v,x)-v.begin()-1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(a) cout<<a<<endl
#define putout2(a,b) putout(a);putout(b)
#define putout3(a,b,c) putout(a);putout(b);putout(c)
#define putout4(a,b,c,d) putout(a);putout(b);putout(c);putout(d)
#define putout5(a,b,c,d,e) putout(a);putout(b);putout(c);putout(d);putout(e)
#define Gput(a,b) G[a].push_back(b)
#define cin1(a) cin>>a
#define cin2(a,b) cin>>a>>b
#define cin3(a,b,c) cin>>a>>b>>c
#define cin4(a,b,c,d) cin>>a>>b>>c>>d
#define cin5(a,b,c,d,e) cin>>a>>b>>c>>d>>e
#define sum(v) accumulate(all(v), 0ll)
#define gcd(x,y) __gcd(x,y)
ll ctoi(char c){
	if(c>='0'&&c<='9'){
		return c-'0';
	}
	return 0;
}
ll lcm(ll x,ll y){
  ll z=gcd(x,y);
  return x*y/z;
}
INT LCM(INT x,INT y){
  INT z=gcd(x,y);
  return x*y/z;
}
ll primejudge(ll n){
  if(n<2)return 0;
  else if(n==2)return 1;
  else if(n%2==0)return 0;
  double sqrtn=sqrt(n);
  Loop(i,3,sqrtn+1){
     if(n%i==0){
        return 0;
     }
     i++;
  }
  return 1;
}
INT modinv(INT a, INT m) {
    INT b = m, u = 1, v = 0;
    while (b) {
        INT t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
int main() {
  cout << fixed << setprecision(30);
  ll n;
  cin>>n;
  vec a(n);
  ll N=0,R=0,SSR=0;
  loop(i,n){
    cin>>a[i];
    if(a[i]%4==0){
      SSR++;
      continue;
    }
    if(a[i]%2!=0)N++;
    else R++;
  }
  if(R>0){
  if(SSR>=N)putout("Yes");
  else putout("No");
  }
  else{
  if(SSR+1>=N)putout("Yes");
  else putout("No");
  }
}


Measured memory_bytes: 1024
import sys
from io import StringIO
import unittest

def resolve():
    n = int(input())
    s = input()
    ans = s.count('R') * s.count('G') * s.count('B')

    for i in range(n):
        for j in range(1, (n - 1)//2 + 1, 1):
            if i + 2 * j < n:
                if s[i] != s[i + j] and s[i] != s[i + 2 * j] and s[i + j] != s[i + 2 * j]:
                    ans -= 1

    print(ans)


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """4
RRGB"""
        output = """1"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """39
RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB"""
        output = """1800"""
        self.assertIO(input, output)

if __name__ == "__main__":
    #unittest.main()
    resolve()

Measured memory_bytes: 16212
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
#define INF __INT32_MAX__
#define LINF __LONG_LONG_MAX__
 
int main() {
    int N;
    cin >> N;
    vi A(N);
    rep(i, N) {
        cin >> A[i];
    }
 
    map<int, int> G;
    rep(i, N) {
        G[A[i]]++;
    }
 
    bool ok = true;
    switch (G.size()) {
        case 1:
            if (A[0] != 0) ok = false;
            break;
        case 2:
            for (auto x: G) {
                if (x.first == 0) {
                    if (x.second != (N / 3)) {
                        ok = false;
                    }
                } else {
                    if (x.second != (2 * N / 3)) {
                        ok = false;
                    }
                }
            }
            break;
        case 3:
            {
                ll y = 0;
                for (auto x: G) {
                    if (x.second != (N / 3)) ok = false;
                    y ^= x.first;
                }
                if (y != 0) ok = false;
            }
            break;
        default:
            ok = false;
            break;
    }
 
    if (ok) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 7040
# a*b, b*c, c*aに並べた時のmin
# 基本的に半分にぶったぎる
ans = 10 ** 18
a, b, c = map(int, input().split())
r1 = (a * b) * (c // 2)
b1 = a * b * c - r1
r2 = (b * c) * (a // 2)
b2 = a * b * c - r2
r3 = (c * a) * (b // 2)
b3 = a * b * c - r3
print(min(abs(r1 - b1), abs(r2 - b2), abs(r3 - b3)))



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

using namespace std;

const int nmax = 1e5+5;
const long long inf = (1LL<<60);

long long dp[nmax][3];
int a[nmax];
char op[nmax];
int n;

int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (i != n) cin >> op[i + 1];
  }
  op[1] = '+';

  for (int i = 1; i <= n; i++) {
    dp[i][1] = dp[i][2] = dp[i][0] = -inf;
  }
  dp[1][0] = a[1];

  for (int i = 2; i <= n; i++) {
    if (op[i] == '+') {
      dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]) + a[i];
      dp[i][1] = dp[i - 1][1] - a[i];
      dp[i][2] = dp[i - 1][2] + a[i];
    } else {
      dp[i][1] = dp[i - 1][0] - a[i];
      dp[i][2] = max(dp[i - 1][1], dp[i - 1][2]) + a[i];
    }
  }

  return 0 * printf("%lld\n", max(max(dp[n][1], dp[n][2]), dp[n][0]));
}


Measured memory_bytes: 3072
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<string>
#include<sstream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
#include<climits>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; i++)
#define FOR(i, j, k) for(int i = j; i < k; i++)
#define P pair<int, int>
const int INF = INT_MAX / 2;

int Inp(string str){
    stringstream ss(str);
    int ret = 0, n;
    char tmp;
    ss >>n >>tmp;
    ret += (n * 3600);
    ss >>n >>tmp;
    ret += (n * 60);
    ss >>n;
    ret += n;
    return ret;
}

int main(){
    int n;
    while(cin >>n && n){
        vector<P> v;
        REP(i, n){
            string str;
            cin >>str; v.push_back( P(Inp(str), 1) );
            cin >>str; v.push_back( P(Inp(str), 0) );
        }
        sort(v.begin(), v.end());

        int t = 0, ans = 0;
        REP(i, v.size()){
            int time = v[i].first;
            int io = v[i].second;
            if(io == 1){
                if(t == 0){
                    ans++;
                } else{
                    t--;
                }
            } else{
                t++;
            }
        }
        cout <<ans <<endl;
    }
    return 0;
}

Measured memory_bytes: 1480
n,m=map(int,input().split())
ks=[list(map(int,input().split()))
for i in range(m)]
p=list(map(int,input().split()))

ans=0
for i in range(1<<n):
    isok=True
    for j in range(m):
        cnt = 0
        for k in range(1,len(ks[j])):
            cnt += (i>>(ks[j][k]-1))&1
        if cnt%2 != p[j]:
            isok = False
            break
    if isok:
        ans += 1
print(ans)

Measured memory_bytes: 3064
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val s = sc.next()
    println(problemagc040a(s))
}

fun problemagc040a(s: String): Long {
    val dp = LongArray(s.length + 1)
    for (i in 0 until s.length) {
        if (s[i] == '<') {
            dp[i + 1] = Math.max(dp[i + 1], dp[i] + 1)
        }
    }
    for (i in s.length - 1 downTo 0) {
        if (s[i] == '>') {
            dp[i] = Math.max(dp[i], dp[i + 1] + 1)
        }
    }
    return dp.sum()
}

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

int Q,N,s,m,i;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> Q;
    for (;Q--;){
        cin >> N;
        for(i=0;N>10;++i){
            s=10,m=0;
            while(s<N){
                m=max(m,(N/s)*(N%s));
                s*=10;
            }
            N=m;
        }
        cout << i << '\n';
    }
}


Measured memory_bytes: 3180
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;

int main(void)
{
    vector<int> S(3);

    cin >> S[0] >> S[1] >> S[2];
    sort(S.begin(), S.end());

    string ans;
    if (S[0] == 5 && S[1] == 5 && S[2] == 7)
    {
        ans = "YES";
    }
    else
    {
        ans = "NO";
    }
    cout << ans << endl;
    return (0);
}

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

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

struct UFDS {
    int par[100010];
    void init()
    {
        memset(par, -1, sizeof(par));
    }

    int root(int x)
    {
        return par[x] < 0 ? x : par[x] = root(par[x]);
    }

    ll merge(int x, int y)
    {
        x = root(x);
        y = root(y);

        if (x == y)
            return 0;

        if (par[x] > par[y])
            swap(x, y);

        ll ret = 1LL * par[x] * par[y];
        par[x] += par[y];
        par[y] = x;

        return ret;
    }

} uf;

int main()
{
    uf.init();
    int n, m;
    scanf("%d %d", &n, &m);

    ll ans = 1LL * n * (n - 1) / 2;
    vector<ll> ret;
    vector<ii> inp;
    for (int i = 0; i < m; i++) {
        int u, v;
        scanf("%d %d", &u, &v);
        inp.push_back({u, v});
    }

    for (int i = m - 1; i >= 0; i--) {
        ret.push_back(ans);
        ans -= uf.merge(inp[i].first, inp[i].second);
    }

    reverse(ret.begin(), ret.end());
    for (auto i : ret)
        printf("%lld\n", i);

    return 0;
}


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

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

    vector<int> c(n), s(n), f(n);
    for(int i=0; i<n-1; i++){
        cin >> c[i] >> s[i] >> f[i];
    }

    vector<int> ans = s;
    for(int i=0; i<n; i++){
        for(int j=i; j<n-1; j++){
            //cout << i << " " << ans[i] << endl;
            ans[i] += c[j];
            if(j == n-2) break;

            if(ans[i] <= s[j+1]) ans[i] = s[j+1];
            if(ans[i] >  s[j+1] && ans[i] % f[j+1] != 0) ans[i] += f[j+1] - ans[i] % f[j+1];
        }
    }

    for(int i=0; i<n; i++){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import std.stdio, std.conv, std.string, std.range, std.algorithm, std.array,
  std.functional, std.container, std.typecons;

void main() {
  int N = readln.chomp.to!int;
  char[] S = readln.chomp.dup;

  foreach(ref c; S) {
    c = ((c - 'A' + N) % 26) + 'A';
  }

  S.writeln;
}


Measured memory_bytes: 256
N=int(input())
A=[int(input()) for _ in range(N)]
A.sort()
A.append(0)
ans=0
i=0
j=0
while i<N:
  b=A[i]
  c=0
  while b==A[i] and i<N:
    c+=1
    i+=1
  ans+=(c%2)
print(ans)

Measured memory_bytes: 13148
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c==' '||c=='\n')c=_buff.get();return c;}
int n,a[4][100111];
int A[100111],B[100111];

int b[100111];
bool geta(int a[],int n)
{
	for(int i=1;i<=n;i++)b[a[i]]=i;
	bool ret=0;
	for(int i=1;i<=n;i++)
	{
		if(b[i]!=i)
		{
			swap(a[b[i]],a[i]);
			swap(b[a[b[i]]],b[a[i]]);
			ret^=1;
		}
	}
	return ret;
}
int main()
{
	geti(n);
	for(int i=1;i<=n;i++)geti(a[1][i]);
	for(int i=1;i<=n;i++)geti(a[2][i]);
	for(int i=1;i<=n;i++)geti(a[3][i]);
	for(int j=1;j<=n;j++)
	{
		if(abs(a[1][j]-a[2][j])!=1||abs(a[2][j]-a[3][j])!=1||abs(a[1][j]-a[3][j])!=2)
		{
			puts("No");
			return 0;
		}
	}
	int cnt0=0,cnt1=0;
	for(int i=1;i<=n;i++)
	{
		if(i%2==0)
		{
			if(((a[1][i]+2)/3)%2!=0)
			{
				puts("No");
				return 0;
			}
			B[i/2]=(a[1][i]+2)/6;
			if(a[1][i]%3==0)cnt0^=1;
		}
		else
		{
			if(((a[1][i]+2)/3)%2!=1)
			{
				puts("No");
				return 0;
			}
			A[(i+1)/2]=(a[1][i]+5)/6;
			if(a[1][i]%3==0)cnt1^=1;
		}
	}
//	cerr<<cnt0<<" "<<cnt1<<endl;
	bool sa=geta(A,(n+1)/2);
	bool sb=geta(B,n/2);
	if(sa==cnt0&&sb==cnt1)puts("Yes");
	else puts("No");
	return 0;
}

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

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

    int count = 0;
    for(int i=0; i<N; i++) {
        if (A.at(i)%2 != 0) count ++;
    }
    if (count % 2 == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
}


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

int main() {
  int a;
  cin >> a;
  int ans = a + a*a + a*a*a;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3612
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)

n, m, p = map(int, input().split())
edge = []
edge_inv = [[] for _ in range(n)]
for i in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    edge.append((a, b, -c+p))
    edge_inv[b].append(a)


visited = [0] * n
def dfs(v):
    for u in edge_inv[v]:
        if visited[u] == 0:
            visited[u] = 1
            dfs(u)

visited[n-1] = 1
dfs(n-1)
target_nodes = set([i for i in range(n) if visited[i] == 1])

INF = float('inf')
d = [INF] * n
d[0] = 0
for i in range(n):
    update = False
    for v_from, v_to, cost in edge:
        if v_from not in target_nodes or v_to not in target_nodes:
            continue
        if d[v_from] != INF and d[v_to] > d[v_from] + cost:
            update = True
            d[v_to] = d[v_from] + cost


if update:
    print(-1)
else:
    print(max(0, -d[n-1]))


Measured memory_bytes: 50908
# 2019/04/26
# AtCoder Beginner Contest 089 - C

# Input
n = int(input())
cl = ["M", "A", "R", "C", "H"]
ml = [0] * 5

# Count char
for i in range(n):
    wkc = input()
    for j in range(len(cl)):
        if cl[j] == wkc[0]:
            ml[j] += 1
            break
ans = 0
for x in range(len(cl) - 2):
    for y in range(x+1, len(cl) - 1):
        for z in range(y+1, len(cl)):
            ans += ml[x] * ml[y] * ml[z]

print(ans)


Measured memory_bytes: 3064
n, m, x = map(int, input().split())


def rikaido(lst):
    a = []
    for i in range(m):
        s = 0
        for j in range(len(lst)):
            s += lst[j][i]
        a.append(s)
    #print(a)
    return min(a)


c = []
a = []
for i in range(n):
  d = list(map(int, input().split()))
  c.append(d[0])
  a.append(d[1:])

ans = 10000000
for i in range(2 ** n):
    if i == 0:
        continue
    lst = []
    cost = 0
    for j in range(n):
        if (i >> j) & 1 == 1:
            lst.append(a[j])
            cost += c[j]
    #print(rikaido(lst))
    if rikaido(lst) >= x:
        ans = min(ans, cost)

if ans == 10000000:
    print(-1)
else:
    print(ans)


    




Measured memory_bytes: 9176
import sys
A=range(12)
m=[[0 for i in A] for j in A]
def f(y,x,d):
    P=[]
    x+=d[0]
    y+=d[1]
    if 0<=x<12 and 0<=y<12 and m[y][x]==1:
        m[y][x]=c
        P=[[y,x]]
    return P
def v1(buf):
    global c
    while buf!=[]:
        y,x=buf.pop()
        m[y][x]=c
        for e in [(-1,0),(1,0),(0,-1),(0,1)]:buf+=f(y,x,e)
    c+=1
    return
def solve():
    global c
    c=2
    for i in A:
        while m[i].count(1)>0:v1([[i,m[i].index(1)]])
    print c-2
    return 0
y=0
for s in sys.stdin:
    if y<12:
        m[y]=map(int,list(s[:-1]))
        y+=1
    else:y=solve()
solve()

Measured memory_bytes: 4280
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll MOD = 1000000007;
	ll n;
	cin >> n;
	vector<ll> A(n);
	rep(i, n) cin >> A[i];
	
	ll ret = 0;
	for (int i = 0; i < 60; ++i) {
		int count = 0;
		for (int j = 0; j < n; ++j) {
			if (A[j] & (1ll << i)) count++;
		}

		ll now = (1ll << i) % MOD;
		now *= count, now %= MOD;//1の数
		now *= n - count, now %= MOD;//0の数
		ret += now, ret %= MOD;
	}
	dunk(ret);
	return 0;
}

Measured memory_bytes: 2560
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
 	int R = sc.nextInt();  

      if(N>=10){
      System.out.println(R);
    }else{
		System.out.println(R+100*(10-N));
    }
}
}

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

int main()
{
    std::string S;
    std::cin >> S;

    const auto is_palindromic = [](const std::string& s) {
        std::string r(s.size(), ' ');
        std::reverse_copy(s.begin(), s.end(), r.begin());
        return s == r;
    };

    std::string S1(S.begin(), S.begin() + (S.size() - 1) / 2);
    std::string S2(S.begin() + (S.size() + 3) / 2 - 1, S.end());

    if(is_palindromic(S) && is_palindromic(S1) && is_palindromic(S2))
    {
        std::cout << "Yes" << std::endl;
    }
    else
    {
        std::cout << "No" << std::endl;
    }

    return 0;
}


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

string s, t;

long long c[100] = { 0 };
int dp[10000000] = { 0 };

int main() {
	int n; cin >> n;
	cin >> s >> t;
	//dp[0] = 0;
	c[s[0] - 'a'] = 1;
	for (int i = 1; i < n-1; i++) {
		//dp[i] = dp[i - 1];
		//dp[i] += c[t[i] - 'a'];
		//dp[i] %= 1000000007;
		c[s[i] - 'a'] += c[t[i] - 'a'];
		c[s[i] - 'a'] %= 1000000007;
	}
	cout << c[t[n-1]-'a'] << endl;
	return 0;
}


Measured memory_bytes: 3328
def main():
    N = int(input())
    A = list(map(int, input().split()))

    # 大きい順
    A.sort()
    A = A[::-1]

    ans = 0
    for i in range(1, N):
        ans += A[i // 2]

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 31424
#include<bits/stdc++.h>
using namespace std;
void lcs(string s,string s1,int m,int n)
{
   int dp[m+1][n+1];
   for(int i=0;i<=m;i++)
   {
      dp[i][0]=0;
   }
   for(int i=0;i<=n;i++)
   {
     dp[0][i]=0;
   }
   for(int i=1;i<=m;i++)
   {
      for(int j=1;j<=n;j++)
      {
         if(s[i-1]==s1[j-1])
         {
           dp[i][j]=1+dp[i-1][j-1];
         }
         else
          dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
      }
   }
   int index=dp[m][n];
   char lcs[index+1];
   lcs[index]='\0';
   int i=m;
   int j=n;
   while(i>0&j>0)
   {
      if(s[i-1]==s1[j-1])
      {
         lcs[index-1]=s[i-1];
         i--;
         j--;
         index--;
      }
      else if(dp[i-1][j]>dp[i][j-1])
      {
         i--;
      }
      else
      {
          j--;
      }
   }
   cout<<lcs<<"\n";
}
int main()
{
  string s,s1;
  cin>>s>>s1;
  int m=s.length();
  int n=s1.length();
  lcs(s,s1,m,n);
  return 0;
}

Measured memory_bytes: 35456
import Queue

n = int(input())
alist = [[] for i in range(n)]

for i in range(n):
	arr = map(int,raw_input().split())
	v,k = arr[0],arr[1]
	for j in range(k):
		alist[v].append([arr[2+j*2+1],arr[2+j*2]])



dist = [float("inf") for i in range(n)]
dist[0] = 0

q = Queue.PriorityQueue()

q.put([dist[0],0])

while not q.empty():
	dist_u, u = q.get()

	if dist[u] < dist_u :
		continue

	for weight,v in alist[u]:
		alt = dist_u + weight
		if dist[v] > alt:
			dist[v] = alt
			q.put([alt,v])


for i in range(n):
	print i,dist[i]


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

int main() {
  int N,K,sum;
  cin >> N >> K;
  for(int i=0;i<N;i++){
    int x;
    cin >> x;
    if (x > K-x){
      sum += 2*(K-x);
    }else{
      sum += 2*x;
    }
  }
  cout << sum <<endl;
}

Measured memory_bytes: 256
import sys
import math
from fractions import gcd
# import queue
from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

S = list(sys.stdin.readline().rstrip())
T = list(sys.stdin.readline().rstrip())

sc = Counter(S)
tc = Counter(T)

s = [x for x in sc.values()]
t = [x for x in tc.values()]

if sorted(s) == sorted(t):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 95944
#include"bits/stdc++.h"
using namespace std;

int main(){
    int n; cin >> n;
    int ans = 0;
    for(int i=1; i<=n; i++){
        if(i < 10){
            ans++;
        }else if(i > 99 && i < 1000){
            ans++;
        }else if(i > 9999 && i < 100000){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include <math.h>
#define M 1000000007
#define ll long long

ll fact[2000003],ifact[2000003];

ll mpow(ll x,ll n){
  ll ans = 1;
  while(n!=0){
    if(n&1) ans=ans*x%M;
    x = x*x%M;
    n=n>>1;
  }
  return ans;
}

ll combi(ll n,ll r){
  if(n==0&&r==0)return 1;
  if(n<r||n<0)return 0;
  ll tmp = ifact[r]*ifact[n-r]%M;
  return fact[n]*tmp%M;
}

int main(){
  ll x,y,k,m,n;
  scanf("%lld %lld",&x,&y);
  if((2*x-y)%3!=0||(2*y-x)%3!=0||2*x<y||2*y<x){
  	printf("0");
    return 0;
  }
  n=(2*x-y)/3;
  m=(2*y-x)/3;
  fact[0]=1;
  ifact[0]=1;

  for(ll i=0;i<2000004;i++){
    fact[i+1]=fact[i]*(i+1)%M;
    ifact[i+1]=ifact[i]*mpow(i+1,M-2)%M;
  }

  printf("%lld\n",combi(n+m,m)%M);
  return 0;
}


Measured memory_bytes: 31360
#!/usr/bin/env python3
import sys

MAX = 10 * 18


def solve(A: int, B: int, C: int, K: int):
    ans = A - B
    if K % 2 != 0:
        ans *= -1
    print(ans)

    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(A, B, C, K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 61988
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=500500;
int n,m;
struct node
{
	int l,r,x;
}e[maxn];
bool cmp(node a,node b)
{
	return a.x<b.x;
}
map<int,int>mp;
int ans[maxn];
set<int>s;
int main()
{
    cin>>n>>m;
    for(int i=1,u,v,w;i<=n;i++)
    {
	    scanf("%d%d%d",&u,&v,&w);
	    e[i].l=u-w;
	    e[i].r=v-w;
	    e[i].x=w;
    }
    for(int i=1,d;i<=m;i++)
    {
	    scanf("%d",&d);
	    mp[d]=i;
	    s.insert(d);
	    ans[i]=-1;
    }
    sort(e+1,e+1+n,cmp);
    for(int i=1;i<=n;i++)
    {
	    while(s.size()>0)
	    {
		    set<int>::iterator it=s.lower_bound(e[i].l);
		    if(it==s.end())break;
		    if((*it)>=e[i].r)break;
		    ans[mp[*it]]=e[i].x;
		    s.erase(it);
	    }
    }
    for(int i=1;i<=m;i++)printf("%d\n",ans[i]);
    /*
    for(int i=1;i<=n;i++)scanf("%d%d%d",&s[i],&t[i],&a[i]);
    for(int i=1;i<=n+1;i++)p[i]=1000000000,q[i]=-1000000000;
    p[1]=s[1]-a[1];
    q[1]=t[1]-a[1];
    s[n+1]=1,t[n+1]=1,a[n+1]=1000000010;
    for(int i=2;i<=n+1;i++)
    {
        p[i]=min(p[i-1],s[i]-a[i]);
        q[i]=max(q[i-1],t[i]-a[i]);
    }
    for(int i=1;i<=n+1;i++)
    {
        printf("!!! %d %d !!!\n",p[i],q[i]);
    }
    while(m--)
    {
        int d;
        scanf("%d",&d);
        int l=1,r=n+1,ans=1;
        while(l<=r)
        {
            int mid=(l+r)>>1;
            int fg=can(mid,d);
            printf("%d %d %d\n",mid,d,fg);
            if(can(mid,d))l=mid+1,ans=mid;
            else r=mid-1;
        }
        if(ans==n+1)printf("-1\n");
        else printf("%d\n",a[ans]);
    }*/
}
/*
10 10
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1

50 100
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
*/


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

int main() {
  int N;
  std::string S;
  std::cin >> N >> S;

  for (const char c : S) {
    const int i = int(c) - 'A';
    const int rot_i = (i + N) % 26;
    std::cout << char(rot_i + 'A');
  }

  return 0;
}


Measured memory_bytes: 256
#include<map>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
map<int ,int> n1,n2;
vector<int > a;
int main()
{
	int n,m;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		int t;
		cin>>t;
		n1[t]++;
	}
	cin>>m;
	for(int i=0;i<m;i++)
	{
		int t;
		cin>>t;
		if(n2[t]==0)
			a.push_back(t);
		n2[t]++;
	}
	for(int i=0;i<a.size();i++)
	{
		if(n2[a[i]]>n1[a[i]])
		{puts("NO");	return 0;}	

	}
	puts("YES");
	return 0;	
}

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

int main() {
	int n;
	cin >> n;
	
	int arr[n];
	for(int i = 0; i<n; i++) cin >> arr[i];
	
	int exp = 1;
	for(int i = 0; i<n; i++) {
		if(arr[i] == exp) exp++;
	}
	
	if(exp == 1) cout << -1 << endl;
	else cout << n-exp+1 << endl;
	return 0;
}

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

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

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  string s;
  while (getline(cin, s)) {
    stringstream ss(s);
    stack<double> st;
    string t, op = "+-*/";
    while (ss >> t) {
      if (op.find(t) == string::npos) {
        st.emplace(stoi(t));
      } else {
        double a, b;
        b = st.top(); st.pop();
        a = st.top(); st.pop();
        if (t == "+") st.emplace(a + b);
        else if (t == "-") st.emplace(a - b);
        else if (t == "*") st.emplace(a * b);
        else if (t == "/") st.emplace(a / b);
      }
    }
    cout << st.top() << endl;
  }

  return 0;
}


Measured memory_bytes: 3268
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

struct Edge {
    ll to;  // 頂点の番号
    ll id;  // 辺の番号
};

vector<vector<Edge>> G;
vl ans;

void dfs(ll v, ll p, ll color) {  // いま見ている頂点v、vの親p、vとpを結ぶ辺の色color
    ll num = 1;
    rep(i, G[v].size()) {
        ll u = G[v][i].to;  // vと隣接する頂点の番号
        ll ei = G[v][i].id;  // vにつながっている辺の番号
        if(u == p) {
            continue;
        }
        if(num == color) {
            num++;
        }
        ans[ei] = num;
        num++;
        dfs(u, v, ans[ei]);
    }
}

int main() {
    ll n;
    cin >> n;

    G.resize(n);
    ans.resize(n-1);
    
    rep(i, n-1) {
        ll a, b;
        cin >> a >> b;
        a--;  b--;
        G[a].pb((Edge){b, i});
        G[b].pb((Edge){a, i});
    } 
    
    dfs(0, -1, -1);

    ll K = 0;
    rep(i, n) {
        chmax(K, (ll)G[i].size());
    }
    out(K);
    rep(i, n-1) {
        out(ans[i]);
    }

    re0;
}

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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
using pll = pair<ll,ll>;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
#if loc||debg||local||debug
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}
template<class T>vector<T> _vec(size_t a,T v){return vector<T>(a,v);}
template<class T, class... Ts>auto _vec(size_t a, Ts... ts){return vector<decltype(_vec<T>(ts...))>(a, _vec<T>(ts...));}

int main(){

  string s;
  cin>>s;
  string hi = "hi";
  string ih = "ih";
  int n=s.size();
  for(int i=0;i<n;i+=2){
    if(s.substr(i,2)!=hi){
      cout<<"No";
      return 0;
    }
  }
  cout<<"Yes";

}

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

using namespace std;
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define PB(x, v) x.push_back(v);
#define M_P(a, b) make_pair(a, b)
#define pll pair<ll, ll>
#define ll long long
#define mll map<ll, ll>
#define vl vector<ll>
#define fa(x, v) for(auto x: v)
#define fr(i, a, b) for(int i= a;i <=b; i++)
#define TEST  ll Test; cin >> Test; while(Test--)

#define B_ begin()
#define E_ end()
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define NL_ "\n"
#define F first
#define S second
#define FF first.first
#define FS first.second
#define SF second.first
#define SS second.second

#define mod(a) a%1000000007
#define MAX 2000000000
#define  ull unsigned long long

void solve()
{
   ll a, b;
   cin>> a >> b;
   if(a< b) swap(a, b);
   ll r= a - b;
   if(!r) {cout << 0<<NL_; return ;}
   ll i =1;
   while(true)
   {
       ll t = i*(i+1)/2;
       if((t-r)%2==0 and t-r>=0)
       {
           cout << i <<NL_;
           return ;
       }
       i++;
   }
}

bool check(ll n)
{
    if(n==2)
        return 1;
    for(ll i = 2; i*i<=n; i++)
    {
        if(n%i==0)
            return 0;
    }
    return 1;

}

int main()
{

    FAST;
    ll a, b, c;
    cin >> a>> b >> c;
    cout << ((a/b)+(a%b!=0))*c;




    return 0;
}


Measured memory_bytes: 3548
n, k = list(map(int, input().split()))
h = list(map(int, input().split()))

# dp[i][j]: 足場iまで見た時 jまでの最小コスト
dp = [0 for i in range(n)]

dp[1] = abs(h[1] - h[0])

for i in range(n):
    if i == 0 or i == 1:
        continue

    costs = []

    for j in range(1, min(k + 1, i + 1)):
        costs.append(dp[i - j] + abs(h[i] - h[i - j]))

    dp[i] = min(costs)

print(dp[-1])


Measured memory_bytes: 56544
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int board[16][16];
int n;//魔法陣n×n

void magic(int y,int x,int i){
	if(i >n*n)
		return ;
	if(y==n+1){//下にはみ出し
		magic(1,x,i);
		return;
	}
	if(x>n){//右にはみ出し
		magic(y,1,i);
		return ;
	}
	if(x<1){//左にはみ出し
		magic(y,n,i);
		return;
	}
	if(board[y][x]==0){
		board[y][x]=i;
		magic(y+1,x+1,i+1);
	}else{
		magic(y+1,x-1,i);
	}

}

int main(){
	while(cin>>n,n){
		for(int i = 1;i <= n;i++){
			for(int j = 1;j <= n;j++){
				board[i][j] = 0;
			}
		}
		int py =0.5*(n+3);
		int px =0.5*(n+1);
		board[py][px] = 1;
		magic(py+1,px+1,2);
		for(int i = 1;i <=n;i++){
			for(int j = 1;j <=n;j++){
				printf("%4d",board[i][j]);
			}
			cout <<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1192
// 2019.cpp : This file contains the 'main' function. Program execution begins and ends there.
//JANUARY: {1521, 1644} -> {1614, 1644} -> {1643, 1644} ->

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


#define int long long
#define all(a) a.begin(), a.end()
#define need_for_speed ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
const int INF = 1e18;
int dp[26][26];
string s[26];


signed main()
{
	need_for_speed;
	
	int n, w; cin >> n >> w;

	vector<pair<int, int> > wv(n);

	for (int i = 0; i < n; i++) {
		cin >> wv[i].first >> wv[i].second;
	}

	vector<vector<int> > dp(n, vector<int>(w + 1));
	for(int i=wv[0].first; i<=w; i++)
		dp[0][i] = wv[0].second;

	for (int i = 1; i < n; i++) {
		for (int j = 0; j <= w; j++) {
			dp[i][j] = max(dp[i - 1][j], 0ll);
			if (j - wv[i].first >= 0)
				dp[i][j] = max(dp[i][j], dp[i - 1][j - wv[i].first] + wv[i].second);
		}
	}
	cout << dp[n - 1][w];
}




Measured memory_bytes: 79488
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

int a,b,c;
int n,n1,n2;

int main()
{
	scanf("%d%d%d",&n,&n1,&n2);
	for(int i=1; i<=n; i++)
	{
		int x; scanf("%d",&x);
		if(x<=n1) {a++;}
		else if(x>n2) {c++;}
		else {b++;}
	}
	printf("%d\n",min(min(a,b),c));
	return 0;
}

Measured memory_bytes: 128
import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18

A, B, X = list(map(Decimal, sys.stdin.readline().split()))

ans = math.floor(B / X) - math.ceil(A / X) + 1
print(ans)


Measured memory_bytes: 13644
#include <stdio.h>

#define N 8
#define FREE -1
#define NOTFREE 1

int row[N],col[N],dpos[2*N-1],dneg[2*N-1],map[N][N];

void init();
void print();
void rec(int);

int main(){
  init();
  int r,c,n,i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d",&r,&c);
    map[r][c]=1;
  }
  rec(0);
  return 0;
}

void init(){
  int i;
  for(i=0;i<N;i++){
    row[i]=FREE;
    col[i]=FREE;
    dpos[i]=FREE;
    dneg[i]=FREE;
  }
  for(;i<2*N-1;i++){
    dpos[i]=FREE;
    dneg[i]=FREE;
  }
}

void print(){
  int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(map[i][j]==1){
	if(row[i]!=j)return;
      }
    }
  }
  
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i]==j)printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}

void rec(int i){
  int j;
  if(i==N){
    print();
    return;
  }
  for(j=0;j<N;j++){
    if(NOTFREE==col[j]||
       NOTFREE==dpos[i+j]||
       NOTFREE==dneg[i-j+N-1])continue;
    row[i]=j;
    col[j]=dpos[i+j]=dneg[i-j+N-1]=NOTFREE;
    rec(i+1);
    row[i]=col[j]=dpos[i+j]=dneg[i-j+N-1]=FREE;
  }
}



Measured memory_bytes: 2700
#include <bits/stdc++.h>
#define pp pair<int,int>
#define fi first
#define se second
#define maxx 100012
#define ll long long
#define pb push_back
#define mp make_pair
#define lb lower_bound
const int mod=998244353;
using namespace std;

int n,a[maxx];

int create(int num){
    int res=1;
    while(num--){
        res*=10;
    }
    return res;
}

int dem(int k){
    int res=0;
    while(k>0){
        res++;
        k/=10;
    }
    return res;
}

void input(){
//    freopen("TEST.INP","r",stdin);
//    freopen("TEST.OUT","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=n-1;i>=1;i--){
        if(a[i]==a[i+1]+1){
            a[i]--;
        }
        else{
            if(a[i]>a[i+1]+1){
                cout<<"No";return ;
            }
        }
    }
    cout<<"Yes";
}

int main()
{
    input();

    return 0;
}


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

const ull B = 100000007;

ull Rev(ull a) {
	ull res = 1;
	for (ull i = 0; i < 0x80; i++) {
		res *= a;
		a *= a;
	}
	return res;
}

ull Pow(ull a, ull b) {
	ull res = 1;
	for (ull i = 0; i < 0x80;i++) {
		if ((b >> i) & 1) {
			res *= a;
		}
		a *= a;
	}
	return res;
}

int main()
{
	int n, m;
	ull l = 0, r = 0;
	ull hash;
	string S, cmd;
	set<ull> hass;
	cin.sync_with_stdio(false);
	cin >> n >> m >> S;
	hash = S[0];
	while (m--) {
		cin >> cmd;
		if (cmd == "L++") {
			hash -= Pow(B, r - l) * S[l];
			l++;
		}
		else if (cmd == "L--") {
			l--;
			hash += Pow(B, r - l) * S[l];
		}
		else if (cmd == "R++") {
			r++;
			hash = hash * B + S[r];
		}
		else if (cmd == "R--") {
			hash = (hash - S[r]) * Rev(B);
			r--;
		}
		hass.insert(hash);
	}
	cout << hass.size() << endl;
	return 0;
}

Measured memory_bytes: 21988
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>

typedef long long ll;
typedef unsigned long long ull;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;


//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()ss		
#define debug system("pause")				//デバッグ用

int saiki(string, int, int);

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

	string s;
    cin>>s;

    cout<<s[0];
    cout<<s.size()-2;
    cout<<s[s.size()-1]<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;
import java.util.ArrayList;
public class Main{
    public static int sum =0;
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        Long a =  sc.nextLong();
        String S = String.valueOf(a);
        Arrays.asList(LIBctoC(S.toCharArray())).forEach(c -> sum +=  c - 48);;
        Long b = sum + 0L;
        System.out.println((a%b==0)?"Yes":"No");
        sc.close();
    }

    public static Character[] LIBctoC(char[] c){
        int size = c.length;
        Character[] C = new Character[size];
        for (int i = 0;i<size;i++){
            C[i] = Character.valueOf(c[i]);
        }
        return C;
    }
}

Measured memory_bytes: 27476
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int a[3];
  for(int i=0;i<3;i++)
    cin>>a[i];
  sort(a,a+3);
  int ans=0;
  if(a[0]==a[2]) ans=1;
  else{
    if(a[0]==a[1]||a[1]==a[2]) ans=2;
    else ans=3;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
int N,L,Q;
int x[MAXN],st[MAXN][20];
void Solve() {
    read(N);
    for(int i = 1 ; i <= N ; ++i) read(x[i]);
    read(L);read(Q);
    for(int i = 1 ; i <= N ; ++i) {
	int t = upper_bound(x + 1,x + N + 1,x[i] + L) - x - 1;
	st[i][0] = t;
    }
    for(int j = 1 ; j <= 19 ; ++j) {
	for(int i = 1 ; i <= N ; ++i) {
	    st[i][j] = st[st[i][j - 1]][j - 1];
	}
    }
    int a,b;
    for(int i = 1 ; i <= Q ; ++i) {
	read(a);read(b);
	if(a > b) swap(a,b);
	int p = a,ans = 0;
	for(int j = 19 ; j >= 0 ; --j) {
	    if(st[p][j] < b) {
		p = st[p][j];
		ans += (1 << j);
	    }
	}
	++ans;
	out(ans);enter;
    }
}

int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 9088
#include<stdio.h>
int main(void){
	char S[26];
	int i=0,j=0;
	int length=0;
	int f=0;

	scanf("%s",S);

	for(i=0;i<26;i++){
		if(S[i]==NULL)break;
		length += 1;
	}
	for(i=0;i<length;i++){
		for(j=i;j<length;j++){
			if(S[i]==S[j+1]){
				f=1;
				break;
			}
		}
		if(f==1) break;
	}
	if(f==0) printf("yes");
	else printf("no");
}

Measured memory_bytes: 128
///#pragma GCC optimize("Ofast")
///#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
///#pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>
///#include<ext/pb_ds/assoc_container.hpp>
///#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
///using namespace __gnu_pbds;
///template<typename T> using orderset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vii> vvii;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const ll N = 10001;
const ll MOD = 1000000007;
const ll INF = LLONG_MAX;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rev(a) reverse(all(a))
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define yes cout<<"YES"<<nl
#define no cout<<"NO"<<nl
#define space ' '
#define nl '\n'
#define PI acos(-1)

#define coutv(v) for(auto it:v)cout<<it<<space;cout<<nl;
#define cinv(v) for(auto &it:v)cin>>it;


int main()
{
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    int tc=1,cs=0;
    ///cin>>tc;
    while(tc--)
    {
        ll n,i,a;
        cin>>n;
        vll cnt(n+1);
        for(i=1;i<n;i++)
        {
            cin>>a;
            cnt[a]++;
        }
        for(i=1;i<=n;i++)
            cout<<cnt[i]<<nl;
    }
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define itn int
typedef long long ll;
typedef pair<ll,ll> p;


int main()
{
  string s;
  cin >> s;
  if (s[0] != s[1] && s[0] != s[2] && s[1] != s[2])
  {
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256