akhauriyash/Code-Regression huggingface dataset:
/**
 * Title: A - Remaining Balls
 * Url: https://atcoder.jp/contests/abc154/tasks/abc154_a
 */
#include<bits/stdc++.h>

using namespace std;

#define ll long long

int main() {
    string s, t; cin >> s >> t;
    int a, b; cin >> a >> b;
    string u; cin >> u;
    if(s==u) {
        cout << a-1 << " " << b << endl;
        return 0;
    }
    if(t==u) {
        cout << a << " " << b-1 << endl;
        return 0;
    }
    cout << a << " " <<  b << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
 
////////////// Prewritten code follows. Look down for solution. ////////////////

#define fs first
#define sc second
#define pb push_back
#define len(x) ((int)(x).size())
#define fastio ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

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

const ll LINF = 1e18;
const int INF = 1e9;
const int MOD = 1e9+7;

/// command for char arrays with spaces -> scanf(" %[^\n]", text);
 
////////////////////////// Solution starts below. //////////////////////////////

int main(){
	fastio;
	ll h, n;
	cin >> h >> n;
	vector<ll> v(n);
	ll sum = 0;
	for(ll& x : v){
		cin >> x;
		sum += x;
	}
	if(sum >= h) cout << "Yes\n";
	else cout << "No\n";
	return 0;
}

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

#define int long long
#define rep(i, a, n) for (int i = a; i < n; i++)
#define pb push_back
#define eb emplace_back
#define dump(x) cout << #x << " = " << (x) << endl
#define chk() cout << "now" << endl;
#define ALL(x) (x).begin(), (x).end()
#define SORT(c) sort((c).begin(), (c).end())
#define SORTG(c) sort(ALL(c), greater<int>());
#define fi first
#define se second
int INF = 1e9 + 7;

typedef pair<int, int> P;
typedef vector<int> vi;

int n, k;

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

  cin >> n >> k;

  double ans = 0;
  for (int i = 1; i <= n; i++) {
    if(i<k) {
    double a = log2((double)k / (double)i);
    int b = (int)a;
    if (a - (double)b != 0) b++;
    ans += 1 / (double)(1LL << b);
    }else{
      ans++;
    }
  }
  ans /= n;
  cout << std::setprecision(10) << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
int main()
{
  int d[100], n, i;
  scanf("%d", &n);
  for ( i = 0; i < n; i++)
    {
      scanf("%d", &d[i]);
    }
  for(i = n - 1; i >= 1; i--)
    {
      printf("%d ", d[i]);
    }
  printf("%d\n", d[0]);
  return 0;
}

Measured memory_bytes: 596
f :: String -> Bool
f [] = True
f str =
	if length str < 5
	then False
	else (g 5 "maerd" str) || (g 5 "esare" str) || (g 6 "resare" str) || (g 7 "remaerd" str)

g :: Int -> String -> String -> Bool
g n kwd str = (take n str == kwd) && (f (drop n str))

main :: IO ()
main = do
 str <- getLine
 if(f $ reverse str) then putStrLn "YES" else putStrLn "NO"

Measured memory_bytes: 7676
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		final Scanner scanner = new Scanner(System.in);
		final int a = scanner.nextInt();
		final int b = scanner.nextInt();
		final int c = scanner.nextInt();

		if (a == b && b == c) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

		scanner.close();

	}

}

Measured memory_bytes: 21716
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using p = pair<int, int>;
int main()
{
	char a;
	cin >> a;
	if (a - 'a' < 0)	cout << 'A' << endl;
	else cout << 'a' << endl;
	return 0;
}

Measured memory_bytes: 3572
# AtCoder用のライブラリ
# 参照
# https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a


# a ** n mod m
def mod_pow(a, n, m=10 ** 9 + 7):
    res = 1
    while n > 0:
        if n & 1 == 1:
            res = res * a % m
        a = a * a % m
        n >>= 1
    return res


# aの-1乗をmで割ったときの商を求める
def mod_inv(a, m=10 ** 9 + 7):
    b = m
    u = 1
    v = 0
    while b > 0:
        t = a // b
        a -= t * b
        c = a
        a = b
        b = c

        u -= t * v
        c = u
        u = v
        v = c
    u %= m
    return u


# 組み合わせ数(nCk)を計算させる。
# nを固定しながら複数のkに対して計算させることができるようにしてあるため、
# 計算量はO(max(k)*log(mod))のため、実質O(max(k))。
class ModCombination:
    def __init__(self, n, mod=10 ** 9 + 7):
        self.N = n
        self.MOD = mod
        self.inv_fact_list = [1]
        self.P_list = [1]

    def combination(self, r):
        if r > len(self.inv_fact_list) - 1:
            self._list_extend(r)
        return self.inv_fact_list[r] * self.P_list[r] % self.MOD

    def _list_extend(self, needed):
        now = len(self.inv_fact_list)
        while now <= needed:
            self.P_list.append(self.P_list[-1] * (self.N - now + 1) % self.MOD)
            self.inv_fact_list.append(self.inv_fact_list[-1] * mod_inv(now) % self.MOD)
            now += 1


n, a, b = map(int, input().split())

MOD = 10 ** 9 + 7

c = ModCombination(n)

ans = (mod_pow(2, n) - c.combination(b) - c.combination(a) - 1) % MOD

print(ans)

Measured memory_bytes: 18868
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define EPS (1e-15)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define bet(x, a, b) (a) <= (x) && (x) < (b)
typedef long long ll;
typedef unsigned long long ull;

int table[101][101];

int main()
{
	int r, c;

	cin >> r >> c;
	rep(i, r) rep(j, c) cin >> table[i][j];

	rep(i, r) {
		int sum = 0;
		rep(j, c) sum += table[i][j];
		table[i][c] = sum;
	}
	rep(j, c + 1) {
		int sum = 0;
		rep(i, r) sum += table[i][j];
		table[r][j] = sum;
	}

	rep(i, r + 1) {
		rep(j, c + 1) {
			cout << table[i][j];
			if (j < c) cout << ' ';
		}
		cout << endl;
	}


	return 0;
}



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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

