akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M=0,S=0,W=0;
  cin >> N;
  vector<vector<int>> data(N, vector<int>(N-1));
  vector<int> vec1(N,0);
  vector<int> vec2(N,N-1);
  for ( int i = 0; i < N; i++){
    for ( int j = 0; j < N-1; j++){
      cin >> data.at(i).at(j);
    }
  }
  while(vec1 != vec2){
    W = 0;
  for ( int i = 0; i < N; i++){
    if(vec1.at(i) < N-1){
    S = data.at(i).at(vec1.at(i));
    if(S == 0){
      vec1.at(i) += 1;
      W --;
      continue;
    }
    if(i < S-1) {
    if(i+1 == data.at(S-1).at(vec1.at(S-1))) {
      data.at(S-1).at(vec1.at(S-1)) = 0;
      data.at(i).at(vec1.at(i)) = 0;
      vec1.at(i) +=1;
      W --;
    }
    else{
      W ++;
    }
  }
  else{
      W ++;
  }
  }
}
M += 1;
if(W == N){
  cout << -1 <<endl;
  break;
}
}
if(vec1 == vec2){
  cout << M <<endl;
}
}

Measured memory_bytes: 6272
import std.stdio;
import std.algorithm;
import std.string;
import std.conv;
import std.math;

void main(){

    int[] primes = [2,3,5];
    for(int i=7;primes.length <= 10000;i++){
	bool flg = true;
	for(int j=0;primes[j]*primes[j]<=i;j++){
	    if(i%primes[j]==0){
		flg = false;
		break;
	    }
	}
	if(flg) primes ~= i;
    }

    while(true){
	int n = to!int(chomp(readln()));
	if(n == 0) break;
	int sum = 0;
	for(int i=0;i<n;i++)
	    sum += primes[i];
	writeln(sum);
    }
}

Measured memory_bytes: 2408
A1 = list(map(int,input().split()))
A2 = list(map(int,input().split()))
A3 = list(map(int,input().split()))
N = int(input())
b = [int(input()) for i in range(N)]
for i in range(N):
    for j in range(3):
        if A1[j] == b[i]:
            A1[j] = 0
        if A2[j] == b[i]:
            A2[j] = 0
        if A3[j] == b[i]:
            A3[j] = 0
if (A1[0] == A2[1] == A3[2] == 0)or(A3[0] == A2[1] == A1[2] == 0)or(A1 == [0,0,0])or(A2 == [0,0,0])or(A3 == [0,0,0])or(A1[0] == A2[0] == A3[0] == 0)or(A1[1] == A2[1] == A3[1] == 0)or(A1[2] == A2[2] == A3[2] == 0):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.IntStream;
import java.util.stream.Stream;
import java.io.*;
//import java.util.stream.IntStream;
import java.nio.charset.Charset;


public class Main {
    static int[] T;
    static int INFTY = Integer.MAX_VALUE;
    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
      //  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));


     //   try{

            int n = sc.nextInt();
            int w = sc.nextInt();

            T = new int[w+1];
            Item[] items = new Item[n+1];

            for(int i=1;i<n+1;i++){
                items[i] = new Item();
                items[i].v = sc.nextInt();
                items[i].w = sc.nextInt();
            }
            for(int i=1;i<=n;i++){
                for(int j=items[i].w;j<=w;j++){
                    T[j] = Math.max(T[j], T[j-items[i].w] + items[i].v);
                }
            }

            System.out.println(T[w]);
    }

}

class Item{
    int v;
    int w;
}


Measured memory_bytes: 27008
# time complexity: O(N + K^2)
# space complexity: O(K^2)

import sys
fin = sys.stdin.readline
from collections import defaultdict
from pprint import pprint

def sum_range_2D(cuml_mat, coord_left_up, Kx, Ky):
    if Kx <= 0 or Ky <= 0:
        return 0
    x, y = coord_left_up
    if x - 1 >= 0 and y - 1 >= 0:
        left_up = cuml_mat[x - 1][y - 1]
    else:
        left_up = 0
    if x - 1 >= 0 and y + Ky - 1 >= 0:
        right_up = cuml_mat[x - 1][y + Ky - 1]
    else:
        right_up = 0
    if x + Kx - 1 >= 0 and y - 1 >= 0:
        left_down = cuml_mat[x + Kx - 1][y - 1]
    else:
        left_down = 0
    right_down = cuml_mat[min(len(cuml_mat) - 1, x + Kx - 1)][min(len(cuml_mat) - 1, y + Ky - 1)]
    return right_down - right_up - left_down + left_up


N, K = [int(elem) for elem in fin().split()]
black_desires = []
for _ in range(N):
    x, y, c = fin().split()
    x = int(x) % (2 * K)
    y = int(y) % (2 * K) if c == 'B' else (int(y) + K) % (2 * K)
    black_desires.append((x, y))

cuml_2D = [[0] * (2*K) for _ in range(2*K)]
for x, y in black_desires:
    cuml_2D[x][y] += 1

for i in range(2 * K):
    for j in range(1, 2 * K):
        cuml_2D[i][j] += cuml_2D[i][j - 1]
for j in range(2 * K):
    for i in range(1, 2 * K):
        cuml_2D[i][j] += cuml_2D[i - 1][j]

max_num = 0
for i in range(K + 1):
    for j in range(K):
        current_num = sum_range_2D(cuml_2D, (i, j), K, K) \
                    + sum_range_2D(cuml_2D, (0, 0), i, j) \
                    + sum_range_2D(cuml_2D, (0, j + K), i, K - j) \
                    + sum_range_2D(cuml_2D, (i + K, 0), K - i, j) \
                    + sum_range_2D(cuml_2D, (i + K, j + K), K - i, K - j)
        max_num = max(max_num, current_num)


