akhauriyash/Code-Regression huggingface dataset:
import sys
# from collections import defaultdict
# from collections import Counter
# from queue import Queue
import math

sys.setrecursionlimit(10000)

def solve(n, start):
    if n == 1:
        return 0

    for i in range(start, int(math.sqrt(n+1))):
        sys.stderr.write('i = {}\n'.format(i))

        if n % i == 0:
            # 素因数を枯らす
            sys.stderr.write('hit: n = {}, i = {}^1\n'.format(n, i))
            sys.stderr.write('hit: {}^1\n'.format(i))
            cnt = 1
            tmp = n // i
            while(tmp % (i ** (cnt+1)) == 0):
                sys.stderr.write('hit: {}^{}\n'.format(i, cnt+1))
                tmp = tmp // (i ** (cnt+1))
                cnt += 1

            while(tmp % i == 0):
                tmp = tmp // i

            return solve(tmp, i+1) + cnt

    return 1

def main():
    N = int(input())

    ans = solve(N, 2)
    print(ans)

    # N, M = [int(s) for s in input().split()]

    # As = []
    # for i in range(N):
    #     tmp = int(input())
    #     As.append(tmp)

    return 0

if __name__ == '__main__':
    sys.exit(main())


Measured memory_bytes: 13680
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  ll N;
  cin>>N;
  string S;
  cin>>S;
  ll ans=0;
  for(ll i=0;i<N;i++) {
    
for(ll j=i+1;j<N;j++) {
if(S[i]!=S[j]) {
    i=j-1;
break;
  }
  if(j==N-1) {
i=j;
  }
}
    ans++;
    
  }
  cout<<ans<<endl;
}
  


Measured memory_bytes: 3696
type
  pair = record
    b : int64;
    c : integer;
  end;
	pairArray = array[1..200000] of pair;

var cur,i,n,m:longint;
    sum:int64;
    bc : pairArray;

procedure	swap(var a,b:pair);
var tmp:pair;
begin
	tmp:=a;
	a:=b;
	b:=tmp
end;

procedure QuickSort(var a:pairArray;start_index,end_index:integer);
var i,j,x:int64;
begin
	x:=a[(start_index+end_index)div 2].c;
	i:=start_index;
	j:=end_index;
	while(true)do
	begin
		while(a[i].c<x)do i:=i+1;
		while(x<a[j].c)do j:=j-1;
		if(i<j)then
		begin
			swap(a[i],a[j]);
			i:=i+1;
			j:=j-1;
		end else
		begin
			if(start_index<i-1)then QuickSort(a,start_index,i-1);
			if(j+1<end_index)then QuickSort(a,j+1,end_index);
			exit;
		end;
	end;
end;

begin
  readln(n,m);
  for i:=1 to n do begin
    read(bc[i].c);
    bc[i].b := 1
  end;
  for i:=n+1 to n+m do read(bc[i].b,bc[i].c);
  QuickSort(bc,1,n+m);
  cur := n+m;
  sum := 0;
  for i:=1 to n do begin
      sum := sum + bc[cur].c;
      bc[cur].b := bc[cur].b - 1;
      if bc[cur].b=0 then cur := cur - 1
    end;
  writeln(sum)
end.

Measured memory_bytes: 3200
//created by Whiplash99
import java.io.*;
import java.util.*;
import java.util.function.BiPredicate;

public class Main
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

        int i,N;

        String s[]=br.readLine().trim().split(" ");
        N=Integer.parseInt(s[0]);
        int K=Integer.parseInt(s[1]);
        int C=Integer.parseInt(s[2]);

        char str[]=br.readLine().trim().toCharArray();

        int left[]=new int[N];
        int right[]=new int[N];
        int l[]=new int[N];
        int r[]=new int[N];

        int prev=-C-10;
        int cur=0;

        for(i=0;i<N;i++)
        {
            if(str[i]=='x') continue;

            left[i]=cur;
            l[i]=prev;
            if(i-prev>C)
            {
                prev=i;
                cur++;
            }
        }

        prev=N+C+10;
        cur=0;
        for(i=N-1;i>=0;i--)
        {
            if(str[i]=='x') continue;

            right[i]=cur;
            r[i]=prev;
            if(prev-i>C)
            {
                prev=i;
                cur++;
            }
        }

        StringBuilder sb=new StringBuilder();
        for(i=0;i<N;i++)
        {
            if(str[i]=='x') continue;
            int count=left[i]+right[i];
            if(r[i]-l[i]<=C) count--;

            if(count<K) sb.append(i+1).append("\n");
        }

        System.out.println(sb);
    }
}

Measured memory_bytes: 41452
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input()) # n=1
def inpm(): return map(int,input().split()) # x=1,y=2
def inpl(): return list(map(int, input().split())) # a=[1,2,3,4,5,...,n]
def inpls(): return list(input().split())  # a=['1','2','3',...,'n']
def inplm(n): return list(int(input()) for _ in range(n)) # x=[] 複数行
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return sorted([list(map(int, input().split())) for _ in range(n)]) # [[1,1,1,1],[2,2,2,2],[3,3,3,3]] 
def graph():
    n=inp()
    g=[[] for _ in range(n)]
    for i in range(n):
        a = inp()
        a -= 1
        g[i].append(a)
        g[a].append(i)
    return n,g

