akhauriyash/Code-Regression huggingface dataset:
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "
#define  E  2.71828182845904523536
#define pb push_back
#define pp pop_back
#define valid(nx,ny) nx>=0 && nx<n && ny>=0 && ny<m
#define ee endl
#define pii pair<int,int>
#define infinity 10000000000000000
#define mod 1000000007
int fx[]={0,0,+1,-1};
int fy[]={+1,-1,0,0};

using namespace std;
///check n=1;
///check corner case;
const int maX=1e5+1;
vector<ll>Graph[maX],cost[maX];
ll visit[maX];


int main()
{
   char ch;cin>>ch;cout<<++ch<<endl;
return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
#define LL long long
#define clr(x,y) memset(x,y,sizeof(x))
#define FOR(x,l,r) for(int x=l,x##_=r;x<=x##_;x++)
#define FR(x,l,r) for(int x=l,x##_=r;x<x##_;x++)
#define DOR(x,r,l) for(int x=r,x##_=l;x>=x##_;x--)
using namespace std;
const int N=300005;
int n,A[N],B[N];
int main() {
	cin>>n;
	FOR(i,1,n)scanf("%d",A+i),B[i]=A[i];
	sort(B+1,B+n+1);
	FOR(i,1,n)
		if(A[i]==B[n])printf("%d\n",B[n-1]);
		else printf("%d\n",B[n]);
	return 0;
}

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

uint32_t bit_count(uint32_t bits) {
  bits = (bits & 0b01010101010101010101010101010101) +
         (bits >> 1 & 0b01010101010101010101010101010101);
  bits = (bits & 0b00110011001100110011001100110011) +
         (bits >> 2 & 0b00110011001100110011001100110011);
  bits = (bits & 0b00001111000011110000111100001111) +
         (bits >> 4 & 0b00001111000011110000111100001111);
  bits = (bits & 0b00000000111111110000000011111111) +
         (bits >> 8 & 0b00000000111111110000000011111111);
  return (bits & 0b00000000000000001111111111111111) +
         (bits >> 16 & 0b00000000000000001111111111111111);
}

int main() {
  uint32_t N = 0, M = 0;
  std::cin >> N >> M;
  std::vector<uint32_t> switch_mask(M, 0);
  for (size_t m = 0; m < M; m++) {
    uint32_t k = 0;
    std::cin >> k;
    for (size_t c = 0; c < k; c++) {
      uint32_t s = 0;
      std::cin >> s;
      switch_mask[m] += (static_cast<uint32_t>(1) << (s - 1));
    }
  }
  uint32_t correct_pattern = 0;
  for (size_t m = 0; m < M; m++) {
    uint32_t p = 0;
    std::cin >> p;
    correct_pattern = (correct_pattern << 1) + p;
  }

  uint32_t count = 0;
  for (size_t sw = 0; sw < (static_cast<uint32_t>(1) << N); sw++) {
    uint32_t pattern = 0;
    for (size_t m = 0; m < M; m++)
      pattern = (pattern << 1) + bit_count(sw & switch_mask[m]) % 2;
    count += (pattern == correct_pattern);
  }

  std::cout << count << std::endl;

  return 0;
}

Measured memory_bytes: 256
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
#pragma GCC optimize("unroll-loops")
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stdio.h>
#include <fstream>
#include <cmath>
#include <stdlib.h>
#include <iomanip>
#include <algorithm>
#include <limits.h>
#include <stack>
using namespace std;
#define FAST_IO ios::sync_with_stdio(false);
#define DEBUG_VIS(x) cerr<<"vis "<<x<<endl;
#define DEBUG_REACH cerr<<"reach here"<<endl;
#define DEBUG_SEQ(x) cerr<<x<<" ";
#define SET_ZERO(x) memset(x,0,sizeof(x));
#define SET_NEGONE(x) memset(x,-1,sizeof(x));
#define SET_INF(x) memset(x,127,sizeof(x));
#define SET_NEGINF(x) memset(x,128,sizeof(x));
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef pair<double,double> pdd;
typedef long long ll;
typedef unsigned int uint;
const int maxn = 1e6 + 10;
template <class T> T mymin(const T a,const T b){return a < b ? a : b;}
template <class T> T mymax(const T a,const T b){return a > b ? a : b;}
int N;
vector<ll> v;
ll max(ll a,ll b,ll c,ll d){
    return max(max(a,b),max(c,d));
}
ll min(ll a,ll b,ll c,ll d){
    return min(min(a,b),min(c,d));
}
int main(){
    FAST_IO
    cin>>N;
    v.assign(2 * N + 1,0);
    for(int i = 1; i <= N; i++) cin>>v[i];
    for(int i = 1; i <= N; i++) v[i] += v[i - 1];
    ll ans = __LONG_LONG_MAX__; 
    int j = 1, k = 3;
    for(int i = 2; i <= N - 1; i++){
        k = max(i + 1,k);
        while(j + 1 < i && v[j + 1] < v[i] - v[j + 1]) j++;
        while(k + 1 < N && v[k + 1] - v[i] < v[N] - v[k + 1]) k++;
        ll a = v[j], b = v[i] - v[j],c = v[k] - v[i],d = v[N] - v[k];
        ans = min(ans,max(a,b,c,d) - min(a,b,c,d));
        a = v[j + 1],b = v[i] - v[j + 1], c = v[k + 1] - v[i],d = v[N] - v[k + 1];
        ans = min(ans,max(a,b,c,d)-min(a,b,c,d));
        a = v[j + 1],b = v[i] - v[j + 1], c = v[k] - v[i],d = v[N] - v[k];
        ans = min(ans,max(a,b,c,d)-min(a,b,c,d));
        a = v[j],b = v[i] - v[j], c = v[k + 1] - v[i],d = v[N] - v[k + 1];
        ans = min(ans,max(a,b,c,d)-min(a,b,c,d));
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl
#define debugvec(v)   rep(i, v.size()) cerr << "L" << __LINE__ << ": " << #v << "[" << i << "] = " << v[i] << endl;
#define debugvec2(v)  cerr << "L" << __LINE__ << ": " << #v << " = { "; rep(i, v.size()) cerr << v[i] << (i + 1 == v.size() ? "" : ", "); cerr << " }" << endl;
typedef long long ll;  /* 10^18 くらいまでいける */

int main(){
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;

  k--;  // インデックスは0スタートなので.
  s[k] = s[k] + 32;  // Aが65, aが97

  cout << s << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <climits>
#include <iomanip>
#include <deque>
#include <limits>

using namespace std;

const int CONSUMPTION_TAX = 0.1;

int main()
{
  string N;

  cin >> N;

  for (int i = 0; i < 3; i++) {
    if (N[i] == '7') {
      cout << "Yes";
      return 0;
    }
  }

  cout << "No";

  return 0;
}


Measured memory_bytes: 3596
n = int(input())
a = list(map(int, input().split()))
if (0 in a):
  print(0)
  exit()
MAX = 10 ** 18
ans = 1
for i in range(len(a)):
  ans *= a[i]
  if (ans > MAX):
    print(-1)
    exit()
print(ans)

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

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  priority_queue<ll> pq;
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
    pq.push(a[i] * -1);
  }

  ll mn = (1LL << 60);
  while (true) {
    vector<ll> arr;
    ll i = 0;
    while (!pq.empty()) {
      ll tmp = pq.top();
      pq.pop();
      if (tmp != 0) arr.push_back(tmp * -1);
      i++;
    }
    pq.push(arr[0] * -1);
    mn      = min(mn, arr[0]);
    ll size = arr.size();
    if (size == 1) break;
    for (ll j = 1; j < size; j++) {
      ll tmp = arr[j] - ((arr[j] / arr[0]) * arr[0]);
      pq.push(tmp * -1);
    }
  }
  cout << mn << endl;
}

Measured memory_bytes: 3556
N = int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
ans = 0
for j in range(N):
    temp = 0
    for k in range(j+1):
        temp += A[k]
    for l in range(j,N):
        temp += B[l]
    ans = max(ans,temp)
print(ans)

Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

void solve() {
	string s;
	cin >> s;
	int n = s.size();
	reverse(s.begin(), s.end());
	int p = 2019;
	int cur = 0;
	int ten = 1;
	map<int, int> ost;
	ost[0] = 1;
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		ten *= 10;
		ten %= p;
		cur += (s[i] - '0') * ten;
		cur %= p;
		ans += ost[cur]++;
	}
	cout << ans;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	for (; q > 0; q--) {
		solve();
		cout << endl;
	}
}

Measured memory_bytes: 3748
#include<bits/stdc++.h>
using namespace std;
#define ll  long long int
#define ld long double
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,a) REP(i,0,a)
#define REV(i,a,b) for(i=a-1;i>=b;i--)
#define rev(s) reverse(s.begin(),s.end())
#define pb push_back
#define mp make_pair
#define ord(v) sort(v.begin(),v.end());
const ll MAXN=2*1e5+10;
#define MAX 2*1e9
#define fi first
#define se second
#define pi 3.141592653589793238
#define rem 1000000007
#define eps 1e-9
// fflush(stdout);
//lower_bound,upper_bound,equal_range
int main()
{
	#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int h,w;
    cin>>h>>w;
    int m = 1000000007;
    char v[h+1][w+1];
    for(int i=0;i<h;i++)
    {
    	for(int j=0;j<w;j++)
    	{
    		cin>>v[i][j];
    	}
    }
    int A[h][w];
    for(int i=0;i<h;i++)
    {
    	for(int j=0;j<w;j++)
    	{
    		if(v[i][j]=='#'){
    			A[i][j]=0;
    		}
    		else
    		{
    			if(i==0&&j==0)A[i][j]=1;
    			else if(i==0){
    				A[i][j]=A[i][j-1];
    			}
    			else if(j==0){
    				A[i][j]=A[i-1][j];
    			}
    			else
    			{
    				A[i][j] = (A[i][j-1]+A[i-1][j])%m;
    			}
    		}
    	}
    }
    cout<<A[h-1][w-1];
	return 0;
}


