akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, N) for (int i = 0; i < (N); ++i)
#define rep2(i, a, b) for (ll i = a; i <= b; ++i)
#define rep3(i, a, b) for (ll i = a; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(c) begin(c), end(c)
#define ok() puts(ok ? "Yes" : "No");
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll, ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
// clang++ -std=c++11 -stdlib=libc++

int D;
int main() {
  cin >> D;
  if (D == 25) {
    puts("Christmas");
  }
  if (D == 24) {
    puts("Christmas Eve");
  }
  if (D == 23) {
    puts("Christmas Eve Eve");
  }
  if (D == 22) {
    puts("Christmas Eve Eve Eve");
  }
  return 0;
}


Measured memory_bytes: 3528
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll K;
string S;
bool same_ht = false;  //S.head == S.tale;
vector<ll> renzoku;  //Sを構成する文字の各所での連続数(のみ)
ll cn = 0;  //変更箇所数

/*n個の同種の文字が並んでいるならn/2個を変えることで改善*/
int main(){
  cin >> S >> K;
  int len = S.size();

  if(S[0] == S[len-1]) same_ht = true;  //語頭と語尾が同じ

  ll i = 0;
  while(i < len){
    ll j = 0;
    while(S[i+j] == S[i]) j++;
    renzoku.push_back(j);    //S[i]の、iからの連続数を記録
    i += j; j = 0;
  }

  int rlen = renzoku.size();
  if(rlen == len && (!same_ht))  //語頭語尾が同じかつ最大連続数が1
    cn = 0;
  else if(rlen == 1)       //一種類の文字で構成されている
    cn = K * renzoku[0] / 2;
  else{
    if(!same_ht){
      for(int k = 0; k < rlen; k++)
        cn += renzoku[k] / 2;
      cn *= K;
    }else{
      for(int k = 1; k < rlen-1; k++)
        cn += renzoku[k] / 2;
      cn *= K;  //語頭語尾以外はK箇所
      cn += renzoku[0] / 2 + renzoku[rlen-1] / 2;  //1term目の語頭とKterm目の語尾は特別
      cn += (K-1) * ((renzoku[0] + renzoku[rlen-1]) / 2);  //語頭と語尾の設置部分はK-1か所
    }
  }

  cout << cn << endl;
  return 0;
      
}

  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;


void solve(){

    int n;
    string s;
    cin >> n;
    cin >> s;
    int count=0;
    rep(i,n-2){
        if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
            count++;
        }
    }
    cout << count << endl;
}

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


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
int main(void) {
	char a, b;
	cin >> a >> b;
	string s, t;
	for (int i = 0;i < b-'0';i++) {
		s += a;
	}
	for (int i = 0;i < a-'0'; i++) {
		t += b;
	}
	if (s < t)cout << s << endl;
	else cout << t << endl;
	return 0;
}

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

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s; cin>>s;
	map<char,int> ct;
	for (const char &ch : s)
		ct[ch]++;
	vector<int> v={ct['a'],ct['b'],ct['c']};
	sort(v.begin(),v.end());
	cout<<(v.back()-v.front()<=1?"YES":"NO")<<"\n";
	return 0;
}

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

int main()
{
    int n,temp,count,max=-1,ans=1;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        temp=i;
        count=0;
        while(temp%2==0)
        {
            temp/=2;
            count++;
        }
        if(count>max)
        {
            max=count;
            ans=i;
        }
    }
    cout<<ans<<endl;

    return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fast                                                                   \
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define ll long long
#define f(i, n) for (int i = 0; i < n; i++)
#define ff(i, n) for (int i = 1; i <= n; i++)
#define F first
#define S second
#define vpii vector<pair<int,int> >
#define sz size()
#define all(v) v.begin(),v.end()
#define pb push_back   
#define PB pop_back
#define vl vector<int>
#define mp make_pair
#define mod 1000000007
typedef unsigned long long ull;
const int N = 200005;
const int MOD = 998244353 ;

void solve(){
    int n, ans = 0, cnt = 0, k;
    cin>>n;
    vl v;
    f(i,n){
        cin>>k;
        v.pb(k);
    }
    sort(all(v));
    f(i,n-1)v.pb(v[i]);
    sort(all(v));
    reverse(all(v));
    f(i,n-1)ans += v[i];
    cout<<ans;
}

int32_t main() {
    fast
    int t;
    t = 1;
    //cin >> t;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 7428
def main():
    X, Y = map(int, input().split())
    remain = Y - 2 * X
    ans = True
    if remain < 0:
        ans = False
    if remain % 2 != 0:
        ans = False
    if remain//2 > X:
        ans = False
    print('Yes' if ans else 'No')

if __name__ == '__main__':
    main()


Measured memory_bytes: 9176
a,b = map(int,input().split())

def xor(n):
    if (n + 1)%2 == 0:
        if (n + 1)%4:
            return 1
        else:
            return 0
    else:
        if n%4:
            return 1^n
        else:
            return n
print(xor(a-1)^xor(b))

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

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = (a); i > (b); --i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(ll s : (x)) cin >> s
#define mp make_pair
#define bitcnt __builtin_popcount
#define All(a) (a).begin(), (a).end()
// template <typename T = long long> inline T IN() {
//     T x;
//     cin >> x;
//     return (x);
// }
// inline void CIN() {}
// template <class Head, class... Tail>
// inline void CIN(Head &&head, Tail &&... tail) {
//     cin >> head;
//     CIN(move(tail)...);
// } CIN(__VA_ARGS__) CIN(__VA_ARGS__) CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef priority_queue<int> PQ;
// typedef priority_queue<int, V, greater<int>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int n;
V a;
VL s;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(true) {
        cin >> n;
        if(n == 0) return 0;
        a.resize(n);
        s.resize(n + 1);
        REP(i, n) cin >> a[i];
        s[0] = 0;
        REP(i, n) { s[i + 1] += s[i] + a[i]; }
        ll ans = -LINF;
        REP(i, n + 1) REP(j, i) { ans = max(ans, s[i] - s[j]); }
        cout << ans << "\n";
        a.clear();
        s.clear();
    }
}



