akhauriyash/Code-Regression huggingface dataset:
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1

//{
/*#pragma GCC optimize ("O3","unroll-loops")
#pragma GCC target ("avx")*/
#include<bits/stdc++.h>
using namespace std;
#define hi cerr<<"hi"<<endl;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1
#define sysp system("pause")
#define PI acos(-1)
#define ins insert
#define aer(v) (v).erase((v).begin(),(v).end()) 

//{
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();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

//}

int n,ans;
string a,b,c;

main(){
	cin>>n>>a>>b>>c;
	rep(i,n){
		if(a[i]==b[i]||a[i]==c[i]||b[i]==c[i]){
			if(a[i]==b[i]&&a[i]==c[i]&&b[i]==c[i])continue;
			else ans++;
		}else ans+=2;
	}
	dans;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int c = 0, pen = 0;
    int[] r = new int[n + 1];
    for(int i = 0; i < m; i++){
      int p = sc.nextInt();
      if(sc.next().equals("WA")){
        if(r[p] >= 0)r[p]++;
      }else{
        if(r[p] >= 0){
          pen += r[p];
          c++;
          r[p] = -1;
        }
      }
    }
    System.out.println(c+" "+pen);
  }
}

Measured memory_bytes: 65684
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;


int main(){
  int n, m;
  cin >> n >> m;
  int a[n][m];
  
  for(int i=0; i<n; i++){
    int k;
    cin >> k;
    for(int j=0; j<k; j++){
      cin >> a[i][j];
    }
    for(int j=k; j<m; j++){
      a[i][j] = 0;
    }
  }
  
  int ans =0;
  for(int j=0; j<m; j++){
    if(a[0][j] == 0) break;
    int count=0;
    for(int i=0; i<n; i++){
      for(int k=0; k<m; k++){
        if(a[0][j] == a[i][k]) count++;
        
      }
    }
    if(count == n) ans++;
  }
  cout << ans <<endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
a_list = list(map(int, input().split()))

ret = 0
my_dict = dict()

for i in range(1, len(a_list)):
    diff = a_list[i] + a_list[0] - i
    if diff in my_dict:
        my_dict[diff].append(i)
    else:
        my_dict[diff] = [i]
    if diff == 0:
        ret += 1

for i in range(1, len(a_list)):
    diff = a_list[i] - a_list[0] + i
    if (-diff) in my_dict:
        tmp_list = my_dict[-diff]
        while len(tmp_list) >= 1:
            if tmp_list[0] <= i:
                tmp_list.pop(0)
            else:
                break
        ret += len(tmp_list)

print(ret)


Measured memory_bytes: 60744
N,M=list(map(int,input().strip().split(' ')))
graph=[[]  for i in range(N+1)]
for _ in range(M):
    a,b,c=list(map(int,input().strip().split(' ')))
    graph[a]+=[b]
    graph[b]+=[a]

checked={}
def dfs(root):
    connected=[]
    stack=[]
    stack+=[root]
    parent={}
    parent[root]=-1
    checked[root]=1
    while stack:
        v=stack.pop()
        for node in graph[v]:
            if node!=parent[v] and node not in checked:
                checked[node]=1
                parent[node]=v
                stack+=[node]
    return stack
count=0
for i in range(1,N+1):
    if i not in checked:
        dfs(i)
        count+=1
print(count)            



                





Measured memory_bytes: 87328
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
#define uni(q) unique(all(q)),q.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

int N, dat[800005], data[800005];

void initmn( int n_ )
{
    N = 1;
    while( N < n_ )
        N <<= 1;
 
    for(int i=0; i < 2*N-1; i++)
        dat[i] = INF;
 
    return;
}

void initmx( int n_ )
{
    N = 1;
    while( N < n_ )
        N <<= 1;
 
    for(int i=0; i < 2*N-1; i++)
        data[i] = 0;
 
    return;
}
 

void updatemn(int k, int a){
    k += N - 1;
    dat[k] = a;
    while(k > 0){
        k = ( k - 1 ) / 2;
        dat[k] = min(dat[ k * 2 + 1 ], dat[ k * 2 + 2 ]);
    }
    return;
}

void updatemx(int k, int a){
    k += N - 1;
    data[k] = a;
    while(k > 0){
        k = ( k - 1 ) / 2;
        data[k] = max(data[ k * 2 + 1 ], data[ k * 2 + 2 ]);
    }
    return;
}


int querymn(int a, int b, int k, int l, int r){
    if( r <= a || b <= l ){
        return INF;
    }
    if( a <= l && r <= b ){
        return dat[k];
    }else{
        int vl = querymn(a, b, k * 2 + 1, l, (l + r) / 2);
        int vr = querymn(a, b, k * 2 + 2, (l + r) / 2, r);
        return min(vl, vr);
    }
}

int querymx(int a, int b, int k, int l, int r){
    if( r <= a || b <= l ){
        return 0;
    }
    if( a <= l && r <= b ){
        return data[k];
    }else{
        int vl = querymx(a, b, k * 2 + 1, l, (l + r) / 2);
        int vr = querymx(a, b, k * 2 + 2, (l + r) / 2, r);
        return max(vl, vr);
    }
}



int main(){
    ll n,k; cin >> n >> k;
    vl p(n);
    rep(i,n) cin >> p[i];
    initmn(n);
    initmx(n);
    rep(i,n){
        updatemn(i,p[i]);
        updatemx(i,p[i]);
    }
    ll ans = n-k+1;
    REP(i,1,n-k+1){
        //cout << querymn(i,i+k-1,0,0,N) << endl;
        //cout << querymx(i,i+k-1,0,0,N) << endl;
        if(p[i-1]<querymn(i,i+k-1,0,0,N) && p[i+k-1]>querymx(i,i+k-1,0,0,N)){
            ans--;
        }
        //cout << p[i+k-1] << endl;
    }
    ll sorted = 1;
    ll sortedcnt = 0;
    REP(i,1,n){
        if(p[i-1]<p[i]){
            if(sorted >= k-1){
                if(p[i-k]>p[i-k+1])sortedcnt++;
            }
            sorted++;
        }else{
            sorted = 1;
        }
    }
    //cout << sortedcnt << endl;
    ans = ans - max(sortedcnt - 1,0LL);
    cout << ans << endl;
}


Measured memory_bytes: 7936
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(string s) {LL 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;}

//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) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

LL n,m;
LL cnt = 0;
LL visited[200000] = {0};
vector<VL> link(200000);

void dfs(LL node){
    if(visited[node])return;
    visited[node] = 1;
    cnt++;
    for(LL adj : link[node]){
        dfs(adj);
    }
}
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n>>m;
    REP(i,m){
        LL a,b;
        cin>>a>>b;
        a--;
        b--;
        link[a].PB(b);
        link[b].PB(a);
    }

    LL ans = 0;
    REP(i,n){
        cnt = 0;
        dfs(i);
        ans = max(ans, cnt);
    }
    PUTS(ans);
}

