akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int N;
int dubling[22][100005];
int X[100005];
int L;
int main()
{
        cin >> N;
        
        for ( int i = 0; i < N; i++ ) cin >> X[i];
        cin >> L;
        for ( int i = 0; i < N; i++ ) {
                dubling[0][i] = upper_bound(X, X + N, X[i] + L) - X - 1;
                //cout << dubling[0][i] << " ";
        }
        //cout << endl;
        
        for ( int p = 1; p < 22; p++ ) {
                for ( int i = 0; i < N; i++ ) {
                        dubling[p][i] = dubling[p - 1][dubling[p - 1][i]];
                        //cout << p << " " << i << " " << dubling[p][i] << endl;
                }
        }
        
        int Q;
        cin >> Q;
        while ( Q-- ) {
                int a, b;
                cin >> a >> b; --a, --b;
                if ( a > b ) swap(a, b);
                int bit = 0;
                int node = a;
                for ( int p = 21; p >= 0; p-- ) {
                        if ( dubling[p][node] < b ) {
                                node = dubling[p][node];
                                bit |= (1 << p);
                        }
                }
                cout << bit + 1 << endl;
        }

        return ( 0 );
}


Measured memory_bytes: 9856
import java.util.*;

public class Main {
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        int k = stdIn.nextInt();
        int p[] = new int[n];
        
        for(int i = 0; i < n; i++){
            p[i] = stdIn.nextInt();
        }
        
        Arrays.sort(p);
        
        int sum = 0;
        for(int i = 0; i < k; i++){
            sum += p[i];
        }
        //boolean flag = true;
        
        System.out.println(sum);
        //if(flag){
        //    System.out.println("Yes");
        //}else{
        //    System.out.println("No");
        //}
    }
}


Measured memory_bytes: 38724
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.Aising2018
{
    class C
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int[] hw = ReadInts();
            int h = hw[0];
            int w = hw[1];
            var black = new bool[h, w];
            for (int i = 0; i < h; i++)
            {
                string s = Read();
                for (int j = 0; j < w; j++)
                {
                    black[i, j] = s[j] == '#';
                }
            }
            long cnt = 0;
            var visited = new bool[h, w];
            for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < w; j++)
                {
                    if (visited[i, j]) continue;
                    long blackCnt = 0;
                    long allCnt
                        = DFS(black, ref visited, h, w, i, j, ref blackCnt);
                    cnt += (allCnt - blackCnt) * blackCnt;
                }
            }
            Console.WriteLine(cnt);
        }

        static int DFS(bool[,] black, ref bool[,] visited,
            int h, int w, int i, int j, ref long blackCnt)
        {
            visited[i, j] = true;
            bool nowBlack = black[i, j];
            if (nowBlack) blackCnt++;
            int cnt = 1;
            if (i > 0 && nowBlack != black[i - 1, j] && !visited[i - 1, j])
            {
                cnt += DFS(black, ref visited, h, w, i - 1, j,ref blackCnt);
            }
            if (j > 0 && nowBlack != black[i, j - 1] && !visited[i, j - 1])
            {
                cnt += DFS(black, ref visited, h, w, i, j - 1, ref blackCnt);
            }
            if (i < h - 1 && nowBlack != black[i + 1, j] && !visited[i + 1, j])
            {
                cnt += DFS(black, ref visited, h, w, i + 1, j, ref blackCnt);
            }
            if (j < w - 1 && nowBlack != black[i, j + 1] && !visited[i, j + 1])
            {
                cnt += DFS(black, ref visited, h, w, i, j + 1, ref blackCnt);
            }
            return cnt;
        }

        private static string Read() { return Console.ReadLine(); }
        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: 28172
using System;

class Program {
    static void Main (string[] args) {
        int k = int.Parse (Console.ReadLine ());
        string s = Console.ReadLine ();
        if (s.Length <= k) {
            Console.WriteLine (s);
        } else {
            Console.WriteLine (s.Substring (0, k) + "...");
        }
    }
}

Measured memory_bytes: 27488
using System;
using System.Linq;
using System.Collections.Generic;

class Program {

    const int inf = 2 << 29;
    const int MAX = 10000;
    const int wht = 0;
    const int gry = 1;
    const int blk = 2;
    static int[] clr = new int[MAX];

    static List<int>[] grp = new List<int>[MAX];


    static void Main(string[] args) {
        
        for (int i = 0; i < MAX; i++) {
            grp[i] = new List<int>();
        }

        var inp = Console.ReadLine().Split(' ').Select(z => int.Parse(z)).ToArray();
        int n, q; n = inp[0]; q = inp[1];

        var ds = new DisJoinSet(n);

        for (int i = 0; i < q; i++) {
            var c = Console.ReadLine().Split(' ').Select(z => int.Parse(z)).ToArray();
            if (c[0] == 0) {
                ds.unite(c[1], c[2]);
            }
            else {
                if (ds.same(c[1], c[2])) Console.WriteLine(1);
                else Console.WriteLine(0);
            }
        }


        
    }



    public class DisJoinSet {

        List<int> rank, p;

        public DisJoinSet() { }
        public DisJoinSet(int size) {
            rank = Enumerable.Repeat(0, size).ToList();
            p = Enumerable.Repeat(0, size).ToList();
            for (int i = 0; i < size; i++) {
                makeSet(i);
            }
        }