def Knapsack2(W,w,v,h): # n個の品物(重さw[i],価値v[i]) 価値iを達成する重量の最小化 計算量O(V*N)
    n=len(w)
    v_max=max(v)+h+5
    # dp[i] : 価値iの組み合わせを達成する重量の最小値
    dp=[0]+[float('inf') for _ in range(v_max+1)]
    for i in range(n):
        for j in range(0,v_max+1):
            if j >= v[i]:
                if j-v[i]>W:
                    continue
                dp[j]=min(dp[j],dp[j-v[i]]+w[i])
    ans = 10**10
    for i in range(h,v_max+1):
        ans = min(ans,dp[i])
        
    print(ans)

def main():
    h,n = inpm()
    a = []
    b = []
    for _ in range(n):
        a1,b1 = inpm()
        a.append(a1)
        b.append(b1)
    Knapsack2(h,b,a,h)

    
if __name__ == "__main__":
    main()




Measured memory_bytes: 47576
// スタックサイズ: 100MB

#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
using namespace std;

typedef int64_t ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define fst first
#define snd second
ll pw(ll x, ll y) { ll r = 1;  rep(i, y) { r *= x; }; return r; }


int main() {
	
	ll a, b;
	cin >> a >> b;
	cout << max({ a + b, a - b, a * b }) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc  __builtin_popcountl
#define m_p make_pair
#define inf 1000000000000000000
#define MAXN 1000001
#define eps 0.0000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
    return uniform_int_distribution<T>()(rng);
}

// string to integer stuuu()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

//////////////

#define S second
#define F first
#define int long long  

//////////

signed main()
{
	fastio;
		int n;
		cin>>n;
	string s;
	cin>>s;
	int r=0;
	for(int i=0;i<n;++i)
	{
		if(s[i]=='R')
			++r;
	}
	if(r>n-r)
	{
		cout<<"Yes";
	}
	else
		cout<<"No";
}

Measured memory_bytes: 256
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(10)
 
typedef long long ll;
typedef pair<int,int> P;
ll longinf=1ll<<60;
int inf=1<<29;

ll N,M,Q;
ll cnt[502][502];
ll usr[502];
ll rui[502][502];
ll Qu[502][502];


int main(){
    cin>>N>>M>>Q;
    rep0(i,M){
        ll L,R;
        cin>>L>>R;
        rui[L][R]++;
        rui[L][N+1]--;
        usr[R]++;
        }
        for(int L=1;L<=N;L++){
            for(int R=L;R<=N;R++){
                cnt[L][R]=cnt[L][R-1]+rui[L][R];
            }
        }
        Qu[1][N]=M;
        for(int i=N;i>=2;i--){
            Qu[1][i-1]=Qu[1][i]-usr[i];
        }
        for(int R=N;R>=1;R--){
            for(int L=1;L<=R-1;L++){
                Qu[L+1][R]=Qu[L][R]-cnt[L][R];
            }
        }
        rep0(i,Q){
            int p,q;
            cin>>p>>q;
            cout<<Qu[p][q]<<endl;
        }

    
      return 0;
}

Measured memory_bytes: 6784
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >=0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
 
typedef long long ll;
#define INF 1e9


