akhauriyash/Code-Regression huggingface dataset:
//marico el que lo lea
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <stdlib.h>
#include <assert.h>
using namespace std;

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

void fastIO() {std::ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}

#define pb push_back
#define all(obj) obj.begin(), obj.end()
#define ms(obj, val) memset(obj, val, sizeof(obj))
#define ms2(obj, val, sz) memset(obj, val, sizeof(obj[0])*sz)

#define fst first
#define snd second

template<typename T, typename U> inline void mnze(T &x, U y) {if(y < x) x = y;}
template<typename T, typename U> inline void mxze(T &x, U y) {if(x < y) x = y;}

void _scan( int &x ) { scanf("%d",&x); }
void _scan( long long &x ) { scanf("%lld",&x); }
void _scan( double &x ) { scanf("%lf",&x); }
void _scan( char &x ) { scanf(" %c",&x); }
void _scan( char *x ) { scanf("%s",x); }
template<typename T>
void _scan( vector<T> &v ){
	for(int i=0; i<(int)v.size(); i++) _scan(v[i]);
}
void scan() {}
template<typename T, typename... U>
void scan( T& head, U&... tail ) { _scan(head); scan(tail...);}

template<typename T> void _dbg(const char* sdbg, T h)
	{ cerr<<sdbg<<"="<<h<<"\n"; }
