akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
using Graph = vector<vector<int> >;
using GraphC = vector<vector<char> >;
const int INF = 1000000000;
typedef pair<int, int> P;
const int MAX_N = 1000000;
typedef int64_t ll;
template<class T> inline bool chmax(T & a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T & a, T b) { if (a > b) { a = b; return 1; } return 0; }




int main() {
	int N, D;
	cin >> N >> D;
	Graph Z(N, vector<int>(D));
	rep(i, N) {
		rep(j, D) {
			cin >> Z.at(i).at(j);
		}
	}
	
	int ans = 0;
	for (int i = 0; i <	N-1; i++)
	{
		for (int j = i+1; j < N; j++)
		{
			int norm = 0;
			for (int k = 0; k < D; k++)
			{
				int tmp = Z.at(i).at(k) - Z.at(j).at(k);
				norm += tmp * tmp;
			}

			bool flag = false;
			for (int m = 0; m*m<= norm; m++)
			{
				if (m*m==norm)
				{
					flag = true;
				}
			}
			if (flag)++ans;
		}
		
	}
	cout << ans << endl;
}

Measured memory_bytes: 3520
#include <stdlib.h>
#include<iostream>
#include<bits/stdc++.h>
#include<cmath>
#define ll long long
const int INF=0x3f3f3f3f;
#define mod 1000000007
using namespace std;
//priority_queue
ll a[2003],b[2003];
ll dp[2003][2003];
int main()
{
int n,m,x,y;cin>>n>>m>>x>>y;
 cout<<1.0*n*m/2<<" ";
 if(1.0*x==1.0*n/2&&1.0*y==1.0*m/2)
    cout<<1<<endl;
 else cout<<0<<endl;
}



Measured memory_bytes: 256
n,m,k=map(int,input().split())
mod=998244353
if m==1:print(0 if k!=n-1 else 1);exit()
fact=[1]*(n-1+1)
inv=[1]*(n-1+1)
for i in range(2,n-1+1):
    fact[i]=i*fact[i-1]%mod
inv[-1]=pow(fact[-1],mod-2,mod)
for i in range(n-1,1,-1):
    inv[i-1]=inv[i]*i%mod
ans=0
po=pow(m-1,n-1,mod)*m%mod
ue=fact[n-1]
iii=pow(m-1,mod-2,mod)%mod
for i in range(k+1):
    ans+=ue*inv[n-1-i]%mod*inv[i]%mod*po%mod
    po*=iii
    po%=mod
print(ans%mod)


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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define endl        "\n"
#define repp(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a,b) 	for(int i=a;i<=b;i++)
#define IOS         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int N=1e5 + 5;
const int M=1e9 + 7;

int32_t main()
{
	IOS;
	//memset(dp,-1,sizeof(dp));	
	int T;
	T=1;
	while(T--)
	{
		int n;
		cin >> n;
		string s;
		cin >> s;
		int ans=0;
		rep(i,0,n-3)
		{
			if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')
			{
				ans++;
			}
		}
		cout << ans << endl;
	}
}


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

const int N = 200005, M = 21, inf = (int)2e9;

int n, k, q, x[N];
int fa1[N][M], fa2[N][M], Log2[N];
long long val1[N][M], val2[N][M];
int main() {
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; i++) scanf("%d", &x[i]);

	x[0] = -inf, x[n + 1] = inf;
	fa1[n + 1][0] = n + 1, fa2[0][0] = 0;
	val1[n + 1][0] = 0, val2[0][0] = 0;
	Log2[1] = 0;
	for (int i = 2; i <= n; i++) Log2[i] = Log2[i >> 1] + 1;
	for (int i = 1; i <= n; i++) {
		fa1[i][0] = lower_bound(x + 1, x + n + 1, x[i] + k) - x;
		fa2[i][0] = upper_bound(x + 1, x + n + 1, x[i] - k) - x - 1;
		val1[i][0] = i, val2[i][0] = i + 1;
	}
	for (int i = 1; i <= Log2[n]; i++) {
		for (int j = 1; j <= n + 1; j++) {
			fa1[j][i] = fa1[fa1[j][i - 1]][i - 1];
			val1[j][i] = val1[j][i - 1] + val1[fa1[j][i - 1]][i - 1];
		}
		for (int j = 0; j <= n; j++) {
			fa2[j][i] = fa2[fa2[j][i - 1]][i - 1];
			val2[j][i] = val2[j][i - 1] + val2[fa2[j][i - 1]][i - 1];
		}
	}

	scanf("%d", &q);
	for (int i = 1; i <= q; i++) {
		int l, r, L, R;
		long long ans = 0;
		scanf("%d%d", &l, &r);
		L = l, R = r;
		for (int j = Log2[n - l + 1]; j >= 0; j--) {
			if (fa1[L][j] <= r) ans -= val1[L][j], L = fa1[L][j];
		}
		ans -= val1[L][0];
		for (int j = Log2[r]; j >= 0; j--) {
			if (fa2[R][j] >= l) ans += val2[R][j], R = fa2[R][j];
		}
		ans += val2[R][0];
		printf("%lld\n", ans);
	}
	return 0;
}

Measured memory_bytes: 103816
n = int(input())
lh = [int(w) for w in input().split()]