int main(){
  vector<int> x(3);
  cin >> x[0] >> x[1] >> x[2];
  sort(x.begin(), x.end());

  x[0] = x[2] - x[0];
  x[1] = x[2] - x[1];
  int cnt = 0;
  
  if(x[0] % 2 && x[1] % 2){
    cnt += x[0] / 2 + x[1] / 2 + 1;
  }
  else if(x[0] % 2 == 0 && x[1] % 2 == 0){
    cnt += x[0] / 2 + x[1] /2;
  }
  else{
    cnt += x[0] / 2 + x[1] /2 + 2;
  }
  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int A, B;
  cin >> A >> B;
  int ans = 0;
  if(A<B){
    ans += B;
    B--;
  }else{
    ans += A;
    A--;
  } 
  if(A<B){
    ans += B;
    B--;
  }else{
    ans += A;
    A--;
  } 
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int c[1005][1005];

int lcs( string X, string Y){

    int m, n, i, j;

    m = X.size();
    n = Y.size();

    X = ' ' + X;
    Y = ' ' + Y;

    int Lmax = 0;

    for( i = 1; i <= m ; i++){

        c[i][0] = 0;

    }

    for( i = 1; i <= n ; i++ ){

        c[0][i] = 0;

    }

    for( i = 1; i <= m; i++ ){

        for( j = 1; j <= n ; j++ ){

            if( X[i] == Y[j] ){

                c[i][j] = c[i-1][j-1] + 1;

            } else if( c[i-1][j] >= c[i][j-1] ){

                c[i][j] = c[i-1][j];

            } else {

                c[i][j] = c[i][j-1];

            }

            Lmax = max( Lmax, c[i][j] );

        }

    }

    return Lmax;

}

int main(){

    int n;
    string X, Y;

    cin >> n;

    for( int i = 0 ; i < n ; i++ ){

        cin >> X >> Y;

        cout << lcs( X, Y) << endl;

    }

    return 0;

}


Measured memory_bytes: 7096
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner scanner=new Scanner(System.in);
        int A=scanner.nextInt();
        int B=scanner.nextInt();
        String S=scanner.next();
        String[] sArray=S.split("-");
        if(sArray.length!=2){
            System.out.println("No");
            System.exit(0);
        }
        if(sArray[0].length()==A&&sArray[1].length()==B){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, e) for (int i = (int)(s); i < (int)(e); i++)
#define _rep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define _REP(i, e, s) for (int i = (int)(e - 1); i >= (int)(s); i--)

#define yes cout << "yes" << endl;
#define Yes cout << "Yes" << endl;
#define YES cout << "YES" << endl;

#define no cout << "no" << endl;
#define No cout << "No" << endl;
#define NO cout << "NO" << endl;

#define AC cout << "AC" << endl;
#define WA cout << "WA" << endl;

#define out(s) cout << s << endl;

#define ll long long
#define ull unsigned long long

const unsigned int BIT_FLAG_0 = (1 << 0);  // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1);  // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2);  // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3);  // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4);  // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5);  // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6);  // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7);  // 0000 0000 1000 0000

const double PI = 3.14159265358979323846;

const int dy[4] = {0, 1, 0, -1};
const int dx[4] = {1, 0, -1, 0};

#define H_MAX 500
#define W_MAX 500
#define INF 1e9 + 7

struct UnionFind {
    vector<int> par;

    UnionFind(int N) : par(N) {
        for (int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

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

    UnionFind tree(N);

    rep(i, Q) {
        int t, u, v;
        cin >> t >> u >> v;
        if (t == 0) {
            tree.unite(u, v);
        } else {
            if (tree.same(u, v)) {
                cout << 1 << endl;
            } else {
                cout << 0 << endl;
            }
        }
    }
}


Measured memory_bytes: 3748
#include <cstdio>
#include <cstring>
#include <algorithm>


int main() {
  int a[4];
  scanf("%d%d%d%d", a + 0, a + 1, a + 2, a + 3);
  std::sort(a, a + 4);
  int b[4] = {1, 4, 7, 9};
  for (int i = 0; i < 4; ++ i)
    if (a[i] != b[i])
      return puts("NO"), 0;
  puts("YES");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int gcd(int p,int q){
  if(p%q==0){
    return q;
  }
  return gcd(q, p % q);
}

int main() {
  int N;
  long long ans=0;
  cin>>N;
  for(int i=1;i<=N;i++){
    for(int j=1;j<=N;j++){
      for(int k=1;k<=N;k++){
        ans=ans+gcd(gcd(i,j),k);
      }
    }
  }
  cout<<ans<<endl;
}







Measured memory_bytes: 3576
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

using i64 = int64_t;

int main() {
    string S;
    cin >> S;
    const int N = S.size();

    int idx = 0;
    for (int j = 0; j < N; ++j) {
        idx += ((S[j] - 'A') - (idx%26) + 25) % 26 + 1;
    }
    cout << idx / 26 << endl;
    return 0;
}

Measured memory_bytes: 3192
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include <cstdint>
#include <utility>
#include <tuple>
#include <map>    
#include <queue> 
#include <set>  
#include <stack> 
#include <deque>  
#include <unordered_map> 
#include <unordered_set> 
#include <bitset>

using namespace std;

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

	vector<vector<int>> X(N, vector<int>(D));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < D; j++) {
			cin >> X.at(i).at(j);
		}
	}

	int count = 0;
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			int dis_square = 0;
			for (int k = 0; k < D; k++) {
				dis_square += (X.at(j).at(k) - X.at(i).at(k))*(X.at(j).at(k) - X.at(i).at(k));
			}
			for (int l = 1; l <= 130; l++) {
				if (l*l == dis_square) {
					count++;
					continue;
				}
			}
		}
	}

	cout << count << endl;
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))
INF = 10 ** 18

dp = [INF] * n
dp[0] = 0
dp[1] = abs(h[1] - h[0])

for i, (e1, e2, e3) in enumerate(zip(h, h[1:], h[2:]), 2):
    dp[i] = min(dp[i], dp[i-1] + abs(e3 - e2), dp[i-2] + abs(e3 - e1))

ans = dp[-1]
print(ans)


Measured memory_bytes: 20600
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <utility>

bool exist[1000004];
bool duplicate[1000004];

bool dfs(std::vector<int >& pr, std::vector<int>& yakusuu, int val, int index, int orig){
  if (index==yakusuu.size()){
    if (val==orig) return false;
    else if (exist[val]) return true;
    else return false;
  } else {
    bool ret = false;
    int target=yakusuu[index];
    int num=pr[target];
    int multiple=1;
    for (int i=0; i<=num; i++){
      ret |= dfs(pr, yakusuu, val*multiple, index+1, orig);
      multiple *= target;
      if (ret) return true;
    }
    return ret;
  }
}

