akhauriyash/Code-Regression huggingface dataset:
// Gaurav Aggarwal

/*
useful stl
array<ll,size> ar;         //size(),front(),back(),fill(),empty()
deque<ll> d                //push_back(),push_front(),pop_front(),pop_back()
vector<ll> v(size,val);    //push_back(),*max_element(v.begin(),v.end()),accumulate(v.begin(),v.end(),0)
stack<ll> g;               //push(),pop(),top(),size(),empty()         LIFO
queue<ll> q;               //push(),size(),front(),back(),empty()      FIFO
priority_queue<ll> pq
*/

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> ipair;
typedef pair<long,long> lpair;
typedef pair<double,double> pdd;
#define scan(x) do{while((x=getchar_unlocked())<'0'); for(x-='0'; '0'<=(_=getchar_unlocked()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#define For(i, a, b) for(__typeof (a) i=a; i<=b; i++)
#define mod 1000000007
#define PI 3.141592653589793238462643383279502884 
#define debug1(a) cout<<a<<"\n";
#define debug2(a,b) cout<<a<<" "<<b<<"\n";
#define debug3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n";
#define debug_arr(a,n) {for(__typeof (n) i=0; i<n; ++i) {cout<<a[i]<<" ";}}
#define inp_arr(a,n) for(__typeof (n) i=0; i<n; ++i) {cin>>a[i];}
#define beg_arr(a,n) for(__typeof (n) i=0; i<n; ++i) {a[i] = 0;}

ll power(ll x, ll y) 
{ 
    ll res = 1;   
    while (y > 0) { 
        if (y & 1) 
            res = (res*x)%mod; 
        y = y>>1;
        x = (x*x)%mod; 
    } 
    return res%mod; 
}


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


    int a[5];
    cin>>a[0]>>a[1]>>a[2]>>a[3]>>a[4];
    sort(a,a+5);

    vector<pair<int,int>> v;
    int tot = 0;
    for(int i=0;i<5;++i) {
        if(a[i] % 10 == 0) {
            tot += a[i];
        }
        else 
            v.push_back(make_pair(a[i]%10,a[i]));
    }
    sort(v.begin(),v.end());

    
    for(int i=v.size()-1;i>=0;--i) {
        tot += v[i].second;
        if(v[i].first != 0 and i>=1) {
            tot += 10 - v[i].first;
        }
    }
    

    cout<<tot<<"\n";

    return 0;
}

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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

struct Edge {
  const int from, to;
  Edge(int from, int to) : from(from), to(to) {}
};

vector<vector<Edge>> ReadDirectedGraph(
    int n, int m, bool is_one_indexed=false) {
  vector<vector<Edge>> graph(n);
  for (int i = 0; i < m; i++) {
    int v1, v2;
    cin >> v1 >> v2;
    if (is_one_indexed) {
      v1--;
      v2--;
    }
    graph[v1].push_back(Edge({v1, v2}));
  }
  return graph;
}

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

  int n, m;
  cin >> n >> m;
  auto graph = ReadDirectedGraph(n, m, true);

  vector<int> shortest_cycle;
  auto process_root_fn = [&](int r) {
    deque<int> queue;
    queue.push_back(r);
    vector<int> visited(n, 0);
    vector<int> ps(n, -1);
    visited[r] = 1;
    while (!queue.empty()) {
      int v = queue.front();
      queue.pop_front();
      for (const auto& e : graph[v]) {
        if (e.to == r) {
          int c = v;
          vector<int> cycle({c});
          while (true) {
            c = ps[c];
            cycle.push_back(c);
            if (c == r) break;
          };
          if (shortest_cycle.empty() || shortest_cycle.size() > cycle.size()) {
            shortest_cycle = cycle;
          }
          return;
        }
        if (visited[e.to]) continue;
        ps[e.to] = v;
        visited[e.to] = true;
        queue.push_back(e.to);
      }
    }
  };

  for (int r = 0; r < n; r++) {
    process_root_fn(r);
  }

  if (shortest_cycle.empty()) {
    cout << -1 << endl;
  } else {
    cout << shortest_cycle.size() << endl;
    for (int v : shortest_cycle) {
      cout << v + 1 << endl;
    }
  }
}

Measured memory_bytes: 384
object Main{
  def main(args: Array[String]){
    if (sys.env.getOrElse("TEST", "")=="1"){
      println(test());
    }else{
      val input=io.Source.stdin.getLines().mkString("\n");
      println(solve(input).trim());
    }
  }

  def solve(input:String):String={
    val List(a,b,c,x)=input.split("\n").map(_.toInt).toList;
    val ay=(0 to a).map(_*500);
    val by=(0 to b).map(_*100);
    val cy=(0 to c).map(_*50);
    ay.flatMap(i=>by.flatMap(j=>cy.map(k=>i+j+k))).filter(_==x).size.toString()
  }

  val tests=List("""2
2
2
100""" -> """2""",
    """5
1
0
150""" -> """0""",
"""30
40
50
6000"""->"""213""");

  def test():String= {
    return tests.map{case (i,o)=>(i.trim(),o.trim())}.zipWithIndex.map{case ((input,outputExpect),i)=>{
      val output=solve(input).trim();
      s"test${i+1}:"+(if(output==outputExpect){
        "Passed"
      }else{
        s"Failed\nexpect:\n${outputExpect}\noutput:\n${output}"
      })
    }}.mkString("\n");
  }
}

Measured memory_bytes: 34412
n, m = map(int, input().split())
drinks = []

