akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long int
#define __ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pi acos(-1)
using namespace std;


int main ()
{
__

int n;
ll ans=0,cnt=1;

cin >> n;

string s[n],p;

for(int i=0;i<n;i++){
cin >> s[i];
sort(s[i].begin(),s[i].end());
}

sort(s,s+n);

for(int i=1;i<n;i++)
{
if(s[i]==s[i-1]) cnt++;

else {
ans += (cnt * (cnt-1))/2;
cnt=1;
}

if(i==n-1) {
ans += (cnt * (cnt-1))/2;
cnt=1;
}

}

cout << ans ;

return 0;
}


Measured memory_bytes: 5760
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

vector< vs64 > dp(1000, vs64(2001, 0));

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

    int s;
    cin >> s;

    dp[0][0] = 1;
    rep (i, CEIL(s, 3))
    {
        rep (j, s + 1)
        {
            if (j - 3 >= 0)
            {
                dp[i + 1][j] = (dp[i + 1][j - 1] + dp[i][j - 3]) % MOD;
            }
        }
    }

    // rep (i, CEIL(s, 3))
    // {
    //     rep (j, s + 1)
    //     {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << "\n";
    // }

    s64 ans = 0;
    rep (i, 1000)
    {
        ans = (ans + dp[i][s]) % MOD;
    }

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



Measured memory_bytes: 19296
N,M,K = map(int,input().split())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
sum_AB = 0
cnt = 0
idx_A = -1
idx_B = -1
for i,a in enumerate(A):
    if sum_AB + a > K:
        break
    else:
        sum_AB += a
        cnt += 1
        idx_A = i
for i,b in enumerate(B):
    if sum_AB + b > K:
        break
    else:
        sum_AB += b
        cnt += 1
        idx_B = i
ans = cnt
A = A[0:idx_A+1][::-1]
from collections import deque
B = deque(B[idx_B+1:])
for a in A:
    sum_AB -= a
    cnt -= 1
    while B:
        if sum_AB + B[0] > K:
            break
        else:
            b = B.popleft()
            sum_AB += b
            cnt += 1
    ans = max(cnt,ans)
print(ans)

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

int main(void)
{
	//下一桁統一して終わり
	int a[55] = { 2
		,3
		,13
		,23
		,43
		,53
		,73
		,83
		,103
		,163
		,193
		,223
		,233
		,263
		,283
		,293
		,313
		,353
		,373
		,383
		,643
		,983
		,853
		,883
		,743
		,773
		,1193
		,1213
		,1723
		,1613
		,1543
		,1523
		,1663
		,1693
		,1913
		,1933
		,2143
		,2243
		,2153
		,2273
		,2683
		,2593
		,2663
		,2543
		,2633
		,3863
		,3943
		,4133
		,4283
		,4483
		,4733
		,4703
		,4793
		,4903
		,4973
	};
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cout << a[i] << " ";
	}
	cout << endl;
	


	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const unsigned int MOD = 1000000007;
#define ll long long
#define PI 3.1416
string day[]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
vector<string>v;
void dfs(string str,string t="",int cnt=0){
    if(cnt==2){
        v.push_back(t);
        return;
    }else{
        for(int i=0;i<str.size();i++){
            dfs(str,t+str[i],cnt+1);
        }
    }
}
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int a,b,c;
    while(cin>>a>>b>>c){
        cout<<(a*b*c)/(2*max(a,max(b,c)))<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#include<bits/stdc++.h>
using namespace std;
int main (){
    int a,p;
    cin >> a >> p;
    cout <<(int)(a*3+p)/2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/functional/hash.hpp>
//example: unordered_set< pair<int,int>,boost::hash< std::pair<int, int> > > used;
//priority_queue< pair<int,pair<int,int> >, vector<pair<int,pair<int,int>>>, greater<pair<int,pair<int,int> > > > pqueue;    //cost, vertex(行き先)
using namespace std;

#define MODULE 1000000007
#define MP make_pair
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<class T, class U>
inline void chmin(T &t, U f) { if (t > f)t = f; }

template<class T, class U>
inline void chmax(T &t, U f) { if (t < f)t = f; }

template<typename A, size_t N, typename T>
inline void Fill(A (&array)[N], const T &val) { //usage: int dp[10][10]; Fill(dp,INF);
    std::fill((T *) array, (T *) (array + N), val);
}

typedef pair<int, int> P;
typedef long long LL;
const int INF = INT_MAX / 2;    //int_max->2*e+9 LLの時はLLONG_MAX
/*const int MAXN = 100001;

struct edge {
    edge(int to, int cost) : to(to), cost(cost) {}
    int to, cost;
};
vector<edge> graph[MAXN];
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};*/
//-----Template---------
#define V 301

int a[V][V];
int test[V][V];
int n;

LL sumCost=0;

int mincost[V];
bool used[V];


void warshallFloid(){
    for (int k = 0; k < n; ++k)
        for (int i = 0; i < n; ++i)
            for (int j = 0; j < n; ++j)
                test[i][j]=min(test[i][j],test[i][k]+test[k][j]);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false); //cout<< fixed << setprecision(10);
    cin >> n;
    Fill(a, 0);
    Fill(test, 0);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; ++j) {
            cin >>a[i][j];
            sumCost+=a[i][j];
            test[i][j] = a[i][j];
        }
    }

    sumCost/=2;

    warshallFloid();

    bool flag = true;
    for (int i = 0; i < n; ++i) {//2.7*10^6
        for (int j = 0; j < n; ++j) {
            if(a[i][j] != test[i][j]){
                flag=false;
            }

        }
    }

    if(flag){
        for (int i = 0; i < n; ++i) {
            for (int j = i+1; j < n; ++j) {
                for (int k = 0; k < n; ++k) {
                    if( k==i || k==j )continue;

                    if(test[i][j]==(test[i][k]+test[k][j])){
                        sumCost-=test[i][j];
                        break;
                    }
                }
            }
        }
        cout<<sumCost<<endl;
    }else{
        cout<<-1<<endl;
    }


}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
vector<int> A, L;

