akhauriyash/Code-Regression huggingface dataset:
#include <string>
#include <cstring>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

#define I(n,m) if(find(v.begin(),v.end(),make_pair(n,m))==v.end())ret|=D(n,m,v);
typedef vector<pair<int,int> >V;
char m[99][99];

int D(int i,int j,V&v){
	if(m[i][j]=='B')return 1;
	if(m[i][j]=='W')return 2;
	if(m[i][j]=='X')return 0;
	int ret=0;
	v.push_back(make_pair(i,j));
	I(i-1,j)I(i+1,j)I(i,j-1)I(i,j+1)
	return ret;
}

main(){
	int w,h,i,j,r,s;
	for(;scanf("%d%d",&w,&h),w;printf("%d %d\n",r,s)){
		for(memset(m,'X',sizeof(m)),r=s=0,i=1;i<=h;i++)scanf("%s",m[i]+1),m[i][w+1]='X';
		for(i=1;i<=h;i++)for(j=1;j<=w;j++)if(m[i][j]=='.'){
			V v;for(int x=D(i,j,v),k=0;k<v.size();k++)
				m[v[k].first][v[k].second]=x;
		}
		for(i=1;i<=h;i++)for(j=1;j<=w;j++)
			if(m[i][j]==1)r++;
			else if(m[i][j]==2)s++;
	}
}

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

#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

#define int long long
using namespace std;
const int INF = 2e16;
const int MOD = 1e9 + 7;
const int MB = 20;


void solve() {
	int n, k;
	cin >> n >> k;
	int r, s, p;
	cin >> r >> s >> p;
	string S;
	cin >> S;

	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (i >= k && S[i - k] == S[i]) {
			S[i] = '-';
		}
		else {
			if (S[i] == 'p') ans += s;
			else if (S[i] == 'r') ans += p;
			else ans += r;
		}
	}
	cout << ans;
}

signed main() {
	/*
	freopen("search.in", "r", stdin);
	freopen("search.out", "w", stdout);
	*/
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << fixed;
	cout.precision(12);
	solve();
}

Measured memory_bytes: 512
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            long ans = 0;

            for (int i = 1; i <= n; i++) {
                if (i % 3 == 0 && i % 5 == 0) {
                    continue;
                } else if (i % 3 == 0) {
                    continue;
                } else if (i % 5 == 0) {
                    continue;
                } else {
                    ans += i;
                }

            }

            // 出力
            out.println(ans);

        }

    }
}



