akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,x,ans=0;
	cin>>a>>b>>c>>x;
	for(int i=0;i<=a;++i)
		for(int j=0;j<=b;++j)
			for(int k=0;k<=c;++k)
				if(500*i+100*j+50*k==x)
					++ans;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 100
int main(){
  int a[N];
  int i,j,x,flag=1,c,d=0;
  scanf("%d",&x);
  for(i=0;i<x;i++){
    scanf("%d",&a[i]);
  }
  while(flag!=0){
    flag=0;
    for(j=x-1;j>=1;j--){
      if(a[j]<a[j-1]){
	c=a[j-1];
	a[j-1]=a[j];
	a[j]=c;
	flag=1;
	d++;
      }
    }
  }
  for(i=0;i<x-1;i++){
    printf("%d ",a[i]);
  }
  printf("%d\n%d\n",a[i],d);
  return 0;
}



Measured memory_bytes: 2144
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    S = input()

    right = 0
    left = 0
    for i in range(n):
        if S[i] == "(":
            left += 1
        else:
            if left:
                left -= 1
            else:
                right += 1
    res = "(" * right + S + ")" * left
    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9192
import math
from operator import itemgetter
N,D,A=map(int,input().split())
l=[]
for i in range(N):
  k=tuple(map(int,input().split()))
  l.append(k)
l.sort(key=itemgetter(0))
S=[0]*N
ma=[0]*N
tmp=N-1
for i in reversed(range(N)):
  x=l[i][0]
  for j in reversed(range(0,tmp)):
    if abs(l[j][0]-(x-D))>D:
      ma[i]=j+1
      tmp=j+1
      break
  else:
    ma[i]=0
    tmp=0
ans=0
S[0]=math.ceil(l[0][1]/A)
for i in range(1,N):
  h=l[i][1]
  left=S[ma[i]-1] if ma[i]>0 else 0
  right=S[i-1]
  sum_=(right-left)*A
  if h<=sum_:
    S[i]=S[i-1]
    continue
  time=math.ceil((h-sum_)/A)
  S[i]=time+S[i-1]
print(S[N-1])

Measured memory_bytes: 47436
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define vi vector<int>
#define vii vector<vector<int>>
#define mod 1000000007
#define fo(i,n) for(int i=0;i<n;i++)
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define pb(x) push_back(x)
typedef long long ll;

void print_Array(int arr[],int start,int end){
    for(int i=start;i<end;i++){
        printf("%d ",arr[i]);
    }
}


int main(){
    int rows,cols,K;
    int out=0;
    cin>>rows>>cols>>K;
    vector<vector<char>> grid(rows,vector<char>(cols));
    fo(i,rows){
        fo(j,cols){
            cin>>grid[i][j];
        }
    }
    fo(l,pow(2,rows)){
        fo(m,pow(2,cols)){
            vector<vector<char>> temp=grid;
            int r=l,c=m;
            int bit=0;
            while(r){
                if(r&1){
                    fo(j,cols) temp[bit][j]='.';
                }
                bit++;
                r>>=1;
            }
            bit=0;
            while(c){
                if(c&1){
                    fo(j,rows) temp[j][bit]='.';
                }
                bit++;
                c>>=1;
            }
            int ctr=0;
            fo(i,rows){
                fo(j,cols){
                    if(temp[i][j]=='#') ctr++;
                }
            }
            if(ctr==K) out++;
        }
    }
    cout<<out<<endl;
}



Measured memory_bytes: 4108
import math

A, B, H, M = map(int, input().split())
angleH = 360 * ((H + (M / 60)) / 12)
angleM = 360 * (M / 60)
angle = abs(angleH - angleM)
answer = math.sqrt(math.pow(A, 2) + math.pow(B, 2) - (2 * A * B * math.cos(math.radians(angle))))
print(answer)

Measured memory_bytes: 9444
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#include <bitset>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
int main(){
    int n;
    cin >> n;
    vector<ll>a(n),b(n);
    rep(i,n)cin >> a[i] >> b[i];
    if(a==b)return cout << 0 << endl, 0;
    ll sum = accumulate(a.begin(),a.end(),0LL);
    ll mi = 1LL<<60;
    rep(i,n)if(a[i]>b[i])mi=min(mi,b[i]);
    cout << sum - mi << endl;
}

Measured memory_bytes: 1144
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007


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

  vector<int> D(N);
  for(int i = 0;i < N;i++) {
    cin >> D.at(i);
  }

  cin >> M;
  vector<int> T(M);
  for(int i = 0;i < M;i++) {
    cin >> T.at(i);
  }

  sort(D.begin(),D.end());
  sort(T.begin(),T.end());
  D.push_back(0);

  int t = 0;
  for(int i = 0;i < M;i++) {
    while(t < N && D.at(t) != T.at(i)) t++;
    if(t == N) {
      cout << "NO" << endl;
      return 0;
    }
    t++;
  }

  cout << "YES" << endl;

}



Measured memory_bytes: 2560
#include<cstdio>
using namespace std;
int main()
{
	int n,t,x,y;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d%d",&t,&x,&y);
		if(x+y>t) return printf("No\n"),0;
		if((x+y)%2==0&&t%2==1) return printf("No\n"),0;
		if((x+y)%2==1&&t%2==0) return printf("No\n"),0;
	}
	return printf("Yes\n"),0;
}

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

int main() {
  int n; cin >> n;
  vector<int> A(n-1,0);
  rep(i,n-1) {
    int a; cin >> a;
    A[i] = --a;
  }
  map<int, int> m;
  rep(i,n) m[i] = 0;
  rep(i,n-1) {
    m[A[i]] += 1;
  }
  for (auto p : m) cout << p.second << endl;
}

