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

int main(){
  string s, c;
  bool flag=false;
  int q, f, t;
  cin >> s >> q;
  for(int i=0;i<q;i++){
    cin >> t;
    if(t==1){
      if(flag==false)flag=true;
      else flag=false;
    }
    else{
      cin >> f >> c;
      if((flag==false&&f==1)||(flag==true&&f==2)){
        s.insert(0,c);
      }
      else{
        s+=c;
      }
    }
  }
  if(flag==false)cout << s << endl;
  else{
    reverse(s.begin(), s.end());
    cout << s << endl;
  }
  return 0;
}


Measured memory_bytes: 900
#include <stdio.h>

void main()
{
	int N, A[200000],i,jo;
	scanf("%d", &N);
	for (i = 0; i < N; i++)
	{
		A[i]=0;
	}
	for (i = 0; i < N-1; i++)
	{
		scanf("%d", &jo);
		A[jo-1]++;
	}
	for (i = 0; i < N; i++)
	{
		printf("%d\n",A[i]);
	}

}

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

using namespace std;

#define ll long long int
#define ld long double
#define MAX 1000001
#define MOD 1000000007
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

int main(){

    fast;

    ll i,n;
    cin >> n;
    ll a[n];
    for(i=0;i<n;i++){
        cin >> a[i];
    }

    ll dp[2][n];

    dp[0][0]=0;
    dp[1][0]=0;
    dp[0][1]=abs(a[1]-a[0]);
    dp[1][1]=abs(a[1]-a[0]);

    for(i=2;i<n;i++){
        dp[0][i]= abs(a[i]-a[i-1]) + min(dp[0][i-1],dp[1][i-1]);
        dp[1][i]= abs(a[i]-a[i-2]) + min(dp[0][i-2],dp[1][i-2]);
    }

    cout << min(dp[0][n-1],dp[1][n-1]) << endl;

}

//    cout << fixed << setprecision(12);




Measured memory_bytes: 2560
// tsukasa_diary's programing contest code template
#include <bits/stdc++.h>
using namespace std;
#define TSUKASA_DIARY_S_TEMPLATE
// define
#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define for_rev(i,a,b) for(int i=(a);i>=(b);--i)
#define allof(a) (a).begin(),(a).end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) int((a).size())
#define cauto const auto
// typedef
typedef long long lint;
typedef double Double;
typedef pair< int, int > pii;
template< typename T > using Vec = vector< T >;
template< typename T > using Matrix = Vec< Vec< T > >;
template< typename T > using USet = unordered_set< T >;
template< typename T, class C > using MyUSet = unordered_set< T, C >;
template< typename T, typename F > using UMap = unordered_map< T, F >;
template< typename T, typename F, class C > using MyUMap = unordered_map< T, F, C >;
// hash
class PiiHash { public: size_t operator () (const pii& p) const { return (p.first << 16) | p.second; } };
// popcount
inline int POPCNT(int x) { return __builtin_popcount(x); }
inline int POPCNT(lint x) { return __builtin_popcount(x); }
// inf
const int iINF = 1L << 30;
const lint lINF = 1LL << 60;
// eps
const Double EPS = 1e-9;
const Double PI = acos(-1);
// inrange
template< typename T >
inline bool in_range(T v, T mi, T mx) { return mi <= v && v < mx; }
template< typename T >
inline bool in_range(T x, T y, T W, T H) { return in_range(x,0,W) && in_range(y,0,H); }
// neighbor clockwise
const int DX[4] = {0,1,0,-1}, DY[4] = {-1,0,1,0};
const int DX_[8] = {0,1,1,1,0,-1,-1,-1}, DY_[8] = {-1,-1,0,1,1,1,0,-1};
// variable update
template< typename T > inline void modAdd(T& a, T b, T mod) { a = (a + b) % mod; }
template< typename T > inline void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > inline void maxUpdate(T& a, T b) { a = max(a, b); }
// converter
template< typename F, typename T >
inline void convert(F& from, T& to) {
	stringstream ss;
	ss << from; ss >> to;
}

int N, a[111];

int calc(int x) {
	int res = 0;
	for_(i,0,N) res += (a[i] - x) * (a[i] - x);
	return res;
}

int main() {
	cin >> N;
	for_(i,0,N) cin >> a[i];
	
	int ans = iINF;
	for_(x,-100,101) minUpdate(ans, calc(x));
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int A, B, sum = 0;
    cin >> A >> B;
    for (int i = 0; i < 2; i++)
    {
        if (A > B)
            sum += (A--);
        else
            sum += (B--);
    }

    cout << sum << endl;
}

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

const int MAXN = 10001;
const int MOD = 998244353;

int pw(int a, int b = MOD - 2) {
    return 0;
}

array<int, MAXN> f, fc, f2, f2c;

string a, b;

int mul(int a, int b) {
    return (ll(a) * b) % MOD;
}

template <typename ... TArgs>
int mul(int x, TArgs&& ... args) {
    return mul(x, mul(std::forward<TArgs>(args)...));
}