int lis() {
  L[0] = A[0];
  int length = 1;
  for (int i = 1; i < n; i++) {
    if (L[length - 1] < A[i]) {
      L[length] = A[i];
      length++;
    } else {
      auto iter = lower_bound(L.begin(), L.begin() + length, A[i]);
      L[iter - L.begin()] = A[i];
    }
    // for (int i = 0; i < length; i++) {
    //   cout << L[i] << " ";
    // }
    // cout << "\n";
  }

  return length;
}

int main() {
  cin >> n;
  A.resize(n);
  L.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> A[i];
    A[i] = A[i];
  }
  cout << lis() << "\n";
  return 0;
}


Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <tuple>
#include <utility>
#include <set>
using namespace std;
using LLI = long long int;

int f(int n) {
    return n % 2 == 0 ? n / 2 : 3 * n + 1;
}

int main(int argc, char *argv[])
{
    int s;
    cin >> s;

    set<int> a;
    a.insert(s);
    int m;
    for (int i=2;; i++) {
        s = f(s);
        if (a.find(s) != a.cend()) {
            m = i;
            break;
        }
        a.insert(s);
    }

    cout << m;

    return 0;
}

Measured memory_bytes: 256
use proconio::input;

// use std::cmp::*;
// use std::collections::*;
// use proconio::marker::Chars;

fn main() {
    input! {
        // s: String
        // n: isize
        mut a:i32,
        mut b:i32,
    }
    a = (a - 2 + 26) % 13;
    b = (b - 2 + 26) % 13;
    let ans = if a == b {
        "Draw"
    } else if a > b {
        "Alice"
    } else {
        "Bob"
    };
    println!("{}", ans);
}


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

typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;

#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define ARR(array) for(int i=0;i<array.size();i++)
#define all(in) in.begin(),in.end()
#define ALL(in,K) (in),(in)+(K)

#define INF 1e18
#define MOD 1000000007
#define SIZE 10005
#define PI 	3.14159265358979323846

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a, b)*b; } //最小公倍数

ll input(){
  ll a;
  cin >> a;
  return a;
}

vi sub(vector<bool> fin,ll n) {
  vi ret;
  REP(i,n) {
    if(fin.at(i))continue;
    vector<bool> cp = fin;
    cp.at(i) = true;
    vi result = sub(cp,n);
    ret.insert(ret.end(),result.begin(),result.end());
  }
  return ret;
}

ll pow_kai(ll a, ll n) {//aのn乗を計算します。
  ll x = 1;
  while(n > 0) {
    if(n&1) x = x*a;
    a = a*a;
    n >>= 1;
  }
  return x;
}