for i in range(n):
    a, b = map(int, input().split())
    drinks.append([a, b])
    
drinks.sort()

cnt, ans = 0, 0
for i in range(n):
    if m <= cnt + drinks[i][1]:
        num = m - cnt
        ans += drinks[i][0] * num
        break
    
    cnt += drinks[i][1]
    ans += drinks[i][0] * drinks[i][1]

print(ans)

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

#define gcd(a,b)     __gcd(a,b)
#define lcm(a,b)     (a*(b/gcd(a,b)))

#define pb   push_back
#define endl "\n"

#define ll  long long
#define ull unsigned long long

#define W(t)            while(t--)
#define rep(i,n)        for(int i = 0; i < n; i++)
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;

int main()
{
    IOS
    ll n,i,sum=0;

    cin>>n;
    ll a[n];
    rep(i,n) cin>>a[i];
    for(i = 1; i < n; i++)
    {
        if(a[i] < a[i-1])
        {

            sum += (a[i-1]-a[i]);
            a[i] = a[i-1];
           // cout<<a[i]<<" ";
        }
    }
    cout<<sum;

    return 0;
}


Measured memory_bytes: 5164
#include <iostream>
#include <string>
#include <functional>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <cstring>
#include <algorithm>

using namespace std;

using i64 = int64_t;

const int N = 200010;

int l;
i64 a[N], f[N][5];

i64 odd(i64 x) {
	if (x <= 2) return 2 - x;
	return x % 2 == 1;
}

i64 even(i64 x) {
	return x % 2 == 0;
}

int main() {
	cin >> l;
	for (int i = 1; i <= l; i++) scanf("%lld", a + i);
	for (int i = 1; i <= l; i++) {
		f[i][0] = f[i - 1][0] + a[i];
		f[i][1] = min(f[i][0], f[i - 1][1] + odd(a[i]));
		f[i][2] = min(f[i][1], f[i - 1][2] + even(a[i]));
		f[i][3] = min(f[i][2], f[i - 1][3] + odd(a[i]));
		f[i][4] = min(f[i][3], f[i - 1][4] + a[i]);
		// cout << "f[" << i << "] = {";
		// for (int j = 0; j <= 4; j++) printf("%d: %lld, ", j, f[i][j]);
		// cout << "}\n";
	}
	cout << f[l][4] << endl;
    return 0;
}

Measured memory_bytes: 9600
#include<iostream>
using namespace std;
int main(){
	int i,j;
	int a[3]={0};
	int b[2]={0};
	int m=0;
	for(i=0;i<3;i++){
		cin>>a[i];
	}
	for(j=0;j<2;j++){
		cin>>b[j];
	}
	m=a[0]+b[0]-50;
	for(i=0;i<3;i++){
		for(j=0;j<2;j++){
			if(m>a[i]+b[j]-50){
				m=a[i]+b[j]-50;
			}
		}
	}
	cout<<m<<endl;
	return 0;
}

Measured memory_bytes: 3092
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;
int main()
{
    int n; cin >> n;
    vector<double> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    double sum;
    for (int i = 0; i < n; ++i)
    {
        sum += 1.0 / a[i];
    }
    cout << 1.0 / sum << endl;
    
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

double PI=acos(-1.0);
#define eps (1e-10)
struct Point{
    double x,y;
    Point(){}
    Point(double x,double y):x(x),y(y){}
    Point operator+(Point p) {return Point(x+p.x,y+p.y);}
    Point operator-(Point p) {return Point(x-p.x,y-p.y);}
    Point operator*(Point p) {return Point(x*p.x-y*p.y,x*p.y+y*p.x);}
    Point operator*(double k){return Point(x*k,y*k);}
    Point operator/(double k){return Point(x/k,y/k);}
    double norm(){return x*x+y*y;}
    double abs(){return sqrt(norm());}
    bool operator == (const Point &p) const{return fabs(x-p.x)<eps && fabs(y-p.y)<eps;}
    double arg(){return atan2(y,x);}
    double dot(Point p){return x*p.x+y*p.y;}
    double det(Point p){return x*p.y-y*p.x;}
};
bool cmp_x(const Point& p,const Point& q){
    if(p.x!=q.x) return p.x<q.x;
    return p.y<q.y;
}
struct Circle{
    double r;
    Point p;
    Circle(){}
    Circle(Point p,double r):p(p),r(r){}
};
pair<Point,Point> tangentC(Circle c,Point p){
    double k=PI/2-acos(c.r/(p-c.p).abs());
    return make_pair(p+(c.p-p)*Point(cos(k),sin(k))*cos(k),p+(c.p-p)*Point(cos(-k),sin(-k))*cos(k));
}
int main(){
    double px,py,cx,cy,r;
    cin>>px>>py>>cx>>cy>>r;
    pair<Point,Point> p=tangentC(Circle(Point(cx,cy),r),Point(px,py));
    if(!cmp_x(p.first,p.second)) swap(p.first,p.second);
    cout<<fixed<<setprecision(12)<<p.first.x<<" "<<p.first.y<<endl;
    cout<<p.second.x<<" "<<p.second.y<<endl;
    return 0;
}


Measured memory_bytes: 3548
import sys
input=sys.stdin.readline

def main():

    s = input().strip()
    t = input().strip()
    s = "".join(sorted(s))
    t = "".join(sorted(t, reverse=True))
    if s < t:
        print("Yes")
    else:
        print("No")

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;


signed main()
{
    int n;
    cin >> n;
    int cnt = 0;
    REP(i,n){
        int a;
        cin >> a;
        a--;
        cnt += a;
    }
    cout << cnt << endl;

    return 0;
}

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

int main(){
    ll N, K; cin >> N >> K;
    if(N<K){
        ll ans = min(N, abs(N-K));
        cout << ans << endl;
        return 0;
    }
    if(N%K==0){
        cout << 0 << endl;
        return 0;
    }
    ll x = N % K;
    ll ans = min(abs(K-x), x);
    cout << ans << endl;
    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n, m, a, b;
	scanf("%d%d%d%d", &n, &m, &a, &b);
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if ((i <= b && j <= a) || (i > b && j > a)) putchar('1');
			else putchar('0');
		}
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define REV(v) reverse(v.begin(), v.end());
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, start, stop) for (int i = start; i < stop; i++)
#define FORR(i, start, stop) for (int i = start; i > stop; i--)
#define SORT(v, n) sort(v, v + n);
#define SORTR(v, n) sort(v, v + n,greater<int>());
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.begin(), v.end(),greater<int>());
#define REMOVE(v,n) remove(vector<int> v,v+v.size(),int n)
#define ERASE(v,n) v.erase(v.begin()+n);
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
#define V(v,i,j) vector(v.begin() + i, v.begin() + j)
#define INSERT(va,vb) va.insert(va.end(), vb.begin(), vb.end())
using namespace std;
typedef vector<int> vint;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
const int MOD = 1000000007;
void chmin(int &a, int b) { if (a > b) a = b; }