for i in range(K + 1):
    for j in range(K, 2 * K):
        current_num = sum_range_2D(cuml_2D, (i, j), K, 2 * K - j) \
                    + sum_range_2D(cuml_2D, (0, j - K), i, K) \
                    + sum_range_2D(cuml_2D, (i + K, j - K), K - i, K) \
                    + sum_range_2D(cuml_2D, (i, 0), K, j - K)
        max_num = max(max_num, current_num)

print(max_num)

Measured memory_bytes: 97372
#!/usr/bin/env python3
import sys


def solve(N: int):
    ret = ''
    for i in range(N, 1000):
        s = str(i)
        if s[0] == s[1] and s[1] == s[2]:
            ret = s
            break
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if (x < y) x = y; }

int main() {
	int N;
	while (~scanf("%d", &N)) {
		vector<int> a(N * 3);
		for (int i = 0; i < N * 3; ++ i)
			scanf("%d", &a[i]);
		sort(a.begin(), a.end());
		ll ans = 0;
		rep(i, N)
			ans += a[N * 3 - (i + 1) * 2];
		printf("%lld\n", ans);
	}
	return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#pragma region atcoder
//#include <atcoder/all>
//using namespace atcoder;
#pragma endregion
#pragma region macros
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vl = vector<ll>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n - 1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#pragma endregion
#pragma region debug for var, v, vv
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){cout << endl;int cnt = 0;for(const auto& v : vv){cout << cnt << "th : "; view(v); cnt++;} cout << endl;}
#pragma endregion

const ll mod = 998244353;
const int inf = 1001001001;
const ll INF = 1001001001001001001;
const int MAX = 2000005;

//using mint = modint998244353;
//These are for segment tree
/*int op(int a, int b){return max(a, b);}
int e(){return -1;}
bool f(int v){ return v < target;}
*/

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

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; }
ll modpow(ll a, ll p){ll ret = 1; while(p){if(p & 1){ret = ret * a % mod;} a = a * a % mod; p >>= 1;} return ret;}

/*--------------------------------------------------------------------------------------------------------------------------------*/

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
    string s; cin >> s;
  if(s[sz(s) - 1] == 's') cout << s << "es" << endl;
  else cout << s << "s" << endl;
	
} 


Measured memory_bytes: 3648
#include<cstdio>
#include<vector>
#include<algorithm>
#include<stdlib.h>
using namespace std;
int main()
{
	int w,h,n;
	int cnt=0;
	scanf("%d %d %d",&w,&h,&n);
	vector< pair<int,int> > root;
	for(int i=0;i<n;i++)
	{
		int x,y;
		scanf("%d %d",&x,&y);
		root.push_back(make_pair(x,y));
	}
	for(int i=0;i<n-1;i++)
	{
		if((root[i].first-root[i+1].first)*(root[i].second-root[i+1].second)>=0)
		{
			cnt +=abs(root[i].first-root[i+1].first)+abs(root[i].second-root[i+1].second)-min(abs(root[i].first-root[i+1].first),abs(root[i].second-root[i+1].second));
		}
		else
		{
			cnt += abs(root[i].first-root[i+1].first)+abs(root[i].second-root[i+1].second);
		}
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 1044
# https://atcoder.jp/contests/abc058/tasks/arc071_a

import sys
# sys.setrecursionlimit(100000)
from collections import Counter


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n = input_int()
    d = Counter(input())
    for _ in range(n - 1):
        s = Counter(input())
        for k, v in d.items():
            if k in s.keys():
                d[k] = min(s[k], v)
            else:
                d[k] = 0
    common_chr = sorted(d.items(), key=lambda x: x[0])
    ans = ""
    for s, cnt in common_chr:
        ans += s * cnt
    print(ans)
    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 69408
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    private static Scanner sc;

    public Main() {
    }

    public static void main(String[] args) {
        sc = new Scanner(System.in);
        new Main().solve();

    }

    private void solve() {
        int N = sc.nextInt();
        int[] a = new int[N];

        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
        }

        Arrays.sort(a);

        int min = a[0];
        int max = a[N - 1];

        System.out.println(max - min);
    }
}


Measured memory_bytes: 21716
x, y = [int(x) for x in input().split(" ")]

a = (4 * x - y) / 2
b = (y - 2 * x) / 2

is_plus = (a >= 0) and (b >= 0)
is_int = a.is_integer() and b.is_integer()

print(["No", "Yes"][is_plus and is_int])


Measured memory_bytes: 9176
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <set>
#include <numeric>

#include <map>
#include <math.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <bitset>
#include <math.h>

#define INF 100100100

typedef long long int llint;

using namespace std;

typedef pair<int, int>Pii;

#define pi 3.141592653589793
#define mod 1000000007

