akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
std::vector<std::pair<int, int>> next_list(const int &x, const int &y) {
	return { std::make_pair(x + 1, y), std::make_pair(x - 1, y), std::make_pair(x, y + 1), std::make_pair(x, y - 1) };
}
template<typename T>
class Queue {
public:
	Queue(const int &n) :vector(n), f(0), b(0) {};
	T front() const {
		return vector.at(f);
	}
	T back() const {
		return vector.at(b);
	}
	void pop() {
		f = (f + 1) % vector.size();
	}
	void push(T f) {
		vector.at(b) = f;
		b = (b + 1) % vector.size();
	}
	void clear() {
		f = 0;
		b = 0;
	}
private:
	std::vector<T> vector;
	int f, b;
};
struct Route {
	Route(const int &ax = 0, const int &ay = 0, const int &an = 0, const int &atime = 0) :x(ax), y(ay), n(an), time(atime) {};
	int x, y, n, time;
	bool operator<(const Route &other) const {
		return time < other.time;
	}
};
int wfs(const std::vector<std::vector<int>> &vector, std::vector<std::vector<int>> &memo, Queue<Route> &queue, const Route &start, const int &goal) {
	queue.clear();
	queue.push(start);
	while (vector.at(queue.front().y).at(queue.front().x) != start.n + 1) {
		for (const auto &coord : next_list(queue.front().x, queue.front().y)) {
			if (vector.at(coord.second).at(coord.first) >= 0 && memo.at(coord.second).at(coord.first) != start.n) {
				memo.at(coord.second).at(coord.first) = start.n;
				queue.push(Route(coord.first, coord.second, 0, queue.front().time + 1));
			}
		}
		queue.pop();
	}
	if (start.n + 1 == goal) {
		return queue.front().time;
	}
	else {
		return wfs(vector, memo, queue, Route(queue.front().x, queue.front().y, start.n + 1, queue.front().time), goal);
	}
}
int main() {
	int h, w, n;
	std::cin >> h >> w >> n;
	std::vector<std::vector<int>> vector(h + 2, std::vector<int>(w + 2, -1));
	Route start(0, 0, 0, 0);
	char *arg = new char[w + 2];
	for (auto i = 1; i <= h; ++i) {
		std::cin >> arg;
		for (auto j = 1; j <= w; ++j) {
			switch (arg[j - 1]) {
			case '.':
				vector.at(i).at(j) = 0;
				break;
			case 'X':
				vector.at(i).at(j) = -1;
				break;
			case 'S':
				vector.at(i).at(j) = 0;
				start = Route(j, i, 0, 0);
				break;
			default:
				vector.at(i).at(j) = arg[j - 1] - '0';
			}
		}
	}
	delete[] arg;
	arg = nullptr;
	std::vector<std::vector<int>> memo(h + 2, std::vector<int>(w + 2, -1));
	Queue<Route> queue(h * w);
	std::cout << wfs(vector, memo, queue, start, n) << std::endl;
	return 0;
}

Measured memory_bytes: 26284
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

A, B, C, D = nl()

if A+B < C+D:
    print('Right')
elif A+B > C+D:
    print('Left')
else:
    print('Balanced')


Measured memory_bytes: 2940
import collections
import math
import operator as op
from functools import reduce
from collections import Counter
import numpy as np
import math
import bisect
import heapq


MOD = 1000000007


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd(a, b)


def get_inputs(cast_func=None):
    if cast_func is None:
        return input().split()
    else:
        return list(map(cast_func, input().split()))


def get_input(cast_func=None):
    if cast_func is None:
        return input()
    else:
        return cast_func(input())


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():
    K = get_input(int)

    Lun = [None for _ in range(10)]
    for n in range(10):
        Lun[n] = [[] for _ in range(11)]
    for n in range(10):
        Lun[n][1].append(n)
    # print(Lun)

    for d in range(2, 11):
        for n in range(10):
            o = n*10**(d-1) 
            for i in [n-1, n, n+1]:
                if i >= 0 and i <= 9:
                    Lun[n][d].extend([l + o for l in Lun[i][d-1]])

    flag = True
    cnt = K
    for d in range(1, 11):
        for n in range(1, 10):
            if cnt - len(Lun[n][d]) <= 0:
                flag = False
                break
            else:
                cnt -= len(Lun[n][d])
        if not flag:
            break
    # print(n, d, cnt)
    # print(Lun[n][d])
    print(Lun[n][d][cnt-1])


    # Lun = np.zeros((10, 11), dtype=np.int64)
    # Lun[:, 1] = 1
    # for d in range(2, 11):
    #     for n in range(10):
    #         for i in [n-1, n, n+1]:
    #             if i >= 0 and i <= 9:
    #                 Lun[n, d] += Lun[i, d-1]





    # flag = True
    # cnt = K
    # for d in range(1, 11):
    #     for n in range(1, 10):
    #         if cnt - Lun[n, d] <= 0:
    #             flag = False
    #             break
    #         else:
    #             cnt -= Lun[n, d]
    #     if not flag:
    #         break
    # print(n, d, cnt)

    # ans = ""
    # cnt = K
    # flag = True
    # for d in range(1, 11):
    #     for n in range(1, 10):
    #         if cnt - Lun[n, d] <= 0:
    #             flag = False
    #             break
    #         else:
    #             cnt -= Lun[n, d]
    #     if not flag:
    #         break
    
    # ans = [None for _ in range(d)]
    # ans[0] = n

    # for _d in range(d-1, 0, -1):
    #     for n in range(1, 10):
    #         if 
    #         if cnt - Lun[n, d] <= 0:
    #             flag = False
    #             break
    #         else:
    #             cnt -= Lun[n, d]
    #     if not flag:
    #         break
 