Measured memory_bytes: 13556
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

double calc_h (int x, int h )
{
	return sqrt((double)h*h + (double)x*x/4.);
}

int main()
{
//	cut here before submit 
//	freopen ("testcase.SAQP", "r", stdin );
	int x, h;
	while (scanf ("%d %d", &x, &h ), x, h ){
		double th = calc_h (x, h );
//		cerr << "th: " << th << endl;
		double res = (double)x*x + 2.*(double)x*th;
		printf ("%.9lf\n", res );
	} // end loop
		
	return 0;
}

Measured memory_bytes: 1220
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <queue>
#include <time.h>

using namespace std;

#define INT_MAX 2147483647
typedef long long ll;

ll gcd(ll m, ll n);		//最大公倍数
ll lcm(ll m, ll n);		//最小公倍数

int main(void) {

	int ans = 0;

	int m, n;
	cin >> m >> n;
	if (m%n != 0) ans = 1;

	cout << ans << endl;

	return 0;

}

// 2番目から3要素だけ抜き出した部分文字列を取得する
//std::string result = s.substr(2, 3);  

#if 1
//最大公倍数
ll gcd(ll m, ll n)
{
	ll temp;
	while (m % n != 0)
	{
		temp = n;
		n = m % n;
		m = temp;
	}
	return n;
}

//最小公倍数
ll lcm(ll m, ll n)
{
	return m * n / gcd(m, n);
}
#endif

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

using namespace std;

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

// chmax, chmin
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;
}

long long D[88][88];


bool dp[85][85][2 * 200 * 100 + 5];

int H, W;

long long ans = 1e9;
void dfs(int r, int c, long long v) {
    if( r == H ) return;
    if( c == W ) return;
    if (dp[r][c][v + 200 * 100]) return;
    dp[r][c][v + 200 * 100] = true;

    if (r == H - 1 && c == W - 1) {
        ans = min(ans, abs(v + D[r][c]));
        ans = min(ans, abs(v - D[r][c]));
        return;
    }

    dfs(r+1, c, v - D[r][c]);
    dfs(r, c+1, v + D[r][c]);

    dfs(r+1, c, v + D[r][c]);
    dfs(r, c+1, v - D[r][c]);


}

void solve(long long H, long long W, std::vector<std::vector<long long>> A,
           std::vector<std::vector<long long>> B) {
    ::H = H;
    ::W = W;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            D[i][j] = A[i][j] - B[i][j];
        }
    }
    dfs(0, 0, 0);
    cout << ans << endl;
}

int main() {
    long long H;
    scanf("%lld", &H);
    long long W;
    scanf("%lld", &W);
    std::vector<std::vector<long long>> A(H, std::vector<long long>(W));
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            scanf("%lld", &A[i][j]);
        }
    }
    std::vector<std::vector<long long>> B(H, std::vector<long long>(W));
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            scanf("%lld", &B[i][j]);
        }
    }
    solve(H, W, std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 265088
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int n, k;
int p[1000];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> n >> k;
    for(int i = 0; i < n; i++) cin >> p[i];
    sort(p, p+n);
    int ans = 0;
    for(int i = 0; i < k; i++) ans += p[i];
    cout << ans << endl;
}

Measured memory_bytes: 3660
import sys
from math import factorial

N = int(input())
S = input()
mod = 10**9+7

if S[0] == 'W' or S[-1] == 'W':
    print(0)
    sys.exit()

op = "L"
for i in range(1, 2*N):
    if S[i] == S[i-1]:
        op += 'R' if op[i-1] == 'L' else 'L'
    else:
        op += 'R' if op[i-1] == 'R' else 'L'

if op.count('L') != N:
    print(0)
    sys.exit()

ct_L, ans = 0, 1

for i in op:
    if i == 'L':
        ct_L += 1
    else:
        ans *= ct_L
        ct_L -= 1
    ans %= mod


print(factorial(N) * ans % mod)


Measured memory_bytes: 4584
#include <iostream>
#include <map>

std::pair<int, int> FibonacciPair(int Index)
{
	if(Index == 0) return std::make_pair(0, 1);
	if(Index == 1) return std::make_pair(1, 1);
	std::pair<int, int> Prev = FibonacciPair(Index - 1);
	return std::make_pair(Prev.second, Prev.first + Prev.second);
}

int FibonacciNumber(int Index)
{
	return FibonacciPair(Index).second;
}

int main()
{
	int Index;
	std::cin >> Index;
	std::cout << FibonacciNumber(Index) << std::endl;
	return 0;
}

Measured memory_bytes: 3100
N, M, Q = map(int, input().split())
ct = [[0] * N for _ in range(N)]

for i in range(M):
  l, r = map(int, input().split())
  ct[l-1][r-1] += 1
  ct[r-1][l-1] += 1

m = [[0] * N for _ in range(N)]
for i in range(N):
  rowsum = 0
  for j in range(N):
    rowsum += ct[i][j]
    m[i][j] = rowsum
    if i > 0:
      m[i][j] += m[i-1][j]

for i in range(Q):
  p, q = map(int, input().split())
  p -= 1
  q -= 1
  ans = m[q][q]
  if p > 0:
    ans = ans - m[p-1][q] - m[q][p-1] + m[p-1][p-1]
  print(ans // 2)

Measured memory_bytes: 15588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0; i<n; i++)
int main()
{
	ll N;
	cin >> N;
	ll ans = N-1;
	for(ll A = 2; A<N; A++){
		ans = ans + N/A;
		if(N%A==0)
			ans--;
	}
	cout << ans;
	cin >> N;
	
	return 0;	
}


Measured memory_bytes: 3660
#include <iostream>

using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