ans = 0
t = 0
for i in range(1, n):
    # print(t, end=" ")
    if lh[i] <= lh[i - 1]:
        t += 1
        ans = max(ans, t)
    else:
        ans = max(ans, t)
        t = 0

print(ans)


Measured memory_bytes: 20044
import java.util.*;

class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	int a,b,c ;
      	a = sc.nextInt();
        b = sc.nextInt();
        c = sc.nextInt();
      	if(a != b && b != c && c != a){
        System.out.println(3);
        }else if( a==b && b==c && c==a){
          System.out.println(1);
        }else{
        System.out.println(2);
        }
    }	
}

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

template <class T>
inline int read (T & x) {
  static char ch; static bool neg;
  for (ch = neg = 0; ch < '0' || '9' < ch; neg |= ch == '-', ch = getchar());
  for (x = 0; '0' <= ch && ch <= '9'; (x *= 10) += ch - '0', ch = getchar());
  return (x = neg ? -x : x);
}

#define lint long long

const int N = 1e6 + 10;

int a[N];
lint sum[N];

int main (void) {
	int n, m, v, p;
	read(n); read(m); read(v); read(p);
	for (int i = 1; i <= n; i++)
		read(a[i]);
	sort(a + 1, a + n + 1, [](int x, int y){ return x > y; });

	for (int i = 1; i <= n; i++)
		sum[i] = sum[i - 1] + a[i];
	for (int i = p + 1; i <= n; i++) {
		if (a[i] == a[i - 1]) continue;
		lint s = 1ll * (i - p) * (a[i] + m) - (sum[i - 1] - sum[p - 1]);
		lint vv = max(0, v - (n - i + 1) - (p - 1));
		// cout << i << " " << s << " " << vv << endl;
		if (vv == 0) {
			if (a[p] <= a[i] + m) continue;
			printf("%d\n", i - 1);
			return 0;
		} else {
			if (s >= m * vv && a[p] <= a[i] + m) continue;
			printf("%d\n", i - 1);
			return 0;
		}
	}
	printf("%d\n", n);
}

Measured memory_bytes: 5120
import heapq
N, M = map(int, input().split())
A = list(map(int, input().split()))
ls = []
for item in A:
  heapq.heappush(ls, -item)
for m in range(M):
  tmp = -heapq.heappop(ls)
  tmp = tmp // 2
  heapq.heappush(ls, -tmp)
print(-sum(ls))


Measured memory_bytes: 20232
year,month,day = input().split('/')
year = int(year)
month = int(month)
dau = int(day)

if year < 2019:
    print('Heisei')
elif year == 2019:
    if month <= 4:
        print('Heisei')      
    else:
        print('TBD')
else:
    print('TBD')

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;


