akhauriyash/Code-Regression huggingface dataset:
import kotlin.math.max

fun main() {
    val nk = nextLong()
    val an = nextLongList()
    val ans = solve(an)
    println(ans)


}


fun solve(k: List<Long>): Long {
    return step(k)
}

fun step(height: List<Long>): Long {
    tailrec fun loop(tempMax: Long, stepSum: Long, index: Int): Long {
        return if (height.size == index) {
            stepSum
        } else {
            val newStepSum = if (tempMax > height[index]) stepSum + (tempMax - height[index]) else stepSum
            val newTempMax = max(tempMax, height[index])
            loop(newTempMax, newStepSum, index + 1)
        }
    }
    return loop(0L, 0L, 0)
}


fun nextInt(): Int {
    return readLine()!!.toInt()
}

fun nextIntList(): List<Int> {
    return readLine()!!.split(" ").map { it.toInt() }
}
fun nextLong(): Long {
    return readLine()!!.toLong()
}

fun nextLongList(): List<Long> {
    return readLine()!!.split(" ").map { it.toLong() }
}

fun nextString(): String {
    return readLine()!!
}

Measured memory_bytes: 65272
#include <bits/stdc++.h>
 using namespace std;
 #define rep(i,N) for(int i=0;i<int(N);++i)
 typedef long long ll;
 
 template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
 const ll INFLL = 1e18;
 int main() {
     int N,T;
     cin>>N>>T;
     vector<ll> A(N),B(N);
     rep(i,N)cin>>A[i]>>B[i];
     /*
     dp1[i][t]:1~iまでの食べ物でt秒以内に完食して得られる満足度の最大値
     dp2[i][t]:N~iまでの食べ物でt秒以内に完食して得られる満足度の最大値
     => dp1[i-1][t] + dp2[i+1][T-1-t]：
     i以外の食べ物でT-1秒以内に完食して得られる満足度の最大値
        これにB[i+1]を足せば、OK
     */
     vector<vector<ll>> dp1(N+2,vector<ll>(T,-INFLL));
     vector<vector<ll>> dp2(N+2,vector<ll>(T,-INFLL));
     rep(t,T){
         dp1[0][t] = 0;
         dp2[N+1][t] = 0;
     }
     rep(i,N)rep(t,T){
         chmax(dp1[i+1][t], dp1[i][t]);
         if(t + A[i] < T){
             chmax(dp1[i+1][t+A[i]],dp1[i][t] + B[i]);
         }
     }
     reverse(A.begin(), A.end());
     reverse(B.begin(), B.end());
     rep(i,N)rep(t,T){
             chmax(dp2[N+1-i-1][t], dp2[N+1-i][t]);
             if(t + A[i] < T){
                 chmax(dp2[N+1-i-1][t + A[i]],dp2[N+1-i][t] + B[i]);
             }
     }
     reverse(A.begin(), A.end());
     reverse(B.begin(), B.end());
     ll ans = 0;
     rep(i,N){
         rep(t,T){
             chmax(ans, dp1[i][t] + dp2[i+2][T-1-t] + B[i]);
         }
     }
     cout<<ans<<endl;
 }

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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<string> vst;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;


const ll mod=1e9+7;
const ll inf=1e16; 

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m;i>=n;i--)

int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);

 ll n;
  cin >> n;
  vll a(n);
  bool flag=true;
  
  rep(i,0,n) {
    cin >> a[i];
    if(a[i]%2==0){
     if(a[i]%3!=0&&a[i]%5!=0) flag=false; 
    }
  }
  if(flag) cout << "APPROVED" << endl;
  else cout << "DENIED" << endl;
  
  
}


Measured memory_bytes: 256
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.TreeMap;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		String[] s = new String[n];

		int i;
		TreeMap<String, Integer> map = new TreeMap<>();
		for(i = 0; i < n; i++) {
			s[i] = scan.next();
			if(map.containsKey(s[i]))
				map.put(s[i], map.get(s[i]) + 1);
			else
				map.put(s[i], 1);
		}
		int max = Integer.MIN_VALUE;
		for(int a: map.values()) {
			if(max < a)
				max = a;
		}
		for(Entry<String, Integer> temp : map.entrySet()) {
			if(temp.getValue() == max)
				System.out.println(temp.getKey());
		}
	}
}

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

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
ll inf = 1e18;

