akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int a[16],b[16];
int f[16][15*9+1][2];
int dp(int pos, int sum, bool ok) {
	if(pos == 16) {
		if (sum ==0) return 1;
		else return 10;
	}
	if (f[pos][sum][ok] != -1) return f[pos][sum][ok];
	int s = 0;
	if (!ok) {
		s = a[pos];
	} else s = 0;
	int res = 10;
	for(int i=s;i<=min(9, sum);i++) {
		if (dp(pos+1, sum-i, ok | (i > a[pos]))!= 10) {
			res = i;
			break;
		}	
	}
	f[pos][sum][ok] = res;
	return res;
}

long long call(long long lastN, long long lastS, long long sum) {
	if (sum == lastS) {
		lastN++;
	}

	long long t = (lastN * sum / lastS);
	if (lastN * sum % lastS !=0) {
		t ++;
	}
	if (t < lastN) t = lastN + 1;
	//cerr << t << endl;
	int cnt = 0;
	memset(a, 0 , sizeof(a));
	memset(b, 0, sizeof(b));
	while (t > 0) {
		b[cnt++] = t  % 10;
		t /= 10;
	}
	for(int i=0;i<cnt;i++) {
		a[15-i] = b[i];
	}
	memset(f, -1, sizeof(f));
	long long res = 0;
	bool ok = false;
	for(int i=0;i<16;i++) {
		int t = dp(i, sum, ok);
		if (t == 10) return 0;
		res = (res * 10) + t;
		ok = (ok | t < a[i]);
		sum -= t;
	}
	return res;
}
long long getsum(long long x) {
	int res = 0;
	while (x) {
		res += (x% 10);
		x/= 10;
	}
	return res;
}
long long getNext(long long lastN, long long lastS) {
	long long N = 1e16;
	long long S = 1;

	for(int i=max(1,(int) lastS-20); i<= min(15*9, (int) lastS+1); i++) {
		long long t = call(lastN, lastS, i);
		//cerr << "x " << i << " " << t << endl;
		if (t==0) continue;
		if (t <= lastN) continue;
		if (lastN * getsum(t) > t * lastS) continue;
		if (N * getsum(t) == t * S) {
			if (t < N) {
				N = t;
				S = getsum(t);
			}
		} else {
			if (N * getsum(t) > t * S) {
				N = t;
				S = getsum(t);
			}
		}
	}
	return N;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int k = 0;
	cin >> k;
	vector<int> res;
	res.push_back(1);
	long long lastN = 1;
	long long lastS = 1;
	cout<< 1<< endl;
	k--;
	while (k--) {
		long long res = getNext(lastN, lastS);
		cout<<res<<endl;
		lastN = res;
		lastS = getsum(res);
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int h,a;
	cin>>h>>a;
	int total = 0;
	while(a--){
		int b;
		cin>>b;
		total+=b;
	}
	if(h>total) cout<<"No";
	else cout<<"Yes";
}

Measured memory_bytes: 3624
class Stack:
    def __init__(self, data=[]):
        self.data = data

    def push(self, x):
        self.data.append(x)
        return self.data

    def pop(self):
        if len(self.data) == 0:
            return "Stack is Empty"
        else:
            return self.data.pop()


stack = Stack()
formula = list(map(str, input().split()))
for i in range(len(formula)):
    if formula[i] == '+':
        b = stack.pop()
        a = stack.pop()
        stack.push(a+b)
    elif formula[i] == '-':
        b = stack.pop()
        a = stack.pop()
        stack.push(a-b)
    elif formula[i] == '*':
        b = stack.pop()
        a = stack.pop()
        stack.push(a*b)
    else:
        stack.push(int(formula[i]))

print(stack.pop())



Measured memory_bytes: 5604
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <map>

//#include <bits/stdc++.h>
using namespace std;
#define print(x) cout<<(x)<<endl
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long int
#define pb push_back

int main() {
  string s, t;
  cin >> s >> t;
  if(s[0]==t[2] && s[1]==t[1] && s[2]==t[0]) print("YES");
  else print("NO");

}


Measured memory_bytes: 504
#include <iostream>
#include <stdio.h>

#include <algorithm>

using namespace std;
int main(){
  int H;
  cin >> H ;
  int a[H];
  for (int i=0;i<H;i++){
    cin >> a[i];
  }
  sort (a,a+H);

  long int sum=0;

  for (int i=1;i<H;i++){
    sum+=a[H-1-i/2];
  }

cout << sum << endl;
}



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

int dp[100010];
int main() {
  int n, m;
  cin >> n >> m;
  string s;
  cin >> s;
  int r = 0;
  dp[0] = 0;
  while (r < n) {
    // cout << r  << " " << dp[r] << endl;
    int nr = r;
    for (int i = 1; i <= m; ++i) {
      if (r+i > n) break;
      if (s[r+i] == '1') continue;
      dp[r+i] = dp[r]+1;
      nr = r+i;
    }
    if (r == nr) {
      cout << "-1" << endl;
      return 0;
    }
    r = nr;
  }
  int l = n;
  vector<int> ans;
  while (l > 0) {
    int bl = l;
    for (int i = 1; i <= m; ++i) {
      if (l-i < 0) break;
      if (s[l-i] == '1') continue;
      if (dp[l-i] < dp[l]) {
        bl = l-i;
      }
    }
    ans.push_back(l-bl);
    l = bl;
  }
  for (int i = ans.size()-1; i >= 0; --i) {
    cout << ans[i] << " ";
  }
  cout << endl;
}



Measured memory_bytes: 1528
import java.util.*;

public class Main {

    int INF = Integer.MAX_VALUE;

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

    void solve() {
        Scanner sc = new Scanner(System.in);
        int N=sc.nextInt();
        int x=sc.nextInt();
        int[] a=new int[N];
        for(int i=0;i<N;i++){
            a[i]=sc.nextInt();
        }
        Arrays.sort(a);
        for(int i=0;i<N;i++){
            x=x-a[i];
            if(x<0){
                System.out.println(i);
                return;
            }
        }
        System.out.println(x==0?N:N-1);
    }
}


Measured memory_bytes: 23252
#include <iostream>
#include <cstdio>
using namespace std;
int H, W, N, a[101010];
int ans[1010][1010];
int main() {
    scanf("%d%d%d",&H,&W,&N);
    for(int i=0;i<N;i++)
		scanf("%d",&a[i]);
    int cu=0;
    for(int y=0;y<H;y++)
		for(int x=0;x<W;x++){
        ans[y][x]=cu+1;
        a[cu]--;
        if (!a[cu]) 
			cu++;
    }
 	for(int y=0;y<H;y++){
        for(int _x=0;_x<W;_x++){
            int x;
            if (y%2==0) 
				x=_x;
            else 
				x=W-1-_x;
            if (_x) 
				printf(" ");
            printf("%d",ans[y][x]);
        }
        printf("\n");
    }
}

Measured memory_bytes: 2688
import java.util.*;


public class Main {
    static int answer;
    static int N;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        N = Integer.parseInt(sc.nextLine());
        String[] str = sc.nextLine().split("[\\s]+");
        int[] inputs = new int[N];
        int count = 0;
        for(int i = 0; i < N ; i++) {
          inputs[i] =Integer.parseInt(str[i]);
        }

        for(int i = 0; i < N; i++) {
          count += hoge(inputs[i],0);
        }

        System.out.println(count);
    }

    public static int hoge(int x,int count) {
      if(x % 2 == 0) {
        return hoge(x/2,count + 1);
      }
      return count;
    }
}