int main() {
  vector<vi> a(3, vi(3));
  REP(i,3)REP(j,3) cin >> a.at(i).at(j);
  ll n;
  cin>> n;
  vector<vector<bool>> c(3,vector<bool>(3));
  REP(i,n) {
    ll b;
    cin >> b;
    REP(j,3)REP(k,3)if(!c.at(j).at(k)) c.at(j).at(k) = b==a.at(j).at(k);
  }
  bool ans = true;
  // REP(i,3){
    // REP(j,3)cout << c.at(i).at(j) << " ";
    // cout << endl;
  // }
  REP(i,3){
    ans = true;
    REP(j,3)if(!c.at(i).at(j)) ans = false;
    if(ans){
      cout << "Yes" << endl;
      return 0;
    }
  }
  ans = true;
  REP(j,3){
    ans = true;
    REP(i,3)if(!c.at(i).at(j)) ans = false;
    if(ans){
      cout << "Yes" << endl;
      return 0;
    }
  }
  ans = true;
  REP(i,3)if(!c.at(i).at(i)) ans = false;
  if(ans){
    cout << "Yes" << endl;
    return 0;
  }
  ans = true;
  REP(i,3)if(!c.at(i).at(2-i)) ans = false;
  if(ans){
    cout << "Yes" << endl;
    return 0;
  }
  ans = true;
  REP(i,3)if(!c.at(2-i).at(i)) ans = false;
  if(ans){
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
}

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

inline int read()
{
	int sum=0,ff=1; char ch=getchar();
	while(!isdigit(ch))
	{
		if(ch=='-') ff=-1;
		ch=getchar();
	}
	while(isdigit(ch))
		sum=sum*10+(ch^48),ch=getchar();
	return sum*ff;
}

const int N=2e5+5;

int n,m,ans,a,b,c;

signed main()
{
	a=read();
	b=read();
	c=read();
	if(a==b&&b==c) return printf("No\n"),0;
	if(a!=b&&b!=c&&a!=c) return printf("No\n"),0;
	printf("Yes\n");
}	

Measured memory_bytes: 256
//boom diggy diggy boom boom
/*
freopen("input.txt","r",stdin);
      freopen("output.txt","w",stdout);
      */
#include<bits/stdc++.h>
#define ull unsigned long long int 
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define mod 1000000007
#define F first
#define S second
#define ll long long 
#define ld long double 

int power(int x,int y){int res=1;x=x%mod;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
int ncr(int n,int r){int res=1;if(r>n-r)r=n-r;for(int i=0;i<r;i++){res*=(n-i);res/=(i+1);}return res;}
int gcd(int a,int b){if (a==0)return b;return gcd(b%a,a);}
int lcm(int a,int b){return (a/gcd(a,b)*b);}int max(int a,int b){int ans=a>b?a:b;return ans;}

using namespace std;

int main()
{
  ll n,w;
  cin>>n>>w;
  vector<pair<ll,ll>> v;
  int cnt=0;
  v.pb({0,0});
  for (int i = 1; i <= n; ++i)
      {
        int x,y;
        cin>>x>>y;
        v.pb({y,x});
        cnt+=y;
      }    
      sort(v.begin(),v.end());
      /*for (int i = 0; i < v.size(); ++i)
      {
        cout<<v[i].F<<" "<<v[i].S<<endl;
      }*/
  ll  weight[n+1][cnt+1];
  for (int i = 0; i <= n; ++i)
  {
    for(int j=0 ; j <= cnt ; j++)
      weight[i][j]=0;
  }
  ll ans=0;
  for (int i = 1; i <= n; ++i)
  {
    for (int j = 1; j <= cnt; ++j)
    {
      if(j==v[i].F)
      {
        if(weight[i-1][j]!=0)
          weight[i][j]=min(weight[i-1][j],v[i].S);
        else 
          weight[i][j]=v[i].S;
      }
      else if(v[i].F<j && weight[i-1][j-v[i].F]!=0)
          {
            ll temp;
              temp=v[i].S;
            temp+=weight[i-1][j-v[i].F];
            if(weight[i-1][j]!=0)
              weight[i][j]=min(weight[i-1][j],temp);
            else 
              weight[i][j]=temp;
          }
      else 
        weight[i][j]=weight[i-1][j];
      if(weight[i][j]<=w && weight[i][j]!=0)
        ans=max(ans,j);
    }
  }
  /*for (int i = 0; i <= n; ++i)
  {
    for (int j = 0; j <= cnt; ++j)
    {
      cout<<weight[i][j]<<" ";
    }cout<<endl;
  }*/
cout<<ans;
return 0;
}


Measured memory_bytes: 79104
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define pb push_back
#define pii pair<long long,long long>
#define endl '\n'
void solve()
{
    int n; cin>>n;
    string s; cin>>s; int r=0,g=0,b=0;
    for(int i=0;i<n;i++)
    if(s[i]=='R')
    r++;
    else if(s[i]=='G')
    g++;
    else
    b++;
    int ans=r*g*b;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            int k = 2*j-i;
            if(k>=n)
            continue;
            if(s[i]!=s[j] && s[j]!=s[k] && s[k]!=s[i])
            ans--;
        }
    }
    cout<<ans;
    cout<<endl;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test;test=1;
    while(test--)
    {
        solve();
    }
    return 0;
}

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

using namespace std;


