akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<cassert>
using namespace std;
int inf = 1000000000;

int main(void) {

  int n;
  while(cin >> n){
    if( n == 0 ) break;
    vector<int> a(n);
    for(int i=0; i<n; i++){
      string s;
      cin >> s;
      a[i] = s.size();
    }

    for(int i=0; i<n; i++){
      int t[5] = {5,7,5,7,7};
      int p = 0;
      int tmp = 0;
      for(int j=i; j<n; j++){
        tmp += a[j];
        if( tmp == t[p] ){
          p++;
          tmp = 0;
        }else if( tmp > t[p] ){
          tmp = 0;
          break;
        }
      }
      if( p == 5 ){
        cout << i + 1 << endl;
        break;
      }
      // cerr << " " << p << endl;
    }

  }

  return 0;
}


// EOF

Measured memory_bytes: 3228
N=int(input())
A=list(map(int,input().split()))
B=[0]*N
for n in range(N,0,-1):
    if A[n-1]==1:
        B[n-1]=1
        for x in range(1,int(n**0.5)+1):
            if n%x==0:
                if x**2==n:
                    A[x-1]=(A[x-1]+1)%2
                else:
                    y=n//x
                    A[x-1]=(A[x-1]+1)%2
                    A[y-1]=(A[y-1]+1)%2
print(sum(B))
for i in range(N):
    if B[i]==1:
        print(i+1,end=" ")

Measured memory_bytes: 64220
from collections import deque
L = int(input())

Lbin = (bin(L)[2:])[::-1]
N = len(Lbin)
M = 0
E = deque()

for i in range(0, N - 1):
    E.append(((i + 1, i + 2), 0))
    E.append(((i + 1, i + 2), 2 ** i))
    M += 2

weight = L
for i in range(0, N - 1):
    if Lbin[i] == '1':  # 2^iの位
        weight -= 2 ** i
        E.append(((i + 1, N), weight))
        M += 1

print(N, M)
for e in E:
    print(e[0][0], e[0][1], e[1])


Measured memory_bytes: 3316
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] h = new int[n];
        for(int i=0;i<n;i++)h[i] = Integer.parseInt(sc.next());
        sc.close();
        int idx1,idx2;
        int min;
        int res = 0;
        while(true){
            idx1 = -1;
            min = 1000000;
            for(int i=0;i<n;i++){
                if(h[i]>0){
                    idx1 = i;
                    min = h[i];
                    break;
                }
            }
            if(idx1==-1)break;
            idx2 = n;
            for(int i=idx1+1;i<n;i++){
                if(h[i]==0){
                    idx2 = i;
                    break;
                }else{
                    min = Math.min(h[i],min);
                }
            }
            for(int i=idx1;i<idx2;i++){
                h[i]-=min;
            }
            res+=min;
        }
        System.out.println(res);
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
const int N = 2e6+10;
const int P = 1e9+7;
#define fr(i,low,up,st) for(register int i = low;i <= up;i += st)
#define nfr(i,low,up,st) for(register int i = low;i >= up;i -= st)
#define size(a) a.size()
#define fill(a,b) memset(a,b,sizeof a)

int fact[N],inv[N];

inline int pow_mod(int x,int k){
   int res = 1,base = x;
   while(k){
      if(k&1)res = 1LL*res*base%P;
      k >>= 1;
      base = 1LL*base*base%P;
   }
   return res;
}

void init(){
   fact[0] = inv[0] = 1;
   fr(i,1,N-1,1)fact[i] = 1LL*fact[i-1]*i%P;
   inv[N-1] = pow_mod(fact[N-1],P-2);
   nfr(i,N-2,1,1)inv[i] = 1LL*inv[i+1]*(i+1)%P;
}

inline int c(int n,int m){
   if(n < m)return 0;
   return 1LL*fact[n]*inv[n-m]%P*inv[m]%P;
}

void Mod(int &x){
   x = (x>=P)?x-P:x;
   x = (x<0)?x+P:x;
}
int n,m;
int calc(int up,int a,int b){
   int pans = 0;
   for(int k = 0;1LL*k*(b+1)+1LL*a*m <= up && k+m <= n; ++k){
      Mod(pans += 1LL*pow_mod(-1,k)*c(up-a*m-k*(b+1)+n,n)*c(n-m,k)%P);
   }
   //cerr << up <<' '<< a << ' ' << b <<' ' << pans << endl;
   return 1LL*pans*c(n,m)%P;
}

int solve(int up){
   int ans = 0;
   fr(i,1,up,1){
      Mod(ans += calc(up,i,i-1)-calc(up,i+1,i-1));
      //cerr << i <<' '<< ans << endl;
   }
   Mod(ans = c(up+n,n)-ans);
   return ans;
}

int main(){
   init();
   int L,R;
   scanf("%d%d%d%d",&n,&m,&L,&R);
   int fans = 0;
   Mod(fans = solve(R)-solve(L-1));
   printf("%d\n",fans);
   return 0;
}


Measured memory_bytes: 15872
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define lf else if

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

const int N=500000+19;

db x[N],y[N],a,b,tmp;
int n,L,frt,top,l,r,res,u,v,pos;

struct Point{
	db x,y;
};
typedef Point Vector;

Vector operator - (Point A,Point B){
	return (Vector){A.x-B.x,A.y-B.y};
}
db cross(Vector A,Vector B){
	return A.x*B.y-A.y*B.x;
}

