akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

class Node {
    Integer parent, left, right;

    public Node() {
        this.parent = null;
        this.left = null;
        this.right = null;
    }

    String getType() {
        if (this.parent == null) return "root";
        else if (this.left == null) return "leaf";
        else return "internal node";
    }

    public String toString(int id, int depth, List<Integer> children) {
        String childrenStr = children.stream().map(i -> i.toString()).collect(Collectors.joining(", "));
        return "node " + id
                + ": parent = " + (this.parent == null ? -1 : this.parent)
                + ", depth = " + depth
                + ", " + getType()
                + ", [" + childrenStr + "]";
    }
}

public class Main {

    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        Node[] nodes = new Node[n];

        // Arrays.fill(nodes, new Node()); じゃだめ
        for (int i = 0; i < n; i++) {
            nodes[i] = new Node();
        }

        for (int i = 0; i < n; i++) {
            int id = sc.nextInt();
            int k = sc.nextInt();
            int l = 0;
            for (int j = 0; j < k; j++) {
                int c = sc.nextInt();
                if (j == 0) {
                    nodes[id].left = c;
                } else {
                    nodes[l].right = c;
                }
                l = c;
                nodes[c].parent = id;
            }
        }

        for (int i = 0; i < n; i++) {
            System.out.println(nodes[i].toString(i, getDepth(0, i, nodes), children2(nodes[i].left, nodes, new ArrayList<>())));
        }

    }

    int getDepth(int depth, int id, Node[] nodes) {
        if (nodes[id].parent == null) return depth;
        else return getDepth(++depth, nodes[id].parent, nodes);
    }

    List<Integer> children(Integer id, Node[] nodes, List<Integer> list) {
        System.out.println("id:" + id);
        if (id == null) {
            return list;
        } else if (nodes[id].right == null) {
            list.add(id);
            return list;
        } else {
            list.add(id);
            return children(nodes[id].right, nodes, list);
        }
    }

    List<Integer> children2(Integer id, Node[] nodes, List<Integer> list) {
        if (id == null) {
            return list;
        }

        list.add(id);

        Integer next = nodes[id].right;

        while (next != null) {
            list.add(next);
            next = nodes[next].right;
        }
        return list;
    }

    public static void main(String[] args) {
        new Main().run();
    }

}


Measured memory_bytes: 170416
n = int(input())
a = list(map(int, input().split()))