int main()
{
  int N, Ma, Mb; scanf("%d %d %d", &N, &Ma, &Mb);
  vector<int> A(N + 5), B(N + 5), C(N + 5);
  for (int i = 1; i <= N; ++i) {
    scanf("%d %d %d", &A[i], &B[i], &C[i]);
  }

  vector<vector<vector<int>>> dp(45, vector<vector<int>>(450, vector<int>(450, INF)));
  dp[0][0][0] = 0;
  for (int i = 1; i <= N; ++i) {
    for (int a = 0; a <= 400; ++a) {
      for (int b = 0; b <= 400; ++b) {
        dp[i][a][b] = min(dp[i][a][b], dp[i - 1][a][b]);
        dp[i][a + A[i]][b + B[i]] = min(dp[i][a + A[i]][b + B[i]], dp[i - 1][a][b] + C[i]);
      }
    }
  }

  int ans = INF;
  for (int a = 1; a <= 400; ++a) {
    for (int b = 1; b <= 400; ++b) {
      if (a * Mb == b * Ma) {
        ans = min(ans, dp[N][a][b]);
      }
    }
  }
  if (ans == INF) { ans = -1; }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 37248
# https://atcoder.jp/contests/abc095/tasks/abc095_b
# 2020/02/15
import sys
input = sys.stdin.readline

def main():
    n, x = map(int, input().split())
    amounts = [int(input()) for _ in range(n)]
    remain = x - sum(amounts)
    print(n + remain // min(amounts))

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

struct edge { int to; int cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int MOD = 1e9+7;
const double EPS = 1.0e-12;
const double PI = acos(-1.0);
 
const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

int dp[500010];

int main(){
	int n;
	cin >> n;
	vi h(n);
	rep(i,n) cin >> h[i];
	rep(i,500010) dp[i] = INF;
	dp[0] = 0;
	for(int i = 0; i < n; i++){
		if(i+1 < n) dp[i+1] = min(dp[i+1],dp[i]+abs(h[i]-h[i+1]));
		if(i+2 < n) dp[i+2] = min(dp[i+2],dp[i]+abs(h[i]-h[i+2]));
	}
	cout << dp[n-1] << endl;

	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>
#include <iomanip>
#include <unordered_map>
#include <map>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
typedef long double ld;
const char sp = ' ';

using namespace boost::multiprecision;
using namespace std;

int main(void){
    ll N, M;
    cin>>N>>M;
    if(N*2>=M) cout<<M/2<<endl;
    else{
        cout<<(N*2+M)/4<<endl;
    }
    return 0;
}


Measured memory_bytes: 3572
S = list(input())

if "S" in S:
    if S[1] == "S" and (S[0] != "S" or S[2] != "S"):
        print(1)
    elif S[0] == "S" and S[1] == "S" and S[2] == "S":
        print(0)
    elif S[1] == "R" and S[0] != "R" and S[2] != "R":
        print(1)
    else:
        print(2)
else:
    print(3)

Measured memory_bytes: 9124
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<float.h>

using namespace std;
#define ll long long


int main(void){
    string s;
    vector<string> change(0);
    cin>>s;
    ll SIZES=s.size();
    s+="GGG";
    ll i=0;
    while(i<SIZES){
        if(s.at(i)!='A') i++;
        else{
            string total="A";
            i++;
            bool check=true;
            while(check){
                if(s.at(i)=='B' && s.at(i+1)=='C'){
                    total+="X";
                    i+=2;
                }
                else if(s.at(i)=='A'){
                    total+="A";
                    i++;
                }
                else{
                    change.push_back(total);
                    check=false;
                }
            }
        }
    }
    ll ans=0;
    for(ll i=0;i<change.size();i++){
        string youso=change.at(i);
        ll asum=0;
        for(ll j=0;j<youso.size();j++){
            if(youso.at(j)=='A') asum++;
            else ans+=asum;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 2684
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>

using namespace std;

int main()
{
   string x;
   cin>>x;
   if(x[0]==x[1]&&x[1]==x[2]){
      cout<<"No"<<endl;
   }else{
      cout<<"Yes"<<endl;
   }
   

}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int MAXN = 123456;
int freq[MAXN];

int main() {
    int N;
    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        int tmp;
        scanf("%d", &tmp);
        freq[tmp]++, freq[tmp - 1]++, freq[tmp + 1]++;
    }
    int ans = 0;
    for (int i = 1; i < MAXN; i++) ans = max(ans, freq[i]);
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int main() {
  ll n;cin>>n;
  ll res=0;
  ll tmp=1;
  while(true){
      ll buf=n-tmp;
      if(buf/tmp<=tmp) break;
      if(buf%tmp==0){
          res+=buf/tmp;
      }
      tmp++;
  }
  cout<<res<<endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
signed main(){
    ll N;cin>>N;
    REP(n,1,N+1){
        ll cnt=0;
    REP(i,1,101){
        REP(j,1,101){
            if(4*n<3*i*i+2*i*j+3*j*j)continue;
            if((double)sqrt(4*n-(3*i*i+2*i*j+3*j*j))==(ll)sqrt(4*n-(3*i*i+2*i*j+3*j*j))){
                ll z=sqrt(4*n-(3*i*i+2*i*j+3*j*j));
                z-=i+j;
                if(z>=2&&z%2==0)cnt++;
            }
        }
    }
    cout<<cnt<<endl;
    }
}

Measured memory_bytes: 3516
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<vector>
#define pa pair<int,int>
 
using namespace std;

const int MAXN=1000010;
int dis[MAXN];
vector <pa> g[MAXN];
vector <int> new_g[MAXN],all[MAXN];
int visit[MAXN],ptr[MAXN];
queue <int> q;
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++)
	{
		int u,v,c;
		scanf("%d%d%d",&u,&v,&c);
		u--,v--;
		g[u].push_back(make_pair(c,v));
		g[v].push_back(make_pair(c,u));
		all[c].push_back(u);
		all[c].push_back(v);
	}
	for (int i=0;i<n;i++)
	{
		sort(g[i].begin(),g[i].end());
		visit[i]=-1;
	}
	int newn=n;
	for (int i=0;i<MAXN;i++)
	{
		if (all[i].empty())
		{
			continue;
		}
		for (int it=0;it<all[i].size();it++)
		{
			int v=all[i][it];
			if (visit[v]==i)
			{
				continue;
			}
			q.push(v);
			visit[v]=i;
			while (!q.empty())
			{
				int x=q.front();
				q.pop();
				while (ptr[x]<(int)g[x].size())
				{
					int c=g[x][ptr[x]].first;
					if (c!=i)
					{
						break;
					}
					int u=g[x][ptr[x]].second;
					if (visit[u]!=i)
					{
						visit[u]=i;
						q.push(u);
					}
					ptr[x]++;
				}
				new_g[x].push_back(newn);
				new_g[newn].push_back(x);	
			}
			newn++;
		}
	}
	for (int i=0;i<newn;i++)
	{
		dis[i]=-2;
	}
	q.push(0);
	dis[0]=0;
	while (!q.empty())
	{
		int x=q.front();
		q.pop();
		for (int i=0;i<new_g[x].size();i++)
		{
			int u=new_g[x][i];
			if (dis[u]==-2)
			{
				dis[u]=dis[x]+1;
				q.push(u);	
			}
		}
	}
	cout<<dis[n-1]/2;
    return 0;
}

Measured memory_bytes: 100096
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
#define inf 1000000007

int main(void){
   string s;
   int k;
   cin >> s; cin >> k;
   int nagasa = 1;
   int count = 0;
   string ans[50000];
   while(nagasa<=k&&nagasa<=s.length()){
       for(int i = 0; i <= s.length()-nagasa; i++){
           ans[count]=s.substr(i, nagasa);
           count++;
       }
        nagasa++;
   }
   sort(ans, ans+count);
   int check=0;
   for(int i = 0; i < count; i++){
    if(ans[i]!=ans[i+1])
        check++;
    if(check==k){
        cout << ans[i] << endl;
        break;
    }
   }
    return 0;
}

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    int N, K; cin >> N >> K;
    double prb = 0.0;
    for(int i=1; i<=N; i++){
        ll me = i;
        int coinn = 0;
        while(me < K){
            me *= 2;
            coinn++;
        }
        prb += pow(0.5, coinn) / N;
    }
    printf("%.10lf\n", prb);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define f(i,a,b) for(ll i=a;i<b;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ii pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define MAX 1e9

ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}
const ld pi=acos(-1);

int main(){
    IOS;
    ll a,b;cin>>a>>b;
    cout<<max({a+b,a-b,a*b});
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var abk = Console.ReadLine().Split().Select(int.Parse).ToArray();

            var ansList = new List<int>();

            for(int i=0;i<abk[2];i++)
            {
                ansList.Add(abk[0]+i);
            }
            for(int i = -abk[2]+1;i<=0;i++)
            {
                ansList.Add(abk[1]+i);
            }

            foreach (var item in ansList.Where(x =>x >= abk[0] && x<=abk[1]).Distinct())
            {
                Console.WriteLine(item);
            }
        }
    }
}


Measured memory_bytes: 13396
N, T = map(int,input().split())
c = []
t = []

for i in range(N):
  c1, t1 = map(int,input().split())
  c.append(c1)
  t.append(t1)
  
ans = []

for i in range(N):
  if t[i] <= T:
    ans.append(c[i])

if len(ans) == 0:
  print("TLE")
else:
  print(min(ans))


Measured memory_bytes: 3060
#include <stdio.h>

#define N 100

int main(void){
  int i, k = 0, value[N+1];

  for(i = 1; i <= N; i++){
    value[i] = 0;
  }
  while(scanf("%d", &i) != EOF){
    value[i]++;
    if(value[i] > k)  k=value[i];
  }
  for(i = 1; i <= N; i++){
    if(value[i] == k){
      printf("%d\n", i);
    }
  }
  return 0;
}

Measured memory_bytes: 596
#include <iostream>

using namespace std;
typedef long long ll;

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

    ll ret = 0;
    for (int i = 1; i <= n; i++)ret += i * (n - i + 1);

    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        if (u > v)swap(u, v);
        ret -= u * (n - v + 1);
    }

    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;
using pll=pair<ll,ll>;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
vector<vector<int> > G(110, vector<int>());

int main() {
	int N;
	cin >> N;
	int u,k;
	rep(i,N) {
		cin >> u >> k;
		u--;
		G[u] = vector<int>(k);
		rep(j,k) cin >> G[u][j], G[u][j]--;
	}

	queue<int> q;
	vector<int> dist(N, 1e9);
	dist[0] = 0;
	q.push(0);
	while(!q.empty()) {
		int p = q.front();
		q.pop();
		for(auto k : G[p]) {
			if(dist[k] > dist[p] + 1) {
				dist[k] = dist[p] + 1;
				q.push(k);
			}
		}
	}
	rep(i,N) if(dist[i] == 1e9) dist[i] = -1;
	rep(i,N) cout << i+1 << " " << dist[i] << endl;


  return 0;
}


Measured memory_bytes: 3108
import numpy as np

n = input()
r = len(n)
n = int(n)
kouho = []
pre = [""]

for i in range(r):
    pro = []
    for temp in pre:
        kouho.append(temp+"3")
        kouho.append(temp+"5")
        kouho.append(temp+"7")
        pro.append(temp+"3")
        pro.append(temp+"5")
        pro.append(temp+"7")
    pre = pro

def ctit(s):
    a = 0
    b = 0
    d = 0
    for c in s:
        if c == "3":
            a += 1
        elif c == "5":
            b += 1
        else:
            d += 1
    if a > 0 and b > 0 and d > 0:
        return True
    else:
        return False

ans = 0
for temp in kouho:
    if int(temp) <= n:
        if ctit(temp):
            ans += 1

print(ans)

Measured memory_bytes: 22424
using System;
class Program
{
	static void Main()
	{
    int c = 0;//チェック済みの文字数
	string s = Console.ReadLine();
    string check;
      
      while(true)
      {
      
      int loop = 0;
        for(int j = 4;j <= 6;j++)
        {
         check = "";
     	 for(int i = j;i>=0;i--)
     	 {
           if(s.Length-i-c-1 >= 0)
     	   check += s[s.Length-i-c-1];
     	 }
      if(check == "dream")c+=5;
      else if(check == "erase")c+=5;
      else if(check == "eraser")c+=6;
      else if(check == "dreamer")c+=7;
      else if(c == s.Length)
      	 {
     	  loop = 100;
     	 }
      else loop ++;
        }
        if(loop == 3)
          {
     	  Console.WriteLine("NO");
     	  break;
     	  }
        if(loop >= 10)
          {
     	  Console.WriteLine("YES");
     	  break;
     	  }
      }
        

	}
}

Measured memory_bytes: 15328
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int n;
    cin >> n;

    bool f = true;
    map<int, int> mp;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        mp[a]++;
        if (mp[a] > 1) {
            f = false;
        }
    }

    if (f) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }

    return 0;
}