int main(){
  int N;
  scanf("%d", &N);
  std::vector<int > A(N);
  for (int i=0; i<1000004; i++){
    exist[i]=false;
    duplicate[i]=false;
  }
  for (int i=0; i<N; i++){
    scanf("%d", &A[i]);
  }
  std::sort(A.begin(), A.end());
  for (int i=0; i<N; i++){
    if (exist[A[i]]) {
      duplicate[A[i]]=true;;
    } else {
      exist[A[i]]=true;
    }
  }
  int ans = 0;
  std::vector<int > prime;
  std::vector<bool > isprime(10004, true);
  for (int i=2; i*i<=1000004; i++){
    if (isprime[i]) {
      prime.push_back(i);
      for (int j=2*i; j*j<1000004; j+=i){
	isprime[j]=false;
      }
    }
  }
  std::sort(prime.begin(), prime.end());
  
  std::vector<int > pr(1000004, 0);
  for (int i=0; i<N; i++){
    //printf("i=%d\n", i);
    if (duplicate[A[i]]) continue;
    std::vector<int > yakusuu;
    int temp=A[i];
    for (int p : prime){
      //printf("temp=%d, p=%d\n", temp, p);
      if (p*p>temp) break;
      while(temp%p==0){
	if(pr[p]==0) yakusuu.push_back(p);
	pr[p]++;
	temp=temp/p;
	//printf("in while temp=%d, p=%d\n", temp, p);
      }
    }
    if (temp!=1) {
      yakusuu.push_back(temp);
      pr[temp]++;
    }
    //printf("prime calc end\n");
    bool existyakusuu = dfs(pr, yakusuu, 1, 0, A[i]);
    if (!existyakusuu) ans++;
    //printf("exist yakusuu = %d\n", existyakusuu);

    for (int p: yakusuu){
      pr[p]=0;
    }
  }
  std::cout << ans << std::endl;
  return 0;
}
 

Measured memory_bytes: 9452
n = int(input())
w = list(map(int, input().split()))

# print(w)

ans = 10*100
for t in range(1,n):
    # print(w[0:t])
    # print(w[t:])
    s1 = sum(w[0:t])
    s2 = sum(w[t:])
    sa = abs(s1 - s2)
    ans = min(sa,ans)

print(ans)

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

int it;

void reconstruction(vector<int> &pre,vector<int> &in,vector<int> &post,int l,int r){
    if(l>=r){
        return;
    }
    int c=pre[it];
    it++;
    int m=distance(in.begin(),find(in.begin(),in.end(),c));
    reconstruction(pre,in,post,l,m);
    reconstruction(pre,in,post,m+1,r);
    post.push_back(c);
}

int main(){
    int n;
    cin>>n;
    vector<int> pre(n),in(n),post(0);
    for(int i=0;i<n;i++){
        cin>>pre[i];
    }
    for(int i=0;i<n;i++){
        cin>>in[i];
    }
    it=0;
    reconstruction(pre,in,post,0,n);
    for(int i=0;i<n;i++){
        if(i) cout<<' ';
        cout<<post[i];
    }
    cout<<endl;
}


Measured memory_bytes: 3148
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

int main(){
	int n;
	cin >> n;
	
	int a[n + 1];
	int b[n + 1];
	for(int i = 1; i < n + 1; i++){
		cin >> a[i];
		b[i] = -1;
	}
	
	for(int i = n; i >= 1; i--){
		
		int c = 0;
		for(int j = (n / i) * i; j > 0; j -= i){ 
			if(b[j] == -1){
				//cout << "c: " << c << endl;
				b[j] = (c + a[j]) % 2;
				break;
			}
			else c += b[j];
		}
	
	}
	
	vector<int> v;
	
	for(int i = 1; i <= n; i++){
		if(b[i]) v.push_back(i);
	}

	cout << v.size() << endl;
	for(int i = 0; i < v.size(); i++) cout << v[i] << " \n"[i == v.size() - 1];
	return 0;
}



Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

typedef vector<double> vd;
typedef vector<vd> vvd;
const double INFTY=1e10;
const double EPS=1e-10;

