akhauriyash/Code-Regression huggingface dataset:
N,M,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
c=0
b=0
for i in range(M):
    b+=B[i]
    if b<=K:
        c+=1
    else:
        break
a=0
b=sum(B)
j=M
ans=0
for i in range(N):
    a+=A[i]
    if a>K:
        break
    while a+b>K:
        b-=B[-1]
        B.pop(-1)
        j-=1
    ans=max(ans,i+j+1)
ans=max(ans,c)
print(ans)






    

        




    















    



    





    






        






    
















        


























            
    


    


    
    














    


    














Measured memory_bytes: 40364
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <iomanip>
using namespace std;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 998244353;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }  

int main(){
  	char s;
    cin >> s;

    if(s == 'S')
        cout << "Cloudy";
    else if(s == 'C')
        cout << "Rainy";
    else
        cout << "Sunny";    
}

Measured memory_bytes: 256
N = int(input())
S = list(input())
def echo(S,N):
    if N % 2 != 0:
        return "No"
    else:
        for i in range(0,N//2):
            if S[i] != S[i + (N//2)]:
                return "No"
        return "Yes"
print(echo(S,N))

Measured memory_bytes: 3060
X,N=map(int,input().split())
if N==0:
  print(X)
  exit()
p=list(map(int,input().split()))
num=10**6
ans=0
np=[]
for i in range(0,201):
  if not i in p:
    np.append(i)
for i in np:
  if num>abs(X-i):
    num=abs(X-i)
    ans=i
print(ans)

Measured memory_bytes: 9144
#ifndef _TEMPLATE_ROOT
#define _TEMPLATE_ROOT
#include "bits/stdc++.h"
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define repl(i, a, b) for(ll i = a; i < (b); ++i)
#define repd(i, a, b) for(int i = a; i >= (b); --i)
#define repdl(i, a, b) for(ll i = a; i >= (b); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
#endif
#ifndef _TEMPLATE_IO
#define _TEMPLATE_IO

template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void writef(T ...tail) { write(tail...); cout << flush; }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }
template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
  if (v.size()) {
    rep(i, 0, sz(v) - 1)
      out << v[i] << " ";
    out << v.back();
  }
  return out;
}
#endif
using namespace std;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

  int n; ll x;
  read(n, x);
  ll a[n];
  rep(i, 0, n) read(a[i]);
  ll ans = 0;
  if (a[0] > x) {
    ans += a[0] - x;
    a[0] = x;
  }
  rep(i, 1, n) {
    if (a[i] + a[i - 1] > x) {
      ll d = a[i] + a[i - 1] - x;
      a[i] -= d;
      ans += d;
    }
  }
  write(ans);
}



Measured memory_bytes: 4432
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>; 
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
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; }


int main(){
  int n; cin >> n;
  vector<int> counter(n+1);
  for(int x=1; x*x<n; x++){
    for(int y=1; x*y<n; y++){
      for(int z=1; x*z<n; z++){
        ll tmp = x*x + y*y + z*z + x*y + y*z + z*x;
        if(tmp <= n)counter[tmp]++;
      }
    }
  }
  rept(i, 1, n+1){
    cout << counter[i] << ln;
  }
}


Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
int main()
{
    ll H, W;
    cin >> H >> W;

    ll ans = INF;
    repd(i, 0, H + 1) {
        ll A = i * W;
        ll w = W / 2;
        ll B = (H - i) * w;
        ll C = H * W - A - B;
        ll max_D = max(A, max(B, C));
        ll min_D = min(A, min(B, C));
        ans = min(ans, max_D - min_D);

        if (i != H - 1) {
            ll h = (H - i) / 2;
            B = W * h;
            C = H * W - A - B;
            max_D = max(A, max(B, C));
            min_D = min(A, min(B, C));
            ans = min(ans, max_D - min_D);
        }
    }

    repd(i, 0, W + 1) {
        ll A = i * H;
        ll h = H / 2;
        ll B = (W - i) * h;
        ll C = H * W - A - B;
        ll max_D = max(A, max(B, C));
        ll min_D = min(A, min(B, C));
        ans = min(ans, max_D - min_D);

        if (i == W - 1) {
            ll w = (W - i) / 2;
            B = H * w;
            C = H * W - A - B;
            max_D = max(A, max(B, C));
            min_D = min(A, min(B, C));
            ans = min(ans, max_D - min_D);
        }
    }

    if (H % 3 == 0) ans = 0;
    else ans = min(ans, W);

    if (W % 3 == 0) ans = 0;
    else ans = min(ans, H);

    cout << ans << endl;
    return 0;
}

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

using namespace std;

using ll = long long;

ll solve(vector<pair<ll, ll>> &v_wv, int w, vector<vector<ll>> &memo,
         int cur = 0) {
  if (cur == v_wv.size()) {
    return 0;
  }

  if (memo[w][cur] == -1) {
    auto p = v_wv[cur];
    ll ans = solve(v_wv, w, memo, cur + 1);
    if (w >= p.first) {
      ans = max(ans, solve(v_wv, w - p.first, memo, cur + 1) + p.second);
    }

    memo[w][cur] = ans;
  }

  return memo[w][cur];
}