template<typename T, typename... U> void _dbg(const char* sdbg, T h, U... t) {
	while(*sdbg != ',')cerr<<*sdbg++;
	cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr<<#x<<" = "; for(auto _i:x) cerr<<_i<<", ";cerr<<"\n";}}
#define debuga(x, sz) {{cerr<<#x<<" = ";for(int _i=0;_i<sz;_i++)cerr<<x[_i]<<", ";cerr<<"\n";}}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define debuga(x, sz)
#define cerr if(0)cout
#endif

ll MOD = 998244353;

inline ll Msum(ll x){return x;}
template<typename... Rest>
inline ll Msum(ll x, Rest... rest){ return (x + Msum(rest...)) % MOD; }

inline ll Mprod(ll x){return x;}
template<typename... Rest>
inline ll Mprod(ll x, Rest... rest){ return x * Mprod(rest...) % MOD; }

inline ll Mnorm(ll x){ return (x%MOD + MOD) %MOD; }

inline ll Msq(ll x){ return (x*x) %MOD; }
inline ll Mpot(ll x, ll e){
	if(!e) return 1;
	return Msq(Mpot(x, e>>1)) * (e & 1 ? x : 1)%MOD;
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

const int MAXN = 3e3+3;

int X, Y, A , B;

ll dp[MAXN][MAXN][2];
ll f(int r, int c, bool sk){
	if(r==X && c==Y) return 1;
	ll &ret = dp[r][c][sk];
	if(ret != -1) return ret;
	if(r == X){
		assert(sk == 1);
		return ret = ((A+r) * f(r, c+1, 1))%MOD;
	}
	if(c == Y){
		return ret = ((B+c) * f(r+1, c, 0))%MOD;
	}

	if(sk == 0){
		ret = ((A+r)*f(r+1, c+1, 1))%MOD;
		if(c+1<Y) ret += (A+r)*f(r, c+1, 0);
		ret %= MOD;
	}else{
		ret = ((B+c) * f(r+1, c, 1))%MOD;
		ret += f(r, c, 0);
		ret %= MOD;
	}
	return ret;
}

int main(){
	int C, D;
	scan(A, B, C, D);
	X = C-A; Y=D-B;
	ms(dp, -1);
	ll ans = f(0, 0, 1);
	printf("%lld\n", ans);
}


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

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

    vector<int> num(n);
    for(int i=0; i<n-1; i++){
        int a;
        cin >> a;
        num[a-1] += 1;
    }

    for(int i=0; i<n; i++){
        cout << num[i] << endl; 
    }
    return 0;
}

Measured memory_bytes: 4052
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

//////////////////////////////////////
ll N, K;

vll op(vll A) {
	vll ret(N + 1, 0);
	
	vll dif(N + 2, 0);
	repn(i, N) {
		ll x = max(1,i-A[i]);
		dif[x] += 1;

		ll y = min(N+1,i+A[i]+1);
		dif[y] += -1;
	}

	repn(i, N) {
		ret[i] = ret[i - 1] + dif[i];
	}

	return ret;
}

int main() {
	cin >> N >> K;
	vll A(N + 1);
	repn(i, N) cin >> A[i];

	repn(k, K) {
		A = op(A);

		bool b = 1;
		repn(i, N) { if (A[i] < N) { b = 0; } }
		if (b) { break; }
	}

	repn(i, N) { cout << A[i] << " "; }
	cout << endl;
}

Measured memory_bytes: 9528
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
  int N;
  cin >> N;
  int A[20];
  int x[20][20];
  int y[20][20];
  for(int i=0; i<N; i++){
    cin >> A[i];
    for(int j=0; j<A[i]; j++){
      cin >> x[i][j] >> y[i][j];
      x[i][j]--;
    }
  }
  int num[50000];
  bool able[50000];
  for(int bit=0; bit<(1<<N); bit++){
    able[bit]=true;
    for(int i=0; i<N; i++){
      if(bit&(1<<i)){
        num[bit]++;
        for(int j=0; j<A[i]; j++){
          int t=0;
          if(bit&1<<x[i][j]) t=1;
          if(y[i][j]!=t){
            able[bit]=false;
            break;
          }
        }
      }
      if(able[bit]==false) break;
    }
  }
  int ans=0;
  for(int bit=0; bit<(1<<N); bit++){
    if(able[bit]==true) ans=max(ans,num[bit]);
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 384
#include <iostream>

#define REP(i, a, b) for ( int i = (a); i < (b); i++ )
#define REVREP(i, a, b) for ( int i = (a); i > (b); i--)
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)

using namespace std;

int main(void) {

	char c;
    scanf("%c", &c);

    if (c == 'A') puts("T");
    else if (c == 'T') puts("A");
    else if (c == 'G') puts("C");
    else puts("G");
   

	return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pii;
typedef vector<pii> vii;

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

    string a, b, c;
    cin >> a >> b >> c;
    if (a.back() == b.front() and b.back() == c.front())
        cout << "YES\n";
    else
        cout << "NO\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fi first
#define se second
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	int a, b;
	cin >> a >> b;
	a--; b--;
	cout << (a + b - 1) / a << endl;
}


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;
typedef pair<int,int> P;

int main() {
  int n;
  cin >> n;
  vector<P> vec;
  rep(i, n) {
    int j;
    cin >> j;
    vec.push_back(P (j,i+1));
  }
  sort(vec.begin(), vec.end());
  rep(i, n) {
    if (i) cout << " ";
    cout << vec[i].second;
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 1780
from heapq import *
n,m = map(int,input().split())
a = list(map(int,input().split()))

heap = []
for i in a:
    heappush(heap,-i)

for _ in range(m):
    tmp = heappop(heap)
    heappush(heap,-(-tmp//2))

ans = 0
for a in heap:
    ans += -a 
print(ans)

Measured memory_bytes: 20552
// AtCoder Beginner Contest 089 - Problem B: Hina Arare (https://atcoder.jp/contests/abc089/tasks/abc089_b)
#include <bits/stdc++.h>

using namespace std;

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

    int p = 0, w = 0, g = 0, y = 0;

    while (N--)
    {
        string s;
        cin >> s;

        switch (s.front()) {
        case 'P':
            p = 1;
            break;

        case 'W':
            w = 1;
            break;

        case 'G':
            g = 1;
            break;

        case 'Y':
            y = 1;
            break;
        }
    }

    int found = p + w + g + y;

    cout << (found == 3 ? "Three" : "Four") << endl;

    return 0;
} 


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    if (n == m) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}



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

typedef long long ll;
typedef unsigned long long ull;

const ll M = 1e9+7;
ll fact[1001], factinv[1001];

ll mpow(ll x, ll n){
    if(n==1) return x%M;
    if(n==0) return 1LL;
    return mpow(x*x%M, n/2)*(n%2==0?1:x)%M;
}

int main(){
    fact[0]=1;
    for(int i=1;i<=1000;i++) fact[i]=fact[i-1]*i%M;
    for(int i=0;i<=1000;i++) factinv[i]=mpow(fact[i],M-2);

    ll dp[1001][1001];
    int N,A,B,C,D;
    cin >> N >> A >> B >> C >> D;
    for(int i=0;i<A;i++){
        dp[i][0]=1;
        for(int j=1;j<=N;j++) dp[i][j]=0;
    }
    for(int i=A;i<=B;i++){
        for(int j=0;j<=N;j++){
            dp[i][j]=dp[i-1][j];
            for(int k=C;k<=D && i*k<=j;k++){
                dp[i][j]+=dp[i-1][j-i*k]*fact[N-j+i*k]%M*mpow(factinv[i],k)%M*factinv[k]%M*factinv[N-j]%M;
                dp[i][j]=dp[i][j]%M;
            }
        }
    }

    cout << dp[B][N] << endl;

    return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
    using namespace std; 
    int main()
    {
        int n , m , a , b ;
        vector <int> h ;
        vector <int> arr[100010] ;
        cin >> n >> m ;
        h.push_back(0) ;
        for(int i = 1 ; i <= n ; i++)
        {
            int x ;
            cin >> x ;
            h.push_back(x) ;
        }
        for(int i = 0 ; i < m ; i++)
        {
            cin >> a >> b ;
            arr[a].push_back(b) ;
            arr[b].push_back(a) ;
        }
        int ans = 0 ;
        for(int i = 1 ; i <= n ; i++)
        {
            int flag = 0 ;
            for(int j = 0 ; j < arr[i].size() ; j++)
            {
                if(h[i] <= h[arr[i][j]])
                {
                    flag = 1 ; 
                }
            }
            if( ( flag == 0 )  )
            {
                ans++ ;
            }
        }
        cout << ans << endl ;
    }

Measured memory_bytes: 8716
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#define pii pair<int, int>
#pragma warning(disable : 4996)
using namespace std;
int N, a, b, c, d, f, g[1009], x[1009]; char e; vector<pii> D[1009];
int main() {
	while (scanf("%d", &N), N) {
		fill(g, g + 1000, -1);
		fill(D, D + 1000, vector<pii>());
		for (int i = 0; i < N; i++) {
			scanf("%02d/%02d %02d:%02d %c %03d", &a, &b, &c, &d, &e, &f);
			int z = a * 1000000 + b * 10000 + c * 60 + d;
			if (e == 'I') {
				g[f] = z;
			}
			else {
				D[f].push_back(make_pair(g[f], z));
				g[f] = -1;
			}
		}
		fill(x, x + 1000, 0);
		for (int i = 1; i < 1000; i++) {
			for (pii d1 : D[i]) {
				for (pii d2 : D[0]) {
					pii d3 = d1, d4 = d2;
					if (d3.first > d4.first) swap(d3, d4);
					if (d3.second < d4.first) continue;
					if (d3.second < d4.second) x[i] += d3.second - d4.first;
					else x[i] += d4.second - d4.first;
				}
			}
		}
		int ret = *max_element(x, x + 1000);
		printf("%d\n", ret);
	}
	return 0;
}

Measured memory_bytes: 3228
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <algorithm>
#include <set>
#include <string>
#include <queue>

using namespace std;

#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)
typedef long long ll;

int main(){
    int N, M;
    cin >> N >> M;
    vector<vector<ll>> cs(N, vector<ll>(3));
    rep(i, N){
        rep(j, cs[i].size()){
            cin >> cs[i][j];
        }
    }
    ll ans = 0;
    rep(i , (1 << 3)){
        bitset<3> p(i);
        vector<ll> ss(N, 0);
        vector<int> sign(3, 1);

        rep(j, 3){
            if(p[j] == 1){
                sign[j] = -1;
            }
        }

        rep(j, N){
            ll s = 0;
            rep(k, 3){
                s += sign[k] * cs[j][k];
            }
            ss[j] = s;
        }
        sort(ss.begin(), ss.end(), greater<ll>());
        ll tmp = 0;
        rep(j, M){
            tmp += ss[j];
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int main() {
  int a, b;
  scanf("%d %d", &a, &b);
  if (b == 1) {
    printf("0\n");
    return 0;
  }
  for (int i = 1; i <= 20; ++i) {
    int sum = (a * i) - i + 1;
    if (sum >= b) {
      printf("%d\n", i);
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=1e5+4;
int n,k,q,cnt[N];
int main() {
	scanf("%d%d%d",&n,&k,&q);
	for (register int i=0;i<q;++i) {
		int x;
		scanf("%d",&x);
		++cnt[x];
	}
	for (register int i=1;i<=n;++i)
		puts(k-q+cnt[i]>0?"Yes":"No");
	return 0;
}

Measured memory_bytes: 1024
from itertools import combinations

s = input()

ans = ['-','-','-']
for i in range(4):
    for comb in combinations(range(3),i):
        temp = int(s[0])
        for j in range(3):
            if j in comb:
                temp += int(s[j+1])
            else:
                temp -= int(s[j+1])
        if temp==7:
            for j in comb:
                ans[j] = "+"
            break 
print("{a}{op1}{b}{op2}{c}{op3}{d}=7".format(a=s[0],op1=ans[0],b=s[1],op2=ans[1],c=s[2],op3=ans[2],d=s[3]))

Measured memory_bytes: 9132
n = int(input())
a_li = list(map(int,input().split()))
cnt = [0]*(10**6+1)


for i in a_li:
    cnt[i] += 1
unique = []
for i in range(10**6+1):
    if cnt[i] == 1:
        unique.append(i)
#print(unique)

a_li = set(a_li)

cnt = [0]*(10**6+1)

for i in a_li:
    for j in range(i * 2, 10 ** 6 + 1, i):
        cnt[j] = 1

ans = 0
for i in unique:
    if cnt[i] == 0:
        ans += 1
print(ans)

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll, ll> pair_t;
using Graph = vector<vector<ll>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = 1 << 29;
/****** define constant end ********/

/****** define variable start ******/
ll x;
/******* define variable end *******/
ll solve()
{
    cin >> x;
    ll ans = 0;
    ans += x / 500 * 1000;
    x = x - (x / 500) * 500;
    ans += x / 5 * 5;
    cout << ans << endl;
    return 0;
}
int main()
{
    //clock_t start = clock();
    cout << std::fixed << std::setprecision(10);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll end_solve = solve();
    /*
    clock_t end = clock();
    const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
    printf("time %lf[ms]\n", time);
    */

    return (int)end_solve;
}


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

#define REP(i, n) for (int i = 0; i < n; i++)
#define INF 1000000000

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef long double ld;

int vector_finder(std::vector<int> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance(vec.begin(), itr);
  if (index != vec.size()) { // 発見できたとき
    return 1;
  } else { // 発見できなかったとき
    return 0;
  }
}

struct edge_t {
  int dest;
  int weight;
};

struct vertex_t {
  vector<edge_t> edges;
  vector<int> weight;

  // for dijkstra
  bool done; // confirm or not
  int cost;  // now cost
  int from;

  bool operator<(const vertex_t &another) const { // priority --> min
    return another.cost < cost;                   // order(cost)
  }

  bool operator>(const vertex_t &another) const { // priority --> min
    return another.cost > cost;                   // order(cost)
  }

  bool operator==(const vertex_t &another) const {
    return another.cost == cost; // order(cost)
  }

  vertex_t() {
    cost = INF;
    done = false;
  }
};

int bellman_ford(vector<vertex_t> &graph, int size, int start) {
  int i, j, k, count = 0;
  bool flag = false;
  graph[start].cost = 0;
  REP(i, size) {
    REP(j, size) {
      vertex_t cur = graph[j];
      for (edge_t edge : cur.edges) {
        if (cur.cost + edge.weight < graph[edge.dest].cost) {
          if (i == size - 1)
            flag = true;
          graph[edge.dest].cost = cur.cost + edge.weight;
        }
      }
    }
  }
  if (flag) {
    return 1;
  } else {
    return 0;
  }
}

class tree_t {
  public:
  bool is_leaf;
  tree_t *right;
  tree_t *left;

  tree_t() {
    is_leaf = false;
    right = NULL;
    left = NULL;
  }
};

vector<string> splitstr(const string &s, char delim) {
  vector<string> elems;
  string item;
  for (char ch : s) {
    if (ch == delim) {
      if (!item.empty())
        elems.push_back(item);
      item.clear();
    } else {
      item += ch;
    }
  }
  if (!item.empty())
    elems.push_back(item);
  return elems;
}

////////////////////////// let's code! /////////////////////////////

int i, j, k;

///// variables frequent to use /////

int main() {

  int A, B, C;

  cin >> A >> B >> C;

  if (B + C > A) {
    cout << C - (A - B);
  } else {
    cout << 0;
  }
}


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

#define int long long

#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define ALL(v) (v).begin(), (v).end()

#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;

using pi = pair<int, int>;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vpi = vector<pi>;
using vvi = vector<vi>;
using vvb = vector<vb>;

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int n, m, l; cin >> n >> m >> l;
    vvi A(n, vi(m)), B(m, vi(l)), C(n, vi(l));
    REP(i, n) REP(j, m) cin >> A[i][j];
    REP(i, m) REP(j, l) cin >> B[i][j];
    REP(i, n)
    {
        REP(j, l)
        {
            int sum = 0;
            REP(k, m)
            {
                sum += A[i][k]*B[k][j];
            }
            C[i][j] = sum;
        }
    }
    REP(i, C.size())
    {
        REP(j, C[i].size())
        {
            cout << C[i][j];
            if(j != C[i].size()-1) cout << " ";
        }
        cout << endl;
    }
}


Measured memory_bytes: 3260
#include <iostream>
using namespace std;
int main(void){
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;
    if (x >= r && x + r <= W && y >= r && y + r <= H ){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}



Measured memory_bytes: 3100
i = input().split(' ')
W = int(i[0])
H = int(i[1])
x = int(i[2])
y = int(i[3])
r = int(i[4])

if (x - r >= 0) and (y - r >=0) and (x + r <= W) and (y + r <= H):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 6728
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
 
int main() {
	int n;
  	cin>>n;
	int h[n];
  	for(int i=0;i<n;i++) cin>>h[i];
  	ll dp[n];
 	dp[0]=0;dp[1] = abs(h[0]-h[1]);
  	for(int i=2;i<n;i++) {
    	dp[i] = min(dp[i-2]+abs(h[i-2]-h[i]), dp[i-1]+abs(h[i-1]-h[i]));
    }
	cout<<dp[n-1]<<endl;
 }  


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int main() {
long long N;
cin>>N;
long long a,b;
long long counter=0;
long long c=100000000000;
for(long long i=1;i<N;i++){
a=i;
b=N-a;
while(a>0){
counter+=a%10;
a/=10;}
while(b>0){
counter+=b%10;
b/=10;}
c=min(counter,c);
counter=0;}
cout<<c<<endl;}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll h,w,ans=0;cin>>h>>w;
  vector<cvector> G(h,cvector(w));
  string s;
  queue<P> que;
  rep(i,h) {
    cin>>s;
    rep(j,w) {
      G[i][j]=s[j];
      if(s[j]=='#') que.push(P(i,j));
    }
  }
  bool operated=false;
  ll l,cnt,x,y;
  lvector dx{1,0,-1,0},dy{0,1,0,-1};
  P tag;
  while(que.size()) {
    operated=false;
    cnt=0,l=que.size();
    while(cnt<l) {
      tag=que.front();que.pop();
      x=tag.first,y=tag.second;
      rep(i,4) {
        if(  0<=x+dx[i]&&x+dx[i]<h&&0<=y+dy[i]&&y+dy[i]<w
           &&G[x+dx[i]][y+dy[i]]=='.') {
          G[x+dx[i]][y+dy[i]]='#';
          que.push(P(x+dx[i],y+dy[i]));
          operated=true;
        }
      }
      cnt++;
    }
    if(operated) ans++;
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 17588
#include <stdio.h>

int main()
{
	int n;
	long long int arr[10000], min, max, sum;
       scanf("%d",&n);
      for(int i=0; i<n; i++)
    {
        scanf("%lld", &arr[i]);
    }

  min = arr[0];
  max = arr[0];
  sum = arr[0];
  
  
   for(int i=1; i<n; i++)
    {
        /* If current element is greater than max */
        if(arr[i] > max)
        {
            max = arr[i];
        }

        /* If current element is smaller than min */
        if(arr[i] < min)
        {
            min = arr[i];
        }
        sum += arr[i];
    }
 	printf("%lld %lld %lld\n", min, max, sum);
	
	return 0;
}



Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007
int main()
{
	fast;
	string s;
	cin>>s;
	ll ans=0;
	for(int i=1;i<s.length();i++)
		if(s[i]==s[i-1])
			s[i]=(char)(abs(1-(s[i]-'0')+'0')),ans++;
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3776
#include <cmath>
#include<iostream>
#include <functional>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <iomanip>
using namespace std;
 
int main(){    
  int N;
  cin >> N;
  double ans;

  ans = round((N/2.0))/N;
  
  cout << fixed << setprecision(10) << ans << endl;
}


Measured memory_bytes: 256
import sys
import re
import math
import collections
import decimal
import bisect
import itertools

import copy

# import heapq
# from collections import deque
# import decimal

# sys.setrecursionlimit(100001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    k, a, b = ns()
    ans = 0
    if b - a < 2:
        ans = k + 1
    else:
        if k - a <= 0:
            ans = k + 1
        else:
            ans = a + (k + 1 - a) // 2 * (b-a) + (k + 1 - a) % 2

    print(ans)


if __name__ == '__main__':
    main()


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

using namespace std;


int main() {
	int N;
	string S;

	cin >> N >> S;

	if (S.size() % 2 == 1) cout << "No" << endl;

	else {
		int n = S.size() / 2;
		int a = 0;
		for (int i = 0; i < n; i++) {
			if (S[i] == S[i + n]) {
				a++;
			}
		}
		if (a == n) cout << "Yes" << endl;
		else cout << "No" << endl;

	}


	
	}

	






Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<list>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
using namespace std;
bool a[10000][721];
int main() {
	int N, M, r, q;
	while (cin >> N >> M&&N != 0 && M != 0) {
		cin >> r;
		for (int i = 0; i < M; i++) {
			for (int j = 0; j <= 720; j++) {
				a[i][j] = false;
			}
		}
		int b[1000][2];
		for (int z = 0; z < r; z++) {
			int t,n, m, s;
			cin >> t >> n >> m >> s;
			m--;
			t -= 540;
			if (s == 1) {
				b[n][0] = t;
				b[n][1] = m;
			}
			else {
				for (int i = b[n][0]; i < t; i++) {
					a[m][i] = true;
				}
			}
		}
		cin >> q;
		for (int z = 0; z < q; z++) {
			int ts, te, m;
			cin >> ts >> te >> m;
			int sum = 0;
			ts -= 540;
			te -= 540;
			m--;
			for (int i = ts; i < te; i++) {
				if (a[m][i]) sum++;
			}
			cout << sum << endl;
		}
	}
} 

Measured memory_bytes: 9788
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;
long long MOD = 1000000007LL;

int main() {
	vector<vector<int>> adjM;
	int N;
	cin >> N;
	adjM.resize(N);
	for (int i = 0; i < N; ++i) {
		adjM[i].resize(N);
	}

	for (int i = 0; i < N; ++i) {
		int v, g;
		cin >> v;
		cin >> g;
		for (int j = 0; j < g; ++j) {
			int k;
			cin >> k;
			adjM[v - 1][k - 1] = 1;
		}
	}

	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N - 1; ++j) {
			cout << adjM[i][j] << " ";
		}
		cout << adjM[i][N - 1] << endl;
	}

	return 0;
}


Measured memory_bytes: 3124
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan =new Scanner(System.in);
		int N=scan.nextInt();
		int[] masu=new int[N];
		int count=0;
		for(int i=0;i<N;i++) {
			masu[i]=scan.nextInt();
		}
		for(int i=0;i<N;i++) {
			if(i%2==0) {
				if(masu[i]%2!=0) {
					count+=1;
				}
			}
		}
		System.out.println(count);
	}

}


Measured memory_bytes: 35836
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define ld long double
#define pld pair<ld,ld>
#define lg length()
#define sz size()
#define pb push_back
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005
#define x1 xdddddddddddddddddd
#define y1 ydddddddddddddddddd

int a,b,c,x,y;

int ans=INF;

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> a >> b >> c >> x >> y;
    for(int i=0;i<=2*max(x,y);i+=2){
        ans=min(ans,c*i+a*max(0,(x-i/2))+b*max(0,(y-i/2)));
    }
    cout << ans;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

#define MAX_N	(50)

/* typedef */

typedef int mat_t[MAX_N][MAX_N];
typedef int vec_t[MAX_N];

/* subroutines */

void mulmod(int n, mat_t m, mat_t m1, int mod) {
  mat_t m0;
  memcpy(m0, m, sizeof(mat_t));

  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) {
      int mij = 0;
      for (int k = 0; k < n; k++)
        mij += m0[i][k] * m1[k][j];
      m[i][j] = mij % mod;
    }
}

void powmod(int n, mat_t m, mat_t m0, int t, int mod) {
  memset(m, 0, sizeof(mat_t));
  for (int i = 0; i < n; i++) m[i][i] = 1;

  while (t > 0) {
    if (t & 1) mulmod(n, m, m0, mod);

    mat_t m1;
    memcpy(m1, m0, sizeof(mat_t));
    mulmod(n, m0, m1, mod);

    t >>= 1;
  }
}

/* main */

int main() {
  for (;;) {
    int n, m, a, b, c, t;
    cin >> n >> m >> a >> b >> c >> t;
    if ((n | m | a | b | c | t) == 0) break;

    vec_t v;
    for (int i = 0; i < n; i++) cin >> v[i];

    mat_t mat0;
    memset(mat0, 0, sizeof(mat_t));
  
    for (int i = 0; i < n; i++) {
      if (i > 0) mat0[i][i - 1] = a;
      mat0[i][i] = b;
      if (i < n - 1) mat0[i][i + 1] = c;
    }

    mat_t mat;
    powmod(n, mat, mat0, t, m);

    vec_t v0;
    for (int i = 0; i < n; i++) {
      int vi = 0;
      for (int j = 0; j < n; j++)
	vi += mat[i][j] * v[j];
      v0[i] = vi % m;
    }

    for (int i = 0; i < n; i++) {
      if (i > 0) cout << ' ';
      cout << v0[i];
    }
    cout << endl;
  }

  return 0;
}
  

Measured memory_bytes: 1204
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

from heapq import heappop, heappush

def dijkstra(E, start):
    N_d = len(E)
    dist = [INF] * N_d
    dist[start] = 0
    q = [(0, start)]
    while q:
        dist_v, v = heappop(q)
        if dist[v] != dist_v:
            continue
        for u, dist_vu in E[v]:
            dist_u = dist_v + dist_vu
            if dist_u < dist[u]:
                dist[u] = dist_u
                heappush(q, (dist_u, u))
    return dist

N = INT()
abc = [LIST() for i in range(N-1)]
Q, K = MAP()
xy = [LIST() for i in range(Q)]

graph = defaultdict(list)

for a, b, c in abc:
    graph[a-1].append((b-1, c))
    graph[b-1].append((a-1, c))

    # graph[a-1].append((b-1, c))

d = dijkstra(graph, K-1)

for x, y in xy:
    # ans = dijkstra(graph, x-1)[K-1] + dijkstra(graph, K-1)[y-1]
    # d = dijkstra(graph, K-1)
    
    ans = d[x-1] + d[y-1]
    # dijkstra(graph, x-1)
    print(ans)


Measured memory_bytes: 98500
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
#include <queue>
#include <stack>
#include <utility>
#include <stdio.h>
#include <unistd.h>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define drep(i, n) for(int i = n - 1; i >= 0; i--)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl
#define PI 3.14159265359

const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const int mod = 1000000007;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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


int main() {
  ll n;
  cin >> n;
  vector<ll> v;

  int ans = INF;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ans = min(ans, (int)(to_string(n / i).size()));
    }
  }
  P(ans);


  return 0;
}



Measured memory_bytes: 256
// include headers{{{
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
/*}}}*/
# define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
    int H, W, h, w; cin >> H >> W >> h >> w;
    int ans = (H-h) * (W-w);
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
def solve():
    N, M = map(int, input().split())
    edges = [[] for _ in [0] * N]
    for _ in [0] * M:
        a, b = map(int, input().split())
        edges[a].append(b)
        edges[b].append(a)
    bridges = sorted((a, b) if a < b else (b, a) for a, b in get_lowlink(edges, M)[0])
    for a, b in bridges:
        print(a, b)


def get_lowlink(edges, edge_num):
    import sys
    sys.setrecursionlimit(10**7)

    n = len(edges)
    order = [-1] * n
    low = [float("inf")] * n
    bridges = []
    articulations = [0] if edge_num == n-1 and len(edges[0]) > 1 else []
    append_bridge, append_articulation = bridges.append, articulations.append

    def dfs(v, prev, k):
        order[v] = low[v] = k

        is_articulation = False
        for dest in edges[v]:
            if order[dest] == -1:
                dfs(dest, v, k + 1)
                if low[v] > low[dest]:
                    low[v] = low[dest]
                if order[v] < low[dest]:
                    append_bridge((v, dest))
                is_articulation |= order[v] <= low[dest]

            elif dest != prev and low[v] > order[dest]:
                low[v] = order[dest]

        if v > 0 and is_articulation:
            append_articulation(v)

    dfs(0, 0, 0)
    return bridges, articulations


if __name__ == "__main__":
    solve()

Measured memory_bytes: 22308
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    string a;
    cin>>a;
    int ans=0;
    int maxn=0;
    for(int i=0;i<n;i++){
    	if(a[i]=='I'){
    		ans++;
    		if(ans>maxn){
    			maxn=ans;
			}
		}else{
			ans--;
		}
	}
	cout<<maxn<<endl;
    return 0;
}



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

ll ans(ll n)
{
    return n*(n-1)/2;
}


int main()
{
  ll n;cin>>n;
  ll a[n];
  for(int i=0;i<n;i++) cin>>a[i];
  
  unordered_map<ll,ll> mp;
  
  ll res=0;
  
  for(int i=0;i<n;i++)
  {
      mp[a[i]]++;
  }
  
  for(auto x:mp)
  {
      res+=ans(x.second);
  }
  for(int i=0;i<n;i++)
  {
      ll answer=res-ans(mp[a[i]]);
      answer+=ans(mp[a[i]]-1);
      cout<<answer<<"\n";
  }
  
}

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

int main()
{
    string S;
    cin >> S;
    list<char> ans;
    for (char s : S)
    {
        ans.emplace_back(s);
    }

    int Q, q;
    cin >> Q;
    bool is_reverse = false;
    for (int i = 0; i < Q; i++)
    {
        cin >> q;
        if (q == 1)
        {
            is_reverse = !is_reverse;
        }
        else if (q == 2)
        {
            int F;
            char C;
            cin >> F >> C;
            if (F == 1)
            {
                if (is_reverse)
                {
                    ans.emplace_back(C);
                }
                else
                {
                    ans.emplace_front(C);
                }
            }
            if (F == 2)
            {
                if (is_reverse)
                {
                    ans.emplace_front(C);
                }
                else
                {
                    ans.emplace_back(C);
                }
            }
        }
    }
    if (is_reverse)
    {
        for (auto itr = ans.rbegin(); itr != ans.rend(); itr++)
        {
            cout << *itr;
        }
    }
    else
    {
        for (auto itr = ans.begin(); itr != ans.end(); itr++)
        {
            cout << *itr;
        }
    }
    cout << endl;
}


Measured memory_bytes: 9984
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define ppb pop_back
#define ppf pop_front
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long
#define ii pair<int,int>
#define iii pair<ii,int>
#define iiii pair<ii,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)/2)
#define all(x) x.begin(),x.end()
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define pw(x) (1ll<<(x))
#define inf 100000000000000008
#define MOD 998244352
#define N 1005	
#define M 1000003
#define C 100000
#define lab(i,j) (((i-1)*n)+j)
#define LOG 19
#define KOK 650
#define EPS 0.0001
using namespace std;

int n,x,t;
int val[N];
int mn[1005];
bool dp[1005][5005];
vector<int> v[N];

void dfs(int node) {

	for(int i:v[node]) dfs(i);
	
	dp[0][0]=1;

	int sum=0;

	for(int i=1;i<=sz(v[node]);i++) {

		int cur=v[node][i-1];

		sum+=val[cur]+mn[cur];

		for(int j=0;j<=5000;j++) {

			dp[i][j]=0;

			if(j-mn[cur]>=0) {

				dp[i][j]|=dp[i-1][j-mn[cur]];

			}

			if(j-val[cur]>=0) {

				dp[i][j]|=dp[i-1][j-val[cur]];

			}

		}

	}

	for(int i=val[node];i>=0;i--) {

		if(dp[sz(v[node])][i]) {

			mn[node]=sum-i;

			return ;

		}

	}

	cout<<"IMPOSSIBLE";

	exit(0);

}

int main() {
 
//	freopen("input.txt","r",stdin);
 
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);

	cin>>n;

	for(int i=2;i<=n;i++) {

		cin>>x;

		v[x].pb(i);

	}

	for(int i=1;i<=n;i++) cin>>val[i];

	dfs(1);

	cout<<"POSSIBLE";

}

Measured memory_bytes: 5248
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007

int main(){
	map<int,int>mp;
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		int tmp;
		cin >> tmp;
		mp[tmp]++;
	}
	int m;
	cin >> m;
	bool flag = 0;
	for(int i=0;i<m;i++){
		int tmp;
		cin >> tmp;
		if(mp[tmp]==0){
			flag = 1;
			break;
		}else{
			mp[tmp]--;
		}
	}
	if(flag){
		cout << "NO" << endl;
	}else{
		cout << "YES" << endl;
	}
	return 0;
}

Measured memory_bytes: 9600
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map> 
#include <unordered_set>
#include <functional>

using namespace std;

typedef pair<long long int, long long int> P;
typedef tuple<int, int, int> T;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

long long int memo[500000];

int main(){
	int pos = 250000;
	for(int i = 0; i < pos; i++){
		memo[i] = -1;
	}
	long long int ans = 0;
	vector<char> v;
	vector<long long int> nums;
	string S;
	cin >> S;
	for(char c : S){
		if(c == '('){
			pos += 1;
			v.push_back(c);
		}else if(c == ')'){
			nums.push_back(memo[pos]);
			memo[pos] = 0;
			pos -= 1;
			memo[pos] += 1;
			ans += memo[pos];
			v.push_back(c);
		}else{
			char c2 = v.back();
			v.pop_back();
			if(c2 == '('){
				pos -= 1;
			}else{
				ans -= memo[pos];
				memo[pos] -= 1;
				pos += 1;
				memo[pos] = nums.back();
				nums.pop_back();
			}
		}
		cout << ans << endl;
	}
	return 0;
}



Measured memory_bytes: 7440
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		String s = scan.next();
		scan.close();

		String s1 = s.substring(0, n / 2);
		String s2 = s.substring(n / 2, n);

		if (n % 2 == 0 && s1.equals(s2))
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}

Measured memory_bytes: 22100
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll a,b,c;
  cin >> a >> b >> c;
  cout << min({abs(a - b) + abs(b - c),abs(b - a) + abs(a - c),abs(a - c) + abs(c - b)}) << endl;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main(){
    int a,b,ans=0;
    cin>>a>>b;
    for(int i=a;i<=b;i++){
        if(i/10000==i%10&&(i%10000)/1000==(i%100)/10)ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define rep(i,j,k) for(int i=j;i<k;i++)
#define all(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
#define mp make_pair
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
const int  COMMAX = 510000;

long long fac[COMMAX], finv[COMMAX], inv[COMMAX];

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcd(int a,int b){return a*b / gcd(a,b);}
// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < COMMAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

struct UnionFind {
  vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
  vector<int> rank;
  int num;
  UnionFind(int N) : par(N) , rank(N) { //最初は全てが根であるとして初期化
    num = N;
    for(int i = 0; i < N; i++){
      par[i] = i;
      rank[i] = 0;
    }
  }

  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); //xの根をrx
    int ry = root(y); //yの根をry
    if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
    if(rank[rx] < rank[ry]){
      par[rx] = ry;  
    }else{
      par[ry] = rx;
      if(rank[rx] == rank[ry])rank[rx]++;
    }
    num--;
  }

  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    return root(x) == root(y);
  }
};