Measured memory_bytes: 9600
fun main(args: Array<String>){
    val input = readLine()!!.toLong()
    var res = 0L
    for (i in 1 until input + 1) {
        if (i % 3L != 0L && i % 5L != 0L) {
            res += i
        }
    }
    println(res)
}

Measured memory_bytes: 34512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#include <numeric>
#include <functional>
#include <stack>
#include <map>

int main (){
	int r, g, b, n;

	std::cin >> r >> g >> b >> n;

	int count = 0;
	for (int i = 0; i <= 3000; i++)
	{
		for (int j = 0; j <= 3000; j++)
		{
			if ((n - (r * i + g * j)) >= 0 && (n - (r * i + g * j)) % b == 0) {
				count++;
			}
		}
	}

	std::cout << count << std::endl;

	return 0;
}

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

int main() {
	int N, max = 0;
	cin >> N;
	vector<vector<int> > data(2, vector<int>(N));

  	for (int i = 0; i < 2; i++) {
    	for (int j = 0; j < N; j++) {
      		cin >> data.at(i).at(j);
    	}
  	}

  	for (int i = 0; i < N; i++) {
  		int total = 0; 
  		for(int j = 0; j < i+1; j++){
  			total += data.at(0).at(j);
  		}
  		for(int j = i; j < N; j++){
  			total += data.at(1).at(j);
  		}
  		if(max < total) max = total;
  	}
  	cout << max << endl;
}