struct Vertex
{
    vector<int> n;
};

Vertex V[100005];
bool T[100005][2];

int main()
{
    ll N, M;
    cin >> N >> M;
    REP(i, M)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        V[a].n.push_back(b);
        V[b].n.push_back(a);
    }

    queue<pll> q;
    q.push(pll(0, 0));
    while (!q.empty())
    {
        pll t = q.front();
        q.pop();

        if (T[t.first][t.second % 2])
            continue;
        T[t.first][t.second % 2] = true;
        int c = t.second + 1;
        REP(i, V[t.first].n.size())
        {
            int n = V[t.first].n[i];
            if (T[n][c % 2])
                continue;
            q.push(pll(n, c));
        }
    }

    ll o = 0, e = 0;
    REP(i, N)
    {
        if (T[i][0])
            o++;
        if (T[i][1])
            e++;
    }

    ll sum = std::min(o * e, N * (N - 1) / 2);
    cout << sum - M << endl;

    return 0;
}

Measured memory_bytes: 7168
## for use in beginner level questions where speed is key
## and also for single test case code
## mastercopy for x,y,z

import sys
import heapq, functools, collections
import random
from collections import Counter, defaultdict

# read line as a string
# strr = input()

# read line as an integer
k = int(input())

# read one line and parse each word as a string
# lst = input().split()

# read one line and parse each word as an integer
lst = list(map(int,input().split()))

res = 0
for i,x in enumerate(lst, start=1):
    if x%2 == 1 and i%2 == 1:
        res += 1

print(res)


Measured memory_bytes: 76576
import sys
stdin=sys.stdin

ns = lambda:stdin.readline().rstrip()
ni = lambda:int(stdin.readline().rstrip())
nm = lambda:map(int,stdin.readline().split())
nl = lambda:list(map(int,stdin.readline().split()))

N,K=nm()
A=nl()

city_l=[0]
city_l.append(1)
city_c=[0]*(N+1)
city_c[1]+=1
n_city=A[0]
flag=True
r_start=-1
r_end=-1
while(flag):
    city_c[n_city]+=1
    city_l.append(n_city)
    if(city_c[n_city]>1):
        r_start=city_l.index(n_city)
        r_end=len(city_l)-1
        city_l.append(A[n_city-1])
        flag=False
    n_city=A[n_city-1]

if(K<=r_end):
    print(A[city_l[K]-1])


else:
    K2=K-r_end+1
    K2=K2%(r_end-r_start)
    if(K2==0):
       print(city_l[r_end])
    else:
       print(city_l[r_start+K2])


Measured memory_bytes: 32256
#include <vector>
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

int main() {
	int N, K;
	cin >> N >> K;
	vector<int> num(N + 1, 0);
	for(int i = 1; i <= N; i++) {
		int j = 0;
		for(;(i << j) < K; j++);
		num[i] = j;
	}
	vector<double> res(N + 1, 0.0);
	for(int i = 1; i <= N; i++) {
		res[i] = 1.0 / (double) N * pow(0.5, num[i]);
	}

	double out = 0;
	for(auto x: res) out += x;
	cout << fixed << setprecision(9) << out << endl;
}


Measured memory_bytes: 1408
import java.io.*;
import java.util.*;
 
public class Main {
 
    public static void main(String[] args) {
        FastReader scan = new FastReader();
        PrintWriter out = new PrintWriter(System.out);
        Task solver = new Task();
        int t = 1;
        while (t --> 0) solver.solve(1, scan, out);
        out.close();
    }
 
    static class Task {
        static HashMap<Long, Long> got = new HashMap<>();
        
        public void solve(int testNumber, FastReader scan, PrintWriter out) {
            long x = scan.nextLong();
            out.println(go(x));
        }
        
        static long go(long curr) {
            if(curr == 1) return 1;
            if(got.containsKey(curr)) return got.get(curr);
            long res = go(curr/2);
            got.put(curr, res+res);
            return res+res+1;
        }
    }
 
    static void shuffle(int[] a) {
        Random get = new Random();
        for (int i = 0; i < a.length; i++) {
            int r = get.nextInt(a.length);
            int temp = a[i];
            a[i] = a[r];
            a[r] = temp;
        }
    }
 
    static void shuffle(long[] a) {
        Random get = new Random();
        for (int i = 0; i < a.length; i++) {
            int r = get.nextInt(a.length);
            long temp = a[i];
            a[i] = a[r];
            a[r] = temp;
        }
    }
 
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;
 
        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
 
        public FastReader(String s) throws FileNotFoundException {
            br = new BufferedReader(new FileReader(new File(s)));
        }
 
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        int nextInt() {
            return Integer.parseInt(next());
        }
 
        long nextLong() {
            return Long.parseLong(next());
        }
 
        double nextDouble() {
            return Double.parseDouble(next());
        }
 
        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
 
}

Measured memory_bytes: 24916
# -*- coding: utf-8 -*-

import collections


N = int(input())
graph = [[] for _ in range(N)]
# graph = collections.defaultdict(list)

for i in range(N-1):
    # print(i)
    a, b, c = map(int, input().split(' '))
    a -= 1
    b -= 1
    graph[a].append([b, c])
    graph[b].append([a, c])


Q, K = map(int, input().split(' '))

dist = [-1 for _ in range(N)]
dist[K-1] = 0
stack = [K-1]
while len(stack) != 0:
    a = stack.pop()
    for b, c in graph[a]:
        if dist[b] == -1:
            dist[b] = dist[a] + c
            stack.append(b)


# def dfs(a):
#     for b, c in graph[a]:
#         if dist[b] == -1:
#             dist[b] = dist[a] + c
#             dfs(b)
# dfs(K-1)
# print(dist)


for _ in range(Q):
    x, y = map(int, input().split(' '))
    x -= 1
    y -= 1
    print(dist[x] + dist[y])