Measured memory_bytes: 21916
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;

struct NODE{
	int a,b,c;
	NODE(int x,int y,int z){ a = x , b = y , c = z;}
	NODE(){}
};

#define INF (1<<21)
NODE Q[1<<20];

int n,U , unit[20];
char done[1<<20];
int main(){
	while(cin >> n >> U , n){
		
		int graph[21] = {0};
		memset(done,0,sizeof(done));
		for(int i = 0 ; i < n ; i++){
			int k;
			cin >> unit[i] >> k;
			for(int j = 0 ; j < k ; j++){
				int a; cin >> a;
				graph[i] |= (1<<a);
			}
		}
		int h = 0;
		int qsize = 0;
		Q[qsize++] = NODE(0,0,0);
		done[0] = 1;
		while(h != qsize){
			NODE q = Q[h++];
			if(q.b >= U){cout << q.c << endl; break;} 
			for(int i = 0 ; i < n ; i++){
				if( !(q.a >> i & 1) && (q.a & graph[i]) == graph[i])
					if(!done[q.a | (1<<i)])Q[qsize++] = (NODE( q.a | (1<<i) , q.b + unit[i] , q.c+1)) , done[q.a|(1<<i)] = true;
			}
		}
		
	}
}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) {
  cout << (expr ? "Yes" : "No") << "\n";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    lint N;
    cin >> N;
    vector<lint> A(N);
    REP(i, N) cin >> A[i];
    lint xo = 0;
    FOR(i, 2, N) xo ^= A[i];
    lint an = A[0] + A[1] - xo;
    if(an < 0 || an%2 != 0) {
        cout << -1 << endl;
        return 0;
    }
    an /= 2;
    lint ans = 0;
    lint tmp = 0;
    IREP(k, 50) {
        if((xo>>k&1) == 0) {
            if((an>>k&1) == 1) ans += 1LL<<k;
        } else {
            if((an>>k&1) == 0) tmp += 1LL<<k;
            else {
                cout << -1 << endl;
                return 0;
            }
        }
    }
    IREP(k, 50) {
        if((tmp>>k&1) == 1 && (ans + (1LL<<k)) <= A[0]) ans += 1LL<<k;
    }
    if(ans > A[0] || ans == 0) {
        cout << -1 << endl;
        return 0;
    }
    cout << A[0] - ans << endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define maxn 250005
#define ll long long
#define mod 1000000007

typedef pair<int, int> P;

int n, m;
vector<P> v[maxn];
bitset<55> b[25];
vector<int> path;

bool dfs(int now, int t, int pa)
{
    if (now == t)
        return 1;
    for (P p : v[now])
    {
        if (p.first == pa)
            continue;
        if (dfs(p.first, t, now))
        {
            path.push_back(p.second);
            return 1;
        }
    }
    return 0;
}

int main()
{
    cin >> n;
    for (int i = 0; i < n - 1; i++)
    {
        int x, y;
        scanf("%d%d", &x, &y);
        x--, y--;
        v[x].push_back(P(y, i));
        v[y].push_back(P(x, i));
    }
    cin >> m;
    for (int i = 0; i < m; i++)
    {
        int x, y;
        scanf("%d%d", &x, &y);
        x--, y--;
        path.clear();
        dfs(x, y, x);
        for (int z : path)
        {
            b[i][z] = 1;
            //printf("z=%d\n", z);
        }
    }
    ll ans = 1ll << (n - 1);
    for (int S = 1; S < (1 << m); S++)
    {
        bitset<55> x = S;
        bitset<55> bb;
        for (int i = 0; i < m; i++)
        {
            if (S >> i & 1)
                bb |= b[i];
        }
        int cnt = n - 1 - bb.count();
        //printf("cnt=%d\n", cnt);
        if (x.count() & 1)
            ans -= (1ll << cnt);
        else
            ans += (1ll << cnt);
    }
    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 6144
n = input()
digit = len(n)
n = int(n)
ans = (digit - 1) * 9 + n // (10 ** (digit - 1)) - 1
tmp = n - n // (10 ** (digit - 1)) * (10 ** (digit - 1))
if tmp == (10 ** (digit - 1)) - 1:
    ans += 1
print(ans)

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    string s, t;
    cin >> s >> t;
    OP(t + s);
    return 0;
}

Measured memory_bytes: 256
#![allow(unused)]

//入力マクロここから
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
//入力マクロここまで

//input
//use std::io::Read;

//collections
//use std::collections::BTreeMap;
//use std::collections::BTreeSet;
//use std::collections::HashMap;
//use std::collections::HashSet;

fn main() {
    input! {
        n: usize,
        s: chars,
    }

    let mut cnt = 0;

    for i in 2..n {
        if s[i - 2] == 'A' && s[i - 1] == 'B' && s[i] == 'C' {
            cnt += 1;
        }
    }

    println!("{}", cnt);
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

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

const int MOD = 2019;
class mint {
public:
    ll x;
    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 *(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;
    }

    friend ostream &operator<<(ostream& os, const mint &m) {
        os << m.x;
        return os;
    }
};


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

    string S;
    cin >> S;
    ll N = S.size();
    
    vector<mint> num(N+1, 0);

    for (ll i = N-1; i >= 0; i--) {
        num[i] = num[i+1] + mint(10).pow(N-1-i) * mint(S[i]-'0');
    }

    // Rep (i, N+1) {
    //     cout << num[i] << " \n"[i==N];
    // }

    vec packet(2019, 0);
    Rep (i, N+1) {
        packet[num[i].x]++;
    }

    ll ans = 0;
    Rep (i, 2019) {
        ans += packet[i] * (packet[i]-1) / 2;
    }

    cout << ans << endl;
}

Measured memory_bytes: 5160
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in Actual solution is at the top
 *
 * @author Silviase
 */
public class Main {

  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    Scanner in = new Scanner(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    KEYENCE2020C solver = new KEYENCE2020C();
    solver.solve(1, in, out);
    out.close();
  }

  static class KEYENCE2020C {

    public void solve(int testNumber, Scanner in, PrintWriter out) {
      int n = in.nextInt();
      int k = in.nextInt();
      int s = in.nextInt();
      int[] ar = new int[n];
      StringBuilder sb = new StringBuilder();
      if (s == 1000000000) {
        for (int i = 0; i < n; i++) {
          if (i < k) {
            ar[i] = s;
          } else {
            ar[i] = s - 1;
          }
        }
      } else {
        for (int i = 0; i < n; i++) {
          if (i < k) {
            ar[i] = s;
          } else {
            ar[i] = s + 1;
          }
        }
      }

      for (int i = 0; i < n; i++) {
        sb.append(ar[i]);
        sb.append(" ");
      }
      out.println(new String(sb));

    }

  }
}



Measured memory_bytes: 32644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// Welcome to my source code!

int main() {
    int n, k;
    cin >> n >> k;
    double ans = 0;
    for (int i = 1; i <= n; i++) {
        ll t = i;
        double p = 1.0 / n;
        while (t < k) {
            t *= 2;
            p /= 2;
        }
        ans += p;
    }
    printf("%.12f\n", ans);
}

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

ll solve(ll ai, ll aj, ll bi, ll bj) {
  if (aj > bj) {
    swap(ai,bi);
    swap(aj,bj);
  }
  ll s = 1;
  rep(i,30) s *= 3;
  ll dist = abs(ai-bi) + abs(aj-bj);
  ll res = dist;
  while (1) {
    s /= 3;
    if (s <= 0) break;
    ll nai = ai/s, nbi = bi/s;
    if (nai != nbi) break;
    ll naj = aj/s, nbj = bj/s;
    if (nai%3 == 1 && abs(naj-nbj) > 1) {
      ll up = s*nai-1;
      ll bot = nai*s + s;
      ll loss = min(ai,bi) - up;
      loss = min(loss, bot - max(ai,bi));
      res += loss*2;
      break;
    }
  }
  return res;
}

int main() {
  int q;
  cin >> q;
  rep(qi,q) {
    ll ai,aj,bi,bj;
    cin >> ai >> aj >> bi >> bj;
    ai--; aj--; bi--; bj--;
    ll ans1 = solve(ai,aj,bi,bj);
    ll ans2 = solve(aj,ai,bj,bi);
    cout << max(ans1, ans2) << endl;
  }
  return 0;
}


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

int main() {
  int N;
  cin >> N;
  int c = 0;
  for (int i = 0; i < N; i++){
    int a,b;
    cin >> a >> b;
    c +=(b-a+1);
  }
cout << c << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
//#include <iostream>
//#include <iomanip>
//#include <vector>
//#include <cmath>
//#include <algorithm>
using namespace std;


#define F first
#define PB push_back
#define MP make_pair

typedef long long ll;

ll p = pow(10, 9) + 7;
int siz = pow(10, 9);



int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, l;
    cin >> n >> l;
    vector<string> val(n);
    for(int i = 0; i < n; i++)
    {
        cin >> val[i];
    }
    sort(val.begin(), val.end());
    string ans = "";
    for(int i = 0; i < n; i++)
    {
        ans += val[i];
    }
    cout<< ans << endl;



}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
using namespace std;
#define ll long long

int main() {
	string S; cin >> S;
	vector<string> t;
	int i=0;
	string now="";
	while(i<S.size()){
	    bool flag=false;
	    if(S[i]=='A'){
	        now += "A";
	        flag=true;
	    }
	    if(S[i]=='B'){
	        if(i+1<S.size()){
	            if(S[i+1]=='C'){
	                now += "D";
	                ++i;
	                flag=true;
	            }
	        }
	    }
	    if(!flag){
	        t.push_back(now);
	        now="";
	    }
	    ++i;
	}
	if(now.size()>0) t.push_back(now);
	ll ans=0;
	for(int g=0; g<t.size(); ++g){
	    int cnt=0;
	    for(int m=0; m<t[g].size(); ++m){
	        if(t[g][m]=='D'){
	            ans += m-cnt;
	            ++cnt;
	        }
	    }
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5368
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>
#include <cmath>
#include <stack>
#include <random>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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;
using ll = long long;
using P = pair<ll, ll>;

constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

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

  string s; cin >> s;
  int d; cin >> d;

  vector<vector<ll>> dp1(2, vector<ll>(d));
  vector<vector<ll>> dp2(2, vector<ll>(d));
  dp1[0][0] = 1;

  rep(i, s.size()) {
    int a = s[i] - '0';
    for(int j=0; j<a; j++) {
      rep(k, d) {
        dp2[1][(k+j)%d] += dp1[0][k];
        dp2[1][(k+j)%d] %= mod;
      }
    }
    rep(k, d) {
      dp2[0][(k+a)%d] += dp1[0][k];
    }
    rep(j, 10) {
      rep(k, d) {
        int r = (k+j)%d;
        dp2[1][r] += dp1[1][k];
        dp2[1][r] %= mod;
      }
    }
    rep(k, d) {
      dp1[0][k] = dp2[0][k];
      dp2[0][k] = 0;
      dp1[1][k] = dp2[1][k];
      dp2[1][k] = 0;
    }
  }

  ll ans = dp1[0][0] + dp1[1][0] + mod - 1;
  ans %= mod;

  cout << ans << endl;
}


Measured memory_bytes: 256
#[macro_use]
mod input {

use std;
use std::io;

const SPLIT_DELIMITER: char = ' ';

#[macro_export]
#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
pub fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
pub fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}

#[allow(dead_code)]
pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
{
    let mut v: Vec<Vec<T>> = Vec::new();

    for _ in 0..line {
        let vec_line = input_vector();
        v.push(vec_line);
    }
    v
}

#[allow(dead_code)]
pub fn input_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
{
    let mut v: Vec<T> = Vec::new();

    let s = input_line_str();
    let split_result = s.split(SPLIT_DELIMITER);
    for z in split_result {
        let buf = match z.parse() {
            Ok(r) => r,
            Err(_) => panic!("Parse Error"),
        };
        v.push(buf);
    }
    v
}

#[allow(dead_code)]
pub fn str2vec(s: &str) -> Vec<char> {
    let mut v: Vec<char> = Vec::new();
    for c in s.chars() {
        v.push(c);
    }
    v
}

}

use input::*;

fn get_dist(a: (isize, isize), b: (isize, isize)) -> usize {
    ((a.0 - b.0).abs() + (a.1 - b.1).abs()) as usize
}

fn main() {
    let (n, m): (usize, usize);
    input!(n, m);
    let mut st = Vec::new();
    let mut ch = Vec::new();

    for _ in 0..n {
        let (a, b): (isize, isize);
        input!(a, b);
        st.push((a, b));
    }
    for _ in 0..m {
        let (c, d): (isize, isize);
        input!(c, d);
        ch.push((c, d));
    }

    for s in &st {
        let mut short_point = (999999999, 0);
        for (i, c) in ch.iter().enumerate() {
            let buf = get_dist(*s, *c);
            if short_point.0 > buf {
                short_point = (buf, i);
            }
        }
        p(short_point.1 + 1);
    }
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main () {
  ll n; cin>>n;
  ll dp[n][3];
  cin>>dp[0][0]>>dp[0][1]>>dp[0][2];
  for (ll i=1;i<n;++i) {
    ll a, b, c; cin>>a>>b>>c;
    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]);
  }
  cout<<max({dp[n-1][0], dp[n-1][1], dp[n-1][2]});
  return 0;
}