colorlist = [0] * 8
freecolor = 0
colormin = 0
for i in a:
    if i >= 3200:
        freecolor += 1
    else:
        colorlist[i // 400] += 1


# print(colorlist)

for i in colorlist:
    if i != 0:
        colormin += 1

# 最小値
if colormin == 0:
    print(1, end=' ')
else:
    print(colormin, end=' ')

# 最大値
s = colormin + freecolor
if s > n:
    s = n
print(s)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#define rep(i, n) rep(int i=0; i<n; i++)
using namespace std;

int main(){
  int S, W;
  cin >> S >> W;

  if(W>=S)
    cout <<"unsafe"<<endl;
  else
    cout<<"safe"<<endl;



  return 0;
}


Measured memory_bytes: 3596
# coding: utf-8
# Your code here!

def checkSuccessionNum(strNum):
    beforChar = strNum[0]
    
    for c in inputNum[1:]:
        if(beforChar == c):
            return True
        else:
            beforChar = c
            
    return False

inputNum = input()

if(checkSuccessionNum(inputNum)):
    print("Bad")
else:
    print("Good")

Measured memory_bytes: 2940
N, M = map(int, input().split())
heights = list(map(int, input().split()))
highest = [True for _ in range(N)]
for m in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    val_a = heights[a]
    val_b = heights[b]
    # print("a= {} b= {}".format(a,b))
    # print("vala= {} valb= {}".format(val_a,val_b))
    if val_a == val_b:
        highest[a] = False
        highest[b] = False
    elif val_a > val_b:
        highest[b] = False
    elif val_a < val_b:
        highest[a] = False
    
print(sum(highest))
 


Measured memory_bytes: 20112
#include <iostream>
#include <set>
#include <cstdio>
#include <string>
#include <cstring>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int n, k, card[10];
int used[10];
set<long long> s;

long long toInt() {
	long long res = 1;
	int a[4];
	REP(i, n) if (used[i] > 0) a[used[i]-1] = card[i];
	REP(i, k) {
		if (a[i] < 10) {
			res = res*10 + a[i];
		} else {
			res = res*10 + a[i]/10;
			res = res*10 + a[i]%10;
		}
	}
	return res;
}

void select(int cnt) {
	if (cnt == k) {
		s.insert(toInt());
		return;
	}
	REP(i, n) {
		if (used[i] == 0) {
			used[i] = cnt + 1;
			select(cnt + 1);
			used[i] = 0;
		}
	}
}

int main() {
	while (true) {
		s.erase(s.begin(), s.end());
		scanf("%d %d", &n, &k);
		if (n == 0 && k == 0) break;
		REP(i, n) scanf("%d", &card[i]);
		select(0);
		cout << s.size() << endl;
	}

	return 0;
}

Measured memory_bytes: 1324
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repA(i,a,b) for(ll i=a;i<=b;i++)
#define repD(i,b,a) for(int i=b;i>=a;i--)
#define fill(a) memset(a,0,sizeof(a))
#define f first
#define s second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int main()
{
    int n;
    cin>>n;
    int h[n];
    rep(i,0,n)
    cin>>h[i];
    int dp[n];
    dp[0]=0;
    dp[1]=abs(h[0]-h[1]);
    rep(i,2,n)
    dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    cout<<dp[n-1]<<endl;
}

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

int main(){
    int n;
    cin >> n;
    for(int i = 0;i < n;i++){
        int x,y,z;
        cin >> x >> y;
        z = x % y;
        if(z == 0){
            cout << y << endl;
            continue;
        }
        cout << z << endl;
    }
    return 0;
}


Measured memory_bytes: 3092
var input = require('fs').readFileSync('/dev/stdin', 'utf8').trim();
var lines = input.split('\n');

var n = +lines.shift();

var g = [[]];
for (var i = 1; i <= n; i++) {
    g.push([]);
    for (var j = 1; j <= n; j++) {
        g[i][j] = 0;
    }
}

for (var i = 1; i <= n; i++) {
    var u = lines.shift().split(' ').map(function(n){return +n;});
    var id = u[0];
    var k = u[1];

    for (var j = 0; j < k; j++) {
        g[i][u[2 + j]] = 1;
    }
}

var d = [];
for (var i = 0; i <= n; i++) {
    d[i] = -1;
}
var Q = [1];
d[1] = 0;
var u;
while (u = Q.shift()) {
    for (var i = 1; i <= n; i++) {
        if (!g[u][i]) continue;

        var v = i;
        if (d[v] == -1) {
            d[v] = d[u] + 1;
            Q.push(v);
        }
    }
}

for (var id = 1; id <= n; id++) {
    console.log(id, d[id]);
}

Measured memory_bytes: 9704
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

int N;
vector<int> A;

int ans;

int main()
{
	cin >> N;
	A = vector<int>(N);
	for (int i = 0; i < N; i++){
		cin >> A[i];
	}
	sort(A.begin(), A.end());
	
	ans = 0;
	for (int i = 0; i < N; i++){
		if (A[i] == A[i + 1]){
			i++;
		} else {
			ans++;
		}
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 640
N = int(input())
a = list(map(int, input().split()))
max_a = max(a)
if max_a == 0:
    print('Yes')
    exit()

if N % 3 != 0:
    print('No')
    exit()

if a.count(max_a) == 2 * N // 3 and a.count(0) == N // 3:
    print('Yes')
    exit()

set_a = list(set(a))
if len(set_a) == 3 and set_a[0] ^ set_a[1] ^ set_a[2] == 0:
    if a.count(set_a[0]) == a.count(set_a[1]) == a.count(set_a[2]):
        print('Yes')
        exit()

print('No')


Measured memory_bytes: 20528
def dfs(n):
    if n < 6:
        return n
    elif n < 9:
        return 1 + dfs(n - 6)
    
    six_max = 1
    nine_max = 1
    while six_max * 6 <= n:
        six_max *= 6
    
    while nine_max * 9 <= n:
        nine_max *= 9
    
    return min(dfs(n - nine_max), dfs(n - six_max)) + 1

print(dfs(int(input())))


Measured memory_bytes: 3060
from bisect import bisect_left,bisect_right
n=int(input())
l=list(map(int,input().split()))
l.sort()

ans=0
a=[]
for i in range(n-2):
    for j in range(i+1,n-1):
        t=l[i]+l[j]
        cnt=bisect_left(l,t)
        ans+=cnt-j-1
print(ans)
 


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int m[10]={0};
	m[a]=1;
	m[b]=1;
	m[c]=1;
	m[d]=1;
	if (m[1]==1&&m[9]==1&&m[7]==1&&m[4]==1)
	cout<<"YES"<<endl;
	else
	cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <string>
using namespace std;
map <string,int> dic;
int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    string s;int a;
    cin>>s>>a;
    dic[s]+=a;
  }
  for(int size=1;size<=5;size++) for(auto i=dic.begin();i!=dic.end();i++) if((int)i->first.size()==size) cout<<i->first<<" "<<\
i->second<<endl;

  return 0;
}

Measured memory_bytes: 3176
#include<iostream>
int main(){
    int N, K;
    std::cin >> N >> K;
    int snk[N];
    for(auto &s:snk) s = 0;
    for(int i = 0; i < K; i++) {
        int x;
        std::cin >> x;
        for(int j = 0; j < x; j++){
            int y;
            std::cin >> y;
            snk[y-1] = 1;
        }
    }
    int count = 0;
    for(auto s:snk) if(!s) count++;
    std::cout << count << "\n";
}

Measured memory_bytes: 3608
import sys

input = sys.stdin.readline


def main():
    N, M = [int(x) for x in input().split()]
    A = []
    C = []
    for _ in range(M):
        a, b = [int(x) for x in input().split()]
        A.append(a)
        c = [int(x) for x in input().split()]
        tmp = 0
        for cc in c:
            tmp |= 1 << (cc - 1)

        C.append(tmp)

    dp = [float("inf")] * (2 ** N + 1)

    dp[0] = 0

    for i in range(M):
        for k in range(2 ** N + 1):
            next = C[i] | k
            if next >= (2 ** N + 1):
                continue
            dp[next] = min(dp[next], dp[k] + A[i])

    if dp[2 ** N - 1] == float("inf"):
        print(-1)
    else:
        print(dp[2 ** N - 1])


if __name__ == '__main__':
    main()


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

int main(void)
{
    int A, B, M;
    cin >> A >> B >> M;
    vector<int> a(A), b(B);
    
    int amin = 200000;
    for(int i=0; i<A; i++)
    {
        cin >> a[i];
        amin = std::min(amin, a[i]);
    }
    int bmin = 200000;
    for(int i=0; i<B; i++)
    {
        cin >> b[i];
        bmin = std::min(bmin, b[i]);
    }

    int ans = amin+bmin;
    for(int i=0; i<M; i++)
    {
        int p, q, r;
        cin >> p >> q >> r;
        ans = std::min(a[p-1]+b[q-1]-r, ans);
    }

    if(ans<0)
    {
        std::cout << 0 << std::endl;
    } else
    {
        std::cout << ans << std::endl;
    }
    
    
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
//#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#define pb push_back
#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);cout<<fixed<<setprecision(16);
#define ll long long int
#define ld long double
#define el '\n'
#define El '\n'
#define PI (ld)3.141592653589793238462643383279502884197169399375105820974944
#define inf (ll)1000000000
#define mod (ll)1000000007
#define mod1 (ll)998244353
#define fo(i, n) for (long long i = 0; i < n; i++)
#define pll pair<ll, ll>
#define ml map<ll,ll>
#define vpl vector<pll>
#define vvl vector<vector<ll> >
#define vvpl vector< vector<pll> >
#define ff first
#define ss second
#define pqueue priority_queue< ll >
#define pdqueue priority_queue< ll,vl ,greater< ll > >
#define mem(a,b) memset(a,b,sizeof(a));
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define sz(a) (ll)a.size()
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fd(i,a,b) for(ll i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define vl vector<ll>
//#define x ff
//#define y ss
#define pt(a) for(auto it:a)cout<<it<<" ";cout<<endl;
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
using namespace std;

// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << t<<" "; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << v.first << " " << v.second ; }

double gcd(double a, double b) { return a < 0.01 ? b : gcd(fmod(b, a), a); }

long long bpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)

      res = res * a % m;
      a = a * a % m;
      b >>= 1;
  }
  return res;
}