Measured memory_bytes: 90272
#include <bits/stdc++.h>
using namespace std;
bool is_palindromic(int n)
{
    int p[5];
    for (int i = 0; i < 5; i++)
    {
        p[i] = n % 10;
        n /= 10;
    }
    return (p[0] == p[4] && p[1] == p[3]);
}
int main()
{
    int a, b, ans = 0;
    cin >> a >> b;
    for (int i = a; i <= b; i++)
    {
        if (is_palindromic(i))
            ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
using System;

class _0038 {
    enum Role { FOUR, FULL, STRA, THRE, TWOP, ONEP, NONE };
    public static void Main() {
        string str;
        string[] strs;
        int[] cards = new int[13];
        Role r;

        while ((str = Console.ReadLine()) != null) {
            for (int i = 0; i < 13; i++) cards[i] = 0;
            strs = str.Split(',');
            for (int i = 0; i < strs.Length; i++) cards[int.Parse(strs[i]) - 1]++;
            r = Role.NONE;
            for (int i = 0; i < 13; i++)
                if (cards[i] != 0) {
                    switch (cards[i]) {
                        case 4:
                            r = Role.FOUR;
                            break;
                        case 3:
                            if (r == Role.ONEP) r = Role.FULL;
                            else r = Role.THRE;
                            break;
                        case 2:
                            if (r == Role.THRE) r = Role.FULL;
                            else if (r == Role.ONEP) r = Role.TWOP;
                            else r = Role.ONEP;
                            break;
                        case 1:
                            if (r == Role.NONE && i < 8) {
                                r = Role.STRA;
                                for (int j = 1; j < 4; j++)
                                    if (cards[i + j] != 1) r = Role.NONE;
                                if (r == Role.NONE && i == 0) {
                                    r = Role.STRA;
                                    for (int j = 12; j > 8; j--)
                                        if (cards[j] != 1) r = Role.NONE;
                                }
                            }
                            break;
                    }
                    if (r != Role.NONE && r != Role.ONEP && r != Role.THRE) break;
                }
            switch (r) {
                case Role.FOUR: Console.WriteLine("four card"); break;
                case Role.FULL: Console.WriteLine("full house"); break;
                case Role.STRA: Console.WriteLine("straight"); break;
                case Role.THRE: Console.WriteLine("three card"); break;
                case Role.TWOP: Console.WriteLine("two pair"); break;
                case Role.ONEP: Console.WriteLine("one pair"); break;
                case Role.NONE: Console.WriteLine("null"); break;
            }
        }
    }
}

Measured memory_bytes: 8856
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, const char *argv[]) {
  int n;
  cin >> n;
  vector<int> va(n);
  for (auto &a : va) {
    cin >> a;
  }

  int ans = 0, cur = 1;
  for (auto &a : va) {
    if (a != cur) {
      ans++;
    } else {
      cur++;
    }
  }

  cout << (ans == va.size() ? -1 : ans) << '\n';
}

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

int main() {
	int A, B, C;
	cin >> A >> B >> C;
	int sum = 0;
	sum = A - B;
	if (sum < C) sum = C - sum;
	else sum = 0;
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
char a[55][55], b[55][55];
signed main() {
	ll n, m, cnt = 0;
	cin >> n >> m;
	rep(i, n) { rep(j, n)cin >> a[i][j]; }
	rep(i, m) { rep(j, m)cin >> b[i][j]; }
	for (int i = 0; i < n - m + 1; i++) {
		for (int j = 0; j < n - m + 1; j++) {
			for (int k = 0; k < m; k++) {
				for (int l = 0; l < m; l++) {
					if (a[i + k][j + l] == b[k][l])cnt++;
				}
			}
			if (cnt == m * m) {
				puts("Yes");
				return 0;
			}
			cnt = 0;
		}
	}
	puts("No");
	getchar(); getchar(); return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
#include<string>
#include <math.h>
#include<algorithm>
#include<functional>
#define ll long long
#define inf  999999999
#define pa pair<int,int>
#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

class Point{
	public:
	double x,y;
	Point(double x=0,double y=0):x(x),y(y) {}
	Point operator + (Point p) {return Point(x+p.x,y+p.y);}
	Point operator - (Point p) {return Point(x-p.x,y-p.y);}
	Point operator * (double a) {return Point(x*a,y*a);}
	Point operator / (double a) {return Point(x/a,y/a);}
	double absv() {return sqrt(norm());}
	double norm() {return x*x+y*y;}
	bool operator < (const Point &p) const{
		return x != p.x ? x<p.x: y<p.y;
	}
	bool operator == (const Point &p) const{
		return fabs(x-p.x)<EPS && fabs(y-p.y)<EPS;
	}
};
typedef Point Vector;

struct Segment{
Point p1,p2;
};


double dot(Vector a,Vector b){
	return a.x*b.x+a.y*b.y;
}
double cross(Vector a,Vector b){
	return a.x*b.y-a.y*b.x;
}

//----------------kokomade temple------------

int main(){
int n;
double x,y;
cin>>n;
Point a[110];
for(int i=0;i<n;i++){
cin>>x>>y;
a[i].x=x;
a[i].y=y;
}
a[n]=a[0];
double ans=0.0;
for(int i=0;i<n;i++){
ans=ans+ 0.5*(a[i].x * a[i+1].y -a[i].y *a[i+1].x);
}
printf("%.1f\n",ans);


}

Measured memory_bytes: 1248
// template
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<long long, long long> LP;
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define REP_AB(i, a, b) for (ll i = ll(a); i <= ll(b); ++i)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)), v.end());
#define SIZE(x) ((ll)(x).size())
#define REVERSE(v) reverse(ALL(v))
// true / false
#define BIN_SEARCH(v, a) binary_search(ALL(v), a)
// index
#define BIN_LEFT(v, a) (lower_bound(ALL(v), a) - v.begin())
#define BIN_RIGHT(v, a) (upper_bound(ALL(v), a) - v.begin())
#define BIN_INSERT(v, a) (v.insert(v.begin() + BIN_LEFT(v, a), a))
#define DEL(v, i) v.erase(v.begin() + i)
#define INSERT(v, i, a) v.insert(v.begin() + i, a)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a / gcd(a, b)) * b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
#define out cout
#define in cin
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 end
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll N;
    in >> N;

    if(N<10){
        out << N << endl;
    }else if(N<100 || N==10){
        out << 9 << endl;
    }
    //else if(N<200){
     //   out << 9 + N -((N/100) * 100) + 1 << endl;
    //}
    else if(N<1000){
        out << 9 + N - 100 + 1 << endl;
    }else if(N<10000 || N==1000){
        out << 909 << endl;
    }
    //else if(N<2000){
     //   out << 9 + 900 + N-((N/10000) * 10000) + 1 << endl;
    //}
    else if(N<100000){
        out << 9 + 900 + N - 10000 + 1 << endl;
    }else if(N==100000){
        out << 9 + 900 + 90000 << endl;
    }
 

 

}