int main()
{
  int h, w;
  string a;
  cin >> h >> w;
  REP(i, w + 2)
    cout << "#";
  cout << endl;
  REP(i, h){
    cout << "#";
    cin >> a;
    cout << a;
    cout << "#" << endl;
  }
	REP(i, w + 2)
		cout << "#";
  cout << endl;
}


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

int H, W;
char ch[ 110 ][ 110 ];
int a[ 110 ][ 110 ];
int Line[ 110 ], Row[ 110 ];

int main() {
    scanf( "%d%d", &H, &W );
    for( int i = 0; i < H; ++i ) scanf( "%s", ch[ i ] );
    for( int i = 0; i < H; ++i )
        for( int j = 0; j < W; ++j )
            a[ i ][ j ] = ( ch[ i ][ j ] == '.' ) ? 0 : 1;
    for( int i = 0; i < H; ++i ) {
        Line[ i ] = 1;
        for( int j = 0; j < W; ++j ) 
            if( a[ i ][ j ] ) {
                Line[ i ] = 0;
                break;
            }
    }
    for( int i = 0; i < W; ++i ) {
        Row[ i ] = 1;
        for( int j = 0; j < H; ++j ) 
            if( a[ j ][ i ] ) {
                Row[ i ] = 0;
                break;
            }
    }
    for( int i = 0; i < H; ++i ) {
    	if( Line[ i ] ) continue;
        for( int j = 0; j < W; ++j ) 
            if( Line[ i ] != 1 && Row[ j ] != 1 ) 
            	if( a[ i ][ j ] ) cout << "#"; else cout << ".";
        cout << endl;
    }
    return 0;
}

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

int main(){
  int N;
  vector<int> L;
  cin >> N;
  for(int i=0; i<N; i++){
    int l; cin >> l;
    L.push_back(l);
  }
  sort(L.begin(), L.end(), greater<int>());
  long count=0;
  for(int i=0; i<L.size()-2; i++){
    for(int j=i+1; j<L.size()-1; j++){
      for(int k=j+1; k<L.size(); k++){
        if(L[i]<L[j]+L[k]) count++;
      }
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define pd(a,n) for(int i=0;i<n;i++)cout<<a[i]<<((i==n-1)?"\n":" ");cout<<endl;
#define pdd(a,n,m)for(int i=0;i<n;i++){for(int j=0;j<m;j++)cout<<a[i][j]<<" ";cout<<endl;}
#define mp make_pair
#define pb push_back
#define ll long long
//#define __int64 lng long
#define P pair<int,int>
#define PP pair<P,int>
int a[100]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main(){
  int k;
  cin>>k;
  k--;
  cout<<a[k]<<endl;
  return 0;
}

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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T>
string join(const vector<T>&v, string del=", "){ stringstream s;
    for(auto x : v) s << del << x; return s.str().substr(del.size());
}
template<typename T>
ostream& operator<<(ostream& o, const vector<T>&v){
    if(v.size()) o << "[" << join(v) << "]"; return o;
}
template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T> >&vv){
    int l = vv.size();
    if(l){ o<<endl; rep(i,l) o << (i==0 ? "[ " : ",\n  " ) << vv[i] << (i==l-1 ? " ]" : ""); }
    return o;
}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    int n; cin >> n;
    vi a(n);
    rep(i,n) cin >> a[i];
    vi dp(n, INF);
    rep(i,n){
        *lower_bound(all(dp), a[i]) = a[i];
    }
    cout << lower_bound(all(dp), INF-1) - dp.begin() << endl;
    return 0;
}


Measured memory_bytes: 3636
//bismillahir rahmanir rahim            //Author:Fayed Anik
 
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
//using namespace __gnu_pbds;
 
/*
template <typename T>  using ordered_set =
    tree<T, null_type, less<T>,   /// greater<T> for sorting decreasingly
    rb_tree_tag, tree_order_statistics_node_update>;
*/

#define         ll                          long  long
#define         lf                          double
#define         pb(x)                       push_back(x)
#define         ull                         unsigned long long
#define         sfl(a)                      scanf("%lld",&a)
#define         sf(a)                       scanf("%d",&a)
#define         pf(a)                       printf("%d\n",a)
#define         pfl(a)                      printf("%lld\n",a)
#define         FOR(x,n)                    for(ll x=1;x<=n;++x)
#define         pii                         pair< ll , ll >
#define         mp(a,b)                     make_pair(a,b)
#define         mod                         1000000007
#define         INF                         2e18
#define         f1                          first
#define         f2                          second
#define         all(v)                      v.begin(),v.end()
#define         PI                          acos(-1)
#define         printminusone               printf("-1\n")
#define         bug                         printf("bug")
#define         FILEIN                      freopen("in.txt","r",stdin)
#define         FILEOUT                     freopen("out.txt","w",stdout)
 
//ll SET(ll mask,ll pos){ return mask = (mask | (1ll<<pos)); }
//ll RESET(ll mask,ll pos){ return mask = mask & ~(1ll<<pos); }
//bool CHECK(ll mask,ll pos) { return (bool) (mask & (1ll<<pos)); }
//priority_queue <ll, vector<ll>, greater<ll> > pq;

#define N 100005

ll fac[N],inv[N],a[N];

ll fastexpo(ll b,ll p){
    ll res=1;
    while(p){
        if(p&1){
            res = (res * b)%mod;
        }
        p=p>>1ll;
        b=(b*b)%mod;
    }
    return res;
}

ll NCR(ll n,ll r){
    if(n==r or r==0) return 1;
    ll val = fac[n];
    val = (val * inv[n-r])%mod;
    val = (val * inv[r])%mod;
    //val = (val * fastexpo(fac[n-r],mod-2))%mod;
    //val = (val * fastexpo(fac[r],mod-2))%mod;
    return val;
}
int main(){
    fac[0]=1;
    for(ll i=1;i<=100000;i++){
        fac[i]=(fac[i-1]*i)%mod;
    }
    inv[100000]=fastexpo(fac[100000],mod-2);
    for(ll i=99999;i>=0;i--){
        inv[i]=(inv[i+1]*(i+1))%mod;
    }
    ll n,k;
    //cout << NCR(5,2) << endl;
    sfl(n),sfl(k);
    for(ll i=1;i<=n;i++){
        sfl(a[i]);
    }
    sort(a+1,a+n+1);
    ll ans = 0;
    for(ll i=1;i<=n;i++){
        if(i-1>=k-1){
            ans += (NCR(i-1,k-1)*a[i])%mod;
            ans %= mod;
        }
        if(n-i>=k-1){
            ans -= (NCR(n-i,k-1)*a[i])%mod;
            (ans += mod)%=mod;
        }
    }
    pfl(ans);
    return 0;
}

Measured memory_bytes: 2560
#include<iostream>
using namespace std;
typedef long long ll;
int main(){
  ll a[101][101]={{}};
  ll b[101][101]={{}};
  int n,m,l;
  int i,j,k;
  cin >> n >> m >> l;
  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      cin >> a[i][j];
    }
  }
  for(i=0;i<m;i++){
    for(j=0;j<l;j++){
      cin >> b[i][j];
    }
  }
  for(i=0;i<n;i++){
    for(j=0;j<l;j++){
      ll o=0;
      for(k=0;k<m;k++){
	o+=a[i][k]*b[k][j];
      }
      if(j==0) cout << o;
      else cout << " " << o; 
    }
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 3256
#include <iostream>
#include <string>
using namespace std;
int main(void){
    // Your code here!
    int a,b;
    string c;
    cin >> a >> c >> b;
    if (c=="+"){
        cout << a+b << endl;
    }
    else if(c=="-"){
        cout << a-b << endl;
    }
    return 0;
}


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

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    
    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5])
        cout << "Yes\n";
    else
        cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
