akhauriyash/Code-Regression huggingface dataset:
charge, n_coin = map(int,input().split())
coin_ls = list(map(int, input().split()))
coin_ls = [0] + coin_ls

dp = [[float('inf')] * (charge+1) for _ in range(n_coin+1)]
dp[0][0] = 0
for coin_i in range(1,n_coin+1):
    for now_charge in range(0,charge+1):
        if now_charge - coin_ls[coin_i] >= 0:
            dp[coin_i][now_charge] = min(dp[coin_i][now_charge], dp[coin_i][now_charge-coin_ls[coin_i]]+1)
        dp[coin_i][now_charge] = min(dp[coin_i-1][now_charge], dp[coin_i][now_charge]) 
print(dp[n_coin][charge])


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

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

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

#define x1 gray_cat_x1
#define y1 gray_cat_y1

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

#define file "cycle"

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

const int MAXLEN = 5e5 + 5;

struct my_string {
	// string
	char s[MAXLEN];
	// string length
	int n;
	
	// prefix function
	int pf[MAXLEN];
	
	// prefix function calculation
	void get_pf(){
		pf[0] = 0;
		for(int i = 1; i < n; i++){
			int j = pf[i - 1];
			while(j > 0 && s[j] != s[i]){
				j = pf[j - 1];
			}
			if (s[j] == s[i]){
				j++;
			}
			pf[i] = j;
		}
	}
};

my_string str, str_rev;

bool check(my_string &str, int len){
	return !str.pf[len - 1] || len % (len - str.pf[len - 1]);
}

void solve(){
	scanf("%s", &str.s[0]);
	str.n = strlen(str.s);
	REP(i, 0, str.n){
		str_rev.s[i] = str.s[str.n - 1 - i];
	}
	str_rev.n = str.n;
	str.get_pf();
	str_rev.get_pf();
	/*REP(i, 0, str.n){
		printf("%d %d\n", str.pf[i], str_rev.pf[i]);
	}*/
	if (check(str, str.n)){
		printf("1 1\n");
		return;
	}
	if (str.n - str.pf[str.n - 1] == 1){
		printf("%d 1\n", str.n);
		return;
	}
	int ans = 0;
	REPN(i, 1, str.n - 1){
		if (check(str, i) && check(str_rev, str.n - i)){
			ans++;
		}
	}
	printf("2 %d\n", ans);
}	