int main(){
	n=IN(),L=IN();
	frt=1;top=1;
	For(i,1,n+1){
		u=IN(),v=IN();
		pos=L-v;
		while (frt<=top&&x[frt]+a>=pos) frt++;
		if (frt>top){
			printf("%.10lf\n",1.0*u*v/L);
			frt--;
			x[frt]=-a;
			y[frt]=-b;
		} else{
			tmp=y[frt]+b+(y[frt-1]-y[frt])/(x[frt-1]-x[frt])*(pos-(x[frt]+a));
			printf("%.10lf\n",(1.0*u*v+y[frt]+b+(y[frt-1]-y[frt])/(x[frt-1]-x[frt])*(pos-(x[frt]+a)))/L);
			frt--;
			x[frt]=pos-a;
			y[frt]=tmp-b;
		}
		a+=v,b+=1.0*u*v;
		while (top-frt+1>=2&&cross((Vector){x[top]+a,y[top]+b},(Vector){x[top-1]-x[top],y[top-1]-y[top]})>=0) top--;
		top++;
		x[top]=-a;
		y[top]=-b;
	}
}

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

using namespace std;

#define LL long long
#define Re register
#define U unsigned
#define forn(i,a,b) for(Re int i = a;i <= b;++i)
#define nfor(i,a,b) for(Re int i = a;i >= b;--i)
#define CLR(i,a) memset(i,a,sizeof(i))
#define BR printf("--------------------\n")
#define pb push_back
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
const double PI=atan(1.)*4.;
const int maxn=1e6+5;
const int inf = 0x3f3f3f3f;
const int mod=1e9+7;
const double e=2.71828182845904523536;
int dir[4][2]={1,0,0,1,-1,0,0,-1};
int a[300];
int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);
   	cout.tie(0);
    int n,l,ans=0;
    int f,num=10000;
    cin>>n>>l;
    for(int i=1;i<=n;i++)
    {
        a[i]=l+i-1;
        ans+=a[i];
        if(abs(a[i])<abs(num))
        {
            num=a[i];
        }
    }
    cout<<ans-num;
    /*if(l>=0)
    {
        ans=(n-1)*l+(n-1)*n/2;
    }
    else if(l+n-1<=0)
    {
        ans=n*l-n+(n+1)*n/2+l-1;
    }
    else
    {
        ans=n*l+(n+1)*n/2-n-(l+n-1);
    }
    cout<<ans;*/
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define N 4

int main(void) {
    char s[N];
    int i;
    int count_s = 0;
    int count_d = 0;
    int num = 0;

    scanf(" %s", s);
    for (i = 0; i < N; i++) {
        if (s[i] == '+')
            count_s++;
    }
    count_d = N - count_s;
    num = 0 + count_s - count_d;
    printf("%d", num);

    return 0;
}

Measured memory_bytes: 128
// ini template jangan diedit
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>
//macros goblok


#define forian(i,a,n) for(ll i=a;i<=n;i++)
#define pb push_back
#define popb pop_back
#define ll long long
#define Faqih using
#define itu namespace
#define Ganteng_Titik std; 
Faqih itu Ganteng_Titik
//int N; int a=0;
//int arr[110];
const double pi = 3.14159265358979323846;
void test_case()
{
	double a,b,h,m;
	double c;
	cin >> a >> b >> h >> m;
	double dif_angle,sudut_jam,sudut_menit;
	double (sudut_jam = double (h*30)+(double(m/2)));
	double (sudut_menit = double (m*6));
	double (dif_angle = abs(sudut_jam - sudut_menit));
//	printf("%.20f\n", dif_angle);
	// Mencari Sisi Ketiga dari Jarum Jam
	c = sqrt((a*a) +(b*b) - (2*a*b*cos(pi*dif_angle/180)));
	printf("%.20f\n", c);
}

int main() // Main Program for At Coder
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	test_case();
return 0;
}


Measured memory_bytes: 4228
#include <stdio.h>

struct card
{
	char suit;
	int num;
};

int bubbleSort(struct card C[], int num)
{
	struct card temp;
	int cnt = 0;
	for (int i = 0; i < num; i++)
	{
		for (int j = num - 1; j >= i + 1; j--)
		{
			if (C[j].num < C[j - 1].num)
			{
				temp = C[j - 1];
				C[j - 1] = C[j];
				C[j] = temp;
				cnt++;
			}
		}
	}
	return cnt;
}


int insertSort(struct card C[], int num)
{
	struct card temp;
	int cnt = 0, min = 0;
	for (int i = 0; i < num; i++)
	{
		min = i;
		for (int j = i; j < num; j++)
		{
			if (C[j].num < C[min].num)
			{
				min = j;
			}
		}
		if (i != min) cnt++;
		temp = C[i];
		C[i] = C[min];
		C[min] = temp;
	}

	return cnt;
}

int isstable(struct card C1[], struct card C2[], int num)
{
	for (int i = 0; i < num; i++)
	{
		if (C1[i].suit != C2[i].suit) return -1;
	}
	return 1;
}




int main()
{
	struct card C1[100];
	struct card C2[100];
	int num, temp_n,re = 0;
	char temp_c;

	scanf(" %d", &num);

	for (int i = 0; i < num; i++)
	{
		scanf(" %c %d", &temp_c, &temp_n);
		C1[i].suit = temp_c;
		C1[i].num = temp_n;
		C2[i].suit = temp_c;
		C2[i].num = temp_n;
	}

	bubbleSort(C1, num);
	insertSort(C2, num);

	for (int i = 0; i < num; i++)
	{
		printf("%c%d", C1[i].suit, C1[i].num);
		if (i < num - 1) printf(" ");
	}
	printf("\nStable\n");

	for (int i = 0; i < num; i++)
	{
		printf("%c%d", C2[i].suit, C2[i].num);
		if (i < num - 1) printf(" ");
	}

	if ((re = isstable(C1, C2, num)) == -1) printf("\nNot stable\n");
	else printf("\nStable\n");

	return 0;
}




Measured memory_bytes: 2100
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll a, b, c, d, e;

