akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t;
  cin >> s;
  cin >> t;

  int tn = t.length();
  int sn = s.length();

  int i,j;

  vector<vector<int> >alpPoint(26,vector<int>(sn,0));
  vector<bool>deta(26,false);

  int tmp = 0;

  int tt = 0;
  int ss = 0;

  int chk = 1;

  long cnt = 0;
  for(i=0;i<sn;i++){
    ss = (int)(s[i]-'a');
    deta[ss]=true;
    alpPoint[ss][i] = 1;
  }

  for(i=0;i<tn;i++){
    tt = (int)(t[i]-'a');
    if(!deta[tt])chk = 0;
  }

  if(chk==0)cout << -1 << endl;
  else{
    for(i=0;i<26;i++){
      if(deta[i]){
        for(j=0;j<sn;j++){
          if(alpPoint[i][j]==1){
            tmp = j;
            break;
          }
        }
        for(j=sn-1;j>=0;j--){
          if(alpPoint[i][j]==0)alpPoint[i][j] = tmp;
          else{
            tmp = j;
            alpPoint[i][j] = tmp;
          }
        }
      }
    }
    cnt = 0;
    i=0;
    while(i<tn){
      tt = (int)(t[i]-'a');

      if(alpPoint[tt][(cnt)%sn]-(cnt%sn)+sn==0)cnt += sn;
      else cnt+=(alpPoint[tt][(cnt)%sn]-(cnt%sn)+sn)%sn;
      i++;
      cnt++;
    }
    cout << cnt << endl;
  }

}


Measured memory_bytes: 11264
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;

  int a = 0;
  int min_a = 200001;
  int z = 0;
  int max_z = -1;


  for (int i = 0 ; i < s.size(); i++) {
    if(s[i] == 'A') {
      a = i;
      min_a = min(min_a , i);
    }

    if(s[i] == 'Z') {
      z = i;
      max_z = max(max_z, i);
    }
  }

  cout << max_z - min_a + 1 << endl;
}

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

int main(void)
{
    vector <int> a;
    int b;

    for (int i = 0; i < 10; i++){
    cin>>b;
a.push_back(b);
}

for (int i = 0; i < 100000; i++){
	for (int j = 0; j < 10000; j++){
		b = 0;
	}
}

sort(a.begin(), a.end());
cout << a[9] << endl << a[8] << endl << a[7] << endl;

return 0;
}

Measured memory_bytes: 0
//
/*==========================================================*/
/*    Template ver 2017-0720    |    Created by JollyBee    */
/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */
/*==========================================================*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
const double EPS=(double)1e-9;
const double PI=(double)acos(-1.0);
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define FOR(i,n) for(int i=0;i<n;i++)
#define REPP(i,l,r,c) for(int i=l;i<=r;i+=c)
#define REP(i,l,r) REPP(i,l,r,1)
#define FORD(i,n) for(int i=n-1;i>=0;i--)
#define REVV(i,l,r,c) for(int i=l;i>=r;i-=c)
#define REV(i,l,r) REVV(i,l,r,1)
//random
int irand(int lo, int hi){
    return (((double)rand())/(RAND_MAX+1.0)) * (hi-lo+1) + lo;
}
//ll to string
string toString(ll x) {
    stringstream ss;
    ss << x;
    return ss.str();
}
//string to ll
ll toNumber(string S) {
    ll ret;
    sscanf(S.c_str(),"%lld",&ret);
    return ret;
}
// std::fill(start, end, value);
// for(auto it: DS){}

const int INF=(int)2e9;
const ll MOD=(ll)1e9+7;
/*==========================================================*/
/*                     END OF TEMPLATE                      */
/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */
/*==========================================================*/

typedef pair<double,int> pd;

double cost[1005][1005];

pair<pii,int> dat[1005];

double res[1005];

int main(){
    // reset
    FOR(i,1003) res[i] = (double)1e12;
    // input
    pii s; scanf("%d %d", &s.fi, &s.se);
    pii t; scanf("%d %d", &t.fi, &t.se);
    int n; scanf("%d", &n);
    //
    dat[0] = mp(s,0);
    dat[n+1] = mp(t,0);
    REP(i,1,n){
        pii x; scanf("%d %d", &x.fi, &x.se);
        int r; scanf("%d", &r);
        dat[i] = mp(x,r);
    }
    REP(i,0,n+1) REP(j,0,n+1){
        double ret = hypot(
            dat[i].fi.fi-dat[j].fi.fi,
            dat[i].fi.se-dat[j].fi.se
        );
        cost[i][j] = max(
            (double)0.0,
            ret - (double)(dat[i].se + dat[j].se)
        );
    }
    //
    priority_queue< pd,vector<pd>,greater<pd> > dijk;
    while(!dijk.empty()) dijk.pop();
    dijk.push(mp((double)0.0, 0));
    while(!dijk.empty()){
        double dist = dijk.top().fi;
        int u = dijk.top().se;
        dijk.pop();
        //
        if(res[u] - dist < EPS) continue;
        res[u] = dist;
        // move
        REP(v,0,n+1) if(dist + cost[u][v] - res[v] < EPS){
            dijk.push(mp(dist + cost[u][v], v));
        }
    }
    // print
    printf("%.15lf\n", res[n+1]);
    return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    int M;
    for(int i=2; i<=N; i++){
        cin >> M;
        a.at(M-1)++;
    }
    
    for(int i=1; i<=N; i++){
        
        cout << a.at(i-1) << endl;
    }
    
    
    return 0;
}



Measured memory_bytes: 4052
#include <bits/stdc++.h>
     
using namespace std;
 
long long int dist[301][301];
long long int dist2[301][301];
const long long int INF = 1e18;
vector <pair<int,int>> adj[301],adj2[301];
int n,m,l;

