akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <iterator>
#include <math.h>
#include <cmath>
#include <stdlib.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <regex>
#include <unordered_set>
#include <string>
#include <map>
#include <iomanip>
#include <sstream>
#include <cassert>
#include <time.h>
#include <numeric>
#include <complex>
 
using namespace std;
using ull = unsigned long long;
using ll = long long;
using ld = long double;
using D = double;
using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
 
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define makeunique(x) sort(all(x)), (x).resize(unique(all(x)) - (x).begin())
#define rep(i, x)  for(int i = 0; i < (x); i++)
#define rrep(i, x) for(int i = (x - 1); i >= 0; i--)
#define sqrt(x) sqrt(abs(x))
#define y1 y1_1234413
#define j1 j1_235
#define y0 y0_235
#define j0 j0_256
#define fi first
#define se second
#define re return
#define prev PREV
#define next next
#define sz(x) ((int)x.size())
 
template<typename T> T sqr(T a) { re a * a; }
template<typename T> T gcd(T a, T b) { re b ? gcd(b, a % b) : a; }
template<typename T> T sgn(T a) { re a > 0 ? 1 : (a < 0 ? -1 : 0); }
template<typename T> T abs(T a) { re a > 0 ? a : -a; }
 
const ld st = 0.000001;
const ld pi = acos((ld)-1);
const int mod = 1000000007;
 
 
#define FILENAME ""
 
const ll MAXN = 100002;

                        
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
    //freopen("sum2.in", "r", stdin);
    //freopen("sum2.out", "w", stdout);
	ll n;
	cin >> n;
	string s;
	cin >> s;
	ll ans = 0;
	for (int i = 0; i <= n - 3; i++) {
	 	string temp;
	 	for (int j = i; j < i + 3; j++) {
	 		temp += s[j];	 	
	 	}
	 	if (temp == "ABC") ++ans;
    }
    cout << ans;      
    re 0;
}

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

int main(){
  string N;
  cin >> N;
  int NN = stoi(N);
  int sum = 0;
  for(int i=0; i<N.size(); i++){
    string c;
    c = N.at(i);
    int n = stoi(c);
    sum += n;
  }
  if(NN % sum == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}
  

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

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    string s;
    cin >> s;
    if(s == "ARC")
        cout << "ABC" << endl;
    else
        cout << "ARC" << endl;
    return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define x_ real()
#define y_ imag()
#define cross(a, b) (conj(a)*(b)).imag()
#define dot(a, b) (conj(a)*(b)).real()
#define PI acos(-1)
#define F first
#define S second
#define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL)
#define fileIO freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef complex<ld> point;
typedef tuple<int, int, int> line;
typedef vector<point> polygon;
typedef pair<double, double> pd;
pair<int, int> dirs[] = { {1, 2}, {-1, 2}, {2, 1}, {2, -1}, {-2, 1}, {-2, -1}, {1, -2}, {-1, -2} };



int main() {
	fastIO;
	int n;
	cin >> n;
	set<int> s;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		s.insert(x);
	}
	cout << (s.size() == n ? "YES" : "NO");


}


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

typedef long long int ll;
ll s1[3005], s2[3005];
int n , m;
ll dp[3005][3005];
const ll mod = 1e9 + 7;

ll lcs(int i , int j){
     if(i >= n){
	    return 0;
	 }
	 if(j >= m){
	     return 0;
	 }
	 if(dp[i][j] != -1){
	    return dp[i][j];
	 }
     ll ans = 0;
	 if(s1[i] == s2[j]){
	    ans = 1 + lcs(i+1,  j)%mod + lcs(i , j + 1)%mod;
	    ans%=mod;
	 }
	 else{
	    ans = ((lcs(i+1 , j)%mod + lcs(i , j+1)%mod)%mod - lcs(i+1 , j + 1)%mod + mod)%mod;
	    ans%=mod;
	 }

	 return(dp[i][j] = ans);
 }

int main(){
    //cout << mod << '\n';
   for(int i = 0; i <= 3000; i++){
        for(int j = 0; j <= 3000; j++){
	       dp[i][j] = -1;
	}
   }
   //int n , m;
   cin >> n >> m;
   for(int i = 0; i < n; i++){cin >> s1[i];}
   for(int i = 0; i < m; i++){cin >> s2[i];}
   cout << (lcs(0 , 0) + 1)%mod << '\n';
}

Measured memory_bytes: 71168
use std::collections::BTreeMap;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let d = sc.read();

    let mut ans = 0;
    for i in 1..19 {
        ans += solve(d, i);
    }
    println!("{}", ans);
}

