akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <vector>
#include <algorithm>

#define MAX_SIZE 1500000

using namespace std;

int main(){
	int dansu,kansu,shelf[20],book[100],min_size,left,right,m,dansu_index,max_length;

	while(true){
		scanf("%d %d",&dansu,&kansu);
		if(dansu == 0 && kansu == 0)break;

		max_length = 0;

		for(int i = 0; i < kansu; i++){
			scanf("%d",&book[i]);
			max_length = max(max_length,book[i]);
		}

		min_size = MAX_SIZE;
		left = max_length,right = MAX_SIZE;
		m = (left+right)/2;

		while(left < right){

			for(int i = 0; i < dansu; i++)shelf[i] = m;
			dansu_index = 0;
			for(int i = 0; i < kansu && dansu_index < dansu;){
				if(book[i] > m){
					dansu_index = dansu;
					break;
				}
				if(shelf[dansu_index] >= book[i]){
					shelf[dansu_index] -= book[i];
					i++;
				}else{
					dansu_index++;
				}
			}

			if(dansu_index == dansu){
				left = m + 1;
				m = (left + right)/2;
			}else{
				min_size = min(min_size,m);
				right = right - 1;
				m = (left + right)/2;
			}
		}

		printf("%d\n",min_size);

	}

    return 0;
}

Measured memory_bytes: 2564
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0

for i in range(n):
    if a[i] <= b[i]:
        ans += a[i]
        b[i] -= a[i]
        a[i] = 0

    else:
        ans += b[i]
        b[i] = 0
        continue

    if a[i+1] <= b[i]:
        ans += a[i+1]
        b[i] -= a[i+1]
        a[i+1] = 0

    else:
        ans += b[i]
        a[i+1] -= b[i]
        b[i] = 0

print(ans)


Measured memory_bytes: 24088
import math

L = int(input())

N = math.floor(math.log(L, 2)) + 1
ans = []
for i in range(1, N):
    ans.append((i, i+1, 0))
    ans.append((i, i+1, 2**(N-i-1)))

tmp = 2 ** (N-1)
for j in range(N-1):
    if L >> j & 1:
        ans.append((1, N-j, (L >> (j+1)) << (j+1)))

print(N, len(ans))
for ans_i in ans:
    print(*ans_i)


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

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

	if (a > b) cout << "a > b" << endl;
	else if (a == b) cout << "a == b" << endl;
	else if (a < b) cout << "a < b" << endl;

	return 0;
}

Measured memory_bytes: 1156
x = input().split()
W, H, x, y, r = int(x[0]), int(x[1]), int(x[2]), int(x[3]), int(x[4])

if 0 <= x-r and x+r <= W and 0 <= y-r and y+r <= H:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
#define what_is(x) cerr << #x << " is " << x << endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;
const int N = 1e5+5;
const int INF = 1e9;
const int MOD = 1e9+7;

int n;
pii a[N];