int main(){
	cin >> a >> b >> c >> d >> e;
    ll ans = ((a+9)/10+(b+9)/10+(c+9)/10+(d+9)/10)*10+e;
    ans = min(((a+9)/10+(b+9)/10+(c+9)/10+(e+9)/10)*10+d, ans);
    ans = min(((a+9)/10+(b+9)/10+(e+9)/10+(d+9)/10)*10+c, ans);
    ans = min(((a+9)/10+(e+9)/10+(c+9)/10+(d+9)/10)*10+b, ans);
    ans = min(((e+9)/10+(b+9)/10+(c+9)/10+(d+9)/10)*10+a, ans);
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
const int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, int b, int _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }



void solve();

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

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}


// https://kyopro-friends.hatenablog.com/entry/2019/01/12/231106
vector<vector<ll> > dp(1001, vector<ll>(20001));

void solve() {
  int n;
  cin >> n;
  vector<tuple<int, int, int> > d(n);
  rep(i, n) {
    int w, s, v;
    cin >> w >> s >> v;
    d[i] = make_tuple(w + s, s, v);
  }
  sort(all(d));
  rep(i, n) {
    int w, s, v;
    tie(w, s, v) = d[i];
    w -= s;
    rep(j, s + 1) {
      chmax(dp[i + 1][j + w], dp[i][j] + v);
    }
    rep(j, 20001) chmax(dp[i + 1][j], dp[i][j]);
  }
  ll ma = 0;
  rep(i, n + 1) chmax(ma, *max_element(all(dp[i])));
  cout << ma << endl;
}


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


int main() {
    int k,a,b;
    cin>>k>>a>>b;
    if(a%k==0){
        cout<<"OK"<<endl;return 0;
    }
    if(b%k==0){
        cout<<"OK"<<endl;return 0;
    }
    int ia=a/k;
    int ib=b/k;
    if(ib>ia){
        cout<<"OK"<<endl;
    }
    else{
        cout<<"NG"<<endl;
    }
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,M,X;
    cin>>N>>M>>X;
    int left=0,right=0;
    int a;
    int cost[N+1];
    for(int i=0;i<N+1;i++){
        cost[i]=0;
    }
    for(int i=0;i<M;i++){
        cin>>a;
        cost[a]=1;
    }
    for(int i=0;i<X;i++){
        left+=cost[i];
    }
    for(int i=X+1;i<N+1;i++){
        right+=cost[i];
    }
    cout<<min(left,right)<<endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define it vector<int>::iterator
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
using namespace std;
int main(){
	int n;
	cin>>n;
	vvi cost(n+1,vi(n+1,inf));
	rep(i,n){
		int s,m;
		cin>>s>>m;
		rep(j,m){
			int t;
			cin>>t;
			cost[s][t]=1;
		}
	}
	rep(k,n+1)rep(i,n+1)rep(j,n+1)
		cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j]);
	int m;
	cin>>m;
	rep(i,m){
		int a,b,c;
		cin>>a>>b>>c;
		int t=cost[a][b]+1;
		if(t>c)cout<<"NA"<<endl;
		else cout<<t<<endl;
	}
}

Measured memory_bytes: 1252
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>  // assert(x>=10), 部分点問題
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <set>

#define repl(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(), (x).end()
#define SORT(v,n) sort(v,v+n)
#define VSORT(v) sort(all(x))
#define FILL(v, value) (v+(sizeof(v) / sizeof *(v)), value);
#define inf 999999999
#define dbg(x) cout<<#x<<":"<<x<<endl;
#define pb(a) push_back((a))
#define mp(a) make_pair((a))
#define sz(x) (int)(x).size()
#define pi 2*acos(0.0)
#define in scanf
#define out printf
#define fi first
#define se second
#define bit(n) (1LL<<(n))

using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;

const int MOD=1000000007; // 10^9 + 7
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};  // 右下左上


int main(int argc, char**argv){
  string ss;
  string tt;
  cin >> ss >> tt;

  vi s, t;
  s.pb(0);
  t.pb(0);
  rep(i, sz(ss)) s.pb(ss[i]=='A'?1:2);
  rep(i, sz(tt)) t.pb(tt[i]=='A'?1:2);

  int q;
  cin >> q;

  rep(i, sz(s)) s[i+1] += s[i];
  rep(i, sz(t)) t[i+1] += t[i];

  rep(i, q){
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    int x = s[b] - s[a-1];
    int y = t[d] - t[c-1];

    // dbg(x);
    // dbg(y);

    if (x % 3 == y % 3) cout << "YES" << endl;
    else cout << "NO" << endl;
  }

	return 0;
}


Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

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

int main(){
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    const int MAX = 2010;
    vi dp(MAX);
    dp[0] = 1;
    rep(i, n) {
        for(int j = MAX-a[i]-1; j >= 0; --j) dp[j+a[i]] |= dp[j];
    }
    int q;
    cin >> q;
    rep(i, q) {
        int m;
        cin >> m;
        cout << (dp[m] ? "yes" : "no") << endl;
    }
    return 0;
}


Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int inf=1e9;
ll A[100005];
ll B[100005];
ll rA[100005];
ll rB[100005];
int main(void)
{
    int N;
    ll ans=0;
    ll ans2=0;
    cin>> N;
    for(int i=0;i<N+1;i++)
    {
        cin >> A[i];
        rA[i]=A[i];
    }
    for(int i=0;i<N;i++)
    {
        cin >> B[i];
        rB[i]=B[i];
    }
    for(int i=0;i<N;i++)
    {
        ll left=A[i];
        ll right=A[i+1];
        ans+=min(B[i],left);
        A[i]-=min(B[i],left);
        B[i]-=min(B[i],left);
        ans+=min(B[i],right);
        A[i+1]-=min(B[i],right);
        B[i]-=min(B[i],right);
    }
    for(int i=N-1;i>=0;i--)
    {
        ll left=A[i];
        ll right=A[i+1];
        ans2+=min(B[i],right);
        A[i+1]-=min(B[i],right);
        B[i]-=min(B[i],right);
        ans2+=min(B[i],left);
        A[i]-=min(B[i],left);
        B[i]-=min(B[i],left);
    }
    cout << max(ans,ans2) << endl;
    
    return 0;
}