fn solve(d: i64, digits: usize) -> i64 {
    let mut head = 1;
    for _ in 1..digits {
        head *= 10;
    }
    let mut tail = 1;

    let mut dp: BTreeMap<i64, i64> = BTreeMap::new();
    dp.insert(d, 1);
    for i in 0..(digits / 2) {
        let mut next_dp = BTreeMap::new();
        for (cur, count) in dp.into_iter() {
            for next in -9i64..=9 {
                let comb = 10 - next.abs() - if i == 0 && next >= 0 { 1 } else { 0 };
                let next = next * (head - tail);
                if (cur - next) % (tail * 10) != 0 {
                    continue;
                }
                let next = cur - next;
                *next_dp.entry(next).or_insert(0) += count * comb;
            }
        }
        dp = next_dp;
        head /= 10;
        tail *= 10;
    }

    dp.get(&0).unwrap_or(&0) * if digits % 2 == 1 { 10 } else { 1 }
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        Self(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write_all(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 2220
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>  
using namespace std;
#define eps 0.00000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
pair<int,int> dp[300000] = {};
int now[300000][27] = {};
int cnt[27] = {};
int compare(string a, string b) {
	if (a.length() < b.length()) {
		return 1;
	}
	else if (a.length() == b.length() && a < b) {
		return 1;
	}
	return 0;
}
int main() {
	string a;
	cin >> a;
	a += "abcdefghijklmnopqrstuvwxyz";
	for (int i = 0;i < 26;++i) {
		cnt[i] = a.length();
	}
	for (int i = a.length() - 1;i >= 0;--i) {
		for (int q = 0;q < 26;++q) {
			now[i][q] = cnt[q];
		}
		cnt[a[i] - 'a'] = i;
	}
	map<char, int> wow;
	for (int q = a.length() - 1;q >= 0;--q) {
		if (wow[a[q] - 'a'] == false) {
			wow[a[q] - 'a'] = true;
			dp[q] = make_pair(1, -1);
		}
		else {
			dp[q] = make_pair(1000000, 1000);
			for (int j = 0;j < 26;++j) {
				if (dp[q].first > dp[now[q][j]].first + 1) {
					dp[q].first = dp[now[q][j]].first + 1;
					dp[q].second = now[q][j];
				}else if(dp[q].first == dp[now[q][j]].first + 1 &&a[now[q][j]] < a[dp[q].second]){
					dp[q].second = now[q][j];
				}
			}
		}
	}
	map<char, int> ha;
	string s;
	for (int i = 0;i < a.length();++i) {
		if (ha[a[i]] == false) {
			ha[a[i]] = true;
			int nowing = i;
			string pre;
			while (nowing != -1) {
				pre.push_back(a[nowing]);
				nowing = dp[nowing].second;
			}
			if (i == 0 || s.length() > pre.length()) {
				s = pre;
			}
			else if (s.length() == pre.length() && s > pre) {
				s = pre;
			}
		}
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 24700
N, K = map(int, input().split())
P = list(map(int, input().split()))
P = [p - 1 for p in P]
C = list(map(int, input().split()))

vis = [False] * N
ans = [-float('inf')] * N

for root in range(N):
    if vis[root]:
        continue

    cycle = [root]
    costs = [C[root]]
    u = P[root]
    while u != root:
        cycle.append(u)
        costs.append(C[u])
        u = P[u]
    
    for u in cycle:
        vis[u] = True

    L = len(cycle)
    S = sum(costs)
    for i, v in enumerate(cycle):
        # Rewrite [1, K] as form q * L + r,
        # 0L + 1, 0L + 2, ..., 0L + L
        # 1L + 1, 1L + 2, ..., 1L + L
        # ⋮ 
        # tL + 1, tL + 2, ... 

        # We can ignore 1L + r, 2L + r, ..., (t - 1) * L + r
        # since the total cost of loop is either > 0 or <= 0
        # When > 0, 0L + r < 1L + r < 2L + r < tL + r
        # When <= 0, the answer should be 0L + r

        if S > 0:
            rem_cost = 0
            for rem in range(1, min(L, K) + 1):
                rem_cost += costs[(i + rem) % L]
                t = (K - rem) // L
                ans[v] = max(ans[v], rem_cost + t * S)
        else:
            rem_cost = 0
            for rem in range(1, min(L, K) + 1):
                rem_cost += costs[(i + rem) % L]
                ans[v] = max(ans[v], rem_cost)

print(max(ans))



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

#define ll long long
#define pb push_back
#define eb emplace_back
//#define st first
#define sc second

using namespace std;

const ll mod = 1e9 + 7;
const int e = 55;
const int base = 311;

// dung inverse module de tinh nCk
// 71
// cach tao hoan vi tu n so : n*(n+1)/2;

//vector<pair<ll,ll>>adj[e];

ll Pow(ll n, ll dem)
{
    if(dem == 0) return 1;
    if(dem == 1) return n ;
    ll t = Pow(n, dem/2);
    if(dem % 2 == 0) return (t*t);
    else return ((t * t) * n);
}

/*ll C(ll k, ll n)
{
    if(k == 0) return 1;
    if(n < k) return 0;
    return (gt[n]%mod * (igt[k]%mod * igt[n-k]%mod)%mod)%mod;
}*/

ll n, m, k;
ll gt[e];
char a[e][e];

int main()
{
   ll n;
   cin >> n;
   ll ans = 0;
   for(int i=1; i<=2; i++)
   {
       for(int j=1; j<=n; j++)
       {
           cin >> a[i][j];
       }
   }
   ll chk ;
   for(int i=1; i<=n; i++)
   {
       if(a[1][i] == a[2][i])
       {
           if(i == 1)
           {
               ans = (ans + 3)%mod;
           }
           else
           {
               if(chk == 1)
               {
                   ans = (ans + ans)%mod;
               }
           }
           chk = 1;
       }
       else
       {
           if(i == 1)
           {
               ans = 6;
           }
           else
           {
               if(chk == 1)
               {
                   ans = (ans*2)%mod;
               }
               else
               {
                   ans = (ans*3)%mod;
               }
           }
           chk = 2;
           i ++;
       }
   }
   cout << ans;
}
/*

*/


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

using namespace std;
using ll = long long;

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

  int n, k;
  cin >> n >> k;
  vector<ll> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];

  for (int i = 0; i < n - k; i++) {
    if (a[i] >= a[i + k]) {
      cout << "No\n";
    } else {
      cout << "Yes\n";
    }
  }

  return 0;
}


Measured memory_bytes: 4780
num_500 = int(input())
num_100 = int(input())
num_50 = int(input())
X = int(input())
ans = 0

for use_500 in range(num_500 + 1):
    for use_100 in range(num_100 + 1):
        for use_50 in range(num_50 + 1):
            if use_500 * 500 + use_100 * 100 + use_50 * 50 == X:
                ans += 1

print(ans)


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

int main(){
	int num,f;
	double kg,m,bmi;
	while(scanf("%d,%lf,%lf",&num,&kg,&m)!=EOF){
		bmi=0;
		bmi=kg/(m*m);
		if(bmi>=25.0)cout<<num<<endl;
	}
}

Measured memory_bytes: 1232
#[allow(unused_imports)]
use std::{cmp::Reverse, collections::*};

#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Chars, Usize1},
};

#[allow(unused_imports)]
use itertools::Itertools;

#[allow(unused_imports)]
use num::Integer;

#[fastout]
pub fn main() {
    input! {
        a: i32, b: i32,
    }

    let x: i32 = (a.to_string() + &b.to_string()).parse().unwrap();
    let sqrtx = (x as f64).sqrt() as i32;
    if sqrtx * sqrtx == x {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 2148
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int D,cnt[19],ans;ll b[20];
void dfs(int x,ll res,int L,int now)
//x为当前的位数，res为当前的数值，L为总长度，now为满足条件的方案数

{
    if(x>(L>>1)-1){//x>=L/2
		if(res==D) ans+=now*(L&1?10:1);return;//如果总长为奇数，那么最中间的1位0~9任取
	}
	
    ll i=-9ll; 
	while(i<9ll  && res+(i+1ll)*(b[L-x-1]-b[x])<=D)  ++i;//不退位，第x位之差最大为i
	
    dfs(x+1,res+i*(b[L-x-1]-b[x]),L,now*(x==0&&i>=0?cnt[i+9]-1:cnt[i+9]));
	
    if(++i<=9) dfs(x+1,res+i*(b[L-x-1]-b[x]),L,now*(x==0&&i>=0?cnt[i+9]-1:cnt[i+9]));//退位，第x位之差最大为i
}
int main()
{
    scanf("%d",&D);
	
    b[0]=1ll;
	
	for(int i=1;i<19;++i) b[i]=b[i-1]*10ll;
	
    for(int i=0;i<=9;++i) 
		
		for(int j=0;j<=9;++j) ++cnt[i-j+9]; //构成i-j的方案数
	
    for(int i=1;i<=18;++i) dfs(0,0,i,1); //i为 假设数字的总长度，总位数为0~L-1
	
    printf("%d",ans);
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace CSharp
{
    class Program
    {
        public static void Main()
        {
            var N = int.Parse(Console.ReadLine());
            var dic = new Dictionary<string, int>();

            var result = 0L;
            for (int i = 0; i < N; i++)
            {
                var s = Console.ReadLine();

                var array = s.ToCharArray().OrderBy(x => x).ToArray();
                Array.Sort(array);
                s = new string(array);

                if (dic.ContainsKey(s))
                {
                    dic[s]++;
                }
                else
                {
                    dic[s] = 0;
                }

                result += dic[s];
            }

            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 29984
#include <bits/stdc++.h>
#define N 32768
#define F for(i=0;++i<N;)
long long M=0x3B9ACA07LL,a[N]={},b[N],c[N]={},n,k,i;
int main(){std::cin>>n>>k;F a[i]=i<n?i:n,b[i]=n/i;while(--k){F c[i]=c[i-1]+b[i];b[N-1]=c[n/(N-1)];for(i=N-2;i>0;i--)b[i]=(b[i+1]+a[i]*(n/i-n/(i+1)))%M;std::swap(a,c);}std::cout<<b[1];}


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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define MX              200005
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    // cin>>t;
    // while(t--){
        
    //     cout<<'\n';
    // }
    string s;cin>>s;
    if(s.length()<6){
        cout<<"No"<<endl;return 0;
    }
    if(s[2]==s[3]&&s[4]==s[5]){
        cout<<"Yes"<<endl;
        return 0;
    }
    cout<<"No";
    return 0;
}




Measured memory_bytes: 256
//{{{
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printw) FUNC(printwe) FUNC(printb) FUNC(printbe) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, t;
    cin >> a >> b >> t;
    int ans = 0;
    for(int i = a; i <= t; i += a){
        ans += b;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 888
#include <stdio.h>

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

int bubbleSort(int A[],int N) {
    int i,j;
    int sw = 0;
    unsigned short flag = 1;
    for(i=0;flag;i++) {
        flag = 0;
        for(j=N-1;j>=i+1;j--) {
            if(A[j]<A[j-1]) {
                swap(&A[j],&A[j-1]);
                flag = 1;
                sw++;
            }
        }
    }
    return sw;
}

int main(void) {
    int i, A[100], N, sw;
    scanf("%d",&N);
    for(i=0;i<N;i++) scanf("%d",&A[i]);

    sw = bubbleSort(A,N);

    for(i=0;i<N;i++) {
        if (i) printf(" ");
        printf("%d",A[i]);
    }
    printf("\n%d\n",sw);

    return 0;
}


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

#define f(i,x,n) for(i=x;i<n;i++)
#define fr(i,x,n) for(i=x;i>=n;i--)
#define pu push_back           
#define pp pop_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SP(x) fixed<<setprecision(x)
#define IOS() ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
const long long MOD=1e9+7;
const long double PI = acos(-1);
const long long INF=INT_MAX;
const long long LINF=LLONG_MAX;
const long long N= 3e5+1;
 
typedef long long ll;
typedef long double ld;

void test_case()
{
    ll n,k,i,j;
    cin>>n>>k;
    ll ans=0;
    while(n>0)
    {
        n/=k;
        ans++;
    }
    cout<<ans<<'\n';

}
int main()
{
   IOS();
 
   test_case();
   return 0;
}



Measured memory_bytes: 256
from bisect import bisect_left

n = int(input())
a = tuple(sorted(map(int, input().split())))
b = tuple(sorted(map(abs, a)))

j = bisect_left(a, 0)
m = a[:j]

if len(m) % 2 == 0:
    print(sum(b))
else:
    print(sum(b) - min(b) * 2)


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

int main()
{
    int n;
    cin>>n;
    while(n)
    {
        if(n%10==7)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
        n=n/10;
    }
    cout<<"No"<<endl;
   

    return 0;
}

Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		double ans;
		if (n % 2 == 0) {
			ans = 0.5;
		} else {
			ans = ((n / 2) + 1) / (double) n;
		}
		System.out.println(ans);

	}

}


Measured memory_bytes: 22996
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        a: [usize; n],
    }

    let mut bit = vec![0; 20];
    for i in 0..20 {
        bit[i] = match (1 << i) & a[0] {
            0 => 0,
            _ => 1,
        };
    }

    let mut res = 1;
    // 閉区間[l, r]について考える
    let mut l = 0;
    for r in 1..n {
        let mut flag = false;

        for i in 0..20 {
            bit[i] += match (1 << i) & a[r] {
                0 => 0,
                _ => 1,
            };
            if bit[i] > 1 {
                flag = true;
            }
        }

        // l を増やす
        while flag {
            flag = false;
            for i in 0..20 {
                bit[i] -= match (1 << i) & a[l] {
                    0 => 0,
                    _ => 1,
                };
            }
            l += 1;

            for i in 0..20 {
                if bit[i] > 1 {
                    flag = true;
                    break;
                }
            }
        }

        // println!("(l,r) = {}, {}", l, r);
        // println!("bit {:?}", bit);
        res += r - l + 1;
    }
    println!("{}", res);
}


Measured memory_bytes: 4916
S = input()

def count(s1, s2):
  n = len(s1)
  count = 0
  for i in range(n):
    if s1[i] != s2[i]:
      count += 1
  return count

N = len(S)
S = list(S)

final_odd = ["0"] * N
final_even = ["0"] * N

for i in range(N):
  if i % 2 == 0:
    final_odd[i] = "1"
  else:
    final_even[i] = "1"
    
print(min(count(S, final_odd), count(S, final_even)))

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    ll n;cin >>n;
    ll x;cin >>x;
    ll sum=0;
    ll mint=INF;
    for (int i = 0; i < n; ++i) {
        ll m;cin >>m;
        mint=min(m,mint);
        sum+=m;
    }
    x-=sum;
    ll ans=0;
    ans+=n;
    ans+=x/mint;
    cout <<ans <<endl;
    return 0;
}

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

int main()
{
  ll n,t,a;
  cin >> n;
  cin >> t >> a;
  t *= 1000;
  a *= 1000;
  ll tmp = LLONG_MAX, cur = 0;
  for (ll i = 0; i < n; i++)
  {
    ll h;
    cin >> h;
    if(tmp>abs(t-6*h-a))
    {
      tmp = abs(t-6*h-a);
      cur = i;
    }
  }
  
  cout << cur+1 << endl;
  
  return 0;
}


Measured memory_bytes: 256
n , x = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
cou = 0
for i in range(n):
    cou += a[i]
    if cou == x:
        print(i + 1)
        break
    elif cou > x:
        print(i)
        break
else:        
    print(n-1)
    

Measured memory_bytes: 3060
#include<stdio.h>

int main(void)
{
	int x, y, d;

	scanf("%d", &x);
	scanf("%d", &y);

	d = x % y;

	while (d != 0){
		x = y;
		y = d;
		d = x % y;
	}
	printf("%d\n", y);
	
	return 0;
}


Measured memory_bytes: 2680
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby, 
C#, VB, Perl, Swift, Prolog, Javascript, Pascal, HTML, CSS, JS
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <bits/stdc++.h>

using namespace std;

int main()
{
    map<string,int>m;
    int n;
    string pal;
    char tes='.';
    bool t=true;
    cin >> n;
    
    while(n--){
        
        cin >> pal;
        
        if(pal[0]==tes and m[pal]==0 or tes=='.'){
            m[pal]++; 
            tes=pal[pal.size()-1];
            continue;
        }
        else t=false;
        
    }
    cout << (t==true ? "Yes\n" : "No\n");
    
    

    return 0;
}


Measured memory_bytes: 256
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

alias sread = () => readln.chomp();
ulong MOD = 1_000_000_007;
ulong INF = 1_000_000_000_000;
alias Score = Tuple!(long, "p", long, "c");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void main()
{
    long n, k;
    scan(n, k);
    auto a = aryread();
    writeln((n - 1 + k - 2) / (k - 1));
}

Measured memory_bytes: 3716
<?php
  fscanf(STDIN,"%d",$N);
  $ans=0;
  $a = array_map('intval', explode(" ", fgets(STDIN)));
 
  for($h=1;$h<=count($a);$h++){
    if($h%2==1){
      if($a[$h-1]%2==1)$ans++;
    }
  }
  echo $ans."\n";
  

Measured memory_bytes: 16240
//PKMKB
#include <bits/stdc++.h>
#define ll long long int
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define scanarr(a,b,c) for( i=b;i<c;i++)cin>>a[i]
#define showarr(a,b,c) for( i=b;i<c;i++)cout<<a[i]<<' '
#define ln cout<<'\n'
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mod 1000000007
#define MAX 100005
using namespace std;
////////////////////////////////////////////////////////////////CODE STARTS HERE////////////////////////////////////////////////////////////////

void solve(){
	
	ll n;
	cin >> n;
	vector <char> ans;
	while(n > 0){

		if(n % 26 == 0){
			ans.push_back('z');
		}
		else
			ans.push_back('a' + (n % 26) - 1);
		
		n = n/26 -  (n % 26 == 0);
	}
	reverse(ans.begin(), ans.end());

	for(char x : ans)
		cout << x;
	ln;
}
int main(){

	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	#endif
	
	solve();
}

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

using namespace std;

#define gc getchar_unlocked
#define foi(i,n) for(int i=0;i<n;i++)
#define Foi(i,k,n) for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define fol(i,n) for(ll i=0;i<n;i++)
#define Fol(i,k,n) for(ll i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)   scanf("%d",&x)
#define sl(x)   scanf("%lld",&x)
#define ss(s)   scanf("%s",s)
#define pi(x)   printf("%d\n",x)
#define pl(x)   printf("%lld\n",x)
#define ps(s)   printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pl;
typedef vector<int>     vi;
typedef vector<ll>      vl;
typedef vector<pii>     vpii;
typedef vector<pl>      vpl;
typedef vector<vi>      vvi;
typedef vector<vl>      vvl;
int mpow(int base, int exp); 
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vi g[N];
int a[N];

int mpow(int base, int exp) {
    base %= mod;
    int result = 1;
    while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
    }
    return result;
}

void ipgraph(int n, int m){
    int i, u, v;
    while(m--){
        cin>>u>>v;
        g[u-1].pb(v-1);
        g[v-1].pb(u-1);
    }
}

void dfs(int u, int par){
    for(int v:g[u]){
        if (v == par) continue;
        dfs(v, u);
    }
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    vector<ll> x(n);
    int check[1000001]={0}; 
    map<ll,int> m;   
    for(int i=0;i<n;i++)
    {
        cin>>x[i];
        m[x[i]]++;
    }    
    int max_ele = *max_element(all(x));
    for(int i=0;i<n;i++)
    {
        if(!check[x[i]])
        {
            for(int j=x[i]+x[i];j<=max_ele;j+=x[i])
                check[j]=1;
        }
    }
    int count=0;
    for(int i=0;i<n;i++)
    {
        if(!check[x[i]]&&m[x[i]]==1)
        {
            count++;
        }
    }
    cout<<count;
}

Measured memory_bytes: 28224
import java.io.*;
import java.util.Arrays;
import java.util.Collections;
public class Main {
	public static void main(String args[]){
    int a = 0,b = 0,c = 0;
    int bar[] = new int[3];
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    try{
      String line = reader.readLine();
      String[] splitted = line.split(" ");
      a = Integer.parseInt(splitted[0]);
      b = Integer.parseInt(splitted[1]);
      c = Integer.parseInt(splitted[2]);
      bar[0] = a;
      bar[1] = b;
      bar[2] = c;
    }catch(Exception e){
      bar[0] = 0;
      bar[1] = 0;
      bar[2] = 0;
    }
    Arrays.sort(bar);
    System.out.println(bar[0] + " " + bar[1] + " " + bar[2]);
    		
	}
}


Measured memory_bytes: 24448
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;

using ll = long long;

const int mxn = 100010;
const int mod = 1e9+7;

ll fact[mxn];

int mod_pow(ll x, ll k) {
    ll v = 1;
    for(; k > 0; k >>= 1) {
        if(k & 1) v = v * x % mod;
        x = x * x % mod;
    }
    return v % mod;
}

void init_comb(int n) {
    fact[0] = 1;
    for(int i = 1; i <= n+1; i++) {
        fact[i] = i * fact[i-1] % mod;
    }
}

int mod_inverse(int a) {
    return mod_pow(a, mod-2) % mod;
}

int mod_comb(int n, int k) {
    if(n < k) return 0;
    ll ans;
    ans = fact[n];
    ans = ans * mod_inverse(fact[k]) % mod;
    ans = ans * mod_inverse(fact[n-k]) % mod;
    return (int)ans;
}


int main() {
    int N;
    cin >> N;
    vector<ll> v(N+1+1);
    map<ll, int> mp;
    int snd;
    for(int i = 1; i <= N + 1; i++) {
        cin >> v[i];
        mp[v[i]]++;
        if(mp[v[i]] == 2) snd = v[i];
    }

    vector<int> p;
    for(int i = 1; i <= N + 1; i++) {
        if(v[i] == snd) p.push_back(i);
    }

    int l = p[0]-1, r = N + 1 - p[1];
    int num = l + r;

    init_comb(N + 1);

    for(int i = 1; i <= N+1; i++) {
        ll all = mod_comb(N+1, i);
        ll minus = mod_comb(num, i-1) ;
        ll ans = (all - minus + mod) % mod;
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 8960
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e5+5;
ll ans,n,m,q;
class obj{
public:
    ll a,b,c,d;
}queries[55];
void func(ll idx,ll mx,vector<ll> v){
    if(idx==n){
        ll sum = 0;
        for(ll i=0;i<q;i++){
            if(v[queries[i].b-1]-v[queries[i].a-1] == queries[i].c)
                sum+=queries[i].d;
        }
        ans=max(ans , sum);
        return;
    }
    for(ll i=mx;i<=m;i++){
        v.push_back(i);
        func(idx+1,i,v);
        v.pop_back();
    }
}
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cin>>n>>m>>q;
    for(ll i=0;i<q;i++)cin>>queries[i].a>>queries[i].b>>queries[i].c>>queries[i].d;
    vector<ll> v;
    func(0,1,v);
    cout<<ans;
}


Measured memory_bytes: 3620
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int long long i=0;i<n;i++)
typedef int long long ll;
using namespace std;
int main(){
    
    int n,m;
    cin>>n>>m;

 
    double x=(1900*m+100*(n-m))*pow(2,m);
    cout<<x<<endl;

    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main{
	public static void main(String[] args)throws IOException{
		BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
		String s;
		String[] t;
		int[] n;
		int number;
		while((s=reader.readLine())!=null){
			t=s.split(" ");
			number=t.length;
			n=new int[number];
			for(int i=0;i<number;i++){
				n[i]=Integer.parseInt(t[i]);
			}
			Arrays.sort(n);
			for(int j=number-1;j>=0;j--){
				System.out.print(n[j]);
				if(j!=0){
					System.out.print(" ");
				}
			}
			System.out.println("");
		}
	}
}

Measured memory_bytes: 16896
#include <cstdio>

int main()
{
        unsigned int a, b, sum;
        unsigned int digit;

        while (scanf("%u %u", &a, &b) != EOF) {
                sum = a + b;
                digit = 0;
                while (sum) {
                        sum /= 10;
                        digit++;
                }
                printf("%u\n", digit);
        }

        return 0;
}

Measured memory_bytes: 1036
/*  Oh, the past it haunted me      */
/*  Oh, the past it wanted me dead  */
/*  Oh, the past tormented me       */
/*  Oh, the past it wanted me dead  */
/*  Oh, the past it haunted me      */
/*  Oh, the past it wanted me dead  */
/*  Oh, the past tormented me       */
/*  But the battle was lost         */
/*  'Cause I'm still here           */

#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long int ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;
ll mod=1000000007;


ll has[1000009];
int main()
{
ios_base::sync_with_stdio(false);
    cin.tie(NULL);

ll t=1;
//cin>>t;
while(t--)
{

ll n;
cin>>n;
ll i;
vector<ll>v;

for(i=2;i*i<=n;i++)
{

   if(n%i==0)
   {
    ll cn=0;
    while(n%i==0)
    {
     n/=i;
     cn++;

    }
v.push_back(cn);
   }
}
if(n!=1)
v.push_back(1);


for(i=0;i<1000009;i++)
has[i]=(i*(i+1))/2;


ll ans=0;

for(i=0;i<v.size();i++)
{
 ll sum=upper_bound(has,has+1000009,v[i])-has;
   ans+=sum-1;
}

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









Measured memory_bytes: 11472
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;
// << fixed << setprecision
// --------------------------------------
int n;

bool divisor(vector<bool>& a, int t) {
  bool f = false;
  for(int i=1; i*i<=t; i++) {
    if(t % i == 0) {
      if(a[i]) f = true;
      if(i != t / i) if(a[t / i]) f = true;
    }
  }
  return f;
}

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

  cin >> n;
  vector<int> v(n);
  vector<bool> a(1000005, false);

  REP(i, n) cin >> v[i];
  sort(v.begin(), v.end());

  int ans = 0;
  REP(i, n) {
    bool f = divisor(a, v[i]);
    if(f || (i < n - 1 && (v[i] == v[i + 1]))) ans++;
    a[v[i]] = true;
  }

  cout << (n - ans) << endl;
}


Measured memory_bytes: 4268
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef vector<int> vec1;
typedef vector<string> vec2;
typedef vector<double> vec3;

int main() {

  string s, t;
  cin >> s >> t;

  string ans;
  for(int i = 0; i < s.size(); i++) {
    if(t.size() > i) {
      cout << s.at(i) << t.at(i);
    } else {
      cout << s.at(i);
    }
  }
}

Measured memory_bytes: 256
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])
    to_lower(C, C2) (C: char? C2: code?)

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).

    match: =, \=

    numeric: <,=<, >, >= (eval)
    lexicographically: @<. @=<, @>, @>=
    value?: =:=, =\= (eval)
    identical: ==, \==