Measured memory_bytes: 8416
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

class Main {
    static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static final PrintWriter pw = new PrintWriter(System.out);
    public static void main(String[] args) throws IOException {
        String[] inputs = br.readLine().split(" ");
        int n = Integer.parseInt(inputs[0]);
        int k = Integer.parseInt(inputs[1]);
        
        int ans = 0;
        int pow = 1;
        while(true) {
            pow *= k;
            ans++;
            if(n < pow) break;
        }

        pw.println(ans);
        pw.flush();
    }
}

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

int main() {

	int n;
	cin >> n;

	if(n % 10 == 7) {
		cout << "Yes\n";
		return 0;
	}

	n /= 10;

	if(n % 10 == 7) {
		cout << "Yes\n";
		return 0;
	}

	n /= 10;
	
	if(n % 10 == 7) {
		cout << "Yes\n";
		return 0;
	}

	cout << "No\n";

	return 0;
}


Measured memory_bytes: 3632
using System;

class Program {
    static void Main() {
        char[] chars = { 'A', 'B', 'C', 'D', 'E' };

        while (true) {
            var maxNo = 0;
            var maxCount = 0;

            for (var i = 0; i < 5; i++) {
                var l = Console.ReadLine().Split(' ');
                var count = int.Parse(l[0]) + int.Parse(l[1]);

                if (count == 0)
                    return;

                if (count > maxCount) {
                    maxNo = i;
                    maxCount = count;
                }
            }

            Console.WriteLine(chars[maxNo] + " " + maxCount);
        }
    }
}

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