void dijkstra(int start)
{
	fill(dist[start],dist[start]+301,INF);
	dist[start][start] = 0;
	priority_queue <pair<long long int,int>,vector<pair<long long int,int>>,greater<pair<long long int,int>>> pque;
	pque.push(make_pair(dist[start][start],start));

	while(!pque.empty())
	{
		int now = pque.top().second;
		if(dist[start][now] < pque.top().first)
		{
			pque.pop();
			continue;
		}
		pque.pop();

		for(auto it : adj[now])
		{
			int next = it.first;
			int c = it.second;
			if(dist[start][next] > dist[start][now] + c)
			{
				dist[start][next] = dist[start][now] + c;
				pque.push(make_pair(dist[start][next],next));
			}
		}

	}
}

void dijkstra2(int start)
{
	fill(dist2[start],dist2[start]+301,INF);
	dist2[start][start] = 0;
	priority_queue <pair<long long int,int>,vector<pair<long long int,int>>,greater<pair<long long int,int>>> pque;
	pque.push(make_pair(dist2[start][start],start));

	while(!pque.empty())
	{
		int now = pque.top().second;
		if(dist2[start][now] < pque.top().first)
		{
			pque.pop();
			continue;
		}
		pque.pop();

		for(auto it : adj2[now])
		{
			int next = it.first;
			int c = it.second;
			if(dist2[start][next] > dist2[start][now] + c)
			{
				dist2[start][next] = dist2[start][now] + c;
				pque.push(make_pair(dist2[start][next],next));
			}
		}

	}
}

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
 
	cin >> n >> m >> l;
 
	for(int i=0;i<m;i++)
	{
		int a,b,c;
		cin >> a >> b >> c;
		if(c>l)
		{
			continue;
		}
		adj[a].push_back(make_pair(b,c));
		adj[b].push_back(make_pair(a,c));
	}
 	
 	for(int i=1;i<=n;i++)
 	{
 		dijkstra(i);
 	}

 	for(int i=1;i<=n;i++)
 	{
 		for(int j=1;j<=n;j++)
 		{
 			if(dist[i][j]>0 && dist[i][j]<=l)
 			{
 				adj2[i].push_back(make_pair(j,1));
 			}
 		}
 	}

 	for(int i=1;i<=n;i++)
 	{
 		dijkstra2(i);
 	}

	int q;
 
	cin >> q;
 
	while(q--)
	{
		int a,b;
		cin >> a >> b;
		
		if(dist2[a][b]==INF)
		{
			cout << -1 << '\n';
		}
		else
		{
			cout << dist2[a][b]-1 << '\n';
		}
	}
 
	return 0;
}


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

int main(){
  char num1 [105];
  char num2 [105];

  scanf("%s", num1);
  scanf("%s", num2);

  int x = strlen(num1);
  int y = strlen(num2);

  if(x > y){
    printf("GREATER\n");
    return 0;
  }
  else if(x < y){
    printf("LESS\n");
    return 0;
  }
  else{
    for(int i = 0; i < x; ++i){
      if(num1[i] > num2[i]){
        printf("GREATER\n");
        return 0;
      }
      if(num1[i] < num2[i]){
        printf("LESS\n");
        return 0;
      }
    }
  }
  printf("EQUAL\n");
  return 0;
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-

# N,Xを取得
n, x = map(int, input().split())

# m1..mNを取得
num = 0
ms = []
for _i in range(n):
    m = int(input()) 
    num += 1
    x -= m
    ms.append(m)

ms_sorted = sorted(ms)

for m in ms_sorted:
    if m > x:
        break

    while m <= x:
        num += 1
        x -= m

# 結果を出力
print("{}".format(num))


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

long long int lcm(long long int num1, long long int num2){
    long long int c, d, r, temp;
    c = num1;
    d = num2;
    if(c<d){
        temp=c;
        c=d;
        d=temp;
    }
    r = c%d;
    while(r!=0){
        c=d;
        d=r;
        r=c%d;
    }
    return (num1*num2)/d;
}

int main(){
    long long int A,B,C,D,LCM;
    cin >> A >> B >> C >> D;
    LCM = lcm(C,D);
    cout << B-(A-1) - (B/C-(A-1)/C) - (B/D-(A-1)/D) +(B/LCM-(A-1)/LCM) << endl;
    return 0;
}

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

#define VI vector<int>
LL N;

pair<VI ,VI> get_ans(LL N, int mval){
	vector<int> l,r; 
	l.clear(),r.clear();
	if (N!=0){
		int nval=mval-1;
		if (N%2==0) nval--;
		pair<VI,VI> res = get_ans((N-1)/2,nval);
		
		l=res.first,r=res.second;
		l.insert(l.begin(),mval);
		r.insert(r.begin(),mval);
		if (N%2==0) l.insert(l.begin(),mval-1),r.push_back(mval-1);
	}
	
	
	return make_pair(l,r);
}

int main(){
	cin >> N;
	
	pair<VI,VI> ans = get_ans(N,100);
	cout << ans.first.size()+ans.second.size() << "\n";
	for (int x : ans.first)
		cout << x << " ";
		
	for (int x : ans.second)
		cout << x << " ";
	cout << "\n";
	return 0;
}


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

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

    int n10000 = -1;
    int n5000 = -1;
    int n1000 = -1;

    int k = 0;
    bool exist_ans = false;
    for(int i = y/10000; i >= 0; i--){
      //cout << i << endl;
      if (10000*i > y) continue;
      for(int j = n-i; j >= 0; j--){
        k = n-i-j;
        //cout << j << endl;
        if (10000*i + 5000*j > y) continue;
        if (10000*i + 5000*j + 1000*k == y){
          n10000 = i;
          n5000 = j;
          n1000 = k;
          exist_ans = true;
          break;

        //debug//////////
        /*
        cout << i << endl;
        cout << j << endl;
        cout << k << endl;
        cout <<  10000*i + 5000*j + 1000*k <<endl;
        d_i++;
        if (d_i > 3) {
          exist_ans = true;
          break;
        }
        */
        ////////////////////
        }
        if(exist_ans) break;
      }
      if(exist_ans) break;
    }

    cout << n10000 << " " << n5000 << " " << n1000 <<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
      public static void main(String[] args){
            Scanner sc=new Scanner(System.in);
            int n=sc.nextInt();
            int k=sc.nextInt();
            int x=sc.nextInt();
            int y=sc.nextInt();
            int money=0;
 
            if(n<k){
                money=n*x;
                System.out.println(money);
            }else{
                money=k*x+(n-k)*y;
                System.out.println(money);
            }
       }
}

