akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define REP(i, n) for(decltype(n) i = 0; i < n; i++)

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (long long)1e18 + 1;

class PrimeNumberCalculator {
    using ull = unsigned long long;
public:
    PrimeNumberCalculator(const ull& n_max) :
        list_(generateList(std::sqrt(n_max))) { }

    const std::vector<ull>& getList() const {
        return list_;
    }

    bool check(const ull& n) const {
        ull n_max = std::sqrt(n);
        for(const auto& v : list_) {
            if(n_max < v) {
                break;
            }
            else if(n % v == 0) {
                return false;
            }
        }
        return true;
    }

    std::map<ull, ull> generateDivisionPrimeCntMap(ull n) const {
        std::map<ull, ull> prime_cnt_map;
        ull n_max = std::sqrt(n);
        for(const auto& v : list_) {
            if(n_max < v) {
                break;
            }
            while(n % v == 0) {
                n /= v;
                auto itr = prime_cnt_map.find(v);
                if(itr != prime_cnt_map.end()) {
                    itr->second++;
                }
                else {
                    prime_cnt_map.insert(make_pair(v, 1));
                }
            }
        }
        if(1 < n) {
            prime_cnt_map.insert(make_pair(n, 1));
        }
        return prime_cnt_map;
    }

    ull calcNumOfDivisor(ull n) const {
        ull  num = 1;
        auto map = generateDivisionPrimeCntMap(n);
        for(const auto& v : map) {
            num *= (v.second + 1);
        }
        return num;
    }

    ull calcSumOfDivisor(ull n) const {
        ull sum   = 1;
        auto map = generateDivisionPrimeCntMap(n);
        for(const auto& v : map) {
            ull t     = 1;
            ull t_sum = 1;
            for(ull i = 0; i < v.second; i++) {
                t     *= v.first;
                t_sum += t;
            }
            sum *= t_sum;
        }
        return sum;
    }

private:
    const std::vector<ull> list_;

