akhauriyash/Code-Regression huggingface dataset:
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}



signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  db r;cin>>r;
  cout<<2*acos(-1.0)*r<<ENDL;
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 3840
from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
    return int(input())

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


def solve():
    n = ri()
    A = rl()

    X = 0
    for a in A:
        X = X ^ a

    print (*[a^X for a in A])






mode = 's'

if mode == 'T':
    t = ri()
    for i in range(t):
        solve()
else:
    solve()


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

using ll = long long;
#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

#define INF 1e9


int main(){
  int n, x;
  cin >> n >> x;
  while(n!=0 || x!= 0){
    int cnt = 0;
    FOR(i, 1, n+1){
      FOR(j, i+1, n+1){
        int k = x - (i+j);
        if(j < k && k <= n){
          cnt++;
        }
      }
    }
    cout << cnt << endl;
    cin >> n >> x;
  }
  return 0;
}



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

int main(){
    string s;
    cin >> s;
    int cnt = 0;
    int now = 0;//wからスタート
    vector<int> rev(0);
    rep(i,s.size()) {
        if (s[i] == 'B' && now ==1){
            cnt++;
        }
        else if (s[i] == 'B' && now == 0){
            if (cnt != 0)rev.push_back(cnt);
            cnt = 1;
            now = 1;
        }
        else if (s[i] == 'W' && now == 1){
            if (cnt != 0)rev.push_back(cnt);
            cnt = 1;
            now = 0;
        }
        else{
            cnt++;
        }
    }
    if (cnt != 0)rev.push_back(1);
    cout << rev.size()-1 << endl;


}

Measured memory_bytes: 1020
import java.util.Scanner;

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

        long N = sc.nextLong();

        long min = Long.MAX_VALUE;
        long max = Long.MIN_VALUE;
        long sum = 0;
        for (long i = 0; i < N; i++) {
            long a = sc.nextLong();

            sum += a;

            if (min > a) {
                min = a;
            }
            if (max < a) {
                max = a;
            }
        }

        System.out.printf("%d %d %d\n", min ,max, sum);
    }
}

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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    for (int j = i; j < s.size(); j++) {
      string s1 = s.substr(0,i);
      string s2 = s.substr(j, s.size() - j);
      string s3 = s1 + s2;
      if (s3 == "keyence") {
        puts("YES");
        return 0;
      }
    }
  }
  puts("NO");
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<set>
#include<string>
typedef long long int lli;
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    vector<string> v;
    vector<string> v1;
    
   int a;
   int x;
   cin>>x>>a;
  
   if(x<a){
       printf("0\n");
   }else{
       printf("10\n");
       
   }
    return 0;
}



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

#pragma GCC optimize("O2,no-stack-protector,unroll-loops,fast-math")

#define F first
#define S second
#define pb push_back
#define SZ(x) (ll)(x.size())
#define all(x) x.begin(),x.end()
#define MP make_pair

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn=2e5+10, maxm=5e4+10, lg=21, mod=1e9+7, inf=1e18;

ll n,vv,h[maxn];
vector<ll> g[maxn];
void dfs(ll v=1,ll p=0){
	h[v]=h[p]+1;
	if(h[v]>h[vv]) vv=v;
	for(auto u:g[v])if(u!=p) dfs(u,v);
}

int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	
	cin>>n;
	for(int i=1;i<n;i++){
		ll v,u; cin>>v>>u;
		g[v].pb(u), g[u].pb(v);
	}
	dfs(),dfs(vv);
	if((h[vv]-1)%3==1) cout<<"Second";
	else cout<<"First";
	
	return 0;
}






Measured memory_bytes: 25496
import java.lang.reflect.Array;
import java.util.*;
import java.io.*;
import java.lang.*;

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

        String inp = sc.next();

        int a = Integer.parseInt(String.valueOf(inp.charAt(inp.length() - 1)));

        if (a== 2|| a== 4|| a== 5|| a== 7|| a== 9)
            System.out.println("hon");
        else if (a== 0|| a== 1|| a== 6|| a== 8)
            System.out.println("pon");
        else if (a== 3)
            System.out.println("bon");
    }
}