const int MS = 2;
const long long mod[] = {999999937LL, 1000000007LL}, base = 9973;
struct rolling_hash {
    int n;
    vector<long long> hs[MS], pw[MS];
    rolling_hash(){}
    rolling_hash(const string &s) {
        n = s.size();
        for (int i = 0; i < MS; i++) {
            hs[i].assign(n+1,0);
            pw[i].assign(n+1,0);
            hs[i][0] = 0;
            pw[i][0] = 1;
            for (int j = 0; j < n; j++) {
                pw[i][j+1] = pw[i][j]*base%mod[i];
                hs[i][j+1] = (hs[i][j]*base+s[j])%mod[i];
            }
        }
    }

    long long hash(int l, int r, int i) { return ((hs[i][r]-hs[i][l]*pw[i][r-l])%mod[i]+mod[i])%mod[i]; }

    bool match(int l1, int r1, int l2, int r2) {
        bool ret = 1;
        for (int i = 0; i < MS; i++) ret &= hash(l1,r1,i)==hash(l2,r2,i);
        return ret;
    }

    bool match(int l, int r, long long h[]) {
        bool ret = 1;
        for (int i = 0; i < MS; i++) ret &= hash(l,r,i)==h[i];
        return ret;
    }
};

int main(){
  int n;
  cin >> n;
  string a,b;
  rep(i,0,n){
    int c;
    cin >> c;
    a += to_string(c);
  }
  rep(i,0,n){
    int c;
    cin >> c;
    b += to_string(c);
  }
  string s = "";
  int c,d;
  c = d = 0;
  int e = 0;
  rep(i,1,n+1)s += to_string(i);
  do {
    e++;
    if(a==s)c=e;
    if(b==s)d=e;
  }while (next_permutation(all(s)));
  cout << abs(c-d) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char c;
  cin >> c;
 
  if(c=='a' || c=='e' || c=='i' || c=='o' || c=='u')
 	cout << "vowel" << endl;
  else
  	cout << "consonant" << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;

class MyUtil
{
    public static int[] ReadIntArray()
    {
	return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }
}

class Program
{
    public static void Main()
    {
	int n = int.Parse(ReadLine());
	Tuple<int,int,int>[] d = new Tuple<int,int,int>[n];
	for (int i = 0; i < n; i++)
	{
	    var tmp = ReadIntArray();
	    int a = tmp[0], b = tmp[1];
	    d[i] = Tuple.Create(a+b, a, b);
	}

	Array.Sort(d);
	Array.Reverse(d);

	long ans = 0;
	for (int i = 0; i < n; i++)
	{
	    var t = d[i];
	    int a = t.Item2, b = t.Item3;
	    if ((i&1) == 0) ans += a;
	    else            ans -= b;
	}

	WriteLine(ans);
    }
}


Measured memory_bytes: 23384
def parentNode(k):
    return k // 2


def leftNode(k):
    return 2 * k


def rightNode(k):
    return 2 * k + 1

banyak = int(input())
elems = [0] + [int(x) for x in input().split()]
# for k in range(1, banyak + 1):
#      print(k,parentNode(k),leftNode(k),rightNode(k))
for k in range(1, banyak+1):
    print("node {}: ".format(k), end="")
    print("key = {}, ".format(elems[k]), end="")
    if parentNode(k) >= 1:
        print("parent key = {}, ".format(
            elems[parentNode(k)]), end="")
    if leftNode(k) <= banyak:
        print("left key = {}, ".format(
            elems[leftNode(k)]), end="")
    if rightNode(k) <= banyak:
        print("right key = {}, ".format(
            elems[rightNode(k)]), end="")
    print()






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

int main(void){
  const int NMAX = 20003;
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N;
  ll p[NMAX], m[NMAX];
  ll ansa[NMAX];
  ll ansb[NMAX];

  cin >> N;
  for(int i = 0; i < N; i++) cin >> p[i], p[i]--;
  for(int i = 0; i < N; i++) m[p[i]] = i;

  ansa[0] = 1;
  ansb[N-1] = 1;
  for(int i = 1; i < N; i++){
    ansa[i] = ansa[i-1] + NMAX;
    ansb[N-i-1] = ansb[N-i] + NMAX;
  }

  for(int i = 0; i < N; i++){
    if(i != 0) cout << " ";
    cout << ansa[i];
  }
  cout << endl;
  for(int i = 0; i < N; i++){
    if(i != 0) cout << " ";
    cout << ansb[i] + m[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 1280