Measured memory_bytes: 2560
n,x = map(int, input().split())
l=list(map(int, input().split()))
dic = {}
dic[0] = 0
dic[1] = l[0]
for i in range(n-1):
    dic[i+2] = l[i+1]+dic[i+1]
res = list(filter(lambda a:a<=x,list(dic.values())))
print(len(res))

Measured memory_bytes: 3064
#5 保留
N, A, B = map(int, input().split())
sum = 0
ans = 0
for i in range(1, N+1):
    for k in range(len(str(i))):
        i = str(i)
        sum += int(i[k])
    if A<=sum<=B:
        ans += int(i)
    sum = 0
print(ans)

Measured memory_bytes: 3060
#include <stdio.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    int n, i, j, k, x[4][13], a;
    char ch;
    scanf("%d", &n);
    for (i=0; i<4; i++) {
        for (j=1; j<+13; j++) {
            x[i][j]=0;
        }
    }
    for (k=0; k<n; k++) {
        scanf("%c", &ch);
        scanf("%c %d", &ch, &a);
        if (ch=='S') {
            x[0][a]=1;
        }else if(ch=='H'){
            x[1][a]=1;
        }else if(ch=='C'){
            x[2][a]=1;
        }else if(ch=='D'){
            x[3][a]=1;
        }
    }
    for (i=0; i<4; i++) {
        for (j=1; j<=13; j++) {
            if (x[i][j]!=1) {
                if (i==0) {
                    printf("S %d\n", j);
                }else if(i==1){
                    printf("H %d\n", j);
                }else if(i==2){
                    printf("C %d\n", j);
                }else if(i==3){
                    printf("D %d\n", j);
                }
            }
        }
    }
    return 0;
}



