akhauriyash/Code-Regression huggingface dataset:
local function str2tbl(s)
    local t = {string.byte(s, 1, #s)}
    for i=1, #t do
        t[i] = string.char(t[i])
    end
    return t
end

------
local H, W = io.read("*n", "*n", "*l")
local grid = {}
local distance = {}
for i=1, H do
    grid[i] = str2tbl(io.read("*l"))
    distance[i] = {}
    local grid_i, distance_i = grid[i], distance[i]
    for j=1, W do
        distance_i[j] = grid_i[j] == '#' and 0 or 2001
    end
end
local math_min = math.min
for i=1, H do
    local distance_i = distance[i]
    for j=2, W do
        distance_i[j] = math_min(distance_i[j], distance_i[j-1] + 1)
    end
end
for i=1, H do
    local distance_i = distance[i]
    for j=W-1, 1, -1 do
        distance_i[j] = math_min(distance_i[j], distance_i[j+1] + 1)
    end
end
for i=2, H do
    local distance_i = distance[i]
    local distance_im1 = distance[i-1]
    for j=1, W do
        distance_i[j] = math_min(distance_i[j], distance_im1[j] + 1)
    end
end
for i=H-1, 1, -1 do
    local distance_i = distance[i]
    local distance_ip1 = distance[i+1]
    for j=1, W do
        distance_i[j] = math_min(distance_i[j], distance_ip1[j] + 1)
    end
end
local ans = 0
local math_max = math.max
for i=1, H do
    local distance_i = distance[i]
    for j=1, W do
        ans = math_max(ans, distance_i[j])
    end
end
print(ans)

Measured memory_bytes: 32760
#include <stdio.h>
int main() {
  int a, b, max;
  scanf("%d%d", &a, &b);
  max = a + b;
  if(max<a-b) max = a-b;
  if(max<a*b) max = a*b;
  printf("%d\n", max);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define ii pair<int, int>
#define N 200012
#define vi vector<int>
#define vii vector<ii>
#define vll vector<ll>
#define pb push_back
#define fs first
#define sc second
#define sz(x) ((int)((x).size()))
#define oo 1000000123
#define mod 1000000007

using namespace std;

string s;
int v[N], rb[N], p10[N];
ll f[2500];

int main(){
    cin.tie(NULL);
    ios_base::sync_with_stdio(0);
    cin >> s;
    int n = sz(s);
    p10[0] = 1;
    for(int i = 1; i <= n; ++i){
        p10[i] = (p10[i-1] * 10) % 2019;
    }
    s = "0" + s;
    for(int i = 1; i <= n; ++i){
        v[i] = (int)(s[i] - '0');
    }
    f[0] = 1;
    for(int i = n; i >= 1; --i){
        rb[i] = (rb[i+1] + v[i]*p10[n-i]) % 2019;
        f[rb[i]]++;
    }
    ll ans = 0;
    for(int i = 0; i <= 2019; ++i){
        ans += (f[i] * (f[i] - 1LL)) / 2LL;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 6112
#include<stdio.h>
int main(){
	int a, b, c, d, e, f, g, h, i;
	scanf("%d %d %d", &a, &b, &c);
	if(a > b){
		d = b;
		e = a;
		b = e;
		a = d;
	}
	if(b > c){
		f = b;
		g = c;
		b = g;
		c = f;
	}
	if(a > b){
		h = a;
		i = b;
		a = i;
		b = h;
	}
	printf("%d %d %d\n",a,b,c);
    return 0;
}

Measured memory_bytes: 596
from math import gcd

from math import factorial as f

from math import ceil, floor, sqrt
import math

import bisect
import re
import heapq

from copy import deepcopy
import itertools
from itertools import permutations

from sys import exit

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

yes = "Yes"
no = "No"


def main():
    x = ii()
    if x == 0:
        print(1)
    else:
        print(0)




main()


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

int main(){
    int n;
    cin>>n;

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

    int count=0,count_temp=0;

    for(int i=1; i<n; i++){
        if(h[i-1]>=h[i]){
            count_temp++;
            if(count_temp>count){
                count=count_temp;
            }
        }else{
            count_temp=0;
        }
    }
    
    cout<<count<<endl;
}

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

using namespace std;

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;

  int a[n+2], left[n+2], right[n+2];
  a[0] = 0;
  left[0] = 0;
  right[0] = 0;
  right[n+1] = 0;

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

  for(int i=1; i<=n; ++i){
    left[i] = gcd(left[i-1], a[i]);
  }

  for(int i=n; i>=1; --i){
    right[i] = gcd(right[i+1], a[i]);
  }

  int mm, res = 0;
  for(int i=1; i<=n; ++i){
    if(i==1){
      mm = right[i+1];
    }else if(i==n){
      mm = left[i-1];
    }else{
      mm = gcd(left[i-1], right[i+1]);
    }
    res = max(res, mm);
  }
  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 1408
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T3;
const int INF = 1000000000;

int main(){
	int n;
	cin >> n;
	map<int,int> mp;

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

	for(int i = 1;i <= n;i++)cout << mp[i] << endl;
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 10;
int e[N][N];
int h, w, t, ans;

int main() {
    cin >> h >> w;
    for (int i = 0; i < 10; ++i) {
        for (int j = 0; j < 10; ++j) {
            cin >> e[i][j];
        }
    }
    for (int i = 0; i < 10; ++i) {
        for (int j = 0; j < 10; ++j) {
            for (int k = 0; k < 10; ++k) {
                e[j][k] = min(e[j][k], e[j][i] + e[i][k]);
            }
        }
    }
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin >> t;
            if (t != -1) {
                ans += e[t][1];
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

#define MAX_LEN (3000)
// #define MAX_LEN (12)
#define SIZE_BUF (30)

using namespace std;

int dpss[MAX_LEN + 1][MAX_LEN + 1];

int main() {
  // read inputs
  char ss[MAX_LEN + 1], ts[MAX_LEN + 1], buf[SIZE_BUF];
  scanf("%s", ss);
  fgets(buf, SIZE_BUF, stdin);
  scanf("%s", ts);
//   printf("%s\n", ss);
//   printf("%s\n", ts);

  // get length of each string
  const int N = strlen(ss), M = strlen(ts);
//   printf("N = %d, M = %d\n", N, M);

  // solve dp
  // initialize
  dpss[0][0] = 0;
  for (int i = 0; i < N; i++) {
    dpss[i + 1][0] = 0;
  }
  for (int j = 0; j < M; j++) {
    dpss[0][j + 1] = 0;
  }
  // update
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      if (ss[i] == ts[j]) {
        dpss[i + 1][j + 1] = dpss[i][j] + 1;
      } else {
        dpss[i + 1][j + 1] = max(dpss[i][j + 1], dpss[i + 1][j]);
      }
    }
  }

  // retrieve the LCS
  char cs[MAX_LEN + 1];
  cs[dpss[N][M]] = '\0';
  int i = N - 1, j = M - 1, k = dpss[N][M] - 1;
  while (k >= 0) {
    if (ss[i] == ts[j] && dpss[i + 1][j + 1] == dpss[i][j] + 1) {
      cs[k--] = ss[i];
      i--;
      j--;
    } else if (dpss[i + 1][j + 1] == dpss[i][j + 1]) {
      i--;
    } else if (dpss[i + 1][j + 1] == dpss[i + 1][j]) {
      j--;
    } else {
      printf("something is wrong...\n");
      printf(
          "i = %d, j = %d, dpss[i + 1][j + 1] = %d, dpss[i + 1][j] = %d, "
          "dpss[i][j + 1] = %d, dpss[i][j] = %d\n",
          i, j, dpss[i + 1][j + 1], dpss[i + 1][j], dpss[i][j + 1], dpss[i][j]);
      exit(1);
    }
  }

//   printf("%d\n", dpss[N][M]);
  printf("%s\n", cs);
}

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

using namespace std;

struct Item {
    int A;
    int B;
    int count;
    int time;

    int diff() const {
        return B - A;
    }

    bool operator<(const Item &rhs) const {
        return time > rhs.time;
    }
};

priority_queue<Item> Q;

int geta = 0;

void add(int A, int B, int count, int time) {
    Q.push({A, B, count, time});
}


long long update(int time) {
    long long dec_sum = 0;
    while (Q.size()) {
        auto q = Q.top();
        if (q.time > time) {
            break;
        }
        Q.pop();
        add(q.A, q.B, q.count, time + q.B);
        dec_sum += 1ll * q.B * q.count;
    }

    return dec_sum;
}

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

    map<pair<int, int>, int> counter;
    long long sum = 0;
    int cnt = 0;
    for (int i = 0; i < M; i++) {
        int A, B;
        cin >> A >> B;
        if (B > 1) {
            counter[{A, B}]++;
            sum += A % B;
            cnt++;
        }
    }
    for (auto i : counter) {
        add(i.first.first, i.first.second, i.second, i.first.second - i.first.first - 1);
    }

    for (int i = 0; i < N; i++) {
        sum += cnt;
        sum -= update(i);
        cout << sum << endl;
    }


}


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

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

// code starts
#define MOD 1000000007

int main()
{
  int n,k;cin>>n>>k;
  vector<ll> a(n);
  int i,j;
  rep(i,n)cin>>a[i];
  ll sum=0;
  rep(i,n)sum+=a[i];
  if(sum<k)cout<<0<<endl;
  else
  {
    vector<vector<ll>> dp(n+1,vector<ll>(k+1,0));
    dp[0][k]=1;
    rep(i,n)
    {
      vector<int> sum(k+2,0);
      rep(j,k+1)sum[j+1]=(sum[j]+dp[i][j])%MOD;
      rep(j,k+1)
      {
        int lim=j+1+a[i];
        if(lim>k+1)lim=k+1;
        dp[i+1][j]=sum[lim]-sum[j]+MOD;
        dp[i+1][j]%=MOD;
      }
    }
    cout<<dp[n][0]<<endl;
  }
}


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

int main(){
  string S;
  cin>>S;
  int i=0;
  for(int j=0;j<4;j++){
    if(S.at(j)=='+'){
      i++;
    }else{
      i--;
    }
  }
  cout<<i<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e5 + 5;

int x, n;
int a[N];

int32_t main()
{
	IOS;
	cin >> x >> n;
	for(int i = 1; i <= n; i++)
		cin >> a[i];
	for(int off = 0; ;off++)
	{
		int val = x - off;
		int flag = 1;
		for(int i = 1; i <= n; i++)
			flag &= (a[i] != val);
		if(flag)
		{
			cout << val;
			return 0;
		}
		val = x + off;
		flag = 1;
		for(int i = 1; i <= n; i++)
			flag &= (a[i] != val);
		if(flag)
		{
			cout << val;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3660
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	string S;
	cin >> S;
	int a[26] = { 0 };
	for (int i = 0; i < S.length(); i++) {
		a[S[i] - 97]++;
	}
	int re = 0;
	for (int i = 0; i < 26; i++) {
		if (a[i] == 0) {
			cout << (char)('a' + i) << endl;
			re++;
			break;
		}
	}
	if (re == 0) {
		cout << "None" << endl;
	}
	return 0;
}

Measured memory_bytes: 3716
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// use std::io::{stdout, Write, BufWriter};
use std::cmp::min;

fn main() {
    input! { s: i32, }
    let mut a: Vec<i32> = vec![s];
    for i in 2.. {
        let next_term = f(*a.last().unwrap());
        if a.contains(&next_term) {
            println!("{}", i);
            break;
        } else {
            a.push(next_term)
        }
    }
}

fn f(n: i32) -> i32 {
    if n%2 == 0 {
        n/2
    } else {
        3*n+1
    }
}


Measured memory_bytes: 4352
#include <cstdio>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_in(int c){int n=0;bool m=false;if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;} //&&c<='9'
_in() {return in(gcu());}
_sc(int &n){int c=gcu();return c==EOF?false:(n=in(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
//_sc(string &s){int c;s="";
//	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
template <typename H,typename... T> _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
template <typename T>
_vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
//_vo(string &s){for (char c: s) pcu(c);}
template <typename H,typename... T> _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename T> _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
_vl(){out('\n');}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

int main() {
	vector<int> v(in());
	for (int &x: v)
		x = in();
	auto s = v.begin();
	for (int q = in(); q; q--) {
		int b = in();
		reverse(s + b, s + in());
	}
	out(v);
}


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


def solve(N: int, A: "List[int]"):
    import collections
    count_dict = collections.Counter(A)
    for i in range(N):
        if i+1 in count_dict.keys():
            pass
        else:
            count_dict[i+1] = 0
    for i in range(N):
        print(count_dict[i+1])

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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
    A = [int(next(tokens)) for _ in range(N - 2 + 1)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 50352
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>

#define STARTUP {(cin.tie(0));\
 (ios::sync_with_stdio(false));}

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define MAX(list) std::max(list)
#define MIN(list) std::min(list)
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())
#define CINVEC(vec) const int size = (vec).size(); REP(i,size) cin>>(vec)[i];

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
std::istream& operator>>(std::istream& is, std::pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

using ll = long long;
using namespace std;
ll mod = 1'000'000'007;

const int INF = 1'050'000'000;

int main() {
    STARTUP;

    string S;
    cin >> S;
    set<char> s;
    REP(i, S.length()) {
        if (s.find(S[i]) != s.end()) {
            cout << "no" << endl;
            return 0;
        }
        s.emplace(S[i]);
    }
    cout << "yes" << endl;
    return 0;
}

Measured memory_bytes: 256
n,m = map(int, input().split())
adj = [[] for i in range(n)]
for i in range(m):
    a,b = map(int, input().split())
    a-=1
    b-=1
    adj[a].append(b)
    adj[b].append(a)
for i in adj:
    print(len(i))

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

using namespace std;
#define ll  long long
#define ld  long double

#define endl '\n'
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int MAXN=1e5+5;

int main()
{
int n;
cin>>n;
ll sum=0;
ll arr[n];
map<int,int>m;
for(int i=0;i<n;i++)
{
    cin>>arr[i];
m[arr[i]-1]++;
m[arr[i]]++;
m[arr[i]+1]++;
}
ll mx=0;
ll req=0;
for(auto i=m.begin();i!=m.end();i++)
{
    if(i->second>mx)
    {
        mx=i->second;
        req=i->first;
    }
}
cout<<mx<<endl;


    return 0;
}


Measured memory_bytes: 5504
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

void rec(vector<vector<vector<ll>>> &dp,const vector<ll> &a,int turn, int front, int back, ll n){
    if(front + back >= n){
        dp[front][back][turn] = 0;
        dp[front][back][turn^1] = 0;
        return;
    }

    if(turn == 0){
        ll f;
        if(dp[front+1][back][turn^1] < 0) rec(dp,a,turn^1,front+1,back,n);
        f = dp[front+1][back][0] + a[front] - dp[front+1][back][1];
        ll b;
        if(dp[front][back+1][turn^1] < 0) rec(dp,a,turn^1,front,back+1,n);
        b = dp[front][back+1][0] + a[n-back-1] - dp[front][back+1][1];
        if(f > b){
            dp[front][back][0] = dp[front+1][back][0] + a[front];
            dp[front][back][1] = dp[front+1][back][1];
        }else{
            dp[front][back][0] = dp[front][back+1][0] + a[n-back-1];
            dp[front][back][1] = dp[front][back+1][1];
        }
    }else{
        ll f;
        if(dp[front+1][back][turn^1] < 0) rec(dp,a,turn^1,front+1,back,n);
        f = dp[front+1][back][0] - (dp[front+1][back][1] + a[front]);
        ll b;
        if(dp[front][back+1][turn^1] < 0) rec(dp,a,turn^1,front,back+1,n);
        b = dp[front][back+1][0] - (dp[front][back+1][1] + a[n-back-1]);
        if(f > b){
            dp[front][back][0] = dp[front][back+1][0];
            dp[front][back][1] = (dp[front][back+1][1] + a[n-back-1]);
        }else{
            dp[front][back][0] = dp[front+1][back][0];
            dp[front][back][1] = (dp[front+1][back][1] + a[front]);
        }
    }
    return;
}

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

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

    vector<vector<vector<ll>>> dp(n+1,vector<vector<ll>>(n+1,vector<ll>(2,-1)));

    rec(dp,a,0,0,0,n);

    cout << dp[0][0][0] - dp[0][0][1] << endl;
    
    return 0;
}

Measured memory_bytes: 493440
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1ll << 60;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int W, H, C[100][100];
const int di[3] = {-1, 0, 1}, dj[3] = {-1, 0, 1};
bool visited[100][100];

int Solve(){
  fill((bool*)visited, (bool*)(visited + H), false);
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      cin >> C[i][j];
    }
  }
  
  int nowi = 0, ans = 0;
  queue <Pii> que;
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      if (C[i][j] == 1){
        que.push(make_pair(i, j));
        nowi = i; visited[i][j] = true;
        ans++;
        break;
      }
    }
    if (!que.empty()) break;
  }
  
  while (!que.empty()){
    Pii Q = que.front(); que.pop();
    int I = Q.first, J = Q.second;

    for (int i = 0; i < 3; i++){
      for (int j = 0; j < 3; j++){
        if (0 <= I + di[i] && I + di[i] < H && 0 <= J + dj[j] && J + dj[j] < W){
          if (C[I + di[i]][J + dj[j]] == 1 && visited[I + di[i]][J + dj[j]] == false){
            que.push(make_pair(I + di[i], J + dj[j]));
            visited[I + di[i]][J + dj[j]] = true;
          }
        }
      }
    }

    if (que.empty()){
      for (int i = nowi; i < H; i++){
        for (int j = 0; j < W; j++){
          if (C[i][j] == 1 && visited[i][j] == false){
            que.push(make_pair(i, j)); ans++; nowi = i;
            visited[i][j] = true; break;
          }
        }
        if (!que.empty()) break;
      }
    }
  }
  cout << ans << endl;
  
  return 0;
}

int main(){
  while (cin >> W >> H){
    if (W == 0 && H == 0) return 0;
    Solve();
  }
  
  return 0;
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

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

int main() {
    ll n,k,ans;
    cin >> n >> k;
    if(n < k){
        ans = min(abs(n-k),n);
    }else{
        if(n%k == 0) ans = 0;
        else{
            ans = min(n%k,abs((n%k)-k));
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;
	if(0 <= x-r && x + r <= W && 0 <= y - r && y + r <= H)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

Measured memory_bytes: 1156
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int n, m, q;
int a[50], b[50], c[50], d[50];
int A[10];

int maxScore = -1;
void dfs(int dep, int x) {
	if (dep == n) {
		int i, score = 0;
		rep(i, q) {
			if (A[b[i]] - A[a[i]] == c[i]) {
				score += d[i];
			}
		}
		maxScore = max(maxScore, score);
		return;
	}
	
	for (int i = x; i <= m; i++) {
		A[dep] = i;
		dfs(dep + 1, i);
	}
}

signed main() {
	int i;
	
	cin >> n >> m >> q;
	rep(i, q) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		a[i]--; b[i]--;
	}
	dfs(0, 1);
	cout << maxScore << endl;
	return 0;
}

Measured memory_bytes: 3636
dp_list = [0]

def dp(N, money_list):
    ans = 100000
    if N==0:
        return dp_list[0]
    else:
        for money in money_list:
            if N-money >= 0:
                ans = min(ans, dp_list[N-money]+1)
        dp_list.append(ans)
        
        return dp_list[N]
        
        
def main():
    money_list = [1]
    for i in range(1,7):
        money_list.append(6**i)
    for i in range(1,6):
        money_list.append(9**i)
    money_list.sort(reverse=True)
        
    N = int(input())
    
    for i in range(N+1):
        ans = dp(i, money_list)
        
    print(ans)
    
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 3860
#include <iostream>
using namespace std;
typedef long long ll;
ll n,a[200010],b,s[200010];
int main(void){
    cin>>n;
    for(int i=0;i<n-1;i++){
        cin>>a[i];
        a[i]--;
        s[a[i]]++;
    }
    for(int i=0;i<n;i++){
        cout<<s[i]<<endl;
    }
}


Measured memory_bytes: 6744
#include <iostream>

int main()
{
    int N, Y, y;
    int a[3] = {-1,-1,-1};
    std::cin >> N >> Y;
    bool find_flag = false;
    for(int i = 0; i <= N && find_flag == false; i++)//10000*i
    {
        for(int j = 0; j <= N - i ; j++)//5000*j
        {
            y = Y;
            if(10000*i <= y) y -= 10000*i;
            else break;
            if(5000*j <= y) y -= 5000*j;
            else break;

            int k = y/1000;
            if(k == N - i - j)
            {
                a[0] = i; a[1] = j; a[2] = k;
                find_flag  = true;
                break;
            }
        }
    }
    std::cout << a[0] << " " << a[1] << " " << a[2] << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <list>
#include <algorithm>

using namespace std;

int main(){
  int q, x;
  char com[20];//命令の種類
  //標準ライブラリよりlistを使用
  list<int> v;
  scanf("%d", &q);//命令の個数
  for(int i = 0; i < q; i++){
    scanf("%s", com);//命令の種類
    if(com[0] == 'i'){//insert
      scanf("%d", &x);
      v.push_front(x);
    }else if(com[6] == 'L'){//deleteLast
      v.pop_back();
    }else if(com[6] == 'F'){//deleteFirst
      v.pop_front();
    }else if(com[0] == 'd'){//delete
      scanf("%d", &x);
      for(list<int>::iterator it = v.begin(); it != v.end(); it++){
        if(*it == x){
          v.erase(it);
          break;
        }
      }
    }
  }
  int i = 0;
  for(list<int>::iterator it = v.begin(); it != v.end(); it++){
    if(i++) printf(" ");
    printf("%d", *it);
  }

  printf("\n");

  return 0;
}


Measured memory_bytes: 33960
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
#define PI acos(-1.0)
#define eps 1e-9
#define ll long long
#define ull unsigned long long
#define nl printf("\n")
#define spc printf(" ")
#define sf scanf
#define pf printf
#define INF (ll)1e15
#define mod 1000000007
#define FI freopen("input.txt","r",stdin)
#define FO freopen("output.txt","w",stdout)
#define si(x) scanf("%d",&x)
#define sii(x,y) scanf("%d %d",&x,&y)
#define siii(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sll(x,y) scanf("%lld %lld",&x,&y)
#define slll(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)

///#define isValid(n,m,nx,ny)nx>=0&&nx<n&&ny>=0&&ny<m
///#define triangle_area(a,b,m,n,x,y) (a*(n-y)+m*(y-b)+x*(b-n))/2.0
///int ax[]={1, 1, -1, -1, 2, 2, -2, -2}; //knight moves
///int ay[]={2,-2,  2, -2, 1,-1,  1, -1}; //knight moves
///int dx[]={1,-1,0,0,1,-1,1,-1};//eight direction
///int dy[]={0,0,1,-1,1,-1,-1,1};//eight direction

///using namespace __gnu_pbds;
using namespace std;

///inline double toRad(double deg){return deg*PI/180;}
///inline double toDeg(double rad){return rad*180/PI;}
///typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;

const int S=123456;
int main()
{
    #ifndef ONLINE_JUDGE
    //FI;
    //FO;
    #endif
    //ios_base::sync_with_stdio(0); cin.tie(0);
    int a,b;
    while(sii(a,b)==2)
    {
        if(a>=1 && a<=9 && b>=1 && b<=9)pf("%d\n",a*b);
        else puts("-1");
    }
    return 0;
}







Measured memory_bytes: 256
from collections import Counter
N = int(input())
A = [int(i) for i in input().split()]
C = Counter(A)
t = 2
E = sorted(C.keys())
E.reverse()
ans = 1
for e in E:
    if(C[e] >= 4):
        t -= 1
        ans *= e
    if(t > 0 and C[e] >= 2):
        ans *= e
        t -= 1
    if(t <= 0):
        print(ans)
        break
else:
    print(0)


Measured memory_bytes: 18600
#include <bits/stdc++.h>
#include <iostream>
#include<math.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;
}
int main()
{
    int64_t N;
    cin >> N;
    const long long INF = 1LL << 60;
    // DP テーブル
    long long dp[100010];
    // DP テーブル全体を初期化 (最小化問題なので INF に初期化)
    for (int i = 0; i < 100010; ++i) dp[i] = INF;
    vector<int>vec(N);
    for (int64_t i=0; i<N; i++) {
        cin >> vec.at(i);
    }

    dp[0] = 0;

    for (int i=1; i<N; i++) {
        chmin(dp[i], dp[i-1] + abs(vec[i-1] - vec[i]));
        if (i > 1) {
            chmin(dp[i], dp[i-2] + abs(vec[i-2] - vec[i]));
        }
    }

    cout << dp[N-1] << endl;
    return 0;
}

Measured memory_bytes: 4352
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

N, K = map(int, input().split())
As = list(map(int, input().split()))

if max(As) < K:
    print('IMPOSSIBLE')
else:
    gcdA = As[0]
    for A in As[1:]:
        gcdA = gcd(gcdA, A)

    if K % gcdA == 0:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')


Measured memory_bytes: 14252
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    s_arr = [int(s) for s in _in[0]]
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    cnt = sum(s_arr)
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)


Measured memory_bytes: 38512
#include <bits/stdc++.h>
#include <chrono>
#include <regex>
using namespace std;
#define len(_x) (sizeof((_x)) / sizeof(_x)[0])
#define ll long long
#define fastIO  ios_base::sync_with_stdio(false); cin.tie(0); 
#define Ichar(_x) char _x;scanf("%c",&_x);
#define Iint(_x) int _x;scanf("%d",&_x); 
#define Ill(_x)  ll _x;scanf("%lld",&_x);
#define inc(a,b,x)(x)>=a && (x)<=b	
#define incE(a,b,x)(x)>=a && (x)<=b	
#define fileIO 	freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
//#define DEBUG


ll modo(ll a)
{
	return a % (int)(1e9+7);
}

ll a[5];
int main()
{
	ll ss = 0;
	Ill(n);
	for (int i = 0; i < n; ++i)
	{
		string s;
		std::cin >> s;
		switch (s[0])
		{
		case 'M':a[0]++;break;
		case 'A':a[1]++;break;
		case 'R':a[2]++;break;
		case 'C':a[3]++;break;
		case 'H':a[4]++;break;
		}
	}
		for (ll i = 0; i < 5; ++i)
		{
			for (ll j = i+1; j < 5; ++j)
			{
				for (ll k = j+1; k < 5; ++k)
				{
					ss += a[i] * a[j] * a[k];
				}
			}
		}


	
	std::cout << ss;
}





Measured memory_bytes: 256
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
    public static void main (String[] args) throws java.lang.Exception
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int i=1;
        for (; i<6; i++){
            if (Integer.parseInt(st.nextToken())==0)
                break;
        }
        System.out.println(i);
    }




}



Measured memory_bytes: 32436
#include<stdio.h>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
typedef long long LL;
#define ms(a,b) memset(a,b,sizeof(a))

LL A[305][305];
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);
	int N;
	cin>>N;
	for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            cin>>A[i][j];
        }
	}
	LL ans=0;
	for(int i=0;i<N;i++){
        for(int j=0;j<i+1;j++){
            bool flag=1;
            for(int k=0;k<N;k++){
                if(A[i][j]>A[i][k]+A[k][j]){
                    cout<<-1<<endl;
                    return 0;
                }else if(i!=k&&j!=k&&A[i][j]==A[i][k]+A[k][j]) flag=0;
            }
            if(flag){
                ans+=A[i][j];
            }//else cout<<i<<" "<<j<<endl;
        }
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1024
n = int(input())
w = list(map(int,input().split()))
ans = 10**10
for i in range(n):
    left = 0
    right = 0
    for k in range(n):
        if k <= i:
            left += w[k]
        else:
            right += w[k]
    if abs(left-right) < ans:
        ans = abs(left-right)
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
  vector<int> tot;
  int now = 0;
  for(int j = 1; j <= 999; j++){
    now += j;
    tot.push_back(now);
  }
  int a, b; cin >> a >> b;
  for(int i = 0; i + 1 < tot.size(); i++){
  	if(a < tot[i] && b < tot[i + 1]){
    	if(tot[i] - a == tot[i + 1] - b){
        	cout << tot[i] - a << endl;
          return 0;
        }
    }
  }
  assert(0);
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int A,B,K;
	scanf("%d %d %d",&A,&B,&K);
	for (int i = 0; i < K; ++i)
	{
		if(i%2 == 0){
			if(A%2 == 1){
				A -= 1;
				B += A/2;
				A = A/2; 
			}
			else{
				B += A/2;
				A /= 2;
			}
		}
		if(i%2 == 1){
			if(B%2 == 1){
				B -= 1;
				A += B/2;
				B = B/2;
			}
			else{
				A += B/2;
				B /= 2;
			}
		}
	}
	printf("%d %d",A,B);
	return 0;	
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define int long long
#define INF 1e9+7
using namespace std;
typedef pair<int,int> P;
int h, w;
char ch[50][50];
int a[50][50];
queue<P> que;
int ax[4] = {0, -1 , 0, 1}, ay[4] = {1, 0, -1, 0};
int bfs() {
    rep(i, h) {
        rep(j, w) {
            a[i][j] = INF;
        }
    }
    que.push(P(0, 0));
    a[0][0] = 0;
    while (que.size()) {
        P p = que.front();que.pop();
        rep(i, 4) {
            int px = p.first + ax[i], py = p.second + ay[i];
            if (px >= 0 && py >= 0 && px < h && py < w && a[px][py] == INF && ch[px][py] != '#') {
                que.push(P(px, py));
                a[px][py] = a[p.first][p.second] + 1;
            }
        }
    }
    return a[h - 1][w - 1];
}
signed main() {
    int c = 0;
    cin >> h >> w;
    rep(i, h) {
        rep(j, w) {
            cin >> ch[i][j];
            if (ch[i][j] == '#') {
                c++;
            }
        }
    }
    if (h * w - 1 - bfs() - c < 0) {
        cout << -1 << endl;
    } else {
        cout << h * w - 1 - bfs() - c << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define ln '\n'
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
typedef long long ll;
typedef unsigned long long ull; 
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A[i];

    map<int, ll> dic;
    rep(i,N) dic[A[i]]++;
    ll MAX = 0;
    for (auto i : dic) {
        MAX += i.second*(i.second-1)/2;
    }
    vector<ll> ans(N);
    rep(i,N) {
        ans[i] = MAX - dic[A[i]]+1;
    }

    for (auto i : ans) cout << i << ln;
}


Measured memory_bytes: 11904
// Author: πα

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

#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define long int64_t

const int N = 3005;
double dp[N][N], p[N];

int main()
{
    FastIO;
    int n, i, j;
    double ans = 0;
    cin >> n;
    for(i = 1; i <= n; ++i)
        cin >> p[i];
    dp[0][0] = 1;
    for(i = 1; i <= n; ++i)
        for(j = 0; j <= n; ++j)
            dp[i][j] = dp[i-1][j]*(1-p[i]) + dp[i-1][j-1]*p[i];
    for(i = n/2+1; i <= n; ++i)
        ans += dp[n][i];
    cout << fixed << setprecision(12) << ans;
    return 0;
}


Measured memory_bytes: 70656
N = int(input())
S = input()

ans = 0
for dl in list(range(1, N))[::-1]:
    if dl < ans: break
    cnt = 0
    ans_tmp = 0
    for l1 in range(N - dl):
        l2 = l1 + dl
        if S[l1] == S[l2]:
            # print("##", l1, l2)
            cnt += 1
        else:
            ans_tmp = max(ans_tmp, cnt)
            cnt = 0
    else:
        ans_tmp = max(ans_tmp, cnt)
    #
    # print("#", dl, ans_tmp)
    ans = max(ans, min(dl, ans_tmp))

print(ans)

Measured memory_bytes: 41836
unittest
{
	assert( [ "4 2", "1 3", "2 4" ].parse.expand.solve == 2 );
	assert( [ "10 3", "3 6", "5 7", "6 9" ].parse.expand.solve == 1 );
	assert( [ "100000 1", "1 100000" ].parse.expand.solve == 100000 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nm = input.front.split.to!( long[] );
	auto lrs = new long[][]( nm[ 1 ], 2 );
	foreach( ref lr; lrs )
	{
		input.popFront;
		lr = input.front.split.to!( long[] );
	}
	return tuple( nm[ 0 ], lrs );
}

auto solve( long n, long[][] lrs )
{
	// IDカードごとに通過できるゲートの数を集計
	auto gs = new long[]( n + 1 );
	foreach( lr; lrs )
	{
		gs[ lr[ 0 ] - 1 ]++;
		gs[ lr[ 1 ]     ]--;
	}
	gs.length--;
	
	// 全ゲートを通れるIDカードを数える
	auto ans = 0L;
	auto c = 0L;
	foreach( g; gs )
	{
		c += g;
		ans += ( c == lrs.length );
	}
	return ans;
}


Measured memory_bytes: 22524
from collections import Counter
s = input()
ls = len(s)

def f(s,c):
    td = s
    cnt = 0
    while(td != c*len(td)):
        t = td
        td = ""
        cnt += 1
        for i in range(len(t)-1):
            if (t[i] == c)or(t[i+1] == c):
                td += c
            else:
                td += t[i]
    return cnt

l = []
for i in range(26):
    l.append(f(s,chr(ord("a")+i)))

print(min(l))

    


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

using namespace std;

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

  int n;
  cin >> n;
  vector<string> s(n);
  vector<int> cnt('z'-'a'+1, INT_MAX);
  for (auto& e : s) {
    cin >> e;
    sort(e.begin(), e.end());
    for (int i = 0; i < cnt.size(); ++i) {
      cnt[i] = min(cnt[i], (int)count(e.begin(), e.end(), 'a' + i));
    }
  }
  string ans;
  for (size_t i = 0; i < cnt.size(); ++i) {
    for (int j = 0; j < cnt[i]; ++j) {
      ans.push_back('a' + i);
    }
  }
  cout << ans << "\n";
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include  <iostream>
#include  <algorithm>
#include  <climits>
#include  <vector>
#include  <string>
#include  <cstring>
#include  <stack>
#include  <queue>
#include  <cmath>
#include  <iomanip>
#include  <set>
#include  <map>
#include  <new>

using namespace std;
#define rep(i,n)  for(int i = 0; i < n; i++)
#define lrep(i,n,m)  for(int i = n; i < m; i++)

using ll = long long;
using Graph = vector<vector<int> >;

const int Mod = static_cast<int>(1e9 + 7);
const int INF = INT_MAX;

string s;
int ans = 0;

void dfs(int i, string c, bool t)
{
	if (i == s.size() || !t) {
		bool f = true;
		rep(j, c.size()) { 
			if (c[j] != 'A' && c[j] != 'C' && c[j] != 'G' && c[j] != 'T') {
				f = false;
			}
		}
		if (f)  ans = max(ans, int(c.size()));
		return;
	}
	dfs(i + 1, c + s[i], true);
	dfs(i + 1, c, false);
}

int main()
{
	cin >> s;
	rep(i, s.size())  dfs(i, "", true);
	cout << ans << endl;
}


Measured memory_bytes: 256
import Control.Monad
import Data.List

calc k ds = head $ dropWhile (\(_, s) -> s<k) ps
  where 
    ps = scanl (\(_, s) (a, b) -> (a, s+b)) (0, 0) $ sort ds


main = map read . words <$> getLine >>= \[n, k] -> replicateM n ((\[a, b] -> (a, b)) . map read . words <$> getLine) >>= print . fst . calc k

Measured memory_bytes: 95612
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: u32,
        a: u32,
        b: u32,
    };
    let mut ans = 0;
    for i in 1..n+1{
        let tmp: u32 = i.to_string().chars().map(|c| c.to_digit(10).unwrap()).sum();
        ans += if tmp <= b && tmp >= a {i}else{0};
    }
    println!("{}" ,ans);
}


Measured memory_bytes: 4352
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  for(int i = 0; i < s.size(); i += 2) cout << s[i];
  cout << endl;
  return 0;
}
//templete by private_yusuke


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

using namespace std;
using ll=long long;
using ull=unsigned long long;

typedef pair<int,int>Pi;
typedef pair<long long,long long>P;
typedef pair<long long,P>PP;
typedef pair<P,P>PPP;

const long long MOD=1e9+7;
const long long INF=5e18;
const int di[4]={1,0,-1,0};
const int dj[4]={0,1,0,-1};

#define fr first
#define sc second
#define pb push_back
#define eb emplace_back
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()


int h,w,n,ni=1,nj=1;
int pos[200010];
ll ans=INF;
map<P,bool>mp;

void find(){
	queue<P>q;
	if(!mp[P(2,1)])q.push(P(2,1));
	while(!q.empty()){
		P p=q.front();
		q.pop();
		if(p.fr+1==h+1)continue;
		if(p.sc+1==w+1)continue;
		if(pos[p.sc+1])continue;
		if(!mp[P(p.fr,p.sc+1)]){
			pos[p.sc+1]=p.fr;
			if(!mp[P(p.fr+1,p.sc+1)])q.push(P(p.fr+1,p.sc+1));
		}
		else{
			if(!mp[P(p.fr+1,p.sc)])q.push(P(p.fr+1,p.sc));
		}
	}
	return;
}

P p[200010];

void input(){
	cin>>h>>w>>n;
	for(int i=0;i<n;i++){
		cin>>p[i].fr>>p[i].sc;
		mp[P(p[i].fr,p[i].sc)]=true;
	}
	return;
}

void solve(){
	pos[1]=1;
	find();
	for(int i=0;i<n;i++){
		if(!pos[p[i].sc])continue;
		if(pos[p[i].sc]<p[i].fr)ans=min(ans,p[i].fr-1);
	}
	if(ans==INF)ans=h;
	cout<<ans<<endl;
	return;
}

int main(){
	input();
	solve();
	return 0;
}

Measured memory_bytes: 37120
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int main() {
    int n, m;
    cin >> n >> m;
    vector< vector< int > > edg(n, vector<int>());
    vector<int> deg(n, 0), tp(n, 0), ans(n, 0);
    for(int i=0;i<n-1+m;i++){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        edg[a].push_back(b);
        deg[b]++;
    }
    
    queue<int> q;
    for(int i=0;i<n;i++) if(deg[i] == 0) q.push(i);
    int cnt = 0;
    tp.assign(n, 0);
    while(!q.empty()){
        int v = q.front();
        q.pop();
        tp[cnt++] = v;
        for(int x : edg[v]){
            if(--deg[x] == 0) q.push(x);
        }
    }
    
    for(int i=0;i<n;i++){
        int v = tp[i];
        for(int x : edg[v]){
            ans[x] = v+1;
        }
    }
    
    for(int i=0;i<n;i++){
        cout << ans[i] << endl;
    }
	return 0;
}

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

int main () {
  int N;
  cin >> N;
  vector<long long int> L(N+1);
  L.at(0) = 2, L.at(1) = 1;
  for (int i = 2; i <= N; i++) {
    L.at(i) = L.at(i-1)+L.at(i-2);
  }
  cout << L.at(N) << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
const int maxn=100010;
int n,m;
int to[maxn*2],Next[maxn*2],Begin[maxn],e;
void read(int& x){
	x=0;
	char c=getchar();
	while(c<'0' || c>'9') c=getchar();
	while(c>='0' && c<='9'){
		x=x*10+c-'0';
		c=getchar();
	}
}
void add(int x,int y){
	to[++e]=y;Next[e]=Begin[x];Begin[x]=e;
}
int cnt[5];
int c[maxn];
bool dfs(int x,int now){
	if(c[x] && c[x]!=now) return false;
	if(c[x] && c[x]==now) return true;
	c[x]=now;
	for(int i=Begin[x];i;i=Next[i]){
		int v=to[i];
		if(c[v]==now) return false;
		if(!dfs(v,now^1)) return false;
	}
	return true;
}
int main(){
	read(n);read(m);
	for(int i=1;i<=m;i++){
		int u,v;
		read(u);read(v);
		add(u,v);add(v,u);
	}
	if(dfs(1,2)){
		for(int i=1;i<=n;i++) cnt[c[i]]++;
		printf("%lld\n",1ll*cnt[2]*cnt[3]-m);
	}else{
		printf("%lld\n",(1ll*n*(n-1)>>1)-m);
	}
	return 0;
}

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

#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 INF 2e9
#define INF_LL 1LL<<60
#define ll long long
#define MOD 1e9+7

#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; 

/* dp[i][j]: (i, j)での経路) */ 
ll dp[1000][1000];
int h, w;
int dx[] = {-1, 0};
int dy[] = {0, -1};

bool inside(int x, int y) {
    return 0<= x && 0 <= y;
}

int main(){
    cin >> h >> w;
    char a[h][w];
    REP(i, h) REP(j, w) cin >> a[i][j];
    dp[0][0] = 1;

    REPN(i, 0, h) REPN(j, 0, w) {
        REP (k, 2) {
            int x = i + dx[k];
            int y = j + dy[k];
            if(!inside(x, y)) continue;
            if(a[x][y] == '#') continue;
            dp[i][j] += dp[x][y];
            dp[i][j] %= 1000000007;
        }
    }

    cout << dp[h-1][w-1] << endl;

    return 0;
}

Measured memory_bytes: 9088