Measured memory_bytes: 256
#include <utility>
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
#define REP(i,n) for(int i=0;i<n;i++)
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
using namespace std;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
    int A,B;
    cin >> A >> B;
    int ans = A*B - (A+B-1);

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

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>
using namespace std;
 
 struct array_p{
     unsigned long value;
     int index;
 };

bool operator<(const array_p &l, const array_p &r){
     return l.value > r.value;
}

int main() {
    int n;
    unsigned long count=0;
    struct array_p *p;
    cin >> n;
    p=new array_p[n];
    set<array_p> st_p;
    multiset<int> s;
    for(int i=0;i<n;i++){
        cin >> p[i].value;
        p[i].index = i;
        st_p.insert(p[i]);
    }
    s.insert(-1);
    s.insert(-1);
    s.insert(n);
    s.insert(n);
    for (auto itr=st_p.begin(); itr!=st_p.end(); itr++){
        int i=(*itr).index;
        auto insrt = s.insert(i);
        auto back = insrt;
        auto go = insrt;
        int w=*(--back);
        int x=*(--back);
        int y=*(++go);
        int z=*(++go);
        count+=((w-x)*(y-i)+(i-w)*(z-y))*(*itr).value;
    }
    cout << count <<endl;
    return 0;
}

Measured memory_bytes: 12800
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <set>

int main()
{
    int64_t N, M;
    std::cin >> N >> M;
    std::multimap<int64_t, int64_t> D;
    for (size_t m = 0; m < M; ++m)
    {
        int64_t a, b;
        std::cin >> a >> b;
        D.emplace(a, b);
        D.emplace(b, a);
    }

    std::set<int64_t> S = { 1 };
    std::map<int64_t, int64_t> R;

    while (true)
    {
        std::set<int64_t> S2;
        for (auto s : S)
        {
            auto range = D.equal_range(s);
            for (auto& i = range.first ; i != range.second; ++i)
            {
                S2.emplace(i->second);
                R.emplace(i->second, s);
            }
            D.erase(s);
        }
        S = S2;
        if (S.empty()) {
            break;
        }
    }

    if (R.size() == N)
    {
        R.erase(1);
        std::cout << "Yes" << std::endl;
        for (auto& r : R)
        {
            std::cout << r.second << std::endl;
        }
    }
    else {
        std::cout << "No" << std::endl;
    }

    return 0;
}


Measured memory_bytes: 39456
from math import log2, ceil
from collections import defaultdict

N = int(input())
A = sorted(list(map(int, input().split())))[::-1]

cnt = defaultdict(int)
for a in A:
  cnt[a] += 1

answer = 0
for a in A:
  if cnt[a]:
    if ceil(log2(a)) == log2(a):
      i = (1 << (ceil(log2(a)) + 1)) - a
    else:
      i = (1 << ceil(log2(a))) - a

    if i != a:
      if cnt[i]:
        cnt[a] -= 1
        cnt[i] -= 1
        answer += 1
    else:
      if cnt[i] > 1:
        cnt[a] -= 2
        answer += 1
        
print(answer)

Measured memory_bytes: 56500
a, b, c, d = map(int, input().split())

# 掛け算が負になるなら最も0に近い数が解
# 正になる組み合わせが存在するなら最も大きい数
ac = a*c
ad = a*d
bc =b*c
bd=b*d

t = max([ac, ad, bc, bd])
print(t)



Measured memory_bytes: 9192
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;


using ll = long long;

//#define int ll


const int N = 2e5 + 11, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 1e5 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 2e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-4;
const double PI = acos(-1.0);


template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }


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


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n, k, p[N];
double prob[N], pref[N], ans;
main() {
    file("threesum");
    ios;
    cin >> n >> k;
    fo(i, 1, n, 1) {
        cin >> p[i];
        fo(j, 1, p[i], 1) prob[i] += j * 1.0 / (p[i]);
        pref[i] = pref[i - 1] + 0.0 + prob[i];
    }
    fo(l, 1, n - k + 1, 1) {
        int r = l + k - 1;
        chmax(ans, pref[r] - pref[l - 1]);
    }
    cout << fixed << setprecision(12) << ans;
    cerr << "\nTime elapsed: " << (clock() + 0.0) / CLOCKS_PER_SEC;
    return 0;
}
/**

*/