bool isPalindrome(string s, int start, int end) {
  for (int i = 0; i <= (end - start) / 2; i++) {
    if (s[start + i] != s[end - i]) {
      return false;
    }
  }
  return true;
};

int main(void) {
  string S;
  cin >> S;
  int N = S.length();
  if (!isPalindrome(S, 0, N - 1)) {
    cout << "No" << endl;
    return 0;
  }
  if (!isPalindrome(S, 0, (N - 1) / 2 - 1)) {
    cout << "No" << endl;
    return 0;
  }
  if (!isPalindrome(S, (N + 3) / 2 - 1, N - 1)) {
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
class Scanner //標準入力
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int Int() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = Int() + add;
        }
        return Array;
    }

    public long Long() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = Long() + add;
        }
        return Array;
    }
}
class Program {
    static Scanner cin = new Scanner();
    static void Main(string[] args) {
        int s = cin.Int();
        var list = new List<int>();
        list.Add(s);
        int i = 1;
        while (true) {
            if(s % 2 == 0) {
                s = s / 2;
                if (list.Contains(s)) {
                    Console.WriteLine(i+1);
                    break;
                }
                list.Add(s);
            }
            else {
                s = 3 * s + 1;
                if (list.Contains(s)) {
                    Console.WriteLine(i+1);
                    break; ;
                }
                list.Add(s);
            }
            i++;
        }
        Console.ReadLine();
    }
}

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

template<typename Monoid>
struct SegmentTree{
    typedef function<Monoid(Monoid,Monoid)> F;
    int n;
    F f;
    Monoid id;
    vector<Monoid> dat;
    SegmentTree(int n_,F f,Monoid id):f(f),id(id){init(n_);}
    void init(int n_){
        n=1;
        while(n<n_) n<<=1;
        dat.assign(n<<1,id);
    }
    void build(const vector<Monoid> &v){
        for (int i=0;i<v.size();++i) dat[i+n]=v[i];
        for (int i=n-1;i;--i) dat[i]=f(dat[i<<1|0],dat[i<<1|1]);
    }
    void update(int k,Monoid x){
        dat[k+=n]=x;
        while(k>>=1) dat[k]=f(dat[k<<1|0],dat[k<<1|1]);
    }
    Monoid query(int a,int b){
        if (a>=b) return id;
        Monoid vl=id,vr=id;
        for (int l=a+n,r=b+n;l<r;l>>=1,r>>=1){
            if (l&1) vl=f(vl,dat[l++]);
            if (r&1) vr=f(dat[--r],vr);
        }
        return f(vl,vr);
    }
    // most left position p that f[a...p] meets conditin "check"
    template<typename C>
    int find_first(int a,const C &check,Monoid &M,int k,int l,int r){
        if (l+1==r){
            M=f(M,dat[k]);
            return check(M)?k-n:-1;
        }
        int m=(l+r)>>1;
        if (m<=a) return find_first(a,check,M,k<<1|1,m,r);
        if (a<=l&&!check(f(M,dat[k]))){
            M=f(M,dat[k]);
            return -1;
        }
        int vl=find_first(a,check,M,k<<1|0,l,m);
        if (~vl) return vl;
        return find_first(a,check,M,k<<1|1,m,r);
    }
    template<typename C>
    int find_first(int a,const C &check){
        Monoid M=id;
        return find_first(a,check,M,1,0,n);
    }
    // most right position p that f[p...b) meets condition "check"
    template<typename C>
    int find_last(int b,const C &check,Monoid &M,int k,int l,int r){
        if (l+1==r){
            M=f(dat[k],M);
            return check(M)?k-n:-1;
        }
        int m=(l+r)>>1;
        if (b<=m) return find_last(b,check,M,k<<1|0,l,m);
        if (r<=b&&!check(f(dat[k],M))){
            M=f(dat[k],M);
            return -1;
        }
        int vr=find_last(b,check,M,k<<1|1,m,r);
        if (~vr) return vr;
        return find_last(b,check,M,k<<1|0,l,m);
    }
    template<typename C>
    int find_last(int b,const C &check){
        Monoid M=id;
        return find_last(b,check,M,1,0,n);
    }
    Monoid operator[](int i){return dat[i+n];}
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,Q; cin >> N >> Q;
    vector<int> A(N);
    for (int i=0;i<N;++i) cin >> A[i];
    SegmentTree<int> seg(N,[](int a,int b){return max(a,b);},0);
    seg.build(A);
    for (;Q--;){
        int T; cin >> T;
        if (T==1){
            int X,V; cin >> X >> V;
            seg.update(--X,V);
        } else if (T==2){
            int L,R; cin >> L >> R;
            cout << seg.query(--L,R) << '\n';
        } else {
            int X,V; cin >> X >> V;
            int ans=seg.find_first(--X,[&](int x){return x>=V;});
            cout << (ans<0?N+1:ans+1) << '\n';
        }
    }
}

Measured memory_bytes: 6004
#include <bits/stdc++.h>
#define nmax 1000010
#define f(c,a,b) for(int c=a; c<=b; c++)
#define inf 1e24

using namespace std;
typedef double db;
struct P{
    db x, y;
    P(){}
    P(db x, db y) : x(x) , y(y) {}
    P operator - (P a){ return P(x-a.x, y-a.y); }
    db clen(){ return sqrt(x*x+y*y); }
};
P p[nmax], t[nmax];
int n;
bool c_x(P& a, P& b) { return a.x < b.x; }
bool c_y(P& a, P& b) { return a.y < b.y; }