int main()
{
	for(string s;getline(cin,s);){
		istringstream iss(s);
		int len;
		iss>>len;
		vi cakes;
		for(int cake;iss>>cake;)
			cakes.push_back(cake);
		
		int csize=cakes.size();
		vvd dp(1<<csize,vd(csize,INFTY));
		rep(i,csize)
			dp[1<<i][i]=cakes[i];
		repi(i,1,1<<csize){
			rep(j,csize)
				rep(k,csize){
					if((i&1<<j) && !(i&1<<k)){
						double x=sqrt(pow(cakes[j]+cakes[k],2)-pow(abs(cakes[j]-cakes[k]),2));
						dp[i|1<<k][k]=min(dp[i|1<<k][k],dp[i][j]+x);
					}
				}
		}
		
		bool ok=false;
		rep(i,csize)
			if(dp[(1<<csize)-1][i]+cakes[i]<=len+EPS)
				ok=true;
		cout<<(ok?"OK":"NA")<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1388
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define mem(a,b) memset((a),(b),sizeof(a))
#define MP make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) x.size()
#define all(x) x.begin(),x.end()
using namespace std;
#define _GLIBCXX_PERMIT_BACKWARD_HASH
#include <ext/hash_map>
using namespace __gnu_cxx;
struct str_hash{size_t operator()(const string& str)const{return __stl_hash_string(str.c_str());}};
typedef long long ll;
typedef unsigned long long ull;
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PDD pair<double,double>
const int INF=0x3f3f3f3f;
const ll LLINF=0x3f3f3f3f3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-6;
const int MAX=5e5+10;
const ll mod=1e9+7;
int main()
{
	int n,a,b,ans,now,i,j;
	while(~scanf("%d%d%d",&n,&a,&b))
	{
		ans=0;
		for(i=1;i<=n;i++)
		{
			int temp=i;
			now=0;
			while(temp)
			{
				now+=temp%10;
				temp/=10;
			}
			if(now>=a&&now<=b) ans+=i;
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> p(M);
    vector<string> S(M);
    REP(i, M) {
        cin >> p[i] >> S[i];
        p[i]--;
    }
    vector<bool> ac(N, false);
    vector<int> wa(N);
    REP(i, M) {
        if(ac[p[i]] == false && S[i] == "WA") wa[p[i]]++;
        else if(ac[p[i]] == false && S[i] == "AC") ac[p[i]] = true;
    }
    int n_ac = 0, n_wa = 0;
    REP(i, N) {
        if(ac[i]) {
            n_ac++;
            n_wa += wa[i];
        }
    }
    cout << n_ac << " " << n_wa << endl;
    return 0;
}

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

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n,m;
  cin>>n>>m;
  int a[10005];
  int sum=0;
  for(int i=0;i<m;i++){
    cin>>a[i];
    sum+=a[i];
  }
  if(n-sum>=0){
    cout<<n-sum;
  }else{
    cout<<-1;
  }

}


Measured memory_bytes: 3660
import java.util.*;

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

    int A = sc.nextInt();
    int B = sc.nextInt();

    int sum = 0;

    for(int i=0;i<2;i++){
      int button = 0;
      if(A > B){
        sum += A;
        A -= 1;
      }else{
        sum += B;
        B -= 1;
      }
    }
    System.out.println(sum);
  }
}

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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    int n; cin >> n;
    vector<ll> a(3 * n);
    for (ll i = 0; i < 3 * n; i++) cin >> a[i];
    
    vector<ll> l(n + 1), r(n + 1);
    priority_queue<ll, vector<ll>, greater<ll>> lq;
    priority_queue<ll> rq;
    for (int i = 0; i < n; i++) {
        l[0] += a[i], r[0] += a[3 * n - i - 1];
        lq.emplace(a[i]); rq.emplace(a[3 * n - i - 1]);
    }
    for (int i = 0; i < n; i++) {
        l[i + 1] = l[i], r[i + 1] = r[i];
        if (a[n + i] > lq.top()) {
            l[i + 1] += a[n + i] - lq.top();
            lq.pop(); lq.emplace(a[n + i]);
        }
        if (a[2 * n - i - 1] < rq.top()) {
            r[i + 1] += a[2 * n - i - 1] - rq.top();
            rq.pop(); rq.emplace(a[2 * n - i - 1]);
        }
    }
    ll ans = -linf;
    for (int i = 0; i <= n; i++) {
        ans = max(ans, l[i] - r[n - i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6000
A, B, K = map(int, input().split())
if A==B:
    print(A)
    exit()
ans_dic={}
A_K = A+K if A+K <= B else B
for i in range(A, A_K):
    ans_dic[i] = 1
K_B = B-K if B-K >= A else A
for i in range(B, K_B, -1):
    if i in ans_dic:
        pass
    else:
        ans_dic[i] = 1
for i, v in sorted(ans_dic.items()):
    print(i)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
using namespace std;
const int MAXN = 21;
const LL MOD = 1000000007;

int N;
bool adj[MAXN][MAXN];
LL dp[1 << MAXN];
vector<int> store[MAXN+1];

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> N;
	for (int i = 0; i < (1 << N); i++) {
		int cnt = 0;
		for (int j = 0; j < N; j++) {
			cnt += i >> j & 1;
		}
		store[cnt].push_back(i);
	}
	
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			cin >> adj[i][j];
		}
	}
	
	dp[0] = 1;
	for (int i = 0; i < N; i++) {
		for (int m : store[i + 1]) {
			for (int j = 0; j < N; j++) {
				if ((m >> j & 1) && adj[i][j]) {
					dp[m] += dp[m ^ (1 << j)];
				}
			}
			dp[m] %= MOD;
		}
	}
	
	cout << dp[(1 << N) - 1] << '\n';
}


Measured memory_bytes: 26044
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (long long int i=a;i<n;i++)
#define per(i,a,n) for (long long int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef vector<long long int> vi;
typedef long long int lli;
const lli mod=1000000007;
lli powmod(lli a,lli b) {lli res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
lli gcd(lli a,lli b) { return b?gcd(b,a%b):a;}
int main()
{
   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
   lli a,b,c;
   cin>>a>>b>>c;
   lli ans=0;
   if(a+b>=c)
    ans=b+c;
   else
   {
       ans=b;
       lli ans1=min(a+b,c);
       ans+=ans1;
       ans++;

   }
   //ans=ans+min(c,a+b);
   cout<<ans<<endl;


}





Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repR(i, n) for(int i = (n) - 1; i > -1; i--)
#define rep1(i, n) for(int i = 1; i < (int)(n + 1); i++)
#define rep1R(i, n) for(int i = (n); i > 0; i--)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int main() {
  int A, B;
  cin >> A >> B;
  rep1(i, 3) {
    if (A * B * i % 2 == 1) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long  K,N;
  cin >>K>>N;
  vector<long long>A(N+1);
  long long sa=0;
  for(long long i=1;i<=N;i++){
    cin>>A.at(i);
  }
  for(long long i=1;i<N;i++){
    sa=max(sa,A.at(i+1)-A.at(i));
  }
  sa=max(sa,K-A.at(N)+A.at(1));
  cout<<K-sa<<endl;
  return 0;
}

Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String[] strTemp;
		int numberOfTriangle, data1, data2, data3;
		/*
		 * Count total of Triangles
		 */
		numberOfTriangle = Integer.parseInt(in.readLine());
		Triangle[] triangles = new Triangle[numberOfTriangle];

		/*
		 * Create all of Triangles
		 */
		for (int i = 0; i < numberOfTriangle; i++) {
			strTemp = in.readLine().split(" ");
			data1 = Integer.parseInt(strTemp[0]);
			data2 = Integer.parseInt(strTemp[1]);
			data3 = Integer.parseInt(strTemp[2]);
			triangles[i] = new Triangle(data1, data2, data3);
		}

		for (int j = 0; j < triangles.length; j++) {
			if (triangles[j].check()) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		}
	}
}