Measured memory_bytes: 35556
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define chmin(x,y) x = min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main() {
    int a, b;
    cin >> a >> b;
    int ans;
    if (a > b) swap(a,b);
    if (a == 1 && b == 2) ans = 3;
    else if (a == 1 && b == 3) ans = 2;
    else ans = 1;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

int main(){
  int n; cin>>n;
  while(n --> 0){
    int w,h; cin>>h>>w;
    char buff[h][w+1];
    bool flag[30][30] = {{false}};
    bool ans = true;
    REP(i,h) cin>>buff[i];
    for(char c = 'A'; c <= 'Z'; c++){
      int cnt = 0;
      int maxx = 0, maxy = 0;
      int minx = w, miny = h;
      REP(i,h) REP(j,w){
        if(buff[i][j] == c){
          cnt++;
          maxx = max(maxx, j);
          maxy = max(maxy, i);
          minx = min(minx, j);
          miny = min(miny, i);
        }
      }
      if(cnt == 0) continue;
      //printf("%c: (%d,%d) => (%d,%d)\n",c,minx,miny,maxx,maxy);
      for(int i = miny; i<=maxy; i++){
        for(int j = minx; j<=maxx; j++){
          char tmp = buff[i][j];
          if(tmp == c) continue;
          if(tmp == '.'){
            ans = false;
            break;
          }
          if(flag[c-'A'][tmp-'A']){
            ans = false;
          }else{
            flag[tmp-'A'][c-'A'] = true;
          }
        }
      }
      if(!ans) break;
    }
    if(ans){
      REP(k,30)REP(i,30)REP(j,30)
        flag[i][j] |= (flag[i][k] & flag[k][j]);
      REP(i,30) REP(j,30)
        if(flag[i][j] && flag[j][i])
          ans = false;
    }
    puts(ans?"SAFE":"SUSPICIOUS");
  }
  return 0;
}

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

int N;
int p[8],q[8];
vector<int> dic(40325);
int idx=0;

int kaijo(int n){
  int ans=1;
  for(int i=1;i<=n;i++) ans*=i;
  return ans;
}

bool is_d_in_x(int d, int x){
  while(x>0){
    int res= x%10;
    if(res==d) return false;
    x/=10;
  }

  return true;
}

int digits(int x){
  int d=0;
  while(x>0){
    x/=10;
    d++;
  }
  return d;
}

void dfs(int d){
  if(digits(d)==N) {
    dic[idx]=d;
    idx++;

    return;
  }
  for(int i=1;i<=N;i++){

    if(is_d_in_x(i,d)){
      dfs(d*10+i);
    }
  }
}
int main() {

  cin>>N;

  for(int i=0;i<N;i++) cin>>p[i];
  for(int i=0;i<N;i++) cin>>q[i];
  int P=0,Q=0;
  for(int i=0;i<N;i++){
    P+=p[N-1-i]*long(pow(10,i));
  }
  for(int i=0;i<N;i++){
    Q+=q[N-1-i]*long(pow(10,i));
  }

  int l,r;

  dfs(0);
  sort(dic.begin(),dic.begin()+kaijo(N));

  int a,b;
  for(int i=0;i<kaijo(N);i++){
    if(dic[i]==P) a=i;
    if(dic[i]==Q) b=i;
  }
  cout<<abs(a-b)<<endl;




}


Measured memory_bytes: 384
package main

import (
	"fmt"
)

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func main() {
	var a, b, c, d, mcd int

	fmt.Scanf("%d %d %d %d", &a, &b, &c, &d)
	mcd = c * d / gcd(c, d)

	total := b - a + 1

	sumC := (b / c) - (a / c)
	if a%c == 0 {
		sumC++
	}
	sumD := (b / d) - (a / d)
	if a%d == 0 {
		sumD++
	}

	sumCD := (b / mcd) - (a / mcd)
	if a%mcd == 0 {
		sumCD++
	}

	// fmt.Printf("%d %d %d\n", sumC, sumD, sumCD)

	sumCD = sumC + sumD - sumCD

	fmt.Print(total - sumCD)
}


Measured memory_bytes: 512
#include <utility>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#define INTINF 2147483647
#define LLINF 9223372036854775807
typedef long long ll;
using namespace std;
int n;
int cnt=0;
ll A[500000];
ll L[500000/2+2];
ll R[500000/2+2];

void merge(int left, int mid, int right) {
  int n1 = mid - left;
  int n2 = right - mid;
  for (size_t i = 0; i < n1; i++) {
    L[i] = A[left + i];
  }
  for (size_t i = 0; i < n2; i++) {
    R[i] = A[mid + i];
  }
  L[n1] = LLINF;
  R[n2] = LLINF;
  int i=0;
  int j=0;
  for (size_t k = left; k < right; k++) {
    cnt++;
    if (L[i] <= R[j]) {
      A[k] = L[i];
      i++;
    }else{
      A[k] = R[j];
      j++;
    }
  }
}


void mergesort(int left, int right){
  if (left+1 < right) {
    int mid = (left + right)/2;
    mergesort(left, mid);
    mergesort(mid, right);
    merge(left, mid, right);
  }
}


int main(int argc, char const *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  std::cin >> n;
  for (size_t i = 0; i < n; i++) {
    std::cin >> A[i];
  }

  mergesort(0,n);

  for (size_t i = 0; i < n; i++) {
    if (i!=0) {
      std::cout << " ";
    }
    std::cout << A[i] ;
  }
  std::cout << '\n';

  std::cout << cnt << '\n';

  return 0;
}



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

long long gcd(long long a, long long b) {
    if (b > a) std::swap(a, b);
    if (a % b == 0) return b;
    else return gcd(b, a % b);
}

long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b;
}