Measured memory_bytes: 4224
import java.util.Arrays;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc=new Scanner(System.in);


		//参加者
		int N=sc.nextInt();
		//所持ポイント数
		int K=sc.nextInt();
		//正解の回数
		int Q=sc.nextInt();
		int[] arrayAnsCount=new int[Q];
		int[] arrayPoint=new int[N];


		//各回答者と持ちポイント数
		int intervalValue=K-Q;
		Arrays.fill(arrayPoint, intervalValue);

		//Qは問題数
		for(int i=0;i<arrayAnsCount.length;i++) {
			//正解者
			arrayAnsCount[i]=sc.nextInt();
			arrayPoint[arrayAnsCount[i]-1]=arrayPoint[arrayAnsCount[i]-1]+1;	
		}


		for(int i=0;i<N;i++) {
			if(arrayPoint[i]>0) {
				System.out.println("Yes");
			}else {
				System.out.println("No");
			}
		}

	}

}

Measured memory_bytes: 70432
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = 0;
		// 文字列の入力
		int[] d = new int[a];
		int[] e = new int[a];
		for(int i = 0; i < a; i++){
			d[i] = sc.nextInt();
			e[i] = d[i];
			if(c < d[i]){
				c = d[i];
			}
		} 
					int ok = c;
					  int no = -1;
					  int s;
					  int r = 0;
                  while(ok - 1 != no){
					s = (ok + no) / 2;
                    r = 0;
					for(int i = 0; i < a; i++){
						d[i] = e[i];
					}
					  for(int i = 0; i < a; i++){
						  for(int j = 0;d[i] > s;j++){
							  d[i] = d[i] / 2;
							r++;
						  }
					  }
                  	if(r < b + 1){
                    	ok = s;
                    }else{
                    	no = s;
                    }
                  }
		
		int f = ok - ok / 2;
      r = 0;
		for(int i = 0; i < a; i++){
			for(int j = 0;e[i] > ok;j++){
				e[i] = e[i] / 2;
			  r++;
			}
		}
		long g = 0;
		for(int i = 0; i < a; i++){
			g += e[i];
          //System.out.println(e[i]);
		}
		System.out.println(g - f * (b - r));
      //System.out.println(f * (b - r));
      //System.out.println(g);
      
		
		
	}
}

Measured memory_bytes: 60252
#include <stdio.h>
int main( void ) {
 long a,b,r,t,x,y;
 while(
 scanf("%ld %ld",&a,&b ) != EOF ) {
 x = a; y = b; if( a < b ){
 t = b; b = a; a = t; }
 r = a % b; while(r != 0){
 a = b; b = r; r = a % b; }

 printf("%ld %ld\n",b, x/b*y); }

 return 0;
} 


Measured memory_bytes: 2028
#include<bits/stdc++.h>
using namespace std;
#define  FIO        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define  all(v)     v.begin(),v.end()
#define  rall(v)    v.rbegin(),v.rend()
#define  MEM(a,x)   memset(a,x,sizeof(a))
#define  pi         acos(-1.0)
#define  ll     long long
#define  pb     push_back
#define  mp     make_pair
#define  pii    pair< int,int >
#define  pll    pair< ll,ll >
#define  vii    vector< int >
#define  vll    vector< ll >
#define  vpi    vector< pii >
#define  vpl    vector<pll>
#define  MX     100005
#define  EPS    1e-12
#define  ss     second
#define  ff     first
int cases=1;
#ifdef ppqq
     #define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template < typename Arg1 >
    void __f(const char* name, Arg1&& arg1){
        cerr << name << " is " << arg1 << std::endl;
    }
    template < typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names+1, ',');
        cerr.write(names, comma - names) << " is " << arg1 <<"  ";
        __f(comma+1, args...);
    }
#else
    #define debug(...)
#endif
///******************************************START******************************************
const int N=2e3+3;
vpl v;
ll dp[N][N];
ll rec(ll pos,ll lft,ll rgt)
{
    if(lft>rgt) return 0LL;
    if(dp[lft][rgt]!=-1) return dp[lft][rgt];
    ll l=abs(lft-v[pos].ss)*v[pos].ff + rec(pos+1,lft+1LL,rgt);
    ll r=abs(rgt-v[pos].ss)*v[pos].ff + rec(pos+1,lft,rgt-1LL);
    return dp[lft][rgt]=max(l,r);
}
int main()
{
   //freopen ("output.txt","w",stdout);
   //freopen ("input.txt","r",stdin);
    FIO;
    ll n;
    MEM(dp,-1);
    cin>>n;
    for(ll i=0;i<n;i++)
    {
        ll c;
        cin>>c;
        v.pb(mp(c,i));
    }
    sort(rall(v));
    cout<<rec(0LL,0LL,n-1LL);
}