int main()
{
	IOS
	// freopen("input.txt", "r", stdin);
	cin >> n;
	for(int i=1; i<=n; i++){
		int x; cin >> x;
		a[i-1] = {x, i};
	}
	sort(a, a+n);
	for(int i=0; i<n; i++){
		cout << a[i].nd << ' ';
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>

using namespace std;

int main(){
  
  long long S; cin >> S;
  long long nmax = 1000000000;
  long long a = S / nmax + 1;
  long long b = nmax - S % nmax;

  if (S == 1000000000000000000){
    cout << "0 0 " << nmax << " " << 0 << " ";
    cout << 0 << " " << nmax << endl;
  }else{
    cout << 0 << " " << 0 << " ";
    cout << nmax << " " << 1 << " ";
    cout << b << " " << a << endl;
  }

  return 0;
}

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

using namespace std;

int main() {
	string S, T;
	cin >> S;
	cin >> T;

	string tmp = T.substr(0,T.length()-1);

	if(S == tmp) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 3596
num_list = list(map(int, input().split()))

num_list.sort()

if num_list[0] == num_list[1] and num_list[1] != num_list[2]:
    print("Yes")
elif num_list[0] != num_list[1] and num_list[1] == num_list[2]:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll = long long ;
using P = pair<ll, ll>;
using Vec = vector<ll>;
using VecP = vector<P>;
#define FOR(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define FORN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define FORR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) FOR(i, 0, n)
#define repn(i, n) FORN(i, 1, n)
#define repr(i, n) FORR(i, n, 0)
#define repnr(i, n) FORR(i, n, 1)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define setp(n) cout << fixed << setprecision(n);
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second

const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

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

	ll sum = 0;
	rep(i, n){
		ll a;
		cin >> a;
		sum += a;
	}
	co(sum-n);


	return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var s int
	fmt.Scan(&s)

	M := 1000000
	a := make([]int, M)

	for i := 1; i < M; i++ {
		if i == 1 {
			a[i] = s
		} else if a[i-1]%2 == 0 {
			a[i] = a[i-1] / 2
		} else {
			a[i] = 3*a[i-1] + 1
		}

		if a[i] == 4 || a[i] == 2 || a[i] == 1 {
			fmt.Println(i + 3)
			break
		}
	}
}


Measured memory_bytes: 2816
N = int(input())
L = [ input() for i in range(N)]
#print(L)
    
dic = {}
m = 0

for i in L:
    if i in dic:
        dic[i] = dic[i] + 1
    else:
        dic[i] = 1
        
    if m < dic[i]:
        m = dic[i]

n = []
for i in dic:
    if dic[i] == m:
        n.append(i)
n.sort()
for i in n:
    print(i)


Measured memory_bytes: 35216
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF (long long)1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main(void) {
	while(true) {
		int n, m;
		cin>>n>>m;
		if(n == 0 && m == 0) break;
		vector<vector<pair<ll, P> > > l(m, vector<pair<ll, P> >(0));
		REP(i, n) {
			ll a, b, c, t;
			cin>>a>>b>>c>>t;
			--a;
			--b;
			l[a].pb(pair<ll, P>(b, P(c, t)));
			l[b].pb(pair<ll, P>(a, P(c, t)));
		}
		vector<vector<ll> > d0(m, vector<ll>(m, INF));
		vector<vector<ll> > d1(m, vector<ll>(m, INF));
		REP(i, m) {
			REP(j, l[i].size()) {
				d0[i][l[i][j].first] = l[i][j].second.first;
				d0[l[i][j].first][i] = l[i][j].second.first;
				d1[i][l[i][j].first] = l[i][j].second.second;
				d1[l[i][j].first][i] = l[i][j].second.second;
			}
		}
		REP(k, m) {
			REP(i, m) {
				REP(j, m) {
					d0[i][j] = min(d0[i][j], d0[i][k] + d0[k][j]);
					d1[i][j] = min(d1[i][j], d1[i][k] + d1[k][j]);
				}
			}
		}
		int k;
		cin>>k;
		REP(i, k) {
			int p, q, r;
			cin>>p>>q>>r;
			--p;
			--q;
			if(r == 0) {
				cout<<d0[p][q]<<endl;
			} else {
				cout<<d1[p][q]<<endl;
			}
		}
	}
}

Measured memory_bytes: 3228
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1e18;

vector<pair<pll,ll>> E;

int main() {
  ll n,q;
  cin >> n >> q;
  for(ll i=0;i<n;i++) {
    ll s,t,x;
    cin >> s >> t >> x;
    s-=x;
    t-=x;
    E.push_back({{s,t},x});
  }
  ll id=0;
  sort(E.begin(),E.end());
  priority_queue<pll> p;
  for(ll i=0;i<q;i++) {
    ll d;cin >> d;
    while(id<n&&E[id].first.first<=d) {
      p.push({-E[id].second,E[id].first.second});
      id++;
    }
    while(p.size()&&p.top().second<=d) p.pop();
    if(p.size()) cout << -p.top().first << endl;
    else cout << -1 << endl;
  }
}

Measured memory_bytes: 14188
from collections import deque
H,W = map(int, input().split())
Ch, Cw = map(int, input().split())
Dh, Dw = map(int, input().split())
S = [input() for _ in range(H)]

used = [[-1]*W for _ in range(H)]
Ch -= 1
Cw -= 1
Dh -= 1
Dw -= 1
q = deque()
flag = True
num = 0
for k in range(H):
    for l in range(W):
        if S[k][l] == "#" or used[k][l] >= 0:
            continue
        used[k][l] = num
        q.append((num, k, l))
        while q:
            temp = q.popleft()
            num = temp[0]
            i = temp[1]
            j = temp[2]

            if i > 0 and S[i-1][j] == "." and used[i-1][j] == -1:
                used[i-1][j] = num
                q.append((num, i-1, j))
            if j > 0 and S[i][j-1] == "." and used[i][j-1] == -1:
                used[i][j-1] = num
                q.append((num, i, j-1))
            if i < H-1 and S[i+1][j] == "." and used[i+1][j] == -1:
                used[i+1][j] = num
                q.append((num, i+1, j))
            if j < W-1 and S[i][j+1] == "." and used[i][j+1] == -1:
                used[i][j+1] = num
                q.append((num, i, j+1))
        num += 1

E = [[] for _ in range(num)]
for i in range(H):
    for j in range(W):
        for k in range(i-2, i+3):
            for l in range(j-2, j+3):
                if k < 0 or k > H-1 or l < 0 or l > W-1:
                    continue
                if S[k][l] == "#" or S[i][j] == "#":
                    continue
                if used[i][j] != used[k][l] and used[i][j] not in E[used[k][l]]:
                    E[used[i][j]].append(used[k][l])
                    E[used[k][l]].append(used[i][j])


dist = [10**6]*num
q = deque()
q.append((0, used[Ch][Cw]))
dist[used[Ch][Cw]] = 0
while q:
    temp = q.popleft()
    d = temp[0]
    i = temp[1]
    for e in E[i]:
        if dist[e] > d+1:
            dist[e] = d+1
            q.append((d+1, e))
if num == 1:
    print(0)
elif dist[used[Dh][Dw]] == 10**6:
    print(-1)
else:
    print(dist[used[Dh][Dw]])

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

ll p2(ll x){
    ll ret = 1;
    for(; ret <= x; ret *= 2){
    }
    return ret;
}

void solve(long long N, std::vector<long long> A){
    multiset<ll> s;
    REP(i, A.size()){
        s.insert(A.at(i));
    }
    ll ans = 0;
    while(s.size()){
        const ll x = *s.rbegin();
        s.erase(s.find(x));
        const ll y = p2(x);
        auto it = s.find(y - x);
        if(it != s.end()){
            ans++;
            s.erase(it);
        }
    }
    cout << ans << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  vector<pair<int, int>> c(n);
  for (int i = 0; i < n; i++) {
    int t, u;
    cin >> t >> u;
    a[i] = t;
    b[i] = u;
    c[i] = {a[i] + b[i], i};
  }
  sort(c.begin(), c.end());
  reverse(c.begin(), c.end());
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    int crr = c[i].second;
    if (!(i & 1)) {
      ans += a[crr];
    } else {
      ans -= b[crr];
    }
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
*/

int main() {
	int W, H;
	vector<int>dx(8);
	vector<int>dy(8);
	dx = { 1,1,0,-1,-1,-1,0,1 };
	dy = { 0,1,1,1, 0,-1,-1,-1};
	while (cin >> W >> H, W != 0) {
		vector<vector<char>>field(H, vector<char>(W));
		rep(i, H) {
			rep(j, W) {
				cin >> field[i][j];
			}
		}
		int cnt = 0;
		rep(sy, H) {
			rep(sx, W) {
				if (field[sy][sx] == '1') {
					cnt++;
					queue<P>que;
					que.push({ sx,sy });
					field[sy][sx] = '0';
					while (!que.empty()) {
						int x = que.front().first;
						int y = que.front().second;
						que.pop();
						rep(i, 8) {
							int xx = x + dx[i];
							int yy = y + dy[i];
							if (xx >= 0 && xx < W && yy >= 0 && yy < H && field[yy][xx] == '1') {
								que.push({ xx,yy });
								field[yy][xx] = '0';
							}
						}
					}
				}
			}
		}
		cout << cnt << endl;
	}
}



Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    string ans = "";
    for(int i=0; i<s.size(); i++){
        if(s[i]=='0'){
            ans += "0";
        }else if(s[i]=='1'){
            ans += "1";
        }else{
            if(!(ans.empty())){
                ans.pop_back();
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;

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

const int kMaxN = 5005, kMod = 1e9 + 7;
int n, len;
ll f[kMaxN][kMaxN];
char str[kMaxN];

ll QuickPow(ll x, ll y) {
  ll ret = 1;
  for (; y; y >>= 1, x = x * x % kMod)
    if (y & 1) ret = ret * x % kMod;
  return ret;
}

int main() {
  scanf("%d\n%s", &n, str + 1);
  len = strlen(str + 1);
  f[0][0] = 1;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j <= i; ++j) {
      f[i + 1][j + 1] = (f[i + 1][j + 1] + 2LL * f[i][j] % kMod) % kMod;
      f[i + 1][max(j - 1, 0)] = (f[i + 1][max(j - 1, 0)] + f[i][j]) % kMod;
    }
  printf("%lld\n", f[n][len] * QuickPow(QuickPow(2, len), kMod - 2) % kMod);
  return 0;
}

Measured memory_bytes: 193920
n,k = (int(x) for x in input().split())
list = [int(i) for i in input().split()]
sumlist = []
sum = 0;ans = 0
for l in range(n):
    list[l] = (1+list[l])/2

for i in range(n):
    sum += list[i]
    sumlist.append(sum)

if k!=n:
    for j in range(n-k):
        ans = max(ans,sumlist[j+k]-sumlist[j])
    print(ans)
else:
    print(sum)

Measured memory_bytes: 25188
import sys,collections as cl,bisect as bs,heapq as hq
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def prime_decomposition(n): #素因数分解
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(int(n))
  return table

def make_divisors(n): #約数列挙
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors


def ok(x,p):
    kkk = 0
    for i in range(len(x)):
        kkk += max(0,-(-(x[i][0] - p) // x[i][2]))
    return kkk


n,k = m()
a = l()

f = l()

for i in range(n):
    a[i]


a.sort(reverse = True)

f.sort()
co = 0

d = []

for i in range(n):
    d.append([a[i]*f[i],a[i],f[i]])

d.sort(reverse = True)



ll = 0

rr = d[0][0] 


while True:
    mid = (rr+ll)//2

    if rr == mid:
        break

    if ok(d,mid) <= k:
        rr = mid
    else:
        ll = mid+1

print(ll)









Measured memory_bytes: 127052
#include <stdio.h>   

int main()    

{    

int a,b,c,x,y,z;    

scanf("%d%d%d",&a,&b,&c);    

if(a > b){     

x = a;     

a = b;    

b = x;     

}    

if(b > c){    

y = b;     

b = c;     

c = y;    

}    

if(a > b){    

z = a;     

a = b;     

b = z;    

}     

printf("%d %d %d\n",a,b,c);    

return 0;    

}

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

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> g[n];            // グラフ
    vector<int> ans(n, -1);      // 答え(自分自身を除くので -1 しておく)
    vector<int> idx(n);          // 各頂点が属する連結成分の index
    vector<int> sz;              // 各連結成分のサイズ
    vector<bool> seen(n, false);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        ans[a]--; ans[b]--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    // bfs で各頂点が属する連結成分の index を求める
    int cnt = 0;
    for (int s = 0; s < n; s++) if (not seen[s]) {
        idx[s] = cnt++;
        queue<int> que;
        que.emplace(s);
        while (not que.empty()) {
            int v = que.front();
            que.pop();
            if (seen[v]) continue;
            seen[v] = true;
            for (int u : g[v]) if (not seen[u]) {
                idx[u] = idx[s];
                que.emplace(u);
            }
        }
    }

    sz.resize(cnt, 0);
    for (int i : idx) sz[i]++;
    for (int i = 0; i < n; i++) ans[i] += sz[idx[i]];

    for (int i = 0; i < k; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        if (idx[a] == idx[b]) {
            ans[a]--;
            ans[b]--;
        }
    }

    for (int i = 0; i < n; i++) cout << ans[i] << endl;

    return 0;
}


Measured memory_bytes: 7928
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cstring>
#define FOR(I, A, B) for (ll I = (A); I <= (B); I++)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(i,n) for(ll i=0;i<n;i++)
#define sz(a) ll((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define dbg3(x,y,z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define dbg4(x,y,z,q) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << ", " << #q << " = " << q << endl
#define scan(char_array) scanf("%[^\n]s",&char_array);

int main(){
	ll h,w;
	cin>>h>>w;
	ll a[h+1][w+1][2];
	FOR(i,1,h){
		FOR(j,1,w){
			cin>>a[i][j][0];


		}
	}
	FOR(i,1,h){
		FOR(j,1,w){
			cin>>a[i][j][1];


		}
	}
	bool dp[h+1][w+1][6400];
	FOR(i,0,h){
		FOR(j,0,w){
			FOR(k,0,6400-1){
				dp[i][j][k]=false;
			}
		}
	}
	dp[0][1][0]=true;
	dp[1][0][0]=true;
	ll o;
	FOR(i,1,h){
		FOR(j,1,w){
			FOR(k,0,6400-1){
				if(dp[i-1][j][k]||dp[i][j-1][k]){
					o=abs(k+abs(a[i][j][0]-a[i][j][1]));
					if(o<6400) dp[i][j][o]=true;
					o=abs(k-abs(a[i][j][0]-a[i][j][1]));
					if(o<6400) dp[i][j][o]=true;
					


				}
			}
		}
	}
	ll miin=6500;
	FOR(i,0,6400-1){
		if(dp[h][w][i]) { miin=min(miin,i);}
	}
	cout<<miin<<endl;

}

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

size_t n;
int k, m;
string s;
size_t j[100010];
bool f;
int x, t;

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

    m = 1;
    j[0] = 0;
    for (size_t i = 1; i < s.size(); ++i){
        if (s[i] != s[i-1]){
            j[m] = i;
            m++;
        }
    }
    j[m] = n;

    x = 0;
    for (int i = 0; i < m; ++i){
        if (s[j[i]] == '0') t = j[min(m, i+2*k)] - j[i];
        else t = j[min(m, i+2*k+1)] - j[i];
        if (x < t) x = t;
    }

    cout << x;
}

Measured memory_bytes: 1280
#include<iostream>

using namespace std;
int main()
{
  int a[3];
  cin>>a[0]>>a[1]>>a[2];
  int five =0;
  int seven = 0;
  for(int i = 0 ; i < 3 ; ++i){
    if(a[i]==5)five++;
    if(a[i]==7)seven++;
  }
  if(five==2 && seven==1)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;

}


Measured memory_bytes: 504
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main() 
{
    int n;
    scanf("%d",&n);
    for (int ix=0; ix<n; ix++) {
        int out=0,score=0;
        int hit[] = {0,0,0};
        string event;
        while (out<3) {
            cin>>event;
            if (event=="HIT") {
                if (hit[2]==1) score++;
                if (hit[1]==1) hit[2]=1;
                if (hit[0]==1) hit[1]=1;
                hit[0]=1;
            }
            else if (event=="HOMERUN") {
                for (int i=0; i<3; i++) {
                    score+=hit[i];
                    hit[i]=0;
                }
                score++;
            }
            else if (event=="OUT") {
                out++;
            }
        }
        printf("%d\n",score);
    }
}

Measured memory_bytes: 0
x,y = map(int, input().split())
a = abs(x)
b = abs(y)
ans = abs(a-b)
if x * y < 0:
  ans += 1
if x == 0 and y < 0:
  ans += 1
if y == 0 and x > 0:
  ans += 1
 
if 0 < x and 0 < y and x > y:
  ans += 2
if 0 > x and 0 > y and x > y:
  ans += 2

print(ans)

Measured memory_bytes: 3064
#pragma GCC optimize("Ofast")
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <functional>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
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; }
// --------------------------------------------------------------------------

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<ll> x(N),y(N),p(N);
  for(int i=0; i<N; i++){
    cin >> x[i] >> y[i] >> p[i];
  }
  vector<vector<ll>> X(N,vector<ll>(1LL<<N,INF)),Y(N,vector<ll>(1LL<<N,INF));
  for(int bit=0; bit<(1LL<<N); bit++){
    for(int i=0; i<N; i++){
      if(bit & (1LL<<i)){
        for(int j=0; j<N; j++){
          chmin(X[j][bit],abs(x[i]-x[j])*p[j]);
          chmin(Y[j][bit],abs(y[i]-y[j])*p[j]);
        }
      }
      chmin(X[i][bit],abs(x[i])*p[i]);
      chmin(Y[i][bit],abs(y[i])*p[i]);
    }
  }
  vector<ll> ans(N+1,INF);
  vector<int> now(N);  
  function<void()> calc = [&N,&X,&Y,&ans,&now](){
    ll now_X=0,now_Y=0;
    int cnt = 0;
    for(int i=0; i<N; i++){
      if(now[i] == 0){
        cnt++;
        now_X += (1LL<<i);
      }else if(now[i] == 1){
        cnt++;
        now_Y += (1LL<<i);
      }
    }
    ll sum = 0;
    for(int i=0; i<N; i++){
      sum += min(X[i][now_X],Y[i][now_Y]);
    }
    chmin(ans[cnt],sum);
  };
  function<void(int)> dfs = [&dfs,&N,&now,&calc](int k){
    if(k == N){
      calc();
    }else{
      for(int i=0; i<3; i++){
        now[k] = i;
        dfs(k+1);
      }
    }
  };
  dfs(0);
  for(int i=0; i<=N; i++){
    cout << ans[i] << "\n";
  }
  return 0;
}


Measured memory_bytes: 11168
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;

const string YES = "Yes";
const string NO = "No";
struct UnionFindPotential{
    vll parent;
    vll potential;
    vll rank;
    //* member functions
    UnionFindPotential(ll n){
        parent = vll(n);
        potential = vll(n, 0);
        rank = vll(n, 0);
        for(ll i=0; i< n; i++) parent[i] = i;
    }

    ll find(ll x){
        if(parent[x] == x) return x;
        else{
            ll r = find(parent[x]);
            potential[x] += potential[parent[x]];
            parent[x] = r;
            return r;
        }
    }

    ll get_potential(ll x){
        find(x);
        return potential[x];
    }

    void unite(ll x, ll y, ll d){ 
        //* potential(y)-potential(x) = d
        d += get_potential(x);
        d -= get_potential(y);
        x = find(x); y = find(y);
        if(x == y) return;
        if(rank[x] < rank[y]){
            parent[x] = y; //* new root is y
            potential[x] = -d;
        }
        else{
            if(rank[x] == rank[y]) rank[x]++;
            parent[y] = x;
            potential[y] = d;
        }
        return;
    }

    bool same(ll x, ll y){
        return find(x) == find(y);
    }
};
void solve(long long N, long long M, std::vector<long long> L, std::vector<long long> R, std::vector<long long> D){
    UnionFindPotential uf(N);
    bool isGood = true;
    for(ll i=0; i< M; i++){
        ll x = L[i]-1, y = R[i] -1, d = D[i];
        uf.unite(x, y, d);
        if(uf.get_potential(y)-uf.get_potential(x) != d){
            isGood = false;
            break;
        }
    }
    if(isGood) cout << YES << endl;
    else cout << NO << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> L(M);
    std::vector<long long> R(M);
    std::vector<long long> D(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&L[i]);
        scanf("%lld",&R[i]);
        scanf("%lld",&D[i]);
    }
    solve(N, M, std::move(L), std::move(R), std::move(D));
    return 0;
}


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

using namespace std;

#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl
#define lint long long
#define yes "Yes"
#define no "No"

typedef pair<int, int> P;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin>>n;
    vector<P > a(n);
    REP(i,n) {
        cin>>a[i].first;
        a[i].second = i+1;
    }
    sort(all(a));
    REP(i,n){
        cout<<a[i].second<<" ";
    }
    cout<<endl;
    return 0;
}

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

int main()
{
	int n;
	cin >> n;
	int cnt[4]={};
	for(int i = 0;i<n;i++)
	{
		string s;
		cin >> s;
		if(s=="AC")cnt[0]++;
		else if(s=="WA")cnt[1]++;
		else if(s=="TLE")cnt[2]++;
		else cnt[3]++;
	}

	cout <<"AC x  " << cnt[0] << endl;
	cout <<"WA x  " << cnt[1] << endl;
	cout <<"TLE x  " << cnt[2] << endl;
	cout <<"RE x  " << cnt[3] << endl;
	
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep1(i,n) for(long long i=1;i<=(long long)(n);i++)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main() {
  ll N;
  cin>>N;
  map<ll,ll> A,B;
  rep1(i,N){cin>>A[i];}
  rep1(i,N){B[A[i]]=i;}
  rep1(i,N){
    cout<<B[i]<<endl;
  }
}

Measured memory_bytes: 13312
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  vector<long long int> a(5);
  long long int high=10000000;
  long long int pre=0;
  for(long long int i=0; i<5; i++){
    cin>>a.at(i);
    if(a.at(i)%10!=0){
      high=min(a.at(i)%10,high);
      if(high==a.at(i)%10){
        pre=i;
      }
    }
  }
  long long int ans=0;
  for(long long int i=0; i<5; i++){
    if(i==pre){
      ans+=a.at(i);
    }else{
      if(a.at(i)%10==0){
        ans+=a.at(i);
      }else{
        ans+=a.at(i)+(10-a.at(i)%10);
      }
    }
  }
  cout<<ans<<endl;
}

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

using namespace std;

int main()
{
    string n;
    
    while(1){
    cin >> n;
    if(n=="-"){
        break;
    }
    int h;
    cin >> h;

    for(int i=0;i<h;i++){
        int s;
        cin >> s;
        n =  n.substr(s)+n.substr(0,s);
    }

    cout << n << endl;
    }
        
    return 0;
}

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

int main() {
   int N, K, R, S, P;
   cin >> N >> K >> R >> S >> P;
   string T;
   cin >> T;

   //mod Kで分割
   vector<string> c(K);
   rep(i, N){
       c[i%K] += T.at(i);
   }
   int ans = 0;
   //dpテーブルは少し多めに作る
   vector<vector<int>> dp(N+10, vector<int>(3));
   //dp[i][T]:i回目までのじゃんけんで最後にTを出したときの最高得点
   //T = 0, 1, 2  r : 0, s : 1, p : 2
   dp[0][0] = 0;
   dp[0][1] = 0;
   dp[0][2] = 0;
   rep(i, K){
       rep(j, c[i].size()){
           if(c[i].at(j) == 'r'){
               dp[j+1][0] = max(dp[j][1], dp[j][2]);
               dp[j+1][1] = max(dp[j][0], dp[j][2]);
               dp[j+1][2] = max(dp[j][0] + P, dp[j][1] + P);
           }
           else if(c[i].at(j) == 's'){
               dp[j+1][0] = max(dp[j][1] + R, dp[j][2] + R);
               dp[j+1][1] = max(dp[j][0], dp[j][2]);
               dp[j+1][2] = max(dp[j][0], dp[j][1]);
           }
           else if(c[i].at(j) == 'p'){
               dp[j+1][0] = max(dp[j][1], dp[j][2]);
               dp[j+1][1] = max(dp[j][0] + S, dp[j][2] + S);
               dp[j+1][2] = max(dp[j][0], dp[j][1]);
           }
       }
       ans += max(dp[c[i].size()][0], max(dp[c[i].size()][1], dp[c[i].size()][2]));
   }

   cout << ans << endl;
}

Measured memory_bytes: 13696
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int n, a[100005];

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

    for (int i = 0; i < n; ++i) {
        ans += a[i]/2;
        a[i] %= 2;
        if (i != n-1 && a[i+1] != 0 && a[i] != 0) {
            ans++;
            a[i+1]--;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 640
#pragma warning (disable :4996)
#include <bits/stdc++.h>
//#pragma GCC optimize(2)
using namespace std;
typedef long long ll;
const double PI = cos(-1.0);
const double eps = 1e-12;
#define For(i,n,m) for(int i=n;i<=m;++i)
#define clr(a,b) memset(a,b,sizeof(a))


ll x;
int main() {
	ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
	cin >> x;
	ll cnt(0), ans(100);
	while (ans < x) {
		ans = ans * 0.01 + ans;
		++cnt;
	}
	cout << cnt << "\n";
}

Measured memory_bytes: 3652
import heapq
class Dijkstra:
    INF = 10**18
    threshold = 10**9

    def __init__(self, N):
        self.MAX_V = N + 1
        self.dist = [self.INF] * self.MAX_V
        self.G = [[] for _ in range(self.MAX_V)]

    def insert(self, X, Y, cost): self.G[X].append((cost, Y))

    def dijkstra(self, st):
        q = []
        heapq.heappush(q, (0, st))
        self.dist[st] = 0

        while len(q):
            p = heapq.heappop(q)
            cost = p[0]
            node = p[1]
            if cost > self.dist[node]: continue
            for to in self.G[node]:
                to_cost = to[0]
                to_node = to[1]
                to_cost += self.dist[node]
                if self.dist[to_node] > to_cost:
                    self.dist[to_node] = to_cost
                    heapq.heappush(q, (to_cost, to_node))

h, w = map(int, input().split())
sh, sw = map(int, input().split())
eh, ew = map(int, input().split())

sh -= 1
sw -= 1
eh -= 1
ew -= 1

S = [input() for _ in range(h)]

di = Dijkstra(h*w)
for x in range(h):
    for y in range(w):
        if S[x][y] == '#': continue
        for i in range(-2, 3):
            for j in range(-2, 3):
                X = x + i
                Y = y + j
                if X < 0 or Y < 0 or X >= h or Y >= w or S[X][Y] == '#': continue
                D = abs(i) + abs(j)

                if D == 1: di.insert(x * w + y, X * w + Y, 0)
                if D >= 2: di.insert(x * w + y, X * w + Y, 1)

di.dijkstra(sh * w + sw)
ans = di.dist[eh * w + ew]
if ans == 10**18: print(-1)
else: print(ans)


Measured memory_bytes: 359132
#include <bits/stdc++.h>
#include <math.h>
#define lli long long int
#include <limits.h>
#include <fstream>
#define F first
#define S second
#define PI 3.141592653589793238
#define pb push_back

using namespace std;

//doesn't work for arrays
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

const lli N=100000;
vector<lli> g[N];
lli low[N],in[N]={0},timer=1;
set<pair<lli,lli>> ans;
bool bridge=0;

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli i,j,tt=1;
    //cin>>tt;
    while(tt--)
    {
        lli n,d,x,ct=0,y;
        cin>>n>>d;
        for(i=0;i<n;i++)
        {
            cin>>x>>y;
            if(x*x+y*y<=d*d)
                ct++;
        }
        cout<<ct<<"\n";
    }
    return 0;
}


Measured memory_bytes: 6000
#include <iostream>

using namespace std;

int n, s, ans;

void rep(int start, int depth, int sum) {
	for (int i = start; i < 10; i++) {
		if (depth == n) {
			if (sum + i == s) {
				ans++;
				return;
			}
		}
		else {
			rep(i+1, depth+1, sum + i);
		}
	}
}

int main() {
	while (1) {
		cin >> n >> s;
		if (n == 0 && s == 0)
			break;
		ans = 0;
		rep(0, 1, 0);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
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; }

using namespace std;
typedef pair<ll, ll> pint;


void yesno(bool b) {
    if (b) {
        cout << "Yes" << endl;
    }     else {
        cout << "No" << endl;
    }

}

long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
int main() {
    int K;
    cin >> K;
    ll ans = 0;
    REP(i,1, K+1) {
        REP(j,1, K+1) {
            REP(l,1, K+1) {
                ll tmp = GCD(i, j);
                ans += GCD(tmp, l);
            }
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 3624
// Beginner159.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <climits>
#include <vector>

using namespace  std;

bool is_strong_pa(const string& s, int from, int to)
{
	bool is_pal = true;

	for (int i = from; i <= (to-from)/2; ++i)
	{
		if (s[i] != s[to-i])
		{
			is_pal = false;
			break;
		}
	}
	
	return is_pal;
}

int main()
{
	/*int n, m;
	cin >> n >> m;

	int sum = 0;
	sum += n * (n - 1) / 2;
	sum += m * (m - 1) / 2;
	cout << sum;*/

	string s;
	cin >> s;

	const int n = s.length();

	bool is_pal = is_strong_pa(s, 0, n - 1) &&
		is_strong_pa(s, 0, (n - 1) / 2 - 1) &&
		is_strong_pa(s, (n + 3) / 2 - 1, n - 1);

	cout << (is_pal ? "Yes" : "No");
}



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

using namespace std;

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

	int col, row;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			string tmp;
			cin >> tmp;
			if (tmp == "snuke") {
				row = i + 1;
				col = j;
			}
		}
	}
	cout << (char)((int)'A' + col) << row << endl;
	return 0;
}

Measured memory_bytes: 256
a,b,n = map(int, raw_input().split(' '))
m = 0
print min(b-1,n) * a /b
"""
for t in range(0, min(b,n) + 1):
	print t*a/b
	m = max(m,t * a / b)
	#print int(t * a / b)
print m
"""

Measured memory_bytes: 85092
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <cmath>
#include <stack>
#include <string>
#include <iomanip>
#include <queue>
#include <deque>
#include<cstring>
#include<limits>
#include <sstream>
#include <stdio.h>
#include<unordered_map>
using namespace std;
#define sz(x) (x).size()
#define all(v) (v).begin(),(v).end()
#define m_p make_pair
void run()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
}
void fast()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

int main()
{    
	fast();
	int x, y;
	cin >> x >> y;
	int zero = 0;
	int z = 0;
	bool flag = 0;
	while (y > 0)
	{
		if (y % 10 != 0)
			flag = 1;
		if (!flag&&y % 10 == 0)
			zero++;
		z = (z * 10) + y % 10;
		y /= 10;
	}
	while (z > 0)
	{
		x = (x * 10) + z % 10;
		z /= 10;
	}
	x *= pow(10, zero);
	double a = sqrt(x);
	int b = a;
	if (a == b)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;

}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int maxn=100000+10;
bool bz[maxn][50];
int i,j,k,l,r,t,n,m,p,mi,ans;
void dfs(int x,int y){
	if (bz[x][y]) return;
	bz[x][y]=1;
	if (!x) ans=min(ans,y);
	int i;
	fo(i,0,9) 
		if (y+i<=46) dfs((x*10+i)%k,y+i);
}
int main(){
	scanf("%d",&k);
	ans=50;
	fo(i,1,9) dfs(i%k,i);
	//fo(i,1,9) f[1][i%k][i]=1;
	/*fo(i,0,k-1)
		if (!pd[i]){
			j=i;
			while (1){
				pd[j]=bz[j]=1;
				j=j*10%k;
				if (pd[j]) break;
			}
			bz[i]=0;
		}*/
	/*ans=50;
	fo(i,1,46){
		fo(l,0,46){
			fo(j,0,k-1) bz[j]=0;
			fo(j,0,k-1){
				if (!j&&f[i][j][l]) ans=min(ans,l);
				if (!bz[j]){
					t=j;
					p=0;
					while (1){
						bz[t]=1;
						if (p) f[i][t][l]=1;
						p|=f[i][t][l];
						t=t*10%k;
						if (bz[t]) break;
					}
					if (p){
						r=t;
						while (1){
							f[i][t][l]=p;
							t=t*10%k;
							if (t==r) break;
						}
					}
				}
			}
		}
		fo(l,0,46)
			fo(j,0,k-1)
				fo(r,1,46-l)
					if (f[i][l][j]) f[i+1][(j*10+r)%k][l+r]=1;
	}*/
	printf("%d\n",ans);
}

Measured memory_bytes: 109824
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		long H = long.Parse(str[0]);
		long W = long.Parse(str[1]);
		long K = long.Parse(str[2]);
		long[] C = new long[7]{2,3,5,8,13,21,34};
		long mod = 1000000007;
		long[,]A = new long[H+1,W];
		A[0,0] = 1;
		for(var i=1;i<H+1;i++){
			for(var j=0;j<W;j++){
				long a = 1;
				if(j>0){
					if(j>=3){
						a *= C[j-3];
					}
					if(W-j>=3){
						a *= C[W-j-3];
					}
					A[i,j-1] += A[i-1,j] * a;
				}
				a = 1;
				if(j>=2){
					a *= C[j-2];
				}
				if(W-j>=3){
					a *= C[W-j-3];
				}
				A[i,j] += A[i-1,j] * a;
				a = 1;
				if(j<W-1){
					if(j>=2){
						a *= C[j-2];
					}
					if(W-j>=4){
						a *= C[W-j-4];
					}
					A[i,j+1] += A[i-1,j] * a;
				}
			}
			for(var j=0;j<W;j++){
				A[i,j] %= mod;
			}
		}
		Console.WriteLine(A[H,K-1]%mod);
	}
}

Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 9999999999999999;
using ll = long long;
int main(){
  int N;
  cin>>N;
  int a[N];
  int ans = 0;
  for(int i = 0;i<N;i++){
    cin>>a[i];
    if((i+1)!=a[i]){
      ans++;
    }
  }
  if(ans>2){
    cout << "NO" << endl;
  }
  else{
    cout << "YES" << endl;
  }
  return 0;
}


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

