akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

int main() {
  string s;
  cin >> s;
  vector<char> a(4);
  rep(i, 4) a.at(i) = s.at(i);
  sort(a.begin(), a.end());
  if (a.at(0) == a.at(1) && a.at(2) == a.at(3) && a.at(1) != a.at(2)) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

int main()
{
	int D, N;
	cin >> D >> N;
	if(D == 0) {
		if (N < 100) {
			cout << N << endl;
		} else {
			cout << 101 << endl;
		}
	} else if(D == 1) {
		if (N < 100) {
			cout << 100 * N << endl;
		} else {
			cout << 10100 << endl;
		}
	} else {
		if (N < 100) {
			cout << 10000 * N << endl;
		} else {
			cout << 1010000 << endl;
		}
	}
	return 0;
}

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

int N;
int X[111];
int maxa;
bool check(){
  for(int i=1;i<N;i++){
    if( X[i] < 0 ) return false;
    if( X[i] ){
      if( (maxa&1) && i <= maxa/2+1 ) return false;
      if( !(maxa&1) && i<= maxa/2 ) return false;
    }
  }
  return true;
}

int main(){
  cin >> N;
  maxa = 0;
  for(int i=0;i<N;i++){
    int a; cin >> a;
    X[a]++;
    maxa = max( maxa, a );
  }

  if( N>2 && maxa == 1 ){
    cout << "Impossible" << endl;
  } else {
    for(int i=maxa;i>maxa/2;i--) 
      X[i] -=2;
    if( !(maxa & 1) ) // g
      X[maxa/2]--;
    if( check() )
      cout << "Possible" << endl;
    else
      cout << "Impossible" << endl;  
  }
}


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

    char s[100];
    rep(i, n){
        cin >> s[i];
    }
    
    bool check = false;
    rep(i, n){
        if(s[i] == 'Y'){
            check = true;
        }
    }

    if(check){
        cout << "Four" << endl;
    }
    else{
        cout << "Three" <<endl;
    }
    return 0;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = (int)1e9;
const ll  inf = (ll)1e18;
const int mod = 1000000007;
const int MAX_N = 100010;
const double PI = acos(-1);

ll N, M;
ll res = 0;

void dfs(vector<vector<int>> &v, vector<int> &p, string flag) {
	if (sz(flag) == N) {
		bool ok = true;
		rep(i, M) {
			int cnt = 0;
			for (auto a : v[i]) {
				if (flag[a] == '1') cnt++;
			}
			if (cnt % 2 != p[i]) {
				ok = false;
			}
		}
		if (ok) res++;
		return;
	}

	dfs(v, p, flag + "0");
	dfs(v, p, flag + "1");

	return;
}

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

	cin >> N >> M;

	vector<vector<int>> vec(M);

	rep(i, M) {
		int k;
		cin >> k;
		rep(j, k) {
			int s;
			cin >> s;
			s--;
			vec[i].push_back(s);
		}
	}

	vector<int> p(M);
	rep(i, M) cin >> p[i];

	dfs(vec, p, "");

	out(res);

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>
#include <functional>

using namespace std;

#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double

//ostream& operator << (ostream &a, const vector<int> &b) {
//    for (auto k : b) cout << k << " ";
//    return a;
//}

#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << (x) << "\n";
    const int INF = 1e18;
//    const int mod = 2600000069;
//    const int p = 10;
//    const ld PI = 3.1415926535;
#else
    #define dbg(x)
    const int INF = 1e18;
//    const int mod = 2600000069;
//    const int p = 179;
//    const ld PI = 3.1415926535;
#endif

//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,sse3,sse4")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("fast-math")
//#pragma GCC target("avx2")
//#pragma GCC optimize("section-anchors")
//#pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
//#pragma GCC optimize("vpt")
//#pragma GCC optimize("rename-registers")
//#pragma GCC optimize("move-loop-invariants")
//#pragma GCC optimize("unswitch-loops")
//#pragma GCC optimize("function-sections")
//#pragma GCC optimize("data-sections")

const int mod = 1e9 + 7;
const int MAXN = 3e6 + 1;

int f[MAXN];

int powmod(int a, int b) {
    if (b == 0) return 1;
    if (b == 1) return a;
    int k = powmod(a, b / 2);
    if (b % 2) return (((k * k) % mod) * a) % mod;
    else return (k * k) % mod;
}

inline int c(int n, int k) {
    int kr = powmod(f[k], mod - 2);
    int nkr = powmod(f[n - k], mod - 2);
    return (((f[n] * kr) % mod) * nkr) % mod;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    f[0] = 1;
    for (int i = 1; i < MAXN; i++) {
        f[i] = (f[i - 1] * i) % mod;
    }
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int ans = 0;
    for (int i = x1; i <= x2; i++) {
        ans = (ans + c(i + y2 + 1, i + 1) - c(i + y1, i + 1) + mod) % mod;
    }
    cout << ans;
}
/*

*/


Measured memory_bytes: 24312
#include <bits/stdc++.h>
#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)
using namespace std;
using ll = long long;
template<typename T>
inline bool chmax(T& a, const T& b) {
    if (a < b){
        a = b;
        return true;
    }
    return false;
}
template<typename T>
inline bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T> vector<T> make_vec(size_t n) { return vector<T>(n); }
template<typename T, typename... Args> auto make_vec(size_t n, Args... args) {
    return vector<decltype(make_vec<T>(args...))>(n, make_vec<T>(args...));
}
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value>::type fill_v(U& u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<!is_same<T, U>::value>::type fill_v(U& u, const V... v) {
    for (auto& e : u) fill_v<T>(e, v...);
}

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

template <typename T>
struct twodim_fenwick_tree {
    int h, w;
    vector<vector<T>> data;
    twodim_fenwick_tree(int h, int w) : h(h), w(w), data(h+1, vector<T>(w+1)) {}
    void add(int r, int c, T x=1) {
        for (int i = r+1; i <= h; i += i&-i)
            for (int j = c+1; j <= w; j += j&-j) data[i][j] += x;
    }
    T sum(int r, int c) {
        T res = 0;
        for (int i = r; i; i -= i&-i)
            for (int j = c; j; j -= j&-j) res += data[i][j];
        return res;
    }
    T sum(int r1, int c1, int r2, int c2) {
        return sum(r2, c2) - sum(r1, c2) - sum(r2, c1) + sum(r1, c1);
    }
};

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

    int n;
    cin >> n;
    vector<string> s(n);
    rep(i, n) cin >> s[i];

    auto f = [](string s) {
        ll ten = 0;
        ll x = 0;
        rep(i, s.size()) {
            if (s[i] == '.') ten = 1;
            else {
                if (ten > 0) ten *= 10;
                x *= 10;
                x += s[i] - '0';
            }
        }
        if (ten == 0) return make_pair(x, 1LL);
        ll g = gcd(x, ten);
        return make_pair(x / g, ten / g);
    };

    vector<pair<ll, ll>> a(n);
    rep(i, n) a[i] = f(s[i]);

    auto g = [](pair<ll, ll> p) {
        int two = 0, five = 0;
        while (p.first % 2 == 0) {
            two++;
            p.first /= 2;
        }
        while (p.first % 5 == 0) {
            five++;
            p.first /= 5;
        }
        while (p.second % 2 == 0) {
            two--;
            p.second /= 2;
        }
        while (p.second % 5 == 0) {
            five--;
            p.second /= 5;
        }
        return make_pair(two, five);
    };

    rep(i, n) a[i] = g(a[i]);

    twodim_fenwick_tree<int> ft(1000, 1000);
    rep(i, n) ft.add(a[i].first + 100, a[i].second + 100);

    ll ans = 0;
    rep(i, n) {
        int x = -a[i].first + 100;
        int y = -a[i].second + 100;
        ans += ft.sum(x, y, 1000, 1000);
        if (a[i].first + 100 >= x && a[i].second + 100 >= y) ans--;
    }
    ans /= 2;
    cout << ans << '\n';
}


Measured memory_bytes: 16600
N = int(input())
A = list(map(int, input().split()))

B = []

# b1 = A1 - B1 + A2 ... - AN (奇数個) が式変形で求められる
b1 = 0
for i in range(len(A)):
    if i % 2 == 0:
        b1 += A[i]
    else:
        b1 -= A[i]

B.append(b1)

# B[i] = 2 * A[i-1] - B[i-1] (式変形により)
for i in range(1, N):
    bi = 2 * A[i-1] - B[i-1] 
    B.append(bi)

print(' '.join(map(str, B)))


Measured memory_bytes: 19096
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define Rep(i,n) for(int i=1;i<=(n);++i)
using LL = long long;
using ULL = unsigned long long;

int main()
{
    int a, b, c, k;
	cin >> a >> b >> c >> k;
	if(k <= a) cout << k << endl;
	else if(k <= (a+b)) cout << a << endl;
	else cout << (a-c) + (a+b+c)-k << endl;
    return 0;
}

Measured memory_bytes: 3600
#include<iostream>
#include<cmath>
#include<string>
using namespace std;
string a,b;
int sum=0;
int main(){
	cin>>a>>b;
	int n=a.size(),m=b.size();
	for(int i=0;i<=n-1;i++){
		sum*=10;sum+=a[i]-'0';
	}
	for(int i=0;i<=m-1;i++){
		sum*=10;sum+=b[i]-'0';
	}
	int i=sqrt(sum);
	if(i*i==sum)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 256
n=int(input())
a=[]
b=[]
for i in range(n):
    ai,bi=map(int,input().split())
    a.append(ai)
    b.append(bi)
ans=0
for i in reversed(range(n)):
    ai=a[i]+ans
    push=0 if ai%b[i]==0 else b[i]-(ai%b[i])
    ans+=push
print(ans)

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

using namespace std;


int main()
{
  int N;
  string s, t;

  cin >> N;
  cin >> s;
  cin >> t;

  for(int i = 0; i < s.size(); i++) {
    if(t.find(s.substr(i)) == 0) {
      cout << t.size() + i << endl;
      return (0);
    }
  }
  cout << s.size() + t.size() << endl;
}


Measured memory_bytes: 256
import sys
from operator import itemgetter

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


class UnionFind:
    # Reference: https://note.nkmk.me/python-union-find/
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -self.parents[self.find(x)]

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}


def main():
    N, *XY = map(int, read().split())

    P = [(x, y) for x, y in zip(*[iter(XY)] * 2)]
    uf = UnionFind(N)

    Q = [(x, y, i) for i, (x, y) in enumerate(P)]

    Q.sort()
    for j in range(N - 1):
        if Q[j][0] == Q[j + 1][0]:
            uf.union(Q[j][2], Q[j + 1][2])

    Q.sort(key=itemgetter(1))
    for j in range(N - 1):
        if Q[j][1] == Q[j + 1][1]:
            uf.union(Q[j][2], Q[j + 1][2])

    ans = 0
    for vec in uf.all_group_members().values():
        x_points = len(set(P[i][0] for i in vec))
        y_points = len(set(P[i][1] for i in vec))
        ans += x_points * y_points - len(vec)

    print(ans)
    return


if __name__ == '__main__':
    main()


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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	string s;
	cin >> s;

	ll wcnt = 0;
	rep(i, s.size()) wcnt += (s[i] == 'W' ? 1 : 0);

	if(wcnt == 0){
		cout << 0 << endl;
		return 0;
	}

	ll ans = 0;
	ll f = 0;
	rep(i, s.size()){
		if(f == wcnt) break;

		if(s[i] == 'W') {
			ans += (i - f);
			f++;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 720
#include "bits/stdc++.h"

using namespace std;
using ll = long long;

//dp[i][j] : i番目まで見て表がj枚の確率
double dp[3000][3000];

int main()
{
	int n;
	cin >> n;
	dp[0][0] = 1.0;
	for (int i = 1; i <= n; ++i)
	{
		double p;
		cin >> p;
		dp[i][0] = dp[i - 1][0] * (1 - p);
		for (int j = 1; j <= i; ++j)
		{
			dp[i][j] = dp[i - 1][j] * (1 - p) + dp[i - 1][j - 1] * p;
		}
	}
	double ans = 0;
	for (int i = n / 2 + 1; i <= n; ++i)
	{
		ans += dp[n][i];
	}
	cout << setprecision(10);
	cout << ans << endl;
}

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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >=0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

typedef long long ll;
#define INF 1e9

int gcd(int a, int b){
  if(b == 0){
    return a;
  }
  return gcd(b, a%b);
}
string dream = "dream";
string erase = "erase";

bool isTrue(string s){
  REPR(i,s.length()-1){
    if(s[i] == 'm'){
      FOR(j, 1, 5){
        if(i-j < 0)
          return false;
        if(s[i-j] != dream[dream.length()-j-1])
          return false;
      }
      i-=4;
    }
    else if(s[i] == 'r'){
      if(i-1 < 3 || (s[i-1] != 'e'))
        return false;
      i-=2;
      if(s[i] == 'm'){
        FOR(j, 1, 5){
          if(i-j < 0)
            return false;
          if(s[i-j] != dream[dream.length()-j-1])
            return false;
        }
        i-=4;
      }
      else if(s[i] == 's'){
        FOR(j,1, 4){
          if(i-j<0)
            return false;
          if(s[i-j] != erase[erase.length()-j-2])
            return false;
        }
        i-=3;
      }
      else{
        return false;
      }
    }
    else if(s[i] == 'e'){
      FOR(j,1, 5){
        if(i-j<0)
          return false;
        if(s[i-j] != erase[erase.length()-j-1])
          return false;
      }
      i-=4;
    }
    else{
      return false;
    }
  }
  return true;
}

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

  cout << (isTrue(s)?"YES": "NO") << endl;

  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const int N=210000;
int n,k;
int a[N];
int go[N];
int main(){
	cin>>n>>k;
	for(int i=0;i<n;i++) cin>>a[i];
	int ans=0;
	go[0]=0;
	for(int i=1;i<n;i++){
		if(a[i]>a[i-1]) go[i]=go[i-1]+1;
		else go[i]=0;
		if(go[i]>=k-1) ans=1;
	}
	set<int> b;
	for(int i=0;i<k;i++) b.insert(a[i]);
	if(go[k-1]!=k-1) ans++;
	for(int i=k;i<n;i++){
		b.insert(a[i]);
		if(*b.begin()!=a[i-k]||*b.rbegin()!=a[i]){
			if(go[i]<k-1) ans++;
		}
		b.erase(a[i-k]);
	}
	cout<<ans<<endl;
	return 0;
}


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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define pll pair<ll, ll>
#define vll vector<ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

int main() {
  ll a, b, c;
  scanf("%lld %lld %lld", &a, &b, &c);

  priority_queue<ll, vector<ll>, greater<ll>> que;  // -> 0,1,2,...
  que.push(a);
  que.push(b);
  que.push(c);

  ll v1 = que.top();
  que.pop();
  ll v2 = que.top();
  que.pop();

  cout << (v1 * v2 / 2) << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		char[] c = sc.next().toCharArray();
		
		if(c[0] == c[1] && c[2] == c[1]) {
			System.out.println("No");
		}
		else {
			System.out.println("Yes");
		}

	}

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

ll cnt[100010];
 
int main(){
    int n;
    cin>>n;

    ll ans=0;
    rep(i,n){
        ll a;
        cin>>a;
        cnt[a]++;
        ans+=a;
    }

    int q;
    cin>>q;
    while(q--){
        ll b,c;
        cin>>b>>c;
        ans-=b*cnt[b];
        ans+=c*cnt[b];
        cnt[c]+=cnt[b];
        cnt[b]=0;
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 4280
#include <iostream>
using namespace std;
typedef long long ll;

int main()
{
    ll n, t;
    cin >> n >> t;
    ll a[200001];
    ll ans = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 0; i < n - 1; i++){
        ans += min(t, a[i + 1] - a[i]);
    }
    cout << ans + t << endl;
}

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

const int N = 101;
const int MAX = 1e5;
const int64_t INF = 1e18;

int n, sum;
int w[N], v[N];
int64_t dp[2][MAX + 1];

signed main() {
    std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);

    std::cin >> n >> sum; 
    
    for (int i = 1; i <= n; i++) {
        std::cin >> w[i] >> v[i];
    }

    std::fill(*dp, *dp + 2 * (MAX + 1), INF);

    dp[0][0] = 0;
    for (int i = 1; i <= n; i++) {
        int id = i & 1;
        
        for (int j = 0; j <= MAX; j++) {
            dp[id][j] = dp[id ^ 1][j];
            if (j < v[i]) continue;

            dp[id][j] = std::min(dp[id][j], dp[id ^ 1][j - v[i]] + w[i]);
        }
    }

    for (int j = MAX; j >= 0; j--) {
        if (dp[n & 1][j] <= sum) {
            std::cout << j;
            break;
        }
    }

    return 0;
}



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

int main(){
	int n,k;
	cin >> n >> k;
	vector<int> h(n);
	rep(i,n) cin >> h[i];
	
	int res = 0;
	rep(i,n){
		if(h[i] >= k) res++;
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<stdio.h>
using namespace std;

int main(){
  int h,w;
  int i,j;

  for(;;){

    cin>>h>>w;

    if(h==0&&w==0){
      break;
    }

    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
        cout<<"#";
      }
      cout<<endl;
    }
    cout<<endl;
  }

  return 0;
}

Measured memory_bytes: 3096
import java.util.Scanner;

public class Main {

	static class Dice {
		private int[] num;
		private int[] x_map = new int[4];
		private int[] y_map = new int[4];

		public Dice() {
			this( new int[]{1,2,3,4,5,6} );
		}

		public Dice(int input_num[]) {
			num = new int[6];
			num[0] = input_num[0];
			num[1] = input_num[1];
			num[2] = input_num[2];
			num[3] = input_num[3];
			num[4] = input_num[4];
			num[5] = input_num[5];
		}

		public void init() {
		//横軸
			x_map[0] = num[3];
			x_map[1] = num[0];
			x_map[2] = num[2];
			x_map[3] = num[5];
		//縦軸
			y_map[0] = num[4];
			y_map[1] = num[0];
			y_map[2] = num[1];
			y_map[3] = x_map[3];
		}

		public int get_no() {
			return x_map[1];
		}

		public void roll(char dc) {
			switch( dc ) {
			case 'N' :
				y_map[1] = y_map[2];
				y_map[2] = x_map[3];
				x_map[3] = y_map[0];
				y_map[0] = x_map[1];

				x_map[1] = y_map[1];
				break;
			case 'S' :
				y_map[1] = y_map[0];
				y_map[0] = x_map[3];
				x_map[3] = y_map[2];
				y_map[2] = x_map[1];

				x_map[1] = y_map[1];
				break;
			case 'E' :
				x_map[1] =  x_map[0];
				x_map[0] =  x_map[3];
				x_map[3] =  x_map[2];
				x_map[2] =  y_map[1];

				y_map[1] = x_map[1];
				break;
			case 'W' :
				x_map[1] =  x_map[2];
				x_map[2] =  x_map[3];
				x_map[3] =  x_map[0];
				x_map[0] =  y_map[1];

				y_map[1] = x_map[1];
				break;
			}
		}
	}


	public static void main(String[] args) {

		int[] input_num = new int[6];
		int dice_face_num = 6;
		String roll_str ="";

		Scanner sc= new Scanner( System.in );

		for ( int i = 0 ; i < dice_face_num ; i++ ) {
			input_num[i] = sc.nextInt();
		}

		roll_str = sc.next();

		Dice dice = new Main.Dice(input_num);

		dice.init();

		for( int i = 0 ; i < roll_str.length(); i++ ) {
			dice.roll(roll_str.charAt(i));
//			System.out.println(roll_str.charAt(i) +":"+ dice.get_no());
		}
		System.out.println( dice.get_no() );
		sc.close();
	}

}


Measured memory_bytes: 26356
#include<stdio.h>
#include<algorithm>

int main()
{
	int n, m, X, Y, x_max = -200, y_min = 200, tmp;
	scanf("%d%d%d%d", &n, &m, &X, &Y);
	for (int i = 0; i < n; ++i)
	{

		scanf("%d", &tmp);
		x_max = std::max(x_max, tmp);
	}
	for (int i = 0; i < m; ++i)
	{
		scanf("%d", &tmp);
		y_min = std::min(y_min, tmp);
	}

	if (x_max < Y && y_min > X && x_max < y_min)
		printf("No War\n");
	else
		printf("War\n");

	return 0;
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;


public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(buf.readLine());
		String[] x = buf.readLine().split(" ");
		String[] y = buf.readLine().split(" ");
		double manhattan = 0;
		double euclidean = 0;
		double chebyshev = 0;
		double minkowski_p3 = 0;
		for (int i = 0; i < x.length; i++) {
			manhattan += Math.abs(Integer.parseInt(x[i]) - Integer.parseInt(y[i]));
			euclidean += Math.pow(Integer.parseInt(x[i]) - Integer.parseInt(y[i]), 2);
			minkowski_p3 += (Math.pow(Math.abs(Integer.parseInt(x[i]) - Integer.parseInt(y[i])), 3));
			if (Math.abs(Integer.parseInt(x[i]) - Integer.parseInt(y[i])) > chebyshev) {
				chebyshev = Math.abs(Integer.parseInt(x[i]) - Integer.parseInt(y[i]));
			}
		}
		euclidean = Math.sqrt(euclidean);
		minkowski_p3 = Math.cbrt(minkowski_p3);
		String line_sep = System.getProperty("line.separator");
		System.out.println(manhattan + line_sep + euclidean + line_sep + minkowski_p3 + line_sep + chebyshev);
	}

}

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

int main() {
  long long int n;
  cin >> n;
  
  long long int sum = 0;
  for (long long int i = 1; i <= n; ++i) {
    if (i % 3 == 0 || i % 5 == 0) continue;
    else sum += i;
  }
  
  cout << sum << endl;
}


Measured memory_bytes: 3652
from collections import deque
N, M = map(int, input().split())
G0 = [set([i]) for i in range(N)]

A = set(range(N))

for i in range(M):
    a, b = map(int, input().split())
    G0[a-1].add(b-1)
    G0[b-1].add(a-1)

G = [A - g for g in G0]

b = 1 << (N//2)
c = [-1]*N
for i in range(N):
    if c[i] != -1:
        continue
    p = 0; s = 0
    que = deque([i])
    c[i] = 0
    while que:
        v = que.popleft()
        s += 1
        if c[v] == 0:
            p += 1
        for w in G[v]:
            if c[w] == -1:
                c[w] = c[v]^1
                que.append(w)
            elif c[w] == c[v]:
                print(-1)
                exit(0)
    b = (b >> p) | (b >> (s-p))

p = N//2 - ((b & -b).bit_length()-1)
q = N - p
print(p*(p-1)//2 + q*(q-1)//2)

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

class Dat
{
public:
  int num, frq;
  Dat():num(0), frq(0) {}
};

class GreaterFrq
{
public:
  bool operator()(const Dat& lhs, const Dat& rhs)
  {
    if (lhs.frq == rhs.frq)
      return lhs.num < rhs.num;
    return lhs.frq > rhs.frq;
  }
};

int main()
{
  int in;
  vector<Dat> dat(100+1);
  while (cin >> in) {
    dat[in].num = in;
    ++dat[in].frq;
  }

  sort(dat.begin(), dat.end(), GreaterFrq());

  int f = dat.front().frq;
  for (int i = 0; i < dat.size(); ++i) {
    if (f == dat[i].frq)
      cout << dat[i].num << endl;
  }

  return 0;

}

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

signed main(){
    string S;
    cin >>S;
    int bans=0;
    int wans=0;
    int ans;
    REP(i,S.size()){
        if(( i%2 == 0 &&S[i]=='0')||(i%2==1 &&S[i]=='1')){
            bans++;
        }
        else{
            wans++;
        }

    }
    cout<<min(bans,wans)<<endl;
}

Measured memory_bytes: 512
#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include <map>
#include <fstream>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <assert.h>
#include <complex>
using namespace std;
#define LONG_INF 10000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353LL
#define seg_size 65536*4
#define REP(i,n) for(long long i = 0;i < n;++i)
int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int cnt[10][10] = {};
	for (int i = 1; i < s.length(); ++i) {
		cnt[s[i - 1] - '0'][s[i] - '0']++;
	}
	vector<int> input;
	REP(i, 9) {
		input.push_back(i + 1);
	}
	long long ans = 10000000;
	vector<int> gogo;
	do {
		long long now = 0;
		for (int q = 0; q < input.size(); ++q) {
			int visited[10] = {};
			visited[q] = 1;
			queue<pair<int,int>> next;
			next.push(make_pair(q, 1));
			while (next.empty() == false) {
				pair<int, int> go = next.front();
				next.pop();
				now += go.second * cnt[input[q]][input[go.first]];
				go.second++;
				if (go.first - 3 >= 0 && visited[go.first - 3] == 0) {
					visited[go.first - 3] = 1;
					next.push(make_pair(go.first - 3, go.second));
				}
				if (go.first % 3 != 0&&visited[go.first - 1] == 0) {
					visited[go.first - 1] = 1;
					next.push(make_pair(go.first - 1, go.second));
				}
				if (go.first + 3 < 9 && visited[go.first + 3] == 0) {
					visited[go.first + 3] = 1;
					next.push(make_pair(go.first + 3, go.second));
				}
				if (go.first % 3 != 2 && visited[go.first + 1] == 0) {
					visited[go.first + 1] = 1;
					next.push(make_pair(go.first + 1, go.second));
				}
			}
		}
		if (ans > now) {
			ans = now;
			gogo = input;
		}
	} while (next_permutation(input.begin(), input.end()));
	REP(i, 3) {
		REP(q, 3) {
			cout << gogo[i * 3 + q];
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3284
#include <stdio.h>
#include <stdlib.h>

#define MAX_LUGGAGE_NUM    100000
#define MAX_TRUCK_NUM      100000

static int BinarySearch(int *weight_buff, int luggage_num, int truck_num, int mid);		/* set luggage in track */

/***********************************************************************************
 ++module <main>
 ++outline
	main function
 ++arguments
	<>			<>					[]
 ++supp
 	<return>
 	  nothing
 ++end_module
************************************************************************************/
int main(void)
{
    int left = 0;
	int right;
	int mid;
	int sum = 0;
	int ans;				/* left or right side next value */
	int luggage_num;		/* luggage num */
	int truck_num;			/* truck num */
	int *weight_buff;		/* luggage weight buffer */
	int loop = 0;
	
	scanf("%d %d", &luggage_num, &truck_num);			/* get luggage num and truck num */
	
	if((luggage_num <= MAX_LUGGAGE_NUM)					/* If luggage num is within max luggage num */
		&& (truck_num <= MAX_TRUCK_NUM))
	{
		weight_buff = (int*)malloc(luggage_num * sizeof(int));							/* malloc buffer size*/
		
		while(((scanf("%d", &(weight_buff[loop]))) != EOF) && (loop < luggage_num))		/* get weight data */
		{
			sum += weight_buff[loop];													/* get all sum data */
			loop++;
		}
		right = sum;																	/* set max value right side*/ 
		
		while(right - left > 1)															/* search best answer with small diff */
		{
	        mid = (right + left) / 2;													/* calcuration middle value */
			ans = BinarySearch(weight_buff, luggage_num, truck_num, mid);				/* find better value */
	        if(ans >= luggage_num)
			{
	            right = mid;		/* max value is more little value than middle */
			}
			else
			{
	            left = mid;			/* max value is more big value than middle */
			}
		}
    }
    printf("%d\n",right);	/* output result */
	
	free(weight_buff);		/* free process */
	
    return 0;
}

/***********************************************************************************
 ++module <BinarySearch>
 ++outline
	set luggage in track
 ++arguments
	<int>			<*weight_buff>					[weight buffer point]
	<int>			<luggage_num>					[common load num]
	<int>			<truck_num>						[truck num]
	<int>			<mid>							[middle value]
 ++supp
 	<return>
	  weight_point     :truck in luggage num 
 ++end_module
************************************************************************************/
static int BinarySearch(int *weight_buff, int luggage_num, int truck_num, int mid)
{
	int sum;				/* sum load value */
	int weight_point = 0;	/* luggage set point */ 
	int loop;
	
	for(loop = 0; loop < truck_num; loop++ )			/* loop all track set luggage */
	{
		sum = 0;
		while((sum + weight_buff[weight_point] <= mid)	/*  while little than average value */
			&& (weight_point < luggage_num))			
		{
			sum += weight_buff[weight_point];			/* sum track weight */
			weight_point++;								/* set next weight */
		}
		if(weight_point == luggage_num)					/*  if luggage is all in track */
		{
			break;
		}
	}
	return weight_point;   								 /* truck in luggage num */
}



Measured memory_bytes: 2100
N = int(input())
S = [input() for i in range(N)]
d = {}
m = 0
for i in S:
    if i in d:
        d[i] += 1
        if d[i] > m:
            m = d[i]
    else:
        d[i] = 1
        
d = dict(sorted(d.items(), key = lambda x:x[1], reverse=True))
a = {}
for i in d.keys():
    if m <= d[i]:
        a[i] = 0
a = sorted(a)
for i in a:
    print(i)

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

#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef long double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int main() {
	int n, k, q; scanf("%d%d%d", &n, &k, &q);
	vi ans(n + 1, 0);
	for1(i, q) {
		int input; scanf("%d", &input);
		ans[input]++;
	}
	for1(i, n) {
		ans[i] - q + k > 0?cout << "Yes\n":cout << "No\n";
	}
}










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

using namespace std;
typedef pair<int,int> pii;
int _w;

int n;
set<pii> st;

int main() {
	cin >> n;
	for( int i = 1; i <= n; ++i )
		for( int j = i+1; j <= n; ++j )
			st.insert( pii(i, j) );
	int L, R;
	if( n & 1 ) {
		L = 1, R = n-1;
	} else {
		L = 1, R = n;
	}
	while( L < R ) {
		st.erase( pii(L, R) );
		++L, --R;
	}
	printf( "%d\n", (int)st.size() );
	for( pii edge : st )
		printf( "%d %d\n", edge.first, edge.second );
	return 0;
}


Measured memory_bytes: 3980
n, m = map(int, input().split())
g = [[] for _ in range(n)]

for _ in range(m):
	a, b = map(int, input().split())
	a -= 1; b-=1;
	g[a].append(b)
	g[b].append(a)

dist = [-1]*n
dist[0] = 0
prev = [-1]*n

que = [0]
pos = 0
while pos < len(que) :
	v = que[pos]; pos += 1;
	for w in g[v]:
		if dist[w] == -1 :
			dist[w] = dist[v] + 1
			prev[w] = v;
			que.append(w)

if -1 in dist :
	print("No");
else :
	print("Yes");
	for i in range(1,n):
		print(prev[i]+1);



Measured memory_bytes: 35488
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    int n,k;
    cin >> n >> k;
    vector<int> snk(n);
    rep(i,k){
        int d;
        cin >> d;
        rep(j,d){
            int a;
            cin >> a;
            a = a - 1;
            snk[a]++;
        }
    }
    int ans = 0;
    rep(i,n){
        if(snk[i] == 0) ans++;
    }
    cout << ans << endl;
}

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

using namespace std;

const int N = 20;

int n;
pair <int, int> dp[1 << N];

int main(){
    scanf("%d", &n); memset(dp, 0, sizeof(dp));
    for (int i = 0; i < (1 << n); i++) scanf("%d", &dp[i].first);
    for (int i = 0; i < n; i++) {
        for (int mask = 0; mask < (1 << n); mask++) {
            if (mask & (1 << i)) {
                dp[mask].second = max(dp[mask].second, dp[mask ^ (1 << i)].first);
                if (dp[mask].first < dp[mask].second) swap(dp[mask].first, dp[mask].second);
            }
        }
    }

    int last = 0;
    for (int i = 1; i < (1 << n); i++) {
        cout << max(last, dp[i].first + dp[i].second) << "\n";
        last = max(last, dp[i].first + dp[i].second);
    }
    return 0;
}


Measured memory_bytes: 11264
#include<bits/stdc++.h> 
#define IRONMAN ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(int i=0; i<n; i++)
#define at(i,a) for(auto &i: a)
using namespace std; 
void solve(); 
int main() 
{ 
   IRONMAN

   #ifndef ONLINE_JUDGE 
   freopen("input.txt", "r", stdin); 
   freopen("output.txt", "w", stdout); 
   #endif 
   
   int t=1; 
   while(t--) 
   { 
      solve(); 
      cout<<"\n"; 
   } 
   
   cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl; 
   return 0; 
} 
void solve() 
{
   int n;cin>>n;
   string ans="";
   rep(i,n){
       int a,b;
       cin>>a>>b;
       if(a==b) ans.append("1");
       else ans.append("0");
   }
   int c=0;
   rep(i,n){
       if(ans[i]=='0'){
           if(c>=3) {
               cout<<"Yes"<<endl;
               return;
           }
           c=0;
           continue;
       }
       ++c;
   }
   (c>=3)? (cout<<"Yes"):(cout<<"No");
   
} 

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

#define what_is(x)    cerr<<#x<<" is "<<x<<"\n";
#define rep(i,a,n)    for(int i=a; i<=n; ++i)
#define rep1(i,a,n)   for(int i=a; i>=n; --i)
#define pb            push_back
#define mp            make_pair
#define int           long long
#define fr            first
#define sc            second
#define vc            vector
#define sz(v)         (int)v.size()
#define all(x)        (x).begin(),(x).end()
#define rall(x)       (x).rbegin(),(x).rend()
#define M             1000000007
#define MM            998244353
#define PI            3.14159265358979
#define INF           1000000000000000

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mii;

int n,m,ans; string str;

int solve(){
    int a,b,c; cin>>a>>b>>c;
    a-=b;
    c-=a;
    cout<<max(c,0ll);
    return 0;
}

signed main() {
    ios::sync_with_stdio(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {


	public static void main(String[] args) {

//		long ans = 0;
//		double ans = 0.0;
		int ans = 0;
//		String ans = "";

		Scanner sc = new Scanner(System.in);
//		double waru = 1000000007;


//		long n = sc.nextLong();
//		long m = sc.nextLong();
//		long k = sc.nextLong();

//		int n = sc.nextInt();
//		int m = sc.nextInt();
//		int k = sc.nextInt();
//		int v = sc.nextInt();
		String s = sc.next();


//		String string = sc.next();
//		StringBuilder s = new StringBuilder(string);

		boolean f = false;

//		String[] s = new String[n];

//		int[] a = new int[n];
//		int[] b = new int[n];
//		long[] a = new long[n];
//		long[] b = new long[n];
//		int[][] a = new int[n][m];

//		ArrayList<Long> list = new ArrayList<>();

//		for (int i = 0; i < n; i++) {
//			a[i]= sc.nextInt();
//		}

//		for (int i = 0; i < h; i++) {
//			for(int j = 0; j < w; j++) {
//				a[i][j] = sc.nextInt();
//			}
//		}

		boolean ff = true;
		String[] strArray = s.split("");
		for(int i = 0; i < strArray.length; i++) {
			if(i+1 < strArray.length) {
				if(strArray[i].equals("h")&&strArray[i+1].equals("i")) {
					i++;
				} else {
					System.out.println("No");
					f = true;
					break;
				}
			} else {
				System.out.println("No");
				f = true;
				break;
			}
		}


		if(!f)System.out.println("Yes");

//		System.out.println(ans);

		sc.close();
	}
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1e5+7;
ll a[maxn];
int main(){
    string s;
    cin>>s;
    int ans=0;
    for(int i=1;i<s.size();i++){
        if(s[i]!=s[i-1]) ans++;
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef pair<int, int> p;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m, c;
    cin >> n >> m >> c;
    int ans = 0;

    vi b(m);
    REP(i, m)
    {
        cin >> b[i];
    }

    REP(i, n)
    {
        int score = c;
        REP(j, m)
        {
            int a;
            cin >> a;
            score += a * b[j];
        }

        if(score > 0)
        {
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int N;
	scanf("%d", &N);
	int a[N], b[N], c[N], d[N], matched[N], nmatched = 0;
	for (int i = 0; i < N; i++) {
		scanf("%d %d", &a[i], &b[i]);
	}
	for (int i = 0; i < N; i++) {
		scanf("%d %d", &c[i], &d[i]);
	}
	for (int i = 0; i < N; i++) {
		matched[i] = 0;
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N - i - 1; j++) {
			if (a[j] > a[j + 1]) {
				int tmp;
				tmp = a[j];
				a[j] = a[j + 1];
				a[j + 1] = tmp;
				tmp = b[j];
				b[j] = b[j + 1];
				b[j + 1] = tmp;
			}
		}
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N - i - 1; j++) {
			if (c[j] > c[j + 1]) {
				int tmp;
				tmp = c[j];
				c[j] = c[j + 1];
				c[j + 1] = tmp;
				tmp = d[j];
				d[j] = d[j + 1];
				d[j + 1] = tmp;
			}
		}
	}
	for (int i = 0; i < N; i++) {
		int max = -1, maxj;
		for (int j = 0; j < N; j++) {
			if (a[j] > c[i]) {
				break;
			}
			if (!matched[j] && b[j] < d[i] && b[j] > max) {
				max = b[j];
				maxj = j;
			}
		}
		if (max != -1) {
			matched[maxj] = 1;
			nmatched++;
		}
	}
	printf("%d\n", nmatched);
}


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

struct Trie {
  Trie *parent;
  bool last = false;
  char chara;
  Trie *next[26];
  Trie(char c='$', Trie *p=(Trie*)0) { fill_n(next,26,(Trie*)0); chara = c; parent = p; }
  Trie *find(string t) {
    Trie *r = this;
    rep(i,t.size()) {
      ll pos = t[i]-'a';
      if (!r->next[pos]) r->next[pos] = new Trie(t[i], r);
      r = r->next[pos];
    }
    r->last = true;
    return r;
  }
};

int main() {
  ll N; cin >> N;
  string S[N]; rep(i,N) { cin >> S[i]; reverse(all(S[i])); }

  Trie tr, st[N]; rep(i,N) st[i] = *tr.find(S[i]);

  ll result = 0;
  rep(i,N) {
    set<char> used;
    while (st[i].parent) {
      // cout << "---" << st[i].chara << " " << result << endl;
      used.insert(st[i].chara);
      st[i] = *st[i].parent;
      for (auto x: used) {
        ll pos = x-'a';
        if (st[i].next[pos]) result += (st[i].next[pos])->last;
      }
    }
  }

  result -= N;
  cout << result << endl;
  return 0;
}


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

int main(){
int n,a,b=1;
  cin >> n >>a;
  for(int i=0 ; i<n; i++){
  if (b*2 <= b+a) b=b*2;
    else b= b+a;
  }
  cout << b << endl;
}

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


int n, m, a, b, q, cor[100010][14], v[100010], d[100010], c[100010];

vector <int> e[100010];

void dfs(int st, int deep, int cl)
{
	if(deep == -1)
		return;
	if(cor[st][deep])
		return;
	cor[st][deep] = cl;
	for(int i = 0; i < e[st].size(); ++ i)
		dfs(e[st][i], deep-1, cl);
}

int main()
{
	cin>>n>>m;
	for(int i=1; i<=m; i++)
	{
		cin>>a>>b;
		e[a].push_back(b);
		e[b].push_back(a);
	}
	for(int i=1; i<=n; i++)
		e[i].push_back(i);
	cin>>q;
	for(int i=1; i<=q; i++)
		cin>>v[i]>>d[i]>>c[i];
	for(int i=q; i>=1; i--)
		dfs(v[i], d[i], c[i]);
	for(int i=1; i<=n; i++)
		cout<<cor[i][0]<<endl;
	return 0;
}

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

struct BipartiteMatching {
    int n, m;
    vector<vector<int>> graph;
    vector<int> matched, match, edgeview, level;
    vector<int> reached[2];
    BipartiteMatching(int n, int m) : n(n), m(m), graph(n), matched(m, -1), match(n, -1) {}

    bool assignLevel() {
        bool reachable = false;
        level.assign(n, -1);
        reached[0].assign(n, 0);
        reached[1].assign(m, 0);
        queue<int> q;
        for (int i = 0; i < n; i++) {
            if (match[i] == -1) {
                level[i] = 0;
                reached[0][i] = 1;
                q.push(i);
            }
        }
        while (!q.empty()) {
            auto cur = q.front(); q.pop();
            for (auto adj : graph[cur]) {
                reached[1][adj] = 1;
                auto next = matched[adj];
                if (next == -1) {
                    reachable = true;
                }
                else if (level[next] == -1) {
                    level[next] = level[cur] + 1;
                    reached[0][next] = 1;
                    q.push(next);
                }
            }
        }
        return reachable;
    }

    int findpath(int nod) {
        for (int &i = edgeview[nod]; i < graph[nod].size(); i++) {
            int adj = graph[nod][i];
            int next = matched[adj];
            if (next >= 0 && level[next] != level[nod] + 1) continue;
            if (next == -1 || findpath(next)) {
                match[nod] = adj;
                matched[adj] = nod;
                return 1;
            }
        }
        return 0;
    }

    int solve() {
        int ans = 0;
        while (assignLevel()) {
            edgeview.assign(n, 0);
            for (int i = 0; i < n; i++)
                if (match[i] == -1)
                    ans += findpath(i);
        }
        return ans;
    }
};

int bx[205], by[205];

int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%d%d",bx+i,by+i);
    BipartiteMatching bm(n,n);
    for(int i=0;i<n;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        for(int j=0;j<n;j++)
        {
            if(x>bx[j] && y>by[j])
                bm.graph[i].push_back(j);
        }
    }
    printf("%d\n",bm.solve());
}


Measured memory_bytes: 764
#include<stdio.h>
int main(){
	int n;
	scanf("%d",&n);
	int i;
	for(i=1;i<=n;i++){
		if(i%3==0) printf(" %d",i);
		else{
			int x=i;
			while(x){
				if(x%10==3){
					printf(" %d",i);
					break;
				}
				x/=10;
			}
		}
	}
	printf("\n");
	return 0;
}



Measured memory_bytes: 2104
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define MOD 1000000007
#define INF 1000000000000000000
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

int main()
{
	int n, x;
	cin >> n >> x;
	vector <int> L(n);
	int ans = 1, d = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> L[i];
		d = d + L[i];
		if(d <= x)
			ans++;
	}
	cout << ans;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<27);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int segtree[816225][2],n;
bool delayed[816225];

void eval(int i, int l, int r){
	if(delayed[i]){
		segtree[i][0] = segtree[i][1]+l;
		if(r-l>1){
			segtree[i*2+1][1] = segtree[i][1];
			delayed[i*2+1] = true;
			segtree[i*2+2][1] = segtree[i][1];
			delayed[i*2+2] = true;
		}
		delayed[i] = false;
	}
}

int query(int a, int b, int i = 0, int l=0, int r=n){
	eval(i,l,r);
	if(r<=a || b<=l){
		return INF;
	}
	if(a<=l && r<=b){
		return segtree[i][0];
	}else{
		return std::min(query(a,b,i*2+1,l,(l+r)/2),query(a,b,i*2+2,(l+r)/2,r));
	}
}

void update(int a, int b, int v, int i = 0, int l=0, int r=n){
	eval(i,l,r);
	if(r<=a || b<=l){
		return;
	}
	if(a<=l && r<=b){
		segtree[i][1] = v;
		delayed[i] = true;
		eval(i,l,r);
	}else{
		update(a,b,v,i*2+1,l,(l+r)/2);
		update(a,b,v,i*2+2,(l+r)/2,r);
		segtree[i][0] = std::min(segtree[i*2+1][0],segtree[i*2+2][0]);
	}
}

int main(void){
	int h,i,j,a,b,v,ans;
	std::cin >> h >> n;
	for(i=0; i<h; ++i){
		std::cin >> a >> b; --a;
		if(a){
			v = query(a-1,a)-(a-1);
		}else{
			v = INF;
		}
		update(a,b,v);
		ans = query(0,n)+i+1;
		if(ans<INF){
			std::cout << ans << std::endl;
		}else{
			std::cout << (-1) << std::endl;
		}
	}
	return 0;
}


Measured memory_bytes: 8248
#include <stdio.h>
 
int main(void) {

	int k, a, b, i;
	
	scanf("%d %d %d", &k, &a, &b);
	
	for(i = 0; ; i++){
		if(k * i >= a && k * i <= b){
			printf("OK");
			break;
		}
		else if(k * i > b){
			printf("NG");
			break;
		}
	}
	
	return 0;
}

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

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

  long double deposit = 100;
  long double interest = 1.01;

  int cnt = 0;
  while(x > deposit){
    deposit = floor(deposit * interest);
    cnt++;
  }

  cout << cnt << endl;
}

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

int main(){
	int n,a,s;

	while( cin >> n , n ){
		vector<int> vc;
		for(int i=0 ; i<n ; ++i ){
			for(int j=0,s=0 ; j<5 ; ++j ){
				cin >> a;
				s += a;
				if( j == 4 )
					vc.push_back( s );
			}
		}
		sort( vc.begin() , vc.end() );
		cout << vc[vc.size()-1] << " " << vc[0] << endl;
	}
}

Measured memory_bytes: 0