ll H, W, K;
string S[15];
ll sumC[15][1010]; //列のホワイトチョコ数
ll ans = inf;
int main() {
	cin >> H >> W >> K;
	REP(i, 0, H) {
		cin >> S[i];
	}
	REP(w, 0, W){
		REP(h,0,H){
			sumC[h+1][w] += sumC[h][w] + (S[h][w] == '1');
		}
	}
//	REP(h,1,H+1){
//		REP(w,0,W){
//			cout << sumC[h][w] << " ";
//		}
//		p("");
//	}
//	ll cnt = 0;
//	ll sum = 0;
//	REP(w, 0, W) {
//		ll now_white = sumC[H][w] - sumC[0][w];
//		if (sum + now_white > K) {
//			sum = now_white;
//			cnt++; //縦カット
//		}else{
//			sum += now_white;
//		}
//	}
//	ans = cnt;
	for (ll mask = 0; mask < (1 << (H-1)); mask++) {
		ll max_cnt = 0;
		ll yoko_cnt = 0;
		vector<ll> yoko;
		yoko.push_back(0LL);
		for (ll h = 0; h < H-1; h++) {
			if (mask & (1 << h)) {
				yoko_cnt++;
				yoko.push_back(h+1);
			}
		}
		yoko.push_back(H);
		ll sum[15];
		for(ll i = 0; i < 15; i++) {
			sum[i] = 0;
		}
		ll cnt = 0;
		REP(w, 0, W) {
			bool cut_flg = false;
			ll now_white[15];
			for(ll i = 0; i < 15; i++) {
				now_white[i] = 0;
			}
			for(ll i = 0; i < yoko.size()-1; i++){
				now_white[i] = sumC[yoko[i+1]][w] - sumC[yoko[i]][w];
				if(now_white[i] > K){
					max_cnt = inf;
				}
				if (sum[i] + now_white[i] > K) {
					cut_flg = true;
				}
			}
			if(cut_flg){
				cnt++; //縦カット
				for(ll i = 0; i < yoko.size()-1; i++) {
					sum[i] = now_white[i];
				}
			}else{
				for(ll i = 0; i < yoko.size()-1; i++) {
					sum[i] += now_white[i];
				}
			}
		}
		max_cnt = max(max_cnt, cnt) + yoko_cnt;
//		p(max_cnt);
		ans = min(ans, max_cnt);
	}
	p(ans);

	return 0;
}

Measured memory_bytes: 384
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)

	g := make([][]int, n)
	ans := make([][]int, n)

	inf := 1 << 30
	for i := 0; i < n; i++ {
		g[i] = make([]int, n)
		ans[i] = make([]int, n)
		for ii := 0; ii < n; ii++ {
			g[i][ii] = getNextInt(scanner)
			if g[i][ii] == -1 {
				g[i][ii] = inf
			}
			ans[i][ii] = -1
		}
	}

	im := make(IntMap, 1)

	im.increment(1)

	for len(im) < n {
		min := inf
		u := -1
		v := -1
		for i := range im {
			for ii := 0; ii < n; ii++ {
				if im.get(ii) != 0 {
					continue
				}
				if min > g[i][ii] {
					min = g[i][ii]
					u = i
					v = ii
				}
			}
		}
		im.increment(v)
		ans[u][v] = min
		ans[v][u] = min
	}

	sum := 0
	for i := 0; i < n-1; i++ {
		for ii := i + 1; ii < n; ii++ {
			if ans[i][ii] != -1 {
				sum += ans[i][ii]
			}
		}
	}

	fmt.Fprintln(writer, sum)
	writer.Flush()
}

// IntMap ...
type IntMap map[int]int

func (m IntMap) get(key int) int {
	if _, ok := m[key]; ok {
		return m[key]
	}
	return 0
}
func (m IntMap) increment(key int) {
	if _, ok := m[key]; ok == false {
		m[key] = 0
	}
	m[key]++
}



Measured memory_bytes: 1384
#include<iostream>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  if(a<b){
    cout<<"a < b"<<'\n';
  }
  else if(a>b){
    cout<<"a > b"<<'\n';
  }
  else if(a=b){
    cout<<"a == b"<<'\n';
  }
  return(0);
}



Measured memory_bytes: 3100
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}


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

    int a=1,b=0,n;
    cin>>n;
    rep(i,n){
        int c,d;
        cin>>c>>d;
        if(c==1)a*=d,b*=d;
        if(c==2)b+=d;
        if(c==3)b-=d;
    }
    cout<<-b<<" "<<a<<endl;
}



Measured memory_bytes: 3176
s=input()
t=list(s)
u=sorted(list(set(t)))
ans=[]
for i in range(len(u)):
  ans.append(u[i])
k=int(input())
for j in range(1,min(10,len(t))):
  for i in range(len(t)-j):
    ans.append(s[i:i+j+1])
ans=sorted(list(set(ans)))
print(ans[k-1])


Measured memory_bytes: 8688
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <chrono> //1e+9で割る auto end= chrono::system_clock::now()-st;  cout<<end.count()%1e+9<<endl;
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef long double db;

#define fr first
#define sc second
#define pb push_back
#define rep(i,x) for(ll i=0;i<x;i++)
#define rep1(i,x) for(ll i=1;i<=x;i++)
#define rrep(i,x) for(ll i=x-1;i>=0;i--)
#define rrep1(i,x) for(ll i=x;i>0;i--)
ll N;
ll a[300000];
ll cnt;
ll ans;