Measured memory_bytes: 256
#include<stdio.h>

#define MAX 101

int main(void){
	int n,ver,edg,u;
	int data[MAX][MAX];
	int i,j;

	scanf("%d",&n);

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

	for(i=0;i<n;i++){
		scanf("%d",&ver);
		scanf("%d",&edg);

		for(j=0;j<edg;j++){
			scanf("%d",&u);
			data[ver-1][u-1]=1;
		}
	}

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

	return 0;
}

Measured memory_bytes: 640
#include<cstdio>
    int a[15][15];
    int main()
    {
        int n,m;
        scanf("%d%d",&n,&m);
        for(int i=0;i<10;i++)
        for(int j=0;j<10;j++)
        scanf("%d",&a[i][j]);
        for(int k=0;k<10;k++)
        for(int i=0;i<10;i++)
        for(int j=0;j<10;j++)
        {
        	if(i==j||i==k||j==k) continue;
        	if(a[i][j]>a[i][k]+a[k][j]) a[i][j]=a[i][k]+a[k][j];
    	}
    	int ans=0;
    	for(int i=0;i<n*m;i++)
    	{
    		int x;scanf("%d",&x);
    		if(x==-1) continue;
    		ans+=a[x][1];
    	}
    	printf("%d\n",ans);
    	return 0;
    }

Measured memory_bytes: 128
#include <cstdio>
 #include <cstdlib>
 #include <iostream>
 #include <fstream>
 #include <sstream>
 #include <set>
 #include <map>
 #include <vector>
 #include <list>
 #include <algorithm>
 #include <cstring>
 #include <cmath>
 #include <string>
 #include <queue>
 #include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
 #include <cassert>
 #include <iomanip>        //do setprecision
 #include <ctime>
 #include <complex>
 using namespace std;

 #define FOR(i,b,e) for(int i=(b);i<(e);++i)
 #define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
 #define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
 #define REP(x, n) for(int x = 0; x < (n); ++x)

 #define ST first
 #define ND second
 #define PB push_back
 #define PF push_front
 #define MP make_pair
 #define LL long long
 #define ULL unsigned LL
 #define LD long double
 #define pii pair<int,int>
 #define pll pair<LL,LL>

 const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
 const int mod=1000000007;

 int main(){
	 string s;
	 cin>>s;
	 int n=s.length();
	 if(s[n-1]=='1'||s[0]=='0'){
		 cout<<-1<<endl;
		 return 0;
	 }
	 FOR(i,0,n/2){
		 int theOther=n-2-i;
		 if(s[i]!=s[theOther]){
			 cout<<-1<<endl;
			 return 0;
		 }
	 }
	 cerr<<"test"<<endl;
	 int nw=1,nx=2;
	 FOR(i,0,n/2){
		 int id=i+1;
		 if(s[i]=='1'){
			 cout<<nw<<" "<<nx<<endl;
			 nw=nx;
			 nx++;
		 }else{
			 cout<<nw<<" "<<nx<<endl;
			 nx++;
		 }
	 }
	 FORQ(i,nx,n){
		 cout<<nw<<" "<<i<<endl;
	 }
   return 0;
 }


Measured memory_bytes: 1664
import numpy as np

N = int(input())
tmp=[]
for i in range(N):
    tmp +=[list(map(int, input().split()))]

W=np.array(tmp)
ind = np.argsort(W[:,1])
W=W[ind,:]

current_time =0
for iw in W:
    current_time += iw[0]
    if current_time > iw[1]:
        print("No")
        exit()

print("Yes")
exit()



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

using namespace std;

#define ll long long

int main(){
	long x, count=0;
	cin >> x;
	while(x > 4){
		if(x>=500){
			x-=500;
			count+=1000;
		}
		else if(x>=5){
			x-=5;
			count+=5;
		}
	}
	
	cout << count;
	
	return 0;
}


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