Measured memory_bytes: 3184
# -*- coding: utf-8 -*-
import functools
INF = 10**9
n = int(input())
p = list(map(int, input().split()))
for i in range(n - 1):
    p.append(int(input().split()[1]))


@functools.lru_cache(maxsize=None)
def matrix_chain_multiplication(i, j):
    if i == j:
        return 0

    tmp = INF
    for k in range(i, j):
        tmp = min(
            tmp,
            matrix_chain_multiplication(i, k) +
            matrix_chain_multiplication(k + 1, j) + p[i - 1] * p[k] * p[j])
    return tmp


print(matrix_chain_multiplication(0, n - 1))



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

#define fi first
#define se second
#define pb push_back
#define int long long
#define all(x) (x).begin(), (x).end()

using LL = long long;
using LD = long double;
using pii = pair<int, int>;
using vii = vector<pii>;

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

int mul(int a, int b) {
    LL res = 1LL * a * b;
    return res % MOD;
}

int pow_mod(int a, int b) {
    int res = 1;
    while (b) {
        if (b & 1)
            res = mul(res, a);
        a = mul(a, a);
        b >>= 1;
    }
    return res;
}

int f(int n, int r) {
    int rf = 1;
    for (int i = 2; i <= r; i++) {
        rf = (rf * i) % MOD;
    }
    int ans = pow_mod(rf, MOD - 2);
    for (int i = n; i >= n - r + 1; i--) {
        ans = (ans * i) % MOD;
    }
    return ans;
}

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

    int n, a, b;
    cin >> n >> a >> b;

    int ans = (pow_mod(2, n) - 1 + MOD) % MOD;
    
    // cout << "ans = " << ans << "\n";

    ans = (ans - f(n, a) + MOD) % MOD;

    // cout << "ans = " << ans << "\n";

    ans = (ans - f(n, b) + MOD) % MOD;

    // cout << "ans = " << ans << "\n";

    cout << ans << "\n";
}

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

flag = False
isIncrease = True
count = 1

for i in range(len(A) - 1) :
    if not flag :
        if A[i] < A[i + 1] :
            isIncrease = True
            flag = True
        elif A[i] > A[i + 1] :
            isIncrease = False
            flag = True
    else :
        if A[i] > A[i + 1] :
            if isIncrease :
                count += 1
                flag = False
        elif A[i] < A[i + 1] :
            if not isIncrease :
                count += 1
                flag = False

print(count)


Measured memory_bytes: 14224
/* mamba mentality */
#include "bits/stdc++.h"
using namespace std;
typedef long double ld;
#define int long long
typedef pair<int,int> pii;
#define RAGE ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,n) for(i=0; i <n; i++)
#define repv(i,k,n) for(int i=k; i<=n; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define endl '\n'
#define deb(x) cout<<#x<<" = "<<x<<endl
#define gcd __gcd
#define inf LLONG_MAX
#define minf LLONG_MIN 
const int mod = (int)(1e9+7);

int power(int x,int n)
{   
    if(n==0)    return 1;
    if(n==1)    return x%mod;
    if(n%2==0)  {   int y = power(x,n/2)%mod;return (y*y)%mod;}
    if(n&1)     {   int y = power(x,n-1);return (x%mod * y%mod)%mod;}
    return 0;
}
bool is_power_2(int n)  { return log2(n)==floor(log2(n));}
bool is_prime(int n){for(int i=2; i*i<=n; i++)if(n%i==0)return 0; return 1;}

int dx[]    =  { 1 ,  0,  -1,  0,  -1, -1, 1,  1};
int dy[]    =  { 0 ,  1,   0, -1,  -1,  1, 1, -1};
char dir[]  =  {'D','R','U','L'};

const int maxn =100005;

/* ------------------------------------------------------- */



void solve()
{
    int n,i,j,k,m;
    cin>>n;
    if(n%1000==0)
        cout<<0;
    else
        cout<<(1000 - n%1000);
}  
signed main()
{    int t=1;
    //  cin>>t;
    while(t--)
    {
        solve();
    }

    return 0;
}


Measured memory_bytes: 3672
#include<stdio.h>