ll kv;
ll t,n,x,y,h,k,z,p,q,w;
string s,s1,s2;
//vvl v;
//vl vis,d;

int main() {
    IOS;
    cin>>n>>k;
    cout<<n/(2*k+1)+(n%(2*k+1)!=0);
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#define REP(i, a, b) for(int i = a; i < b; i++)
#define REP_(i, a, b) for(int i = a; i <= b; i++)
#define sl(n) scanf("%lld", &n);
#define si(n) scanf("%d", &n);
#define RepAll(a) for(auto x: a)
#define cout(ans) cout << ans << endl;
typedef long long ll;
const int maxn = 1e5 + 10;
using namespace std;


ll a[maxn],b[maxn];
bool cmp(int x,int y){return x > y;}
int main()
{
    ll n, h, ans = 0;
    scanf("%lld%lld", &n ,&h);
    for(int i = 0;i < n; i++){scanf("%lld%lld", &a[i], &b[i]);}
         sort(a, a+n, cmp);
         sort(b, b+n, cmp);//把攻击力高的放在前面
         for(int i = 0; i < n; i++){
             if(b[i]>= a[0] && h >= a[0]){
                 h -= b[i];
                 ans++;
                //攻击次数增加
             }
         }
         if(h >= 0){
             ans += h/a[0];
            if(h%a[0] != 0){ans++;}
         }
        return printf("%d", ans)* 0;

}


Measured memory_bytes: 1792
#include<stdio.h>
int main(){
  int n,i;
  scanf("%d",&n);
  int h[n+1];
  for(i=0;i<n;i++)
    scanf("%d",&h[i]);
  h[0]--;
  for(i=1;i<n;i++){
    if(h[i]>h[i-1])
      h[i]--;
    else if(h[i]<h[i-1]){
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define eps (1e-11)
using namespace std;

class Point{
public:
  double x,y;
  Point(double x=0,double y=0):x(x),y(y){}
 
  Point operator+(Point p){return Point(x+p.x,y+p.y);}
  Point operator-(Point p){return Point(x-p.x,y-p.y);}
  Point operator*(double k){return Point(x*k,y*k);}
  Point operator/(double k){return Point(x/k,y/k);}
         
  double norm(){ return (x*x+y*y); }
};

typedef Point Vector;
typedef vector<Point> Polygon;

class Segment{
public:
  Point p1,p2;
  Segment(Point p1,Point p2):p1(p1),p2(p2){}
};
typedef Segment Line;

double norm(Vector a){return (a.x*a.x+a.y*a.y); }
double abs(Vector a){ return sqrt(norm(a)); }
double dot(Vector a,Vector b){ return (a.x*b.x+a.y*b.y); }
double cross(Vector a,Vector b){ return (a.x*b.y-a.y*b.x); }

int ccw(Point p0,Point p1,Point p2){
  Vector a=p1-p0;
  Vector b=p2-p0;
  if(cross(a,b)>eps)return 1;
  if(cross(a,b)<-eps)return -1;
  if(dot(a,b)<-eps)return 2;
  if(a.norm()<b.norm())return -2;
  return 0;
}

Point getCrossPointLL(Line a,Line b){
  double A=cross(a.p2-a.p1,b.p2-b.p1);
  double B=cross(a.p2-a.p1,a.p2-b.p1);
  if(abs(A)<eps || abs(B)<eps)return b.p1;
  return b.p1+(b.p2-b.p1)*(B/A);
}

double getPolygonArea(Polygon p){
  double res=0.0;
  int n=p.size();
  for(int i=0;i<n;i++)res+=cross(p[i],p[(i+1)%n]);
  return res/2.0;
}

Polygon convex_cut(Polygon p,Line l){
  Polygon ans;
  int n=p.size();
  for(int i=0;i<n;i++){
    Point A=p[i],B=p[(i+1)%n];
    if(ccw(l.p1,l.p2,A)!=-1)ans.push_back(A);
    if(ccw(l.p1,l.p2,A)*ccw(l.p1,l.p2,B)<0)
      ans.push_back(getCrossPointLL(l,Segment(A,B)));
  }
  return ans;
}

int main()
{
  int a,b,c,d,e,f,count=1;

  while(1){
    cin>>a>>b>>c>>d>>e>>f;
    if(a+b+c+d+e+f==0)break;
    Point ic(a,b),pc(c,d),acm(e,f);
    Polygon p;
    p.push_back(Point(0,0));
    p.push_back(Point(10000,0));
    p.push_back(Point(10000,10000));
    p.push_back(Point(0,10000));
    double area=getPolygonArea(p);

    Point m1=ic+(pc-ic)/2.0,m2=ic+(acm-ic)/2.0;
    Vector v1,v2;
    v1=ic-m1;
    v2=pc-m1;
    swap(v1.x,v1.y);
    v1.y=(-1)*v1.y;
    swap(v2.x,v2.y);
    v2.y=(-1)*v2.y;
    Segment s1(m1+v2,m1+v1);
    p=convex_cut(p,s1);
    v1=ic-m2;
    v2=acm-m2;
    swap(v1.x,v1.y);
    v1.y=(-1)*v1.y;
    swap(v2.x,v2.y);
    v2.y=(-1)*v2.y;
    s1 = Segment(m2+v2,m2+v1);
    p=convex_cut(p,s1);
    printf("%d %.10f\n",count,getPolygonArea(p)/area);
    count++;
  }

  return 0;
}

Measured memory_bytes: 1224
def f(a):
	q=a[:n];s=sum(q);heapify(q);yield s
	for e in a[n:2*n]:s+=e-heappushpop(q,e);yield s
from heapq import*;r=reversed;n,*a=map(int,open(0).read().split());print(max(map(sum,zip(f(a),r(list(f([-e for e in r(a)])))))))

Measured memory_bytes: 127704
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0; i<n; ++i)
#define rep1(i,n) for(ll i=1; i<=n; ++i)
#define revrep(i,n) for(ll i=n-1; n>=0; --i)
inline constexpr ll Inf = (1ULL << 62) -1;

template <ll Mod>
class modint {
    public:
    ll n=0;
    modint(){}
    modint(ll n):n(n){ clamp(); }
    modint& operator = (modint const& a) = default;
    modint& operator = (int a) { n = a; clamp(); return *this; }
    modint operator - () { modint t = *this; t.n = -t.n; t.clamp(); return t; }
    modint& operator *= (modint const& a) { n *= a.n; clamp(); return *this; }
    modint& operator *= (ll const& a) { n *= a; clamp(); return *this; }
    modint& operator += (modint const& a) { n += a.n; clamp(); return *this; }
    modint& operator %= (modint const& a) { n %= a.n; clamp(); return *this; }
    friend modint operator * (modint a, modint b) { modint t(a); t.n *= b.n; t.clamp(); return t; }
    friend modint operator + (modint a, modint b) { modint t(a); t.n += b.n; t.clamp(); return t; }
    friend modint operator - (modint a, modint b) { modint t(a); t.n -= b.n; t.clamp(); return t; }
    friend ostream& operator << (ostream& os, modint const& a) { os << a.n; return os; }
    friend bool operator == (modint const& a, int b) { return a.n == b; }
    void clamp() { n %= Mod; if (n < 0) n += Mod; }
    modint& inv() { return pow(Mod-2); }
    ll get() { return n; }
    modint& pow(ll p) {
        ll a=1, e=n;
        while (p > 0) {
            if (p&1) { a *= e; a %= Mod; }
            e *= e; e %= Mod; p >>= 1;
        }
        n = a; clamp();
        return *this;
    }
};
const ll Mod = 1e9+7;
using mint = modint<Mod>;

int main() {
    ll ans=0, N;
    cin >> N;
    vector<ll> a(N+1);
    rep1(i,N) cin >> a[i];
    mint x,d;
    rep1(i,N) {
        x += a[i];
        d += a[i]*a[i];
    }
    ans = ((x * x - d) * mint(2).inv()).get();
    cout << ans << endl;
}


Measured memory_bytes: 4796
N = int(input())
S = [input() for _ in range(N)]
M = int(input())
T = [input() for _ in range(M)]

word_set = set(S)
max_revenue = 0
for w in word_set:
  revenue = 0
  for s in S:
    if w == s:
      revenue += 1
  for t in T:
    if w == t:
      revenue -= 1
  if revenue > max_revenue:
    max_revenue = revenue

print(max_revenue)

Measured memory_bytes: 38512
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int n,q;
  cin>>n>>q;
  int a[q+1]={},b[q+1]={};
  for(int i=0;i<q;i++){
      cin>>a[i]>>b[i];
  }

  int ball[n+1]={};
  ball[1]=2;
  ball[2]=1;
  int it=1;

  for(int i=0;i<q;i++){
      if(a[i]==it) it=b[i];
      else if(b[i]==it) it=a[i];

      swap(ball[a[i]],ball[b[i]]);
      if(it>1) ball[it-1]=1;
      if(it<n) ball[it+1]=1;
  }

  int ans=0;
  for(int i=1;i<=n;i++){
      if(ball[i]>0) ans++;
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i ,n) for(int i = 0 ; i < (n) ; i ++ )
#define all(x) (x).begin(),(x).end()
using ll = long long;
using namespace std;
double kitai(double x){
  double ans;
  ans=(x+1)/2;
  return ans;
}

int main() {
  int n,k;
  cin>>n>>k;
  vector<double> p(n);
  rep(i,n) cin>>p.at(i);
  double m=0;
  double sum=0;
  for(int j = 0 ; j < (k) ; j ++ ){
       sum=sum+kitai(p.at(j)) ;
  // cout<<kitai(p[j])<<endl;
  }
    m=sum;
    //rep(i,n-k+1){
        double nsum;    
    for(int i = 1 ; i < (n-k+1) ; i ++ ){
      
      
      
      if(i==1) nsum=sum;
      nsum=nsum-kitai(p[i-1])+kitai(p[k+i-1]);
      m=max(m,nsum);
     // cout<<nsum<<endl;
    }
  
  cout<<fixed<<setprecision(10) ;
  cout<<m<<endl;
}




Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <iostream>
using namespace std;

int main(){
    int n;
    cin >> n;
    int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, j = 0;
    for(int i = 0; i < n; i++){
        int t;
        cin >> t;
        if(1 <= t && t <= 399 && a == 0){
            a = 1;
        }else if(400 <= t && t<= 799 && b == 0){
            b = 1;
        }else if(800 <= t && t <= 1199 && c == 0){
            c = 1;
        }else if(1200 <= t && t <= 1599 && d == 0){
            d = 1;
        }else if(1600 <= t && t <= 1999&& e == 0){
            e = 1;
        }else if(2000 <= t && t <= 2399 && f == 0){
            f = 1;
        }else if(2400 <= t && t <= 2799 && g==0){
            g = 1;
        }else if(2800 <= t && t <= 3199 && h == 0){
            h = 1;
        }else if(t>= 3200){
            j++;
        }
    }
    int sum = a+b+c+d+e+f+g+h;
    if(sum == 0){
        printf("%d %d\n", 1, j);
    }else{
        printf("%d %d\n", sum, sum + j);
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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--)
using namespace std;

long long solve(long long int N, long long int X){
    if(N % X == 0){
        return X * 3 * (N / X - 1);
    }
    long long ans = 0;
    ans += X * 3 * (N / X - 1);
    ans += solve(N % X + X, N % X);
    return ans;
}

int main()
{
    long long int N, X;
    scanf("%lld %lld", &N, &X);
    if(X > N / 2) X = N - X;
    printf("%lld\n", solve(N, X));
}

Measured memory_bytes: 256
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String c = sc.next();
    
    List<String> chars = new ArrayList<String>();
    chars.add("a");
    chars.add("b");
    chars.add("c");
    chars.add("d");
    chars.add("e");
    chars.add("f");
    chars.add("g");
    chars.add("h");
    chars.add("i");
    chars.add("j");
    chars.add("k");
    chars.add("l");
    chars.add("m");
    chars.add("n");
    chars.add("o");
    chars.add("p");
    chars.add("q");
    chars.add("r");
    chars.add("s");
    chars.add("t");
    chars.add("u");
    chars.add("v");
    chars.add("w");
    chars.add("x");
    chars.add("y");
    chars.add("z");
    
    String result = "";
    for (int i = 0; i<chars.size(); i++) {
      String xChar = chars.get(i);
      if (c.equals(xChar)) {
        result = chars.get(i+1);
        break;
      }
    }
    
    System.out.println(result);
  }
}

Measured memory_bytes: 22228
/* monkukui 競技プログラミング用のテンプレート  (ここから) */
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
using ll = long long int;
using lnt = long long int;
using graph = vector<vector<int>>;
using wgraph = vector<vector<pair<int, long long int>>>;
long long int INF = 1001001001001001LL;
int inf = 100100100;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;
long long int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
long long int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
inline void yes(){ cout << "yes" << endl; }
inline void Yes(){ cout << "Yes" << endl; }
inline void YES(){ cout << "YES" << endl; }
inline void no(){ cout << "no" << endl; }
inline void No(){ cout << "No" << endl; }
inline void NO(){ cout << "NO" << endl; }
inline void possible(){ cout << "possible" << endl; }
inline void Possible(){ cout << "Possible" << endl; }
inline void POSSIBLE(){ cout << "POSSIBLE" << endl; }
inline void impossible(){ cout << "impossible" << endl; }
inline void Impossible(){ cout << "Impossible" << endl; }
inline void IMPOSSIBLE(){ cout << "IMPOSSIBLE" << endl; }

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
#define srep(i,s,t) for(int i = s; i < t; i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back

/* monkukui 競技プログラミング用のテンプレート (ここまで)*/

int main(){
  
  int n; cin >> n;
  vector<int> a(n);
  vector<int> ans(n);
  for(int i = 0; i < n; i++) {
    int a; cin >> a;
    a--;
    ans[a] = i + 1;
  }

  for(int i = 0; i < n; i++){
    if(i + 1 == n) cout << ans[i] << endl;
    else cout << ans[i] << " ";
  }


  return 0;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fastio() ios::sync_with_stdio(0),cin.tie(0);
#define REP(i,n) for(int i=0;i<(n);i++)

int main()
{
	fastio();
	string S, T;
	cin >> S >> T;
	int a[26] = { 0, }, b[26] = { 0, };
	REP(i, S.size())a[S[i] - 'a']++;
	REP(i, T.size())b[T[i] - 'a']++;
	bool x = false;
	sort(a, a + 26);
	sort(b, b + 26);
	REP(i,26) x|= (a[i] != b[i]);
	x ? cout << "No" : cout << "Yes";
	return 0;
}

Measured memory_bytes: 916
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    for(int i=a;i<1111111;i+=a){
        if(i%b==c){
            cout<<"YES";
            return 0;
        }
    }
    cout<<"NO";
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int INF = (int)1e9 + 7;

int main() {
    int n;
    while (cin >> n, n) {
        vector<vector<int>> stage_time(n, vector<int>(n + 1));
        for (int i = 0; i < n; i++) {
            for (int j = 0; j <= n; j++) cin >> stage_time[i][j];
        }
        vector<int> dp((1 << n) + 1, INF);
        dp[0] = 0;
        for (int cur = 0; cur < (1 << n); cur++) {
            for (int t = 0; t < n; t++) {
                int next = cur | (1 << t);
                int best = stage_time[t][0];
                for (int s = 0; s < n; s++) if (cur & (1 << s)) {
                    best = min(best, stage_time[t][s + 1]);
                }
                dp[next] = min(dp[next], dp[cur] + best);
            }
        }
        cout << dp[(1 << n) - 1] << endl;
    }
    return 0;
}


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

int main(){
  int a, b;
  cin >> a >> b;

  if(a<b){
    for(int i=0; i<b; i++){
      cout << a;
    }
  }
  else{
    for(int i=0; i<a; i++){
      cout << b;
    }
  }
  
  cout << endl;

  return 0;
}

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

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

int main(){
    /* A
    int n;
    cin >> n;
    bool check = false;
    for(int i=0;i<3;i++){
        if(n%10 == 7)check = true;
        n/=10;
    }
    cout << ((check)? "Yes": "No") << endl;*/

    /* B
    int64_t n;
    cin >> n;
    int64_t ans = 0;
    for(int i=1;i<=n;i++){
        if(i%3!=0&&i%5!=0)ans+=i;
    }
    cout << ans << endl;*/

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

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

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

	int n, k;
	cin >> n >> k;
	unordered_set<int> s;
	
	while (k--) {
		int m;
		cin >> m;
		rep(i, m) {
			int a;
			cin >> a;
			s.insert(a);
		}
	}
	cout << n - s.size() << endl;
}


Measured memory_bytes: 3664
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
 #define int ll
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair
 
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
 
const int mod=1e9+7;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
int mul(int a,int b)
{
	return ((a)*1ll*(b))%mod;
}
 
void add(int &a,int b)
{
	a+=b;
	if(a>=mod)a-=mod;
}
 
int sub(int a,int b){
	a-=b;
	if(a<0){
		a+=mod;
	}
	return a;
}
 
int powz(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1){
			res=mul(res,a);
		}
		b/=2;
		a=mul(a,a);
	}
	return res;
}
 
template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
	input>>x.F>>x.S;
	return input;
}
 