        public void makeSet(int x) {
            p[x] = x;
            rank[x] = 0;
        }

        public int findSet(int x) {
            if (x != p[x]) {
                p[x] = findSet(p[x]);
            }
            return p[x];
        }

        public bool same(int x, int y) {
            return findSet(x) == findSet(y);
        }

        public void unite(int x, int y) {
            link(findSet(x), findSet(y));
        }

        public void link(int x, int y) {
            if (rank[x] > rank[y]) {
                p[y] = x;
            }
            else {
                p[x] = y;
                if (rank[x] == rank[y]) {
                    rank[y]++;
                }
            }
        }
    }
}




Measured memory_bytes: 25340
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
	char str[60];
	int n, k;
	scanf("%d %d", &n, &k);

	int i = 0;
	while (i <= n)
	{
		scanf("%c",&(str[i]));
		i++;
	}
	str[i] = '\0';
	str[k] = str[k] - ('A'-'a');
	printf("%s\n",&(str[1]));
	return(0);
}


Measured memory_bytes: 128
n=gets.to_i
x=gets.split(" ").map(&:to_i)
sum=999999999999999999999999999
tmp=0
(x.min..x.max).each do |i|
    y=x.map { |n| (n - i)**2 }
    tmp=y.inject(:+)
    sum=tmp<sum ? tmp : sum
end
p sum

Measured memory_bytes: 1916
import java.io.*;

public class Main {

    public static void main(String[] args) throws IOException  {
        
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
 
        String[] line = reader.readLine().split(" ");
        int a = Integer.parseInt(line[0]);
        int b = Integer.parseInt(line[1]);
        int c = Integer.parseInt(line[2]);
        
        if(a < b){
            if(b < c){
                System.out.println("Yes");
            }
            else System.out.println("No");
        }
        
        else System.out.println("No");
        
        
    }
    
}

Measured memory_bytes: 24304
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] params = sc.nextLine().split(" ");
        int a = Integer.parseInt(params[0]);
        int b = Integer.parseInt( params[1]);

        int minB = b * 10;
        int maxB = b * 10 + 9;

        for( int i = minB ; i < maxB ; i++ ){
            int ans = (int)(i * 0.08);
            if( ans == a ){
                System.out.println( i );
                return;
            }
        }

        System.out.println( -1 );
    }

}


Measured memory_bytes: 23124
from heapq import heappush, heappop

n, m, s, t = map(int, input().split())
# zero start
s -= 1
t -= 1

# 
vertices = []
for i in range(n):
  v = []
  vertices.append(v)

#print(n, m, s, t)
# load node
for k in range(m):
    u, v, a, b = map(int, input().split())
    vertices[u-1].append([v-1, a, b])
    vertices[v-1].append([u-1, a, b])


#print('-----------------')

#print(n, m, s, t)
#for i in range(n):
#    print(vertices[i])

mode = 0
# return list of [no_adj, cost]
def get_adj(v):
    res = []
    for adj in vertices[v]:
        res.append([adj[0], adj[1+mode]])
    return res

#print('show adjcent(a)')
#for k in range(n):
#    print(get_adj(vertices[k]))

mode = 1
#print('show adjcent(b)')
#for k in range(n):
#    print(get_adj(vertices[k]))

def dijkstra(s):
    inf = int(10e20)
    dist_pre = [inf] * n
    dist = [inf] * n
    h = []
    heappush(h, (0, s))
    dist_pre[s] = 0
    while len(h) > 0:
        # pop 1 node
        dv, v = heappop(h)
        # if already decided, continue
        if dist[v] < inf:
            continue
        dist[v] = dv
        # push adjcent node
        list_adj = get_adj(v)
        #print(v, list_adj)
        for adj in list_adj:
            if dist[adj[0]] == inf:
                dnew = dv + adj[1]
                if dnew < dist_pre[adj[0]]:
                    dist_pre[adj[0]] = dnew
                    heappush(h, (dnew, adj[0]))
                pass
        pass
    return dist

mode = 0
dist_a = dijkstra(s)
mode = 1
dist_b = dijkstra(t)
cost = [a+b for a, b in zip(dist_a, dist_b)]
#cost = []
#for k in range(len(dist_a)):
#    cost.append(dist_a[k] + dist_b[k])
#cost = np.array(dist_a,dtype = 'int') + np.array(dist_b,dtype = 'int')
#cost = np.array(cost, dtype='int')
#print(dist_a)
#print(dist_b)
#print(cost)
#cost = np.array(cost, dtype='int')

res = [0]*n

min_temp = int(1e20)
m0 = int(1e15)
for i in range(n):
    k = n-1-i
    if(cost[k]<min_temp):
        min_temp = cost[k]
    res[k] = m0 - min_temp
    #cost_available = cost[i:]
    #print(m0-np.amin(cost_available))

for r in res:
    print(r)

Measured memory_bytes: 68492
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cassert>
#include <string>
#include <memory.h>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <map>
#include <cctype>
#include <iomanip>
#include <sstream>
#include <cctype>
#include <fstream>
#include <cmath>
using namespace std;

#define REP2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define ITER(c) __typeof((c).begin())
#define PB(e) push_back(e)
#define FOREACH(i, c) for(ITER(c) i = (c).begin(); i != (c).end(); ++i)
#define MP(a, b) make_pair(a, b)
#define PARITY(n) ((n) & 1)

typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1000 * 1000 * 1000 + 7;
const double EPS = 1e-10;