int main() {
    long long n, m;
    std::string s, t;
    std::cin >> n >> m >> s >> t;
    long long l = lcm(n, m);
    long long a = l / n, b = l / m;
    std::map<long long, char> ma;
    for (int i = 0; i < n; i++) {
        ma[i * a] = s[i];
    }
    for (int i = 0; i < m; i++) {
        if (ma[i * b] > 0) {
            if (ma[i * b] != t[i]) {
                std::cout << -1 << std::endl;
                return 0;
            }
        }
    }
    
    std::cout << l << std::endl;

    return 0;
}

Measured memory_bytes: 10880
s = str(input())
ans = 0
for bits in range(1 << len(s)-1):
    a = s[0]
    for i in range(len(s)-1):
        if (bits >> i & 1) == 1:
            a += '+'
        a += s[i+1]
    ans += eval(a)
print(ans)

Measured memory_bytes: 2940
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<iterator>
#include<stack>
#include<queue>
#include<utility>
#include<functional>
#include<bitset>
#include<numeric>
#include<cstring>
#include<tuple>
using namespace std;

int n, dish;
vector< int > cnt( 5, 0 );
int hit[ 310 ][ 310 ][ 310 ];
long double dp[ 310 ][ 310 ][ 310 ];

long double solve( int a, int b, int c )
{
	if( a < 0 || b < 0 || c < 0 || ( a == 0 && b == 0 && c == 0 ) )
	{
		return 0;
	}
	if( hit[ a ][ b ][ c ] != -1 )
	{
		return dp[ a ][ b ][ c ];
	}
	hit[ a ][ b ][ c ] = 1;
	dp[ a ][ b ][ c ] = ( n * 1.0 ) / ( a + b + c ) + a * solve( a - 1, b, c ) / ( a + b + c )
													+ b * solve( a + 1, b - 1, c ) / ( a + b + c )
													+ c * solve( a, b + 1, c - 1 ) / ( a + b + c );
	return dp[ a ][ b ][ c ];
}

int main( void )
{
	ios :: sync_with_stdio( 0 );
	cin.tie( 0 );
	
	memset( hit, -1, sizeof( hit ) );
	cin >> n;
	for( int i = 1; i <= n; ++i )
	{
		cin >> dish;
		++cnt[ dish ];		
	}
	cout << fixed << setprecision( 25 ) << solve( cnt[ 1 ], cnt[ 2 ], cnt[ 3 ] ) << "\n";
	return 0;
}

Measured memory_bytes: 567808
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <string>
#include <functional>
#include <cassert>
#include <cmath>
#define SIZE 100005
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
 
int main()
{
    int m,d;
    scanf("%d %d", &m, &d);

    int ret = 0;
    for(int i=1; i<=m; i++){
        for (int j=1; j<=d; j++){
            int d10 = j / 10;
            int d1 = j % 10;
            if(i == d10*d1 && d1>=2 && d10>=2){
                ret++;
            }
        }
    }
    printf("%d", ret);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;

const long long INFLL = 1LL << 60;
const int INFI = 1000000000;


int main(){
    int N,K; cin >> N >> K;
    vector<int> h(N);
    for(int i=0;i<N;i++){cin >> h[i];}
    sort(h.begin(), h.end());
    int min = 1000000010;
    for(int i=0;i<=N-K;i++){
        if((h[i+K-1] - h[i]) < min)  min = h[i+K-1] - h[i];
    }
    cout << min << endl;
}



Measured memory_bytes: 640
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

//台形の面積計算、速度が高さで幅は1、縦横2倍にして計算したから面積4分の1
double calcarea(int a, int b) {
	return (double)(a + b)/8.0;
}

// 山形のとんがりができると誤差がでるので、0.5秒ごとに計算すべきだが
// 途中少数を扱うのがめんどくさいので縦横2倍してあとで4分の1することにした
// 結局最後の足し上げのところで少数使っているが、これはさけられないのだろうか…

//うまい人がこぞってdp解でやってるので、チェック
//このソースは解説放送のやり方

//やるだけ感はあるが、含む含まないとかめんどくさいので図をきちんと書くの推奨
int main() {
	int n; cin >> n;

	vector<int> t(n);
	vector<int> v(n);

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

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

	vector<int> limitspeed(sum*2+1,INF);
	
	//入力を一つの時間軸にまとめる
	int now = 0;
	for (int i = 0; i < n; i++) {
		for (int j = now; j <= t[i]*2+now; j++) {
			limitspeed[j] = min(limitspeed[j], v[i]*2);
		}

		now += t[i] * 2;
	}
	
	//始点側からの速度の更新
	limitspeed[0] = 0;
	for (int i = 0; i < sum * 2; i++) {
		limitspeed[i + 1] = min(limitspeed[i + 1], limitspeed[i] + 1);
	}

	//終点側からの速度の更新
	limitspeed[sum * 2] = 0;
	for (int i = sum * 2; i >0 ; i--) {
		limitspeed[i-1] = min(limitspeed[i-1], limitspeed[i] + 1);
	}

	//面積の足し上げ
	double ans = 0.0;

	for (int i = 0; i < sum * 2; i++) {
		ans += calcarea(limitspeed[i], limitspeed[i + 1]);
	}

	//出力
	cout << fixed << setprecision(12) << ans << endl;


	return 0;
}

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

void b_card_game_for_two(void) {
	int n;
	int a[110] = { 0 };
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n,std::greater<>());

	int a_sum = 0;
	int b_sum = 0;
	for (int i = 0; i < n; i++) {
		if ((i & 0x1) == 0x0) a_sum += a[i];
		else                  b_sum += a[i];
	}
	cout << a_sum - b_sum << endl;
}

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

