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

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

    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    if(n==2)
        cout<<abs(a[0]-a[1])<<"\n";
    else
    {
        int dp[n];
        dp[0]=0;
        dp[1]=abs(a[0]-a[1]);

        for(int i=2;i<n;i++)
            dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
        cout<<dp[n-1]<<"\n";
    }

    return 0;
}


Measured memory_bytes: 1024
import java.util.*;


public class Main{
	
	public static void main(String... args){
		Scanner scan = new Scanner(System.in);
		
		// input
		int num = scan.nextInt();
		long[] edges = new long[100000];
		for(int i = 0; i < num; i++){
			edges[i] = scan.nextLong();
		}
		
		// search
		Arrays.sort(edges);
		long memory = edges[99999];
		int count = 1;
		long firstLen = 0;
		long secondLen = -1;
		for(int i = 99998; i >= 0; i--){
			if(memory == edges[i]){
				count++;
				if(count == 2){
					if(edges[i] > firstLen){
						secondLen = firstLen;
						firstLen = edges[i];
						count = 0;
					} else if(edges[i] > secondLen){
						secondLen = edges[i];
						count = 0;
					}
				}
			} else {
				memory = edges[i];
				count = 1;
			}
		}
		
		// output
		long area = 0;
		if(firstLen * secondLen > 0){
			area = firstLen * secondLen;
		}
		System.out.println(area);
		
	}
	
}

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

def main():
    N = int(input())
    Dic = {}
    for _ in range(N):
        S = input()    
        S_list = [S[i] for i in range(len(S))]
        S_list.sort()
        S_sorted = "".join(S_list)
        Dic[S_sorted] = Dic.get(S_sorted,0) + 1
        
    ans = 0
    for x in Dic:
        num = Dic[x]
        ans += num * (num-1) // 2
        
    print(ans)
        
    
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 59484
#include<stdio.h>
#include<stdlib.h>
#define MAX 100005
#define NIL -1

struct Node {int p, l, r; };

struct Node T[MAX];
int n, D[MAX];

void print(int u){
  int i, c;
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].p);
  printf("depth = %d, ",D[u]);

  if(T[u].p == NIL){
    printf("root, ");
  }
  else if(T[u].l == NIL){
    printf("leaf, ");
  }
  else{
    printf("internal node, ");
  }

  printf("[");

  for(i = 0, c = T[u].l ; c != NIL ; i++, c = T[c].r){
    if(i){
      printf(", ");
    }
    printf("%d",c);
  }

    printf("]\n");
}

int rec(int u, int p){
  D[u] = p;
  if(T[u].r != NIL){
    rec(T[u].r, p);
  }
  if(T[u].l != NIL){
    rec(T[u].l, p + 1);
  }
}

int main(){
  
  int i, j, d, v, c, l, r;

  scanf("%d",&n);

  for(i = 0 ; i < n ; i++){
    T[i].p = T[i].l =T[i].r = NIL;
  }

  for(i = 0 ; i < n ; i++){
    scanf("%d%d",&v,&d);
    for(j = 0 ; j < d ; j++){
      scanf("%d",&c);
      if(j == 0){
	T[v].l = c;
      }
      else{
	T[l].r = c;
      }
      l = c;
      T[c].p = v;
    }
  }

  for(i = 0 ; i < n ; i++){
    if(T[i].p == NIL){
      r = i;
    }
  }

  rec(r, 0);

  for(i = 0 ; i < n ; i++){
    print(i);
  }
  return 0;
}


Measured memory_bytes: 6380
N, K = map(int, input().split())
A = list(map(int, input().split()))

history = {i+1: -1 for i in range(N)}
now = 1
history[now] = 0
hist = [now]
start = -1
end = -1
for i in range(K):
    now = A[now - 1]
    hist.append(now)
    if history[now] >= 0:
        start = history[now]
        end = i + 1
        break
    history[now] = i + 1

if start < 0 or end < 0:
    print(now)
else:
    index = (K - start) % (end - start)
    print(hist[start:end][index])


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

