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

class SegTreeLazy {
    using T = long long int;
    static const T op(const T& lhs, const T& rhs) { // binary operator***
        return lhs + rhs;
    }
    constexpr static T unit = 0; // unit***
    const int N;
    T *data, *delay;
    int calc_size(int n) { int ret = 1; while (n > ret) ret *= 2; return ret; }
    void force(int i, int l, int r) {
        if (delay[i]) {
            data[i] += delay[i] * (r - l); // force***
            if (r - l > 1) {
                delay[2*i+1] += delay[i];
                delay[2*i+2] += delay[i];
            }
            delay[i] = 0;
        }
    }
public:
    explicit SegTreeLazy(int n) : N(calc_size(n)) {   // [0, n-1]
        data = new T[2*N-1]();
        delay = new T[2*N-1]();
    }
    ~SegTreeLazy() { delete[] data; delete[] delay; }
    T query(int a, int b, int i = -1, int l = -1, int r = -1) {
        if (i == -1) { i = 0; l = 0; r = N; }
        if (r <= a || b <= l) return unit;
        force(i, l, r);
        if (a <= l && r <= b) return data[i];
        const int m = (l+r)/2;
        if (r - l == 1) return data[i];
        if (b <= m) return query(a, b, 2*i+1, l, m);
        if (m <= a) return query(a, b, 2*i+2, m, r);
        T v1 = query(a, b, 2*i+1, l, m),
            v2 = query(a, b, 2*i+2, m, r);
        return op(v1, v2);
    }
    void add(int a, int b, T v, int i = -1, int l = -1, int r = -1) {
        if (i == -1) { i = 0; l = 0; r = N; }
        if (r <= a || b <= l) return;
        if (a <= l && r <= b) { delay[i] += v; force(i, l, r); return; }
        add(a, b, v, 2*i+1, l, (l+r)/2); force(2*i+1, l, (l+r)/2);
        add(a, b, v, 2*i+2, (l+r)/2, r); force(2*i+2, (l+r)/2, r);
        data[i] = op(data[2*i+1], data[2*i+2]);
    }
    T get(int i) { return query(i, i+1); }
    void init(int *a, int n) {
        for (int i = 0; i < n; i++) data[i+N-1] = a[i];
        for (int i = N-2; i >= 0; i--) data[i] = op(data[2*i+1], data[2*i+2]);
    }
};

int main() {
    int n, q; scanf("%d %d", &n, &q);
    int c[n]; for (int i = 0; i < n; i++) scanf(" %d", &c[i]), c[i]--;
    vector<pair<int, int> > query[n];
    for (int i = 0; i < q; i++) {
        int l, r; scanf(" %d %d", &l, &r);
        l--; r--;
        query[r].push_back({l, i});
    }
    int ans[q], pos[n];
    fill(pos, pos+n, 0);
    SegTreeLazy st(n+1);
    for (int i = 0; i < n; i++) {
        st.add(pos[c[i]], i+1, 1);
        pos[c[i]] = i+1;
        for (auto [l, idx] : query[i]) {
            int a = st.get(l);
            ans[idx] = a;
        }
    }
    for (int i = 0; i < q; i++) printf("%d\n", ans[i]);
}


Measured memory_bytes: 47688
#include <cstdio>
#include <vector>
#include <cassert>
#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))
#define repeat_from(i,m,n) for (int i = (m); (i) < int(n); ++(i))
using ll = long long;
using namespace std;

ll powmod(ll x, ll y, ll p) { // O(log y)
    assert (0 <= x and x < p);
    assert (0 <= y);
    ll z = 1;
    for (ll i = 1; i <= y; i <<= 1) {
        if (y & i) z = z * x % p;
        x = x * x % p;
    }
    return z;
}
ll inv(ll x, ll p) { // p must be a prime, O(log p)
    assert ((x % p + p) % p != 0);
    return powmod(x, p-2, p);
}
template <int mod>
int fact(int n) {
    static vector<int> memo(1,1);
    if (memo.size() <= n) {
        int l = memo.size();
        memo.resize(n+1);
        repeat_from (i,l,n+1) memo[i] = memo[i-1] *(ll) i % mod;
    }
    return memo[n];
}
template <int mod>
int inv_fact(int n) {
    static vector<int> memo(1,1);
    if (memo.size() <= n) {
        int l = memo.size();
        memo.resize(n+1);
        repeat_from (i,l,n+1) if (i >= 1) memo[i] = inv(fact<mod>(i), mod);
    }
    return memo[n];
}
template <int mod>
int choose(int n, int r) { // O(n) at first time, otherwise O(\log n)
    if (n < r) return 0;
    r = min(r, n - r);
    return fact<mod>(n) *(ll) inv_fact<mod>(n-r) % mod *(ll) inv_fact<mod>(r) % mod;
}

constexpr int mod = 1e9+7;
int main() {
    int n, m, k; scanf("%d%d%d", &n, &m, &k);
    vector<int> dp(k+1);
    repeat (i, k+1) {
        ll acc = 0;
        repeat (j, i) {
            int l = i - j;
            acc += dp[j] *(ll) choose<mod>(2*l, l) % mod;
        }
        dp[i] = (choose<mod>(2*i-1, i) - acc % mod + mod) % mod;
    }
    ll result = 0;
    repeat (i, k+1) {
        int l = k - i;
        ll a = 0;
        repeat (j, i+1) {
            a += dp[j] *(ll) choose<mod>(n + 2*(i-j)+1, i-j) % mod;
        }
        a = (choose<mod>(n + 2*i, i) -(ll) a % mod + mod) % mod;
        ll b = 0;
        repeat (j, l+1) {
            b += dp[j] *(ll) choose<mod>(m + 2*(l-j)+1, l-j) % mod;
        }
        b = (choose<mod>(m + 2*l, l) -(ll) b % mod + mod) % mod;
        result += choose<mod>(n + m + 2*k, n + 2*i) *(ll) a % mod * b % mod;
    }
    printf("%lld\n", result % mod);
    return 0;
}