const int B = 400;

const int maxn = 100010;
int par[maxn];
vector<int> ch[maxn];

int   V[maxn];
char QT[maxn];
int ancester[maxn];
bool use[maxn];
bool marked[maxn];

void compress(int l, int r){
  vector<int> vs;
  
  memcpy(use, marked, sizeof(marked));
  REP2(i, l, r) use[V[i]] = true;
  
  queue<P> que;
  que.push(P(1, 0));
  ancester[1] = 0;
  
  while(!que.empty()){
    int v = que.front().first;
    int a = que.front().second;
    que.pop();
    if(use[v] || marked[v]) a = v;
    REP(i, ch[v].size()){
      int to = ch[v][i];
      ancester[to] = a;
      que.push(P(to, a));
    }
  }
}

void mark(int v){
  marked[v] = true;
}

int calc(int v){
  while(!marked[v]) v = ancester[v];
  return v;
}

int main(){
  int N, Q;

  while(cin >> N >> Q && N + Q){
    memset(par, 0, sizeof(par));
    memset(marked, false, sizeof(marked));
    
    REP(i, maxn) ch[i].clear();

    marked[1] = true;
    
    REP(i, N - 1){
      cin >> par[i+2];
      ch[par[i+2]].push_back(i+2);
    }
    
    REP(i, Q){
      cin >> QT[i] >> V[i];
    }
  
    ll s = 0;
    for(int l = 0; l < Q; l += B){
      int r = min(l + B, Q);
      compress(l, r);
      REP2(i, l, r){
        if(QT[i] == 'M') mark(V[i]);
        if(QT[i] == 'Q') s += calc(V[i]);
      }
    }
    cout << s << endl;
  }
  return 0;
}

Measured memory_bytes: 10168
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<iomanip>
using namespace std;

int main() {
    int N; cin >> N;
    vector<long long> A(N), B(N), C(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    for (int i = 0; i < N; i++) cin >> B[i];
    for (int i = 0; i < N; i++) cin >> C[i];

    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());

    long long ans = 0;
    for (int i = 0; i < N; i++) {
        long long a_cnt = lower_bound(A.begin(), A.end(), B[i]) - A.begin();
        long long c_cnt = C.end() - upper_bound(C.begin(), C.end(), B[i]);
        ans += a_cnt * c_cnt;
    }

    cout << ans << endl;
}


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

#define ALL(v) (v).begin(), (v).end()

class DisjointSet{
private:
  vector< int > rank, p;
  void link(int x,int y){
    if(rank[x] > rank[y]){
      p[y] = x;
    }else{
      p[x] = y;
      if(rank[x] == rank[y]) rank[y]++;
    }
  }
public:
  DisjointSet(int size){
    rank.resize(size,0);
    p.resize(size,0);
    for(int i = 0; i < size; i++){
      makeSet(i);
    }
  }
  void makeSet(int x){
    p[x] = x, rank[x] = 0;
  }
  void Union(int x,int y){
    link(findSet(x),findSet(y));
  }
  int findSet(int x){
    return( x != p[x] ? p[x] = findSet(p[x]) : p[x]);
  }
};

int main()
{
  int N;
  while(scanf("%d", &N), N){
    DisjointSet UnionFind(N * N);
    for(int i = 0; i < N; i++){
      for(int j = 0; j < N; j++){
        int x, y;
        scanf("%d %d", &x, &y);
        UnionFind.Union( i * N + j, y * N + x);
      }
    }
    vector< bool > size(N * N, false);
    for(int i = 0; i < N * N; i++){
      size[UnionFind.findSet(i)] = true;
    }
    cout << count(ALL(size), true) << endl;
  }
}

Measured memory_bytes: 1284
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	string S;
	cin >> S;
	vector<int> x(26,0);
	int n = S.size();
	int flag=0;
	for (int i = 0; i < n; i++){
		x[S[i] -'a'] ++;
		if (x[S[i] - 'a']==2){
			flag = 1;
			break;
		}

	}
	if (flag == 0){
		cout << "yes" <<endl;
	}
	else{
		cout << "no" << endl;
	}
	
	return 0;
}

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

int main() {
  int N; cin >> N;
  int max = 0;
  vector<int> cost(N);
  vector<int> value(N);
  
  for (int i = 0; i < N; i++) cin >> value[i];
  for (int i = 0; i < N; i++) cin >> cost[i];
  
  for (int i = 0; i < N; i++) {
    if ((value[i] - cost[i]) > 0) max += value[i] - cost[i];
  }
  
  cout << max << endl;
}

Measured memory_bytes: 888
/*
Created by Rishu Sahu @ covid 20-20
*/
/*
*****************************************************************
*/

#include<bits/stdc++.h>
using namespace std;

#define IOS cin.sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define pai pair<int,int>
#define pal pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,a,b) for(int i=a;i<=b;i++)
#define ff first 
#define ss second
#define sz(x) (int)x.size()
#define vi vector<int>
#define vl vector<ll>
#define mpl map<ll,ll>
#define mpi map<int,int>
#define pb push_back
#define all(x) x.begin(),x.end()

const int mod = 1e9+7;
const int INF = INT_MAX;

void prime(int &temp,int fa,vi &vec){
    while(temp%fa==0){
        vec.pb(fa);
        temp=temp/fa;
        break;
    }
}