int main() {
	int n;
	cin >> n;
	while (n & (n - 1))n--;
	cout << n << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define per(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define INF 2e9
#define LINF 1e18
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int n; cin >> n;
    vector<int> p(n);
    rep(i, n) {
        cin >> p[i];
        p[i]--;
    }
    vector<int> idx(n);
    rep(i, n) idx[p[i]] = i;

    set<int> s;
    ll ans = 0;
    per(i, n) {
        int x = idx[i];
        s.insert(x);
        vector<int> l(2, -1);
        vector<int> r(2, n);
        auto it = s.find(x);
        rep(j, 2) {
            if (it == s.begin()) break;
            it--;
            l[j] = *it;
        }

        it = s.find(x);
        rep(j, 2) {
            it++;
            if (it == s.end()) break;
            r[j] = *it;
        }
        
        ll c = (ll)(x-l[0])*(r[1]-r[0]) + (ll)(l[0]-l[1])*(r[0]-x);
        ans += c*(i+1);
    }
    cout << ans << endl;

}


Measured memory_bytes: 5760
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    // insert code here...
    int rows;
    int cols;
    cin>>rows>>cols;
    int a[rows][cols];
    bool ok = true;
    for(int i=0; i<rows; i++) {
        for(int j=0; j<cols; j++) {
            char fig;
            cin>>fig;
            if(fig == '#') {
                a[i][j] = 1;
            } else {
                a[i][j] = 0;
            }
        }
    }
    
    for(int i=0; i<rows; i++) {
        for(int j=0; j<cols; j++) {
            if(i<rows-1 && j<cols-1 && i>0 && j>0) {
                if(a[i][j]==1) {
                    if(a[i-1][j]!=1 && a[i+1][j]!=1 && a[i][j-1]!=1 && a[i][j+1]!=1) {
                        ok = false;
                        break;
                    }
                }
            }
            else if(i==0 && j==0) {
                if(a[i][j]==1) {
                    if(a[i+1][j]!=1 && a[i][j+1]!=1) {
                        ok = false;
                        break;
                    }
                }
            }
            
            else if(i==0 && j==cols-1) {
                if(a[i][j]==1) {
                    if(a[i+1][j]!=1 && a[i][j-1]!=1) {
                        ok = false;
                        break;
                    }
                }
            }
            
            else if(i==rows-1 && j==0) {
                if(a[i][j]==1) {
                    if(a[i-1][j]!=1 && a[i][j+1]!=1) {
                        ok = false;
                        break;
                    }
                }
            }
            
            else if(i==rows-1 && j==cols-1) {
                if(a[i][j]==1) {
                    if(a[i-1][j]!=1 && a[i][j-1]!=1) {
                        ok = false;
                        break;
                    }
                }
            }
            
            else if(i==0 && j>0) {
                if(a[i][j]==1) {
                    if(a[i+1][j]!=1 && a[i][j-1]!=1 && a[i][j+1]!=1) {
                        ok = false;
                        break;
                    }
                }
            }
            
            else if(i==rows-1 && j>0) {
                if(a[i][j]==1) {
                    if(a[i-1][j]!=1 && a[i][j-1]!=1 && a[i][j+1]!=1) {
                        ok = false;
                        break;
                    }
                }
            }
            else if(i>0 && j==0) {
                if(a[i][j]==1) {
                    if(a[i-1][j]!=1 && a[i+1][j]!=1 && a[i][j+1]!=1) {
                        ok = false;
                        break;
                    }
                }
            }
            
            else if(i>0 && j==cols-1) {
                if(a[i][j]==1) {
                    if(a[i-1][j]!=1 && a[i+1][j]!=1 && a[i][j-1]!=1) {
                        ok = false;
                        break;
                    }
                }
            }
            
            
            
        }
    }
    if(ok) {
        cout<<"Yes";
    } else {
        cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 256
// デバッグ実行：Ctrl+F5

using System;

class Program
{
    static void Main(string[] args)
    {
        String line;
        line = Console.ReadLine();
        String[] words = line.Split(' ');
        int H, W;
        H = int.Parse(words[0]);
        W = int.Parse(words[1]);
        bool[] white_gyo = new bool[H];
        bool[] white_retsu = new bool[W];
        char[] math = new char[H*W];
        for (int i = 0; i < H; i++)
        {
            white_gyo[i] = true;
        }
        for (int i = 0; i < W; i++)
        {
            white_retsu[i] = true;
        }

        for (int i = 0; i < H; i++)
        {
            line = Console.ReadLine();
            for (int j = 0; j < W; j++)
            {
                math[i*W+j]=line[j];
                if (line[j] == '#')
                {
                    white_gyo[i] = false;
                    white_retsu[j] = false;
                }
            }
        }

        for (int i = 0; i < H; i++)
        {
            if (white_gyo[i]) continue;
            for (int j = 0; j < W; j++)
            {
                if (white_retsu[j]) continue;
                Console.Write(math[i * W + j]);
            }
            Console.WriteLine();
        }
    }
}

Measured memory_bytes: 11092
///I don't wanna read problem's statement anymore
using namespace std;
#include<bits/stdc++.h>
#define ll long long
#define read freopen("in.txt", "r", stdin)
#define write freopen("out.txt", "w", stdout)
#define sf scanf
#define pb push_back
#define pfr push_front
#define reap(i,n) for(int i=0; i<n; i++)
#define case_ printf("Case %d: ",i)
#define check printf("working\n")
#define pf printf
#define ato(v) for(auto k:v)
#define vi vector<int>
#define vll vector<ll>
#define vec_ch vector<char>
#define list_i list<int>
#define list_ll list<ll>
#define list_ch list<ch>
#define M 100005
#define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);


ll d[M];
ll a[M];
int main(){
    ios
    //if(read)
    //read;
    //write;
    //double st = clock();

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

    for(ll i=1; i<n; i++){
        d[i]=d[i-1]+abs(a[i]-a[i-1]);
        if(i>1){
            d[i]=min(d[i], d[i-2]+abs(a[i]-a[i-2]));
           // cout<<d[i]<<"akshd";
        }
       // cout<<d[i]<<" "<<i<<endl;
    }
    cout<<d[n-1]<<endl;
    //double en = clock();
    //cerr<<"Exicution Time: "<<((en-st)/CLOCKS_PER_SEC*1000)<<endl;
    return 0;
}


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

s = list(map(int, input().split()))

ans = 0
diff = 100

for i in range(n):
    if diff >= abs(sum(s[:i]) - sum(s[i:])):
        diff = abs(sum(s[:i]) - sum(s[i:]))
        ans = i

print(abs(sum(s[:ans]) - sum(s[ans:])))

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

int main() {
    int A, B, C, X, Y;
    long long max = 2 * 100005;
    cin >> A >> B >> C >> X >> Y;

    long long min_price = max * 5000;
    for(long long i=0; i<=max; i+=2) {
        long long num_X, num_Y;
        if (X < i/2) num_X = 0;
        else num_X = (X-i/2);
        if (Y < i/2) num_Y = 0;
        else num_Y = (Y-i/2);
        long long price = C * i + A * num_X + B * num_Y;
        if(price < min_price) min_price = price;
    } 
    cout << min_price << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000

ll gcm(ll a,ll b);
ll lcm(ll a,ll b);

int main(){
  int n,m;
  cin >> n >> m;
  vint ans(n+1);
  rep(i,m){
    int a,b;
    cin >> a >> b;
    if(a == 1){
      ans[b]++;
    }
    if(b == n){
      ans[a]++;
    }
  }
  bool OK = false;
  erep1(i,n){
	if(ans[i] == 2){
      cout << "POSSIBLE" << endl;
      OK = true;
      break;
    }
  }
  if(!(OK)) cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int v[60][30];

int dx[] = {-2,-1,-1,0,0,0,1,1,2};
int dy[] = {1,1,2,1,2,3,1,2,1};//反転

int h,w;

bool in(int x, int y){
    if(x < 0 || x >= h) return false;
    if(y < 0 || y >= w) return false;
    return true;
}

int main(void) {
    int i,j,k;
    while(cin >> w >> h, w){

        vector<pii> s,g;

        rep(i,h)rep(j,w){
            string t;
            cin >> t;

            if(isdigit(t[0])){
                v[i][j] = t[0] - '0';
            }else if(t[0] == 'S'){
                v[i][j] = 0;
                s.push_back(pii(i,j));
            }else if(t[0] == 'T'){
                v[i][j] = 0;
                g.push_back(pii(i,j));
            }else{
                v[i][j] = -1;
            }

        }

        int dp[60][30][2];
        rep(i,h)rep(j,w)rep(k,2) dp[i][j][k] = INF;

        queue<vi> q;

        rep(i,s.size())rep(j,2){
            vi t(3);
            t[0] = s[i].first;
            t[1] = s[i].second;
            t[2] = j;
            dp[t[0]][t[1]][j] = 0;
            q.push(t);
        }

        while(q.size()){
            int x = q.front()[0];
            int y = q.front()[1];
            int z = q.front()[2];
            q.pop();
            //cout << x << " " << y << " " << z << endl;
            rep(i,9){
                int nx = x + dx[i];
                int ny = y + dy[i];
                int nz = 1;
                if(z){
                    ny = y - dy[i];
                    nz = 0;
                }
                if(!in(nx,ny) || v[nx][ny] < 0)continue;
                vi t(3);
                t[0] = nx;
                t[1] = ny;
                t[2] = nz;
                if(dp[nx][ny][nz] > dp[x][y][z] + v[x][y]){
                    dp[nx][ny][nz] = dp[x][y][z] + v[x][y];
                    q.push(t);
                }
            }
        }



        int ans = INF;
        rep(i,g.size())rep(j,2){
            ans = min(ans,dp[g[i].first][g[i].second][j]);
        }
        if(ans < INF){
            cout << ans << endl;
        }else{
            cout << -1 << endl;
        }
    }
}



Measured memory_bytes: 3228
n,k = map(int, input().split())
 
ans = 0
for s in range(k, n+2):
  maxNum = (s*((n-s+1)+n))//2
  minNum = (s*(s-1))//2
  ans += maxNum - minNum +1
  ans %= 10**9+7
print(ans)

Measured memory_bytes: 9184
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <unistd.h>

#define lli long long int

#define MAX(A,B) (((A)>(B))?(A):(B))
typedef struct s_item
{
	lli w;
	lli v;
	lli sumw;
	lli sumv;
}	t_item;
int main (void)
{
	lli n, w;
	scanf("%lld %lld", &n, &w);

	lli index = 0;
	t_item items[n];
	lli dp[n+1][w+1];
	while (index < n)
	{
		scanf("%lld %lld",&(items[index].w),&(items[index].v));
		items[index].sumw = items[index].w;
		items[index].sumv = items[index].v;
		index++;
	}
	
	lli j = 0;
	index=0;
	while (j < w +1)
	{
		dp[0][j] = 0;
		j++;
	}
	index = 1;
	while (index < n+1)
	{
		j = 0;
		while (j < w+1)
		{
			if(j - items[index-1].w >= 0)
			{
				dp[index][j] = MAX(dp[index-1][j], dp[index-1][j-items[index-1].w]+items[index-1].v);
			}
			else
			{
				dp[index][j] = dp[index-1][j];
			}
			j++;
		}
		index++;
	}
	printf("%lld\n", dp[n][w]);
	return(0);
}



Measured memory_bytes: 79104
def main(a, b):
    if 0 < a <= b:
        print("Positive")
        return

    elif a <= b < 0:
        if (b - a + 1) % 2 == 0:
            print("Positive")
            return
        else:
            print("Negative")
            return

    elif a <= 0 <= b:
        print("Zero")


if __name__ == "__main__":
    a, b = map(int, input().split())
    main(a, b)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> a(n - 1);
  for (int i = 0; i < n - 1; i++) {
    a[i] = (int) abs(s[i] - s[i + 1]);
  }
  n--;
  vector<int> cnt(3, 0);
  for (int x : a) {
    cnt[x] += 1;
  }
  int coeff = 1;
  if (cnt[1] == 0) {
    coeff *= 2;
    for (int& x : a) {
      x >>= 1;
    }
  }
  int res = 0;
  for (int i = 0; i < n; i++) {
    if (((n - 1) & i) == i) {
      res ^= a[i];
    }
  }
  cout << (res & 1) * coeff << '\n';
  return 0;
}



Measured memory_bytes: 5276
#pragma comment(linker, "/STACK:10240000")
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 2020;
const int MAX_INF = 0x3fffffff;

int n;
int a[MAXN], dp[MAXN][MAXN], d[MAXN][2];

int dfs (int x, int y)
{
    int ans;
    if (y > x)
    {
        if (d[y + 1][0] != -1)
        {
            ans = d[y + 1][0];
        }
        else
        {
            ans = 0;
            for (int i = n; i > y; i --)
            {
                int tmp = dp[i][y] == -1 ? dfs (i, y) : dp[i][y];
                if (tmp > ans)
                {
                    ans = tmp;
                }
                if (i != n)
                {
                    d[i][0] = ans;
                }
            }
        }
    }
    else
    {
        if (d[x + 1][1] != -1)
        {
            ans = d[x + 1][1];
        }
        else
        {
            ans = MAX_INF;
            for (int i = n; i > x; i --)
            {
                int tmp = dp[x][i] == -1 ? dfs (x, i) : dp[x][i];
                if (tmp < ans)
                {
                    ans = tmp;
                }
                if (i != n)
                {
                    d[i][1] = ans;
                }
            }
        }
    }
    dp[x][y] = ans;
    return ans;
}

int main ()
{
    scanf ("%d", &n);
    scanf ("%d%d", &a[1], &a[2]);
    memset (dp, -1, sizeof (dp));
    memset (d, -1, sizeof (d));
    for (int i = 1; i <= n; i ++)
    {
        scanf ("%d", &a[i + 2]);
    }
    n += 2;
    for (int i = 1; i < n; i ++)
    {
        dp[i][n] = abs (a[n] - a[i]);
    }
    for (int i = 2; i < n; i ++)
    {
        dp[n][i] = abs (a[n] - a[i]);
    }
    printf ("%d\n", dfs (1, 2));
    return 0;
}


Measured memory_bytes: 16384
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve{
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        string[] str = Console.ReadLine().Split(' ');
        int N = int.Parse(str[0]);
        int W = int.Parse(str[1]);
        long[] DP = new long[W+1];
        for(int j=0;j<N;j++){
            str = Console.ReadLine().Split(' ');
            int v = int.Parse(str[0]);
            int w = int.Parse(str[1]);
            for(int i=w;i<=W;i++){
                DP[i] = Math.Max(DP[i],DP[i-w]+v);
            }
        }
        sb.Append(DP[W]+"\n");
    }
}

Measured memory_bytes: 9264
#include<bits/stdc++.h>
using namespace std;
int d(int n){
	if(n==0)return 0;
  	return 1+d(n/10);
}
int main(){
  	int n,ans=0;cin>>n;for(int i=1;i<=n;i++){ans+=(d(i)&1);}
  	cout<<ans;
}

Measured memory_bytes: 256
// abc170_d
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF (ll)(1e9)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;



int main() {
#ifdef LOCAL
    ifstream in("../arg.txt");
    cin.rdbuf(in.rdbuf());
#endif

    int N;
    cin >> N;
    vector<int> nums(1e6+1);
    REP(i, N) {
        int a;
        cin >> a;
        nums[a]++;
    }

    if (nums[1] > 0){
        if (nums[1] == 1){
            print(1);
        } else {
            print(0);
        }
        return 0;
    }

    int ans = 0;
    for (int i = 2; i < 1e6+1; i++) {
        if (nums[i] > 0) {

            if (nums[i] == 1) ans++;

            for (int j = i; j < 1e6 + 1; j += i) {
                nums[j] = 0;
            }
        }
    }

    print(ans);

    return 0;
}


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

using namespace std;

int main(){
    string s,t;
    cin>>s;
    int n=s.size(),i,j=0;
    for(i=0;i<n;i++){
        if(s[i]=='0'){
            t[j]='0';
            j++;
        } else if(s[i]=='1'){
            t[j]='1';
            j++;
        } else {
            if(j!=0){
                j--;
            }
        }
    }
    for(i=0;i<j;i++)
        cout<<t[i];
    return 0;
}


Measured memory_bytes: 256
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var s = Console.ReadLine();
        int curMaxLength = 0;
        var hash = new RollingHash(s);
        for (int i = 0; i < s.Length; i++)
            for (int j = i; j < s.Length; j++)
                while (curMaxLength < j - i && j + curMaxLength < n && hash.Slice(i, curMaxLength + 1) == hash.Slice(j, curMaxLength + 1)) curMaxLength++;
        Console.WriteLine(curMaxLength);
    }
}