Measured memory_bytes: 9044
#include <bits/stdc++.h>
#define mset(a, b) memset(a, b, sizeof(a))
#define mcpy(a, b) memcpy(a, b, sizeof(a))
#define rg register
using namespace std;
typedef long long LL;
const int N = 45;
 
template <typename T> inline void read(T &AKNOI) {
    T x = 0, flag = 1;
    char ch = getchar();
    while (!isdigit(ch)) {
        if (ch == '-') flag = -1;
        ch = getchar();
    }
    while (isdigit(ch)) {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    AKNOI = flag * x;
}
 
char g[N][N];
int n;
LL dp[N][N][N];
 
LL DP(int l, int r, int k) {
	LL &ret = dp[l][r][k];
	if (~ret) return ret;
	if (l == r) return ret = 1;
	if (l == k || r == k) return ret = 0;
	ret = 0;
	for (int x = l; x < k; ++x) {
		for (int y = k + 1; y <= r; ++y) {
			if (g[x][y] == '0') continue;
			for (int p = x; p < k; ++p) {
				for (int q = k + 1; q <= y; ++q) {
					ret += DP(l, p, x) * DP(p + 1, q - 1, k) * DP(q, r, y);
				}
			}
		}
	}
	return ret;
}
 
void init() {
	read(n);
	for (int i = 1; i <= n * 2; ++i) {
		scanf("%s", g[i] + 1);
	}
}
 
void solve() {
	mset(dp, -1);
	LL ans = 0;
	for (int i = 2; i <= n * 2; ++i) {
		if (g[1][i] == '1') {
			ans += DP(2, n * 2, i);
		}
	}
	printf("%lld\n", ans);
}
 
int main() {
	init();
	solve();
	return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int cnt[26];
main(){
    string s;
    cin >> s;
    for(char c:s)cnt[c-'a']++;
    for(int i = 0;i < 26;i++){
        if(cnt[i] >= 2){
            cout << "no" << endl;
            return 0;
        }
    }
    cout << "yes" << endl;
}

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

using namespace std;

int main()
{
    int n,l;
    cin>>n>>l;
    string s[n];
    for(int i=0;i<n;i++) {
        cin>>s[i];
    }
    sort(s,s+n);
    for(int i=0;i<n;i++) {
        cout<<s[i];
    }
    return 0;
}


Measured memory_bytes: 3604
#include <iostream>

using namespace std;

int main() {
    int H, W;

    while (1) {
        cin >> H >> W;
        if (H == 0 && W == 0) break;
        else {
            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    cout << "#";
                }
                cout << endl;
            }
        }
        cout << endl;
    }
    return 0;
}


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

int main() {
	int n;
	cin >> n;
	int a[n];
	for (int i = 0; i < n; i++) {
		cin >> a[(n - 1) - i];
	}
	for (int j = 0; j < n - 1; j++) {
		cout << a[j] << " ";
	}
	cout << a[n - 1] << endl;
	return 0;
}

Measured memory_bytes: 3080
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ld = long double;
using P = pair<int,int>;

ld PI = M_PI, H = 12, M = 60;
int main() {
  ld a,b,h,m;
  cin >> a >> b >> h >> m;

  ld xa = a*sin(ld(2)*PI*(h/H+m/M/12));
  ld ya = a*cos(ld(2)*PI*(h/H+m/M/12));
  ld xb = b*sin(ld(2)*PI*m/M);
  ld yb = b*cos(ld(2)*PI*m/M);
  ld dx = abs(xb-xa), dy = abs(yb-ya);
  ld ans = sqrt(dx*dx+dy*dy);
  printf("%.10Lf\n",ans);
}


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

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

template <typename T>
vector<T> dijkstra(int s, vector<vector<pair<int, T>>>& G, T INF) {
  using P = pair<T, int>;
  int n = G.size();
  vector<T> d(n, INF);
  priority_queue<P, vector<P>, greater<P>> que;
  d[s] = 0;
  que.emplace(0, s);
  while (que.size()) {
    P p = que.top(); que.pop();
    int u = p.second;
    if (d[u] < p.first) continue;
    for (auto& e : G[u]) {
      int v = e.first;
      if (d[v] <= d[u] + e.second) continue;
      d[v] = d[u] + e.second;
      que.emplace(d[v], v);
    }
  }
  return d;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  
  int n, m;
  cin >> n >> m;

  vector<int> b(n), p(m);
  int one = 0, sum = 0, s = 0;
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    one += b[i];
    s += (b[i] << (n - i - 1));
  }
  for (int i = 0; i < m; i++) {
    cin >> p[i];
    if ((i & 1) == 0) sum += p[i];
  }

  vector<int> goal;
  if (one == sum) {
    int g = 0, shift = n - 1;
    for (int i = 0; i < m; i++) {
      if ((i & 1) == 0) for (int j = 0; j < p[i]; j++) g |= 1 << (shift - j);
      shift -= p[i];
    }
    goal.emplace_back(g);
  }
  if (n - one == sum) {
    int g = 0, shift = n - 1;
    for (int i = 0; i < m; i++) {
      if ((i & 1) != 0) for (int j = 0; j < p[i]; j++) g |= 1 << (shift - j);
      shift -= p[i];
    }
    goal.emplace_back(g);
  }

  vector<vector<pii>> G(1 << n);
  for (int i = 0; i < 1 << n; i++) {
    if (__builtin_popcount(i) != one) continue;
    for (int j = 1; j < n; j++) {
      if (((i >> (j - 1)) & 1) ^ ((i >> j) & 1)) {
        int to = i, l = (to >> j) & 1, r = (to >> (j - 1)) & 1;
        to -= (1 << j) * l + (1 << (j - 1)) * r;
        to += (1 << j) * r + (1 << (j - 1)) * l;
        G[i].emplace_back(to, 1);
      }
    }
  }

  auto dis = dijkstra(s, G, 1 << 30);
  int ans = 1 << 30;
  for (int i = 0; i < goal.size(); i++) ans = min(ans, dis[goal[i]]);
  cout << ans << endl;

  return 0;
}


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