Measured memory_bytes: 27016
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder_Cs
{
    class Program
    {
        public static void Main()
        {
            string St = Console.ReadLine().Trim();
            string S;
            if (St.Length % 2 == 1)
            {
                S = St.Substring(0, St.Length - 1);
            }
            else
            {
                S = St.Substring(0, St.Length - 2);
            }
            int i = 0;
            for (i = S.Length; i > 0; i -= 2)
            {
                if(S.Substring(0, (i / 2)) == S.Substring( (i / 2), (i / 2)))
                {
                    break;
                }
            }
            Console.WriteLine($"{i}");
        }
    }
}


Measured memory_bytes: 13268
import sys
sys.setrecursionlimit(10**7)

class Node:
    def __init__(self,parent,left,right):
        self.parent = parent
        self.left = left
        self.right = right

def get_depth(T:dict,u:int):
    d = 0
    while T[u] != -1:
        u = T[u].parent
        d += 1

D = {}

def get_all_depth(T:dict,u:int,p:int):
    D[u] = p
    if T[u].left != -1:
        get_all_depth(T,T[u].left,p+1)
    if T[u].right != -1:
        get_all_depth(T,T[u].right,p+1)

H = {}

def get_all_height(T:dict,u:int):
    h1 = 0
    h2 = 0
    if T[u].right != -1:
        h1 = get_all_height(T,T[u].right)+1
    if T[u].left != -1:
        h2 = get_all_height(T,T[u].left)+1
    H[u] = max(h1,h2)
    return H[u]

def get_sibling(T:dict,u:int):
    if T[u].parent == -1:
        return -1
    if T[T[u].parent].left != u and T[T[u].parent].left != -1:
        return T[T[u].parent].left
    if T[T[u].parent].right != u and T[T[u].parent].right != -1:
        return T[T[u].parent].right
    return -1

def PRINT(T:dict,node:int,D:dict,H:dict):
    dig = (T[node].right!=-1)+(T[node].left!=-1)
    if (T[node].left==-1) and (T[node].right==-1):
        node_type = "leaf"
    else:
        node_type = "internal node"
    if T[node].parent == -1:
        node_type = "root"
    print(f"node {node}: parent = {T[node].parent}, sibling = {get_sibling(T,node)}, degree = {dig}, depth = {D[node]}, height = {H[node]}, {node_type}")

def preorder(u:int):
    if u == -1:
        return 
    print(" "+str(u),end="")
    preorder(T[u].left)
    preorder(T[u].right)

def inorder(u:int):
    if u == -1:
        return 
    inorder(T[u].left)
    print(" "+str(u),end="")
    inorder(T[u].right)

def postorder(u:int):
    if u == -1:
        return 
    postorder(T[u].left)
    postorder(T[u].right)
    print(" "+str(u),end="")

n = int(input())
T = {k: Node(-1,-1,-1) for k in range(n)}

R = -1

for _ in range(n):
    a,b,c = map(int,input().split())
    T[a].left = b
    T[a].right = c
    if b != -1:
        T[b].parent = a
    if c != -1:
        T[c].parent = a
for node in range(n):
    if T[node].parent == -1:
        R = node

print("Preorder")
preorder(R)
print("")
print("Inorder")
inorder(R)
print("")
print("Postorder")
postorder(R)
print("")


Measured memory_bytes: 5668
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<string>
#include<cmath>
#include<cassert>
#include<map>
  using namespace std;

typedef long long ll;
typedef ll int__;
#define rep(i,j) for(int__ (i)=0;(i)<(j);(i)++)
#define repeat(i,j,k) for(int__ i=(j);i<(k);(i)++)
#define all(v) begin(v),end(v)

#define W    0b01
#define B    0b10
#define WW 0b0100
#define BB 0b1000


const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

int w,h;

void rec(vector< vector<unsigned char> > &s,unsigned char symbol,int x,int y){
  rep(dir,4){
    int nx =x+dx[dir];
    int ny =y+dy[dir];
    if(0<=nx and nx <w and 0<=ny and ny<h){
      if(!(s[ny][nx]&WW) && !(s[ny][nx]&BB)){
        if((s[ny][nx]&symbol) ==0){
          s[ny][nx]|=symbol;
          rec(s,symbol,nx,ny);
        }
      }
    }
  }
}