class RollingHash
{
    const ulong MOD1 = 998244353;
    const ulong MOD2 = 1000000007;
    const ulong POSITIVIZER1 = MOD1 << 31;
    const ulong POSITIVIZER2 = MOD2 << 31;
    static uint Base1;
    static uint Base2;
    static ulong[] powMemo1 = new ulong[500000 + 1];
    static ulong[] powMemo2 = new ulong[500000 + 1];

    static RollingHash()
    {
        Base1 = (uint)new Random().Next(129, int.MaxValue);
        powMemo1[0] = 1;
        for (int i = 1; i < powMemo1.Length; i++)
            powMemo1[i] = (powMemo1[i - 1] * Base1) % MOD1;
        Base2 = (uint)new Random().Next(129, int.MaxValue);
        powMemo2[0] = 1;
        for (int i = 1; i < powMemo2.Length; i++)
            powMemo2[i] = (powMemo2[i - 1] * Base2) % MOD2;
    }

    ulong[] hash1;
    ulong[] hash2;

    public RollingHash(string s)
    {
        hash1 = new ulong[s.Length + 1];
        for (int i = 0; i < s.Length; i++)
            hash1[i + 1] = (hash1[i] * Base1 + s[i]) % MOD1;
        hash2 = new ulong[s.Length + 1];
        for (int i = 0; i < s.Length; i++)
            hash2[i + 1] = (hash2[i] * Base2 + s[i]) % MOD2;
    }

