akhauriyash/Code-Regression huggingface dataset:
/* ****GT_18**** */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  100005
ll ans=0,n;
string s;
void solve(ll x,ll d)
{
    if(x>=n-2||x<0)
        return;
    ll sum=0;
    for(ll i=0;i<n-1;i++)
    {
        if(s[i]=='B'&&s[i+1]=='C')
        {
            ans+=sum;
            i+=1;
        }
        else
        {
            if(s[i]=='A')
                sum++;
            else
            {
                sum=0;
            }
        }
    }
    return;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        ll i,j,k,l,m;
        cin>>s;
        n=s.size();
        solve(0,1);
        cout<<ans;
    }
    return 0;
}

Measured memory_bytes: 720
from collections import Counter
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    S = readline().strip()[::-1]
    N = len(S)

    a = [0]
    s = 0
    for i in range(N):
        s += int(S[i]) * pow(10, i, 2019)
        a.append(s % 2019)
    
    t = Counter(a)

    ans = 0
    for _, v in t.items():
        ans += v * (v-1) // 2
    
    print(ans)
    

if __name__ == "__main__":
    main()


Measured memory_bytes: 16612
n, x = map(int, input().split())

a_list = list(map(int, input().split()))
a_list.sort()
give = 0
count = 0

for num in a_list:
    give += num
    if give == x:
        count += 1
        break
    if give > x:
        count -= 1
    count += 1

if give < x:
    count -= 1

print(count)


Measured memory_bytes: 3060
n,l=(map(int,input().split()))
if l>0:
  print(int((n*l+(n+1)*n/2-n-l)))
elif l+n-1<0:
  print(int((n*l+(n+1)*n/2-n-(l+n-1))))
else:
  print(int((n*l+(n+1)*n/2-n)))

Measured memory_bytes: 38384
using System;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            string T = Console.ReadLine();
            int cnt = 0;

            for (int i = 0; i < S.Length; i++)
            {

                if (S.Substring(i,1) != T.Substring(i, 1))
                {
                    cnt++;
                }
            }

            Console.WriteLine(cnt);
        }
    }
}


Measured memory_bytes: 36732
#include <stdio.h>

int main(void)
{
    int a, b;
    scanf("%d %d", &a, &b);
    if (a >= 1 && a <= 9 && b >= 1 && b <= 9)
    {
        printf("%d\n", a * b);
    }
    else
    {
        printf("-1\n");
    }

    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main () {
    int N;
    scanf("%d",&N);
    int b[N];
    int i,x,y,z,m;
    for(i=0;i<N;i++){
        b[i] = 0;
        for(x=1;x<=80;x++){
            for(y=x;y<=90;y++){
                for(z=y;z<=100;z++){
                    m = x*x + y*y + z*z + x*y + y*z + z*x;
                    if(m == (i+1)){
                        if(x == y && y == z){
                            b[i] += 1;
                        }else if(x != y && y != z && z != x){
                            b[i] += 6;
                        }else{
                            b[i] += 3;
                        }
                    }
                }
            }
        }
        printf("%d\n",b[i]);
    }
    return 0;
}

Measured memory_bytes: 1756
N = int(input())
words = dict()
for i in range(N):
    w = input()
    if w in words:
        words[w] -= 1
    else:
        words[w] = -1
        
wd_list = list()
for w,c in words.items():
    wd_list.append((c,w))  # Tupple of count(rev), word
    
wd_list.sort()
max_c = wd_list[0][0]
for w in wd_list:
    if w[0] != max_c:
        break
    print(w[1])

Measured memory_bytes: 44252
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<tuple>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<math.h>
using namespace std;
int main(){
    int n,m;
    cin >> n >> m;
    int sum=0;
    for(int i=0;i<m;i++){
        int a;
        cin >> a;
        sum += a;
    }

    if(n>=sum){
        cout << n-sum << endl;
    }else{
        cout << -1 << endl;
    }
}

Measured memory_bytes: 3640
"""
Atcoder_Beginner_Contest_148
E - Double Factorial
https://atcoder.jp/contests/abc148/tasks/abc148_e
"""
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000000)

N = int(input())

if N % 2 != 0:
    print(0)
    quit()

zero_count = 0
divide_number = 10
while divide_number <= N:
    zero_count += N // divide_number

    # print("zero_count:{},divide_number:{}".format(zero_count, divide_number))
    divide_number *= 5

print(zero_count)


Measured memory_bytes: 3060
#include "iostream"
#include <string.h>
using namespace std;
 
int main(){
 
  string S,T,U;
  int A,B;
  
  cin >> S >> T;
  cin >> A >> B;
  cin >> U;
  
  if(S == U){
   cout << A-1 <<" "<< B; 
  
  }else{
   cout << A <<" "<< B-1;    
  }
  
  return 0;
  
}

Measured memory_bytes: 256
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE BangPatterns #-}
import Data.Char (isSpace)
import Data.List (unfoldr)
import Control.Monad
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import qualified Data.ByteString.Char8 as BS
import qualified Data.IntSet as IntSet
import Data.Foldable
import Control.Monad.ST