template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
	for(auto& i:x)
		input>>i;
	return input;
}
 
template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
	for(auto& i:x)
		output<<i<<' ';
	return output;
}
 
const int N=1000002;

void solve(){
	int n,m,v,p;
	cin>>n>>m>>v>>p;
	vi a(n);
	cin>>a;
	sort(all(a));
	int l=0,r=n-1;
	int ans=n;
	debug(a);
	while(l<=r){
		int mid=(l+r)/2;
		vi b=a;
		int v2=v;
		b[mid]+=m;
		v2--;
		for(int i=0;i<mid;i++){
			if(v2){
				b[i]+=m;
				v2--;
			}
			if(!v2){
				break;
			}
		}
		vi zz;
		for(int i=n-1;i>mid;i--){
			if(b[i]<=b[mid]){
				zz.pb(i);
				continue;
			}
			if(v2){
				b[i]+=m;
				v2--;
			}
			if(!v2){
				break;
			}
		}
		//~ reverse(all(zz));
		int tot=v2*m;
		vi used;
		for(auto i:zz){
			if(tot>b[mid]-b[i]){
				used.pb(b[mid]-b[i]);
				tot-=b[mid]-b[i];
				b[i]=b[mid];
			}
			else{
				used.pb(tot);
				b[i]+=tot;
				tot=0;
			}
		}
		int ind=0;
		while(tot){
			if(tot>m-used[ind]){
				tot-=m-used[ind];
				b[zz[ind]]+=m-used[ind];
				used[ind]=m;
				ind++;
			}
			else{
				b[zz[ind]]=b[mid]+1;
				tot=0;
				break;
			}		
			
		}
		int vl=b[mid];
		sort(all(b));
		if(b[n-p]<=vl){
			//~ l=mid+1;
			r=mid-1;
			debug(mid,"AC");
			ans=min(ans,mid);
		}
		else{
			debug(mid,"WA");
			l=mid+1;
		}
	}
	debug(ans);
	cout<<(n-ans);
}

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int tc=1;
	//~ cin>>tc;
	for(int _=0;_<tc;_++){
		//~ cout<<"Case #"<<_+1<<": ";
		solve();
		if(_!=tc-1)
		cout<<"\n";
	}
}