Measured memory_bytes: 3608
N,M = map(int,input().split())
H = [0]
H += list(map(int,input().split()))

AB = []
for i in range(M):
    A,B = map(int,input().split())
    AB.append([A,B])
h = [0]
for i in range(N):
    h.append(1)
    
for k in range (M):
    i = AB[k][0]
    j = AB[k][1]
    if H[i] < H[j]:
        h[i] = 0
    elif H[i] > H[j]:
        h[j] = 0
    else:
        h[i] = 0
        h[j] = 0

print(sum(h))

Measured memory_bytes: 28952
#include <stdio.h>
 
int main(void){
  char s[101],p[101];
  int i,j,sn=0,pn=0,t;
 
  scanf("%s %s",s,p);
 
//文字数カウント
  while(s[sn] != '\0') sn++;
  while(p[pn] != '\0') pn++;
 
  for(i=0;i<sn;i++){
    t=1;
    for(j=0;j<pn;j++)
      if(s[(i+j)%sn] != p[j]) t=0;
    if(t) break;
  }
 
  if( t )
    printf("Yes\n");
  else
    printf("No\n");
 
  return 0;
}
   


Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define il inline
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define mid ((l+r)>>1)
#define MAXN 4005
#define MAXM
#define mod 998244353
#define inf (1<<30)
#define eps (1e-6)
#define alpha 0.75
#define rep(i, x, y) for(register int i = x; i <= (y); ++i)
#define repd(i, x, y) for(register int i = x; i >= (y); --i)
#define file(s) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, int> pli;
typedef pair <int, ll> pil;
typedef pair <ll, ll> pll;
template <typename T> il bool chkmin(T &x, T y) {return x > y ? x = y, 1 : 0;}
template <typename T> il bool chkmax(T &x, T y) {return x < y ? x = y, 1 : 0;}
template <typename T> il void read(T &x) {
	char ch = getchar(); int f = 1; x = 0;
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') x = x*10+ch-'0', ch = getchar();
	x *= f;
}
template <typename T, typename... Args> il void read(T &x, Args &...args) {
	read(x), read(args...);
}
int n;
char s[MAXN];
ll dp[MAXN][MAXN];
void add(ll &x, ll y) {
	(x += y) %= mod;
}
int main() {
	scanf("%s", s+1);
	n = strlen(s+1);
	dp[0][0] = 1;
	int r = 0, b = 0;
	rep(i, 1, n * 2) {
		if(i <= n) b += s[i] - '0', r += '2' - s[i];
		rep(j, 0, i) 
			if(r >= j && b >= i-j) {
				add(dp[i][j], dp[i-1][j]);
				if(j) add(dp[i][j], dp[i-1][j-1]);
			}
	}
	cout << dp[n * 2][r] << endl;
	return 0;
}


Measured memory_bytes: 123520
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.nextLine();
		String s = sc.nextLine();
		char[] chr = s.toCharArray();
		int ans = 0, count = 1;
		for(int i = 0; i < n - 1; i++){
			if(chr[i] != chr[i+1]){
				count++;
			}
		}
		System.out.println(count);
	}

	}

Measured memory_bytes: 26308
S = input()
ans = 0
bc = 0
c_flag = 0
for i in range(len(S) - 1, -1, -1):
    if S[i] == "A" and c_flag == 0:
        ans += bc
    elif S[i] == "C" and c_flag == 0:
        c_flag = 1
    elif S[i] == "B" and c_flag == 1:
        bc += 1
        c_flag = 0
    else:
        bc = 0
        if S[i] == "C":
            c_flag = 1
        else:
            c_flag = 0
print(ans)






Measured memory_bytes: 3500
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#define INF 1000000000
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;

