akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    ll H, W;
    cin >> H >> W;

    VS s(H);
    rep(h, 0, H){
        cin >> s[h]; 
    }

    ll black = 0;
    rep(h, 0, H){
        rep(w, 0, W){
            if(s[h][w] == '#') black++;
        }
    }

    queue<PL> que;
    que.push({0, 0});
    vector<VL> dist(H, VL(W, -1));
    dist[0][0] = 0;
    bool f = false;
    while(!que.empty()){
        auto t = que.front();
        que.pop();
        rep(i, 0, 4){
            ll nh = d1[i] + t.first;
            ll nw = d2[i] + t.second;
            if(nh < 0 || nw < 0 || nh >= H || nw >= W) continue;
            if(dist[nh][nw] != -1) continue;
            if(s[nh][nw] == '#') continue;
            dist[nh][nw] = dist[t.first][t.second] + 1;
            que.push({nh, nw});
            if(nh == H-1 && nw == W-1){
                f = true;
                break;
            }
        }
        if(f) break;
    }
    if(!f) cout << -1 << endl;
    else cout << (H*W-2) -black - (dist[H-1][W-1] - 1) << endl;
    return 0;
}

Measured memory_bytes: 256
import sys

word=input()

for char in [chr(ord('a') + i) for i in range(26)]:
    left=-10**6
    for right,s in enumerate(word):
        if s == char:
            if 1 <= right - left <=2:
                print(left+1,right+1)
                sys.exit()
            else:
                left = right
else:
    print(-1,-1)

Measured memory_bytes: 41324
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

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

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

string solve1(int n, vector<int> x, vector<int> y) {
    int m = x.size();
    vector<bitset<50009>> a(n);
    rep(i, n) a[i].set(i);
    rep(i, m) a[x[i]] = a[y[i]] = a[x[i]] | a[y[i]];
    rep(i, n) {
        if(int(a[i].count()) != n) continue;
        bitset<50009> b;
        b.set(i);
        string ret(m, 'v');
        while(m--) {
            if(b[x[m]]) {
                b.set(y[m]);
                ret[m] = '^';
            } else
                b[x[m]] = b[y[m]];
        }
        return ret;
    }
    return "-1";
}

string solve2(int n, vector<int> x, vector<int> y) {
    if(n == 2) return "-1";
    int m = x.size();
    string ret(m, '^');
    vector<int> a(n), num(n);
    rep(i, n) {
        a[i] = i;
        num[i] = 1;
    }
    for(int i = m - 1; i >= 0; i--) {
        if(num[a[x[i]]] > 1) {
            num[a[x[i]]]--;
            num[a[y[i]]]++;
            a[x[i]] = a[y[i]];
            ret[i] = 'v';
        } else {
            num[a[x[i]]]++;
            num[a[y[i]]]--;
            a[y[i]] = a[x[i]];
        }
    }
    return ret;
}

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

    int n, m, t;
    cin >> n >> m >> t;

    vector<int> x(m), y(m);
    rep(i, m) {
        cin >> x[i] >> y[i];
        x[i]--;
        y[i]--;
    }
    if(t == 1) cout << solve1(n, x, y) << endl;
    if(t == 2) cout << solve2(n, x, y) << endl;

    return 0;
}

Measured memory_bytes: 307456
n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))
Ans = []
for i in range(n):
    ans = t-h[i]*0.006
    Ans.append(abs(ans-a))
abc = 10**100000
for j in range(n):
    abc = min(abc, Ans[j])
print(Ans.index(abc)+1)


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

int main(void){
    int n, r;
    cin>>n>>r;
    if(n>=10) cout<<r<<endl;
    else cout<<r+100*(10-n)<<endl;
    return 0;
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    string c;
    cin >> c;
    if (c == "a" || c == "e" || c == "i" || c == "u" || c == "o") {
        cout << "vowel" << endl;
    } else {
        cout << "consonant" << endl;
    }
    return 0;
}

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

int main()
{
  int n;
  cin>>n;
  long long int p=0;
  for(int i=1;i<=n;i++)
  {
	for(int j=1;j<=n;j++)
    {
		for(int k=1;k<=n;k++)
          p+=__gcd(__gcd(i,j),k);
    }
  }
  cout<<p;
}

Measured memory_bytes: 3620
#include <sstream>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iterator>
#include <numeric>
#include <functional>
#include <climits>



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

class card{
public:
  char mark;
  int num;
  card(){}
  card(char m, int n): mark(m), num(n){}
  bool operator<(const card& c){
    return num < c.num;
  }
  bool operator<=(const card& c){
    return (*this < c) || (num == c.num);
  }
  void print(){
    cout << mark << " " << num << endl;
  }
};

const card CARD_MAX('Z', INT_MAX);


void swap(int& x, int& y){
  if(&x == &y) return;
  x = x^y;
  y = x^y;
  x = x^y;
}

void merge(vector<card>& v, int l, int m, int r){
  int n1 = m-l;
  int n2 = r-m;
  vector<card> v1(n1+1);
  vector<card> v2(n2+1);
  for (size_t i = 0; i < n1; i++) {
    v1[i] = v[l+i];
  }
  for (size_t i = 0; i < n2; i++) {
    v2[i] = v[m+i];    
  }
  v1.back() = CARD_MAX;
  v2.back() = CARD_MAX;
  int i = 0, j = 0;
  for (size_t k = l; k < r; k++) {
    if(v1[i] <= v2[j]){
      v[k] = v1[i++];
    } else{
      v[k] = v2[j++];
    }
  }
}