Measured memory_bytes: 3328
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		String s = scanner.next();

		int max = 0;
		int sum = 0;
		for (int i = 0; i < n; i++) {
			char target = s.charAt(i);
			if (target == 'I') {
				sum++;
			} else {
				sum--;
			}
			max = Math.max(max, sum);
		}

		System.out.println(max);
	}
}

Measured memory_bytes: 21332
#dpでできないかな？
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n,k=MI()
s=SI()
ze=[]
on=[]

if s[0]=="0":
    state="ze"
    sq=1
    on.append(0)
else:
    state="on"
    sq=1
    
for i in range(1,n):
    u=s[i]
    if state=="ze":
        if u=="0":
            sq+=1
        else:
            ze.append(sq)
            sq=1
            state="on"
            
        
    elif state=="on":
        if u=="1":
            sq+=1
        else:
            on.append(sq)
            sq=1
            state="ze"
if state=="on":
    on.append(sq)
elif state=="ze":
    ze.append(sq)
if len(ze)<k:
    print(n)
    sys.exit()
if s[-1]=="0":
    on.append(0)
#print(on)
#print(ze)
u=len(on)

smz=[0 for i in range(u-k)]
smo=[0 for i in range(u-k)]
for i in range(k):
    smz[0]+=ze[i]
for i in range(k+1):
    smo[0]+=on[i]
#print(smo)
#print(smz)
for i in range(u-k-1):
    smz[i+1]=smz[i]-ze[i]+ze[i+k]
for i in range(u-k-1):
    smo[i+1]=smo[i]-on[i]+on[i+k+1]
#print(smo)
#print(smz)
mx=0
for i in range(u-k):
    val=smo[i]+smz[i]
    if val>mx:
        mx=val
print(mx)

Measured memory_bytes: 7552
#include<iostream>
#include<cstdio>
#include<cstring>
#include <fstream>
#include<string>
#include<sstream>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
#include <math.h>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const long long int MOD = 1000000007;
const int INF = 1000000007;
const double EPS = 1e-10;
const double PI = 3.14159265359;
const int N = 100005;
//cout << fixed << std::setprecision(9)
//--------------------------

ll dp[1 << 21];
int bitcnt[1 << 21];
int a[23][23];
int n;


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

	dp[0] = 1;
	for (int s = 1; s < (1 << n); s++) {
		bitcnt[s] = bitcnt[s / 2] + s % 2;
		for (int l = 0; l < n; l++) {
			if ((s >> l) % 2 == 0) continue;
			dp[s] += dp[s - (1 << l)] * a[bitcnt[s] - 1][l];
			dp[s] %= MOD;
		}	
	}

	cout << dp[(1 << n) - 1] << endl;
	return 0;
}


Measured memory_bytes: 24832
#include<stdio.h>
#include<stdlib.h>
#define NIL NULL
   
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
   
typedef struct node * Node;
   
Node root= NIL;
Node treeSu(Node,int);
void insert(int);
void preorder(Node);
void inorder(Node);


void inorder(Node n){
  if(n->left != NIL)
    inorder(n->left);
  printf(" %d", n->key);
  if(n->right != NIL)
    inorder(n->right);
}

void preorder(Node n){
  printf(" %d", n->key);
  if(n->left != NIL)
    preorder(n->left); 
  if(n->right != NIL)
    preorder(n->right);
}
void insert(int n){
  Node y = NIL;
  Node x = root;
  Node z;
  z = malloc(sizeof(struct node));
  z->key = n;
  z->left = NIL;
  z->right = NIL;
   
  while(x != NIL){
    y = x;
    if(z->key < x->key)
      x = x->left; 
    else
      x = x->right;  }
  z->parent = y;
  if(y == NIL)
    root = z;
  else if(z->key < y->key)
    y->left = z;
  else
    y->right = z; 
}
   
Node treeSu(Node u, int k){
  while(u != NIL && k != u->key){
    if(k < u->key)
      u = u->left;
    else
      u = u->right;
  }
  return u;
}

int main(){
  int i;
  int n,m;
  char cha[20];
   scanf("%d", &n);
   for(i = 0;i < n;i++){
     scanf("%s",cha);
     if(cha[0] == 'f'){
       scanf("%d",&m);
       if(treeSu(root,m) != NIL)
	 printf("yes\n");
       else
	 printf("no\n");
     } 
     else if (cha[0] == 'i' ){
       scanf("%d",&m);
       insert(m);
     }
     else if (cha[0] == 'p' ){
       inorder(root);
       printf("\n");
       preorder(root);
       printf("\n");
     }
   }
   return 0;
}

Measured memory_bytes: 19364
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		String s = sc.next();
		String head = s.substring(0,1);
		int len = s.length();
		String tail = s.substring(len-1,len);
		String mid = String.valueOf(len-2);
		// 出力
		System.out.println(head + mid + tail);
	}
}

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

int main() {
  string S;
  cin >> S ;

 if(S.at(0) == S.at(1) && S.at(2) == S.at(3)) {
    if(S.at(0) == S.at(2)){
     cout << "No" << endl;
    }else{
     cout << "Yes" << endl;
    }
}else if(S.at(0) == S.at(2) && S.at(1) == S.at(3)){
    if(S.at(0) == S.at(1)){
     cout << "No" << endl;
    }else{
     cout << "Yes" << endl;
    }
}else if(S.at(0) == S.at(3) && S.at(1) == S.at(2)){
    if(S.at(0) == S.at(1)){
     cout << "No" << endl;
    }else{
     cout << "Yes" << endl;
    }
}else{
  cout << "No"  << endl;
}
}


Measured memory_bytes: 256
def insertionSort(A, N):
    for i in range(1, N):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j+1] = A[j]
            j -= 1
        A[j+1] = v
        print (' '.join([str(x) for x in A]))