Measured memory_bytes: 35868
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define _rep(i,m,n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;

int main(){
   ll n; cin >> n;
   pair<ll,ll> a[n + 100]; 
   rep(i,n){
      cin >> a[i].second >> a[i].first; 
   }
   sort(a, a + n);
   
   ll time_sum = 0;
   rep(i,n){
      time_sum += a[i].second;
      if(time_sum > a[i].first){
         cout << "No" << endl;
         return 0;
      }
   }
   cout << "Yes" << endl;
   return 0;
}


Measured memory_bytes: 3328
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
long long fac[200005], finv[200005], inv[200005];
vector<long long>dij;
struct edge { long long to, cost; };
vector<vector<edge> >G;

long long mod_pow(long long a, long long b) {
	long long res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}

	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

//↑template↑


stack<int>q;
int main() {
	int n;
	while (cin >> n) {
		if (n != 0) { q.push(n); }
		else { cout << q.top() << endl; q.pop(); }
	}
}


Measured memory_bytes: 3060
from operator import add


class SegmentTreeClass:
    def __init__(self,
                 init_val: 'initial value: iterable',
                 segfunc: 'operation unique in case',
                 ide_ele: 'identity element corresponding init_val' = 0,
                 ):
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.size = 1 << (len(init_val) - 1).bit_length()
        self.tree = self._build(init_val)

    def _build(self, init_val) -> 'tree':
        segfunc = self.segfunc

        tree = [self.ide_ele] * (self.size * 2 - 1)

        for idx, val in enumerate(init_val, self.size - 1):  # set
            # modify val if needed (e.g. str -> ord())
            tree[idx] = val

        for idx in range(self.size - 2, -1, -1):  # build
            tree[idx] = segfunc(tree[idx * 2 + 1], tree[idx * 2 + 2])

        return tree

    def update(self, idx: int, val) -> None:
        tree = self.tree
        segfunc = self.segfunc

        idx += self.size - 1
        # modify val if needed as same as in _build()
        tree[idx] = val
        while idx > 0:
            idx = (idx - 1) // 2
            tree[idx] = segfunc(tree[idx * 2 + 1], tree[idx * 2 + 2])

    def query(self, left: int, right: int) -> 'result':
        left += self.size
        right += self.size
        ret = self.ide_ele  # left >= right: return self.ide_ele
        segfunc = self.segfunc
        tree = self.tree
        while left < right:  # どの段も奇偶...順
            if left & 1:  # odd
                ret = segfunc(ret, tree[left - 1])
                left += 1
            if right & 1:  # odd
                right -= 1
                ret = segfunc(ret, tree[right - 1])
            left >>= 1
            right >>= 1
        return ret


L = 10
n = int(input())
s = map(int, input())

d1 = [0] * L
s1 = SegmentTreeClass(init_val=d1, segfunc=add, ide_ele=0)
d2 = [0] * L
s2 = SegmentTreeClass(init_val=d1, segfunc=add, ide_ele=0)
d3 = [0] * L
s3 = SegmentTreeClass(init_val=d1, segfunc=add, ide_ele=0)

for c in s:
    x = s2.query(0, L)
    s3.update(c, x)

    x = s1.query(0, L)
    s2.update(c, x)

    s1.update(c, 1)

print(s3.query(0, L))

# O(3*N)分からない


Measured memory_bytes: 3316
import java.util.*;
import java.io.*;

public class Main {
	private static int[] goods = {100,101,102,103,104,105};
	private static void solve(){
		//Implement solution here.
		int x = ni();
		int result = rec(x,0);
		System.out.println(result > 0 ? 1 : 0);
	}
	
	private static int rec(int rest, int idx) {		
		if(idx > 5)return 0;
		if(rest%goods[idx] == 0) return 1;
		int tmp = 0;
		int result = 0;
		while(rest - tmp >= 0) {			
			if(rec(rest - tmp, idx + 1) > 0)return 1;
			tmp += goods[idx];
		}
		return result;
	}
	
	//Switch input source (stdin/file)
	private static BufferedReader br;
	public static void main(String[] args){
		br = new BufferedReader(new InputStreamReader(System.in));
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		solve();
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}

Measured memory_bytes: 21588
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

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

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 200010;

int main() {
	int n;
	cin >> n;
	map<ll, int> mp;
	bool ans = true;
	rep(i, n) {
		ll a;
		cin >> a;
		if(mp[a] != 0) ans = false;
		mp[a]++;
	}
	if(ans) cout << "YES" << endl;
	else cout << "NO" << endl;
}


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

using namespace std;

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

	int k;
	cin >> k;
	string s;
	cin >> s;
	if ((int) s.length() <= k) {
		cout << s << '\n';
	} else {
		for (int i = 0; i < k; i++) {
			cout << s[i];
		}
		cout << "...\n";
	}

	return 0;
}



Measured memory_bytes: 3640
N=int(input())
L=[int(i) for i in input().split()]
cnt = 0
for i in range(N):
    for j in range(i+1,N):
        for k in range(j+1,N):
            #print('{}:{}:{}'.format(i,j,k))
            if not ((L[i] == L[j]) or (L[j]==L[k]) or (L[i]==L[k])):
                mx = max(L[i],L[j],L[k])
                s = L[i]+L[j]+L[k]-mx-mx
                if s > 0:
                    cnt += 1
print(cnt)

Measured memory_bytes: 9212
import sys
input = sys.stdin.readline
from collections import deque
from copy import deepcopy
def main():
    N, M, P = map( int, input().split())
    E = []
    rE = [[] for _ in range(N)]
    
    for _ in range(M):
        a, b, c = map( int, input().split())
        a, b = a-1, b-1
        E.append((a,b,c-P))
        rE[b].append(a)
    # 頂点Nに到達する頂点
    G = [False]*N
    G[N-1] = True
    q = deque([N-1])
    while q:
        v = q.popleft()
        for w in rE[v]:
            if G[w] == False:
                G[w] = True
                q.append(w)
    # Bellman-Ford
    V = [None]*N
    V[0] = 0
    I = sum([1 for i in range(N) if G[i] == True])
    for _ in range(I-1):
        for s, t, cost in E:
            if V[s] == None or G[t] == False:
                continue
            if V[t] == None:
                V[t] = V[s] + cost
                continue
            if V[s] + cost > V[t]:
                V[t] = V[s] + cost
    W = deepcopy(V) #[ V[i] for i in range(N)]
    for _ in range(I-1):
        for s, t, cost in E:
            if V[s] == None or G[t] == False:
                continue
            if V[t] == None:
                V[t] = V[s] + cost
                continue
            if V[s] + cost > V[t]:
                V[t] = V[s] + cost
    for i in range(N):
        if W[i] == None or G[i] == False:
            continue
        if V[i] > W[i]: # 頂点iは、頂点Nに到達するので、負（正？）閉路は伝播する
            print(-1)
            return

    print( max(W[-1], 0))
if __name__ == '__main__':
    main()


Measured memory_bytes: 48836
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int,int> pii;
#define int ll
#define fi first
#define se second
#define Sort(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/4
#define INTINF INT_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<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;}
/*----------------------------------------------------------------*/
// const int MOD = 998244353;
// const int MOD = 1000000007;


/*----------------------------------------------------------------*/
signed main(){

	int n;
	cin >> n;

	vector<pii> ab(n);
	vector<pii> ba(n);
	rep(i,n){
		cin >> ab[i].fi >> ab[i].se;
		ba[i] = MP(ab[i].se,ab[i].fi);
	}
	Sort(ab);
	Sort(ba);

	if(n%2 == 0){
		int a1 = ab[n/2-1].fi;
		int a2 = ab[n/2].fi;
		int b1 = ba[n/2-1].fi;
		int b2 = ba[n/2].fi;
		cout << b1+b2-a1-a2+1 << endl;

	}else{
		int a = ab[n/2].fi;
		int b = ba[n/2].fi;
		cout << b-a+1 << endl;
	}

	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=gnu++17 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://pakencamp-2019-day3.contest.atcoder.jp/tasks/pakencamp_2019_day3_c
// rm -r -f test;oj dl https://atcoder.jp/contests/abc169/tasks/abc169_b


Measured memory_bytes: 6424
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        
        // 文字列切り出し
        int ss = 0;
        for(int i = 0; i < s.length(); i++) {
            ss += ctoi(s.charAt(i));
        }
        if(ss%9==0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

    }

    static int ctoi(char c) {
        if ('0' <= c && c <= '9') {
            return (int)(c-'0');
        }
        return -1;
      }
    
}



Measured memory_bytes: 39904
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B;
  cin >> A >> B;
  
  if (A <= 9 && B <= 9) {
    cout << A * B << endl;
  }
  
  else {
    cout << -1 << endl;
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	set<int> s;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		if (s.find(a) == s.end()) s.insert(a);
		else s.erase(a);
	}
	cout << s.size() << endl;
	return 0;
}