Measured memory_bytes: 35168
def resolve():
    H, W, K = map(int, input().split())
    G = [list(input()) for _ in range(H)]
    all_cnt = sum([g.count("#") for g in G])
    ans = 0
    for bit_i in range(1<<H):
        for bit_j in range(1 << W):
            cnt = 0
            for i in range(H):
                for j in range(W):
                    if bit_i>>i & 1 or bit_j>>j & 1:
                        if G[i][j] == "#":
                            cnt += 1
            if all_cnt - cnt == K:
                ans += 1
    print(ans)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 9208
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <cstring>
#include <queue>
#include <functional>
#include <random>
using namespace std;
#define Would
#define you

const int MOD = 1e9 + 7;
const int INF = 999999999;

string h;
int k[30];
int main() {
	cin >> h;
	if (h == "zyxwvutsrqponmlkjihgfedcba") {
		cout << -1 << endl;
		return 0;
	}
	if (h.length() < 26) {
		for (int i = 0; i < h.length(); ++i) {
			++k[h[i] - 'a'];
		}
		for (int i = 0; i < 26; ++i) {
			if (!k[i]) {
				h += i + 'a';
				break;
			}
		}
		cout << h << endl;
		return 0;
	}
	string mon = h, ans;
	next_permutation(h.begin(), h.end());
	for (int i = 0; i < h.length(); ++i) {
		ans += h[i];
		if (mon[i] != h[i]) { break; }
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import math

A,B,H,M = map(int,input().split())

angH = H*30 + M*0.5
angM = M*6
ang = abs(angH - angM)

answ = A**2 + B**2 - 2*A*B*math.cos(math.radians(ang))
ans = math.sqrt(answ)

print(ans)

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

using namespace std;

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    
    int n, r;
    cin >> n >> r;
    
    if (n >= 10)
        cout << r;
    else
        cout << r + 100 * (10 - n);
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N,Q = map(int,input().split())
aLst = [[int(i) for i in input().split()] for _ in range(N-1)]
pLst = [[int(i) for i in input().split()] for _ in range(Q)]
to = [[]for _ in range(N+1)]

for a,b in aLst:
    to[a].append(b)
    to[b].append(a)

ps = [0]*(N+1)
for a,b in pLst:
    ps[a] += b

def dfs(v, i):
    for j in to[v]:
        if j == i:
            continue
        ps[j] += ps[v]
        dfs(j,v)

dfs(1,0)
print(' '.join(map(str, ps[1:])))


Measured memory_bytes: 285840
#include<bits/stdc++.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define ednl endl
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r)for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r)for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k)for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

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

/*
   upll : (a<b)なら-1, (a=b)なら0, (a>b)なら1
 downll : (a<b)なら1, (a=b)なら0, (a>b)なら-1

 const void* a : 型を縛らずにconstをつける(=変数aが読み込み専用の変数であることを明示する)
        (ll*)a : 変数aがconst long long *型であると明示する
*/
// int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
// int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
// void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
// void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}

#define INF ((1LL<<62)-(1LL<<31))
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p) pom(a,p-2,p)

bool compare(pair<ll,ll> p1, pair<ll,ll> p2){
    return p1.se < p2.se;
}

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

    vector<pair<ll,ll>> lst;
    vector<ll> p, y;
    rep(i,0,m){
        ll s, t;
        cin >> s >> t;
        p.pb(s); y.pb(t);
        s--;
        lst.pb(mp(s,t));
    }

    map<ll,ll> mapp;
    vector<ll> cnt(n,1);
    sort(all(lst),compare);
    rep(i,0,m){
        //cout << lst[i].fi << " " << lst[i].se << ednl;
        mapp[lst[i].se] = cnt[lst[i].fi]++;
        //cout << mapp[lst[i].se] << " " << cnt[lst[i].fi] << ednl;
    }

    rep(i,0,m) cout << setfill('0') << right << setw(6) << p[i] << setfill('0') << right << setw(6) << mapp[y[i]] << ednl;
}

Measured memory_bytes: 11740
#include <stdio.h>

int bubbleSort(int a[],int n){
  int i,j,tmp,cnt=0;
  for(i=0;i<n-1;i++){
    for(j=n-1;j>i;j--){
      if(a[j-1] > a[j]){
        tmp = a[j];
        a[j] = a[j-1];
        a[j-1] = tmp;
        cnt++;
      }
    }
  }
  return cnt;
}

int main(){
  int cnt;
  int a[110];
  int i,n;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  cnt = bubbleSort(a,n);
  for(i=0;i<n;i++) {
    printf("%d",a[i]);
    if(i<n-1) printf(" ");
  }
  printf("\n");
  printf("%d\n",cnt);
  return 0;
}



Measured memory_bytes: 2124
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_D main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 10;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif 


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

    int N, K; cin >> N >> K;
    string S; cin >> S;
    
    int score = 0;
    REP(i,N-1) {
        if (S[i]==S[i+1]) score++;
    }

    int ans = min(score + 2 * K, N - 1);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial, log, log10, log2
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
from datetime import datetime as dt

def main():
  n = int(readline())
  s = input()
  last = ''
  ans = 0
  for i in range(n):
    if last != s[i]:
      last = s[i]
      ans += 1
  print(ans)
  
  
  
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 13464
#include <bits/stdc++.h>
#define Nmax 3005
using namespace std;