int main() {
#ifdef PAUNSVOKNO
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(20);
    cin >> a >> b;
    int n = a.length();

    int k = 0, c = 0;
    for (int i = 0; i < n; i++)
        if (a[i] == '1') {
            k++;
            c += (b[i] - '0');
        }

    f.fill(0);
    f2.fill(0);

    f[0] = 1;

    for (int i = 1; i <= k; i++) {
        fc = f;
        f2c = f2;
        f.fill(0), f2.fill(0);
        for (int j = 0; j <= i; j++) {
            int d = i - j;
            ll ans = 0;

            if (j > 0) {
                f2[j] += mul(fc[j - 1], i);
                if (j > 1) f2[j] += mul(i, j - 1, f2c[j - 1]);
                f2[j] %= MOD;
            }

            if (j) ans += mul(j, fc[j - 1]);
            if (j > 1) {
                ans += mul(j, j - 1, f2c[j - 1]);
            }
            if (d) ans += mul(d, d, fc[j]);
            if (j > 0) ans += mul(j, d, fc[j - 1]);

            f[j] = ans % MOD;
        }

    }

    cout << f[c] << "\n";
}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace puro
{
    class Program
    {
        static void Main(string[] args)
        {
            int a =int.Parse (Console.ReadLine());
            if  (a%2 ==0)
            { Console.WriteLine(a); }
            else { Console.WriteLine(2 * a); }
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define dbug(x) cout<<#x<<"="<<x<<endl
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
char s[10];
int main() {
	//freopen("1.txt","r",stdin);
	scanf("%s",s+1);
	if (s[1]=='S') printf("Cloudy\n");
	else if (s[1]=='C') printf("Rainy\n");
	else printf("Sunny\n");
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
char str[6][10]={"..rr....","..rr....","ggyybbww","ggyybbww","..oo....","..oo...."};
char com[110];
char tmp[6][10];
int main(){
	scanf("%s",com);
	for(int i=0;com[i];i++){
		for(int j=0;j<6;j++)for(int k=0;k<10;k++)tmp[j][k]=str[j][k];
		switch(com[i]){
			case 'U':
				tmp[0][2]=str[1][2];
				tmp[0][3]=str[0][2];
				tmp[1][3]=str[0][3];
				tmp[1][2]=str[1][3];
				tmp[2][0]=str[2][2];
				tmp[2][1]=str[2][3];
				tmp[2][2]=str[2][4];
				tmp[2][3]=str[2][5];
				tmp[2][4]=str[2][6];
				tmp[2][5]=str[2][7];
				tmp[2][6]=str[2][0];
				tmp[2][7]=str[2][1];
				break;
			case 'R':
				tmp[2][4]=str[3][4];
				tmp[2][5]=str[2][4];
				tmp[3][5]=str[2][5];
				tmp[3][4]=str[3][5];
				tmp[0][3]=str[2][3];
				tmp[1][3]=str[3][3];
				tmp[2][3]=str[4][3];
				tmp[3][3]=str[5][3];
				tmp[4][3]=str[3][6];
				tmp[5][3]=str[2][6];
				tmp[2][6]=str[1][3];
				tmp[3][6]=str[0][3];
				break;
			case 'D':
				tmp[4][2]=str[5][2];
				tmp[4][3]=str[4][2];
				tmp[5][3]=str[4][3];
				tmp[5][2]=str[5][3];
				tmp[3][0]=str[3][6];
				tmp[3][1]=str[3][7];
				tmp[3][2]=str[3][0];
				tmp[3][3]=str[3][1];
				tmp[3][4]=str[3][2];
				tmp[3][5]=str[3][3];
				tmp[3][6]=str[3][4];
				tmp[3][7]=str[3][5];
				break;
			case 'L':
				tmp[2][0]=str[3][0];
				tmp[2][1]=str[2][0];
				tmp[3][1]=str[2][1];
				tmp[3][0]=str[3][1];
				tmp[0][2]=str[3][7];
				tmp[1][2]=str[2][7];
				tmp[2][2]=str[0][2];
				tmp[3][2]=str[1][2];
				tmp[4][2]=str[2][2];
				tmp[5][2]=str[3][2];
				tmp[2][7]=str[5][2];
				tmp[3][7]=str[4][2];
				break;
			case 'F':
				tmp[2][2]=str[3][2];
				tmp[2][3]=str[2][2];
				tmp[3][3]=str[2][3];
				tmp[3][2]=str[3][3];
				tmp[1][2]=str[3][1];
				tmp[1][3]=str[2][1];
				tmp[2][4]=str[1][2];
				tmp[3][4]=str[1][3];
				tmp[4][3]=str[2][4];
				tmp[4][2]=str[3][4];
				tmp[3][1]=str[4][3];
				tmp[2][1]=str[4][2];
				break;
			case 'B':
				tmp[2][6]=str[3][6];
				tmp[2][7]=str[2][6];
				tmp[3][7]=str[2][7];
				tmp[3][6]=str[3][7];
				tmp[0][3]=str[3][5];
				tmp[0][2]=str[2][5];
				tmp[2][0]=str[0][3];
				tmp[3][0]=str[0][2];
				tmp[5][2]=str[2][0];
				tmp[5][3]=str[3][0];
				tmp[3][5]=str[5][2];
				tmp[2][5]=str[5][3];
				break;
		}
		for(int j=0;j<6;j++)for(int k=0;k<10;k++)str[j][k]=tmp[j][k];
	}
	for(int i=0;i<6;i++)printf("%s\n",str[i]);
}

Measured memory_bytes: 948
import sys
from copy import copy


N, K, *D = map(int, open(0).read().split())


candidate = sorted(list({i for i in range(10)} - set(D)))
like_integer = copy(candidate)
  
# 1桁の場合を判定
for j in candidate:
  if j >= N:
    print(j)
    sys.exit()
    
for i in range(1, 6):  
  order = 10 ** i
  
  
  _candidate = []
  for l in like_integer:
    for c in candidate:
      lc = order * l + c
      if lc >= N:
        print(lc)
        sys.exit()
      _candidate.append(lc)
  candidate = _candidate
    

Measured memory_bytes: 3700
#include "bits/stdc++.h"

typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))
#define min3(x, y, z) min(x, min(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif

using namespace std;
int main() {
  string a;
  cin >> a;
  if (a == "ARC") {
    cout << "ABC";
  } else {
    cout << "ARC";
  }
  return 0;
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
rep(i,N) {
  cin >> list[i];
}
//配列(スタックとしても使える)
vector<int> list;
list.at(i)
vector<vector<int>> list(10, vector<int>(10));
//ソート クイックだからO(NlogN)
sort(all(list));
sort(all(list), greater<int>());

//配列の最小最大(Nは要素数)
*min_element(all(c))
*max_element(all(c))

//a[0]からa[N]を逆順にする(計算量はO(N))
reverse(all(a));
//listの末尾に要素を追加
list.push_back(10);
//listの末尾から要素を削除
list.pop_back();
//空ですか？
list.empty()



//キュー(待ち行列)
//定義
queue<int> a;
//追加
a.push(x);
//取る
a.pop();
//チェック
a.front()
//サイズ
a.size()
//空ですか
a.empty()



//優先度付きキュー※全部計算量がO(NlogN)あるので注意
// int 型の要素を持ち、最も小さい値を取り出す形の priority_queue を定義
priority_queue<int, vector<int>, greater<int>> Q1;
// double 型の要素を持ち、最も大きい値を取り出す形の priority_queueを定義
priority_queue<double, vector<double>, less<double>> Q2;
//追加
a.push(x);
//取る
a.pop();
//一番小さいの教えて下さい
a.top()
//サイズ
a.size()
//空ですか
a.empty()



//配列の内容表示
dout << "====listの内容====\n";
for (int edp = 0; edp < N; edp++) dout << list[edp] << endl;
dout << "====ここまで====\n";



//部分文字列
//添字3から5文字
s.substr(3,5)
//添字3から全部
s.substr(3)

//入れ替え
swap(a,b);


*/



Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
long long inf=(long long)1E17;
using namespace std;
int main(){
  string s;
  cin>>s;
  string ans="";
  for(int i=0;i<s.size();i+=2){
    ans += s[i];
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n,k;
  cin >> n >> k;
  vector<int>a(n+1);
  for(int i=1;i<=n;i++){
    cin >> a.at(i);
  }
  for(int i=0;i<k;i++){
    vector<int>imos(n+2,0);
    for(int j=1;j<=n;j++){
      int l=max(1,j-a.at(j));
      int r=min(n+1,j+a.at(j)+1);
      imos.at(l)++;
      imos.at(r)--;
    }
    for(int j=1;j<=n;j++){
      imos.at(j)+=imos.at(j-1);
    }
    int flag=0;
    for(int j=1;j<=n;j++){
      if(imos.at(j)!=n){
        flag=1;
      }
    }
    
    for(int j=1;j<=n;j++){
      a.at(j)=imos.at(j);
    }
    if(flag==0){
      break;
    }
  }
  for(int i=1;i<=n;i++){
    if(i!=n){
      cout << a.at(i) << " ";
    }
    else{
      cout << a.at(i);
    }
  }
  return 0;
}


Measured memory_bytes: 4840
//1 tahun dibagi N semester
//tiap akhir semester ada ujian
//hasilnya dikasi grade gt kan

//utk tiap semester K-1, gadikasi grade
//utk tiap semester K hingga N
//hasil ujian sebelumnnya di semester ke K dan baik itu dikasi nilai atau tidak
//dikalikan dengan nilai ujian N

//M dapet Ai di akhir semester ke i (A itu nilai) di semester i gt
//dengan i >= K+1, kalo ga dikasi grade ga dianggep (K-1 gadikasi grade mksdnya) ini kan dikasi
//dan i <= N, kan tiap N ujiannya (gmn ada nilai kl gaada ujian)

//tentukan nilai dia utk semester ke i lebih gede tidak dengan hasil semester i-1 (sebelumnya


//BANDINGINNYA PAKE ARRAY, yatuhan

#include <stdio.h>
int main(){
	int N, K;
	scanf("%d %d", &N, &K);

	int ujian[N+1];

	for(int i =0; i<N; i++)
	{
		scanf("%d", &ujian[i+1]);	//masukin sampe arraynya full
	}

	for(int i= K+1; i<= N; i++)	//selama i memenuhi, kyk di soal
	{
		if(ujian[i] > ujian[i-K])	//selama hasil ujian ke i (kayak Ai disoal) lebih dari yg sebelumnya
		{
			puts("Yes");
		}
		else puts("No");
	}

	return 0;
}


Measured memory_bytes: 2364
N = int(input())
h = list(map(int, input().split()))
cnt = 0
i = 0
for _ in range(100 * 100):
    if h[i] > 0:
        j = i
        cnt += 1
        while j < N and h[j] > 0:
            h[j] = h[j] - 1
            j += 1
    else:
        i += 1
        if i == N:
            break
print(cnt)

Measured memory_bytes: 3060
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int n) { return n & 1; }
constexpr bool even(const int n) { return ~n & 1; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
// clang-format on

using Flow = int;
struct FlowEdge {
  int src, dst, rev;
  Flow cap;
  FlowEdge(const int s = 0, const int d = 0, const Flow c = 0, const int r = 0) : src(s), dst(d), cap(c), rev(r) {}
};

using FlowEdges = std::vector<FlowEdge>;

class FlowGraph {
  std::vector<FlowEdges> g;

public:
  FlowGraph(const int size = 0) : g(size) {}
  size_t size() const { return g.size(); }
  FlowEdges &operator[](const int i) & { return g[i]; }

  void addEdge(const int src, const int dst, const Flow c = 1) {
    g[src].emplace_back(src, dst, c, g[dst].size());
    g[dst].emplace_back(dst, src, 0, g[src].size() - 1);
  }
};

// Change it to 'FlowGraph &g' when you need a residual network
template<Flow inf = std::numeric_limits<Flow>::max() / 8> Flow fordFulkerson(FlowGraph g, const int source, const int sink) {
  std::vector<int> used(g.size());
  std::function<Flow(int, Flow)> dfs = [&](int v, Flow f) -> Flow {
    if (v == sink) return f;
    used[v] = true;
    for (auto &e : g[v]) {
      if (used[e.dst] || e.cap <= 0) continue;
      Flow d = dfs(e.dst, min(f, e.cap));
      if (d <= 0) continue;
      e.cap -= d;
      g[e.dst][e.rev].cap += d;
      return d;
    }
    return 0;
  };
  Flow s = 0;
  for (;;) {
    std::fill(used.begin(), used.end(), false);
    Flow f = dfs(source, inf);
    if (f == 0) return s;
    s += f;
  }
}

constexpr int gcd(int a, int b) {
  while (b) b ^= a ^= b ^= a %= b;
  return a;
}

main {
  int m, n;
  while (cin >> m >> n, m || n) {
    vi b(m), r(n);
    cin >> b >> r;
    FlowGraph g(m + n + 2);
    rep(i, m) g.addEdge(m + n, i);
    rep(i, n) g.addEdge(m + i, m + n + 1);
    rep(i, m) rep(j, n) if (gcd(b[i], r[j]) > 1) g.addEdge(i, m + j);
    cout << fordFulkerson(g, m + n, m + n + 1) << endl;
  }
}

Measured memory_bytes: 20544
import itertools

n, m = map(int, input().split())
pice = []
for _ in range(n):
    x, y, z = map(int, input().split())
    pice.append((x, y, z))
ans = 0
for i, j, k in itertools.product((-1, 1), repeat=3):
    a = [x * i + y * j + z * k for (x, y, z) in pice]
    a.sort()
    ans = max(ans, abs(sum(a[0:m])))
print(ans)


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

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

  int mxi = X;

  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    mxi = max(mxi, x);
  }

  int mni = Y;

  for (int i = 0; i < M; i++) {
    int y;
    cin >> y;
    mni = min(mni, y);
  }

  cout << ((mxi < mni) ? "No War" : "War") << "\n";
}

Measured memory_bytes: 384
#include <vector>
#include <map>
#include <set>
#include <sstream>
#include <iostream>
#include <limits>
#include <algorithm>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <cmath>


using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<pair<int, int>> vii;
typedef stringstream ss;
const int mii = numeric_limits<int>::min();
const int mai = numeric_limits<int>::max();
const ll mil = numeric_limits<long long>::min();
const ll mal = numeric_limits<long long>::max();

#define REP(i, a, b) for(long long i=a; i<=b; ++i)
#define RREP(i, a, b) for(long long i=a; i>=b; --i)
#define PB(x) push_back(x)
#define MP(x, y) make_pair(x, y)

int main(int argc, char **argv) {
    int n, m;
    cin >> n>>m;

    ll tot = 0;

    if(n >= 2) {
        tot += n*(n-1)/2;
    }

    if(m>= 2) {
        tot += m*(m-1)/2;
    }

    cout << tot << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define endl "\n"

int main()
{
  i64 H, W;
  cin >> H >> W;
  if (H == 1 || W == 1)
    cout << 1 << endl;
  else
    cout << ((H + 1) / 2) * ((W + 1) / 2) + (H / 2) * (W / 2) << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
import math
import fractions
import itertools
from collections import deque
import copy
import heapq
import bisect
from scipy.sparse.csgraph import shortest_path
import numpy as np

MOD = float('inf')
INF = 10 ** 18 + 7
input = lambda: sys.stdin.readline().strip()

H, W = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(10)]
A = [list(map(int, input().split())) for _ in range(H)]

result = shortest_path(np.array(c))

ans = 0
for i in range(H):
    for l in range(W):
        if A[i][l] != -1:
            ans += result[A[i][l]][1]
print(int(ans))




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

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

ll mod_inv(ll n, ll mod){
    return fast_pow(n,mod-2,mod);
}

ll comb(ll n, ll r, ll mod){
    if(n<r) swap(n,r);
    ll temp=1;
    for(int i=r+1;i<=n;i++){
        temp=(temp*i)%mod;
    }
    ll temp2=1;
    for(int i=2;i<=n-r;i++){
        temp2=(temp2*i)%mod;
    }
    return temp*mod_inv(temp2,mod)%mod;
}

int main(){
    ll n;
    cin >> n;
    ll lim=n/3;
    ll ans=0;
    for(int i=1;i<=lim;i++){
        ll temp=n-i*3;
        ans+=comb(temp+i-1,temp,MOD);
        ans%=MOD;
    }
    cout << ans << endl;
}

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

lis = []
for _ in range(n):
    lis.append(input())
    
if len(lis) != len(set(lis)):
    print("No")
    exit()
 
tmp = lis[0][-1]
for i in range(1,n):
    if lis[i][:1] != tmp:
        print("No")
        exit()
    else:
        tmp = lis[i][-1]

print("Yes")

Measured memory_bytes: 3064
package main

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

var (
	sc = bufio.NewScanner(os.Stdin)
	wtr = bufio.NewWriter(os.Stdout)
)

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

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

func main() {
	sc.Split(bufio.ScanWords)

	n := scanInt()

	a := make([][]t, n)

	for i := 0; i < n; i++ {
		in := scanInt()
		for j := 0; j < in; j++ {
			x,y := scanInt()-1,scanInt()
			a[i] = append(a[i], t{x,y})
		}
	}

	p := 1 << uint(n)
	ans := 0

	for i := 0; i < p; i++ {
		f := true
		for k, e := range a {
			if i & (1 << uint(k)) != (1 << uint(k)) {
				continue
			}
			for _, ee := range e {
				if ee.y == 1 {
					if i & (1 << uint(ee.x)) != (1 << uint(ee.x)) {
						f = false
					}
				} else {
					if i & (1 << uint(ee.x)) == (1 << uint(ee.x)) {
						f = false
					}
				}
			}
		}
		// fmt.Println(i,f)
		if !f {
			continue
		}
		c := 0
		for j := 0; j < n; j++ {
			if i & (1 << uint(j)) == (1 << uint(j)) {
				c++
			}
		}
		// fmt.Println(i,f,c)
		ans = max(ans,c)
	}

	fmt.Println(ans)
}

type t struct {
	x int
	y int
}

func min(a,b int) int {
	if a<b {
		return a
	}
	return b
}

func max(a,b int) int {
	if a>b {
		return a
	}
	return b
}


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

bool cek(char c){
    if(c=='A'){
        return true;
    }else if(c=='C'){
        return true;
    }else if(c=='G'){
        return true;
    }else if(c=='T'){
        return true;
    }
    return false;
}
int main(){
    string s;
    cin>>s;
    int maxL = 0;
    int Lnow = 0;
    for(int i=0;s[i];i++){
        if(cek(s[i])){
            Lnow++;
            if(Lnow > maxL){
                maxL = Lnow;
            }
        }else{
            Lnow = 0;
        }
    }
    cout<<maxL<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>

#define LLI long long int

using namespace std;

int main(){
	LLI L,R,ans=2020;
	cin>>L;
	cin>>R;
	if(R-L>=2019){
			ans=0;
	}else{
		for(LLI j=L+1;j<=R;j++)for(LLI i=L;i<j;i++){
			LLI tmp=(i*j)%2019;
			if(ans>tmp)ans=tmp;
		}
	}
	cout<<ans<<endl;

	return 0;
}



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

import sys

a, b, m = map(int, input().split())
price_a = list(map(int, input().split()))
price_b = list(map(int, input().split()))

xn = []
yn = []
cn = []
for i in range(m):
    x, y, c = map(int, input().split())
    xn.append(x)
    yn.append(y)
    cn.append(c)

# print()
# print(a, b, m)
# print(price_a)
# print(price_b)
# print(xn, yn, cn)

# find min with no discount
min_a = min(price_a)
min_b = min(price_b)
min_s = min_a + min_b

# find smaller min of discounts than no discount
min_d_s = min_s
for i in range(m):
    # print(i, xn[i], yn[i], cn[i])
    s = price_a[xn[i] - 1] + price_b[yn[i] - 1] - cn[i]
    min_d_s = min(min_d_s, s)

print(min_d_s)


Measured memory_bytes: 25004
from itertools import product

data = [map(int, raw_input().split()) for _ in range(input())]

for cx, cy in product(range(101), repeat=2):
    ch = next(h + abs(cx - x) + abs(cy - y) for x, y, h in data if h != 0)
    if all(max(0, ch - abs(cx - x) - abs(cy - y)) == h for x, y, h in data):
        print cx, cy, ch
        break


Measured memory_bytes: 2692
/* 
    Author - linpaws07 
*/
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define inf (int)1e9
#define f first
#define s second
#define eps 1e-9
#define PI 3.1415926535897932384626433832795
#define scd(t) scanf("%d",&t)
#define sclld(t) scanf("%lld",&t)
#define scc(t) scanf("%c",&t)
#define scs(t) scanf("%s",t)
#define scf(t) scanf("%f",&t)
#define sclf(t) scanf("%lf",&t)
#define memst(a, b) memset(a, (b), sizeof(a))
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int,int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int uint64;
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define rp(i,n) for(int i=0;i<(n);i++)
#define fr(i,a,b) for(int i=(a);i<(b);i++)
#define fre(i,a,b) for(int i=(a);i<=(b);i++)
#define frd(i,a,b) for(int i=(a);i>=(b);i--)
inline bool eq(double a, double b) { return fabs(a-b) < 1e-9; }
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
auto start = high_resolution_clock::now();
inline void measure();

vector<int> g[100002];
bool visited[100002];
int dp[100002];
int dfs(int u){
    visited[u] = true;
    int ans = 0;
    if(g[u].size() == 0)    return dp[u] = 0;
    for(int to : g[u]){
        if(!visited[to])
            dfs(to);
        ans = max(ans, dp[to]);
    }
    dp[u] = 1 + ans;
    return dp[u];
}
int main(){
    FAST
    //Do awesome things here
    int n, m;
    cin >> n >> m;
    rp(i, m){
        int u, v;
        cin >> u >> v;
        g[u].pb(v);
    }
    int ans = 0;
    fre(i, 1, n){
        if(!visited[i]){
            ans = max(ans, dfs(i));
        }
    }
    cout << ans << endl;
    return 0;
}


inline void measure(){
    auto stop = high_resolution_clock::now(); 
    auto duration = duration_cast<milliseconds>(stop - start);
    cout << duration.count() << endl;
}

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


int main() {
    int n; cin>>n;
    vector<int> d(n);
    for (int i=0; i<n; i++) cin>>d[i];
    sort(d.begin(), d.end());
    int ans;
    ans = d[n/2] - d[n/2-1];
    cout<<ans<<endl;
}



Measured memory_bytes: 3800
#include <iostream>

using namespace std;

bool a[10] = {true, true, true, true, true, true, true, true, true, true};

bool check(int n) {
	while (n) {
		int rem = n % 10;
		if (a[rem] == false)
			return false;
		n /= 10;
	}
	return true;
}

int main() {
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < k; ++i) {
		int x;
		cin >> x;
		a[x] = false;
	}
	while (!check(n)) {
		n++;
	}
	cout << n << '\n';
	return 0;
}

Measured memory_bytes: 256
N, Q = map(int, input().split())
a = [0] * (N - 1)
b = [0] * (N - 1)
ab = [0] * (N - 1)
for i in range(N-1):
    ab[i] = list(map(int, input().split()))
ab.sort()

p = [0] * Q
x = [0] * Q
for i in range(Q):
    p[i], x[i] = map(int, input().split())

score = [0] * (N + 1)
for i in range(Q):
    score[p[i]] += x[i]

for i in range(N-1):
    score[ab[i][1]] += score[ab[i][0]]


for i in range(len(score)):
    score[i] = str(score[i])

score.pop(0)

ans = ' '.join(score)

print(ans)


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

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

  string s;
  int k;
  cin >> s >> k;

  set<string> subs;

  for (int i = 0; i < s.size(); i++) {
    string c{s.at(i)};
    subs.insert(c);
    for (int j = i + 1; j < s.size(); j++) {
      c += s.at(j);
      subs.insert(c);
      if (c.size() == k) {
        break;
      }
    }
  }

  int counter = 0;
  for (auto itr = subs.begin(); counter < k; ++itr, ++counter) {
    if (counter == k - 1) {
      cout << *itr << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1664
import java.io.*;
import java.util.*;
class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		int t = 1;
		//int t = Integer.parseInt(reader.readLine());
		for(int i1 = 0;i1<t;i1++){
			char[] list = reader.readLine().toCharArray();
			int max = 0;
			int p = 0;
			for(int i = 0;i<3;i++){
					if(list[i]=='S'){
						max = Math.max(max,p);
						p=0;
					}
					else p++;
			}
			max = Math.max(p,max);
			System.out.println(	max);
		}
	}
}

Measured memory_bytes: 32492
#include<bits/stdc++.h>
#define fo(i, n) for(int i = 1; i <= (n); i ++)
#define out(x) cout << #x << " = " << x << "\n"
using namespace std;
typedef long long ll;
//by piano
template<typename tp> inline void read(tp &x) {
  x = 0;char c = getchar();bool f = 0;
  for(; c < '0' || c > '9'; f |= (c == '-'), c = getchar());
  for(; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
  if(f) x = -x;
}
int n, a, b, pa, pb;
main(void) {
  read(n); read(a); read(b);
  string s =  (!((b - a) & 1) ? "Alice" : "Borys");
  cout << s << "\n";

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <set>
#include <map>
#include <cassert>
#include <fstream>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

const ll mod = 1e9 +7;

int main() {
    
    ll x, y, z, k;
    cin >> x >> y >> z >> k;
    vector<ll> a(x), b(y), c(z);
    
    for (int i = 0; i < x; ++i)
    {
        cin >> a[i];
    }
    for (int i = 0; i < y; ++i)
    {
        cin >> b[i];
    }
    for (int i = 0; i < z; ++i)
    {
        cin >> c[i];
    }
    
    priority_queue<ll> q;
    for (int i = 0; i < x; ++i)
    {
        for (int j = 0; j < y; ++j)
        {
            q.push(a[i] + b[j]);
        }
    }
    int count = 0;
    vector<ll> ret;
    while (q.size() > 0 && count < k)
    {
        ll now = q.top();
        q.pop();
        for (int i = 0; i < z; ++i)
        {
            ret.push_back(now + c[i]);
        }
        count++;
    }
    
    sort(ret.begin(), ret.end(), greater<ll>());
    
    for (int i = 0; i < k; ++i)
    {
        cout << ret[i] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 43240
#include <stdio.h>

typedef struct TreeNode_t {
    int parent;
    int size;
} TreeNode;

void TreeUnion(TreeNode node[], int a, int b)
{
    node[b].parent = a;
    node[a].size += node[b].size;
}

int TreeRoot(TreeNode node[], int a)
{
    if (node[a].parent == a) {
        return a;
    }

    int root = TreeRoot(node, node[a].parent);
    node[a].parent = root;
    return root;
}

int TreeSize(TreeNode node[], int a)
{
    return node[TreeRoot(node, a)].size;
}

int main(int argc, char *argv[])
{
    int n, m;
    int a[100000], b[100000];
    TreeNode node[100000];
    int i;
    int ans[100000];
    long long ans_sum;

    scanf("%d %d", &n, &m);

    for (i = 0; i < m; i++) {
        scanf("%d %d", &a[i], &b[i]);
        // to 0-origin
        a[i]--;
        b[i]--;
    }

    // initialize node-list
    for (i = 0; i < n; i++) {
        node[i].parent = i;
        node[i].size = 1;
    }

    for (i = m - 1; i >= 0; i--) {
        int root_a = TreeRoot(node, a[i]);
        int root_b = TreeRoot(node, b[i]);

        if (root_a == root_b) {
            // 行き来できるので，不便でない
            ans[i] = 0;
        } else {
            // 不便
            ans[i] = TreeSize(node, root_a) * TreeSize(node, root_b);
            TreeUnion(node, root_a, root_b);
        }
    }

    ans_sum = 0;
    for (i = 0; i < m; i++) {
        ans_sum += ans[i];
        printf("%lld\n", ans_sum);
    }

    return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef vector<llong> LV;

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



int main() {
	LV men(5);
    int sum=0;
    int m=10;
    REP(i,5){
        cin >> men[i];
    }
    REP(i,5){
        int a=(men[i]%10);
        m=min(m,(a==0?10:a));
    }
    REP(i,5){
        int b=men[i]%10;
        int a=men[i]/10;
        sum+=a*10+(b>0?10:0);
    }
    // string S;
    // cin >> S;
    cout << sum-10+m << endl;





}


Measured memory_bytes: 256
n = gets.to_i
nums = gets.split.map(&:to_i)
prev = ""
streak_count = 1
ans = 0
nums.each do |num|
  if prev == num
    streak_count += 1
  else
    ans += streak_count / 2
    streak_count = 1
  end
  prev = num
end
ans += streak_count / 2
puts ans


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


int main(){
    ll k;
    cin>>k;
    vector<ll>a;
    for(int i=1;i<=9;i++)a.push_back(i);
    while(1){
        if(k<=a.size()){
            cout<<a[k-1]<<endl;
            return 0;
        }
        k-=a.size();
        vector<ll>old;
        swap(old,a);
        for(ll x:old){
            for(int i=-1;i<=1;i++){
                int d=x%10+i;
                if(d<0 || d>9)continue;
                ll nx=x*10+d;
                a.push_back(nx);
            }
        }
    }
}

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

int main() {
  int n, x, y = 30;
  cin >> n;
  for (int i = 0; i < n; i ++){
    cin >> x;
    for (int j = 0; ; j ++){
      if (x % 2 == 0)
        x /= 2;
      else{
        if (j < y)
          y = j;
        break;
      }
    }
  }
  cout << y;
}

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

#define INF (1LL<<60)

int main(){
	int n;	cin>>n;
	long long a[n];

	for(int i=0;i<n;i++){
		cin>>a[i];
	}

	for(int i=1;i<n;i++){
		a[i]+=a[i-1];
		//cout<<a[i]<<endl;
	}

	long long ans=INF;
	for(int i=0;i<n-1;i++){
		ans = min(ans, abs( (a[n-1]-a[i])-a[i]));
	}

	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

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

inline int tax(int p, int x) {
    return p * (100 + x) / 100;
}

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

    int x, y, s;
    while (cin >> x >> y >> s, x) {
        int ans = -1;
        rep2(i, 1, s) {
            rep2(j, i, s) {
                if (tax(i, x) + tax(j, x) == s) {
                    ans = max(ans, tax(i, y) + tax(j, y));
                }
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 3132
N=int(input())
A=[int(x)for x in input().split()]
B=[]
p = 10 ** 9 + 7
if N%2==0:
    B= sorted([2*i-1 for i in range(1,N//2+1)]*2)
    if sorted(A)==B:
        ans=2**(N//2)%(10 ** 9 + 7)
    else:
        ans=0
else:
    B= [0]+sorted([2*i for i in range(1,N//2+1)]*2)
    if sorted(A)==B:
        ans=2**(N//2)%(10 ** 9 + 7)
    else:
        ans=0
print(int(ans))
 


Measured memory_bytes: 13812
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define out(x) cout << x << '\n'
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define pb push_back
#define eb emplace_back
#define mp make_pair
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vvli = vector<vlli>;
using vs = vector<string>;
using vvs = vector<vs>;
using vb = vector<bool>;
using vvb = vector<vb>;
using ll = long long;
//---------------------------------------------------------------------------------------------------
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
//---------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------
void solve()
{
  lli a = 0, b = 0, c = 0, h = 0, n = 0, w = 0, ans = 0, count = 0;
  string s = "", t = "";
  vector<pair<lli, lli>> pr;
  map<lli, lli> ma;
  set<lli> st;

  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> s;
  rep(i, 0, s.size())
  {
    ans += s[i] - '0';
  }
  if (ans % 9 == 0 || ans == 0)
  {
    out("Yes");
  }
  else
  {
    out("No");
  }
}

//---------------------------------------------------------------------------------------------------
signed main()
{
  solve();
}

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



typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;
typedef vector< vector< vector<ll> > > vvvint;
typedef vector<string> vstring;
typedef vector< vector<string> > vvstring;
typedef vector<char> vchar;
typedef vector< vector<char> > vvchar;
typedef vector<long double> vdouble;
typedef vector< vector<long double> > vvdouble;
typedef vector< vector< vector<long double> > > vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;
typedef vector<bool> vbool;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define ALL(obj) (obj).begin(), (obj).end()
// #define LLONG_MAX 9223372036854775806
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())
#define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>())
#define MOD 1000000007
// #define MOD 998244353
// #define MOD LLONG_MAX
const double PI=3.14159265358979323846;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }




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




void printv(vint &v){
  for(auto e:v) cout<<e<<" ";
  cout<<endl;
}


int main() {


  cout<<fixed<<setprecision(10);

  string n; cin>>n;

  ll keta = n.size();


  ll kk; cin>>kk;

  ll dp[keta+1][2][5];
  rep(i,keta+1)rep(j,2)rep(k,5) dp[i][j][k] = 0;

  dp[0][0][0] = 1;

  rep(i,keta){

    ll x = n[i] - '0';

    if(x == 0){
      // 00
      rep(k,4){
        dp[i+1][0][k] += dp[i][0][k];
      }
  

      // 01
      // rep(k,4){
      //   dp[i+1][1][k] += dp[i][0][k]; // k -> k
      // }

      // 11
      rep(k,4){
        dp[i+1][1][k] += dp[i][1][k]; // k -> k
        dp[i+1][1][k+1] += dp[i][1][k]*9; // k -> k+1
      }

    }else{
      // 00
      rep(k,4){
        dp[i+1][0][k+1] += dp[i][0][k];

        // dp[i+1][0][k] += dp[i][0][k]; // k -> k
        // dp[i+1][0][k+1] += dp[i][0][k]*(x-1); // k -> k+1
      }

      // 01
      rep(k,4){
        dp[i+1][1][k] += dp[i][0][k];
        dp[i+1][1][k+1] += dp[i][0][k]*(x-1); // k -> k+1
      }

      // 11
      rep(k,4){
        dp[i+1][1][k] += dp[i][1][k]; // k -> k
        dp[i+1][1][k+1] += dp[i][1][k]*9; // k -> k+1
      }

    }




  }


  cout<<dp[keta][0][kk] + dp[keta][1][kk]<<endl;
}

//


Measured memory_bytes: 256
from collections import deque
H,W = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(H)]
B = [[0 if A[i][j]%2==0 else 1 for j in range(W)] for i in range(H)]
C = [deque([]) for _ in range(H)]
for i in range(H):
    for j in range(W):
        if B[i][j]==1:
            C[i].append(j)
cnt = 0
for i in range(H):
    cnt += sum(B[i])
if cnt%2==1:
    for i in range(H-1,-1,-1):
        if len(C[i])>0:
            C[i].pop()
            break
D = []
flag = 0
i = 0
while i<H:
    while len(C[i])>=2:
        if flag==0:
            j1 = C[i].popleft()
            i1 = i
            j2 = C[i].popleft()
            i = i
            for j in range(j1,j2):
                D.append((i,j,i,j+1))
        else:
            j1 = C[i].pop()
            i1 = i
            j2 = C[i].pop()
            i2 = i
            for j in range(j1,j2,-1):
                D.append((i,j,i,j-1))
    if len(C[i])==0:
        i += 1
    else:
        j = i+1
        while j<H:
            if len(C[j])>0:
                break
        j1 = C[i].pop()
        i1 = i
        if flag==0:
            j2 = C[j].pop()
            i2 = j
            for l in range(j1,W-1):
                D.append((i1,l,i1,l+1))
            for k in range(i1,i2):
                D.append((k,W-1,k+1,W-1))
            for l in range(W-1,j2,-1):
                D.append((i2,l,i2,l-1))
        else:
            j2 = C[j].popleft()
            i2 = j
            for l in range(j1,0,-1):
                D.append((i1,l,i1,l-1))
            for k in range(i1,i2):
                D.append((k,0,k+1,0))
            for l in range(j2):
                D.append((i2,l,i2,l+1))
        flag = 1-flag
        i = j
print(len(D))
for d in D:
    print(d[0]+1,d[1]+1,d[2]+1,d[3]+1)

Measured memory_bytes: 84060
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  int A,B;
  cin >> A >> B;
  int count = 0;
  for(int i=A;i<B+1;i++)
  {
    int k = (i/10000)*10000;
    int l = ((i-k)/1000)*1000;
    int m = ((i-k-l)/100)*100;
    if(i/10000==i%10)
    {
      if((i-k)/1000==(i-k-l-m)/10)
      {
        count ++;
      }
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
    int x=0,k=1;char c=getchar();
    while(c<'0' || c>'9'){if(c=='-') k=0;c=getchar();}
    while(c>='0' && c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
    return k?x:-x;
}
int l;
char ch[20];
int main()
{
    scanf("%s",ch);
    l=strlen(ch);
    for(int i=0;i<l;i++) printf("%c",ch[i]==','?' ':ch[i]);
    puts("");
    return 0;
}


Measured memory_bytes: 256
/// awoooooo

# include <bits/stdc++.h>
# define sz(x) (int)((x).size())

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair < int, int > pii;

const int N = (int)2e5 + 5;
const int inf = (int)1e9 + 7;

int main(){
  int a, b, c, k;
  scanf("%d %d %d %d", &a, &b, &c, &k);
  if(k % 2 == 0){
    printf("%d\n", a - b);
  } else{
    printf("%d\n", b - a);
  }
  return 0;
}


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

using namespace std;

struct syain {
	int name;
	long long int u;
};

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		vector<syain> s;
		for (int i = 0; i < n; i++) {
			int a;
			long long int b, c;
			cin >> a >> b >> c;
			bool hantei = true;
			for (int j = 0; j < s.size(); j++) {
				if (s[j].name == a) {
					s[j].u += b * c;
					hantei = false;
					break;
				}
			}
			if (hantei) {
				syain d;
				d.name = a;
				d.u = b * c;
				s.push_back(d);
			}
		}
		bool hantei2 = true;
		for (int i = 0; i < s.size(); i++) {
			if (s[i].u >= 1000000) {
				cout << s[i].name << endl;
				hantei2 = false;
			}
		}
		if (hantei2) {
			cout << "NA" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1256
n = int(input())
score = [0 for i in range(n)]
inning = 1
runner = [0 for i in range(3)]
outCount = 0
inningScore = 0
while inning <= n:
    str = input()
    if str == "OUT":
        outCount += 1
    elif str == "HIT":
        runner.insert(0, 1)
        inningScore += runner[3]
        runner.pop()
    elif str == "HOMERUN":
        inningScore += 1
        for i in range(len(runner)):
            inningScore += runner[i]
            runner[i] = 0
    if outCount == 3:
        for i in range(len(runner)):
            runner[i] = 0
        score[inning-1] = inningScore
        inningScore = 0
        outCount = 0
        inning += 1
for i in range(len(score)):
    print(score[i])

Measured memory_bytes: 7604
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
using vc= vector<char>;
#define REP(i,x,n) for(int i=x; i<n; i++)
#define rep(i,n) REP(i,0,n)
#define all(x) x.begin(), x.end()

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  bool ans= true;

  for(int i=0; i< n/2; i++){
    if(s[i]==s[i+ (n/2) ]){
      continue;
    }else{
      ans= false;
      break;
    }
  }
  
  if(n%2) ans= false;

  if(ans){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
def main():
    n=int(input())
    xs=[0]*n
    ls=[0]*n
    ranges=[0]*n
    for i in range(n):
        xs[i],ls[i]=map(int,input().split())
        ranges[i]=[xs[i]-ls[i],xs[i]+ls[i]]
    ranges.sort(key=lambda x:x[1])
    count=0
    point=-1000000000000
    for irange in ranges:
        if irange[0]>=point:
            count+=1
            point=irange[1]
    print(count)
if __name__ == "__main__":
    main()


Measured memory_bytes: 29264
#pragma GCC optimize ("-O3")
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
 
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
ll NUM = 1e9+7;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define INF 1e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define zer ll(0)

void solve()
{
  int n;
  cin>>n;
  int t=(n%1000==0)?n/1000:1+n/1000;
  cout<<t*1000-n<<ln;
}
 
int  main()
{
  fast_cin();
  ll t=1;
  //cin>>t;
  while(t--)solve();
  return 0;
} 

Measured memory_bytes: 3648