int main(){

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

Measured memory_bytes: 5120
#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++) //最初の数値を指定したループ

//型名省略
typedef long long ll;
//配列要素数
static const int MAX = 200000;
//値
static const ll MX = 1e18;

using namespace std;

//#include "./lib/generic/search.h"

/*std::tuple<int, int> swap(int num1, int num2){
     return std::forward_as_tuple(num1, num2);
}*/

int main(){

    int n;
    cin >> n;;
    int s[n];
    REP(i, n){
        cin >> s[i]; 
    }
    int q;
    cin >> q;
    
    /*int tmp, j=0, ans=0;
    bool ret;
    REP(i, q){
        cin >> tmp;
        j = 0;
        search::Search test;
        ret = test.searchByLinear(s, n, tmp);
        if(ret==true) ans++;
    }*/
    
    int tmp, mid, left, right, j=0, ans=0;
    bool ret;
    REP(i, q){
        cin >> tmp;
        left = 0;
        right = n;
        while(left<right){
            mid = (left+right)/2;
            if(s[mid]==tmp){
                ans++;
                break;
            }
            else if(s[mid]<tmp){
                left = mid+1;
            }
            else if(s[mid]>tmp){
                right = mid;
            }
        }
    }

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


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

int main(int argc, const char * argv[]) {
    char S[4] = {0};
    
    cin >> S;
    if (strlen(S) == 3) {
        char tmp = S[0];
        S[0] = S[2];
        S[2] = tmp;
    }
    cout << S << endl;
    
    return 0;
}

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

using namespace std;

int main() {
	int sx, sy, tx, ty;
	
	cin >> sx >> sy >> tx >> ty;
	
	int yoko = tx - sx, ue = ty - sy;

	for (int i = 0; i < ue; i++) {
		cout << 'U';
	}
	for (int i = 0; i < yoko; i++) {
		cout << 'R';
	}
	for (int i = 0; i < ue; i++) {
		cout << 'D';
	}
	for (int i = 0; i < yoko; i++) {
		cout << 'L';
	}

	cout << 'L';
	for (int i = 0; i < ue + 1; i++) {
		cout << 'U';
	}
	for (int i = 0; i < yoko + 1; i++) {
		cout << 'R';
	}
	cout << 'D';

	cout << 'R';
	for (int i = 0; i < ue + 1; i++) {
		cout << 'D';
	}
	for (int i = 0; i < yoko + 1; i++) {
		cout << 'L';
	}
	cout << 'U' << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using std::max;
const int MAXN=200005;
int n,i,x,y,z,a[MAXN],f[MAXN][3];
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
    	if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
inline void print(int x)
{
    if (x<0)
        putchar('-'),x=-x;
    if (x>9)
        print(x/10);
    putchar(x%10+'0');
}
signed main(void)
{
	read(n);
	for (i=1;i<=n;i++)
		read(a[i]);
	if (!(n%2))
	{
		f[1][0]=a[1];
		for (i=2;i<=n;i++)
			if (i%2)
				f[i][0]=f[i-2][0]+a[i];
			else
			{
				if (i>=3)
					f[i][1]=max(f[i-2][1],f[i-3][0])+a[i];
				else
					f[i][1]=f[i-2][1]+a[i];
			}
		return print(max(f[n-1][0],f[n][1])),0;
	}
	f[1][0]=a[1];
	for (i=2;i<=n;i++)
		if (i%2)
		{
			f[i][0]=f[i-2][0]+a[i];
			if (i>=4)
				f[i][2]=max(f[i-2][2],max(f[i-3][1],f[i-4][0]))+a[i];
			else
			{
				if (i>=3)
					f[i][2]=max(f[i-2][2],f[i-3][1])+a[i];
				else
					f[i][2]=f[i-2][2]+a[i];
			}
		}
		else
		{
			if (i>=3)
				f[i][1]=max(f[i-2][1],f[i-3][0])+a[i]; 
			else
				f[i][1]=f[i-2][1]+a[i];
		}
	print(max(f[n][2],max(f[n-1][1],f[n-2][0])));
	return 0;
}

Measured memory_bytes: 9884
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<list>
#include <array>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807
#define INF I64_MAX
#define MOD 1000000007

bool prime_judge(int A)
{
  for (int i = 2; i <= sqrt(A); i++)
  {
    if(A%i == 0) return true;
  }

  return false;
  
  
}


void solve(void)
{ 
  int N;
  cin>>N;
  string S;
  string T;

  cin>>S;
  cin>>T;
  vector<char> New(2*S.size());
  for (int i = 0; i < S.size(); i++)
  {
    New[2*i] = S[i];
    New[2*i+1] = T[i];
  }

  for (int i = 0; i < New.size(); i++)
  {
    cout<<char(New[i]);
  }
  
  
  return;  
}



int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  // std::cout << std::fixed;
  // std::cout << std::setprecision(8);

  solve();

 
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	int n = s.size();
	int ans = 0;
	rep(i, n / 2) {
		if (s[i] != s[n - i - 1]) ans++;
	}
	printf("%d\n", ans);
	return 0;
}


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

using namespace std;

vector<string> split(const string &s, char delim) {
  vector<string> elems;
  string item;
  for (char ch: s) {
    if (ch == delim) {
      if (!item.empty()) {
        elems.push_back(item);
      }
      item.clear();
    }
    else {
      item += ch;
    }
  }
  if (!item.empty()) {
    elems.push_back(item);
  }
  return elems;
}

string to_str_with_zero(int i, int w) {
  ostringstream sout;
  sout << std::setfill('0') << std::setw(w) << i;
  string s = sout.str();
  return s;
}

int letter_to_int(char c) {
  return tolower(c) - 'a';
}

int compare_array(vector<int> a1, vector<int>a2) {
  if (a1.size() != a2.size()) {
    return a1.size() - a2.size();
  }
  for (int i=0; i<a1.size(); i++) {
    if (a1.at(i) != a2.at(i)) {
      return a1.at(i) - a2.at(i);
    }
  }
  return 0;
}

int gcd(int a, int b) {
  if (a == b) {
    return a;
  }
  else if (a > b) {
    return gcd(a - b, b);
  }
  else {
    return gcd(a, b - a);
  }
}

char int_to_char(int a) {
  if (a == -1) {
    return 'z';
  }
  else {
    return 'a' + a;
  }
}

long nCr(int n, int r) {
    long ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

int divide_count(int a, int divider) {
  int r = 0;
  while(a % divider == 0) {
    a /= divider;
    r++;
  }
  return r;
}

bool is_prime(int a) {
  int i = 2;
  while(i * i <= a) {
    if(a % i == 0) {
      return false;
    }
    i++;
  }
  return true;
}

int main() {
  std::cout << std::setprecision(9);
  int n, k;
  cin >> n >> k;

  vector<int> h(n);
  for(int i=0; i<n; i++) {
    cin >> h[i];
  }
  sort(h.begin(), h.end());

  long ans = 0;
  for(int i=0; i<n - k; i++) {
    ans += h[i];
  }
  cout << ans << endl;
}

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


int main() {
	int d;
	int x;
	int y;
	cin >> x >> y;
	if (x > y)
	{
		d = x % y;
		x = y;
		y = d;
		while (d != 0)
		{
			d = x % y;
			x = y;
			y = d;
		}
	}
	else
	{
		d = x % y;
		x = y;
		y = d;
		while (d != 0)
		{
			d = x % y;
			x = y;
			y = d;
		}
	}
	cout << x << "\n";
	return 0;
}


Measured memory_bytes: 3080
import sys
from itertools import islice


def resolve(in_):
    R, C, K = map(int, next(in_).split())
    _rcv = (map(int, line.split()) for line in islice(in_, K))

    R1 = R + 1
    C1 = C + 1
    R2 = R + 2
    C2 = C + 2
    limit_item = 3
    limit_item1 = limit_item + 1
    C2limit_item1 = C2 * limit_item1

    # grid = [[0] * C2 for _ in range(R2)]
    grid = [0] * (R2 * C2)
    for r, c, v in _rcv:
        # grid[r][c] = v
        grid[(r * C2) + c] = v

    
    # dp = [[[0] * limit_item1 for j in range(C2)] for i in range(R2)]
    dp = [0] * (R2 * C2 * limit_item1)
    # dp[1][1][1] = grid[1][1]
    dp[(1 * C2limit_item1) + (1 * limit_item1) + 1] = grid[(1 * C2) + 1]

    for i in range(1, R1):
        for j in range(1, C1):
            for k in range(limit_item1):
                # current = dp[i][j][k]
                current = dp[(i * C2limit_item1) + (j * limit_item1) + k]

                # left = grid[i][j + 1]
                left = grid[(i * C2) + (j + 1)]
                # dp[i][j + 1][k] = max(dp[i][j + 1][k], current)
                dp[(i * C2limit_item1) + ((j + 1) * limit_item1) + k] = max(dp[(i * C2limit_item1) + ((j + 1) * limit_item1) + k], current)
                if k < limit_item:
                    # dp[i][j + 1][k + 1] = max(dp[i][j + 1][k + 1], left + current)
                    dp[(i * C2limit_item1) + ((j + 1) * limit_item1) + (k + 1)] = max(dp[(i * C2limit_item1) + ((j + 1) * limit_item1) + (k + 1)], left + current)

                # top = grid[i + 1][j]
                top = grid[((i + 1) * C2) + j]
                # dp[i + 1][j][0] = max(dp[i + 1][j][0], current)
                dp[(i + 1) * C2limit_item1 + (j * limit_item1) + 0] = max(dp[(i + 1) * C2limit_item1 + (j * limit_item1) + 0], current)
                # dp[i + 1][j][1] = max(dp[i + 1][j][1], top + current)
                dp[(i + 1) * C2limit_item1 + (j * limit_item1) + 1] = max(dp[(i + 1) * C2limit_item1 + (j * limit_item1) + 1], top + current)
    # return max(dp[R][C])
    return max(dp[(R * C2limit_item1) + (C * limit_item1):((R + 1) * C2limit_item1) + ((C + 1) * limit_item1)])


def main():
    answer = resolve(sys.stdin.buffer)
    print(answer)


if __name__ == '__main__':
    main()


Measured memory_bytes: 421132
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val l = sc.nextInt()
    val r = sc.nextInt()
    val d = sc.nextInt()
    var count = 0
    for (i in l..r) {
        if (i % d == 0) {
            count++
        }
    }
    println(count)
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


Measured memory_bytes: 34264
import java.util.Scanner;

/**
 * Created by enpingkuang on 2020/9/10 11:18 下午
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        long max = 0;
        long ans = 0;
        for(int i = 0;i<n;i++){
            int tmp = scanner.nextInt();
            if(tmp < max){
                ans += (max-tmp);
            }else{
                max = Math.max(tmp,max);
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 58668
//ITP 1_7_B

#include<iostream>
using namespace std;

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

int main() {
	int n, x; 
	while (cin >> n >> x, n) {
		int a = 0;
		for (int i = 1; i <= n; i++)
			for (int j = i + 1; j <= n; j++)
				for (int k = j + 1; k <= n; k++) {
					if (i + j + k == x) a++;
				}
		cout << a << endl;
	}
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

int main() {
  i64 N, K;
  cin >> N >> K;
  vector<i64> A(N);
  i64 sum = 0;
  rep(i,0,N) {
    cin >> A[i];
    sum += A[i];
  }

  auto ff = [&](i64 d) {
    vector<i64> B(N);
    rep(i,0,N) B[i] = A[i] % d;
    sort(all(B));
    vector<i64> S(N + 1, 0);
    rep(i,0,N) S[i + 1] = S[i] + B[i];
    rep(i,0,N) {
      i64 mns = S[i];
      i64 pls = (N - i) * d - (S[N] - S[i]);
      if(max(mns, pls) <= K) return true;
    }
    return false;
  };

  i64 res = 0;
  for(i64 d = 1; d * d <= sum; d++) {
    if(sum % d == 0) {
      if(ff(d)) res = max(res, d);
      if(ff(sum / d)) res = max(res, sum / d);
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 256
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools, random
from collections import deque
from heapq import heappush, heappop
sys.setrecursionlimit(10 ** 7)
ans = 0
tmp = 0
inf = 10 ** 20
INF = float("INF")
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
ddn9 = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1), (0, 0)]
"""for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""
def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]#WideIntPoint
def ws(): return sys.stdin.readline().split()
def i(): return int(sys.stdin.readline())
def s(): return input()
def hi(n): return [i() for _ in range(n)]
def hs(n): return [s() for _ in range(n)]#HeightString
def mi(n): return [wi() for _ in range(n)]#MatrixInt
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]

h, w, n = wi()
c = mip(n)

d = collections.defaultdict(int)

for i in range(n):
    for dx, dy in ddn9:
        nx = c[i][1] + dx;
        ny = c[i][0] + dy
        if 0 < nx < w - 1 and 0 < ny < h - 1:
            d[str(ny) + "+" + str(nx)] += 1#前のままだと，28+1,2+81とかがが被る

ansli = [0] * 10
for i in d:
    ansli[d[i]] += 1

ansli[0] = (h - 2) * (w - 2) - sum(ansli)
for i in ansli:
    print(i)

Measured memory_bytes: 225500
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;


struct aUnionFind {
	vector<pair<int, long long int>> data;
	aUnionFind(int size) : data(size, make_pair(-1, 0)) { }

	//y is w bigger than x
	bool unionSet(const int x, const int y, const long long int w) {
		const int rx(root(x).first), ry(root(y).first);
		if (rx != ry) {
			data[rx].first += data[ry].first; data[ry].first = rx;
			data[ry].second = w + data[x].second - data[y].second;
			return true;
		}
		else {
			return root(x).second + w == root(y).second;
		}
	}

	//x is belong to first
	//x is second bigger than first
	pair<int, long long int> root(const int x) {
		if (data[x].first < 0) {
			return make_pair(x, 0);
		}
		else {
			pair<int, long long int>ndata;
			ndata.first = root(data[x].first).first;
			ndata.second = data[x].second + root(data[x].first).second;
			return data[x] = ndata;
		}
	}
	int size(const int x) {
		return -data[root(x).first].first;
	}
};



int main() {
	
	while (true) {
		int T;cin>>T;
		if(!T)break;
		map<string,int>mp;
		int id=0;
		aUnionFind uf(1000);
		bool ok=true;
		while (T--) {
			string one,name1,eq,num,name2;
			cin>>one>>name1>>eq>>num>>name2;

			if (mp.find(name1) == mp.end()) {
				mp[name1]=id++;
			}
			if (mp.find(name2) == mp.end()) {
				mp[name2]=id++;
			}

			string n_st(num);
			int anum=stoi(n_st.substr(3));

			if (uf.root(mp[name1]).first != uf.root(mp[name2]).first) {
				uf.unionSet(mp[name1],mp[name2],anum);
			}
			else {
				if (uf.root(mp[name1]).second + anum == uf.root(mp[name2]).second) {

				}
				else {
					ok=false;
				}
			}
		}
		if(ok)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3196
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a , b;
    cin >> a >> b;
    cout << ( a - 1 ) * ( b - 1 );
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using llong = long long;
using P = pair<int, int>;
const int inf = 1 << 20;
const int mod = 1e9 + 7;

int g[8][8];
int main() {
   int n, m;
   cin >> n >> m;
   rep(i, m) {
      int a, b;
      cin >> a >> b;
      a--;
      b--;
      g[a][b] = 1;
      g[b][a] = 1;
   }
   vector<int> p(n);
   rep(i, n) { p[i] = i; }
   int ans = 0;
   do {
      if (p[0] != 0)
         continue;
      int isok = true;
      rep(i, n - 1) {
         if (g[p[i]][p[i + 1]] == 0)
            isok = false;
      }
      if (isok)
         ans++;
   } while (next_permutation(p.begin(), p.end()));
   cout << ans << endl;
   return 0;
}

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

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            //var N = int.Parse(Console.ReadLine());
            //var txylist = Enumerable.Range(0, N)
            //    .Select(_ => Console.ReadLine().Split(' ').Select(int.Parse).ToArray());

            var N = Io.Read<int>();
            var txylist = Enumerable.Range(0, N).Select(_ => Io.ReadSplit<int>());

            var currentT = 0;
            var currentX = 0;
            var currentY = 0;
            var can = true;
            foreach (var txy in txylist)
            {
                var t = txy[0];
                var x = txy[1];
                var y = txy[2];

                var dt = t - currentT;
                var dx = Math.Abs(x - currentX);
                var dy = Math.Abs(y - currentY);

                if (dx + dy > dt
                    || (dx + dy) % 2 != dt % 2
                    )
                {
                    can = false;
                    break;
                }
            }

            Console.WriteLine(can ? "Yes" : "No");
        }
    }

    class Io
    {
        public static string Read()
        {
            return Console.ReadLine();
        }

        public static T Read<T>()
        {
            return (T)Convert.ChangeType(Read(), typeof(T));
        }

        public static string[] ReadSplit(char devide = ' ')
        {
            return Read().Split(devide);
        }

        public static T[] ReadSplit<T>(char devide = ' ')
        {
            return ReadSplit(devide)
                .Select(s => (T)Convert.ChangeType(s, typeof(T)))
                .ToArray();
        }
    }
}


Measured memory_bytes: 17560
from collections import defaultdict

INF = 999999999999999999999
NEGATIVE_CYCLE = -1

def bellman_ford(G, n, r):
  d = {}
  for i in range(n):
    d[i] = INF
  d[r] = 0
  for i in range(n-1):
    d = relax(G, d)
  for u in G:
    for v in G[u]:
      if d[u] == INF and d[v] == INF:
        continue
      if d[u] + G[u][v] < d[v]:
        return NEGATIVE_CYCLE
  return d

def relax(G, d):
  for u in G:
    if d[u] == INF:
      continue
    for v in G[u]:
      if d[u] + G[u][v] < d[v]:
        d[v] = d[u] + G[u][v]
  return d


G = {}

n, m, r = [int(v) for v in input().strip().split(' ')]
for i in range(n):
  G[i] = {}
for _ in range(m):
  s, t, c = [int(v) for v in input().strip().split(' ')]
  G[s][t] = c

d = bellman_ford(G, n, r)

if d == NEGATIVE_CYCLE:
  print("NEGATIVE CYCLE")
else:
  for i in range(n):
    if d[i] == INF:
      print("INF")
    else:
      print(d[i])

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

using namespace std;

typedef long long ll;

ll md = 1000000007;


int main(int, char**)
{
	ll n, x, s = 0, ans = 1;
	cin >> n >> x;
	for ( int i = 0; i< n; ++i) {
		int y;
		cin >> y;
		s += y;
		if (s > x)
			break;
		ans++;
	}

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


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

#define ll long long
#define rep(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////

ll N;
char C[202020];

ll i, j, k;


int main(){
    scanf("%lld%s", &N,C);
    ll w = 0, r = 0;
    rep(i,0,N){
        if(C[i]=='R'){
            ++r;
        }
    }
    ll ans = 1e9;
    rep(i,0,N+1){
        //printf("%lld:%lld,%lld\n", i, w, r);
        ans = min(ans, max(w, r));
        if(C[i]=='R'){
            --r;
        }
        if(C[i]=='W'){
            ++w;
        }
    }
    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 4008
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1000000001;
const ll MOD = 1000000007;

//GCD

ll gcd(int a, int b){
  if(a%b == 0) return b;
  return gcd(b, a%b);
}

int main(){
  int n;
  cin >> n;
  cout << 2*n/gcd(2, n) <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
// #include <prettyprint.hpp>
using namespace std;
typedef long long llong;
static const llong max_n = 100010;
static const llong max_rgb = 300010;
// static const llong mod = 1000000007;
vector<pair<llong, llong>> R;


int main(){
    // int u, v;
    llong X, Y, A, B, C, p;
    // bool updated = false;
    llong ans = 0;
    scanf("%lld %lld %lld %lld %lld", &X, &Y, &A, &B, &C);
    R.resize(A+B+C);
    for(llong i=0;i<A;i++){
        scanf("%lld", &p);
        R[i] = make_pair(-p, 0);
    }

    for(llong i=0;i<B;i++){
        scanf("%lld", &p);
        R[i+A] = make_pair(-p, 1);

    }

    for(llong i=0;i<C;i++){
        scanf("%lld", &p);
        R[i+A+B] = make_pair(-p, 2);
    }

    sort(R.begin(), R.end());
    llong num_R=0, num_G=0, num_N=0;
    llong i = 0, total_score = 0;
    bool pick_r = true, pick_g = true;
    for(i=0;i<A+B+C;i++){
        bool pick = false;
        if(R[i].second==0 && pick_r){
            // printf("pick R, R[%lld]=%lld\n", i, R[i].first);
            num_R ++;
            pick = true;
            pick_r = num_R < X;
        }else if(R[i].second==1 && pick_g){
            // printf("pick G, G[%lld]=%lld\n", i, R[i].first);
            num_G ++;
            pick = true;
            pick_g = num_G < Y;

        }else if(R[i].second==2){
            num_N ++;
            pick = true;
        }
        if(pick){
            total_score += R[i].first;
            if(num_R+num_G+num_N==X+Y){
                break;
            }
        }
    }


    printf("%lld\n", -total_score);
    // double limit = 1. / (double)(4 * M);



    return 0;

}

Measured memory_bytes: 4992
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#define VIZ2 {printf("graph G{\n"); for(int i=1;i<=n;i++) for es(i,e) if(vb[e]>=i)printf("%d--%d;\n",i,vb[e]); puts("}");}
#define SZ 666666
int c[5],cc[SZ];
int main()
{
	int h,w;
	cin>>h>>w;
	for(int i=1;i<=h;++i)
	{
		char s[233]; scanf("%s",s);
		for(int j=0;j<w;++j) ++cc[s[j]];
	}
	for(int i=1;i<=h+1-i;++i)
	{
		for(int j=1;j<=w+1-j;++j)
		{
			int p=(1+(i!=h+1-i))*(1+(j!=w+1-j));
			++c[p];
		}
	}
	int c4=0,c2=0,c1=0;
	for(int i='a';i<='z';++i)
	{
		c4+=cc[i]/4; cc[i]%=4;
		c2+=cc[i]/2; cc[i]%=2;
		c1+=cc[i];
	}
	if(c[4]>c4)
	{
		puts("No");
		return 0;
	}
	c4-=c[4]; c2+=c4*2;
	if(c[2]>c2)
	{
		puts("No");
		return 0;
	}
	c2-=c[2]; c1+=c2*2;
	if(c[1]>c1)
	{
		puts("No");
		return 0;
	}
	puts("Yes");
}


Measured memory_bytes: 256
package main
 
import (
	"fmt"
	"sort"
)
 
func main() {
  var p, q, r int
  fmt.Scan(&p, &q, &r)
 
  times := []int { p + q, q + r, r + p}
  sort.Ints(times)
  fmt.Println(times[0])
}

Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#define REP(i, n) for(long long i = 0; i < n; ++i)
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    int N,K;
    cin >> N >> K;
    long long ans = K;
    REP(i,N-1) ans *= K-1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int main(){
    char num[1001];
    int sum,i,n;
    for(;;){
        scanf("%s",num);
        i= 0;
        sum = 0;
        while(num[i] != 0){
            sum = sum + (num[i] - '0');
            i++;
            }
        if(sum == 0){
            break;
        }
        printf("%d\n", sum);
    }
        return 0;
}


Measured memory_bytes: 2716
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n = I()
    p = LI()
    t = LI()
    ans = float("inf")
    for i in range(n+1):
        x0 = t[0]*i
        m0 = p[0]*i
        for j in range(n+1):
            x1 = x0+t[1]*j
            m1 = m0+p[1]*j
            for k in range(n+1):
                x2 = x1+t[2]*k
                m2 = m1+p[2]*k
                rest = max(0,math.ceil((n-x2)/t[3]))
                m3 = m2+p[3]*rest
                if m3 < ans:
                    ans = m3
    print(ans)
    return

#B
def B():
    n = I()

    return

#C
def C():
    n = I()

    return

#D
def D():
    n = I()

    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return

#G
def G():
    n = I()

    return

#Solve
if __name__ == "__main__":
    A()



Measured memory_bytes: 8236
#include <iostream>
#include <string>

using namespace std;

int Solve(const string &str)
{
    auto res = 1;
    auto last = str[0];

    for (size_t i = 1; i < str.size(); i += 1) {
        if (str[i] == last) {
            if (i + 1 < str.size()) {
                res += 1;
                last = 0;
                i += 1;
            }
        } else {
            res += 1;
            last = str[i];
        }
    }
    return res;
}

int main()
{
    string str;
    getline(cin, str);

    auto res = Solve(str);
    cout << res << "\n";

    return 0;
}


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

void reader(int *x) {
	int k = getchar_unlocked(); *x = k - '0';
	while (1) {
		k = getchar_unlocked();
		if (k < '0' || k > '9') break;
		*x = ((*x) << 1) + ((*x) << 3) + k - '0';
	}
}
vector<int>E[100000];
int u[200000], v[200000], r[200000], ans[200000], d[100000], cnt = 1;
bool b[200000], ok[100000]{ 1 };
queue<int>que;

void bfs(int u, int t) {
	que.push(u);
	while (!que.empty()) {
		int p = que.front(); que.pop(); for (int v : E[p]) {
			if (t) {
				if (d[v] > d[p] && !ok[v]) {
					ok[v] = 1; cnt++; que.push(v);
				}
			}
			else if (!~d[v]) {
				d[v] = d[p] + 1; que.push(v);
			}
		}
	}
}
int main() {
	int n, m, q; reader(&n); reader(&m); reader(&q);
	rep(i, m) {
		reader(&u[i]); reader(&v[i]);
		u[i]--; v[i]--;
		E[u[i]].emplace_back(v[i]); E[v[i]].emplace_back(u[i]);
	}
	memset(d, -1, sizeof(d));
	d[0] = 0; bfs(0, 0);
	rep(i, m) {
		if (d[u[i]] > d[v[i]])swap(u[i], v[i]);
	}
	rep(i, n)E[i].clear();
	rep(i, q) {
		reader(&r[i]); r[i]--;
		b[r[i]] = 1;
	}
	rep(i, m) {
		if (!b[i]) {
			if (d[v[i]] > d[u[i]]) {
				E[u[i]].emplace_back(v[i]);
			}
		}
	}
	bfs(0, 1);
	for (int i = q - 1; i >= 0; i--) {
		ans[i] = n - cnt;
		if (d[v[r[i]]] > d[u[r[i]]] && !ok[v[r[i]]]) {
			E[u[r[i]]].emplace_back(v[r[i]]);
			if (ok[u[r[i]]]) {
				cnt++; ok[v[r[i]]] = 1;
				bfs(v[r[i]], 1);
			}
		}
	}
	rep(i, q)printf("%d\n", ans[i]);
}

Measured memory_bytes: 13704
n = int(input())
dic = {}
for i in range(n):
    string = input()

    if string in dic:
        dic[string] += 1
    else:
        dic[string] = 0

answers = []
app = 0

for key, value in dic.items():
    if value > app:
        answers.clear()
        answers.append(key)
        app = value
    elif value == app:
        answers.append(key)

answers.sort()
for ans in answers:
    print(ans, sep="\n")


Measured memory_bytes: 32096
#include <iostream>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
#define ALL(a)  (a).begin(),(a).end()
#define REP(i,n) for(int i=0;i<(n);++i)
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define dump(x) cerr << "  (L" << __LINE__ << ") " << #x << " = " << (x) << endl;
#define dumpv(x) cerr << "  (L" << __LINE__ << ") " << #x << " = "; REP(q,(x).size()) cerr << (x)[q] << " "; cerr << endl;
template<typename T1, typename T2>
ostream& operator<<(ostream& s, const pair<T1, T2>& d) {return s << "(" << d.first << "," << d.second << ")";}

LL factorial(int n) {
  if (n == 1) return 1;
  return n * factorial(n-1);
}

int main() {
  int n; cin >> n;
  cout << factorial(n) << endl;
}

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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>istream &operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S>ostream &operator<<(ostream &os, pair<T, S> &p) { os << p.first << " " << p.second; return os; }

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; }return false; }
template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; }return false; }

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int a, b, t; cin >> a >> b >> t;
	cout << t / a * b << endl;

	return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
#define pb push_back

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * g / b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}




const long double PI = 3.14159265359;
const int MAX_N = 100010;

int n;
int ans = 0;
void dfs(int now, int a, int b, int c) {
	if (now > n)return;
	if (a&&b&&c) {
		ans++;
	}
	dfs(now * 10 + 3, 1, b, c);
	dfs(now * 10 + 5, a, 1, c);
	dfs(now * 10 + 7, a, b, 1);
}
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	dfs(0, 0, 0, 0);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
ans=0
if k==0:
    ans=n*n
else:
    #count a<b cases 
    for b in range(k+1,n+1):
        ans+=b-1-k+1
    #count a>b cases 
    for b in range(k+1,n+1):
        #from b+k to b+b-1 mod>=k after that cycle repeats
        steps=(n-b+1)//b
        ans+=steps*(b-k)
        rem=(n-b+1)%b
        if rem>k:
            ans+=rem-k
print(ans)



Measured memory_bytes: 3060
import sys
input = sys.stdin.readline
N, Q = map(int, input().split())
S = input()
dp = [0]*(N+1)
cnt = 0
for i in range(2,N+1):
    if S[i-1] == "C" and S[i-2] == "A":
        cnt += 1
    dp[i] = cnt
ans = []
for _ in [0]*Q:
    l, r = map(int, input().split())
    ans.append(dp[r] - dp[l])
print(*ans, sep="\n")

Measured memory_bytes: 53980
# union by size
class DisjointSet:
    def __init__(self, size):
        self.size = [0 for i in range(size)]
        self.p = [0 for i in range(size)]
        for i in range(size):
            self.makeSet(i)
    
    def makeSet(self, x):
        self.p[x] = x
        self.size[x] = 1

    def same(self, x, y):
        return self.findSet(x) == self.findSet(y)

    def unite(self, x, y):
        self.link(self.findSet(x), self.findSet(y))

    def link(self, x, y):
        if self.size[x] > self.size[y]:
            self.p[y] = x
            self.size[x] += self.size[y]
        else:
            self.p[x] = y
            self.size[y] += self.size[x]
    
    def findSet(self, x):
        if x != self.p[x]:
            self.p[x] = self.findSet(self.p[x])
        return self.p[x]

    def getSize(self, x):
        return self.size[ds.findSet(x)]

N, M = map(int, input().split())
ds = DisjointSet(N+1)
for m in range(M):
    A, B = map(int, input().split())
    ds.unite(A, B)
ans = len(set([ds.findSet(i) for i in range(1, N+1)])) - 1
print(ans)


Measured memory_bytes: 87872
// 1から足してってちょうどになったらそれ、越えたら超えたぶんをぬかしたそれ
package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)
	sum := 0
	ans := make(map[int]bool)
	for i := 1; sum < N; i++ {
		sum += i
		ans[i] = true
	}
	if sum > N {
		ans[sum-N] = false
	}
	for k, v := range ans {
		if v {
			fmt.Println(k)
		}
	}
}


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

namespace ABC121 {
	class ABC121_A {
		static void Main(string[] args) {
			var inputLine1 = Console.ReadLine().Split(' ').Select(s => int.Parse(s));
			var H = inputLine1.First();
			var W = inputLine1.Last();
			var inputLine2 = Console.ReadLine().Split(' ').Select(s => int.Parse(s));
			var h = inputLine2.First();
			var w = inputLine2.Last();
			Console.WriteLine(H*W-((h*W)+(w*H))+h*w);
		}
	}
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;

int main(){
    ll N, M;
    cin >> N >> M;
    string S;
    cin >> S;
    vector<ll> ans;

    ll cnt = 0;

    ll l;
    ll r = N;
    bool check;
    while(r != 0){
        check = false;
        l = max(r - M, zero);
        for (; l < r; l++) {
            if(S[l] == '0'){
                ans.push_back(r - l);
                r = l;
                check = true;
                break;
            }
        }
        if(check == true){
            cnt++;
        }
        else{
            printf("-1\n");
            return 0;
        }

    }
    for (ll i = cnt - 1; i >= 0; i--) {
        printf("%lld ", ans[i]);
    }


}

Measured memory_bytes: 1528
import sys

H, W = map(int,input().split())
canv = [list(map(str, input())) for _ in range(H)]

def judge(f, i, j):
	np = [[i-1,j], [i+1,j], [i,j-1], [i,j+1]]
	for p in np:
		if 0 <= p[0] <= H-1 and 0 <= p[1] <= W-1 and f[p[0]][p[1]] =="#":
			return 0
	return 1


for i in range(H):
	for j in range(W):
		if canv[i][j] == "#":
			if judge(canv, i, j) == 1:
				print("No")
				sys.exit()

print("Yes")		


Measured memory_bytes: 3064
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
    WRITER:kakitamasziru/OxOmisosiru
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG //FOR THE DEBUG! COMMENT OUT THIS WHEN SUBMITTING!
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
//#include <unordered_map> // unordered_map
//#include <unordered_set> // unordered_set
#include <bitset> // bitset
//#include <cctype> // isupper, islower, isdigit, toupper, tolower
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 100100100100100;
const int MOD = 1000000007;
typedef pair<int,int> P;
//NのM乗を求める(繰り返し二乗法)
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}
long long nCr(long long n, long long r) {
    long long A = 1, B = 1;
    //Aが分子Bが1/r!
    for (long long i = n - r + 1; i <= n; i++) {
        A = A * i % MOD;
    }
    for (long long i = 1; i <= r; i++) {
        B = B * i % MOD;
    }
    B = mod_pow(B, MOD - 2);
    B %= MOD;
    //Bは割るのではなく掛ける
    return (A * B) % MOD;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
 
long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}

long long A,B;

bool ok(long long key,long long index){
    string S = to_string(index);
    long long nagasa = S.size();
    if(index*A+nagasa*B > key) return true;
    else if(index*A+nagasa*B <= key) return false;
}

long long binary_search(long long key,long long size){
    //left,right,midはいずれもindex
    long long left = -1,right = size;
    while(right - left > 1){
        long long mid = left + (right-left)/2;
        long long hantei = ok(key,mid);
        if(hantei) right = mid;
        else left = mid;
    }
    if(left == -1)return 0;
    return left;
}

int main() {
    int N;cin >> N;
    vector<int> retu(N);
    for(int i = 0;i<N;i++)cin >> retu.at(i);
    long long ans = retu.at(0);
    for(int i = 1;i<N;i++){
        ans = gcd(ans,retu.at(i));
    }

    cout << ans << endl;
    // PLEASE GIVE ME THE "ACCEPTED" !
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                              \
  ifstream in("atcoder-problems/arc101_a.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N, K;
  cin >> N >> K;

  vector<ll> c(N, 0);
  rep(i, N) { cin >> c[i]; }

  ll ans = LINF;
  rep(i, N - K + 1) {
    int l = i;
    int r = i + K - 1;
    ll time = min(abs(c[l]) + abs(c[l] - c[r]), abs(c[r]) + abs(c[l] - c[r]));
    ans = min(ans, time);
  }

  cout << ans << endl;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
#define MN 40002
#define MM 5000001
#define ll long long
#define ld long double
#define inf 0x7fffffff
#define clz 1000000007
#define ers(arr,val) memset(arr,val,sizeof(arr));
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define repd(i,b,a) for(int i=(b);i>=(a);i--)
#define repe(i,u) for(int i=h[u];i;i=e[i].nx)
using namespace std;
int f[101][9],g[10];
int h,w,k;
int main(){
	g[0]=1;g[1]=1;
	for(int i=2;i<=10;i++) g[i]=(g[i-1]+g[i-2])%clz;
	scanf("%d%d%d",&h,&w,&k);
	f[0][1]=1;
	rep(i,1,h)rep(j,1,w){
		f[i][j]=(f[i][j]+1ll*(1ll*g[max(j-1,0)]*g[max(w-j,0)]%clz)*f[i-1][j])%clz;
		if(j<=w-1) f[i][j]=(f[i][j]+1ll*(1ll*g[max(j-1,0)]*g[max(w-j-1,0)])%clz*f[i-1][j+1])%clz;
		if(j>=2) f[i][j]=(f[i][j]+1ll*(1ll*g[max(j-2,0)]*g[max(w-j,0)])%clz*f[i-1][j-1])%clz;
	}
	printf("%d",f[h][k]);
	return 0;
}

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

void avoid(vector<int> &B , int i){
	for( int j = i ; j < B.size()-1 ; j++ ){
		// cout << "call.j : " << j << endl;
		B[j] = B[j+1];
	}
	B[B.size()-1] = 0;
	// cout << "avoid" << endl;
	// for (int x : B) cout << x;
	// cout << endl;

	return;
}

int main() {
	int N;
	cin >> N;
	vector<int> B(N);
	for(int i = 0 ; i < N ; i++){
		cin >> B[i];
	}
	vector<int> ans(N);
	for(int i = N-1 ; i >= 0 ; i--){
		// cout << "call.i : " << i << endl;
		for(int k = N-1 ; k >= 0 ; k--){
			// cout << "call,k : " << k << endl;
			if(B[k] == k+1){
				ans[i] = k+1;
				avoid(B,k);
				break;
			}
		}
	}
	if(B[0] == 0){
		for(int l = 0 ; l < N ; l++) cout << ans[l] << endl;
	} else{
		cout << -1 << endl;
	}
}

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

using namespace std;


int main(){	
	int K, S;
	int count = 0;
	cin >> K >> S;
	for (int i = 0; i <= K; i++) {
		for (int j = 0; j <= K; j++) {
			if (S - i - j >= 0&&S-i-j<=K) {
				count++;
			}
		}
	}
	cout << count << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ms(a,b) memset(a,b,sizeof(a))
const int MAXN=1e5+10;

int main()
{
	string s1,s2;
	cin>>s1>>s2;
	for(int i=0;i<s1.size();i++){
		if (s1[i]!=s2[s1.size()-i-1]){
			cout<<"NO"<<endl;
			return 0;
		}
	}
	cout<<"YES"<<endl;
	return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  string s;
  cin >> s;
  int n = s.size()-1;
  ll ans = 0;
  rep(i, (1<<n)) {
    bitset<9> b(i);
    ll ten = 1;
    rep(j, n) {
      ans += ten * (s[n-j]-'0');
      if (b.test(j)) {
        ten = 1;
      } else {
        ten *= 10;
      }
    }
    ans += ten * (s[0]-'0');
  }
  cout << ans << "\n";
}

Measured memory_bytes: 256