//vector< vector<int> > v (size1, vector<int>(size2) );

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin>>N;
    vector<ll> A(N);
    for(ll i=0;i<N;i++) cin>>A[i];
    VSORT(A);
    bool ok=true;
    if(N%2==0){
        for(ll i=0;i<N/2;i++){
            if(!(A[2*i]==2*i+1 && A[2*i+1]==2*i+1)) ok=false;
        }
    }else{
        if(A[0]!=0) ok=false;
        for(ll i=0;i<(N-1)/2;i++){
            if(!(A[2*i+1]==2*i+2 && A[2*i+2]==2*i+2)) ok=false;
        }
    }
    
    if(ok) cout<<modpow(2,N/2,MOD)<<endl;
    else cout<<0<<endl;
    
}

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

int main() {
  int r,d,x;
  cin >> r >> d >> x;
  
  int ans;
  
  
  for(int i=0;i<10;i++) {
    ans = r * x - d;
    cout << ans << endl;
    x = ans;
  }
  return 0;
}

Measured memory_bytes: 256
/**
 * 二分探索
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_B&lang=ja
 */

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector <int>S(n);
  for (int i = 0; i < n; i++) {
    cin >> S.at(i);
  }

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

  // 二分探索
  int cnt = 0;
  // Tに含まれる整数で、Sに含まれているものの個数をカウントする
  for (int i = 0; i < q; i++) {
    int minJ = 0;
    int maxJ = n;
    while (minJ <= maxJ) {
      // Sの中央の値で比較することで、配列の前半と後半のどちらに求める値があるのかを探索する
      int j = (minJ + maxJ) / 2;

      if (S.at(j) < T.at(i)) {
        // 前半に探索する値は存在しない
        minJ = j + 1;
      } else if (S.at(j) > T.at(i)) {
        // 後半に探索する値は存在しない
        maxJ = j - 1;
      } else {
        // 要素が一致した
        cnt++;
        break;
      }
    }
  }
  
  cout << cnt << endl;
  return 0;
}



Measured memory_bytes: 3368
#include<iostream>

#define MAXMAP 21

using namespace std;

const int dx[]={0,1,-1,0},dy[]={1,0,0,-1};
const char direction[]={'N','E','W','S'};
bool myMap[MAXMAP][MAXMAP]={false};