db closestP(int l, int r){
    db ta = inf;
    if(r-l<=4){
        f(i,l,r) f(j,i+1,r) ta = min(ta, (p[i]-p[j]).clen() );
        sort(p+l, p+r+1, c_y);
    }else{
        int mid = (l+r)>>1;
        db mx = p[mid].x, d;
        ta = d = min( closestP(l,mid), closestP(mid+1,r) );
        merge(p+l, p+mid+1, p+mid+1, p+r+1, t, c_y);
        copy(t, t+r-l+1, p+l);
        int jsz=0;
        f(i,l,r) if( abs(p[i].x-mx) < d ) {
                for (int j=jsz; j>=1 && p[i].y-t[j].y<d; j--) ta = min(ta, (t[j]-p[i]).clen() );   
                t[++jsz] = p[i];
        }
    }
    return ta;
}

int main(){
    //freopen("owo.in","r",stdin);
    cin >> n;
    f(i,1,n) scanf("%lf%lf", &p[i].x, &p[i].y);
    sort(p+1, p+n+1, c_x);
    printf("%.11lf\n", closestP(1, n));
    return 0;
}


Measured memory_bytes: 6368
import sys
sys.setrecursionlimit(1000000)
def input():
    return sys.stdin.readline()
n, k = [int(i) for i in input().split()]
e = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = [int(i) for i in input().split()]
    a -= 1
    b -= 1
    e[a].append(b)
    e[b].append(a)
ans = 1
mod = 10**9+7


def dfs(i=0, r=-1):
    global ans
    if r == -1:
        ans *= k
        ans %= mod

        p = k-1
        for j in e[i]:
            if j == r:
                continue
            ans *= p
            ans %= mod
            p -= 1
            dfs(j, i)
    else:
        p = k-2
        for j in e[i]:
            if j == r:
                continue
            ans *= p
            ans %= mod
            p -= 1
            dfs(j, i)


dfs()
print(ans)


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

int main() {
  ll k;
  cin >> k;
  if(k%2==0) {
      cout << -1 << endl;
      return 0;
  }

  int cnt = 0;
  bool valid = false;
  ll target = 7;
  while(true){
    cnt++;
    if(target % k == 0){
      valid = true;
      break;
    }
    if(cnt > 1000005){
      break;
    }
    target = target * 10 % k;
    target = (target + 7) % k;
  }
  if(valid){
    cout << cnt << endl;
  } else {
    cout << -1 << endl;
  }
}


Measured memory_bytes: 3588
N, X, Y = map(int, input().split())
k = [0] * (N - 1)

for i in range(1,N):
  for j in range(i+1,N+1):
    tmp = min(abs(i-j), abs(X-i)+1+abs(j-Y))
    k[tmp-1] += 1
    
for ans in k:
  print(ans)

Measured memory_bytes: 9204
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
signed main(){
  string S1,S2,S3;
  cin>>S1>>S2>>S3;
  cout<<S1[0]<<S2[1]<<S3[2];
  }


Measured memory_bytes: 384
#include<stdio.h>
int main(){
int x,y,n,a[200][200],i,j,dic[10][200],min=210000000,k,v,ans;
scanf("%d\n",&n);
for(i=0;i<n;i++){
for(j=0;j<n;j++){
a[i][j]=0;    
}
}
for(j=0;j<n;j++){
scanf("%d %d",&v,&k);
for(i=0;i<k;i++){
scanf("%d %d",&x,&y);
a[v][x]=y;
}
scanf("\n");
}
for(i=0;i<n;i++){
dic[0][i]=0;
dic[1][i]=210000000;
}
dic[1][0]=0;
for(k=0;k<n;k++){
for(j=0;j<n;j++){
if(min>dic[1][j] && dic[0][j]==0){
ans=j;
min=dic[1][j];
}
}
min=210000000;
for(i=0;i<n;i++){
if(a[ans][i]!=0 && dic[1][i]>a[ans][i]+dic[1][ans]){
dic[1][i]=a[ans][i]+dic[1][ans];
}
}
dic[0][ans]=1;
}
for(i=0;i<n;i++){
printf("%d %d\n",i,dic[1][i]);
}
return 0;
}


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

int main(){

  int n;
  while(cin >> n && n != 0){
    int x[11] ={};
    for(int i = 0; i < n; i++){
      int tmp;
      cin >> tmp;
      x[tmp]++;
    }
    for(int i = 0; i < 10; i++){
      if(x[i] == 0) cout << "-" << endl;
      else{
	//	cout << x[i] << " ";
	for(int j = 0; j < x[i]; j++){
	  cout << "*";
	}
	cout << endl;
      }
    }
  }


}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=9e18;
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