int main() {
  string S;
  cin >> S;
  int cost = 0;
  for (int i = 0; i < S.size() - 1; i++) {
    char lhs = S.at(i);
    char rhs = S.at(i + 1);
    if (lhs != rhs) cost++;
  }
  cout << cost << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main()
{  
   vector<ll>a;
   ll ee=0;
   for(int i=1;i<=55;i++){ 
       ee+=i;
       a.push_back(ee);
   }
   ll n,ans=0;
   map<ll,int>cnt;
   cin>>n;
   for(ll i=2;i*i<=n;i++){ 
       while(n%i==0){ 
           //v.push_back(i);
           cnt[i]++;
           n=n/i;
       }
   } 
   if(n>1)cnt[n]++;
   for(auto i:cnt){ 
      int c=i.second;
      int l=0,r=54,mid,ok=-1;
      while(l<=r){ 
        mid=(l+r)/2;
        if(a[mid]<=c){ 
            l=mid+1;
            ok=mid+1;
        }
        else r=mid-1;
      } 
      if(ok!=-1)ans+=ok;
   }
   cout<<ans<<'\n';
      
       
   
   

    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=mod*mod*3LL;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
vector<ll> a, d;
vector<pair<ll, ll> > p;
vector<vector<ll> > v;
vector<ll> ans;
void dfs(ll now, ll pa = -1){
	ll id = lower_bound(be(d), a[now]) - d.begin();
	if(id == ll(d.size())){
		p[now] = make_pair(id, 0LL);
		d.pb(a[now]);
	}else{
		p[now] = make_pair(id, d[id]);
		d[id] = a[now];
	}
	ans[now] = d.size();
	for(auto& to: v[now]){
		if(pa == to)continue;
		dfs(to, now);
	}
	d[p[now].first] = p[now].second;
	if(p[now].second == 0LL){
		d.resize(d.size()-1);
	}
	return;

}
int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    a.resize(n);
    v.resize(n);
    p.resize(n);
    ans.resize(n);
    ll u, b;
    for(int i=0;i<n;i++){
    	cin >> a[i];
    }
    for(int i=1;i<n;i++){
    	cin >> u >> b;
    	u--;b--;
    	v[u].pb(b);
    	v[b].pb(u);
    }
    dfs(0);
    for(int i=0;i<n;i++){
    	cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 28932
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    if(a <= 9 && b <= 9) cout << a*b << endl;
    else cout << -1 << endl;
    return 0;
}


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

struct Union_find{

    vector<int> tree;
    
    Union_find(int n){
        tree.resize(n + 1);
        for(int i = 1; i <= n; i++) tree[i] = i;
    }

    int find(int x){
        if(tree[x] == x) return x;
        else return tree[x] = find(tree[x]);
    }

    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return;
        tree[y] = x;
    }

    bool solve(int x, int y){
        return (find(x) == find(y));
    }

};

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

    vector<int> p(N);
    for(int i = 0; i < N; i++){
        cin >> p[i];
    }
    Union_find tree(N);
    int x, y;
    for(int i = 0; i < M; i++){
        cin >> x >> y;
        tree.unite(x, y);
    }

    int ans = 0;
    for(int i = 0; i < N; i++){
        if(tree.solve(i + 1, p[i])) ans++;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
using namespace std;
long long  dp[105][100005],v[105],w[105];
int main(){
    int n,maa;
    cin>>n>>maa;
    for(int i=0;i<n;i++){
        cin>>w[i]>>v[i];
    }
    for(int i=0;i<=maa;i++){
        dp[0][i]=0;
    }
    for(int i=0;i<n;i++){
        for(int k=0;k<=maa;k++){
            if(k>=w[i]){
               dp[i+1][k]=max(dp[i][k-w[i]]+v[i],dp[i][k]);
            }else{
                dp[i+1][k]=dp[i][k];
            }
        }
    }
    cout<<dp[n][maa]<<endl;
}

Measured memory_bytes: 80128
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

struct edge
{
	int to;
	long long cost;
	edge(int to_, long long cost_) :
		to(to_), cost(cost_) {}
};
const long long INF = 123456789012345;
using P = pair<long long, int>;//first:cost,second:vertice
void dijkstra(vector<edge>graph_[], long long dist[], int n_, int s_)
{
	priority_queue<P, vector<P>, greater<P>>que;
	que.push({ 0,s_ });
	fill(dist, dist + n_, INF);
	dist[s_] = 0ll;
	while (!que.empty())
	{
		auto q = que.top();
		que.pop();
		long long thd = q.first;
		int thv = q.second;
		if (thd > dist[thv])
		{
			continue;
		}
		for (auto ed : graph_[thv])
		{
			if (dist[ed.to] > ed.cost + thd)
			{
				dist[ed.to] = ed.cost + thd;
				que.push({ dist[ed.to],ed.to });
			}
		}
	}
}

vector<edge>graph[5000000];
LL dist[5000000];
map<pair<int, int>, int>vecset;
int n, m;

int main(void)
{
	cin >> n >> m;
	for (int i = 0; i < n; ++i)
		vecset[make_pair(i, 0)] = i;
	for (int i = 0; i < m; ++i)
	{
		int p, q, c;
		cin >> p >> q >> c;
		--p; --q;
		int f1 = 0, f2 = 0;
		if (!vecset.count(make_pair(p, c)))
		{
			f1 = vecset[make_pair(p, c)] = vecset.size();
			//改札の外に出る＝0
			graph[f1].push_back(edge(p, 0));
			//改札の中に入る＝1
			graph[p].push_back(edge(f1, 1));
		}
		else
		{
			f1 = vecset[make_pair(p, c)];
		}
		if (!vecset.count(make_pair(q, c)))
		{
			f2 = vecset[make_pair(q, c)] = vecset.size();
			//改札の外に出る＝0
			graph[f2].push_back(edge(q, 0));
			//改札の中に入る＝1
			graph[q].push_back(edge(f2, 1));
		}
		else
		{
			f2 = vecset[make_pair(q, c)];
		}
		//線路同士＝0
		graph[f1].push_back(edge(f2, 0));
		graph[f2].push_back(edge(f1, 0));
	}
	dijkstra(graph, dist, vecset.size(), 0);
	if (dist[n - 1] >= INF)
	{
		cout << -1 << endl;
		return 0;
	}
	cout << dist[n - 1] << endl;
	return 0;
}


Measured memory_bytes: 181620
A, B, C = 0, 0, 0  # A直角, B鋭角, C鈍角
while True:
	i = list(map(int, input().split()))
	i.sort()
	a, b, c = i[0], i[1], i[2]
	if c >= a + b:  # 三角形ではない
		break
	a2, b2, c2 = a ** 2, b ** 2, c ** 2
	if c2 == b2 + a2:  # 直角
		A = A + 1
	elif c2 < b2 + a2:  # 鈍角
		B = B + 1
	elif c2 > b2 + a2:  # 鋭角
		C = C + 1

print('{0} {1} {2} {3}'.format(A + B + C, A, B, C))



Measured memory_bytes: 5604
import java.util.*;
public class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                int 鶏 = sc.nextInt();
                sc.close();
                boolean あなた = true;
                for(int i = 1 ; i <= 360 && あなた ; i++){
                        if((i * 鶏) % 360 == 0){
                                System.out.println(i);
                                あなた = false;
                        }
                }
        }
}

Measured memory_bytes: 35616
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}
int n = 10;
bool in(int a, int b){
    if(a < 0 || a >= n || b < 0 || b >= n)return false;
    return true;
}
int dx[] = {0,0,1,0,-1};
int dy[] = {0,1,0,-1,0};