int main(){
  int N;
  int a[100];
  cin >> N;
  LOOP(i,N){
    cin >> a[i];
  }
  sort(a,a+N);
  int A=0,B=0;
  int c=0;
  for(int i=N-1;i>=0;i--){
    if(c%2==0)A+=a[i];
    else    B+=a[i];
    c++;
  }
  cout << (A-B) << endl;
}


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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int _i=(first);_i<(last);++_i){cout<<#a<<"["<<_i<<"] = "<<(a)[_i]<<endl;}
#define PRINTP(p)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#p<<" = ("<<(p.first)<<", "<<(p.second)<<")"<<endl;
#define PRINTI(a,i)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<#i<<"] = "<<#a<<"["<<(i)<<"] = "<<(a)[i]<<endl;
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#define PRINTP(p)
#define PRINTI(a,i)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define MOD 1000000007
//#define MOD 998244353

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

template <class T>
using vec2 = vector<vector<T>>;

template <class T>
using vec3 = vector<vector<vector<T>>>;

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

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

    int N;
    cin >> N;

    PRINT(N);

    vector<int> a(N + 1);
    FOR(x, 1, N + 1) {
        int s = x * x;
        if (s > N) {
            break;
        }
        FOR(y, 1, N + 1) {
            s = x * x + y * y + x * y;
            if (s > N) {
                break;
            }
            FOR(z, 1, N + 1) {
                s = x * x + y * y + z * z + x * y + y * z + z * x;
                if (s > N) {
                    break;
                }
                PRINT(x);
                PRINT(y);
                PRINT(z);
                PRINT(s);
                a[s]++;
            }
        }
    }
    FOR(i, 1, N + 1) {
        cout << a[i] << '\n';
    }
    cout << flush;

    return 0;
}


Measured memory_bytes: 3644
def make_tbl(n):
    tbl = [False, True, False, False, False, True] * (n // 6 + 1)
    for i in range(1, 4):
        tbl[i] = not tbl[i]
    p, stp, sqrt = 5, 2, n ** 0.5
    while p < sqrt:
        for i in range(p ** 2, n, 2 * p):
            tbl[i] = False
        while True:
            p += stp
            stp = 6 - stp
            if tbl[p]:
                break
    return tbl
tbl = make_tbl(50000)
ps = [i for i in range(50000) if tbl[i]]
while True:
    n = int(input())
    if not n:
        break
    res = 0
    if n % 2:
        if tbl[n - 2]:
            res += 1
    else:
        res = 0
        for p in ps:
            if 2 * p > n:
                break
            if tbl[n - p]:
                res += 1
    print(res)

Measured memory_bytes: 8080
def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    ABC = [list(map(int, input().split())) for i in range(N)]

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

    dp[0] = ABC[0]
    ind = [[1, 2], [0, 2], [0, 1]]
    for i in range(1, N):
        a, b, c = ABC[i]

        dp[i][0] = a + max(dp[i-1][1], dp[i-1][2])
        dp[i][1] = b + max(dp[i-1][0], dp[i-1][2])
        dp[i][2] = c + max(dp[i-1][0], dp[i-1][1])

    print(max(dp[-1]))


if __name__ == "__main__":
    main()


Measured memory_bytes: 69596
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

/*Node treeMinimum(Node x){


}

Node treeMaximum(Node x){


}*/

Node treeSearch(Node u, int k){
  Node x;
  x = root;//初期値は根
  while(x != NIL&& k!=x->key){//葉でないかつkeyの値が異なれば下に降りる
    if(k < x->key) x = x->left;
    else x = x->right;
  }
  
  return x;
}

/*Node treeSuccessor(Node x){


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}
*/
void insert(int k){
  Node y = NIL;
  Node x = root;//根から探索start
  Node z;//挿入したいノードを格納
    
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
  while(x != NIL){//挿入する場所を探索
  	y=x;
  	if(z->key<x->key) x=x->left;
  	else x=x->right;
  }
  
  z->parent=y;
  if(y==NIL) root=z;//最初の根を設定
  else if(z->key<y->key) y->left=z;//上の探索で見つけた親から左右どちらに入れるか判断
  else y->right=z;
}

void inorder(Node u){
  if(u==NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u==NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      //treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}


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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

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

using Pi = pair<int, int>;
using Ti = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int k;
  cin >> k;
  vint a(k);
  rep(i, k) cin >> a[i];
  reverse(all(a));
  int mn = 2, mx = 2;
  rep(i, k) {
    mn = ((mn+a[i]-1)/a[i])*a[i];
    mx = (mx/a[i])*a[i] + a[i]-1;
    if(mn > mx) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << mn << " " << mx << endl;

  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<math.h>
using namespace std;
int main(){
  int A,B;
  cin>>A>>B;
  if((B-1)%(A-1)==0){
    cout<<(B-1)/(A-1)<<endl;
  }
  else{
    cout<<(B-1)/(A-1)+1<<endl;
  }
}

Measured memory_bytes: 256
//https://onlinejudge.u-aizu.ac.jp/problems/ALDS1_5_C
//p148.cpp

#include<stdio.h>
#define _USE_MATH_DEFINES
#include<math.h>

//g++では、問題ないが、VC++（VSでコンパイルするとき）では
// #define _USE ～～　ないと「M_PI」がつかえない。

struct Point{double x,y;};

void koch(int n,Point a,Point b){
  if(n==0)return;

  Point s,t,u;
  double th = M_PI * 60.0 / 180.0; //度から、ラジアンへ変換

  s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
  s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
  t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
  t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
  u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
  u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;

  koch(n - 1,a,s);
  printf("%.8f %.8f\n", s.x , s.y);
  koch(n - 1,s,u);
  printf("%.8f %.8f\n", u.x , u.y);
  koch(n - 1,u,t);
  printf("%.8f %.8f\n", t.x , t.y);
  koch(n - 1,t,b);
}

int main(){
  Point a,b;
  int n;

  scanf("%d",&n);

  a.x = 0;
  a.y = 0;
  b.x = 100;
  b.y = 0;

  printf("%.8f %.8f\n", a.x , a.y);
  koch(n,a,b);
  printf("%.8f %.8f\n", b.x , b.y);

  return 0;
}



Measured memory_bytes: 2756
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(v) v.begin(), v.end()
#define revall(v) v.rbegin(), v.rend()
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) return true; return false; }
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true; } return false; }