Measured memory_bytes: 4992
import collections
import math
N = int(input())

s = list([input() for _ in range(N)])

for i in range(N):
    s_temp=list(s[i])
    s_temp.sort()
    s[i] = str(''.join(s_temp))
    
s_ctr = collections.Counter(s)

cnt=0
for j in s_ctr.values():
    if j>1:
        cnt += math.factorial(j)//(math.factorial(2)*math.factorial(j-2))
    
print(cnt)

Measured memory_bytes: 19820
import sys
import math

# a != b のとき


def count(a, b, N):

    keta = len(str(N))

    cnt = 0

    # k == 1 なら a == b
    if a == b:
        cnt += 1 if a <= N else 0

    if keta == 1:
        return cnt

    # k == 2 なら ba のみ
    if keta == 2:
        cnt += 1 if b * 10 + a <= N else 0
        return cnt

    # k 桁より少ない数の場合 : 好きな数を間に挟む
    for k in range(2, keta):
        cnt += 10**(k - 2)

    # k 桁の数字の場合
    s = N // (10**(keta - 1))
    t = N % 10
    if b > s:
        return cnt
    elif b < s:
        cnt += 10**(keta - 2)
    else:
        tempN = (N - s * (10**(keta - 1)) - t) // 10
        # print(f"tempN {tempN}")
        cnt += (tempN + 1)  # tempN が 1 なら 0,1 を選べる
        if a > t:
            cnt -= 1

    return cnt


def count_aa(a, N):

    keta = len(str(N))

    cnt = 0

    # keta == 1
    if keta == 1:
        return 1 if a <= N[-1] else 0

    cnt += 1  # a

    # k == 2 なら aa のみ
    if keta == 2:
        return cnt + 1 if a <= N[-1] else 0

    # 3桁以上
    # k 桁より少ない数の場合
    for k in range(2, keta):
        cnt += 10**(k - 2)

    # k 桁の数字の場合
    s = N // (10**(keta - 1))
    t = N % 10
    if b > s:
        return cnt
    elif b < s:
        cnt += 10**(keta - 2)
    else:
        tempN = (N - s * (10**(keta - 1)) - t) // 10
        # print(f"tempN {tempN}")
        cnt += (tempN + 1)  # tempN が 1 なら 0,1 を選べる
        if a > t:
            cnt -= 1

    return cnt


N = int(input())

c = 0
for i in range(1,N+1):
    a = int(str(i)[0])
    b = i % 10
    # print(a,b)
    if b == 0:
        continue
    c += count(a,b,N)

print(c)