    public ulong Slice(int begin, int length)
    {
        return 
            ((hash1[begin + length] + POSITIVIZER1 - hash1[begin] * powMemo1[length]) % MOD1) << 32 |
            ((hash2[begin + length] + POSITIVIZER2 - hash2[begin] * powMemo2[length]) % MOD2);
    }
}


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

using namespace std;

template <typename T>
using vec1 = vector<T>;

template <typename T>
T cin2var()
{
    T val;
    cin >> val;
    return val;
}

template <typename T>
vec1<T> cin2vec(size_t size)
{
    vec1<T> vec1(size);
    for (auto& v : vec1) {
        v = cin2var<T>();
    }
    return vec1;
}

string sub()
{
    const auto N(cin2var<size_t>());
    const auto Q(cin2var<size_t>());

    map<int, string> map_year_name;
    map_year_name[1] = "kogakubu10gokan";
    for (size_t i = 0; i < N; ++i) {
        const auto year(cin2var<int>());
        const auto name(cin2var<string>());
        map_year_name[year] = name;
    }

    {
        // Just
        const auto ite(map_year_name.find(Q));
        if (ite != map_year_name.end()) {
            return ite->second;
        }
    }

    // 要素を追加し、一つ前
    auto ite(map_year_name.emplace(Q, "").first);
    --ite;
    return ite->second;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << sub() << endl;
    return 0;
}