void solve(){
    int n;
    cin>>n;
    ll sum=0;
    int arr[n];
    rep(i,n) cin>>arr[i];
    int mx=arr[0];
    for(int i=1;i<n;i++){
        if(arr[i]<mx)
        sum+=(mx-arr[i]);
        mx=max(mx,arr[i]);
    }
    cout<<sum<<endl;
}


int main(){
    /*int t;
    cin>>t;
    while(t--){*/
        solve();
    //}
}

Measured memory_bytes: 4408
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MAX=10005;
const ll INF=0x3f3f3f3f3f3f3f;
const ll MOD=1000000007;
ll n,a[MAX],len,k;
bitset<MAX> bit;
ll bin(ll x,ll y){
    ll p=(x+y)/2;
    if(y-x==1) return x;
    bit.reset();
    bit[0]=1;
    for(ll i=0;i<len;i++) {
        if(i==p) bit=(bit<<a[i]);
        else bit=(bit<<a[i])|bit;
    }
    bit=bit>>k;
    for(ll i=0;i<a[p];i++) {
        if(bit[i]) return bin(x,p);
    }
    return bin(p,y);
}
int main(){
    scanf("%lld%lld",&n,&k);
    for(ll i=1;i<=n;i++) scanf("%lld",&a[i]);
    sort(a,a+n+1);
    for(ll i=0;i<n+1;i++){
        if(a[i]>=k) break;
        len=i+1;
    }
    printf("%lld\n",bin(0,len));
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
 
class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        RootedTree rtree = new RootedTree();
        for (int i = 0; i < n; i++)
        {
            List<int> inputs = Console.ReadLine().Split(' ')
                                        .Select(val => int.Parse(val))
                                        .ToList();
            int p = inputs[0];
            inputs.RemoveRange(0, 2);
            rtree.Add(p, inputs);
        }
        for (int i = 0; i < n; i++)
        {
            rtree[i].Display();
        }
    }
}

class RootedTree
{
    public class Node
    {
        internal const int MaxValue = 100000;
        public int Value {get; internal set;}
        internal Node parent;
        internal List<Node> children = new List<Node>();
        private int _depth = 0;
        int Depth
        {
            get
            {
                if(this._depth != 0 ) return this._depth;
                else if(this.parent == null) return this._depth = 0;
                else return this._depth = this.parent.Depth + 1;
            }
            set
            {
                this._depth = value;
            }
        }
        string Type
        {
            get
            {
                if(parent == null) return "root";
                else if(children.Count == 0) return "leaf";
                else return "internal node";
            }
        }

        internal Node(int val, Node parent)
        {
            this.Value = val;
            if(parent != null)
            {
                this.parent = parent;
                this.parent.children.Add(this);
            }
        }

        public void Display()
        {
            Console.WriteLine("node {0}: parent = {1}, depth = {2}, {3}, [{4}]"
              , this.ToString(), this.parent != null ? this.parent.ToString() : "-1", this.Depth
              , this.Type, string.Join(", ", this.children.Select(elem => elem.ToString()).ToArray()));
        }

        public override string ToString(){
            return this.Value.ToString();
        }
    }

    private Node[] nodes = new Node[Node.MaxValue + 1];
    public Node this[int i]
    {
        get
        {
            return nodes[i];
        }
        set
        {
            nodes[i] = value;
        }
    }

    public void Add(int i, List<int> childList)
    {
        if(this[i] == null) this[i] = new Node(i, null);
        foreach (int j in childList)
        {
            if(this[j] == null) this[j] = new Node(j, this[i]);
            else
            {
                this[j].parent = this[i];
                this[i].children.Add(this[j]);
            }
        }
    }
}

Measured memory_bytes: 33476
#include <iostream>

using namespace std;
int main() {
    int n;
    int a, b;
    cin >> n >> a >> b;
    int s = 0;
    for(int i = 1; i <= n;i++){
        int sum = 0;
        sum += (i / 1) % 10;
        sum += (i / 10) % 10;
        sum += (i / 100) % 10;
        sum += (i / 1000) % 10;
        sum += (i / 10000) % 10;
        if(a <= sum && sum <= b){
            s += i;
        }
    }
    cout << s << endl;
}



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

int main(){
    int H, N;
    cin >> H >> N;
    vector<int> A(N);
    string ans = "No";

    
    for(int i = 0; i < N; i++){
        cin >> A.at(i);
    }
    for(int i = 0; i < N; i++){
        H -= A.at(i);
    }
    if(H <= 0){
        ans = "Yes";
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
def read_inputs
  n, m, l = gets.split(" ").map(&:to_i)
  a = (1..n).map{gets.split(" ").map(&:to_i)}
  b = (1..m).map{gets.split(" ").map(&:to_i)}
  return n, m, l, a, b
end

n, m, l, a, b = read_inputs
puts (0...n).map{|i|
  (0...l).map{|j|
    (0...m).map{|k|
      a[i][k] * b[k][j]
    }.inject(:+)
  }.join(" ")
}.join("\n")

Measured memory_bytes: 13056
import java.util.Scanner;

public class Main {

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

		int N = sc.nextInt();
		int num = N % 10;

		if(num == 3) {
			System.out.println("bon");
		}else if(num == 0 || num == 1 || num == 6 || num == 8) {
			System.out.println("pon");
		}else {
			System.out.println("hon");
		}
	}

}

Measured memory_bytes: 35776
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)