main = do
  [n,m] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  edges <- U.replicateM m $ do
    [u,v] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
    return (u-1,v-1)
  [s,t] <- map (subtract 1) . unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  let graph :: V.Vector IntSet.IntSet
      graph = V.create $ do
        vec <- VM.replicate (3 * n) IntSet.empty
        U.forM_ edges $ \(u,v) -> do
          modify' vec (IntSet.insert (3 * v + 1)) (3 * u)
          modify' vec (IntSet.insert (3 * v + 2)) (3 * u + 1)
          modify' vec (IntSet.insert (3 * v)) (3 * u + 2)
        return vec
      result = runST $ do
        visited <- UM.replicate (3 * n) False
        let !target = 3 * t
        -- bfs :: IntSet -> ST s (Maybe Int)
        let bfs !depth ss = do
              forM_IntSet ss $ \u ->
                UM.write visited u True
              let ts = foldMap_IntSet (graph V.!) ss
              ts' <- foldMapM_IntSet (\v -> do
                                         d <- UM.read visited v
                                         pure $ if d then IntSet.empty else IntSet.singleton v
                                     ) ts
              if target `IntSet.member` ts'
                then return $ Just (depth `quot` 3)
                else if IntSet.null ts'
                     then return Nothing
                     else bfs (depth+1) ts'
        bfs 1 (IntSet.singleton (3 * s))
  case result of
    Nothing -> putStrLn "-1"
    Just d -> print d

modify' :: VM.MVector s a -> (a -> a) -> Int -> ST s ()
modify' vec f !i = do x <- VM.read vec i
                      VM.write vec i $! f x

foldMap_IntSet :: (Monoid n) => (Int -> n) -> IntSet.IntSet -> n
foldMap_IntSet f set = go set
  where
    go set = case IntSet.splitRoot set of
               [] -> mempty
               [x] -> foldMap f (IntSet.toList x)
               xs -> foldMap go xs

forM_IntSet :: Monad m => IntSet.IntSet -> (Int -> m ()) -> m ()
forM_IntSet set f = go set
  where
    go set = case IntSet.splitRoot set of
               [] -> return ()
               [x] -> forM_ (IntSet.toList x) f
               xs -> forM_ xs go

foldMapM_IntSet :: (Monoid n, Monad m) => (Int -> m n) -> IntSet.IntSet -> m n
foldMapM_IntSet f set = go set
  where
    go set = case IntSet.splitRoot set of
               [] -> return mempty
               [x] -> foldlM (\x v -> mappend x <$> f v) mempty (IntSet.toList x)
               xs -> foldlM (\x set' -> mappend x <$> go set') mempty xs


Measured memory_bytes: 45052
#include<stdio.h>
#include<math.h>
#define N 10000
main()
{
  int i,j,n,c=0,f=0,a[N];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
    for(i=0;i<n;i++){
      for(j=2;j<=sqrt(a[i]);j++){
    if(a[i]%j==0){
      f=1;
      break;
    }
      }
      if(f==0){
	c++;
      }
      f=0;
    }
    printf("%d\n",c);
    return 0;
}



Measured memory_bytes: 2040
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<stdio.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<set>
#include<math.h>
#include<stack>
#include<sstream>
#include<queue>
#include<list>
#include<iomanip>
#include<bitset>
#include<limits.h>
#include <bits/stdc++.h>
#define MOD  1000000007
#define BIG  1000000005
#define ii pair<int,int>
#define iii pair<int,pair<int,int> >
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define pi pair<int,int>;
typedef long long ll;
using namespace std;