int main(){
	int i,j,l;
	int a[100],b[100],c=0,d=0;
	for(i=1;i<=4;i++){
		scanf("%d",&a[i]);
		c+=a[i];
	}
	for(j=1;j<=4;j++){
		scanf("%d",&b[j]);
		d+=b[j];
	}
	if(c<d){
		printf("%d\n",d);
	}
	else if(c==d){
		printf("%d\n",c);
	}
	else{
		printf("%d\n",c);
	}
	return 0;
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int main(void) {
	ll N, A; cin >> N >> A;
	printf("%lld\n", N * N - A);
	return 0;
}

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

int n, x, y;
int cnt[2005];

int main()
{
	cin >> n >> x >> y;
	for (int i = 1; i < n; i++)
	{
		for (int j = i + 1; j <= n; j++)
		{
			int a = j - i;
			int b = abs(i - x) + abs(j - y) + 1 ;
			cnt[min(a, b)]++; 
		}
	}
	for (int i = 1; i < n; i++) cout << cnt[i] << endl;
	return 0;
}


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

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int inf = 1e9;
const int maxn = 2505;
const int maxm = 5005;
int Eu[maxm],Ev[maxm],Ec[maxm], dist[maxn], vis[maxn]; VI G[maxn]; 

void dfs(const int u)
{
    vis[u]++;
    FOR_ALL(i,G[u]) {
        const int v = Ev[*i];
        if (!vis[v])
            dfs(v);
    }
}

/* need use the real spfa to get the in Q count correctly */
int bfs(const int n)
{
    memset(vis,0,sizeof(vis));
    FOR(i,1,n+1)
        dist[i] = -inf;
    dist[1] = 0;
    queue<int> Q; Q.push(1); vis[1]++; VI cnt(n+1); cnt[1]++;
    while (Q.size()) {
        const int u = Q.front(); Q.pop(); vis[u] = 0;
        FOR_ALL(i,G[u]) {
            const int v = Ev[*i];
            const int c = Ec[*i];
            const int d = dist[u]+c;
            if (d > dist[v]) {
                dist[v] = d;
                if (!vis[v]) {
                    Q.push(v); vis[v]++;
                    if (++cnt[v] > n)
                        return -1;
                }
            }
        }
    }
    return max(0,dist[n]);
}

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m,p;
    while (cin >> n >> m >> p) {
        FOR(i,1,n+1)
            G[i].clear();
        FOR(i,0,m) {
            int u,v,c; cin >> u >> v >> c;
            /* -p the price for passing E[i] each time */
            Eu[i] = u; Ev[i] = v; Ec[i] = c-p;
            G[u].push_back(i);
        }
        VI good(n+1);
        FOR(i,1,n+1) {
            memset(vis,0,sizeof(vis));
            dfs(i);
            good[i] = vis[n];
        }
        FOR(i,1,n+1)
            G[i].clear();
        FOR(i,0,m) {
            const int u = Eu[i];
            const int v = Ev[i];
            if (good[v])
                G[u].push_back(i);
        }
        cout << bfs(n) << endl;
    }
    return 0;
}


Measured memory_bytes: 640
#include<cstdio>
#include<algorithm>
int a[100000];
int search(int x, int l, int r) {
	if (std::abs(r - l) < 2) {
		if (std::abs(x - a[r]) > std::abs(x - a[l]))return l;
		else return r;
	}
	else if (a[(r + l) / 2] < x) return search(x, (r + l) / 2, r);
	else return search(x, l, (l + r) / 2);
}
int main() {
	int n, i;
	scanf("%d", &n);
	for (i = 0; i < n; i++) scanf("%d", &a[i]);
	std::sort(a, a + n);
	printf("%d %d", a[n - 1], a[search(a[n - 1] / 2, 0, n - 2)]);
	return 0;
}

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