int main(){cout<<fixed<<setprecision(20);
		   ll t1,t2;
           ll a1,a2;
           ll b1,b2;
           cin>>t1>>t2>>a1>>a2>>b1>>b2;
           if(a1<b1){
             swap(a1,b1);
             swap(a2,b2);
           }
           if(t1*(a1-b1)+t2*(a2-b2)==0){
            cout<<"infinity"<<endl;
             return 0;
           }
           if(a1*t1+a2*t2>b1*t1+b2*t2){
            cout<<0<<endl;
             return 0;
           }
           ll sa=(a1*t1+a2*t2-(b1*t1+b2*t2));
           sa*=-1;
           if((a1*t1-b1*t1)%sa==0){
             cout<<(a1*t1-b1*t1)/sa*2<<endl;
           }
           else{
           cout<<(a1*t1-b1*t1)/sa*2+1<<endl;
           }
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define fall(i,a,b) for(int i=a;i<b;i++)
using namespace std;
int main() {
	ll n;
  	cin>>n;
  	ll a[n+1];
  	ll dp[n+1];
  	for(int i=1;i<=n;i++)cin>>a[i];
  	a[0]=a[1];
  	dp[0]=0;
  	dp[1]=0;
  	
  	for(int i=2;i<=n;i++)
    {
      dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
    }
  	cout<<dp[n]<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define pll pair<ll,ll>
#define pii pair<int,int>
#define F first
#define S second
const int maxn = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    while(cin >> k) {
        k--;
        cout << a[k] << '\n';
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<bitset>
#include<queue>
#include<set>
#include<map>
using namespace std;
 
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define ROF(i,b,a) for (int i=(b);i>(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,n-1,-1)
 
typedef int i32;
typedef long long int i64;
typedef unsigned long long int ui64;
typedef float f32;
typedef double f64;
typedef long double f128;
typedef pair<int,int> Pi;
 
constexpr int INF = 1e9 + 7;
constexpr int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

int main() {
    int N; cin>>N;
    int h[N]; REP(i,N) cin>>h[i];
    int p = 0, ans = 0;
    REP(i,N) {
        if (h[i]>p) {
            ans += h[i]-p;
        }
        p = h[i];
    }
    cout<<ans<<endl;
}


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

using namespace std;

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

    bool ok = false;
    for (int i = 0; i < s.size();i++){
        if(s==t){
            ok = true;
            break;
        }
        s = s.back() + s.substr(0, s.size() - 1);
    }
    if(ok){
        cout << "Yes";
    }else{
        cout << "No";
    }
}

Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef vector<vector<P>> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<ll> vec;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30);
const int INF = (1LL << 60);
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}



signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    int n,k;
    cin>>n>>k;
    ll cnt=0;
    while(n!=0){
        n/=k;
        cnt++;
    }
    cout<<cnt<<endl;
    
}

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

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

Measured memory_bytes: 3664
n,a,b = map(int,input().split())

cnt = 0

n_min = (a * (n-1)) + b
n_max = (b * (n-1)) + a

if (n_max - n_min + 1) < 0:
    result = 0
else:
    result = n_max - n_min + 1
print(result)

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

int main(){
	ll n; cin >> n;
	vector<string> s(n); vl t(n); rep(i,n)cin >> s[i] >> t[i];
	string x; cin >> x;
	ll time = 0;
    ll start;
	rep(i,n){
		if(s[i] == x){
			start = i + 1;
			break;
		}
	} 
	for(ll i = start;i < n;i++)time += t[i];
	cout << time << endl;
}

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

bool flag[10];
int n, k;

bool can(int x) {
	while(x) {
		if(flag[x % 10]) return 0;
		x /= 10;
	}
	return 1;
}