Measured memory_bytes: 2112
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define speedX ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cout<< name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_time() cout << "\n\nTime of execution: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define trace(...)
#define end_time()
#endif


#define int long long 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
inline bool equals(ld a, ld b) {return fabs(a - b) < 1e-9;}
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define uset unordered_set
#define umap unordered_map
#define all(x) x.begin(), x.end()
#define mod 1000000007


void solve(){
	int n;
	cin>>n;
	vector<pii> v;
	for(int i = 1; i<=n; i++){
		int a;
		cin>>a;
		v.pb(mp(a,i));
	}
	sort(all(v));
	for(int i = 0; i<n; i++){
		cout<<v[i].ss<<" ";
	}
}
signed main(){
	speedX;
	#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	end_time();
	return 0;
}

Measured memory_bytes: 2544
n=input()
k=int(input())

len_n=len(n)
dp0=[[0]*(k+1) for _ in range(len_n+1)]
dp1=[[0]*(k+1) for _ in range(len_n+1)]
dp0[0][0]=1
# dp0: N以下であることが未確定
# dp1: N以下であることが確定
for i, n_i in enumerate(n):
    for k_i in range(k+1):
        if n_i=='0':
            dp0[i+1][k_i]+=dp0[i][k_i]
            dp1[i+1][k_i]+=dp1[i][k_i]
            if k_i<k:
                dp1[i+1][k_i+1]+=9*dp1[i][k_i]
        else:
            if k_i<k:
                dp0[i+1][k_i+1]+=dp0[i][k_i]
                dp1[i+1][k_i+1]+=(int(n_i)-1)*dp0[i][k_i]
                dp1[i+1][k_i+1]+=9*dp1[i][k_i]
            dp1[i+1][k_i]+=dp0[i][k_i]
            dp1[i+1][k_i]+=dp1[i][k_i]