*/

main :-
    get_number(N),
    X is 111 + 999 - N,
    writeln(X).


Measured memory_bytes: 8108
#include <cmath>
#include <vector>
#include <map>
#include <functional>
#include <queue>
#include <iostream>
#include <string.h>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdint>
#include <climits>
#include <unordered_set>
#include <sstream>

using namespace std;

#define ll long long int
#define ti4 tuple<int,int,int,int>
#define pii pair<ll,ll>
#define REP(x,n) for(int x = 0;x < n;x++)

struct UnionFind {
    vector<ll> data;
    UnionFind(ll size) : data(size, -1) { }
    bool unionSet(ll x, ll y) {
        x = root(x); y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y]; data[y] = x;
        }
        return x != y;
    }
    bool findSet(ll x, ll y) {
        return root(x) == root(y);
    }
    ll root(ll x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    ll size(ll x) {
        return -data[root(x)];
    }
};

int cost[400][400];
int dp[400][400];

int main()
{
    int h, w;
    cin >> h >> w;
    vector<string> cs(h);
    for(int i = 0;i < h;i++)
    {
        cin >> cs[i];
    }
    ll costSum = 0;
    for(int i = 0; i < w - 1; i++){
        memset(cost, 0, sizeof(cost));
        memset(dp, 0, sizeof(dp));
        
        for(int j = 1; j <= h; j++){
            for(int k = 1; k <= h; k++){
                cost[j][k] = cost[j - 1][k - 1];
                cost[j][k] += (cs[j - 1][i] == cs[k - 1][i + 1]);
                dp[j][k] = 1e7;
            }
        }
        
        for(int j = 1; j <= h; j++){
            for(int k = 1; k <= h; k++){
                dp[j][k] = min(dp[j][k], dp[j - 1][k]);
                dp[j][k] = min(dp[j][k], dp[j][k - 1]);
                dp[j][k] += cost[j][k];
            }
        }
        
        costSum += dp[h][h];
    }
    cout << costSum << endl;
    return 0;
}