int p[11][11];
int money[11];
int dp[100010];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, d, x;
    cin >> n >> d >> x;
    rep(i, 0, d){
        rep(j, 0, n){
            cin >> p[i][j];
        }
    }
    rep(i, 0, d) money[i] = x;
    rep(i, 0, d){
        rep(j, i + 1, d){
            vector<int> cost(n), value(n);
            rep(k, 0, n){
                cost[k] = p[i][k];
                value[k] = p[j][k] - p[i][k];
            }
            fill(dp, dp + 100010, 0);
            rep(k, 0, n){
                rep(l, 0, money[i] + 1){
                    if(l + cost[k] > money[i]) break;
                    dp[l + cost[k]] = max(dp[l + cost[k]], dp[l] + value[k]);
                }
            }
            int MAX = 0;
            rep(k, 0, money[i] + 1) MAX = max(MAX, dp[k]);
            money[j] = max(money[j], money[i] + MAX);
        }
    }
    cout << money[d - 1] << endl;
}


Measured memory_bytes: 3556
#include <bits/stdc++.h>
#define lli long long int
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,a,n) for(int i = a; i < n; i++)
#define s(n) cin >> n
#define csl ios_base::sync_with_stdio(false); cin.tie(NULL)
#define rsz(x,n) x.clear(); x.resize(n)
#define rrsz(x,a,n) x.clear(); x.resize(n,a)
#define wt while(true)
#define all(x) x.begin(),x.end()
#define pb push_back
#define ls(x) ((2*(x)) + 1)
#define rs(x) ((ls(x)) + 1)
#define md(a,b) (((a) + (b))/2)
#define INF (1e9 + 7)
using namespace std;
lli query(lli index,lli l,lli r,lli cl,lli cr,lli a[])
{
    if(l>cr||cl>r)
    return 0;
    if(cl<=l&&r<=cr)
    return a[index];
    lli mid=(l+r)/2;
    return max(query(index*2,l,mid,cl,cr,a),query(2*index+1,mid+1,r,cl,cr,a));
}
lli update(lli index,lli l,lli r,lli h,lli val,lli a[])
{
    if(l==r){
    return a[index]=max(a[index],val);}
    lli mid=l+r;
    mid/=2;
    if(h<=mid)
    a[index]=max(update(2*index,l,mid,h,val,a),a[index]);
    else
    a[index]=max(update(2*index+1,mid+1,r,h,val,a),a[index]);
}
int main()
{
    lli  n;
    s(n);
    lli a[4*n+1]={0};
    lli h[n+1]={0};
    lli val[n+1]={0};
    rep(i,n){
    s(h[i+1]);}
    rep(i,n){
    s(val[i+1]);}
    vector<lli>b(n+2);
    reps(f,1,n+1)
    {
        b[f]=val[f]+query(1,1,n,0,h[f]-1,a);
        update(1,1,n,h[f],b[f],a);
    }
    cout<<query(1,1,n,1,n,a);
    return 0;
}