int main() {
	ll N; cin >> N;
	ll a[10000]; rep(i, 0, N)cin >> a[i];

	ll cnt = 0;
	bool hasEven = false;
	//bool overlimit = false;
	while (1) {
		rep(i, 0, N) {
			if (a[i] % 2 == 0 && !hasEven) {
				a[i] /= 2;
				cnt++;
				hasEven = true;
				break;
			}
			//else {
			//	a[i] *= 3;
			//	if (a[i] > 1000000000) {
			//		overlimit = true;
			//	}
			//}
		}

		if (!hasEven) {// || overlimit) {
					   //if (overlimit) {
					   //	cnt--;
					   //}
			break;
		}
		hasEven = false;
		//overlimit = false;
	}
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 384
import java.util.*;

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

        int count = 0;
        while (H > 0) {
            H -= A;
            count++;
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 35672
import networkx as nx
from networkx.utils.union_find import UnionFind
n,m=map(int,input().split())
if m==0:print(1);exit()
a=[[i for i in input().split()] for _ in range(m)]
g=nx.Graph()
uf=UnionFind()
for x in a:
     uf.union(x[0],x[1])
print(len(max(uf.to_sets(),key=len)))

Measured memory_bytes: 143064
#!/usr/bin/env python3

n = int(input())
a, b = [int(x) for x in input().split()]
p = [int(x) for x in input().split()]
p1 = [x for x in p if x <= a]
p2 = [x for x in p if a < x <= b]
p3 = [x for x in p if b < x]
r = [len(p1), len(p2), len(p3)]
print(min(r))


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

using namespace std;

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<int(n);i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using Pint = pair<int,int>;
const ll mod = 1e9+7;

ll g1(ll n, ll p){
  if(n==0) return 0;
  return n/p + g1(n/p, p);
}

ll g2(ll n, ll p){
  if(n&1) return 0;
  if(p==2) {
    return g1(n/2, p) + n/2;
  }
  return g1(n/2, p);
}

int main(){
  ll n;
  cin>>n;

  ll ans=g2(n,5);

  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 3644
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
//#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl
/* -- template -- */

const int MAX = 1000100;
ll 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;//拡張euclid互除法によるi!の逆元計算
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll 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;
}

const int MAX_N = 3100;

ll dp[MAX_N][MAX_N]; //dp[i][j] : 区間[i, j)のみの配列が与えられたときの最善のX-Y

int main() {
    int N; cin >> N;
    int a[N];
    rep(i, N) cin >> a[i];
    rep(i, N) dp[i][i] = 0;
    for(int len = 1; len <= N; ++len) {
        for(int i = 0; i + len <= N; ++i) {
            int j = i + len;
            if((N - len) % 2 == 0) {//いままで取り出した数が偶数個なら先手
                dp[i][j] = max(dp[i + 1][j] + a[i], dp[i][j - 1] + a[j - 1]);
            }else {
                dp[i][j] = min(dp[i + 1][j] - a[i], dp[i][j - 1] - a[j - 1]);
            }
        }
    }
    cout << dp[0][N] << endl;
}


Measured memory_bytes: 73984
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define rt return 0
#define endln "\n"
#define all(v) v.begin(), v.end()
#define for1(i, a, b) for (long long int i = a; i < b; i++)
#define for2(i, a, b) for (long long int i = a; i > b; i--)
//  cout << fixed << setprecision(0) << pi <<" "<<npi<<endl;typedef long long int i;
typedef long long int lli;
typedef pair<lli, lli> pll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // lli t;
    // cin >> t;
    vector<lli> v;
    char c;
    cin >> c;
    if (c < 97)
    {
        cout << "A" << endl;
    }
    else
    {
        cout << "a" << endl;
    }
}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>

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

using ll = long long;
using namespace std;

constexpr int INF = 2147483647; // 2 * 1e9
constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

ll gcd(ll x, ll y){
	if(x < y){
		ll tmp = y;
		y = x;
		x = tmp;
	}
	if(y == 0) return x;
	return gcd(y, x % y);
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	ll ans = 1;
	cin >> n;
	ll t;
	REP(i, n) {
		cin >> t;
		ll g = gcd(ans, t);
		ans = ans / g * t ;
	}
	cout << ans << "\n";
	return 0;
}


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

using namespace std;

int main()
{
    int n;
    cin>>n;
    int a[n],b[n];
    for(int i1=0;i1<n;i1++){
        cin>>a[i1];
    }
    int d2=a[0];
    for(int i1=1;i1<n;i1++){
            d2=d2^a[i1];
    }
    for(int i1=0;i1<n;i1++){
        int d1=d2^a[i1];
        cout<<d1<<" ";
    }
    return 0;
}


Measured memory_bytes: 4412
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, ll> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 35;
const int MAXK = 510;
const int MAXQ = 200010;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int a, b, c;
    cin >> a >> b >> c;
    cout << min(a+b, min(b+c, c+a));
    return 0;
}

Measured memory_bytes: 256
import sys

MOD = 10 ** 9 + 7

def make_table(n=10**5+1, p=10**9+7):
    fac = [None] * (n + 1)
    fac[0] = 1
    ifac = fac.copy()
    for i in range(1, n + 1):
        fac[i] = fac[i-1] * i % p
    ifac[n] = pow(fac[n], p - 2, p)
    for i in range(n-1, 0, -1):
        ifac[i] = ifac[i+1] * (i + 1) % p
    return fac, ifac