def binarySearch(key, arr, N):
    left = 0
    right = N
    while left < right:
        mid = (left + right) // 2
        if arr[mid] == key:
            return 1
        elif key < arr[mid]:
            right = mid
        else:
            left = mid + 1
    return 0


N1 = int(input())
arr1 = [int(n) for n in input().split()]
N2 = int(input())
arr2 = [int(n) for n in input().split()]

print(sum([binarySearch(key, arr1, N1) for key in arr2]))



Measured memory_bytes: 16900
#include<stdio.h>
#include<math.h>
struct circle
{
    double x;
    double y;
    double radius;
}circle;

int fun(double a,double b,double c,double d, double e,double f);

int main()
{
    int n;


    double x1,y1,x2,y2,x3,y3;
    double a,b,c,d,e,f;
    int i;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {

        scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3);
            a = 2*(x3-x1);
            b = 2*(y3-y1);
            c = y3*y3+x3*x3-y1*y1-x1*x1;
            d = 2*(x2-x1);
            e = 2*(y2-y1);
            f = y2*y2+x2*x2-y1*y1-x1*x1;
            if (a != 0)
            {
                fun(a,b,c,d,e,f);
            }
            else
            {
                fun(d,e,f,a,b,c);
            }

        circle.radius  = sqrt((circle.x-x1)*(circle.x-x1)+(circle.y-y1)*(circle.y-y1));
        printf("%.3lf %.3lf %.3lf\n",circle.x,circle.y,circle.radius);
    }
    return 0;
}

int fun(double a,double b,double c,double d,double e,double f)
{
    circle.y=(c*d-a*f)/(b*d-e*a);
    circle.x=(c-b*circle.y)/a;
    return 0;
}

Measured memory_bytes: 664
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()

using namespace std;

int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, -1, 0, 1 };

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

void inputVector(vector<int> &v, int &n) {rep(i,n){v.push_back(nextInt());}}
void inputVector(vector<double> &v, int &n) {rep(i,n){v.push_back(nextDouble());}}
void inputVector(vector<string> &v, int &n) {rep(i,n){v.push_back(nextString());}}

signed main() {
    string s;
    while (getline(cin, s)) {
	if (s == ".") break;

	stack<char> st;
	rep(i, s.size()) {
	    if (s[i] == '(' || s[i] == '[') {
		st.push(s[i]);
	    } else if (s[i] == ')') {
		if (st.size() > 0 && st.top() == '(') {
		    st.pop();
		} else {
		    cout << "no" << endl;
		    break;
		}
	    } else if (s[i] == ']') {
		if (st.size() > 0 && st.top() == '[') {
		    st.pop();
		} else {
		    cout << "no" << endl;
		    break;
		}
	    }
	    if (i == s.size() - 1) {
		cout << (st.size() ? "no" : "yes") << endl;
	    }
	}
    }

    return 0;
}

Measured memory_bytes: 3088
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define MAX_V 400010
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}

#define INF 1e9+7
#define LLINF 1e18+7
ll MOD=1e9+7;
#define N 110000
vector<pii> G[N];
main(){
    int a=in(),b=in(),c=in();
    if(a==b&&b==c)cout<<"Yes";
    else cout<<"No";
}


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

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

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

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

    vector<int> l(n), r(n);
    rep(i, n-1) l[i+1] = gcd(l[i], a[i]);
    rep(i, n-1) r[i+1] = gcd(r[i], a[(n-1) - i]);

    reverse(r.begin(), r.end());

    int ans = 1;
    rep(i, n) ans = max(ans, gcd(l[i], r[i]));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4460