int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,m;cin >> n >> m;
	ll ans = min(n, m / 2);
	m -= ans * 2;
	ans += m / 4;
	cout << ans << endl;
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n;
  cin >> n;
  if(n == 1) cout << "Hello World" << endl;
  else {
    int a, b;cin >> a >> b;
    cout << a+b << endl;
  }
}

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

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

#define PI 3.14159265358979323846
#define N 100000
#define MOD 1000000007

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	set<int> si;
	int a;
	for (int i = 0; i < 3; ++i)
	{
		cin >> a;
		si.insert(a);
	}

	if (si.size() == 2)
		cout << "Yes\n";
	else
		cout << "No\n";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int IOIOI(string str, string target) {
  int cnt = 0;
  int idx = 0;
  while((idx = (int)str.find(target, idx)) >= 0) {
	idx++;
	cnt++;
  }
  return cnt;
}

int main() {
  int n, m;
  string t, str;
  while(cin >> n, n) {
	cin >> m; // not use
	cin.ignore();
	getline(cin, str);
	t = "IOI";
	while(n-- > 1) {
	  t += "OI";
	}
	cout << IOIOI(str, t) << endl;
  }
  return 0;
}

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

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


Measured memory_bytes: 3620
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int d = sc.nextInt();
    if(a+1==c && d==1){
      System.out.println('1');
    } else {
      System.out.println('0');
    }
  }
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll maxn=2e5+1;
void solve()
{
	ll n;
	cin>>n;
	set<string> f;
	for(ll i=0;i<n;i++)
	{
		string s;
		cin>>s;
		f.insert(s);
	}
	ll ans=f.size();
	cout<<ans<<"\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll T=1,p=0;
	//cin>>T;
	do
	{
		solve();
		p++;
	}while(p<T);
	return 0;
}



Measured memory_bytes: 19144
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MAXN 200010
#define LL long long
using namespace std;

namespace Fenwick{
	int c[MAXN];

	void add(int x,int v){
		while(x<MAXN){
			c[x]+=v;
			x+=x&(-x);
		}
	}

	int sum(int x){
		int res=0;
		while(x){
			res+=c[x];
			x-=x&(-x);
		}
		return res;
	}
}

struct edge{
	int to,next;
	edge(int _to=0,int _next=0):to(_to),next(_next){}
}e[MAXN<<1];

int n;
int g[MAXN],nume,deg[MAXN];
int pre[MAXN],w[MAXN][2],numw;
int d[MAXN],d2[MAXN],d3[MAXN],d4[MAXN];
char type[MAXN];
LL ans;

void addEdge(int u,int v){
	e[nume]=edge(v,g[u]);
	g[u]=nume++;
}

void dfs(int x,int p){
	w[x][0]=++numw;
	d[x]=0;
	d3[x]=n+1;
	pre[x]=p;
	for(int i=g[x];~i;i=e[i].next)
		if(e[i].to^p){
			dfs(e[i].to,x);
			d[x]=max(d[x],d[e[i].to]+1);
			d3[x]=min(d3[x],d3[e[i].to]+1);
		}
	if(d3[x]==n+1) d3[x]=0;
	w[x][1]=numw;
}

void dfs2(int x,int p){
	pair<int,int> td1(-1,0),td2(-1,0);
	pair<int,int> td3(n+1,0),td4(n+1,0);
	if(p) td3=td1=make_pair(d2[x],0);
	else d4[x]=n+1;
	for(int i=g[x];~i;i=e[i].next)
		if(e[i].to^p){
			pair<int,int> temp=make_pair(d[e[i].to],e[i].to);
			if(temp>td1) td2=td1,td1=temp;
			else if(temp>td2) td2=temp;
			if(temp<td3) td4=td3,td3=temp;
			else if(temp<td4) td4=temp;
		}
	for(int i=g[x];~i;i=e[i].next)
		if(e[i].to^p){
			if(e[i].to==td1.second) d2[e[i].to]=td2.first+1;
			else d2[e[i].to]=td1.first+1;
			if(e[i].to!=td3.second) d4[e[i].to]=td3.first+1;
			else if(td4.first!=n+1) d4[e[i].to]=td4.first+1;
			else d4[e[i].to]=0;
			dfs2(e[i].to,x);
		}
}

