akhauriyash/Code-Regression huggingface dataset:
//デバッグ用オプション：-fsanitize=undefined,address

//コンパイラ最適化
#pragma GCC optimize("Ofast")

//インクルードなど
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

//マクロ
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
//FORAは範囲for文(使いにくかったら消す)
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define FORA(i,I) for(const auto& i:I)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
ll extGCD(ll a, ll b, ll &x, ll &y) {
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll d=extGCD(b,a%b,y,x);
    y-=a/b*x;
    return d;
}

ll myceil(ll a,ll b){
    return (a+(b-1))/b;
}

ll make_divisors(ll n){
    vector<ll> divisors;//約数を格納する配列
    ll ret=n/2-1;
    FOR(i,1,sqrt(n)){
        if(n%i==0){
            divisors.PB(i);
            if(i!=n/i){
                divisors.PB(n/i);
            }
        }
    }
    FORA(i,divisors){
        ll x0,y0,a,b;a=i;b=n/i;
        if(extGCD(a,-b,x0,y0)!=1)continue;
        //cout<<a<<" "<<b<<" "<<0<<endl;
        //cout<<x0<<" "<<y0<<" "<<0<<endl;
        if(x0>=0 and y0>=0){
            ll m=min(ll(x0/b),ll(y0/a));
            if(x0-b*m==0 or y0-a*m==0)m--;
            ll x,y;x=a*(x0-b*m);y=b*(y0-a*m);
            ret=min(ret,y);
            //cout<<x<<" "<<y<<" "<<1<<endl;
        }else if(x0<0 and y0<0){
            ll m=max(myceil(-x0,b),myceil(-y0,a));
            if(x0+b*m==0 or y0+a*m==0)m++;
            ll x,y;x=a*(x0+b*m);y=b*(y0+a*m);
            ret=min(ret,y);
            //cout<<x0+b*m<<" "<<y0+a*m<<2<<endl;
            //cout<<x<<" "<<y<<" "<<2<<endl;
        }else if(x0<0){
            ll m=myceil(-x0,b);
            if(x0+b*m==0)m++;
            ll x,y;x=a*(x0+b*m);y=b*(y0+a*m);
            ret=min(ret,y);
            //cout<<x0+b*m<<" "<<y0+a*m<<3<<endl;
            //cout<<x<<" "<<y<<" "<<3<<endl;
        }else{
            ll m=myceil(-y0,a);
            if(y0+a*m==0)m++;
            ll x,y;x=a*(x0+b*m);y=b*(y0+a*m);
            ret=min(ret,y);
            //cout<<x0+b*m<<" "<<y0+a*m<<4<<endl;
            //cout<<x<<" "<<y<<" "<<4<<endl;
        }
    }
    return ret;
}
signed main(){
    //入力の高速化用のコード
    //ios::sync_with_stdio(false);
    //cin.tie(nullptr);
    ll n;cin>>n;
    if(n==1)cout<<1<<endl;
    else cout<<make_divisors(2*n)<<endl;
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

bool U[100005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K;
    ll R, S, P;
    cin >> N >> K >> R >> S >> P;
    string T;
    cin >> T;
    ll ans = 0;
    REP(i, N) {
        if (i - K >= 0 && T[i - K] == T[i] && U[i - K])
            continue;
        U[i] = true;
        if (T[i] == 'r')
            ans += P;
        if (T[i] == 's')
            ans += R;
        if (T[i] == 'p')
            ans += S;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#define ll long long
using namespace std;


int A[1111];
int main() {
    int N;
    cin>>N;
    for(int i=0;i<N;i++)
        cin>>A[i];
    sort(A,A+N);
    cout << A[N-1]-A[0] << endl;
}

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

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

    int n = s.size();

    vector<bool> dp(100010,false);

    dp[0] = true;

    for(int i = 5; i <= n; i++){
        if(dp[i-5] && s.substr(i-5, 5) == "dream") dp[i] = true;
        else if(i >= 7 && dp[i-7] && s.substr(i-7,7) == "dreamer") dp[i] = true;
        else if(dp[i-5] && s.substr(i-5,5) == "erase") dp[i] = true;
        else if(i >= 6 && dp[i-6] && s.substr(i-6,6) == "eraser") dp[i] = true;
    }

    if(dp[n]){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }

}

Measured memory_bytes: 512
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}

const int MAX_V = 2e5;
const int64_t INF = 1e18;

struct edge {
  int64_t to, cost;
};

int n;
std::vector<edge> G[MAX_V];
int64_t dis[MAX_V];

void dijkstra(int s){
  std::priority_queue<std::pair<int64_t, int64_t>,
                      std::vector<std::pair<int64_t, int64_t>>,
                      std::greater<std::pair<int64_t, int64_t>>> pq;
  std::fill(dis, dis + n, INF);
  dis[s] = 0;
  pq.push(std::pair<int64_t, int64_t>(0, s));

  while (!pq.empty()){
    std::pair<int64_t, int64_t> p = pq.top(); pq.pop();
    int v = p.second;
    if (dis[v] < p.first) continue;
    for (int i = 0; i < (int) G[v].size(); ++i){
      edge e = G[v][i];
      if (dis[e.to] > dis[v] + e.cost){
        dis[e.to] = dis[v] + e.cost;
        pq.push(std::pair<int64_t, int64_t>(dis[e.to], e.to));
      }
    }
  }
}

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

  int m; cin >> n >> m;
  vector<int> a(m), b(m);
  for (int i = 0; i < m; ++i) {
    cin >> a[i] >> b[i];
    --a[i]; --b[i];
    G[a[i]].push_back({b[i], 1});
    G[b[i]].push_back({a[i], 1});
  }

  dijkstra(0);

  if (dis[n - 1] == 2) print("POSSIBLE");
  else print("IMPOSSIBLE");

  return 0;
}