Measured memory_bytes: 1664
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
N = int(input())
A = list(map(int,input().split()))
AB = [tuple(map(int,input().split())) for i in range(N-1)]
es = [[] for _ in range(N)]
for a,b in AB:
    a,b = a-1,b-1
    es[a].append(b)
    es[b].append(a)

r = -1
for i in range(N):
    if len(es[i]) > 1:
        r = i
        break
if r == -1:
    assert N==2
    print('YES' if A[0]==A[1] else 'NO')
    exit()

def dfs(v,p=-1):
    if len(es[v]) == 1:
        return A[v]
    s = mxc = 0
    for to in es[v]:
        if to==p: continue
        c = dfs(to,v)
        s += c
        mxc = max(mxc,c)
    pair = s - A[v]
    ret = s - pair*2
    if pair < 0 or ret < 0 or (mxc*2 > s and pair > s - mxc):
        print('NO')
        exit()
    return ret

print('YES' if dfs(r)==0 else 'NO')

Measured memory_bytes: 126764
n,*a=map(int,open(0).read().split())
b=[0]*n
for i in range(1,n+1)[::-1]:
  if not sum(b[i-1::i])%2==a[i-1]:
    b[i-1]=1
print(sum(b))
print(*[i+1 for i,b_i in enumerate(b) if b_i==1])

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