int main(int argc, const char *argv[]) {
  int n, w;
  cin >> n >> w;

  vector<pair<ll, ll>> v_wv(n);
  for (int i = 0; i < n; ++i) {
    cin >> v_wv[i].first >> v_wv[i].second;
  }

  vector<vector<ll>> memo(w + 1, vector<ll>(n + 1, -1));
  cout << solve(v_wv, w, memo) << '\n';
  return 0;
}

Measured memory_bytes: 82304
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        String S = sc.next();
        String T = sc.next();
        String[] s = S.split("");
        String[] t = T.split("");
        String ans = "Yes";
        for(int i=0; i<s.length; i++) {
            if(s[i].equals(t[i])) {
                continue;
            }else {
                ans = "No";
            }
        }
        
        System.out.println(ans);
        
    }
}

Measured memory_bytes: 35732
#include <cstdio>
#include <cstring>
#include <map>
using namespace std;

char buf[100000];
map<int, int> table, ans;

int main() {
  while (1) {
    fgets(buf, sizeof(buf), stdin);
    int n = strlen(buf);
    if (n <= 1) break;

    int id, times;
    sscanf(buf, "%d,%d", &id, &times);
    ++table[id];
  }

  while (1) {
    if (scanf("%s", buf) != 1) break;

    int id, times;
    sscanf(buf, "%d,%d", &id, &times);
    if (ans.count(id)) ans[id]++;
    else if (table.count(id)) ans[id] = table[id] + 1;
  }

  for (auto itr=ans.begin(); itr!=ans.end(); itr++) {
    printf("%d %d\n", itr->first, itr->second);
  }
}

Measured memory_bytes: 2700
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <set>
#include <map>
#include <queue>
using namespace std;
typedef long long int lli;
typedef pair<int, int> pii;
typedef pair<lli, lli> pll;
const lli inf = 1e18;
const lli mod = 1e9 +7;

int main(){
	string s;
	cin >> s;
	int n = s.length();
	{
		string ns = "";
		for(int i=0; i<n; i++){
			if(i!=n-1 and s[i] == 'B' and s[i+1] == 'C'){
				ns += "D";
				i++;
			}else{
				ns += s[i];
			}
		}
		s = ns;
		n = s.length();
	}
	vector<string> vs(1, "");
	for(int i=0; i<n; i++){
		if((s[i] == 'B' or s[i] == 'C') and vs.back() != ""){
			vs.push_back("");
		}else{
			vs.back() += s[i];
		}
	}
	lli ans = 0;
	for(string t: vs){
		int numa = 0;
		for(char c: t){
			if(c == 'A'){
				numa++;
			}else if(c == 'D'){
				ans += numa;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


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

int n, h[200005], dp[200005];

int fn(int i) {
    if (i <= 0) return 0;
    if (i == 1) return abs(h[1] - h[0]);
    if (~dp[i]) return dp[i];
    dp[i] = min(fn(i - 1) + abs(h[i] - h[i - 1]), fn(i - 2) + abs(h[i] - h[i - 2]));
    return dp[i]; 
}

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &h[i]);
    }
    memset(dp, -1, sizeof dp);
    printf("%d\n", fn(n - 1));
    return 0;
}

Measured memory_bytes: 2944
/**
*   @author: Kshitiz Srivastava (Pirate_ksh) @ MNNIT Allahabad
*/
#include<bits/stdc++.h>
using namespace std;
 
// General
#define ll long long
#define ld long double
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007 // 998244353
#define PI 3.1415926535897932384
#define endl "\n"
#define debug(x) cout<<x<<endl
#define REP(i,n) for(i=0;i<n;++i)
#define FOR(i,x,n) for(i=x;i<n;++i)
#define RREP(i,n) for(i=n-1;i>=0;--i)
#define RFOR(i,x,n) for(i=n-1;i>=x;--i)
#define TR(i,c) for(auto i=c.begin();i!=c.end();++i)
#define RTR(i,c) for(auto i=c.rbegin();i!=c.rend();++i)
#define sz(a) a.size()
 
// Bounds
#define lb(a,x) a.lower_bound(x)
#define ub(a,x) a.upper_bound(x)
#define all(a) a.begin(),a.end()
 
// Vector
#define vi vector <int>
#define pb(v,x) v.push_back(x)
#define vll vector <ll>
 
// Map
#define mii map <int, int>
#define umii unordered_map <int, int>
 
// Set
#define si set <int>
#define msi multiset<int>
 
// Pair
#define vpii vector<pair < int, int > >
#define vpll vector<pair < ll, ll > >
#define pii pair < int, int >
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define vppi vector<pair<pair<int,int>,int>>
#define ppi pair<pair<int,int>,int>

void solve();

int main(){
    io
    ll t;
    t=1;
    // cin >> t;
    for(int i=0;i<t;++i) solve();
    return 0;
}

void solve() {
    ll i, j;
    ll d, t, s;
    cin >> d >> t >> s;
    double tt = (double)d/(double)s;
    // cout << tt << endl;
    if(tt > t) cout << "No\n";
    else cout << "Yes\n";
}


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

//def
#define debug(x) cout << #x << ": " << x << '\n'
#define out(x) cout << x << '\n'
#define repeat(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define revrepeat(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define foreach(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
constexpr int MOD = 1e9 + 7;
constexpr int INF = __INT_MAX__;               // 2^31 - 1
constexpr long long INFLL = __LONG_LONG_MAX__; // 2^61 - 1
constexpr int MAX_N = 1e5 + 5;
constexpr double PI = acos(-1);

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

    int d, t, s;
    cin >> d >> t >> s;
    if (d <= t * s)
        CYES;
    else
        CNO;

    return 0;
}