Measured memory_bytes: 9252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define REP(i, n) for (long long i = 0; i < (n); i++)
struct UnionFind {
    vector<int> parent, size;
    UnionFind(int n) {
        parent.resize(n, -1);
        size.resize(n, 1);
    }
    void unite(int x, int y) {
        if (same(x, y)) {
            return;
        }
        x = root(x);
        y = root(y);
        if (size[x] <= size[y]) {
            swap(x, y);
        }
        parent[y] = x;
        size[x] += size[y];
    }
    bool same(int x, int y) { return (root(x) == root(y)); }
    int root(int x) {
        while (parent[x] != -1) {
            x = parent[x];
        }
        return x;
    }
    int getsize(int x) { return size[root(x)]; }
};
vector<vector<P>> mst(vector<vector<P>> graph) {
    vector<pair<ll, P>> as;
    REP(i, graph.size()) {
        REP(j, graph[i].size()) { as.push_back({graph[i][j].second, {i, graph[i][j].first}}); }
    }
    sort(as.begin(), as.end());
    UnionFind uf(graph.size());
    vector<vector<P>> ans(graph.size());
    REP(i, as.size()) {
        if (!uf.same(as[i].second.first, as[i].second.second)) {
            ans[as[i].second.first].push_back({as[i].second.second, as[i].first});
            ans[as[i].second.second].push_back({as[i].second.first, as[i].first});
            uf.unite(as[i].second.second, as[i].second.first);
        }
    }
    return ans;
}
signed main() {
    int n;
    cin >> n;
    vector<vector<P>> graph(n);
    vector<vector<P>> out;
    vector<P> as;
    ll anssum = 0;
    REP(i, n) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        as.push_back({a, b});
    }
    sort(as.begin(), as.end());
    vector<int> index(n);

    REP(i, n) { index[i] = i; }
    sort(index.begin(), index.end(), [&](int i, int j) { return as[i] < as[j]; });
    // REP(i, n) { cout << index[i] << endl; }
    REP(i, n - 1) {
        graph[index[i]].push_back({index[i + 1], min(abs(as[index[i]].first - as[index[i + 1]].first),
                                                     abs(as[index[i]].second - as[index[i + 1]].second))});
        graph[index[i + 1]].push_back({index[i], min(abs(as[index[i]].first - as[index[i + 1]].first),
                                                     abs(as[index[i]].second - as[index[i + 1]].second))});
    }
    REP(i, n) {
        index[i] = i;
        swap(as[i].first, as[i].second);
    }
    sort(index.begin(), index.end(), [&](int i, int j) { return as[i] < as[j]; });
    REP(i, n - 1) {
        graph[index[i]].push_back({index[i + 1], min(abs(as[index[i]].first - as[index[i + 1]].first),
                                                     abs(as[index[i]].second - as[index[i + 1]].second))});
        graph[index[i + 1]].push_back({index[i], min(abs(as[index[i]].first - as[index[i + 1]].first),
                                                     abs(as[index[i]].second - as[index[i + 1]].second))});
    }
    out = mst(graph);
    //REP(i, n) { cout << index[i] << endl; }
    REP(i, out.size()) {
        REP(j, out[i].size()) { anssum += out[i][j].second; }
    }
    cout << anssum / 2 << endl;
}

Measured memory_bytes: 42724
<?php
while(true){
    $n = trim(fgets(STDIN));
    if($n == 0) break;
    $s = explode(" ",trim(fgets(STDIN)));
    $m = array_sum($s) / $n;
    $t = 0;
    foreach($s as $v){
        $t += pow(($v-$m),2);
    }
    $al = sqrt($t / $n);
    echo sprintf("%.5f",$al)."\n";
}

Measured memory_bytes: 15800
import java.io.*
import java.util.*

var pw = PrintWriter(System.out)
const val NO = "IMPOSSIBLE"
fun solve(A: Long, B: Long){
    if ((A + B) % 2L != 0L){println(NO)}
    else println((A+B)/2L)
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val A = sc.next().toLong()
    val B = sc.next().toLong()
    solve(A, B)
}



Measured memory_bytes: 31396
import sys
sys.setrecursionlimit(1000000)
from collections import deque
h,w=map(int,input().split())
s=[list(input()) for i in range(h)]
c=0
for i in range(w):
    for j in range(h):
        if s[j][i]=='.':
            c+=1
def bfs():
    d=[[float('inf')]*w for i in range(h)]
    dx=[1,0,-1,0]
    dy=[0,1,0,-1]
                
    que=deque([])
    que.append((0,0))
    d[0][0]=0
    
    while que:
        p=que.popleft()
        if p[0]==h-1 and p[1]==w-1:
            print(c-d[h-1][w-1]-1)
            exit()
        for i in range(4):
            nx=p[0]+dx[i]
            ny=p[1]+dy[i]
            
            if 0<=nx and nx<h and 0<=ny and ny<w and s[nx][ny]!='#' and d[nx][ny]==float('inf'):
                que.append((nx,ny))
                d[nx][ny]=d[p[0]][p[1]]+1
    print(-1)

bfs()

Measured memory_bytes: 3444
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

int main() {
	long long int n=0,m,a,b,c,d,e;
	long double z,w;
	string str;
	char ch;
	long long int x[130]={};
	cout << fixed << setprecision(10);
	cin>>str;
	if(str[0]=='+'){n++;}
	else{n--;}
	
	if(str[1]=='+'){n++;}
	else{n--;}
	
	if(str[2]=='+'){n++;}
	else{n--;}
	
	if(str[3]=='+'){n++;}
	else{n--;}
	


	cout<<n;



	cout<<endl;
} 


Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<vector>
#include<cstdio>

using namespace std;

struct P{short c,r;};
struct State{
  int t;
  short pos, remain;
  bool operator < (const State& st) const {
    return t > st.t;
  }
};

const int MAX = 5005;
const int INF = (1<<25);
int T[MAX][MAX];
vector<short> Edge[MAX];
P price[MAX];
int N,K;

void input(){
  scanf("%d %d",&N,&K);
  for(int i = 0; i < N; i++) cin >> price[i].c >> price[i].r;
  for(int i = 0; i < K; i++){
    int a,b;
    scanf("%d %d",&a, &b);
    a--;b--;
    Edge[a].push_back(b);
    Edge[b].push_back(a);
  }
}