using namespace std;

struct state {
    int idx;
    int candy;
};

int main(int argc, char *argv[]) {
    int N;
    cin >> N;
    
    vector<vector<int>> grid(2, vector<int>(N));
    int cur;
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < N; j++) {
            cin >> grid[i][j];
        }
    }

    int row_size = 2;
    int col_size = N;

    deque<state> q;
    state root = {0};
    root.candy += grid[0][0];
    q.push_back(root);

    vector<int> row_diff = {1, 0};  //  下/右
    vector<int> col_diff = {0, 1};  //  下/右

    int ans = INT_MIN;
    while (!q.empty()) {
        state cur = q.front();
        q.pop_front();

        int cur_idx = cur.idx;
        int row_idx = cur_idx / col_size;
        int col_idx = cur_idx % col_size;

        if (row_idx == 1 && col_idx == N - 1) {
            if (cur.candy >= ans) {
                ans = cur.candy;
            }
        }

        //  右または下にしか移動できない
        for (int k = 0; k < 2; k++) {
            int new_row_idx = row_idx + row_diff[k];
            int new_col_idx = col_idx + col_diff[k];

            if (new_row_idx >= 0
             && new_col_idx >= 0
             && new_row_idx < row_size
             && new_col_idx < col_size) {
                int new_idx = (new_row_idx * col_size) + new_col_idx;
                state newstate = cur;
                newstate.idx = new_idx;
                newstate.candy += grid[new_row_idx][new_col_idx];
                q.push_back(newstate);
            }
        }
    }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string A,B;