if __name__ == '__main__':
    main()


Measured memory_bytes: 21428
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
using namespace std;
typedef pair<int, int> P;

int a[51], b[51], c[51], d[51];

signed main(){
    int n, m;
    cin >> n >> m;
    rep(i, 0, n) cin >> a[i] >> b[i];
    rep(i, 0, m) cin >> c[i] >> d[i];
    rep(i, 0, n){
        int id = -1, MIN = 1e9;
        rep(j, 0, m){
            int tmp = abs(a[i] - c[j]) + abs(b[i] - d[j]);
            if(tmp < MIN){
                MIN = tmp;
                id = j;
            }
        }
        cout << id + 1 << endl;
    }
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		TreeMap<Long, Integer> order = new TreeMap<>();
		ArrayList<CP> data = new ArrayList<>();
		for (int i = 0; i < M; i++) {
			int pref = sc.nextInt();
			int year = sc.nextInt();
			order.put(pref * 10000000000l + year, pref);
			data.add(new CP(year, pref));
		}

		int[] preCount = new int[N + 1];
		for (long key : order.keySet()) {
			int pref = order.get(key);
			preCount[pref] = preCount[pref] + 1;
			order.put(key, preCount[pref]);
		}

		for (int i = 0; i < data.size(); i++) {
			CP a = data.get(i);
			int pref = a.pref;
			int year = a.year;
			int yRank = order.get(pref * 10000000000l + year);
			String strPref = add(pref, 6 - (String.valueOf(pref).length()));
			String strRank = add(yRank, 6 - (String.valueOf(yRank).length()));
			System.out.println(strPref + strRank);
		}
		sc.close();
	}

	private static String add(int year, int tobeadded) {
		String strYear = year + "";
		for (int j = 0; j < tobeadded; j++) {
			strYear = "0" + strYear;
		}
		return strYear;
	}

	static class CP {
		int year;
		int pref;

		public CP(int year, int pref) {
			super();
			this.year = year;
			this.pref = pref;
		}
	}

}

Measured memory_bytes: 118460
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <bitset>
#include<iomanip>//小数点以下を精度良く表示

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define INF 2000000000
#define INF2 1000000000000000000
#define rep(i,n) for(int i=0;i<(n);i++)
typedef pair<string, string> P;
const ll MOD=1000000007;
using Graph = vector<vector<int>>;



const int MAX_N = 1000;
const int MAX_K = 100000;

template<class T>  T gcd(T a, T b) {
    while (a % b != 0) {
        T tmp = b;
        b = a % b;
        a = tmp;
    }
    return b;
}

template<class T> T lcm(T a, T b) {
    if (a == b) return b;
    T g = gcd(a, b);
    return (a / g) * b;
}



int main() {
    ll n;
    cin >> n;
    ll res = 0;
    for (ll i = 1; i <= n; i++) {
        if (i % 3 == 0 || i % 5 == 0)  continue;
        res += i;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3624
def solve():
    S = list(input())
    ans = S[:]
    T = input()
    Sn = len(S)
    Tn = len(T)
    
    restorable = False
    for i in range(Sn - Tn, -1, -1):
        flag = True
        if S[i] == T[0] or S[i] == '?':
            for j in range(Tn):
                if S[i+j] != T[j] and S[i+j] != '?':
                    flag = False
                    break
            if flag:
                restorable = True
                for j in range(Tn):
                    ans[i+j] = T[j]
                break
    
    if not restorable:
        print('UNRESTORABLE')
    else:
        for i in range(Sn):
            if ans[i] == '?':
                ans[i] = 'a'
        print(''.join(ans))


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3064
/* ****Ragnar7**** */
/* It's Going to be Hard, but hard does not mean Impossible. */
#include<bits/stdc++.h>
#define ll          long long
#define hell        1000000007
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	char c;
	cin>>c;
	cout<<char(c+1);
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define tam 100010
#define mod 1000000007

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef pair <ll, ll> dl;
typedef pair <int, int> ii;
typedef vector <ii> vii;
typedef vector <vii> graph;

bool comp(int a, int b) {
	return a > b;
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

	int n, W;
	cin >> n >> W;
	ll val[n + 10];
	int w[W + 10];
	for (int i = 1; i <= n; ++i)
	{
		cin >> w[i] >> val[i];
	}
	ll dp[n + 10][W + 10];
	for (int i = 0; i <= W; ++i)
	{
		dp[0][i] = 0;
	}
	for (int i = 1; i <= n; ++i)
	{
		dp[i][0] = 0;
		for (int j = 1; j <= W; ++j)
		{
			if (w[i] <= j) dp[i][j] = max(dp[i - 1][j], val[i] + dp[i - 1][j - w[i]]);
			else dp[i][j] = dp[i - 1][j];
		}
	}
	cout << dp[n][W] << "\n";
	return 0;
}

Measured memory_bytes: 80128
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n=1000000;
        boolean[] N=new boolean[n+1];
        for(int i=2;i*i<=n;i++){
            if(!N[i]){
                for(int j=i+i;j<=n;j+=i){
                    N[j]=true;
                }
            }
        }
        while(sc.hasNextInt()){
            n=sc.nextInt();
            int ans=0;
            for(int i=2;i<=n;i++){
                if(!N[i]){
                    ans++;
                }
            }
            System.out.println(ans);
}
}
}

Measured memory_bytes: 13000
/*
Author: Sagar Gupta
E mail: sagar.june97p@gmail.com
*/