// https://atcoder.jp/contests/abc089/tasks/abc089_c
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
char s[20];
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    // ASCIIコード 128通り
    vector<int> cnt(128);

    for (int i = 0; i < n; i++) {
        cin >> s;
        cnt[s[0]]++;
    }
    int ans = 0;
    const string a = "MARCH";
    REP(i, a.size()) FOR(j, i + 1, a.size()) FOR(k, j + 1, a.size()) {
        ans += (cnt[a[i]] * cnt[a[j]] * cnt[a[k]]);
    }

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


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	set<string> st;
	while(n--){
		string s; cin >> s;
		st.insert(s);
	}
	cout << st.size() << endl;
}

Measured memory_bytes: 19244
#include <iostream>
#include <vector>
#include <cstdlib>
#include <string>
using namespace std;

int main(){
  string S;
  cin >> S;
  if (S[2]) {
    for (int i=0; i < 3; i++) {
      cout << S[2-i];
    }
    cout << endl;
  } else {
    cout << S << endl;
  }
  return 0;
}


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

int main (){
    string str;
    cin>>str;
     int size=str.length();
      int s;int e;
    for(int i=0;i<size-1;i++){
    	if(str[i]=='A'){  s=i ;break;}
    }
    for(int j=size-1;j>0;j--){
    	if(str[j]=='Z'){  e=j  ; break;}
    }  
    
    
    	cout<<e-s+1;
    

     return 0;
}


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

using namespace std;

#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define f first
#define s second

typedef long long ll;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;

int main(){ _

	int n, W; cin >> n >> W;
	vector<ll> w(n), val(n);
	for(int i=0; i<n; i++) cin >> w[i] >> val[i];
	W++;

	vector<vector<ll>> memo(2, vector<ll>(W));

	for(int i=0; i<n; i++) {
		memo[i&1] = memo[i&1^1];
		for(int j=0; j<W; j++) if(j-w[i] >= 0)
			memo[i&1][j] = max(memo[i&1][j], memo[i&1^1][j-w[i]] + val[i]);
	}

	ll ans = *max_element(memo[(n-1)&1].begin(), memo[(n-1)&1].end());

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 5552
from operator import itemgetter
from functools import reduce
N, K = map(int, input().split())
t, d = zip(*(map(int, input().split()) for _ in range(N)))
fn = itemgetter(0)
fd = itemgetter(1)
ss = sorted(zip(t, d), key=fd, reverse=True)
netas = set()
duplicates = []
for s in ss[:K]:
  if s[0] in netas:
    duplicates.append(s[1])
  else:
    netas.add(s[0])
p = sum(map(fd, ss[:K])) + len(netas)**2
ans = p
for s in ss[K:]:
  if s[0] not in netas and duplicates:
    netas.add(s[0])
    duplicate = duplicates.pop()
    p += (s[1] - duplicate) + 2 * len(netas) - 1
    ans = max(ans, p)
print(ans)

Measured memory_bytes: 58828
n = int(input())
l = [False] * n
inputList = list(map(int, input().split()))
pairs = 0
for i in range(n):
    if l[i]:
        continue

    x = inputList[i]-1 
    if inputList[x]-1 == i:
        pairs += 1
        l[x] = True
print(pairs)

Measured memory_bytes: 84516
import sys,heapq
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True  and False
def ddprint(x):
  if DBG:
    print(x)

n,m = inm()
dst = [ [] for i in range(n*3) ]
for i in range(m):
    u,v = inm()
    u -= 1
    v -= 1
    dst[u].append(v+n)
    dst[u+n].append(v+n*2)
    dst[u+n*2].append(v)
s,t = inm()
s -= 1
t -= 1
ddprint(dst)

dist = [-1] * (n*3)
dist[s] = 0
q = deque([s])
while len(q)>0:
    v = q.popleft()
    #ddprint('v='+str(v))
    for nxt in dst[v]:
        #ddprint('nxt='+str(nxt))
        if nxt==t:
            print((dist[v]+1)//3)
            exit()
        if dist[nxt] > -1:
            continue
        dist[nxt] = dist[v]+1
        q.append(nxt)
    #ddprint(dist)
    #ddprint(q)
print(-1)


Measured memory_bytes: 83620
N = int(input())
A = [int(x) for x in input().split()]
S = 0
temp = 0
flg = False

for i in A:
    S += abs(i)
    if i < 0:
        temp += 1
    if i == 0:
        flg = True

if temp % 2 == 0 or flg is True:
    print(S)
else:
    print(S - 2*min([abs(y) for y in A]))


Measured memory_bytes: 14332
#include <stdio.h>
int main(void){
    int n,t,a;
    scanf("%d%d%d",&n,&t,&a);
    int h[n];
    for(int i=0;i<n;i++){
        scanf("%d",&h[i]);
    }
    int min=100000000;
    int y;
    int ans;
    for(int i=0;i<n;i++){
        y=t*1000-h[i]*6;
        if(y<a*1000)y=2000*a-y;
        if(y-a*1000<min){
            min=y-a*1000;
            ans=i;
        }
    }
    printf("%d\n",ans+1);
}

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

using namespace std;

int main(void){
  int N, M;
  cin >> N >> M;
  int homework = 0;
  for(int i = 0; i < M; i++){
    int A;
    cin >> A;
    homework += A;
  }
  
  cout << max(N - homework, -1) << endl;
  
  return 0;
}


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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}


int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VI a(n);
	rep(i, n) cin >>a[i];


	VI as1(n), as2(n);
	
	rep(i, n){
		as1[i] = i - a[i];
		as2[i] = a[i] + i;
	}
	map<int, ll> mp1,mp2;
	rep(i, n){
		mp1[as1[i]]++;
		mp2[as2[i]]++;
	}
	
	//for(auto x :mp1) printf("%d:%d ",x.first,x.second); dbg();
	//for(auto x :mp2) printf("%d:%d ",x.first,x.second); dbg();
	
	ll ans = 0;
	for(auto x :mp1){
		if(mp2.count(x.first)) ans += x.second * mp2[x.first];
	}
	cout << ans <<"\n";
	return 0;
}