print(dp0[-1][k]+dp1[-1][k])


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

int main() {
  int N, D;
  cin >> N >> D;
  vector<vector<int>> X(N, vector<int>(D));
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < D; ++j) {
      cin >> X[i][j];
    }
  }
  
  int ans = 0;
  for (int i = 0; i < N; ++i) {
    for (int j = i + 1; j < N; ++j) {
      int norm = 0;
      for (int k = 0; k < D; ++k) {
        int diff = abs(X[i][k] - X[j][k]);
        norm += diff * diff;
      }
      bool flag = false;
      for (int k = 0; k <= norm; ++k) {
        if (k * k == norm) {
          flag = true;
        }
      }
      if (flag) ++ans;
    }
  }
  
  cout << ans << endl;
}


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

int main(){

    string s;
    cin >> s;
    for(int i=0; i<s.length(); i++){
        if(s[i] == '1'){
            s[i] = '9';
        }else{
            s[i] = '1';
        }
    }

    cout << s << endl;

    return 0;
}

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

typedef long long ll;
const int INF = 1e9;
const ll INFF = 1e18;
const int MAXN = 510;
const int MOD = 1e9 + 7;

char s[15];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	for (int i = 1 ; i <= n ; i++)
		cin >> s[i];
	int k;
	cin >> k;
	for (int i = 1 ; i <= n ; i++) if (s[i] != s[k])
		s[i] = '*';
	for (int i = 1 ; i <= n ; i++)
		cout << s[i];
	cout << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
using namespace std;
typedef long long ll;
int main(){
  int n,a,b;
  cin>>n>>a>>b;
  cout<<min(a,b)<<" "<<max(a+b-n,0)<<endl;
}


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 lint;