int main(int argc, char *argv[]){
        int a,b,c;
        int count = 0;
        cin >> a >> b >> c;
        for(int i = a; i <= b; i++){
                if(c % i == 0)count++;
        }
        cout << count << "\n";
        return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

using cat = long long;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N, K;
	cin >> N >> K;
	cat ans = 0;
	for(int r = 0; r <= min(N, K-1); r++) if((2*r) % K == 0) {
		int cnt = (N-r)/K+1;
		if(r == 0) cnt--;
		ans += 1LL*cnt*cnt*cnt;
	}
	cout << ans << "\n";
	return 0;
}

// look at my code
// my code is amazing


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
short a[8]={1,2,4,8,16,32,64},n;
int main()
{
    cin>>n;
    for(short i=6;i>=0;i--)
    	if(a[i]<=n) cout<<a[i]<<endl,exit(0);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

int main() {
    string s;
    cin >> s;
    VI c(26);
    REP(i,0,s.size()) ++c[s[i]-'a'];
    int maxi = 0;
    REP(i,0,26) maxi = max(maxi, c[i]);
    VI t;
    REP(i,0,26) if (c[i] == maxi) t.push_back(i);
    int ans = 100;
    //for (auto pos: t) {
    REP(pos,0,26) {
        //cout << "pos: " << pos << endl;
        string str = s;
        bool b = true;
        REP(i,0,str.size()-1) if (str[i] != str[i+1]) {
            b = false;
            break;
        }
        if (b) {
            ans = 0;
            continue;
        } 
        for (int len = str.size() - 1; len > 0; --len) {
            REP(i,0,len) {
                if (s[i] != 'a' + pos) str[i] = str[i+1];
            }
            bool b = true;
            REP(i,0,len-1) if (str[i] != str[i+1]) {
                b = false;
                break;
            }
            if (b) {
                //cout << str.size() << endl;
                //cout << len << endl;
                //cout << str << endl;
                ans = min(ans, (int)(str.size()) - len);
                break;
            } 
        }
    }
    cout << ans << endl;

    return 0;
}

/*
7 6 5 4
6 5 4 3
1 2 3 4
2 3 4 3
*/

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define INF 1000000
using namespace std;
int main(){
    int n,x,y;
    cin >> n >> x >> y;
    --x; --y;
    queue<int> q;
    vector<int> dist(n);
    rep(i,n) dist[i]=0;
    rep(i,n){
        vector<int> d(n);
        rep(j,n) d[j]=INF;
        q.push(i);
        d[i]=0;
        dist[0]++;
        while(!q.empty()){
            int now=q.front(); q.pop();
            if(now!=0 && d[now-1]==INF){
                q.push(now-1);
                d[now-1]=d[now]+1;
                dist[d[now-1]]++;
            }
            if(now!=n-1 && d[now+1]==INF){                
                q.push(now+1);
                d[now+1]=d[now]+1;
                dist[d[now+1]]++;
            }
            if(now==x && d[y]==INF){
                q.push(y);
                d[y]=d[now]+1;
                dist[d[y]]++;
            }
            if(now==y && d[x]==INF){
                q.push(x);
                d[x]=d[now]+1;
                dist[d[x]]++;
            }
        }
    }
    rep(i,n-1) cout << dist[i+1]/2 << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

struct UnionFindTree {
  std::vector<int> data;

  UnionFindTree(int size) : data(size, -1) { }
  bool Unite(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) std::swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
    return x != y;
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) { return -data[root(x)]; }
};


int main() {
  int N, M; cin >> N >> M;
  UnionFindTree tree(N);
  for (int i = 0; i < M; ++i) {
    int A, B; cin >> A >> B; --A, --B;
    tree.Unite(A, B);
  }
  int vmax = 0;
  for (int i = 0; i < N; ++i) {
    vmax = max(vmax, tree.size(i));
  }
  cout << vmax  << endl;

}


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

int main() {
  int N;
  cin >> N;
  
  vector<int> a(N);
  for (int i = 0; i < N; ++i) cin >> a.at(i);

  sort(a.begin(), a.end(), greater<int>());
  
  int A, B;
  A = B = 0;
  for (int i = 0; i < N; i += 2) A += a.at(i);
  for (int i = 1; i < N; i += 2) B += a.at(i);
  
  cout << A - B << endl;
}

Measured memory_bytes: 3636
#include <stdio.h>

int main(void) {

  int a, b, c, tmp;

  scanf("%d %d %d", &a, &b, &c);

  if(a > b){
    tmp = b;
    b = a;
    a = tmp;
  }
  if(b > c){
    tmp = c;
    c = b;
    b = tmp;
  }
  if(a > b){
    tmp = b;
    b = a;
    a = tmp;
  }
  printf("%d %d %d\n", a, b, c);

  return 0;
}



Measured memory_bytes: 2044
package main

import (
  "fmt"
  "unicode/utf8"
)


func main() {
  var a int
  var b int
  for _, err := fmt.Scan(&a, &b); err == nil; _, err = fmt.Scan(&a, &b) {
    fmt.Println(utf8.RuneCountInString(fmt.Sprint(a+b)))
  }
}


Measured memory_bytes: 1140
#include <stdio.h>
int main(void){
  
    int a,b,s,l;
    scanf("%d",&a);
    scanf("%d",&b);
    
    s=a*b;
    
   
    
    l=2*(a+b);
    
    printf("%d %d\n",s,l);
    
    return 0;
}



Measured memory_bytes: 2040
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
//		  System.setIn(B081.class.getResourceAsStream("input.txt"));
		  Scanner in = new Scanner(System.in);

		  int n = in.nextInt();
		  int alice = 0;
		  int bob = 0;
		  Integer card[] = new Integer[n];

		  for(int i= 0; i < n; i++) {
			  card[i] = in.nextInt();
		  }

		  Arrays.sort(card,  Collections.reverseOrder());

		  for(int i = 0; i < n; i++) {
			  if(i == 0) {
				  alice += card[i];
				  continue;
			  }
			  if(i % 2 != 0) {
				  bob +=card[i];
				  continue;
			  }
			  alice += card[i];
		  }
		  System.out.println(alice - bob);
		  in.close();
	}
}

Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
long long p=998244353;
long long fac[333333],inv[333333],fi[333333];
long long c(long long x,long long y)
{
	return fac[x]*fi[y]%p*fi[x-y]%p;
}
int main()
{
	long long n,a,b,k,ans=0;
	long long i,j;
	cin>>n>>a>>b>>k;
	fac[0]=fac[1]=inv[0]=inv[1]=fi[0]=fi[1]=1;
	for (i=2;i<=323232;i++)  
	{  
		fac[i]=fac[i-1]*i%p;
		inv[i]=(p-p/i)*inv[p%i]%p;
		fi[i]=fi[i-1]*inv[i]%p;
	}
	for (i=0;i<=n;i++)
	{
		j=(k-i*a)/b;
		if (i*a+j*b!=k||j>n||j<0) continue;
		//cout<<c(n,i)<<' '<<c(n,j)<<endl;
		ans+=c(n,i)*c(n,j)%p;
		ans%=p;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 7936
import math

while True:
    n=int(input())
    if n==0:
        break
    
    s=list(map(int,input().split()))
    m=sum(s)/n
    A=0
    for i in range(n):
        A+=(s[i]-m)**2
    a=math.sqrt(A/n)
    print(f'{a:.8f}')


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

using namespace std;


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

    vector<int> v(N+1), w(N+1);

    // ナップサック問題の容量W以内でk個までの価値の最大和dp[k][W]
    vector<vector<int> > dp(N+1, vector<int>(W+1, 0));

    for(int i = 0; i < N; i++) {
        cin >> v[i+1] >> w[i+1];
    }

    // 初期条件
    for(int j = 0; j <= W; j++) {
        dp[0][j] = 0;
    }

    // dp開始
    for(int i = 1; i <= N; i++) {
        for(int j = 0; j <= W; j++) {
            if(j - w[i] >= 0) {
                dp[i][j] = max(dp[i-1][j - w[i]] + v[i], dp[i-1][j]);
            } else {
                dp[i][j] = dp[i-1][j];
            }
        }
    }

    cout << dp[N][W] << endl;
	return 0;
}


Measured memory_bytes: 6832
/*input
1
11 11
*/

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

int main() {
    int K, A, B;
    cin >> K >> A >> B;
    if (A%K == 0 || B%K == 0) {
        cout << "OK" << endl;
    }
    else if ((B-1)/K-A/K > 0) {
        cout << "OK" << endl;
    }
    else cout << "NG" << endl;
}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>

using namespace std;

long solve(const int N, const int M, const vector<long> A, const vector<int> B)
{
  vector<int> idx(N);
  iota(idx.begin(), idx.end(), 0);
  sort(idx.begin(), idx.end(), [&](int a, int b) { return A.at(a) < A.at(b); });

  long total_money = 0, total_num = 0;

  for (int i = 0; i < N; i++)
  {
    int item_price = A.at(idx.at(i));
    int num_item = B.at(idx.at(i));
    while (num_item--)
    {
      total_money += item_price;
      total_num++;
      if (total_num == M)
        return total_money;
    }
  }

  return total_money;
}

int main(int argc, char **argv)
{
  int N, M;

  cin >> N >> M;

  vector<long> A(N);
  vector<int> B(N);
  
  for (int i = 0; i < N; i++)
    cin >> A.at(i) >> B.at(i);

  cout << solve(N, M, A, B) << endl;

  return 0;
}


Measured memory_bytes: 2944
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int ctoi(char c){return c-'0';}


// TODO: write
int main() {
  string s;cin>>s;

  vector<int> a(s.size()+1,0);
  rep(i,s.size()){
    a[i] = ctoi(s[s.size()-i-1]);
  }
  vector<int> b = a;
  rep(i,s.size()){
    if(b[i] > 5){
      b[i] = 0;
      b[i+1]++;
    }
    if(b[i] == 5 && b[i+1] >= 5){
      b[i] = 0;
      b[i+1]++;
    }
  }
  
  int ans = 0;
  rep(i,b.size()){
    ans += b[i];
  }
  rep(i,b.size()){// おつり
    if(b[i] >= a[i])ans += b[i] - a[i];
    else{
      ans += 10+b[i]-a[i];
      b[i+1]--;
    }
  }

  print(ans);
  return 0;
}




Measured memory_bytes: 9220
#include <iostream>

using namespace std;

int main()
{int n;
 int x=0;


cin>>n;
 int arr2[n+1];
  arr2[0]=0;
   char arr[n+1];
   for(int i=0;i<n;i++)
   {
       cin>>arr[i];

   }
   for(int i=0;i<n;i++)
   {
       if(arr[i]=='I'){x=x+1;}
       if(arr[i]=='D'){x=x-1;}
       arr2[i+1]=x;

   }
   for(int i=0;i<n+1;i++){
   if(arr2[0]<arr2[i]){arr2[0]=arr2[i];}

   }
   cout<<arr2[0];
}


Measured memory_bytes: 256
import math
A = []
for i in range(5):
  A.append(int(input()))
A.sort(key=lambda x:10 if (x % 10) == 0 else x % 10,reverse=True)
ans = 0
for i in range(4):
  ans += math.ceil(A[i] / 10) * 10
print(ans + A[4])

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

using ll = long long;
using namespace std;
const int INFint = 1e9+1;
const ll INFll = (ll)1e18+1;
ll MOD=1e9+7;


int main(){
  int N;
  cin>>N;
  int cnt[10001] = {0};
  for(int i(1);i<=100;i++){
    for(int j(1);j<=100;j++){
      for(int k(1);k<=100;k++){
        int x = i*i+j*j+k*k+i*j+j*k+k*i;
        if(x <= N){
          cnt[x]++;
        }
      } 
    }
  }
  for(int i(1);i<=N;i++){
    cout << cnt[i] << endl;
  }
  return 0;
}



Measured memory_bytes: 3624
#include <cstdio>
int a[110], dp[100010];
int main() {
	int n, k;
	scanf("%d%d", &n, &k);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	for (int i = 1; i <= k; i++) {
		for (int j = 0; j < n; j++) {
			if (i >= a[j] && !dp[i-a[j]]) dp[i] = 1;
		}
	}
	puts(dp[k] ? "First" : "Second");
	return 0;
}


Measured memory_bytes: 512
//33
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<vector>

using namespace std;

int main(){
  int n;
  cin>>n;
  char g[10][11];
  for(int i=0;i<n;i++){
    cin>>g[i];
  }
  int p[10],s=0;
  vector<int> v;
  for(int i=0;i<n;i++){
    p[i]=1;
    for(int j=0;j<n;j++){
      p[i]+=(g[i][j]=='o')?3:0;
    }
  }
  int r[10]={};
  for(int i=0;i<1000;i++){
    int d=1;
    for(int i=0;i<n;i++){
      if(r[i]*p[i]>r[d]*p[d]){
	d=i+1;
      }
    }
    cout<<d<<endl;
    cin>>d;
    r[d-1]++;
  }
  return 0;
}

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

int binarysearch(int right, int s[], int key){
    int left = 0;
    int mid;
	while(left<right){
        mid = (left + right) / 2;
        if(s[mid] == key){
            return 1;
        }else if( key < s[mid]){
            right = mid;
        }else{
            left = mid + 1;
    	}
    }
	return 0;
}

int main(void){
    int rt, lt = 0;
    int key, mid;
    int n, q, count=0;
    int i,j;
	int t[100001];
	int s[100001];
    cin >> n;
    for (i=0; i<n; i++){
        cin >> s[i];
    }
    cin >> q;
    for (i=0; i<q; i++){
        cin >> t[i];
    }
    for(i=0; i<q;i++){
    	if (binarysearch(n, s, t[i])){
    		count++;
    	}
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define double long double
using namespace std;
const ll inf = 1000000000000000000;

typedef pair<ll, ll> para;
ll n, x, y, mun = inf, mux = -inf, ans = -inf, a[200005], b[200005];
vector<para> v1, v2, v3, v4, myvec;
bool fcmp(const para& a, const para& b) {
    return (a.first + a.second < b.first + b.second);
}
bool fcmp2(const para& a, const para& b) {
    return (a.first - a.second < b.first - b.second);
}
ll manh(para a, para b) {
    return (abs(a.first - b.first) + abs(a.second - b.second));
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    for (ll i = 1; i <= n; ++i) {
        cin >> x >> y;
        myvec.push_back(make_pair(x, y));
    }
    sort(myvec.begin(), myvec.end(), fcmp);
    ans = max(ans, manh(myvec[0], myvec.back()));
    sort(myvec.begin(), myvec.end(), fcmp2);
    ans = max(ans, manh(myvec[0], myvec.back()));
    cout << ans;
    return 0;
}


Measured memory_bytes: 7400
#include<stdio.h>
int main(){
  char s[10];
  int i,count1=0,count2=0;
  
  scanf("%s",s);
  
  for(i=0;i<10;i++){
    
    if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T')
      count1++;
    else
      count1=0;
    
    if(count1>count2)
      count2=count1;
  }
  
 printf("%d",count2);
  
  return 0;
}

Measured memory_bytes: 128
from bisect import bisect

# n, k = 5, 4
n = int(input())
seq = []
for i in range(n):
	ele = int(input())
	pos = bisect(seq, -ele)
	if len(seq) <= pos:
		seq.append(-ele)
	else:
		seq[pos] = -ele 
print(len(seq))


Measured memory_bytes: 7072
#include<stdio.h>
int main(void)
{
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if(a<b){
        if(b<c)
            printf("%d %d %d\n",a,b,c);
        else{
            if(a<c)
                printf("%d %d %d\n",a,c,b);
            else
                printf("%d %d %d\n",c,a,b);
            }
    }
    else{
        if(a<c)
            printf("%d %d %d\n",b,a,c);
        else{
            if(b<c)
                printf("%d %d %d\n",b,c,a);
            else
                printf("%d %d %d\n",c,b,a);
        }
    }
    return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
// using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  set<int> st;
  for (int i = 0; i < N; i++)
  {
    int d;
    cin >> d;
    st.insert(d);
  }
  cout << st.size() << endl;
  return 0;
}


Measured memory_bytes: 3536
n,a,b = map(int,input().split())
from functools import reduce
def mod_comb(n,r,mod=10**9+7):
    num=reduce(lambda x,y:x*y%mod,range(n,n-r,-1))
    den=reduce(lambda x,y:x*y%mod,range(1,r+1))
    return num*pow(den,mod-2,mod)%mod
mod = 10**9+7
bi = [(2**i)%mod for i in range(30) if 2**i<=n]
ans = 1
s = list(reversed(bin(n)[2:]))
for i in range(len(s)):
    ans *= 2**(bi[i]*int(s[i]))
    ans %= mod
ans = (ans+mod-1)%mod
ans = (ans-mod_comb(n,a)-mod_comb(n,b))%mod
print(ans)





Measured memory_bytes: 166392
# tenka1-2018D - Crossing
def main():
    N = int(input())
    K = int((N * 2) ** 0.5)
    if K * (K + 1) / 2 != N:
        print("No")
        return
    row, cur, cnt = [], 1, 1
    while cur + cnt - 1 <= N:
        row.append(list(range(cur, cur + cnt)) + [0] * (K - cnt))
        cur += cnt
        cnt += 1
    col = [list(c) for c in zip(*row)]
    ans, diag = [], []  # diag: diagonal line
    for i, (r, c) in enumerate(zip(row, col)):
        diag.append(r[i])
        ans.append(r[:i] + c[i:])
    ans.append(diag)
    print("Yes", K + 1, sep="\n")
    for a in ans:
        print(K, end=" ")
        print(" ".join(map(str, a)))


if __name__ == "__main__":
    main()

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

	int n;
	int a,b;
	int p[105];

	cin >> n >> a >> b;

	int x,y,z; x=y=z=0;

	for (int i = 0;i < n;i++){
		cin >> p[i];
		if(p[i] <= a) x++;
		else if(p[i] <= b) y++;
		else z++;
	}

	int ans = min(x,y);

	cout << min(ans,z) << endl;

	return 0;

}


Measured memory_bytes: 256
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

N, M = list(map(int, sys.stdin.buffer.readline().split()))
PS = [sys.stdin.buffer.readline().decode().rstrip().split() for _ in range(M)]

ac = np.zeros(N + 1, dtype=int)
wa = np.zeros(N + 1, dtype=int)

for p, s in PS:
    p = int(p)
    if s == 'AC':
        ac[p] = 1
    if s == 'WA':
        if ac[p]:
            continue
        wa[p] += 1
print(ac.sum(), wa[ac > 0].sum())


Measured memory_bytes: 42756
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<cmath>
#include<iomanip>
using namespace std;

int INF = 1e9 + 7;

typedef long long ll;
typedef pair<int, int> P;

int main() {
	ll a, b, c;
	ll k;
	cin >> a >> b >> c >> k;

	if (abs(a - b) > pow(10, 18)) {
		cout << "Unfair" << endl;
	}

	if (k % 2 == 1) {
		cout << -a + b << endl;
	}
	else {
		cout << a - b << endl;
	}
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>

using namespace std;

const int INF = 1e7;
const int N_MAX = 50;

vector<int> G[N_MAX];
int d[N_MAX] = {};
int N, M;
bool visited[N_MAX];

bool bfs(int s) {
  int i;
  queue<int> que;
  que.push(s);
  for (i = 0; i < N; i++) {
    visited[i] = false;
  }
  while (!que.empty()) {
    int b = que.front();
    que.pop();
    visited[b] = true;
    for (i = 0; i < G[b].size(); i++) {
      if (visited[G[b][i]] == true) {
	continue;
      } else {
	que.push(G[b][i]);
      }
    }
  }
  bool flag = false;
  for (i = 0; i < N; i++) {
    //printf("%d ", int(visited[i]));
    if (visited[i] == false) {
      return true;
    }
  }
  return false;
}
  

int main() {
  int i, j;
  int a[55], b[55];
  scanf("%d %d", &N, &M);
  for (i = 0; i < M; i++) {
    scanf("%d %d", &a[i], &b[i]);
    G[a[i]-1].push_back(b[i]-1);
    G[b[i]-1].push_back(a[i]-1);
  }
  /*for (i = 0; i < N; i++) {
    printf("%d: ", i);
    for (j = 0; j < G[i].size(); j++) {
      printf("%d ", G[i][j]);
    }
    printf("\n");
    }*/
  int ans = 0;
  for (i = 0; i < M; i++) {
    G[a[i]-1].erase(remove(G[a[i]-1].begin(),  G[a[i]-1].end(), b[i]-1),  G[a[i]-1].end());
    G[b[i]-1].erase(remove(G[b[i]-1].begin(),  G[b[i]-1].end(), a[i]-1),  G[b[i]-1].end());
    /*for (int k = 0; k < N; k++) {
      printf("%d: ", k);
      for (j = 0; j < G[k].size(); j++) {
	printf("%d ", G[k][j]);
      }
      printf("\n");
      }*/
    if (bfs(0)) {
      ans += 1;
    }
    G[a[i]-1].push_back(b[i]-1);
    G[b[i]-1].push_back(a[i]-1);
  }
  printf("%d", ans);
  return 0;
}


Measured memory_bytes: 384
using System;

namespace _0619
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] rika = new int[4];
            for (int i = 0; i < 4; i++)
            {
                rika[i] = int.Parse(Console.ReadLine());
            }
            int[] syakai = new int[2];
            for (int i = 0; i < 2; i++)
            {
                syakai[i] = int.Parse(Console.ReadLine());
            }
            Array.Sort(rika);
            Array.Sort(syakai);
            Console.WriteLine(rika[1] + rika[2] + rika[3] + syakai[1]);
        }
    }
}