int main(){
	int N,M,nowX,nowY;
	bool flag;
	
	while(cin>>N){
		
		if(N==0){
			break;
		}
		fill((bool*)myMap,(bool*)(myMap+MAXMAP),false);
		nowX=nowY=10;
		flag=false;
		
		for(int i=0;i<N;i++){
			int x,y;
			cin>>x>>y;
			myMap[y][x]=true;
		}
		
		cin>>M;
		for(int i=0;i<M;i++){
			char tempDirec;
			int distance,tempDist;
			
			cin>>tempDirec>>distance;
			
			
			for(int j=0;j<4;j++){
				if(tempDirec==direction[j]){
					
					
					if(dx[j]!=0){
						tempDist=nowX+dx[j]*distance;
						if(dx[j]==1){
							for(int k=nowX;k<=tempDist;k++){
								if(myMap[nowY][k]){
									myMap[nowY][k]=false;
								}
							}
						}
						else if(dx[j]==-1){
							for(int k=nowX;k>=tempDist;k--){
								if(myMap[nowY][k]){
									myMap[nowY][k]=false;
								}
							}
						}
						nowX=tempDist;
					}
					
					
					if(dy[j]!=0){
						tempDist=nowY+dy[j]*distance;
						if(dy[j]==1){
							for(int k=nowY;k<=tempDist;k++){
								if(myMap[k][nowX]){
									myMap[k][nowX]=false;
								}
							}
						}
						else if(dy[j]==-1){
							for(int k=nowY;k>=tempDist;k--){
								if(myMap[k][nowX]){
									myMap[k][nowX]=false;
								}
							}
						}
						nowY=tempDist;
					}
					
					
					break;
				}
			}
		}
		
		
		for(int i=0;i<MAXMAP;i++){
			for(int j=0;j<MAXMAP;j++){
				if(myMap[i][j]==true){
					flag=true;
					//cout<<"i="<<i<<" j="<<j<<endl;
					break;
				}
			}
		}
		
		
		if(flag){
			cout<<"No"<<endl;
		}
		else{
			cout<<"Yes"<<endl;
		}
	}
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
const int INF = (1<<28);
typedef struct{
  int to; //行き先
  int cap; //容量 
  int rev; //逆辺
} Edge;

vector<Edge> g[10005]; //グラフの表現
int iter[10005]; //どこまで調べ終わったか
int level[10005]; //sからの距離

//増加パスをDFSで探す
int dfs(int v,int t,int f);

//sからtへの最大流を求める
int max_flow(int s,int t);

//sからの最短距離をBFSで計算する
void bfs(int s);

int main()
{
  ios_base::sync_with_stdio(false);
  
  int n,q,a,b,c;
  cin >> n >> q;
  for(int i=0;i<q;i++){
    cin >> a >> b >> c;
    g[a].push_back((Edge){b,c,g[b].size()}); //bのベクターの中の番号を逆辺に格納
    g[b].push_back((Edge){a,0,g[a].size()-1});
  }
  cout << max_flow(0,n-1) << endl;
  return 0; 
}

int dfs(int v,int t,int f)
{
  if(v == t) return f; //ゴールについたらfを流す
  
  for(int &i=iter[v];i < g[v].size() ;i++){
    Edge &e = g[v][i];
    if( e.cap > 0 && level[v] < level[e.to] ){
      int d = dfs( e.to , t , min(f,e.cap) ); //今までの経路の最小容量
      if(d > 0){
	e.cap -= d; //容量をdだけ引く
	g[e.to][e.rev].cap += d; //逆流をdだけたす
	return d;
      }
    }
  }
  
  return 0;
}

int max_flow(int s,int t)
{
  int flow=0;
  while(1){
    bfs(s);
    if(level[t] < 0) return flow;
    memset(iter,0,sizeof(iter));
    int f;
    while( (f = dfs(s,t,INF)) > 0){
      flow += f;
    }
  }
}

void bfs(int s)
{
  memset(level, -1,sizeof(level));
  queue<int> que;
  level[s] = 0;
  que.push(s);
  
  while(!que.empty()){
    int v = que.front(); que.pop();
    for(int i=0;i<g[v].size();i++){
      Edge &e = g[v][i];
      if(e.cap > 0 && level[e.to] < 0){
	level[e.to] = level[v] + 1;
	que.push(e.to);
      }
    }
  }
  return;
}


Measured memory_bytes: 3540
///بِسْمِ الّٰلهِ الرَّحْمٰنِ الرَحِيْمِ
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi acos(-1.0)
int main()
{
     ios_base::sync_with_stdio(false);cin.tie(NULL);
     ll int i,n,t,j=0,p,x,a=0,b,l=0,r=0,y,k,c,sum=0,m,d;
     char s;
     cin>>s;
     if(s>64 && s<91){
        cout<<"A"<<endl;
     }
     else{
        cout<<"a"<<endl;
     }

     return EXIT_SUCCESS;
}


Measured memory_bytes: 3648
#include <stdio.h>
int main(void){
	
	int H,W,i,j;
	
	while(1){
		scanf("%d %d", &H, &W);
		if(H==0 && W==0) break;
		else{
			for(i=1;i<=W;i++){
				printf("#");
			}
			printf("\n");
			for(j=1;j<=H-2;j++){
				printf("#");
				for(i=1;i<=W-2;i++){
					printf(".");
				}
				printf("#\n");
			}
			for(i=1;i<=W;i++){
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
	
	return 0;
}

Measured memory_bytes: 588
import numpy as np
import copy
H, W, K = map(int, input().split())
mat = np.zeros((H, W), dtype = int)
for i in range(H):
    s = input()
    s = s.replace('.', '0 ')
    s = s.replace('#', '1 ')
    mat[i, :] = list(map(int, s.split()))
cnt = 0
for i in range(2 ** H):
    for j in range(2 ** W):
        a = copy.deepcopy(mat)
        for k in range(H):
            if (i >> k) & 1:
                a[k, :] *= 0
            for l in range(W):
                if (j >> l) & 1:
                    a[:, l] *= 0
        if np.count_nonzero(a == 1) == K:
            cnt += 1
print(cnt)

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

typedef long long ll;

int main() {
	int a[5];
	scanf("%d%d%d", a + 1, a + 2, a + 3);
	std::sort(a + 1, a + 4);
	if(a[1] % 2 == 0 || a[2] % 2 == 0 || a[3] % 2 == 0) printf("0\n");
	else printf("%lld\n", (ll)a[2] * a[1]);
	return 0;
}

Measured memory_bytes: 256
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 10

A, B = [int(x) for x in stdin.readline().rstrip().split()]

tmp = A+B

if tmp % 2 == 0:
    print(tmp//2)
else:
    print("IMPOSSIBLE")


Measured memory_bytes: 66156
#include<stdio.h>
#include <math.h>

int main()
{
    int a,b,c, count=0;
    scanf("%d%d%d", &a, &b, &c);
    for (int i=a; i<=b; i++){
        if ( c % i == 0 ){
            count++;
        }     
    }
    printf("%d\n", count);
        return 0;
  }


Measured memory_bytes: 2072
import std;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long N, M;
    scan(N, M);
    auto A = aryread();
    long ans = N - A.sum();
    writeln(max(-1, ans));
}


Measured memory_bytes: 3964
n, k = map(int, input().split())
s = str(input())


for i in range(n):
    if i != k-1:
        print(s[i], end='')
    else:
        if s[i] == 'A':
            print('a', end='')
        elif s[i] == 'B':
            print('b', end='')
        else:
            print('c', end='')

Measured memory_bytes: 3064
#include <stdio.h>
#include <math.h>
int main()
{
    int a,s,b,c=1;
    scanf("%d%d",&a,&b);
    s=b;
while(b)
    {
        b=b/10;
        c=c*10;
    }
    a=a*c;
    a=a+s;
    b=(int)sqrt(a)*(int)sqrt(a);
    if(b==a)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 128
N = int(input())
a = list(map(int, input().split()))
b = [0 for i in range(N+1)]
for i in range(1, N + 1):
    b[i] = b[i-1] + a[i-1]
ans = 2 * 10 ** 9
for i in range(1, N):
    ans = min(ans, abs(b[i] - (b[N] - b[i])))
print(ans)

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

#define int long long

using namespace std;

int32_t main()
{
    map <string,int> m;

    int n;
    cin >> n;
    n--;

    string s;
    cin >> s;
    m[s]++;

    while(n--)
    {
        string ss;
        cin >> ss;

        if(ss[0] != s[s.size()-1] || m[ss] != 0)
        {
            cout << "No\n";
            return 0;
        }

        m[ss]++;
        s = ss;
    }

    cout << "Yes\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
const lld mod = 1e9 + 7;
lld dp[222222],dp2[222222],ans[222222];
int sz[222222];
vector<int> v[222222];
lld calc(lld now,lld num){
	if(num==1) return now;
	lld now2 = calc(now,num/2);
	if(num%2==0) return (now2*now2)%mod;
	return (((now2*now2)%mod)*now)%mod;
}
lld fat(lld n,lld r){
	lld f = dp[n];
	lld s = (dp[r]*dp[n-r])%mod;
	return (f*calc(s,mod-2))%mod;
}
lld divs(lld n,lld r){
	return (n*calc(r,mod-2))%mod;
}
int recur(int now,int left){
	sz[now]++;
	for(int e=0;e<v[now].size();e++){
		int next = v[now][e];
		if(next!=left){
			sz[now] += recur(next,now);
		}
	}
	return sz[now];
}
void recur2(int now,int left){
	dp2[now] = 1;
	int tot = sz[now] - 1;
	for(int e=0;e<v[now].size();e++){
		int next = v[now][e];
		if(next!=left){
			recur2(next,now);
			dp2[now] = (dp2[now]*fat(tot,sz[next]))%mod;
			dp2[now] = (dp2[now]*dp2[next])%mod;
			tot -= sz[next];
		}
	}
}
void recur3(int now,int left){
	ans[now] = dp2[now];
	for(int e=0;e<v[now].size();e++){
		int next = v[now][e];
		if(next!=left){
			lld f1 = dp2[now],f2 = dp2[next];
			lld s1 = sz[now],s2 = sz[next];
			sz[next] = sz[now];
			sz[now] -= s2;
			lld dif1 = divs(dp2[now],dp2[next]);
			dif1 = divs(dif1,dp[s1-1]);
			dif1 = (dif1*dp[s1-1-s2])%mod;
			dif1 = (dif1*dp[s2])%mod;
			lld dif2 = (dp2[next]*dif1)%mod;
			dif2 = divs(dif2,dp[s2-1])%mod;
			dif2 = (dif2*dp[sz[next]-1])%mod;
			dif2 = divs(dif2,dp[sz[now]]);
			dp2[now] = dif1;
			dp2[next] = dif2;
			recur3(next,now);
			dp2[next] = f2;
			dp2[now] = f1;
			sz[now] = s1;
			sz[next] = s2;
		}
	}
}
int main(void){
	dp[0] = 1;
	for(int e=1;e<222222;e++) dp[e] = (dp[e-1]*(lld)e)%mod;
	int n;
	scanf("%d",&n);
	for(int e=0;e<n-1;e++){
		int a,b;
		scanf("%d%d",&a,&b);
		v[a].push_back(b);
		v[b].push_back(a);
	}
	recur(1,-1);
	recur2(1,-1);
	recur3(1,-1);
	for(int e=1;e<=n;e++) printf("%lld\n",ans[e]);
	return 0;
}


Measured memory_bytes: 20608
#include<iostream>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int d[n+1][3],cnt=0;
  for(int i=1;i<=n;i++)	
  {
     cin>>d[i][1]>>d[i][2];
    if(d[i][1]==d[i][2]) cnt++;
    else cnt=0;
    if(cnt==3) return cout<<"Yes",0;
  }
  cout<<"No";
  return 0;
}

Measured memory_bytes: 3636
# -*- coding: utf-8 -*-
N, K, S = map(int, input().split())
a = []
if S != 10**9:
    for i in range(K):
        a.append(S)
    for i in range(N-K):
        a.append(S+1)
else:
    for i in range(K):
        a.append(S)
    for i in range(N-K):
        a.append(S-1)
maped_a = map(str, a)
ans = " ".join(maped_a)
print(ans)

Measured memory_bytes: 15128
#!/usr/bin/env python3

import sys

DEBUG = False

def read(t):
    return t(sys.stdin.readline().rstrip())


def read_list(t, sep = " "):
    return [t(s) for s in sys.stdin.readline().rstrip().split(sep)]


def dprint(*args, **kwargs):
    if DEBUG:
        print(*args, **kwargs)
    return


def main():
    l = read(int)
    print((l/3)**3)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>

int main()
{
 
 int n,m;
 while(scanf("%d%d",&n,&m)==2){
     if(n==0 && m==0){
         break;
     }
     else
     {
         int a[1010];
        for(int i=0;i<n;i++){
            scanf("%d",&a[i]);
        }
        int max = 0;
        for(int i=0;i<n-1;i++){
            for(int j=i+1;j<n;j++){
                if(a[i]+a[j]>max && a[i]+a[j]<=m){
                    max = a[i]+a[j];
                }
            }
        }
        if (max==0){
            printf("NONE\n");
        } 
        else{
            printf("%d\n",max);
        }

     }
     
 }
    return 0;
}


Measured memory_bytes: 2692
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

    public void Proc()
    {
        this.MaxStep = int.Parse(Reader.ReadLine());
        this.AddValue = int.Parse(Reader.ReadLine());

        int current = 1;
        for (int i = 0; i < MaxStep; i++) {
            current = Math.Min(current * 2, current + AddValue);
        }
        Console.WriteLine(current);
        
    }



    private int AddValue;
    private int MaxStep;


    public class Reader
    {
        private static StringReader sr;
        public static bool IsDebug = false;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (sr == null)
                {
                    sr = new StringReader(InputText.Trim());
                }
                return sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        private static string InputText = @"



10
10


";
    }

    public static void Main(string[] args)
    {
#if DEBUG
        Reader.IsDebug = true;
#endif
        Program prg = new Program();
        prg.Proc();
    }
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const int INF=1e9;
const int MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define ALL(v) v.begin(), v.end()
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbgmap(mp) for (auto i = mp.begin(); i != mp.end(); ++i) { cout << i->first <<":"<<i->second << endl;}
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<" ";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll ans=0;
    if(n%2==0){
        ans=n/2-1;
    }else{
        ans=n/2;
    }
    
    cout<<ans<<endl;
    return  0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <sstream>
using namespace std;

#define REP(i,a,n) for(i=a; i<n; i++)
#define rep(i,n) REP(i,0,n)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define foreach(it,x) for(typeof(x.begin()) it=x.begin(); it!=x.end(); it++)

bool isinside(int x, int y, int r){
    return ( x*x + y*y < 4*r*r );
}

int main(){
    int tate,yoko,high,n,r,i;

    while( cin >> tate >> yoko >> high, tate|yoko|high ){
        cin >> n;
        rep(i,n){
            cin >> r;
            if( isinside(tate,yoko,r) || isinside(tate,high,r) || isinside(yoko,high,r) ){
                puts("OK");
            }
            else{
                puts("NA");
            }
        }
    }

    return 0;
}

Measured memory_bytes: 0
from enum import Enum
from queue import Queue
import collections

import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

def partition(A,p,r):
    x = A[r]
    i = p-1
    for j in range(p,r):
        if A[j] <= x:
            i += 1
            A[i],A[j] = A[j],A[i]
    A[i+1],A[r] = A[r],A[i+1]
    return i+1

N = int(input())
A = list(map(int,input().split()))

j=partition(A,0,N-1)
print(*(x if i != j else "[%d]" % x for i, x in enumerate(A)))



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

int main() {
  string S;
  cin >> S;
  int n = S.size();
  int c = 0;
  for(int i = 0; i < (n + 1) / 2; i++) {
    if(S.at(i) != S.at(n - i - 1)) c++;
  }
  cout << c << endl;
}

Measured memory_bytes: 256
n = gets.to_i
s = gets.split.map(&:to_i)
b = [-1]
j = -1
s.each{|c|
	j = b[j] while j >= 0 && s[j] != c
	j += 1
	b << j
}
if n % (n - b[n]) == 0
	puts n / (n - b[n])
else
	puts 1
end

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  string s;
  getline(cin,s);
  rep(i,n){
    getline(cin,s);
    while(s.find("Hoshino") != string::npos){
      s.replace(s.find("Hoshino"),7,"Hoshina");
    }
    cout << s << endl;
  }
  return 0;
}

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

int Zellers_congruence(int y, int m, int d) {
	int num;
	if (m < 3)num = (y - 1) + (y - 1) / 4 - (y - 1) / 100 + (y - 1) / 400 + (13 * (m + 12) + 8) / 5 + d;
	else num = y + y / 4 + -y / 100 + y / 400 + (13 * m + 8) / 5 + d;
	return num % 7;
}

int main() {
	int year=2004, month, day;
	while (cin>>month>>day&&month!=0&&day!=0) {
		switch (Zellers_congruence(year, month, day)) {
		case 0: {cout << "Sunday" << endl; break; }
		case 1: {cout << "Monday" << endl; break; }
		case 2: {cout << "Tuesday" << endl; break; }
		case 3: {cout << "Wednesday" << endl; break; }
		case 4: {cout << "Thursday" << endl; break; }
		case 5: {cout << "Friday" << endl; break; }
		case 6: {cout << "Saturday" << endl; break; }
		default:cout << "error" << endl;
		}
	}
}

Measured memory_bytes: 3076
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <iostream>
#define maxn 100009
using namespace std;
const int MOD = 1e9 + 7;
char s[maxn], t[maxn];
int sum1[maxn], sum2[maxn];
int s1[maxn], s2[maxn];
int main(){
	scanf("%s%s", s + 1, t + 1);
	int n = strlen(s + 1);
	int m = strlen(t + 1);
	for(int i = 1; i <= n; i++){
		if(s[i] == 'A')
			sum1[i] = sum1[i - 1] + 1;
		else
			sum1[i] = sum1[i - 1] + 2;
	}
	for(int i = 1; i <= m; i++){
		if(t[i] == 'A')
			sum2[i] = sum2[i - 1] + 1;
		else
			sum2[i] = sum2[i - 1] + 2;
	}
	
	int q;
	scanf("%d", &q);
	while(q--){
		int l1, r1, l2, r2;
		scanf("%d%d%d%d", &l1, &r1, &l2, &r2);
		int x = sum1[r1] - sum1[l1 - 1];
		int y = sum2[r2] - sum2[l2 - 1];
		//cout << sum1[r1] << " " << y <<endl;
		if(x % 3 == y % 3)
			puts("YES");
		else
			puts("NO");
	}
	return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<int> V(N);
  for (int i = 0; i < N; i++) {
    cin >> V[i];
  }
  vector<map<int, int>> cnts(2);
  for (int i = 0; i < N; i++) {
    cnts[i & 1][V[i]]++;
  }
  vector<pair<int, int>> A, B;
  for (auto it = cnts[0].begin(); it != cnts[0].end(); it++) {
    A.emplace_back(make_pair(it->first, it->second));
  }
  for (auto it = cnts[1].begin(); it != cnts[1].end(); it++) {
    B.emplace_back(make_pair(it->first, it->second));
  }
  A.emplace_back(make_pair(0, 0));
  B.emplace_back(make_pair(0, 0));
  sort(A.begin(), A.end(),
       [](pair<int, int> a, pair<int, int> b) { return a.second > b.second; });
  sort(B.begin(), B.end(),
       [](pair<int, int> a, pair<int, int> b) { return a.second > b.second; });

  int res = 0;
  if (A[0].first == B[0].first) {
    res = N - max(A[0].second + B[1].second, A[1].second + B[0].second);
  } else {
    res = N - A[0].second - B[0].second;
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 6524
import math
import fractions

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def bitlist(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

#a = list(map(int, input().split()))
# --------------------------------------------

n = int(input())
a = list(map(int, input().split()))
b = []

for i in range(n):
    b.append(bitlist(a[i],61))

c = [0 for i in range(61)]

for i in range(61):
    for j in range(n):
        c[i] += b[j][i]
ans = 0
for i in range(61):
    ans += c[i]*(n-c[i])*2**i % 1000000007
print(ans % 1000000007)


Measured memory_bytes: 240180
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) throws IOException {
		new Main().solve();
	}

	private void solve() throws IOException {
		try {
			//			solveA();
			//			solveB();
			solveC();
			//			 solveD();
			//			 solveE();
			//			 solveF();
		} finally {
			if (in != null) {
				in.close();
			}
			if (out != null) {
				out.flush();
				out.close();
			}
		}

	}

	private void solveA() {
		long count = Arrays.stream(next().split("")).filter(i -> i.equals("o")).count();
		out.println(700 + count * 100);
	}

	private void solveB() {
		String wk = "";
		for (int i = 0; i < 3; i++) {
			String tmp = next();
			for (int j = 0; j < 3; j++) {
				if (i == j) {
					wk += tmp.charAt(j);
				}
			}
		}

		out.println(wk);
	}

	private void solveC() {
		int n = nextInt();
		int m = nextInt();
		int x = nextInt();
		int[] wk = IntStream.range(0, m).map(i -> nextInt()).toArray();
		int[] rui = new int[n + 1];
		for (int i : wk) {
			rui[i] = 1;
		}
		for (int i = 1; i < rui.length; i++) {
			rui[i] = rui[i] + rui[i - 1];
		}

		out.println(Integer.min(rui[x] - rui[0], rui[n] - rui[x]));
	}

	private void solveD() {
		int n = nextInt();

		out.println("");
	}

	private void solveE() {
		int n = nextInt();

		out.println("");
	}

	private void solveF() {
		int n = nextInt();

		out.println("");
	}

	private final PrintWriter out = new PrintWriter(System.out);
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
}

Measured memory_bytes: 26708
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int dp[MAXN];
int main() {
	int n; read(n);
	for (int i = 1; i <= n; i++) {
		dp[i] = dp[i - 1] + 1;
		for (int j = 6; j <= i; j *= 6)
			chkmin(dp[i], dp[i - j] + 1);
		for (int j = 9; j <= i; j *= 9)
			chkmin(dp[i], dp[i - j] + 1);
	}
	writeln(dp[n]);
	return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main(void)
{
	int a,b,c,x;
	x=101;
	cin>>a>>b;
	c=a+b;
	x=a-b;
	if(x<c) x=c;
	c=a*b;
	if(x<c) x=c;
	cout<<x<<endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input())

dp = [0] * (N+1)

for i in range(1, N+1):
    dp[i] = dp[i-1] + 1
    for j in [6, 9]:
        now = j
        while now <= i:
            if i - now >= 0:
                dp[i] = min(dp[i-now] + 1, dp[i])
            now *= j
print(dp[-1])

Measured memory_bytes: 3828
#include<bits/stdc++.h>
#define pb emplace_back
using namespace std;
using ll = long long;
#ifdef KEV
#define DE(i, e) cerr << #i << ' ' << i << e
void debug(auto L, auto R) { while (L < R) cerr << *L << " \n"[L+1==R], ++L; }
#else
#define DE(...) 0
void debug(...) {}
#endif
const int maxn = 300010;
signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	vector<ll> a(2), b(2);
	cin >> a[0] >> a[1] >> b[0] >> b[1];
	if (a[0] <= 0 && a[1] >= 0) a.pb(0);
	if (b[0] <= 0 && b[1] >= 0) b.pb(0);
	ll res = LLONG_MIN;
	for (ll i : a) for (ll j : b)
		res = max(res, i * j);

	cout << res << '\n';
}



Measured memory_bytes: 3644
import heapq
N, M = map(int, input().split())
A = list(map(int, input().split()))
Ai = list(map(lambda x: x*(-1), A))
heapq.heapify(Ai)

for i in range(M):
  maxA = heapq.heappop(Ai)*(-1)
  waribiki = maxA // 2
  heapq.heappush(Ai,waribiki * (-1))
  #print(Ai)
  
print(sum(Ai) * (-1))


Measured memory_bytes: 14180
#include <cstdio>

using namespace std ;
#define maxn 10
typedef long long ll ;

int map[maxn][maxn] ;
int n,m ;
ll ans ;
int vis[maxn] ;

bool check() {
	for(int i=1 ; i<=n; i++ )
		if(!vis[i]) return false ;
	return true ;
}

void dfs(int a) {
	vis[a] = 1 ;
	if(check()) {
		ans ++ ;
		vis[a] = 0 ;
		return ;
	}
	for(int i=1; i<=n; i++) {
		if(map[a][i]) {
			if(!vis[i])
				dfs(i) ;
		}
	}
	vis[a] = 0 ;
}


int main(void){

	scanf("%d %d",&n,&m ) ;
	for(int i=0; i<m; i++ ) {
		int a, b ;
		scanf("%d%d",&a,&b) ;
		map[a][b] = 1 ;
		map[b][a] = 1 ;
	}
	dfs(1) ;

	printf("%lld\n",ans) ;
	return 0 ;
}

Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int n,m,K;
inline int read() {
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	return x*f;
}
char mp[7][7],tmp[7][7];
int ans;
inline void paint(int str,int stc) {
	for (int i=1;i<=n;++i)
		for (int j=1;j<=m;++j)
			tmp[i][j]=mp[i][j];
	for (int i=1;i<=n;++i)
		if (str&(1<<(i-1))) {
			for (int j=1;j<=m;++j)
				tmp[i][j]='r';
		}
	for (int j=1;j<=m;++j)
		if (stc&(1<<(j-1))) {
			for (int i=1;i<=n;++i)
				tmp[i][j]='r';
		}
}
inline int count() {
	int ret=0;
	for (int i=1;i<=n;++i)
		for (int j=1;j<=m;++j)
			ret+=(tmp[i][j]=='#');
	return ret;
}
int main() {
	n=read(),m=read(),K=read();
	for (int i=1;i<=n;++i)
		scanf("%s",mp[i]+1);
	for (int str=0;str<(1<<n);++str)
		for (int stc=0;stc<(1<<m);++stc) {
			paint(str,stc);
			if (count()==K) {
				++ans;
			}
		}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 3824
#include<iostream>
#include<set>
#include<algorithm>
using namespace std;
int main() {
	int n, m;
	cin >> n >> m;
	long long a[100000] = { 0 }, b;
	for (int i = 1; i < n; i++) {
		cin >> b;
		a[i] = (a[i - 1] + b);
	}
	long long sum = 0;
	long long p = 0;
	for (int i = 0; i < m; i++) {
		cin >> b;
		if (b < 0) sum += (a[p] - a[p + b]);
		else 
			sum += (a[p+b]-a[p]);
		p += b;
		sum %= 100000;
	}
	cout << sum << endl;
	cin >> sum >> sum;
}

Measured memory_bytes: 3876
#include<iostream>
#include<cstdlib>

#include<cmath>
#include<map>
#include<string>
#include<vector>
#include<algorithm> 

using namespace std;

# define p(s) std::cout << s << endl;
# define printIf(j,s1,s2) std::cout << (j ? s1 : s2) << endl;
# define YES(j) std::cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define rep(n,i) for(i = 0 ; i < n ; i++)

int main()
{
    int n,ma,mi;cin >> n;

    int tmp; cin >> tmp;
    ma=mi=tmp;
    for(int i=0; i<n-1 ; i++){
        cin >> tmp;
        ma=std::max(tmp,ma);
        mi=std::min(tmp,mi);
    }
    p(ma-mi)
}

Measured memory_bytes: 256
n,m = map(int,input().split())
sw = []
for i in range(m):
    L = list(map(int,input().split()))
    L.pop(0)
    sw.append(L)
p = list(map(int,input().split()))
def s(x,N):
    LI = []
    for i in range(N):
        A = x % (2**(N-i))
        B = A // (2**(N-1-i))
        if B == 1:
            LI.append(i+1)
    return LI
ans = 0
for i in range(2**n):
    ansl = []
    for j in range(m):
        C = list(set(sw[j]) & set(s(i,n)))
        if len(C) % 2 == p[j]:
            ansl.append(1)
    if len(ansl) == m:
        ans += 1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    long n,k;
    cin>>n>>k;
 
    long surplus=n%k;
 
    if(n>=k){
        cout<<min(surplus,k-surplus)<<endl;
    }else{
        cout<<min(n,k-n)<<endl;
    }
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int A, B; cin >> A >> B;
    FOR(i, 1, 10000) {
        if ((i * 8) / 100 == A && (i * 10) / 100 == B) {
            cout << i << endl; return 0;
        }
    }
    cout << -1 << endl;
	
	return 0;
}
 

Measured memory_bytes: 256