int borrow[10];
int C[10];
int K,ans;

void solve(int p,int cnt){
  if(p==(int)A.size()){
    int num=0,j=1;
    for(int i=0;i<p;i++){
      num+=C[i]*j;
      j*=10;
    }
    ans=max(ans,num);
    return;
  }
  int a=A[p]-'0',b=B[p]-'0';
  if(a-borrow[p]>=b){
    C[p]=a-borrow[p]-b;
    borrow[p+1]=0;
    solve(p+1,cnt);
  }else{
    C[p]=a-borrow[p]+10-b;
    if(cnt+1<=K){
      borrow[p+1]=0;
      solve(p+1,cnt+1);
    }
    borrow[p+1]=1;
    solve(p+1,cnt);
  }
}

int main(){
  cin>>A>>B>>K;
  while(B.size()<A.size())B="0"+B;
  reverse(A.begin(),A.end());
  reverse(B.begin(),B.end());
  solve(0,0);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1212
def compose(W, w):
  A = [0]*W
  S = [0]*(W+1)
  S[W%w] = 1000
  for j in range(W-w+1):
    S[j+w] = S[j] - 1
  for j in range(W):
    A[j] = S[j+1] - S[j]
    
  return A

H, W, h, w = map(int, input().split())

if H%h == 0 and W%w == 0:
  print("No")
else:
  print("Yes")
  if W%w:
    S = compose(W, w)
    for _ in range(H):
      print(*S)
  else:
    S = compose(H, h)
    for i in range(H):
      print(*[S[i] for _ in range(W)])

Measured memory_bytes: 4616
/**
 * Combinatorial - 0-1 Knapsack Problem II
 */

#include <iostream>

using namespace std;
using LL = long long;

const LL INF = 1L << 60;

int main() {

    int N, W, total = 0;
    LL dp[101][10001];

    cin >> N >> W;

    fill(dp[0], dp[100], INF);
    dp[0][0] = 0;

    for (int i = 1; i <= N; i++) {
        int v, w;
        cin >> v >> w;
        total += v;
        for (int j = 0; j <= total; j++) {
            if (j < v) {
                dp[i][j] = dp[i - 1][j];
            } else {
                dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v] + w);
            }
        }
    }

    int ans = 0;

    for (int i = total; i >= 0; i--) {
        if (dp[N][i] <= W) {
            ans = i;
            break;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 10968
#CAST IN THE NAME OF GOD, YE NOT GUILTY.

from collections import deque
INF = 1000000
dij = [[1, 0, -1, 0], [0, 1, 0, -1]]

def vectorBool(i, j, k, maze):
    if k == 0 and maze[2*i+1][j] == 1:
        return False
    elif k == 1 and maze[2*i][j] == 1:
        return False
    elif k == 2 and maze[2*i-1][j] == 1:
        return False
    elif k == 3 and maze[2*i][j-1] == 1:
        return False
    else:
        return True


def bfs(w, h, maze):
    q = deque()
    dist = [[INF for i in range(w)]for j in range(h)]
    q.append((0, 0))
    dist[0][0] = 1

    while(len(q)):
        p = q.popleft()
        if p == (h - 1, w - 1):
            break
        for k in range(4):
            nxy = (p[0] + dij[0][k], p[1] + dij[1][k])
            if(0<= nxy[0] < h) and (0<= nxy[1] < w) and vectorBool(p[0], p[1], k, maze) and dist[nxy[0]][nxy[1]] == INF:
                q.append(nxy)
                dist[nxy[0]][nxy[1]] = dist[p[0]][p[1]] + 1
    if dist[h-1][w-1] == INF:
        return 0
    else:
        return dist[h-1][w-1]


while True:
    w, h = list(map(int, input().split()))
    if w == 0 and h ==0:
        break
    maze = []
    for i in range(2 * h - 1):
        maze.append(list(map(int, input().split())))
    print(bfs(w, h, maze))

Measured memory_bytes: 8020
#include <bits/stdc++.h>
 using namespace std;
 #define rep(i,N) for(int i=0;i<int(N);++i)
 using ll = long long;
 const int INF = 2147483647;
 const ll MOD = 1000000007;
//  const long long INF = 1LL << 60;

int main(){
   int a,b,c;
   cin >> a >> b >> c;
   int k;
   cin >> k;
   while(k>0){
      if(a>=b) b*=2;
      else break;
      k--;
   }
   while(k>0){
      if(b>=c) c*=2;
      else break;
      k--;
   }
   if(a<b&&b<c) cout << "Yes" << endl;
   else cout << "No" << endl;
   return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ifor(i,n) for(i=0;i<n;i++)
#define ll long long
int main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     ll int i,n,t,p=INT_MAX,j=0,x,a=0,b,l=0,r=0,y;
     string s,m;
     int ara[32]={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};
     cin>>n;
     cout<<ara[n-1]<<endl;

     return EXIT_SUCCESS;
}





Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0;i<(n);i++)
typedef complex<double> xy_t;
double cross_product(xy_t a, xy_t b) { return (conj(a) * b).imag(); }


const double eps = 1e-12;
double x[4], y[4];
int n;

int main() {
	cin >> n;
	rep(t, n) {
		rep(i, 4) cin >> x[i] >> y[i];	
		xy_t a[2] = { xy_t(x[0],y[0]) - xy_t(x[1],y[1]),xy_t(x[2],y[2]) - xy_t(x[3],y[3]) }; //This is how to make an array.
		bool p = abs(cross_product(a[0],a[1])) < eps; //The calculated area is not exactly 0.
		cout << (p ? "YES" : "NO") << endl; //I've seen this kind of expression for the first time...so intuitive.
	}
	return 0;
}


Measured memory_bytes: 3040
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    if(n % 2 == 0 && s.substr(0 , n / 2) == s.substr(n / 2 , n / 2))
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
    return 0;
}