void solve(){
  fill(T[0], T[0]+MAX*MAX, INF);
  
  T[0][0] = 0;
  priority_queue<State> Q;
  Q.push((State){0,0,0});
  while(!Q.empty()){
    const State now = Q.top();
    Q.pop();
    
    if(now.t > T[now.pos][now.remain]) continue;
    
    if(now.remain > 0){
      for(int i = 0; i < (int)Edge[now.pos].size(); i++){
	State nex = now;
	nex.pos = Edge[now.pos][i];
	nex.remain--;
	
	if(T[nex.pos][nex.remain] > nex.t){
	  T[nex.pos][nex.remain] = nex.t;
	  Q.push(nex);
	}
      }
    }
    
    State nex = now;
    nex.t += price[now.pos].c; 
    nex.remain = price[now.pos].r;
    if(T[nex.pos][nex.remain] > nex.t){
      T[nex.pos][nex.remain] = nex.t;
      Q.push(nex);
    }
  }
  
  int ans = INF;
  for(int i = 0; i < MAX; i++) ans = min(ans,T[N-1][i]);
  printf("%d\n",ans);
}

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

Measured memory_bytes: 99520
#include<stdio.h>
int main()
{
    int n,m,x,i,a[100],sum1=0,sum2=0,t;
    scanf("%d %d %d",&n,&m,&x);
    for(i=0;i<m;i++)
        scanf("%d",&a[i]);
        t=0;
    for(i=0;i<x;i++)
    {
        if(a[t]==i+1)
        {
            sum1++;t++;
        }
    }
        for(i=x;i<n;i++)
        {
            if(a[t]==i+1)
            {
                sum2++;t++;
            }
        }
        if(sum1<sum2)
            printf("%d\n",sum1);
        else
            printf("%d\n",sum2);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using P=pair<ll, ll>;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
#define PI acos(-1)
#define oo LLONG_MAX
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
/*

*/
struct E{
  ll to, co;
  E(ll to = 0, ll co = 0) : to(to), co(co){}
};

string rev(string S){
  reverse(all(S));
  return S;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  
  ll M;
  cin >> M;
  vector<string> S(M);
  vector<ll> C(M);
  rep(i, M) cin >> S[i] >> C[i];
  rep(i, M){
    S.push_back(rev(S[i]));
    C.push_back(C[i]);
  }
  
  ll n = 1;//木のナンバリング。abcdなら [a]=1 [ab]=2 [abc]=3 [abcd]=4
  vector<vector<ll>> ID(M * 2);
  rep(i, M * 2){
    ll l = S[i].size();
    ID[i].resize(l);
    rep(j, l){
      ID[i][j] = n++;
    }
  }

  vector<vector<E>> G(n);
  rep(i, M * 2){
    ll l = S[i].size();
    rep(j, l){ //j文字目以降があまってる = j文字目までは合致してると仮定
      ll v = ID[i][j];
      rep(ni, M * 2){
        if (i / M == ni / M) continue;
//cout << "i:"<< i << "j:"<< j << " ni:"<< ni << endl;        
        ll nl = S[ni].size();
        // nl:lに対して逆さ文字候補の文字数 l-j:あまってる文字数
        ll w = min(nl, l - j);//w:合致してるだろう文字数
        //[abcd]と[a]があって、すでに[abcd....a]として
        //[bcd]と合致するものを探すとかいうパターンの網羅  
        if (S[i].substr(j, w) != S[ni].substr(0, w)) continue;
        ll u = 0;
//cout<<"w:"<<w<<" nl:"<<nl<<" ni:"<<ni<<endl;
        if (nl > w){//後ろがあまるパターン
          u = ID[ni][w];
        }
        else if (l > j + w){//先頭余るパターン
          u = ID[i][j + w];
        }
        else//あまりなし。空文字列
          u = 0;
//        printf("%d -> %d\n", v, u);
        G[v].emplace_back(u, C[ni]);
      }
    }
  }
  
  vector<ll> dist(n, oo);
  priority_queue<P, vector<P>, greater<P>> q;
  auto push = [&](ll v, ll x){
    if (dist[v] <= x) return;
    dist[v] = x;
    q.emplace(x, v);
  };
  
  rep(i, M) push(ID[i][0], C[i]);
  while(!q.empty()){
    ll x = q.top().first;
    ll v = q.top().second;
    q.pop();
    if (dist[v] != x) continue;
    for (E e: G[v]) push(e.to, x + e.co);
  }
  
  ll ans = dist[0];
  rep(i, M * 2){
    ll l = S[i].size();
    rep(j, l){
      string T = S[i].substr(j);//index[j]以降の文字を出力
      if (T == rev(T)) {
        chmin(ans, dist[ID[i][j]]);
      }
    }
  }
  
  if (ans == oo)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3696
#include <stdio.h>

int main(void)
{
	int a[10];
	int b;
	int i;
	int j;
	
	for (i = 0; i < 10; i++){
		scanf("%d", &a[i]);
	}
	
	for (i = 0; i < 10; i++){
		for (j = 0; j < 10; j++){
			if (a[i] > a[j]){
				b = a[i];
				a[i] = a[j];
				a[j] = b;
			}
		}
	}
	
	for (i = 0; i < 3; i++){
		printf("%d\n", a[i]);
	}
	
	return (0);
}

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

using namespace std;

#define fRead(x)  freopen(x,"r",stdin)
#define fWrite(x) freopen (x,"w",stdout)

#define LL long long
#define ULL unsigned long long
#define ff first
#define ss second
#define pb push_back
#define INF 2e16
#define PI acos(-1.0)
#define mk make_pair

#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define min4(a,b,c,d) min(a,min(b,min(c,d)))
#define max4(a,b,c,d) max(a,max(b,max(c,d)))
#define SQR(a) ((a)*(a))
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define REP(i,b) for(int i=0;i<b;i++)
#define MEM(a,x) memset(a,x,sizeof(a))
#define ABS(x) ((x)<0?-(x):(x))

#define scanI(a) scanf("%d",&a)
#define scanI2(a,b) scanI(a) , scanI(b)
#define scanI3(a,b,c) scanI(a), scanI(b), scanI(c)
#define scanI4(a,b,c,d) scanI(a), scanI(b), scanI(c), scanI(d)

#define scanL(a) scanf("%I64d",&a)
#define scanL2(a,b) scanL(a) , scanL(b)
#define scanL3(a,b,c) scanL(a), scanL(b), scanL(c)
#define scanL4(a,b,c,d) scanL(a), scanL(b), scanL(c), scanL(d)

#define SORT(v) sort(v.begin(),v.end())
#define REV(v) reverse(v.begin(),v.end())

#define FastRead ios_base::sync_with_stdio(0);cin.tie(nullptr);

const int N = 105;

int main()
{
    int n , m;
    cin >> n >> m;
    int c;
    cin >> c;
    if(n > m)swap(n,m);
    int ans = c/m;
    if(c % m != 0)ans++;
    cout << ans << "\n";
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner scn = new Scanner(System.in);
    int K = scn.nextInt();
    int X = scn.nextInt();

    for (int i = X - (K - 1); i <= X + (K - 1); i++) {
      if (i >= -1000000 && i <= 1000000) {
        System.out.printf("%d ", i);
      }
    }

  }

}


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

int main() {
  int a,b,d,r;
  double f;
  cin >>a>>b;
  
  d=a/b;
  r=a%b;
  f=a*1.0/b;
  cout <<d<<" "<<r<<" "<<fixed<<setprecision(5)<<f<< endl;
  
    return 0;
}



Measured memory_bytes: 3224
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

MAX = 2000
MOD = int(1e9) + 7
factors = [0] * MAX
primes = []


def p():
    ps = [True] * MAX

    for i in range(2, MAX):
        j = 2 * i
        if not ps[i]:
            continue
        primes.append(i)

        while j < MAX:
            ps[j] = False
            j += i


def fac(x):
    for p in primes:
        while x != 1 and x % p == 0:
            factors[p] += 1
            x //= p


N = int(input())

p()
for i in range(2, N + 1):
    fac(i)

ans = 1
for f in factors:
    ans = ans * (f + 1) % MOD

print(ans)

Measured memory_bytes: 39536
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
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 V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    int N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    vint memo(N + 1); //memo[i] := 0~iまでに'AC'が何個現れるか
    for (int i = 0; i < N; i++)
    {
        if (S[i] == 'A' and S[i + 1] == 'C')
            memo[i + 1] = memo[i] + 1;
        else
            memo[i + 1] = memo[i];
    }
    vint l(Q), r(Q);
    for (int i = 0; i < Q; i++)
    {
        cin >> l[i] >> r[i];
        r[i]--;
        l[i]--;
    }
    for (int i = 0; i < Q; i++)
    {
        cout << memo[r[i]] - memo[l[i]] << endl;
    }

    return 0;
}