int main(){
    int n, sum = 0;
    cin >> n;
    int tmp = n;
    while(tmp != 0){
        sum += tmp %10;
        tmp /=10;
    }

    cout << (n % sum == 0 ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
x,y,z,k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

a.sort(reverse = True)
b.sort(reverse = True)
c.sort(reverse = True)

d = []
for i in a:
  for j in b:
    d.append(i+j)
d.sort(reverse = True)
d = d[:k]

e = []
for i in c:
  for j in d:
    e.append(i+j)
e.sort(reverse = True)

e = e[:k]

for i in e:
  print(i)
  
  


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

int main()
{
    int n;
    cin >> n;
    if (n == 1)
        cout << "Hello World" << endl;
    else
    {
        int a, b;
        cin >> a >> b;
        cout << a + b << endl;
    }
    return 0;
}

Measured memory_bytes: 3504
#include <math.h>
#include <stdio.h>

int main() {
  int n;
  scanf(" %d", &n);
  int i, count = 0;
  for (i = 0; i < n; i++) {
    int num;
    scanf(" %d", &num);
    int j;
    char isPrime = 1;
    double root = sqrt((double)num);
    for (j = 2; j <= root; j++) {
      if (num % j == 0) {
        isPrime = 0;
        break;
      }
    }
    if (isPrime) {
      count++;
    }
  }
  printf("%d\n", count);
  return 0;
}


Measured memory_bytes: 2040
import java.util.*;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        int N = Integer.parseInt(scanner.nextLine());
        long[] nums = Arrays.stream(scanner.nextLine().split(" ")).mapToLong(Long::parseLong).toArray();
        int[][] bits = new int[N + 1][63];
        int max = 0;
        for (int i = 0; i < nums.length; i++) {
            long n = nums[i];
            for (int j = 0; j <= 62; j++) {
                if ((n & (1L << j)) > 0) {
                    bits[i + 1][j] = bits[i][j] + 1;
                    max = Math.max(max, j);
                } else {
                    bits[i + 1][j] = bits[i][j];
                }
            }

        }

        long ans = 0;
        for (int i = 0; i < nums.length; i++) {
            long n = nums[i];
            for (int j = 0; j <= max; j++) {
                int cnt = bits[N][j] - bits[i + 1][j];
                if ((n & (1L << j)) > 0) {
                    ans = (ans + ((((1L << j) % MOD) * (N - i - 1 - cnt)) % MOD)) % MOD;
                } else {
                    ans = (ans + ((((1L << j) % MOD) * cnt) % MOD)) % MOD;
                }
            }
        }

        System.out.println(ans);
    }

}


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

int main() {
  double r;
  cin >> r;

  double a, b, pai;
  pai = 3.141592653589;
  a = r * r * pai;
  b = (r + r) * pai;

  cout << fixed << setprecision(6);
  cout << a << " ";
  cout << b << endl;
}



Measured memory_bytes: 3236
/*********************************
                                                        *****          All is Well          *********
                                                        ******       Mehedi Hasan       ******
                                                        *******    Dept of ICE,IU           ****
                                                        *****************************/
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,m,i,j,arr[100005],c=0;
cin>>n;

cout<<"ABC"<<n<<endl;

  return 0;
}



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

using namespace std;

#define int long long

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)

template <typename T> T gcd(T m, T n) { return n == 0 ? m : gcd(n, m % n); }
template <typename T> T lcm(T m, T n) { return n * m / gcd(n, m); }
template <typename T> T fact(T n) { return (n == 0 ? 1 : n * fact(n - 1)); }
template <typename T> T modpow(T a, T e, T m) { return (e == (T)0 ? 1 : ((a % m) * modpow((a % m), e - 1, m)) % m); }

constexpr int MOD = 1e9 + 7;

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

  cout << n * n << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
int a, b, c, d;

int main() {
  cin >> a >> b >> c >> d;

  if (abs(c - a) <= d) {
    cout << "Yes" << endl;
    return 0;
  }
  if (abs(b - a) <= d && abs(c - b) <= d) {
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.LinkedList;


public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.processingMultiplication();
		return;
	}
	
	//九九の計算
	private void processingMultiplication () {
		
		LinkedList<Integer> leftOperandList = new LinkedList<Integer>(); //左の被演算子のリスト
		LinkedList<Integer> rightOperandList = new LinkedList<Integer>(); //右の被演算子のリスト
		
		for (int i = 1; i < 10; i ++) {
			leftOperandList.add(i);
			rightOperandList.add(i);
		}
		
		int index = 0;
		
		for (int i = 0; i < 9; i ++) {
			
			int left = leftOperandList.get(i);
			
			for (int j = 0; j < 9; j++) {
				
				int answer = left * rightOperandList.get(j);
				index++;
				
				if (index < 9) {
					index = 0;
				}
				
				System.out.printf("%dx%d=%d\n", left, rightOperandList.get(j), answer);
			}
		}
		
	}
}

Measured memory_bytes: 18096
x,y = map(int,input().split())


def cmb(n, r, mod):
  if (r < 0 or r > n):
    return 0
  r = min(r, n - r)
  return g1[n] * g2[r] * g2[n - r] % mod


mod = 10 ** 9 + 7  # 出力の制限
N = 10 ** 6
g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  # 逆元テーブル
inverse = [0, 1]  # 逆元テーブル計算用テーブル