Measured memory_bytes: 28684
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
#define rem(i, m, n) for (int i = m; i >= n; --i)
typedef long long ll;
#define mod 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

int main() {
  int N, H;
  cin >> N >> H;
  vector<int> a(N), b(N);;
  rep(i, 0, N) cin >> a[i] >> b[i];
  sort(b.begin(), b.end(), greater<int>());
  int mx = *max_element(a.begin(),a.end());
  int ans = 0;
  rep(i, 0, N) {
    if(b[i] < mx) break;
    ans++;
    H -= b[i];
    if(H <= 0) break;
  }
  if(H > 0) ans += (H + mx - 1) / mx;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
import java.util.*;

public class Main{
  public static void main(String[] args){

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int m = sc.nextInt();
    int number_digit;
    int number;

    Map<Integer,Integer> map = new HashMap<>();


    for(int i=0; i<m; i++){
      number_digit = sc.nextInt()-1;
      number = sc.nextInt();
      if(map.containsKey(number_digit)&&number!=map.get(number_digit)){
        System.out.println(-1);
        return;
      }
      map.put(number_digit,number);
    }


    if(map.containsKey(0)){
      if(map.get(0)==0&&n!=1){
        System.out.println(-1);
        return;
      }
    }

    if(n==1&&m==0){
      System.out.println(0);
      return;
    }
    int ans=0;
    outside:for(int i=(int)Math.pow(10,n-1); i<(int)Math.pow(10,n); i++){
      char[] c = new char[n];
      c = String.valueOf(i).toCharArray();
      for(int key : map.keySet()){
        if((int)c[key]-48!=map.get(key)){
          continue outside;
        }
      }
      ans = i;
      break;
    }

    System.out.println(ans);

  }
}

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

#define in cin
#define out cout

#define REP(i,n) for(int i=0; i<n; i++)
#define REP2(i,s,e) for(int i=s; i<e; i++)
#define REPE(i,s,e) for(int i=s; i<=e; i++)
#define REPR(i,s,e) for(int i=s; i>=e; i--)

#define all(v) v.begin(), v.end()
#define pb push_back

#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define rd(n) scanf("%d", &n)

#define x first
#define y second
#define intINF 2147483647
#define llINF 9223372036854775807LL
#define MOD 1000000007

int main()
{
    ll n, a, b; in >> n >> a >> b;

    ll res = 0;
    vector<int> v(n);
    REP(i, n) in >> v[i];
    REP(i, n-1)
    {
        res += min((v[i+1]-v[i])*a, b);
    }

    out << res << endl;

    return 0;
}


Measured memory_bytes: 640
N,K=map(int,input().split())
nusuke=[i for i in range(1,N+1)]

for k in range(K):
    k=int(input())
    listA=list(map(int,input().split()))
    for j in listA:
        while True:
            try:
                nusuke.remove(j)
            except ValueError:
                break
print(len(nusuke))

Measured memory_bytes: 9188
n=int(input())
arr=[int(input()) for _ in range(n)]
mod=10**9+7

dp=[0]*n
dp[0]=1

record={arr[0]:0}

for i,v in enumerate(arr):
  if i==0:
    continue
  dp[i]=dp[i-1]
  if v in record and record[v]<i-1:
    dp[i]+=dp[record[v]]
    dp[i]=dp[i]%mod
  record[v]=i
print(dp[-1])


Measured memory_bytes: 36552
use std::io::prelude::*;

fn input<T>() -> T
    where T: std::str::FromStr {
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let a: Vec<i64> =
        (0..n).map(|_| input::<i64>() * 2).collect();
    let mut a2 = 0;
    for i in 0..n {
        if i%2==0 {
            a2+=a[i];
        } else{
            a2-=a[i];
        }
    }
    println!("{}", a2/2);
    let mut t = a2/2;
    for i in 0..n-1{
        t = a[i] - t;
        println!("{}", t);
    }
}

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

vector<double> t(3000, -1.0);
vector<vector<double>> dp(3000, t);

double prob(vector<double> &p, int i, int k){
    if( k == 0)return 1;
    if( i == p.size())return 0;
    if( dp[i][k] != -1.0)return dp[i][k];
    
    double ans = (1 - p[i]) * prob(p, i + 1, k) + p[i] * prob(p, i + 1, k - 1);
    dp[i][k] = ans;
    return ans;
    
}

int main() {
    int n;
    cin>>n;
    vector<double> p(n, 0.0);
    for(int i =0  ; i < n ; i++)cin>>p[i];
    
    printf("%.10f", prob(p, 0, n/2 + 1));
    
	return 0;
}


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

int main() {
  int N;
  cin>>N;
  int data[N];
  bool quiz;
  quiz=true;
  for(int i=0;i<N;i++){
    cin>>data[i];
  }
  for(int i=0;i<N;i++){
    if(data[i]%2==0){
      if(data[i]%3==0 || data[i]%5==0){
        quiz=true;
      }
      else{
        quiz=false;
        break;
      }
    }
  }
  if(quiz==true){
    cout<<"APPROVED"<<endl;
  }
  else{
    cout<<"DENIED"<<endl;
  }
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
int main() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	string s;
	cin >> s;
	int g = 0, p = 0;
	for(char ch : s) {
		if(ch == 'g') ++g;
		else ++p;
	}
	cout << (g + p) / 2 - p << '\n';
	return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

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

	    int a= gi();
	    int b= gi();



        //System.out.print(Math.max(a*b, c*d));
        if (a==b) {
        	System.out.print("Draw");
        }else if(a==1){
        	System.out.print("Alice");
        }else if(b==1){
        	System.out.print("Bob");
        }else if(a>b){
        	System.out.print("Alice");
        }else{
        	System.out.print("Bob");
        }

	   
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}
}