int dp[Nmax][Nmax];

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

    for (int i = 1; i <= s.length(); ++i) {
        for (int j = 1; j <= t.length(); ++j) {
            if (s[i - 1] == t[j - 1]) {
                dp[i][j] = dp[i - 1][j - 1] + 1;
            }
            else {
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
            //cout << i << " " << j << " " << dp[i][j] << "\n";
        }
    }

    int x, y;
    x = s.length();
    y = t.length();

    stack <char> st;

    int lcsSize = dp[x][y];
    while (st.size() != lcsSize) {
        if (s[x - 1] == t[y - 1]) {
            st.push(s[x - 1]);
            x--;
            y--;
        }
        else {
            if (dp[x][y] == dp[x - 1][y]) {
                --x;
            }
            else {
                --y;
            }
        }
    }

    while (!st.empty()) {
        cout << st.top();
        st.pop();
    }
    return 0;
}


Measured memory_bytes: 35456
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
char s[4];
int main(){
	cin>>s;
	for(int i=0;i<strlen(s);i++) if(s[i]=='7') {
		puts("Yes"); return 0;
	}
	 puts("No"); return 0;
	 
}

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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;




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

	VI a(n), b(n), c(n - 1);
	REP(i, n)cin >> a[i], a[i]--;
	REP(i, n)cin >> b[i];
	REP(i, n - 1)cin >> c[i];

	int ans = 0;

	REP(i, n) {
		ans += b[a[i]];
		if (i != 0 && a[i] == a[i - 1] + 1)ans += c[a[i - 1]];
	}


	cout << ans << endl;

}

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

#define fast ios::sync_with_stdio(false); cin.tie(0);
#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf = 1e9;
const ll INF = 1e18;

int n, m;
int p[200010];
int sz[200010];

int Find(int a) { return p[a] = p[a] == a ? a : Find(p[a]); }
void Union(int a, int b) {
	a = Find(a);
	b = Find(b);

	if(a == b) return;

	p[b] = a;
	sz[a] += sz[b];

}

int main() {
	fast;

	cin >> n >> m;

	for(int i=1; i<=n; i++) p[i] = i, sz[i] = 1;

	for(int i=0; i<m; i++) {
		int a, b;
		cin >> a >> b;

		Union(a, b);
	}

	int ans = 0;
	for(int i=1; i<=n; i++)
		ans = max(ans, sz[Find(i)]);

	cout << ans;
}

Measured memory_bytes: 5432
#include<cstdio>
#include<cstring>
#include<vector>
#include<map>
#include<cmath>
#include<algorithm>
#define M 100005
using namespace std;
int n;
int a[105];
int main() {
	scanf("%d", &n);
	int ans = -1;
	int i;
	for (i = 1; i <= n; i++) scanf("%d", &a[i]);
	for (i = -100; i <= 100; i++) {
		int sum=0;
		for (int j = 1; j <= n; j++) {
			sum += (a[j] - i) * (a[j] - i);
		}
		if (ans == -1) ans = sum;
		else ans = min(ans, sum);
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
typedef pair<int, int> pii;
int main(){
    int n,h; cin >> n >> h;
    int ans = 0;
    vector<int> a(n);
    vector<int> b(n);
    rep(i,n){
        cin >> a[i] >> b[i];
    }
    
    sort(ALL(a));
    sort(ALL(b));
    int key = a[n-1];
    for(int i = n-1; i >= 0; i--){
        if(b[i] > key){
            h -= b[i]; ans++;
            if(h <= 0){
                cout << ans << endl;
                return 0;
            }
        }
        else break;
    }
    ans += h / key;
    if(h % key != 0) ans++;
    cout << ans << endl;
}


Measured memory_bytes: 1024
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);

    int a = stdIn.nextInt();
    int b = stdIn.nextInt();
    if (a <= 9 && b <=9){
      System.out.println(a*b);
    }else{
      System.out.println(-1);
    }

  }
}


Measured memory_bytes: 23252
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <stdint.h>
using namespace std;

int main()
{
  for (int n; cin >> n; ) {
    int ans = 0;
    for (int a = 0; a <= 9; a++)
    for (int b = 0; b <= 9; b++)
    for (int c = 0; c <= 9; c++)
    for (int d = 0; d <= 9; d++)
      if (a + b + c + d == n) ans++;
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <fstream>
#include <vector>

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

using namespace std;

inline int Char_to_int(char a){
    return (int)a - (int)'a';
}

int main(){
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> x(26, 0);
    FOR (i, n)
        x[Char_to_int(s[i])]++;
    const int prime = 1e9 + 7;
    long long ans = 1;
    FOR (i, 26)
        ans = (ans * (x[i] + 1)) % prime;
    cout << ans - 1 << endl;
}



Measured memory_bytes: 512
N, M = [int(x) for x in input().split()]

P, S = [], []
for i in range(M):
    _p, _s = list(input().split())
    P.append(int(_p))
    S.append(_s)

Q = []
Q_ans = []
for i in range(N):
    Q.append(0)
    Q_ans.append(False)

for i in range(M):
    q_num = P[i]
    if Q_ans[q_num-1]:
        continue
    if S[i] == "WA":
        Q[q_num-1] += 1
    if S[i] == "AC":
        Q_ans[q_num-1] = True

num_AC, num_WA = 0, 0
for i in range(N):
    if Q_ans[i]:
        num_WA += Q[i]
        num_AC += 1

print(num_AC, num_WA, sep=' ')



Measured memory_bytes: 14952