fac, ifac = make_table()
def comb_mod(n, r, mod=10**9+7):
    if r < 0 or r > n:
        return 0
    return fac[n] * ifac[r] % mod * ifac[n-r] % mod

n, *a = map(int, sys.stdin.read().split())

def main():
    appeared = [False] * (n + 1)
    for i in range(n+1):
        cur = a[i] 
        if appeared[cur]:
            x1, x2 = appeared[cur], i+1
            break
        appeared[cur] = i+1
    
    res = [0] * (n + 2)
    for i in range(1, n+2):
        res[i] += comb_mod(n+1, i)

    x = (x1 - 1) + (n + 1 - x2)
    for i in range(x+1):
        res[i+1] -= comb_mod(x, i)
        res[i+1] %= MOD

    return res[1:]

if __name__ == '__main__':
    ans = main()
    print(*ans, sep='\n')

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


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t,d;
    cin >> t >> d;
    ll count=0,x,y;
    for(ll i=0;i<t;i++){
        cin >> x >> y;
        if(d*d >= x*x + y*y){
            count++;
        }
    }
    cout << count ;
    return 0;
}


Measured memory_bytes: 3644
//============================================================================
// Name        : aoj001.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {
	int S,h,m,s;
	cin >> S;
	h = S / 3600 ;
	m = S % 3600 / 60;
	s = S % 3600 % 60;
	cout << h << ":" << m << ":" << s << endl;
	return 0;
}



Measured memory_bytes: 3088
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define f first
#define s second
#define pb push_back
#define fix  cout<<std::fixed;
#define mk make_pair
#define N 100005
#define mod 1000000007
#define time  cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;
#define IOS        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
vector <int> v[N];
ll vis[N],p[N],dis[N];
int main()
{
    ll n;cin>>n;
    ll m;cin>>m;

    for(int i=0;i<m;i++)
    {
        int a,b;cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    }

    queue <int> q;

    q.push(1);
vis[1]=1;
    while(!q.empty())
    { //cout<<1<<endl;
        int r=q.front();
        q.pop();
        for(auto i:v[r])
        {   if(vis[i]==0)
            {p[i]=r;
            dis[i]=dis[p[i]]+1;
            q.push(i);vis[i]=1;}
        }
        
    }

    for(int i=1;i<=n;i++)
    {
        if(vis[i]==0){cout<<"No";return 0;}
    }
cout<<"Yes"<<endl;
    for(int i=2;i<=n;i++)cout<<p[i]<<endl;


}

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


#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

int64_t getVal(int64_t d){
  int64_t ans = 1;
  for(int i=1;i<d;i++){
    ans *= 10;
  }
  return ans;
}



signed main() {
  uint64_t n;
  cin >> n;
  list<uint64_t> factors;  
  
  uint64_t minSteps = n*2;

  for(uint64_t i=1;i<=sqrt(n);i++){
    if(n%i==0){
      minSteps = min(minSteps, i+n/i-2);
    }
  }
  cout << minSteps << endl;
  return 0;
  
}




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

#define ll long long
#define pb push_back
#define eb emplace_back
//#define st first
#define sc second

using namespace std;

const ll mod = 1e9 + 7;
const int e = 1e6 + 69;
const int base = 311;

// dung inverse module de tinh nCk
// beginer 85
// mbeginer 162
// cach tao hoan vi tu n so : n*(n+1)/2;

//vector<pair<ll,ll>>adj[e];
//vector<ll>adj[e];

/*ll Pow(ll n, ll dem)
{
    if(dem == 0) return 1;
    if(dem == 1) return n ;
    ll t = Pow(n, dem/2);
    if(dem % 2 == 0) return (t*t);
    else return ((t * t) * n);
}*/

/*ll C(ll k, ll n)
{
    if(k == 0) return 1;
    if(n < k) return 0;
    return (gt[n]%mod * (igt[k]%mod * igt[n-k]%mod)%mod)%mod;
}*/

int main()
{
    int n;
    ll h;
    cin >> n >> h;
    ll maxx = 0;
    ll ans = 0;
    ll pos = 1e18;
    vector<ll>b(n);
    for(int i=0; i<n; i++)
    {
        ll a;
        cin >> a >> b[i];
        maxx = max(maxx, a);
    }
    ll dem = 0;
    sort(b.begin(), b.end());
    while(h > 0 && b.size() != 0)
    {
        if(b.back() <= maxx) break;
        dem ++;
        h -= b.back();
        b.pop_back();
    }
    if(h > 0) dem += (h + maxx - 1)/maxx;
    cout << dem;
}
/*

*/


Measured memory_bytes: 1024
N = int(input())
L = list(map(int,input().split( )))
L.sort()
ans = 0
for i in range(N):
    for j in range(i,N):
        for k in range(j,N):
            li = L[i]
            lj = L[j]
            lk = L[k]
            if li + lj > lk and lj + lk > li and lk + li >= lj and li != lj and lj != lk:
                ans += 1
print(ans)

Measured memory_bytes: 9188
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

const ll INF = 1ll << 60;

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int H, N;
  while (cin >> H >> N) {
    vector<int> A(N), B(N);
    for (int i = 0; i < N; i++) cin >> A[i] >> B[i];
    vector<ll> dp(H + 1, INF);
    dp[H] = 0;
    for (int h = H; h > 0; h--) {
      for (int i = 0; i < N; i++) {
        chmin(dp[max(0, h - A[i])], dp[h] + B[i]);
      }
    }
    cout << dp[0] << endl;
  }
  return 0;
}