int main()
{
    //freopen("input.txt", "r", stdin);

     int a , b;
     cin >> a >> b ;
     int c = a <= b ? a : a-1 ;

     cout << c << endl ;
            return 0 ;

}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {
	static BufferedReader br;
	static PrintWriter pw;
	static int inf = (int) 1e9;
	static long mod = (long) 1e9 + 7;

	public static void main(String[] args) throws NumberFormatException, IOException, InterruptedException {
		br = new BufferedReader(new InputStreamReader(System.in));
		pw = new PrintWriter(System.out);
		char[] a = br.readLine().toCharArray();
		int[] cum = new int[2019];
		int mul = 1;
		int lmod = 0;
		for (int i = a.length - 1; i >= 0; i--) {
			lmod = (lmod + (mul * (a[i]-'0')) % 2019) % 2019;
//			System.out.println(lmod);
			cum[lmod]++;
			mul = (mul * 10) % 2019;
		}
		cum[0]++;
		long sum = 0;
		for (int i = 0; i < cum.length; i++) {
			sum += cum[i] * 1l * (cum[i] - 1);
		}
		pw.println(sum/2);

		pw.flush();

	}

	static int n;
	static boolean[] visited;
	static ArrayList<Integer>[] g;

	static void bfs(int s, int[] arr) {
		Queue<Integer> q = new LinkedList<Integer>();
		q.add(s);
		visited = new boolean[n];
		visited[s] = true;
		arr[s] = 0;
		while (!q.isEmpty()) {
			int u = q.remove();

			for (int v : g[u])
				if (!visited[v]) {
					visited[v] = true;
					q.add(v);
					arr[v] = arr[u] + 1;
				}
		}
	}

	static class Edge implements Comparable<Edge> {
		int node, cost, con;

		Edge(int a, int b, int c) {
			node = a;
			cost = b;
			con = c;
		}

		public int compareTo(Edge e) {
			return cost - e.cost;
		}
	}

	static class pair implements Comparable<pair> {
		int x;
		int y;

		public pair(int d, int u) {
			x = d;
			y = u;
		}

		public int compareTo(pair o) {
			return y - o.y;
		}

	}

	static class triple implements Comparable<triple> {
		int x;
		int y;
		int z;

		public triple(int a, int b, int c) {
			x = a;
			y = b;
			z = c;
		}

		public int compareTo(triple o) {
			return x - o.x;
		}
	}

	static int[] nxtarr() throws IOException {
		StringTokenizer st = new StringTokenizer(br.readLine());
		int[] a = new int[st.countTokens()];
		for (int i = 0; i < a.length; i++) {
			a[i] = Integer.parseInt(st.nextToken());
		}
		return a;
	}

	static long pow(long a, long e) // O(log e)
	{
		long res = 1;
		while (e > 0) {
			if ((e & 1) == 1)
				res *= a;
			a *= a;
			e >>= 1;
		}
		return res;
	}

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


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

#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

bool dp[80][80][26000];

void init(){
    rep(i, 80) rep(j, 80) rep(k, 26000) dp[i][j][k] = false;
}

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    init();
    int H, W; cin >> H >> W;
    pair<int, int> point[H][W];
    rep(i, H) rep(j, W) cin >> point[i][j].first;
    rep(i, H) rep(j, W) cin >> point[i][j].second;
    int base = 13000;
    dp[0][0][base + (point[0][0].first - point[0][0].second)] = dp[0][0][base + (point[0][0].second - point[0][0].first)] = true;
    rep(i, H){
        rep(j, W){
            if(j+1 < W){
                int nextblue = point[i][j+1].first, nextred = point[i][j+1].second;
                rep(k, 26000){
                    if(dp[i][j][k]) dp[i][j+1][k + nextblue - nextred] = dp[i][j+1][k + nextred - nextblue] = true;
                }
            }

            if(i+1 < H){
                int nextblue = point[i+1][j].first, nextred = point[i+1][j].second;
                rep(k, 26000){
                    if(dp[i][j][k]) dp[i+1][j][k + nextblue - nextred] = dp[i+1][j][k + nextred - nextblue] = true;
                }
            }
        }
    }
    int ans = mod;
    rep(k, 26000){
        if(dp[H-1][W-1][k] && abs(base - k) < ans) ans = abs(base - k);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 166180
# coding: utf-8
# Shell Sort 2018/3/15

def insertionSort(A, n, g):
    global cnt
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j-g
            cnt += 1
        A[j+g] = v

def shellSort(A, n):
    global cnt
    cnt = 0
    if n == 1:
        G = [1]
    else:
        G = []
        h = 1
        while h < n:
            G.append(h)
            h = 3*h +1
        G = G[::-1]
    m = len(G)
    print m
    print " ".join([str(i) for i in G])
    for i in range(m):
        insertionSort(A, n, G[i])

if __name__ == "__main__":
    n = int(raw_input())
    A = []
    for i in range(n):
        A.append(int(raw_input()))
    shellSort(A, n)
    print cnt
    for i in A:
        print i



Measured memory_bytes: 68072
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>

typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for(ll i=init;i<(n);i++)

int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    
    cout << max({a, b, c}) * pow(2, k) + a + b + c - max({a,b,c})<< endl;
    return 0;
}

Measured memory_bytes: 4256
num = int(input())
str_input = input()
str_arr = list(str_input)

for i in range(len(str_arr)):
    if ord(str_arr[i]) + num <= ord("Z"):
        str_arr[i] = chr(ord(str_arr[i]) + num)
    else:
        str_arr[i] = chr(ord(str_arr[i]) - ord("Z") + ord("A") + num - 1)
print("".join(str_arr))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define F(i,a,b) for(int i=(a);i<=(b);++i)
#define D(i,a,b) for(int i=(a);i>=(b);--i)
#define y1 yy1
using namespace std;
const int N=50,inf=1e9;
char a[N][N];
int s[N][N];
int dp[N][N][N][N];
inline void cmin(int &x,int y){x=x<y?x:y;}
inline int qsize(int x1,int y1,int x2,int y2){
	return s[x2][y2]-s[x1-1][y2]-s[x2][y1-1]+s[x1-1][y1-1];
}
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	F(i,1,n)scanf("%s",a[i]+1);
	int px,py;
	F(i,1,n)F(j,1,m){
		if(a[i][j]=='P')
			px=i,py=j,a[i][j]='+';
		s[i][j]=s[i-1][j]+s[i][j-1]-s[i-1][j-1]+(a[i][j]=='#');
	}
	F(x1,1,n)F(y1,1,m)F(x2,x1,n)F(y2,y1,m)
		dp[x1][y1][x2][y2]=inf;
	dp[1][1][n][m]=0;
	int ans=inf;
	F(x1,1,n)F(y1,1,m)
		D(x2,n,x1)D(y2,m,y1){
			if(px<x1||px>x2||py<y1||py>y2)continue;
			int w=dp[x1][y1][x2][y2];
			F(x,x1,x2)F(y,y1,y2){
				int c1=qsize(x1,y1,x,y)+qsize(x+1,y+1,x2,y2);
				int c2=qsize(x1,y1,x2,y2)-c1;
				cmin(dp[x1][y+1][x][y2],w+c1);
				cmin(dp[x+1][y1][x2][y],w+c1);
				cmin(dp[x1][y1][x][y],w+c2);
				cmin(dp[x+1][y+1][x2][y2],w+c2);
			}
			cmin(ans,w+qsize(x1,y1,px,py));
			cmin(ans,w+qsize(px,y1,x2,py));
			cmin(ans,w+qsize(x1,py,px,y2));
			cmin(ans,w+qsize(px,py,x2,y2));
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 20096
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<29
#define LINF LLONG_MAX/3
#define mp make_pair
#define pb push_back
#define EB emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    int r,g,b;
    cin >> r >> g >> b;
    int n = r * 100 + g * 10 + b;
    if(n%4==0){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}


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

#define int long long
#define fi first
#define se second
#define otp(n) cout << n;
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define ctv(v) rep(i,(v).size()) ct(v[i])
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define repv(i,v) for(int i=0;i<(v).size();i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);

int x,y,ans;

main() {
    cin >> x >> y;
    while(x<=y) x*=2,ans++;
    ct(ans)
}


Measured memory_bytes: 256
#ABC107, B - grid comprehension
import numpy as np
h, w = map(int, input().split(' '))
A = np.array([list(input()) for i in range(h)])


row_change = 1
col_change = 1
while(row_change == 1 or col_change == 1):
    row_change = 0
    col_change = 0
    row_del = []
    col_del = []

    for i in range(A.shape[0]):
        if all([a == '.' for a in A[i,:]]):
            row_del.append(i)
            row_change = 1
    A = np.delete(A, row_del, 0)

    for j in range(A.shape[1]):
        if all([a == '.' for a in A[:,j]]):
            col_del.append(j)
            col_change = 1
    A = np.delete(A, col_del, 1)

for i in range(A.shape[0]):
    print(''.join(A[i,:]))


Measured memory_bytes: 12584
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
#include <iostream>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;

#define pf(n) cout << n << endl
#define ps() cout <<" ";
#define sf(n) cin >> n
#define in(i,n) for (int i = 0; i < n; i++)
#define vi vector<int>
#define vp vector<pair<int, int>>
#define graph vector< vector<int> >
#define vs vector<string>
#define mn -
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define NEG(i,a,b) for (int i = b; i >= a; i--)
/**  '' "\n" ^ - **/
ll gcd(ll a,ll b)
{
    if(b==0)return a;
    return gcd(b,a%b);
}
int five=5;
int six=6;
int main() {
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    int n;
    sf(n);
    double x= (double) ((n/2)+(n%2));
    x= x/(double)n;
    pf(x);

}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 100010
int a[MAXN*2],n;
bool check(int k)
{
	for(int i=0;i<n-1;i++)
	{
		int c1=0,c2=0;
		if(a[n-i]>=k&&a[n-i-1]>=k) c1++;
		if(a[n+i]>=k&&a[n+i+1]>=k) c1++;
		if(a[n-i]<k&&a[n-i-1]<k) c2++;
		if(a[n+i]<k&&a[n+i+1]<k) c2++;
		if(c1) return 1;
		if(c2) return 0;
	}
	return a[1]>=k;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n*2-1;i++)
		scanf("%d",&a[i]);
	int l=2,r=2*n-1,ans=1;
	while(l<=r)
	{
		int mid=(l+r)/2;
		if(check(mid)) l=mid+1,ans=mid;
		else r=mid-1;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 896
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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 mod = 1000000007;
struct mint{
	ll x;
	mint(ll x = 0):x((x%mod+mod)%mod){}
	mint operator-() const{return mint(-x);}
	mint& operator+=(const mint a){
		if((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a){
		if((x += mod-a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a){
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const{
		mint res(*this);
		return res+=a;
	}
	mint operator-(const mint a) const{
		mint res(*this);
		return res-=a;
	}
	mint operator*(const mint a) const{
		mint res(*this);
		return res*=a;
	}
	mint pow(ll t) const{
		if(!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if(t&1) a *= *this;
		return a;
	}
	mint inv() const{
		return pow(mod-2);
	}
	mint& operator/=(const mint a){
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const{
		mint res(*this);
		return res/=a;
	}
	bool operator==(const mint a){
		return x == a.x;
	}
};

mint dp[2005][2005][2];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> s(n+1), t(m+1);
    rep(i,n) cin >> s[i];
    rep(j,m) cin >> t[j];
    dp[0][0][0] = 1;
    rep(i,n+1)rep(j,m+1){
        dp[i+1][j][0] += dp[i][j][0];
        dp[i][j][1] += dp[i][j][0];
        dp[i][j+1][1] += dp[i][j][1];
        if(s[i] == t[j]) dp[i+1][j+1][0] += dp[i][j][1];
    }
    mint ans = dp[n][m][1];
    cout << ans.x << endl;
	return 0;
}

Measured memory_bytes: 66476
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);
    
    int N = sc.nextInt();
    int K = sc.nextInt();

    int[] A = new int[N];

    for (int i = 0; i < N; i++) {
      A[i] = sc.nextInt();
    }

    sc.close();

    long mod = 1000000007;

    // Aの内部で発生する転倒数
    long count1 = 0;

    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        if (i < j && A[i] > A[j] ){
          count1++;
        }
      }
    }

    // AiとAjの間で発生する転倒数
    long count2 = 0;

    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        if (A[i] > A[j]){
          count2++;
        }
      }
    }

    // A単体で発生する転倒数の総和（% mod）
    long mod1 = ((long)count1 * K) % mod;

    // AiとAjの間で発生する転倒数の総和（% mod）
    long mod2 = (count2 % mod) * ((((long)K * (long)(K-1))/2) % mod);

    System.out.println((mod1 + mod2) % mod);

  }

}

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

int main(){
    int X, N;
    cin >> X >> N;
    vector<int> Seen(100, 0);
    for (int i=0; i<N; i++){
        int p;
        cin >> p;
        Seen[p-1] = 1;
    }
    int ans = X;
    if (Seen[ans-1] == 0){
        cout << ans << endl;
        return 0;
    }
    for (int i=1; i<101; i++){
        ans = X - i;
        if (Seen[ans-1] == 0){
            cout << ans << endl;
            return 0;
        }
        ans = X + i;
        if (Seen[ans-1] == 0){
            cout << ans << endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 3632
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=998244353;
constexpr int N=1000000;

inline unsigned long xor128() {
	static unsigned long x=123456789, y=362436069, z=521288629, w=88675123;
	unsigned long t=(x^(x<<11));
	x=y; y=z; z=w;
	return (w=((w>>19)^t^(t>>8)));
}

int D,c[26],s[200000][26],t[200000],T[200000],v,V,l[26];

int main(){
	scanf("%d",&D);
	for(int i=0;i<26;i++){
		scanf("%d",&c[i]);
	}
	for(int i=0;i<D;i++){
		for(int j=0;j<26;j++){
			scanf("%d",&s[i][j]);
		}
	}
	for(int i=0;i<D;i++){
		pair<int,int>mx={-1,-1};
		for(int j=0;j<26;j++){
			mx=max(mx,{s[i][j],j});
		}
		t[i]=mx.second;
	}
	for(int i=0;i<26;i++){
		l[i]=-1;
	}
	for(int i=0;i<D;i++){
		l[t[i]]=i;
		v+=s[i][t[i]];
		for(int j=0;j<26;j++){
			v-=c[j]*(i-l[j]);
		}
	}
	for(int i=0;i<N;i++){
		for(int j=0;j<D;j++){
			if(xor128()%200==0){
				T[j]=xor128()%26;
			}
			else{
				T[j]=t[j];
			}
		}
		for(int j=0;j<26;j++){
			l[j]=-1;
		}
		V=0;
		for(int j=0;j<D;j++){
			V-=c[T[j]]*(j-l[T[j]]-1)*(j-l[T[j]])/2;
			l[T[j]]=j;
			V+=s[j][T[j]];
		}
		for(int j=0;j<26;j++){
			V-=c[j]*(D-l[j]-1)*(D-l[j])/2;
		}
		if(V>v){
			v=V;
			for(int j=0;j<D;j++){
				t[j]=T[j];
			}
		}
	}
	for(int i=0;i<D;i++){
		printf("%d\n",t[i]+1);
	}
}


Measured memory_bytes: 3888
/*
Aaaye mera solution dekhne aaye ho... bdia hai... :P

Swaagat hai aap logo ka!!
*/


#include<bits/stdc++.h>
#define ull unsigned long long
#define lld long long
#define mod 1000000007
#define ld long
#define ldo long double

using namespace std;

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

    string s;
    cin>>s;
    lld i,bCount = 0,ans = 0;
    lld siz = (lld)s.length();

    for(i=0;i<siz;++i){
        if(s[i] == 'B')
            bCount++;
        else{
            ans += bCount;
        }
    }

    cout<<ans;

    return 0;
}



Measured memory_bytes: 720
import System.IO

main :: IO()
main = do
  end <- isEOF
  if end then return()
  else do
    n <- readLn
    let xs = [a+b+c+d | a<-[0..9],b<-[0..9],c<-[0..9],d<-[0..9]] :: [Int]
        f x = length $ filter (==x) xs
        in putStrLn . show $ f n
    main

Measured memory_bytes: 4104
N = int(input())

nodes = [tuple(map(int, input().split(' '))) for _ in range(N)]
d = [-1 for _ in range(N + 1)]
f = [-1 for _ in range(N + 1)]

clock = 0


def dfs(node):
    global clock
    if d[node] == -1:
        clock += 1
        d[node] = clock
    neighbors = sorted(nodes[node - 1][2:])

    for neighbor in neighbors:
        if d[neighbor] == -1:
            dfs(neighbor)

    if f[node] == -1:
        clock += 1
        f[node] = clock


for i in range(1, N + 1):
    dfs(i)
    print(i, d[i], f[i])



Measured memory_bytes: 5664
#pypyは内包表記使わない, rstrip注意
#提出前に見返すこと！
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 1000000007

    x = int(input())
    for i in range(x, 0, -1):
        for b in range(1, 35):
            for p in range(2, 10):
                if b**p==i:
                    print(i)
                    exit()

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
	cin>>a>>b>>c;
    if(a==b) 
	  cout<<c<<endl;
    if(b==c)
	  cout<<a<<endl;
    if(c==a) 
	  cout<<b<<endl;
return 0;
}

Measured memory_bytes: 256
import sys
from collections import defaultdict

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N = int(rl())
    graph = [[] for _ in range(N)]
    counter = defaultdict(int)
    edges = []
    for _ in range(N - 1):
        a, b = map(lambda x: int(x) - 1, rl().split())
        graph[a].append(b)
        edges.append(b)
        counter[a] += 1
        counter[b] += 1
    
    ans = [0] * N
    
    def bfs(parent, p_color):
        c_color = 1
        for child in graph[parent]:
            if c_color == p_color:
                c_color += 1
            ans[child] = c_color
            bfs(child, c_color)
            c_color += 1
    
    bfs(0, 0)
    print(max(counter.values()))
    for edge in edges:
        print(ans[edge])


if __name__ == '__main__':
    solve()


Measured memory_bytes: 135964
#include<iostream>
using namespace std;
int main(){
	int k,s;
	cin>>k>>s;
	int a=0;
		for(int x=0;x<=k;x++){
		for(int y=0;y<=k;y++){
		int z=s-(x+y);
	    if(z>=0&&z<=k)
	    a++;
}
}
cout<<a;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

int main()
{
	int n;
	cin >> n;
	int d[51] = {};
	for(int i = 1; i < n + 1; i++){
		cin >> d[i];
	}
	if(n + 1 >= 25){
		cout << 0 << endl;
		return 0;
	}
	if(n + 1 == 24){
		int cnt[13] = {};
		for(int i = 0; i < n; i++){
			cnt[d[i]]++;
		}
		int ans = 1;
		if(cnt[0] >= 2 || cnt[12] >= 2) ans = 0;
		for(int i = 1; i <= 11; i++){
			if(cnt[i] > 2) ans = 0;
		}
		cout << ans << endl;
		return 0;
	}
	int ans = 0;
	for(int i = 0; i < (1 << n); i++){
		int nowd[51] = {};
		for(int j = 1; j < n + 1; j++){
			if((i & (1 << (j - 1))) == 0 || d[j] == 0) nowd[j] = d[j];
			else nowd[j] = -d[j];
		}
		sort(nowd, nowd + n + 1);
		int s = 24 - (nowd[n] - nowd[0]);
		// cout << i << endl;
		// for(int j = 0; j < n + 1; j++){
		// 	cout << nowd[j] << " ";
		// }
		// cout << endl;
		for(int j = 0; j < n; j++){
			s = min(s, nowd[j + 1] - nowd[j]);
		}
		// cout << s << endl;
		ans = max(ans, s);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;

int main()
{
	int n, k;
	cin >> n >> k;
	vector<char> s(n);
	rep(i, n) cin >> s.at(i);
	int happy = 0;
	rep(i, n-1) {
		if (s.at(i)=='L'&&s.at(i+1) == 'L') ++happy;
		if (s.at(i) == 'R'&&s.at(i+1) == 'R') ++happy;
	}
	cout << min(happy + 2 * k,n-1)<< endl;
}

Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <vector>

auto N = std::size_t();
auto W = std::size_t();
int main()
{
    std::cin >> N >> W;

    auto weight = std::vector<int64_t>(N);
    auto value = std::vector<std::int64_t>(N);

    for (std::size_t i = 0; i < N; ++i) std::cin >> weight[i] >> value[i];

    auto dp = std::vector<std::vector<std::int64_t>>(N + 1, std::vector<std::int64_t>(W + 1, 0));

    for (std::size_t i = 0; i < N; ++i)
    {
        for (std::size_t w = 0; w <= W; ++w)
        {
            if (w >= weight[i])
                dp[i + 1][w] = std::max(dp[i][w - weight[i]] + value[i], dp[i][w]);
            else
                dp[i + 1][w] = dp[i][w];
        }
    }

    std::cout << dp[N][W] << std::endl;

    return 0;
}

Measured memory_bytes: 80256
#include <iostream>//cout<<right で右揃え
#include <iomanip>//cout<<setw(数字) で空白による桁揃え
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <cstdlib>//abs()で整数絶対値
#include <cmath>//abs()かfabs()で少数絶対値
#include <functional>//sort第三引数greater<型名>()で降順
#include <map>

using namespace std;
using ll = long long int;

int main(){
    string S;
    cin>>S;
    string s = S.substr(0,3);
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 3628
import numpy as np

N, L = map(int, input().split())
apples = np.array([L]*N)
apples = apples + np.arange(0, N)

if apples.min() >= 0:
    print(apples.sum()-apples.min())
elif apples.max() <= 0:
    print(apples.sum()-apples.max())
else:
    print(apples.sum())

Measured memory_bytes: 21524
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1000000000000000000;
constexpr int MOD = 1000000007;

#include <boost/multiprecision/cpp_int.hpp>

namespace mp = boost::multiprecision;
using namespace mp;

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    bool zero = false;
    bool inf = false;
    bool one = false;
    rep(i,n){
        cin >> a[i];
        if(a[i]==0LL) zero = true;
        if(a[i] > LINF) inf = true;
        if(a[i] > 1) one = true;
    }
    if(zero||(one && inf)){
        cout << 0 << endl;
        return 0;
    }
    cpp_int p = 1;
    ll ans = 1;
    bool ok = true;
    rep(i,n){
        ans *= a[i];
        p *= a[i];
        //cout << ans << endl;
        if(p > LINF || p < 0){
            ok = false;
            break;
        }
    }
    if(ok){
        cout << ans << endl;
    }else{
        cout << -1 << endl;
    }
    return 0;
}

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

N,M = list(map(int, input().split()))

AC = [False for _ in range(N)]
WA = [0 for _ in range(N)]
total_WA = 0

for _ in range(M):
    p,s = input().split()
    p = int(p)-1
    if AC[p]:
        continue
    if s=='AC':
        AC[p] = True
        total_WA += WA[p]
    else:
        WA[p] += 1

print(sum(AC), total_WA)

Measured memory_bytes: 4656
MOD = 1_000_000_007

io = STDIN
n,k=io.gets.split.map(&:to_i)
ar=Array.new(n+1){|i|i}
cum=Array.new(n+2,0)
(n+1).times do |i|
  cum[i+1]+=cum[i]+ar[i]
end
ans=0
(n-k+2).times do |i|
  ans+=(cum[-1]-cum[-1-i])-(cum[i])+1
  ans %= MOD
end
puts ans


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

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int R;
signed main() {
    cin>>R;
    if(R<1200)cout<<"ABC"<<endl;
    else if(R<2800) cout<<"ARC"<<endl;
    else cout<<"AGC"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int dp[200010];

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

    string last;
    int pos = 0, ans = 0;
    rep(i, s.size()) {
        string t = s.substr(pos, i - pos + 1);
        if (last != t) {
            last = t;
            pos = i + 1;
            ans++;
        }
    }
    cout << ans << endl;
}


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

using namespace std;

#define REP(i,m) for(int i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define INF 1000000001
#define INFL (1LL << 60)
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>

int main() {
  int n;
  cin >> n;
  int p[n];
  REP(i, n) cin >> p[i];
  REP(i, n){
    if(p[i] > i){
      cout << -1 << endl;
      return 0;
    }
    if(i != n-1 && p[i+1]-p[i] > 1){
      cout << -1 << endl;
      return 0;
    }
  }
  ll ans = 0;
  REP(i, n-1){
    if(p[i] >= p[i+1]) ans += p[i];
  }
  cout << ans+p[n-1] << endl;
  return 0;
}


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

string sp, t, s;
vector<string> sv;

int main() {
	cin >> sp >> t;
	for (int i = 0; i + (int) t.size() <= (int) sp.size(); i++) {
		s = sp;
		bool b = 1;
		for (int j = 0; j < (int) t.size(); j++)
			if (sp[i + j] == '?')
				s[i + j] = t[j];
			else if (sp[i + j] != t[j]) {
				b = 0;
				break;
			}
		if (b) {
			for (int j = 0; j < (int) s.size(); j++)
				if (s[j] == '?')
					s[j] = 'a';
			sv.push_back(s);
		}
	}

	if (sv.size()) {
		sort(sv.begin(), sv.end());
		cout << sv[0] << endl;
	} else
		cout << "UNRESTORABLE" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

int A[300][300] = {0};
set<int> removedSet;

int main()
{
    // 整数の入力
    long long N,M,i,j,temp,minmax;
    cin >> N >> M;
    for (i=0;i<N;i++){
        for (j = 0;j<M;j++){
            cin >> temp;
            A[i][j] = temp;
        }
    }

    map<int,int> counts;
    minmax = 301;
    for (j=0;j<M;j++){
        counts.clear();
        for (i=0;i<N;i++){
            int t = 0;
            while(removedSet.count(A[i][t]) != 0){
                t++;
            }
            counts[A[i][t]] += 1;
        }
        int max = 0;
        int key = 0;
        for(auto itr = counts.begin(); itr != counts.end(); ++itr) {
            if (itr->second > max){
                max = itr->second;
                key = itr->first;
            }
        }
        removedSet.insert(key);
        if (max < minmax){
            minmax = max;
        }
    }
    cout << minmax << endl;

    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define vlli vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vplli vector< pair< ll,ll> >
#define plli pair< ll,ll >
#define vps vector< pair< string, string> >
#define vpi vector< pair< int, int> >
#define all(x) x.begin(), x.end()
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n) for(ll i=a;i<n;i++)
#define scan(arr,a,n) for(ll i=(a);i<(n);i++)cin>>(arr)[i];
#define print(arr,a,n) for(ll i=(a);i<(n);i++)cout<<(arr)[i]<<" ";

ll add(ll x, ll y) {ll res = x + y; return (res >= mod ? res - mod : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= mod ? res % mod : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + mod : res);}
ll power(ll x, ll y) {ll res = 1; x %= mod; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
ll mod_inv(ll x) {return power(x, mod - 2);}


int main(){
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
    #endif
    unsigned ll n, k;
    cin>>n>>k;
    ll a[n+1] = {};
    scan(a, 1, n+1);
    forn(i, k+1, n+1){
        if(a[i]>a[i-k]){
            cout<<"Yes"<<endl;
        }
        else{
            cout<<"No"<<endl;
        }
    }
}

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

using namespace std;

void Main() {
    string s;
    cin >> s;
    int K;
    cin >> K;

    int N = s.size();
    set<string> topK;
    for (int i = 0; i < N; ++i) {
        int M = min(5, N - i);
        for (int j = 1; j <= M; ++j) {
            string subs = s.substr(i, j);
            if (topK.size() < K) {
                topK.insert(subs);
            }
            else {
                for (auto e : topK) {
                    if (subs < e) {
                        topK.insert(subs);
                        if (topK.size() > K) {
                            topK.erase(*(topK.rbegin()));
                        }
                    }
                }
            }
        }
    }
    cout << *(topK.rbegin()) << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3608
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

type prob struct {
	p, score, bonus, sum int
}

func main() {
	d, g := uint(getInt()), getInt()
	ps := make([]prob, d)
	for i := range ps {
		ps[i].p = getInt()
		ps[i].bonus = getInt()
		ps[i].score = (i + 1) * 100
		ps[i].sum = (ps[i].p * ps[i].score) + ps[i].bonus
	}

	ans := 1 << 60
	for i := 0; i < (1 << d); i++ {
		tmp := 0
		cnt := 0
		s := make([]int, 0)
		for j := uint(0); j < d; j++ {
			k := 1 << j
			if (i & k) > 0 {
				tmp += ps[j].sum
				cnt += ps[j].p
			} else {
				for l := 0; l < ps[j].p; l++ {
					s = append(s, ps[j].score)
				}
				s[len(s)-ps[j].p] += ps[j].bonus
			}
		}

		for j := len(s) - 1; tmp < g; j-- {
			tmp += s[j]
			cnt++
		}

		ans = min(ans, cnt)
	}

	fmt.Println(ans)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
}

func getInt() int {
	i, err := strconv.Atoi(getString())
	if err != nil {
		panic(err)
	}
	return i
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}


Measured memory_bytes: 6656
import sys
sys.setrecursionlimit(10**6)

input = sys.stdin.readline
n = int(input())
G = [[] for _ in range(n)]
E = []
for i in range(n-1):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
    E.append((a, b))

cs = []
ans = {}
def dfs(v, p, c):
    color = 0
    for g in G[v]:
        if g == p:
            continue
        color += 1
        if color == c:
            color += 1
        dfs(g, v, color)
        ans[(v+1, g+1)] = color

dfs(0, -1, 0)
print(max(ans.values()))
for e in E:
    print(ans[e])


Measured memory_bytes: 77684
N, K = map(int, input().split())

ans = 0

for i in range(1, N + 1):
    tmp = 1 / N  # その目が出る確率
    now = i
    while now < K:
        now *= 2
        tmp /= 2
    ans += tmp  # その目でクリアできる確率
print(ans)


Measured memory_bytes: 2940
#include<iostream>
#include<vector>
using namespace std;
int main() {
  long long N;
  cin >> N;
  if(N == 2) {
    cout << 1 << endl;
    return 0;
  }
  long long i,n = N-1;
  long long cnt = 1;
  vector<int> A;
  for(i=2;i*i<=n;i++) {
    if(n % i == 0) {
      A.push_back(0);
      while(n%i == 0) {
        n /= i;
        A[A.size()-1]++;
      }
    }
  }
  if(n > 1)A.push_back(1);
  for(i=0;i<A.size();i++) {
    cnt *= (A[i]+1);
  }
  for(i=2;i*i<N;i++) {
    if(N%i == 0) {
      n = N;
      while(n%i == 0)n /= i;
      if(n%i == 1)cnt++;
      n = i;
      while(n%(N/i) == 0)n /= (N/i);
      if(n%(N/i) == 1)cnt++;
    }
  }
  if(i*i == N)cnt++;
  cout << cnt << endl;
}

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

int main() {
  ll N, K;
  cin >> N >> K;
  
  ll x = N / K;
  ll ans = x * x * x;
  
  if (K % 2 == 0) {
    ll y = (N + K / 2) / K;
    ans += (y * y * y);
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
N=int(input())
ans=[0]*N
for x in range(1,int((N-1)/2)):
    for y in range(x,int((N-1)/2)):
        if x ** 2 + y ** 2 + 1 ** 2 + x * y + y * 1 + 1 * x > N:
            break
        for z in range(y,int((N-1)/2)):
            if x**2+y**2+z**2+x*y+y*z+z*x<=N:
                if x==y and y==z:
                    ans[x**2+y**2+z**2+x*y+y*z+z*x-1]+=1
                elif x==y or y==z or z==x:
                    ans[x**2+y**2+z**2+x*y+y*z+z*x-1]+=3
                else:
                    ans[x**2+y**2+z**2+x*y+y*z+z*x-1]+=6
            else:
                break

for n in range(N):
    print(ans[n])

Measured memory_bytes: 9288
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))



int main(){
    ll ans,n;
    cin>>n;
    ll c[n],v[n];
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    for(int i=0;i<n;i++){
        cin>>c[i];
    }
    for(int i=0;i<n;i++){
        ans=max(ans,ans+(v[i]-c[i]));
    }
    

    dbg{
        if(true)cout <<"YES"<<endl;
        else cout <<"NO"<<endl;
    }

    cout <<ans<<endl;

    return 0;

}

Measured memory_bytes: 256
#include <stdio.h>

#define SIZE_MAX 8

typedef unsigned int ui;

char s[SIZE_MAX][SIZE_MAX + 1];

int isMami;
int remain;

ui fucker;

int isvalidcoor(int n){
	return (0 <= n) && (n < SIZE_MAX);
}

char cake(){
	return (isMami ? 'o' : 'x');
}

void progress(int h, int w){
	int vects[8][2] = {
		{-1, -1},
		{-1,  0},
		{-1, +1},
		{ 0, -1},
		{ 0, +1},
		{+1, -1},
		{+1,  0},
		{+1, +1}
	};
	int v;
	char c = cake();
	s[h][w] = c;
	// printf("fucker: %d", fucker);
	for (v = 0; v < 8; v++) {
		int i, j;
		int isLinable = fucker & 1;
		fucker /= 2;
		if (!isLinable) continue;
		i = h;
		j = w;
		// printf("%d ", v);
		for (;;) {
			i += vects[v][0];
			j += vects[v][1];
			if (isvalidcoor(i) && isvalidcoor(j)) {
				if (s[i][j] == c) {
					break;
				} else {
					s[i][j] = c;
				}
			} else {
				break;
			}
		}
	}
	// putchar('\n');
	return;
}

ui isvalidturn(int h, int w){
	ui n = 0;
	char c;
	int vects[8][2] = {
		{-1, -1},
		{-1,  0},
		{-1, +1},
		{ 0, -1},
		{ 0, +1},
		{+1, -1},
		{+1,  0},
		{+1, +1}
	};
	int v;
	char k = cake();
	ui raper = 0;
	for (v = 0; v < 8; v++) {
		int i, j;
		int m = 0;
		i = h;
		j = w;
		for (;;) {
			i += vects[v][0];
			j += vects[v][1];
			c = s[i][j];
			if (!isvalidcoor(i) || !isvalidcoor(j) || c == '.') {
				m = 0;
				break;
			} else if (c == k) {
				raper |= (1 << v);
				break;
			} else {
				m++;
			}
		}
		n += m;
	}
	// printf("r = %d\n", raper);
	// printf("n = %d\n", n);
	return (n << 8) + raper;
}

int isBetter(int h, int w, int i, int j){
	if (isMami) {
		return ((i < h) || (i == h && j < w));
	} else {
		return ((i > h) || (i == h && j > w));
	}
}

int virtuoso(){
	int h = 0, w = -1;
	ui n = 0;
	int i, j;
	ui f;
	for (i = 0; i < SIZE_MAX; i++)
		for (j = 0; j < SIZE_MAX; j++) {
			ui m;
			if (s[i][j] != '.')
				continue;
			// printf("%d %d", i, j);
			m = isvalidturn(i, j);
			f = m % (1 << 8);
			m = m >> 8;
			// printf("f = %d\n", f);
			// printf("m = %d\n", m);
			if (m > n || (m == n && isBetter(h, w, i, j))) {
				h = i, w = j;
				n = m;
				fucker = f;
			}
		}
	return(n ? (h * SIZE_MAX + w) : SIZE_MAX * SIZE_MAX);
}

int output(){
	int i;
	for (i = 0; i < SIZE_MAX; i++) {
		puts(s[i]);
	}
	return! 810;
}

int hideous(){
	int n;
	int is_collapse = 2;
	while (is_collapse && remain) {
		// printf("%d %d", is_collapse, remain);
		isMami ^= 1;
		n = virtuoso();
		// printf("%d %d\n", n / 8, n % 8);
		// printf("%d\n", fucker);
		if (n == SIZE_MAX * SIZE_MAX) {
			is_collapse--;
			continue;
		}
		is_collapse = 2;
		progress(n / 8, n % 8);
		remain--;
		// output();
		// putchar('\n');
	}
	return output();
}

int main(void){
	int i;
	for (i = 0; i < SIZE_MAX; i++) {
		scanf("%s", s[i]);
		{
			char *c = s[i];
			while (*c) {
				if (*c == '.')
					remain++;
				c++;
			}
		}
	}
	hideous();
	return! 114514;
}

Measured memory_bytes: 524