akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))//memset only use to initialize 0 or -1 no other number.
#define pii pair<int,int>
#define pll pair<ll,ll>
//#define mod 1000000007
#define mod 998244353
using namespace std;
using namespace __gnu_pbds; 
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> os;
typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> os_pair;

ll power(ll x,ll n){ll res =1;while(n>0){if(n%2==1){res=res*x;}x=x*x;n=n/2;}return res;}
ll powm(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modinv(ll a){
	return powm(a,mod-2)%mod;
}

int main(){

ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,i,j;
    cin>>n;
    int a[n+1],r[n+1]={0},c[n+1];
    for(i=1;i<=n;i++)
    {
    	cin>>a[i];
    	r[i]=i-a[i];
    	c[i]=i+a[i];
	}
	map<int,int>m;
	ll ans=0;
	for(i=1;i<=n;i++)
	{
		m[c[i]]++;
		if(m.find(r[i])!=m.end())
		ans=ans+m[r[i]];

	}
	cout<<ans;
	
    	
    	
	
}

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

struct UnionFind {
  vector<int> d;
  UnionFind(int n = 0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if(x == y) return false;
    if(d[x] > d[y]) swap(x, y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};

int deg[100005];
vector<int> to[100005];

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  UnionFind uf(n);
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    deg[a]++;
    deg[b]++;
    uf.unite(a,b);
  }
  rep(i,k) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  rep(i,n) {
    int ans = uf.size(i)-1-deg[i];
    for (int u : to[i]) {
      if (uf.same(i,u)) ans--;
    }
    printf("%d%c", ans, i==n-1?'\n':' ');
  }
  return 0;
}

Measured memory_bytes: 9156
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,d,x[11][11],cnt=0;
	cin>>n>>d;
	for(int i=0;i<n;i++) for(int j=0;j<d;j++) cin>>x[i][j];
	for(int i=0;i<n-1;i++){
		for(int j=i+1;j<n;j++){
			int sum=0;
			for(int k=0;k<d;k++) sum+=abs(x[i][k]-x[j][k])*abs(x[i][k]-x[j][k]);
			if(sqrt(sum)==(int)sqrt(sum)) cnt++;
		}
	}
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

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

  int even = 0;
  int odd = 0;
  rep(i, N) {
    int a;
    cin >> a;
    (a % 2 == 0 ? even : odd)++;
  }

  even += odd / 2;
  odd = odd % 2;

  cout << (even > 0 && odd > 0 ? "NO" : "YES") << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
int MOD = 1e9+7;
using ll = long long;
using namespace std;
int main(){
    string s;
    cin >> s;
    bool h=false;
    if(s[0]=='B'){
        h=true;
    }
    int c=0;
    for(int i=1;i<s.size();i++){
        if(h&&s[i]=='W'){
            c++;
            h=false;
        }
        if(!h&&s[i]=='B'){
            c++;
            h=true;
        }
    }
    cout<<c<<endl;
    int x;cin >> x;
}


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

#ifdef ONLINE_JUDGE
#define freopen \
  if (0) freopen
#define cerr \
  if (0) cerr
#endif

#define fi first
#define se second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)

#define sqr(a) ((a)*1ll * (a))
#define sz(a) (int)a.size()
#define len(a) (int)a.length()
#define all(a) a.begin(), a.end()
#define nl '\n'

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pi;

const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const ll linf = (ll)1e18 + 7;

int n, a, x[55];
ll dp[55][6000];
const int zero = 2505;

void solve() {
  cin >> n >> a;
  rep(i, 1, n) {
    cin >> x[i];
    x[i] -= a;
  }

  dp[0][zero] = 1;
  rep(i, 1, n) {
    rep(sum, 0, 5000) {
      dp[i][sum] += dp[i - 1][sum];
      if (sum - x[i] >= 0 && sum - x[i] <= 5000)
        dp[i][sum] += dp[i - 1][sum - x[i]];
    }
  }

  cout << dp[n][zero] - 1;
}

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

  freopen(".in", "r", stdin);

  solve();

  return 0;
}


Measured memory_bytes: 5796
N = int(input())

count = [[0 for _ in range(9)] for _ in range(9)]
for i in range(1, N + 1):
    s = str(i)
    prefix = int(s[0])
    surfix = int(s[-1])
    if surfix != 0:
        count[prefix - 1][surfix - 1] += 1

ans = 0
for i in range(9):
    for j in range(9):
        if i == j:
            continue
        ans += count[i][j] * count[j][i]

for i in range(9):
    ans += count[i][i] ** 2

print(ans)


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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

using namespace std;
using P = pair<int, int>;

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( a > b ) { a = b; return 1; } return 0; }

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

vector<int> G[100001];
int color[100001];

void dfs( int v, int c ){
    color[v] = c;
    for( auto nv : G[v] ){
        if( color[nv] ) continue;
        dfs( nv, c );
    }
}