Measured memory_bytes: 384
n=int(input())
h=list(map(int,input().split()))
if n==1:
    print('Yes')
else:
    h[0]-=1
    for i in range(n-1):
        if h[i]<h[i+1]:
            h[i+1]-=1
        elif h[i]>h[i+1]:
            print('No')
            exit()
    print('Yes')

Measured memory_bytes: 14396
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func indexOf(slice []string, item string) int {
	for i, _ := range slice {
		if slice[i] == item {
			return i
		}
	}
	return -1
}

func main() {
	a := nextLine()
	arr := strings.Split(a, " ")
	indnex := indexOf(arr, "0")
	first, _ := strconv.Atoi(arr[0])
	secound, _ := strconv.Atoi(arr[1])
	if first != 0 {
		fmt.Println(first + indnex)
	} else {
		fmt.Println(secound - 1)
	}
}


Measured memory_bytes: 1772
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#define ll long long
#define F(i,a,b) for(int i=(a);i<=(b);i++)
#define mst(a,b) memset((a),(b),sizeof(a))
#define PLL pair<ll,ll>
using namespace std;
template<class T>inline void read(T &x) {
    x=0; int ch=getchar(),f=0;
    while(ch<'0'||ch>'9'){if (ch=='-') f=1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    if(f)x=-x;
}
const int inf=0x3f3f3f3f;
const int maxn=200050;
ll n,d,t,c[maxn];
PLL a[maxn];
int main()
{
	cin>>n>>d>>t;
	for(int i=1;i<=n;i++)
	{
		read(a[i].first);read(a[i].second);
	}
	sort(a+1,a+n+1);
	ll i=1;
	ll temp=0,ans=0;
	d*=2;
	while(i<=n)
	{
		temp-=c[i];
		a[i].second-=temp;
		if(a[i].second>0)
		{
			ll tt=(a[i].second+t-1)/t;
			ans+=tt;
			temp+=t*tt;
			int l=0,r=n+1;
			while(l<r)
			{
				int mid=l+r>>1;
				if(a[mid].first>a[i].first+d) r=mid;
				else l=mid+1;
			}
			if(l!=n+1) c[l]+=t*tt;
		}
		i++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#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)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main()
{
    int n;
    cin >> n;
    vector<P> v(n);
    rep(i,n){
        int a, b;
        cin >> a >> b;
        v[i] = make_pair(b,a);
    }
    
    sort(ALL(v));
    int t = 0;
    string ans = "Yes";
    rep(i,n){
        t+=v[i].second;
        if(t > v[i].first){
            ans = "No";
            break;
        }
    }   

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4816
N,M = [int(i) for i in input().split()]
A = [int(input()) for _ in range(M)]

m = 10**9+7

memo = [1]*(N+3)
for i in range(3,N+3):
    memo[i] = memo[i-1] + memo[i-2]

memo[0] = 0

A.append(N+1)
p = A[0]
ans = memo[p]
for i in range(1,M+1):
    ans *= memo[A[i]-p-1]
    p = A[i]

print(ans%m)


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

// main.cpp

std::int_fast64_t f(std::int_fast64_t x) {
  std::int_fast64_t result = 0;
  while (x > 0) {
    result += x % 10;
    x /= 10;
  }
  return result;
}

int main() {
  std::int_fast64_t n, a, b;
  std::cin >> n >> a >> b;

  std::int_fast64_t answer = 0;
  for (std::int_fast64_t i = 1; i <= n; ++i) {
    const std::int_fast64_t x = f(i);
    if (a <= x && x <= b) answer += i;
  }

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

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

const int N = 2e5;

int n;

map<string,int> cnt;

int main(){
	cin >> n;
	int maksi = 0;
	for(int i=1;i<=n;i++){
		string s;
		cin >> s;
		cnt[s]++;
		maksi = max(maksi,cnt[s]);
	}
	vector<string> ans;
	for(auto x:cnt){
		if(x.second == maksi) ans.push_back(x.first);
	}
	sort(ans.begin(),ans.end());
	for(int i=0;i<ans.size();i++){
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 26868
h,w = map(int,input().split())
s = [input() for i in range(h)]

if h == 1 and w == 1:
    if s[0]=='#':
        print('#')
    else:
        print('0')

elif h == 1:
    ans = ''
    for i in range(w):
        if s[0][i]=='#':
            ans += '#'
        elif i != 0 and i != w-1:
            ans += str(s[0][i-1:i+2].count('#'))
        elif i == 0:
            ans += str(s[0][1].count('#'))
        elif i == w-1:
            ans += str(s[0][i-1].count('#'))
    print(ans)

elif w == 1:
    for i in range(h):
        if s[i]=='#':
            print('#')
        elif i != 0 and i != h-1:
            print(str(s[i-1:i+2].count('#')))
        elif i == 0:
            print(str(s[1].count('#')))
        elif i == h-1:
            print(str(s[i-1].count('#')))

else:
    for i in range(h):
        ans = ''
        for j in range(w):
            if s[i][j] == '#':
                ans += '#'
            else:
                if i != 0 and j!= 0 and i != h-1 and j!= w-1:
                    up = s[i-1][j-1:j+2].count('#')
                    parallel = s[i][j-1:j+2].count('#')
                    down = s[i+1][j-1:j+2].count('#')
                    ans += str(up+parallel+down)
                elif i==0 and j==0:
                    parallel = s[0][1].count('#')
                    down = s[1][0:2].count('#')
                    ans += str(parallel+down)
                elif i==0 and j==w-1:
                    parallel = s[0][w-2:].count('#')
                    down = s[1][w-2:].count('#')
                    ans += str(parallel+down)
                elif i==h-1 and j==0:
                    up = s[i-1][:2].count('#')
                    parallel = s[i][:2].count('#')
                    ans += str(up+parallel)
                elif i==h-1 and j==w-1:
                    up = s[i-1][w-2:].count('#')
                    parallel = s[i][w-2:].count('#')
                    ans += str(up+parallel)
                elif i==0:
                    parallel = s[0][j-1:j+2].count('#')
                    down = s[1][j-1:j+2].count('#')
                    ans += str(parallel+down)
                elif j==0:
                    up = s[i-1][:2].count('#')
                    parallel = s[i][:2].count('#')
                    down = s[i+1][:2].count('#')
                    ans += str(up+parallel+down)
                elif i==h-1:
                    up = s[i-1][j-1:j+2].count('#')
                    parallel = s[i][j-1:j+2].count('#')
                    ans += str(up+parallel)
                else:
                    up = s[i-1][w-2:].count('#')
                    parallel = s[i][w-2:].count('#')
                    down = s[i+1][w-2:].count('#')
                    ans += str(up+parallel+down)
        print(ans) 

Measured memory_bytes: 3260
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
typedef long long ll;
typedef pair<ll,ll> PP;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug false
#define debug2 false

int N;
vector<int> A,U,V;
vector<vector<int>> G;
vector<int> Ans;

vector<int> D;

vector<int> ind,value;


void dfs(int v,int p){
    int pos=distance(D.begin(),lower_bound(D.begin(), D.end(),A[v]));
    if(pos==D.size()){
        ind[v]=D.size();
        value[v]=-1;
        D.push_back(A[v]);
    }else{
        ind[v]=pos;
        value[v]=D[pos];
        
        D[pos]=A[v];
    }
    Ans[v]=D.size();
    
    #if debug
    cout << v+1 << "  ";
    REP(i,D.size()){cout << D[i] << " ";}cout << endl;
    #endif
    
    for(int& e:G[v]){
        if(e==p)continue;
        
        dfs(e,v);
        
    }
    
    #if debug
    cout << v+1 << "  ";
    REP(i,D.size()){cout << D[i] << " ";}cout << endl;
    #endif
    
    if(value[v]==-1){
        D.pop_back();
    }else{
        D[ind[v]]=value[v];
    }
    
    
}


signed main(void){
    int a;
    cin >> N;
    REP(i,N){
        cin >> a;
        A.push_back(a);
    }
    REP(i,N-1){
        cin >> a;a--;
        U.push_back(a);
        cin >> a;a--;
        V.push_back(a);
    }
    
    G.resize(N);
    REP(i,N-1){
        G[U[i]].push_back(V[i]);
        G[V[i]].push_back(U[i]);
    }
    
    Ans.clear();
    REP(i,N){Ans.push_back(0);}
    ind.clear();
    REP(i,N){ind.push_back(0);}
    value.clear();
    REP(i,N){value.push_back(-1);}
    
    dfs(0,-1);
    
    REP(i,N){
        cout << Ans[i] << endl;
    }
    
    return 0;
}




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

int main(){
  int N;
  string S;
  cin >> N >> S;
  
  int ans = 0;
  for(int i = 0;i<N;i++){
    int count = 0;
    for(char c='a';c<='z';c++){
      bool left = false;
      bool right = false;
      for(int j = 0;j<=i;j++){
        if(c == S.at(j)) left = true;
      }
      for(int j = i+1;j<N;j++){
        if(c == S.at(j)) right = true;
      }
      if(left && right) count++;
      ans = max(ans,count);
    }
  }
  cout << ans << endl;
}


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

using namespace std;

// Macros
#define f(i,a,b) for(int i=a; i<b; i++)
#define f_(i,a,b) for(int i=a; i>=b; i++)
#define F first
#define S second
#define PB push_back
#define endl '\n'
// Debuging
#define deb(x) cout << #x << " " << x << '\n'
// Shortcuts
typedef long long ll;
typedef pair<int,string> pi;
typedef vector<string> vi;

int main()
{
   ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
   /* code */
   int n; cin>>n;
   unordered_map<string,int> mp;
   f(i,0,n)
   {
      string s; cin>>s;
      sort(s.begin(),s.end());
      mp[s]++;
   }
   ll ans = 0;
   for(auto& it : mp){
      int s = it.S;
      ans += (ll)s*(s-1)/2; // nCr (Combination formula) in particular of r=2
   }
   cout<<ans<<endl;

}

Measured memory_bytes: 10660
n,k = map(int,input().split())
v = list(map(int,input().split()))
ans = 0
for a in range(n):
    for b in range(a,n+1):
        c = 0
        if a+n-b <= k:
            p = k-(a+n-b)
            s = v[:a]+v[b:]
            s.sort()
            for t in s:
                if p >= 1 and t < 0:
                    p -= 1
                else:
                    c += t

        ans = max(c,ans)

print(ans)

Measured memory_bytes: 39792