int main() {
  int N; cin >> N;
  vector<double> A(N); rep(i,N)cin >> A.at(i);
  double bunsi = 1;
  rep(i,N)bunsi *= A.at(i);
  vector<double> B(N);
  double bunbo = 0
  rep(i,N){
    B.at(i) = bunsi / A.at(i);
    bunbo += B.at(i);
  }
  if(bunbo == 0)cout << 0 << endl;
  else printf("%.10f\n", bunsi / bunbo);
   
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
#N = int(input())
#S = str(input())
N, A, B = map(int, input().split())

maxN = min(A, B)
minN = max(A+B-N, 0)

print (str(maxN) + " " + str(minN))

Measured memory_bytes: 3444
object Main extends App {
  val inputs: Seq[String] = scala.io.Source.stdin.getLines().toList
  
  val n = inputs(0).toInt
  val s = inputs(1)

  println(solve(n, s))

  private def solve(n: Int, s: String): Int = {
    val seq = scala.collection.mutable.ArrayBuffer.fill(n+1)(0)
    (1 to n).foreach { i =>
      s(i-1) match {
        case 'I' =>
          seq.update(i, seq(i-1) + 1)
        case 'D' =>
          seq.update(i, seq(i-1) - 1)
        case _   => ()
      }
    }
    seq.max
  }

}

Measured memory_bytes: 58504
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll =  long long ;
using P = pair<int,int> ;
const int INF = 1e9;
const int MOD = 1000000007;

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> a(m);
    rep(i,m) cin >> a[i];
    ll sum = 0;
    rep(i,m) sum += a[i];
    if(sum <= n) cout << n - sum << endl;
    else cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAX 2000000
#define INFTY (1<<30)

int Htw ,Atw[MAX+1];

void swap(int *a, int*b){
    int tmp;
    tmp = *a;
    *a = *b;
    *b = tmp;
}

void maxHeapify(int i){
    int l,r,largest;
    l=2*i;
    r=2*i+1;


    if(l<=Htw && Atw[l]>Atw[i])largest = l;
    else largest = i;
    if(r<=Htw && Atw[r] > Atw[largest])largest = r;

    if(largest != i){
        swap(&Atw[i],&Atw[largest]);
        maxHeapify(largest);
    }
}

int extract(){
    int maxv;
    if(Htw<1)return -INFTY;
    maxv=Atw[1];
    Atw[1]=Atw[Htw--];
    maxHeapify(1);
    return maxv;
}

void increaseKey(int i,int key){
    if(key < Atw[i])return;
    Atw[i]=key;
    while (i>1&&Atw[i/2]<Atw[i]){
        swap(Atw[i],Atw[i/2]);
        i=i/2;
    }
}

void insert(int key){
    Htw++;
    Atw[Htw]=-INFTY;
    increaseKey(Htw,key);
}

int main(){
    int key;
    char comtw[10];

    while(1){
        scanf("%s",comtw);
        if(comtw[0]=='e'&&comtw[1]=='n')break;
        if(comtw[0]=='i'){
            scanf("%d",&key);
            insert(key);
        }else{
            printf("%d\n",extract());
        }
    }

    return 0;
}


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

using namespace std;

typedef long long ll;
const ll maxn = 200010,mod = 1e9 + 7;
ll n,a[maxn],b[maxn],f[4010][4010],c[4010][4010];
ll ni[maxn],nijie[maxn],jie[maxn],ans;

ll qpow(ll a,ll b)
{
    ll res = 1;
    while (b)
    {
        if (b & 1)
            res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}

ll C(ll n,ll m)
{
    return jie[n] * nijie[m] % mod * nijie[n - m] % mod;
}

int main()
{
    ni[0] = ni[1] = nijie[0] = nijie[1] = jie[0] = jie[1] = 1;
    for (ll i = 2; i <= 8001; i++)
    {
        jie[i] = jie[i - 1] * i % mod;
        ni[i] = (mod - mod / i) * ni[mod % i] % mod;
        nijie[i] = nijie[i - 1] * ni[i] % mod;
    }
    scanf("%lld",&n);
    for (ll i = 1; i <= n; i++)
    {
        scanf("%lld%lld",&a[i],&b[i]);
        f[2001 - a[i]][2001 - b[i]]++;
    }
    for (ll i = 1; i <= 4001; i++)
        for (ll j = 1; j <= 4001; j++)
            f[i][j] = (f[i][j] + f[i - 1][j] + f[i][j - 1]) % mod;
    for (ll i = 1; i <= n; i++)
        ans = (ans + f[a[i] + 2001][b[i] + 2001]) % mod;
    for (ll i = 1; i <= n; i++)
        ans = (ans - C(a[i] + a[i] + b[i] + b[i],a[i] + a[i]) + mod) % mod;
    ans = ans * qpow(2,mod - 2) % mod;
    printf("%lld\n",ans);

    return 0;
}


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

using namespace std;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)((x).size()))

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long long int64;
typedef unsigned int uint;
typedef unsigned long long uint64;

#define gi(x) ((x) = F())
#define gii(x, y) (gi(x), gi(y))
#define giii(x, y, z) (gii(x, y), gi(z))

int F()
{
	char ch;
	int x, a;
	while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-');
	if (ch == '-') ch = getchar(), a = -1;
	else a = 1;
	x = ch - '0';
	while (ch = getchar(), ch >= '0' && ch <= '9')
		x = (x << 1) + (x << 3) + ch - '0';
	return a * x;
}

long long n;

deque<int> l, r;

int tot;

void solve(long long n)
{
	if (n == 1) return;
	solve(n >> 1);
	l.push_front(++tot);
	r.push_front(tot);
	if (n & 1)
	{
		l.push_front(++tot);
		r.push_back(tot);
	}
}