int main() {
	cin >> n >> k;
	for(int i = 1 ; i <= k ; i++) {
		int x; cin >> x;
		flag[x] = 1;
	}
	while(!can(n)) n++;
	cout << n << endl;
	return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
	int n; scanf("%d",&n);
	vector<int> d(n);
	rep(u,n) scanf("%d",&d[u]);

	vector<int> hist(n);
	rep(u,n) hist[d[u]]++;

	int d_min=*min_element(d.begin(),d.end());
	int d_max=*max_element(d.begin(),d.end());

	bool ok=(hist[d_min]<=2);
	for(int x=d_min+1;x<=d_max;x++) if(hist[x]<2) ok=false;
	if(2*(d_max-d_min)+(hist[d_min]==1?0:1)!=d_max) ok=false;
	puts(ok?"Possible":"Impossible");

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// nichijou
#define REP(i,a,b) for (int i(a), _B(b); i < _B; ++i)
#define RP(i,n) REP(i,0,n)
#define PER(i,a,b) for(int i((a)-1), _B(b); i >= _B; --i)
#define PR(i,n) PER(i,n,0)
#define REP1(i,a,b) REP(i,a,(b)+1)
#define RP1(i,n) REP1(i,1,n)
#define PER1(i,a,b) PER(i,(a)+1,b)
#define PR1(i,n) PER1(i,n,1)
#define DO(n) REP(__i,0,n)
template<typename T>
void cmax(T & a, T b) {a = max(a, b);}
template<typename T>
void cmin(T & a, T b) {a = min(a, b);}

// data type
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define F first
#define S second

// STL container
typedef vector<int> vi;
typedef vector<ll> vll;
#define SZ(a) ((int)a.size())
#define ALL(a) a.begin(), a.end()
#define CLR(a) a.clear()
#define BK(a) (a.back())
#define FT(a) (a.front())
#define DB(a) a.pop_back()
#define DF(a) a.pop_front()
#define PB push_back
#define EB emplace_back

/* I gave you my heart and then you turned around. */
void _BG(const char * s) {}
template<typename T, typename ... TT>
void _BG(const char * s,T a, TT...b)
{
	for (int c = 0; *s && (c || *s != ','); ++s) {
		cerr<<*s;
		switch (*s) {
		case '(':
		case '[':
		case '{':
			++c;
			break;
		case ')':
		case ']':
		case '}':
			--c;
			break;
		}
	}
	cerr<<" = "<<a;
	if (*s) {
		cerr<<", ";
		_BG(++s,b...);
	} else
		cerr<<endl;
}
#define BG(...) do { \
	cerr << __PRETTY_FUNCTION__ << ':' << __LINE__ << ": "; \
	_BG(#__VA_ARGS__,__VA_ARGS__); \
} while(0)

/* Reading input is now 20% cooler! */
bool RD(void) {return true;}
bool RD(char & a) {return scanf(" %c", &a) == 1;}
bool RD(char * a) {return scanf("%s", a) == 1;}
bool RD(double & a) {return scanf("%lf", &a) == 1;}
bool RD(int & a) {return scanf("%d", &a) == 1;}
bool RD(ll & a) {return scanf("%lld", &a) == 1;}

template<typename T, typename ... TT>
bool RD(T & a, TT & ...  b) {return RD(a) && RD(b...);}

/* Do princesses dream of magic sheep? */
#define RI(a) int a; RD(a)
#define RII(a,b) RI(a); RI(b)
#define RIII(a,b,c) RI(a); RII(b,c)
#define RIIII(a,b,c,d) RI(a); RIII(b,c,d)

/* For it's time for you to fulfill your output. */
void PT(const char a) {putchar(a);}
void PT(const char * a) {fputs(a, stdout);}
void PT(char * a) {fputs(a, stdout);}
void PT(const double a) {printf("%.16f", a);}
void PT(const int a) {printf("%d", a);}
void PT(const ll a) {printf("%lld", a);}

/* The line will last forever! */
template<char sep = ' ',char end = '\n'>
void PL(void) {if (end) PT(end);}
template<char sep = ' ',char end = '\n',typename T, typename ... TT>
void PL(const T a, const TT ...  b) {PT(a); if (sizeof...(b) && sep) PT(sep); PL<sep,end>(b...);}

/* Good Luck && Have Fun ! */
const int W = 106;
const int N = W * W;
int g[W][W];
int a[N],k;
void upd(int r,int c)
{
	g[r][c] = k;
	if (--a[k] == 0)
		++k;
}
int main()
{
	RIII(h,w,n);
	RP1(i,n) RD(a[i]);
	k = 1;
	RP(r,h) {
		if (r&1) {
			PR(c,w)
				upd(r,c);
		} else {
			RP(c,w)
				upd(r,c);
		}
	}
	RP(r,h)
		RP(c,w)
			PL<0,0>(g[r][c]," \n"[c==w-1]);
}


Measured memory_bytes: 384
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long
#define TBMod 1000000007

int main(int argc, char const *argv[])
{
	int a,b;
	int k;
	scanf("%d%d",&a,&b);
	k = (a + b) / 2;
	if(abs(a - k) == abs(b - k))	printf("%d\n", k);
	else puts("IMPOSSIBLE");
	return 0;
}


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

int main(){
    int n,sum=1;
    bool a;
    cin >> n;
    vector<int> h(n);
    cin >> h.at(0);
    for(int i=1;i<n;i++){
        a=true;
        cin >>h.at(i);
        for(int l=0;l<i;l++){
            if(h.at(i)<h.at(l)){
                a=false;
                break;
            }
        }
        if(a){
            sum++;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
a, b, c = 0, 0, 0
for i in range(N):
  if A[i] % 4 == 0:
    a += 1
  elif A[i] % 2 == 0:
    b += 1
  else:
    c += 1
#print("{0} {1} {2}".format(a, b, c))
b = 1 if b > 0 else 0  
if b + c > a + 1:
  print('No')
else:
  print('Yes')
  

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

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> c(n, 0); 
    int cnt_r = 0;
    rep(i, n){
        if(s[i]=='W')c[i]=1;
        else cnt_r++;
    }
    
    int ans = 0;
    rep(i, cnt_r){
        ans += c[i];
    }
    
    cout << ans << endl;
    
}

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

#define int long long
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; }

signed main(){
	int n, m;
	cin >> n >> m;

	int tmp[100010] = {};

	for(int i = 0;i < m;i++){
		int l, r;
		cin >> l >> r;
		tmp[l-1]++;
		tmp[r]--;
	}

	int now = tmp[0];
	int ans = now == m;
	for(int i = 1;i < n;i++){
		now += tmp[i];
		tmp[i] = now;
		ans += tmp[i] == m;
	}

	cout << ans << endl;

	return 0;
}


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

bool can (vector<int> &V, int I) {
	vector<int> C;
	C.push_back(0);
	for(auto &T : V) {
		vector<int> D;
		for(auto &X : C) {
			D.push_back(X+T);
			D.push_back(X-T);
		}
		sort(D.begin(), D.end());
		D.erase(unique(D.begin(), D.end()), D.end());
		swap(C, D);
	}
	for(auto &T : C) {
		if(T == I) return true;
	}
	return false;
}

int main()
{
	int C = 0, X, Y;
	vector<int> V[2];
	string S;
	cin >> S >> X >> Y;
	int I = S.size();
	for(int i=0;i<(int)S.size();i++) {
		if(S[i] == 'T') {
			I = i;
			break;
		}
	}
	X -= I;
	for(int i=I;i<(int)S.size();i++) {
		if(S[i] == 'T') {
			C ^= 1;
			V[C].push_back(0);
		}
		else {
			int T = V[C].back();
			V[C].pop_back();
			V[C].push_back(T+1);
		}
	}
	puts(can(V[0], X) && can(V[1], Y) ? "Yes" : "No");
}


Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define max(x,y)(x>y?x:y)
#define min(x,y)(x>y?y:x)
typedef long long int ll;
typedef unsigned long long int ull;
int asc_cmp(const void* X,const void* Y){int x=*(int*)X,y=*(int*)Y;if(x<y)return -1;else if(x==y)return 0;else return 1;}
int desc_cmp(const void* X,const void* Y){int x=*(int*)X,y=*(int*)Y;if(x<y)return 1;else if(x==y)return 0;else return -1;}

int main(){
    int n;scanf("%d",&n);
    int d[n];for(int i=0;i<n;i++)scanf("%d",&d[i]);

    qsort(d,n,sizeof(int),asc_cmp);
    printf("%d\n",d[n/2]-d[n/2-1]);
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> P;
typedef priority_queue<P,vector<P>,greater<P>> P_queue;

#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());
#define ADD(a,b) a=(a+b)%mod

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
vec dx={1,0,-1,0};
vec dy={0,1,0,-1};

ll N; 
vec d;

bool ABLE(){
    rep(i,N) {
        if(d[i]>i) return false;
        if(i>0) if(d[i]>d[i-1]+1) return false;
    }
    return true;
}


int main(){
    cin>>N;
    rep(i,N){
        ll x; cin>>x;
        d.pb(x);
    }
    ll ans=0;
    if(!ABLE()) ans=-1;
    else{
        for(int i=N-1; i>=0; i--){
            if(i==N-1) ans+=d[i];
            else if(d[i]!=d[i+1]-1) ans+=d[i];
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 2420
N = int(input())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7


ans = 0

for i in range(61):

  one = 0
  for a in A:
    if (a >> i) & 1:
      one += 1
  
  zero = N - one
  ans += one * zero * (2 ** i)
  ans %= mod

print(ans)

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

int main(){
    int n,W;
    int v[101],w[101];
    int dp[101][10001];//dp[i+1][j] i番目まで使えて重さの総和がj以下
    cin >> n >> W;
    rep(i,n){
        cin >> v[i] >> w[i];
    }
    rep(i,n)rep(j,W+1){
        if(j<w[i]){//i番目を使ってる可能性がない
            dp[i+1][j] = dp[i][j];
        }
        else{
            dp[i+1][j] = max(dp[i][j], dp[i+1][j-w[i]]+v[i]);
        }
    }
    cout << dp[n][W] << endl;

}


Measured memory_bytes: 7012
#include<stdio.h>

int LinearSearch(int [],int,int);

int main(){
  int i,n,A[10001],q,key,sum = 0;

  scanf("%d",&n);
  for(i = 0;i< n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i = 0;i < q;i++){
    scanf("%d",&key);
    if(LinearSearch(A,n,key))
      sum++;
  }
  printf("%d\n",sum);

  return 0;
}

int LinearSearch(int A[],int n,int key){
  int i = 0;
  A[n] = key;
  while(A[i] != key){
    i++;
  }
  return i != n;
 }




Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define FOR(i, a, b) for (int i=(a); i<(b); ++i)
#define ROF(i, b, a) for (int i=(b); i>(a); --i)
#define CASET int _T; cin >> _T; REP(caset, 0, _T)
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define vvi vector<vi>
#define vvb vector<vb>
#define pii pair<int,int>
#define t3i tuple<int,int,int>
#define mii map<int,int>
#define vpii vector<pii>
#define vt3i vector<t3i>
#define sq(x) (x)*(x)
#define inv(x) powa(x, MOD-2)

long long INF = 1LL<<60;
long long MOD = 1e9+7;

template <typename A, typename B> istream &operator>>(istream &is, pair<A, B> &pr) {is >> pr.first >> pr.second; return is;}
template <typename A> istream &operator>>(istream &is, vector<A> &v) {for (auto &x : v) is >> x; return is;}
ostream &operator<<(ostream &os, char &c) {os << (char)c; return os;}
ostream &operator<<(ostream &os, const char s[]) {os << (string)s; return os;}
ostream &operator<<(ostream &os, string &s) {for (char &c : s) os << (char)c; return os;}
template <typename A, typename B> ostream &operator<<(ostream &os, pair<A, B> &pr) {os << '(' << pr.first << ", " << pr.second << ')'; return os;}
ostream &operator<<(ostream &os, vb &v) {
    bool first = true;
    os << '[';
    for (const bool &x : v) {
        if (!first) os << ", ";
        first = false;
        os << x;
    }
    os << ']';
    return os;
}
template <class C> ostream &operator<<(ostream &os, C &v) {
    bool first = true;
    os << '[';
    for (auto &x : v) {
        if (!first) os << ", ";
        first = false;
        os << x;
    }
    os << ']';
    return os;
}
string bin_string(int x) {
    const int d = 32;
    string res(d, ' ');
    FOR(i, 0, d) res[d-1-i] = '0'+(x>>i & 1LL);
    return res;
}
int powa(int base, int exp) {
    int res = 1;
    while (exp) {
        if (exp&1) res = res*base % MOD;
        base = base*base % MOD;
        exp >>= 1;
    }
    return res;
}

vi nine;
vvi nCk;
int f(int n, int k) {
    if (k < 0 || k > n) return 0;
    return nCk[n][k] * nine[k];
}

main() {
    ios::sync_with_stdio(0), cin.tie(0);
    
    string s;
    int k;
    cin >> s >> k;
    int n = s.size();
    nCk.assign(n, vi(n));
    nCk[0][0] = 1;
    FOR(i, 1, n) {
        nCk[i][0] = 1;
        FOR(j, 1, i+1) nCk[i][j] = nCk[i-1][j-1] + nCk[i-1][j];
    }

    nine.resize(n);
    int temp = 1;
    FOR(i, 0, n) {
        nine[i] = temp;
        temp *= 9;
    }
    
    int i = 0;
    int res = 0;
    int z = 0;
    while (true) {
        if (s[i] != '0') {
            res += f(n-1-i, k) + max(0, s[i]-'0'-1) * f(n-1-i, k-1);
            --k;
        }
        ++i;
        if (i >= n) {
            if (k == 0) ++res;
            break;
        }
    }
    cout << res;
}

Measured memory_bytes: 384
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>
#include<unordered_map>

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

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
typedef long long ll;

int main()
{
    int n; cin >> n;
    cout << n*n*n << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<list>

using namespace std;

int main()
{
	int n;
	long ans = 0;
	list<int> a, c;
	int buf = -1;


	cin >> n;



	for (int i = 0; i < n - 1; i++) {
		int k;
		cin >> k;

		ans += k;

		if (i == 0) {
			ans += k;
		}

		if (k < buf) {
			ans -= buf;
			ans += k;
		}

		buf = k;
	}


	cout << ans;
}

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

class E
{
	static void Main()
	{
		Func<int[]> read = () => Console.ReadLine().Split().Select(int.Parse).ToArray();
		var z = read();
		int h = z[0], n = z[1];
		var ms = new int[n].Select(_ => read()).ToArray();

		var dp = new int[h + 1];
		for (int i = 1; i <= h; i++)
		{
			int min = int.MaxValue, j;
			foreach (var m in ms)
			{
				if ((j = i - m[0]) < 0) j = 0;
				min = Math.Min(min, dp[j] + m[1]);
			}
			dp[i] = min;
		}
		Console.WriteLine(dp[h]);
	}
}


Measured memory_bytes: 13484
#include <iostream>
#include<algorithm>
#include <vector>
#include<string>
#include<cmath>
#include<cstdio>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define max(x,y) (((x)>(y)) ? x:y)
#define min(x,y) (((x)<(y)) ? x:y)
#define FOR(a) for(int i=0;i<a;i++)
#define ender {return 0;}
#define tosasuretu(a) (a*(a+1)/2)
inline ll kaizyo(ll);
ll gcd(ll, ll);
ll combination(ll, ll);
int main() {
	int d;
	cin >> d;
	switch (d) {
	case 22:
		cout << "Christmas Eve Eve Eve";
		break;
	case 23:
		cout << "Christmas Eve Eve";
		break;
	case 24:
		cout << "Christmas Eve";
		break;
	case 25:
		cout << "Christmas";
		break;
	}
	return 0;
}


inline ll kaizyo(ll x) {
	long ans = 1;
	for (int z = 0; z < x; z++) {
		ans *= (x - z);
	}
	return ans;
}
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a%b);
}

Measured memory_bytes: 256
/*input
7?4
*/
#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;
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld long double
#define pii pair<int,int>
#define f first
#define s second
#define pb emplace_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define sz(_a) (ll)(_a.size())
#define FILL(n) memset(n,0,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
const ll maxn=100005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
ll mypow(ll a,ll b){
    ll res=1LL;
    while(b){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}
ll dp[maxn][13];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
    cin>>s;
    FILL(dp);
    if(s[0]=='?'){
        REP(i,10) dp[0][i]=1; 
    }
    else{
        dp[0][s[0]-'0']=1;
    }
    for(int i=1;i<s.length();i++){
        if(s[i]=='?'){
            REP(j,13){
                REP(z,10){
                    dp[i][(j*10+z)%13]+=dp[i-1][j];
                    dp[i][(j*10+z)%13]%=MOD;
                }
            }
        }
        else{
            REP(j,13){
                dp[i][(j*10+s[i]-'0')%13]+=dp[i-1][j];
                dp[i][(j*10+s[i]-'0')%13]%=MOD;
            }
        }
    }
    cout<<dp[s.length()-1][5];
}

Measured memory_bytes: 10624
s=input()
for i in range(8):
    sum=int(s[0])
    ans=s[0]
    for j in range(3):
        if (i>>j)&1:
            sum+=int(s[j+1])
            ans+="+"+s[j+1]
        else:
            sum-=int(s[j+1])
            ans+="-"+s[j+1]
    if sum==7:
        ans+="=7"
        print(ans)
        exit()

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i < b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const long double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	ll x, y;
	cin >> x >> y;

	if (llabs(x - y) <= 1) {
		out("Brown");
	}
	else {
		out("Alice");
	}

	return 0;
}

Measured memory_bytes: 256
from sys import exit
N = int(input())
V = [int(n) for n in input().split()]
C = [int(n) for n in input().split()]
VC=[0]*N
for i in range(N):
    VC[i] = (V[i],C[i])
VC = sorted(VC,key=lambda x:-x[0])
ans = 0
for i in range(N):
    if(VC[i][0] > VC[i][1]):
        ans+=VC[i][0] - VC[i][1]
print(ans)
# a = [int(input()) for _ in range(N)]
# S = str(input())
# L = len(S)
# T = str(input())
# exit()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MAX=1e5+10;
ll N,W,A[MAX],B[MAX],C[MAX],dp[105][MAX];
ll solve(int idx,int w)
{
    if(idx>N)return 0;
    if(dp[idx][w]!=-1)return dp[idx][w];
    ll res=0;
    if(w+A[idx]<=W)res = max(res,solve(idx+1,w+A[idx])+B[idx]);
    res = max(res,solve(idx+1,w));
    return dp[idx][w]=res;
}
int  main ()
{
    memset(dp,-1,sizeof dp);
    cin >> N >> W;
    for(int i=1;i<=N;i++){
        cin >> A[i] >> B[i];
    }
    cout<<solve(1,0)<<endl;
    return 0;
}





Measured memory_bytes: 84224
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;

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

  double* X = new double[n];
  double* Y = new double[n];
  double p_1=0,p_2=0,p_3=0,p_inf=0;

  for(int i=0;i<n;i++) cin >> X[i];
  for(int i=0;i<n;i++) cin >> Y[i];

  for(int i=0;i<n;i++){
    int x_y = abs(X[i] - Y[i]);
    p_1 += x_y;
    p_2 += x_y * x_y;
    p_3 += x_y * x_y * x_y;
    p_inf = (p_inf > x_y) ? p_inf : x_y;
  }
  p_2 = sqrt(p_2);
  p_3 = cbrt(p_3);

  delete[] X;
  delete[] Y;

  cout << setprecision(12) << p_1 << endl;
  cout << p_2 << endl;
  cout << p_3 << endl;
  cout << p_inf << endl;
}


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

int main(){
    string S;
    cin >> S;
    string w[] = {"Sunny", "Cloudy", "Rainy"};
    if(S==w[0]) cout << w[1] << endl;
    else if(S==w[1]) cout << w[2] << endl;
    else cout << w[0] << endl;
    return 0;
}

Measured memory_bytes: 256