Measured memory_bytes: 3652
a,b,c = map(int,input().split())

if a < b:
    if b < c:
        print(a,b,c)
    else:
        if a < c:
            print(a,c,b)
        else:
            print(c,a,b)
        
elif a > b:
    if a < c:
        print(b,a,c)
    else:
        if b < c:
            print(b,c,a)
        else:
            print(c,b,a)


Measured memory_bytes: 5592
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int a[n];
  int counter=0;
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
  }
  sort(a,a+n);
  //int o,p,mid;
  int i=0;
  int j=1;
  int k;
  while(i<n-2)
  {
  		k=j+1;
  		while(k<n&&a[i]+a[j]>a[k])
  		{
  			k++;	
		}
		counter+=k-j-1;
		j++;
		if(j>n-2)
		{
			i++;
			j=i+1;
		}
  }
  cout<<counter<<endl;
  return 0;
}

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

int main() {
	string s;
	cin>>s;
	int N=0;
	int W=0;
	int S=0;
	int E=0;
	int e=s.size();
	for(int i = 0; i < e ; i++) {
		if(s.at(i)=='N') {
			N++;
		}
		else if(s.at(i)=='W') {
			W++;
		}
		else if(s.at(i)=='S') {
			S++;
		}
		else if(s.at(i)=='E') {
			E++;
		}
	}
	if(N==0&&S>0) {
		cout<<"No"<<endl;
	}
	else if(N>0&&S==0) {
		cout<<"No"<<endl;
	}
	else if(W==0&&E>0) {
		cout<<"No"<<endl;
	}
	else if(W>0&&E==0) {
		cout<<"No"<<endl;
	}
	else {
		cout<<"Yes"<<endl;
	}
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int n, q;
    cin >> n >> q;
    vector<int> s(n), t(n), x(n);
    for(int i=0; i<n; ++i)
        cin >> s[i] >> t[i] >> x[i];

    vector<int> d(q);
    for(int i=0; i<q; ++i)
        cin >> d[i];

    vector<tuple<int, int, bool> > v(2*n);
    for(int i=0; i<n; ++i){
        v[2*i] = make_tuple(s[i] - x[i], x[i], true);
        v[2*i+1] = make_tuple(t[i] - x[i], x[i], false);
    }
    sort(v.begin(), v.end());

    int k = 0;
    multiset<int> ms;
    for(int i=0; i<q; ++i){
        while(k < 2 * n && get<0>(v[k]) <= d[i]){
            if(get<2>(v[k]))
                ms.insert(get<1>(v[k]));
            else
                ms.erase(ms.find(get<1>(v[k])));
            ++ k;
        }
        if(ms.empty())
            cout << -1 << endl;
        else
            cout << *ms.begin() << endl;
    }

    return 0;
}


Measured memory_bytes: 18432
#![allow(unused_mut, unused_macros, unused_variables, unused_assignments, non_snake_case, unused_imports, dead_code, non_camel_case_types)]

// [Rustで競技プログラミングの入力をスッキリ記述するマクロ - Qiita]
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 から拝借
macro_rules! input {
    ($($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)*}
    };
}
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<_>>()
    };
    // ABC128-C-Switches用に拡張
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, $t);
        (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")
    };
}

// お約束
use std::collections::{HashMap, BinaryHeap, BTreeMap};
const MOD : usize = 1_000_000_007;
macro_rules! Print {($t:expr) => {println!("{}", $t);};}
macro_rules! Debug {($t:expr) => {println!("{:?}", $t);};}

// エントリーポイント
fn main() {
    input! {
        N : usize,
        Q : usize,
        AB : [(usize, usize); N - 1],
        PQ : [(usize, usize); Q],
    }
    // グラフ生成
    let g = {
        let mut g = vec![vec![]; N + 1];
        for (a, b) in AB {
            g[a].push(b);
            g[b].push(a);
        }
        g
    };
    // カウンタ初期化(いもす法の下準備)
    let mut cnt = vec![0; N + 1];
    for (p, q) in PQ {
        cnt[p] += q;
    }
    // 根(1)から木を巡りつつカウンタ更新
    let mut q = vec![1usize];
    let mut alr = vec![false; N + 1];
    while !q.is_empty() {
        let cur = q.pop().unwrap();
        alr[cur] = true;
        for &nxt in &g[cur] {
            if alr[nxt] {continue;}
            cnt[nxt] += cnt[cur];
            q.push(nxt);
        }
    }
    // 出力
    for c in &cnt[1..] {
        Print!(c);
    }
}


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

int main() {
    long long N,K,result=0,temp;
    cin >> N >> K;
    vector<int> p;

    for (int i = 0 ; i<N;i++) {
        cin >> temp;
        p.push_back(temp);
    }

    sort(p.begin(), p.end());

    for (int i=0;i<K;i++){
        result += p[i];
    }

    cout << result << endl;
  	return 0;
}



Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;