if __name__ == '__main__':
    length = int(input())
    hoge = [int(x) for x in input().split()]
    print (' '.join([str(x) for x in hoge]))
    insertionSort(hoge, length)


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

using ll = long long int;
using bigint = int64_t;

#define pll pair<ll, ll>
#define vll vector<ll>
#define vpll vector<pll>
#define lob lower_bound
#define upb upper_bound
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define pf push_front
#define ins insert
#define mp make_pair
#define w(t) cin >> t;while(t--)
#define bitcount __builtin_popcount
#define endl "\n"
#define sz(s) (int)s.size()
#define mem(n,m) memset(n,m,sizeof(n))
#define deb(x) cout << #x << " = " << x << endl;
#define rep(i,n) for(ll i = 0; i < n; i++)
#define ren(i,n) for(ll i = n-1; i >= 0; i--)
#define all(x) x.begin(),x.end()
#define fo(i, a, b) for(ll i = a; i <= b; i++)
#define ffo(i, a, b) for(ll i = a; i >= b; i--)
#define ffi(i,a,b,c) for(ll i = a ; i <= b ; i += c)
#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
const int MOD = 1000000007;

void io_set() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

void solve() {
    ll n;
    cin >> n;
    map < ll, ll > mpp;
    ll a[n];
    rep(i, n) {
        cin >> a[i];
        mpp[a[i]]++;
    }
    ll ans = 0;
    for (auto it : mpp) {
        ll diff = it.ss;
        ans += ((diff * (diff - 1)) / 2);
    }
    rep(i, n) {
        ll t = mpp[a[i]];
        ll diff = ans - ((t * (t - 1)) / 2);
        ll count = t - 1;
        if(count > 0){
            diff += ((count * (count-1))/2);
        }
        cout << diff << endl;
    }
}

