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

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vii vector<vi>

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int gcd(int a,int b){
  int r=a%b;
  while(r>0){a=b;b=r;r=a%b;}
  return b;
}


const ll INF = 1LL << 60;



int main(){
  int n; cin >> n;
  vi a(n); for(auto &x:a) cin >> x;
  int ans = a[0];

  for (int i = 1; i < n; i++) {
    ans = gcd(ans,a[i]);
  }

  std::cout << ans << '\n';
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>

int w, h;
int xs, ys, xg, yg;
int cs;

bool isOK = false;

void calc(int (&field)[101][101], int x, int y){

	field[x][y] = -1;

	if (x == xg&&y == yg)isOK = true;

	if (x < w - 1 && field[x + 1][y] == cs)calc(field, x + 1, y);
	if (x > 0 && field[x - 1][y] == cs)calc(field, x - 1, y);
	if (y < h - 1 && field[x][y + 1] == cs)calc(field, x, y + 1);
	if (y > 0 && field[x][y - 1] == cs)calc(field, x, y - 1);

}

int main(){

	while (std::cin >> w >> h){

		if (w == 0 && h == 0)break;

		std::cin >> xs >> ys >> xg >> yg;

		xs--, ys--, xg--, yg--;

		int n;
		std::cin >> n;

		int field[101][101];
		for (int i = 0; i < 100; i++){
			for (int j = 0; j < 100; j++){
				field[i][j] = 0;
			}
		}

		for (int i = 0; i < n; i++){
			int c, d, x, y;
			std::cin >> c >> d >> x >> y;

			x--, y--;

			if (d == 0){
				for (int j = y; j < y + 2; j++){
					for (int k = x; k < x + 4; k++){
						field[k][j] = c;
					}
				}
			}
			if (d == 1){
				for (int j = y; j < y + 4; j++){
					for (int k = x; k < x + 2; k++){
						field[k][j] = c;
					}
				}
			}
		}

		cs = field[xs][ys];

		calc(field, xs, ys);

		if (cs != 0 && isOK)std::cout << "OK" << std::endl;
		else std::cout << "NG" << std::endl;

		isOK = false;
	}
	return 0;
}

Measured memory_bytes: 1212
#include<bits/stdc++.h>
using namespace std;
using ll=long long;

int main()
{
    double A,B;
    cin >> A >> B;
    double tax_8=0.08;
    double tax_10=0.1;
    double B_o=B/tax_10;
    double A_o=A/tax_8;
    //cout << A_o << " " << B_o;
    if(A_o<B_o){
        if((int)(B_o*tax_8)==A)cout << B_o << endl;
        else cout << "-1" << endl;
    }
    else if(A_o==B_o)cout << A_o << endl;
    else{
        if((int)A_o<A_o)A_o=int(A_o+1);
        if((int)(A_o*tax_10)==B)cout << A_o << endl;
        else cout << "-1" << endl;
    }
}

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

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

	set<int> outputs;
	int a, i = 1;
	cin >> a;

	while (outputs.find(a) == outputs.end()) {
		outputs.insert(a);
		if (a % 2) a = 3 * a + 1;
		else a = a / 2;
		++i;
	}

	cout << i << "\n";

	return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9 + 7;

int main() {
  ll n, ans = 1;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    ans *= i;
    ans %= INF;
  }

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


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORR(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)

#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl
#define PRINT(x) cout << x << endl
#define all(x) x.begin(),x.end()

int main() {
    string s;
    cin >> s;
    if(s[2]==s[3]&&s[4]==s[5]) cout << "Yes" << endl;
    else cout << "No" << endl;

}



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


const int MAX_V = 204;
const int INF = 1e9;

struct edge {
    int to, cap, rev;
};

vector<edge> G[MAX_V];
bool used[MAX_V];

void add_edge(int from, int to, int cap) {
    G[from].push_back((edge){to, cap, G[to].size()});
    G[to].push_back((edge){from, 0, G[from].size() - 1});
}

int dfs(int v, int t, int f) {
    if (v == t) return f;
    used[v] = true;
    for (int i = 0; i < G[v].size(); i++) {
        edge &e = G[v][i];
        if (!used[e.to] && e.cap > 0) {
            int d = dfs(e.to, t, min(f, e.cap));
            if (d > 0) {
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

int max_flow(int s, int t) {
    int flow = 0;
    for (;;) {
        memset(used, 0, sizeof(used));
        int f = dfs(s, t, INF);
        if (f == 0) return flow;
        flow += f;
    }
}

int main() {
    int X, Y, E;
    cin >> X >> Y >> E;
    
    int s = 201;
    int t = 202;
    for (int i = 0; i < E; i++) {
        int x, y;
        cin >> x >> y;
        add_edge(x, y+100, 1);
    }

    for (int i = 0; i < X; i++) {
        add_edge(s, i, 1);
    }
    for (int i = 0; i < Y; i++) {
        add_edge(i+100, t, 1);
    }

    cout << max_flow(s, t) << endl;

    return 0;
}


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int n,k,ans;
int main()
{
	scanf("%d%d",&n,&k);
	ans=k;
	for(int i=1;i<=n-1;++i)
	ans=ans*(k-1);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()
#define all(arr) arr.begin(), arr.end()

using namespace std;
typedef long long ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

void Main() {
  Cin(string, s);
  int mmax = 0;

  int tmp = 0;
  for (auto e : s) {
    if (e == 'A' || e == 'C' || e == 'G' || e == 'T')
      tmp++;
    else
      tmp = 0;
    mmax = max(mmax, tmp);
  }

  cout << mmax << endl;
}

int main() {
  cout << fixed << setprecision(15);
  Main();
  return 0;
}

Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
  console.log(Number(input) >= 30 ? 'Yes' : 'No');
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29676
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> P(m);
    vector<int> Y(m);
    vector<vector<int>> YS(n + 1);
    for (int i = 0; i < m; i++) {
        cin >> P[i] >> Y[i];
        YS[P[i]].push_back(Y[i]);
    }
    for (int i = 0; i <= n; i++) {
        if (!YS[i].empty()) {
            sort(YS[i].begin(), YS[i].end());
        }
    }
    for (int i = 0; i < m; i++) {
        int ord = lower_bound(YS[P[i]].begin(), YS[P[i]].end(), Y[i]) - YS[P[i]].begin() + 1;
        cout << setfill('0') << right << setw(6) << P[i];
        cout << setfill('0') << right << setw(6) << ord << endl;
    }

    return 0;
}


Measured memory_bytes: 7808
N = int(input())
A = list(map(int,input().split()))

dp = [[[0] for j in range(2)] for i in range(N-1)]
dp[0][0] = sum(A)
A_ = A.copy()
A_[0] = A_[0]*-1
A_[1] = A_[1]*-1
dp[0][1] = sum(A_)

for i in range(1, N-1):
  dp[i][0] = max(dp[i-1][0],dp[i-1][1])
  cg1 = (A[i]+A[i+1])*2
  cg2 = (-A[i]+A[i+1])*2
  dp[i][1] = max(dp[i-1][0]-cg1,dp[i-1][1]-cg2)
  
print(max(dp[N-2][0],dp[N-2][1]))

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

int main() {
  unsigned long long n=0,a=2,b=1,ans=0;
  cin >> n;
  
  unsigned long long tmp=0;
  
  for (unsigned long long i=2; i<=n; i++) {
    tmp = a;
    a = b;
    b = tmp + a;
  }
  
  cout << b << endl;
}

Measured memory_bytes: 256
n = int(input())
l = []
for _ in range(2):
    a = list(map(int,input().split()))
    l.append(a)

if n == 1:
    print(l[0][0]+l[1][0])
    exit()

m1 = []
m2 = []
m1.append(0)
m1.append(l[0][0])
m2.append(0)
m2.append(l[1][0])

for i in range(1,n):
    m1.append(m1[i]+l[0][i])
    m2.append(m2[i]+l[1][i])

ans = [0]*n
for j in range(1,n+1):
    ans[j-1] = m1[j]+(m2[n]-m2[j-1])


print(max(ans))

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

int main() {
  int W, H, N;
  cin >> W >> H >> N;
  vector<int> x(N), y(N), a(N);
  for(int i=0; i<N; i++) cin>>x[i]>>y[i]>>a[i];
  int graph[110][110] = {0};
  for(int k=0; k<N; k++) {
    switch(a[k]) {
      case 1:
        for(int i=x[k]-1; i>=0; i--)
          for(int j=0; j<H; j++)
            graph[i][j]=1;
        break;
      case 2:
        for(int i=x[k]; i<W; i++)
          for(int j=0; j<H; j++)
            graph[i][j]=1;
        break;
      case 3:
        for(int i=0; i<W; i++)
          for(int j=y[k]-1; j>=0; j--)
            graph[i][j]=1;
        break;
      case 4:
        for(int i=0; i<W; i++)
          for(int j=y[k]; j<H; j++)
            graph[i][j]=1;
        break;
      defalt:
        break;
    }
  }
  int count=0;
  for(int i=0; i<W; i++)
    for(int j=0; j<H; j++)
      if(graph[i][j]==0) count++;

  cout << count << endl;
  /*
  for(int j=H-1; j>=0; j--) {
    for(int i=0; i<W; i++) cout<<graph[i][j]<<' ';
    cout<<endl;
  }
  */
  return 0;
}


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

using namespace std;

#define TRUE 1
//#define WAIT cout<<flush,system("pause");
#define oo 100010

int arr[oo];
int lea[oo];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	int N, T, a,l;
	
	cin >> N >> T;
	memset(arr,0,T);
	memset(lea,0,T);
	
	for(int i=0;i<N;i++){
		cin >> a >> l;
		arr[a]++;
		lea[l]++;
	}
	
	int maxi,total=0;
	for(int i=0;i<T;i++){
		total+=arr[i]-lea[i];
		maxi=max(maxi,total);	
	}
	
	cout << maxi << endl;
	//WAIT
}



Measured memory_bytes: 3940
program abc133c

   implicit none

   integer(8) :: L, R, i, j , skip
   integer :: ans, calc_mod

   read(*,*) L, R

   ans = 2018
   R = min(R, L+2019)

   do i = L, R-1
      do j =i+1, R

         calc_mod = mod(i*j,2019)
         if (ans > calc_mod ) then
            ans = calc_mod
            !if (ans == 0) goto 999  ! 0になったら打ち切る
         else
            cycle
         end if
      enddo
   enddo
999 continue

   print *, ans


end program abc133c


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size();
    int ans = 0;
    for(int i=0; i<n/2; i++){
        if(s[i] != s[n-i-1]){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
D = int(input())
c = list(map(int,input().split()))
m = sum(c)
S = []
d = []
ans = 0
for i in range(D) :
    s = list(map(int,input().split()))
    S.append(s)
for i in range(D) :
    t = int(input())
    d.append(t)
    ans += S[i][t-1]
    for j in range(26) :
        if j+1 not in d :
            ans -= c[j] * (i+1)
        else :
            a = [k for k, x in enumerate(d) if x == j+1 ]
            ans -= c[j] * (i-a[-1])
    print(ans)


    




Measured memory_bytes: 9384
from collections import defaultdict, deque

def resolve():
    n, m = map(int, input().split())
    aisle = defaultdict(list)
    for _ in range(m):
        a, b = map(int, input().split())
        aisle[a - 1].append(b - 1)
        aisle[b - 1].append(a - 1)

    d = deque()
    d.append(0)

    room_depths = [-1] * 100010
    room_depths[0] = 0
    room_inds = [-1] * 100010

    # BFS
    while d:
        room = d.popleft()
        for next_room in aisle[room]:

            # 隣接する頂点で、まだ数字が書かれていない頂点に、現在の頂点の数字+1を書く
            if room_depths[next_room] == -1:
                d.append(next_room)
                room_depths[next_room] = room_depths[room] + 1
                room_inds[next_room] = room + 1

    print('Yes')
    for i in range(1, n):
        print(room_inds[i])
        
resolve()

Measured memory_bytes: 45164
//Dragon_warrior7(IITK)
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 1000000000000000000
#define pll pair<ll, ll> 
#define ull unsigned ll
#define vll vector<ll> 
#define rub cout << "\n------------------------------------\n"
#define deb(x) cout<<#x<<' '<<'='<<' '<<x<<'\n'
//typedef  tree < int ,  null_type ,  greater<int> ,  rb_tree_tag ,  tree_order_statistics_node_update > oset;
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
}
// const int mod=1e9+7;
// ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// ll modInverse(ll a){return power(a,mod-2);}
ll n,m,a,b,c,k,temp,x,y;
void solveforthiscase(const int & test)
{//deb(test);
set<char> s;
string str;
cin>>str;
for(int i=0;i<str.size();i++)
s.insert(str[i]);
if(s.size()==1)
cout<<"No";
else
cout<<"Yes";






return ;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
// 	cin>>test;
    for(int i=1;i<=test;i++)
    {
        solveforthiscase(i);
    }
}

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

int main() {
    int N, M;
    cin >> N >> M;

    vector<pair<int, int>> itv(M);
    rep(i, M) cin >> itv[i].second >> itv[i].first;

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

    int ans = 0, now = 0;
    rep(i, M) {
        if (now <= itv[i].second) {
            ans++;
            now = itv[i].first;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    vector<ll> v(n);
    for (auto &&i : v) scanf("%lld", &i);
    for (int i = 0; i < n; ++i) {
        if(v[i] == 0) {
            puts("0");
            return 0;
        }
    }
    __uint128_t x = 1;
    for (int i = 0; i < n; ++i) {
        x *= v[i];
        if(x > 1'000'000'000'000'000'000){
            puts("-1");
            return 0;
        }
    }
    cout << u64(x) << "\n";
    return 0;
}

Measured memory_bytes: 4048
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
 
  if (S.at(0) != S.at(1)) {
    cout << "Yes" << endl;
  }
  else if (S.at(1) != S.at(2)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    string s;
    cin >> s;
    int ans = 700;
    for(char c: s)
        if (c == 'o')
            ans += 100;
    cout << ans << endl;
    return 0;
}



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

typedef long long ll;

const ll MOD = 998244353;
ll N;
vector<pair<ll, ll>> Points;
map<tuple<ll, ll, ll>, ll> Count;
map<ll, ll> InvNC2;
vector<ll> Pow;
ll R;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll pow_multi(ll n) { return (Pow[n] + MOD - n - 1) % MOD; }
int main() {
  cin >> N;
  for (ll i = 0; i < N; ++i) {
    ll x, y;
    cin >> x >> y;
    Points.push_back(make_pair(x, y));
  }
  for (ll i = 0; i < N; ++i)
    for (ll j = i + 1; j < N; ++j) {
      ll x, y, x2, y2;
      tie(x, y) = Points[i];
      tie(x2, y2) = Points[j];
      ll dx = x2 - x, dy = y2 - y;
      // line ax+by=c, a>=0 or a==0 and b>0, a and b are coprime
      ll a = dy, b = -dx;
      if (a < 0 || (a == 0 && b < 0)) {
        a *= -1;
        b *= -1;
      }
      ll g = gcd(abs(a), abs(b));
      assert(a >= 0 || (a == 0 && b > 0));
      a /= g;
      b /= g;
      ll c = a * x + b * y;
      assert(c == a * x2 + b * y2);
      ++Count[make_tuple(a, b, c)];
    }
  for (ll i = 2; i <= N; ++i) InvNC2[i * (i - 1) / 2] = i;
  Pow.resize(N + 1);
  Pow[0] = 1;
  for (ll i = 1; i <= N; ++i) Pow[i] = 2 * Pow[i - 1] % MOD;
  R = pow_multi(N);
  for (const auto &linecount : Count) {
    ll k = InvNC2.at(linecount.second);
    (R += MOD - pow_multi(k)) %= MOD;
  }
  cout << R << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=505,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    vector<int> A((1<<N));
    for(int i=0;i<(1<<N);i++) cin>>A[i];
    for(int i=0;i<N;i++){
        vector<int> to;
        for(int i=0;i+1<si(A);i+=2){
            if(A[i]==A[i+1]) to.push_back(A[i]);
            else to.push_back(abs(A[i]-A[i+1]));
        }
        A=to;
    }
    cout<<A[0]<<endl;
}



Measured memory_bytes: 4908
#include <iostream>
#include <string>

using namespace std;

char swap(char,char,char);

int main(){
	string a;
	char init ='A';
	while(cin >> a){
		//string a;
		//cin >> a;
		init = swap(init,a[0],a[2]);
	}
	cout << init << endl;
}

char swap(char now, char pos1, char pos2){
	if(now == pos1){
		return pos2;
	}
	else if(now == pos2){
		return pos1;
	}
	else{
		return now;
	}
}

Measured memory_bytes: 0
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
//#define int long long
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define mod 1000000007
#define LL long long
const int maxnodes=1005;

 
 
int32_t main()
{
    IOS;
    
    int k;
    cin>>k;
    vector<int> dist(k,1000000000);
    dist[1] = 1;
    deque<int> q;
    q.push_front(1);
    while(!q.empty())
    {
    	int p = q.front();
    	q.pop_front();
    	if(dist[(p*10)%k] > dist[p])
    	{
    		dist[(p*10)%k] = dist[p];
    		q.push_front((p*10)%k);
    	}
    	if(dist[(p+1)%k] > dist[p] + 1)
    	{
    		dist[(p+1)%k] = dist[p] + 1;
    		q.push_back((p+1)%k);
    	}
    }
    cout<<dist[0];
    return 0;
}


Measured memory_bytes: 896
N,K= gets.split.map(&:to_i)
A = gets.split.map(&:to_i).sort
F = gets.split.map(&:to_i).sort.reverse
max_time = A.map.with_index{|a,i| a * F[i]}.max

puts (0...(max_time+100)).bsearch{|x|
  k = K
  N.times do |i|
    next if A[i] * F[i] <= x
    k -= A[i] - (x / F[i])
    break if k < 0
  end
  k >= 0
}

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

int main()
{
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	int ans=0;
	for(int i=0;i<n-1;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			ans+=a[i]*a[j];
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = null;
		PrintStream out = null;
		try {
			sc = new Scanner(System.in);
			out = System.out;
			exec(sc, out);
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		} finally {
			if(out != null) {
				out.close();
			}
			if(sc != null) {
				sc.close();
			}
		}
		System.exit(0);
	}
	public static void exec(final Scanner sc, final PrintStream out) throws Exception{
		final String S = sc.next();
		if(S.equals("Sunny")) {
			out.println("Cloudy");
			return;
		}
		if(S.equals("Cloudy")) {
			out.println("Rainy");
			return;
		}
		if(S.equals("Rainy")) {
			out.println("Sunny");
			return;
		}

	}

}


Measured memory_bytes: 21844
class Facts

  def initialize(mod=10**9+7, n_max=1)
    @mod = mod
    @n_max = n_max
    @fact = [1, 1]
    @inv = [0,1]
    @factinv = [1, 1]
    setup_table(n_max) if 1 < @n_max
  end

  def cmb(n,r)
    return 0 if r < 0 || n < r
    setup_table(n) if @n_max < n
    @fact[n] * (@factinv[r] * @factinv[n-r] % @mod) % @mod
  end

  def factorial(n)
    setup_table(n) if @n_max < n
    @fact[n]
  end

  def prm(n,k)
    setup_table(n) if @n_max < n
    @fact[n] * @factinv[n-k] % @mod
  end

  private
    # O(t)
    def setup_table(t)
      (@n_max+1).upto(t) do |i|
        @fact.push( @fact[-1] * i % @mod )
        @inv.push( -@inv[@mod % i] * (@mod / i) % @mod )
        @factinv.push( @factinv[-1] * @inv[-1] % @mod )
      end
      @n_max = t
    end
end

x, y = gets.to_s.split.map{|t|t.to_i}

a =    2 * x -  y 
b =   - x + 2 * y 
 
ans = 0
if a % 3 == 0 and b % 3 == 0
  a = a / 3
  b = b / 3
  ans = Facts.new.cmb(a+b, a)
end

print(ans)

Measured memory_bytes: 19564
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int row[7],col[7];
char a[7][7];
int main()
{
    FASTINOUT;
    int r,c,k,black=0,ans=0;
    cin>>r>>c>>k;
    for (int i=0; i<r; i++)
    {
        for (int j=0; j<c; j++)
        {
            cin>>a[i][j];
            if (a[i][j]=='#')
            {
                row[i]++;
                col[j]++;
                black++;
            }
        }
    }
    for (int i=0; i<(1<<r); i++)
    {
        int sum=0;
        vector<int>pos;
        for (int j=0; j<r; j++)
        {
            if ((i & (1 << j)) != 0)
            {
                sum+=row[j];
                pos.push_back(j);
            }
        }
        for (int j=0; j<(1<<c); j++)
        {
            int sum2=0;
            for (int m=0; m<c; m++)
            {
                if ((j & (1 << m)) != 0)
                {
                    sum2+=col[m];
                    for (auto kl:pos)
                    {
                        if (a[kl][m]=='#')
                            sum2--;
                    }
                }
            }

            /*cout<<sum<<endl;
            cout<<sum2<<endl;
            cout<<endl;*/
            if (black-(sum+sum2)==k)
                ans++;
        }
    }
    cout<<ans;
    return 0;
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int h, n;
    cin >> h >> n;
    vector<int> a(n);
    int sum = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        sum += a[i];
    }
    if (sum >= h) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 640
//?????????????????????????????????????????????
using System;

namespace DefaultNamespace
{
	/// <summary>
	/// Description of Class1.
	/// </summary>
	public class Class1
	{		
		public static void Main(String[] args)
		{				
			var listA=new listArray();
			listA.start();
			listA.finish();
		}			
	
	}

	public class listArray
	{
		public int first=0;
		public int last=0;
		public int[] list=new int[1000000];
		
		public void start()
		{
			int n = int.Parse(Console.ReadLine());
			for(int i=0;i<n;i++)
			{
				string com=Console.ReadLine();
				string[] command=com.Split();
				switch (command[0])
				{
					case "insert":
						insert(int.Parse(command[1]));
						break;
					case"deleteFirst":
						deleteFirst();
					
						break;
					case"deleteLast":
						deleteLast();
										
						break;
					case "delete":
						delete(int.Parse(command[1]));
						break;				
				}
			}
		}
		
		public void insert(int val)
		{
			list[first]=val;//first?????¨????????????first-1????????????????????\??£?????????
			first++;
		}
		public void deleteFirst()
		{
			first--;
			while(list[first-1]==-1)
			{
				first--;
			}
		}
		public void deleteLast()//last???????????\??£????????????
		{
			last++;
			while(list[last]==-1)
			{
				last++;
			}
		}
		public void delete(int val)
		{
			for(int j=first-1;j>=last;j--)
			{
				if(list[j]==val)
				{
					list[j]=-1;//?????????????????????-1???????????????
					while(list[first-1]==-1)
					{
						first--;
					}
					while(list[last]==-1)
					{
						last++;
					}
					return;
				}
			}
			return;
		}
		public void finish()
		{
				for(int k=first-1;k>last;k--)
			{
				if(list[k]!=-1)
				{
					Console.Write(list[k]+" ");
				}				
			}			
				Console.WriteLine(list[last]);	
		}	
	}	
}

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

int main() {
    int N, Q;
    string S;
    cin >> N >> S >> Q;
    vector<set<int>> al(26,set<int>({(int)1e9}));
    rep(i,S.size()){
        int index = S[i] - 'a';
        al[index].insert(i);
    }
    rep(_,Q){
        int q;
        cin >> q;
        if(q == 1){
            int i;
            char q;
            cin >> i >> q;
            i--;
            al[S[i]-'a'].erase(i);
            al[q-'a'].insert(i);
            S[i] = q;
        } else {
            int l,r;
            cin >> l >> r;
            --l;
            int ans = 0;
            rep(al_i,26){
                if(al[al_i].empty()) continue;
                int lid = *al[al_i].lower_bound(l);
                int rid = *al[al_i].lower_bound(r);
                if(rid > lid) ans++;
            }
            cout << ans << endl;
        }
    }
}


Measured memory_bytes: 24196
gets
*a = gets.chomp.split.map(&:to_i).sort { |a, b| b <=> a }
before = 0
count = 0
v = 0
h = 0

a.each do |x|
  if before == x
    count += 1
  else
    count = 1
    before = x
  end

  if count >= 2
    h = v
    v = x
    count -= 2
  end
  break if !h.zero? && !v.zero?
end

puts h * v


Measured memory_bytes: 11032
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [input() for _ in range(n)]

import math

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


x,y = map(int ,input().split())

print(lcm(x,y))


Measured memory_bytes: 9148
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
using namespace std;
int mod = 1e9 + 7;
template <class T>
void inputV(vector<T> &x, int n){
  for(int i=0; i<n; i++) cin >> x[i];
}
const int maxsize = 200010;
long long int fac[maxsize], finv[maxsize], inv[maxsize];
void init() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for(int i=2; i<maxsize; 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 int nCk(int n, int k, int mod){
  if( n < k ) return 0;
  if(n<0 || k<0) return 0;
  return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}

int main() {
  int h, w, a, b;
  cin >> h >> w >> a >> b;

  init();
  long long int ans = 0;
  for(int i=b; i<w; i++){
    long long int x = nCk(h-a-1+i, i, mod);
    long long int y = nCk(a-1+w-1-i, w-1-i, mod);
    ans += (x * y)%mod;
    ans %= mod;
  }
  cout << ans << endl;


  return 0;
}




//


Measured memory_bytes: 4992
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;

int n;
int activ[100005][4];
int DP[100005][4];

int main(){
    scanf("%d", &n);
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= 3; j++) scanf("%d", &activ[i][j]);
    }
    for(int i = 1; i <= n; i++){
        DP[i][1] = activ[i][1] + max(DP[i-1][2], DP[i-1][3]);
        DP[i][2] = activ[i][2] + max(DP[i-1][1], DP[i-1][3]);
        DP[i][3] = activ[i][3] + max(DP[i-1][2], DP[i-1][1]);
    }
    printf("%d", max(DP[n][1], max(DP[n][2], DP[n][3])));
    return 0;
}


Measured memory_bytes: 3328
cnt_a = [0] * 100001

N, K = [int(n) for n in input().split()]
for n in range(N):
  a, b = [int(i) for i in input().split()]
  cnt_a[a] += b

cnt = 0
for n in range(100001):
  cnt += cnt_a[n]
  if cnt >= K:
    print(n)
    import sys
    sys.exit(0)

Measured memory_bytes: 5740
def resolve():
    from scipy.sparse.csgraph import floyd_warshall
    import sys
    def input(): return sys.stdin.readline().rstrip()
    n, m, l = map(int, input().split())
    inf = float("inf")
    ar = [[0] * n for _ in range(n)]
    for _ in range(m):
        a, b, c = map(int, input().split())
        ar[a - 1][b - 1] = c
    x = floyd_warshall(ar, directed=False)
    br = [[0] * n for _ in range(n)]
    for i in range(n):
        for j in range(i + 1, n):
            if x[i, j] <= l:
                br[i][j] = 1
    y = floyd_warshall(br, directed=False)
    q = int(input())
    for _ in range(q):
        s, t = map(int, input().split())
        print(int(y[s - 1, t - 1]) - 1 if y[s - 1, t - 1] < inf else -1)


if __name__ == "__main__":
    resolve()


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

using namespace std;

using int64 = long long;
const int64 INF = 1LL << 60;

vector< vector< int64_t > > get_combination(int N) {
  vector< vector< int64_t > > mat(N + 1, vector< int64_t >(N + 1));
  for(int i = 0; i <= N; i++) {
    for(int j = 0; j <= i; j++) {
      if(j == 0 || j == i) mat[i][j] = 1;
      else mat[i][j] = mat[i - 1][j - 1] + mat[i - 1][j];
    }
  }
  return (mat);
}

int main() {
  int N, A, B;
  int64 V[50];
  cin >> N >> A >> B;
  map< int64, int > sz;
  for(int i = 0; i < N; i++) {
    cin >> V[i];
    sz[V[i]]++;
  }
  sort(V, V + N, greater< int64 >());
  int64 sum = 0, choose = 0, ret = 0;
  auto c = get_combination(N);
  for(int i = 0; i < B; i++) {
    if(i >= A && V[i] != V[0]) {
      break;
    }
    if(V[A - 1] == V[i]) {
      ++choose;
    }
    if(i < A) {
      sum += V[i];
    }
    if(i + 1 >= A) {
      ret += c[sz[V[A - 1]]][choose];
    }
  }
  cout << fixed << setprecision(10) << 1.0 * sum / A << endl;
  cout << ret << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <random>
#include <ctime>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx2")
#define ll long long
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define pll pair<ll,ll>
#define ld long double
#define pld pair<ld,ld>
#define pii pair<int,int>
#define sqr(a) ((a)*(a))
#define all(v) v.begin(),v.end()

using namespace std;
//using namespace __gnu_pbds;

const ll MOD = 1e9+7;
const ll INF=1e18;
const ld E=1e-8;
mt19937_64 rnd(time(0));
ll p1 = 31, p2 = 29, p3 = 7, p4=rnd()%100+1, md1 = MOD, md2 = 998244353, md3=998244357, md4=rnd()%1000000000;

//using ord_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

ll n, m, k, h, T;
pii b[300001];

ll binpow(ll h, ll r, ll md = MOD)
{
    ll l = 1;
    while (r)
    {
        if (r & 1) l *= h, l %= md;
        h *= h;
        h %= md;
        r /= 2;
    }
    return l;
}

ll gcd(ll x, ll y)
{
    if (x < y) swap(x, y);
    while (x && y)
    {
        x %= y;
        swap(x, y);
    }
    return x + y;
}

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //freopen("capitals.in","r",stdin);
    //freopen("capitals.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    ll o=1, tt=0;
    for (int i = 1; i <= n; i++)
    {
        ll x;
        cin >> x;
        if (x==0)
        {
            cout << "0\n";
            return 0;
        }
        if (!tt &&  o>INF/x) {tt=1;}
        if (!tt) o*=x;
    }
    if (tt) cout << "-1\n"; else
    cout << o;
    return 0;
}

/*
4
1 4 3 6
3
1 2 3
4
6 3 4 1
*/


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

int main() {
  int N;
  string s;
  cin >> N;
  N = (N%100)%10;
  if (N == 3) s = "bon";
  else if (N == 0 || N == 1 || N == 6 || N == 8) s = "pon";
  else s = "hon";
  
  cout << s << endl;
}

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

using namespace std;
typedef long long ll;

// #define DEBUG

const int INTMAX = 2 * 1e9 + 10;
const int NMAX = 2 * 1e3;

struct material
{
    int v;
    int w;
    char t;
    ll d;
    string s;
};

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    int n, v, w;
    char t;
    cin >> n;
    material a[n];
    ll d;
    string s;
    for (int i = 0; i < n; i++)
    {
        cin >> v >> w >> t >> d >> s;
        a[i].v = v;
        a[i].w = w;
        a[i].t = t;
        a[i].d = d;
        a[i].s = s;
    }
    sort(a, a + n, [](auto const &left, auto const &right) {
        if (left.v != right.v)
            return left.v < right.v;
        else if (left.w != right.w)
            return left.w < right.w;
        else if (left.t != right.t)
            return left.t < right.t;
        else if (left.d != right.d)
            return left.d < right.d;
        else if (left.s != right.s)
            return left.s < right.s;
        return true;
    });

    for (int i = 0; i < n; i++)
    {
        cout << a[i].v << " " << a[i].w << " " << a[i].t << " " << a[i].d << " " << a[i].s << endl;
        ;
    }
    return 0;
}


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

int main() {
    int n, tmp;
    cin >> n;
    cout << (tmp = n) << ":";
    for(int i = 2; i * i < n; ++i) {
        while(!(tmp % i)) {
            tmp /= i;
            cout << " " << i;
        }
    }
    if(tmp != 1) cout << " " << tmp;
    cout << endl;
}

Measured memory_bytes: 1164
n, lx = map(int, input().split())
x = list(map(lambda x: x-lx, list(map(int, input().split()))))
def gcm(a, b) :
  while(b) :
    a, b = b, a%b
  return a
for i in range(n-1) :
  x[i+1] = gcm(x[i], x[i+1])
print(abs(x[-1]))

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

main() {
  int K, S, cnt;
  vector<int> num;
  cin >> K >> S;
  cnt = 0;
  rep(i, K + 1) num.push_back(i);
  rep(X, K + 1) rep(Y, K + 1) {
    int Z = S - X - Y;
    if (binary_search(num.begin(), num.end(), Z)) cnt++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'

typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;
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; }
const Int INF = (1<<20);

int main(){
    int k,x;cin >> k >> x;
    if(k*500>=x) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main(){
  string s;
  cin >> s;
  int s1, s2;
  s1 = stoi(s.substr(0, 2));
  s2 = stoi(s.substr(2));
  if(s1 <= 12 && s1 > 0 && s2 <= 12 && s2 > 0){
    cout << "AMBIGUOUS" << endl;
  } else if (s1 <= 12 && s1 > 0) {
    cout << "MMYY" << endl;
  } else if (s2 <= 12 && s2 > 0) {
    cout << "YYMM" << endl;
  } else {
    cout << "NA" << endl;
  }
}

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

typedef long long ll ;
#define rep (i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	int a, b, c;
	
	cin >> a >> b >> c;

	//int a[100];
	if ( a == b )
	{
		if (a == c)
		{
			cout << 1 << endl;
		}
		else
		{
			cout << 2 << endl;
		}
	}
	else 
	{
		if (a == c)
		{
			cout << 2 << endl;
		}
		else if (b == c)
		{
			cout << 2 << endl;
		}
		else
		{
			cout << 3 << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N, D;
  cin >> N >> D;
  vector<vector<int>> xs(N, vector<int>(D));
  F0R(i, N) {
    F0R(j, D) {
      cin >> xs[i][j];
    }
  }

  int result = 0;
  F0R(i, N) {
    FOR(j, i + 1, N) {
      int d = 0;
      F0R(k, D) {
        int a = xs[i][k] - xs[j][k];
        d += a * a;
      }
      int s = sqrt(d);
      if (s * s == d) {
        result++;
      }
    }
  }
  cout << result;
}
#endif


Measured memory_bytes: 3672
#include<iostream>
using namespace std;
int main(){
       int a,b,c, flag=0;
       cin>>a>>b>>c;
       if(a==b && b!=c)
              flag=1;
        if(b==c && c!=a)
              flag=1;
         if(a==c && a!=b)
              flag=1;
         if(flag==1)
               cout<<"Yes";
         else
               cout<<"No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=(1<<20)+10;
ll dp[N],ans;
int mat[N],n;
void solve(int l,int r,int lab) {
	if (l==r) return;
	int md=(l+r)>>1;
	solve(l,md,lab*2);
	solve(md+1,r,lab*2+1);
	rep(i,l,md+1) {
		int cc=mat[i]+(1<<(n-1));
		ll mul=1;
		int d=i+(1<<(n-1));
		while (d!=lab) {
			mul=mul*d%mod;
			d=d/2;
		}
		while (cc>1) {
			mul=(mul*cc)%mod;
			dp[cc]=(dp[cc]+mul)%mod;
			cc/=2;
		}
	}
	rep(i,md+1,r+1) {
		int cc=mat[i]+(1<<(n-1));
		ll mul2=1;
		int d=i+(1<<(n-1));
		while (1) {
			mul2=mul2*d%mod;
			if (d==lab) break;
			d=d/2;
		}
		mul2=mul2*cc%mod;
		while (cc>1) {
			mul2=mul2*(cc/2)%mod;
			ans=(ans+mul2*dp[cc^1])%mod;
			cc/=2;
		}
	}
	rep(i,l,md+1) {
		int cc=mat[i]+(1<<(n-1));
		while (cc>1) {
			dp[cc]=0;
			cc/=2;
		}
	}

}

int main() {
	scanf("%d",&n);
	rep(i,0,1<<(n-1)) scanf("%d",mat+i),--mat[i];
	solve(0,(1<<(n-1))-1,1);
	printf("%lld\n",ans);
}


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

int main(){
  int n; cin >> n;
  int count=0;
  if(n<10){
    count = n;
  }else{
    count = 9;
  }
  if(n>99){
  if(99<n && n<1000){
    count += n-99;
  }else{
    count += 900;
  }
  }
  if(n>9999){
    if(9999<n && n<100000){
    count += n-9999;
  }else{
    count += 90000;
  }
  }
  cout << count << endl;
}
  

Measured memory_bytes: 256
#import <stdio.h>
#import <limits.h>
#define MIN(a,b) ((a)<(b)?(a):(b))
int q(int *n, int m){
    int r = *n/m;
    *n -= m*r;
    return r;
}
int main(){
    int n;
    scanf("%d",&n);
    int result = INT_MAX;
    for(int i=0;i<=n;i++){
        int I = i;
        int N = n-i;
        int count = 0;
        count += q(&I, 59049);
        count += q(&I, 6561);
        count += q(&I, 729);
        count += q(&I, 81);
        count += q(&I, 9);
        
        N += I;

        count += q(&N, 46656);
        count += q(&N, 7776);
        count += q(&N, 1296);
        count += q(&N, 216);
        count += q(&N, 36);
        count += q(&N, 6);
        
        count += N;
        
        result = MIN(result,count);
    }
    printf("%d", result);
}


Measured memory_bytes: 7120
#include <cstdio>
#include <vector>
#include <numeric>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;

class unionfind {
private:
	int size_;
	std::vector<int> parent;
	std::vector<int> rank;
public:
	unionfind() : size_(0), parent(std::vector<int>()), rank(std::vector<int>()) {};
	unionfind(int size__) : size_(size__), parent(std::vector<int>(size_)), rank(std::vector<int>(size_, 0)) {
		std::iota(parent.begin(), parent.end(), 0);
	}
	int size() { return size_; }
	int root(int x) {
		if (parent[x] == x) return x;
		return parent[x] = root(parent[x]);
	}
	bool same(int x, int y) {
		return root(x) == root(y);
	}
	void unite(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return;
		if (rank[x] < rank[y]) parent[x] = y;
		else if (rank[x] > rank[y]) parent[y] = x;
		else parent[y] = x, rank[x]++;
	}
};

int W, H, N, x[40009], y[40009], tx[100009], ty[100009], cnt[40009];
int main() {
	scanf("%d%d%d", &N, &W, &H);
	fill(tx, tx + W, -1);
	fill(ty, ty + H, -1);
	bool flag = false;
	unionfind uf(N);
	for (int i = 0; i < N; i++) {
		scanf("%d%d", &x[i], &y[i]); x[i]--, y[i]--;
		if (x[i] == 0 || y[i] == 0 || x[i] == W - 1 || y[i] == H - 1) flag = true;
		if (tx[x[i]] != -1) uf.unite(tx[x[i]], i); tx[x[i]] = i;
		if (ty[y[i]] != -1) uf.unite(ty[y[i]], i); ty[y[i]] = i;
	}
	for (int i = 0; i < N; i++) cnt[uf.root(i)]++;
	int comp = 0;
	for (int i = 0; i < N; i++) {
		if (cnt[i]) comp++;
	}
	int ret = N + comp - 1;
	if (comp == 1 || flag) ret--;
	printf("%d\n", ret);
	return 0;
}

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

int main(){
    int N;
    cin >> N;

    vector<int> a(N);
    for (int i = 0; i < N; i++){
        cin >> a.at(i);
    }

    int flag = 1;

    for (int i = N - 2; i > 0; i--){
        if (a.at(i) > a.at(i + 1) && a.at(i) - a.at(i + 1) == 1){
            a.at(i) -= 1;
        }
        else if (a.at(i) > a.at(i + 1) && a.at(i) - a.at(i + 1) != 1) {
            flag = 0;
            break;
        }
    }

    if (flag == 1){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int main(){
    int l,a,b,c,d;
    cin >> l >> a >> b >> c >> d;
    int ans = 0;
    while(true){
	ans++;
	if(c*ans >= a && d*ans >= b){
	    break;
	}
    }
    ans = l - ans;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
#define mp make_pair
using namespace std;
using ll=long long;
using P=pair<int,int>;
const ll INF=1LL<<30;
const ll LINF=1LL<<61;
const double eps=1e-5;
const ll MOD=1e9+7;
ll dp[110][100010];
int main(){
    int n;cin>>n;
    int W;cin>>W;
    vector<ll> w(n+10),v(n+10);
    for(int i=1;i<=n;i++)cin>>w[i]>>v[i];
    for(int i=0;i<=n;i++)for(int j=0;j<=W;j++)dp[i][j]=-LINF;
    dp[0][0]=0;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=W;j++){
            if(j>=w[i]){
                dp[i][j]=max(dp[i][j],dp[i-1][j-w[i]]+v[i]);
            }
            dp[i][j]=max(dp[i][j],dp[i-1][j]);
        }
    }
    ll ans=0;
    for(int i=0;i<=W;i++)ans=max(ans,dp[n][i]);
    cout<<ans<<endl;
}   


Measured memory_bytes: 80128
/*
(1)for binary shift operator always use 'LL' 1LL<<63

*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set_pair tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_multiset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
  const double  pi=3.1415926535; 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll a;cin>>a;
	ll i,j,sum=0;
	for(i=2;i*i<=a;i++){
		ll c=0;
		while(a%i==0){
			a/=i;
			c++;
		}
		for(j=1;j*(j+1)<=2*c;){
			j++;
		}
		sum+=j-1;
	}
	if(a>1) sum++;
	cout<<sum;
	return 0;
} 


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int INF = 1e15;

struct WeightedUnionFind{
    vector<int> par;
    vector<int> sz;
    vector<int> diff_weight;
    WeightedUnionFind(int n){
        par.resize(n);
        sz.resize(n, 1);
        diff_weight.resize(n);
        for(int i = 0; i < n; i++) par[i] = i;
    }
    int root(int x){
        if(x == par[x]) return x;
        int r = root(par[x]);
        diff_weight[x] += diff_weight[par[x]];
        return par[x] = r;
    }
    int weight(int x){
        root(x);
        return diff_weight[x];
    }
    int diff(int x, int y){
        return weight(y) - weight(x);
    }
    bool unite(int x, int y, int w){
        w += weight(x) - weight(y);
        x = root(x); y = root(y);
        if(x == y) return false;
        if(sz[x] < sz[y]) swap(x, y), w = -w;
        sz[x] += sz[y];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }
    bool same(int x, int y){
        return root(x) == root(y);
    }
};

signed main(){
    int n, m;
    while(cin >> n >> m, n){
        WeightedUnionFind uf(n);
        rep(i, 0, m){
            char c;
            int x, y, w;
            cin >> c >> x >> y;
            x--; y--;
            if(c == '!'){
                cin >> w;
                uf.unite(x, y, w);
            }else{
                if(!uf.same(x, y)){
                    cout << "UNKNOWN" << endl;
                }else{
                    cout << uf.diff(x, y) << endl;
                }
            }
        }
    }   
}


Measured memory_bytes: 5248