int N;
int a[300000];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    for(int i=0; i<3*N; i++) cin >> a[i];
    long long ans = 0;
    sort(a, a+3*N);
    for(int i=N; i<3*N; i+=2)
        ans += a[i];

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1408
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 1100000000000000000LL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//ここまでテンプレ
int main(){
	int A,B;
	cin>>A>>B;
	cout<<max({A+B,A-B,A*B})<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define FORCLS(i,a,b) for(int i = (a); i <= (b); i++)
#define REPCLS(i,n) FORCLS(i,1,n)

#define NMAX 100005

int n;
int a[NMAX];
int b[NMAX];
using ll = long long;
ll m = 1000000007;
ll solve2() {
    cin >> n;
    int d = (n % 2 == 0) ? -1 : 0;
    REP(i, n){cin >> a[i];}
    REP(i, n){
        int j = (a[i] + d) / 2;
        b[j]++;
    }
    int u = (n + d) / 2 + 1;
    REP(i, u) {
        if (i == 0 && (n % 2 == 1)){
            if (b[0] != 1) return 0;
        }
        else {
            if (b[i] != 2) return 0;
        }
    }
    int p = n / 2;
    ll value = 1;
    REP(i ,p) {
        value <<= 1;
        value %= m;
    }
    return value;
}
void solve(){
    cout << solve2() << endl;
}

#ifdef DEBUG
#define MAIN hoge
#else
#define MAIN main
#endif

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


Measured memory_bytes: 896
import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;

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

        int n = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        int count = 0;
        int max = 0;

        for(int i = 0 ; i < n ; i++){
            list.add(sc.nextInt());
        }

        for(int i = 0 ; i < n -1 ; i++){
            if(list.get(i) >= list.get(i + 1)){
                count++;
            }else{
                if(max <= count){
                    max = count;
                }
                count = 0;
            }
        }
        if(max <= count){
            max = count;
        }

        System.out.println(max);

        

            
                


    }
}

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

int main(){
  string s;
  cin>>s;
  char min='1';
  for(char c='a';c<='z';c++){
    bool flag=true;
    for(int t=0;t<s.size();t++){
      if(s[t]==c)flag=false;
    }
    if(flag){
      min=c;
      break;
    }
  }
  if(min=='1'){
    cout<<"None"<<"\n";
  }else{
    cout<<min<<"\n";
  }

  return 0;
}


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

int main(){
	
	int n;
	cin>>n;
	while(n--){
		int a,b,c;
		cin>>a>>b>>c;
		if( c*c==a*a+b*b || a*a==b*b+c*c || b*b==a*a+c*c ){
			cout<<"YES\n";
		}
		else{
			cout<<"NO\n";
		}
	}
	return 0;
}


Measured memory_bytes: 1120
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
using namespace std;
int main(){
  long long kazu;
  cin >> kazu;
  vector<int> nagasa(kazu);
  long long goukei = 0;
  for(int i = 0;i <= kazu - 1;i++){
    cin >> nagasa[i];
    goukei += nagasa[i];
  }
  vector<long long> kei(kazu);
  kei[0] = nagasa[0];
  for(int i = 1;i <= kazu - 1;i++){
    kei[i] = kei[i - 1] + nagasa[i];
  }
  long long saisyou = 0;
  saisyou = -1;
  for(int i = 0;i <= kazu - 1;i++){
    if(abs((goukei - kei[i]) - kei[i]) <= saisyou || saisyou == -1){
      saisyou = abs((goukei - kei[i]) - kei[i]);
    }
  }
  cout << saisyou << endl;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  int N = S.size();
  string T = S;
  sort(T.begin(), T.end());
  reverse(T.begin(), T.end());
  vector<int> A;
  for (int i = 0; i < N; i++){
    if (S[i] == 'B'){
      A.push_back(i);
    }
  }
  vector<int> B;
  for (int i = 0; i < N; i++){
    if (T[i] == 'B'){
      B.push_back(i);
    }
  }
  int M = A.size();
  long long ans = 0;
  for (int i = 0; i < M; i++){
    ans += B[i] - A[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 2936
/*
 ============================================================================
 Name        : atcorder_001.c
 Author      :
 Version     :
 Copyright   : Your copyright notice
 Description : Hello World in C, Ansi-style
 ============================================================================
 */

#include <stdio.h>
#include <stdlib.h>

int main(void) {

	int a,b;
	int total;
	int amari;

	scanf("%d", &a);
	if(a > 100 || a <= 0) {
		printf("1-100の整数を入力ください\n");
		return EXIT_FAILURE;
	}

	scanf("%d", &b);
	if(b > 100 || b <= 0) {
		printf("1-100の整数を入力ください\n");
		return EXIT_FAILURE;
	}

	total = a + b;
	amari = total%3;

	if (amari == 0) {
		printf("Possible");
		return EXIT_SUCCESS;
	}

	amari = a%3;
	if (amari == 0) {
		printf("Possible");
		return EXIT_SUCCESS;
	}

	amari = b%3;
	if (amari == 0) {
		printf("Possible");
		return EXIT_SUCCESS;
	}
	else {
		printf("Impossible");
		return EXIT_SUCCESS;
	}

	return EXIT_SUCCESS;
}


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

using namespace std;
int row[1000000];

int main(void)
{
	int s,temp,in,ans;
	int cnt=0;
	bool jud=false;

	cin>>s;
	row[0]=s;
	temp=s;

	for(int i=1;i<1000000;i++){
		if(temp%2==0) in=temp/2;
		else in=temp*3+1;

		row[i]=in;

		for(int j=0;j<cnt;j++){
			if(row[j]==row[i]){
				jud=true;
				ans=i+1;
				break;
			 }
		}
		if(jud) break;
		temp=in;
		cnt++;
	}

	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <array>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#define MOD 1000000007
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int H, W, A, B;
LL fac[1123456], ans;

LL mul(LL x, LL y)
{
	return (x * y) % MOD;
}

LL inv(LL n)
{
	LL res = 1, m = MOD - 2;
	while (true) {
		if (m & 1)
		{
			res = mul(res, n);
		}
		if (m >>= 1)
		{
			n = mul(n, n);
		}
		else
		{
			break;
		}
	}
	return res;
}

LL comb(int n, int m)
{
	--n, --m;
	return (fac[n + m] * inv((fac[n] * fac[m]) % MOD)) % MOD;
}

int main()
{
	in >> H >> W >> A >> B;

	fac[0] = 1;
	for (int i = 1; i < 1123456; ++i)
	{
		fac[i] = fac[i - 1] * i;
		fac[i] %= MOD;
	}
	for (int i = B + 1; i <= W; ++i)
	{
		ans += (comb(H - A, i)*comb(A, W - i + 1)) % MOD;
		ans %= MOD;
	}

	out << ans << std::endl;
	return 0;
}

Measured memory_bytes: 8960
#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        m: usize,
        a: [[usize]; n],
    }
    let mut count = vec![0; m + 1];
    for ai in a {
        for aij in ai {
            count[aij] += 1;
        }
    }
    let mut result = 0;
    for v in count {
        if v == n {
            result += 1;
        }
    }
    println!("{}", result);
}


Measured memory_bytes: 4352
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define STACK_SIZE 100
void push(int );
int pop(void );

int stack[STACK_SIZE];
int top = 0;

int main(){
  int x,y,t;
  char s[100];

  while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){
      x = pop( );
      y = pop( );
      push(x + y);

    } else if ( s[0] == '-' ){
      x = pop( );
      y = pop( );
      push(y - x);

    } else if ( s[0] == '*' ){
      x = pop( );
      y = pop( );
      push(x * y);
       
    } else {
      t = atoi(s);
      push(t);
    }
  }
  printf("%d\n",pop()); 
  
  return 0;
}