int main()
{
  while(true){
    cin>>w>>h;
    if(w==0 and h==0)break;
    vector<string> s(h);
    vector< vector<unsigned char> > flgs(h,vector<unsigned char>(w,0));
    rep(i,h)cin>>s[i];
    rep(i,h){
      rep(j,w){
        if(s[i][j]=='.')flgs[i][j]=0;
        if(s[i][j]=='W')flgs[i][j]=WW;
        if(s[i][j]=='B')flgs[i][j]=BB;
      }
    }

    rep(y,h){
      rep(x,w){
        if(flgs[y][x]&WW)rec(flgs,W,x,y);
        else if(flgs[y][x]&BB)rec(flgs,B,x,y);
      }
    }

    int white=0,black=0;
    rep(y,h){
      rep(x,w){
        if(!(flgs[y][x]&WW) && !(flgs[y][x]&BB)){
          if((flgs[y][x]&W) && (flgs[y][x]&B)){
            //putchar('A');
            continue;
          }
          else if(flgs[y][x]&W){
            //putchar('W');
            white++;
          }
          else if( flgs[y][x]&B){
            //putchar('B');
            black++;
          }
        }
        else{
          //putchar(flgs[y][x]&WW ? 'W' : 'B');
          ;
        }
      }
      //puts("");
    }

    cout<<black<<" "<<white<<endl;
    
  }
  return 0;
}

Measured memory_bytes: 1312
package main

import (
	"fmt"
)

func main() {
	var N int
	fmt.Scan(&N)

	w := make([]string, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&w[i])
	}

	bw := w[0]
	mp := map[string]bool{w[0]: true}

	for i := 1; i < N; i++ {
		if bw[len(bw)-1] != w[i][0] {
			fmt.Println("No")
			return
		}
		if mp[w[i]] == true {
			fmt.Println("No")
			return
		}
		bw = w[i]
		mp[w[i]] = true
	}
	fmt.Println("Yes")
}


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

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;

typedef long long LL;

LL GCD(LL x, LL y){
        LL r=0;
        if(x < y) swap(x, y);
        r = x % y;
        while(r!=0){
                x = y;
                y = r;
                r = x % y;
        }
        return y;
}

LL LCM(LL x, LL y){
        if(x < y) swap(x, y);
        return (x/GCD(x, y))*y;
}