Measured memory_bytes: 2256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		//全体のボールの数
		long n = sc.nextLong();
		//青いボールの数
		long a = sc.nextLong();
		//赤いボールの数
		long b = sc.nextLong();

		//小数点切り捨てた結果
		long num = n / (a + b);

		num = num * a;

		long amari = n % (a + b);

		//numが入力した値の比較判定
		if (amari <= a) {
			num += amari;

		} else if (amari > a) {
			num += a;
		}
		System.out.println(num);

		//System.out.println(num * a + Math.min(amari, a));

		sc.close();
	}

}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()

int main(){
    string S;
    cin>>S;
    string H;
    if(S.length()%2==1){
        cout<<"No"<<endl;
        return 0;
    }
    int a=S.length()/2;
    rep(i,a){
        H+="hi";
    }

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

    return 0;
}

//a=97,z=122

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int h,w;
	while(1){
	scanf("%d %d", &h, &w);
	if(h == 0 && w == 0)	break;
	int i, j;
	for ( i = 0; i < h; i++ ){
    	for ( j = 0; j < w; j++ ){
        	if(i != 0 && i != (h-1) && j != 0 && j != (w-1)){
           	 printf(".");
       		 } else {
         	   printf("#");
        	}
    	}
    	printf("\n");
	}
	printf("\n");
	}
return 0;
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 7;