for i in range(2, N + 1):
  g1.append((g1[-1] * i) % mod)
  inverse.append((-inverse[mod % i] * (mod // i)) % mod)
  g2.append((g2[-1] * inverse[-1]) % mod)


flag = True
a = 0
b = 0

if (2*y-x)%3 != 0 or (2*y-x) < 0:
  flag = False
else:
  a = (2*y-x)//3

if (2*x-y) %3 != 0 or (2*x-y) < 0:
  flag = False
else:
  b = (2*x-y)//3

if not flag:
  print(0)
else:
  print(cmb(a+b,a,10**9+7))

Measured memory_bytes: 124116
import math
menu = list()
for i in range(5):
    menu.append(int(input()))
    
diff_menu = list()
ans_menu = list()
for i in menu:
    amari = i % 10
    if amari == 0:
        amari = 10
    diff_menu.append(i+10-amari-i)
    ans_menu.append(i + 10-amari)
    
print(sum(ans_menu) - max(diff_menu))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define ld long double
#define ull unsigned long long
#define ff first
#define ss second
#define Mod 1000000007
//#define Mod 998244353
#define nl "\n" 
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define f(i, a, b) for (ll i = a; i < b; ++i)
#define rf(i, a, b) for (ll i = a; i >= b; --i)
#define vll vector<ll>
#define pll pair<ll, ll>
#define mem(a, b) memset(a, b, sizeof(a))
#define printv(v) for(int i=0;i<v.size();i++) { cout<<v[i]<<" "; } cout<<nl;
using namespace std;
inline bool kthbit(ll n, int k) { return (n >> k) & 1; }
ll pw(ll a, ll b){ll c = 1, m = a;while (b){if (b & 1) c = (c * m);m = (m * m);b /= 2;}return c;}
//------------------------------------------------------------------------------------------------

int main()
{
    fast;
    ll T=1;
    //cin>>T; //comment for single test

    while(T--)
    {
        //code...
        ll N,cnt=0;
        cin>>N;
        ld D,x,y;
        cin>>D;
        f(i,0,N)
        {
            cin>>x>>y;
            ld p=sqrt(x*x+y*y);
            if(p<=D)
                cnt++;
        }
        cout<<cnt<<nl;
    }
    return 0;  
}

Measured memory_bytes: 3868
// vim: set fdm=marker:
// {{{
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <utility>

using namespace std ;

typedef long long ll ;

// }}}

#define MOD 1000000007

struct K {
  int v;
  ll d;
};

struct cmp{
    bool operator() ( K k1, K k2) {
        return k1.d > k2.d;
    }
} ;

struct sp{
    vector<ll> sd;
};

int N, M;
ll dis[111111];
bool vis[111111];

vector<pair<int, ll>> to[111111];

sp* singleSP(int orig) {
    auto ret = new sp;
    ret->sd.resize(N+1);
    memset(dis, 0x7F, sizeof(dis));
    memset(vis, 0, sizeof(vis));
    priority_queue<K, vector<K>, cmp> PQ;
    PQ.push({orig, 0});
    while(PQ.size()) {
        K now;
        do {
          now = PQ.top();
          PQ.pop();
        } while(PQ.size() && vis[now.v]);
        if(!PQ.size() && vis[now.v])
            return ret;
        dis[now.v] = now.d;
        //printf("dis[%d] = %lld\n", now.v, now.d);
        ret->sd[now.v] = now.d;
        vis[now.v] = true;
        for(auto p: to[now.v]) {
            if(!vis[p.first]) {
                PQ.push({p.first, now.d+p.second});
                //printf("PQ push %d, d = %lld\n", p.first, now.d+p.second);
            }
        }
    }
    return ret;
}

struct edge{
    int first;
    int second;
    ll d;
};

ll calcComb(int now, const sp* dis, vector<ll>* out) {
    if((*out)[now] != -1)
        return (*out)[now];
    ll acc = 0;
    for(auto p: to[now]) {
        if(dis->sd[p.first] + p.second == dis->sd[now]) {
            acc += calcComb(p.first, dis, out);
            acc %= MOD;
        }
    }
    (*out)[now] = acc;
    //printf("comb %d = %lld\n", now, acc);
    return acc;
}

int main()
{
    int S, T;
    cin >> N >> M >> S >> T;
    vector<edge> es;
    for(int i = 0 ; i != M ; i++) {
        int U, V, D;
        scanf("%d%d%d", &U, &V, &D);
        to[U].push_back({V, D});
        to[V].push_back({U, D});
        es.push_back({U, V, D});
        es.push_back({V, U, D});
    }
    auto ssp = singleSP(S);
    auto tsp = singleSP(T);
    auto scomb = new vector<ll>;
    auto tcomb = new vector<ll>;
    scomb->resize(N+1, -1);
    tcomb->resize(N+1, -1);
    (*scomb)[S] = 1;
    (*tcomb)[T] = 1;
    calcComb(T, ssp, scomb);
    calcComb(S, tsp, tcomb);
    ll pd = ssp->sd[T];
    //printf("pd = %lld\n", pd);
    vector<ll> mp;
    for(auto e: es) {
        if(tsp->sd[e.first] * 2 < pd &&
           ssp->sd[e.second] * 2 < pd &&
           tsp->sd[e.first] + ssp->sd[e.second] + e.d == pd) {
          mp.push_back((*tcomb)[e.first] * (*scomb)[e.second] % MOD);
        }

    }
    for(int i = 1 ; i <= N ; i++) {
        if(tsp->sd[i] * 2 == pd &&
           ssp->sd[i] * 2 == pd)
          mp.push_back((*tcomb)[i] * (*scomb)[i] % MOD);
    }
    ll ans = 0;
    ll tot = 0;
    for(auto c: mp) {
        tot += c;
        tot %= MOD;
    }
    for(auto c: mp) {
        ans += c*(tot - c + MOD);
        ans %= MOD;
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 31336
#include<iostream>
#include<cstdio>
using namespace std;
int n,i;
char s[114514];
main()
{
	scanf("%d",&n);
	if(n==0)
	{
		printf("0");
		return 0;
	}
	while(n)
	{
		s[i++]=(n&1)+'0';
		n=n>0?-n/2:-(n-1)/2;
	}
  for(;i--;)printf("%c",s[i]);
}


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

#define clr(i, j)     memset(i, j, sizeof(i))
#define pb            push_back
#define mp            make_pair
typedef long long     ll;

int a,b,c;
int arr[101][101][101];
int main()
{
 /*cin>>a>>b>c;
for(int i=0;i<a;i++){
    int x,y,z;cin>>x>>y>>z;
    arr[x][y][z]++;
}
  for(int i = 1 ; i<=100 ; ++i)
        for(int j = 1 ; j<=100 ; ++j)
            for(int a = 0 ; a<=m ; ++a)
            {
               arr[i][j][a] += arr[i-1][j][a] + arr[i][j-1][a];
                arr[i][j][a] -= arr[i-1][j-1][a];
            }*/
ll a,b,c,d,n;
cin>>a>>b>>c>>d>>n;
if(a*4<c){
    c=a*4;
}if(b*2<c){
    c=b*2;
}
if(c*2<d){d=c*2;}
if(n%2){
    cout<<(c)+((n-1)/2)*d;
}else{
cout<<(n/2)*d;
}
}
/*
2
2
2 3
2
2 4
*/


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

const ll mod = 1000000007;

int main() {
    int n, m; cin >> n >> m;
    vector<ll> oks(n+1, true);
    rep (i, m) {
        int a; cin >> a;
        oks[a] = false;
    }

    vector<int> dp(n+1);
    dp[0] = 1;
    rep (now, n) {
        for (int next = now+1; next <= min(n, now+2); ++next) {
            if (oks[next]) {
                dp[next] += dp[now];
                dp[next] %= mod;
            }
        }
    }
    cout << dp[n] << endl;
}


Measured memory_bytes: 1408
#include <iostream>
using namespace std;
int main(){
    int n,u,k,m;
    int v[1000][1000]={};
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>u>>k;
        for(int l=1;l<=k;l++){
            cin>>m;        
            v[u][m]=1;
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(j==n){
                cout<<v[i][j];
            }
            else{
                cout<<v[i][j]<<" ";
            }
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 7008
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int N = Integer.parseInt(sc.next());

	int a ;
	String result = "APPROVED";

	for (int i=0;result.equals("APPROVED") && i < N;i++){

	    a = Integer.parseInt(sc.next());

	    if(a%2 == 0){
		if(a%3 == 0 || a%5 == 0){
		}else {
		    result = "DENIED";
		}
	    }
		   
	}
	System.out.println(result);
    }
}


Measured memory_bytes: 23252
object Main extends scala.App {
    import java.util
    import scala.collection._
    import scala.collection.mutable
    import scala.math._

    val sc = new java.util.Scanner(System.in)
    val eachItemMax = 1000000
    val x = sc.nextInt()

    if (x < 100) {
        println(0)
    } else {
        val dp = new Array[Int](x)
        def recursive(index: Int): Unit = {
            (100 to 105).foreach(t => {
                if (index - t >= 0 && dp(index - t) == 0) {
                    dp(index - t) = 1
                    recursive(index - t)
                }
            })
        }
        recursive(x)
        println(if (dp(0) == 1) 1 else 0)
    }
}

Measured memory_bytes: 28712
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAX 10000

int V, E;
vector<int> G[MAX];
vector<int> out;
int integ[MAX];
bool color[MAX];

void bfs(int s) {
    queue<int> Q;
    Q.push(s);
    color[s] = true;

    while(!Q.empty()) {
        int u = Q.front(); Q.pop();
        
        out.push_back(u);

        for(int i=0; i<G[u].size(); i++) {
            int v = G[u][i];
            integ[v] --;

            if( integ[v] ==  0 && color[v] == false) {
                color[v] = true;
                Q.push(v);
            }
        }
    }
}

void tsort() {
    for(int i=0; i<V; i++) {
        for(int j=0; j<G[i].size(); j++) {
            integ[G[i][j]] ++;
        }
    }

    for(int i=0; i<V; i++) {
        if (integ[i] == 0 && color[i] == false) {
            bfs(i);
        }
    }
}

int main() {
    int s,t;

    cin >> V >> E;

    for(int i=0; i<V; i++) {
        color[i] = false;
    }

    for(int i=0; i<E; i++) {
        cin >> s >> t;
        G[s].push_back(t);
    }

    tsort();

    for(vector<int>::iterator it= out.begin(); it != out.end(); ++it) {
        cout << *it << endl;
    }

    return 0;
}



Measured memory_bytes: 3892
def max_min(val,pos):
  if val<abs_max[pos][0]:
    abs_max[pos][0]=val
  elif val>abs_max[pos][1]:
    abs_max[pos][1]=val
    

n=int(input())

abs_max=[[float('inf'),float('-inf')] for __ in range(4)]

for _ in range(n):
  x,y=map(int,input().split())
  max_min(x+y,0)
  max_min(x-y,1)
  max_min(-x+y,2)
  max_min(-x-y,3)
ans=0
for Min,Max in abs_max:
  ans=max(ans,Max-Min)
print(ans)
  

Measured memory_bytes: 74456
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,m,h;
  cin>>n>>m;
  vector<int> height(n+1, 0);
  for (int i=1; i<=n; i++) {
    cin>>h;
    height[i] = h;
  }

  unordered_set<int> bad;
  int a,b;
  for (int i=0; i<m; i++) {
    cin>>a>>b;
    if (height[a] > height[b]) {
      bad.insert(b);
      // cout<<b<<endl<<endl;
    }
    else if (height[a] < height[b]) {
      bad.insert(a);
      // cout<<a<<endl<<endl;
    }
    else {
      bad.insert(a);
      bad.insert(b);
      // cout<<a<<' '<<b<<endl<<endl;
    }
  }
  // cout<<endl;
  // for (auto&s : bad) {
  //   cout<<s<<" ";
  // }
  // cout<<endl;
  cout<<n - (int)bad.size()<<endl;
  return 0;
}

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

#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)

int main(int argc, char *argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    long long int n, k, d = 0;
    cin >> n >> k;

    while (n > 0)
    {
        n /= k;
        d++;
    }

    cout << d << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct _OMAZINAI_ { _OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } __omazinai_instance__;
#define INF ((1LL<<61) + (1<<29))
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
void _INPUT_IMPL_() {};
template <class T, class... Args> void _INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; _INPUT_IMPL_(args...); }
void _OUTPUT_IMPL_() {};
template <class T, class... Args> void _OUTPUT_IMPL_(T dest, Args... args) { cout<< dest << (sizeof...(Args)?" ":""); _OUTPUT_IMPL_(args...); }
#define in(type, ...) type __VA_ARGS__; _INPUT_IMPL_(__VA_ARGS__)
#define in_v(type, name, cnt) vector<type> name(cnt); loop(i, cnt) cin >> name[i];
#define sort_v(v) std::sort(v.begin(), v.end())
#define out(...) (_OUTPUT_IMPL_(__VA_ARGS__), std::cout<<std::endl)
//小さい方に寄る
#define space_op(x, y, a, b, c) ([](auto x_, auto y_, auto a_, auto b_, auto c_){if(x_<y_)return a_;if(x_>y_)return c_;return b_;}(x,y,a,b,c))
#define space_out(x, y, a, b, c) out(space_op(x, y, a, b, c))

int main() {
	bool res = false;
	in(int, N);
	loop(x, 100)
		loop(y, 100)
			if (x * 4 + y * 7 == N)
				res = true;
	YesNo(res);
}

Measured memory_bytes: 256
from itertools import accumulate

def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True

def main():
    Q = int(input())
    N = 10 ** 5
    num_list = [0] * (N + 5)

    for i in range(1,N+1):
        if is_prime(i) and is_prime((i+1)//2):
            num_list[i] = 1

    sum_num = [0] * (N + 6)

    for i in range(1,N+2):
        sum_num[i+1] = sum_num[i] + num_list[i]

    sum_num.pop(0)

    for _ in range(Q):
        l, r = map(int, input().split())
        print(sum_num[r]-sum_num[l-1])



main()

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

typedef long int lint;
typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<int, string> pis;
typedef pair<long, long> pll;

#define EACH(t, c) for (auto&& t : c)
#define ALL(c) begin(c), end(c)
#define FOR(i, s, e) for (int i = (s); i < (int)(e); ++i)
#define REP(i, n) FOR(i, 0, n)
#define endl '\n'
#define fk first
#define sv second

const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1}, dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

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

  cin >> n;

  int sum = n[0] - '0';
  FOR(i, 1, n.length()) {
    if (n[i] - '0' != 9) {
      sum += (n.length() - i - 1) * 9 + 8;
      break;
    } else {
      sum += n[i] - '0';
    }
  }

  cout << sum << endl;
}

Measured memory_bytes: 256
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(ll __x = __start; __x < __end; __x++)

typedef pair<int, int> Edge;

int n;
vector<Edge> G[100000];
vector<ll> D(100000, 0);

int main() {
  cin >> n;
  loop(i,0,n-1) {
    int a, b, c; cin >> a >> b >> c;
    a--;b--;
    G[a].emplace_back(b, c);
    G[b].emplace_back(a, c);
  }
  int q, k; cin >> q >> k; k--;
  queue<pair<int, int> > Q;
  Q.push({ k, -1 });
  D[k] = 0;
  while (Q.size()) {
    auto _v = Q.front(); Q.pop();
    int v = _v.first, p = _v.second;
    for (auto &&edge: G[v]) {
      int u = edge.first, w = edge.second;
      if (u == p) continue;
      D[u] = D[v] + w;
      Q.push({ u, v });
    }
  }
  
  while (q--) {
    int x, y; cin >> x >> y; x--;y--;
    cout << D[x] + D[y] << endl;
  }
  
  return 0;
}


Measured memory_bytes: 11052
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

struct Node{
  int key;
  Node  *right,*left,*parent;
};

Node *root,*NIL;

Node * treeMinimum(Node *x){
  while(x->left!=NIL)x=x->left;
  return x;
}

Node * find(Node *u,int k) {
  while(u!=NIL&&k!=u->key){
    if(k<u->key)u=u->left;
    else u=u->right;
  }
  return u;
}

Node * treeSuccessor(Node *x){
  if(x->right!=NIL)return treeMinimum(x->right);
  Node *y = x->parent;
  while(y!=NIL&&x==y->right){
    x=y;y=y->parent;
  }
  return y;
}

void treeDelete(Node *z){
  Node *y;
  Node *x;

  if(z->left==NIL||z->right==NIL)y=z;
  else y=treeSuccessor(z);
  //ｙの子xを決める
  if(y->left!=NIL){
    x=y->left;
  }else{
    x=y->right;
  }
  if(x!=NIL){
    x->parent =y->parent;
  }

  if(y->parent==NIL){
    root=x;
  }else{
    if(y==y->parent->left){
      y->parent->left=x;
    }else{
      y->parent->right=x;
    }
  }

  if(y!=z){
    z->key=y->key;
  }
  //free(y);
}


void insert(int k){
  Node *y =NIL;
  Node *x =root;//`アドレががそのままxに入る`
  Node *z;

  z=(Node *)malloc(sizeof(Node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;

  while(x!=NIL){
    y=x;
    if(z->key<x->key){
      x=x->left;
    }else{
      x=x->right;
    }
  }
  z->parent=y;
  if(y==NIL){
    root=z;
  }else{
    if(z->key<y->key){
      y->left=z;
    }else{
      y->right=z;
    }
  }
}

void inorder(Node *u){
  if(u==NIL) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}
void preorder(Node *u){
  if(u==NIL)return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}




int main(){
  int n,i,x;
  string com;
  scanf("%d",&n);

  for(int i=0;i<n;i++){
    cin>>com;
    if(com=="insert"){
      scanf("%d",&x);
      insert(x);
    }else if(com=="print"){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n" );
    }else if(com=="find"){
      scanf("%d", &x);
      Node *t=find(root,x);
      if(t!=NIL)printf("yes\n" );
      else printf("no\n");
    }else if(com=="delete"){
      scanf("%d",&x);
      treeDelete(find(root,x));
    }
  }
  return 0;
}



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

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


Measured memory_bytes: 3288
#include<iostream>
#include<vector>
#include<map>
using namespace std;

void print(int A[], int N)
{
	for (int i = 0; i < N; i++){
		cout << A[i];
		if (i != N - 1)
			cout << " ";
	}
	cout << endl;
}

void sort(int A[], int N)
{
	int v;
	for (int i = 1; i < N; i++){
		v = A[i];
		int j = i - 1;
		while (j >= 0 && A[j] > v){
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = v;
		print(A, N);
	}
}

int main()
{
	int A[100], N;
	
	cin >> N;
	for (int i = 0; i < N; i++){
		cin >> A[i];
	}
	print(A, N);
	sort(A, N);

	return 0;
}

Measured memory_bytes: 1160
N = int(input())
for i in range(1, 3501):
    for j in range(1, 3501):
        if 4 * i * j - N * i - N * j <= 0:
            continue
        k = (N * i * j) / (4 * i * j - N * i - N * j)
        if k == round(k):
            print(i, j, int(k))
            exit()

Measured memory_bytes: 9132