int main()
{
	scanf("%lld", &n);
	solve(n + 1);
	printf("%d\n", l.size() + r.size());
	for (auto x : l) printf("%d ", x);
	for (auto x : r) printf("%d ", x);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<complex>
#include<queue>
#include<cmath>
#include<algorithm>
 
using namespace std;
 
typedef complex<double> P;
 
struct S{
  int w,p,n;
  double d;
  bool operator<(S s)const{
    return d>s.d;
  }
};
 
double dot(P a,P b){
  return (conj(a)*b).real();
}
 
int main(){
  int n;
  double r,th;
  cin>>n>>r>>th;
  P p[21];
  for(int i=1;i<=n;i++){
    int x,y;
    cin>>x>>y;
    p[i]=P(x,y);
  }
  double t[21][21][21];
  fill(t[0][0],t[21][0],-1);
  for(int i=0;i<=n;i++){
    for(int j=1;j<=n;j++){
      for(int k=1;k<=n;k++){
	auto f=p[j]-p[i];
	auto to=p[k]-p[j];
	if(j!=k&&(i==0||acos(min(1.,max(-1.,dot(f,to)/abs(f)/abs(to))))*90<=th*acos(0))){
	  t[i][j][k]=abs(to);
	}
      }
    }
  }
  priority_queue<S> que;
  que.push({1,0,0,0});
  static bool mem[21][21][22222];
  int m=0;
  while(!que.empty()){
    auto cs=que.top();
    if(cs.d>r)break;
    que.pop();
    if(mem[cs.w][cs.p][cs.n]++)continue;
    m=max(m,cs.n);
    for(int i=1;i<=n;i++){
      auto v=t[cs.p][cs.w][i];
      if(v<0)continue;
      que.push({i,cs.w,cs.n+1,cs.d+v});
    }
  }
  cout<<m<<endl;
}

Measured memory_bytes: 9400
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i, n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i, n) for(ll i=(ll)(n-1);i>=0;i--)
#define FOR(i, a, b) for(ll i=(ll)(a), i<=(ll)(b); i++)
#define RFOR(i, a, b) for(ll i=(ll)(a);i>=(ll)(b); i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

ll count(string N, int K)
{
	ll n = N.length();
	string com="0";
	if(n==1 and N==com){
		return 0;
	}
	if(N.substr(0, 1)==com){
		return count(N.substr(1, n-1), K);
	}
	string n10 = string(n-1, '9');
	string tmp = N.substr(0, 1);
	ll nmax=stoi(tmp);
	switch(K){
		case 1:
			if(n==1){
				return stoi(N);
			}
			else{
				return (ll)(nmax+count(n10, 1));
			}
			break;
		case 2:
			if(n==1){
				return 0;
			}
			else if(n==2){
				tmp = N.substr(1, 1);
				return (ll)(nmax-1)*9+stoi(tmp);
			}else{
				return count(n10, 2)+(nmax-1)*count(n10, 1)+count(N.substr(1, n-1), 1);
			}
			break;
		case 3:
			if(n==1){
				return 0;
			}else if(n==2){
				return 0;
			}else if(n==3){
				return count(to_string(99), 2)*(nmax-1)+count(N.substr(1, 2), 2);
			}else{
				return count(n10, 3)+(nmax-1)*count(n10, 2)+count(N.substr(1, n-1), 2);
			}
			break;
	}
}

signed main()
{
	ll K;
	string N;
	cin >> N;
	cin >> K;
	cout << count(N, K);
	cout << endl;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);
		ArrayList<Integer> list = new ArrayList<>();

		while(true){

			int num = in.nextInt();
			int sum = in.nextInt();
			int count = 0;

			if(num == 0 && sum == 0){

				break;

			}else{

				for(int i = 1; i <= (num-2); i++){

					for(int j = i; j <= (num-2); j++){

						for(int k = j; k <= (num-2); k++){

							// ??°????¢????
							// String c = i + "+" + (j + 1) + "+" + (k + 2);
							// System.out.println(c);

							if(i + (j + 1) + (k + 2) == sum){

								count++;

							}
						}
					}
				}

				list.add(count);

			}
		}

		for(int result: list){

			System.out.println(result);

		}

	}
}

Measured memory_bytes: 26476
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long t=0,j,n,m;
    cin>>n>>m;
    long long a[m];
    for(j=0;j<m;j++){
        cin>>a[j];
        t=t+a[j];
    }if(t>=n)
    cout<<"Yes";
    else
    cout<<"No";
    return 0;

  
}


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

int main(){
    string S;
    cin >> S;
    string a = S.substr(0,1);
    string b = S.substr(1,1);
    string c = S.substr(2,1);
    string d = S.substr(3,1);
    if (a ==  b && c ==  d && a != c){
            cout << "Yes" << endl;
    }
    else if (a == c && b == d && a != b){
            cout << "Yes" << endl;
    }
    else if (a == d && b == c && a != b){
            cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

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

#define ONLINE_JUDGE

#define V vector
#define P pair

using LL = long long;
#define FOR(i, x, y) \
    for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) \
    for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
#ifndef ONLINE_JUDGE
#define dbg(x...)                             \
    do {                                      \
        cerr << "\033[32;1m" << #x << " -> "; \
        err(x);                               \
    } while (0)
void err() { cerr << "\033[39;0m" << endl; }
template <template <typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) {
    for (auto v : a) cerr << v << ' ';
    err(x...);
}
template <typename T, typename... A>
void err(T a, A... x) {
    cerr << a << ' ';
    err(x...);
}
#else
#define dbg(...)
#endif
#define sz(x) (int)x.size()

LL bin(LL a, LL b, LL p) {
    LL res = 1;
    a = (a % p + p) % p;
    for (; b; b >>= 1, a = a * a % p)
        if (b & 1) res = res * a % p;

    return res;
}