int main()
{
	ios::sync_with_stdio(false);

	ll a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a+3);
	if (a[0] % 2 == 0 || a[1] % 2 == 0 || a[2] % 2 == 0)
		cout << "0\n";
	else
		cout << a[0] * a[1] << "\n";

	return 0;
}

Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = []
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', (line) => {
  lines.push(line);
});

reader.on('close', () => {
 var s = lines[0].split('');
 var sset = new Set(s);
 var sarray = Array.from(sset);
 sarray.sort();
 var alpha = ['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'];

 var ans = alpha.filter(function(value){
   return sarray.indexOf(value) == -1;
 });
 if(ans[0] == undefined){
   console.log('None');
 }else{
   console.log(ans[0]);
 }
});

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

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(NULL);
#define endl            "\n"
#define NUM             100005
typedef long long ll;

map<string,int>mp;

int main()
{
    FastRead

    ll n,mx=INT_MIN;
    set<string>st;

    cin>>n;

    for(ll i=0;i<n;i++)
    {
        string s;
        cin>>s;
        mp[s]++;
    }

    for(auto it : mp)
    {
        if(it.second>mx)
        {
            st.clear();
            st.insert(it.first);
            mx = it.second;
            continue;
        }
        if(it.second==mx)
        {
            st.insert(it.first);
            continue;
        }
    }

    for(auto it:st)
        cout<<it<<endl;
}


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

int main()
{
  string a, b, c;
  cin >> a >> b >> c;
  cout << ((a[a.length() - 1] == b[0] && b[b.length() - 1] == c[0]) ? "YES" : "NO");
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.stream.IntStream;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int offsetX = 0;
            int offsetY = 0;
            int sum = 0;
            for (int i = 0; i < 8; i++) {
                String text = sc.next();
                for (int j = 0; j < 8; j++) {
                    if (text.charAt(j) == '1') {
                        if (sum == 0) {
                            offsetX = j;
                            offsetY = i;
                            sum++;
                        } else {
                            sum += i * 4 - offsetY * 4 + j - offsetX + 1;
                        }
                    }
                }
            }
            char answer = 0;
            switch (sum) {
            case 14:
                answer = 'A';
                break;
            case 28:
                answer = 'B';
                break;
            case 10:
                answer = 'C';
                break;
            case 18:
                answer = 'D';
                break;
            case 16:
                answer = 'E';
                break;
            case 22:
                answer = 'F';
                break;
            case 12:
                answer = 'G';
                break;
            }
            System.out.println(answer);
        }
    }
}


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

int main() {
    int x[6];
    cin >> x[1] >> x[2] >> x[3] >> x[4] >> x[5];
    int i;
    for(i=1;i<=5;i++)
        if(x[i] == 0)
            break;
    cout << i;        
}

Measured memory_bytes: 3588
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define REP1(j,n) for(int j=0;j<(int)n;++j)
#define REPD(i,n) for(int i=n;i>=0;--i)
#define REPD1(j,n) for(int j=n;j=>0;--j)
#define REPS(i,n) for(int i=1;i<=(int)n;++i)
#define REPS1(j,n) for(int j=1;j<=(int)n;++j)
#define rep(i,a,n) for(int i=a;i<=(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;