int main (){
    int N;
    cin >> N;
    int L[N];
    for (int i = 0; i < N; i++){
        cin >> L[i];
    }
    int max = 0;
    for (int i = 0; i < N; i++){
        if (L[i] >= max){
            max = L[i];
        }
    }
    int all = 0;
    for (int i = 0; i < N; i++){
        all += L[i];
    }
    all -= max;
    if (max < all){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main(){
   int a, b;
   cin >> a >> b;
   for(int c = 1; c < 4; c++){
      if(not(a*b*c % 2 == 0)){
         cout << "Yes" << endl;
         return 0;
      }
   }
   cout << "No" << endl;

   return 0;
}

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

using namespace std;

typedef long long ll;

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

	string s;
	cin >> s;

	int k;
	cin >> k;

	int n = s.size();

	ll dp[n+1][k+1][2];
	rep(i, n+1) rep(j, k+1) rep(l, 2) dp[i][j][l] = 0;
	dp[0][0][1] = 1;

	rep(i, n) rep(j, k+1){
		// 1 -> 1
		if(s[i] == '0'){
			if(j <= k) dp[i+1][j][1] += dp[i][j][1];
		}else{
			if(j+1 <= k) dp[i+1][j+1][1] += dp[i][j][1]; 
		}

		// 1 -> 0
		if(s[i] != '0'){
			ll t = s[i] - '0';
			if(j+1 <= k) dp[i+1][j+1][0] += (t - 1) * dp[i][j][1];
			if(j <= k) dp[i+1][j][0] += dp[i][j][1];
		}

		// 0 -> 0
		if(j+1 <= k) dp[i+1][j+1][0] += 9LL * dp[i][j][0];
		if(j <= k) dp[i+1][j][0] += dp[i][j][0];
	}

	cout << dp[n][k][0] + dp[n][k][1] << endl;
}


Measured memory_bytes: 256
/*
  Author - KISHAN TIWARI
  Dream bigger. Do bigger.
  Wake up with determination. Go to bed with satisfaction.
*/
//Sometimes later becomes never. Do it now.
#include<bits/stdc++.h>
using namespace std;
#define ll           long long
#define f(i,a,b)     for(ll i=a;i<b;i++)
#define mod          1000000007
#define fi           first
#define se           second
#define pa           pair <ll,ll>
#define mp           make_pair
#define pb           push_back
#define ve           vector<ll>
#define vep          vector< pa >
#define all(a)       a.begin(), a.end()
#define sz(x)        (ll)x.size()
#define c(t)         cout<<t<<"\n"
using namespace std;
void solve()
{  ll a,b;
cin>>a>>b;
ll co=0;
while(b>1)
{   b=b-(a-1);
    co++;
}
c(co);
}
int main()
{
    ios::sync_with_stdio(true);
   //freopen ("input.txt","r",stdin);
   //freopen ("output.txt","w",stdout);
    cin.tie(0);
    cout.tie(0);
    ll t=1;
    //cin>>t;
    while(t--)
    {

        solve();
    }
return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
long long int a,s,d[1000001],f[1000000],g,h;
int j,i,k;
int main(void)
{
	scanf("%lld %lld",&a,&s);
	for(i=0;i<a;i++){
		scanf("%lld",&d[i]);
		if(i!=0)
			f[i-1]=d[i]+d[i-1]-s;
	}
	g=0;
	for(i=1;i<a;i++){
		if(f[i-1]>0){
			if(f[i]>0){
				if(d[i]>=f[i-1]){
					d[i]-=f[i-1];
					g+=f[i-1];
					f[i-1]=d[i]+d[i-1]-s;
					f[i]=d[i]+d[i+1]-s;
				}
				else if(d[i]<f[i-1]){
					f[i-1]=f[i-1]-d[i];
					d[i-1]-=f[i-1];
					g+=d[i]+f[i-1];
					d[i]=0;
					f[i-1]=d[i]+d[i-1]-s;
					f[i]=d[i]+d[i+1]-s;
				}
			}
			else if(f[i]<=0){
				g+=f[i-1];
				f[i-1]=f[i-1]-d[i];
				d[i-1]-=f[i-1];
				f[i-1]=d[i]+d[i-1]-s;
				f[i]=d[i]+d[i+1]-s;
			}
		}
	}
	printf("%lld\n",g);
	return 0;
}

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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

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

  std::vector<std::set<int64_t>> l(26);

  for (int64_t i = 0; i < s.size(); i++) {
    l[s[i] - 'a'].insert(i + 1);
  }

  int64_t ans = 0;
  int64_t index = 0;
  int64_t itr = 0;
  for (const auto c : t) {
    const auto n = c - 'a';
    if (l[n].empty()) {
      std::cout << -1 << std::endl;
      return 0;
    }

    const auto i = l[n].upper_bound(index);
    if (i == l[n].end()) {
      index = *l[n].cbegin();
      itr++;
      ans = itr * s.size() + index;
    } else {
      index = *i;
      ans = itr * s.size() + index;
    }
  }

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

Measured memory_bytes: 5248
import math

a,b,C=map(int,input().split())
S=float(a*b*math.sin(C/180*math.pi)/2)
c=float( math.sqrt(pow(a,2)+pow(b,2)-2*a*b*math.cos(C/180*math.pi)) )
L=a+b+c
h=S*2/a

print(S)
print(L)
print(h)



Measured memory_bytes: 5708
#include <bits/stdc++.h>
#define pvar(x) clog<<"["<<#x<<":"<<x<<"]\n"
using namespace std;
using ll = long long int;
int main(){
	ios_base::sync_with_stdio(false);
  cin.tie(NULL);
	int x;
	cin>>x;
	int ans;
	if(x>=400 && x<=599)ans = 8;
	else if(x>=600 && x<=799)ans = 7;
	else if(x>=800 && x<=999)ans = 6;
	else if(x>=1000 && x<=1199)ans = 5;
	else if(x>=1200 && x<=1399)ans = 4;
	else if(x>=1400 && x<=1599)ans = 3;
	else if(x>=1600 && x<=1799)ans = 2;
	else ans = 1;
	cout<<ans<<endl;
}
 


Measured memory_bytes: 3628
x = []
y = []

n = int(input())

for i in range(n):
    a, b = map(int, input().split())
    x.append(a)
    y.append(b)

z = 0

for i in range(n-2):
    if x[i] == y[i]:
        if x[i + 1] == y[i + 1]:
            if x[i + 2] == y[i + 2]:
                z = 1
                break
            else:
                z = 0
                continue
        else:
            z = 0
            continue
    else:
        z = 0
        continue
    


if z == 1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9212
/*Remember: The Struggle is Important*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

#include<bits/stdc++.h>
using namespace std;

#define     int          long long int
#define     ld           long double
#define     fast()       ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)       x.begin(),x.end()
#define     mem(a,b)     memset(a,b,sizeof(a))
#define     gcd(a,b)     (__gcd((a),(b)))
#define     lcm(a,b)     (((a)*(b))/gcd((a),(b)))
#define     pb           push_back
#define     ins          insert
#define     pii          pair<int,int>
#define     F            first
#define     S            second
#define     makep        make_pair
#define     maket        make_tuple
#define     show(x)      for(auto c:x)cout<<c<<" ";cout<<"\n";
#define     show2(x)     for(auto c:x)cout<<c.F<<" "<<c.S<<"\n";

const int inf=1e18,M=1e9+7;
const int N=1;

void solve()
{
    int a,b,m;
    cin>>a>>b>>m;

    vector<int> v(a),w(b);
    for(int i=0;i<a;++i)
        cin>>v[i];

    for(int i=0;i<b;++i)
        cin>>w[i];

    int ans=*min_element(all(v))+*min_element(all(w));

    for(;m;--m)
    {
        int c,x,y;
        cin>>x>>y>>c;

        ans=min(ans,v[x-1]+w[y-1]-c);
    }

    cout<<ans;
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
        //cout<<"\n";
    }

    return 0;
}




Measured memory_bytes: 1792
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        c11: isize, c12: isize, c13: isize,
        c21: isize, c22: isize, c23: isize,
        c31: isize, c32: isize, c33: isize,
    }

    let a_32_1 = c31-c21;
    let a_32_2 = c32-c22;
    let a_32_3 = c33-c23;
    let a_21_1 = c21-c11;
    let a_21_2 = c22-c12;
    let a_21_3 = c23-c13;

    let b_32_1 = c13-c12;
    let b_32_2 = c23-c22;
    let b_32_3 = c33-c32;
    let b_21_1 = c12-c11;
    let b_21_2 = c22-c21;
    let b_21_3 = c32-c31;

    let flg = {
        a_32_1 == a_32_2 && a_32_2 == a_32_3 &&
        a_21_1 == a_21_2 && a_21_2 == a_21_3 &&
        b_32_1 == b_32_2 && b_32_2 == b_32_3 &&
        b_21_1 == b_21_2 && b_21_2 == b_21_3
    };

    if flg { println!("Yes") }
    else { println!("No") }
}


Measured memory_bytes: 2128
#include <bits/stdc++.h>
using namespace std;
 
using vi = vector<int>;
#include <boost/range/irange.hpp>
using boost::irange;
 
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
}
 
int main() {
  int n;
  cin >> n;
  vi arr(n);
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  vi ans;
  for (int i: irange(n, 0, -2)) {
    ans.push_back(arr[i - 1]);
  }
  for (int i: irange(n % 2, n, 2)) {
    ans.push_back(arr[i]);
  }
  print(ans);
}

Measured memory_bytes: 3828
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <stack>
#include <queue>
#include <bitset>
#include <functional>

#define FOR(i, b, e) for(ll i = (ll)(b); i < (ll)(e); ++i)
#define RFOR(i, b, e) for(ll i = (ll)(e-1); i >= (ll)(b); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPC(x,c) for(const auto& x:(c))
#define VS vector<string>
#define VL vector<long long>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVL vector<vector<ll>>
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort((x).rbegin(),(x).rend())
#define PAIR pair<ll,ll>
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using  ll = long long;
//constexpr ll MOD = 1000000007;
constexpr ll MOD = 998244353;
using std::cout;
using std::endl;
using std::cin;
using std::sort;
using std::pair;
using std::string;
using std::stack;
using std::queue;
using std::vector;
using std::list;
using std::map;
using std::unordered_map;
using std::multimap;
using std::unordered_multimap;
using std::set;
using std::unordered_set;
using std::multiset;


// ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
// ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
// ll pow(ll a, ll b) { ll ans = 1; while (b > 0) { if (b % 2 == 1) { ans *= a; ans %= MOD; }b /= 2; a *= a; a %= MOD; }return ans%MOD; }
// ll comb(ll n, ll r) { if (n - r < r) { return comb(n, n - r); }static VVL memo = {{1}}; if (memo.size() < n + 1) { memo.reserve(n + 1); FOR(i, memo.size(), n + 1) { memo.emplace_back(i + 1, 0); REP(j, i + 1) { memo[i][j] = 0;	if (j < i) { memo[i][j] += memo[i - 1][j]; }if (j > 0) { memo[i][j] += memo[i - 1][j - 1]; }memo[i][j] %= MOD; } } }return memo[n][r]; }
// ll comb_L(ll a, ll b) { if (a - b < b) { return comb(a, a - b); }static unordered_map<ll, ll> memo; ll c = 1; FOR(i, a - b + 1, a + 1) { c *= i; c %= MOD; }if (memo.find(b) == memo.end()) { ll k = 1; FOR(i, 2, b + 1) { k *= i;	k %= MOD; }memo[b] = pow(k, MOD - 2); }	c *= memo[b]; return c % MOD; }
// multiset<ll> prime_decomposition(ll n) { ll i = 2; multiset<ll> table{}; while (i * i <= n) { while (n % i == 0) { n /= i;	table.emplace(i); }++i; }if (n > 1) { table.emplace(n); return table; }return table; }
//-- bit -- REP(i, (1 << n)) {REP(j, n) {cout << (1 & (i >> j));}cout << endl;}

//==============================================================================================

ll ans = 0;
void f(const string& s, ll n, bool a, bool b, bool c) {
	if (s.size() > 9) { return; }
	string s1 = s + "3";
	string s2 = s + "5";
	string s3 = s + "7";

	if ((ll)(stod(s1) + 0.1) <= n) {
		if (b&c) { ++ans; }
		f(s1, n, true, b, c);
	}
	if ((ll)(stod(s2) + 0.1) <= n) {
		if (a&c) { ++ans; }
		f(s2, n, a, true, c);
	}
	if ((ll)(stod(s3) + 0.1) <= n) {
		if (a&b) { ++ans; }
		f(s3, n, a, b, true);
	}
}

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

	string s = "";
	f(s, n, false, false, false);
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int i,b=0;

    char A[4];
    scanf("%s",A);
    for(i=0;i<3;i++)
    {
        if(A[i]=='7')
        {
            b=1;
            break;
        }
    }
    if(b) printf("Yes\n");

    else printf("No\n");

    return 0;
}


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

long long N=0,K=0,M=0,A=0,B=0,ans=0,p=0;
long long n=0,x=0,s=0,t=0;
string S;

int main(){
    cin >> x;
    p=x;
    while(true){
        for(long i=2;i*i<=p;i++){
            if(p%i==0){
                n=1;
                break;
            }
        }
        if (n==0){
            ans=p;
            break;
        }
        p++;
        n=0;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll k;
    ll now = 7;
    cin >> k;
    ll cnt = 1;
    while(1){
        now %= k;
        if(now == 0){
            cout << cnt << endl;
            return 0;
        }
        cnt++;
        now *= 10;
        now += 7;
        if(cnt == 1000000){
            cout << -1 << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int main(){
    ll N, K; cin >> N >> K;
    ll ans = 0;
    if(K == 0){
        cout << N*N << endl;
        return 0;
    }

    for(int i = K+1; i <= N; i++){
        ll x = N % i; //あまり
        ll loop = N-x;//ループを構成する個数
        ll loopN = loop / i;//ループの数
        ll num = i-K;//1ループ内のK以上の個数
        ll tmp=0;
        if(num > 0) {
            tmp += num * loopN;
            //cout << i << "    " << num * loopN << endl;

            if(x >= K){
                tmp += x - K + 1;
                //cout << i << "       " << x - K + 1 << endl;
            }
        }
        ans+= tmp;
        //cout << " " << i << " loops:" << loopN << "  bigger than K:" << i-K << "  sum:" << tmp << endl;   
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

var pathNum = 0
var visited []int
var VISIT = 1
var UNVISITED = 0

func isAllVisited() bool {
	for _, v := range visited {
		if v == UNVISITED {
			return false
		}
	}

	return true
}

func dfs(v int, graph [][]int) {
	if isAllVisited() {
		pathNum++
		return
	}

	for i, adjecent := range graph[v] {
		if adjecent == 1 && visited[i] == UNVISITED {
			visited[i] = VISIT
			dfs(i, graph)
			visited[i] = UNVISITED
		}
	}
}

func main() {
	var N, M int
	fmt.Scanf("%d %d", &N, &M)

	graph := make([][]int, N)
	visited = make([]int, N)
	for i := 0; i < N; i++ {
		graph[i] = make([]int, N)
	}

	var s, t int
	for i := 0; i < M; i++ {
		fmt.Scanf("%d %d", &s, &t)
		graph[s-1][t-1] = 1
		graph[t-1][s-1] = 1
	}

	visited[0] = VISIT
	dfs(0, graph)
	fmt.Println(pathNum)
}


Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <vector>
using namespace std;

int Xs[100008];
int As[100008];
int Bs[100008];
int Ys[100008];
int edge_ids[100008];
int cmp(const void *a,const void *b) {
	int va=*(int  *)a;
	int vb=*(int  *)b;
	if(Ys[va]!=Ys[vb]) return Ys[va]-Ys[vb];
	return va-vb;
}
int N,M;
int ufs[100008];
long long weights[100008];
void reset(void) {
	for(int i=1;i<=N;i++) {
		ufs[i]=i;
		weights[i]=Xs[i];
	}
}
int getpa(int id) {
	if(ufs[id]==id) return id;
	ufs[id]=getpa(ufs[id]);
	return ufs[id];
}
void comb(int a,int b) {
	weights[getpa(b)] += weights[getpa(a)];
	ufs[getpa(a)]=getpa(b);
}
int M_MST=0;
int mst_ids[100008];
int mst_uses[100008];
vector<int> mst_to[100008];
vector<int> mst_vec_edge_id[100008];
vector<int> mst_y[100008];
int mst_search_used[100008];
void search(int now,int from,int weight) {
	for(int i=0;i<mst_to[now].size();i++) {
		int to=mst_to[now][i];
		if(to==from) continue;
		if(mst_search_used[mst_vec_edge_id[now][i]]) continue;
		if(mst_y[now][i]>weight) continue;
		mst_search_used[mst_vec_edge_id[now][i]]=1;
		comb(now, to);
		search(to, now, weight);
	}
}
int main() {
	scanf("%d%d",&N,&M);
	for(int i=1;i<=N;i++) scanf("%d",&Xs[i]);
	for(int i=0;i<M;i++) {
		scanf("%d%d%d",&As[i],&Bs[i],&Ys[i]);
		edge_ids[i]=i;
	}
	qsort(edge_ids, M,sizeof(int),cmp);
	// get MST
	reset();
	for(int i=0;i<M;i++) {
		int eid=edge_ids[i];
		if(getpa(As[eid])!=getpa(Bs[eid])) {
			mst_ids[M_MST++]=eid;
			comb(As[eid], Bs[eid]);
		}
	}
	// setup graph
	for(int i=0;i<M_MST;i++) {
		int eid=mst_ids[i];
		mst_to[As[eid]].push_back(Bs[eid]);
		mst_y[As[eid]].push_back(Ys[eid]);
		mst_vec_edge_id[As[eid]].push_back(eid);
		mst_to[Bs[eid]].push_back(As[eid]);
		mst_y[Bs[eid]].push_back(Ys[eid]);
		mst_vec_edge_id[Bs[eid]].push_back(eid);
	}
	// check use
	reset();
	for(int i=0;i<M_MST;i++) {
		int eid=mst_ids[i];
		if(weights[getpa(As[eid])] + weights[getpa(Bs[eid])] >= Ys[eid]) {
			//use
			mst_uses[i]=1;
		}
		comb(As[eid], Bs[eid]);
	}
	reset();
	for(int i=M_MST-1;i>=0;i--) {
		if(mst_uses[i]) {
			int eid=mst_ids[i];
			search(As[eid], -1, Ys[eid]);
		}
	}
	int sol=0;
	for(int i=0;i<M;i++) {
		if(weights[getpa(As[i])] < Ys[i]) sol++;
	}
	printf("%d\n",sol);
	return 0;
}


Measured memory_bytes: 28660
#include <stdio.h>
#include <ctype.h>
#define SIZE 26

int
main(void)
{
    char ch;
    int i;
    int counter[SIZE] = {};
    while ((ch = getchar()) != EOF)
        if (isalpha(ch))
            counter[tolower(ch) - 'a']++;
    
    for (i = 0; i < SIZE; i++)
        printf("%c : %d\n", 'a' + i, counter[i]);
    
    return 0;
}


Measured memory_bytes: 2044
// while (clock()<=69*CLOCKS_PER_SEC)
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define pb push_back
#define SZ(x) ((int)(x).size())
#define ALL(x) x.begin(),x.end()
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define erase_duplicates(x) sort(all(x)); (x).resize(distance((x).begin(), unique(all(x))));


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

//X.find_by_order(k); - zwraca iterator na k-ty element (numeracja od zerowego)
//X.order_of_key(k); - zwraca liczbę elementów ostro mniejszych niż k

typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<LL> VLL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long double LD;
typedef pair<LD,LD> PLD;
typedef vector<LD> VLD;
typedef vector<PLD> VPLD;

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<" = "<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<" = "<<h<<", "; _dbg(sdbg+1, a...);
}

#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#define cerr if(0)cout
#endif

const int maxn = (1e6)+7;
const int maxk = 20;
const int inf = (1e9)+7;
const LL LLinf = ((LL)1e18)+7LL;
const LD eps = 1e-9;
const LL mod = 1e9+7;

// ***************************** CODE ***************************** //

LL tab[maxn];

VI rob(VI V)
{
  for(int i = 0;i < SZ(V);i++)
    tab[i] = 0;
  for(int i = 0 ;i < SZ(V);i++)
  {
    tab[max(0, i - V[i])]++;
    tab[i + V[i] + 1]--;
  }
  for(int i = 0;i < SZ(V);i++)
  {
    if(i > 0)
      tab[i] += tab[i - 1];
    V[i] = tab[i];
  }
  return V;
}

int main()
{
	_upgrade
  int n, k;
  cin>>n>>k;
  VI V;
  for(int i = 0;i < n;i++)
  {
    int a;
    cin>>a;
    V.pb(a);
  }
  while(k--)
  {
    bool ok = 0;
    for(auto s : V)
      if(s < SZ(V))
        ok = 1;
    if(ok)
      V = rob(V);
    else
      break;
  }
  for(auto s : V)
    cout<<s<<" ";

	return 0;
}


Measured memory_bytes: 8336
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define MOD 1000000007
struct UnionFind {
    vector<int> data;
    // data[i]はマイナスなら連結成分の要素数を表す
    //プラスならば親ノードを表す
    UnionFind(int sz) { data.assign(sz, -1); }

    bool unite(int x, int y) {
        x = find(x), y = find(y);
        if(x == y)
            return (false);
        if(data[x] > data[y])
            swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return (true);
    }

    int find(int k) {
        if(data[k] < 0)
            return (k);
        return (data[k] = find(data[k]));
    }
    bool isSame(int x, int y) { return find(x) == find(y); }
    ll size(int k) { return (-data[find(k)]); }
};
int main() {
    int n, k, l;
    cin >> n >> k >> l;
    UnionFind uf1(n), uf2(n);
    vector<set<int>> s1(n), s2(n);
    for(size_t i = 0; i < k; i++) {
        int p, q;
        cin >> p >> q;
        p--, q--;
        uf1.unite(p, q);
    }
    for(int i = 0; i < n; i++) {
        s1[uf1.find(i)].insert(i);
    }

    for(int i = 0; i < l; i++) {
        int p, q;
        cin >> p >> q;
        p--, q--;
        uf2.unite(p, q);
    }
    for(int i = 0; i < n; i++) {
        s2[uf2.find(i)].insert(i);
    }
  map<pair<int,int>,int> mp;
  for(int i=0;i<n;i++){
    mp[make_pair(uf1.find(i),uf2.find(i))]++;
  }
  for(int i=0;i<n;i++){
    cout<<mp[make_pair(uf1.find(i),uf2.find(i))]<<" ";
  }
  cout<<endl;
}



Measured memory_bytes: 49664
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		while(sc.hasNextInt()){
			int a=sc.nextInt();
			int b=sc.nextInt();
			double c=a+b;
			int cnt=0;
			while(c>=1){
				c=c/10;
				cnt++;
			}
			System.out.println(cnt);
		}
		sc.close();
	}
}

Measured memory_bytes: 26516
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
map<ll, ll>ins;
void facterize(ll n) {
	ll a = 2;
	while (n >= a * a) {
		if (n % a == 0) {
			ins[a]++;
			ins[a] = ins[a] % 1000000007;
			n /= a;
		}
		else {
			a++;
		}
	}
	ins[n]++;
}

vector<ll>relation[20], money(20, 1);
char s[110][110];
int dp[110][110];

int keta(int x) {
	int y = 0;
	while (x > 0) {
		y++;
		x /= 10;
	}
	return y;
}

int main() {
	int n;
	cin >> n;
	vector<string>a(n);
	map<string, int>mp;
	rep(i, n) {
		cin >> a[i];
		mp[a[i]]++;
	}
	int ans = 0;
	for (auto p : mp) {
		ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 25080
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <cmath>
#include <iomanip>
#include <functional>
#include <random>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;

int main()
{
    // 整数の入力
    ll A,B;
    cin >> A >> B;
    cout << A*(A-1)/2 + B*(B-1)/2<< endl;
   return 0;
}

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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

void solve() {
    int A, B, C, X;
    cin >> A >> B >> C >> X;

    int cnt = 0;
    for (int a = 0; a <= A; a++) {
        for (int b = 0; b <= B; b++) {
            for (int c = 0; c <= C; c++) {
                if (500 * a + 100 * b + 50 * c == X) {
                    cnt++;
                }
            }
        }
    }

    cout << cnt << endl;
}

int main() {
    solve();

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define P pair<int,int>
#define PP pair<P,int>
#define F first
#define S second
#define f(i,n) for(int i=0;i<(n);i++)
#define INF LLONG_MAX/3
#define eps LDBL_EPSILON
#define mod (int)(1000000007)
#define pie 3.141592653589793238462643383279
#define Bpri priority_queue
#define Spri priority_queue<P,vector<P>,greater<P>>
using namespace std;
int x[100000];
int mypow(int a,int b,int c){
	if(b==0)return 1;
	if(b%2)return mypow(a,b-1,c)*a%c;
	int z=mypow(a,b/2,c);
	return z*z%c;
}
signed main(){
	int n,ans=0;
	cin>>n;
	f(i,n){
		cin>>x[i+1];
		ans+=abs(x[i+1]-x[i]);
	}
	ans+=abs(x[n]);
	f(i,n){
		cout<<ans-abs(x[i+1]-x[i])-abs(x[i+2]-x[i+1])+abs(x[i+2]-x[i])<<endl;
	}
	return 0;
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>                          
using namespace std;                                               
int main()
{
	string s;
	getline(cin,s);
	reverse(s.begin(),s.end());
	for(int i=0;i<s.size();)
	{
		if(s[i]=='m'&&s[i+1]=='a'&&s[i+2]=='e'&&s[i+3]=='r'&&s[i+4]=='d') i+=5;
		else
		{
		    if(s[i]=='r'&&s[i+1]=='e'&&s[i+2]=='m'&&s[i+3]=='a'&&s[i+4]=='e'&&s[i+5]=='r'&&s[i+6]=='d') i+=7;
            else{
			if(s[i]=='r'&&s[i+1]=='e'&&s[i+2]=='s'&&s[i+3]=='a'&&s[i+4]=='r'&&s[i+5]=='e') i+=6;
		    else{if(s[i]=='e'&&s[i+1]=='s'&&s[i+2]=='a'&&s[i+3]=='r'&&s[i+4]=='e') i+=5;
		    else {
			cout<<"NO";
			exit(0);}}}}
	}
	cout<<"YES";
	return 0;
}                  

Measured memory_bytes: 512
// Created by Nandu Vinodan
#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define pi pair<int, int>
#define INF INT_MAX
#define _INF INT_MIN
#define TC 0

using namespace std;
using ll = long long;

int n;
vector<pi> adj[100005];
vector<int> col;

// void dfs(int u, int c, int pt=-1) {
// 	col[u] = c;
// 	for (auto p : adj[u]) {
// 		int v = p.first;
// 		int w = p.second;
// 		if (v != pt) {
// 			if (w & 1)
// 				c = 1-c;
// 			dfs(v, c, u);
// 		}
// 	}
// }

void dfs(int v, int p, int cur) {
    col[v] = cur;
 
    for (auto n : adj[v]) {
        if (n.first == p) {
            continue;
        }
 
        if (n.second & 1)
            dfs(n.first, v, 1 - cur);
        else
            dfs(n.first, v, cur);
    }
}
void testcase() {
    cin >> n;
    rep (i, 1, n) {
    	adj[i].clear();
    }
    col.clear();
    col.resize(n+1);
    rep (i, 2, n) {
    	int u, v, w;
    	cin >> u >> v >> w;
    	adj[u].push_back({v, w});
    	adj[v].push_back({u, w});
    }
    dfs(1, -1, 0);
    rep (i, 1, n) cout << col[i] << endl;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    if (TC)
        cin>>t;
    while(t--) {
        testcase();
    }
    return 0;
}

Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<P,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define print(v) cout<<v<<endl;
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;

int main(){
    ll N;
    cin >> N;
    ll M;
    cin >> M;
    if(N>1&&M>1)print((N-2)*(M-2))
    else if(N==1&&M>1)print(M-2)
    else if(N>1&&M==1)print(N-2)
    else print(1)



    return 0;
}

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

int gcdx(int x, int y){
    if(x < y){
        swap(x, y);
    }

    while(y > 0){
        int r = x % y;
        x = y;
        y = r;
    }

    return x;
}

int main() {
    int x, y; cin >> x >> y;
    cout << gcdx(x, y) << endl;

    return 0;
}


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

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll a, b, c;
    cin >> a >> b >> c;
    ull d = abs(c - a - b);
    cout << (c >= a + b && 4ULL * a * b < d * d ? "Yes" : "No") << "\n";
    return 0;
}

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

using namespace std;

int main(){
  string s, ans="NO";
  cin >> s;
  string dream="dream", dreamer="dreamer", erase="erase", eraser="eraser";

  reverse(s.begin(), s.end());
  reverse(dream.begin(), dream.end());
  reverse(dreamer.begin(), dreamer.end());
  reverse(erase.begin(), erase.end());
  reverse(eraser.begin(), eraser.end());

  while(s.size()!=0){
    if((s.find(dream)==0)||(s.find(erase)==0))s.erase(s.begin(),s.begin()+5);
    else if(s.find(eraser)==0)s.erase(s.begin(),s.begin()+6);
    else if(s.find(dreamer)==0)s.erase(s.begin(),s.begin()+7);
    else break;
    //cout << s << endl;
    if(s.size()==0)ans="YES";
  }
  cout << ans << endl;
}


Measured memory_bytes: 512
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

struct state {
	string s;
	int d;
	state(string s, int d) : s(s), d(d) {};
};

int main() {
	int n;
	while(cin >> n, n) {
		vector<vs> data(n, vs(2));
		REP(i, n) {
			cin >> data[i][0] >> data[i][1];
		}
		string s, g;
		cin >> s >> g;

		int ans = -1;
		queue<state> Q;
		Q.push(state(s, 0));
		while(!Q.empty()) {
			state st = Q.front();
			Q.pop();

			if(st.s == g) {
				ans = st.d;
				break;
			}
			if(g.size() <= st.s.size()) {
				continue;
			}

			REP(i, n) {
				string cs = st.s, ns;
				int pos = cs.find(data[i][0]);
				bool update = false;
				while(pos != string::npos) {
					update = true;
					ns += (cs.substr(0, pos) + data[i][1]);
					cs = cs.substr(pos+data[i][0].size());
					pos = cs.find(data[i][0]);
				}
				ns += cs;
				if(update) {
					Q.push(state(ns, st.d+1));
				}
			}
		}

		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1576