signed main(){
    int N, M; cin >> N >> M;
    REP( i, M ){
        int s, t; cin >> s >> t;
        G[s].push_back( t );
        G[t].push_back( s );
    }

    int c = 1;
    REP( i, N ){
        if( color[i] == 0 ){
            dfs( i, c );
            c++;
        }
    }

    int Q; cin >> Q;
    REP( i, Q ){
        int s, t; cin >> s >> t;
        if( color[s] == color[t] ){
            cout << "yes" << endl;
        }else{
            cout << "no" << endl;
        }
    }

}


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

int main() {
  int N, T, A;
  cin >> N >> T >> A;

  double m = 1000;
  int ans = -1;
  for (int i = 0; i < N; i++) {
    int H;
    cin >> H;
    double t = abs(A-(T-H*0.006));
    if(m>t) {
        m = t;
        ans = i+1;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
  int n,i,j;
  scanf("%d",&n);
  char w[n+1][11],last;
  for(i=0;i<n;i++)
    scanf("%s",w[i]);
  for(i=0;i<n;i++){
    for(j=0;j<i;j++){
      if(strcmp(w[i],w[j])==0){
        puts("No");
        return 0;
      }
    }
    if(i!=0 && last!=w[i][0]){
      puts("No");
      return 0;
    }
    last=w[i][strlen(w[i])-1];
  }
  puts("Yes");
  return 0;
}


Measured memory_bytes: 128
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    a, b, c, k = map(int, input().split())
    if k & 1:
        print(b-a)
    else:
        print(a-b)


if __name__ == '__main__':
    main()


Measured memory_bytes: 62076
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

int main() {
	long i, j, k;
	long a, b;

	cin >> a >> b >> k;

	long sa = b - a;

	long mem = 0;
	for (i = a; i < a + k; i++) {
		if (i > b) break;
		cout << i << endl;

		mem = i;
	}

	for (i = b - (k - 1); i <= b; i++) {
		if (i <= mem) continue;
		cout << i << endl;
	}








	getchar();
	getchar();
	return 0;
}

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

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

  int A[N];

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

  int ans = 0;

  while(1){
    bool odd = false;

    for(int i=0; i<N; i++){
      if(A[i]%2 == 1){
        odd = true;
      }
    }
    if(odd) break;
    ans++;

    for(int i=0; i<N; i++){
      A[i] /= 2;
    }
  }

  cout << ans << endl;

  return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int INF=1e9;
const int maxn=50005;
int a[25];
int dp[maxn];
int main()
{
    int n,m;
    cin>>n>>m;
    for (int i=0;i<m;i++)
        cin>>a[i];
    for (int i=0;i<=n;i++) dp[i]=INF;
    dp[0]=0;
    for (int i=1;i<=n;i++){
        for (int j=0;j<m;j++){
            if(a[j]<=i&&dp[i-a[j]]<dp[i])
                dp[i]=dp[i-a[j]]+1;
        }
    }
    cout<<dp[n]<<endl;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

int n;
char s[100005];
int a[100005], b[100005], c[100005];

int main() {
    scanf("%s", s);
    n = strlen(s);
    forn(i, n) a[i] = s[i] - '0';
    int lo = 1, hi = n, mid;
    while (lo < hi) {
        mid = (lo + hi + 1) >> 1;
        forn(i, n) b[i] = a[i];
        forn(i, n + 1) c[i] = 0;
        int cur = 0;
        forn(i, n) {
            cur ^= c[i];
            if (i + mid <= n && (b[i] ^ cur) != 0) {
                c[i + mid] ^= 1;
                cur ^= 1;
            }
            b[i] ^= cur;
        }
        bool ok = true;
        forn(i, mid) if (b[i] != 0) {
            ok = false;
        }
        if (ok) lo = mid;
        else hi = mid - 1;
    }
    cout << lo << endl;
    return 0;
}


Measured memory_bytes: 1536
#include <iostream>

int main() {
    int n, m, a[100][100], b[100], ans[100];
    for (int i=0;i<100;++i) ans[i] = 0;
    std::cin >> n >> m;
    for (int i=0;i<n;++i)
        for (int j=0;j<m;++j) {
            int val;
            std::cin >> val;
            a[i][j] = val;
        }
    for (int j=0;j<m;++j) {
        int val;
        std::cin >> val;
        b[j] = val;
    }
    for (int i=0;i<n;++i)
        for (int j=0;j<m;++j) {
            ans[i] += a[i][j] * b[j];
        }
    for (int i=0;i<n;++i)
        std::cout << ans[i] << std::endl;
            
    return 0;
}


Measured memory_bytes: 3108
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    s = input().rstrip()
    string_dict={}

    for i in s:
        if i not in string_dict:
            d = {i:1}
            string_dict.update(d) 
        else:
            print("no")
            exit()
    print("yes")

if __name__=="__main__":
    main()

Measured memory_bytes: 9084
#include<stdio.h>
#define ll long long

int main()
{

    ll x,i,j;

    scanf("%ld",&x);

    if(x==2){

        printf("%ld\n",x);

        return 0;
    }

    if(x%2==0)x++;

    for(i=x;;i+=2){

        ll f=0;

        for(j=3;j*j<=x;j+=2){

            if(i%j==0){

                f=1;
                break;
            }
        }

        if(f==0){

            printf("%ld\n",i);

            return 0;
        }
    }


}


Measured memory_bytes: 760
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0;i < n;i++)
#define REP(i,n,k) for(int i = n;i < k;i++)
#define P(p) cout << (p) << endl;
#define sP(p) cout << setprecision(15) << fixed << p << endl;
#define vi vector<int>
#define mp(a,b) make_pair(a,b)
using namespace std; typedef long long ll; typedef unsigned long long ull; int dx[] = { 1, -1 , 0 , 0 }; int dy[] = { 0,  0,  1, -1 };


void solve() {
	ll h, w;
	cin >> h >> w;
	ll ans = h*w;
	for (int i = 1; i <= h; i++) {
		ll a, b, c;
		a = i*w;
		b = (h - i)*floor(w/2.0);
		c = (h - i)*ceil(w/2.0);
		ans = min(ans, max(a, max(b, c)) - min(a, min(b, c)));
		b = floor((h-i)/2.0)*w;
		c = ceil((h - i) / 2.0)*w;
		ans = min(ans, max(a, max(b, c)) - min(a, min(b, c)));
	}
	for (int i = 1; i <= w; i++) {
		ll a, b, c;
		a = i*h;
		b = (w - i)*floor(h / 2.0);
		c = (w - i)*ceil(h / 2.0);
		ans = min(ans, max(a, max(b, c)) - min(a, min(b, c)));
		b = floor((w - i) / 2.0)*h;
		c = ceil((w - i) / 2.0)*h;
		ans = min(ans, max(a, max(b, c)) - min(a, min(b, c)));
	}
	P(ans);
}

int main() {
	solve();
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define int long long int

const int MAX = 3 * 1000000;
const int MOD = 1000000007;

int fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

int COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

using ll = long long;
using namespace std;

void solve() {
  ll X, Y;
  cin >> X >> Y;

  ll b = (2 * Y - X) / 3;
  ll a = Y - 2 * b;

  if ((2 * Y - X) % 3 != 0 || b < 0 || a < 0) {
    cout << 0 << endl;
    return;
  }

  COMinit();
  cout << COM(a + b, a) << endl;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}


Measured memory_bytes: 70656
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <list>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
const int ININF = 1000000;
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;
}
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;

int N;
Graph G;
vector<int> res;

void dfs(int v, int p, int c) {
    for(auto e : G[v]) {
        if(e.first == p)
            continue;
        if(e.second % 2 == 0) {
            res[e.first] = c;
        } else {
            res[e.first] =1-c;
        }
        dfs(e.first, v, res[e.first]);
    }
}
int main() {
    cin >> N;
    G.assign(N, vector<Edge>());
    rep(i, 0, N - 1) {
        int u, v, w;
        cin >> u >> v >> w;
        u--;
        v--;
        G[u].push_back(make_pair(v, w));
        G[v].push_back(make_pair(u, w));
    }
    res.assign(N, 0);
    res[0]=1;
    dfs(0, -1, 1);
    rep(i, 0, N) { cout << res[i] << endl; }
}


Measured memory_bytes: 8960
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

using namespace std;

int my_abs(int num) {
    if (num > 0)
        return num;
    else
        return -num;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

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

int main() {
    int X, Y, Z;
    cin >> X >> Y >> Z;
    X = X - Z;
    int count = 0;
    for (int i = 0; i < 1000000; i++) {
        if (X >= Y + Z) {
            count++;
            X = X - Y - Z;
        }
        else {
            break;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
		  // 		#ifndef ONLINE_JUDGE
  		// 	// for getting input from input.txt
  		// 	freopen("input.txt", "r", stdin);
  		// 	// for writing output to output.txt
  		// 	freopen("output.txt", "w", stdout);
  		// #endif
	ll n,sum=0;
	std::vector<ll> v;
	cin>>n;
	cout<<(n*(n-1))/2<<endl;
	return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf
import Debug.Trace

readInt = ( readLn :: IO Int )
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	[ x1, y1, x2, y2 ] <- readInts
	let
		dx = x2 - x1
		dy = y2 - y1
		x3 = x2 - dy
		y3 = y2 + dx
		x4 = x3 - dx
		y4 = y3 - dy
	putStrLn $ unwords $ map show [ x3, y3, x4, y4 ]

Measured memory_bytes: 380
INF = 100000
INF2 = 10 ** 5000
n = gets.to_i
nums = gets.split.map(&:to_i)
pow_memo = [1]
# (0..INF).each do |i|
#   if pow_memo[i] < 10 ** 2900
#     pow_memo[i + 1] = pow_memo[i] * 2
#   else
#     pow_memo[i + 1] = pow_memo[i]
#   end
# end

if n == 0 && nums.first == 1
  puts 1
  exit
elsif n == 0 && nums.first == 0
  puts -1
  exit
end

leaves = [1]
rests = [nums.sum]
0.upto(n - 1) do |from|
  tmp = rests[from]
  tmp2 = (leaves[from] - nums[from]) * 2
  tmp = tmp2 if tmp > tmp2
  leaves[from + 1] = tmp
  if tmp < 1
    puts -1
    exit
  end
  rest = rests[from]
  rest -= nums[from + 1]
  # if rest < 1 && from != n - 1
  #   puts -1
  #   exit
  # end
  # if rest != 0 && from == n - 1
  #   puts -1
  #   exit
  # end
  if nums[from + 1] >= tmp && from != n - 1
    puts -1
    exit
  end
  if nums[from + 1] > tmp
    puts -1
    exit
  end
  rests[from + 1] = rest
end

if rests.last != 0
  puts -1
  exit
end

tmp = 1
nums.each do |num|
  tmp -= num
  if tmp < 0
    puts -1
    exit
  end
  tmp *= 2 if tmp < INF2
end

puts leaves.sum


Measured memory_bytes: 97836
N=input()
n=int(N)
a=0
w=0
t=0
r=0
for j in range(n):
  c=input()
  if c=='AC':
    a+=1
  elif c=='WA':
    w+=1
  elif c=='TLE':
    t+=1
  elif c=='RE':
    r+=1
print('AC x {}'.format(a))
print('WA x {}'.format(w))
print('TLE x {}'.format(t))
print('RE x {}'.format(r))


Measured memory_bytes: 9120
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int g = sc.nextInt();
        int b = sc.nextInt();
        int sum = 100*r + 10*g + b;
        if(sum%4 == 0){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
	}
}

Measured memory_bytes: 21716
def main():
    _ = int(input())
    v = sorted([int(x) for x in input().split()])
    # 小さい方から足す
    for num in range(len(v) - 1):
        v[num + 1] = (v[num] + v[num + 1]) / 2
    print(v[-1])

if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e5)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
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; }
typedef pair <ll,ll> P;

int main()
{
    string S;
    cin >> S;
    rep(i, S.size()-1) {
        if (S[i] == S[i+1]) {
            print("Bad");
            return 0;
        }
    }
    print("Good");
    return 0;
}

Measured memory_bytes: 256
import collections

N = int(input())
A = list(map(int, input().split(' ')))
Q = int(input())

c = collections.Counter(A)

ans = 0

for k, v in c.items():
    ans += k * v

BC = [map(int, input().split(' ')) for q in range(Q)]

for i in range(Q):
    B, C = BC[i]
    sabun = 0
    if B in c.keys():
        poped_val = c.pop(B)
        if C not in c.keys():
            c[C] = 0
        c[C] += poped_val
        sabun = C * poped_val - B * poped_val
    ans += sabun
    print(ans)

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

int main() {
  int X, A, B;
  cin >> X >> A >> B;
  
  if(B <= A) {
    cout << "delicious" << endl;
  } else if (B > A && B <= A + X) {
    cout << "safe" << endl;
  } else {
    cout << "dangerous" << endl;
  }
  
    
   
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> card(n);
    for (int i = 0; i < n; i++)
    {
        cin >> card.at(i);
    }

    sort(card.begin(), card.end(), greater<int>());

    int ans = 0;

    for(int i = 0; i < n; i++){
        if(i % 2 == 0) ans += card.at(i);
        else ans -= card.at(i);
    }

    cout << ans << endl;

    return 0;
    
}

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

using namespace std;
typedef long long ll;
const ll INF = 1e9;

int main() {
    int N, M, R;
    cin >> N >> M >> R;
    vector<int> vR(R);
    for (int i = 0; i < R; ++i) {
        cin >> vR[i];
        vR[i]--;
    }

    int d[N][N];
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            d[i][j] = i == j ? 0 : INF;
        }
    }
    for (int i = 0; i < M; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        a-- , b--;
        d[a][b] = d[b][a] = c;
    }
    for (int k = 0; k < N; ++k) {
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < N; ++j) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    ll ans = INF;
    sort(vR.begin(), vR.end());
    do {
        ll sum = 0;
        for (int i = 0; i < vR.size() - 1; ++i) {
            sum += d[vR[i]][vR[i + 1]];
        }
        ans = min(sum, ans);
    } while (next_permutation(vR.begin(), vR.end()));

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

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

int int_len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}

int int_sum(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}






int gcd(int a,int b)
{
 
  int r, tmp;
 
  
 
  /* 自然数 a > b を確認・入替 */
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
 
 
 
  return b;
}







int fac(int n){
  int m=1;
  while(n>=1) m*=n,n--;
  return m;
}

int vec_sum(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}
///////////////////////////
int main() {
  long long int n;
  cin>>n;
  long long int a=sqrt(n);
  cout<<a*a<<endl;
}
///////////////////////////



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

int main() {
  int H,W;
  cin >> H >> W;
  char a[H][W];
  for(int i = 0;i < H;i++){
    for(int j = 0;j < W;j++){
      cin >> a[i][j];
    }
  }
  for(int i = 0;i < W + 2;i++)
    cout << '#';
  cout << endl;
  
  for(int i = 0;i < H;i++){
    cout << '#';
    for(int j = 0;j < W;j++){
      cout << a[i][j];
    }
    cout << '#' << endl;
  }
  
  for(int i = 0;i < W + 2;i++)
    cout << '#';
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
n = gets.chomp.to_i
t, a = gets.chomp.split(' ').map(&:to_i)
list = gets.chomp.split(' ').map(&:to_i).map{|i| (t - (i * 0.006)-a).abs}

print n.times.min_by{|i| list[i] } + 1

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

using namespace std;

const int nax = 1e9 + 9;

bool possible(vector<int> &arr, int len, int maxcuts) {
    int reqcuts = 0;
    for(auto x : arr) {
        reqcuts += x/len;
        if(!(x%len)) reqcuts--;
        if(reqcuts > maxcuts) return false;
    }
    return true;
}

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> arr(n);
    for(auto &x : arr) cin >> x;
    //sort(arr.begin(), arr.end());
    int l = 1, r = nax;
    while(l < r) {
        int mid = l + ((r-l)>>1);
        //cout << l << ' ' << mid << ' ' << r << endl;
        if (possible(arr, mid, k)) {
            r = mid;
        }
        else {
            l = mid+1;
        }
    }
    cout << l << endl;
    return 0;
}

Measured memory_bytes: 3940
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
using namespace std;

#define REP(i,p,n) for(ll i=p;i<ll(n);++i)
#define rep(i,n) REP(i,0,n)

using ll = long long int;
using pll = pair<ll, ll>;

ll N, M, Q;

const ll MAXQ = 64;
ll A[MAXQ];
ll B[MAXQ];
ll C[MAXQ];
ll D[MAXQ];

const ll MAXN = 16;
ll V[MAXN] = { 1 };

ll dfs(ll k)
{
    if (N <= k)
    {
        ll res = 0;

        rep (i, Q) if (V[B[i]] - V[A[i]] == C[i])
        {
            res += D[i];
        }

        return res;
    }

    ll ans = 0;

    for (ll v=V[k];v<=M;++v)
    {
        V[k + 1] = v;

        ans = max(ans, dfs(k + 1));
    }

    return ans;
}

int main()
{
    cin >> N >> M >> Q;
    rep (i, Q) { cin >> A[i] >> B[i] >> C[i] >> D[i]; }

    const auto ans = dfs(0);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
    int N, x;
    cin >> N >> x;

    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }

    int sum = 0;
    for (int i = 0; i < N; i++) {
        if (i > 0) {
            if (a[i-1] + a[i] > x) {
                int rm = a[i-1] + a[i] - x;
                sum += rm;
                a[i] -= rm;
            }
        } else if (a[i] > x) {
            sum += a[i] - x;
            a[i] = x;
        }
    }
    cout << sum << endl;

    return 0;
}


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

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

    if(k<=a){
        cout << a-k << ' '<< b << endl;
    }else if(k<a+b){
        cout << 0 <<' '<<b-(k-a)<<endl; 
    }else if(k>=a+b){
        cout << 0 << ' ' << 0 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String input = sc.next();
        int start = -1;
        int end = -1;
        int size = input.length();
        for(int i = 0; i < size; i++){
            if( i + 1 < size) {
                if (input.charAt(i) == input.charAt(i + 1)) {
                    start = i + 1;
                    end = i + 2;
                }
            }
            if(i + 2 < size){
                if(input.charAt(i) == input.charAt(i + 2)){
                    start = i + 1;
                    end = i + 3;
                }
            }
        }
        System.out.println(start + " " + end);

    }
}