int pop( ){
  if(top <= 0){
    top--;
    return 0;
  }
  else {
    top--;
    return stack[top + 1]; 
  }
}
 
void push(int p){
  stack[++top] = p;
}
 


 



 



Measured memory_bytes: 2052
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main(void) {
  int H, W, K;
  cin >> H >> W >> K;
  vector<string> s(H);
  for (int i = 0; i < H; i++) 
    cin >> s[i];
  
  vector<vector<int> > t(H);
  for (int i = 0; i < H; i++)
    t[i].resize(W, 0);

  int cnt = 1;
  for (int i = 0; i < H; i++)
    for (int j = 0; j < W; j++)
      if (s[i][j] == '#')
        t[i][j] = cnt++;

  for (int i = 0; i < H; i++) {
    bool isFirst = true;
    for (int j = 0; j < W; j++) {
      if (t[i][j] != 0) {
        int k, n = t[i][j];
        if (isFirst) {
          for (k = 0; k < j; k++)
            t[i][k] = n;
          isFirst = false;
        }
        for (k = j + 1; k < W && t[i][k] == 0; k++) 
          t[i][k] = n;
        j = k - 1;
      }
    }
  }

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (t[i][j] == 0) {
        bool isFound = false;
        for (int k = i+1; k < H; k++) {
          if (t[k][j] != 0) {
            t[i][j] = t[k][j];
            isFound = true;
            break;
          }
        }
        if (!isFound) {
          for (int k = i-1; k >= 0; k--) {
            if (t[k][j] != 0) {
              t[i][j] = t[k][j];
              break;
            }
          }
        }
      }
    }
  }

  for (int i = 0; i < H; i++) {
    cout << t[i][0];
    for (int j = 1; j < W; j++) {
      cout << ' ' << t[i][j];
    }
    cout << endl;
  }
}

Measured memory_bytes: 1280
l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
i = int(input())
print(l[i-1])

Measured memory_bytes: 3060
#include<stdio.h>
int main(void)
{
	int i,flg,j;
	int zen[30];
	int a[28],cnt[30]; 
	for(i=1;i<=28;i++){
		scanf("%d",&a[i]);
	}
	for(i=1;i<=30;i++){
		zen[i]=i;
		cnt[i]=0;
	}
	for(i=1;i<=28;i++){
		flg=0;
		for(j=1;j<=30;j++){
			if(a[i]==zen[j]){
				flg=1;
				cnt[j]=flg;
				break;
			}
		}
	}
	for(i=1;i<=30;i++){
		if(cnt[i]==0){
			printf("%d\n",i);
		}
	}
	return 0;
}

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

using namespace std;

#define MAX 400010
typedef long long ll;

int bit[MAX], n;

void init()
{
    n = MAX-1;
    memset(bit, 0, sizeof(bit));   
}

int sum(int i)
{
    int s = 0;
    while (i > 0) {
        s += bit[i];
        i -= i & -i;
    }
    return s;
}

void add(int i, int x)
{   
    while (i <= n) {
        bit[i] += x;
        i += i & -i;
    }
}