void gao(int x){
	static pair<int,int> b[MAXN];
	int numb=0;
	for(int i=g[x];~i;i=e[i].next)
		if(e[i].to^pre[x])
			b[++numb]=make_pair(d[e[i].to]+1,Fenwick::sum(w[e[i].to][1])-Fenwick::sum(w[e[i].to][0]-1));
	if(pre[x])
		b[++numb]=make_pair(d2[x]+1,Fenwick::sum(n)-Fenwick::sum(w[x][1])+Fenwick::sum(w[x][0]-1));
	sort(b+1,b+numb+1);
	bool flag=(type[x]=='1');
	for(int i=0;i<numb;i++){
		if(b[i].second) flag=1;
		if(!flag) continue;
		if(i<numb-1) ans+=b[i+1].first-b[i].first;
		else{
			int t0=b[i].first;
			int t1=min(b[i+1].first-1,b[i].first+1);
			if(t0<=t1) ans+=t1-t0+1;
		}
	}
}

int main(){
#ifdef DEBUG
	freopen("F.in","r",stdin);
#endif
	memset(g,-1,sizeof g);
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		addEdge(u,v);
		addEdge(v,u);
		deg[u]++; deg[v]++;
	}
	scanf("%s",type+1);
	dfs(1,0);
	dfs2(1,0);
	ans++;
	for(int i=1;i<=n;i++) 
		if(type[i]=='1'){
			Fenwick::add(w[i][0],1);
			//if(deg[i]>1) ans+=min(d3[i],d4[i]+1);
			//else ans++;
		}
	for(int i=1;i<=n;i++) 
		gao(i);
	printf("%lld\n",ans);
	return 0;
}



Measured memory_bytes: 26752
#include<iostream>
#define D(x) cout<<"D:"<<#x<<'='<<x<<endl;
using namespace std;
typedef long long ll;
int main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int T;
	cin>>T;
	while(T--)
	{
		int k;
		cin>>k;
		if(!(k%2) && k%3 && k%5)
		{
			puts("DENIED");
			return 0;
		}
	}
	puts("APPROVED");
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextInt();
		long k = sc.nextInt();
		long ret = 1;
		for (long i = 0; i < n; i++) {
			if (i == 0) {
				ret *= k;
			} else {
				ret *= k - 1;
			}
		}
		System.out.println(ret);
	}

}

Measured memory_bytes: 23124
<?php
  list($n,$x) = explode(" ", trim(fgets(STDIN)));
  $m=[];
  for($i=0;$i<$n;$i++){
    list($m[]) = explode(" ", trim(fgets(STDIN)));
  }
  $all = array_sum($m);

  echo $n+intdiv($x-$all, min($m));

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