int main() {
    IOS;
    //io_set();
    ll tt = 1;
    //cin >> tt;
    while (tt--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 11136
#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdio.h>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <string>
#include <ctype.h>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <functional>

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ll long long
//#define scanf scanf_s

int i, j, s;
int p[15][15];

void nuri(int i, int j)
{
	if (i >= 0 && i < 10 && j >= 0 && j < 10) p[i][j]++;
}

void shou(int i, int j)
{
	nuri(i, j);
	nuri(i - 1, j);
	nuri(i, j - 1);
	nuri(i, j + 1);
	nuri(i + 1, j);
}

void chu(int i, int j)
{
	shou(i, j);
	nuri(i - 1, j - 1);
	nuri(i - 1, j + 1);
	nuri(i + 1, j - 1);
	nuri(i + 1, j + 1);
}

void dai(int i, int j)
{
	chu(i, j);
	nuri(i - 2, j);
	nuri(i, j - 2);
	nuri(i, j + 2);
	nuri(i + 2, j);
}

int main()
{
	REP(i, 15)REP(j, 15) p[i][j] = 0;
	while (scanf("%d,%d,%d", &i, &j, &s) != EOF)
	{
		if (s == 1) shou(i, j);
		if (s == 2) chu(i, j);
		if (s == 3) dai(i, j);
	}
	int cnt = 0; int mx = 0;
	REP(i, 10)REP(j, 10)
	{
		if (p[i][j] == 0) cnt++;
		mx = max(p[i][j], mx);
	}
	cout << cnt << endl << mx << endl;
	return 0;
}

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

int main(){
  
       int X,t;
  cin >> X >> t;
  if(X-t>=0)
  cout << X-t << endl;
  else
    cout << '0' << endl;
    
  
  
  
}

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

int main() {
  vector<int> vec{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};
  int k;
  cin >> k;
  
  cout << vec.at(k-1) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define cs const
#define pb push_back
using namespace std;
cs int N = 2e5 + 50;
int n, a[N], k, sta[N], vl[N], top, ok;
void ins(int x){
	if(!x) return ok=true, void();
	while(top&&sta[top]>x) --top;
	if(sta[top]==x){
		++vl[top]; 
		if(vl[top]>=k) vl[top]=0, --top, ins(x-1);
	} else sta[++top]=x, vl[top]=1;
}
bool chk(){
	ok=top=0; for(int i=1; i<=n; i++)
	if(a[i]<=a[i-1]) ins(a[i]);
	return !ok;
}
int main(){
	#ifdef FSYolanda
	freopen("1.in","r",stdin);
	#endif
	scanf("%d",&n); int c=0;
	for(int i=1; i<=n; i++) scanf("%d",&a[i]), c+=a[i]<=a[i-1];
	if(!c) return puts("1"),0;
	int l=2, r=n; while(l<r){
		int mid=(l+r)>>1; k=mid;
		if(chk()) r=mid; else l=mid+1;
	} cout<<l; return 0;
} 

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

const int MAXN = 1e5+5;

int n, m;
set<int> odd[MAXN];
int ct[MAXN];
int ctm[MAXN];
set<int> o;

int l;
int ans = 0;

int main() {
	cin >> n >> m;
	l = n;
	for (int i = 0; i < n; ++i) {
		int x; cin >> x;
		ct[x]++;
		ctm[x%m]++;
	}

	for (int i = 0; i <= m/2; ++i) {
		if (i == 0 || (2*i == m)) {
			ans += ctm[i]/2;
			continue;
		}

		//pair i, m-i
		int oi = 0;
		int omi = 0;
		for (int j = i; j <= 100000; j += m)
			oi += (ct[j]%2 == 1);
		for (int j = m-i; j <= 100000; j += m)
			omi += (ct[j]%2 == 1);

		// cout << i << ' ' << oi << ' ' << omi << endl;

		int ops = min(ctm[i], ctm[m-i]);
		int waste = max(0, oi-ops) + max(0, omi-ops);

		// cout << i << ' ' << oi << ' ' << omi << ' ' << ops << ' ' << waste << endl;
		ans += (ctm[i] + ctm[m-i] - waste)/2;
	}

	cout << ans << endl;
}

Measured memory_bytes: 5760
package main

import (
	"fmt"
	"strconv"
	"strings"
)

func dfs() {

}

func main() {
	var s string
	fmt.Scan(&s)
	numbers := strings.Split(s, "")

	var sum int
	for bit := 0; bit < (1 << uint64(len(s)-1)); bit++ {
		var added int

		for i := 0; i < len(s); i++ {
			num, _ := strconv.Atoi(numbers[i])

			if bit&(1<<uint64(i)) > 0 {
				sum += added*10 + num
				added = 0
			} else {
				added = added*10 + num
			}
		}

		sum += added
	}

	fmt.Println(sum)
}


Measured memory_bytes: 640
#include <stdio.h>

int main() {
  int m, n, oddctr = 0, evenctr = 0;
  scanf("%d %d", &m, &n);

  for(int i = 2; i <= m; i++) {
    oddctr = oddctr + i - 1;
  }

  for(int i = 2; i <= n; i++) {
    evenctr = evenctr + i - 1;
  }

  printf("%d", oddctr + evenctr);
  return 0;
}


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

int main() {
    int N; cin >> N;
    vector<int> P(N), Q(N);
    for (int i = 0; i < N; ++i) cin >> P[i], --P[i];

    for (int i = 0; i < N; ++i) Q[P[i]] = i;
    for (int i = 0; i < N; ++i) cout << Q[i]+1 << " ";
    cout << endl;
}

Measured memory_bytes: 1664
import re
l = input()
l = l.split(' ')
s = l[1]
p = re.compile('^[A-Z][a-z]*')

result = ''
if 1 <= len(s) <= 100:
  if p.fullmatch(s):
    result = l[0][0] + s[0] + l[2][0]
print(result)

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <string.h>
#include <cstdio>
#include <string>
#include <math.h>

using namespace std;

#define INT_MAX 100

int main(){
    int N;
    int W[INT_MAX];
    int S1 = 0, S2 = 0;
    scanf("%d", &N);
    for (int i = 0; i < N; i++){
        scanf("%d", &(W[i]));
        if(i <= N/2){
            S1 += W[i];
        }else{
            S2 += W[i];
        }
    }
    int itr = N/2;
    int ret = abs(S1-S2);
    int S1_temp = S1;
    int S2_temp = S2;
    int ret_l = ret, ret_r = ret, ret_l_new, ret_r_new;
    while (itr < N-1){
        ret_r_new = abs((S1_temp+W[itr+1])-(S2_temp-W[itr+1]));
        if (ret_r > ret_r_new){
            S1_temp += W[itr+1];
            S2_temp -= W[itr+1];
            ret_r = ret_r_new;
        }else{
            break;
        }
        itr++;
    }
    itr = N/2;
    S1_temp = S1;
    S2_temp = S2;

    while (itr > 0){
        ret_l_new = abs((S1_temp-W[itr])-(S2_temp+W[itr]));
        if (ret_l > ret_l_new){
            S1_temp -= W[itr];
            S2_temp += W[itr];
            ret_l = ret_l_new;
        }else{
            break;
        }
        itr--;
    }

    ret = (ret_r > ret_l) ? ret_l:ret_r;
    printf("%d\r\n", ret);
    fflush(stdout);
    return 0;
}

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

int main() {
  int n,x,sum;
  cin >> n;
  x = n;
  while(x != 0){
    int a;
    //1の位
    a = x%10;
    sum += a;

    x = (x-a)/10;

  }
  
  if(n%sum == 0)
    cout << "Yes" << endl;
  
  else
    cout << "No" << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx=1e5+2;
struct  S
{
    int to,clo,val;
};
vector<S> a[maxx];
int deep[maxx],f[maxx][30],lg[maxx];
int len[maxx];
void dfs(int x,int fa){
    deep[x]=deep[fa]+1;
    f[x][0]=fa;
    for(int i=1;(1<<i)<=deep[x];i++){
        f[x][i]=f[f[x][i-1]][i-1];
    }
    for(auto t : a[x]){
        if(t.to==fa) continue;
        len[t.to]=len[x]+t.val;
        dfs(t.to,x);
    }
}
int lca(int x,int y){
    if(deep[x]<deep[y]) swap(x,y);
    while(deep[x]>deep[y]){
        x=f[x][lg[deep[x]-deep[y]]-1];
    }
    if(x==y) return x;
    for(int i=lg[deep[x]]-1;i>=0;i--){
        if(f[x][i]!=f[y][i])
            x=f[x][i],y=f[y][i];
    }
    return f[x][0];
}
struct node
{
    int clo,val,u,v;
};
node b[maxx];
struct D
{
    int id,clo,val;
};
vector<D> c[maxx];
int cnt[maxx],Len[maxx];
int tot[maxx],ans[maxx];
void DFS(int x,int fa){
    for(auto it : c[x]){
        tot[it.id]+=it.val*cnt[it.clo];
        ans[it.id]-=it.val*Len[it.clo];
    }
    for(auto t : a[x]){
        if(t.to==fa) continue;
        cnt[t.clo]++;
        Len[t.clo]+=t.val;
        DFS(t.to,x);
        cnt[t.clo]--;
        Len[t.clo]-=t.val;
    }
}
int main(){
    int n,m; cin>>n>>m;
    for(int i=1;i<n;i++){
        int x,y,c,w;
        scanf("%d%d%d%d",&x,&y,&c,&w);
        a[x].push_back(S{y,c,w});
        a[y].push_back(S{x,c,w});
    }
    dfs(1,0);
    for(int i=1;i<=n;i++)
      lg[i]=lg[i-1]+(1<<lg[i-1]==i);
    for(int i=1;i<=m;i++){
        scanf("%d%d%d%d",&b[i].clo,&b[i].val,&b[i].u,&b[i].v);
        int lc=lca(b[i].u,b[i].v);
        ans[i]=len[b[i].u]+len[b[i].v]-2*len[lc];
        c[b[i].u].push_back(D{i,b[i].clo,1});
        c[b[i].v].push_back(D{i,b[i].clo,1});
        c[lc].push_back(D{i,b[i].clo,-2});
    }
    DFS(1,0);
    for(int i=1;i<=m;i++){
        ans[i]+=tot[i]*b[i].val;
        printf("%d\n",ans[i]);
    }
}

Measured memory_bytes: 34872
import sys
INF = 99999999999999
N = int(input())
a = [0]*N
b = [0]*N
c = [0]*N
memo = [[0 for _ in range(3)]for _ in range(N)]
for i in range(N):
    a[i],b[i],c[i] = [int(n) for n in input().split()]

memo[0][0] = a[0]
memo[0][1] = b[0]
memo[0][2] = c[0]

for i in range(1,N):
    memo[i][0] = max(memo[i-1][1] + a[i],memo[i-1][2] + a[i] )
    memo[i][1] = max(memo[i-1][0] + b[i],memo[i-1][2] + b[i] )
    memo[i][2] = max(memo[i-1][1] + c[i],memo[i-1][0] + c[i] )
print(max(memo[N-1][0],memo[N-1][1],memo[N-1][2]))


Measured memory_bytes: 36160
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] nums = new int[n + 1];
		for (int i = 1; i < n; i++) {
			int next = scan.nextInt();
			nums[next] = ++nums[next];
		}
		for (int j = 0; j < n; j++) {
			System.out.println(nums[j + 1]);
		}

		scan.close();
	}

}


Measured memory_bytes: 60488
from collections import Counter as C
n,k,q=map(int, input().split())

a = [int(input()) for i in range(q)]
#ans=["Yes"]*n
d=C(a)
len=len(a)
for i in range(1,n+1):
  try:
    if k - (len-d[i]) > 0:
      print("Yes")
    else:
      print("No")
  except:
    if k-len(a)>0:
      print("Yes")
    else:
      print("No")

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

using namespace std;

string s;

bool can(int i, int j, int a, int b){
    return (s[i] == s[j]) && (s[a] == s[b]) && (s[i] != s[a]);
}

int main()
{
    cin >> s;
    if(can(0, 1, 2, 3) || can(0, 2, 1, 3) || can(0, 3, 1, 2))
        cout << "Yes";
    else
        cout << "No";
    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main{
	static int n,w;
	static int[] weight=new int[101];
	static int[] cost=new int[101];
	static long[][] dp=new long[101][100001];
	public static long solve(int curr,int weig){
		if(curr==n)
			return 0;
		if(weig==0)
			return 0;
		if(dp[curr][weig]!=-1)
			return dp[curr][weig];
		long op1=0,op2=0;
		if(weight[curr]<=weig)
		op1=cost[curr]+solve(curr+1,weig-weight[curr]);

		op2=0+solve(curr+1,weig);
		return dp[curr][weig]=Math.max(op1,op2);

	}
	public static void main(String[] args) throws IOException{
    	 BufferedReader br = new BufferedReader( 
                              new InputStreamReader(System.in)); 
        String str[]=br.readLine().split(" ");
		n=Integer.parseInt(str[0]); 
		w=Integer.parseInt(str[1]); 
		
		for(int i=0;i<n;i++){	
		str=br.readLine().split(" ");		
		   weight[i]=Integer.parseInt(str[0]);
		   cost[i]=Integer.parseInt(str[1]);
		}
		for(long[] x:dp){
			Arrays.fill(x,-1);
		}
		System.out.println(solve(0,w));
	}
    }


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

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

int h, w;
int n;
int lx[1010], ly[1010], rx[1010], ry[1010];
vector<int> x, y;

bool d[2020][2020];

void dfs(int i, int j)
{
  if (i < 0 || j < 0 || h < i || w < j) return;
  if (d[i][j]) return;
  d[i][j] = true;

  for (int k = 0; k < 4; k++){
    dfs(i + dy[k], j + dx[k]);
  }
}

int main()
{
  while (cin >> h >> w, h){
    x = vector<int>();
    y = vector<int>();
    memset(d, false, sizeof(d));
    
    cin >> n;

    for (int i = 0; i < n; i++){
      cin >> lx[i] >> ly[i] >> rx[i] >> ry[i];
      x.push_back(lx[i]); x.push_back(rx[i]);
      y.push_back(ly[i]); y.push_back(ry[i]);
    }
    x.push_back(0); x.push_back(w);
    y.push_back(0); y.push_back(h);

    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    x.erase(unique(x.begin(), x.end()), x.end());
    y.erase(unique(y.begin(), y.end()), y.end());

    for (int i = y.size() - 2; i >= 0; i--){
      for (int j = x.size() - 2; j >= 0; j--){
        bool f = false;
        for (int k = 0; k < n; k++){
          if (lx[k] <= x[j] && x[j + 1] <= rx[k] && 
              ly[k] <= y[i] && y[i + 1] <= ry[k]) f = true;
        }
        d[i][j] = f;
      }
    }

    h = y.size() - 2;
    w = x.size() - 2;

    int ans = 0;
    for (int i = 0; i < y.size() - 1; i++){
      for (int j = 0; j < x.size() - 1; j++){
        if (d[i][j]) continue;
        dfs(i, j);
        ans++;
      }
    }

    cout << ans << endl;
  }
}

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

typedef long long ll;
typedef unsigned long long ull;

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

  string s;
  cin >> s;

  ll ans = 1;
  char prev = s[0];
  for (ll i = 1; i < n; ++i) {
    if (prev != s[i]) {
      ans++;
      prev = s[i];
    }
  }

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

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

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

    vector<int> num(200001, 0);

    for (int i = 2; i <= n; i++) {
        int tmp; cin >> tmp;
        num[tmp]++;
    }

    for (int i = 1; i <= n; i++) {
        cout << num[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 4016
@image = []
h, w = gets.chomp.split(" ").map(&:to_i)

h.times do
  line = gets.chomp
  @image << line
end

@new_image = []

h.times do |i|

       @new_image  << @image[i]
  @new_image  << @image[i]
 
end

@new_image.count.times do |i|
  puts @new_image[i]
end

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

using namespace std;

int main()
{
    char s[19];
    scanf("%s",s);
    for (int i=0;i<19;i++)
    {
        if(s[i]==',')
        {
            s[i]=' ';
        }
    }
    printf("%s",s);

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
const long long MOD = 1e9 + 7;
using namespace std;
typedef long long ll;

map<ll, int> mp;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	int counter = 0;
	for (int i = 0; i < n; i++) {
		if (a[a[i] - 1] == i + 1) counter++;
	}
	cout << counter / 2<< endl;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
#define reg register
using namespace std;
ll tmp,sum;
int main()
{
    for(reg ll i=1;i<=3;i++)
    {
		scanf("%lld",&tmp);
		if(tmp==7)sum++;
	}
    if(sum==1)puts("YES");
    else puts("NO");
    return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException {
		//		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		//		String W	 = in.readLine();
		//		int num = Integer.parseInt(W.split(" ")[0]);

		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int N = sc.nextInt();
		List<Integer> p = new ArrayList<>();
		int ans = 99999;
		int ansZettai = 99999;
		for(int i=0;i<N;i++) {
			p.add(sc.nextInt());
		}

		for(int i=-5;i<105;i++) {
			if(p.contains(i)) {
				continue;
			}
			if(ansZettai > Math.abs(X-i) || (ansZettai == Math.abs(X-i) && i < ans)) {
				ans = i;
				ansZettai = Math.abs(X-i);
			}
		}


		System.out.println(ans);

	}

	//	//二分探索
	//k <= num となる最小の配列要素kのインデックスを返す
	static private int binarySearch(long num, long[] orderedArray){
		int lowerBorder = -1;
		int upperBorder = orderedArray.length;
		int mid;

		while(upperBorder - lowerBorder >1) {
			mid = (upperBorder + lowerBorder)/2;
			if(orderedArray[mid]<=num) {
				lowerBorder = mid;
			}else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//二分探索
	//k <= num となる最小のList要素kのインデックスを返す
	static private int binarySearch(long num, ArrayList<Long> orderedList){
		int lowerBorder = -1;
		int upperBorder = orderedList.size();
		int mid;

		while(upperBorder - lowerBorder >1) {
			mid = (upperBorder + lowerBorder)/2;
			if(orderedList.get(mid)<=num) {
				lowerBorder = mid;
			}else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//aとbの最小公倍数を求める
	public static int gcd(int a, int b) {
		return b == 0 ? a: gcd(b, a % b);
	}
	public static long gcd(long a, long b) {
		return b == 0 ? a: gcd(b, a % b);
	}



}


Measured memory_bytes: 35864
from collections import Counter
N = int(input())
alist = list(map(int,input().split()))
zero , one , two = 0 , 0 , 0
for a in alist:
    if a % 4 == 0:
        two += 1
    elif a % 2 == 0:
        one += 1
    else:
        zero += 1
def func(zero, one, two):
    if zero == 0:
        return True
    if one == 0 :
        if (zero <= (two + 1)):
            return True
        else:
            return False
    if (zero + 1 )  <= (two + 1): 
        return True
    return False
print("Yes" if func(zero , one, two) else "No")

Measured memory_bytes: 14636
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<cstring>
#include<bitset>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<numeric>
#include<set>
#include<stdio.h>
#include<stdlib.h>
using namespace std;

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

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

#define rep(i,x) for(int i=0;i<x;i++)
#define re(i,x,y) for(int i=x;i<y;i++)

long long INF=1e9;
const long long mod=1e9+7;
#define ll long long

int main(){
  cin.tie(0); ios::sync_with_stdio(false);
  ll n;
  cin>>n;
  cout<<n*(n-1)/2<<endl;
  return 0;
}

Measured memory_bytes: 256
fun main() = abc167d()

@OptIn(ExperimentalStdlibApi::class)
fun abc167d() {
    var (n, k) = readLine()!!.split(' ').map { it.toLong() }
    val aList = readLine()!!.split(' ').map { it.toInt() - 1 }.toIntArray()

    val visited = mutableSetOf(0)
    val indices = IntArray(n.toInt())
    indices[0] = 0

    var outerLoop = 0
    var curr = 0

    while (--k >= 0) {
        curr = aList[curr]
        if (!visited.add(curr)) break

        outerLoop++
        indices[curr] = outerLoop
    }

    if (k == -1L) return println(curr + 1)

    val visitedInLoop = mutableSetOf<Int>()
    var loopLength = 0
    val path = IntArray(n.toInt()) { -1 }

    repeat(n.toInt()) {
        if (visitedInLoop.add(curr)) {
            path[curr] = loopLength
            loopLength++
            curr = aList[curr]
        }
    }

    val answer = path.indexOf((k % loopLength).toInt()) + 1

    println(answer)
}


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

int main() {
  int datasets_num;
  int datasets[1000];

  while(true) {
    double deviation;
    double variance = 0;
    double avarage = 0;
    double sum = 0;
    cin >> datasets_num;

    if(datasets_num == 0) {
      break;
    }

    for(int i = 0; i < datasets_num; i++) {
      int data;
      cin >> datasets[i];
      sum += datasets[i];
    }

    avarage = sum / datasets_num;
    for(int i = 0; i < datasets_num; i++){
      variance += pow((avarage - datasets[i]), 2);
    }
    variance /= (double)datasets_num;

    deviation = sqrt(variance);

    printf("%f\n", deviation);
  }
}



Measured memory_bytes: 3224
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
	string S, T;
	cin >> S;
	cin >> T;
	int ans = 0;
	for (int i = 0; i < S.size(); i++)
	{
		if (S[i]==T[i])
		{
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256