void mergeSort(vector<card>& v, int l, int r){
  if(l+1 < r){
    int m = (l + r) / 2;
    mergeSort(v, l, m);
    mergeSort(v, m, r);
    merge(v, l, m, r);
  }
}



int partition(vector<card>& a, int p, int r){
  card x = a[r];
  int i = p - 1;
  for (int j = p; j < r; j++) {
    if(a[j] <= x){
      i++;
      swap(a[i], a[j]);
    }
  }
  i++;
  swap(a[i], a[r]);
  return i;
}


void quick(vector<card>& v, int p, int r){
  if(p < r){
    int q = partition(v, p, r);
    quick(v, p, q-1);
    quick(v, q+1, r);
  }
}

int main(int argc, char *argv[]){
  size_t n;
  cin >> n;
  vector<card> v(n);
  char c[100];
  int buf;
  for (size_t i = 0; i < n; i++ ){
    scanf("%s%d", c, &buf);
    v[i].mark = c[0];
    v[i].num = buf;
  }
  vector<card> q = v;
  vector<card> m = v;
  quick(q, 0, n-1);
  mergeSort(m, 0, n);
  bool stable = true;
  for (size_t i = 0; i < n; i++) {
    if(q[i].mark != m[i].mark){
      stable = false;
      break;
    }
  }
  if(stable){
    cout << "Stable" << endl;
  } else{
    cout << "Not stable" << endl;
  }
  
  for (size_t i = 0; i < n; i++) {
    q[i].print();
  }
  

  return 0;
}

Measured memory_bytes: 4196
package main

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

func main() {
	sc = initScanner(os.Stdin)
	n, k, q := scanInt(sc), scanInt(sc), scanInt(sc)
	a := scanIntSlice(sc, q)

	resolve(n, k, q, a)
}