def solve(a: int, b: int, x: int):
    if a % x == 0:
        print(int((b - a) // x + 1))
        return
    next = (x - a % x) + a
    if next > b:
        print(0)
        return
    v = (b - next) // x
    print(v + 1)
    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
    x = int(next(tokens))  # type: int
    solve(a, b, x)

if __name__ == '__main__':
    main()


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

typedef long long ll;

#define rep(var,n) for(int var=0;var<(n);++var)
#define all(a) (a.begin()),(a.end())

int main(){
  int a[3];
  cin >> a[0] >> a[1] >> a[2];

  int c[2]={0,0};
  rep(i,3){
    if(a[i]==5) c[0]++;
    if(a[i]==7) c[1]++;
  }
  if(c[0]==2&&c[1]==1) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

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

	string S;
	cin >> S;

	int ans = 0;
	rep(i, 6) if(S[i] == '1') ans++;
	cout << ans << endl;
}


Measured memory_bytes: 256
def solve():
    dists_y = [abs(y-a) for a in range(0,n+1)]
    dists_x = [abs(x-a) for a in range(0,n+1)]
    count_dists = [0]*(n+1)
    for a in range(1,n+1):
        for b in range(1,a+1):
            dis = min(abs(b-a), dists_x[a] + dists_y[b] + 1, dists_y[a] + dists_x[b] + 1)
            count_dists[dis] += 1
    #print(min_dists)
    for j in range(1,n):
        print(count_dists[j])





#
# def ceildiv(a, b):
#     return a // b + a % b



n, x, y = [int(i) for i in input().split(" ")]

# import time
# t = time.time()
#n, x, y = 2000, 200, 600
solve()
#print(time.time()- t)

Measured memory_bytes: 43120
#include<iostream>
#include<vector>
#include<math.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using namespace std;

int main()
{
    ll n, d, ans = 0;
    cin >> n >> d;
    rep(i,n){
        ll b, c;
        cin >> b >> c;
        if(sqrt(b * b + c * c) <= d) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3676
/**
 *  author: Haunted_Cpp
**/
 
#include <bits/stdc++.h>
using namespace std;
 
#pragma GCC optimize("Ofast")
#pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
 
template<typename T> ostream &operator << (ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream &operator << (ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream &operator << (ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
 
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }
 
#ifdef LOCAL
#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#else
#define debug(...) 47
#endif

int main() {
  
  ios::sync_with_stdio(0);
  cin.tie(0); 
  int n;
  cin >> n;
  vector<int> arr(n);
  for (int i = 0; i < n; i++) cin >> arr[i];
  priority_queue<tuple<int, int, int>> pq;
  sort(arr.rbegin(), arr.rend());
  long long res = arr[0];
  auto inserir = [&](int a, int b) {
    pq.push({make_tuple(min(a, b), a, b)});
  };
  inserir(arr[0], arr[1]);
  inserir(arr[0], arr[1]);
  for (int i = 2; i < n; i++) {
    tuple<int, int, int> best_way = pq.top();
    pq.pop();
    res += get<0>(best_way);
    const int L = get<1>(best_way);
    const int R = get<2>(best_way);
    inserir(arr[i], L);
    inserir(arr[i], R);
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 7180
//Utkarsh.25dec
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// ordered_set s ; s.order_of_key(val)  no. of elements strictly less than val
// s.find_by_order(i)  itertor to ith element (0 indexed)
typedef vector<vector<ll>> matrix;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=500023;
bool vis[N];
vector <int> adj[N];
void solve()
{
    ll n;
    cin>>n;
    n%=1000;
    n=1000-n;
    n%=1000;
    cout<<n;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T=1;
    //cin>>T;
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

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

char ans [4000][4000];
int dp[4000][4000];
pair <int ,int > par[4000][4000];
vector <char> vec;







void find (int a , int b){
	if (a == 0 or b == 0)
		return ;
	if(ans[a][b]!= '0')
		vec.push_back(ans[a][b]);
	
	find (par[a][b].first , par[a][b].second );
}
int main(){
	string s,t;
	cin>>s>>t;
	int ss = s.size(), ts = t.size(); 
	for(int i=1;i<=ss;i++){
		for (int j =1;j<=ts;j++){
			if (dp[i][j-1]>dp[i-1][j]){
				dp[i][j]= dp[i][j-1];
				par[i][j]={i,j-1};
				ans[i][j]='0';
			}
			else {
				dp[i][j]= dp[i-1][j];
				ans[i][j]='0';
				par[i][j]={i-1,j};
			}
			if (s[i-1]==t[j-1] and dp[i][j]<dp[i-1][j-1]+1){
				dp[i][j]= dp[i-1][j-1]+1;
				ans[i][j]=s[i-1];
				par[i][j] = {i-1,j-1};
			}
		}
	}

	find(ss,ts);
	reverse (vec.begin(), vec.end () );
	for (int i =0;i<vec.size();i++){
		
			cout<<( vec[i]);
	}
}

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

#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++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


void solve(std::string S){
    int cnt = 0;
    int idx2 = S.size()-1;
    REP(idx, S.size()) {
        if (S[idx] != S[idx2] ) cnt++;
        idx2--;
    }

    cout << (cnt/2) << endl;
}

int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
    char s[11],t[11],u[11];
    scanf("%s%s",s,t);
    int a,b;
    scanf("%d%d",&a,&b);
    scanf("%s",u);
    for(int i=0;i<10;i++){
        if(s[i]!=u[i]){
            printf("%d %d ",a,b-1);
            break;
        }
        if(t[i]!=u[i]){
            printf("%d %d ",a-1,b);
            break;
        }
    }
    return 0;
}

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

typedef pair<int, int> pii;

int N;
vector<int> arr;
vector<pii> tmp;

vector<vector<int> > cc;
int dp(int idx, int t) {
    int &ret = cc[idx][t];
    if(ret != -1) return ret;

    if(idx == N - 1) return ret = tmp[idx].first + tmp[idx].second;

    ret = 1e9;
    if(tmp[idx].second && t) {
        ret = min(ret, tmp[idx].first + tmp[idx].second - min(tmp[idx].first + tmp[idx].second, tmp[idx + 1].first + tmp[idx + 1].second) + dp(idx + 1, 0));
        ret = min(ret, tmp[idx].first + tmp[idx].second - min(tmp[idx].first + tmp[idx].second, tmp[idx + 1].first) + dp(idx + 1, 1));
    }
    else {
        ret = min(ret, tmp[idx].first + tmp[idx].second - min(tmp[idx].first, tmp[idx + 1].first + tmp[idx + 1].second) + dp(idx + 1, 0));
        ret = min(ret, tmp[idx].first + tmp[idx].second - min(tmp[idx].first, tmp[idx + 1].first) + dp(idx + 1, 1));
    }
    return ret;
}

int main() {
    scanf("%d", &N);
    arr.resize(N);
    for(int i = 0; i < N; i++) {
        scanf("%d", &arr[i]);
    }

    tmp.resize(N);
    for(int i = 0; i < N; i++) {
        int p = 1;
        for(int j = 0;; j++) {
            if(arr[i] < p) {
                tmp[i] = pii(j - 1, (arr[i] != p / 2));
                break;
            }
            p *= 2;
        }
    }

    cc = vector<vector<int> >(N, vector<int>(2, -1));
    printf("%d", dp(0, 1));
}


Measured memory_bytes: 11520