Measured memory_bytes: 11136
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define REP(i, n) for(int i = 0;i < (n);i++)
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const int mod=1000000007 ;
const llint inf=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-10;
template <class T,class U>bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	int h,w,n;cin>>h>>w>>n;
	cout<<(n+max(h,w)-1)/max(h,w)<<endl;
}

Measured memory_bytes: 888
/**
 *   author: malviyanshiv
 *   created: 01 May 2019  15:10:45
**/

#include <bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for(int i = a; i < b; i++)
#define RREP(i, a, b) for(int i = a-1; i >= b; i--)
#define FORE(a) for(auto ele : a )
#define ALL(a) begin(a), end(a)
#define RPB(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define PB push_back
#define MP make_pair
#define MOD 1000000007
#define INF 0x7fffffff
#define LINF 2000000000000000007
#define F first
#define S second
#define TC int t; cin >> t; while(t--)
#define SET(a,b) memset(a,b,sizeof(a))

#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif

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


void optimizeIO(){
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
}

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

int main(){
	optimizeIO();

	int n;
	cin >> n;
	vector<int> pre(n+1), suf(n+1), arr(n+1);
	REP(i, 1, n+1)
		cin >> arr[i];
	pre[0] = suf[n] = 0;
	REP(i, 1, n+1)
		pre[i] = gcd(pre[i-1], arr[i]);

	for(int j = n-1; j >= 0; j--)
		suf[j] = gcd(suf[j+1], arr[j+1]);
	
	int mg = suf[1];
	REP(i, 1, n){
		mg = max(mg, gcd(pre[i], suf[i+1]));
	}

	/*cout << " pre " << endl;
	for(int i : pre )
		cout << i << " ";
	cout << endl;
	cout << " suf " << endl;
	for(int i : suf )
		cout << i << " ";
	cout << endl;*/
	cout << mg << endl;
	return 0;
}

Measured memory_bytes: 1408