signed main(void) {
    int num;
    cin >> num;
    while(num--){
        vvi a(n,vi(n));
        rep(i,n)rep(j,n)cin >> a[i][j];
        rep(bit, 1<<n){
            vvi t = a;
            vvi ans(n,vi(n,0));
            rep(i,n)if(bit&(1<<i)){
                ans[0][i]++;
                rep(j,5){
                    int x = 0 + dx[j];
                    int y = i + dy[j];
                    if(in(x,y))t[x][y] ^= 1;
                }
            }
            rep(i,n-1)rep(j,n)if(t[i][j]){
                ans[i+1][j]++;
                rep(k,5){
                    int x = i+1 + dx[k];
                    int y = j + dy[k];
                    if(in(x,y))t[x][y] ^= 1;
                }
            }
            bool c = true;
            rep(j,n)if(t[n-1][j])c = false;
            if(c){
                rep(i,n)rep(j,n)cout << ans[i][j] << " \n"[j == n-1];
            }
        }
        vvi ans(n,vi(n,0));
    }
}



Measured memory_bytes: 3104
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Linq.Enumerable;
using static System.Math;

class Program
{
    static void Main()
    {
        var (A, B, C, D) = ReadLine().Split(' ').Select(long.Parse).ToArray();

        var ans = Max(Max(Max(A * C, A * D), B * C), B * D);

        WriteLine(ans);
    }
}

static class ArrayDeconstructExtensions
{
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2) => (i1, i2) = (a[0], a[1]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3) => (i1, i2, i3) = (a[0], a[1], a[2]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4) => (i1, i2, i3, i4) = (a[0], a[1], a[2], a[3]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4, out T i5) => (i1, i2, i3, i4, i5) = (a[0], a[1], a[2], a[3], a[4]);
}


Measured memory_bytes: 28224
#include<iostream>