const int N = 2e5+50;

int f[N];
int p2[3][N];

inline int popcount(int x) {
    int res = 0;
    while (x) {
        ++res;
        x &= (x-1);
    }
    return res;
}

void init() {
    for (int i=1; i<N; ++i) {
        f[i] = 0;
        int t = i;
        while (t) {
            ++f[i];
            t = t % popcount(t);
        }
    }
}


int n;
char s[N];

void solve() {
    scanf("%d", &n);
    scanf("%s", s);
    vector<int> res(3, 0);

    int bitcnt = 0;
    for (int i=0; i<n; ++i) {
        if (s[i] == '1')
            bitcnt += 1;
    }
    for (int i=0; i<n; ++i) {
        for (int j=0; j<3; ++j) {
            if ((bitcnt - 1 + j) == 0)
                continue;
            res[j] = (res[j] << 1 | (s[i] - '0')) % (bitcnt - 1 + j);
        }
    }
    p2[0][0] = p2[1][0] = p2[2][0] = 1;
    for (int i=1; i<n; ++i) {
        for (int j=0; j<3; ++j) {
            if ((bitcnt - 1 + j) == 0)
                continue;
            p2[j][i] = (p2[j][i-1] << 1) % (bitcnt - 1 + j);
        }
            
    }

    for (int i=0; i<n; ++i) {
        int nmod, ans;
        if (bitcnt == 1 && s[i] == '1') {
            puts("0");
            continue;
        }

        if (s[i] == '1') {
            nmod = bitcnt - 1;
            ans = (res[0] - p2[0][n-i-1]) % nmod + nmod;
        } else {
            nmod = bitcnt + 1;
            ans = (res[2] + p2[2][n-i-1]) % nmod + nmod;
        }
        ans %= nmod;
        printf("%d\n", f[ans] + 1);
    }
}

int main() {
    init();

    // for (int i=1; i<=20; ++i) {
    //     dbg(i, f[i], popcount(i));
    // }
    // int t;
    // cin >> t;
    // while (t--) solve();

    solve();

    return 0;
}

Measured memory_bytes: 7016
import java.util.*;

public class Main{
	public static void main(String[] args){
    	Scanner s = new Scanner(System.in);
      	int n = s.nextInt();
      	int d = s.nextInt();
      	int counter = 0;
      	int[][] x = new int[n][d];
      	for(int i = 0; i < n; i ++){
        	for(int j = 0; j < d; j ++){
            	x[i][j] = s.nextInt();
            }
        }
      	for(int i = 0; i < n-1; i ++){
        	for(int j = i + 1; j < n; j ++){
            	if(distance(x[i], x[j], d)){
                	counter ++;
                }
            }
        }
      	System.out.print(counter);
      	
    }
  	public static boolean distance(int[] x, int[] y, int d){
      	int sum = 0;
    	for(int k = 0; k < d; k++){
        	sum += (x[k] - y[k]) * (x[k] - y[k]); 
        }
      	if(Math.sqrt(sum) == (int)(Math.sqrt(sum))){
        	return true;
        }
      	else{
        	return false;
        }
    }
}

Measured memory_bytes: 21844
N = int(input())
A = list(map(int,input().split()))
A.insert(0,0)
X = [0 for _ in range(N+1)]
x = A[1]-A[2]
for i in range(3,N+1):
    if i%2==0:
        x -= A[i]
    else:
        x += A[i]
X[1] = x//2
for i in range(2,N+1):
    X[i] = A[i-1]-X[i-1]
for i in range(1,N+1):
    X[i] = 2*X[i]
print(*X[1:])

Measured memory_bytes: 89076
def is_neighbor_same(lst):
  for i in range(len(lst)-1):
    if(lst[i]==lst[i+1]):
      return True
  return False

input()
input_line=[int(x) for x in input().split()]
input_line.sort()
if(is_neighbor_same(input_line)):
  print("NO")
else:
  print("YES")
  

Measured memory_bytes: 25168
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B;
  char op;
  cin >> A >> op >> B;
  
  int Answer = 0;
  if(op == '+'){
    Answer = A + B;
  }else if(op == '-'){
    Answer = A - B;
  }else if(op == '*'){
    Answer = A * B;
   }else if(op == '/'){
      Answer = A / B;
   }
    cout << Answer << endl;
    
}  

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;
typedef pair<int,int> P;
const long long INF = 1LL<<60;
#define rev(s) (string((s).rbegin(), (s).rend()))


ll dp[110][100010];


int main () {
    int n;

    ll W;

    cin>>n>>W;
    ll w[110];
    ll v[110];



    rep(i,n) {
        cin>>w[i]>>v[i];
    }

    
    
    rep(i,110) {
        rep(j,100010) {
            dp[i][j]=INF;
        }
    }
    dp[0][0]=0;

    rep(i,n) {
        rep(j,100010) {
            if(j-v[i]>=0) {
                dp[i+1][j]=min(dp[i+1][j],dp[i][j-v[i]]+w[i]);
            }
            dp[i+1][j]=min(dp[i][j],dp[i+1][j]);

        }
    }

    ll ans = -1;
    rep(i,100010) {
        if (dp[n][i]<=W) {
            ans=i;
        }
    }

    cout<<ans<<endl;

}

Measured memory_bytes: 86272