Measured memory_bytes: 4324
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned ui;
typedef unsigned long long ul;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef pair<bool, bool> pbb;
typedef vector<int> vi;
#define pb push_back
#define fi first
#define se second
#define mid ((l + r) >> 1)
#define ls (i << 1)
#define rs (i << 1 | 1)
#define enum(i, j, k) for(int i = j; i <= (k); i ++)
#define open(i, j, k) for(int i = j; i <  (k); i ++)
#define dec(i, j, k)  for(int i = j; i >= (k); i --)
#define ae(x) for(node *p = h[x]; p; p = p->nxt)
#define fill(x, k) memset(x, k, sizeof x)
#define copy(x, y) memcpy(x, y, sizeof x)
#define fio(x) freopen(x".in", "r", stdin); freopen(x".out", "w", stdout);
template <class T> bool chkmin(T &x, T y)
{ return y < x ? (x = y , true) : false; }
template <class T> bool chkmax(T &x, T y)
{ return y > x ? (x = y , true) : false; }
void __init()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(16);
    srand(time(0) ^ ui(ul(new char)));
}
/* default code ends here */
const int maxn = 510;
ll arr[maxn][maxn], sum[maxn][maxn];
int main()
{
	__init();
	int n, m, a, b;
	cin >> n >> m >> a >> b;
	enum(i, 1, n)
		enum(j, 1, m)
		{
			sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
			if(i < a || j < b)
				arr[i][j] = 1000;
			else
				arr[i][j] = -(sum[i][j] - sum[i - a][j] - sum[i][j - b] + sum[i - a][j - b]) - 1;
			assert(-1e9 <= arr[i][j] && arr[i][j] <= 1e9);
			sum[i][j] += arr[i][j];
		}
	if(sum[n][m] <= 0)
		return cout << "No\n", 0;
	cout << "Yes\n";
	enum(i, 1, n)
	{
		enum(j, 1, m)
			cout << arr[i][j] << ' ';
		cout << '\n';
	}
	return 0;
}


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

using namespace std;
using LL = long long;
int main()
{
    int a,b,c,d,e,f,g,h;
    cin >> a >> b >> c >> d >> e >> f >> g >> h;
    int ha = a*e + a/10*g + b*f + b/20*h;
    int ta = c*e + c/10*g + d*f + d/20*h;
    if(ha == ta){
        cout<<"even"<<endl;
    }
    if(ha > ta){
        cout<<"hiroshi"<<endl;
    }
    if(ha < ta){
        cout<<"kenjiro"<<endl;
    }
    return 0;
}



Measured memory_bytes: 3088
import java.util.Scanner;

public class Main {
	  
	public static void main(String args[]) {
		    Scanner scanner = new Scanner(System.in);
		    
		    int a = scanner.nextInt();
		    int b = scanner.nextInt();
		    
		    if( a <= b ) 
		    {
		    	System.out.println(a);
		    }
		    else 
		    {
		    	System.out.println(a - 1);
		    }
		    
		    scanner.close(); }
		  }

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

int main()
{
    int n;
    cin >> n;
    int arr[n];
    for(int i=0;i<n;i++)
    cin >> arr[i];
    int count=0,max=0;
    for(int i=0;i<n-1;i++)
    {
        if(arr[i]>=arr[i+1])
        count++;
        else
        count=0;
        if(max<count)
        max=count;
    }
    cout << max << endl;
    return 0;
}


Measured memory_bytes: 640
"""
22.40.00

"""

N,X = map(int, input().split())
# 層の数 : 2**(N+2) - 3
# パティの数 : 2**(N+1) - 1
# 肉の数 : 2**(N+1) - 2
l = N
cnt = 0
while l >= 0:
    n_all = 2**(l+2) - 3
    p_all = 2**(l+1) - 1
    if l == 0:
        cnt += 1
    if X == 1:
        break
    elif X == n_all:
        cnt += p_all
        break
    elif X == (n_all+1)//2:
        cnt += (p_all+1) // 2
        break
    elif 1 < X < (n_all+1)//2:
        X -= 1
    elif (n_all+1)//2 < X < n_all:
        X -= (n_all+1)//2
        cnt += 2**l
    l -= 1

print(cnt)



Measured memory_bytes: 3064
#include <iostream>
#include<algorithm>
#include<string>
#include<vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
using namespace std;

int main()
{
	int n,cnt=0,Maxcnt=-10000000;
	string s;
	cin >> n >> s;
	for (int i=0; i < n; i++) {
		if (s[i] == 'I')cnt++;
		else cnt--;
		Maxcnt = max(Maxcnt,cnt);
	}
	cout << (Maxcnt<0 ? 0 : Maxcnt) << endl;
}




Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

def main():
    n = int(input())
    a = [int(_) for _ in input().split()]
    seek = 1

    for i in range(n):
        if a[i] == seek:
            seek += 1

    if seek == 1:
        ans = -1
    else:
        ans = n + 1 - seek

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 72140
def abc126_d():
    import sys
    sys.setrecursionlimit(10010010)
    read = sys.stdin.buffer.read
    inp = iter(map(int, read().split()))

    N = next(inp)
    G = [[] for _ in range(N)]
    for _ in range(N-1):
        u = next(inp) - 1
        v = next(inp) - 1
        w = next(inp)
        G[u].append((v, w))
        G[v].append((u, w))

    color = [-1] * N
    color[0] = 0

    def dfs(u):
        for v, w in G[u]:
            if color[v] != -1: continue
            if w % 2 == 0:
                color[v] = color[u]
            else:
                color[v] = abs(color[u] - 1)
            dfs(v)

    dfs(0)
    print(*color, sep='\n')