#pragma comment(linker, "/STACK:268435456")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define endl ("\n")
#define deb(n) cerr << #n << " = " << (n) << '\n'
#define PI (3.141592653589)
#define ordered_set tree<int, null_type, std::less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define MOD 1000000007

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed;
    cout.precision(10);
    // Those who forgive themselves, and are able to accept their true nature...THEY ARE THE STRONG ONES

    int n, k;
    cin >> n >> k;
    int arr[n];
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
    sort(arr, arr + n);
    if (k >= n)
    {
        cout << 0;
        return 0;
    }
    long long sum = 0ll;
    for (int i = 0; i < n - k; i++)
    {
        sum += arr[i];
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define ll long long
using namespace std;
int main() {
  int q,w,e; cin >>q>>w>>e;
  if(q <= e && w >= e){
    cout << "Yes";
  }
  else{
    cout << "No";
  }
}

Measured memory_bytes: 3588
// Strange Bank

#include <iostream>

using namespace std;

int main(){
	int N;
	cin >> N;

	int res = N; // only 1 yen is used in the case.

	// full search: deposit 0~N yen by 6^p
	for (int i = 0; i <= N; ++i){
		int cnt = 0;
		int dep6 = i; // First: deposit i yen by 6^p
		// 6^p (i >= 6^p,...,6^0)
		while (dep6 > 0){
			cnt += dep6 % 6; // 6^p trial count <= 6
			dep6 /= 6;
		}
		int dep9 = N - i; // Second: deposit N-i yen by 9^p
		// 9^p (N-i >= 9^p,...,9^0)
		while (dep9 > 0){
			cnt += dep9 % 9;
			dep9 /= 9;
		}
		if (res > cnt)
			res = cnt;
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int N;
  cin >> N;
  int H[N];
  for(int i=0;i<N;i++){
    cin >> H[i];
  }
  int max_move = 0;
  int move_cnt = 0;
  for(int i=0;i<N-1;i++){
    if(H[i] >= H[i+1]){
      move_cnt++;
    }else{
      move_cnt = 0;
    }
    max_move = max(max_move, move_cnt);
  }
  cout << max_move << endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
static const int MAX = 100005;

int N;
int A[MAX], L[MAX];

int main()
{
    cin >> N;
    for (int i = 0; i != N; ++i)
    {
        cin >> A[i];
    }

    L[0] = A[0];
    int length = 1;

    for (int i = 1; i <= N - 1; ++i)
    {
        if (L[length-1] < A[i])
        {
            L[length++] = A[i];
        }
        else
        {
            *lower_bound(L, L + length, A[i]) = A[i];
        }
    }
    cout << length << endl;
    return 0;
}



Measured memory_bytes: 3832
N, D = list(map(int, input().split()))
point = []
for _ in range(N):
    point += [list(map(int, input().split()))]

count = 0
for i in range(N):
    for j in range(i + 1, N):
        distance = sum([(y - z) ** 2 for y, z in zip(point[i], point[j])]) ** .5
        # print(f"i:{i} j:{j} distance:{distance}", file=sys.stderr)
        if abs(distance - int(distance)) < 0.0001:
            count += 1
print(count)

Measured memory_bytes: 3188
import sys
import bisect
import math
input = sys.stdin.readline

n = int(input())
l = [list(map(int, input().split())) for _ in range(n)]

mc = 0
for v in l:
    mc = max(mc, v[1])
mc_sqrt = math.sqrt(mc)

prime = [i for i in range(2, mc + 1)]
c = 0
while True:
    if c >= len(prime):
        break
    t = prime[c]
    prime = [v for v in prime if v == t or v % t != 0]
    c = c + 1
    if c >= mc_sqrt:
        break
        
cum = [0 for i in range(mc + 1)]
for i in range(len(cum)):
    prime_index = bisect.bisect_left(prime, i)
    
    n2 = (i + 1) / 2
    prime_index2 = bisect.bisect_left(prime, n2)
    if len(prime) > prime_index and len(prime) > prime_index2 and prime[prime_index] == i and prime[prime_index2] == n2:
        cum[i] = cum[i - 1] + 1
    else:
        if i - 1 < 0:
            cum[i] = 0
        else:
            cum[i] = cum[i - 1]

for t in l:
    x, y = t[0], t[1]
    p = 0
    if 0 <= x - 1:
        p = cum[x] - cum[x - 1]
    if x != y:
        p += cum[y] - cum[x]
    print(p)


Measured memory_bytes: 32292
#include <iostream>
    using namespace std;
     
    int main() {
    int w,h,x,y,r;
    cin>>w>>h>>x>>y>>r;
    if(r<=x && x <=w-r &&r<=y && y<=h-r) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
    }

Measured memory_bytes: 1160
n = int(input())
s = input()
i = 0
k = 0
while i < len(s):
  if s[i] == "(":
    k += 1
  else:
    if k > 0:
      k -= 1
    else:
      s = "(" + s
      i += 1
  i += 1
print(s+")"*k)  

Measured memory_bytes: 3060
import sys
sys.setrecursionlimit(700000)


def main():

    def nim(i, parent=None):
        ret = 0
        for j in edges[i]:
            if j == parent:
                continue
            ret ^= nim(j, i) + 1
        return ret

    n = int(raw_input())
    edges = [[] for i in xrange(n)]
    for i in xrange(n - 1):
        x, y = [int(_) - 1 for _ in raw_input().split()]
        edges[x].append(y)
        edges[y].append(x)
    if nim(0) == 0:
        return "Bob"
    else:
        return "Alice"


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 124648
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random

import os
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N,A,B = inputMap()
    
    ans1 = min(A,B)
    tmp = N-A
    if tmp >= B:
        ans2 = 0
    else:
        ans2 = B-tmp
        
    print("{} {}".format(ans1, ans2))
    
    
if __name__ == "__main__":
	main()


Measured memory_bytes: 38512
#include <stdio.h>

int main(){
    int a, b;
    scanf("%d %d", &a, &b);
    if(a > b){
        printf("a > b\n");
    }else if(a < b){
        printf("a < b\n");
    }else{
        printf("a == b\n");
    }
    return 0;
}


Measured memory_bytes: 2144
# import numpy as np
import sys, math, heapq
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial, gcd
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep="\n")

D, T, S = map(int, input().split())

if D / S > T:
    print("No")
else:
    print("Yes")


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

int main()
{
    int n, ans;
    bool a = false;
    cin >> n;
    for(int i = 0; i <= 9; i++){
        for(int j = 0; j <= 9; j++){
            if(n == i * j){
                a = true;
                break;
            }
        }
        if(a == true){
            break;
        }
    }

    if(a == true){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) for(int sz=0;sz<int(vec.size());sz++) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

using PI = P<ll, int>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    V<PI> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(ALL(a));
    reverse(ALL(a));

    vvll dp(n + 1, vll(n + 1, 0));
    for (int i = 0; i < n; i++) {
        for (int j = 0; i + j < n; j++) {
            chmax(dp[i + 1][j], dp[i][j] + a[i + j].first * abs(a[i + j].second - i));
            chmax(dp[i][j + 1], dp[i][j] + a[i + j].first * abs(n - 1 - a[i + j].second - j));
        }
    }

    ll ans = 0;
    for (int i = 0; i <= n; i++) chmax(ans, dp[i][n - i]);
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 34612
#include<bits/stdc++.h>
#define INF 1e9+7
#define ll long long
#define f(x) for(ull i=0;i<x;i++)
#define F first
#define S second
#define N 100005
#define M 1000000007
#define mp make_pair
#define ull unsigned long long
#define sc(n) scanf("%d",&n)
#define gcd __gcd
using namespace std;
ll a[N],b[N];
int main() {
	ios::sync_with_stdio(false);
    int n;
    cin>>n;
    ll sum=0;
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];
    }
    ll counter;
    for(int i=n-1;i>=0;i--){
        a[i]+=sum;
        if(a[i]%b[i]){
            counter=a[i]%b[i];

            if((a[i]+counter)%b[i]!=0)
                counter=b[i]-counter;
//                 cout<<counter<<endl;
            sum+=counter;
        }
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 1920
#include<iostream>

using namespace std;

const int N(1e5 + 9);

int n, V, W, ans;
long long f[N];
int w[N], v[N];

int main()
{
	cin>>n>>W;
	for (int i=1;i<=n;i++)
	{
		cin>>w[i]>>v[i];
		V += v[i];
	}
	for (int i=1;i<=V;i++)
	{
		f[i] = 1e9;
	}
	for (int i=1;i<=n;i++)
	{
		for (int j=V;j>=v[i];j--)
		{
			f[j] = min(f[j], f[j - v[i]] + w[i]);
		}
	}
	for (int i=V;i>=0;i--)
	{
		if (f[i] <= W)
		{
			cout<<i<<endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int i,j;
    int a[3][3];
    set<int>s;

    for(i=0; i<3; i++){
        for(j=0; j<3; j++){
            cin>>a[i][j];
        }
    }
    int n,x;
    cin>>n;
    for(i=0; i<n; i++){
        cin>>j;
        s.insert(j);
    }
    for(i=0; i<3; i++){
        for(j=x=0; j<3; j++){
            if(s.count(a[i][j]))
                x++;
        }
        if(x==3){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    for(i=0; i<3; i++){
        for(j=x=0; j<3; j++){
            if(s.count(a[j][i]))
                x++;
        }
        if(x==3){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    for(i=x=0; i<3; i++){
        if(s.count(a[i][i]))
            x++;
    }
    if(x==3 || (n<3 && x>=n)){
        cout<<"Yes"<<endl;
        return 0;
    }
    for(i=2,x=0; i>=0; i--){
        if(s.count(a[i][2-i]))
            x++;
    }
    if(x==3){
        cout<<"Yes"<<endl;
        return 0;
    }
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
S = list(input())

sum_R = 0
sum_B = 0
sum_G = 0
sum_A = 0

for i in range(N):
    if S[i] == "R":
        sum_R = sum_R +1
    if S[i] == "G":
        sum_G = sum_G+1
    if S[i] == "B":
        sum_B = sum_B +1
     
sum_A = sum_R*sum_G*sum_B

M = int((N-1)/2)

for j in range(1,M+1):
    for i in range(j):
        if S[i]!=S[j] and S[j]!=S[j+(j-i)] and S[i]!=S[j+(j-i)]:
            sum_A = sum_A -1

for j in range(M+1,N):
    for i in range(j+1,N):
        if S[i]!=S[j] and S[j]!=S[j+(j-i)] and S[i]!=S[j+(j-i)]:
            sum_A = sum_A -1
    
print(sum_A)

Measured memory_bytes: 9096
#include<iostream>
#include<vector>
using namespace std;
int main()
{	
  int n,k;
  cin>>n>>k;
  vector<int> v(n);
  for (int i=0;i<n;i++)
  {
    int a;
    cin>>a;
    v[i]=a;
  }
  vector<int> dp(n);
  dp[0]=0;
  dp[1]=abs(v[1]-v[0]);
  for (int i=2;i<n;i++)
  {
    for (int j=1;j<=k and i-j>=0;j++)
    {
      int curr=dp[i-j]+abs(v[i]-v[i-j]);
      if (curr<dp[i] or j==1)
      {
         
        dp[i]=curr;
      }
    }
  }
  cout<<dp[n-1];
  
}

Measured memory_bytes: 4032
/*by freesteed*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fill(x,c) memset(x,c,sizeof(x))
#define fi first
#define se second
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define caset int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define get_be(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
//get_be biger & equal
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
const ll mod=1e9+7;
const ll oo=1e9+10;
const int Max = 1e6+10;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
//ll a[Max];
ll n,m;
//SUN, MON, TUE, WED, THU, FRI, or SAT.
void solve(){
	cin>>n>>m;
	cout<<max(0LL,n-2*m); 
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//caset{
		solve();
	//}
  	return 0;
}



 

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

def main():
    N,K = map(int,input().split())
    r1 = 0
    for i in range(1,N+1):
        if i%K == 0:
            r1 += 1
    if K%2 == 1:
        print(r1**3)
    else:
        r2 = 0
        for i in range(1,N+1):
            if i%K == K//2:
                r2 += 1
        print(r1**3+r2**3)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
typedef long long LL;

LL n,m;

int main()
{
	ios::sync_with_stdio(false);
	while(cin>>n>>m){
		LL t0=n/m,t,ans=t0*t0*t0;
		if(m%2==0){
			t=n/(m/2)-t0;
			ans+=t*t*t;
		}
		cout<<ans<<endl;
	}
	
	return 0;
}

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

using namespace std;

#define DBG cerr << '!' << endl;
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)
#define INF 1000000000
#define MOD 1000000007

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

ll hanmemo[100010];
ll tokeimemo[100010];

int main()
{
	ll n,c;cin >> n >> c;
	vector<pair<ll,ll>> v;
	vector<pair<ll,ll>> gyaku;
	vector<pair<ll,ll>> tokei;
	vector<pair<ll,ll>> han;
	
	REP(i,n){
		ll a,b;cin >> a >> b;
		v.PB(MP(a,b));
		gyaku.PB(MP(c-a,b));
		if(a <= c/2){
			tokei.PB(MP(a,b));
		}
		else{
			han.PB(MP(c-a,b));
		}
	}
	sort(ALL(v));
	sort(ALL(gyaku));
	sort(ALL(tokei));
	sort(ALL(han));
	
	ll ans = 0;
	ll sum = 0;
	
	ll kata = 0;
	ll ryou = 0;
	sum = 0;
	REP(i,tokei.size()){
		sum += tokei[i].SE;
		ryou = max(ryou,sum - 2 * tokei[i].FI);
		tokeimemo[i] = ryou;
	}
	sum = 0;
	REP(i,han.size()){
		sum += han[i].SE;
		kata = max(kata,sum - han[i].FI);
	}
	ans = max(ans,kata + ryou);

	
	kata = 0;
	ryou = 0;
	sum = 0;
	REP(i,han.size()){
		sum += han[i].SE;
		ryou = max(ryou,sum - 2 * han[i].FI);
		hanmemo[i] = ryou;
	}
	sum = 0;
	REP(i,tokei.size()){
		sum += tokei[i].SE;
		kata = max(kata,sum - tokei[i].FI);
	}
	ans = max(ans,kata + ryou);

	sum = 0;
	
	//SHOW1d(tokeimemo,n);
	//SHOW1d(hanmemo,n);
	
	//cout << "! " << ans << endl;
	
	REP(i,n){
		sum += v[i].SE;
		ll tmp = sum - v[i].FI;
	//	cout << tmp  << ' ' <<  max(0LL,hanmemo[n-i-2]) << endl;
		if(n-i-2 >= 0)tmp += max(0LL,hanmemo[n-i-2]);
		ans = max(ans,tmp);
	//	cout << tmp << endl;
	}
	sum = 0;
	REP(i,n){
		sum += gyaku[i].SE;
		ll tmp = sum - gyaku[i].FI;
	//	cout << tmp << ' ' << max(0LL,tokeimemo[n-i-2]) << endl;
		if(n-i-2 >= 0)tmp += max(0LL,tokeimemo[n-i-2]);
		ans = max(ans,tmp);
	//	cout << tmp << endl;
	}
	
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6744
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define BUGAVOID(x) x
#define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define sz(c) (int)(c.size())
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T, class U>using vp = vector<pair<T, U>>;
template<class T>using vv = vector<vector<T>>; template<class T, class U>using vvp = vv<pair<T, U>>;
template<class T>vv<T> vvec(const size_t n, const size_t m, const T v) { return vv<T>(n, vector<T>(m, v)); }
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; }
constexpr ll pow2(const int n) { return 1ll << n; }
constexpr int INF = 1 << 28; constexpr ll LINF = 1ll << 60;
constexpr int MAX = 1e5 + 5; constexpr int MOD = 1e9 + 7; constexpr double EPS = 1e-6;
constexpr int dy[4] = { 0,1,0,-1 }; constexpr int dx[4] = { 1,0,-1,0 };
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

ll N;
vll A(5);

int main() {
	cin >> N;
	rep(i, 5) cin >> A[i];
	auto rds = min_element(all(A));

	int irds = rds - A.begin();
	ll vrds = *rds;

	ll ans = (N + vrds - 1) / vrds + 4;
	write(ans);
}

Measured memory_bytes: 256
x = []
for k in range(10000):
    n = input()
    if n == "0":
        break
    x.append(int(n))
i = 1
for j in x:
    int_j = int(j)
    if int_j != 0:
        print("Case", str(i)+":", int_j)
        i += 1
    else:
        break

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

int main(){
    using namespace std;
    constexpr unsigned long P{2003};
    unsigned long N;
    cin >> N;
    vector<string> S(N);
    for(auto&& i : S){
        cin >> i;
        reverse(begin(i), end(i));
    }
    sort(begin(S), end(S), [](auto i, auto j){return size(i) == size(j) ? i < j : size(i) < size(j);});
    map<string, bitset<26>> s;
    unsigned long ans{0};
    for(const auto& i : S){
        vector<bitset<26>> b(size(i));
        for(unsigned long j{0}; j < size(i); ++j)b[j][i[j] - 'a'] = true;
        for(unsigned long j{size(i) - 1}; j--;)b[j] |= b[j + 1];
        string T;
        for(unsigned long j{0}; j < size(i); ++j){
            if(s.count(T) > 0)ans += (s[T] & b[j]).count();
            T += i[j];
        }
        s[string(begin(i), end(i) - 1)][i.back() - 'a'] = true;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  string s;
  cin >> s;
  
  bool answer = true;
  
  for (int i = 0; i < s.size()/2; i++){
    if (s.at(i) != s.at(s.size()-1-i)) answer = false;
  }

  for (int i = 0; i < (s.size()-1)/4; i++){
    if (s.at(i) != s.at((s.size()-1)/2-1-i)) answer = false;
  } 

  int count = 0;
  for (int i = (s.size()+3)/2-1; i < s.size()*3/4-1; i++){
    if (s.at(i) != s.at((s.size()-1)/2-1-count)) answer = false;
    count ++;
  }

  if (answer) cout << "Yes" << endl;
  else cout << "No" << endl;
} 

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

inline int binary_search(vector<ll> &v, ll val){
	if(v.back() <= val)return v.size();
	int l = 0, r = (int)v.size() - 1;
	while(l < r){
		int m = (l + r)/2;
		if(val < v[m])r = m;
		else l = m + 1;
	}
	return l;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int x, y, z, k;
	cin>>x>>y>>z>>k;
	vector<ll> a(x), b(y), c(z);
	for(int i = 0; i < x; i++){
		cin>>a[i];
	}
	for(int i = 0; i < y; i++){
		cin>>b[i];
	}
	for(int i = 0; i < z; i++){
		cin>>c[i];
	}
	sort(a.rbegin(), a.rend());
	sort(b.rbegin(), b.rend());
	sort(c.rbegin(), c.rend());
	vector<ll> v;
	for(int i = 0; i < x; i++){
		for(int j = 0; j < y; j++){
			v.push_back(a[i] + b[j]);
		}
	}
	sort(v.begin(), v.end());
	ll req;
	{
		ll cnt = x*1LL*y*z - k;
		ll lo = 0, hi = a[0] + b[0] + c[0];
		while(lo < hi){
			ll mi = lo + (hi - lo)/2;
			ll tmp = 0;
			for(int i = 0; i < z; i++){
				tmp += binary_search(v, mi - c[i]);
			}
			if(tmp < cnt)lo = mi + 1;
			else hi = mi;
		}
		req = lo;
	}
	vector<ll> vec;
	for(int i = 0; i < x; i++){
		if(a[i] + b[0] + c[0] <= req)break;
		for(int j = 0; j < y; j++){
			if(a[i] + b[j] + c[0] <= req)break;
			for(int kk = 0; kk < z; kk++){
				if(a[i] + b[j] + c[kk] <= req)break;
				vec.push_back(a[i] + b[j] + c[kk]);
			}
		}
	}
	sort(vec.rbegin(), vec.rend());
	while(vec.size() < k){
		vec.push_back(req);
	}
	for(auto x : vec){
		cout<<x<<'\n';
	}


	return 0;
}

Measured memory_bytes: 10608
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "YES"; }
  string_type do_falsename() const { return "NO"; }
};

void solve(string S) {
  vector<int> cnt(3);
  for (char c: S)
    cnt[c - 'a']++;
  int mi = *min_element(ALL(cnt));
  int ma = *max_element(ALL(cnt));
  cout << (ma - mi <= 1) << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	string S;
	cin >> S;
	solve(S);
	return 0;
}


Measured memory_bytes: 764
import sys
from itertools import combinations
L, R = map(int, input().split())
    
if R - L + (L % 2019) >= 2019:
    print(0)
    sys.exit()

else:
    tmp = 2 * (10 ** 9)
    lis = list(range(L, R + 1))
    for item in list(combinations(lis, 2)):
        mini = min((((item[0] % 2019) * item[1]) % 2019), (((item[1] % 2019) * item[0]) % 2019))
        if tmp >= mini:
            tmp = mini
            #print(item[0], item[1])
            #print(tmp)
print(tmp)

Measured memory_bytes: 148284
const main = (input) => {
  const lines = input.trim().split("\n");
  const [N, M] = lines[0].split(' ').map(str => parseInt(str));
  const waCount = new Array(N).fill(0);
  const isAC = new Array(N).fill(false);
  let waSum = 0;

  lines.slice(1).forEach(line => {
    let [p, s] = line.split(' ');
    p = parseInt(p) - 1;
    if (s === 'AC' && !isAC[p]) {
      isAC[p] = true;
      waSum += waCount[p];
    } else {
      waCount[p]++;
    }
  });

  const acSum = isAC.filter(bool => bool).length;

  console.log(acSum + ' ' + waSum);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 29956
#include <stdio.h>

int max = 0;
int min = 1000;

int maximum(int s)
{
	if(max < s){ max = s; }
	
	return max;
}


int minimum(int s)
{
	if(min > s){ min = s; }
	
	return min;
}


int main(void)
{
	int n;
	int i;
	int s;
	
	while(scanf("%d", &n) != EOF){
		if(n == 0){ break; }
		int ans = 0;
		int maxi, mini;
		for(i = 0; i < n; i++){
			scanf("%d", &s);
			maxi = maximum(s);
			mini = minimum(s);
			ans += s;		
		}
		ans = (ans - maxi - mini) / (n - 2);
		printf("%d\n", ans);
		
		max = 0;
		min = 1000;
	}
	return 0;
}

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define INF LONG_LONG_MAX
#define yn(f) cout << (f ? "Yes" : "No") << endl;

int k;
vector<int> v;
queue<int> que;

signed main() {
    cin >> k;
    rep11(i,10) {
        que.push(i);
    }
    while(que.size() < k) {
        queue<int> tmpque;
        map<int,bool> m;
        while(que.size()) {
            int tmp = que.front();
            que.pop();
            if (!m[tmp]) tmpque.push(tmp), m[tmp] = true;
            if (!m[tmp*10+tmp%10]) tmpque.push(tmp*10+tmp%10), m[tmp*10+tmp%10] = true;
            if (tmp%10 != 0) {
                if (!m[tmp*10+tmp%10-1]) tmpque.push(tmp*10+tmp%10-1), m[tmp*10+tmp%10-1] = true;
            }
            if (tmp%10 != 9) {
                if (!m[tmp*10+tmp%10+1]) tmpque.push(tmp*10+tmp%10+1), m[tmp*10+tmp%10+1] = true;
            }
        }
        que = tmpque;
    }
    while(que.size()) {
        v.pb(que.front());
        que.pop();
    }
    sort(all(v));
    cout << v[k-1] << endl;
}





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

#define forn(i,n) for(int i=0;i<n;i++)

typedef long long ll;
using namespace std;

int main() {
	int n,m,c;
	cin>>n>>m>>c;
	vector<int> B(m);
	forn(i,m)cin>>B[i];
	int A[n][m];
	forn(i,n) forn(j,m) cin>>A[i][j];
	int cnt=0;
	forn(i,n){
		ll sum=c;
		forn(j,m){
			sum+=A[i][j]*B[j];
		}
		if(sum>0)cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>

using namespace std;
 
int main(){
    int a, b, c;
    cin >> a >> b >> c;

    if (a > b) {
        return 0;
    }

    int count = 0;
    //for (int x=a; x <= b; x++) {
    //    if ((c % x)==0) {
    //        count += 1;
    //    }
    //}

    for (a; a<=b; a+=1) {
        if ((c % a)==0) {
            count += 1;
        }
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#include<iostream>
using namespace std;
#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
    cout << fixed << setprecision(12);
    double ans=0,kaku,coin;
    double n,k; cin >> n >> k;
    kaku=1/n;
    for(int i=1;i<=n;i++){ //i=出る目
    for(int j=0;j<100;j++){//j=乗数
    if(i*pow(2,j)>=k) {
        coin=j;
        double a=pow(0.5,coin);
        ans+=kaku*a;
        
        break;
    }
    }
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
// Created by abhay
#include <bits/stdc++.h>
#define sz(a) int((a).size())
#define pb push_back
#define allc c.begin(),c.end()
#define tr(c,i) for(typeof(c).begin() i = c.begin(); i != c.end(); i++)
#define present(c,x) (c.find(x) != c.end())
#define cpresent(c,x) (find(allc,x) != c.end())
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long
using namespace std;

int main()

{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

    ll n;
    cin>>n;
    ll g=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            for(int k=1;k<=n;k++)
            {
                g=g+__gcd(__gcd(i,j),k);
            }
        }
    }
    cout<<g<<endl;
}


Measured memory_bytes: 3652
from collections import deque

def readlines(n):
    for _ in range(n):
        a, b = map(int, input().split())
        yield a-1, b-1

def main():
    n, m = map(int, input().split())
    H = list(map(int, input().split()))
    r = [True] * n
    for a, b in readlines(m):
        if H[a] < H[b]:
            r[a] = False
        elif H[b] < H[a]:
            r[b] = False
        else:
            r[a] = False
            r[b] = False

    print(r.count(True))


main()



Measured memory_bytes: 20648
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		List<Integer> ArrayList = new ArrayList<Integer>();
		int lastAdd;
		int counter = 0;
		do {
			lastAdd = stdIn.nextInt();
			ArrayList.add(lastAdd);
			counter++;
			
		}while(lastAdd != 0);
		
		for(int i = 0; i < ArrayList.size()-1; i++) {
			System.out.println("Case " + (i+1) + ": " + ArrayList.get(i));
		}
	}
}

Measured memory_bytes: 40104
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define forn for(int i=0;i<n;i++)
#define form for(int j=0;j<m;j++)
#define pb push_back
#define s second
#define f first
int main()
{
   string s;
   cin>>s;
   int n=s.size();
   int cnt=0;
   forn
   {
             if(s[i]=='1') cnt++;
   }
   cout<<cnt;
   return 0;
}

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

char s[101],p[101];
char S[202];

main()
{
	scanf("%s",s);
	scanf("%s",p);
	
	strcpy(S,s);
	strcat(S,s);
	
	if(strstr(S,p)!=NULL){
	printf("Yes\n");
	}
	
	else{
	printf("No\n");
	}
	
	return 0;
}

Measured memory_bytes: 540
#include <iostream>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
using namespace std;

using VI = vector <int>;
using VVI = vector <VI>;
using VMII = vector <map<int, int>>;

const int MAXH = 10;

inline int getHeight(int now) {
    int ret = 0;

    while (now >= 1) {
        now >>= 1;
        ++ret;
    }

    return ret;
}

void solveDP(VMII& dp, int now, int sum, int val, const VI& V, const VI& W, const VI& H) {
    int N = V.size()-1;

    dp[now][-sum] = max(dp[now][-sum], val);
    dp[now][-(sum + W[now])] = max(dp[now][-(sum + W[now])], val + V[now]);

    if (H[now] >= MAXH) {
        return ;
    }

    if (now*2 <= N) {
        solveDP(dp, now*2, sum+W[now], val+V[now], V, W, H);
        solveDP(dp, now*2, sum, val, V, W, H);
    }

    if (now*2+1 <= N) {
        solveDP(dp, now*2+1, sum+W[now], val+V[now], V, W, H);
        solveDP(dp, now*2+1, sum, val, V, W, H);
    }
}

int main() {
    int N;
    cin >> N;

    VI V(N+1);
    VI W(N+1);
    VI H(N+1);

    for (int i = 1; i <= N; ++i) {
        H[i] = getHeight(i);
    }

    for (int i = 1; i <= N; ++i) {
        cin >> V[i] >> W[i];
    }

    VMII dp(N+1);

    // table creation => O(N) * 2^MAXH
    solveDP(dp, 1, 0, 0, V, W, H);

    // stay monotone
    for (int i = 1; i <= N; ++i) {
        if (!dp[i].empty()) {
            auto iter = dp[i].end();
            --iter;

            while (iter != dp[i].begin()) {
                auto iter2 = iter;
                --iter2;

                if (iter2->second <= iter->second) {
                    dp[i].erase(iter2);
                    continue;
                }

                --iter;
            }
        }
    }

    int Q;
    cin >> Q;

    // Q * 2^(LEVEL-MAXH) * dp Query
    while (Q--) {
        int v;
        int L;

        cin >> v >> L;

        if (H[v] <= MAXH) {
            auto iter = dp[v].lower_bound(-L);
            cout << iter->second << endl;
        } else {
            VI cand;
            int p = v;

            while (H[p] > MAXH) {
                cand.push_back(p);
                p /= 2;
            }

            int allMask = 1<<cand.size();
            int ans = -1;

            // 2^9 * 18
            for (int cho = 0; cho < allMask; ++cho) {
                int sum = 0;
                int val = 0;

                for (int i = 0; i < cand.size(); ++i) {
                    int nowv = cand[i];
                    if (cho & (1<<i)) {
                        sum += W[nowv];
                        val += V[nowv];
                    }
                }

                if (sum <= L) {
                    auto iter = dp[p].lower_bound(-(L-sum));
                    if (iter != dp[p].end()) {
                        ans = max(ans, val + iter->second);
                    }
                }
            }

            cout << ans << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 51312
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt(), w = sc.nextInt();
        for(int i = 0; i < w + 1; i++){
            System.out.print("#");
        }
        System.out.println("#");
        for(int i = 0; i < h; i ++){
            System.out.print("#");
            System.out.print(sc.next());
            System.out.println("#");
        }
        for(int i = 0; i < w + 2; i++){
            System.out.print("#");
        }
    }
}


Measured memory_bytes: 24276
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#undef int
#define mk make_pair
#define pb push_back
typedef pair<int, int> pii;
const int mod = 1000000007;
const int INF = 1000000009;
const long long INFL = 1000000000000000018ll;

int N, W, w[110], v[110], dp[110][100100];

signed main()
{
    cin >> N >> W;
    for(int i = 0; i < N; i++){
        cin >> w[i] >> v[i];
    }
    for(int i = 0; i <= 100000; i++){
        dp[0][i] = INFL;
    }
    int ans = INFL;
    dp[0][0] = 0;
    for(int i = 0; i < N; i++){
        for(int j = 0; j <= 100000; j++){
            if(j - v[i] >= 0)dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]);
            else dp[i + 1][j] = dp[i][j];
        }
    }
    for(int i = 0; i <= 100000; i++){
        if(dp[N][i] <= W){
            ans = i;
        }
    }
    cout << ans << endl;

    return 0;
}
/*



*/



Measured memory_bytes: 80128
/************************************
/ AUTHOR : YATHARTH GOSWAMI         /  
/ ALIAS : hacker_yg                 /
/ INSTITUTE : IIT Kanpur            /
************************************/
//          TEMPLATE                //

#include <bits/stdc++.h>

#define ll long long
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second

using namespace std;

int main(){
    string s;
    getline(cin,s);
    if ((s[0]==s[1])&&(s[1]==s[2])) puts("No");
    else puts("Yes");
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
 
#define pi 3.1415926535

int main()
{
  int temp, ans;

  for(int i = 0; i < 5; i++){
    cin >> temp;
    if(temp == 0){
      ans = i + 1;
    }
  }

  cout << ans << endl;

  return 0; 
}

Measured memory_bytes: 3520
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        int n  = str.length();
        int m = sc.nextInt();
        char c[] = str.toCharArray();
        
        int[][][] dp = new int[n+1][m+1][2];
        dp[0][0][0] = 1;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m + 1; j++) {
            //  m -> mの遷移もあるので「< m + 1」
            // 配列からはみ出る場合は中のcontinueで抜ける
                for (int k = 0; k < 2; k++) {
                    int nd = c[i] - '0';
                    
                    for (int d = 0; d <= 9; d++) {
                        // i: 必ずi+1へ遷移
                        int ni = i + 1, nj = j, nk = k;
                        
                        // j: jは現在までの非0の個数
                        // !0なら1個多い状態へ遷移
                        // m超過は遷移を見る必要はないのでcontinue
                        if (d != 0) nj++;
                        if (nj > m) continue;
                        
                        // k: 指定の数未満が確定しているか否か
                        // d > nd => 指定の数より大きいので遷移できない
                        // d < nd => 指定の数未満が確定なのでk=1へ遷移
                        if (k == 0) {
                            if (d > nd) continue;
                            if (d < nd) nk = 1;
                        }
                        
                        dp[ni][nj][nk] += dp[i][j][k];
                    }
                }
            }
        }
        
        System.out.println(dp[n][m][0] + dp[n][m][1]);
    }
}


Measured memory_bytes: 23508