class Triangle {
	private int id, data1, data2, data3, count;
	private Triangle[] triangles;

	/*
	 * instance
	 */
	public Triangle(int data1, int data2, int data3) {
		this.data1 = data1;
		this.data2 = data2;
		this.data3 = data3;
	}

	public boolean check() {
		int temp1, temp2, temp3;
		temp1 = (int) Math.pow(data1, 2);
		temp2 = (int) Math.pow(data2, 2);
		temp3 = (int) Math.pow(data3, 2);
		if (temp1 == temp2 + temp3 || temp2 == temp1 + temp3
				|| temp3 == temp1 + temp2) {
			return true;
		} else {
			return false;
		}
	}
}

Measured memory_bytes: 25792
def c_make_a_rectangle(N, A):
    from collections import Counter
    count = Counter(A)  # リストの要素が何回現れたか
    cond = []  # 同じ長さのものが2個ある棒の長さ
    for k, v in count.items():
        cond.extend([k] * (v // 2))  # 2本の組を何個作れるか
    if len(cond) <= 1:
        return 0  # 長方形を作れない
    cond = sorted(cond, reverse=True)
    ans = cond[0] * cond[1]  # 長いもの2組を使う
    return ans

N = int(input())
A = [int(i) for i in input().split()]
print(c_make_a_rectangle(N, A))

Measured memory_bytes: 18316
#include <bits/stdc++.h>
#define ll long long int
#define fori(n) for(int i=0;i<n;i++)
using namespace std;
int gcd(int a, int b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
int main(){
ll n;cin>>n;
  
ll p=(3*n*n)-(3*n)+(1);

for(int i=2;i<=n;i++){
    for(int j=2;j<=n;j++){
        if(gcd(i,j)==1) p=p+n-1;
        else {
            for(int k=2;k<=n;k++){
                p=p+gcd(k,gcd(i,j));
            }
        }
        
    }
    
}
cout<<p;

 return 0;    
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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 long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n,m;
	int ans=0;
	cin >>n>>m;
	VPi data(m);
	rep(i,m){
		cin>>data[i].F>>data[i].S;
	}

	sort(all(data));
	Pi dis = data[0];
	clog<<endl;
	rep(i, m)
	{
	//	clog << data[i].F <<" "<< data[i].S<<endl;
		if(dis.S <=data[i].F){
			ans++;
			dis=data[i];
		}else{
			chmax(dis.F,data[i].F);
			chmin(dis.S,data[i].S);
		}
	}
	cout<<ans+1<<endl;
}

Measured memory_bytes: 1152
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{

    static class Program
    {
        static void Main()
        {
            Solve();

            Console.ReadKey();
        }

        static void Solve()
        {
            var n = GetStr().ToCharArray().Select(s => int.Parse(s.ToString())).ToArray();
            var a = n[0];
            var b = n[1];
            var c = n[2];
            var d = n[3];

            string ans = "";
            if (a + b + c + d == 7) ans = a + "+" + b + "+" + c + "+" + d + "=7";
            if (a + b + c - d == 7) ans = a + "+" + b + "+" + c + "-" + d + "=7";
            if (a + b - c + d == 7) ans = a + "+" + b + "-" + c + "+" + d + "=7";
            if (a - b + c + d == 7) ans = a + "-" + b + "+" + c + "+" + d + "=7";
            if (a + b - c - d == 7) ans = a + "+" + b + "-" + c + "-" + d + "=7";
            if (a - b + c - d == 7) ans = a + "-" + b + "+" + c + "-" + d + "=7";
            if (a - b - c + d == 7) ans = a + "-" + b + "-" + c + "+" + d + "=7";
            if (a - b - c - d == 7) ans = a + "-" + b + "-" + c + "-" + d + "=7";

            Console.WriteLine(ans);
        }


        static public string GetStr() { return Console.ReadLine(); }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public string[] GetStrArray() { return Console.ReadLine().Split(' '); }
        static public int[] GetIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
        static public long[] GetLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
        static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
        static public void WriteObjects<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
        static string yesno(this bool b) { return b ? "yes" : "no"; }
        static string YesNo(this bool b) { return b ? "Yes" : "No"; }
        static string YESNO(this bool b) { return b ? "YES" : "NO"; }

        static bool eq<T, U>() => typeof(T).Equals(typeof(U));
        static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
        static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
                           : eq<T, long>() ? ct<T, long>(long.Parse(s))
                           : eq<T, double>() ? ct<T, double>(double.Parse(s))
                           : eq<T, char>() ? ct<T, char>(s[0])
                                             : ct<T, string>(s);
        static void Multi<T>(out T a) => a = cv<T>(GetStr());
        static void Multi<T, U>(out T a, out U b)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]);
        }
        static void Multi<T, U, V>(out T a, out U b, out V c)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]);
        }
    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define debug(var) do{cout << #var << " : "; print(var); } while(0)
using namespace std;
typedef long long ll;
void print() { cout << endl; }
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { cout << head; if (sizeof...(tail) != 0) cout << " "; print(forward<Tail>(tail)...); }
template <class T> void print(vector<T> &vec) { for (auto& a : vec) { cout << a; if (&a != &vec.back()) cout << " "; } cout << endl; }
template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec); } }
const int INF = 1e9;
const int MOD = 1e9+7;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(10);

	int N, K; cin >> N >> K;
	vector<double> P(N);
	rep(i, N) cin >> P[i];

	for(double &p: P) {
		p = (p*(p+1.0)/2.0)/p;
	}

	double total = 0.0;
	rep(i, K) total += P[i];
	double ans = total;
	FOR(i, K, N) {
		total -= P[i-K];
		total += P[i];
		ans = max(ans, total);
	}

	cout << ans << endl;
}

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