int get_val(int N, int key)
{
    int l = 0, idx = N;
    while (idx - l > 0) {
        int mid = (l + idx) / 2;
        if (sum(mid) < key) {
            l = mid + 1;
        } else {
            idx = mid;
        }
    }
    return l;
}

int main()
{
    ll Q, lim, x;
    int q;
    while (1) {
        scanf("%lld %lld", &Q, &lim);
        if (Q == 0 && lim == 0) break;
        ll idx = 1;
        init();
        map<ll, ll> i2v, v2i;
        while (Q--) {
            scanf("%d %lld", &q, &x);
            switch (q) {
                case 0: {
                    i2v[idx] = x; v2i[x] = idx;
                    add(idx, 1); idx++;
                    int r = sum(idx);
                    if (r > lim) {
                        add(get_val(idx, r - lim), -1);
                    }
                    break;
                }
                case 1: {
                    add(get_val(idx, x), -1);
                    break;
                }
                case 2: {                   
                    printf("%lld\n", i2v[get_val(idx, x)]);
                    break;
                }
                case 3: {
                    add(v2i[x], -1);
                    break;
                }
            }
        }
        puts("end");
    }
    return 0;
}

Measured memory_bytes: 54656
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

class UF{
private:
    vector<int> par,rank,elmNum;
    vector<set<int>> elmList;
public:
    int groups;
    
    UF(int __size):par(__size) , rank(__size,0) , elmNum(__size,1), elmList(__size) , groups(__size){
        rep(i,__size)elmList[i].insert(i);
        for(int i=0;i<__size;i++)par[i]=i;
    }
    
    int getElementsNum(int n){ return elmNum[find(n)]; }
    set<int> getElementsList(int n){ return elmList[find(n)]; }
    
    int find(int x){
        if(par[x]==x) {
            return x;
        }else{
            return par[x]=find(par[x]);
        }
    }
    
    void unite(int x,int y){
        x=find(x);
        y=find(y);
        if(x==y) return;
        
        groups--;
        if(rank[x]<rank[y]){
            par[x]=y;
            elmNum[y]+=elmNum[x];
            for(auto &e:elmList[x])elmList[y].insert(e);
            
        }else{
            par[y]=x;
            elmNum[x]+=elmNum[y];
            for(auto &e:elmList[y])elmList[x].insert(e);
            if(rank[x]==rank[y])rank[x]++;
        }
    }
    
    bool isSame(int x,int y){
        return find(x)==find(y);
    }
};

int main(){
    int n,m;
    cin>>n>>m;
    UF uf(n);
    
    vector<int> p(n);
    rep(i,n){
        cin>>p[i];
        p[i]--;
    }
    rep(i,m){
        int a,b;
        cin>>a>>b;
        uf.unite(a-1,b-1);
    }
    
    int ans = 0;
    rep(i,n){
        if(uf.isSame(p[i],i))ans++;
    }
    
    cout<<ans<<endl;
}


Measured memory_bytes: 42240
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public int[] Sarray() { return ReadLine().Split().Select(int.Parse).ToArray(); }
        static public List<int> Slist() { return ReadLine().Split().Select(int.Parse).ToList(); }

        static int N;
        static int[,] Move;
        static int[,] dp;
        static void Main(string[] args)
        {
            var NW = Sarray();
            var N = NW[0];
            var W = NW[1];
            var v = new long[N];
            var w = new long[N];
            for(var i=0;i<N;++i)
            {
                var t = Sarray();
                w[i] = t[0];
                v[i] = t[1];
            }
            var wv = new long[W + 1];
            for (var i = 0; i < N; ++i)
            {
                for (var j = W; 0<j ; --j)
                {
                    if (wv[j] != 0 && j + w[i] <= W)
                        wv[j + w[i]] = Max(wv[j + w[i]], wv[j] + v[i]);
                }
                wv[w[i]] = Max(v[i], wv[w[i]]);
            }
            WriteLine(wv.Max());
        }
    }
}


Measured memory_bytes: 13920
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define fi first
#define se second
#define pf push_front
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define debug(val) cerr << "Value " << #val << " : " << val << '\n';
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f;
const ld epsilon = 10e-9;
const ll nax = 2e5+5;
ll n, k;
ld arr[nax], pref[nax], maks=0;

int main(void){
	IOS
	cin >> n >> k;
	for(int i=0;i<n;i++){
		cin >> arr[i];
	}
	for(int i=0;i<n;i++){
		if(i==0){
			pref[i]=(arr[i]+1)/2;
		}
		else pref[i]=pref[i-1]+((arr[i]+1)/2);
	}
	for(int i=0;i+k-1<n;i++){
		ld ans=0;
		ans=pref[i+k-1]-pref[i-1];
		maks=max(maks, ans);
	}
	cout << setprecision(10) << fixed;
	cout << maks << '\n';
}