int main(void) {
	int n;
	string s;
	cin >> n;
	cin >> s;
	int ans = 0,cnt=0;
	REP(i, n) {
		if (s[i] == 'I') {
			cnt++;
			ans = max(ans, cnt);
		}
		else {
			cnt--;
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;
void yesno(bool ok, string yes = "Yes", string no = "No") {
    if (ok) {
        cout << yes << endl;
    } else {
        cout << no << endl;
    }
}

ll two(ll num) {
    if (num == 0) {
        return 0;
    }
    ll ans = 0;
    while (num % 2 == 0) {
        num /= 2;
        ans++;
    }
    return ans;
}

ll solve01(string s, char c) {
    ll len = s.size();
    ll lennum = 0;
    REP(i, 1, len) {
        lennum += two(i);
    }
    ll tmpnum = lennum;
    bool b = false;
    REP(i, 0, len) {
        ll p = lennum - tmpnum;
        if (p == 0 && s[i] == c) {
            b = !b;
        }
        tmpnum += two(i + 1);
        tmpnum -= two(len - 1 - i);
    }
    if (b) {
        return 1;
    } else {
        return 0;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    string ss;
    cin >> ss;
    string s;
    REP(i, 0, N - 1) {
        ll num = abs(ss[i] - ss[i + 1]);
        s += to_string(num);
    }
    N--;
    // cout << s << endl;
    bool one = false;
    REP(i, 0, N) {
        if (s[i] == '1') {
            one = true;
        }
    }
    ll ans = inf;
    if (one) {
        REP(i, 0, N) {
            if (s[i] == '2') {
                s[i] = '0';
            }
        }
        ans = solve01(s, '1');
    } else {
        ans = solve01(s, '2') * 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3228
#include <iostream>
#include <math.h>
#include <string>
#include <stdio.h>
#include <algorithm>

using namespace std;

int main()
{
	int a[1000];
	int N;
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> a[i];
	}
	for (int i = 0; i < N; i++)
	{
		//偶数
		if (a[i] % 2 == 0)
		{
			//3でも5でも割り切れない
			if (a[i] % 3 != 0 && a[i] % 5 != 0)
			{
				cout << "DENIED" << endl;
				return 0;
			}
		}
	}
	cout << "APPROVED" << endl;
	return 0;
}


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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x%mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
	mint operator+(const mint a) const { return mint(*this) += a; }
	mint operator-(const mint a) const { return mint(*this) -= a; }
	mint operator*(const mint a) const { return mint(*this) *= a; }
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const { return pow(mod - 2); }
	mint& operator/=(const mint a) { return *this *= a.inv(); }
	mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

vector<int>Prime(1000000);
set<int>PrimeList;
void f(int x) {
	for (int i = 2; i*i <= x; i++) {
		int m = 0;
		while (x%i == 0) { // 素数で割り切れなくなるまで割っていく
			m++;//割った個数を配列に足す
			x /= i;
		}
		if (0 != m) {
			Prime[i] = max(Prime[i],m);
			PrimeList.insert(i);
		}
		if (1 == x) {
			break;
		}
	}
	if (1 != x) {
		Prime[x] = max(Prime[x], 1);
		PrimeList.insert(x);
	}
}


int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int n = 0;n < N;++n) {
		cin >> A[n];
	}
	for (int n = 0; n < N; ++n) {
		f(A[n]);
	}
	mint lcm = 1;
	for (std::set<int>::iterator it = PrimeList.begin(); it != PrimeList.end(); ++it){
		mint p = (mint)*it;
		lcm *= p.pow((long long)Prime[*it]);
	}
	mint ans = 0;
	for (int n = 0; n < N; ++n) {
		ans += lcm / (mint)A[n];
	}
	cout << ans <<endl;
	return 0;
}

Measured memory_bytes: 7516
// {{{ by shik
#include <bits/stdc++.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-function"
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REP1(i, a, b) for (int i = (a); i <= int(b); i++)
#define MP make_pair
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef pair<int, int> PII;
typedef vector<int> VI;

namespace { namespace shik {

template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%" SCNd64, &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }

template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%" PRId64, x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }

#ifdef SHIK
#include "dump.hpp"
#else
#define dump(...)
#endif

template<class T, class F = less<T>> void sort_uniq(vector<T> &v, F f = F()) { sort(begin(v), end(v), f); v.resize(unique(begin(v), end(v)) - begin(v)); }
template<class T> inline T bit(T x, int i) { return (x >> i) & 1; }
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

// }}}

const int N=20010;
int n,a[N];

bool solve( int x ) {
    REP(i,n-1) {
        while ( x%2!=0 && x%3!=0 && x%5!=0 ) x++;
        a[i]=x++;
    }
    int s=0;
    REP(i,n-1) s+=a[i];
    dump(s%30,x);
    while ( x<=30000 && (s+x)%30!=0 ) {
        x++;
        while ( x%2!=0 && x%3!=0 && x%5!=0 ) x++;
    }
    if ( x<=30000 ) {
        a[n-1]=x;
        return 1;
    } else {
        return 0;
    }
}

void main() {
    R(n);
    int x=1;
    while ( !solve(x) ) x++;
    W(VI(a,a+n));
    int s=0;
    REP(i,n) s+=a[i];
    REP(i,n) assert(__gcd(a[i],s)!=1);
}

// {{{ main
}}
int main() { shik::main(); return 0; }
// }}}


Measured memory_bytes: 512
#include<iostream>
#include<cmath>

#define N 100000

using namespace std;


int main(void){

  int n,count = 0;
  while(cin >> n){

    for(int i = 0; i <= 9;i++){
      for(int j = 0; j <= 9;j++){
        for(int k = 0; k <= 9;k++){
          for(int l = 0 ;l <= 9;l++){
            if(n == i+j+k+l){
              count++;
            }
          }
        }
      }
    }
    cout << count << endl;
    count = 0;
  }



  return 0;
}

Measured memory_bytes: 3052
import sys
from collections import deque

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    H, W = map(int, input().split())
    S = [list(input()) for _ in range(H)]

    start = []
    for h in range(H):
        for w in range(W):
            if S[h][w] != "#":
                start.append([h, w])

    res = 0
    for sh, sw in start:
        maze = [[f_inf] * W for _ in range(H)]
        maze[sh][sw] = 0
        que = deque([[sh, sw]])
        while que:
            h, w = que.popleft()
            for dh, dw in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
                next_h, next_w = h + dh, w + dw
                if next_h < 0 or next_h >= H or next_w < 0 or next_w >= W:
                    continue
                elif S[next_h][next_w] == "#":
                    continue
                else:
                    if maze[next_h][next_w] > maze[h][w] + 1:
                        maze[next_h][next_w] = maze[h][w] + 1
                        que.append([next_h, next_w])
        ma = 0
        for h in range(H):
            for w in range(W):
                if S[h][w] != "#":
                    ma = max(ma, maze[h][w])
        res = max(res, ma)
    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9376