int main()
{
	cin>>N;
	rep(i,N*3) cin>>a[i];
	sort(a,a+3*N);
	for(ll i=N*3-2;i>=0;i-=2){
		if(cnt==N) break;
		ans+=a[i];
		cnt++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int v_num = pow(10, 5) + 1;

int main()
{
    int n, v;
    cin >> n;
    vector<int> even(v_num, 0), odd(v_num + 1, 0);
    for(int i=0; i < n; ++i){
        cin >> v;
        if(i%2==0) even[v]++;
        else odd[v]++;
    }

    bool same = false;
    vector<int>::iterator evenMaxIt = max_element(even.begin(), even.end());
    vector<int>::iterator oddMaxIt  = max_element(odd.begin(), odd.end());
    if(distance(even.begin(), evenMaxIt) == distance(odd.begin(), oddMaxIt)) same = true;

    sort(even.begin(), even.end(), greater<int>());
    sort(odd.begin(), odd.end(), greater<int>());
    if(same){
        if(even[0] == odd[0]){
            if(even[1] < odd[1]) {
                cout << n - even[0] - odd[1] << endl;
            }else{
                cout << n - even[1] - odd[0] << endl;
            }
        }else if(even[0] > odd[0]){
            cout << n - even[0] - odd[1] << endl;
        }else{
            cout << n - even[1] - odd[0] << endl;
        }
    }else{
        cout << n - even[0] - odd[0] << endl;
    }

    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define All(a) a.begin(),a.end()
#define INF 1000000007
const int MOD = 1000000007;
//accumulate(vec.begin(), vec.end(), 0)

int gcd(int x,int y){
  if(x%y==0) return y;
  else return gcd(y,x%y);
}

bool isPrime(int n){
  if(n < 2) return false;
  else if(n == 2) return true;
  else if(n%2==0) return false;

  for(int i=3;i<=sqrt(n);i++){
    if(n%i==0) return false;
  }
  return true;
}

int main(){
  int n;
  cin >> n;
  vector<int>v(n);
  for(int i=0;i<n;i++) cin >> v[i];
  sort(All(v));
  double ans = v[0];
  for(int i=0;i<n-1;i++){
    ans = (ans+v[i+1])/2;
  }
  cout<< ans <<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
using namespace std;

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

	vector<int32_t> T(N), A(N);
	for (int32_t i = 0; i < N; i++)
		cin >> T[i] >> A[i];

	int64_t taka = 0, aoki = 0;
	for (int32_t i = 0; i < N; i++) {
		int64_t j = max(taka / T[i], aoki / A[i]);
		if (j == 0)
			j = 1;

		while (true) {
			if (taka <= T[i] * j && aoki <= A[i] * j) {
				taka = T[i] * j;
				aoki = A[i] * j;
				break;
			}
			j++;
		}
	}

	cout << taka + aoki  << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
const long INF=1000000000000000;
const long MOD=1000000007;

int main() {
    long x,y;
    cin>>x>>y;
    vector<long> v={0,1,3,1,2,1,2,1,1,2,1,2,1};
    if(v.at(x)==v.at(y)) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>

using namespace std;
int main(){
    string s;
    cin >> s;
    char c = s[0];
    for (int i = 1; i < 4; i++){
        if (c == s[i]){
            cout << "Bad" << endl;
            return 0;
        }
        c = s[i];
    }
    cout << "Good" << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
def E():
    N = int(input())
    A = [int(n) for n in input().split()]
    record = defaultdict(int)
    count = 0
    for i in range(len(A)):
        cur = i-A[i]
        count += record[cur]
        record[i+A[i]] += 1
    
    print(count)

E()

Measured memory_bytes: 61924
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_129
{
    class A
    {
        static void Main(string[] args)
        {
            Method(args);
        }

        static void Method(string[] args)
        {
            int[] pqr = ReadInts();
            int p = pqr[0];
            int q = pqr[1];
            int r = pqr[2];
            int min = Min(Min(p + q, p + r), q + r);

            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            // Write output here
            WriteLine(min);

            Out.Flush();
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 11092
' Imports System.Collections.Generic
' Imports System.Text.RegularExpressions

Class Main
    Public Shared Sub Main()
        Dim A, B, C, D As Integer
        Dim arr() As String
        arr = Split(Console.ReadLine())
        A = arr(0) : B = arr(1) : C = arr(2): D = arr(3)
        Console.WriteLine(
            If(Math.Floor((B + C - 1) / B) <= Math.Floor((A + D - 1) / D) , "Yes", "No"))
        Return
    End Sub
End Class


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

using namespace std;
typedef long long ll;

void dfs(vector<char> &v, char to, int n) {
    if (v.size() == n) {
        for (auto e : v) printf("%c", e);
        printf("\n");
        return;
    }
    for (char c = 'a'; c <= to; c++) {
        v.push_back(c);
        if (c == to) dfs(v, to + 1, n);
        else dfs(v, to, n);
        v.pop_back();
    }
}

int main() {
    int n;
    cin >> n;
    vector<char> v;
    v.push_back('a');
    dfs(v, 'b', n);
}


Measured memory_bytes: 1536
#include <stdio.h>
#define MAX 101

int main(void) {
    int i, max, ary[MAX] = {};
    for(max = 0; ~scanf("%d", &i); max < ++ary[i] && (max = ary[i]));
    for(i = 1; i < MAX; max - ary[i++] || printf("%d\n", ~-i));
    return 0;
}

Measured memory_bytes: 596
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.Map;
import java.util.HashMap;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

	static class B_PowersOfTwo {
		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			int n = in.nextInt();
			int[] a = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = in.nextInt();
			}
			Arrays.sort(a);
			Map<Integer, Integer> m = new HashMap<>();
			for (int x : a) {
				addOne(m, x);
			}
			int ans = 0;
			for (int i = n - 1; i >= 0; i--) {
				int x = a[i];
				if (!m.containsKey(x)) {
					continue;
				}
				removeOne(m, x);
				for (int bit = 30; bit >= 0; bit--) {
					int y = (1 << bit) - x;
					if (m.containsKey(y)) {
						removeOne(m, y);
						++ans;
						break;
					}
				}
			}
			out.println(ans);
		}

		private void addOne(Map<Integer, Integer> m, int x) {
			int v = 0;
			if (m.containsKey(x)) {
				v = m.get(x);
			}
			m.put(x, v + 1);
		}

		private void removeOne(Map<Integer, Integer> m, int x) {
			int v = m.get(x);
			if (v == 1) {
				m.remove(x);
			} else {
				m.put(x, v - 1);
			}
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					String rl = in.readLine();
					if (rl == null) {
						return null;
					}
					st = new StringTokenizer(rl);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

	}
}



Measured memory_bytes: 96408
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n, s;
		int pow[];

		while (true) {
			n = sc.nextInt();
			s = sc.nextInt();
			if ((n | s) == 0) {
				break;
			}

			pow = new int[n];
			for (int i = 0; i < n; i++) {
				pow[i] = sc.nextInt();
			}
			Arrays.sort(pow);

			int id = n - 1;
			int cnt = 0;
			for (int i = 0; i < n; i++) {
				while (s < pow[i] + pow[id] && i < id) {
					id--;
				}
				if (i <= id) {
					cnt += n - id - 1;
				} else {
					cnt += n - i - 1;
				}
			}

			System.out.println(cnt);
		}
	}
}

Measured memory_bytes: 159476
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math

    #inf = 10**17
    #mod = 10**9 + 7

    def segfunc(a, b):
        if b == 0:
            return a
        else:
            return segfunc(b, a % b)

    def init(arr):
        # 0-index/上段の分ズラす
        for i in range(n):
            seg[i+num-1]=arr[i]
        # 上段の分を右から埋めていく
        for i in range(num-2,-1,-1) :
            seg[i]=segfunc(seg[2*i+1],seg[2*i+2]) 
        
    def update(k,x):
        # 元の配列のindex→seg木上のindex
        k += num-1
        seg[k] = x
        while k:
            k = (k-1)//2
            seg[k] = segfunc(seg[k*2+1],seg[k*2+2])
        
    def query(p,q):
        # 不当な区間
        if q<=p:
            return ide_ele
        p += num-1
        q += num-2
        res=ide_ele
        # 最下段から区間を見て更新していく
        # 見ている区間が覆う区間はその時点で見る必要はなく
        # 半分しか覆っていない区間は更新する
        # 上段に上がる際に区間外が混ざらないようにする
        while q-p>1:
            if p&1 == 0:
                res = segfunc(res,seg[p])
            if q&1 == 1:
                res = segfunc(res,seg[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        if p == q:
            res = segfunc(res,seg[p])
        else:
            res = segfunc(segfunc(res,seg[p]),seg[q])
        return res

    n = int(input())
    A = list(map(int, input().split()))

    # 単位元
    ide_ele = 0

    # num:n以上の最小の2のべき乗
    # n:5~8のときnum=8なので3が入ってほしいから-1
    num =2**((n-1).bit_length())

    # セグ木初期化
    seg=[ide_ele]*2*num
    init(A)

    res = 0
    for i in range(n):
        res = max(res, segfunc(query(0, i), query(i+1, n)))
    print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 14512
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef pair<int,int> P;
typedef long long ll;

ll sum[200010]={0};

int main(void){
    ll n,ans=0;
    cin>>n;
    vector<ll>a(n),b(n);
    for(ll i=0;i<n;i++)cin>>a[i];
    for(ll i=0;i<n;i++){
        b[i]=a[i];
    }
    sort(b.begin(),b.end());
    ll m1=b[n-1],m2=b[n-2];
    for(ll i=0;i<n;i++){
        if(a[i]<m1)cout<<m1<<endl;
        else{
            cout<<m2<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 4736
a, b, c, d = gets.chomp.split(' ').map(&:to_i)
x = (b / c) + (b / d) - (b / c.lcm(d))
y = (a / c) + (a / d) - (a / c.lcm(d))
z = b - x - a + y + 1
z -= 1 if a % c == 0 || a % d == 0
puts z

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

const int H = 19;
const int W = 15;

struct State{
    int xstate;
    unsigned char h, w;
    
    bool operator < (const State &r) const{
        int xl = xstate * H * W + h * W + w;
        int xr = r.xstate * H * W + r.h * W + r.w;
        return xl < xr;
    }
};

vector<string> board(H);
vector<int> xhs, xws;
map<State, int> d;

bool infield(int h, int w){
    if(h == H)
        return true;
    else
        return 0<=w && w<W;
}

int bfs(int sh, int sw){
    int xn = xhs.size();
    map<pair<int, int>, int> ipoint;
    for(int i=0; i<xn; i++)
        ipoint[{xhs[i], xws[i]}] = i;
    
    queue<State> que;
    State s;
    s.xstate = (1<<xn)-1;
    s.h = sh;
    s.w = sw;
    que.push(s);
    
    d[s] = 0;
    
    int maxq = 0;
    
    while(!que.empty()){
        maxq = max(maxq, (int)que.size());
        auto s = que.front(); que.pop();
        //cout << que.size() << endl;
        
        for(int dh=-1; dh<=1; dh++){
            for(int dw=-1; dw<=1; dw++) if(dh != 0 || dw != 0){
                State ns;
                ns.xstate = s.xstate;
                ns.h = s.h + dh;
                ns.w = s.w + dw;
                
                if(ipoint.find({ns.h, ns.w}) == ipoint.end() || ((ns.xstate>>ipoint[{ns.h, ns.w}])&1) == 0)
                    continue;
                
                int count = 0;
                while(infield(ns.h, ns.w) && ipoint.find({ns.h, ns.w})!= ipoint.end() && (ns.xstate>>ipoint[{ns.h, ns.w}])&1){
                    ns.h += dh;
                    ns.w += dw;
                    count++;
                }
                if(!infield(ns.h, ns.w))
                    continue;
                
                ns.h = s.h + dh;
                ns.w = s.w + dw;
                for(int i=0; i<count; i++){
                    ns.xstate -= 1<<ipoint[{ns.h, ns.w}];
                    ns.h += dh;
                    ns.w += dw;
                }
                
                if(d.find(ns) != d.end())
                    continue;
                
                que.push(ns);
                d[ns] = d[s] + 1;
                
                if(H-1<=ns.h){
                    return d[ns];
                }
            }
        }
    }
    //cout << maxq << endl;
    return -1;
}

int main(){
    for(auto &s: board) cin >> s;
    
    int sh, sw;
    for(int h=0; h<H; h++){
        for(int w=0; w<W; w++){
            if(board[h][w] == 'O')
                sh = h, sw = w;
            if(board[h][w] == 'X')
                xhs.push_back(h), xws.push_back(w);
        }
    }
    cout << bfs(sh, sw) << endl;
    
    return 0;
}

Measured memory_bytes: 8392
def main():
    n=int(input())
    p=list(map(int,input().split()))
    q=list(map(int,input().split()))
    fact = [1]
    for i in range(1,9):
        fact.append(i*fact[i-1])
    tmp = []
    for i in range(n):
        tmp.append(i+1)
    i=0
    ansp = caldict(fact,i,p,tmp)
    tmp = []
    for i in range(n):
        tmp.append(i+1)
    i=0
    ansq = caldict(fact,i,q,tmp)

    print(abs(ansp-ansq))
def caldict(f,i,p,tmp):
    if i < len(p)-1:
        nowi = tmp.index(p[i])
        now = tmp.pop(nowi)
        i+=1
        return nowi * f[len(tmp)] + caldict(f,i,p,tmp)
    else:
        return 1


if __name__=='__main__':
    main()


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

using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr ll mod = static_cast<ll>(1e9 + 7);

int n, x, l[105];
int main() {
	std::cin >> n >> x;

	for (int i = 0; i < n; ++i)
		std::cin >> l[i];

	int ans = 1;
	int pos = 0;
	for (int i = 0; i < n; ++i) {
		pos += l[i];
		if (pos > x)
			break;
		++ans;
	}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::multiprecision;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define pt pop_front
#define pk pop_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
template<class T> T count_bit(T p){
  if(typeid(p)==typeid(int))return __builtin_popcount(p);
  else if(typeid(p)==typeid(long))return __builtin_popcountl(p);
  else return __builtin_popcountll(p);
}
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;}
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                                      ins(T &p){for_each(all(p),in<decltype(p[0])>);}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}
inline                                              void out(double p){printf("%.10f\n",p);}
template<class T>inline                             void outs(T p){for_each(all(p),out<decltype(p[0])>);}

inline void solve(void){
  string S;
  in(S);
  map<char,long>m;
  for(auto&& e:S)m[e]++;
  bool flag=true;
  for(auto&& e:m)if(e.sd!=2)flag=false;
  if(m.size()==2&&flag)out("Yes");
  else out("No");

}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    int A1, A2, A3;
    cin >> A1 >> A2 >> A3 ;
    if (A1+A2+A3 <= 21){
        cout<< "win" <<endl;
    }
    else {
        cout<< "bust" <<endl;
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()

int main() {
  //
  int n;
  cin >> n;
  map<int, ll> p;
  p.insert(make_pair(2, 1));
  for (int i = 3; i <= n; i++) {
    int tmp = i;
    for (auto& x : p) {
      int cnt = 0;
      while (tmp % x.first == 0) {
        tmp = tmp / x.first;
        cnt++;
      }
      // cout << i << ":" << x.first << "," << cnt << endl;
      p[x.first] += cnt;
    }
    if (tmp > 1) {
      p[tmp] = 1;
    }
  }
  int over74 = 0;
  int over24 = 0;
  int over14 = 0;
  int over4 = 0;
  int over2 = 0;
  for (auto& x : p) {
    if (x.second >= 74) over74++;
    if (x.second >= 24) over24++;
    if (x.second >= 14) over14++;
    if (x.second >= 4) over4++;
    if (x.second >= 2) over2++;
    // cout << x.first   << "," << x.second << endl;
  }
  int ans = over4 * (over4 - 1) / 2 * (over2 - 2) + over14 * (over4 - 1) +
            over24 * (over2 - 1) + over74;
  cout << ans << endl;
  return 0;
}


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

#define Solved int main()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define forn(i, n) for(int i = 1; i <= n; i++)
#define rep(i, x, y) for(int i = x; i <= y; i++)
#define sz(x) (int)x.size()
#define pii pair<int, int>
#define ll long long
#define ull unsigned long long
#define ld long double
#define mii map<int, int>
#define all(x) x.begin(), x.end()
#define lb lower_bound
#define ub upper_bound
using namespace std;

inline ll bip(ll x,ll n,ll mod){ll res=1;while(n){if(n&1){res=(res*x)%mod;}x=(x*x)%mod;n>>=1;}return res;}

const int maxn = 1e9;
const ll inf = 1e18;
//const int mod = 998244353;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;

int n, a[3011];
ll sum[3011], dp[3011][3010];

ll rec(int l, int r, int pl) {
    if (l > r) return 0;
    if (dp[l][r]) return dp[l][r];

    ll v1 = a[l] + (sum[r] - sum[l] - rec(l + 1, r, 3 - pl));
    ll v2 = a[r] + (sum[r - 1] - sum[l - 1] - rec(l, r - 1, 3 - pl));
    return dp[l][r] = max(v1, v2);
}

void solve() {
    cin >> n;

    forn (i, n)
        cin >> a[i];

    sum[1] = a[1];
    for (int i = 2; i <= n; i++)
        sum[i] = sum[i - 1] + a[i];

    ll X = rec(1, n, 1);
    cout << X - (sum[n] - X);
}

Solved {
    SpeedForce;
	int tt = 1;
    //cin >> tt;
	while (tt--) {
		solve();
		cout << '\n';
	}

}


Measured memory_bytes: 70272
def main():
    N, A = map(int, input().split())
    x = list(map(int, input().split()))

    x.insert(0, 0)

    dp = [[[0 for _ in range(N * A + 1)] for _ in range(N + 1)] for _ in range(N + 1)]
    for i in range(N + 1):
        dp[i][0][0] = 1

    for i in range(1, N + 1):
        for j in range(1, i + 1):
            for k in range(1, N * A + 1):
                dp[i][j][k] = dp[i - 1][j][k]
                if k >= x[i]:
                    dp[i][j][k] += dp[i - 1][j - 1][k - x[i]]

    ans = 0
    for j in range(1, N + 1):
        ans += dp[N][j][A * j]

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 58484
from fractions import gcd
a,b,c,d = map(int,input().split())
def solve(a,b,n):
    if a == b:
        if a%n==0:
            return 1
        else:
            return 0
    elif a%n == 0:
        return b//n-a//n+1
    elif b%n==0:
        return b//n-a//n
    else:
        return b//n-a//n

print(b-a+1-(solve(a,b,c)+solve(a,b,d)-solve(a,b,c*d//gcd(c,d))))

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

int main(){
	bool is_prime[1000000];
	
	is_prime[0] = is_prime[1] = false;
	for(int i = 2; i < 1000000; i++){
		is_prime[i] = true;
	}
	for(int i = 2; i * i < 1000000; i++){
		if(is_prime[i]){
			for(int j = i * i; j < 1000000; j+=i){
				is_prime[j] = false;
			}
		}
	}
	
	int n_prime[1000000];
	int cnt = 0; 
	for(int i = 0; i < 1000000; i++){
		if(is_prime[i]){
			cnt++;
		}
		n_prime[i] = cnt;
	}
	while(true){
		int n;
		cin >> n;
		if(cin.eof()){
			break;
		}
		cout << n_prime[n] << endl;
	}
	return 0;
}

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

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

  int money_remain;
  int money_remain2;

  int count_500;
  int count_5;
  int happy;

  money_remain = money % 500;
  count_500 = (money-money_remain)/500;

  money_remain2 = money_remain % 5;
  count_5 = (money_remain-money_remain2)/5;

  happy = (1000*count_500) + (5*count_5);
  cout << happy << endl;
}


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

using namespace std;

vector < pair < int, int > > g[20];

main() {
#ifdef HOME
    //freopen("input.txt", "r", stdin);
#endif // HOME
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, x, y, f, ans = 0;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> x;
        for (int j = 1; j <= x; ++j) {
            cin >> y >> f;
            g[i].push_back({y, f});
        }
    }
    for (int mask = 0; mask < (1 << n); ++mask) {
        int cnt = 0, ok = 1;
        for (int j = 0; j < n; ++j) {
            if ((mask&(1 << j)) > 0) cnt++;
        }
        for (int j = 0; j < n; ++j) {
            if ((mask&(1 << j)) > 0) {
                //if (mask == 5) cout << j << '\n';
                for (auto key : g[j + 1]) {
                    //if (mask == 5 && j == 0) cout << key.first << ' ' << key.second << '\n';
                    if (key.second == 1) {
                        if ((mask&(1 << (key.first - 1))) == 0) ok = 0;
                    }
                    else {
                        //if (mask == 5 && j == 0) cout << (mask&(1 << (key.first - 1))) << " " << key.first << '\n';
                        if ((mask&(1 << (key.first - 1))) > 0) ok = 0;
                    }
                }
            }
        }
        if (ok) ans = max(ans, cnt);
        //if (ok && cnt == 2) cout << mask << '\n';
    }
    cout << ans << '\n';
    return 0;
}



Measured memory_bytes: 256
<?php
$n = trim(fgets(STDIN));
$s = trim(fgets(STDIN));

$w = [];
$e = [];

$w[0] = 0;
$w[$n + 1] = 0;
$e[0] = 0;
$e[$n + 1] = 0;

for ($i = 1; $i <= $n; $i++) {
    if ($s[$i - 1] === 'W') {
        $w[$i] = $w[$i - 1] + 1;
    } else {
        $w[$i] = $w[$i - 1];
    }

    if ($s[$n - $i] === 'E') {
        $e[$n - $i + 1] = $e[$n - $i + 2] + 1;
    } else {
        $e[$n - $i + 1] = $e[$n - $i + 2];
    }
}

$ans = 500000;

for ($i = 1; $i <= $n; $i++) {
    if ($w[$i - 1] + $e[$i + 1] < $ans) {
        $ans = $w[$i - 1] + $e[$i + 1];
    }
}

echo $ans . PHP_EOL;

Measured memory_bytes: 36344
#include <bits/stdc++.h>
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)
using namespace std;
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
  stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
string to_string(char c) { return "'" + string(1, c) + "'";}
string to_string(string s) { return '"' + s + '"';}
string to_string(const char* s) { return to_string((string) s);}
template<typename A> string to_string(A);
template<typename A, typename B> string to_string(pair<A, B> p){
  return "(" + to_string(p.first) + ": " + to_string(p.second) + ")";}
template<typename A> string to_string(A v) {bool f = false; string r = "{"; 
  for (auto x: v) {if (f) r += ", "; r += to_string(x); f = true;} return r += "}";}
template<typename A> string to_string(vector<vector<A>> v) {string r; 
  for (auto x: v) r += "\n" + to_string(x); return r;}
void err(istream_iterator<string>) { cerr << endl; }
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " =: " << to_string(a) << "; "; err(++it, args...); }
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
int const MOD = 1e9 + 7;
long long const INF = 1e18 + 42;
/*************************************/

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  i64 n;
  cin >> n;
  if (n & 1) kek(0);
  n /= 2;
  i64 ans = 0;
  while (n > 0) {
    ans += (n / 5);
    n /= 5;
  }
  kek(ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <tuple>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;

int gcd(int a, int b) {
    return b != 0 ? gcd(b, a % b) : a;
}

//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
      fac[i] = fac[i-1] * i % MOD;
      inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
      finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
//組み合わせ
long long COM (int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

void solve() {
	int h, w;
	cin >> h >> w;
	char board[h][w];
	for (int i = 0; i < h; ++i) {
		string s;
		cin >> s;
		for (int j = 0; j < w; ++j) {
			board[i][j] = s[j];
		}
	}
	int dx[] = {-1, 0, 1};
	int dy[] = {-1, 0, 1};
	int  ans[h][w];
	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			ans[i][j] = 0;
		}
	}
	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			for (unsigned int k = 0; k < sizeof(dx) / sizeof(dx[0]); ++k) {
				for (unsigned int l = 0; l < sizeof(dy) / sizeof(dy[0]); ++l) {
					if (k == 1 && l == 1) continue;
					if ((i + dy[l] > -1 && i + dy[l] < h) && (j + dx[k] > -1 && j + dx[k] < w)) {
						if (board[i + dy[l]][j + dx[k]] == '#' && board[i][j] == '.') {
							ans[i][j]++;
						}
					}
				}
			}
		}
	}
	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			if (board[i][j] == '.') {
				cout << ans[i][j];
			} else if (board[i][j] == '#') {
				cout << board[i][j];
			}
		}
		cout << endl;
	}
    return;
}

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



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
     int n,m;
     cin >> n>>m;
    vector<int>a(m);
    vector<int>b(m);
    int num[n]={0};
    for(int i=0;i<m;i++){
        cin >> a[i] >> b[i];
        num[a[i]-1]++;
        num[b[i]-1]++;
    }
    for(int i=0;i<n;i++)cout << num[i] <<endl; 

}

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

def koike(X, n):
    if (int(X/n)):
        return koike(int(X/n), n)+str(X%n)
    return str(X%n)
x = N
new_x = koike(x, K)
print(len(new_x))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define forN(n, N) for(int n=0; n<N; n++)
#define res_out(ans) cout << ans << "\n";
#define ll long long

int l[9];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b;
    cin >> a >> b;
    if(a * b <= 0)res_out("Zero")
    else if(b < 0 && (b - a + 1) % 2)res_out("Negative")
    else res_out("Positive")
    return 0;
}

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

int main(){
    int a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;
    int ans = 1000000000;
    for(int i = 0;i < 100001;i++){
        int sum = c*i*2+a*max(0,x-i)+b*max(0,y-i);
        ans = min(ans,sum);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=200010;
const ll mod=1e9+7;

template<typename T>
struct LazySegmentTree{
private:
  int n;
  vector<T> node,lazy;
  T E0,E1;
  inline void updatef(T& lazy,T& value){
    lazy += value/2;					       //区間add//区間sum
    //lazy = value; 						//区間max//区間update
    //lazy = max(lazy, value);
    //lazy = min(lazy, value);
  }
  inline void calculatef(T& node,T& lazy,int len){
    ///node += lazy * len;
    node += lazy ;							//区間add//区間sum
    //node = lazy ;							//区間max//区間update
  }
  inline T queryf(T& x,T& y){
    return x + y;								//区間add//区間sum
    //return x * y;
    //return min(x, y);											
    //return max(x, y);							//区間max//区間update
  }
public:
  LazySegmentTree(int sz,T nodeE,T lazyE = 0):E0(nodeE), E1(lazyE){	//0からつくる
    n=1;
    while(n<sz)n<<=1;
    node.resize(2*n-1,E0);
    lazy.resize(2*n-1,E1);
  }
  LazySegmentTree(vector<T>& v,T E0,T E1 = 0):E0(E0),E1(E1){        //配列から作る
    n=1;
    int sz=v.size();
    while(n<sz)n<<=1;
    node.resize(2*n-1,E0);
    lazy.resize(2*n-1,E1);
    rep(i,sz)node[i+n-1] = v[i];
    for(int i=n-2; i>=0; --i){
      node[i] = queryf(node[2*i+1],node[2*i+2]);
    }
  }
 
  void eval(int k,int l,int r){
    if(lazy[k]==E1){return;}
    calculatef(node[k], lazy[k], r-l);
    if(r-l>1){
      updatef(lazy[2*k+1], lazy[k]);
      updatef(lazy[2*k+2], lazy[k]);
    }
    lazy[k]=E1;
  }
 
  
  void update(int a, int b, T x,int k=0,int l=0,int r=-1){
    if(r<0)r=n;
    eval(k,l,r);
    if(r<=a||b<=l)return;
    if(a<=l&&r<=b){
//      updatef(lazy[k], x);		//区間update
      lazy[k] += (r-l)*x;      //区間add
      eval(k,l,r);
    } else {
      update(a,b,x,2*k+1,l,(l+r)/2);
      update(a,b,x,2*k+2,(l+r)/2,r);
      node[k]=queryf(node[2*k+1], node[2*k+2]);
    }
  }
  T query(int a,int b,int k=0,int l=0,int r=-1){
    if(r<0)r=n;
    eval(k,l,r);
    if(r<=a||b<=l)return E0;
    if(a<=l&&r<=b)return node[k];
    T xl=query(a,b,2*k+1,l,(l+r)/2);
    T xr=query(a,b,2*k+2,(l+r)/2,r);
    return queryf(xl, xr);
  }
};

int main(){
  ll n,d,a;
  cin >> n >> d >> a;
  vector<pair<ll,ll>> xh(n);
  vector<ll> x(n);
  vector<ll> h(n);

  rep(i,n){ cin>>xh[i].F>>xh[i].S; }
  sort(xh.begin(),xh.end());
  rep(i,n){ h[i]=xh[i].S; x[i]=xh[i].F; }
  
  LazySegmentTree<ll> sg(h,0,0);
  ll cnt=0;
  rep(i,n){
    ll enemy = sg.query(i,i+1);
    if(enemy<0){ sg.update(i,i+1,enemy*(-1)); continue; }
    ll bomb = x[i]+2*d;
    ll th = (enemy+a-1)/a;
    cnt += th;
    int safe = upper_bound(x.begin(),x.end(),bomb)-x.begin();
    sg.update(i,safe,(-1)*th*a);   
  }
  
  cout << cnt << endl;
  return 0;
}

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

using namespace std;

/**
ワーシャルフロイド
計算量O(n^3)
全体全の最短距離を求める
**/
#define NODE 301
long long dist[NODE][NODE];
void WF(int num){
	for(int k = 0;k < num;k++){
		for(int i = 0;i < num;i++){
			for(int j = 0;j < num;j++){
				dist[i][j] = min(dist[i][j],dist[i][k] + dist[k][j]);
			}
		}
	}
}

int main(){
	int H, W;
	int A[210][210];

	cin >> H >> W;
	for(int i = 0; i <= 9; i++) {
		for(int j = 0; j <= 9; j++) {
			cin >> dist[i][j];
		}
	}
	WF(10);

	int ans = 0;
	for(int i = 0; i < H; i++) {
		for(int j = 0; j < W; j++) {
			int A;
			cin >> A;
			if(A != -1) {
				ans += dist[A][1];
			}
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 200100
//#define NIL -1

int main() {
    int n;
    set<LL> a;
    LL tmp_a;
    LL ans_low;

    cin >> n;
    for(int i=0; i<n; i++){
        cin >> tmp_a;
        a.insert(tmp_a);
    }

    auto itr_ans1=a.begin();
    auto itr_ans2=a.begin();
    auto itr_low=a.begin();
    auto itr_mid=a.begin();
    auto itr_high=a.begin();
    auto itr=a.end();
    itr--;
    LL diff=(*itr);
    LL half=(*itr)/2;
    vector<LL> cand_value(3);
    LL mid_diff;
    LL high_diff;
    itr_mid=a.lower_bound(half);
    if(itr_mid!=a.begin()){
        itr_low=itr_mid;
        itr_low--;
    }else{
        itr_low=itr_mid;
    }
    if((*itr)%2==0){
        itr_high=itr_mid;
    }else{
        itr_high=a.lower_bound(half+1);
    }
    cand_value[0] = (*itr_low);
    cand_value[1] = (*itr_mid);
    cand_value[2] = (*itr_high);
    for(int i=0; i<3; i++){
        LL tmp;
        if((*itr)%2==0){
            tmp=(LL)abs(half-cand_value[i]);
        }else{
            if((LL)abs(half-cand_value[i])>(LL)abs(half+1-cand_value[i])){
                tmp=(LL)abs(half+1-cand_value[i]);
            }else{
                tmp=(LL)abs(half-cand_value[i]);             
            }
        }
        if(diff>tmp){
            diff=tmp;
            ans_low=cand_value[i];
        }        
    }

    cout << (*itr) << " " << ans_low << endl;

    return 0;
}

Measured memory_bytes: 4992
import java.util.*;
import java.math.*;
public class Main 
{
	public static void main(String[] args) 
	{
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		while(n-- != 0)
		{
			BigInteger bInt1 = stdIn.nextBigInteger();
			BigInteger bInt2 = stdIn.nextBigInteger();
			bInt1 = bInt1.add(bInt2);
			if(bInt1.toString().length() > 80)
			{
				System.out.println("overflow");
			}
			else
			{
				System.out.println(bInt1);
			}
		}
	}
}

Measured memory_bytes: 12000