Measured memory_bytes: 35640
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                                                       \
    for(long long hoge = 0; (hoge) < (n); ++(hoge))                            \
    cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    int p[N];
    for(int i = 0; i < N; i++)
        cin >> p[i];
    sort(p, p + N);
    long long ans = 0;
    for(int i = 0; i < K; i++)
        ans += p[i];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3620
#include <iostream>
using namespace std;
int conbi(int n, int r){
  int num = 1;
  for(int i = 1; i <= r; i++){
    num = num * (n - i + 1) / i;
  }
  return num;
}
int main() {
  int M,N; cin>>M>>N;
  int n = conbi(M,2);
  n += conbi(N,2);
  cout<<n<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int S[4*200010];
int N[200010];
int T;
int MIN(int a,int b){return a<b?a:b;}
int MAX(int a,int b){return a<b?b:a;}
//????????¢??°?????????MIN???
int hyoka(int a,int b){return (a<0||b<0)?(a<0?b:a):N[a]<N[b]?a:b;}
//?????°??¨?????????n?????°???d??§?????????????§????
void sset(int n){
  int i;
  for(T=1;T<n;T*=2);
  for(i=0;i<n;i++)S[T+i]=i;
  for(   ;i<T;i++)S[T+i]=-1;
  for(i=T-1;i;i--)S[i]=hyoka(S[i*2],S[i*2+1]);
}
//?????°??¨???update??¢??°
//i???????????°??????n????????´???????§????
void sud(int i,int n){for(N[i+=T]=n;i/=2;)S[i]=hyoka(S[i*2],S[i*2+1]);}
//?????°??¨???find??¢??°
//[a,b)????????????????????????sout(a,b,1,0,T);
int sout(int a,int b,int i,int l,int r){//printf("%d %d %d %d %d\n",a,b,i,l,r);
  if(r<=a||b<=l)return -1;
  if(a<=l&&r<=b)return S[i];
  return hyoka(sout(a,b,i*2,l,(l+r)/2),sout(a,b,i*2+1,(l+r)/2,r));
}
int ta[100010],to[100010],nt[100010],d[100010],r=0,fi[100010],ID[200010];
void ldfs(int s){
  int i;
  fi[s]=r;
  N[r]=d[s];
  ID[r++]=s;
  for(i=ta[s];i+1;i=nt[i]){
    if(d[to[i]])continue;
    d[to[i]]=d[s]+1;
    ldfs(to[i]);
    N[r]=d[s];
    ID[r++]=s;
  }
}
void slca(int p){
  d[p]=1;
  r=0;
  ldfs(p);
  sset(r);
}
int alca(int a,int b){return sout(MIN(fi[a],fi[b]),MAX(fi[a],fi[b])+1,1,0,T);}
int main(){
  int n,m,i,j,e=0;
  scanf("%d",&n);
  for(i=0;i<n;i++)ta[i]=-1;
  for(i=0;i<n;i++){
    scanf("%d",&m);
    while(m--){
      scanf("%d",&j);
      nt[e]=ta[i];
      to[e]=j;
      ta[i]=e++;
    }
  }
  slca(0);//printf("\n");
  //for(i=1;i<2*T;i++)printf("%d %d\n",S[i],N[S[i]]);printf("\n");
  //for(i=0;i<r;i++)printf("%d %d\n",ID[i],N[i]);printf("\n");
  //for(i=0;i<n;i++)printf("%d %d\n",i,fi[i]);printf("\n");
  scanf("%d",&n);//printf("%d\n\n",sout(0,0,1,0,T));
  while(n--){
    scanf("%d %d",&i,&j);
    printf("%d\n",ID[alca(i,j)]);
  }
  return 0;
}

Measured memory_bytes: 10360
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
    int n,m,l;
    cin >> n >> m >> l;
    long long way[n][n];
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            way[i][j] = 2000000000;
            if(i == j){
                way[i][j] = 0;
            }
        }
    }
    for(int i=0;i<m;i++){
        int a,b,c;cin >> a >> b >> c;
        a --;b --;
        if(c <=l){
            way[a][b] = c;
            way[b][a] = c;
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            for(int k=0;k<n;k++){
                way[j][k] = min(way[j][k],way[j][i]+way[i][k]); 
            }
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(way[i][j]<= l){
                way[i][j] = 1;
            }
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            for(int k=0;k<n;k++){
                way[j][k] = min(way[j][k],way[j][i] + way[i][k]);
            }
        }
    }
    int q;cin >> q;
    for(int i=0;i<q;i++){
        int s,t;cin >> s >> t;
        s--;t--;
        if(way[s][t] < 2000000000){
            cout << way[s][t]-1 << endl;
        }
        else{
            cout << "-1" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1280
import scala.collection.mutable.ListBuffer
import scala.io.StdIn
object Main extends App {
  val n = StdIn.readLine().trim.toInt
  
  val result = (0 until n).foldLeft(ListBuffer.empty[String], Set.empty[String]){
    case ((acc, dict), _) =>
    val cmd = StdIn.readLine().split(' ')
    if(cmd(0)(0) == 'i'){
      (acc, dict + cmd(1))
    } else {
      if(dict.contains(cmd(1))) {
        (acc += "yes", dict)
      } else {
        (acc += "no", dict)
      }
    }
  }
  println(result._1.mkString(f"%n"))

}


Measured memory_bytes: 482540
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(300000)


def solve(N: int):
    ret = []
    while N > 0:
        tmp = N % 26
        if tmp > 0:
            ret.append(chr(ord('a') + tmp - 1))
        else:
            ret.append('z')
        N = (N - 1) // 26
    ret.reverse()
    ret = ''.join(ret)
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 61840
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

void main_()
{
    ll N, Y;
    cin >> N >> Y;

    for (ll yen10k = 0; yen10k <= N; yen10k++) {
        for (ll yen5k = 0; yen5k <= N; yen5k++) {
            if (yen10k + yen5k > N) {
                continue;
            }
            auto yen10k_yen5k_total = yen10k * 10000 + yen5k * 5000;
            if (yen10k_yen5k_total > Y) {
                continue;
            }
            auto yen1k = N - (yen10k + yen5k);
            auto total = yen10k_yen5k_total + yen1k * 1000;
            if (total == Y) {
                cout << yen10k << " " << yen5k << " " << yen1k << endl;
                return;
            }
        }
    }

    cout << "-1 -1 -1" << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <cstdio>

using namespace std;

const long long INF = 1000000000000;
const long long MOD = 1000000007;

//書くくらいの輪を返す
long long f(long long N){
  string s = to_string(N);
  long long slen = s.length();
  long long ret=0;
  for (int i = 0; i < slen; i++)
    ret += (s[i] - '0');
  return ret;
}

int main()
{
  long long N;
  cin >> N;
  set<long long>set;
  set.insert(1);
  set.insert(2);
  set.insert(3);
  set.insert(5);
  set.insert(6);
  set.insert(9);
  set.insert(10);
  set.insert(13);
  set.insert(17);

  if(set.find(N)==set.end())
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


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

t = [0]
x = [0]
y = [0]
for i in range(N):
    l = [int(c) for c in input().split()]
    t.append(l[0])
    x.append(l[1])
    y.append(l[2])

for i in range(N):
    move = abs(x[i+1]-x[i]) + abs(y[i+1]-y[i])
    time = t[i+1]-t[i]
    if time%2 ^ move%2 == 1 or time < move:
        print("No")
        exit()

print("Yes")

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

using namespace std; 

#define pb push_back
#define fi first
#define se second
#define all(vec) vec.begin(),vec.end()
#define f(i,a,b) for(int i=a;i<b;i++)
#define fr(i,a,b) for(int i=a;i>=b;i--)
#define fp(i,a,b,p) for(int i=a;i<b;i+=p)
#define SZ(x) (int)x.size()

typedef  vector<string> vs;
typedef  vector<int> vi;
typedef  vector<long long> vl;	



int main(){
		
	string s;
	cin >> s; 
	int con = 0;
	f(i,0,SZ(s)){
		if(s[0]!='A'){
			cout << "WA" << endl;
			return 0;
		}
		if(isupper(s[i])){
			if((s[i]!='A' && s[i]!='C')){
				cout << "WA" << endl;
				return 0;
			}
		}
		
		if(i>=2 && i<=SZ(s)-2 && s[i]=='C'){
			con++;
		}
	}
	if(con==1){
		cout << "AC" << endl;
	}else{
		cout << "WA" << 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;

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

	string S, T; cin >> S >> T;
	int n = S.size();

	vector<char> cntS(26, 0), cntT(26, 0);
	REP(i, n) {
		cntS[S[i]-'a']++;
		cntT[T[i]-'a']++;
		if (cntS[S[i]-'a'] != cntT[T[i]-'a']) {
			cout << "No" << '\n';
			return 0;
		}
	}

	cout << "Yes" << '\n';
	return 0;
}


Measured memory_bytes: 3748
def sort(a, b, c):
    arr = [a, b, c]

    if arr[0] > arr[1]:
        arr[0], arr[1] = arr[1], arr[0]
    if arr[1] > arr[2]:
        arr[1], arr[2] = arr[2], arr[1]
    if arr[0] > arr[1]:
        arr[0], arr[1] = arr[1], arr[0]
    return ' '.join(map(str, arr))


if __name__ == "__main__":
    a, b, c = map(int, input().split())
    print(sort(a, b, c))



Measured memory_bytes: 5600
N, Y = list(map(int, input().split()))

z = Y//1000 - N
flag = False

for m in range(z//9 + 1):
    if (z - 9*m)%4 == 0:
        g = (z - 9*m)//4
        if m + g <= N:
            result = [m, g, N-m-g]
            flag = True
            break
    else:
        pass

if not flag:
    result = [-1, -1, -1]

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

Measured memory_bytes: 3064
#include <stdio.h>

void swap(int *A1, int *A2) {
	int tmp;
	tmp = *A1;
	*A1 = *A2;
	*A2 = tmp;
}

int bubbleSort(int A[], int N) {
	int i, j, sw = 0;
	int flag = 1;
	for (i = 0; flag; i++) {
		flag = 0;
		for (j = N - 1; j >= i + 1; j--) {
			if (A[j] < A[j - 1]) {
				swap(&A[j], &A[j - 1]);
				flag = 1;
				sw++;
			}
		}
	}
	return sw;
}

int main(void) {
	int N;
	int A[100];
	int sw;
	int i;
	
	scanf("%d", &N);
	
	for ( i = 0; i < N; i++ ) {
		scanf("%d", &A[i]);
	}
	
	sw = bubbleSort(A, N);
	
	for ( i = 0; i < N; i++ ) {
		if (i) {
			printf(" ");
		}
		printf("%d", A[i]);
	}
	
	printf("\n");
	printf("%d\n", sw);
	

	return 0;
}

Measured memory_bytes: 604