Measured memory_bytes: 20576
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N, A, B;
	cin >> N >> A >> B;

	int tmp,ttmp;
	if (abs(A - B) % 2==0) {
		cout << abs(A - B) / 2 << endl;
		return 0;
	}
	else {
		tmp = min(max(A, B) - 1, N - min(A, B));
		
		if (A - 1 < N - B) {
			ttmp = A + (B - (A - 1) - 1) / 2;
		}
		else {
			ttmp = N - B + 1 + (N - (A + (N - B))) / 2;
		}
	}
	cout << min(tmp, ttmp) << endl;

	return 0;
}



Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[2000010];
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
void init_fact(){
    kaijo[0]=1;
    for(int i=1;i<=2000000;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
int comb(int a,int b){
    if(!kaijo[0])init_fact();
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
int n,k,c;
string s;
vector<int>v,as,bs,ans;
signed main(){
    cin>>n>>k>>c>>s;
    rep(i,n){
        if(s[i]=='o')v.pb(i+1);
    }
    int cur=v[0];
    as.pb(cur);
    while(1){
        if(cur+c>=v.back())break;
        cur=*upper_bound(all(v),cur+c);
        as.pb(cur);
    }
    if(as.size()>k)return 0;
    cur=v.back();
    bs.pb(cur);
    rep(_,k-1){
        int lb=lower_bound(all(v),cur-c)-v.begin();
        lb--;
        cur=v[lb];
        bs.pb(cur);
    }
    reverse(all(bs));

    for(int i=as.size()-1;i>=0;i--){
        if(i==as.size()-1){
            if(as[i]!=v.back());
            else ans.pb(as[i]);
        }
        else{
            if(*upper_bound(all(v),as[i])<=bs[i]);
            else ans.pb(as[i]);
        }
    }
    reverse(all(ans));
    for(int h:ans)cout<<h<<endl;
    return 0;
}


Measured memory_bytes: 8180
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
#define fs first
#define re resize
#define sc second
#define pb push_back
#define eb emplace_back
#define MP make_pair
#define all(x) x.begin(),x.end()
#define mod 1000000007
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define REP(i,n) FOR(i,0,n-1)
#define ins insert
#define mod 1000000007
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << std::endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif
#define endl "\n"
void fastIO(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif   
}
ll modexpo(ll a , ll b){
    if(a==0)return 0;
    if(a==1 or b==0)return 1;
    if(b==1)return a;
    if(b&1) return (a%mod*modexpo(a,b-1)%mod)%mod;
    return modexpo(a%mod * a%mod  ,  b/2 ) % mod;
}
void printv(vll v){
    for(auto&x:v) {
        cout<<x<<" ";
    }
    cout<<endl;
}
string to_string1(ll x){stringstream ss; ss<<x; return ss.str();}
ll to_integer(string s){stringstream ss(s); ll x; ss>>x; return x;}
#define tp9 1000000000 
#define N 8000
ld pi = 3.1415926535;
void printYes() {
    cout << "Yes\n";
}
void printNo() {
    cout << "No\n";
}
ll t , n , p ;
string s;
ll a [100010];
int main (){
    ll n;
    cin >> n  ;
    REP(i,n){
        cin >> a[i] ;
    }
    ll zero =0;
    REP(i,n) if(a[i]==0) zero ++;
    if(zero){
        cout<<0<<endl;
        return 0;
    }
    ll ans =1;
    for(int i=0;i<n;i++){
        if(a[i] <=1000000000000000000/ ans ){
            ans *=a[i];
        }else{
            cout<<-1<<endl;
            return 0;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 4416
import math
a, b, h, m = map(int, input().split())
ax = a * math.cos(math.radians((h/12 + 1/12 * m/60) * 360))
ay = a * math.sin(math.radians((h/12 + 1/12 * m/60) * 360))
bx = b * math.cos(math.radians(m/60 * 360))
by = b * math.sin(math.radians(m/60 * 360))
print(math.sqrt((ax-bx)**2 + (ay-by)**2))

Measured memory_bytes: 9440
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
#include <stack>
#include <iomanip>
#include <limits>
using namespace std;
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
typedef priority_queue<ll> PQ_HIGH;
typedef priority_queue<ll,VL,greater<ll>> PQ_LOW;//昇順

int main(){
  int a,b,c,d;cin>>a>>b>>c>>d;
  int flag=1;
  int turn=0;
  while(flag==1){
    if(turn%2==0){
      c=c-b;
    }else{
      a=a-d;
    }
    turn++;
    if(a<=0){
      flag=0;
      cout<<"No"<<endl;
    }
    if(c<=0){
      flag=0;
      cout<<"Yes"<<endl;
    }
  }
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
const int MOD=1000000007;
const int nmax=3123;
int n,dp[nmax],res;
char s[nmax];
int main(){
    scanf("%d",&n);
    scanf("%s",s+1);
    dp[1]=1;
    for(int i=2; i<=n; ++i){
        if(s[i-1]=='<'){
            int tmp=0;
            for(int j=1; j<=i; ++j){
                int tmp2=dp[j];
                dp[j]=dp[j-1]+tmp;
                if(dp[j]>=MOD)dp[j]-=MOD;
                tmp=tmp2;
            }
        }
        else
            for(int j=i-2; j>0; --j){
                dp[j]+=dp[j+1];
                if(dp[j]>=MOD)dp[j]-=MOD;
            }
    }
    for(int i=1; i<=n; ++i){
        res+=dp[i];
        if(res>=MOD)res-=MOD;
    }
    printf("%d",res);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; 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() {
    ll n, d, x, y;
    cin >> n >> d;
    ll ans = 0; 
    rep1(i, n){
        cin >> x >> y;
        if (x*x + y*y <= d*d) ans++;
    }
    cout << ans << endl;
}

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

typedef long long ll;

int max(int a, int b){
  if(a > b) return a;
  else return b;
}
int min(int a, int b){
  if(a < b) return a;
  else return b;
}

int sort(const void *a ,const void *b){
  return *(int*)a - *(int*)b;
}

int f(int a){
  int count = 0;
  int flag = 0;
  for(int i = 1; i <= pow(a,0.5); ++i){
    if(a % i == 0) count ++;
    if(i*i == a)flag = 1;
  }
  count *= 2;
  if(flag == 1) --count;
  return count;
}


int main(){

  int n;
  scanf("%d",&n);
  printf("%d\n",n*n*n);

  return 0;
}



Measured memory_bytes: 2104
import java.util.*;

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

        int N = sc.nextInt();
        int[] a = new int[N];
        int cntOfRemain = 0;

        for (int i = 0; i < N; i++) a[i] = sc.nextInt();

        if (N == 1 && a[0] == 1) {
            System.out.println(0);
            return;
        }

        for (int i = 0; i < N; i++) {
            if (cntOfRemain + 1 == a[i]) {
                cntOfRemain++;
            }
        }

        System.out.println(cntOfRemain == 0 ? -1 : N - cntOfRemain);
    }
}

Measured memory_bytes: 76040
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    int h=0;
    int co=0;
    cin >> n;
    for(int i=1;i<=n;i++){
        h=0;
        if(i%2==1){
            for(int j=1;j<=i;j++){
                if(i%j==0)h++;
            }
        }
        if(h==8)co++;
    }
    cout << co << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

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

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

#define endl "\n"

void solve() {
  int N;
  cin >> N;
  vector<int> dp(N + 1, INF);
  dp[0] = 0;
  for (int i = 0; i < N; i++) {
    chmin(dp[i + 1], dp[i] + 1);
    int t = 6;
    while (i + t <= N) {
      chmin(dp[i + t], dp[i] + 1);
      t *= 6;
    }
    t = 9;
    while (i + t <= N) {
      chmin(dp[i + t], dp[i] + 1);
      t *= 9;
    }
  }
  cout << dp[N] << endl;
  return;
}

signed main() {
  fastio();
  solve();
  //   int t;
  //   cin >> t;
  //   while (t--) solve();
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#include<cmath>
#include<stack>
#include<string.h>
#include <iomanip>
#define rep(i,n) for(int i = 0;i<n;i++)
#define _GLIBCXX_DEBUG
using ll = long long; 
using namespace std;
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() {
    ll N,K;
    cin >> N >> K;
    ll ans = 0;
    for(ll i = K; i <= N+1; i++) {
        ll a = i*(i-1)/2;
        ll b = i*(2*N-i+1)/2;
        ll add = b-a+1;
        ans = (ans+add)%1000000007;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3644
from fractions  import gcd

def lcm(x, y):
  return (x * y) // gcd(x, y)

a, b, c, d = map(int, input().split())

a_num = (a - 1) - ((a - 1) // c + (a - 1) // d - (a - 1) // lcm(c, d))
b_num = b - (b // c + b // d - b // lcm(c, d))

ans = b_num - a_num

print(ans)

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

const int pow10[10] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 };
int N;

string add_next(string s) {
	int len = s.length();
	string comp = string(len, '7');
	int p = 0;
	while (true) {
		if (s == comp) {
			s = string(len + 1, '3');
			break;
		}
		if (s[p] == '7') {
			s[p] = '3';
			++p;
			continue;
		}
		s[p] = (s[p] == '3') ? '5' : '7';
		break;
	}
	return s;
}

int str_num(string s) {
	int len = s.length();
	int sum = 0;
	for (int i = 0; i < len; ++i)
		sum += (int)(s[i] - '0') * pow10[i];
	return sum;
}

bool check_753(string s) {
	int c3, c5, c7;
	c3 = c5 = c7 = 0;
	for (int i = 0; i < (int)s.length(); ++i) {
		if (s[i] == '3')
			++c3;
		else if (s[i] == '5')
			++c5;
		else
			++c7;
		if (c3 != 0 && c5 != 0 && c7 != 0)
			return true;
	}
	return false;
}

int main(void) {
	cin >> N;

	int ans = 0;
	string s = "753";
	while (true) {
		int sn = str_num(s);
		if (((int)s.length() > 9) || (sn > N))
			break;
		if (check_753(s))
			++ans;
		s = add_next(s);
	}

	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        Shi[] shi = new Shi[m];
        for(int i = 0; i<m; i++) {
            shi[i] = new Shi(Integer.parseInt(sc.next()), Integer.parseInt(sc.next()), i);
        }
        Arrays.sort(shi,(ac, bc)->(ac.b-bc.b));

        int cnt[] = new int[n+1];
        String[] strings = new String[m];

        for(int i = 0; i<m; i++) {
            cnt[shi[i].a]++;
            strings[shi[i].index] = String.format("%06d", shi[i].a) + String.format("%06d", cnt[shi[i].a]);
        }
        for(String s: strings) {
            System.out.println(s);
        }

    }
}
class Shi {
    int a,b,index;
    public Shi(int a, int b, int index) {
        this.a = a;
        this.b = b;
        this.index = index;
    }
}

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


long long d[10][10];

void warshall_floyd(long long n){
    for(long long k = 0;k < n;k++){ /*経由する頂点*/
        for(long long i = 0;i < n;i++){ /*始点*/
            for(long long j = 0;j < n;j++){ /*終点*/
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]); /*距離*/
            }
        }
    }
}

int main(){
    long long h, w;
    cin >> h >> w;

    for(long long i = 0; i < 10; i++){
        for(long long j = 0; j < 10; j++){
            cin >> d[i][j];
        }
    }

    warshall_floyd(10);

    long long cost = 0;
    for(long long i = 0; i < h; i++){
        for(long long j = 0; j < w; j++){
            long long a;
            cin >> a;
            if(a != -1) cost += d[a][1];
        }
    }

    cout << cost << endl;
    return 0;
}

Measured memory_bytes: 3604
#include<stdio.h>
#include<string.h>

int main(void)
{
	int i,JOI,IOI;
	char st[10000];
	
	while(scanf("%s",st)!=EOF)
	{
		JOI=0;
		IOI=0;
		for(i=0;i<=strlen(st)-3;i++)
		{
			if(st[i]=='J')
			{
				if(st[i+1]=='O' && st[i+2]=='I') JOI++;
			}
			else if(st[i]=='I')
			{
				if(st[i+1]=='O' && st[i+2]=='I') IOI++;
			}
		}
		printf("%d\n%d\n",JOI,IOI);
	}
	return 0;
}

Measured memory_bytes: 552
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <tuple>
#include <algorithm>
#include <array>
using namespace std;
using ll = long long;
#define rep(i,n) for(decltype(n) i=0; i<n; ++i)
inline constexpr ll Inf = (1ULL << 62) -1;

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

int main() {
    ll x,k,d;
    cin >> x >> k >> d;
    ll ans=0;
    ll s = x>=0 ? 1 : -1;
    ll n = abs(x) / d;
    if (n > k) {
        cout << abs(x - s*d*k) << endl;
        return 0;
    }
    ll p = x - s*d*n;
    ll r = k-n;
    if (r % 2) {
        ans = p - s*d;
    } else {
        ans = p;
    }

    cout << abs(ans) << endl;
    return 0;
}


Measured memory_bytes: 3116
/*
sonu_verma1
*/
#include <bits/stdc++.h>
// For policy based data structure
/*#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> */
using namespace std;
/*using namespace __gnu_pbds; 
typedef tree<int, null_type, less<int>, rb_tree_tag, 
             tree_order_statistics_node_update> 
    new_data_set;*/
 
#define MD 1000000007
#define X first
#define Y second
#define pb push_back
#define debug(val, ch) cout <<val <<ch
#define FOR(i, st, en, ch) for(register int i = (st); i <= (en) ; i += (ch))
#define RFOR(i, st, en, ch) for(register int i = (st); i >= (en) ; i -= (ch))
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
 
typedef long long int ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<int, bool> pib;
typedef pair<bool, int> pbi;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
/*********************************************************************/
void test(int r)
{
	ll n,k;
	cin>>n>>k;
	ll a[n],i,j;
	for(i=0;i<n;i++)
		cin>>a[i];
	vector<int>vis(n+1,0),cn(n+1,0);
	ll c=0,c1,c2;
	j=1;
	ll nd;
	vis[1]=1;
	vector<int>v;
	v.push_back(1);
	for(i=1;;i++)
	{
		int p=a[j-1];
		c++;
		if(vis[p]==1)
		{
			nd=p;
			c1=cn[p];
			c2=c;
			break;
		}
		vis[p]=1;
		v.pb(p);
		j=p;
		cn[p]=c;

	}
	if(k<v.size())
		cout<<v[k];
	else
	{
		k=k-c1;
		ll l=c2-c1;
		k=k%l;
		k=k+c1;
		cout<<v[k];
	}

}
/***********************************************************************/
int main()
{
	fast();
    int t=1,r;
    // cin>>t;
    for(r=1;r<=t;r++)
        test(r);
    return 0;
}

Measured memory_bytes: 7364
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
typedef vector<int> vi;
typedef long long ll;


int main(){
    
    ll N,a[100010],cnt=1;
    cin>>N;
    rep(i,0,N)cin>>a[i];
    int ku=0;
    if(N==1){
        cout<<1<<endl;
        return 0;
    }
    else{
        rep(i,0,N-1){
            if(ku==0 && a[i]<a[i+1]){
                ku=1;
            }
            else if(ku==0&&a[i]>a[i+1]){
                ku=2;
            }
            if(ku==1&&a[i]>a[i+1]){
                ku=0;
                cnt++;
            }
            else if(ku==2&&a[i]<a[i+1]){
                ku=0;
                cnt++;
            }
        }
        
    }
    
    cout<<cnt<<endl;
}




Measured memory_bytes: 1024
#include <bits/stdc++.h>  // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sun Jun 28 20:59:50 JST 2020
 **/

template <class T, class S> T make_vec(S x) { return x; }
template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) {
    return std::vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...));
}

Int D;
constexpr Int K = 26;

signed main() {
    // input
    std::cin >> D;
    std::vector<Int> c(K);
    auto s = make_vec<Int>(D, K, 0);
    REP(i, K) std::cin >> c[i];
    REP(i, D) REP(j, K) std::cin >> s[i][j];

    // hoge
    std::vector<Int> ans(D);
    REP(i, D) { ans[i] = std::max_element(s[i].begin(), s[i].end()) - s[i].begin(); }

    // output
    for (Int x : ans) std::cout << x + 1 << "\n";
    std::cout << std::endl;
}


Measured memory_bytes: 3752
n,m,c=map(int,input().split())
b=list(map(int,input().split()))

count=0
for i in range(n):
  sm=0
  a=list(map(int,input().split()))
  for i in range(m):
    sm+=a[i]*b[i]
  if sm>-c: count+=1
    
print(count)

Measured memory_bytes: 38384
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')

def solve():
    n, m = MI()

    num = [-1] * n
    for i in range(m):
        s, c = MI()
        s -= 1
        if num[s] == -1:
            num[s] = c
        elif num[s] == c:
            continue
        else:
            print(-1)
            return

    # print(num)
    if num[0] == 0:
        if n == 1:
            print(0)
        else:
            print(-1)
        return

    if num[0] == -1:
        if n == 1:
            print(0)
            return
        else:
            num[0] = 1

    ans = ''
    for idx, i in enumerate(num):
        if i == -1:
            ans += '0'
        else:
            ans += str(i)
    print(ans)

if __name__ == '__main__':
    solve()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll n;
  cin>>n;
  vector<ll> a(n);
  vector<ll> b(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
    b[i]=a[i];
  }
  sort(b.begin(),b.end());
  ll memo1=0,memo2=0,count=0;
  for(int i=0;i<n;i++){
    if(a[i]!=b[i]){
      if(count<2){
        if(memo1==0){
          memo1=i;
          count++;
        }
        else {
          memo2=i;
          count++;
        }
      }
      else {
        count++;
        break;
      }
    }
  }
  if(count>2)cout<<"NO"<<endl;
  else {
    if(count==2){
      if(memo1+1==a[memo2]&&memo2+1==a[memo1])cout<<"YES"<<endl;
      else cout<<"NO"<<endl;
    }
    else {
      cout<<"YES"<<endl;
    }
  }
}

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

int main(){
    int a1, a2, a3, tmp;

    cin >> a1 >> a2 >> a3;

    if (a1 > a2){
        tmp = a1;
        a1 = a2;
        a2 = tmp;
    }

    if (a2 > a3){
        tmp = a2;
        a2 = a3;
        a3 = tmp;
    }

    if (a1 > a2){
        tmp = a1;
        a1 = a2;
        a2 = tmp;
    }

    cout << a1;
    cout << " ";
    cout << a2;
    cout << " ";
    cout << a3;
    cout << endl;

    return 0;
}


Measured memory_bytes: 3100
#include <iostream>

using namespace std;

int main(){

  const int NUM = 50100;
  bool prime[NUM];
  prime[0] = false;
  prime[1] = false;
  for(int i=2;i<NUM;i++)
    prime[i] = true;
  for(int i=2;i*i<NUM;i++)
    for(int k=2;i*k<NUM;k++)
      prime[i*k]=false;

  int n,i;
  while(cin>>n){
    for(i=n-1;!prime[i];i--);
    cout << i << " ";
    for(i=n+1;!prime[i];i++);
    cout << i << endl;    
  }
  return 0; 

}

Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define MOD 1000000007

int fact[200010];
int H,W,A,B;

void memo_nCr(){
  fact[0] = fact[1] = 1;
  for(int i = 2; i <= H+W-2; i++){
    fact[i] = i * fact[i-1] % MOD;
  }
}

int inverse(int n){ // MODは素数
  int r = 1;
  for(int m = MOD - 2; m > 0; m >>= 1){
    if(m & 1) r = (r * n) % MOD;
    n = (n * n) % MOD;
  }
  return r;
}

int comb(int n,int r){
  return fact[n]*inverse(fact[r])%MOD*inverse(fact[n-r])%MOD;
}

signed main(){

  cin >> H >> W >> A >> B;
  memo_nCr();
  int ans = 0;
  for(int i = B+1; i <= W; i++){
    ans += comb((H-A-1)+(i-1),H-A-1) * comb((A-1)+(W-i),A-1);
    ans %= MOD;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
<?php
list($n,$a,$b) = explode(" ", trim(fgets(STDIN)));

if($n == 1){
if($a == $b){
echo 1;
}else{
echo 0;
}
}else{
if($a > $b){
echo 0;
}elseif($a == $b){
echo 1;
}else{
$n = $n - 2;
$d = ($b - $a) * $n + 1;
echo $d;
}
}

Measured memory_bytes: 3828
#include <stdio.h>

int main(void){

  int ScoreA,ScoreB;
  int i,j;
  int info,math,scie,eng;


  scanf("%d %d %d %d" ,&info ,&math ,&scie ,&eng);

  ScoreA = info + math + scie + eng;



  scanf("%d %d %d %d" ,&info ,&math ,&scie ,&eng); 
  
  ScoreB = info + math + scie + eng;


  if( ScoreA >= ScoreB ) printf("%d\n" ,ScoreA);
  else printf("%d\n" ,ScoreB);


  return 0;

}

Measured memory_bytes: 588
s = input().split()
intX = int(s[0])
intY = int(s[1])

if (intX > intY / 2) :
    print('No')
    exit()

if ((intY / intX) > 4) :
    print('No')
    exit()

q, mod = divmod(intY, 2)
if (mod == 1) : 
    print('No')
    exit()

intB = (intY-2*intX) / 4
q2, mod2 = divmod(intB, 1)
if (mod == 0) : 
    print('Yes')
    exit()
print('No')

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

int main(){
    int h,w;
    cin>>h>>w;
    string s[h];
    for(int i=0;i<h;i++){
        cin>>s[i];
    }
    for(int i=0;i<h;i++){
        cout<<s[i]<<endl;
        cout<<s[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <deque>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <random>

using namespace std;

void solve() {
    long long n, k;
    cin>>n>>k;
    vector < long long > v(n);
    long long sum = 0;
    for (auto &i : v) {
        cin>>i;
        sum += i;
    }
    long long ans = -1;
    for (long long d = 1; d * d <= sum; d++) {
        if (sum % d != 0)
            continue;
        long long dd = sum / d;
        {
            long long curr = 0;
            long long mx = 0;
            vector < long long > a;
            long long sm = 0;
            for (long long i = 0; i < n; i++) {
                a.push_back(v[i] % dd);
                sm += a.back();
            }
            sort(a.rbegin(), a.rend());
            long long pr = 0;
            curr = sm;
            for (int i = 0; i < n; i++) {
                curr = min(curr, max(i * dd - pr, sm));
                pr += a[i];
                sm -= a[i];
            }
            if (curr <= k) {
                cout << dd << "\n";
                return;
            }
        }
        dd = d;
        {
            long long curr = 0;
            long long mx = 0;
            vector < long long > a;
            long long sm = 0;
            for (long long i = 0; i < n; i++) {
                a.push_back(v[i] % dd);
                sm += a.back();
            }
            sort(a.rbegin(), a.rend());
            long long pr = 0;
            curr = sm;
            for (int i = 0; i < n; i++) {
                curr = min(curr, max(i * dd - pr, sm));
                pr += a[i];
                sm -= a[i];
            }
            if (curr <= k) {
                ans = dd;
            }
        }
    }
    cout<<ans<<"\n";
}

int main() {
    ios::sync_with_stdio(false);
    long long t = 1;
    while (t--)
        solve();
}

Measured memory_bytes: 3672
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from functools import *
from itertools import permutations,combinations,groupby
import sys
import bisect
import string
import math
import time
import random
def Golf():
    *a,=map(int,open(0))
def S_():
    return input()
def IS():
    return input().split()
def LS():
    return [i for i in input().split()]
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def NI(n):
    return [int(input()) for i in range(n)]
def NI_(n):
    return [int(input())-1 for i in range(n)]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def LtoS(ls):
    return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0}):
#h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
    mp=[1]*(w+2)
    found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[1]+[mp_def[j] for j in s]+[1]
    mp+=[1]*(w+2)
    return h+2,w+2,mp,found
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['YES','NO']

mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
#sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()
 
def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

ans=0

n=I()
s=[1 if i=='o' else 0 for i in input()]

# 1 true, 0 lie
def check(y):
    t=[0]*n
    t[0],t[1]=y
    p=t[0]
    for i in range(2,n):
        t[i]=t[i-1]^t[i-2]^s[i-1]
    for i in range(n):
        if s[i]!=t[i-1]^t[i]^t[(i+1)%n]:
            return -1
    return t

for i in range(2):
    for j in range(2):
        ans=check((i,j))
        if ans!=-1:
            ans=''.join(['S' if i==1 else 'W' for i in ans])
            print(ans)
            exit()

print(ans)


Measured memory_bytes: 50428
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <numeric>
//#include<bits/stdc++.h>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;++i)
#define REP(i,s,n) for(int i=(s);i<(n);++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define REPR(i,s,n) for(int i=(s);i>=(n);--(i))
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
const ll mod = 1e9 + 7;
ll dx[4] = { 1,0,-1,0 };
ll dy[4] = { 0,1,0,-1 };

void printvll(vll v) {
	cout << "------------------------------------------------\n";
	rep(i, v.size()) cout << v[i] << " ";
	cout << endl;
	cout << "------------------------------------------------\n";
}
void printvvll(vvll v) {
	cout << "------------------------------------------------\n";
	rep(i, v.size()) {
		rep(j, v[i].size()) {
			cout << v[i][j] << " ";
		}
		cout << endl;
	}
	cout << "------------------------------------------------\n";
}

void prints(string s) {
	cout << "------------------------------------------------\n";
	rep(i, s.size()) cout << s[i] << " ";
	cout << endl;
	cout << "------------------------------------------------\n";
}

void printvs(vs s) {
	cout << "------------------------------------------------\n";
	rep(i, s.size()) {
		rep(j, s[i].size()) {
			cout << s[i][j] << " ";
		}
		cout << endl;
	}
	cout << "------------------------------------------------\n";
}

void Yes(bool x) {
	if (x) cout << "Yes\n";
	else cout << "No\n";
}

void YES(bool x) {
	if (x) cout << "YES\n";
	else cout << "NO\n";
}

void yes(bool x) {
	if (x) cout << "yes\n";
	else cout << "no\n";
}


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

	ll  d, n, m, k, ans = 0, ret = M;
	bool flag = false, flag2 = false;
	string s, t;
	cin >> n >> m >> d;
	vll b(m);
	rep(i, m) cin >> b[i];
	ret = 0;
	rep(i, n) {
		ans = 0;
		rep(j, m) {
			cin >> k;
			ans += b[j]*k;
		}
		//cout << ans << endl;
		if (ans + d > 0) ret++;
	}
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>
#include <regex>
#include <numeric>

#define M_PI       3.14159265358979323846

using namespace std;

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

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

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define MOD 1000000007
#define SQ(x) ((x)*(x))

using edge = PII;
using node = vector<PII>;
using graph = vector<node>;
map<PII, int> idx;
int dp[500005];

int get_index(PII p) {
	if (idx.end() != idx.find(p))return idx[p];
	else return idx[p] = idx.size();
}

int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	int cnt = 0;
	graph g(2*m+n);
	REP(i, n) {
		idx[MP(i, 0)] = idx.size();
	}
	REP(i, m) {
		int p, q, c;
		scanf("%d%d%d", &p, &q, &c);
		p--, q--;
		int u = get_index(MP(p, c));
		int v = get_index(MP(q, c));
		g[u].PB(edge(v, 0));
		g[v].PB(edge(u, 0));
		g[u].PB(edge(p, 0));
		g[p].PB(edge(u, 1));
		g[v].PB(edge(q, 0));
		g[q].PB(edge(v, 1));
	}
	memset(dp, 0x7f, sizeof(dp));
	priority_queue<PII, vector<PII>, greater<PII>> q;
	q.push(MP(0, 0));
	while (!q.empty()) {
		auto tmp = q.top();
		q.pop();
		for (auto e : g[tmp.second]) {
			if (dp[e.first] > tmp.first + e.second) {
				dp[e.first] = tmp.first + e.second;
				q.push(MP(dp[e.first], e.first));
			}
		}
	}
	
	if (dp[n - 1] > n + 5)cout << -1 << endl;
	else cout << dp[n-1] << endl;
}

Measured memory_bytes: 65396
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long;
using llint = long long;
using namespace std;

int main() {
    fastIO;
    int m1, d1, m2, d2;
    cin >> m1 >> d1 >> m2 >> d2;
    if ((m1 + 1 == m2) && (d1 > d2)) {
        cout << 1;
    } else {
        cout << 0;
    }
}

Measured memory_bytes: 3584
// C.

#include <iostream>
#include <sstream>
#include <algorithm>

using namespace std;

typedef long long LL;

int main(int argc, char *argv[]) {
	LL n, k, ans = 0;
	cin >> n >> k;
	for (LL a = 1; a <= n; ++a) {
		if ((a * 2) % k == 0) {
			LL b = k - (a % k);
			LL c = (n - b + k) / k;
			ans += c * c;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
long long int min(long long a,long long b)
{
    return a<b?a:b;
}
int main(void)
{
    long long int n,a[100005]={0},i;
    long long int dp[100005]={0};

    scanf("%lld",&n);

    for(i=0;i<n;i++)
    scanf("%lld",&a[i]);

    dp[0] = 0;
    dp[1] = fabs(a[1] - a[0]);
        for(i=2;i<n;i++)
        {
            dp[i] = min(dp[i-1] + fabs(a[i] - a[i-1]),dp[i-2] + fabs(a[i] - a[i-2]));
        }
    printf("%lld",dp[n-1]);
    return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define int ll
//const ll mod = 1000000007;

int n;

vector<int> enum_divisor(int n) {
    vector<int> divisors;
    for (int i=1;i*i<=n;i++) {
        if (n % i == 0) {
            divisors.push_back(i);
            if (i*i != n) divisors.push_back(n/i);
        }
    }
    sort(divisors.begin(),divisors.end());
    return divisors;
}

signed main() {
    cin >> n;

    int ans = 0;
    for (int i=1;i<=n;i++) {
        if (i%2) {
            if (enum_divisor(i).size() == 8) {
                // cout << i << endl;
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define pb push_back
#define mp make_pair
typedef long long ll;
using namespace std;
typedef pair<int, int> P;



int main()
{
  const int busstop[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
  const int bussize = sizeof(busstop) / sizeof(int);

  int n;
  while (cin >> n) {
    while (n--) {
      int a, b;
      cin >> a >> b;

      int s = 0;
      for (; s < bussize; ++s) {
	if (busstop[s] == a)
	  break;
      }

      vector<int> ans;
      for (int i = s; i < bussize; ++i) {
	ans.push_back(busstop[i]);
	if (busstop[i] == b)
	  break;
      }

      if (1 <= a && a <= 5 && b < a) {
	vector<int> rev;
	for (int i = s; i >= 0; --i) {
	rev.push_back(busstop[i]);
	if (busstop[i] == b)
	  break;
	}
	if (rev.size() < ans.size())
	  ans = rev;
      }

      for (int i = 0; i < ans.size()-1; ++i)
	cout << ans[i] << " ";
      cout << ans.back() << endl;
    }
  }
  return 0;
}

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

typedef long long int ll;
using namespace std; 

string s;
ll ans = 0;

void dfs(ll i, ll sum, ll num){
  if (i == s.size()){
    ans += sum + num;
  } else {
    dfs(i+1, sum, num*10+s.at(i)-'0');
    dfs(i+1, sum+num, s.at(i)-'0');
  }
}


int main() {
  cin >> s;
  dfs(1,0,s.at(0)-'0');
  cout << ans << endl;
}


Measured memory_bytes: 256