Measured memory_bytes: 10012
#include<stdio.h>
#include<queue>
#include<map>
#define INF 10000000
using namespace std;
typedef pair<int,int> P;
bool pos[1000][1000];
int d[1000][1000];
int cx[10];
int cy[10];
int dx[4]={-1,0,0,1};
int dy[4]={0,1,-1,0};
int h,w,n;
int bfs(int sx,int sy,int gx,int gy){
	int i,j;
	queue<P> que;
	for(i=0;i<h;i++)for(j=0;j<w;j++)d[i][j]=INF;
	d[sx][sy]=0;
	que.push(P(sx,sy));
	while(!que.empty()){
		P p=que.front();
		que.pop();
		int x=p.first;
		int y=p.second;
		for(i=0;i<4;i++){
			if(x+dx[i]>=0&&x+dx[i]<h&&y+dy[i]>=0&&y+dy[i]<w&&pos[x+dx[i]][y+dy[i]]&&d[x+dx[i]][y+dy[i]]==INF){
				d[x+dx[i]][y+dy[i]]=d[x][y]+1;
				que.push(P(x+dx[i],y+dy[i]));
			}
		}
	}
	return d[gx][gy];
}
		
int main(){
	int i,j;
	char c;
	scanf("%d %d %d",&h,&w,&n);
	for(i=0;i<h;i++)for(j=0;j<w;j++)pos[i][j]=true;
	for(i=0;i<h;i++)for(j=0;j<w;j++){
		scanf(" %c",&c);
		if(c=='S'){cx[0]=i;cy[0]=j;}
		else if(c>='1'&&c<='9'){cx[c-'0']=i;cy[c-'0']=j;}
		else if(c=='X')pos[i][j]=false;
	}
	int ans=0;
	for(i=1;i<=n;i++)ans+=bfs(cx[i-1],cy[i-1],cx[i],cy[i]);
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

deque<char> S;
int Q;

signed main()
{
  string s; cin >> s;
  for(char c : s) {
    S.push_back(c);
  }

  cin >> Q;
  int cnt = 0;
  REP(q,Q) {
    int d;
    cin >> d;
    if (d == 1) {
      cnt++;
    } else {
      int f; char c;
      cin >> f >> c;
      if (f == 1) {
        if(cnt%2 == 0) {
          S.push_front(c);
        } else {
          S.push_back(c);
        }
      } else {
        if(cnt%2 == 0) {
          S.push_back(c);
        } else {
          S.push_front(c);
        }
      }
    }
  }

  if(cnt%2 == 1) {
    reverse(begin(S), end(S));
  }

  for(char c : S) {
    cout << c;
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll a,b;
  string s,t;
  cin>>a>>s;
  t=s.substr(2,2);
  s=s.substr(0,1);
  b=stoi(s);b*=100;b+=stoi(t);a*=b;
  cout<<a/100;
}

Measured memory_bytes: 3624
#include<iostream>

#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
using namespace std;


int main () {
  int H, W;
  int i, j;
  while (1) {
    cin >> H >> W;
    if (H == 0 && W == 0) break;
    rep(i,H) {
      rep(j,W) {
	if ((i+j)%2 != 1) {
	  cout << '#';
	} else {
	  cout << '.';
	}
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1152
N, M = [int(_) for _ in input().split()]
xyz = [tuple(int(_) for _ in input().split()) for _ in range(N)]

#import itertools
#l = list(range(N))
#result = 0
#for xs in itertools.combinations(l, M):
#    r = abs(sum(xyz[x][0] for x in xs)) + abs(sum(xyz[x][1] for x in xs)) + abs(sum(xyz[x][2] for x in xs))
#    result = max(result, r)

signs = [
    (+1, +1, +1),
    (+1, +1, -1),
    (+1, -1, +1),
    (+1, -1, -1),
    (-1, +1, +1),
    (-1, +1, -1),
    (-1, -1, +1),
    (-1, -1, -1),
]

result = 0

for s in signs:
    xyz.sort(key=lambda x:s[0] * x[0] + s[1] * x[1] + s[2] * x[2], reverse=True)
    r = sum(abs(sum(r[i] for r in xyz[:M])) for i in range(3))
    result = max(result, r)

print(result)


Measured memory_bytes: 3256
import sys
def I(): return int(sys.stdin.readline())
def LI(): return [int(x) for x in sys.stdin.readline().split()]

def calc(a,b,n):
    ret = 0
    if a==b and a<=n:
        ret += 1
    if a*10+b <= n:
        ret += 1
    for i in range(2,7):
        if a*(10**i)+b>n:
            break
        if a*(10**i)+(10**i)-10+b<=n:
            ret += 10**(i-1)
            continue
        tmp = n
        while(tmp%10!=b):
            tmp -= 1
        tmp -= a*(10**i)
        tmp //= 10
        tmp += 1
        ret += tmp
    return ret

def main():
    N = I()
    ans = 0
    for A in range(1,10):
        for B in range(1,10):
            ans += calc(A,B,N) * calc(B,A,N)
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 39828
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;


const int MAX_N = 100010;

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	// ∧ -> 論理積(AND)
	int n; cin >> n;
	VE t(n), a(n); rep(i, n)cin >> t[i] >> a[i];
	// A,B->得票数
	int A = 1, B = 1;
	rep(i, n) {
		// A <= nx && B <= ny となるような最小の自然数nを求める
		int MINN = max((A + t[i] - 1) / t[i], (B + a[i] - 1) / a[i]);
		A = MINN * t[i]; B = MINN * a[i];
	}
	cout << A + B << endl;
	return 0;
}

Measured memory_bytes: 256
/*
 * coder: @SumitRaut
 */
#include <bits/stdc++.h>
#define debug1(x) cerr<<#x<<' '<<x<<'\n'
#define debug2(x,y) cerr<<#x<<' '<<x<<' '<<#y<<' '<<y<<'\n'
#define debug3(x,y,z) cerr<<#x<<' '<<x<<' '<<#y<<' '<<y<<' '<<#z<<' '<<z<<'\n'
#define ll long long

using namespace std;
ll mod=1e9+7;
ll pwm(ll a,ll b) {
    ll p=1ll,one=1ll;
    while(b) {
        if(b&one)
            p=p*a%mod;
        a=a*a%mod;
        b >>=1;
    }
    return p;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m,t,i,j;
    cin>>n>>m>>t;
    vector<pair<int,int>>vec(t);
    for(auto &it:vec) cin>>it.first>>it.second;
    sort(vec.begin(),vec.end(),[&](pair<int,int>&a,pair<int,int>&b) {
        return (a.first==b.first ? a.second<b.second : a.first<b.first);
    });
    int Sz=n+m+4;
    ll fac[Sz],inv[Sz];
    inv[0]=fac[0]=1;
    for(i=1;i<Sz;++i) {
        fac[i]=(i*fac[i-1])%mod;
        inv[i]=pwm(fac[i],mod-2);
    }
    auto ways=[&](int X,int Y) {
        return fac[X+Y]*inv[X]%mod*inv[Y]%mod;
    };
    ++t;
    vector<ll>pth(t);
    vec.emplace_back(n,m);
    for(i=0;i<t;++i) {
        pth[i]=ways(vec[i].first-1,vec[i].second-1);
        for(j=i-1;~j;--j) {
            if(vec[i].second>=vec[j].second) {
                pth[i]-=pth[j]*ways(vec[i].first-vec[j].first,vec[i].second-vec[j].second)%mod;
                if(pth[i]<0) pth[i]+=mod;
            }
        }
    }
    cout<<pth[t-1]<<'\n';
}


Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define less Less
#define EPS 1e-4
#define arg ARG
#define pdd pair<double,double>
#define cpdd const pdd
#define MXN 300005
int f[200005];
int Find(int x){
    if(f[x]==x)return x;
    return f[x]=Find(f[x]);
}
int match[200005];
int main(){
    int n,h,w;
    scanf("%d %d %d",&n,&h,&w);
    for(int i = 1;i<=h+w;i++)
        f[i]=i;
    pair<int,pii> p[100005];
    for(int i = 0;i<n;i++){
        int r,c,a;
        scanf("%d %d %d",&r,&c,&a);
        p[i]=mp(a,mp(r,c+h));
    }
    sort(p,p+n);
    reverse(p,p+n);
    LL ans=0;
    for(int i = 0;i<n;i++){
        int a=Find(p[i].y.x);
        int b=Find(p[i].y.y);
        if(!match[a]){
            match[a]=1;
            f[a]=b;
            ans+=p[i].x;
        }
        else if(!match[b]){
            match[b]=1;
            f[b]=a;
            ans+=p[i].x;
        }
    }
    printf("%lld\n",ans);
}

Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
long long arr[200000+10];
long long a[200000+10];
long long n,k;
long long ans = 0;
void Merge(int l,int mid,int r)
{
    int i=l,j=mid+1,k=l;
    while(i<=mid&&j<=r)
    {
        if(arr[i]>arr[j])
        {
            a[k++]=arr[j++];
            ans+=mid-i+1;
        }
        else
		{
			a[k++]=arr[i++];
		}
    }
    while(i<=mid)
        a[k++]=arr[i++];
    while(j<=r)
        a[k++]=arr[j++];
    for(int e=l;e<=r;e++)
        arr[e]=a[e];
}
void Merge_sort(int l,int r)
{
    if(l<r)
    {
        int mid=(l+r)/2;
        Merge_sort(l,mid);
        Merge_sort(mid+1,r);
        Merge(l,mid,r);
    }
}
int main()
{
	scanf("%lld%lld",&n,&k);
	arr[0] = 0;
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&arr[i]);
		arr[i] += arr[i-1] - k;
	}
	Merge_sort(0,n);
	printf("%lld\n",(n*n+n)/2-ans);
	return 0;
}

Measured memory_bytes: 3456
#include <stdio.h>
#include<vector>
#include<iostream>
#include<string>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<cmath>
using namespace std;


int main() {
	
	int a, b, c,d,e,f;

	cin >> a >> b >> c;
	d = a * 7 + b;
	e = c / d*7;
	if (c%d <= a * 6)
	{
		f = (c % d+(a-1))/a;
	}
	else
	{
		f = 7;
	}cout <<e+f<< endl;
	return 0;
}


Measured memory_bytes: 3100
#include <vector>
#include <iostream>
#include <string>

using namespace std;

int main()
{
	int n;
	cin >> n;
	int k;
	cin >> k;
	string	str;
	cin >> str;
	k--;

	str[k] = 'a' + (str[k] - 'A');
	cout << str;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<string>
#include<utility>
#include<vector>

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MAX 1000001
using namespace std;
typedef long long ll;

int main(){
  int n, k; cin >> n >> k;
  vector<int> vec(n, 0);
  rep(i, 0, n){
    int a;  cin >> a;
    a--;
    vec[a]++;
  }
  int ans=0;
  sort(rall(vec));
  rep(i, 0, n){
    if(vec[i]>0)  k--;
    ans+=vec[i];
    if(k<=0)  break;
  }
  ans = n-ans;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024