Measured memory_bytes: 3232
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1e6+1;
ll mod=998244353;
int modpow(ll x,ll p){
    if(p==0) return 1;
    ll ans=modpow(x,p/2);
    ans=ans*ans%mod;
    if(p%2) ans=ans*x%mod;
    return ans;
}
int main(){
    ios::sync_with_stdio(0);cin.tie(0);
    int n;
    cin>>n;
    ll inp,mu[N]={},cnt[N]={},cnt2[N]={},out[N]={},in[N]={};
    for(ll i=0;i<n;i++) cin>>inp,in[inp]++;
    for(ll &i:mu) i=1;
    for(int i=1;i<N;i++){
        for(int j=i;j<N;j+=i){
            cnt[i]+=j*in[j];
            cnt2[i]+=1ll*j*j%mod*in[j];
            cnt[i]%=mod;
            cnt2[i]%=mod;
        }
        if(out[i] or i==1) continue;
        for(int j=i;j<N;j+=i){
            mu[j]*=-1;
            out[j]=1;
            if(j%(i*i)==0) mu[j]=0;
        }
    }
    mu[1]=1;
    ll ans=0;
    for(int i=1;i<N;i++){
        ll tmp=0;
        for(int j=i;j<N;j+=i){
            tmp+=(cnt[j]*cnt[j]%mod-cnt2[j]+mod)*(mu[j/i]+mod);
            tmp%=mod;
        }
        ans+=tmp*(modpow(i*2,mod-2));
        ans%=mod;
    }
    cout<<ans;
}

Measured memory_bytes: 42748
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <utility>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <stack>
#define N 100010

using namespace std;

int n;
long long x, a[N], sum[N], cnt;

void solve()
{
    for (int i=1;i<n;i++)
    {
        if (sum[i]>x)
        {
            long long t = sum[i] - x;
            cnt += t;
            sum[i] -= t;
            if (a[i+1]>=t)
            {
                a[i+1] -= t;
            }
            else
            {
                t -= a[i+1];
                a[i+1] = 0;
                a[i] -= t;
            }
        }
        if (i!=n-1)
        {
            sum[i+1] = a[i+1]+a[i+2];
        }
    }
}

int main()
{
    scanf("%d%lld",&n,&x);
    for (int i=1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
        if (i>=2)
        {
            sum[i-1] = a[i-1]+a[i];
        }
    }
    cnt = 0;
    solve();
    printf("%lld\n",cnt);
    return 0;
}


Measured memory_bytes: 1792
// g++ -std=c++11 temp.cpp
#include <bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define EACH(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3

#define MAX_N 1000

int h,w;
string s[100];
bool used[100][100];

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

void dfs(int y, int x, char c){
	used[y][x] = true;
	REP(i,4){
		int nx = x+dx[i], ny = y+dy[i];
		if(nx>=0&&nx<w&&ny>=0&&ny<h&&!used[ny][nx]&&s[ny][nx]==c){
			dfs(ny,nx,c);
		}
	}
}

int main(){
	while(1){
		cin>>h>>w;
		if(h==0&&w==0) break;
		REP(i,h) cin>>s[i];
		REP(i,h)REP(j,w) used[i][j] = false;
		int res=0;
		REP(i,h)REP(j,w){
			if(!used[i][j]){
				res++; dfs(i,j,s[i][j]);
			}
		}
		cout<<res<<endl;
	}

	return 0;
}

Measured memory_bytes: 3976
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}
const int INF = 1001001001;

int h, w, k;
vs grid;

