akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main() {
	int h, w; cin >> h >> w;
	string s[55];
	for(int i=1;i<=h;i++){
		cin >> s[i];
	}
	string ans = "Yes";
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(s[i][j]=='#' ){
				if(s[i-1][j]!='#' && s[i+1][j]!='#' && s[i][j-1]!='#' && s[i][j+1]!='#'){
					ans = "No";
					break;
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

//------------------------------------------------------------
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
		int n = Integer.parseInt(sc.next());
		Set<Integer> mochis =new HashSet<>();
		for (int i=0;i<n;i++) {
			mochis.add(sc.nextInt());
		}
		System.out.println(mochis.size());
		//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
	}
}



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

Measured memory_bytes: 21972
n, m = map(int, input().split())
a = []
b = []

for x in range(n):
    a.append(list(input()))

for y in range(m):
    b.append(list(input()))


def check_photo(base, target):
    for i in range(n-m+1):
        check = base[i:i+m]
#        print(check)
        for j in range(n-m+1):
            check2 = [line[j:j+m] for line in check]
#            print(check2)
            if check2 == target:
                return print('Yes')
    return print('No')

check_photo(a, b)


Measured memory_bytes: 3064
#   2???????????????????????????????????????????????????????????°??????


#   ??????????????¢????????????????????????
#   top = 1 front = 2 right = 3 left = 4 back = 5 bottom = 6
class Dice:
    def __init__(self, nums):
        self.face = nums

    #   2->1->5->6
    def turnSouth(self):
        temp = self.face[0]
        self.face[0] = self.face[4]
        self.face[4] = self.face[5]
        self.face[5] = self.face[1]
        self.face[1] = temp
        return self

    #   4->1->3->6
    def turnEast(self):
        temp = self.face[0]
        self.face[0] = self.face[2]
        self.face[2] = self.face[5]
        self.face[5] = self.face[3]
        self.face[3] = temp
        return self

    #   3->1->4->6
    def turnWest(self):
        temp = self.face[0]
        self.face[0] = self.face[3]
        self.face[3] = self.face[5]
        self.face[5] = self.face[2]
        self.face[2] = temp
        return self

    #   5->1->2->6
    def turnNorth(self):
        temp = self.face[0]
        self.face[0] = self.face[1]
        self.face[1] = self.face[5]
        self.face[5] = self.face[4]
        self.face[4] = temp

    #   2->3->5->4
    def turnRight(self):
        temp = self.face[1]
        self.face[1] = self.face[2]
        self.face[2] = self.face[4]
        self.face[4] = self.face[3]
        self.face[3] = temp
        return self

    #   2->4->5->3
    def turnLeft(self):
        temp = self.face[1]
        self.face[1] = self.face[3]
        self.face[3] = self.face[4]
        self.face[4] = self.face[2]
        self.face[2] = temp
        return self

    def equals(self, another):
        #   ?????¢??????????????????????????????
        for i in range(0, 4):
            if self.face[0] == another.face[0]:
                #   ??£??¢???????????????????????¢????????????????????¢
                for j in range(0, 4):
                    if self.face[1] == another.face[1]:
                        if self.face == another.face:
                            return True
                    another.turnRight()
            another.turnNorth()
        #   ?????¢??????????????????????????????
        for i in range(0, 4):
            if self.face[0] == another.face[0]:
                #   ??£??¢???????????????????????¢????????????????????¢
                for j in range(0, 4):
                    if self.face[1] == another.face[1]:
                        if self.face == another.face:
                            return True
                    another.turnRight()
            another.turnEast()
        return False

#   Dice?????????
Dice1 = Dice(input().split())
Dice2 = Dice(input().split())

if Dice1.equals(Dice2):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 7700
#include <bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pa;
typedef unsigned int uint;
typedef unsigned long long ull;
#define w1 first
#define ls (x<<1)
#define w2 second
#define rs (x<<1|1)
#define mp make_pair
#define pb push_back
#define mid ((l+r)>>1)
#define SZ(x) (int((x).size()))
#define All(x) (x).begin(),(x).end()
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define per(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define Rep(p,x) for(int (p)=head[(x)];(p);(p)=nxt[(p)])
#define Rep2(p,x) for(int (p)=cur[(x)];(p);(p)=nxt[(p)])
template<class T>void read(T&num){
	num=0;T f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
	num*=f;
}
#define quit return puts("No"),0;
const int maxn=1e5+5;
int n;
int c[maxn],a[3][maxn],rev[2];
int lowbit(int x){
	return x&(-x);
}
int M(int x){
	for(;x<=n+1;x+=lowbit(x))c[x]^=1;
}
int Q(int x){
	int res=0;
	for(;x;x-=lowbit(x))res^=c[x];
	return res;
}
int nxd(int x){
	memset(c,0,sizeof c);
	int ans=0;
	per(i,n,1)if((i&1)==x)ans^=Q(a[1][i]/3+1),M(a[1][i]/3+1);
	return ans;
}
int main(){
	read(n);
	rep(i,0,2)rep(j,1,n)read(a[i][j]);
	rep(j,1,n)if(a[1][j]%3!=2)quit;
	rep(j,1,n)if(abs(a[0][j]-a[1][j])!=1||abs(a[2][j]-a[1][j])!=1)quit;
	rep(j,1,n)if(((a[1][j]/3)&1)==(j&1))quit;
	rep(j,1,n)if(a[0][j]>a[2][j])rev[j&1]^=1;
	if(nxd(0)!=rev[1])quit;
	if(nxd(1)!=rev[0])quit;
	puts("Yes");
	return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <iostream>

using namespace std;

const int N = 81;
const int S = N * N * 2;

int a[N][N];
int b[N][N];
bool f[2][N][2 * S];

int main() {
  int h, w;
  scanf("%d%d", &h, &w);
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      scanf("%d", a[i] + j);
    }
  }
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      scanf("%d", b[i] + j);
    }
  }
  for (int i = 0; i < w; ++i) {
    for (int j = 0; j < 2 * S; ++j) {
      f[0][i][j] = false;
    }
  }
  f[0][0][a[0][0] - b[0][0] + S] = true;
  f[0][0][b[0][0] - a[0][0] + S] = true;
  for (int j = 1; j < w; ++j) {
    for (int k = 0; k < 2 * S; ++k) {
      if (k + a[0][j] - b[0][j] >= 0 && k + a[0][j] - b[0][j] < 2 * S) {
        if (f[0][j - 1][k]) {
          f[0][j][k + a[0][j] - b[0][j]] = true;
        }
      }
      if (k + b[0][j] - a[0][j] >= 0 && k + b[0][j] - a[0][j] < 2 * S) {
        if (f[0][j - 1][k]) {
          f[0][j][k + b[0][j] - a[0][j]] = true;
        }
      }
    }
  }
  for (int i = 1; i < h; ++i) {
    int z = i % 2;
    for (int j = 0; j < w; ++j) {
      for (int k = 0; k < 2 * S; ++k) {
        f[z][j][k] = false;
      }
      for (int k = 0; k < 2 * S; ++k) {
        if (k + a[i][j] - b[i][j] >= 0 && k + a[i][j] - b[i][j] < 2 * S) {
          if (f[1 - z][j][k] || (j - 1 >= 0 && f[z][j - 1][k])) {
            f[z][j][k + a[i][j] - b[i][j]] = true;
          }
        }
        if (k + b[i][j] - a[i][j] >= 0 && k + b[i][j] - a[i][j] < 2 * S) {
          if (f[1 - z][j][k] || (j - 1 >= 0 && f[z][j - 1][k])) {
            f[z][j][k + b[i][j] - a[i][j]] = true;
          }
        }
      }
    }
  }
  int ans = 1'000'000'000;
  for (int i = 0; i < 2 * S; ++i) {
    if (f[(h - 1) % 2][w - 1][i]) {
      ans = min(ans, abs(i - S));
    }
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 4480
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#define debug(x)  cerr << #x << " = " << x << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;

const int maxN = 1e5 + 5;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

ll gcd(ll a, ll b){return !b ? a : gcd(b, a % b);}
ll modP(ll a, ll b) {return (!b ? 1 : (modP(a, b / 2) * modP(a, b / 2) * (b % 2 ? a : 1)) % MOD);}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, a, x, cnt;
	cin >> n;
	x = 0;
	cnt = 0;
	for (int i = 0; i < n; i++){
		cin >> a;
		if (a >= x){
			cnt += 1;
			x = a;
		}
	}
	cout << cnt << endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/numeric>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define oo 0x3f3f3f3f
#define OO 0x3f3f3f3f3f3f3f3f
#define ones(n) __builtin_popcount(n)
#define ONES(n) __builtin_popcountll(n)

using namespace std;
//using namespace __gnu_cxx;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef pair<int, int> ii;
typedef pair<long long, pair<int, int>> iii;
typedef pair<ii, ii> iiii;

const double PI = acos(-1.0), EPS = 1e-6;
const int N = 22, M = 5000006, mod = 1000000007, mxLog = 20;

int n;
int memo[N][M];
bool isComp[N][N];
int solve(int i, int msk) {
    if (i == n)
        return 1;
    int &ret = memo[i][msk];
    if (~ret)
        return ret;
    ret = 0;
    for (int j = 0; j < n; ++j) {
        if (isComp[i][j] && !(msk & (1 << j))) {
            ret += solve(i + 1, msk | (1 << j));
            ret %= mod;
        }
    }
    return ret;
}


int main() {
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "rt", stdin);
//    freopen("output.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(10), cout << fixed;

    cin >> n;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            cin >> isComp[i][j];
        }
    }
    memset(memo, -1, sizeof memo);
    cout << solve(0, 0) << '\n';

    return 0;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t,n;
    t = 1;
    while(t--) {
     cin >> n;
      cout << 48 - n << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using ll = long long int;


int main(){
    ll N, W; cin >> N >> W;
    ll dp[N+1][W+1];
    vll w(N+1), v(N+1);
    for(int i=1; i<=N; i++){
        cin >> w[i] >> v[i];
    }
    for(int i=0; i<W+2; i++){
        dp[0][i] = 0;
    }
    for(int i=1; i<N+1; i++){
        for(int j=0; j<W+1; j++){
            if(w[i] > j){
                dp[i][j] = dp[i-1][j];
            }
            else{
                dp[i][j] = max(dp[i-1][j-w[i]]+v[i], dp[i-1][j]);
            }
        }
    }
    cout << dp[N][W];
}

Measured memory_bytes: 79104
x = [int(i) for i in input().split(' ')]
A = [int(i) for i in input().split(' ')]
N, M = x


count = 0
for i in A:
    if i >= sum(A)/(4 * M):
        count += 1

if count >= M:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 38512
#include <iostream>
#include<string.h>
#include<stdio.h>
#define LL long long
#define siz 100005

using namespace std;

const int maxn = 100000;
struct Edge{
   int to,w,next;
}edges[maxn*3];

int n,tot,q,k;
int head[maxn+5];
LL d[maxn+5];

void Addedge(int x,int y,int w)
{
    edges[++tot].to = y, edges[tot].w = w;
    edges[tot].next = head[x], head[x] = tot;
}

void dfs(int x,int fa)
{
    for(int i=head[x];i!=-1;i=edges[i].next)
    {
        int to = edges[i].to;
        if(to==fa) continue;
        d[to] = d[x] + edges[i].w*1ll;
        dfs(to,x);
    }
}

int main()
{
    int x,y,w;
    while(scanf("%d",&n)!=EOF)
    {
        tot = 0;
        for(int i=1;i<=n;i++) head[i] = -1;
        for(int i=1;i<n;i++)
        {
            scanf("%d %d %d",&x,&y,&w);
            Addedge(x,y,w);
            Addedge(y,x,w);
        }
        scanf("%d %d",&q,&k);
        
        d[k]=0;
        dfs(k,-1);
        
        for(int i=1;i<=q;i++)
        {
            scanf("%d %d",&x,&y);
            LL ans = d[x] + d[y];
            printf("%lld\n",ans);
        }
    }
    return 0;
}


Measured memory_bytes: 10624
### main

while true
  n = gets.strip.to_i
  break if n == 0

  foods = []

  n.times do
    i, p, q, r = gets.strip.split(' ').map{|s| s.to_i}
    c = 4 * p + 9 * q + 4 * r
    foods << [i, p, q, r, c]
  end
  #p foods

  max_p, max_q, max_r, max_c = gets.strip.split(' ').map{|s| s.to_i}

  edible = 0
  for fd in foods
    if fd[1] <= max_p && fd[2] <= max_q && fd[3] <= max_r && fd[4] <= max_c
      puts fd[0]
      edible += 1
    end
  end

  if edible == 0
    puts 'NA'
  end
end

Measured memory_bytes: 6124
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

struct Edge {
  int from;
  int to;
  int cost;
  int use;
  Edge() {;}
  Edge(int from, int to, int cost, int use) : from(from), to(to), cost(cost), use(use) {;}
  bool operator<(const Edge &rhs) const {
    return cost > rhs.cost;
  }
};

vector<Edge> edges[110];
bool visit[110][110];
int dist[110][110];


int main() {
  int n, m, c;
  while (scanf("%d %d %d", &n, &m, &c), n|m|c) {
    MEMSET(visit, false);
    MEMSET(dist, 0x0f);
    REP(i, 110) { edges[i].clear(); }
    REP(i, m) {
      int from, to, cost;
      scanf("%d %d %d", &from, &to, &cost);
      from--; to--;
      edges[from].push_back(Edge(from, to, cost, 0));
    }
    priority_queue<Edge> que;
    que.push(Edge(0, 0, 0, 0));
    int ans = 110;
    while (!que.empty()) {
      int from = que.top().to;
      int cost = que.top().cost;
      int use = que.top().use;
      que.pop();
      if (visit[use][from]) { continue; }
      visit[use][from] = true;
      if (from == n - 1) { ans = min(ans, use); continue; }
      FORIT(it, edges[from]) {
        int to = it->to;
        int ncost = cost + it->cost;
        int nuse = use;
        if (visit[nuse][to] || use >= n || dist[nuse][to] <= ncost || c < ncost) { continue; }
        dist[nuse][to] = ncost;
        que.push(Edge(from, to, ncost, nuse));
      }
      FORIT(it, edges[from]) {
        int to = it->to;
        int ncost = cost;
        int nuse = use + 1;
        if (visit[nuse][to] || use >= n || dist[nuse][to] <= ncost || c < ncost) { continue; }
        dist[nuse][to] = ncost;
        que.push(Edge(from, to, ncost, nuse));
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1260
S = input()
N = len(S)
l = 0
a = {}
if N%2==0:
    if S[N//2] != S[N//2-1]:
        print(N//2)
    else:
        flag = S[N//2]
        l = 2
        i = 1
        while i <= N//2-1:
            if S[N//2+i]==flag and S[N//2-1-i]==flag:
                l+=2
                i += 1
            else:
                break
        print(N//2+l//2)
else:
    flag = S[N//2]
    i = 1
    l = 1
    while i <= N//2:
        if S[N//2+i]==flag and S[N//2-i]==flag:
            l += 2
            i += 1
        else:
            break
    print((N-l)//2 + l)

Measured memory_bytes: 39536
#include <iostream>
#include <stdio.h>
#include <array>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <algorithm>
#include <map>
#include <cmath>
#include <stdlib.h>
#include <string.h>
#include <stack>
#include <bitset>

using namespace std;

typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;

int a, b;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n)
#define MAX(a,b) a>b? a:b
#define MIN(a,b) a>b? b:a


const int MOD = 1e9 + 7;
const ll INF=1e10;
const db PI = acos(-1.0);
const db EPS = 1e-10;


ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


ll MAXX(vector<ll> a,ll k) {
	ll max = 0;
	REP(i, k) {
		if (a[i] >= max) max = a[i];
	}
	return max;
}

ll MINN(vector<ll> a,ll k) {
	ll min = INF;
	REP(i, k) {
		if (a[i] <= min)min = a[i];
	}
	return min;
}

ll SUM(vector<ll> a, ll k) {
	ll sum = 0;
	REP(i, k) {
		sum += a[i];
	}
	return sum;
}

db AVE(vector<ll> a, ll k) {
	db ave = SUM(a,k)/(db)k;
	return ave;
}

db VAR(vector<ll> a, ll k) {
	db ave,ave2,var;
	db sum = 0;
	REP(i, k) {
		sum += a[i] * a[i];
	}
	ave2 =sum/ k;
	ave = AVE(a,k);
	ave = pow(ave,2);
	var = ave2 - ave;
	return var;
}


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


void prime(int k) {
	int cnt = 0;
	for (int i = 2;i<k;i++) {
		if (k % i == 0) { cnt++; }
	}
	if (cnt == 0) cout << k << "は素数です。" << endl;
	else cout << k << "は素数ではありません。" << endl;
}



int main() {
	bool b = true;
	ull k;
	string s;
	cin >> s>>k;
	REP(i, k) {
		if (s[i] != '1') {
			cout << s[i] << endl;
			b = false;
			break;
		}
	}
	if (b) cout << '1' << endl;
	return 0;

}

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

using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using f64 = double;
using f80 = long double;

#define FOR(v, a, b) for(i64 v = (a); v < (b); ++v)
#define FORE(v, a, b) for(i64 v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(i64 v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...) ((void)0)
#endif

using namespace std;

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T> void pout(const T &value){std::cout << value << "\n";}
template <typename T, typename ...Args> void pout(const T &value, const Args&... args){std::cout << value << " ";pout(args...);}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}
template <typename T> auto make_vector(int n, int m, const T &value){return vector<vector<T>>(n, vector<T>(m, value));}


struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;



int main(){
  int K;
  while(cin >> K){
    i64 ans = 0;

    FORE(a,1,K){
      FORE(b,1,K){
        FORE(c,1,K){
          ans += gcd(gcd(a, b), c);
        }
      }
    }
    

    pout(ans);
  }


  return 0;
}


Measured memory_bytes: 3652
#include <iostream>


using namespace std;

bool adjmatrix[101 * 101];
int costs[101];



void BFS(int vertex, int cur_cost, int N) {
  if (costs[vertex] < cur_cost) return;
  costs[vertex] = cur_cost;
  for (int i =1; i<= N; i++) {
    if(adjmatrix[vertex*101 + i]) {
      BFS(i, cur_cost + 1, N);
    }
  }
}
  

int main() {
  for (int i = 0; i < 101; i++) {
    costs[i] = 101;
  }
  int N;
  cin >> N;

  for (int i = 0; i < N; i++) {
    int vertex, degree;
    cin >> vertex >> degree;

    for (int j = 0; j < degree; j++) {
      int outvertex;
      cin >> outvertex;
      adjmatrix[vertex * 101 + outvertex] = true;
    }
  }


  /*
  //function to print adjmatrix
  for (int i = 0; i <= N; i++) {
    for (int j= 0; j <= N; j++) {
      if (adjmatrix[i * 101 + j]) {
	cout << "1 ";
      } else {
	cout << "0 ";
      }
    }
    cout << endl;
    }*/

  BFS(1, 0, N);

  for (int i =1; i<=N; i++) {
    if (costs[i] == 101) {
      cout << i << " " << -1 << endl;
    } else {
      cout << i << " " << costs[i] << endl;
    }
  }

 

}

Measured memory_bytes: 1168
using System;

class Program {
  static void Main(string[] args) {
    int N, M, m, cost, rep;
    int[] a;
    string[] buf;

    N = int.Parse(Console.ReadLine());
    M = -100; m = 100;
    a = new int[N];
    buf = Console.ReadLine().Split(' ');

    for(int i = 0; i < N; ++i) {
      a[i] = int.Parse(buf[i]);
      if(M < a[i]) M = a[i];
      if(m > a[i]) m = a[i];
    }

    cost = 0;
    rep = 200 * 200 * 100;
    for(int i = m; i <= M; ++i) {
      cost = 0;
      for(int j = 0; j < N; ++j) {
        cost += (i - a[j]) * (i - a[j]);
      }
      if(rep > cost) rep = cost;
    }

    Console.WriteLine(rep);
  }
}


Measured memory_bytes: 11092
#include <iostream>
#include <algorithm>
#include <cmath>

int q, l[100005], r[100005];
bool prime[100005];
int num[100005];
int main() {
	std::fill(prime, prime + 100005, true);

	for (int i = 2, end = std::sqrt(100005); i < end; ++i)
		if (prime[i]) {
			for (int j = 0; i*(j + 2) < 100005; ++j)
				prime[i*(j + 2)] = false;
		}
	prime[0] = prime[1] = false;

	for (int i = 3; i < 100005; i += 2) {
		num[i] = num[i - 2];
		if (prime[i] && prime[(i + 1) / 2])
			++num[i];
	}

	std::cin >> q;
	for (int i = 0; i < q; ++i)
		std::cin >> l[i] >> r[i];

	for (int i = 0; i < q; ++i)
		std::cout << num[r[i]] - num[l[i] - 2] << std::endl;

	return 0;
}


Measured memory_bytes: 1920
#include<iostream>
#include<cmath>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<cstdlib>
#include<queue>
#include<list>
using namespace std;

int main(){
    int x, y, a[]={0, 1, 2, 1, 3, 1, 3, 1, 1, 3, 1, 3, 1};
    cin>>x>>y;
    cout<<(a[x]==a[y]? "Yes": "No")<<endl;
}


Measured memory_bytes: 256
def main():
  import sys
  input = sys.stdin.readline
  n=int(input())
  xyh=[list(map(int,input().split())) for _ in [0]*n]
  xx,yy,hh=sorted(xyh,key=lambda x:x[2])[-1]
  for cx in range(101):
    for cy in range(101):
      H=hh+abs(xx-cx)+abs(yy-cy)
      for x,y,h in xyh:
        if max(H-abs(x-cx)-abs(y-cy),0)!=h:
          break
      else:
        print(cx,cy,H) 
        exit()
if __name__=='__main__':
  main()

Measured memory_bytes: 3064
#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++)


int main() {
  string s;
  cin >> s;
  vector<bool>a(26,true);
  
  rep(i,s.size()){
    a.at(s.at(i)-'a')=false;
  }
  bool ex=true;
  
  rep(i,26){
    if(a.at(i)){
      char ans='a'+i;
      cout<<ans<<endl;
      ex=false;
      break;
    }
  }
  if(ex){
    cout<<"None"<<endl;
  }
}





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

using namespace std;

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

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

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a*b/gcd(a,b);
}

int toi(string s){
    int ret = 0;
    rep(i,s.size()){
        ret *= 10;
        ret += s[i]-'0';
    }
    return ret;
}

#define M 60*24+3

int main(void) {
    int i,j;
    int n;
    int days[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
    rep(i,12)days[i+1] += days[i];
    while(cin >> n, n){
        vector<vector<vp> > v(365,vector<vp>(1000));
        rep(i,n){
            string a,b,io,id;
            cin >> a >> b >> io >> id;
            int day = days[toi(a.substr(0,2))-1] + toi(a.substr(3,2));
            int t = toi(b.substr(0,2))*60 + toi(b.substr(3,2));
            v[day][toi(id)].push_back(pii(t,int(io=="O")));
        }
        vi sum(1000,0);
        rep(i,365){
            int god[M] = {};
            rep(k,v[i][0].size()){
                if(v[i][0][k].second) god[v[i][0][k].first]--;
                else god[v[i][0][k].first]++;
            }
            rep(k,M-1)god[k+1] += god[k];
            loop(j,1,1000)if(v[i][j].size()){
                int t[M] = {};
                rep(k,v[i][j].size()){
                    if(v[i][j][k].second) t[v[i][j][k].first]--;
                    else t[v[i][j][k].first]++;
                }
                rep(k,M-1)t[k+1] += t[k];
                rep(k,M)if(god[k]&&t[k])sum[j]++;
            }
        }
        sort(all(sum));
        cout << sum[999] << endl;
    }
}



Measured memory_bytes: 11476
from sys import stdin


def __sum(n):
    return n*(n+1)//2


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N = int(_in[0]) # type:int
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    cnt = __sum(N)-3*__sum(N//3)-5*__sum(N//5)+15*__sum(N//15)
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)


Measured memory_bytes: 61916
S = input()
c0, c1 = 0,0
ans = 0
for ch in S:
  if c0 == 0 and ch == '1':
    c1 += 1
  elif c1 == 0 and ch == '0':
    c0 += 1
  elif ch == '1':
    ans += 2
    c0 -= 1
  else:
    ans += 2
    c1 -= 1
    
print(ans)


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

using namespace std;

typedef long long int ll;

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

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    vector<ll> left(n), right(n); 
    left[0] = a[0];
    right[n - 1] = a[n - 1];
    for(int i = 1; i < n; i++){
        left[i] = gcd(left[i - 1], a[i]);
    }
    for(int i = 1; i < n; i++){
        left[i] = gcd(left[i - 1], a[i]);
    }
    for (int i = n - 2; i >= 0; i--){
        right[i] = gcd(right[i + 1], a[i]);
    }
    ll ans = 0;
    ans = max(right[1], left[n - 2]);
    for(int i = 1; i < n; i++){
        ans = max(ans, gcd(left[i - 1], right[i + 1]));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2560
#include <stdio.h>

int main(void)
{
    int n;
    scanf("%d", &n);
    
    int p, w, g, y;
    p = w = g = y = 0;
    char s;
    for (int i = 0; i < n; i++) {
        scanf("%c", &s);
        if (s == 'P')
            p++;
        else if (s == 'W')
            w++;
        else if (s == 'G')
            g++;
        else if (s == 'Y')
            y++;
    }
    if (y == 0)
        puts("Three");
    else
        puts("Four");
    return 0;
}

Measured memory_bytes: 128
def main(str)
  s = str.split("\n")[1]
  s.scan("ABC").length
end

unless ENV["TEST"]
  puts(main($stdin.read.chomp))
  exit(0)
end

require 'minitest/autorun'

class TestA < Minitest::Test
  def test_main
    assert_equal(2, main("10
ZABCDBABCQ"))
  end
end




Measured memory_bytes: 14352
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
import Control.Monad
import Control.Monad.ST
import Control.Monad.Primitive
import Data.Maybe
import Data.Char
import Data.Array
import Data.Array.ST
import Data.STRef
import Data.List
import Data.STRef
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as MV
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM

cardToIndex ["S",n] = (read n) - 1
cardToIndex ["H",n] = 13 + (read n) - 1
cardToIndex ["C",n] = 26 + (read n) - 1
cardToIndex [_  ,n] = 39 + (read n) - 1


main = do
  n <- readLn :: IO Int
  cards <- replicateM n $ fmap (cardToIndex . words) getLine
  cardList <- V.thaw $ V.fromList [(mark ++ show number) | mark <- ["S ","H ","C ","D "], number <- [1..13]]

  forM_ cards $ \card -> do
    MV.write cardList card ""

  forM_ [0..51] $ \i -> do
    b <- MV.read cardList i
    when ( b /= "") $ do
      putStrLn b



Measured memory_bytes: 4356
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

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

template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v){
    for (auto &e : t) fill(e, v);
}

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }

#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

using pint = pair<int,int>;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N, K;
    while (cin >> N >> K) {
        int ma = (N-1)*(N-2) / 2;
        if (ma < K) cout << -1 << endl;
        else {
            vector<pint> res;
            for (int i = 1; i <= N-1; ++i) res.push_back({i, N});

            int rem = ma - K;
            int ci = 1, cj = 2;
            for (int _ = 0; _ < rem; ++_) {
                res.push_back({ci, cj});

                ++cj;
                if (cj == N) {
                    ++ci;
                    cj = ci + 1;
                }
            }

            cout << res.size() << endl;
            for (auto p : res) cout << p.first << " " << p.second << endl;
        }
    }
}


















Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int r,g,b,n,ans;
int main()
{
	cin>>r>>g>>b>>n;
	for(int i=0;i*r<=n;i++)
	for(int j=0;i*r+j*g<=n;j++)
	if((n-i*r-j*g)%b==0)ans++;
	cout<<ans<<endl;
}

Measured memory_bytes: 256
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

s = LS2()
x,y = MI()

A = []  # 'F'
B = []  # 'T'
r = 0
for i in range(len(s)):
    if i == 0:
        if s[i] == 'F':
            A.append(1)
        else:
            r = 1
            B.append(1)
    else:
        if s[i] == s[i-1]:
            if r == 0:
                A[-1] += 1
            else:
                B[-1] += 1
        else:
            if r == 0:
                B.append(1)
            else:
                A.append(1)
            r = 1-r

C = []  # x軸方向
D = []  # y軸方向
if s[0] == 'F':
    x -= A[0]
    del A[0]
r = 0  # 0ならx軸方向、1ならy軸方向
for i in range(len(A)):
    if (r + B[i]) % 2 == 0:
        C.append(A[i])
        r = 0
    else:
        D.append(A[i])
        r = 1

# Cの各々の元を、1倍か-1倍して全て加えた時にxにできるか
# Dの各々の元を、1倍か-1倍して全て加えた時にyにできるか

if (x+sum(C)) % 2 != 0:
    print('No')
    exit()
x = (x+sum(C)) // 2

if (y+sum(D)) % 2 != 0:
    print('No')
    exit()
y = (y+sum(D)) // 2

if x < 0 or y < 0:
    print('No')
    exit()

# Cの元をいくつか選んで和をとることで、xを作れるか
# Dの元をいくつか選んで和をとることで、yを作れるか

C = [0] + C
from itertools import accumulate
E = list(accumulate(C))
e = 0
if x == 0:
    e = 1
for i in range(1,len(C)):
    for j in range(i,len(C)):
        if E[j] - E[i-1] == x:
            e = 1
if e == 0:
    print('No')
    exit()

D = [0] + D
from itertools import accumulate
F = list(accumulate(D))
f = 0
if y == 0:
    f = 1
for i in range(1,len(D)):
    for j in range(i,len(D)):
        if F[j] - F[i-1] == y:
            f = 1
if f == 0:
    print('No')
else:
    print('Yes')


Measured memory_bytes: 74188
"""
AtCoder :: M-Solutions Programming Contest 2020 :: Marks
https://atcoder.jp/contests/m-solutions2020/tasks/m_solutions2020_c
"""
import sys
from functools import reduce
from operator import add
from math import log


def solve(A, K):
    """Solve puzzle."""
    solns = []
    grade = reduce(add, A[:K])
    for i in range(K, len(A)):
        grade0 = (grade - A[i-K]) + A[i]
        if grade0 > grade:
            solns.append('Yes')
        else:
            solns.append('No')
        grade = grade0
    return(solns)


def main():
    """Main program."""
    N, K = (int(i) for i in sys.stdin.readline().split())
    A = [log(float(i)) for i in sys.stdin.readline().split()]
    print("\n".join(solve(A, K)))


if __name__ == '__main__':
    main()


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


int main(){
  string s;
    cin >> s;
  for(int i=0;i<3;i++){
    if(s[i]=='7') {
      cout << "Yes" << endl;
      return 0;
    }
  }
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3572
#import <stdio.h>
#import <stdlib.h>


double sqrt(double x) {
    double         xHalf = 0.5 * x;
    long long int  tmp   = 0x5FE6EB50C7B537AAl - ( *(long long int*)&x >> 1);//initial guess
    double         xRes  = * (double*)&tmp;
    
    xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
    xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
    xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
    xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
    return xRes * x;
}

int main(){
    int a,b;
    char h[10] = {'\0'};
    scanf("%d %d",&a,&b);
    sprintf(h,"%d%d",a,b);
    int n = atoi(h);
    int r = (int)sqrt((double)n);
    printf(n==r*r ? "Yes":"No");
    return 0;
}


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

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
#define PI 3.14159265359 //πの値
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

 
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll a,b,c,d; cin>>a>>b>>c>>d;
ll ans = max(b*d,max(b*c,max(a*d,a*c)));
cout << ans;
}

Measured memory_bytes: 3608
#include <stdio.h>

int main (void){
  
  long long N;
  
  long long Y;
  
  scanf("%lld %lld", &N, &Y);
  
  long long i, j, k;
  long long p=0, a, b;
  
  for (i=0; i<= N; i++){
    for (j=0; j<= N-i; j++){
      if (10000*i + 5000*j + 1000*(N-i-j) == Y)
      {p=1; a=i; b=j;}
    }
  }
  
  if (p==1) {printf("%lld %lld %lld", a, b, N-a-b);}
  else {printf("%d %d %d", -1, -1, -1);}
  
  return 0;
}

Measured memory_bytes: 1712
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author G. Guarnieri
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            char[] s = in.next().toCharArray();

            int opened = 0;
            int closed = 0;
            StringBuilder outcome = new StringBuilder();
            for (int i = 0; i < n; i++) {
                char current = s[i];
                switch (current) {
                    case '(':
                        outcome.append(current);
                        ++opened;
                        break;
                    case ')':
                        outcome.append(current);
                        if (opened > 0) {
                            --opened;
                        }
                        else {
                            ++closed;
                        }
                        break;
                }
            }
            for (int j = 0; j < closed; j++) {
                outcome.insert(0, '(');
            }

            for (int j = 0; j < opened; j++) {
                outcome.append(')');
            }
            out.println(outcome.toString());
        }

    }
}



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

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)

int main() {
    int n,m,a[110];long long sum=0;
	cin >> n>>m;
    fori(n){cin>>a[i];sum+=a[i];}
    sort(a,a+n,greater<int>());
    fori(m){
        if(a[i]*4*m<sum){
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
	return 0;
}

Measured memory_bytes: 256
#pragma region ヘッダー
#define _CRT_SECURE_NO_WARNINGS

#ifdef _____MY_DEBUG_____
#define VS_ENDPAUSE()	(system("pause"))
#define DEBUG_OUT(...)  (printf(__VA_ARGS__))
#else
#define VS_ENDPAUSE()
#define DEBUG_OUT(...)
#endif

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>

using namespace std;
typedef signed char int8;
typedef signed short int16;
typedef signed int int32;
typedef signed long long int64;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef unsigned long long uint64;
//#define int int64

#ifndef INT8_MIN
#define INT8_MIN	(-127)
#endif
#ifndef INT8_MAX
#define INT8_MAX	( 128)
#endif
#ifndef UINT8_MAX
#define UINT8_MAX	( 255)
#endif
#ifndef INT16_MIN
#define INT16_MIN	(-32768)
#endif
#ifndef INT16_MAX
#define INT16_MAX	( 32767)
#endif
#ifndef UINT16_MAX
#define UINT16_MAX	( 65535)
#endif
#ifndef INT32_MIN
#define INT32_MIN	(-2147483648)	// -2 * 10^9
#endif
#ifndef INT32_MAX
#define INT32_MAX	( 2147483647)	//  2 * 10^9
#endif
#ifndef UINT32_MAX
#define UINT32_MAX	( 4294967295)	//  4 * 10^9
#endif
#ifndef INT64_MIN
#define INT64_MIN	(-9223372036854775808)	// -9 * 10^18
#endif
#ifndef INT64_MAX
#define INT64_MAX	( 9223372036854775807)	//  9 * 10^18
#endif
#ifndef UINT64_MAX
#define UINT64_MAX	( 18446744073709551615)	// 18 * 10^18
#endif

void func(void);
#pragma endregion

int32 main(void)
{
    func();
    VS_ENDPAUSE();
    return 0;
}

//DEBUG_OUT("----\n");
void func(void)
{
    string s;
    cin >> s;

    int aCnt = 0;
    int bCnt = 0;
    int cCnt = 0;
    for(int i=0; i<s.size(); i++){
        if(s[i] == 'a'){ aCnt++; }
        if(s[i] == 'b'){ bCnt++; }
        if(s[i] == 'c'){ cCnt++; }
    }

    int n = min(aCnt, min(bCnt, cCnt));
    aCnt -= n;
    bCnt -= n;
    cCnt -= n;

    vector<int> v(3);
    v[0] = aCnt;
    v[1] = bCnt;
    v[2] = cCnt;
    sort(v.begin(), v.end());


    if((v[0]==0 && v[1]==0 && v[2]==0)
    || (v[0]==0 && v[1]==0 && v[2]==1)
    || (v[0]==0 && v[1]==1 && v[2]==1)
    ){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int firstIndex = S.indexOf("A");
		int lastIndex = S.lastIndexOf("Z");
		System.out.println(S.substring(firstIndex, lastIndex + 1).length());
		sc.close();
	}
}

Measured memory_bytes: 26660
import sys
import math

INF = 10**9+7

stdin = sys.stdin
def na(): return map(int, stdin.readline().split())
def ns(): return stdin.readline().strip()
def nsl(): return list(stdin.readline().strip())
def ni(): return int(stdin.readline())
def nil(): return list(map(int, stdin.readline().split()))

o = ns()
e = ns()

ans = []
for i in range(len(e)):
    ans.append(o[i])
    ans.append(e[i])

if(len(o) - len(e) == 1):
    ans.append(o[-1])

print(''.join(ans))

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include<algorithm>
#include <stdio.h>
using namespace std;



int main() {
	string s;
	char a='0',b='0';
	cin >> s;
	bool frag1=false,frag2=false;
	for (int i = 0; i < 4; i++) {
		if (a == '0') {
			a = s[i];
		}
		else if (b == '0'&&s[i]!=a) {
			b = s[i];
		}
		else if (s[i] == a) {
			frag1 = true;
		}
		else if (s[i] == b) {
			frag2 = true;
		}
		
	}
	if (frag1==true&&frag2 == true) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,x,s=0,y;
	scanf("%d%d%d%d",&a,&b,&c,&x);
	for(int i=0;i<=a;i++)
	for(int j=0;j<=b;j++)
	for(int k=0;k<=c;k++)
	{
		y=500*i+100*j+50*k;
	    if(y==x)    
	    s++;
	    if(y>x)
	    break;   
	}
	printf("%d",s);  
	return 0;      
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;
//debug 
#ifdef _DEBUG
#define debug(var)  do{cout << #var << " :";view(var);}while(0)
#else
#define debug(...)
#endif
template<typename T> void view(T e){cout << e << endl;}
template<typename T> void view(const vector<T>& v){for(const auto& e : v){ cout << e << " "; } cout << endl;}
template<typename T> void view(const vector<vector<T> >& vv){ for(const auto& v : vv){ view(v); } }


int main(){
  int n, m, X, Y;
  cin >> n >> m >> X >> Y;
  vector<int> x;
  x.push_back(X);
  vector<int> y;
  y.push_back(Y);

  REP(i,n){
    int xx;
    cin >> xx;
    x.push_back(xx);
  }
  REP(i,m){
    int yy;
    cin >> yy;
    y.push_back(yy);
  }

  sort(RALL(x));
  sort(ALL(y));
  if(x[0] < y[0]) cout << "No War" << endl;
  else cout << "War" << endl;
  return 0;
}

Measured memory_bytes: 3608
import string
N = int(input())
S = list(input())

al = list(string.ascii_uppercase)
ans = []
for i in S:
    pos = al.index(i) + N
    if pos < 26:
        ans.append(al[pos])
    else:
        ans.append(al[pos-26])
print(''.join(ans))

Measured memory_bytes: 3832
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

//解説の「比較的容易に」にハラスメントを感じる

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


	int N;
	cin >> N;
	int A[200000];
	int ichi = 1;
	int maeichi = 0;
	rep(i, N) {
		cin >> A[i];
		if (maeichi >= A[i]) ichi = 0;
		maeichi = A[i];
	}
	if (ichi) {
		co(1);
		return 0;
	}

	int L = 2;
	int R = N;
	while (L < R) {
		int H = (L + R) / 2;
		map<int, int> MP;
		int mae = 0;
		rep(i, N) {
			int k = A[i];
			if (mae >= k) {
				auto itr = MP.upper_bound(k);
				MP.erase(itr, MP.end());
				if (MP[k] == 0) MP[k] += 2;
				else MP[k] += 1;
				while (k >= 0 && MP[k] > H) {
					MP[k] = 1;
					if (MP[k - 1] == 0) MP[k - 1] += 2;
					else MP[k - 1] += 1;
					k--;
				}
			}
			else {
				MP[k] = 1;
			}
			mae = k;
		}
		if (MP.find(0) == MP.end()) R = H;
		else L = H + 1;
	}

	co(L);

	Would you please return 0;
}

Measured memory_bytes: 3840
import bisect
import collections
import copy
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
input = sys.stdin.readline
sys.setrecursionlimit(10**9)
MOD = 10**9+7

#nCrは以下のやつ全てを使ってください
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]
 
gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]
 
def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

def nPr(n,r):
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

N,K = map(int,input().split())
if K >= N:
    M = N
else:
    M = K

ans = 0
for i in range(1,M+1):
    ans += nCr(N,i) * nCr(N-1,i)
    ans %= MOD
print(ans+1)

Measured memory_bytes: 93052