func resolve(n, k, q int, a []int) {
	scores := make([]int, n)
	for _, v := range a {
		scores[v-1]++
	}

	for i := 0; i < n; i++ {
		if 0 < k-(q-scores[i]) {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

// --------------- BASE DEFINITIONS ---------------

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords)
	return sc
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func scanIntSlice(sc *bufio.Scanner, n int) []int {
	is := make([]int, n)
	for i := 0; i < n; i++ {
		is[i] = scanInt(sc)
	}

	return is
}

func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 4096
def main():
    N, K = map(int, input().split())
    C = [0] * 100001
    for _ in range(N):
        a, b = map(int, input().split())
        C[a] += b
    for i, c in enumerate(C):
        K -= c
        if 0 >= K:
            print(i)
            break


main()


Measured memory_bytes: 5744
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    string s;
    cin >> s;
    int n = s.size();

    constexpr int M = 2019, I = 202;
    static_assert(10 * I % M == 1);

    int p[M] = {};

    ll r = 0;
    int t = 0, d = 1;

    //for (int i = 0; i < n - 1; i++) {
    //    d = d * 10 % M;
    //}

    for (int i = 0; i < n; i++) {
        int c = s[i] - '0';

        p[t * 10 * d % M]++;
        t = (t * 10 + c) % M;
        r += p[t * d % M];
        d = d * I % M;
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 3788
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define f first
#define s second
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mem(arr,v) memset(arr,v,sizeof(arr))
/*bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
} */
int main()
{
     ll t,a,m,b,cnt=0;
     cin>>a>>m>>b;
     for(int i=1;i<=m;i++)
     {
         if((a*i)%m==b)
         {
             cnt=10;
             break;
         }
     }
     if(cnt==10) cout<<"YES"<<endl;
     else cout<<"NO"<<endl;
}




Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST

class UnionFind
{
private:
    std::vector<ll> data;
    std::vector<ll> tree_size;

public:
    UnionFind(ll n)
    {
        data = std::vector<ll>(n);
        tree_size = std::vector<ll>(n, 1);
        for (ll i = 0; i < n; ++i)
        {
            data[i] = i;
        }
    }

    ll root(ll a)
    {
        if (data[a] == a)
            return a;
        else
            return data[a] = root(data[a]);
    }

    ll unite(ll a, ll b)
    {
        ll root_a = root(a);
        ll root_b = root(b);
        if (root_a == root_b)
            return root_a;
        else
        {
            tree_size[root_b] += tree_size[root_a];
            tree_size[root_a] = 0;
            data[root_a] = root_b;
            return root_b;
        }
    }

    ll get_tree_size(ll a)
    {
        return tree_size[root(a)];
    }
};


int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long N, M, K;
    cin >> N >> M >> K;
    UnionFind uf((ll)N);
    //vector<pair<long, long>> AB(N);
    //vector<pair<long, long>> CD(N);
    long A, B, C, D;
    vector<vector<long>> relation(N);
    vector<vector<long>> bad_relation(N);
    for(size_t i=0;i<M; i++)
    {
        cin >> A >> B;
        //AB[i] = make_pair(A, B);
        uf.unite(A-1,B-1);
        relation[A-1].push_back(B-1);
        relation[B-1].push_back(A-1);
    }
    for(size_t i=0;i<K; i++)
    {
        cin >> C >> D;
        //CD[i] = make_pair(C, D);
        bad_relation[C-1].push_back(D-1);
        bad_relation[D-1].push_back(C-1);
    }

    for(size_t i=0;i<N; i++)
    {
        ll bad_count=0;
        //cerr << uf.root(i) << endl;
        for (auto b = bad_relation[i].begin(); b != bad_relation[i].end(); b++)
        {
            //cerr << i << ":" << uf.root(i) << "::" << *b << ":" << uf.root(*b) << endl;
            if (uf.root(i) == uf.root(*b))
                bad_count++;
        }
        cout << uf.get_tree_size(i) - 1 - relation[i].size() - bad_count << " ";
    }
    cout << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 14836
#include <iostream>

using namespace std;

int main()
{
   int S, h, m, s;
   cin >> S;
   h = S / 3600;
   m = (S - h*3600)/60;
   s = S - h*3600 - m*60;
   cout << h << ":" << m << ":" << s <<endl; 
   
   return 0;
}


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

int main(){
    vector <int> num;
    int max = 0, N, i, j, tmp, f = 0, ans;

    cin >> N;
    for(i = 0; i < N; i++){
        cin >> tmp;
        max += tmp;
        num.push_back(tmp);
    }
    max -= N;
    cout << max << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main()
{
	int n;
	int taro = 0;
	int hanako = 0;
	char str_t[101];
	char str_h[101];
	int i;
	int judge;
	scanf("%d", &n);	/*??????????????°*/
	for(i = 0;i < n; i++){
	scanf("%s %s", str_t, str_h);	/*??????????????????*/
	judge = strcmp(str_t, str_h);	/*????????????*/
	if(judge > 0) taro+=3;
	else if(judge < 0) hanako += 3;
	else {
		taro++;
		hanako++;
	}
	}
	printf("%d %d\n", taro, hanako);

	return 0;
}

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

#define INF_LL (int64)1e18
//#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

class UnionFind{
private:
    ::std::vector<int_fast32_t> par, edge;
    size_t n;

public:
    UnionFind(){}
    UnionFind(size_t n):n(n){
        par.resize(n, -1);
        edge.resize(n, 0);
    }

    uint_fast32_t find(uint_fast32_t x){
        return par[x] < 0 ? x : par[x] = find(par[x]);
    }

    size_t size(uint_fast32_t x){
        return -par[find(x)];
    }

    bool unite(uint_fast32_t x, uint_fast32_t y){
        x = find(x);
        y = find(y);
        edge[x] += 1;
        if(x == y) return false;
        if(size(x) < size(y)) std::swap(x, y);
        par[x] += par[y];
        edge[x] += edge[y];
        par[y] = x;
        return true;
    }

    bool same(uint_fast32_t x, uint_fast32_t y){
        return find(x) == find(y);
    }

    size_t esize(uint_fast32_t x) {
        return edge[find(x)];
    }
};

int main(void) {
    int64 N;
    cin >> N;
    vector<int64> W(N);
    REP(i, N) cin >> W[i];

    int64 lsum = 0, rsum = accumulate(all(W), 0), res = INF_LL;
    REP(i, N) {
        chmin(res, abs(lsum-rsum));
        lsum += W[i];
        rsum -= W[i];
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
const int N = 3e5 + 5;
int n, q[N], a[N], top, sta[N], mn[N];
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') {x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar();}
	return x * f;
}
int main()
{
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	n = read();
	for(int i = 1; i <= n; i ++) q[i] = read();
	q[0] = 0; q[n + 1] = n + 1;
	for(int i = 1; i <= n; i ++)
	{
		if(q[i - 1] != i - 1 && q[i] != i && q[i + 1] != i + 1) {puts("No"); return 0;}
		a[i] = (q[i] == i);
	}
	for(int i = 1, j; i <= n; i = j + 1)
	{
		j = i;
		while(j < n && a[j] != a[j + 1]) j ++;
		top = 0;
		for(int k = i; k <= j; k ++)
		{
			if(q[k] < i || q[k] > j) {puts("No"); return 0;}
			if(!a[k]) sta[++ top] = q[k];
		}
		mn[top] = sta[top];
		for(int k = top - 1; k >= 1; k --) mn[k] = min(mn[k + 1], sta[k]);
		int mx = sta[1];
		for(int k = 2; k < top; k ++)
		{
			mx = max(mx, sta[k]);
			if(mn[k] < sta[k] && sta[k] < mx) {puts("No"); return 0;}
		}
	}
	puts("Yes");
	fclose(stdin);
	fclose(stdout);
	return 0;
}


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

int main() {
    int n, k;
    cin >> n >> k;
    vector<pair<ll, ll>> sushi(n);
    rep(i, n) cin >> sushi[i].second >> sushi[i].first;
    sort(sushi.begin(), sushi.end());

    vector<bool> type_set(n + 1, false);
    stack<int> to_del;
    ll sum = 0, type = 0;
    for (int i = n - 1; i >= n - k; i--) {
        sum += sushi[i].first;
        if (type_set[sushi[i].second]) {  // second (or more) times to see this type
            to_del.push(sushi[i].first);
        } else {  // first time to see this type
            type_set[sushi[i].second] = true;
            type++;
        }
    }
    ll ans = sum + type * type;
    for (int i = n - k - 1; i >= 0; i--) {
        if (type_set[sushi[i].second]) continue;
        // i th sushi is the type never seen
        if (to_del.empty()) continue;
        // and there's some sushi that shares the same type
        sum -= to_del.top();
        to_del.pop();
        sum += sushi[i].first;
        type_set[sushi[i].second] = true;
        type++;
        ans = max(ans, sum + type * type);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1920
s = input()
alp = 'abcdefghijklmnopqrstuvwxyz'
if len(s) < 26:
    for a in alp:
        if a not in s:
            print(s + a)
            exit()
else:
    for i in range(25, 0, -1):
        if s[i - 1] < s[i]:
            c = 'ω'
            for j in range(i, 26):
                if s[i - 1] < s[j]:
                    c = min(c, s[j])
            print(s[:i-1] + c)
            exit()

    print(-1)


Measured memory_bytes: 8960
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	a, w := make([]int, n, n), make([]int, n, n)
	for i := 0; i < n; i++ {
		a[i], w[i] = 0, 0
	}

	sc.Scan()
	m, _ := strconv.Atoi(sc.Text())

	ac, wa := 0, 0
	for i := 0; i < m; i++ {
		sc.Scan()
		p, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		s := sc.Text()

		if a[p-1] == 1 {
			continue
		}

		if s == "AC" {
			ac++
			a[p-1] = 1
			wa += w[p-1]
		} else {
			w[p-1]++
		}
	}

	fmt.Println(ac, wa)
}


Measured memory_bytes: 2816
#include <iostream>
using namespace std;
int main() {
    long long int X, Y; cin >> X >> Y;
    if (X == Y) {
        printf("%d\n", -1);
        return 0;
    }
    if (X < Y) {
        printf("%d\n", X);
        return 0;
    }
    if (X % Y == 0) {
        printf("%d\n", -1);
        return 0;
    }
    for (long long int i = X; i <= 10e18; i += X) {
        if (i % Y != 0) {
            printf("%lld\n", i);
            return 0;
        }
    }
    printf("%d\n", -1);
}

Measured memory_bytes: 3764
#include"stdio.h"

int main()
{
	int H, W;
	int i,j;
	char a[102][102];

	scanf("%d %d", &H, &W);
	for (i = 0; i < H; i++) {
		scanf("%s", a[i]);
	}

	for (j = 0; j < W + 2; j++) { printf("#"); }
	printf("\n");
	for (i = 0; i < H; i++) {
		printf("#");
		printf("%s", a[i]);
		printf("#\n");

	}
	for (j = 0; j < W + 2; j++) { printf("#"); }
}


Measured memory_bytes: 128
#include<stdio.h>

int main() {
	int data[101][101];

	int tr, tc;

	scanf("%d %d", &tr, &tc);

	int i, j;
	for (i = 0; i < tr; i++) {
		data[i][tc] = 0;
		for (j = 0; j < tc; j++) {
			fflush(stdin);
			scanf("%d", &data[i][j]);

			data[i][tc] += data[i][j];

		}
	}
	// i\j

	for (j = 0; j <= tc; j++) {
		data[tr][j] = 0;
		for (i = 0; i < tr; i++) {
			data[tr][j] += data[i][j];
		}
	}
	

	for (i = 0; i <= tr; i++) {
		for (j = 0; j < tc; j++) {
			printf("%d ", data[i][j]);
		}
		printf("%d\n", data[i][j]);
	}

	return 0;
}

Measured memory_bytes: 2748
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    string s;
    string t;
    int answer=0;
    cin >>  s >> t;
    REP(i,s.length()){
        if(s[i]!=t[i])answer++;
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 3916
#include <iostream>
#include <cstdio>
using namespace std;
const int maxn = 105;
int flag[maxn][maxn];
char maze[maxn][maxn];
int row[maxn],colum[maxn];

int main()
{
    int h,w;
    int i,j;

    scanf("%d%d",&h,&w);
    for(i = 0;i < h;i++)
    {
        getchar();
        for(j = 0;j < w;j++)
        {
            scanf("%c",&maze[i][j]);
        }
    }
    for(i = 0;i < h;i++)
    {
        int f1 = 0;
        for(j = 0;j < w;j++)
        {
            if(maze[i][j] == '#')
            {
                f1 = 1;
                break;
            }
        }
        if(f1 == 0)
        {
            row[i] = 1;
            for(j = 0;j < w;j++)
                flag[i][j] = 1;//not print
        }
    }
    for(j = 0;j < w;j++)
    {
        int f2 = 0;
        for(i = 0;i < h;i++)
        {
            if(maze[i][j] == '#')
            {
                f2 = 1;
                break;
            }
        }
        if(!f2)
        {
            colum[j] = 1;
            for(i = 0;i < h;i++)
                flag[i][j] = 1;
        }
    }
    for(i = 0;i < h;i++)
    {
        for(j = 0;j < w;j++)
        {
            if(!flag[i][j]) printf("%c",maze[i][j]);
        }
        if(!row[i]) printf("\n");
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int W,H,x,y,r;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    if(x - r >= 0 && x + r <= W && y - r >= 0 && y + r <= H){
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
//const ll mod = 1000000007;
int M;
vector<int> X, Y;
int sum[4001][4001][2];
//int field[4001][4001];
void solve() {
    X.resize(M + 1);
    Y.resize(M + 1);
    for(int i = 0; i < M; i++) {
        cin >> X[i] >> Y[i];
        X[i] += 2000;
        Y[i] += 2000;
    }
    X[M] = X[0];
    Y[M] = Y[0];
    for(int i = 0; i <= 4000; i++) {
        for(int j = 0; j <= 4000; j++) {
            for(int k = 0; k <= 1; k++) {
                sum[i][j][k] = 0;
            }
        }
    }
    for(int i = 0; i < M; i++) {
        for(int y = min(Y[i], Y[i+1]); y < max(Y[i], Y[i+1]); y++) {
            int dy1 = abs(Y[i] - y);
            int dy2 = abs(Y[i+1] - y);
            double x1 = (double)(dy1 * X[i+1] + dy2 * X[i]) / (dy1 + dy2);
            dy1 = abs(Y[i] - y-1);
            dy2 = abs(Y[i+1] - y-1);
            double x2 = (double)(dy1 * X[i+1] + dy2 * X[i]) / (dy1 + dy2);
            if(x1 > x2) swap(x1, x2);
            int X1 = floor(x1 + 1e-9);
            int X2 = ceil(x2 - 1e-9);
            //cerr << i << " " << y << " " << X1 << " " << X2 << endl;
            sum[y][X1][0]++;
            sum[y][X1][1]++;
            sum[y][X2][1]--;
        }
    }
    for(int y = 0; y <= 4000; y++) {
        for(int x = 1; x <= 4000; x++) {
            for(int j = 0; j <= 1; j++) {
                sum[y][x][j] += sum[y][x-1][j];
            }
        }
    }
    /*
    for(int i = 0; i <= 1; i++) {
        for(int y = 2020; y >= 1980; y--) {
            for(int x = 1980; x <= 2020; x++) {
                cerr << sum[y][x][i] << " ";
            }
            cerr << endl;
        }
        cerr << endl;
    }
    */
    int ans = 0;
    for(int y = 0; y <= 4000; y++) {
        for(int x = 0; x <= 4000; x++) {
            if(sum[y][x][1] >= 1 or sum[y][x][0] % 2 == 1) {
                ans++;
                //field[y][x] = 1;
            }
        }
    }
    /*
    for(int y = 2020; y >= 1980; y--) {
        for(int x = 1980; x <= 2020; x++) {
            cerr << field[y][x] << " ";
        }
        cerr << endl;
    }
    */
    cout << ans << endl;
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> M) {
        if(M == 0) break;
        solve();
    }
    return 0;
}


Measured memory_bytes: 128120
#pragma GCC optimize("O3") 
#include<bits/stdc++.h>
#define ll      				long long int
#define vi      				vector<int>
#define ii      				pair<int,int>
#define iii     				pair<ii,int>
#define iiii    				pair<ii,ii>
#define fi      				first
#define se      				second

#define pb      				push_back
#define pob     				pop_back

#define all(x)  				x.begin(), x.end()
#define len     				length()

#define db(x)					  cout << "!!!!!! " << #x << " => " << x << "\n"

#define fori(i, s, N)     for (int i = s; i <= N; i++)
#define fd(i, s, N)     for (int i = s; i >= N; i--)
using namespace std;

void init(int precision){
  	ios_base::sync_with_stdio(0);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(precision);
}

	string s;
int ha(){
	
	for(char c : s){
		if(c == '7') return 1;
	}
	return 0;
}
int t;
int main(){
	init(10);
	cin>>s;
	cout<<((ha()) ? "Yes" : "No")<<"\n";
	return 0;
}

Measured memory_bytes: 3692
#include<bits/stdc++.h>
using namespace std;
const int M=3e5+10;
int n;
struct SGT{
	#define lc (x<<1)
	#define rc (x<<1|1)
	#define mid (l+r>>1)
	int mi[M<<3];
	void build(int x,int l,int r){	
		mi[x]=n;
		if (l==r) return ;
		build(lc,l,mid); build(rc,mid+1,r);
	}
	void upd(int x,int l,int r,int ll,int rr,int d){
//		cout<<l<<" "<<r<<" "<<ll<<" "<<rr<<"\n";
//		system("pause");
		if (l==ll && r==rr){
			mi[x]=min(mi[x],d);
			return ;
		}
		if (rr<=mid) upd(lc,l,mid,ll,rr,d);
		else if (ll>mid) upd(rc,mid+1,r,ll,rr,d);
		else upd(lc,l,mid,ll,mid,d),upd(rc,mid+1,r,mid+1,rr,d);
	}
	int qry(int x,int l,int r,int p){
		if (l==r) return mi[x];
		int ret=mi[x];
		if (p<=mid) return min(ret,qry(lc,l,mid,p));
		return min(ret,qry(rc,mid+1,r,p));
	}
}s1,s2;
int m;
int main(){
	cin.tie(0);
	cin>>n>>m;
	s1.build(1,1,n);
	s2.build(1,1,n);
	long long ans=1ll*(n-2)*(n-2);
	for (int i=1;i<=m;i++){
		int op,x;
		cin>>op>>x;
		if (op==1){
			int pos=s2.qry(1,1,n,x);
			ans-=max(pos-2,0);
//			cout<<1<<" "<<pos<<"  fuc \n";
			s1.upd(1,1,n,1,pos,x);
			s2.upd(1,1,n,x,x,1);
		}
		else{
			int pos=s1.qry(1,1,n,x);
			ans-=max(pos-2,0);
//			cout<<pos<<" "<<1<<"   fuck \n";
			s2.upd(1,1,n,1,pos,x);
			s1.upd(1,1,n,x,x,1);
		}
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 7624
c = ''
while True:
    a,b = map(int, input().split())
    if(a == 0 and b == 0):
        break  
    for i in range(0,a):
        if(i %2 == 0):
            for j in range(0,b):
                if(j % 2 == 0):
                    print("#", end="")
                else:
                    print(".", end="")
        else:
            for j in range(0,b):
                if(j % 2 == 0):
                    print(".", end="")
                else:
                    print("#", end="")
        print()
    print()



Measured memory_bytes: 7004
#include <stdio.h>

int main (void) {
    int H1, M1, H2, M2, K;
    scanf("%d %d %d %d %d", &H1, &M1, &H2, &M2, &K);

    int ans = 60 * (H2 - H1) + M2 - M1 - K;
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 1732
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define str string
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define all(x) x.begin(),x.end()
#define int long long
signed  main(){
  int N,K;
  str S;
  vector<int>A(3);
  cin>>A.at(0)>>A.at(1)>>A.at(2);
  sort(all(A));
  cout<<A.at(1)-A.at(0)+A.at(2)-A.at(1)<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long double PI = acos(-1.0);
// cout << fixed << setprecision(14);
 
signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	char c;
	cin >> c;
	if(c-'a' <= 26 && c-'a' >= 0){
		cout << 'a' << endl;
	}
	else{
		cout << 'A' << endl;
	}
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define MAX 1e18
#define MIN -1e18
#define MOD 1000000007
#define mod2 20071027
#define mod 1000074259
#define base 139
#define memz(a) memset(a, 0, sizeof(a))
#define memn(a) memset(a, -1, sizeof(a))
#define in1(a) scanf("%lld", &a)
#define in2(a, b) scanf("%lld%lld", &a, &b)
#define tc(c) printf("Case %lld: ", ++c)
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
const ll N=500010;
string s;
ll n;
int main()
{
    cin>>n>>s;
    ll sz=s.length();
    for(int i=0;i<sz;i++)
    {
        s[i]+=n;
        if(s[i]>'Z')
        {
        ll m = s[i]%('Z'+1);
        s[i]='A'+m;
        }
    }
    cout<<s<<endl;
    return 0;
}
/*

*/


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

int main() {
  int N; cin >> N;
  vector<int> A(N); rep(i, N) cin >> A[i];
  vector<int> B(N); rep(i, N) cin >> B[i];
  vector<int> C(N-1); rep(i, N-1) cin >> C[i];
  
  int ans = 0;
  
  for(int i = 0; i < N; i++){
    ans += B[A[i]-1];
    if( (A[i]+1) == A[i+1] && i != (N-1)){
      ans += C[A[i]-1];
    }
  }
  cout << ans << endl;

}


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

int main()
{
	int n, m, a[100][100], b[100], N[100] = {};
	cin >> n >> m;


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

	for (int x = 0;x < n;x++) {
		for (int y = 0;y < m;y++) {
			N[x] = a[x][y] * b[y] + N[x];
		}
		cout << N[x] << endl;
	}

    return 0;
}


Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << '\n';
typedef int64_t Int;
Int mod = 1e9+7;
Int INF = 1e9+7;

#define MAX_V 1005
#define MAX_E 2005

struct edge { int from, to, cost; };

edge es[MAX_E];
vector<Int> d(MAX_V);
vector<Int> d2(MAX_V);

vector<bool> used(MAX_V, false);
vector<pair<Int, Int>> G[MAX_V];

Int V, E, r;

bool find_negative_loop() {
    fill(d2.begin(), d2.end(), 0);
    for (Int i = 0; i < V; i++) {
        for (Int j = 0; j < E; j++) {
            edge e = es[j];
            if (!used[e.from] || !used[e.to]) continue;
            if (d2[e.to] > d2[e.from] + e.cost) {
                d2[e.to] = d2[e.from] + e.cost;
                if (i == V - 1) return true;
            }
        }
    }
    return false;
}

void bellman_ford(Int s) {
    fill(d.begin(), d.end(), INF);
    d[s] = 0;
    bool update = true;
    while (update) {
        update = false;
        for (Int i = 0; i < E; i++) {
            edge e = es[i];
            // if (!used[e.from] || !used[e.to]) continue;
            if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
                d[e.to] = d[e.from] + e.cost;
                update = true;
            }
        }
    }
}

void dfs(Int v) {
    if (used[v]) return;
    used[v] = true;
    for (Int i = 0; i < (Int)G[v].size(); i++) {
        Int next = G[v][i].first;
        if (used[next]) continue;
        dfs(next);
    }
}

int main() {
    cin >> V >> E >> r;
    for (Int i = 0; i < E; i++) {
        cin >> es[i].from >> es[i].to >> es[i].cost;
        G[es[i].from].emplace_back(es[i].to, es[i].cost);
    }
    dfs(r);
    if (find_negative_loop()) {
        dump("NEGATIVE CYCLE");
        return 0;
    }
    bellman_ford(r);
    for (Int i = 0; i < V; i++) {
        if (d[i] != INF) {
            dump(d[i]);
        }
        else {
            dump("INF");
        }
    }
    return 0;
}


Measured memory_bytes: 3192
Public Class Program
  Shared Sub Main()
    Dim n As Integer = Integer.Parse(Console.ReadLine())
    Dim a(0 To n - 1) As Integer
    Dim x(0 To n - 1)() As Integer
    Dim y(0 To n - 1)() As Integer
    For i As Integer = 0 To n - 1
      a(i) = Integer.Parse(Console.ReadLine())
      x(i) = New Integer(0 To a(i) - 1) {}
      y(i) = New Integer(0 To a(i) - 1) {}
      For j As Integer = 0 To a(i) - 1
        Dim xy As Integer() = Array.ConvertAll(Of String, Integer)(Console.ReadLine().Split(" "), AddressOf Integer.Parse)
        x(i)(j) = xy(0)
        y(i)(j) = xy(1)
      Next
    Next
    
    Dim ans As Integer = 0
    For i As Integer = 0 To Math.Pow(2, n) - 1
      Dim katei(0 To n - 1) As Boolean
      For j As Integer = 0 To n - 1
        Dim z As Integer = (i >> j) And 1
        If z = 1 Then 
          katei(j) = True
        Else
          katei(j) = False
        End If
      Next
      
      Dim ok As Boolean = True
      For j As Integer = 0 To n - 1
        If katei(j) Then
          For k As Integer = 0 To a(j) - 1
            If Not katei(x(j)(k) - 1) = (y(j)(k) = 1) Then ok = False
          Next
        End If
      Next
      If ok Then
        ans = Math.Max(ans, Array.FindAll(Of Boolean)(katei, AddressOf IsTrue).Length())
      End If
    Next
    Console.WriteLine(ans.ToString())
  End Sub

  Private Shared Function IsTrue(element As Boolean) As Boolean
    Return element
  End Function
End Class

Measured memory_bytes: 15312
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    char[]ss = S.toCharArray();
    
    int cou = 0;
    for(int i=0; i<3; i++) {
    	if(ss[i]=='1'){
    			cou++;
    	}
    }
    	 System.out.println(cou);
    }
}

Measured memory_bytes: 35600
from math import floor
def Main(X):
    i = 1
    a = 100
    while True:
        a = floor(a*1.01)
        if a >= X:
            return i
        i += 1
        
def main():
    X = int(input())
    print(Main(X))

if __name__ == '__main__':
    main()

Measured memory_bytes: 9112
N, M, Q = map(int, input().split())
G = [[0] * (N+1) for i in range(N+1)]
for m in range(M):
    l, r = map(int, input().split())
    G[l][r] += 1

# 2次元累積和を導出
for i in range(2, N+1):
    G[i][1] += G[i-1][1]
    G[1][i] += G[1][i-1]
for i in range(2, N+1):
    for j in range(2, N+1):
        G[i][j] += G[i-1][j] + G[i][j-1] - G[i-1][j-1]

# クエリに答えていく
for q in range(Q):
    p, q = map(int, input().split())
    print(G[q][q] - G[q][p-1] - G[p-1][q] + G[p-1][p-1])


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

int main() {
  int A,B;
  cin >> A >> B;
  int x;
  int sum = 0;
  int count = 1;
  rep(i,A){
    cin >> x;
    sum += x;
    if(sum > B){
     break; 
    }
   count++; 
  }
  cout << count << endl;
}


Measured memory_bytes: 3636
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <sstream>
#include <utility>
#include <deque>
#include <numeric>
#include <map>
#include <stack>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF 1000000000000

using namespace std;
 
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

class UnionFind {
public:
    vector < int > par; // 各元の親を表す配列
    vector < int > siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(int sz_): par(sz_), siz(sz_, 1) {
        for (int i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(int sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1);
        for (int i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    int root(int x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool same(int x, int y) { // 連結判定
        return root(x) == root(y);
    }

    int size(int x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

int main () {
	int N, M;
    cin >> N >> M;
	vector<pii> bridges(M);
	int u,v;
	rep(i,M) {
		cin >> u >> v;
		bridges[i] = pii(--u,--v);
	}
	UnionFind uf(N);
	vector<ll> ans(M);
	ans[M-1] = 1LL * N*(N-1)/2;
	for (int i = M-2; i >= 0; --i) {
		int u = bridges[i+1].first;
		int v = bridges[i+1].second;
		if (uf.same(u,v))
			ans[i] = ans[i+1];
		else
		{
			ans[i] = ans[i+1] - 1LL * uf.size(u) * uf.size(v);
			uf.merge(u,v);
		}
	}
	rep(i,M) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 3712
#include<iostream>
#include<cstring>
using namespace std;
using ll = long long;

int main (){
    string S,T;
    int ans = 0;
    cin >> S >> T;
    for (int i = 0; i < S.size(); i++){
        if (S[i] == T[i]){
            ans++;
        }
    }
    if(ans == S.size()){
        cout << "Yes"<< endl;
    }else cout << "No" << endl;
return 0;
}
   

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

ll gcd(ll a,ll b){
	if(b==0){
		return a;
	}
	if(a%b==0){
		return b;
	}
	gcd(b,a%b);
}
int main() {
	ll n,x,a[100010],ans=0;
	cin>>n>>x;
	for(int i=0;i<n;i++){
		ll z;
		cin>>z;
		a[i]=abs(x-z);
	}
	for(int i=0;i<n;i++){
		ans=gcd(max(ans,a[i]),min(ans,a[i]));
	}
	cout << ans;
	return 0;
}

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

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

int main() {
	int h, w; cin >> h >> w;
	string s[h];
	for (int i = 0; i < h; i++)	cin >> s[i];
	int res[h][w] = {};
	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			int cnt = 0;
			for (int k = 0; k < 8; k++)
			{
				if(i + dy[k] < 0 || i + dy[k] >= h || j + dx[k] < 0 || j + dx[k] >= w) continue;
				if(s[i+dy[k]][j+dx[k]] == '#') cnt++;
			}
			res[i][j] = cnt;
		}
	}
	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			if(s[i][j] == '#') cout << "#";
			else cout << res[i][j];
		}
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 3604
import queue
import time
import sys
input = sys.stdin.readline


def main():
    K = int(input().strip())
    que = queue.Queue()
    [que.put(i) for i in range(1, 10)]
    for _ in range(K):
        answer = que.get()
        if answer % 10 != 0:
            que.put(10*answer + answer % 10 - 1)
        que.put(10 * answer + answer % 10)
        if answer % 10 != 9:
            que.put(10*answer + answer % 10 + 1)
    print(answer)


if __name__ == '__main__':
    main()


Measured memory_bytes: 12528
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;

int main(){
    ll n ; cin >> n;
    vector<ll> p(n);
    rep(i,n) cin >> p.at(i);
    ll ans = 0;
    for(int i=2;i<n;i++){
        if(p[i]>p[i-1] && p[i-1]>p[i-2]) ans++;
        if(p[i]<p[i-1] && p[i-1]<p[i-2]) ans++;
    }
    cout << ans << endl;
}

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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> A(N, 0);
    rep(i, K) {
        int d;
        cin >> d;
        rep(j, d) {
            int tmp;
            cin >> tmp;
            A[tmp - 1]++;
        }
    }
    int cnt = 0;
    rep(i, N) {
        if (A[i] == 0) { cnt++; }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define rep(i,j,k) for(int i=j;i<k;i++)
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
const int  COMMAX = 510000;

long long fac[COMMAX], finv[COMMAX], inv[COMMAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < COMMAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

struct UnionFind {
  vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
  vector<int> rank;
  int num;
  UnionFind(int N) : par(N) , rank(N) { //最初は全てが根であるとして初期化
    num = N;
    for(int i = 0; i < N; i++){
      par[i] = i;
      rank[i] = 0;
    }
  }

  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); //xの根をrx
    int ry = root(y); //yの根をry
    if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
    if(rank[rx] < rank[ry]){
      par[rx] = ry;  
    }else{
      par[ry] = rx;
      if(rank[rx] == rank[ry])rank[rx]++;
    }
    num--;
  }

  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    return root(x) == root(y);
  }
};

const int MS = 2;
const long long mod[] = {999999937LL, 1000000007LL}, base = 9973;
struct rolling_hash {
    int n;
    vector<long long> hs[MS], pw[MS];
    rolling_hash(){}
    rolling_hash(const string &s) {
        n = s.size();
        for (int i = 0; i < MS; i++) {
            hs[i].assign(n+1,0);
            pw[i].assign(n+1,0);
            hs[i][0] = 0;
            pw[i][0] = 1;
            for (int j = 0; j < n; j++) {
                pw[i][j+1] = pw[i][j]*base%mod[i];
                hs[i][j+1] = (hs[i][j]*base+s[j])%mod[i];
            }
        }
    }

    long long hash(int l, int r, int i) { return ((hs[i][r]-hs[i][l]*pw[i][r-l])%mod[i]+mod[i])%mod[i]; }

    bool match(int l1, int r1, int l2, int r2) {
        bool ret = 1;
        for (int i = 0; i < MS; i++) ret &= hash(l1,r1,i)==hash(l2,r2,i);
        return ret;
    }

    bool match(int l, int r, long long h[]) {
        bool ret = 1;
        for (int i = 0; i < MS; i++) ret &= hash(l,r,i)==h[i];
        return ret;
    }
};

int main(){
  string s;
  cin >> s;
  int n = s.length();
  char last = '0';
  int res = 0;
  rep(i,0,n){
    if(last != s[i]){
      last = s[i];
    }else{
      last = '0';
      i++;
      if(i == n)break;
    }
    res++;
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cctype>
#include <cstring>
int N,A[200005],B[200005],F[200005],Ans;
inline void read(int &Res){
	char ch=getchar();
	for (Res=0;!isdigit(ch);ch=getchar());
	for (;isdigit(ch);ch=getchar()) Res=(Res<<3)+(Res<<1)+ch-48;
}
int main(){
	read(N);
	for (int i=1;i<=N;++i) read(B[i]),A[B[i]]=i;
	for (int i=1;i<=N;Ans=F[i]>Ans?F[i]:Ans,++i) if (A[i]>A[i-1]) F[i]=F[i-1]+1; else F[i]=1;
	printf("%d",N-Ans);
	return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define Khela ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define llu long long unsigned int
#define pf printf
#define sf scanf
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define pii pair<int ,int>
 
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
 
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
int Set(int N,int pos){return N=N | (1<<pos);}
int reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}
const int Max=1e9+100;
const ll Maxx=1e18+500;
const int sz=1e3+100;
 
int main()
{
    Khela
    ll a,b,c,i,j,k,q,p,x,y,ct,ct1,m,l,r,x1,y1,mn,h,sum1,in,z,mid,n,mx;
    char ch;
    double d;
    string str1,str2,str;
    bool bl,bl1;
    int t,cs=1;
    while(cin>>n)
    {
        ll ara[n+2];
        for(i=0;i<n;i++) cin>>ara[i];
        ll last=0;
        ara[n]=0ll;
        ll sum=0;
        ll mn=Maxx;
        ll ct=0;
        for(i=0;i<=n;i++){
            if(ara[i]>=0){
                if(ct>0){
                    if((ct+last)%2==0) last=0;
                    else last=1;
                }
                ct=0;
            }
            else{
                ++ct;
            }
            sum+=abs(ara[i]);
            if(i<n) mn=min(mn,abs(ara[i]));
        }
        if(last>0) sum-=(2*mn);
        cout<<sum<<endl;
    } 





}

Measured memory_bytes: 1024