int divide(int bit) {
    int d = __builtin_popcount(bit);
    vvi cnt(d+1, vi(w, 0));
    vi now(d+1, 0);
    int row = 0;
    rep(i, h) {
        rep(j, w) {
            cnt[row][j] += (grid[i][j] == '1');
        }
        if (bit>>i&1) row++;
    }
    int res = d;
    rep(j, w) {
        bool flag = false;
        rep(i, d+1) {
            now[i] += cnt[i][j];
            if (now[i] > k) flag = true;
        }
        if (flag) {
            res++;
            flag = false;
            rep(i, d+1) {
                now[i] = cnt[i][j];
                if (now[i] > k) {
                    res = INF;
                    flag = true;
                    break;
                }
            }
        }
        if (flag) break;
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    cin >> h >> w >> k;
    grid.resize(h);
    rep(i, h) cin >> grid[i];
    
    int ans = INF;
    rep(bit, 1<<(h-1)) { 
        chmin(ans, divide(bit));
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <cstring>
#include <algorithm>
#include <ctime>
#include <vector>
#include <map>
#include <set>
#include <math.h>
#include <list>
#include <limits.h>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>

using namespace std;
typedef long long ll;
const int INF = 1e5 + 10;

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

    string ans = "APPROVED";
    for(int i = 0; i < N; i++) {
        cin >> a;
        if(a % 2 == 0 && !(a % 3 == 0 || a % 5 == 0)) {
            ans = "DENIED";
            break;
        }
    }
    cout << ans << endl;
}


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

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

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

int main() {
    int n;
    cin >> n;
    double a = 0;
    for (int i = 1; i <= n; ++i) {
        if(i&1) a++;
    }
    printf("%.10f\n", a/n);
    return 0;
}

Measured memory_bytes: 764
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<string>
#include<cstdlib>
using namespace std;


int main()
{
	int a, b, c = 0;
	cin >> a >> b;
	if (a - 1 >= b) {
		c = 2 * a - 1;
	}
	else if (b - 1 >= a) {
		c = 2 * b - 1;
	}
	else
		c = a + b;
	cout << c << endl;

}


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

int main() {
	int n;
	string s;
	cin >> n >> s;
	int M = 0;
	for (int i = 1;i < n ;i++) {
		int m = 0;
		string p = s.substr(0, i), q = s.substr(i, n - i);
		int pp[100] = {}, qq[100] = {};
		for (int j = 0;j < p.size();j++) {
			pp[p[j] - 'a']++;
		}
		for (int j = 0;j < q.size();j++) {
			qq[q[j] - 'a']++;
		}
		for (int j = 0;j < 100;j++) {
			if (pp[j] > 0 && qq[j] > 0)m++;
		}
		M = max(M, m);
	}
	cout << M << endl;	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define U [1<<17]={}
typedef long long L;using namespace std;map<L,L>T U;L P U,E U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c,p,r;char s U;
L D(L a){L d;Z[a]=1;for(map<L,L>::iterator I=T[a].begin();I!=T[a].end();I++)
    d=I->first,d-P[a]?P[d]=a,E[d]=E[a]+1,C[d]=I->second,D(d),Z[a]+=Z[d],!H[a]|Z[H[a]]<Z[d]?H[a]=d:0:0;}
#define G(a)((r=A[a]+A[P[a]]+C[a])%k?r:0)
L M(L i){return i?B[i]+M(i^i&-i):0;}
L S(L x,L i){for(x=G(x)+M(i++)-M(i);i<1<<17;i+=i&-i)B[i]+=x;}
L W(){for(c=0;p=X[a],n=X[b],p-n;a=P[p])E[p]<E[n]?swap(p,n),swap(a,b),0:0,c+=M(O[a])-M(O[p])+G(p);cout<<c+abs(M(O[a])-M(O[b]))<<endl;}
main(){for(cin>>n>>k;++p<n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;
       for(D(c=p=0);p<n;p++)if(!p|H[P[p]]-p)for(a=p;!c|a;S(a=H[a],O[a]=c++))X[a]=p;
       for(cin>>a;cin>>s>>a>>b;*s&2?W():A[a]+=b,S(H[a],O[a]),a?S(a,O[a]-1):0);}

Measured memory_bytes: 33464
import java.util.*;
import java.text.DecimalFormat;

public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		Random rn = new Random();
		DecimalFormat df = new DecimalFormat("#,###.##");

		int N = sc.nextInt(), num;

		num = (int)Math.pow(N,3);

		System.out.println(num);
	}
}

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n;
    cin >> n;
    vector<ll> p(n);
    for(i = 0;i < n;++i){
        cin >> p.at(i);
    }
    vector<ll> r(n);
    for(i = 0;i < n;++i){
        r.at(p.at(i)-1) = i + 1;
    }
    vector<ll> a(n);
    vector<ll> b(n);
    for(i = 0;i < n;++i){
        a.at(i) = (n+1)*(i+1);
        b.at(i) = (n+1)*(n-i-1) + r.at(i);
    }

    for(i = 0;i < n-1;++i){
        cout << a.at(i) << " ";
    }
    cout << a.at(i) << endl;
    for(i = 0;i < n-1;++i){
        cout << b.at(i) << " ";
    }
    cout << b.at(i) << endl;

    return 0;
}

Measured memory_bytes: 1280
#include <algorithm>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 0
constexpr int kMod = 1000000007;
typedef long long LL;

LL dp[101][2][5];  // keta, smaller, K

int main() {
  std::string N; std::cin >> N;
  int K; std::cin >> K;
  int length = N.length();

  // Initialize.
  for (int i = 0; i <= length; ++i) {
    for (int s = 0; s < 2; ++s) {
      for (int k = 0; k <= K; ++k) {
        dp[i][s][k] = 0;
      }
    }
  }

  dp[0][0][0] = 1;
  for (int i = 1; i <= length; ++i) {
    LL v = N[i-1] - '0';
    for (int k = 0; k <= K; ++k) {
      if (v == 0) {
        dp[i][0][k] += dp[i-1][0][k];
        dp[i][1][k+1] += 9 * dp[i-1][1][k];
        dp[i][1][k] += dp[i-1][1][k];
      } else {  // v != 0
        dp[i][0][k+1] += dp[i-1][0][k];
        dp[i][1][k+1] += 9 * dp[i-1][1][k] + (v-1) * dp[i-1][0][k];
        dp[i][1][k] += dp[i-1][1][k] + dp[i-1][0][k];
      }
    }
  }

#if DEBUG
  for (int i = 0; i <= length; ++i) {
    for (int s = 0; s < 2; ++s) {
      for (int k = 0; k <= K; ++k) {
        std::cout << dp[i][s][k] << " ";
      }
      std::cout << std::endl;
    }
    std::cout << "-----" << std::endl;
  }
#endif

  std::cout << (dp[length][0][K] + dp[length][1][K]) << std::endl;
}


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

using namespace std;

int main(){
 int n;
  cin >> n;
  
  vector<pair<long,long>> p(n);
  for(int i=0;i<n;i++){
    long a,b;
  cin >> a >> b;
    p[i]=make_pair(b,a);
  }
  
  sort(p.begin(),p.end());
 
  long lapse=0;
  bool dis=true;
 
  for(int i=0;i<n;i++){
  lapse+=p[i].second;
    
    if(lapse>p[i].first){
     dis=false;
   break;
   }
  }
 
  if(dis){
  cout << "Yes" << endl;
  }
  else{
  cout << "No" << endl;
  }
  
}  
  

Measured memory_bytes: 3456
#include<iostream>
#include<cmath>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<cstdlib>
#include<queue>
using namespace std;

int main(){
    int n, q;
    queue<string>  name;
    queue<int> time;
    cin>>n>>q;
    
    for(int i=0; i<n; i++){
        string a;
        int t;
        cin>>a>>t;
        name.push(a);
        time.push(t);
    }
    
    int T=0;
    while(!time.empty()){
        if(time.front()>q){
            T+=q;
            time.front()-=q;
            time.push(time.front());
            time.pop();
            name.push(name.front());
            name.pop(); 
        }else {
            T+=time.front();
            cout<<name.front()<<' '<<T<<endl;
            name.pop();
            time.pop();
        }
    }
    
}



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

typedef long long ll;
int main() {
	int g1, s1, b1;
	int g2, s2, b2;
	int N;
	cin >> N;
	cin >> g1 >> s1 >> b1;
	cin >> g2 >> s2 >> b2;

	vector<ll> dp1(N + 1, 0);

	pair<int, int> v[4];

	v[0] = make_pair(g1, g2);
	v[1] = make_pair(s1, s2);
	v[2] = make_pair(b1, b2);
	v[3] = make_pair(1, 1); //買わない

	for(int i = 1; i <= N; i++) {
		for(int j = 0; j < 4; j++) {
			if(i - v[j].first < 0) continue;
			dp1[i] = max(dp1[i], dp1[i - v[j].first] + v[j].second);
		}
	}

	ll M = dp1[N];

	vector<ll> dp2(M + 1, 0);
	pair<int, int> w[4];
	w[0] = make_pair(g2, g1);
	w[1] = make_pair(s2, s1);
	w[2] = make_pair(b2, b1);
	w[3] = make_pair(1, 1);

	for(ll i = 1; i <= M; i++) {
		for(int j = 0; j < 4; j++) {
			if(i - w[j].first < 0) continue;
			dp2[i] = max(dp2[i], dp2[i - w[j].first] + w[j].second);
		}
	}
	cout << dp2[M] << endl;
}


Measured memory_bytes: 195584
from collections import Counter
import sys
input=sys.stdin.readline
n=int(input())
s=[input().rstrip() for _ in range(n)]
C=Counter(s).most_common()
f=C[0][1]
t=[]
for k,v in C:
	if v<f:
		break
	t.append(k)
print(*sorted(t),sep="\n")

Measured memory_bytes: 45040
#include <bits/stdc++.h>
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 endl "\n"
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 2e+9 + 10;
typedef pair<ll, ll> P;


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

  string s; cin >> s;
  rep(i, s.size()) {
    if(i%2 == 0) cout << s[i];
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 592
/**
    BISMILLAH
    @Author : Arham
*/
#include <bits/stdc++.h>
using namespace std;

void solve() {
    int val;
    cin >> val;
    cout << !val << endl;

    return;
}

int main() {
    int t = true;
//    cin >> t;
    while(t--)
        solve();

    return 0;
}


Measured memory_bytes: 3632
s = []
t = []
s = gets.chomp.gsub(/S/, "1").gsub(/C/, "2").gsub(/R/, "3").split("").map(&:to_i)
t = gets.chomp.gsub(/S/, "1").gsub(/C/, "2").gsub(/R/, "3").split("").map(&:to_i)
results = 0
3.times do |i|
  if s[i] == t[i]
    results+=1
  end
end
puts results


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back
#define mp make_pair
#define M 1000000007
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
const int N=1e6+1;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	cout<<c<<" "<<a<<" "<<b<<endl;







}	

Measured memory_bytes: 256
use std::io::{stdin, Read};
use std::str::FromStr;

// https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[allow(dead_code)]
fn main() {
    let n = read::<i64>();
    if n == 0 {
        println!("0");
        return;
    }
    let mut s = std::collections::VecDeque::new();
    let mut d = 1 as i64;
    let mut total = 0;

    loop {
        if total == n {
            break;
        }

        let candidate = total + d;
        d *= -2;
        if n % d == candidate || n % d - d == candidate {
            s.push_front(1);
            total = candidate
        } else {
            s.push_front(0)
        }
    }
    for c in s {
        print!("{}", c)
    }
    println!()
}


Measured memory_bytes: 4352