if __name__ == '__main__':
    abc126_d()

Measured memory_bytes: 112092
n, k = map(int, input().split())
h = list(map(int, input().split()))

dp = [1 << 30] * n
dp[0] = 0
for i in range(1, n):
    mn = 1 << 30
    for j in range(1, k + 1):
        if i - j < 0:
            continue
        mn = min(mn, dp[i - j] + abs(h[i] - h[i - j]))
    dp[i] = mn

print(dp[-1])

Measured memory_bytes: 52448
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()

class SegmentTree(object):
    def __init__(self, A, dot, unit):
        n = 1 << (len(A) - 1).bit_length()
        tree = [unit] * (2 * n)
        for i, v in enumerate(A):
            tree[i + n] = v
        for i in range(n - 1, 0, -1):
            tree[i] = dot(tree[i << 1], tree[i << 1 | 1])
        self._n = n
        self._tree = tree
        self._dot = dot
        self._unit = unit

    def __getitem__(self, i):
        return self._tree[i + self._n]

    def update(self, i, v):
        i += self._n
        self._tree[i] = v
        while i != 1:
            i >>= 1
            self._tree[i] = self._dot(self._tree[i << 1], self._tree[i << 1 | 1])

    def add(self, i, v):
        self.update(i, self[i] + v)

    def sum(self, l, r):
        l += self._n
        r += self._n
        l_val = r_val = self._unit
        while l < r:
            if l & 1:
                l_val = self._dot(l_val, self._tree[l])
                l += 1
            if r & 1:
                r -= 1
                r_val = self._dot(self._tree[r], r_val)
            l >>= 1
            r >>= 1
        return self._dot(l_val, r_val)

from operator import add
def resolve():
    n = int(input())
    color = [[] for _ in range(n)]
    for v, c in enumerate(map(int, input().split())):
        color[c - 1].append(v)
    E = [[] for _ in range(n)]
    for _ in range(n - 1):
        u, v = map(int, input().split())
        u -= 1; v -= 1
        E[u].append(v)
        E[v].append(u)

    # Euler tour
    start = [-1] * n
    end = [-1] * n
    count = 0
    stack = [(~0, -1), (0, -1)]
    while stack:
        v, p = stack.pop()
        if v >= 0:
            start[v] = count
            count += 1
            for nv in E[v]:
                if nv == p:
                    continue
                stack.append((~nv, v))
                stack.append((nv, v))
        else:
            end[~v] = count

    f = lambda x : x * (x + 1) // 2
    ans = [f(n)] * n
    tree = SegmentTree([1] * n, add, 0)
    history = []
    for c in range(n):
        for v in sorted(color[c], key = lambda x : start[x], reverse = 1):
            count = 1
            for nv in E[v]:
                if start[v] > start[nv]: # nv == p
                    continue
                s = tree.sum(start[nv], end[nv])
                ans[c] -= f(s)
                count += s
            tree.add(start[v], -count)
            history.append((start[v], count))
        ans[c] -= f(tree.sum(0, n))
        while history:
            tree.add(*history.pop())

    print(*ans, sep = '\n')
resolve()

Measured memory_bytes: 174432
def judge_format(text):
    former, latter = int(text[:2]), int(text[2:])
    if 1 <= former <= 12 and (latter == 0 or latter > 12):
        return 'MMYY'
    elif 1 <= latter <= 12 and (former == 0 or former > 12):
        return 'YYMM'
    elif 1 <= former <= 12 and 1 <= latter <= 12:
        return 'AMBIGUOUS'
    else:
        return 'NA'
    

def main():
    s = input()
    print(judge_format(s))


main()

Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

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

    int l[10], r[10];
    fill_n(l, 10, -1);
    fill_n(r, 10, -1);
    for(int i = 0; i < 10; i++){
        string c = to_string(i); 
        if(s.find(c) != string::npos){
            l[i] = s.find(c);
            r[i] = s.rfind(c);
        }
    }

    // p1p2p3 となるような3桁の暗証番号を考えてその数を ans としてカウント
    int ans = 0;
    for(int p1 = 0; p1 < 10; p1++){
        if(l[p1] == -1) continue;

        for(int p3 = 0; p3 < 10; p3++){
            if(r[p3] <= l[p1] + 1) continue;

            string str = s.substr(l[p1]+1, r[p3]-l[p1]-1);
            for(int p2 = 0; p2 < 10; p2++){
                if(str.find(to_string(p2)) != string::npos)
                    ans++;
            }
        }
    }

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

Measured memory_bytes: 3716
//From Naruto to Hokage
//#include <RJ>
#include<bits/stdc++.h>
using namespace std;

#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=100005;
void solve(){
    string s,t;
    cin>>s>>t;
    ll ans=0;
    rep(i,0,2){
        if(s[i]==t[i]) ans++;
    }
    cout<<ans;
}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    time
    return 0;
}

Measured memory_bytes: 256
inputs = input().split(' ')
 
N = int(inputs[0])
M = int(inputs[1])
 
pattern_N = 0
pattern_M = 0
 
if N > 0:
  pattern_N = N * (N - 1) // 2 
  
if M > 0:
  pattern_M = M * (M - 1) // 2 
  
print(pattern_N + pattern_M)

Measured memory_bytes: 3060
s = input()

flag = 1

l = len(s)