using namespace std;
int main(){
    int a,ans;
    cin >> a;
    if(a % 2 == 0 && a>0){
        ans = a / 2;
    }else{
        ans = (a / 2) + 1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
long long a[100011];
int main(void)
{
    a[1]=1;
    for(long long i=2;i<=100010;++i)
    {
        a[i]=(a[i-1]*i)%mod;
    }
    long long n,m;
    cin>>n>>m;
    if(abs(n-m)>=2)
    {
        cout<<0<<endl;
        return 0;
    }
    else
    {
        if(abs(n-m)==1)
        {
            cout <<((a[n]*a[m])%mod)<<endl;
        }
        else
        {
            cout <<((a[n]*a[m]*2)%mod)<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string s;
int ln,k;
ll fun(int id,int ch,int k)
{
	ll ans=0;
	int vl=s[id]-'0';
	if(k==0) return 1;
	if(k<0 || id>=ln) return 0;
	if(ch && !vl) ans=fun(id+1,1,k);
	else ans=fun(id+1,0,k);
	for(int i=1;i<=9;i++)
	{
		if(ch)
		{
			if(i<vl) ans+=fun(id+1,0,k-1);
			else if(i==vl) ans+=fun(id+1,1,k-1);
		}
		else ans+=fun(id+1,0,k-1);
	}
	return ans;
}
int main()
{
	cin>>s>>k;
	ln=s.length();
	cout<<fun(0,1,k);
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#define MAX 10000
#define NIL -1

struct Node 
{
    int parent,left,right;
};

Node T[MAX];
int n,D[MAX],H[MAX];

void setDepth(int u,int d)
{
    if(u == NIL) return;
    D[u] = d;
    setDepth(T[u].left,d+1);
    setDepth(T[u].right,d+1);
}

int setHeight(int u)
{
    int h1 = 0, h2 = 0;
    if(T[u].left!=NIL)
    h1 = setHeight(T[u].left)+1;
     if(T[u].right!=NIL)
    h2 = setHeight(T[u].right)+1;
    return H[u] = (h1 > h2 ? h1 : h2);
}

int getSibling(int u)
{
    if(T[u].parent == NIL) return NIL;
    if(T[T[u].parent].left != u && T[T[u].parent].left != NIL)
    return T[T[u].parent].left;
    if(T[T[u].parent].right != u && T[T[u].parent].right != NIL)
    return T[T[u].parent].right;
    return NIL;
}

void print(int u)
{
    printf("node %d: ", u);
    printf("parent = %d, ", T[u].parent);
    printf("sibling = %d, ", getSibling(u));
    int deg = 0;
    if(T[u].left != NIL)deg++;
    if(T[u].right != NIL)deg++;
    printf("degree = %d, ", deg);
    printf("depth = %d, ", D[u]);
    printf("height = %d, ", H[u]);

    if(T[u].parent == NIL)
    {
        printf("root\n");
    }
    else if(T[u].left == NIL && T[u].right == NIL)
    {
        printf("leaf\n");
    }
    else{
        printf("internal node\n");
    }
}

int main()
{
    int v,r,l,root=0,i;
    scanf("%d",&n);

    for(i=0;i<n;i++) T[i].parent = NIL;

    for(i = 0;i < n;i++)
    {
        scanf("%d %d %d",&v,&l,&r);
        T[v].left = l;
        T[v].right = r;
        if(l != NIL) T[l].parent = v;
        if(r != NIL) T[r].parent = v;
    }

    for(i=0;i<n;i++) if(T[i].parent == NIL) root = i;

    setDepth(root,0);
    setHeight(root);

    for(i=0;i<n;i++)print(i);

    return 0;

}


Measured memory_bytes: 2768
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#define INF 100005
using namespace std;

int sy[INF];
int ru[INF]{};
int main() {
	int a, b;
	scanf("%d%d", &a, &b);
	for (int c = 0; c < a - 1; c++)scanf("%d", &sy[c]);
	int ge = 0;
	for (int e = 0; e < b; e++) {
		int f;
		scanf("%d", &f);
		ru[min(ge, ge + f)]++;
		ru[max(ge, ge + f)]--;
		ge += f;
	}
	int s = 0;
	int k = 0;
	for (int x = 0; x < a - 1; x++) {
		k += ru[x];
		s += k*sy[x];
		s %= 100000;
	}
	printf("%d\n", s);
}

Measured memory_bytes: 3960
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <sstream>
#include <cstdlib>
#include <cmath>
 
using namespace std;

int main(){
    int n;
    int res;
    while(cin >> n){
        res = 0;
        for(int a = 0; a < 10; a++){
            for(int b = 0; b < 10; b++){
                for(int c = 0; c < 10; c++){
                    for(int d = 0; d < 10; d++){
                        if(n - a - b - c - d == 0) res++;
                    }
                }
            }
        }
        cout << res << endl;
    }
    return 0;
}

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

int main ()
{
    int n, k, a[3];
    string s;
    cin >> n >> s;
    int sum = 0;
    for (int i = 0; i < 1000; i ++)
    {
        a[0] = i / 100, a[1] = i / 10 - a[0]*10, a[2] = i %10;
        k = 0;
        for (int j = 0; j < s.length(); j ++)
        {
            if(k > 2) break;
            if(s[j] -'0' == a[k])
                k ++;
        }
        if(k == 3)
            sum ++;
    }
    cout << sum << endl;
    return 0;
}

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

#define INF (2e9)
#define FOR(i, a, b) for (ll (i) = (a); (i) < (b); ++(i))
#define REP(i, n) FOR(i, 0, n)

using namespace std;

template<class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

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

#define ALL(x) (x).begin(), (x).end()
template<class T>
using vc = vector<T>;
using vi = vc<ll>;
using vvi = vc<vi>;

template<class T>
using va = valarray<T>;
using vad = va<ld>;
using vai = va<ll>;
using vvai = va<vai>;

using pii = pair<ll, ll>;

vi Read(ll n) {
    auto      v = vi(n);
    for (auto i = std::size_t(0); i < n; ++i) {
        cin >> v[i];
    }
    return v;
}

template<class T>
void DumpRow(const T& A) {
    for (const auto& value : A)
        cout << value << "\n";
}

template<class T>
void DumpColumn(const T& A) {
    auto isFirst = true;
    for (const auto& value : A) {
        if (isFirst) {
            cout << value;
            isFirst = false;
        } else {
            cout << " " << value;
        }

    }
    cout << endl;
}

int Count(int h, int w, int i, int j, const vvai& a){
    auto count = 0;
    REP(m,h) REP(n, w){
            count += min(abs(m - i), abs(n - j)) * a[m][n];
    }
    return count;
}

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

    int h, w;
    cin >> h >> w;
    auto a = vvai(vai(w), h);
    REP(i, h) REP(j, w) cin >> a[i][j];

    int ans = INF;
    REP(i,h) REP(j, w){
        chmin(ans, Count(h, w, i, j, a));
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3208
N = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
a = int(input())

print(N[a-1])

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

using namespace std;

long long A, B;
char op;

int main() {
  cin >> A >> op >> B;
  if (op == '+') {
    cout << A + B << endl;
  }
  if (op == '-') {
    cout << A - B << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int MOD = 1000000007;
const int INF = 1e9;

const int mod = 1000000007;
const int inf = 1e9;
#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    vector<int> l(n), r(n);
    for(int i = 0; i < n; i++) {
        if(i == 0) {
            l[i] = a[0];
        }else{
            l[i] = __gcd(a[i], l[i-1]);
        }
    }
    for(int i = n-1; i >= 0; i--) {
        if(i == n-1){
            r[i] = a[i];
        }else{
            r[i] = __gcd(r[i+1], a[i]);
        }
    }
    int g = a[0];
    for(int i = 1; i < n; i++) {
        g = __gcd(g, a[i]);
    }
    for(int i = 0; i < n-2; i++) {
        chmax(g, __gcd(l[i], r[i+2]));
    }
    chmax(g, r[1]);
    chmax(g, l[n-2]);
    cout << g << endl;
}

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


int main() {
    string s,alphabet = "abcdefghijklmnopqrstuvwxyz";
    cin >> s;
    vector<int> a(alphabet.size());
    rep(i,s.size()){
        rep(j,alphabet.size()){
            if(s[i] == alphabet[j])a[j] = 1;
        }
    }
    rep(i,alphabet.size()){
        if(a[i] == 0){
            cout << alphabet[i] << endl;
            exit(0);
        }
    }
    cout << "None" << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main()
  {int N, K; cin >> N >> K;
  vector<int> Hs(N); for (int &H: Hs) cin >> H;
  sort(Hs.begin(), Hs.end());
  int n = N - min(N, K);
  long long s = 0;
  for (int i = 0; i < n; ++i) s += Hs[i];
  cout << s << endl;}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s1 = sc.next();
		String s2 = sc.next();
		String s3 = sc.next();
		
		String S1 = s1.substring(0, 1).toUpperCase();
		String S2 = s2.substring(0, 1).toUpperCase();
		String S3 = s3.substring(0, 1).toUpperCase();
		
		System.out.println(S1 + S2 + S3);
		
	}
}


Measured memory_bytes: 25300
N = int(input())
A = input().split()
A = [int(x) for x in A]
c = abs(A[0]-A[1])
for i in range(N):
  a = A[i]
  for j in range(i+1,N):
    b = A[j]
    c = max(c,abs(a-b))
print(c)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <numeric>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10
#define MAX_N 20000
#define MAX_M 16

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int m, n;
bool f[1001];

string changes(int i){
	stringstream ss;
	string res;
	ss << i;
	ss >> res;
	return res;
}

int main(){
	while (cin >> m >> n&&m + n){
		REP(i, 1001)f[i] = 1;
		int now = 1, co = m;
		FOR(i, 1, n + 1){
			string t;
			cin >> t;
			while (!f[now]){
				now++;
				if (now > m)now = 1;
			}
			if (co == 1)continue;
			if (i % 15 == 0){
				if (t != "FizzBuzz"){
					f[now] = 0;
					co--;
				}
			}
			else if (i % 5 == 0){
				if (t != "Buzz"){
					f[now] = 0;
					co--;
				}
			}
			else if (i % 3 == 0){
				if (t != "Fizz"){
					f[now] = 0;
					co--;
				}
			}
			else{
				string s = changes(i);
				if (s != t){
					f[now] = 0;
					co--;
				}
			}
			now++;
			if (now > m)now = 1;
		}
		bool ff = 0;
		FOR(i, 1, m + 1){
			if (f[i]){
				if (!ff) {
					cout << i;
					ff = 1;
				}
				else{
					cout << " " << i;
				}
			}
		}
		cout << endl;
	}
}

Measured memory_bytes: 1232
//47
#include<iostream>

using namespace std;

int main(){
  for(int n;cin>>n,n;){
    int rest=1000-n;
    int coin[]={500,100,50,10,5,1};
    int ans=0;
    for(int i=0;i<6;i++){
      ans+=rest/coin[i];
      rest%=coin[i];
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {
	public static final int MAX = 200000;
	public static boolean[] isPrime = new boolean[MAX + 1];
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		eratos();
		
		int n = sc.nextInt();
		while (n != 0) {
			int sum = 0, count = 0;
			for (int i = 2; ; i++) {
				if (count == n) break;
				if (isPrime[i] == true) {
					sum += i;
					count++;
				}
			}
			System.out.println(sum);
			n = sc.nextInt();
		}
	}
	
	public static void eratos() {
		for (int i = 0; i < MAX + 1; i++) {
			isPrime[i] = true;
		}
		
		isPrime[0] = isPrime[1] = false;
		for (int i = 2; i <= Math.sqrt(MAX); i++) {
			if (isPrime[i] == true) {
				for (int j = i + i; j <= MAX; j += i) {
					isPrime[j] = false;
				}
			}
		}
	}
}

Measured memory_bytes: 27092
def binarySearch(array, key):
    left = 0
    right = len(array)
    while left < right:
        mid = int((left + right) / 2)
        if key == array[mid]:
            return True
        elif key > array[mid]:
            left = mid + 1
        elif key < array[mid]:
            right = mid
        else:
            print("ERROR")
    return False
 
 
n = int(input())
s = [int(x) for x in input().split()]
q = int(input())
t = [int(x) for x in input().split()]
a = [x for x in t if binarySearch(s, x)]
print(len(a))


Measured memory_bytes: 16896
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int A,B;
  cin >> A >> B;
  if(A>B*2) cout << A-2*B << endl;
  else cout << 0 << endl;
  return 0;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
A = sorted(list(map(int,input().split())))
ans_sum = 0

def cmb(n, r, mod):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % mod

mod = 10**9+ 7
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
 
for i in range(2, n+1):
    fact.append((fact[-1] * i) % mod)
    inv.append((-inv[mod % i] * (mod // i)) % mod)
    factinv.append((factinv[-1] * inv[-1]) % mod)



for i in range(n):
    a = A[i]
    mi = i
    ma = n-1-i
    ## +miCk-1*a - maCk-1 
    ans_sum += cmb(mi,k-1,mod)* a
    ans_sum -= cmb(ma,k-1,mod)* a
    ans_sum %= mod
print(ans_sum)

Measured memory_bytes: 25684
#include <cstdio>
#include <iostream>

using namespace std;

int main(void)
{
	int A,B;
	
	cin >> A >> B;
	if(A >=1&&A<=9)
		if(B>=1&&B<=9)
			printf("%d",A*B);
		else 
			printf("%d",-1);
	else 
		printf("%d",-1);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
//FILE *fi = freopen("1.txt", "r", stdin);
//FILE *fo = freopen("1", "w", stdout);
//FILE *fi = freopen("P.inp", "r", stdin);
//FILE *fo = freopen("P.out", "w", stdout);
int n;
int s;
int a[30001];
const long long Mod = 998244353;
long long dp[3001][3001];
int main()
{
    //------------------------------
    // Faster
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //-------------------------------
    cin >> n >> s;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    dp[0][0] = 1;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 0; j <= s; j++)
        {
            dp[i][j] = (2 * dp[i - 1][j]) % Mod;
            if (j >= a[i])
            {
                dp[i][j] += dp[i - 1][j - a[i]];
                dp[i][j] %= Mod;
            }
        }
    }
    cout << dp[n][s];
    return 0;
}

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

int n,d,hed[2010],cnt,k,fa[2010],dep[2010],ans=2e9,book[2010];
struct node
{
	int from,to,next;
}a[100010];
inline void add(int from,int to)
{
	a[++cnt].to=to;
	a[cnt].from=from;
	a[cnt].next=hed[from];
	hed[from]=cnt;
}
inline void dfs(int x)
{
	for(int i=hed[x];i;i=a[i].next)
	{
		int y=a[i].to;
		if(fa[x]==y||book[y])
		continue;
		dep[y]=dep[x]+1;
		fa[y]=x;
		dfs(y);
	}
}
int main()
{
	scanf("%d%d",&n,&k);
	cnt=1;
	for(int i=1;i<=n-1;++i)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		add(x,y);
		add(y,x);
	}
	if(k%2)
	{
		for(int i=2;i<=cnt;i++)
		{
			memset(fa,0,sizeof(fa));
			memset(dep,0,sizeof(dep));
			book[a[i].to]=1;
			dfs(a[i].from);
			int ji=0;
			for(int j=1;j<=n;++j)
			{
				if(dep[j]>k/2)
				++ji;
			}
			memset(fa,0,sizeof(fa));
			memset(dep,0,sizeof(dep));
			book[a[i].from]=1;
			book[a[i].to]=0;
			dfs(a[i].to);
			for(int j=1;j<=n;++j)
			{
				if(dep[j]>k/2)
				++ji;
			}
			book[a[i].from]=0;
			ans=min(ans,ji);
		}
	}
	else
	{
		for(int i=1;i<=n;++i)
		{
			memset(fa,0,sizeof(fa));
			memset(dep,0,sizeof(dep));
			dfs(i);
			int ji=0;
			for(int j=1;j<=n;++j)
			{
				if(dep[j]>k/2)
				++ji;
			}
			ans=min(ans,ji);
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    string s;
    cin>>s;
    ll k=s.size();
    ll c=1,kk=0;
    for(ll i=0;i<k;i++)
    {
        if(s[i]=='R')
        {
            kk=1;
        }
        if(kk){
        if(s[i]=='R'&&s[i+1]=='R')
        {
            c++;
        }
    }
    }
    if(kk)
    cout<<c<<endl;
else
    cout<<0<<endl;
}


Measured memory_bytes: 3624
fun main(args: Array<String>) {
    val (n, y) = readIntList()

    for (i in 0..2000) {
        for (j in 0..2000) {
            val k = (y - 10000 * i - 5000 * j) / 1000
            if (k >= 0 && i + j + k == n) {
                println("$i $j $k")
                return
            }
        }
    }
    println("-1 -1 -1")
}

// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)

Measured memory_bytes: 36408
using System;
using System.Collections.Generic;

namespace ABC109A
{
    class MainClass
    {
        public static void Main(string[] args)
        {

            string[] input1 = Console.ReadLine().Split(' ');
            int A = int.Parse(input1[0]);
            int B = int.Parse(input1[1]);

            if (A * B % 2 == 0)
            {
                Console.WriteLine("No");
            }
            else
            {
                Console.WriteLine("Yes");
            }
        }

    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>

#define INF 999999999
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define MOD(x) (x%(mod))
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

/*---------------------------------------------------*/

void judge_sort(pair<pi,int>score[],int t){
  //sort(score,score+t);reverse(score,score+t);
  rep(j,t)rep(i,t-1){
    //cout<<"DEBUG "<<score[i].first.second<<" "<<score[i+1].first.second<<endl;
    if((score[i].first.first < score[i+1].first.first)||
			(score[i].first.first == score[i+1].first.first && score[i].first.second > score[i+1].first.second)||
                        (score[i].first.first == score[i+1].first.first && score[i].first.second == score[i+1].first.second&&score[i].second > score[i+1].second)){
                               swap(score[i].first.first,score[i+1].first.first);
                               swap(score[i].first.second,score[i+1].first.second);
                               swap(score[i].second,score[i+1].second);
    }
  }
}

int main(){
  pair<pi,int>score[55];
  int wa[55][12];
  string s;
  int t,p,r,tID,pID,time;
  
  while(cin>>t>>p>>r){
    if(t==0&&p==0&&r==0)break;

    rep(i,55){
      score[i].second=i+1;
      score[i].first.first=0;
      score[i].first.second=0;
      rep(j,12){
	wa[i][j]=0;
      }
    }
    
    rep(i,r){
      cin>>tID>>pID>>time>>s;
      
      if(s=="CORRECT"&&wa[tID-1][pID]!=-1){
	score[tID-1].first.first+=1;
	score[tID-1].first.second+=(time+wa[tID-1][pID]*1200);
	wa[tID-1][pID]=-1;
      }else if(s=="WRONG"){
	wa[tID-1][pID]++;
      }
      
    }
    judge_sort(score,t);
    
    rep(i,t)cout<<score[i].second<<" "<<score[i].first.first<<" "<<score[i].first.second<<endl;
    //cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 3152
/*
   🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊
   🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊
   🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊
   🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊
   🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊
   🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊
   🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊
   🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊
   🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊
   🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊
*/

#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <iomanip>

using namespace std;

typedef long long ll;

mt19937 rnd(228);

int main()
{
#ifdef ONPC
    freopen("a.in", "r", stdin);
#endif
    int n, m;
    cin >> n >> m;
    ll ans = 1900 * m + 100 * (n - m);
    cout << ans * (1ll << m) << '\n';
}


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

int main() {
  int count = 0;
  string S, T;

  cin >> S >> T;

  for (int i = 0; i < 3; i++) {
    if(S[i] == T[i]) {
      count++;
    }
  }

  cout << count;

  return 0;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> b(n);
  for(int i=0;i<n;i++)
    cin>>b.at(i);
  vector<int> a;
  for(int s=n;s>0;s--){
    int p=s;
    for(int i=0;i<s;i++)
      p=(b.at(i)==i+1?i:p);
    if(p==s){
      cout<<-1<<endl;
      return 0;
    }
    a.push_back(p+1);
    for(int i=p;i+1<s;i++)
      b.at(i)=b.at(i+1);
  }
  for(int i=n-1;i>=0;i--)
    cout<<a.at(i)<<endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for (int i=a; i<b; ++i)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll N; cin >> N;
    string s;
    cin >> s;
    string t=s;
    int changes=0;
    sort(t.begin(), t.end());
    for (int i=0; i<N; ++i)
    {
        if (s[i]!=t[i])
        {
            changes++;
        }
    }
    cout << changes/2 + (changes%2) << "\n";
    return 0;
}

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


int main() {
  int h,w;
 std::cin >> h >> w;
 while(h!=0){
   int i,j;
   for(i=0;i<h;i++){
     for(j=0;j<w;j++){
 std::cout << "#";
     }
     std::cout << std::endl;
   }
   std::cout << std::endl;
   std::cin >> h >> w;
 }
  return 0;
}



Measured memory_bytes: 3084
#include<iostream>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<string>
#include<deque>
#include<stack>
#include<map>
#include<random>
#include<queue>
#include<iterator>
#include<bitset>
#include<unordered_set>
#include<set>

using namespace std;
#define ll long long
#define endl "\n"
const int dx[] = { -1 , -1 , -1 , 0 , 0 , 0 , 1 , 1 , 1 };
const int dy[] = { -1 , 0 , 1 , -1 , 0 , 1 , -1 , 0 , 1 };
const ll integer = pow(2, 32) - 1; // 4294967295
#define N 8010000
#define TC int t;cin>>t;for(int T=1;T<=t;T++)
#define mod 1000000007
#define PI acos(-1)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
void AIA() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
bool isprime(ll n) {
	for (ll i = 2; i * i <= n; i++) {
		if (n % i == 0)return 0;
	}
	return 1;
}
ll prim(ll n) {
	for (int i = 2; i * i <= n; i++) {
		if (i % n == 0) {
			return i;
		}
	}
}
//cout<<fixed<<setprecision(20);
// freopen("stand.in","r",stdin);
// freopen("stand.out","w",stdout);

/*
 _____________              __                ___        ___       ___________________________     ____        ____
|             |            /\ \              |   |      |   |     |                           |    \   \      /   /
|   __________|           / /\ \             |   |      |   |     |      _____      _____     |     \   \    /   /
|  |                     / /  \ \            |   |      |   |     |     |     |    |     |    |      \   \  /   /
|  |                    / /    \ \           |   |      |   |     |     |     |    |     |    |       \   \/   /
|  |______             / /      \ \          |   |______|   |     |     |     |    |     |    |        \      /
|         |           / /        \ \         |              |     |     |     |    |     |    |         \    /
|   ______|          / /          \ \        |    ______    |     |     |     |    |     |    |          |  |
|  |                / /============\ \       |   |      |   |     |     |     |    |     |    |          |  |
|  |               / /==============\ \      |   |      |   |     |     |     |    |     |    |          |  |
|  |              / /                \ \     |   |      |   |     |     |     |    |     |    |          |  |
|  |             / /                  \ \    |   |      |   |     |     |     |    |     |    |          |  |
|__|            /_/                    \_\   |___|      |___|     |_____|     |____|     |____|          |__|

										  <<<<<<<<<<< NEVER GIVE UP !! >>>>>>>>>>>
										<<<<<<<< YOU CAN DO IT IF YOU WANT !! >>>>>>>>
										 <<<<<<<<< BELIEVE IN YOURSELF !! >>>>>>>>>

*/

int  main() {
	//cout << fixed << setprecision(9);
	//freopen("stand.in","r",stdin);
	//freopen("stand.out","w",stdout);

	AIA();

	string s;
	cin >> s;
	int n = s.size();
	for (int i = 0; i < n; i++) {
		if (s[i] == '?') {
			s[i] = 'D';
		}
	}
	cout << s;
	return 0;
}


Measured memory_bytes: 3764
def cut_count(N, S):
    counter = [0]
    for i in range(1, N):
        x = list(set(S[:i]))
        y = ''.join(list(set(S[i:])))
        c = [y.count(x[j]) for j in range(len(x))]
        if sum(c) != 0:
            counter.append(sum(c))
        else:
            pass
    return max(counter)

def main():
    N = int(input())
    S = list(input())
    print(cut_count(N, S))

if __name__ == "__main__":
    main()

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



int main()
{
    int n,x;
    int arr[110];
    cin >> n >> x;
    for(int i=1; i<=n; i++) cin >> arr[i];
    sort(arr+1,arr+n+1);
    int ans=0;
    for(int i=1; i<n; i++)
    {
        if(arr[i]<=x) ans++;
        x=max(0,x-arr[i]);
    }
    if(x==arr[n]) ans++;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {

  int i,j,k;
  int N=0;
  char A[4];
  scanf("%s", A);

  for(i=0;i<4;i++){
    if(A[i]=='-')N--;
    if(A[i]=='+')N++;
    
  }
  printf("%d", N);
  return 0;
}

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

int main(void) {
  int a, b;
  cin >> a >> b;
  if (a % 2 == 1 and b % 2 == 1) {
    cout << "Odd" << endl;
  }
  else {
    cout << "Even" << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
  long x, k, d;
  scanf("%ld %ld %ld", &x, &k, &d);
  
  if (x < 0) {
    x *= -1;
  }
  
  double maxMoveDistance = (double)k * (double)d;
  if (x > maxMoveDistance) {
    // 原点に到達できないとき
    printf("%.0lf\n", (double)x - maxMoveDistance);
    return 0;
  }
  
  if (x % d == 0) {
    // 原点に移動することがあるとき
    long moveCount = x / d;
    long remainingMoveCount = k - moveCount;
    if (remainingMoveCount % 2 == 0) {
      // 原点にはじめて移動した後の残移動回数が偶数なら原点
      printf("0\n");
      return 0;
    } else {
      // 奇数なら原点から一度移動した座標
      printf("%ld\n", d);
      return 0;
    }
  }
  
  // 原点を跨ぐことができるがちょうど止まることがないとき
  long moveCount = floor(x / d); // 原点を跨ぐ一つ手前の移動回数
  long remainingMoveCount = k - moveCount;
  if (remainingMoveCount % 2 != 0) {
    // 残移動回数が奇数なら、そこからもう一回原点方向に移動する(原点を跨ぐ)
    moveCount++;
  }
  x -= d * moveCount;
  
  printf("%ld\n", labs(x));
  
  return 0;
}

Measured memory_bytes: 1700
s = int(input().strip())
A = [s]
for i in range(1000000):
  if A[i] % 2 == 0:
    f = int(A[i]/2)
  else:
    f = 3*A[i]+1
  if f in A:
    print(i+2)
    break
  A.append(f)
  

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

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

// Lib
//

int main(){
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    int N; cin >> N;

    // place[i]...値iのaにおけるindex
    ll place[N + 1];
    for (int i = 1; i <= N; ++i) {
        ll a; cin >> a;
        place[a] = i;
    }

    ll ans = 0;
    set<ll> used = {0, N + 1};

    for (int i = 1; i <= N; ++i) {
        ll r, l;

        auto itr = used.lower_bound(place[i]);
        r = *itr;
        l = *(--itr);
        ans += i * (place[i] - l) * (r - place[i]);
        used.insert(place[i]);
    }

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


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

const int MAX_V = 50;
const int INF = 1e9;

struct edge {int to, index;};

vector<vector<int>> d(MAX_V,vector<int>(MAX_V,INF));
int n;

void warshall_floyd(){
  rep(k,n){
    rep(i,n){
      rep(j,n) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    }
  }
}

int main(){
  cin >> n;
  vector<edge> g[n];
  rep(i,n-1) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    d[a][b] = 1; d[b][a] = 1;
    g[a].push_back(edge{b,i}), g[b].push_back(edge{a,i});
  }
  int m;
  cin >> m;
  int u[m], v[m];
  rep(i,m) {
    cin >> u[i] >> v[i];
    u[i]--; v[i]--;
  } 
  rep(i,n) d[i][i] = 0;
  warshall_floyd();
  vector<vector<vector<int>>> e(n,vector<vector<int>>(n,vector<int>()));
  rep(i,n) {
    rep(j,n) {
      int p = i;
      while(d[p][j] > 0) {
        for(auto k : g[p]) {
          if(d[p][j] == d[k.to][j] + 1) {
            e[i][j].push_back(k.index);
            p = k.to;
            break;
          }
        }
      }
    }
  }
  ll ans = 0;
  rep(i,1<<m) {
    vector<bool> f(n-1,false);
    int b = 0;
    rep(j,m) {
      if(i & (1<<j)) {
        b++;
        for(auto k : e[u[j]][v[j]]) {
          f[k] = true;
        }
      }
    }
    int c = 0;
    rep(j,n-1) {
      if(f[j]) c++;
    }
    if(b % 2) ans -= (ll)1<<(n-1-c);
    else ans += (ll)1<<(n-1-c);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int a = scan.nextInt();
		int b = scan.nextInt();
		scan.close();
		System.out.println((n*a>b)? b:n*a);
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define mod 1000000007
#define pb emplace_back
#define MP make_pair
#define dbg(x) cout << #x << ": " << x << endl
#define check(k, i, j) ((k>=i) && (k<=j))
#define ff first
#define ss second
#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
typedef long long ll;
using namespace std;
int dx[]={1,1,0,-1,-1,-1, 0, 1}; 
int dy[]={0,1,1, 1, 0,-1,-1,-1};

template<typename T>
void printV(vector<T> v){
    for(int i=0; i<v.size(); i++){
        cout << v[i] << " ";
    }
    cout << endl;
}

// ===================================== //

int main(){


    FAST_IO;
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans = max(a*c, max(a*d, max(b*c, b*d)));
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3648
t[100],h[100];
main(i,s,N,T,L){
scanf("%d%d%d%d",&N,&T,&L,&L);
for(i=0;i<N;i++)scanf("%d%d",t+i,h+i);
for(i=s=0;;i=(i+1)%N){
	if(t[i]){
		t[i]--;
		if(++T>L)break;
		if(++s==9)s=0;
	}else if(h[i]){
		h[i]--;
		s++;
		if(T<s)break;
		t[i]=s;
		T-=s;
		s=0;
	}else break;
}
printf("%d\n",i+1);exit(0);}

Measured memory_bytes: 600
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, n; cin >> h >> n;
  vector<int>a(n);
  for(int i; i<n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  int t=0;
  for(int i; i<n; i++) t += a[i];
  if(t >= h)cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

using namespace std;

int main(void)
{
  string s,t;
  cin >> s >> t;

  int ans = 0;

  for(int i = 0;i < 3;i++){
    if(s[i] == t[i]) ans++;
  }

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


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

int n, t = 0, d[110] = {}, f[110];
bool a[110][110] = {};

void dfs(int u){
  d[u] = ++t;
  
  for(int i = 1;i <= n;i++) if(a[u][i] && d[i] == 0) dfs(i);
  
  f[u] = ++t;
}

int main(){
  
  int u, k, v;
  
  cin >> n;
  for(int i = 0;i < n;i++){
    cin >> u >> k;
    for(int j = 0;j < k;j++){
      cin >> v;
      a[u][v] = true;
    }
  }
  
  for(int i = 1;i <= n;i++){
    for(int j = 1;j <= n;j++){
      if(a[i][j] && d[i] == 0) dfs(i);
    }
  }
  
  for(int i = 1;i <= n;i++) cout << i << " " << d[i] << " " << f[i] << endl;
  
  return 0;
}



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

int dis(int a, int b){
    if(a > b) return a - b;
    else return b - a;
}

int main(){

    int nt = 0, nx = 0, ny = 0;
    int N; cin >> N;

    bool flag = true;
    for(int i = 0; i < N; i++){
        int t, x, y; cin >> t >> x >> y;
        int d = dis(nx, x) + dis(ny, y);
        //cout << d << endl;
        if(d > t - nt || (t - nt - d) % 2 != 0){
            flag = false;
            for(int j = i + 1; j < N; j++){
                int a, b, c; cin >> a >> b >> c;
            }
            //cout << i << endl;
            break;
        }

        nt = t;
        nx = x;
        ny = y;
    }

    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256