int main(int argc, char* argv[]){
	int N;
	LL T[102] = {0};

	cin >> N;
	LL ans = 0;
	for(int i=1; i<=N; i++){
		cin >> T[i];
		if(i == 1){
			ans = T[1];
		}
		else{
			ans = LCM(ans, T[i]);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
def cmb(n, r):
  if r == 0: return 1
  if r == 1: return n
  if n < r: return 0
  if n - r < r: r = n - r

  numerator = [n - r + k + 1 for k in range(r)]
  denominator = [k + 1 for k in range(r)]

  for p in range(2,r+1):
    pivot = denominator[p - 1]
    if pivot > 1:
      offset = (n - r) % p
      for k in range(p-1,r,p):
        numerator[k - offset] /= pivot
        denominator[k] /= pivot

  result = 1
  for k in range(r):
    if numerator[k] > 1:
      result *= int(numerator[k])

  return result

n,k = map(int,input().split())
blue = k
red = n-k

print(red+1)
for i in range(2,blue+1):
  tmp = (cmb(red+1,i)%(10**9+7)) * (cmb(blue-1,i-1)%(10**9+7))
  print(tmp % (10**9+7))


Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
int main(){
  int n,k,c=0;cin>>n>>k;vector<int>a(n);
  r(i,k){
    int d;cin>>d;
    r(j,d){
      int x;cin>>x;a.at(x-1)++;
    }
  }
  r(i,n){if(a.at(i)==0)c++;}
  cout<<c<<endl;
}

Measured memory_bytes: 3632
// #include <bits/stdc++.h>
#include <algorithm>
#include <bitset>
#include <climits>
#include <complex>
#include <cstring>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
//#define dump(x) cerr << #x << "=" << (x) << endl;
using namespace std;
const int INF = (int)2e9 + 1;
const long long LINF = (long long)9e18 + 1;

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

  int N, K, Q, temp;
  cin >> N >> K >> Q;

  vector<int> point(N);
  for (int i = 0; i < Q; i++) {
    cin >> temp;
    point[--temp]++;
  }

  for (int i = 0; i < N; i++) {
    if (point[i] <= Q - K) {
      cout << "No" << endl;
    } else {
      cout << "Yes" << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int N = 50;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
typedef pair<int,int> P;
typedef long long ll;
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(auto &t:a)cin>>t;return i;}
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T> void prArr(T a,string s=" "){int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}
int n,XYZ[3];

int DP(){

  struct dat{
    int idx;
    vector<P> A;
    dat(){}
    dat(int idx,vector<P>A):idx(idx),A(A){};
  };
 
  queue<dat> Q;
  map<vector<P>,int> dp[N];

  Q.push(dat(0,{}));
  dp[0][{}] = 1;
  
  while(!Q.empty()){
    auto t = Q.front();Q.pop();
    int idx = t.idx;
    auto A = t.A;
    int sum = dp[idx][A]%mod;
    if(idx == n) continue;
    
    A.push_back(P(0,0));
    for(int i=1;i<=10;i++){
      vector<P> nA;
      int nidx = idx+1;
      int ok = 1;
      for(auto p:A) {
        int sum = p.first + i;
        int k = p.second;
        if(sum == XYZ[k]) k++,sum = 0;
        if(k == 3) ok = 0;
        if(k == 3 || sum > XYZ[k]) continue;
        nA.push_back(P(sum,k));
      }
      if(!ok) continue;
      if(dp[nidx].count(nA) == 0) Q.push(dat(nidx,nA));
      dp[nidx][nA] = (dp[nidx][nA] + sum)%mod;
    }    
  }
  int res = 1;
  for(int i=0;i<n;i++) res = res * 10 %mod;
  for(auto p:dp[n]) res = (res - p.second + mod) % mod;
  return res;
}

signed main(){
  cin>>n>>XYZ[0]>>XYZ[1]>>XYZ[2];
  int ans = DP();
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 21760
#include <bits/stdc++.h>
#include <bitset>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S, T;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

int main(){
    cin>>N>>K;
    if(N == 2){
        cout<<(K == 2 ? "Yes\n1\n2\n3" : "No")<<endl;
    }else if(K == 1 || K == N*2 - 1){
        cout<<"No"<<endl;
    }else {
        cout<<"Yes"<<endl;
        vec ans(N*2 - 1);
        vector<bool> used(N*2, false);
        if(K == 2){
            ans[N - 1] = 2;
            ans[N - 2] = 1;
            ans[N - 3] = 4;
            ans[N] = 3;
            rep(i,4) used[i+1] = true;
        }else {
            ans[N - 1] = K;
            ans[N - 2] = K + 1;
            ans[N - 3] = K - 1;
            ans[N] = K - 2;
            reps(i, K - 3, K + 1) used.at(i + 1) = true;
        }
        ll id = 0;
        reps(i, 1, N * 2) {
            if (id == N - 3) id += 4;
            if (used[i]) i += 4;
            if(i == N * 2) break;
            //cout<<id<<' '<<i<<endl;
            ans.at(id++) = i;
        }
        rep(i, N * 2 - 1) cout<<ans[i]<<endl;

    }
}

Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,K;cin>>N>>K;
  vector<int> a(N);
  for(int i=0;i<N;i++)cin>>a.at(i);
  sort(a.begin(),a.end());
  
  int ans=1000000000,sub;
  for(int i=0;i<N-K+1;i++){
    sub=a.at(i+K-1)-a.at(i);
    ans=min(ans,sub);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000000
using namespace std;
int main(){
    string g;
    string s = "?";
    int y,m,d;
    while(1){
        cin >> g;
        if(g=="#") return 0;

        cin >> y >> m >> d;

        if(y>=31){
            if(y==31&&m>=5){
                cout << s << " " << y-30 << " " << m << " " << d << endl;
            }else if(y>=32){
                cout << s << " " << y-30 << " " << m << " " << d << endl;
            }else{
                cout << g << " " << y << " " << m << " " << d << endl;
            }
        }else{
            cout << g << " " << y << " " << m << " " << d << endl;
        }
    }

}


Measured memory_bytes: 3200
#include<bits/stdc++.h>
#define int long long

using namespace std;

const int N = 1e5;

int readInt ()
{
    bool minus = false;
    int result = 0;
    char ch;
    ch = getchar();
    while (true)
    {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getchar();
    }
    if (ch == '-') minus = true;
    else result = ch-'0';
    while (true)
    {
        ch = getchar();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus)
        return -result;
    else
        return result;
}
int ans[N + 1][2];
int cnt;
void addEdge(int i, int j)
{
    ans[++cnt][0] = i;
    ans[cnt][1] = j;
}
main() {
    int n = readInt(), k = readInt();
    if ((n - 1) * (n - 2) / 2 < k) {
        puts("-1");
        return 0;
    }
    for (int i = 2; i <= n; i++) {
        addEdge(1, i);
    }
    int cur = (n - 1) * (n - 2) / 2;
    for (int i = 2; i <= n; i++) {
        for (int j = i + 1; cur > k && j <= n; j++) {
            addEdge(i, j);
            cur--;
        }
    }
    cout << cnt << "\n";
    for (int i = 1; i <= cnt; i++) {
        cout << ans[i][0] << " " << ans[i][1] << "\n";
    }
}
/**


**/


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

int main() {
  string s;
  cin >> s;
  int n =  s.size();
  vector<ll> a(n+1,0);
  rep(i,n) {
    if(s.at(i)=='<') {
      a[i+1] = a[i]+1;
    }
  }
  for(int i = n; i > 0; --i) {
    if(s.at(i-1)=='>') {
      a[i-1] = max(a[i-1], a[i]+1);
    }
  }
  ll ans = 0;
  rep(i,n+1) ans += a[i];
  cout << ans << endl;
}


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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

ll h, w;

ll ans = INF;

int main(void) {
  // Here your code !
  scanf("%lld %lld\n", &h, &w);

  for (ll i = 1; i <= h; ++i) {
    ll mid = (i + h) / 2;

    ll cur_base = w * i;

    for (ll j = max(mid - 2, i); j <= min(mid + 2, h); ++j) {
      ll cur_1 = w * (j - i);
      ll cur_2 = w * (h - j);

      ll cur_diff = max(cur_base, max(cur_1, cur_2)) - min(cur_base, min(cur_1, cur_2));

      ans = min(ans, cur_diff);
    }
  }

  for (ll i = 1; i <= h; ++i) {
    ll mid = w / 2;

    ll cur_base = w * i;

    for (ll j = max(mid - 2, 0LL); j <= min(mid + 2, w); ++j) {
      ll cur_1 = (h - i) * j;
      ll cur_2 = (h - i) * (w - j);

      ll cur_diff = max(cur_base, max(cur_1, cur_2)) - min(cur_base, min(cur_1, cur_2));

      ans = min(ans, cur_diff);
    }
  }

  for (ll i = 1; i <= w; ++i) {
    ll mid = (i + w) / 2;

    ll cur_base = h * i;

    for (ll j = max(mid - 2, i); j <= min(mid + 2, w); ++j) {
      ll cur_1 = h * (j - i);
      ll cur_2 = h * (w - j);

      ll cur_diff = max(cur_base, max(cur_1, cur_2)) - min(cur_base, min(cur_1, cur_2));

      ans = min(ans, cur_diff);
    }
  }

  for (ll i = 1; i <= w; ++i) {
    ll mid = h / 2;

    ll cur_base = h * i;

    for (ll j = max(mid - 2, 0LL); j <= min(mid + 2, h); ++j) {
      ll cur_1 = (w - i) * j;
      ll cur_2 = (w - i) * (h - j);

      ll cur_diff = max(cur_base, max(cur_1, cur_2)) - min(cur_base, min(cur_1, cur_2));

      ans = min(ans, cur_diff);
    }
  }

  printf("%lld\n", ans);

  return 0;
}


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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> x(n), y(n), h(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i] >> h[i];
  }
  for (int cx = 0; cx <= 100; cx++) {
    for (int cy = 0; cy <= 100; cy++) {
      int ans = 1;
      for (int i = 0; i < n; i++) {
        int d = abs(cx - x[i]) + abs(cy - y[i]);
        if (h[i] > 0) {
          ans = max(ans, d + h[i]);
        }
      }
      bool ok = true;
      for (int i = 0; i < n; i++) {
        int d = abs(cx - x[i]) + abs(cy - y[i]);
        ok &= max(ans - d, 0) == h[i];
      }
      if (ok) {
        cout << cx << ' ' << cy << ' ' << ans << endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pii pair<int,int>
#define pb push_back
#define nmax
#define inf
using namespace std;

int main()
{
    long long ans = 0;
    int n;
    cin>>n;
    for (int i=1;i<=n;++i){
        if (i % 5 == 0 || i % 3 == 0){
            continue;
        }
        ans += i;
    }
    cout<<ans<<'\n';
    return 0;
}


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

int main()
{
	int a,b,c,d=0;
	cin>>a>>b>>c; 
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	for(int i=b;i<=c;i++){
		if(i%a==0)
			d++;
	}
	if(d>0)
		cout<<"OK";
	else
		cout<<"NG";
	return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<utility>
#include<queue>
#define rep(i, n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int n, k;
	cin>>n>>k;
	int a[n];
	rep(i, n){
		cin>>a[i];
	}
	cout<<(n-2)/(k-1)+1<<endl;
	return 0;
}

Measured memory_bytes: 640
from fractions import gcd
import math
K = (int)(input())
sum = 0        
for a in range(3,K+1):
    for b in range(2,a):
        for c in range(1,b):
            sum += 6*math.gcd(math.gcd(a,b),c)
for a in range(1,K+1):
    sum += a
for a in range(2,K+1):
    for b in range(1,a):
        sum += 6*math.gcd(a,b)
print(sum)

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

const int mod = 1e9 + 7;
struct mint {
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    mint up = 0, down = 0;
    rep(i, n) for(int j = i + 1; j < n; j++){
        if (a[i] < a[j]) up.x++;
        else if (a[i] > a[j]) down.x++;
    }
    mint ans = 0;
    ans += up * k * (k - 1) / 2 + down * (k + 1) * k / 2;
    cout << ans.x << endl;
}

Measured memory_bytes: 3640
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    if((a+b)%2==0) System.out.println((a+b)/2);
    else System.out.println((a+b)/2+1);
  }
}

Measured memory_bytes: 21716
#include <iostream>
#include <vector>
using namespace std;
// class Vector
// {
//     int a[200000];
//     int i = 0;

// public:
//     void pushBack(int x); //外からもらう値かどうか
//     void randomAccess(int p);
//     void popBack();
// };
// void Vector::pushBack(int x)
// {
//     a[i] = x;
//     i++;
// }
// void Vector::randomAccess(int p)
// {
//     cout << a[p] << endl;
// }
// void Vector::popBack()
// {
//     // (*i)--; //()がないと--が優先されている
//     i--;
// }
int main()
{
    vector<int> v; //vector型のint型の配列のような
    int q;
    cin >> q;

    while (q)
    {
        int query;
        cin >> query;
        if (query == 0)
        {
            int x;
            cin >> x;
            v.push_back(x);
        }
        else if (query == 1)
        {
            int p;
            cin >> p;
            cout << v[p] << endl;
        }
        else if (query == 2)
        {
            v.pop_back();
        }
        q--;
    }
}


Measured memory_bytes: 3840
#include<iostream>
#include<fstream>
#include<sstream>
#include<cstdio>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<cstdlib>
#include<climits>
#include<utility>
#include<cctype>
using namespace std;

#define ull unsigned long long
#define stt(it,order) sort(it.begin(),it.end(),order)
#define st(it) sort(it.begin(),it.end())
#define ll long long
#define rep(i,j) for(int i=0;i<j;++i)
#define loop(i,a,j) for(int i=a;i<j;++i)
#define mpi(it,table,T,E) for(map<T,E>::iterator it = table.begin();it!=table.end();++it)
#define PI 3.141592654
#define pb(v,e) v.push_back(e)
#define ms(a,v) memset(a,v,sizeof(a))
#define cp(a,b,n) rep(i,n)a[i] = b[i]
#define print_array_int(a,n) rep(i,n-1){printf("%d ",a[i]);}printf("%d\n",a[n-1])

string sint(int i){
   stringstream buf;
   buf<<i;
   return buf.str();
}

/*
ifstream fin("input.txt");
ofstream fout("output.txt");
#define cin fin
#define cout fout
*/

int n;
int ant[15],ata[15];

bool check(){
   rep(i,n){
      if(ant[i] != ata[i])return false;
   }
   return true;
}

int main(){
   while(scanf("%d",&n) != EOF, n){
      rep(i,n){
         scanf("%d",&ant[i]);
      }
      int times = 0;
      ms(ata,0);
      map<int,int> tt;
      while( times<5 ){
         tt.clear();
         times++;
         rep(i,n){
            tt[ant[i]]++;
         }

         rep(i,n){
            ata[i] = tt[ant[i]];
         }

         if( check()){
            break;
         }
         cp(ant,ata,n);
      }

      printf("%d\n",times-1);
      print_array_int(ant,n);
   }
   return 0;
}

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

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

    ll res=0;
    rep(i,N.size()){
        res+=N[i]-'0';
    }

    if(res%9==0)cout<<"Yes";
    else cout<<"No";

    return 0;
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 2e5 + 5;

vi g[MAXN];

int dp[MAXN];
int prv[MAXN];
int vv[MAXN], top_vv;
int sorted[MAXN], top_sorted;

void dfs(int s) {
	REP(i, 0, SZ(g[s])) {
		int to = g[s][i];
		if (to != prv[s]) {
			prv[to] = s;
			dfs(to);
		}
	}
	sorted[top_sorted++] = s;
}

void solve(){
	int n;
	scanf("%d", &n);
	REP(i, 1, n) {
		int a, b;
		scanf("%d%d", &a, &b);
		g[a].pb(b);
		g[b].pb(a);
	}
	
	int cnt = 0;
	REPN(i, 1, n) {
		cnt += SZ(g[i]) % 2;
	}
	cnt /= 2;
	
	int ind = 0;
	REPN(i, 1, n) {
		if (SZ(g[i]) == 1) {
			ind = i;
			break;
		}
	}
	dfs(ind);
	
	int l = 0, r = n - 1;
	for(; l + 1 < r; ) {
		int lim = (l + r) >> 1;
		bool good = true;
		REP(i, 0, n) {
			int s = sorted[i];
			dp[s] = 0;
			top_vv = 0;
			REP(j, 0, SZ(g[s])) {
				int to = g[s][j];
				if (to != prv[s]) {
					vv[top_vv++] = dp[to] + 1;
				}
			}
			
			if (top_vv % 2 == 0) {
				vv[top_vv++] = 0;
			}
			
			sort(vv, vv + top_vv);
			
			if (vv[top_vv - 1] > lim) {
				good = false;
			} else {
				for(int ind_r = top_vv / 2, ind_l = top_vv / 2 - 1; ind_l >= 0; ind_l--, ind_r++) {
					if (vv[ind_r] + vv[ind_l] > lim) {
						good = false;
						break;
					}
				}
			}
			if (good) {
				int ind = top_vv - 1;
				for(ind--; ind >= 0; ind--) {
					if (ind >= top_vv / 2) {
						if (vv[ind + 1] + vv[top_vv - 2 - ind] > lim) {
							break;
						}
					} else {
						if (vv[ind + 1] + vv[top_vv - 1 - ind] > lim) {
							break;
						}
					}
				}
				ind++;
				dp[s] = vv[ind];
			}
			
			if (!good) {
				break;
			}
		}
		
		if (good) {
			r = lim;
		} else {
			l = lim;
		}
	}
	
	printf("%d %d\n", cnt, r);
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 16128
import sys
sys.setrecursionlimit(10**6)

def check(y,x):
    if 0<=y<=h-1 and 0<=x<=w-1:
        if g[y][x]=="#":
            return True
    return False

def dfs(y,x):
    dx=(0,1)
    dy=(1,0)
    if y==h-1 and x==w-1:
        return True
    for i in xrange(2):
        nxy=y+dy[i]
        nxx=x+dx[i]
        if check(nxy,nxx) and not visited[nxy][nxx]:
            visited[nxy][nxx]=True
            if dfs(nxy,nxx):
                return True
            visited[nxy][nxx]=False
    return False

h,w=map(int,raw_input().split())
g=[raw_input() for _ in xrange(h)]
visited=[[False]*w for _ in xrange(h)]
visited[0][0]=True
if not dfs(0,0):
    print("Impossible")
    exit()
for i in xrange(h):
    for j in xrange(w):
        if g[i][j]=="#" and not visited[i][j]:
            print("Impossible")
            exit()
print("Possible")

Measured memory_bytes: 2696
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int[] a = new int[n];
			IntStream.range(0, n).forEach(i -> a[i] = scanner.nextInt());
			Arrays.sort(a);
			int max = a[n - 1];
			int[] b = new int[n - 1];
			IntStream.range(0, n - 1).forEach(i -> b[i] = Math.min(a[i], max - a[i]));
			Arrays.sort(b);
			int next = b[n - 2];
			if (Arrays.binarySearch(a, next) >= 0) {
				System.out.println(max + " " + next);
			} else {
				System.out.println(max + " " + (max - next));
			}
		}
	}
}


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

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;;
int main()
{
	int n;
	cin>>n;
	vector <int> dp(3);
	for(int day = 0 ; day < n ; day++)
	{
		vector <int> new_dp(3,0);
		vector <int> c(3);
		for(auto &x : c)
			cin>>x;
		for(int i=0;i<3;i++)
		{
			for(int j=0;j<3;j++)
			{
				if(i!=j)
					new_dp[j] = max(new_dp[j] , dp[i]+c[j]);
			}
		}
		dp = new_dp;
	}
	cout<<max({dp[0] , dp[1] , dp[2]})<<endl;
	return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <sstream>
#include <istream>

using namespace std;

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


int main(){
	ll a,b,c;
	cin >> a >> b >> c;
	ll ans;
	if(a+b+1<c){
		ans = b+(a+b)+1;
	}else{
		ans = b+c;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
const double PI  = 3.1415926535897932384626433832795028841971;
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n, m, k;
int a[15], b[15];
P c[15];

int main(){
	cin >> n >> m >> k;
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n) c[i] = P(a[i],b[i]);
    int ans = 0;
    sort(c,c+n);
    rep(i,(1<<n)){
        int fl = 0, ii = i;
        vector<P> tmp;
        rep(j,n){
            if(ii&1){
                fl++;
                tmp.push_back(c[j]);
            }
            ii >>= 1;
        }
        if(fl > k) continue;
        sort(tmp.begin(),tmp.end(),greater<P>());
        int mm = m, cnt = 0;
        rep(j,tmp.size()){
            cnt += tmp[j].first*min(mm,tmp[j].second);
            mm -= tmp[j].second;
            if(mm <= 0) break;
        }
        ans = max(ans,cnt+max(mm,0));
    }
    cout << ans << endl;
}

Measured memory_bytes: 1204
import Control.Applicative

solver :: Int->Int->Bool
solver a b = or $ [a`mod`3==0,b`mod`3==0,(a+b)`mod`3==0]

myshow :: Bool -> String
myshow True = "Possible"
myshow False = "Impossible"
 
main :: IO ()
main = do
    -- スペース区切り整数の入力
    [a, b] <- map read . words <$> getLine
    -- 出力
    putStrLn $ myshow $ solver a b



Measured memory_bytes: 508
# -*- coding: utf-8 -*-
def isMonth(value):
  return (value >= 1) and (value <= 12)


s = input()
first = int(s[:2])
last = int(s[2:])

if isMonth(first) and isMonth(last):
  print('AMBIGUOUS')
elif not isMonth(first) and not isMonth(last):
  print('NA')
elif not isMonth(first):
  print('YYMM')
else:
  print('MMYY')


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>
#include <thread>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>


ll n, s[210000], sum, ans = INF, now;
int main() {
	cin >> n;
	REP(i, n) {
		cin >> s[i];
		sum += s[i];
	}
	REP(i, n) {
		now += s[i];
		ans = min(ans, abs(sum - now - now));
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
from math import gcd

from math import factorial as f

from math import ceil, floor, sqrt
import math

import bisect
import re
import heapq

from copy import deepcopy
import itertools
from itertools import permutations

from sys import exit

ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(map(int, input().split()))

yes = "Yes"
no = "No"


def main():
    f = [[0,0] for i in range(200005)]
    n = ii()
    for i in range(n):
        x,y = mi()
        f[i][0] = x+y
        f[i][1] = x-y
    xmax,ymax,xmin,ymin = 0,-1000000000000000,100000000000000000,10000000000000000
    for i in range(n):
        xmax = max(xmax,f[i][0])
        xmin = min(xmin,f[i][0])
        ymax = max(ymax,f[i][1])
        ymin = min(ymin,f[i][1])

    xmax = max(xmax-xmin,ymax-ymin)

    print(xmax)





main()


Measured memory_bytes: 39972
#include<bits/stdc++.h>
#define int long long
#define ld long double
#define ri register int
#define il inline
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define vi vector<int>
#define all(x) x.begin(),x.end() 
#define rep(i,a,b) for(ri i=(a);i<=(b);++i)
#define per(i,a,b) for(ri i=(a);i>=(b);--i)
#define ls (x<<1)
#define rs (x<<1|1)
#define mid (l+r>>1)
#define db(x) cout << "#x:" << x << endl
#define dd() cout << "Out put!\n"
const int mod=1e9+7,eps=1e-6,pi=acos(-1.0),maxn=1000010;
const int inf=0x7f7f7f7f7f7f7f7f;
using namespace std;
int a[maxn],b[maxn],c[maxn];
string s; 
int ok(int x,int y)
{
	if(x-a[x]-0.5 > y)
		return 0;
	if(x+a[x]+0.5 < y)
		return 0;
	return 1;
}
signed main()
{
	ios::sync_with_stdio(0);
	int t=1;
//	cin >> t;
	while(t--)
	{
		int n,k;
		cin >>n  >> k;
		int cnt = 0;
		rep(i,1,n)
			cin >> a[i];
		while(k--)
		{
		//	cout << k << endl;
			rep(i,1,n)
				b[i] = 0;
			rep(i,1,n)
			{
				int l=max(1ll,i-a[i]);
				int r=min(n,i+a[i]);
				b[l]++,b[r+1] --;
			}
			int sum = 1;
			rep(i,1,n)
				b[i] += b[i-1],a[i] = b[i];
			rep(j,1,n)
				if(a[j]<n)
					sum = 0;
			if(sum )
				break;
		}
		rep(i,1,n)
			cout << a[i] <<" ";
	} 
	return 0;
}

Measured memory_bytes: 6748
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <math.h>
#include <map>
using namespace std;

int main(){
	int h,w,K;
	cin >> h >> w >> K;
	char c[h][w];
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin >> c[i][j];
		}
	}
	
	vector<vector<int>> hs(1<<h);
	for(int i=0;i<(1<<h);i++){
		for(int j=0;j<h;j++){
			if(i&(1<<j)){
				hs[i].push_back(1);
			}else{
				hs[i].push_back(0);
			}
		}
	}
	
	vector<vector<int>> ws(1<<w);
	for(int i=0;i<(1<<w);i++){
		for(int j=0;j<w;j++){
			if(i&(1<<j)){
				ws[i].push_back(1);
			}else{
				ws[i].push_back(0);
			}
		}
	}
	
	int ans=0;
	for(int i=0;i<hs.size();i++){
		for(int k=0;k<ws.size();k++){
			int cnt=0;
			for(int x=0;x<h;x++){
				if(hs[i][x]==0)continue;
				for(int y=0;y<w;y++){
					if(ws[k][y]==0)continue;
					if(c[x][y]=='#')cnt++;
				}
			}
			if(cnt==K)ans++;
		}
	}
	cout << ans << endl;			
	return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define MAX(a, b) (a > b ? a : b)
#define MIN(a, b) (a < b ? a : b)
#define int long long
using namespace std;

long long N;

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin >> N;
  long long ans = 1e18;
  for(int i = 1; i * i <= N; i++) {
    if(N % i == 0) {
      ans = MIN(ans, MAX(log10(i), log10(N / i)));
    }
  }
  cout << ans + 1 << "\n";
}

Measured memory_bytes: 512
N = int(input())
T,A = map(int,input().split())
H = list(map(int,input().split()))

d = 1000
ans = 0
for i,h in enumerate(H):
    d_ = abs(A-(T-h*0.006))
    if d > d_:
        d = d_
        ans = i
print(ans+1)

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

typedef struct{
	char name[10];
	int time;
}Process;

Process p[100000];
int head,tail;

int isEmpty(){
	return head == tail;
}

int isFull(){
	return head == (tail + 1) % 100000;
}

void enqueue(Process x){
	if(isFull()){
		exit(1);
	}
	p[tail] = x;
	if(tail+1 == 100000){
		tail = 0;
	}else{
		tail++;
	}
}

Process dequeue(){
	Process x = p[head];
	if(head + 1 == 100000){
		head = 0;
	}else{
		head++;
	}
	return x;
}

int main(void){
	int n,i,q,sum = 0;
	Process x;
	scanf("%d %d",&n,&q);
	for(i=0;i<n;i++){
		scanf("%s %d",p[i].name,&p[i].time);
	}
	head = 0,tail = n;
	while(isEmpty() != 1){
		x = dequeue();
		if(x.time <= q){
			sum += x.time;
			printf("%s %d\n",x.name,sum);
		}else{
			sum += q;
			x.time -= q;
			enqueue(x);
		}
	}
	return 0;
}


Measured memory_bytes: 3268
using System;
class a
{
    public static void Main()
    {
        string[] str = Console.ReadLine().Split(' ');
        int n = int.Parse(str[0]);
        int a = int.Parse(str[1]);
        int b = int.Parse(str[2]);
        if (n * a > b)
            Console.WriteLine(b);
        else
            Console.WriteLine(n * a);
      
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <random>
#include <queue>
#include <sstream>
#include <iomanip>

using namespace std;

using Graph = vector<vector<int> >;

vector<int> seen;



int main()
{
	int N;

	cin >> N;

	vector<int> Ls(N);

	for (int ni = 0; ni < N; ni++) {
		cin >> Ls[ni];
	}

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


	int add;
	long long cnt = 0;
	//int cs, ce;
	for (int ai = 0; ai < N - 2; ai++) {
		//if (ai != 0 && Ls[ai - 1] == Ls[ai])continue;
		for (int bi = ai + 1; bi < N - 1; bi++) {
			//if (bi != ai + 1 && Ls[bi - 1] == Ls[bi])continue;
			add = Ls[ai] + Ls[bi];
			//cs = lower_bound(Ls.begin(), Ls.end(), Ls[bi]+1 ) - Ls.begin();
			//ce = upper_bound(Ls.begin(), Ls.end(), add-1 ) - Ls.begin();
			//cnt += max(0,ce - cs);
			
			for (int ci = bi + 1; ci < N; ci++) {
				//if (ci != bi + 1 && Ls[ci - 1] == Ls[ci])continue;
				if (Ls[ci] < add) {
					cnt++;
				}
				else {
					break;
				}
			}
		}
	}


	//printf("%d %d %lld", xi, yi, H + gap);

	cout << cnt;


	return 0;
}



Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
const long long mod = 1e9 + 7;

int main(){
     int n;
     cin >> n;
     if(n % 2 == 0) cout << 0.5 << endl;
     else{
          double ans = (n - 1) / 2 + 1;
          ans /= n;
          cout << ans << endl;
     }
}

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


signed main(){
	Int n;
	cin>>n;
	Int f[n][10];
    for(Int i=0;i<n;i++)
    	for(Int j=0;j<10;j++)
        	cin>>f[i][j];
    Int p[n][11];
    for(Int i=0;i<n;i++)
    	for(Int j=0;j<11;j++)
        	cin>>p[i][j];

    Int ans=-(1LL<<55);
    for(Int b=1;b<(1<<10);b++){
    	Int tmp=0;
    	for(Int i=0;i<n;i++){
        	Int k=0;
        	for(Int j=0;j<10;j++)
        		if((b>>j)&1) if(f[i][j]) k++;
        		tmp+=p[i][k];
      	}
		ans=max(ans,tmp);
    }

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

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

#define reps(v, f, l) for (int v = (f), v##_ = (l); v < v##_; ++v)
#define rep(v, n) reps(v, 0, n)
#define lep(v, n) reps(v, 1, n + 1)

using namespace std;

typedef long long int lint;

static inline int in(){ int x; scanf("%d", &x); return x; }
static inline lint inl(){ lint x; scanf("%lld", &x); return x; }
template<typename T> void show(T& a, char del='\n', char last='\n'){ rep(i, a.size() - 1) cout << a[i] << del; cout << a[a.size() - 1] << last; }

struct Edge {
  int from, to, w;
  Edge(int from, int to, int w) : from(from), to(to), w(w) {}
  Edge(){}
  bool operator<(const Edge& x) const {
    return w != x.w ? w > x.w : from != x.from ? from < x.from : to < x.to;
  }
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

int prim(const Graph& g, int r=0){
  int n = g.size();
  int total = 0;
  vector<bool> visited(n);
  priority_queue<Edge> Q;
  Q.push(Edge(-1, r, 0));
  while (!Q.empty()){
    Edge e = Q.top();
    Q.pop();
    if (visited[e.to]) continue;
    total += e.w;
    visited[e.to] = true;
    for (Edges::const_iterator f = g[e.to].begin(); f != g[e.to].end(); f++){
      if (!visited[f->to]) Q.push(*f);
    }
  }
  return total;
}

int main()
{
  int n, m;
  while (n = in(), m = in(), n){
    Graph g(n);
    rep(i, m){
      int from, to, w;
      from = in();
      to = in();
      w = in();
      g[from].push_back(Edge(from, to, w));
      g[to].push_back(Edge(to, from, w));
    }
    printf("%d\n", prim(g));
  }
  return 0;
}

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

//vector…可変長、データの大きさに合わせてサイズを変える
//list…双方向リスト、要素を挿入、削除の多いとき
//forward_list
//array…固定長配列
//set…集合
//multiset
//bitset…2進数、固定長ビット列
//map…連想配列、キーと値を関連付ける
//multimap
//deque
//stack…FILO
//queue…FIFO
//priority_queue…格納された最大値から順に取り出す
//pair…二つの値を一組
//tuple…複数の値を一組

template<typename T>
void remove(std::vector<T>& vector, char index) {
    vector.erase(vector.begin() + index);
}

template<class T>
T ma(std::vector<T> &v) {
    T maxi = 0;
    for(auto &i:v) maxi = max(maxi, i);
    return maxi;
}

template<class T>
T mi(std::vector<T> &v) {
    T mini = 0;
    for(auto &i:v) mini = min(mini, i);
    return mini;
}

template <class T>
T pow(T x, T y, T n = numeric_limits<T>::max()) {
    if(y == 0) return 1;
    if(y % 2 == 0) return pow((x * x) % n, y / 2);
    return (x * pow(x, y - 1)) % n;
}

#define rep(i, n, m) for (int i = n; i <= m; i++)
#define Rep(i, n, m) for (int i = m; i >= 1; i--)

typedef long long ll;
typedef unsigned long long ull;

/*
int gcd(int x, int y) {
    if (x < y) swap(x, y);
    return !y ? x : gcd(x % y, y);
}
*/
int main() {
    vector<string> C(3);
    rep(i, 0, 2) cin >> C[i];

    int i = 0;
    do {
        int j = C[i].front() - 'a';
        C[i].erase(C[i].begin());
        i = j;
        if (C[i].empty()) {
            break;
        }
    } while (true);

    switch (i) {
        case 0:
            cout << 'A' << endl;
            return 0;
        case 1:
            cout << 'B' << endl;
            return 0;
        case 2:
            cout << 'C' << endl;
            return 0;
    }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    string S;
    cin >> S;
    int N = S.size();
    for(int i = N-1; i >= 1; i--){
        if(S[i] != '9'){
            int ans = S[0] - '0' - 1;
            ans += (9*(N-1));
            cout << ans << endl;
            return 0;
        }
    }
    int ans = S[0] - '0';
    ans += (9*(N-1));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256