    std::vector<ull> generateList(const ull& n_max) const {
        std::vector<uint> table(n_max + 1, 0);
        std::vector<ull> list;
        for(ull i = 2; i <= n_max; i++) {
            if(table[i] == 0) {
                list.push_back(i);
                for(uint j = i; j <= n_max; j+=i) {
                    table[j] = 1;
                }
            }
        }
        return list;
    }
};

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

    int N;
    std::cin >> N;
    vector<ll> sum_list(N + 1);
    for(int i = 2; i <= N; i++) {
        PrimeNumberCalculator p(i);
        auto map = p.generateDivisionPrimeCntMap(i);
        for(const auto& v : map) {
            sum_list[v.first] += v.second;
        }
    }

    auto ans = 1;
    for(const auto& v : sum_list) {
        ans = (ans * (v + 1)) % MOD;
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
import math


def read():
    X, K, D = map(int, input().strip().split())
    return X, K, D


def solve(X, K, D):
    X = abs(X)
    k = X // D 
    if K % 2 == 0:
        if k % 2 == 0:
            i = min(X // D, K)
        else:
            i = min(X // D + 1, K)
    else:
        if k % 2 == 0:
            i = min(X // D + 1, K)
        else:
            i = min(X // D, K)
    ans = X - i * D
    return abs(ans)


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


Measured memory_bytes: 9196
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
4 5
4 2
5 2
2 1
8 3

output:
13
"""

import sys
from collections import namedtuple


# def solve():
#     for i, item in enumerate(item_list, 1):
#         for cp in range(1, real_cp + 1):
#             # capacity allows putting in, calculate value
#             if item.w <= cp:
#                 values[i][cp] = max(values[i - 1][cp], values[i - 1][cp - item.w] + item.v)
#             # can't put in, skip current item
#             else:
#                 values[i][cp] = values[i - 1][cp]
#
#     return values[c_items][real_cp]


def solve_2():
    dp = [0] * (real_cp + 1)
    for item in item_list:
        v, w = item.v, item.w
        for cp in range(real_cp - w, -1, -1):
            dp[cp + w] = max(dp[cp + w], dp[cp] + v)

    return dp[-1]


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    c_items, real_cp = map(int, _input[0].split())
    items = map(lambda x: x.split(), _input[1:])

    Item = namedtuple('Item', ('v', 'w'))
    item_list = [Item(int(v), int(w)) for v, w in items]

    # values = [[0] * (real_cp + 1) for _ in range(c_items + 1)]
    ans = solve_2()
    print(ans)

Measured memory_bytes: 8340
#include <bits/stdc++.h>
using namespace std;
#define pb(x) push_back(x)
#define faster ios::sync_with_stdio(false)
#define ll long long int
#define sz 200005
#define mp(x,y) make_pair(x,y) 
#define pii pair<long long int,long long int>
#define tor ::iterator
#define letsgo long long  int i,j,k,q=0,t,tmp,n,flg=0,cntr=0,maxxer = 0
#define fi first
#define se second
#define be begin()
#define en end()
#define mod 1000000007
#define debug(x) cout<<" "<<x<<endl

ll dp[105][100005] ;
ll knapsack(ll i,ll w,ll wt[],ll v[],ll n){
	// cout<<i<<"   "<<w<<"   "<<endl;
	if(i==n)
		return 0;
	if(dp[i][w]!=-1)
		return dp[i][w];
	if( wt[i]<= w){
		dp[i][w] = max(knapsack(i+1,w,wt,v,n)
			,knapsack(i+1,w-wt[i],wt,v,n)+v[i]);
	}
	else 
		dp[i][w] = knapsack(i+1,w,wt,v,n);
	return dp[i][w];
}
int main(){
	faster;
	letsgo; 
	ll w;
	cin>>n>>k>>q;
	for(i=0;i<10;i++){
		cout<<(n*q) - k<<endl;
		q = (n*q) - k;
	}

}

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

using namespace std;
 
typedef long long ll;
#define For(i,x,y) for(int i=x; i<y; ++i)
#define mem(x,y) memset(x,y,sizeof(x))
#define ALL(a) a.begin(),a.end()
#define PII pair<int,int>
#define INF 0x3f3f3f3f
#define DOF 0x7f7f7f7f
#define se second
#define fi first
#define endl '\n'
 
template <typename T>
inline void read(T &r){
    static char c; r=0; int f=1;
    for(c=getchar(); c<'0'||c>'9'; c=getchar()) if(c=='-')f=-1;
    for(; c>='0'&&c<='9'; r=(r<<1)+(r<<3)+(c^48),c=getchar());
    r*=f;
} // -_-

const int N = 2e5 + 105;
ll a[N], pre[N], k;
int main(){
    int n; scanf("%d", &n);
    scanf("%lld", &k);
    pre[0] = 0;
    for(int i = 1; i <= n; ++i){
        scanf("%lld", &a[i]);
        pre[i] = pre[i - 1] + a[i];
    }
    map<ll, int>ma;
    ll ans = 0;
    for(int i = 0; i <= n; ++i){
        if(i >= k){
            ma[(pre[i - k] - (i - k))%k] --;
        }
        if(ma[(pre[i] - i)%k]){
            ans += ma[(pre[i] - i)%k];
        }
        ma[(pre[i] - i)%k] ++;
    }
    cout<<ans<<endl;
    // system("pause");
    return 0;
}

Measured memory_bytes: 15872
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int N = stdIn.nextInt();
        int M = stdIn.nextInt();

        int[] A = new int[N];
        int sum = 0;
        for (int i = 0; i < N; i++) {
            A[i] = stdIn.nextInt();
            sum += A[i];
        }
        stdIn.close();

        int over = 0;
        for (int i = 0; i < N; i++) {
            if ((double)A[i] >= (double)sum / (4 * M)) {
                over++;
            }
        }

        if (over >= M) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 21844
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 20)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね

//ここから編集する


int main() {
    int N,T;
    cin >> N >> T;
    vector<ll> A(N);
    vector<ll> B(N);

    REP(i,0,N){
        cin >> A[i];
    }
    ll min_b = A[0];
    B[1] = min_b;
    REP(i,2,N){
        min_b = min(min_b,A[i-1]);
        B[i] = min_b;
    }
    ll max_m =A[1] - B[1];
    int ans = 1;
    REP(i,2,N){
        if(A[i]-B[i] == max_m){
            ans++;
        }else if(A[i]-B[i] < max_m){
            continue;
        }else{
            ans = 1;
            max_m = A[i]-B[i];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int n,cnt;
int a[110];
int main(){
	cin>>n;
for(int i=1;i<=n;i++){
	cin>>a[i];
	if(i%2==1&&a[i]%2==1){
		cnt++;
	}
}
cout<<cnt;
return 0;
}


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

public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long A;
        A = sc.nextLong();
        long B;
        B = sc.nextLong();

        final Solver solver = new Solver();
        solver.solve(A, B);
    }
}

class Solver {
    public void solve(long A, long B) {
        System.out.println(A * B / lcd(A, B));
    }

    private long lcd(long A, long B) {
        if (B == 0) {
            return A;
        }
        return lcd(B, A % B);
    }
}



Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define for(i, m, n) for(int i = m; i < n; i++)
#define inf 1e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main(){
  int a, b;
  cin >> a >> b;
  cout << max({a+b, a-b, a*b}) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <time.h>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <array>
#include <string>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mp make_pair
#define eb emplace_back
#define F first
#define S second
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> ost;

const ll maxN = 1e7;
const ll INF = 1e17;
const ll MOD = 1e9 + 7;

ll xs[] = {-1, 1, 0, 0, -1, 1, 1, -1};
ll ys[] = {0, 0, -1, 1, -1, 1, -1, 1};

ll segtree[maxN << 2];
ll lazy[maxN << 2];
ll A[maxN];

inline ll left(ll x){
	return x << 1;
}

inline ll right(ll x){
	return (x<<1) + 1;
}

void build(ll node, ll start, ll end){
	if(start == end)
		segtree[node] = A[start];
	else{
		ll mid = (start + end)/2;
		build(left(node), start, mid);
		build(right(node), mid+1, end);
		segtree[node] = segtree[left(node)] + segtree[right(node)];
	}
}

void update(ll node, ll start, ll end, ll l, ll r, ll val){
	if(lazy[node] != 0){
		segtree[node] += (end-start+1)*lazy[node];
		if(start != end){
			lazy[left(node)] += lazy[node];
			lazy[right(node)] += lazy[node];
		}
		lazy[node] = 0;
	}
	if(start > end or l > start or r < end)
		return ;
	else if(start >= l and r >= end){
		segtree[node] += val;
		if(start != end){
			lazy[left(node)] += val;
			lazy[right(node)] += val;
		}
	}
	else{
		ll mid=(start + end)/2;
		update(left(node), start, mid, l, r, val);
		update(right(node), mid+1, end, l, r, val);
		segtree[node] = segtree[left(node)] + segtree[right(node)];
	}
}

ll sums(ll node, ll start, ll end, ll l, ll r){
	if(lazy[node] != 0){
		segtree[node] += (end-start+1)*lazy[node];
		if(start != end){
			lazy[left(node)] += lazy[node];
			lazy[right(node)] += lazy[node];
		}
		lazy[node] = 0;
	}
	if(l > end or r < start or start > end)
		return 0;
	if(l <= start and r >= end)
		return segtree[node];
	ll mid = (start+end)/2;
	return sums(left(node), start, mid, l , r) + sums(right(node), mid + 1, end, l , r);
}

int main(){
	cin.sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin >> n;
	ll a[n];
	ll k = 0;
	for(ll i=0; i<n; i++)
		cin >> a[i];
	sort(a, a+n);
	for(ll i=0; i<n; i++){
		if(a[i] < 0 and a[i+1] <= 0){
			k += -1*(a[i]+a[i+1]);
			i++;
		}
		else if(a[i] < 0 and a[i+1] > 0 and -1*a[i] > a[i+1]){
			k += -1*a[i];
			k += -1*a[i+1];
			i++;
		}
		else
			k += a[i];
	}
	cout << k;
	return 0;
}

Measured memory_bytes: 4348
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef pair<int,int> P;
int const INF=1001001001;
ll const LINF=1001001001001001001;
ll const MOD=1000000007;

ll D;
ll c[26+1];
ll s[365+1][26+1];

ll last[365+1];

void input(){
    cin>>D;
    repn(i,26) cin>>c[i];
    repn(i,D) repn(j,26) cin>>s[i][j];
}

// 貪欲法 62,634,806
void solve1(){
    repn(d,D){
        ll maxi=-LINF;
        ll idx=0;
        repn(i,26){
            ll res=0;
            res+=s[d][i];
            repn(j,26){
                if(i==j) continue;
                res-=c[j]*(d-last[j]);
            }
            if(maxi<res){
                maxi=res;
                idx=i;
            }
        }
        last[idx]=d;
        cout<<idx<<endl;
    }
}

int main(){
    input();
    solve1();
}

Measured memory_bytes: 3736
import java.util.Scanner;

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

        sc.close();

        if (s.equals(t)) {
            System.out.println("Yes");
            return;
        }
        char[] work = s.toCharArray();

        for (int i = 0; i < work.length - 1; i++) {
            StringBuilder sb = new StringBuilder();
            sb.append(work[work.length - 1]);
            sb.append(s.substring(0, s.length() - 1));
            String txt = sb.toString();
            if (txt.equals(t)) {
                System.out.println("Yes");
                return;
            }
            work = txt.toCharArray();
            s = txt;
        }
        System.out.println("No");
    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
//#define MOD 998244353
#define MOD 1000000007

int main(){
    int n,k,c;
    scanf("%d %d %d",&n,&k,&c);
    char s[200010];
    scanf("%s",s);
    int a[200010],b[200010],pos=0;
    rep(i,1,n+1)if(s[i-1]=='o')a[pos++]=i,i+=c;
    pos=0;
    for(int i=n;i>0;i--)if(s[i-1]=='o')b[pos++]=i,i-=c;
    rep(i,0,k)if(a[i]==b[k-i-1])printf("%d\n",a[i]);
}

Measured memory_bytes: 3200
#include <iostream>
#include <algorithm>
#include <vector>

int main()
{
  int n;
  std::cin >> n;
  std::string s;
  std::cin >> s;

  int x = 0;
  int max = 0;
  for (const auto& itr : s)
  {
    if (itr == 'D')
    {
      --x;
    }
    else
    {
      ++x;
    }
    max = std::max(max, x);
  }
  std::cout << max << std::endl;
  return 0;
}

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

public class Main
{
    public static void main(String args[])
    {
        Scanner scn = new Scanner(System.in);
        int a = scn.nextInt();
        int b = scn.nextInt();
        int c = scn.nextInt();
        int x = scn.nextInt();
        int y = scn.nextInt();
        ArrayList<Long> arr = new ArrayList<>();
        arr.add((long) (a * x + b * y));
        long s = 0;
        int q = Math.min(x, y);
        int dif = Math.abs(x - y);
        if (x > y)
        {
            s = 2 * q * c + (x - y) * a;
        }
        else
        {
            s = 2 * q * c + (y - x) * b;
        }
        arr.add(s);
        arr.add((long) (Math.max(x, y) * c * 2));
        Collections.sort(arr);
        System.out.println(arr.get(0));
    }
}


Measured memory_bytes: 23124
from collections import defaultdict

N = int(input())
*A, = map(int, input().split())
INF = 10**20
dp = defaultdict(lambda :-INF)
dp[(0,0,0)] = 0

for i in range(1, N+1):
    for j in range(i//2-1, i//2+2):
        dp[1,i,j] = dp[0,i-1,j-1]+A[i-1]
        dp[0,i,j] = max(dp[1,i-1,j], dp[0,i-1,j])

ans = max(dp[1,N,N//2], dp[0,N,N//2])
print(ans)


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

using namespace std;

#define ll long long

const int mod  = 1e9 + 7;
const ll INF = 1e14;

void solve(){

    int a; cin >> a;
    cout << (a + a*a + a*a*a);

}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    //int test; cin >> test;
    //for(int t = 1; t <= test; ++t){
        solve();    
    //}

	return 0;
}



Measured memory_bytes: 3640
#include <fstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <string>
using namespace std;

#define REP(i,n) for(ll i = 0; i < (n); ++i)

using ll = long long;
using vl = vector<ll>;
int main() {
#ifdef CIN_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(5);
	ll n;
	string x;
	ll d;
	cin >> n >> x >> d;


	string ans;
	REP(i, n){
		if (x[i] == '1'){
			ans.push_back('1');
		}
		else if (x[i] == '0' && d > 0){
			d--;
			ans.push_back('1');
		}
		else{
			ans.push_back('0');
		}
	}

	if (d > 0) {
		for (ll i = n - 1; i >= 0; --i) if (x[i] == ans[i]){
			ans[i] = '0';
			d--;
			if (d == 0) break;
		}
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> void chmax(T& x, U y){if(x<y) x=y;}
template<class T,class U> void chmin(T& x, U y){if(y<x) x=y;}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);

	ll H,W; cin >> H >> W;
	if(H>W) swap(H,W);
	if(W == 1){
		cout << 1 << endl;
		return 0;
	}
	if(H == 1){
		cout << W-2 << endl;
		return 0;
	}
	cout << (H-2)*(W-2) << endl;
}


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

char a[2][100];
vector<int> v;
signed main(){
	int n;
	scanf("%lld", &n);
	scanf("%s%s", a[0], a[1]);
	
	for(int i = 0;i < n;i++){
		if(a[0][i] == a[1][i]){
			v.push_back(1);
		}else{
			v.push_back(0);
			i++;
		}
	}
	
	int ans = (v[0] == 0 ? 6 : 3);
	for(int i = 1;i < v.size();i++){
		if(v[i-1] == 1 && v[i] == 1)ans *= 2;
		if(v[i-1] == 0 && v[i] == 1)ans *= 1;
		if(v[i-1] == 1 && v[i] == 0)ans *= 2;
		if(v[i-1] == 0 && v[i] == 0)ans *= 3;
		ans %= mod;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)

/*
*/

template<int MOD>
struct ModInt {
	static const int Mod = MOD;
	unsigned x;
	ModInt() : x(0) { }
	ModInt(signed sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	ModInt(signed long long sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	int get() const { return (int)x; }

	ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
	ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }

	ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
	ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
	ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
	ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }

	ModInt inverse() const {
		signed a = x, b = MOD, u = 1, v = 0;
		while (b) {
			signed t = a / b;
			a -= t * b; std::swap(a, b);
			u -= t * v; std::swap(u, v);
		}
		if (u < 0) u += Mod;
		ModInt res; res.x = (unsigned)u;
		return res;
	}
};
typedef ModInt<1000000007> mint;

string s;
ll n;
mint dp[13],dp2[13];

void init(){
	cin>>s;
	n=s.size();
	dp[0]=1;
}

int main(void){
	init();
	rep(i,n){
		// cerr<<s[i]<<endl;
		if(s[i]=='?'){
			// cerr<<"???"<<endl;
			rep(j,13){
				rep(k,10)dp2[(j*10+k)%13]+=dp[j];
			}
		}else{
			int k = s[i]-'0';
			// cerr<<"k:"<<k<<endl;
			rep(j,13){
				dp2[(j*10+k)%13]+=dp[j];
			}
		}
		rep(j,13){
			dp[j]=dp2[j];
			dp2[j]=0;
		}
	}
	cout<<dp[5].get()<<endl;
	return 0;
}

Measured memory_bytes: 512
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        char[] S = s.toCharArray();
        char[] T = t.toCharArray();
        Arrays.sort(S);
        Arrays.sort(T);
        for(int i=0;i<=T.length/2-1;i++){
            char temp = T[i];
            T[i] = T[T.length-1-i];
            T[T.length-1-i] = temp;
        }
        String ans = "No";
        int i=0;
        while(i<Math.min(T.length,S.length)){
            if(S[i]<T[i]){
                ans = "Yes";
                break;
            }
            if(S[i]>T[i]){
                break;
            }
            i++;
        }
        if(i==Math.min(T.length,S.length)&&S.length<T.length) ans = "Yes";
        System.out.println(ans);
    }
}

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

using namespace std;
#define ll long long
const long long mod=1e9+7;
const int maxn=1e6+7;

ll fac[maxn*2],inv_fac[maxn*2];

ll quickpow(ll x,ll n){
    ll res=1;
    x=x%mod;
    while(n){
        if(n&1)res=(res*x)%mod;
        n>>=1;
        x=(x*x)%mod;
    }
    return res;
}


void init(){
    fac[0]=1;
    for(int i=1;i<=maxn;i++) fac[i]=(fac[i-1]*i)%mod;
    inv_fac[maxn]=quickpow(fac[maxn],mod-2);
    for(int i=maxn-1;i>=0;i--) inv_fac[i]=(inv_fac[i+1]*(i+1))%mod;
}

ll C(int n,int m){
    if(n < 0 || m < 0 || m > n) return 0;
    if(m == 0 || m == n) return 1;
    return fac[n]*inv_fac[n-m]%mod*inv_fac[m]%mod;
}




int main (){
	init();
	ll n,m;
	cin>>n>>m;
	ll tot = C(m,n)*fac[n]%mod;
	ll flag=1;
	ll tmp=0;
	for(int j=0;j<=n;j++){

		ll zx = C(n,j) *C(m-j,n-j)%mod*fac[n-j]%mod;
		zx*=flag;
		zx+=mod,zx%=mod;
		tmp+=zx,tmp%=mod;
		flag*=-1;

	}
	tmp+=mod,tmp%=mod;
	cout<<tmp*tot%mod<<endl;
	return 0;
}


Measured memory_bytes: 19164
program ABC151D
    implicit none
    integer::H,W
    character(20)::S
    integer,allocatable,dimension(:,:)::maze
    integer,allocatable,dimension(:,:)::Route
    integer::i,j
    integer::ans
    read*,H,W
    allocate(maze(H,W))
    maze=0
    do i=1,H
        read*,S
        do j=1,W
            if(S(j:j)==".")maze(i,j)=1
        end do
    end do
    allocate(Route(point(H,W),point(H,W)))
    Route=1000
    do i=1,W
        if(maze(geti(i),getj(i))==1)then
            Route(i,i)=0
            if(i/=1)then
                if(maze(geti(i),getj(i)-1)==1)then
                    Route(i,i-1)=1
                    Route(i-1,i)=1
                endif
            endif
        endif
    end do
    do i=W+1,H*W
        if(maze(geti(i),getj(i))==1)then
            Route(i,i)=0
            if(geti(i)/=1)then
                if(maze(geti(i),getj(i)-1)==1)then
                    Route(i,i-1)=1
                    Route(i-1,i)=1
                endif
            endif
            if(maze(geti(i)-1,getj(i))==1)then
                Route(i,i-W)=1
                Route(i-W,i)=1
            endif
        endif
    end do
    call Warshall_Floyd(H*W,Route)
    ans=0
    do i=1,H*W
        do j=1,H*W
            if(Route(i,j)/=1000)ans=max(ans,Route(i,j))
        end do
    end do
    print"(i0)",ans
contains
function point(i,j)
    integer::i,j
    integer::point
    point=(i-1)*W+j
end function
function geti(i)
    integer::i
    integer::geti
    geti=(i-1)/W +1
end function
function getj(i)
    integer::i
    integer::getj
    getj=mod(i-1,W)+1
end function
subroutine Warshall_Floyd(n,Route)
  !nは頂点の数、Routeは全ての経路の長さを記録したもの
  !以下の型宣言は場合に応じて変えること
  implicit none
  integer, intent(in) :: n
  integer, intent(inout) :: Route(n, n)
  integer :: i, j, k

    do k = 1, n
      do i = 1, n
        do j = 1, n
          Route(j, i) = min( Route(j, i), Route(j, k) + Route(k, i))
        end do
      end do
    end do
end subroutine Warshall_Floyd
end program ABC151D

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

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define 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 ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    int n, k; cin >> n >> k;
    double res = 0;
    FOR(i, 1, n) {
        if (i < k) {
            res += (1/(double)n) * pow((1/(double)2), ceil(log2(k/(double)i)));
        } else {
            res += (1/(double)n);
        }
    }
    cout.precision(17);
    cout << fixed << res << endl;
    return 0;
}

Measured memory_bytes: 384
# from collections import defaultdict

# N, K = [int(i) for i in input().split()]
# A = [int(i) for i in input().split()]

# d = defaultdict(lambda: -1)
# d[1] = 0
# L = [1]
# i = 0
# k = i
# while i<N:
#     if d[A[k]]==-1:
#         d[A[k]] = i+1
#         L.append(A[k])
#         k = A[k]-1
#     else:
#         p = d[A[k]]
#         q = i+1
#         break
#     i += 1

# L = L[p:]
# print(L[(K-p)%(q-p)])

A, B, C, K = [int(i) for i in input().split()]

res = 0
if (A >= K):
    print(K)
    quit()
elif (A < K):
    K -= A
    res += A

if (B >= K):
    print(res)
    quit()
elif (B < K):
    K -= B

if (C >= K):
    print(res-K)
    quit()


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

int main() {
  string s;
  cin>>s;
  string devide[4]={"dream","dreamer","erase","eraser"};
  reverse(s.begin(),s.end());
  for(int i=0;i<4;i++) reverse(devide[i].begin(),devide[i].end());
  bool can=true;
  for(int i=0;i<s.size();){
    bool can2=false;
    for(int j=0;j<4;j++){
      string d=devide[j];
      if(s.substr(i,d.size())==d){
        can2=true;
        i+=d.size();
      }
    }
    if(!can2){
      can=false;
      break;
    }
  }
  if(can)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}

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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  int n,m;cin>>n>>m;
  vector<int> x(m);
  vector<int> y(m);
  int i;
  rep(i,m)cin>>x[i]>>y[i];
  rep(i,m)
  {
    x[i]--;
    y[i]--;
  }
  vector<int> balls(n,1);
  vector<bool> prob(n,false);
  prob[0]=true;
  rep(i,m)
  {
    balls[x[i]]--;
    balls[y[i]]++;
    if(prob[x[i]])
    {
      prob[y[i]]=true;
    }
    if(balls[x[i]]==0)
    {
      prob[x[i]]=false;
    }
  }
  int ans=0;
  rep(i,n)if(prob[i])ans++;
  cout<<ans<<endl;
}


Measured memory_bytes: 1408
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
)

/*-----------Main-----------*/

func main() {
	x, k, d := readI(), readI(), readI()
	if x < 0 {
		x = -x
	}

	saitank := x / d
	saitank = min([]int{saitank, k})

	saitanp := x - saitank*d

	nokorik := k - saitank

	if nokorik%2 == 0 {
		fmt.Println(saitanp)
		return
	}

	fmt.Println(-(saitanp - d))

}

func roundDiv(a, b int) int {
	return int(math.Round(float64(a) / float64(b)))
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

/*-----------Utilities-----------*/

var sc = bufio.NewScanner(os.Stdin)

func init() {
	if len(os.Args) >= 2 {
		if os.Args[1] == "debug" {
			debug()
		}
	}
	const maxBuf = 200100
	var buf []byte = make([]byte, maxBuf)
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBuf)
}

func debug() {
	testFile, err := os.Open("./test/sample-1.in")
	if err != nil {
		fmt.Fprintln(os.Stderr, "Error : There is no testfile.")
		os.Exit(1)
	}
	sc = bufio.NewScanner(testFile)
}

func readS() string {
	sc.Scan()
	return sc.Text()
}

func readSs(a int) []string {
	b := make([]string, a)
	for i := 0; i < a; i++ {
		b[i] = readS()
	}
	return b
}

func readI() int {
	sc.Scan()
	r, _ := strconv.Atoi(sc.Text())
	return r
}

func readIs(a int) []int {
	b := make([]int, a)
	for i := 0; i < a; i++ {
		b[i] = readI()
	}
	return b
}

func readF() float64 {
	sc.Scan()
	r, _ := strconv.ParseFloat(sc.Text(), 64)
	return r
}

func readFs(a int) []float64 {
	b := make([]float64, a)
	for i := 0; i < a; i++ {
		b[i] = readF()
	}
	return b
}

func max(a []int) int {
	l := len(a)
	m := a[0]
	for i := 1; i < l; i++ {
		if a[i] > m {
			m = a[i]
		}
	}
	return m
}

func min(a []int) int {
	l := len(a)
	m := a[0]
	for i := 1; i < l; i++ {
		if a[i] < m {
			m = a[i]
		}
	}
	return m
}

func sortI(a []int) []int {
	sort.Ints(a)
	return a
}

func reverse(a []int) []int {
	l := len(a)
	r := make([]int, l)
	for i := 0; i < l; i++ {
		r[i] = a[l-i-1]
	}
	return r
}

func countI(a []int, b int) int {
	l := len(a)
	var c int
	for i := 0; i < l; i++ {
		if a[i] == b {
			c++
		}
	}
	return c
}


Measured memory_bytes: 1784
N, M = map(int, input().split())
mod = int(1e9) + 7

g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + M + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

# 組み合わせ(1e9+7で割る場合)
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

# 順列(1e9+7で割る場合)
def pmt(n, r, mod):
    if (r < 0 or r > n):
        return 0
    return cmb(n, r, mod) * g1[r] % mod

if __name__ == "__main__":
    ans = 0
    for i in range(N+1):
        if i % 2 == 1:
            ans -= cmb(N, i, mod) * pmt(M, i, mod) * (pmt(M - i, N - i, mod))**2 % mod
        else:
            ans += cmb(N, i, mod) * pmt(M, i, mod) * (pmt(M - i, N - i, mod))**2 % mod
    print(ans % mod)

Measured memory_bytes: 215404
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cstdio>
using namespace std;
int main(){
	int n,m;
	int dist[100001];
	scanf("%d %d\n",&n,&m);
	memset(dist,0,sizeof(dist));
	int sumDist=0;
	int cp=1;
	int t,dd;
	int movingDistance=0;
	for(int i = 1; i <= n; i++){
		dist[i]=sumDist;
		if(i==n)
			break;
		scanf("%d",&t);
		sumDist+=t;
	}
	for(int i = 0; i < m; i++){
		scanf("%d",&dd);
		cp+=dd;
		movingDistance+=abs(dist[cp]-dist[cp-dd]);
		movingDistance%=100000;
	}
	printf("%d\n",movingDistance%100000);
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int x[4] = {0, 1,0,-1};
int y[4] = {1, 0,-1,0};
int h, w;
char s[8][8];
bool dfs(int a,int b){
    rep(k, 2)
    {
        int ny = a + y[k], nx = b + x[k];
        if (!(0 <= ny && ny < h) || !(0 <= nx && nx < w))
            continue;
        if (s[ny][nx] == '#')
        {
            s[ny][nx] = '.';
            if(dfs(ny, nx))return true;
            else return false;
        }
    }
    bool flag = true;

    rep(ci, h)
    {
        rep(cj, w)
        {
            if (s[ci][cj] == '#')
                flag = false;
        }
    }
    return flag;
}
int main()
{
    cin >> h >> w;
    rep(i, h)
    {
        rep(j,w){
            cin >> s[i][j];
        }
    }
    s[0][0] = '.';
    if (dfs(0,0))
    {
        cout << "Possible" << endl;
        return 0;
    }
    cout << "Impossible" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n ;
int dp[1000005];
int a[1000005]; 
int k0 ; 
int dpf(int r)
{

	if(r<0)
		return INT_MAX/2;
	if(r==0)
		return 0 ;
	if(dp[r]!=-1)
		return dp[r];
	else
	{
		int k = INT_MAX;
		int temp ;
		for(int i = 1 ; i <= k0 ; ++i)
		{
			//k = INT_MAX;
			if(r-i<0)
				break ; 
			temp = abs(a[r]-a[r-i]) + dpf(r-i);
			k = min(temp,k);

		}
		return dp[r] = k ;
	}
}
int main()
{
	cin >> n ;
	cin >> k0 ;
	fill(dp,dp+1000005,-1); 
	for(int i = 0 ; i <n ; ++i)cin >> a[i];
	cout << dpf(n-1);	

}

Measured memory_bytes: 12672
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, gcd, lcm 
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <vector> // vectors
#include <string> // string
#include <queue> // queue
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <unordered_map> // hashed by keys
#include <iomanip>
#define _for(i,n) for(int i = 0; i < (int) n; i++)

typedef long long ll; // at least int64 > 9*10^18
typedef unsigned long long ull; // at least uint64

int main() {
  long double n;
  long double k;
  std::cin >> n >> k;
  long double winrate_sum = 0;
  for (long double i = 1;i <= n; i++) {
    long double c = 0;
    while(pow(2,c)*i<k) {
      c++;
    }
    winrate_sum+=(long double)1/((long double)pow(2,c)*n);
  }
  std::cout<<std::setprecision(10)<<winrate_sum<<std::endl;

  return 0;
}

Measured memory_bytes: 256
import sys

def f(x):
    p=0
    cnt=0
    for i in range(n-1,-1,-1):
        while p<n and a[i]+a[p]<x:
            p+=1
        cnt+=n-p
    return cnt

n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()

l,r=a[0]*2,a[n-1]*2
md=(r+l)//2
while r-l>0:
    if r-l<=1:
        if f(r)==m: md=r;break 
        else: md=l;break
    md=(r+l)//2
    k=f(md)
    if k==m: break
    elif k>m: l=md
    else: r=md

p=0
cnt=0
ans=0

for q in range(n-1,-1,-1):
    try:
        while p<n and a[q]+a[p]<=md:
            p+=1
    except:
        b=1
        while True:
            b+=1

    if p==n: break
    cnt+=n-p
    ans+=a[q]*(n-p)*2


ans+=(m-cnt)*md
print(ans)


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

int main() {
  
  int64_t N; cin >> N;
  
  int64_t MOD = 1000000007;
  
  if (N == 1) { cout << 0 << endl; return 0; }
  
  int64_t whole = 1, rest = 1, notInclude = 1;
  
  for (int i = 0; i < N; i++) {
    
    whole *= 10; whole %= MOD;
    
    rest *= 8; rest %= MOD;
    
    notInclude *= 9; notInclude %= MOD;
    
  }
  
  notInclude *= 2; notInclude %= MOD;
  
  int64_t ans = (whole + rest) % MOD - notInclude;
  
  ans %= MOD;
  
  if (ans < 0) ans += MOD;
  
  cout << ans << endl;
  
}

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

using namespace std;

using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using PIL = pair<int, LL>;
using PLL = pair<LL, LL>;
// const int mod = 1e9 + 7;

#define mem(a, b) memset(a, b, sizeof(a))
#define REP(i, a) for (int i = 0; i < a; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(a) a.begin(), a.end()

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
}

inline void print_vector(vector<int> &A){
    for (auto&& x : A){
        cout << x << " ";
    }
    cout << endl;
}

inline void print_array(const int A[], int n) {
    REP(i, n) {
        cout << A[i] << " ";
    }
    cout << endl;
}

inline void solve() {
    int n, m;

    cin >> n >> m;

    int h[n+1];

    for (int i = 1; i <= n; i++) {
        cin >> h[i];
    }
    // print_array(h, n);
    unordered_map<int, set<int>> nei;
    int start, end;
    for (int i = 0; i < m; i++) {
        cin >> start >> end;
        nei[start].insert(end);
        nei[end].insert(start);
    }

    int res = 0;

    for (int i = 1; i <= n; i++) {
        if (nei[i].empty()) res++;
        else {
            bool good = true;
            for (auto&& n : nei[i]) {
                // cout << i << " " << n << " " << h[i] << " " << h[n] << endl;
                if (h[i] <= h[n]) {
                    good = false;
                    break;
                }
            }
            if (good) res++;
        }
    }

    cout << res << endl;
}

int main() {
    // freopen("input.txt", "r", stdin);
    quickread();
    int t = 1;
    // cin >> t;

    for (int _ = 0; _ < t; _++) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 21848
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
char a;
cin >> a;
if(a=='A') {
  cout << "T" << endl;
} else if(a=='T') {
  cout << "A" << endl;
} else if(a=='C') {
  cout << "G" << endl;
} else if(a=='G') {
  cout << "C" << endl;
}
return 0;
}


Measured memory_bytes: 256
N, W = map(int, input().split())
w = [0] * N
v = [0] * N
for i in range(N):
    w[i], v[i] = map(int, input().split())
dp = [[0] * (W + 1) for _ in range(N + 1)]
for i in range(N):
    for sum_w in range(W + 1):
        if sum_w - w[i] >= 0:
            dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w - w[i]] + v[i])
        dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w])
print(dp[N][W])

Measured memory_bytes: 120684
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
#include<bitset>

#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000

using namespace std;

int main(void) {
	int n;
	int p;
	cin >> n;

	FOR(i, 1, 10e7) {
		if (n <= (i*i + i) / 2) {
			p = i;
			break;
		}
	}
	RFOR(i, p, 1) {
		if (n - i >= 0) {
			cout << i << endl;
			n -= i;
		}
		if (n == 0) {
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;  
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define Rep(i, a, b) for(ll i = a; i <= b; i++)
#define repr(i, a, b) for(ll i = b-1; i >= a; i--)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
// const ll INF = 1LL << 60;
const ll INF = 100000000000;
#define pp pair<ll, pair<ll, ll>> 
// #define fi first
// #define se second

void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif          // -D_DEBUG をつけて実行 cf)可変引数
 
// rep(i, 0, sz(v)) cout << v[i] << " \n"[i==sz(v)-1];
 
////////////////////////////////////////////////////////

ll MAXR = 1000001;

//MAXR(=10^5)までの整数が素数であると仮定する
vector<ll> PN_chk(MAXR+1,1);//0indexでi番目が整数iに対応(0~MAXR)

//素因数分解で出てきた素数を全て挿入する
// vector<ll> prime;

//O(MAXR)
void se(){
    ll MAXRR=sqrt(MAXR)+1;
    //2以上の数の素因数分解をするので無視して良い
    PN_chk[0]=0;PN_chk[1]=0;
    Rep(i,2,MAXRR){
        //たどり着いた時に素数と仮定されているなら素数
        //ある素数の倍数はその素数で割り切れるのでマークづけ
        if(PN_chk[i]==1) Rep(j,i,ll(MAXR/i)){PN_chk[j*i]=i;}
    }
}

//O(logn)
set<ll> prime;
//primeはこの場合は整列されてないので注意！！！
void prime_factorize(ll n){
    if(n<=1) return;
    //1の場合はnは素数
    if(PN_chk[n]==1){prime.insert(n);return;}
    //マークされている数は素数
    prime.insert(PN_chk[n]);
    //マークされている数でnを割った数を考える
    prime_factorize(ll(n/PN_chk[n]));
}

ll b[1000005];

int main() {
	se();
	ll n; cin >> n;
	Vl a(n);
	rep(i, 0, n) cin >> a[i];

	rep(i, 0, n){
		prime.clear();
		prime_factorize(a[i]);
		for(auto it : prime) b[it]++;
	}
	// Rep(i, 1, 6) co(i << " " << b[i]);
	int f = 1;
	Rep(i, 1, 1000000){
		if(b[i] == n){
			f = 3;
			break;
		}
		if(b[i] >= 2) f = 2;
	}
	if(f == 1) co("pairwise coprime");
	else if(f == 2) co("setwise coprime");
	else if(f == 3) co("not coprime");

    return 0;
}

Measured memory_bytes: 26744
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a7=1000000007;
ll inf=100000000000000000;

int main()
{
  ll a,b;
  cin>>a>>b;
  if(a>=1&&a<=9&&b>=1&&b<=9){
    cout<<a*b<<endl;
  }
  else{
    cout<<-1<<endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <map>
#include <queue>
#include <cmath>
#include <iomanip>
#include <functional>

#define MOD (1000000007)

using namespace std;

typedef long long ll;
typedef pair<ll, ll> tup;
const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];


ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

map<ll,ll> prime;//素因数分解でそれぞれの素数がいくつ出てきたかを保存するmap

//O(√n)
//整列済み(mapはkeyで自動で整列される)
void prime_factorize(ll n){
    if(n<=1) return;
    ll l=sqrt(n);
   for(ll i=2;i<=(ll)(l);i++) { //
        if(n%i==0){
        prime_factorize(i);prime_factorize(ll(n/i));return;
        }
    }
    //mapでは存在しないkeyの場合も自動で構築される
    prime[n]++;return;
}



vector<ll> A;

bool next() {
    vector<ll> cumsum(A.size()+1, 0);
    for(ll i = 0; i < A.size(); i++) {
        //確認
        ll left = max(i - A[i], (ll)0);
        ll right = min(i + A[i]+1, (ll)A.size());
        cumsum[left]++;
        cumsum[right]--;
    }
    
    ll sum = 0;
    bool all_max = true;
    for(ll i = 0; i < A.size(); i++) {
        sum += cumsum[i];
        A[i] = sum;
        if(A[i] < A.size()) all_max = false;
    }   

    return all_max;
}
int main() {
    ll N, K;
    cin >> N >> K;

    A.assign(N, 0);
    for(ll i = 0; i < N; i++) {
        cin >> A[i];
    }

    bool all_max = false;
    for(ll i = 0; i < K; i++) {
        all_max = next();
        if(all_max == true) break;
    }

    for(ll i = 0; i < N; i++) {
        if(all_max == true) cout << A.size() << " ";
        else cout << A[i] << " ";
    }

    

    return 0;    
}



Measured memory_bytes: 6336
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] bridge = new int[n + 1];
        for (int i = 0; i < m; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            bridge[a]++;
            bridge[b]++;
        }
        for (int i = 1; i < n + 1; i++) {
            System.out.println(bridge[i]);
        }
        sc.close();
    }
}

Measured memory_bytes: 22996
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    W = [SS() for _ in range(N)]

    ans = 'Yes'
    for i in range(N - 1):
        if W[i][-1] != W[i+1][0]:
            ans = 'No'
            break

    if len(set(W)) < len(W):
        ans = 'No'

    print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 10056
n = int(input())

def dfs(num, cnt):
  if num > n: return 0
  str_num = str(num)
  ret = 0
  if ('7' in str_num) and ('5' in str_num) and ('3' in str_num):
    ret = 1
  
  ret += dfs(int(str_num + '7'), cnt)
  ret += dfs(int(str_num + '5'), cnt)
  ret += dfs(int(str_num + '3'), cnt)
  return ret
ans = dfs(0,0)
print(ans)

Measured memory_bytes: 3064