Measured memory_bytes: 24416
n, l = map(int,input().split())
sum1,sum2,li = 0,0,[]
for i in range(n):
    sum1 += l+i

for i in range(n):
    sum2 = (sum1 - (l+i))
    li.append(sum2)

li2 = []
for i in range(n):
    li2.append(abs(sum1-li[i]))

a = li2.index(min(li2))
print(li[a])

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

int main(){
    while(1){
        int n;
        cin >> n;
        if(n == 0) break;
        vector<int> a(n);
        rep(i, 0, n){
            string s;
            cin >> s;
            a[i] = s.size();
        }
        int d[6] = {5, 7, 5, 7, 7, 114514};
        int ans = -1;
        rep(i, 0, n){
            int now = 0;
            int tmp = 0;
            rep(j, i, n){
                if(a[j] + tmp < d[now]){
                    tmp += a[j];
                }else if(a[j] + tmp == d[now]){
                    now++;
                    tmp = 0;
                }else{
                    break;
                }
                // cout << now << " " << tmp << endl;
                if(now == 5){
                    cout << i + 1 << endl;
                    i = n;
                    break;
                }
            }
        }
    }
}

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

int main() {
	int N; cin >> N;
	vector<string> X(N);
	for(string &x : X) cin >> x;
	for(int i = 0 ; i < N ; i++){
		for(int j = 0 ; j < N ; j++){
			if(i != j){
				if(X[i] == X[j]){
					cout << "No" << endl;
					return 0;
				}
			}
		}
	}
	for(int i = 0 ; i < N - 1 ; i++){
		if(X[i][X[i].size()-1] != X[i+1][0]){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
#include <numeric>
#include <bitset>
#include <cassert>

using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#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 all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

int main() {
	int N, L;
	cin >> N >> L;
	int min_tmp = INF;
	int total_N = 0;
	rep1(i, N + 1) {
		total_N += L + i - 1;
	}
	int total_N_1;
	int final_total_N_1 = 0;
	rep1(i, N + 1) {
		total_N_1 = total_N - (L + i - 1);
		if (min_tmp > abs(total_N - total_N_1)) {
			min_tmp = abs(total_N - total_N_1);
			final_total_N_1 = total_N_1;
		}
	}
	cout << final_total_N_1;
	return 0;
}

Measured memory_bytes: 256
result = gets.chomp.to_i.times.reduce({t: 0, r: 0}) { |result, t|
  card_t, card_r = gets.chomp.split
  if card_t < card_r
    result[:r] += 3
  elsif card_t > card_r
    result[:t] += 3
  else
    result[:r] += 1
    result[:t] += 1
  end
  result
}
puts "#{result[:t]} #{result[:r]}"


Measured memory_bytes: 6860
# -*- coding: utf-8 -*-
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys

def s():
    return raw_input().strip()
def n():
    return int(raw_input())
def d():
    return float(raw_input())

def ls():
    return raw_input().strip().split()
def ln():
    return map(int, raw_input().strip().split())
def ld():
    return map(float, raw_input().strip().split())

def fs():
    return [raw_input().strip() for i in xrange(input())]
def fn():
    return [int(raw_input().strip()) for i in xrange(input())]
def fd():
    return [float(raw_input().strip()) for i in xrange(input())]

N = n()

S = [line.strip() for line in sys.stdin]

M = len(S)

cost = 0
for i in xrange(N):
    count = collections.Counter()
    for j in xrange(M):
        count[S[j][i]] += 1
    cost += M - count.most_common(1)[0][1]

print cost


Measured memory_bytes: 4508
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n,x = map(int, input().split())
    a = list(map(int, input().split()))
    res = 0
    for i in range(n-1):
        b = a[i+1] + a[i] - x
        if b <= 0:
            continue
        else:
            if a[i+1] - b >= 0:
                a[i+1] -= b
            else:
                a[i+1] = 0
            res += b
    print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 14512
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void DFS(int V,vector<vector<int> >&GRAPH,vector<int>& used,int pV,vector<int>&counter)
{
  // if(used[V] == 1)return;
  used[V] = 1;
  counter[V] = pV + counter[V];
  // DEBUG(V);
  for (int i = 0; i < GRAPH[V].size(); i++)
  {
    if(used[GRAPH[V][i]] == 0)
    {
      DFS(GRAPH[V][i],GRAPH,used,counter[V] ,counter);
    }
  }
  return;
}

void solve(void)
{
  int N,Q;
  cin>>N>>Q;
  vector<vector<int> > GRAPH(N);
  for (int i = 0; i < N-1; i++)
  {
    int A,B;
    cin>>A>>B;
    A--;B--;
    GRAPH[A].push_back(B);
    GRAPH[B].push_back(A);
  }
  vector<int> used(N,0);
  vector<int>counter(N,0);
  for (int q = 0; q < Q; q++)
  {
    int p,x;
    cin>>p>>x;
    p--;
    counter[p] += x;
  }
  
  DFS(0,GRAPH,used,0LL,counter);
  for (int i = 0; i < N; i++)
  {
    if(i != 0)cout<<char(32);
    cout<<counter[i];
  }
  cout<<endl;
  
  return;
}



int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


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

int main(){
      map<char, char> m;
      m['A'] = 'T';
      m['T'] = 'A';
      m['G'] = 'C';
      m['C'] = 'G';
      char c;cin >> c;
      cout << m[c];
}

Measured memory_bytes: 256
#include <iostream>
#include <iosfwd>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cassert>
#include <cctype>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <math.h>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <sstream>
#include <complex>
#include <fstream>
#include <functional>
#include <numeric>
#include <utility>
#include <algorithm>
#include <assert.h>
#include <unordered_map>
#pragma GCC optimize ("-O3")
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL);
#define tolower(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define toupper(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define ll long long int
ll max(ll a, ll b) {  return a > b ? a : b; }
ll gcd(ll a, ll b) { if (a == 0) { return b; } return b == 0 ? a : gcd(b, a % b);}
#define case(i) cout<<"Case #"<<i<<": ";
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cerr << '\n'; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
#define debug2(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
void err(istream_iterator<string> it, T a, Args... args) { cerr << "[ " << *it << " = " << a << " ]"; err(++it, args...);}
#define time__(d) for (auto blockTime = make_pair(chrono::high_resolution_clock::now(), true); blockTime.second; debug2("%s: %lld ms\n", d, chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - blockTime.first).count()), blockTime.second = false)
#define pii pair <ll , ll >
#define pb push_back
#define PRECISION 10
const ll inf = 9223372036854775800;
const int MAXN = 100001;
const int LOGN = 22;
const int MAXBIT = 62;
const long double PI = 3.141592653589793;
const int DIGITSIZE = 18;
ll mod = 1e9 + 7;
ll MOD = 998244353;
int x4[] = {1, -1, 0, 0};
int y4[] = {0, 0, 1, -1};
int x8[] = {1, 1, 1, -1, -1, -1, 0, 0};
int y8[] = {1, 0, -1, 1, 0, -1, 1, -1};
bool takeTestCases = 0;
bool printCaseNo = 0;

void getac(int T) {
	string s;
	string t;
	cin >> s >> t;
	int n = s.length();
	int m = t.length();
	int ans = INT_MAX;
	for (int i = 0; i <= n - m; i++) {
		int curr = 0;
		for (int j = 0; j < m; j++) {
			if (s[i + j] != t[j]) {
				curr++;
			}
		}
		ans = min(ans, curr);
	}
	cout << ans << '\n';
}
int  main()
{

	fastio;
	int t = 1;
	if (takeTestCases) { cin >> t; }
	int t_t = 1;
	while (t--) {
		if (printCaseNo)
		case (t_t);
		getac(t_t);
		t_t++;
	}
	cerr << "Total time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
	return 0;
}


Measured memory_bytes: 3792
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;typedef vector<ll> vll;
#define fill(a,b) memset(a, b, sizeof (a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0; i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define _ios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int maxn = 2000100;

int main(){
        _ios;

        ll n, m, t = 0; cin>>n>>m;
        for(int i =0; i < m; i++){
            ll x; cin>>x;
            t += x;
        }
        cout<<(n < t ? - 1 : n - t)<<endl;


return 0;
}



Measured memory_bytes: 3652
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <numeric>
#include <functional>

using namespace std;
#define ALL(x)              (x).begin(),(x).end()
#define REP(i, n)           for (int (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n)       for (int (i) = m ; (i) < (ll)(n) ; ++(i))
#define INF                 (int)2e9
#define MOD                 (1000 * 1000 * 1000 + 7)
#define Ceil(x, n)          (((((x))+((n)-1))/n))
#define CeilN(x, n)         (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)        ((x)-(x)%(n))
#define IsOdd(x)            (((x)&0x01UL) == 0x01UL)
#define IsEven(x)           (!IsOdd((x)))
#define M_PI                3.14159265358979323846
typedef long long           ll;
typedef pair<ll, ll>        P;

/*-----------------------------------------------------------------------------
　処理
 -----------------------------------------------------------------------------*/
vector<bool>		isUsed;
vector<vector<int>>	G;
void dfs(int from, int to)
{
	for (auto nextTo : G[to]) {
		if (from != nextTo) {
			if (!isUsed[nextTo]) {
				isUsed[nextTo] = true;
				dfs(to, nextTo);
			}
		}
	}
}

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

	vector<P> condCnt(N);
	for (int j = 0; j < N; j++) {
		condCnt[j].first = 0;
		condCnt[j].second = j;
	}

	G.resize(N);
	for (int j = 0; j < M; j++) {
		int x, y, z;
		cin >> x >> y >> z;
		x--;  y--;
		G[x].emplace_back(y);
		G[y].emplace_back(x);
		condCnt[x].first++;
		condCnt[y].first++;
	}
	sort(condCnt.rbegin(), condCnt.rend());

	int ans = 0;
	isUsed.resize(N, false);
	REP(i, N) {
		int startPos = condCnt[i].second;
		if (!isUsed[startPos]) {
			isUsed[startPos] = true;
			ans++;
		}
		dfs(-1, startPos);
	}

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



Measured memory_bytes: 12032
#include <bits/stdc++.h>
#define sqr(a) ((a)*(a))
#define rsz resize
#define forr(i,a,b) for(int i=(a);i<(b);i++)
#define forn(i,n) forr(i,0,n)
#define dforn(i,n) for(int i=n-1;i>=0;i--)
#define forall(it,v) for(auto it=v.begin();it!=v.end();it++)
#define sz(c) ((int)c.size())
#define zero(v) memset(v, 0, sizeof(v))
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define fst first
#define snd second
#define PI 3.1415926535897932384626

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int main()
{
	#ifdef REJUNTE
	freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	#endif
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	string s;
	cin >> s;
	ll ans=0,maxToR=s.size()-1;
	dforn(i,s.size())if(s[i]=='B')
	{
		ans+=maxToR-i;
		maxToR--;
	}
	cout << ans << '\n';
	return 0;
}

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

int f(int N){
  int cnt = 0;
  while(N>0){
    cnt++;
    N /= 10;
  }
  return cnt;
}

int main() {
  int N; cin >> N;
  int ans = 0;
  for(int i = 1; i <= N;i++){
    if(f(i)%2==1) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3628
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    S = readline().strip()
    
    print(S.count('ABC'))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 61916
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    sc.close();

    for(int j = 1; j <= n; j++) {
      int x = j;
      if(x % 3 == 0) {
        System.out.print(" " + j);
        continue;
      }
      while(x > 0) {
        if(x % 10 == 3) {
          System.out.print(" " + j);
          break;
        }
        x /= 10;
      }
    }
    System.out.println();

  }
}


Measured memory_bytes: 28436
#include <cstdio>
#include <cctype>
#include <utility>
#include <vector>
#include <algorithm>
#include <array>
#include <numeric>
using namespace std;

const auto gcu = getchar_unlocked;
const auto pcu = putchar_unlocked;
#define _NE noexcept
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _sc _il bool scan
_T T in(int c)_NE{T n=0;int m=1;while(isspace(c)){c=gcu();}if(c=='-')m=-1,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
_il int in()_NE{return in<int>(gcu());}
_T T scan(T &n)_NE{int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c)_NE{c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s)_NE{int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t)_NE{return scan(h)&&scan(t...);}
#define _ot _il void out
#define _ol _il void outl
_ot(bool b)_NE{pcu('0'+b);}
_ot(const char *s)_NE{while(*s)pcu(*s++);}
_ot(char c)_NE{pcu(c);}
#ifdef _GLIBCXX_STRING
_ot(string s)_NE{for(char c:s)pcu(c);}
#endif
_T _ot(T n)_NE{static char b[20];char *p=b,m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=n%10*m+'0',n/=10;while(p!=b)pcu(*--p);}
_ol()_NE{out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _ot(vector<T> &v)_NE{for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _ot(H&& h, T&&... t)_NE{out(h);out(move(t)...);}
template <typename... T> _ol(T&&... t)_NE{out(move(t)...);outl();}

#define all(o) o.begin(), o.end()

void radix_sort(vector<int> &v) {
	vector<int> t(v.size());
	array<int, 256> c, s;
	for (int i = 0; i < 32; i += 8) {
		fill(all(c), 0);
		for_each(all(v), [&](int j) {c[(j >> i) & 255]++;});
		s.front() = 0;
		partial_sum(all(c) - 1, s.begin() + 1);
		for_each(all(v), [&](int j) {t[s[(j >> i) & 255]++] = j;});
		swap(v, t);
	}
}

int main() {
	for (int N, M; N = in(), M = in();) {
		vector<int> t(N), u;
		for (int &p: t)
			p = in();
		t.push_back(0);
		for (auto i = t.begin(); i != t.end(); i++)
			for (auto j = i; j != t.end(); j++)
				if (*i + *j <= M)
					u.push_back(*i + *j);
		radix_sort(u);
		int r = 0;
		for (auto i = u.begin(), e = u.end() - 1; i <= e; i++) {
			for (; *i + *e >= M; e--)
				;
			r = max(r, *i + *e);
		}
		outl(r);
	}
}


Measured memory_bytes: 6264
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    //cable way
    int m,n, total;
//    total = 29;
//    int colors[3];
//    for (int i = 0; i< 3; i++){
//        cin>> colors[i];
//    }
//    m= 0;
//    n = 0;
//    for (int j = 0; j< 3; j++){ //redefine color
//        if (colors[j]%2==1){
//            colors[j]  = colors[j]/2+1;
//        }
//        else {
//            colors[j] = colors[j]/2;
//        }
//    }
//    for (int i = 0; i< 3; i++){
//        if (colors[i]>=m){
//            m = colors[i];
//            n = i;
//        }
//    }
//    n++;
//    total = 29 + 3*(m-1) + n;
//    cout << total;
    //81 --> works
    bool product= false;
    cin>> n;
    for (int i = 1; i<= 9; i++){
        int h = n/i;
        int g = n%i;
        if (g == 0){
            if (1<=h && h<=9){
                product = true;
            }
        }
    }
    if (product){
        cout<< "Yes";
    }
    else {
        cout << "No";
    }
    return 0;
}

Measured memory_bytes: 256