int main(){
	string S;
	cin >> S;
	if( S.length() < 26 ){
		for( auto c = 'a'; c <= 'z'; c++ ){
			bool flag = true;
			for( auto x : S ){
				if( x == c )flag = false;
			}
			if( flag ){
				cout << S << c << endl;
				break;
			}
		}
	} else{
		if( S == "zyxwvutsrqponmlkjihgfedcba" ){
			cout << -1 << endl;
		} else{
			vector<bool>D(26, false);
			for( int i = S.length() - 1; i >= 0; i-- ){
				int memo = -1;
				for( int j = S[i] - 'a'; j < 26; j++ ){
					if( D[j] ){
						memo = j;
						break;
					}
				}
				if( memo != -1 ){
					for( int k = 0; k < i; k++ ){
						cout << S[k];
					}
					cout << (char) ( memo + 'a' ) << endl;
					break;
				}
				D[S[i] - 'a'] = true;
			}
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define ss(x) (int) x.size()
#define fi first
#define se second
#define cat(x) cerr << #x << " = " << x << endl
#define rep(i, j, n) for (int i = j; i <= n; ++i)
#define per(i, j, n) for (int i = n; j <= i; --i)
#define all(x) x.begin(), x.end()
#define ld long double

using namespace std;	

const int N = 888;

int h, w, k;
char s[N][N];

int dr[] = {0, 0, 1, -1};
int dc[] = {1, -1, 0, 0};

bool in(int r, int c) {
	return 1 <= r && r <= h && 1 <= c && c <= w;
}

int dis[N][N];
queue <pair<int, int>> Q;

int main() {
	scanf ("%d%d%d", &h, &w, &k);
	int R, C;
	rep(i, 1, h) {
		scanf ("%s", s[i] + 1);
		rep(j, 1, w)
			if (s[i][j] == 'S') {
				R = i; C = j;
			}
	}
	
	rep(i, 1, h) rep(j, 1, w) dis[i][j] = 1e9;
	dis[R][C] = 0;
	Q.push(mp(R, C));
	
	while (!Q.empty()) {
		int r = Q.front().fi, c = Q.front().se;
		Q.pop();
		rep(i, 0, 3) {
			int nr = r + dr[i];
			int nc = c + dc[i];
			if (in(nr, nc) && s[nr][nc] == '.' && dis[r][c] < k && dis[nr][nc] == 1e9) {
				dis[nr][nc] = dis[r][c] + 1;
				Q.push(mp(nr, nc));
			}
		}
	}
	
	int ans = 1e9;
	rep(i, 1, h)
		rep(j, 1, w)
			if (dis[i][j] <= k)
				ans = min(ans, 1 + (min({i - 1, h - i, j - 1, w - j}) + k - 1) / k);
	printf("%d\n", ans);
	
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int& a : A) cin >> a;
  int ans = 100000000;
  for (int i = -100; i < 101; i++) {
    int target = i, tmp = 0;
    for (int j = 0; j < N; j++) {
      tmp += (A[j] - target) * (A[j] - target);
    }
    ans = min(ans, tmp);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define IOS std::cin.tie(0),std::ios::sync_with_stdio(false)

namespace idaten {

	using namespace std;
	using ll = int_fast64_t;
	using ull = uint_fast64_t;
	using P = std::pair<int64_t, int64_t>;
	template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
	template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
	template<class Type>struct is_vector : std::false_type {};
	template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
	template <typename T> inline std::ostream& operator << (std::ostream& out, const std::vector<T>& v) {
		if (v.empty())return out;
		constexpr bool is_vector_v = is_vector<T>::value;
		if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
		else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
		return out;
	}
	inline void put() {}
	template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
	template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
	inline void putn() {}
	template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

	void solve() {
		IOS;
		ll n,m;
		cin >> n>>m;
		vector<ll> a(m);
		REP(i, m) {
			cin >> a[i];
		}
		ll sum = 0;
		REP(i, m) {
			sum += a[i];
		}
		if (sum > n) {
			put(-1);
		} else {
			put(n - sum);
		}
	}

} // namespace idaten

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


Measured memory_bytes: 3696
#include <iostream>

using namespace std;

int main()
{
        int N, K;
        cin >> N >> K;
        int *d = new int[K];
        int **A = new int*[K];
        for (int i = 0; i < K; i++) {
                cin >> d[i];
                A[i] = new int[d[i]];
                for (int j = 0; j < d[i]; j++) {
                        cin >> A[i][j];
                }
        }

        bool *array = new bool[N];
        for (int i = 0; i < N; i++) {
                array[i] = false;
        }
        for (int i = 0; i < K; i++) {
                for (int j = 0; j < d[i]; j++) {
                        array[A[i][j] - 1] = true;
                }
        }

        int count = 0;
        for (int i = 0; i < N; i++) {
                if (array[i] == false)
                        count++;
        }
        cout << count << endl;

        for (int i = 0; i < K; i++) {
                delete[] A[i];
        }
        delete[] A;
        delete[] d;
        delete[] array;
        return 0;
}

Measured memory_bytes: 3588
/*
　　　∫ ∫ ∫
　　　ノヽ
　　（＿　 ）
　（＿　　　 ）
（＿＿＿＿＿＿ ）
　ヽ(´･ω･)ﾉ　
　　 |　 /
　　 UU
*/
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
using P = pair<ll, ll>;
typedef vector<int> vi;
const int MOD = (int)1e9 + 7;
const ll INF = 1LL << 62;
const int inf = 1<<30;
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; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
#define mp make_pair
template <typename T>
ostream& operator<<(ostream& os, vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, pair<T,T> const&P){
    os << P.first;
    os << " ";
    os << P.second;
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
    auto it=S.begin();
    while(it!=S.end()){
        os << *it;
        os << " ";
        it++;
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
    for(auto it=q.begin();it<q.end();it++){
        os<<*it;
        os<<" ";
    }
     os<<endl;
    return os;
}
vector<pair<int,int>> dxdy = {mp(0,1),mp(1,0),mp(-1,0),mp(0,-1)};
//fixed<<setprecision(10)<<ans<<endl;

//素因数分解
vector<ll> prime_factorization(ll n){
    ll copy = n;
    vector<ll> res;
    for(ll i=2;i*i<=copy;i++){
        if(n%i==0){
            res.push_back(i);
        }
        while(n%i==0){
            n/=i;
        }
    }
    if(n!=1) res.push_back(n);
    return res;
}

int MAX = 55555;
vector<bool> Eratos(2*MAX+2,1);
//エラトステネスの篩
void Eratosthenes(int n){
    for(int i=2;i*i<=n;i++){
        if(Eratos[i]==0) continue;
        for(int j=2*i;j<=n;j+=i){
            Eratos[j]=0;
        }
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    Eratosthenes(MAX);
    vi ans;
    for(int i=2;i<MAX;i++){
        if(!Eratos[i]) continue;
        bool ok = i%5==4; 
        if(ok)ans.emplace_back(i);
        if(ans.size()==N)break;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ii pair<int,int>
#define ll long long

using namespace std;

int main(){
    int n,k,q;cin>>n>>k>>q;
    vector<int>a(100010,0);
    for(int i =0;i<q;i++){
        int x;cin>>x;
        x--;
        a[x]++;
    }
    for(int i =0;i<n;i++){
        if(k-q+a[i]>0){
            cout<<"Yes";
        }
        else{
            cout<<"No";
        }
        cout<<endl;
    }
}

Measured memory_bytes: 1024
import sys
input = sys.stdin.readline


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def main():
    abcd = list(map(int, list(readstr())))
    l = [['+', '+', '+'], ['+', '+', '-'], ['+', '-', '+'], ['+', '-', '-'], ['-', '+', '+'], ['-', '+', '-'], ['-', '-', '+'], ['-', '-', '-']]
    for ll in l:
        ans = abcd[0]
        for i, x in enumerate(ll):
            if x == '+':
                ans += abcd[i + 1]
            else:
                ans -= abcd[i + 1]
        if ans == 7:
            s = ''
            for i in range(3):
                s += str(abcd[i]) + ll[i]
            s += str(abcd[3])
            print(s + '=7')
            break


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
int arr[100005];
int ans[102][102];
int main()
{
  int h,w,n;
    cin>>h>>w>>n;
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    int i=0,j=0;
    int counter=0;
    int op=1;
    int save=0;
    while(true){
        if(arr[counter]==0){
            counter+=1;
        }
         ans[i][j]=counter+1;
         --arr[counter];
         save=i;
         i+=op;
        if(i==h||i==-1){
            j++;
            op=op*-1;
            i=save;
        }
        if(j==w&&((i==h)||(i==0))){
            break;
        }
    }
    for(int k=0;k<h;k++){
        for(int m=0;m<w;m++){
            cout<<ans[k][m]<<" "<<flush;
        }
        cout<<""<<endl;
    }


    return 0;
}


Measured memory_bytes: 384
#include<iostream>

using namespace std;

int main(){
    
    int s;
    
    cin>>s;
    
    int h,m;
    
    h=s/3600;
    m=s%3600/60;
    s=s%3600%60;
    
    cout<<h<<":"<<m<<":"<<s<<endl;
    
    return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
 
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vvvi> vvvvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<vvvll> vvvvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<vvc> vvvc;
typedef vector<pair<long long,long long> > vpll;
typedef vector<vector<pair<ll,ll> > > vvpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
 
#define PI 3.141592653589793
#define MOD 1000000007
 
template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, ll m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }

int main()
{
	IOS;
	string s;
	cin>>s;
	vll f(26,0);
	ll n=s.size();
	ll sum=n;
	for(ll i=0;i<n;i++)
	{
		f[s[i]-'a']++;
	}
	ll ans=0;
	ll st=n;
	for(ll i=0;i<n;i++)
	{
		ans+=st-f[s[i]-'a'];
		f[s[i]-'a']--;
		st--;
	}
	cout<<ans+1;
    return 0;
}

Measured memory_bytes: 720
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdio>
#include <list>
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int 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 vec vector<int>
#define vecll vector<ll>
#define vecstr vector<string>
#define vecch vector<char>
#define vecpii vector<pii>
#define bs binary_search
#define All(c) (c).begin(),(c).end()
using namespace std;
int in(){int x;scanf("%d",&x);return x;}
string stin(){string s;cin>>s;return s;}
ll lin(){ll x;scanf("%lld",&x);return x;}
vector<vector<bool>> done;
int main(){
    string a=stin();
    cout<<"A"<<stin().at(0)<<"C"<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;
const int inf=1<<30;
int main(){
  int a,b,c,k,ans,tmp;cin>>a>>b>>c>>k;
  tmp=max(max(a,b),c);
  for(int i=0;i<k;i++){
    tmp*=2;
  }
  ans=a+b+c+tmp-max(max(a,b),c);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll n;
  cin >> n;
  ll a[n], x[n + 1], sum[n + 1];
  x[0] = sum[0] = 0;
  for(ll i = 0; i < n; i++){
    cin >> a[i];
    x[i + 1] = x[i] ^ a[i];
    sum[i + 1] = sum[i] + a[i];
  }
  ll ans = 0, l = 0, r = 0;
  while(r < n){
    if((x[r + 1] ^ x[l]) == sum[r + 1] - sum[l]){
      r++;
      ans += r - l;
    }else{
      l++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

int main(){
	int n; cin>>n;
	string s; cin>>s;
	int mx=0;
	rep(i,n-1){
		int cnt=0;
		vector<char> a;
		for(int k=0; k<=i; k++){
			a.push_back(s[k]);
		}
		sort(all(a));
		UNIQUE(a);
		
		vector<char> b;
		for(int j=i+1; j<n; j++){
			b.push_back(s[j]);
		}
		sort(all(b));
		UNIQUE(b);
		for(auto x:a){
			for(auto y:b){
				if(x==y) cnt++;
			}
			mx=max(mx,cnt);
		}
	}
	cout<<mx<<endl;
}

Measured memory_bytes: 3640
D, G = gets.split.map(&:to_i)
ps, cs = [], []
D.times do |i|
    ps[i+1], cs[i+1] = gets.split.map(&:to_i)
end
ans = 10**9
(0...(2**D)).each do |bits|
    pt = 0
    num = 0
    (1..D).each do |i|
        if bits[i-1] == 1
            pt += i * 100 * ps[i] + cs[i]
            num += ps[i]
        end
    end
    D.downto(1) do |i|
        break if pt >= G
        next if bits[i-1] == 1
        d = [ps[i], (G-pt-1)/100/i+1].min
        pt += d * i * 100
        num += d
    end
    ans = num if ans > num
end
puts ans

Measured memory_bytes: 3836
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
# define mod 1000000007
# define INF (1 << 29)
# define MAX_N 1000010
/* ちゃんと考えてわかって実装 */

int main(void){
    int n, w;
    cin >> n >> w;
    vector< pair<ll, ll> > prod(n+1);
    for(int i=1; i<=n; i++){
        cin >> prod[i].first >> prod[i].second;
    }
    ll dp[n+1][w+1]; // dp[i][j] = i番目までの品物を選んで重さをj以下にした時の価値の最大値
    for(int i=0; i<=w; i++) dp[0][i] = 0;
    for(int i=0; i<=n; i++) dp[i][0] = 0;
    
    for(int i=1; i<=n; i++){
        for(int j=1; j<=w; j++){
            if(j - prod[i].first >= 0){
                dp[i][j] = max(dp[i-1][j], dp[i-1][j-prod[i].first] + prod[i].second);
            }
            else{
                dp[i][j] = dp[i-1][j];
            }
        }
    }
    cout << dp[n][w] << endl;
    return 0;
}

Measured memory_bytes: 79104
import qualified Data.Set as S

divisors n = dedup ds
  where ds' = (filter ((== 0) . (mod n)) . takeWhile ((<= n) . (^ 2))) [1..n]
        ds = foldl (\acc -> \d -> d:(n `div` d):acc) [] ds'
        dedup as = if a0 == a1 then a0:as' else as
          where a0:a1:as' = as

f n d
    | n `mod` d == 0 = f (n `div` d) d
    | otherwise = n `mod` d == 1

solve n = length ks
  where ks1 = (S.fromList . (filter (f n)) . (filter (/= 1)) . divisors) n
        ks2 = (S.fromList . (filter (/= 1)) . divisors) (n - 1)
        ks = S.union ks1 ks2

main = do
    n <- readLn
    print $ solve n


Measured memory_bytes: 1276
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

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

        int a = Integer.parseInt(scan.next());
        int b = Integer.parseInt(scan.next());
        int coin = 0;
        if(a>b){
          coin += a;
          if(a-1>b){
              coin += (a-1);
          }else{
              coin += b;
          }
        }else if(b>a){
            coin += b;
            if(b-1>a){
                coin += (b-1);
            }else {
                coin += a;
            }
        }else{
            coin = a + b;
        }
        PrintWriter out = new PrintWriter(System.out);
        out.println(coin);
        out.flush();
        scan.close();
    }
}

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  bool check[b] = {};
  int suma = 0;
  for (int i = 0; i < b; i++) {
    suma += a;
    int r = suma % b;
    if (r == c) {
      cout << "YES" << endl;
      return 0;
    }
    else if (check[r]) break;
    check[r] = true;
  }
  cout << "NO" << endl;
}

Measured memory_bytes: 256
//Amumu-style
#include<bits/stdc++.h>
#define ll long long
#define IOSF ios::sync_with_stdio(false)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define ini(a,b) memset(a,b,sizeof(a))
#define ms multiset
#define um unordered_map
using namespace std;
inline __int128 read() {
	__int128 x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') {
		if(ch=='-')
			f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') {
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x*f;
}
inline void print(__int128 x) {
	if(x<0) {
		putchar('-');
		x=-x;
	}
	if(x>9)
		print(x/10);
	putchar(x%10+'0');
}
int main() {
	__int128 x,k,d;
	x=read();
	k=read();
	d=read();
	if(x<0) x=-x;
	if(x>=k*d) print(x-k*d);
	else {
		k-=x/d;
		x-=x/d*d;
		if(k%2==0) print(x);
		if(k%2!=0) {
			__int128 abs1;
			__int128 abs2;
			abs1=x+d;
			abs2=-(x-d);
			if(abs1<abs2) print(abs1);
			else print(abs2);
		}
	}
	return 0;
}
//当年陈刀仔！

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <cmath>
#include <iomanip>
#include <string>
#include <set>

using namespace std;

long long int Assemble(string::iterator b, string::iterator e,int c) {
	long long int s = 0;
	long long int k = *b - '0';
	for (int i = 0; i < e - b - 1; i++) {
		if ((c&(1 << i)) == 0) {
			k *= 10;
			k += *(b + i + 1) - '0';
		}
		else {
			s += k;
			k = *(b + i + 1) - '0';
		}
	}
	s += k;
	return s;
}

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

	int comb = 1 << (S.length() - 1);
	long long int sum = 0;

	set<long long int> a;

	for (int i = 0; i < comb; i++)
		sum += Assemble(S.begin(), S.end(), i);

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <string>
#include <vector>
 
using namespace std;
typedef long long ll;
using gra = vector<vector<ll>>;
using gram = vector<unordered_map<ll,ll>>;
 
typedef unsigned long long ull;
 
template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
 
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <class T> T dup(T a, T b) { return (a + b - 1) / b; }
template <class T> T modpow(T x, T p, T m) { T a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
// template <class T> void prim(T a) { for(ll i=0;i<a.size();++i) { cout << a[i]; } cout << "\n"; }
 
#define mod 1000000007LL
#define INF 10000000000000000LL
 
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
#define rrep(i, n) for (int i = (n - 1); i >= 0; --i)
#define rrep1(i, n) for (int i = n; i > 0; --i)
 
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
//#define modpow(x, p, m) { ll a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
 
#define m0(h) memset(h, 0, sizeof(h))
#define m1(h) memset(h, 1, sizeof(h))
#define m(h, n) memset(h, (n), sizeof(h))
#define all(n) (n).begin(),(n).end()
#define bit(n) (1LL << (n))
#define pb push_back
 
//#ifdef LOCAL
//
//#define dpri(...) fprintf(stderr, __VA_ARGS__)
//#define pria(g) rep(i,g.size()){ cout << i << "{"; rep(j,g[i].size()) cout << g[i][j] << " "; cout << "}" << "\n"; }
//#else
//#define dpri(...) 42
//#define pria(g) 42
//#endif
 
 
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ---------------------
  // コーディング開始
  // ---------------------
  ll n,w;
  cin >> n >> w;
  ll o,v;
  
  // 何個目か何個選んだか重さ
  ll dp[n+1][n+1][3*n];
  m0(dp);
  ll d = INF;
  rep(i,n){
    cin >> o >> v;
    if(d==INF)d=o;
    rep(j,n){
      rep(k,n*3){
        // 選ばなかった場合
        dp[i+1][j][k] = max(dp[i+1][j][k],dp[i][j][k]);
        // 選んだ場合
        if(w>=j*d+k+o)
          dp[i+1][j+1][k+o-d] = max(dp[i+1][j+1][k+o-d],dp[i][j][k]+v);
      }
    } 
  }
  ll ans =0;
  rep(j,n+1)
    rep(k,n*3)
      ans = max(ans,dp[n][j][k]);
  
  pri(ans);
  
  return 0;
}



Measured memory_bytes: 24192
import collections
h, w = map(int, input().split())
queue = collections.deque()
maze = [list(input()) for _ in range(h)]

origin = 0
for i in maze:
    origin += i.count('#')
# print(origin)


def bfs(y, x, cnt):
    if (y < 0 or h <= y or x < 0 or w <= x):
        return
    if (maze[y][x] != '.'):
        return
    maze[y][x] = cnt
    if (y == h - 1 and x == w - 1):
        return cnt
    queue.append([y + 1, x, cnt + 1])
    queue.append([y - 1, x, cnt + 1])
    queue.append([y, x+1, cnt+1])
    queue.append([y, x-1, cnt+1])


queue.append([0, 0, 0])
while (len(queue) > 0):
    l = queue.popleft()
    bfs(l[0], l[1], l[2])
if (maze[h - 1][w - 1] == '.'):
    print(-1)
    exit()

# print(ans)
print(h*w-origin-maze[h-1][w-1]-1)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

int main() {

	int n,m;
	cin>>n>>m;

	ll t=0;
	rep(i,n-1){
		t+=(i+1);
	}
	ll t2=0;
	rep(i,m-1)t2+=(i+1);
	cout<<t+t2<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5+10;
int b[3*maxn];
int head, tail, n;
bool rev;
int main () {
    scanf ("%d", &n);
    head = maxn+1; tail = maxn;
    for (int i = 1; i <= n; i++) {
        int a;
        scanf("%d", &a);
        if (!rev) {
            b[++tail] = a;
        }
        else {
            b[--head] = a;
        }
        rev = !rev;
    }
    if (!rev) {
        for (int i = head; i <= tail; i++) {
            printf ("%d", b[i]);
            if (i != tail) printf (" ");
            else printf ("\n");
        }
    }
    else {
        for (int i = tail; i >= head; i--) {
            printf ("%d", b[i]);
            if (i != head) printf (" ");
            else printf ("\n");
        }
    }
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
constexpr int di[] = { 0, 1, 0, -1 }, dj[] = { 1, 0, -1, 0 };
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(), (v).end()
#define MAX 10000
#define nil -1
#define vmax 10000
#define sentinel 2000000000
constexpr long long int inf = 1000000000000;
constexpr long long int rinf = -(INT64_MAX);
//cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);

int pos,n;
vector<int> pre,in,post;

void rec(int l,int r){
    if(l==r) return;
    int root=pre[pos++];
    int m=distance(in.begin(),find(in.begin(),in.end(),root));
    rec(l,m);
    rec(m+1,r);
    post.push_back(root);
}

void solve(){
    pos=0;
    rec(0,n);
    rep(i,n){
        if(i){
            cout<<" ";
        }
        cout<<post[i];
    }
    cout<<endl;
}

int main() {
    int k;
    cin>>n;
    rep(i,n){
        cin>>k;
        pre.push_back(k);
    }
    rep(i,n){
        cin>>k;
        in.push_back(k);
    }

    solve();
    
    return 0;
}






Measured memory_bytes: 3140
#include <iostream>
#include <string>
using namespace std;
 
int main(){
  string S;
  string T;
  cin >> S;
  cin >> T;
  int i=0;
  int count=0;
  while(S[i]!='\0'){
    if(S[i]!=T[i]){
      count++;
    }
    i++;
  }
  cout << count << endl;
  return 0;
}

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

int main(){
    int x,y,z;
    cin >> x >> y >> z;
    cout << z << " " << x << " " << y << endl;
    return 0;
}

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

using namespace std;

#define PB push_back
#define f first
#define s second
#define what_is(x) cerr << #x << " is " << x << endl;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int a, b;
    cin >> a >> b;
    cout << a*b;
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
const ll INF = 1LL<<60;

const int mod = 1000003;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  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;
  }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    vector<mint> prod(mod);//, prodinv(mod);
    prod[0]=1;
    //prodinv[mod-1]=-1;
    rep2(i,1,mod)prod[i]=prod[i-1]*i;
    //rep2(i,1,mod)prodinv[mod-i-1]=mint(mod-i)*prodinv[mod-i];
    //rep2(i,0,mod)prodinv[i]=prod[i].inv();
    ll q;cin>>q;
    rep(i,q){
        ll x,d,n;cin>>x>>d>>n;
        mint mx=mint(x),md=mint(d);
        if(d==0){cout<<mx.pow(n).x<<endl;continue;}
        mint aa = md.inv();
        mint l = mx*aa;
        mint r = (mx+md*(n-1))*aa;
        if(n>=mod||r.x<l.x){cout<<0<<endl;continue;}
        cout<<(prod[r.x]/prod[l.x-1]*md.pow(n)).x<<endl;

    }
    return 0;
}

Measured memory_bytes: 8704
import java.util.*;
import java.io.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int q = sc.nextInt();
		int[] arr = new int[n];
		Arrays.fill(arr, k-q);
		for(int i = 0; i < q; i++) {
			arr[sc.nextInt()-1]++;
		}
		for(int i = 0; i < n; i++) {
			if(arr[i] > 0) {
				System.out.println("Yes");
			}
			else {
				System.out.println("No");
			}
		}
	}

}


Measured memory_bytes: 67116
#include <iostream>
    using namespace std;
    int main(void){
        // Your code here!
        int n,x;
        
        cin>>n>>x;
        
        int L[n];
        int sum=0;
        int i;
        int ans=1;
        
        for(i=0; i<n; i++){
            cin>>L[i];
            sum=sum+L[i];
            if(sum<=x){
                ans++;
            }
        }
            cout<<ans;
    }

Measured memory_bytes: 256
// A

#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};

int main(){
  int N,A,B,C,D;
  string s;
  cin>>N>>A>>B>>C>>D;
  cin>>s;
  for (int i(A);i<=max(C,D);i++){
    if (s[i-1] == '#' && s[i] == '#' && s[i+1] == '#'){
      cout << "No" << endl;
      return 0;
    }
  }
  if (C<D){ //交わらない時
    cout << "Yes" << endl;
    return 0;
  }else{
    int migi = D-1,hidari = B-1;
    for (int i(hidari-1);i<=migi-1;i++){
      if (s[i] == '.' && s[i+1] == '.' && s[i+2] == '.'){
        cout << "Yes" << endl;
        return 0;
      }
    }
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(void){
 double w;
  while(cin >> w){
    string s;
   if(w <= 48.0) s="light fly";
   else if(w <= 51.0) s = "fly";
   else if(w <= 54.0) s = "bantam";
   else if(w <= 57.0) s = "feather";
   else if(w <= 60.0) s = "light";
   else if(w <= 64.0) s = "light welter";
   else if(w <= 69.0) s = "welter";
   else if(w <= 75.0) s = "light middle";
   else if(w <= 81.0) s = "middle";
   else if(w <= 91.0) s = "light heavy";
   else  s = "heavy";
   cout<<s<<endl;
   }
   return 0;
 }


Measured memory_bytes: 3128
#include <stdio.h>
#include <math.h>
  
int isprime(int);
  
main(){
  
  int n,res=0;
  int i;
  int A[10000];
    
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  for(i=0;i<n;i++){
    if(isprime(A[i])==0) res++;
  }
  
  
  printf("%d\n",res);
  
  return 0;
}
  
  
  
int isprime(int x)
{
  int i;
  
  if(x==2) return 0;
  
  if(x<2 || x%2==0) return 1;
  
  
  i=3;
  while(i<=sqrt(x)){
    if(x%i==0) return 1;
    i+=2;
  }
  return 0;
 }


Measured memory_bytes: 2100
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define all(a)          (a).begin(), (a).end()
#define sort(a)         sort(all(a))
#define uniq(a)         sort(a);(a).erase(unique(all(a)), (a).end())
#define reverse(a)      reverse(all(a))
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }
#define pb              push_back
#define fst             first
#define int             long long
#define INF             __LONG_LONG_MAX__

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve() {
  ll X, Y, Z; cin >> X >> Y >> Z;
  swap(X, Y);
  swap(X, Z);
  cout << X << " " << Y << " " << Z << endl;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 888
#include <stdio.h>

int main(){
    int x,y,tmp = 0;

    scanf("%d%d",&x,&y);
    while(1){
        if((x%y)==0){
            break;
        }
        else{
            tmp = y;
            y = x%y;
            x = tmp;
        }
    }
    printf("%d\n",y);
    return 0;
}


Measured memory_bytes: 2084