Measured memory_bytes: 4480
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
#include <iostream>
#include <deque>
#include <math.h>
#include <cstdio>
#include <iomanip>
typedef  long long ll;
using namespace std;

int main(void) {
	string s, r, s1, s2, r1, r2;
	cin >> s;
	int n = s.length();
	bool flag = true;
	r = s;
	reverse(r.begin(), r.end());
	if (s != r)  flag = false;
	s1 = s.substr(0,(n - 1) / 2);
	r1 = s1;
	reverse(r1.begin(), r1.end());
	s2 = s.substr((n + 1) / 2);
	r2 = s2;
	reverse(r2.begin(), r2.end());
	if (s1 != r1)  flag = false;
	if (s2 != r2)  flag = false;
	
	if (flag) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long int llint;
int main(void){
	
	llint N,ans = 0,roop = 0;
	cin >> N;
	vector<llint> A(N);
	for(llint i=0;i<N;i++){
		cin >> A[i];
	}
	
	sort(A.begin(),A.end());
	
	for(int i=N-1;i>=0;i--){
		
		if(roop%2 == 0){
			ans += A[i];
		}else{
			ans -= A[i];
		}
		roop++;
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
	int a, b;
	cin >> a >> b;
	if (a <= 8 && b <= 8) {
		cout << "Yay!" << endl;
	}
	else {
		cout << ":(" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <tuple>
#include <cassert>
#include <exception>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
#define fprint(NUM,X) cout << fixed << setprecision(NUM) << (X) << endl
#define fprints(NUM,X,Y) cout << fixed << setprecision(NUM) << (X) << " " << (Y) << endl
const ll INF = 1e+9+7;
ll n,m,l;
string s,t;
ll d[200010],dp[550][550];
double w[1000],v[1000];
double box[200010];


#define MAX 100000

vector<int> G[MAX];
int N;
bool visited[MAX];
int prenum[MAX],parent[MAX],lowest[MAX],timer;

void dfs(int current,int prev){
  prenum[current] = lowest[current] = timer;
  timer++;

  visited[current] = true;

  int next;

  for(int i = 0;i < G[current].size();i++){
    next = G[current][i];
    if(!visited[next]){
      parent[next] = current;
      dfs(next,current);
      lowest[current] = min(lowest[current],lowest[next]);
    }else if(next != prev){
      lowest[current] = min(lowest[current],prenum[next]);
    }
  }
}

void art_points(){
  for(int i = 0;i < N;i++)visited[i] = false;
  timer = 1;
  dfs(0,-1);

  set<int> ap;
  int np = 0;
  for(int i = 1;i < N;i++){
    int p = parent[i];
    if(p == 0)np++;
    else if(prenum[p] <= lowest[i])ap.insert(p);
  }
  if(np > 1)ap.insert(0);
  for(set<int>::iterator it = ap.begin();it != ap.end();it++){
    cout << *it << endl;
  }
}

int main(){
  int m;
  cin >> N >> m;
  for(int i = 0;i < m;i++){
    int s,t;
    cin >> s >> t;
    G[s].push_back(t);
    G[t].push_back(s);
  }
  art_points();
  return 0;
}


Measured memory_bytes: 7072
#[allow(unused_macros)]
macro_rules! input {
    ( $($t:ty),* ) => {{
        let mut s = String::new();
        std::io::stdin().read_line(&mut s);
        let mut splits = s.trim().split_whitespace();
        ($( { splits.next().unwrap().parse::<$t>().unwrap() },)*)
    }}
}


use std::fmt::Display;
#[allow(dead_code)]
pub fn print_vec<T: Display>(v: &Vec<T>, prefix: &str, suffix: &str) {
    if v.is_empty() {
        println!("[]");
        return;
    }
    print!("{}", prefix);
    print!("{}", v[0]);
    for i in 1..v.len() {
        print!(" {}", v[i]);
    }
    println!("{}", suffix);
}


#[allow(unused_macros)]
macro_rules! invec {
    ( $ t : ty ) => {{
        let mut s = String::new();
        match std::io::stdin().read_line(&mut s) {
            Ok(0) => Vec::<$t>::new(),
            Ok(n) => s
                .trim()
                .split_whitespace()
                .map(|s| s.parse::<$t>().unwrap())
                .collect::<Vec<$t>>(),
            Err(_) => Vec::<$t>::new(),
        }
    }};
}

#[allow(unused_must_use)]
#[allow(unused_variables)]
fn solve() {
    let (n, ) = input!(usize);
    let a = invec!(usize);
    
    let mut ans = vec![0; n];

    for i in 0..n {
        ans[a[i] - 1] = i + 1;
    }

    print_vec(&ans, "", "");
}

fn main() {
    solve();
}


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

#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T,typename U>bool chmin(T& a,const U& b){return a>b?(a=b,1):0;}
template<typename T,typename U>bool chmax(T& a,const U& b){return a<b?(a=b,1):0;}

void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
	print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
	print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<0,Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	#ifndef _GLIBCXX_DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	constexpr char endl='\n';
	#endif

	for(int n,k;cin>>n>>k&&n|k;){
		vi a(n);
		rep(i,n) cin>>a[i];
		cout<<(n-1+k-2)/(k-1)<<endl;
	}
}


Measured memory_bytes: 640
package main

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

func main() {
	a := getInt()
	s := getString()

	ans := s
	if a < 3200 {
		ans = "red"
	}

	fmt.Println(ans)
}

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

var sc = bufio.NewScanner(os.Stdin)

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

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

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


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

bool unique(vector<char> s) {
    char c = s.at(0);
    for (char x : s) {
        if (x != c) return false;
    }
    return true;
}

int main() {
    string s;
    cin >> s;
    char c = 'v';
    set<char> st;
    rep(i, s.size()) {
        st.insert(s.at(i));
    }
    int ans = 1e9;
    for (auto c : st) {
        int count = 0;
        vector<char> sv(s.size());
        rep(i,s.size()) sv.at(i) = s.at(i);
        while(!unique(sv)) {
            vector<char> next;
            rep(i, sv.size()-1) {
                if (sv.at(i) == c) next.push_back(sv.at(i));
                else next.push_back(sv.at(i+1));
            }
            sv = next;
            count++;
        }
        ans = min(ans, count);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3600
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;

inline char nc(){
  static char buf[100000],*p1=buf,*p2=buf;
  return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline void read(int &x){
  char c=nc(),b=1;
  for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;
  for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;
}

const int N=100005;
const int P=1e9+7;

struct edge{
  int u,v,next;
}G[N<<1]; int head[N],inum=1;
inline void add(int u,int v,int p){
  G[p].u=u; G[p].v=v; G[p].next=head[u]; head[u]=p;
}

int n,a[N];
int deg[N];

namespace Calc{
  const int INV2=(P+1)/2;
  ll fac[N],inv2[N],pow[N],inv[N];
  inline void Pre(int n){
    fac[0]=1; for (int i=1;i<=n;i++) fac[i]=fac[i-1]*i%P;
    inv[1]=1; for (int i=2;i<=n;i++) inv[i]=inv[P%i]*(P-P/i)%P;
    inv[0]=1; for (int i=1;i<=n;i++) (inv[i]*=inv[i-1])%=P;
    inv2[0]=1; for (int i=1;i<=n;i++) inv2[i]=inv2[i-1]*INV2%P;
    pow[0]=1; for (int i=1;i<=n;i++) pow[i]=pow[i-1]*2%P;
  }
  inline ll C(int n,int m){
    return fac[n]*inv[m]%P*inv[n-m]%P;
  }
  inline ll Pow(ll a,int b){
    ll ret=1;
    for (;b;a=a*a%P,b>>=1)
      if (b&1)
	(ret*=a)%=P;
    return ret;
  }
  int cnt[N];
  inline ll Solve(){
    Pre(n);
    ll ans=1;
    for (int i=1;i<=n;i++){
      if (!cnt[i]) continue;
      ll ret=0,tmp;
      for (int a=0;2*a<=cnt[i];a++){
	tmp=C(cnt[i],2*a)*(fac[2*a]*inv2[a]%P)%P*inv[a]%P*Pow(i,a)%P;
	if ((i&1) && (i>1)) (tmp*=pow[cnt[i]-2*a])%=P;
	ret=(ret+tmp)%P;
      }
      (ans*=ret)%=P;
    }
    return ans;
  }
}

int cnt;
int depth[N],fat[N];
int path[N],len,_l[N];
int inp[N];
#define V G[p].v
inline void dfs(int u,int fa){
  cnt++;
  for (int p=head[u];p;p=G[p].next)
    if (p!=(fa^1)){
      if (!depth[V])
	fat[V]=u,depth[V]=depth[u]+1,dfs(V,p);
      else if (depth[V]<=depth[u]){
	int t=u;
	while (t!=V) path[++len]=t,t=fat[t]; path[++len]=t;
      }
    }
}

int maxd;

inline void dfs2(int u,int fa){
  cnt++;
  depth[u]=depth[fa]+1; maxd=max(maxd,depth[u]);
  for (int p=head[u];p;p=G[p].next)
    if (V!=fa && !inp[V])
      dfs2(V,u);
}

int l[N],d[N];

int main(){
  ll Ans=1;
  read(n);
  for (int i=1;i<=n;i++) read(a[i]),deg[a[i]]++,add(i,a[i],++inum),add(a[i],i,++inum);
  for (int i=1;i<=n;i++) if (deg[i]>2) return printf("0\n"),0;
  for (int i=1;i<=n;i++){
    if (depth[i]) continue;
    cnt=len=0; depth[i]=1; dfs(i,0);
    if (len==2 && path[1]==path[2]) len--;
    if (cnt==len || cnt==1){
      Calc::cnt[::cnt]++; continue;
    }
    for (int j=1;j<=len;j++) inp[path[j]]=1;
    for (int j=1;j<=len;j++){
      cnt=maxd=0; dfs2(path[j],0);
      if (cnt>maxd) return printf("0\n"),0;
      _l[j]=maxd;
    }
    if (len>1 && a[path[1]]!=path[2]){
      reverse(path+1,path+len+1);
      reverse(_l+1,_l+len+1);
    }
    ll tmp=1; *l=*d=0;
    for (int j=1;j<=len;j++) if (_l[j]>1) l[++*l]=_l[j]-1,d[++*d]=j;
    l[++*l]=l[1]; d[++*d]=d[1]+len;
    for (int j=2;j<=*l && tmp;j++)
      if (d[j]-d[j-1]>=l[j]){
	if (l[j]<d[j]-d[j-1])
	  (tmp*=2)%=P;
      }else
	tmp=0;
    (Ans*=tmp)%=P;
  }
  (Ans*=Calc::Solve())%=P;
  printf("%lld\n",Ans);
  return 0;
}


Measured memory_bytes: 12032
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <sstream>
#include <set>
#include <map>
#define LLMAX 9223372036854775807

using namespace std;
using ll = long long;

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

	vector<ll> argA(argN);
	for (ll i = 0; i < argN; ++i) {
		cin >> argA.at(i);
	}

	map<int, int> mapA;
	for (ll i = 0; i < argN; ++i) {
		if (mapA.find(argA.at(i)) != mapA.end()) {
			mapA.at(argA.at(i))++;
		}
		else {
			mapA.emplace(argA.at(i), 1);
		}

		if (mapA.find(argA.at(i) - 1) != mapA.end()) {
			mapA.at(argA.at(i) - 1)++;
		}
		else {
			mapA.emplace(argA.at(i) - 1, 1);
		}

		if (mapA.find(argA.at(i) + 1) != mapA.end()) {
			mapA.at(argA.at(i) + 1)++;
		}
		else {
			mapA.emplace(argA.at(i) + 1, 1);
		}
	}

	vector<int> vecA(mapA.size());
	ll counter = 0;
	for (auto itr = mapA.begin(); itr != mapA.end(); ++itr) {
		vecA.at(counter) = itr->second;
		counter++;
	}

	cout << *max_element(vecA.begin(), vecA.end()) << endl;
}

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

using namespace std;
using ll =long long;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//Write From this Line

int main()
{
	string s, t;
	cin >> s >> t;
	rep(i,s.size()){
		if(s[i] != t[i]){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}


Measured memory_bytes: 3576
function main(input) {
  inputs = input.split("\n")
  len = inputs[0]
  str = inputs[1]
  
  let index = 0
  let count = 0
  while (index + 3 <= len) {
    if (str.substr(index, 3) == "ABC") {
      count++
    }
    index++
  }
  console.log(count)
}

main(require('fs').readFileSync('/dev/stdin', 'UTF-8'));


Measured memory_bytes: 7500
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <sstream>
#include <string>
#include <utility>
#include <map>
#include <memory>
#include <set>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>

using namespace std;

const int infty = 2000000000;

class Inversions
{
public:
  void msort( vector<int>& ar, int left, int right, long long& cnt );
  void merge( vector<int>& ar, int left, int mid, int right, long long& cnt );
  int solve();
};

void Inversions::msort( vector<int>& ar, int left, int right, long long& cnt )
{
  if ( left + 1 < right )
    {
      int mid = ( left + right ) / 2;

      msort( ar, left, mid, cnt );
      msort( ar, mid, right, cnt );
      merge( ar, left, mid, right, cnt );
    }
}

void Inversions::merge( vector<int>& ar, int left, int mid, int right, long long& cnt )
{
  int n1 = mid - left;
  int n2 = right - mid;

  vector<int> l( n1 + 1 );
  vector<int> r( n2 + 1 );

  for ( auto i = 0; i < n1; ++i )
    l[i] = ar[left + i];
  
  for ( auto i = 0; i < n2; ++i )
    r[i] = ar[mid + i];

  l[n1] = infty;
  r[n2] = infty;

  int x = 0;
  int y = 0;

  for ( auto i = left; i < right; ++i )
    {
      if ( l[x] <= r[y] )
        ar[i] = l[x++];
      else
        {
          ar[i] = r[y++];
          cnt += n1 - x;
        }
    }
}

int Inversions::solve()
{
  int n;
  cin >> n;

  vector<int> a( n );

  long long cnt = 0;
  
  for ( auto i = 0; i < n; ++i )
    cin >> a[i];

  msort( a, 0, n, cnt );
  
  cout << cnt << endl;
  
  return 0;
}

int main()
{

  Inversions inv;

  inv.solve();

  return 0;
}

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

int main()
{
        int n, m, sum = 0;

        cin >> n >> m;

        int a[n][m], b[m];

        for(int i = 0; i < n; i++) {
                for(int j = 0; j < m; j++) {
                        cin >> a[i][j];
                }
        }

        for(int j = 0; j < m; j++) {
                cin >> b[j];
        }

        for(int i = 0; i < n; i++) {
                for(int j = 0; j < m; j++) {
                        sum += a[i][j]*b[j];
                }
                cout << sum << endl;
                sum = 0;
        }

        return 0;
}


Measured memory_bytes: 3148