Measured memory_bytes: 9352
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define sz(x) (ll)(x).size()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;
typedef vector<ll> vl;
typedef vector<P> vp;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

const ll MAX_N = 3005;
// dp[i][x] .. using [0, i), x is count of heads.
double dp[MAX_N][MAX_N];

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  cout << setprecision(10) << fixed;

  ll n;
  cin >> n;
  vector<double> p(n);
  rep(i, n) {
    cin >> p[i];
  }
  dp[0][0] = 1.0;
  rep(i, n) {
    rep(j, n+1) {
      // head
      if (j >= 1) {
        dp[i+1][j] += dp[i][j-1] * p[i];
      }
      // tail
      dp[i+1][j] += dp[i][j] * (1-p[i]);
    }
  }
  // rep(i, n) {
  //   rep(j, n+1) {
  //     cout << dp[i][j] << ",";
  //   }
  //   cout << endl;
  // }

  double ans = 0;
  rep(i, n+1) {
    if (i > n-i) {
      ans += dp[n][i];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 70656
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end


h, w = gets_i_list

h.times do
  l = gets.chomp
  puts l
  puts l
end

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

x = int(input())
a = 1
while True:
    for b in range(0, a):
        if a**5 - b**5 == x:
            print(a, b)
            sys.exit()
        if a**5 + b**5 == x:
            print(a, -b)
            sys.exit()
    a += 1


Measured memory_bytes: 64380
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define fi first
#define se second
#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)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
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;
}
int main(){
    int n;cin >> n;
    vector<string> s(n);
    vector<int> path[n+1];
    rep(i,n){
        cin >> s[i];
        rep(j,n){
            if(s[i][j]=='1'){
                path[i+1].push_back(j+1);
                path[j+1].push_back(i+1);
            }
        }
    }
    vector<vector<int>> d(n+1,vector<int>(n+1));
    vector<int> color(n+1);
    stack<int> st;
    st.push(1);
    color[1]=1;
    bool ok=true;
    while(st.size()){
        int now=st.top();st.pop();
        for(auto next: path[now]){
            if(color[next]==0){
                color[next]=-1*color[now];
                st.push(next);
            }
            else if(color[next]!=0){
                if(color[next]==color[now]){
                    ok=false;
                }
            }
        }
    }
    if(!ok){
        cout << -1 << endl;
        return 0;
    }
    rrep(i,n){
        rrep(j,n){
            if(s[i-1][j-1]=='1') d[i][j]=1;
            else d[i][j]=INF;
        }
        d[i][i]=0;
    }
    rrep(k,n){
        rrep(i,n){
            rrep(j,n){
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
    int ans=0;
    rrep(i,n){
        rrep(j,n){
            chmax(ans,d[i][j]+1);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 896
import java.util.*;

import static java.lang.System.*;

public class Main {
    public static int A;
    public static int B;
    public static int C;


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        A = sc.nextInt();
        B = sc.nextInt();
        C = sc.nextInt();

        int[] l = new int[N];
        for (int i = 0; i < N; i++) {
            l[i] = sc.nextInt();
        }

        out.println(calMin(0, 0, 0, l, 0, 0));
    }

    public static int calMin(int a, int b, int c, int[] l, int i, int cost) {
        if (i == l.length) {
            if (a == 0 || b == 0 || c == 0) {
                return Integer.MAX_VALUE;
            } else {
                return cost + Math.abs(A - a) + Math.abs(B - b) + Math.abs(C - c) - 30;
            }
        }

        return Math.min(
                Math.min(
                        calMin(a + l[i], b, c, l, i + 1, cost + 10),
                        calMin(a, b + l[i], c, l, i + 1, cost + 10)
                ),
                Math.min(
                        calMin(a, b, c + l[i], l, i + 1, cost + 10),
                        calMin(a, b, c, l, i + 1, cost)
                )
        );
    }
}

Measured memory_bytes: 23636
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

const int INF = 10000000;
using namespace std;
typedef long long  ll;

/** Problem0037 : Path on a Grid **/
int main()
{
	string s, ds="LRUD";
	bool grid[5][5][4]={0};
	int y=0;
	rep(k, 9) {
		cin>>s;
		if (k%2==0) {
			for (int i=0; i<4; i++) {
				if (s[i] == '1') {
					grid[i][y][1]=true;
					grid[i+1][y][0]=true;
				}
			}
		} else {
			for (int i=0; i<5; i++) {
				if (s[i] == '1') {
					grid[i][y][3]=true;
					grid[i][y+1][2]=true;
				}
			}
			y++;
		}
	}
	int d=1, x=0; y=0;
	while (1) {
		switch (d) {
			case 1:
				if (grid[x][y][2]) {
					y--; d=2;
					cout << "U";
				} else if (grid[x][y][1]) {
					x++; d=1;
					cout << "R";
				} else if (grid[x][y][3]) {
					y++; d=3;
					cout << "D";
				} else {
					x--; d=0;
					cout << "L";
				} break;
				
			case 3:
				if (grid[x][y][1]) {
					x++; d=1;
					cout << "R";
				} else if (grid[x][y][3]) {
					y++; d=3;
					cout << "D";
				} else if (grid[x][y][0]) {
					x--; d=0;
					cout << "L";
				} else {
					y--; d=2;
					cout << "U";
				} break;
				
			case 0:
				if (grid[x][y][3]) {
					y++; d=3;
					cout << "D";
				} else if (grid[x][y][0]) {
					x--; d=0;
					cout << "L";
				} else if (grid[x][y][2]) {
					y--; d=2;
					cout << "U";
				} else {
					x++; d=1;
					cout << "R";
				} break;
				
			case 2:
				if (grid[x][y][0]) {
					x--; d=0;
					cout << "L";
				} else if (grid[x][y][2]) {
					y--; d=2;
					cout << "U";
				} else if (grid[x][y][1]) {
					x++; d=1;
					cout << "R";
				} else {
					y++; d=3;
					cout << "D";
				} break;
		}
		if (x==0 && y==0)
			break;
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1180