Measured memory_bytes: 256
n=int(input())
csf=[[int(i) for i in input().split()] for j in range(n-1)]

time=[]
for i in range(n-1):
    arrive=csf[i][0]+csf[i][1]
    for j in range(i+1,n-1):
        if csf[j][1]>=arrive:
            arrive=csf[j][1]+csf[j][0]
        else:
            if (arrive-csf[j][1])%csf[j][2]==0:
                arrive=((arrive-csf[j][1])//csf[j][2])*csf[j][2]+csf[j][0]+csf[j][1]
            else:
                arrive=((arrive-csf[j][1])//csf[j][2])*csf[j][2]+csf[j][2]+csf[j][0]+csf[j][1]
    time.append(arrive)
    
for i in time:
    print(i)
print(0)        
        

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
#define INF 1001001001
#define PI 3.14159265359
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repX(i, n , x) for (int i = (int)(x); i < (int)(n); ++i)
#define repB(i, n) for (int i = n; i >= 1; --i)
#define repBX(i, n , x) for (int i = (int)(n); i >= int(X); --i)
#define dup(x,y) (((x)+(y)-1)/(y))

int main() {
    int N,K;
    int R,S,P;
    string T;
    cin >> N >> K;
    cin >> R >> S >> P;
    cin >> T;
    vector<char> ta(N);
    ll ans = 0;
    rep(i,K){
        if(T[i]=='r'){
            ta[i] = 'p';
            ans += P;
        }
        if (T[i] == 's')
        {
            ta[i] = 'r';
            ans += R;
        }
        if (T[i] == 'p')
        {
            ta[i] = 's';
            ans += S;
        }
    }
    repX(i,N,K){
        char w = ' ';
        if(T[i]=='r'){
            w = 'p';
            if(ta[i-K]!=w){
                ta[i] = w;
                ans += P;
            }
            else{
                w = '0';
            }
        }
        if (T[i] == 's')
        {
            w = 'r';
            if (ta[i - K] != w)
            {
                ta[i] = w;
                ans += R;
            }
            else
            {
                w = '0';
            }
        }
        if (T[i] == 'p')
        {
            w = 's';
            if (ta[i - K] != w)
            {
                ta[i] = w;
                ans += S;
            }
            else
            {
                w = '0';
            }
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 512