char *substr(char *ss, int s, int w){
    static char t[200];
    char *p;
    int i;

    p=t;
    for (i=s;w>0;w--)
       *p++=ss[i++];
    *p='\0';
    return t;
}

int main(){
   char s[101],t[101];
   int i,l;
    
   scanf("%s",s);
   l=strlen(s)-7;
   if (l==0 && strcmp(s,"keyence")==0) {
      puts("YES");
      return 0;
   }
   if (strcmp(substr(s,l-1,7),"keyence")==0) {
      puts("YES");
      return 0;
   }
   for (i=1;i<7;i++) {
      strcpy(t,substr(s,0,i));
      strcat(t,substr(s,i+l,7-i));
      if (strcmp(t,"keyence")==0) {
         puts("YES");
         return 0;
      }
   }
   puts("NO");
   return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

vector<int> to[200005];
ll ad[200005];
ll sum[200005];

void dfs (int x, ll now, int p) {
    sum[x] += now;
    sum[x] += ad[x];
    for (int e: to[x]) {
        if (e==p) continue;
        dfs(e, sum[x], x);
    }
}

int main(){
    int n, q;
    cin >> n >> q;
    rep(i, n-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        to[a].emplace_back(b);
        to[b].emplace_back(a);
    }
    rep(i, q) {
        int p, x;
        cin >> p >> x;
        p--;
        ad[p] += x;
    }
    dfs(0, 0, -1);
    rep(i, n) {
        cout << sum[i] << " ";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 25600
#include<stdio.h>
int main(){
        int N ;
        int X ;
        scanf("%d%d",&N,&X) ;
        int arr[N] ;
        int arr2[N+1] ;
        arr2[0] = 0 ;
        int i;
        for(i =0 ; i <N ;i++){
            scanf("%d",&arr[i]) ;
        }

        for(i = 0 ; i < N ;i++){
            arr2[i+1] = arr2[i]+arr[i];
        }
        int count = 0 ;
        i = 0;
        while(arr2[i] <= X && i < N+1){
            count++;
            i++ ;
        }
        printf("%d",count);

}


Measured memory_bytes: 128
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

total = B[A[0] - 1]

for i in range(1,N):
    total += B[A[i] - 1]
    if A[i] == A[i-1] + 1:
        total += C[A[i-1]-1]
print(total)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int a,b; cin >> a >> b;
  COUT(a*b%2 ? "Yes" : "No");
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int solve(vector<int> h)
{
    if(h.size()==1)
    return h[0];
    if(h.empty())
    return 0;
    vint now[h.size()];
    int cnt=0,res=0;
    rep(i,h.size())
    {
        if(h[i]==0)
        {
            cnt++;
        }else
        {
            now[cnt].push_back(h[i]);
        }
    }
    rep(i,min(cnt+1,(int)h.size()))
    {
        if(!now[i].empty())
        {
        int Min=*min_element(all(now[i]));

        for(int j = 0;j<now[i].size();j++)
        {
            now[i][j]-=Min;
        }
        res+=Min+solve(now[i]);
        }
    }
    return res;
}
int main()
{
    int N;
    cin >> N;
    vint h(N);
    rep(i, N)
    {
        cin >> h[i];
    }
    cout<<solve(h);
    return 0;
}

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


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

    int ans = 0;
    while (N > 0) {
        N /= K;
        ++ans;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3592
import numpy as np
N = int(input())

t = np.array([[0] * 10] * 10)

ans = 0
for i in range(1, N + 1):
    if i % 10 == 0:
        continue
    else:
        a = int(str(i)[0])
        b = int(str(i)[-1])
        t[a][b] = t[a][b] + 1

for i in range(1, 10):
    for j in range(1, 10):
        ans += t[i][j] * t[j][i]
print(ans)

Measured memory_bytes: 22416
import java.util.*;
import java.io.*;

public class Main{
    public static void main(String[] args)throws Exception{
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        String str=sc.next();
        sc.close();
        if(str.substring(0,n/2).equals(str.substring(n/2))){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

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

bool isprime(int n)
{
	for(int i=5;i*i<=n;i+=6)
	{
		if(n%i==0 || n%(i+2)==0)
		return false;
	}
	return true;
}

int main()
{
	int n;cin>>n;
  	if(n==2)
    {
      cout<<2;
      return 0;
    }
	int i;
	if(n%2==0)	i = n+1;
	else		i = n;
	for(;;i+=2)
	{
		if(i%3==0)
		continue;
		if(isprime(i))
		{
			cout<<i;
			return 0;
		}
	}
}


Measured memory_bytes: 3676
def susiki(n, s, dest):
    if n == len(s):
        tmp = 0
        pre = 0
        for d in dest:
            tmp += int(s[pre:d])
            pre = d
        tmp += int(s[pre:])
        return tmp
    return susiki(n+1, s, dest+[n]) + susiki(n+1, s, dest)

s = input()
l = len(s)

print(susiki(1, s, []))

Measured memory_bytes: 38896
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <iomanip>
#include <string>

using namespace std;

int main() {
    int n;
    cin>>n;
    string s;
    cin>>s;
    bool tmp=true;
    if(n%2==1) tmp=false;
    for(int i=0;i<n/2;++i){
      if(s[i]!=s[i+n/2]) tmp=false;
    }
    if(tmp) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

   return 0;
 }


Measured memory_bytes: 256
from string import ascii_lowercase
n = int(input())
ans_l = [100 for i in range(26)]
for i in range(n):
    s = str(input())
    for i, j in enumerate(ascii_lowercase):
        ans_l[i] = min(ans_l[i], s.count(j))
print("".join(i * j for i, j in zip(ascii_lowercase, ans_l)))


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

#define lint long long

const int N = 1e5 + 2 ;



int main()
{
    int m, d ; cin >> m >> d ; int cnt = 0 ;
    for(int i = 1;i <= m ; i++)
    {
        for(int j = 1; j <= d ; j++)
        {
            int d1 = j % 10 ;
            int d2 = j / 10 ;

            if(d1*d2 == i and d1 >= 2 and d2 >= 2 )
            {
                cnt++ ; // cout << i << " " << j << endl ;
               // cout << d1 << " " << d2 << " " << m << endl ;
            }
        }
    }
    cout << cnt ;
}


Measured memory_bytes: 764
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long llabs(long long a){
	return a>0?a:-a;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
	return *(TYPE *)b-*(TYPE *)a;
}
int char_cmp(const void *a,const void *b){
	return strcmp((char *)a,(char *)b);
}
int char_cmp_r(const void *a,const void *b){
	return strcmp((char *)b,(char *)a);
}
void swap(int *a,int *b){
	int t=*a;
	*a=*b;
	*b=t;
}
long long gcd(long long x,long long y){
	return x%y?gcd(y,x%y):y;
}
long long lcm(long long x,long long y){
	return x/gcd(x,y)*y;
}

// konoshita kara kaku
#define N 1000
#define M 2000
int a[M],b[M];
long long c[M];
int n,m;

long long bellman_ford(void){
	long long dist[N];
	int i,j;
	rep(i,n)dist[i]=INF;
	dist[0]=0;
	
	rep(j,n-1){
		rep(i,m){
			if(dist[a[i]-1]==INF)continue;
			if(dist[b[i]-1]>dist[a[i]-1]+c[i])
				dist[b[i]-1]=dist[a[i]-1]+c[i];
		}
	}
	
	long long ans = dist[n-1];
	
	int negative[N]={};
	
	rep(j,n){
		rep(i,m){
			if(dist[a[i]-1]==INF)continue;
			if(dist[b[i]-1]>dist[a[i]-1]+c[i]){
				dist[b[i]-1]=dist[a[i]-1]+c[i];
				negative[b[i]-1]=1;
			}
			if(negative[a[i]-1]==1)negative[b[i]-1]=1;
		}
	}
	
	return negative[n-1]?INF:ans;
}

int main(void){
	int i;
	n=in(),m=in();
	rep(i,m){
		a[i]=in();
		b[i]=in();
		c[i]=llin();
		c[i]*=-1;
	}
	long long ans=bellman_ford();
	if(ans==INF)puts("inf");
	else llprint(-ans);
	return 0;
}

Measured memory_bytes: 256