for i in range((l-1)//2):
    if s[i] == s[(l-1)//2 - 1-i]:
        continue
    else:
        flag = 0
        break

if s[:(l-1)//2] != s[(l+3)//2-1:]:
    flag = 0

print("Yes" if flag == 1 else "No")


Measured memory_bytes: 9116
#include<stdio.h>
int main()
{
	int n,a,b,t;
	scanf("%d",&n);
	t=n;
	a=0;
	while(t)
	{
		a+=t%10;
		t/=10;
	}
     if(n%a==0)
     printf("Yes\n");
     else
     printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
	int x,y;
	cin >> x >> y;
	if(x==2 ||y==2)cout << "No" << endl;
	else if((x==1 || x==3 || x==5 || x==7 || x==8 || x==10 || x==12)&&(y==1 || y==3 || y==5 || y==7 || y==8 || y==10 || y==12))
		cout << "Yes" << endl;
	else if((x==4 || x==6 || x==9 || x==11)&&(y==4 || y==6 || y==9 || y==11))
		cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

template <typename T> inline void getint(T &num){
	register int ch, neg = 0;
	while(!isdigit(ch = getchar())) if(ch == '-') neg = 1;
	num = ch & 15;
	while(isdigit(ch = getchar())) num = num * 10 + (ch & 15);
	if(neg) num = -num;
}

int N, K, ans = 0x3f3f3f3f, dis[2005], tope = 0;
struct Edge {int np; Edge *nxt;} E[4005], *V[2005];
struct edge {int u, v;} ed[2005];

inline void addedge(const int &u, const int &v){
	E[++tope].np = v, E[tope].nxt = V[u], V[u] = E + tope;
}

void dfs(const int &u, const int &fa){
	for(register Edge *ne = V[u]; ne; ne = ne->nxt)
		if(ne->np != fa) dis[ne->np] = dis[u] + 1, dfs(ne->np, u);
}

int main(){
	getint(N), getint(K);
	for(register int i = 1; i < N; i++){
		getint(ed[i].u), getint(ed[i].v);
		addedge(ed[i].u, ed[i].v), addedge(ed[i].v, ed[i].u);
	}
	if(K & 1){
		for(register int i = 1; i < N; i++){
			dis[ed[i].u] = 0, dfs(ed[i].u, ed[i].v);
			dis[ed[i].v] = 0, dfs(ed[i].v, ed[i].u); int res = 0;
			for(register int j = 1; j <= N; j++) if(dis[j] > (K >> 1)) res++;
			ans = min(ans, res);
		}
	}
	else{
		for(register int i = 1; i <= N; i++){
			dis[i] = 0, dfs(i, 0); int res = 0;
			for(register int j = 1; j <= N; j++) if(dis[j] > (K >> 1)) res++;
			ans = min(ans, res);
		}
	}
	return printf("%d\n", ans), 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iomanip>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;

#define ld long double
#define ll long long

map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ll N,W;
  cin >> N >> W;

  vector<ll> vec[5]; // vec(5)はダメ
  for(int i=0;i<5;i++) vec[i].clear();

  ll w,v,w0;
  cin >> w0 >> v;
  vec[0].push_back(v);
  for(int i=1;i<N;i++){
    cin >> w >> v;
    vec[w-w0].push_back(v);
  }
  for(int i=0;i<4;i++)sort(vec[i].begin(),vec[i].end(),greater<ll>());

  ll sum[5][120];
  for(int it=0;it<4;it++){
    sum[it][0]=0;
    for(int i=0;i<110;i++){
      sum[it][i+1]=sum[it][i]+(i<vec[it].size()?vec[it][i]:0);
    }
  }

  ll ans=0;
  for(int a=0;a<=N && w0*a <=W; a++){
    for(int b=0;b+a<=N && w0*a+(w0+1)*b <=W; b++){
      for(int c=0;c+b+a<=N && w0*a+(w0+1)*b+(w0+2)*c <=W; c++){
        //ll d = min(N-a-b-c, (W-w0*a-(w0+1)*b-(w0+2)*c)/(w0+3));
        //if (d < 0) continue;
        ll d=(W-w0*a-(w0+1)*b-(w0+2)*c)/(w0+3);
        if(d<0)continue;
        ll cnt=sum[0][a]+sum[1][b]+sum[2][c]+sum[3][d];
        if(ans<cnt)ans=cnt;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cerr << head << " ";
  print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
  int val = ((a % mod) + (b % mod)) % mod;
  if (val < 0) { val += mod; }
  a = val;
}

// ------------------------------------------------------------------------------------------

string s;

signed main() {
  cin >> s;
  int n = s.size();

  if (s.size() == 2) {
    if (s[0] == s[1]) {
      cout << 1 << " " << 2 << endl;
    } else {
      cout << -1 << " " << -1 << endl;
    }
    return 0;
  }

  for (int i = 0; i < n-2; i++) {
    string t = s.substr(i, 3);

    set<char> S;
    for (char c : t) {
      S.insert(c);
    }
    if (S.size() == 1 || S.size() == 2) {
      cout << i+1 << " " << i+3 << endl;
      return 0;
    }
  }

  cout << -1 << " " << -1 << endl;

  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()	{
  string a, b;
  cin >> a >> b;
  reverse(b.begin(), b.end());
  if (b == a)
	  cout << "YES" << endl;
  else
	  cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	   c = getchar();
    }
    while(c >= '0' && c <= '9') {
    	res = res * 10 +c - '0';
    	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
    	out(x / 10);
    }
    putchar('0' + x % 10);
}
int W,H;
int64 p[MAXN],q[MAXN],ans;
int id[2][MAXN],c[2];
void Solve() {
    read(W);read(H);
    for(int i = 0 ; i < W ; ++i) {
        id[0][i] = i;
        read(p[i]);
    }
    for(int i = 0 ; i < H ; ++i) {
        id[1][i] = i;
        read(q[i]);
    }
    sort(id[0],id[0] + W,[](int a,int b){return p[a] < p[b];});
    sort(id[1],id[1] + H,[](int a,int b){return q[a] < q[b];});
    int p1 = 0,p2 = 0;
    for(int i = 1 ; i <= W + H ; ++i) {
        if(p2 >= H || (p1 < W && p[id[0][p1]] < q[id[1][p2]])) {
            ans += 1LL * (H - c[1] + 1) * p[id[0][p1]];
            ++p1;++c[0];
        }
        else {
            ans += 1LL * (W - c[0] + 1) * q[id[1][p2]];
            ++p2;++c[1];
        }
    }
    out(ans);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef set<ll> sl;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second

int main(void) {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    //freopen("in.txt", "r", stdin);
    int n, m;
    cin >> n >> m;
    vector<int> a(n+1);
    vector<bool> b(n+1);
    a[1] = 1;
    b[1] = true;
    rep(i,2,n+1) {
        a[i] = 1;
        b[i] = false;
    }
    rep(iter, 0, m) {
        int i, j;
        cin >> i >> j;

        if(b[i]) b[j] = true;
        a[i]--;
        a[j]++;
        if(!a[i]) b[i] = false;
    }
    int ret = 0;
    rep(i,1,n+1) {
        if(b[i]) ret++;
    }
    cout << ret << '\n';
    return 0;
}


Measured memory_bytes: 640
import math

a,b,h,m = map(float,input().split())

deg_h = h*30 + 30*(m/60)
deg_m = m*6

deg_sub = abs(deg_h - deg_m)
rad_sub = deg_sub*(math.pi/180)

len = math.sqrt(a*a + b*b - 2*a*b*math.cos(rad_sub))

print(len)


Measured memory_bytes: 9432
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
using namespace std;
int main(){
	int A,B,C;
	cin>>A>>B>>C;
	if(A==5&&B==7&&C==5)
	
	{cout<<"YES"<<endl;
	}else if(A==5&&B==5&&C==7){cout<<"YES"<<endl;
	}else if(A==7&&B==5&&C==5){cout<<"YES"<<endl;
	} 
	else{cout<<"NO"<<endl;
	}
	
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <list>
using namespace std;


#define MAX 500000
#define SENTINEL 2000000000
#define INFTY (1<<21)
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2


int main(){
  int N; cin >> N;
  vector<int> A(N);
  for (int i=0; i<N; i++){
    cin >> A[i];
  }
  /*std::uniqueはゴミの手前のポインタを返すので、vector::eraseで後ろのゴミを削除する。これで重複要素のないvectorが得られる。  std::uniqueは隣接する重複要素を削除するが、vectorの長さなどには変更を加えないため、末尾にはゴミが残ることになる。*/
  sort(A.begin(), A.end());
  A.erase(unique(A.begin(), A.end()), A.end()); //最後に削除された要素の次のイテレータを返す
  cout << A.size() << endl;
  return 0;
}

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


int main(){
    ll n,m;
    cin >> n >> m;
    if(2*n>=m)cout << m/2 << endl;
    else{
        cout << n + (m-2*n)/4 << endl;
    }
    return 0;  
}

Measured memory_bytes: 256
import java.util.*;

import static java.lang.System.*;

public class Main {
    final static long prime = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String S = sc.next();

        long charCount[] = new long['z' - 'a' + 1];
        for (int i = 0; i < N; i++) {
            char c = S.charAt(i);
            charCount[c - 'a']++;
        }

        long ans = 1;
        for (int i = 0; i <= 'z' - 'a'; i++) {
            ans = (ans * (charCount[i] + 1)) % prime;
        }
        ans--;

        out.println(ans);
    }
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
string s;	
int freq[26];

int main(){
cin>>s;
	for(int i=0;i<s.size();++i)
	{
		freq[s[i]-'a']++;
		
	}
	for(int j=0;j<26;++j)
		{
		if(freq[j]==0){
		cout<<char(j+97);
		return 0;
		}
		}
		cout<<"None"<<endl;
	return 0;
}

Measured memory_bytes: 512
import numpy as np

n = int(input())
a = []
for i in range(n):
  a.append(int(input()))

max_idx = np.argmax(a)
first = a[max_idx]
a[max_idx] = 0
second = max(a)
a[max_idx] = first

for i in range(n):
  if a[i] == first:
    print(second)
  else:
    print(first)

Measured memory_bytes: 21844
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
#ifdef LOCAL_TEST
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif
    string yes = "Yes", no = "No";
    string s;
    cin >> s;
    rep(i, 2) {
        if(s[i] == s[i+1] && s[i] == s[i+2]) {
            cout << yes << endl;
            return 0;
        }
    }
    cout << no << endl;
    return 0;
}

Measured memory_bytes: 256
from math import sqrt

n = int(input())

tCood = []
for _ in range(n):
	x,y = map(int, input().split())
	tCood.append((x,y))

def dist(c1,c2):
	return(sqrt((c1[0]-c2[0])**2+(c1[1]-c2[1])**2))

distSum = 0
for i in range(n):
	for j in range(i+1,n):
		distSum += dist(tCood[i],tCood[j])

avg = (2*distSum)/n
print(avg)

Measured memory_bytes: 38256
x = gets.to_i
a1 = x / 11
r1 = x - (a1 * 11)                                                                                                           
a = a1 * 2                                                                                                                   
if r1 > 0
  if r1 < 7                                                                                                                  
    a += 1                                                                                                                   
  else                                                                                                                       
    a += 2                                                                                                                   
  end                                                                                                                        
end
puts a

Measured memory_bytes: 1788
using System;
 
class Program
{
    static void Main()
    {
        string[] s = Console.ReadLine().Split(' ');
        int n = int.Parse(s[0]);
        int m = int.Parse(s[1]);
 
        int[,] A = new int[n, m];
        int[]  b = new int[m];
 
        for(int i = 0; i < n; i++)
        {
            string[] t = Console.ReadLine().Split(' ');
            for (int j = 0; j < m; j++)
            {
                A[i, j] = int.Parse(t[j]);
            }
        }
 
        for(int i = 0; i < m; i++)
        {
            b[i] = int.Parse(Console.ReadLine());
        }
 
 		int[] c = new int[n];
        for(int i = 0; i < n; i++)
        {
            for(int j = 0; j < m; j++)
            {
                c[i] += A[i, j] * b[j];
            }
            Console.WriteLine(c[i]);
        }
    }
}

Measured memory_bytes: 9348
#define dbg(fmt,...) fprintf(stderr,fmt,__VA_ARGS__)
#define dpri(x) dbg(#x ": %d\n", x)
#define dprs(x) dbg(#x ": %s\n", x)
#include <stdio.h>
typedef long long ll;
const int MYINF = 1e9+7;
typedef int bool;
const bool true = 1;
const bool false = 0;

#define MAX_H 500010
#define parent(i) ((i)/2)
#define left(i) ((i)*2)
#define right(i) ((i)*2+1)

int H;
int heap[MAX_H];
#define len heap[0]

void maxHeapify(int i) {
	int l, r, *A, largest;
	A = heap;
	l = left(i);
	r = right(i);

	if (l <= H && A[l] > A[i]) largest = l;
	else largest = i;

	if (r <= H && A[r] > A[largest]) largest = r;

	if (largest != i) {
		int t;
		t = A[i];
		A[i] = A[largest];
		A[largest] = t;
		maxHeapify(largest);
	}
}

void buildMaxHeap() {
	int i;
	for (i = H/2; 0 < i; i--) {
		maxHeapify(i);
	}
}

void insert(int x) {
	heap[++len] = x;
}

//void insert(int x) {
//	int i, t;
//	heap[++len] = x;
//	for (i = len; 0 < parent(i) && heap[parent(i)] < heap[i]; i = parent(i)) {
//		t = heap[parent(i)];
//		heap[parent(i)] = heap[i];
//		heap[i] = t;
//	}
//}

int main(int argc, char **argv)
{
	int i, x;
	scanf("%d", &H);
	for (i = 0; i < H; i++) {
		scanf("%d", &x);
		insert(x);
	}
	buildMaxHeap();

	for (i = 1; i <= H; i++) {
		printf(" %d", heap[i]);
	}
	puts("");

	return 0;
}

Measured memory_bytes: 2560
//C
//#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>


#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Hang in there!

using namespace std;


int main() {
	string b;
	cin >> b;
	if (b == "A") {
		cout << "T" << endl;
	}
	if (b == "T") {
		cout << "A" << endl;
	}
	if (b == "C") {
		cout << "G" << endl;
	}
	if (b == "G") {
		cout << "C" << endl;
	}
}

Measured memory_bytes: 256
from sys import stdin

def countingSorted(A):
    VALUE_MAX = max(A)
    B = [0] * (len(A)+1)
    C = [0] * (VALUE_MAX+1)

    for A_i in A:
        C[A_i] += 1

    for i in range(1, VALUE_MAX+1):
        C[i] += C[i-1]

    for A_i in reversed(A):
        B[C[A_i]] = A_i
        C[A_i] -= 1

    return B[1:]

n = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
print(*countingSorted(A))



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

int main() {
  string s;
  cin >> s;
  
  int count = 0;
  for (int i = 0; i < s.size()/2; i++) {
    if (s[i] != s[s.size()-1-i]) count++;
  }
  cout << count << endl;
}

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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

void Main()
{
	int n; cin>>n;
	VI v(n);
	REP(i, n) cin >> v[i];

	VI odd(100000+10,0);
	VI even(100000+10,0);

	REP(i,n){
		if(i%2 == 0){
			odd[v[i]]++;
		}
		else{
			even[v[i]]++;
		}
	}

	int odd_max = 0;
	int odd_second = 0;
	int odd_itr = 0;
	REP(i,100000+10){
		if(odd[i] >= odd_max){
			odd_second = odd_max;
			odd_max = odd[i];
			odd_itr = i;
		}
		else{
			odd_second = max(odd_second, odd[i]);
		}
	}

	int even_max = 0;
	int even_second = 0;
	int even_itr = 0;
	REP(i,100000+10){
		if(even[i] >= even_max){
			even_second = even_max;
			even_max = even[i];
			even_itr = i;
		}
		else{
			even_second = max(even_second, even[i]);
		}
	}
	
	//dump(odd_max)
	//dump(odd_second)
	//dump(odd_itr)
	//dump(even_max)
	//dump(even_second)
	//dump(even_itr)
	
	if(odd_itr != even_itr){
		cout << n- odd_max - even_max << endl;
	}
	else{
		cout << n - max(odd_max+even_second, odd_second+even_max) << endl;
	}
	

	

	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

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

int main() {
  int k;
  cin>> k;
  string s;
  cin >> s;
  if(s.length()>k) cout << s.substr(0,k) << "..." << endl;
  else cout << s << endl;

}

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

const int N = 222222;
ll a[N];
int n;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll sum = 0;
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    ll ans = 1LL << 62;
    ll cs = 0;
    for(int i = 1; i < n; i++) {
        cs += a[i];
        ans = min(ans, abs(2 * cs - sum));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main(void) {
	char s[4];
  scanf("%s", s);

  if (s[0] == s[1] && s[1] == s[2]) printf("Yes");
  else if (s[1] == s[2] && s[2] == s[3]) printf("Yes");
  else {printf("No");}

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
using namespace std;
#define MAX_N 200000
const int INF = 1e6;
int n, m;
int dp[MAX_N + 1];

int main() {
    cin >> n >> m;
    pair<int, int> A[m + 1];
    for (int i = 0; i < m; i++) cin >> A[i].first >> A[i].second;
    sort(A, A + m);
    for (int i = 0; i < MAX_N; i++) dp[i] = INF;
    dp[0] = 0;
    for (int i = 0; i < m; i++) {
        dp[A[i].second - 1] = min(dp[A[i].second - 1], dp[A[i].first - 1] + 1);
    }
    if (dp[n - 1] <= 2) puts("POSSIBLE");
    else puts("IMPOSSIBLE");
}

Measured memory_bytes: 2560
import collections
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

MOD = 998244353

n = ri()
ls = ril()

counter = collections.Counter(ls)
if ls[0] > 0 or counter[0] > 1:
    print(0)
    exit()

res = 1
for i in range(2, max(counter.keys()) + 1):
    if counter[i - 1] == 0:
        print(0)
        exit()
    res *= counter[i - 1]**counter[i]
    res %= MOD
print(res)

Measured memory_bytes: 19864
#include<iostream>
#include<cmath>
using namespace std;
#define LIMIT 35
struct Puzzle{char cont[8]; int space; };
Puzzle puzzle;
int limit,path[LIMIT],MD[8][8];
static const int dx[4] = {-1,0,1,0};
static const int dy[4] = {0,-1,0,1};
static const char direction[4] = {'d','r','u','l'};

int getHeuristic(){
  int sum = 0;
  for(int i=0;i<8;i++){
    if(puzzle.cont[i]=='0')continue;
    sum += MD[i][puzzle.cont[i]-'0'];
  }
  return sum;
}

bool isTarget(){
  for(int i=0;i<8;i++){
    if(puzzle.cont[i] != '0' + i )return false;
  }
  return true;
}

bool dfs(int depth,int prev){
  if(isTarget())return true;
  if(depth+getHeuristic()>limit)return false;

  int px,py,tx,ty;
  Puzzle tmp;
  px = puzzle.space%4;
  py = puzzle.space/4;
  
  
  for(int r=0;r<4;r++){

    tx=px+dx[r];
    ty=py+dy[r];

    if(max(prev,r)-min(prev,r)==2)continue;
    if(tx<0||ty<0||tx>=4||ty>=2)continue;

    tmp=puzzle;

    puzzle.cont[py*4+px] = puzzle.cont[ty*4+tx];
    puzzle.cont[ty*4+tx] = '0';
    puzzle.space = ty*4+tx;

    if(dfs(depth+1,r)){path[depth]=r;return true;}
    puzzle=tmp;
  }
  return false;
}

void solve(){
  for(limit=getHeuristic();limit<=LIMIT;limit+=2){
    if(dfs(0,-100)){
      cout<<limit<<endl;
      //for(int i=0;i<limit;i++)cout<<direction[path[i]];cout<<endl;
      
      return;
    }
  }
  cout<<"unsolvable"<<endl;
}

bool input(){
  for(int i=0;i<8;i++){
    if(cin>>puzzle.cont[i]){}else return false;
    if(puzzle.cont[i]=='0')puzzle.space = i;
  }
  return true;
}

int main(){
  for(int i=0;i<8;i++){
    for(int j=0;j<8;j++){
      MD[i][j]=abs(i/4-j/4)+abs(i%4-j%4);
    }
  }
  while(input()){
    solve();
  }
  return 0;
}

Measured memory_bytes: 1136
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define degreeToRadian(deg) (((deg)/360)*2*M_PI)
#define radianTodegree(rad) (((rad)/2/M_PI)*360)
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; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const int MOD = 1e9 + 7;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//cin.tie(0);ios::sync_with_stdio(false);
//cout << fixed << setprecision(15) << y << endl;
int main() {
  int n; cin >> n;
  map<int, int> mp;
  rep (i, n) {
    int x; cin >> x;
    mp[x]++;
  }
  int m; cin >> m;
  vector<int> t(m);
  rep (i, m) cin >> t[i];
  
  bool ok = true;
  for (auto v : t) {
    if (mp[v]) {
      mp[v]--;
    } else {
      ok = false;
    }
  }

  if (ok) cout << "YES" << endl;
  else cout << "NO" << endl;

  
  return 0;
}


Measured memory_bytes: 13060
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int main(){
  int a[101];

  for(int i = 0; i < 101; i++){
    a[i] = 0;
  }

  int N, d, ans;

  ans = 0;
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> d;
    if(a[d] == 0){
      a[d] = 1;
      ans++;
    }
  }

  cout << ans << endl;




  return 0;
}

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

double base[] = {
	48.0, 51.0, 54.0, 57.0, 60.0, 64.0, 69.0, 75.0, 81.0, 91.0
};
const char *name[] = {
	"light fly",
	"fly",
	"bantam",
	"feather",
	"light",
	"light welter",
	"welter",
	"light middle",
	"middle",
	"light heavy",
};

int main(){
	double w;
	while(scanf("%lf", &w) == 1){
		const char *ans = "heavy";
		for(int i = 0; i < 10; ++i){
			if(w <= base[i]){
				ans = name[i];
				break;
			}
		}
		puts(ans);
	}
}

Measured memory_bytes: 1036
a, b, c, d = map( int, input().split() )
#print( a, b, c, d )

ac = a * c
ad = a * d
bc = b * c
bd = b * d

ans1 = max( ac, bd )
ans2 = max( ad, bc )

ans = max( ans1, ans2 )
print( ans )




Measured memory_bytes: 8964
#include <bits/stdc++.h>
#define rei register int
#define int long long
using namespace std;
const int maxn = 200010,mod = 998244353;
int n,k;
int l[maxn],r[maxn];
int sum[maxn],dp[maxn];
void add(int &x,int y){
	x = x + y < mod ? x + y : x + y - mod;
}
signed main(){
	cin >> n >> k;
	for(rei i = 1;i <= k;++i) scanf("%lld%lld",&l[i],&r[i]);
	dp[1] = sum[1] = 1;
	for(rei i = 2;i <= n;++i){
		for(rei j = 1;j <= k;++j){
			add(dp[i],(sum[max(i - l[j],(long long)0)] - sum[max(i - r[j],(long long)1) - 1] + mod) % mod);
		} add(sum[i],sum[i - 1]),add(sum[i],dp[i]);
	} cout << dp[n] << endl; return 0;
}

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

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n,k; cin>>n>>k;
	int ret=k; n--; k--;
	for (int i=0; i<n; i++)
		ret*=k;
	cout << ret << endl;
	return 0;
}


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

// syntax sugar: `for (int i = 0; i < N; ++i)`
#define rep(i, N) for (int i = 0; i < (int)(N); ++i)
// syntax sugar: `for (int i = 0; i < N; ++i)`
#define REP(type, name, beginValue, endCondValue) \
  for (type name = beginValue; name < endCondValue; ++name)
// syntax sugar: 多次元vector
#define VECTOR_DIM3(T, name, d1, d2, d3, initValue) \
    std::vector<std::vector<std::vector<T>>> name(d1, std::vector<std::vector<T>>(d2, std::vector<int>(d3, initValue)));
#define VECTOR_DIM2(T, name, d1, d2, initValue) \
    std::vector<std::vector<T>> name(d1, std::vector<T>(d2, initValue));
#define VECTOR_DIM1(T, name, d1, initValue) \
    std::vector<T> name(d1, initValue);
#define ll long long
#define ld long double

vector<int> enum_divisors(int N) {
    vector<int> res;
    for (int i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            // 重複しないならば i の相方である N/i も push
            if (N/i != i) res.push_back(N/i);
        }
    }
    return res;
}

int main(){
  int n; // 1 <= N <= 2 * 1e5
  cin >> n;
  vector<int> a(n, 0); // 1 <= a_i <= 1e6
  unordered_map<int, int> nums; // 数値 -> 個数
  rep(i, n) {
    cin >> a[i];
    nums[a[i]]++;
  }

  int ans = 0;
  rep(i, n) {
    int ai = a[i];
    // a_iと同じ数が jにもあるなら満たせない
    if (nums[ai] > 1) {
      continue;
    }
    bool found = false;
    const auto& divs = enum_divisors(ai);
    for (const auto& div : divs) {
      if (div != ai && nums[div] > 0) {
        found = true;
        break;
      }
    }
    if (!found) {
      ++ans;
    }
  }

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



Measured memory_bytes: 32536
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    S = input().rstrip()
    tree = SegmentTree(initial_values=S, f=lambda x,y:x|y, converter=lambda c: 1 << (ord(c)-ord('a')))
    Q = int(input())
    update = tree.update
    query = tree.query
    for _ in range(Q):
        t, a, b = input().rstrip().split()
        if t == '1': update(int(a)-1, b)
        else: print(bin(query(int(a)-1, int(b))).count('1'))

class SegmentTree:
    def __init__(self, n=None, f=max, zero_factory=int, converter=lambda x:x, initial_values=None):
        assert(n or initial_values)
        size = n if n else len(initial_values)
        self.__f, self.__z, self.__c = f, zero_factory, converter
        self.__n = 1 << ((size - 1).bit_length())
        self.__dat = [zero_factory() for _ in range(2 * self.__n)]
        if initial_values:
            zi = self.__get_leaf(0)
            for i, v in enumerate(initial_values): self.__dat[zi + i] = converter(v)
            for i in range(zi-1, -1, -1): self.__dat[i] = f(*self.__get_children(i))

    def update(self, index, value):
        i, v = self.__get_leaf(index), self.__c(value)
        if self.__dat[i] == v: return
        self.__dat[i] = v
        while i:
            i = self.__get_parent(i)
            self.__dat[i] = self.__f(*self.__get_children(i))

    def query(self, from_inclusive, to_exclusive):
        ans = self.__z()
        if to_exclusive <= from_inclusive: return ans
        l, r = self.__get_leaf(from_inclusive), self.__get_leaf(to_exclusive) - 1
        while r - l > 1:
            if self.__is_right(l): ans = self.__f(ans, self.__dat[l])
            if self.__is_left(r): ans, r = self.__f(ans, self.__dat[r]), r-1
            l, r = l//2, self.__get_parent(r)
        ans = self.__f(ans, self.__dat[l])
        if l != r: ans = self.__f(ans, self.__dat[r])
        return ans

    def __get_leaf(self, i): return self.__n + i - 1
    def __get_parent(self, i): return (i-1)//2
    def __get_children(self, i): return (self.__dat[2*i+1], self.__dat[2*i+2])
    def __is_left(self, i): return i&1 == 1
    def __is_right(self, i): return i&1 == 0

if __name__ == '__main__':
    main()


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

int main(){
  string S;
  cin >> S;
  int a = 0;
  for(int i = 0; i < S.size(); i++){
    if(S.at(i) == 'o'){
      a++;
    }
  }
  cout << 700 + 100 * a << endl;
}


Measured memory_bytes: 256