akhauriyash/Code-Regression huggingface dataset:
/*
計算機
*/

#include<stdio.h>
int main(void){
  int a,b,c;
  char op;/*演算子*/

  do{
    scanf("%d %c %d",&a,&op,&b);
    if(c != '?'){
      switch(op){
      case '+':
	c = a+b;
	printf("%d\n",c);
	break;
      case '-':
	c = a-b;
	printf("%d\n",c);
	break;
      case '*':
	c = a*b;
	printf("%d\n",c);
	break;
      case '/':
	c = a/b;
	printf("%d\n",c);
	break;
      }
    }
  }while(op != '?');
  return 0;
}


Measured memory_bytes: 2040
n,q=map(int,input().split())
s=input()

ac=[0]*n
for i in range(n-1):
    ac[i+1]=ac[i]
    if s[i]=="A" and s[i+1]=="C":
        ac[i+1]+=1


lr=[]
for i in range(q):
    lr.append(list(map(int,input().split())))

for i in range(q):
    print(ac[lr[i][1]-1]-ac[lr[i][0]-1])


Measured memory_bytes: 30624
#include <iostream>

int main(void)
{
  int N;
  char c;
  char typeFlag[4] = {0};

  std::cin >> N;
  for(int i = 0; i < N; i++){
    std::cin >> c;
    if(c == 'P')
      typeFlag[0] = 1;
    else if(c == 'W')
      typeFlag[1] = 1;
    else if(c == 'G')
      typeFlag[2] = 1;
    else if(c == 'Y')
      typeFlag[3] = 1;
  }
  int typeNum = 0;
  for(int i = 0; i < 4; i++){
    typeNum += typeFlag[i];
  }

  if(typeNum == 3){
    std::cout << "Three" << std::endl;
  }else{
    std::cout << "Four" << std::endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
#define rep(i,n) for(ll i=0;i<n;++i)
#define ALL(x) x.begin(),x.end()

using namespace std;
typedef long long ll;

template<typename T>
T gcd(T a, T b) {
	if (a % b == 0) {
		return(b);
	}
	else {
		return(gcd(b, a % b));
	}
}

template<typename T>
T lcm(T a, T b) {
	return a / gcd(a, b) * b;
}

int main(void) {
	double a, b, h, m;
	cin >> a >> b >> h >> m;
	double arc_h, arc_m;
	arc_h = h * 30 + m / 2;
	arc_m = m * 6;
	double Arc = min(arc_h - arc_m, 360 - (arc_h - arc_m));
	cout << std::setprecision(20) <<sqrt(a * a + b * b - 2 * a * b * cos(Arc*acos(-1)/180));
	//cout << arc_h << endl << arc_m;
}

/*

*/


Measured memory_bytes: 4280
#include<cstdio>
#include<algorithm>
#include<functional>
long long s[100001],s_rev[100001],t[100001],t_rev[100001];
int main(){
    int a,b,q;
    scanf("%d%d%d",&a,&b,&q);
    for(int i=0;i<a;i++){
        scanf("%lld",&s[i]);
        s_rev[a-1-i]=s[i];
    }
    for(int i=0;i<b;i++){
        scanf("%lld",&t[i]);
        t_rev[b-1-i]=t[i];
    }
    for(int i=0;i<q;i++){
        long long x;
        scanf("%lld",&x);
        auto la=std::lower_bound(s_rev,s_rev+a,x,std::greater<long long>());
        auto ra=std::lower_bound(s,s+a,x);
        auto lb=std::lower_bound(t_rev,t_rev+b,x,std::greater<long long>());
        auto rb=std::lower_bound(t,t+b,x);
        long long la_x=(la<s_rev||s_rev+a<=la)?1e15:(x-*la), ra_x=(ra<s||s+a<=ra)?1e15:(*ra-x),
                  lb_x=(lb<t_rev||t_rev+b<=lb)?1e15:(x-*lb), rb_x=(rb<t||t+b<=rb)?1e15:(*rb-x);
        long long ans_l=std::max(la_x,lb_x), ans_r=std::max(ra_x,rb_x),
                  ans_m1=std::min(la_x,ra_x), ans_m2=std::min(lb_x,rb_x),
                  ans_m=std::min(ans_m1,ans_m2)+ans_m1+ans_m2;
        printf("%lld\n",std::min(ans_l,std::min(ans_r,ans_m)));
    }
    return 0;
}

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

from collections import Counter
C=Counter(A)
ANS=0
for i in C.values():
    ANS+=i*(i-1)//2

for a in A:
    k=C[a]

    print(ANS-(k*(k-1)//2)+((k-1)*(k-2)//2))


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

#define REP(i, s,  n) for(int i = s;i < (n);i++)
#define VSORT(v) sort(v.begin(), v.end());
#define int64 long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> PP;

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

//---------------------------------------------------------------
//---------------------------------------------------------------

int N, Y;

signed main(){
	cin >> N >> Y;
	
	int wk, j, k, s, m;
	if(Y <= (10000 * 2000) && Y % 1000 == 0) {
		REP(i, 0, (N+1)) {                          		// 千円
			wk = Y - i * 1000;
			if(wk % 5000 != 0)			continue;			// 5000 の倍数しか作れない
			if(wk > (N - i) * 10000)	continue;			// 残り全部一万円より大きくはならない
			s = (wk % 10000) / 5000;						// 端数の五千円の枚数(0/1)
			m = wk / 10000;									// 残り全部一万円の場合の枚数

			// 残っている枚数(N - i)から五千円の端数(s)を引く　→　使える枚数
			// 使える枚数から一万円だけで払った場合の枚数(m)を引く　→　この差が足りない枚数
			// 足りない枚数が１なら、一万円１枚を五千円２枚に変える　→　１枚増えて枚数が一致する
			j = m - (N - i - s - m);						// 一万円
			k = N - i - j;                          		// 五千円
			if(j >= 0 && k >= 0 && (Y == (i * 1000 + j * 10000 + k * 5000))) {
				cout << j << " " << k << " " << i << endl;;
				return 0;
			}
		}
	}
	cout << "-1 -1 -1" << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
using namespace std;
long long int num[10000005],d[10000005];//num´æÔ¼Êý¸öÊý£¬d´æÒ»¸öÊý×îÐ¡ÖÊÒò×ÓµÄ¸öÊý
int vis[10000005];
long long int prime[10000005];
void fun(int n)
{
	memset(vis,0,sizeof(vis));
	num[1]=1;
	d[1]=1;
	prime[0]=0;
	for(int i=2;i<=n;i++)
	{
		if(!vis[i])
		{
			prime[++prime[0]]=i;
			d[i]=1;
			num[i]=2;
		}
		for(int j=1;j<=prime[0]&&i<=n/prime[j];j++)
		{
			vis[i*prime[j]]=1;
			if(i%prime[j]==0)
			{
				d[i*prime[j]]=d[i]+1;
				num[i*prime[j]]=num[i]/(d[i]+1)*(d[i]+2);
				break;
			}
			d[i*prime[j]]=1;
			num[i*prime[j]]=num[i]*2;
		}
	}
}
long long int ans=0;
int n; 
int main(){
//memset(u,0,sizeof(u));
memset(num,0,sizeof(num));
memset(d,0,sizeof(d));
scanf("%d",&n);
fun(n);
for(int i=1;i<=n;i++)
ans+=i*num[i];
printf("%lld",ans);
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define faster  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define sq(x)   (x)*(x)
#define PI      acos(-1.0)
#define all(x) x.begin(),x.end()
#define nl      '\n'

typedef long long int ll;
typedef unsigned long long int  llu;


int main()
{
	faster
	int a,b,c,ans;
	cin>>a>>b>>c;
	if(a%b==0)ans=a/b;
	else ans=a/b+1;
	cout<<ans*c<<nl;
	return 0;

}


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

ll inf =1e9+7;

#define pi 3.14159265358979323846L
bool isprime(ll a)
{
	
	ll cnt=0;	
	for(ll i=1;i*i<a;i++)
	{
		
	 	if(a%i==0)
	 	{
	 		cnt+=2;
		 }
		
		
	}
	
		if(cnt==2)
		return true;
		else
		return false;
		
}
ll mod(ll a)
{
	if(a<inf)return a;
	else
	return a%inf;
}
void solve()
{
ll a,b,n;
cin>>a>>b>>n;
ll ans;

ans=(a*min(b-1,n))/b;	


cout<<ans;
}

int main()
{


ios::sync_with_stdio(0); 
	cin.tie(0);

		solve();
	
return 0;

		
	}
	
	
	


Measured memory_bytes: 3600
#include <bits/stdc++.h>
 
using std::pair;
using std::vector;
using std::string;

typedef long long ll;
typedef pair<int, int> pii;
 
#define fst first
#define snd second
#define pb(a) push_back(a)
#define mp(a, b) std::make_pair(a, b)
#define debug(...) fprintf(stderr, __VA_ARGS__)
 
template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }
 
const int oo = 0x3f3f3f3f;
 
template<typename T> T read(T& x) {
    int f = 1; x = 0;
    char ch = getchar();
    for(;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48; 
    return x *= f;
}

const int N = 6;
const int C = 50;

int n, c;
int l[N + 5];
ll dp[N * (C + 5)][(1 << N) + 5], ans, tot;

ll calc() {
    memset(dp, 0, sizeof dp);

    dp[0][0] = 1;
    for(int i = 0; i < (n+1) * c; ++i) {
        int t = i % (n+1) - 1;
        if(t < 0) continue;

        for(int j = 0; j < i; ++j) {
            for(int k = 0; k < (1 << n); ++k) if(!(k >> t & 1)) {

                if(i - (n+1) * l[t] <= j) 
                    dp[i][k | (1 << t)] += dp[j][k];
                else 
                    dp[j][k | (1 << t)] += dp[j][k];
            }
        }
    }

    ll res = 0;
    for(int i = (c-l[n]) * (n+1); i < (n+1) * c; ++i) {
        ans += dp[i][(1 << n) - 1];
    }
    return res;
}

int main() {
#ifdef Wearry
    freopen("in", "r", stdin);
    // freopen("out", "w", stdout);
#endif 

    read(n), read(c);
    for(int i = 0; i < n; ++i) { read(l[i]); }
    std::sort(l, l + n);

    n--;
    do {
        ++ tot;
        ans += calc();
    } while(std::next_permutation(l, l + n));

    for(int i = 0; i < n; ++i) tot *= c;
    printf("%.15lf\n", (double) ans / tot);

    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
//#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <climits>

using namespace std;

int main(int **argc) {

	int n;
	cin >> n;

	int mn = INT_MAX;
	int mx = -1;
	int diffMax = INT_MIN;
	for (int i = 0;i<n;i++) {
		int tmp;
		cin >> tmp;
		diffMax = max(tmp - mn, diffMax);
		mn = min(mn, tmp);
	}

	cout << diffMax << endl;
	return 0;
}

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

struct Node{
    ll key;
    Node *parent, *left, *right;
};
Node *root;

void insert(ll k){
    Node *x = root;
    Node *y = nullptr;
    Node *z;
    z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = nullptr;
    z->right = nullptr;

    while(x != nullptr){
        y = x;
        if(z->key < x->key) x = x->left;
        else x = x->right;
    }

    z->parent = y;
    if(y == nullptr) root = z;
    else if(z->key < y->key) y->left = z;
    else y->right = z;
    return;
}

void inorder(Node* n){
    if(n == nullptr) return;
    inorder(n->left);
    cout << ' ' << n->key;
    inorder(n->right);
    return;
}

void preorder(Node* n){
    if(n == nullptr) return;
    cout << ' ' << n->key;
    preorder(n->left);
    preorder(n->right);
    return;
}

int main(){
    ll n; cin >> n;
    rep(i, 0, n){
        string com; cin >> com;
        if(com[0] == 'i'){
            ll k; cin >> k;
            insert(k);
        } else {
            inorder(root);
            cout << endl;
            preorder(root);
            cout << endl;
        };
    }
    return 0;
}


Measured memory_bytes: 26608
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  int n; rd(n);

  auto a=new long[](n+1);
  for(int i=1; i<=n; i++){
    int q=i;
    for(int j=2; j<=i; j++){
      while(q>1 && q%j==0){
        q/=j;
        a[j]++;
      }
    }
  }

  // writeln(a);

  const long mod=1_000_000_000+7;
  auto ret=reduce!((r, e)=>(r*(e+1)%mod))(1L, a);
  writeln(ret);
}

void rd(Type...)(ref Type x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x) e=l[i].to!(typeof(e));
}

Measured memory_bytes: 256
a, b, c = map(int, input().split())
ans = 0
if b < c:
    ans += 2 * b
    c -= b
    if c > a:
        ans += a + 1
    elif c == a:
        ans += c
    else:
        ans += c

else:
    ans = ans + b + c

print(ans)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define int long
struct edge{int a,b,c;};
main(){
  int n,m,r;
  cin>>n>>m;
  vector<edge> e(m);
  vector<int> d(n,-1e18),nc(n,0);
  for(int i=0;i<m;++i){
    cin>>e[i].a>>e[i].b>>e[i].c;
    --e[i].a;--e[i].b;
  }
  d[0]=0;
  for(int i=0;i<2*n-1;++i)for(int j=0;j<m;++j){
    if(d[e[j].a]+e[j].c>d[e[j].b]){
      if(i>n-2)nc[e[j].b]=1;
      d[e[j].b]=d[e[j].a]+e[j].c;
    }
    nc[e[j].b]|=nc[e[j].a];
    if(i==n-2)r=d[n-1];
  }
  if(nc[n-1])cout<<"inf";
  else cout<<r;
}

Measured memory_bytes: 256
#入力
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = input()

k_list = ['']*k
for i in range(n):
  if len(k_list[i%k]) == 0:
    k_list[i%k] += t[i]  
  elif k_list[i%k][-1] == t[i]:
    k_list[i%k] += 'z'
  else:
    k_list[i%k] += t[i]
ans = 0
for h in k_list:
  ans += p*h.count('r')+r*h.count('s')+s*h.count('p')
print(ans)

Measured memory_bytes: 6132
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define im imag()
#define re real()
#define r(I, N) for(int I=0;I<N;I++)
#define f(I, A, B) for(int I=A;I<B;I++)
#define fd(I, A, B) for(int I=A;I>=B;I--)
#define ite(x) for(__typeof((x).begin()) it=(x).begin();it!=(x).end();it++)
#define sz(x) ((int)(x).size())
#define clr(x) memset(x, 0, sizeof(x))

typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
typedef complex<ld> Point;
typedef Point Vector;

const ld pi = acos(-1.0);
const ld eps = 1e-12;

int l1, l2;
char s[123];
ll num[123], ans;
bool f1 = true, f2 = true;
string buf;

void parse(string u)
{
      int pt;
      r(i, u.length())
      {
            if(u[i] >= '0' && u[i] <= '9')
            {

                  pt = i;
                  while(u[pt] >= '0' && u[pt] <= '9' && pt < u.length())
                  {
                        pt++;
                  }
                  ll tmp = 0;
                  f(j, i, pt) tmp *= 10, tmp += u[j] - '0';
                  num[l2++] = tmp;i = pt - 1;
            }
            else
            {
                  s[l1++] = u[i];
            }
      }
}


int main()
{
      cin >> buf >> ans;
      parse(buf);
      /// lr Case 1
      ll a1 = num[0];
      r(i, l1)
      {
            if(s[i] == '+')
            {
                  a1 += num[i + 1];
            }
            else
            {
                  a1 *= num[i + 1];
            }
      }
      if(a1 != ans) f1 = false;

      /// mf Case 2
      ll a2 = num[0];
      ll t = 0;
      r(i, l1)
      {
            if(s[i] == '*')
            {
                  a2 *= num[i + 1];
            }
            else
            {
                  t += a2;
                  a2 = num[i + 1];
            }
      }
      t += a2;
      if(t != ans) f2 = false;
      if(f1 && f2) cout << "U" << endl;
      else if(f1 && !f2) cout << "L" << endl;
      else if(!f1 && f2) cout << "M" << endl;
      else cout << "I" << endl;
      return 0;
}

Measured memory_bytes: 1204
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
using ll = long long;
using P = pair<int, int>;
static const ll nmax = 1000000010;

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];

    map<ll, int> dic;
    ll ans = 0;
    for (int i = 0; i < n; ++i)
    {
        ++dic[a[i]];
        if (dic[a[i]] == 1)
        {
            ++ans;
        }
        else
        {
            dic[a[i]] = 0;
            --ans;
        }
        
    }

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


Measured memory_bytes: 10340
#include <bits/stdc++.h>
using namespace std;
int main () {
  string s="aeiou";
  char c;
  cin>>c;
  for (int i=0;i<5;i++) {
    if (c==s.at(i)) {
      cout<<"vowel"<<endl;
      break;
    }
      if (i==4)
        cout<<"consonant"<<endl;
  }
}

Measured memory_bytes: 3604
k, x = gets.split.map(&:to_i)
min_c = -1000000
max_c = 1000000

min_c = [min_c, x - (k - 1)].max
max_c = [max_c, x + (k - 1)].min
puts (min_c..max_c).to_a.join(' ')


Measured memory_bytes: 1916
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

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

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

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

def RS():
    return list(input().split())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input().split()) for _ in range(n) ]

n = I()
a = RI()
q = I()
bc = LI(q)

s = sum(a)

d = defaultdict(int)
for i in range(n):
    d[ a[i] ] += 1
# print(d)   

for i in range(q):
    b = bc[i][0]
    c = bc[i][1]
    s += (c-b)*d[b]
    d[c] += d[b]
    d[b] = 0
    # print(d)
    print(s)

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

using namespace std;
#define int64 long long

const int nMax = 1010;

int64 A[nMax], B[nMax], C[nMax], S[nMax];
int n, m;
int nTest;

void outerInit()
{
    if (ifstream("test.inp")) freopen("test.inp", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << setprecision(9) << fixed;
}

void enter()
{
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) cin >> A[i] >> B[i] >> C[i];
}

void init()
{
}

void solve()
{
    int64 res = 0;
    for (int ma = -1; ma <= 1; ++ma)
    for (int mb = -1; mb <= 1; ++mb)
    for (int mc = -1; mc <= 1; ++mc)
    if (ma && mb && mc)
    {
        for (int i = 1; i <= n; ++i)
            S[i] = ma * A[i] + mb * B[i] + mc * C[i];
        sort(S + 1, S + n + 1, greater<int64>());

        int64 s = 0;
        for (int i = 1; i <= m; ++i) s += S[i];
        res = max(res, s);
    }

    cout << res;
}

int main()
{
    outerInit();

    nTest = 1;
    // cin >> nTest;
    for (int i = 1; i <= nTest; ++i)
    {
        if (i > 1) cout << "\n";
        enter();
        init();
        solve();
    }
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int R = sc.nextInt();
    int ans = 0;
    if(N>=10){
      ans = R;
    }else{
      ans = R+100*(10-N);
    }
    System.out.println(ans);
  }
}
      

Measured memory_bytes: 35892
#import numpy as np
import sys
from collections import defaultdict
read = sys.stdin.buffer.read
readline = sys.stdin.readline
readlines = sys.stdin.buffer.readlines

N , M = map(int,input().split())
data = []
[data.append(list(map(int,input().split()))) for _ in range(M)]
P = list(map(int,readline().rstrip().split()))

ans = 0
for x in range(2 ** N):
    bi = bin(x)[2::][::-1]
    on = [0] * N
    flag = 1
    for index , b in enumerate(bi) :
        if b == "1":
            on[index] = 1
    for index , d in enumerate(data) :
        num_sw = 0
        for s in d[1::]:
            num_sw += on[s-1]
        if P[index] != (num_sw % 2):
            flag = 0
            break
    if flag == 1 :
        ans += 1

print(ans)

Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>
#include <string>
#include <stack>
#include <regex>
 
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
 
using namespace std;
 
typedef long long ll;

int n,m;

int main(int argc, char const *argv[])
{
  cin >> n >> m;
  vector<bool> res(m,true);
  REP(i,n) {
    vector<bool> tmp(m,false);
    int k;
    cin >> k;
    REP(j,k){
      int a;
      cin >> a;
      tmp[a-1] = true;
    }
    REP(j,m){
      res[j] = res[j] && tmp[j];
    }
  }
  int cnt = 0;
  REP(i,m){
    if (res[i])cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
from itertools import accumulate

n = int(input())
s = input()

left_w = [0]
for c in s:
    if c == 'W':
        left_w.append(1)
    else:
        left_w.append(0)
left_w = list(accumulate(left_w))

right_r = [0]
for c in s[::-1]:
    if c == 'R':
        right_r.append(1)
    else:
        right_r.append(0)
right_r = list(accumulate(right_r))
right_r.reverse()

print(min(map(max, zip(left_w, right_r))))


Measured memory_bytes: 26724
#include<iostream>
#include<string>
#include <vector>
#include<queue>
#include<map>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<bitset>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define vsort(v) sort(v.begin(), v.end())
#define rv(v) reverse(v.begin(), v.end())
#define ll long long
using vll = vector<ll>;
using Graph = vii;
const ll MOD = 1e9 + 7;

string divide[4] = { "dream","dreamer","erase","eraser" };

int main() {
	string s;
	cin >> s;
	rv(s);
	rep(i, 4) {
		rv(divide[i]);
	}
	bool flag = true;
	for (int i = 0; i < s.size();) {
		bool flag2 = false;
		for (int j = 0; j < 4; j++) {
			string d = divide[j];
			if (s.substr(i, d.size()) == d) {
				flag2 = true;
				i += d.size();
			}
		}
		if (!flag2) {
			flag = false;
			break;
		}
	}
	if (flag) cout << "YES" << endl;
	else cout << "NO" << endl;
}


Measured memory_bytes: 512
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
//#include <conio.h>
using namespace std;

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

#define rep(i,n)	for(ll i=0;i<(n);i++)
#define SZ(x) ((ll)x.size())
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define F first
#define S second
#define int ll
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll MOD = INT_MAX;
const double PI = acos(-1);

void openfile(){
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
}

signed main(){
	IOS
	int n,a,b;	cin >> n >> a >> b;
	cout << n/(a+b) * a + min(a,n-n/(a+b)*(a+b)) << endl;
}


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

typedef long long ll;
using namespace std;

int main(void) {
   ll N;
   cin>>N;
   ll A[N];
   rep(i,N) cin>>A[i];
   double ans = 0.;
   rep(i,N) ans += 1./(double)A[i];
   ans = 1./ans;
   cout<<ans<<endl;

   return 0;
}

Measured memory_bytes: 256
def binary_patterns(size, patterns = [[true], [false]])
	return patterns if patterns[0].size == size
	ret = []
	patterns.each {|pattern|
		ret += binary_patterns(size, [pattern + [true]])
		ret += binary_patterns(size, [pattern + [false]])
	}
	ret
end

lines = $stdin.read.lines.map(&:chomp)
H, W, K = lines.shift.split(' ').map(&:to_i)
c = lines.map {|line| line.split(//) }
black = c.flatten.find_all {|x| x == '#' }.size

row_patterns = binary_patterns(H)
col_patterns = binary_patterns(W)

total = 0
row_patterns.each {|row|
	col_patterns.each {|col|
		red = 0
		0.upto(H - 1) {|i|
			0.upto(W - 1) {|j|
				red += 1 if (c[i][j] == '#') and (row[i] or col[j])
			}
		}
		total += 1 if black - red == K
	}
}
puts total


Measured memory_bytes: 14364
# -*- coding: utf-8 -*-
from collections import Counter
n = int(input())
v = [int(i) for i in input().split()] 

a1 = [0 for _ in range(n // 2)]
a2 = [0 for _ in range(n // 2)]
for i in range(n):
    if i % 2 == 0:
        a1[i // 2] = v[i]
    elif i % 2 == 1:
        a2[i // 2] = v[i]
#print(a1)
#print(a2)
tmp_a1 = Counter(a1)
tmp_a2 = Counter(a2)
#print(tmp_a1.most_common()[0][1] , tmp_a2.most_common()[0][1])
if tmp_a1.most_common()[0][0] == tmp_a2.most_common()[0][0] and len(tmp_a1.most_common()) > 1 and len(tmp_a2.most_common()) > 1:
    ans = min(n - tmp_a1.most_common()[0][1] - tmp_a2.most_common()[1][1], n - tmp_a2.most_common()[0][1] - tmp_a1.most_common()[1][1])
elif tmp_a1.most_common()[0][0] == tmp_a2.most_common()[0][0] and len(tmp_a1.most_common()) == 1 and len(tmp_a2.most_common()) > 1:
    ans = n // 2 - tmp_a2.most_common()[1][1]
elif tmp_a1.most_common()[0][0] == tmp_a2.most_common()[0][0] and len(tmp_a1.most_common()) > 1 and len(tmp_a2.most_common()) == 1:
    ans = n // 2 - tmp_a1.most_common()[1][1]
elif tmp_a1.most_common()[0][0] == tmp_a2.most_common()[0][0] and len(tmp_a1.most_common()) == 1 and len(tmp_a2.most_common()) == 1:
    ans = n // 2
else:
    ans = n - (tmp_a1.most_common()[0][1] + tmp_a2.most_common()[0][1])
print(ans)


Measured memory_bytes: 19040
#include<cstdio>
int a[5]={-1,-1,-1,-1,-1};
int main(void)
{
    int n,m,s,c;
    scanf("%d %d" ,&n,&m);

    for(int i=1;i<=m;i++)
    {
        scanf("%d %d" ,&s,&c);
        if(a[s]==-1)
        {
            if(n!=1 && s==1 && c==0)
            {
                printf("-1");
                return 0;
            }
            a[s]=c;
        }
        else
            if(a[s]!=c)
            {
                printf("-1");
                return 0;
            }
    }
    for(int i=1;i<=n;i++)
        if(a[i]==-1)
        {
            if(i==1 && n!=1) a[i]=1;
            else a[i]=0;
        }
    for(int i=1;i<=n;i++)
        printf("%d" ,a[i]);
    return 0;
}


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

int main(void){
    int N;
    cin >> N;
    int mochi[N];
    int dan[N];
    int check = 0;
    int count = 0;
    int i, j;

    for(i = 0; i < N; i++){
        cin >> mochi[i];
        for(j = 0; j < check; j++){
            if(mochi[i] != dan[j])
                count++;
        }
        if(count == check){
            dan[check] = mochi[i];
            check++;
        }
        count = 0;
    }

    cout << check << endl;
    return 0;
}

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

int main(){	
	int N,X;cin>>N>>X;
  	int m,sum=0,minv;
  	cin>>m;sum+=m;minv=m;
	for(int i=1;i<N;++i){
      cin>>m;
  	  sum+=m;
      minv=min(minv,m);
    }X-=sum;
  	N+=X/minv;
  	cout<<N<<endl;
  	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e16;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

ll dp[110][410][110];

int main(){
    ll N, W; cin >> N >> W;
    ll w1, v1; cin >> w1 >> v1;
    dp[1][1][1] = v1;
    FOR(i, 1, N){
        ll w, v; cin >> w >> v;
        w -= w1-1;
        REP(j, 410) REP(k, 105){
            if(j >= w) dp[i+1][j][k+1] = max(dp[i][j][k+1], dp[i][j-w][k]+v);
            else dp[i+1][j][k] = dp[i][j][k];
        }
    }
    ll ans = 0;
    REP(i, 410) REP(k, N+1){
       if(k*(w1-1) + i <= W) ans = max(ans, dp[N][i][k]);
    }
    cout << ans << endl;
    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll, ll> Pll;
typedef pair<int, Pii > P1;

#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define mp1(a,b,c) P1(a,P(b,c))
#define get_arsize(a) (sizeof(a)/sizeof(a[0]))

const ll MOD = 1000000007;
const double EPS = 1e-10;
const int MAX = 200000;

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


Measured memory_bytes: 3636
using System;

class ITP1_7_C
{
    public static void Main()
    {
        int r, c, tmp;
        string[] Input;
        int[,] Output;

        Input = Console.ReadLine().Split(' ');
        r = int.Parse(Input[0]);
        c = int.Parse(Input[1]);

        Output = new int[r + 1, c + 1];


        for (int i = 0; i < r; i++)
        {
            Output[i, c] = 0;

            Input = Console.ReadLine().Split(' ');
            for (int j = 0; j < c; j++)
            {
                if (i == 0) Output[r, j] = 0;

                tmp = int.Parse(Input[j]);
                Output[i, j] = tmp;
                Output[i, c] += tmp;
                Output[r, j] += tmp;
                Output[r, c] += tmp;
            }
        }


        for (int i = 0; i < r + 1; i++)
        {
            for (int j = 0; j < c + 1; j++)
            {
                if (j != 0) Console.Write(" ");
                Console.Write(Output[i, j]);
            }
            Console.WriteLine();
        }
    }
}

Measured memory_bytes: 9324
#include<iostream>
using namespace std;
int main(){
    int n, m;
    cin >> n >> m;
    int a[n][m] = {};
    int b[m] = {};
    
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            cin >> a[i][j];
        }
    }
    
    for(int i = 0; i < m; i++){
        cin >> b[i];
    }
    
    int c[n] = {};
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            c[i] += a[i][j] * b[j];
        }
        cout << c[i] << endl;
    }
    return 0;    
}


Measured memory_bytes: 3120
#include<cstdio>
#define RI register int
#define CI const int&
using namespace std;
const int N=100005;
struct edge
{
	int to,nxt;
}e[N<<1]; int n,m,head[N],cnt,x,y,deg[N],c4,num; bool vis[N];
inline void addedge(CI x,CI y)
{
	e[++cnt]=(edge){y,head[x]}; head[x]=cnt;
	e[++cnt]=(edge){x,head[y]}; head[y]=cnt;
}
#define to e[i].to
inline void DFS(CI now)
{
	if (now==y) return (void)(++num);
	for (RI i=head[now];i;i=e[i].nxt)
	if (!vis[i+1>>1]) vis[i+1>>1]=1,DFS(to);
}
#undef to
int main()
{
	RI i; for (scanf("%d%d",&n,&m),i=1;i<=m;++i)
	scanf("%d%d",&x,&y),addedge(x,y),++deg[x],++deg[y];
	for (i=1;i<=n;++i) if (deg[i]&1) return puts("No"),0;
	for (i=1;i<=n;++i) if (deg[i]>=6) return puts("Yes"),0;
	for (i=1;i<=n;++i) if (deg[i]==4) ++c4;
	if (c4>=3) return puts("Yes"),0; if (c4<=1) return puts("No"),0;
	for (i=1;i<=n;++i) if (deg[i]==4) { x=i; break; }
	for (i=x+1;i<=n;++i) if (deg[i]==4) { y=i; break; }
	return DFS(x),puts(num==4?"No":"Yes"),0;
}

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

int main(){
	string s;
	cin >> s;
	int total = 700;

	if(s.at(0) == 'o') total += 100;
	if(s.at(1) == 'o') total += 100;
	if(s.at(2) == 'o') total += 100;

	cout << total << endl;
}

Measured memory_bytes: 256
a,b,c = tuple(map(int,input().split()))
if len(set((a,b,c)))==1 and a%2==1:
    print(0)
    exit()
ans = 0
while True:
  if len(set((a,b,c)))==1:
    print(-1)
    exit()
  if a%2==0 and b%2==0 and c%2==0:
    a,b,c = b//2+c//2,c//2+a//2,a//2+b//2
    ans+=1
  else:
    break
print(ans)


Measured memory_bytes: 38416
#include <stdio.h>

int main(void) {
	int n, m, d;
	int up_start, down_start;
	int tonari;
	double bunsi, bunbo;
	if (scanf("%d%d%d", &n, &m, &d) != 3) return 1;
	if (d > 0) {
		up_start = 1 + d;
		down_start = n - d;
		tonari = 0;
		if (up_start <= n) tonari += n - up_start + 1;
		if (1 <= down_start) tonari += down_start;
	} else {
		tonari = n;
	}
	bunsi = (double)tonari * (m - 1);
	bunbo = (double)n * n;
	printf("%.30f\n", bunsi / bunbo);
	return 0;
}

/*

n=3, m=3, d=1 で実験

1 1 1     2*1 1     3 1 1
1 1*2     2*1*2     3 1*2
1 1 3     2*1 3     3 1 3
1*2*1     2 2*1     3*2*1
1*2 2     2 2 2     3*2 2
1*2*3     2 2*3     3*2*3
1 3 1     2*3 1     3 3 1
1 3*2     2*3*2     3 3*2
1 3 3     2*3 3     3 3 3

結果：ペアは合計24個 (左右12個ずつ)

隣同士だけで考えると？

1 1
1*2
1 3
2*1
2 2
2*3
3 1
3*2
3 3

4個

→ 隣同士のパターン数 × 残りのパターン数(n**(m-2)) × 列数(m-1) と予想できる

数列の数(n**m)で割ると

(隣同士のパターン数 × (m-1)) / (n**2)

*/


Measured memory_bytes: 1724
N,X = map(int,input().split())
li = []
for _ in range(N):
    li.append(int(input()))
li.sort()
ans = X-sum(li)
count = N 
for i in range(N):
    temp = ans//li[i]
    count += temp
    ans -= li[i]*temp
    if ans >= 0:
        break
print(count)

Measured memory_bytes: 3064
#include<iostream>
#include<set>
#include<cstring>
using namespace std;

int n;
set<string> t;
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		t.insert(s);
	}
	cout<<t.size()<<endl;
}

Measured memory_bytes: 19208
#include <stdio.h>
#include <string.h>
int main()
{
    char ch[20];
    int i,j;
    gets(ch);
    j=strlen(ch);

    for(i=j-1;i>=0;i--)

    {
        printf("%c",ch[i]);
    }

    printf("\n");

    return 0;

}

Measured memory_bytes: 908
#include<iostream>
#include<cstdio>
using namespace std;
int n;
char ch[4001];
long long sum1,sum2,sum3,ans;
int main()
{
	scanf("%d\n",&n);
	for(int i=1;i<=n;i++){
		scanf("%c",&ch[i]);
		if(ch[i]=='R') sum1++;
		if(ch[i]=='G') sum2++;
		if(ch[i]=='B') sum3++;
		for(int j=1;j*2+1<=i;j++)
			if(ch[i]!=ch[i-j]&&ch[i]!=ch[i-2*j]&&ch[i-j]!=ch[i-2*j]) ans--;
	}
	ans+=sum1*sum2*sum3;
	printf("%lld",ans);
}

Measured memory_bytes: 3848
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7

n = I()
H = LI() + [1]
dp = [1] * (n + 1)

for k in range(n):
    new_dp = [0] * (n + 1)
    for i in range(n + 1):
        if H[i] <= H[k]:
            if H[k - 1] <= H[i]:
                new_dp[i] = dp[i] * 2 * pow(2, H[k] - H[i], mod)
            elif H[k - 1] > H[k]:
                new_dp[i] = dp[i] - dp[k] + dp[k] * 2
            else:
                new_dp[i] = (dp[i] - dp[k - 1] + dp[k - 1] * 2) * pow(2, H[k] - H[k - 1], mod)
        else:
            new_dp[i] = dp[k] * 2
        new_dp[i] %= mod
    dp = new_dp


print(dp[-1])


Measured memory_bytes: 83652
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<ll(n);i++)
ll MOD = 1e9 + 7;
int main() {
    string s, t;
    cin >> s >> t;
    map<char, int> ms,mt;
    map<int, vector<int>> vs, vt;
    rep(i, s.length()){
        if (ms[s[i]] == 0) {
            ms[s[i]] = i;
        }else {
            vs[ms[s[i]]].push_back(i);
        }
    }
    rep(i, t.length()){
        if (mt[t[i]] == 0) {
            mt[t[i]] = i;
        }else {
            vt[mt[t[i]]].push_back(i);
        }
    }
    rep(i, s.length()) {
        if (vs[i] != vt[i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}



Measured memory_bytes: 36852
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner s=new Scanner(System.in);
    int n=s.nextInt();
    int[][] arr=new int[n][3];
    for(int i=0;i<n;i++){
      arr[i][0]=s.nextInt();
      arr[i][1]=s.nextInt();
      arr[i][2]=s.nextInt();
    }
    int[][] dp=new int[n][3];
    for(int i=0;i<n;i++){
      for(int j=0;j<3;j++){
        if(i==0){
          dp[i][j]=arr[i][j];
        }
        else{
          if(j==0)
            dp[i][j]=Math.max(dp[i-1][1],dp[i-1][2])+arr[i][j];
          else if(j==1)
            dp[i][j]=Math.max(dp[i-1][0],dp[i-1][2])+arr[i][j];
          else
            dp[i][j]=Math.max(dp[i-1][0],dp[i-1][1])+arr[i][j];
        }
      }
    }
      int max=Integer.MIN_VALUE;
      for(int i=0;i<3;i++){
        max=Math.max(dp[n-1][i],max);
      }
      System.out.println(max);
    }
  }
  
        
    

Measured memory_bytes: 100964
#include <iostream>
#include <iterator>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <numeric>
#include <iomanip>
#include <limits>

typedef long long ll;

using namespace std;

int main(){

   string s;
   cin>>s;

   bool ans=false;

   if(s[2]==s[3] && s[4]==s[5]){
       ans=true;
   }

   if(ans){
       cout<<"Yes"<<endl;
   }
   else{
       cout<<"No"<<endl;
   }
  
    return 0;
}


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

using namespace std;

int find(string s){
    int ans = 0;
    for (int i = 0; i < s.length()-1; i++)
    {
        if(s[i]=='A'){
            if(s[i+1]=='B')
                ans++;
        }
    }
    return ans;
}

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

    vector <string> s(n);

    for (int i = 0; i < n; i++)
    {
        cin>>s[i];
    }
    

    int ans=0;
    int aend=0,bstart=0,both=0;

    for (int i = 0; i < n; i++)
    {
        ans+= find(s[i]);
        if(s[i].front()=='B'){
            if(s[i].back()=='A'){
                both++;
            }else{
                bstart++;
            }
        }else{
            if(s[i].back()=='A'){
                aend++;
            }
        }
    }


    if(aend==0&&both>0){
        aend++;
        both--;
    }
    if(bstart==0&&both>0){
        bstart++;
        both--;
    }
    ans += min(aend,bstart);
    if(both>0){
        ans += both;
    }
    
    
    cout << ans <<endl;
    return(0);
}

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

int main(){
  int N;
  cin >> N;
  vector<int> p(N);
  REP(i,N){
    cin >> p[i];
    --p[i];
  }

  vector<int> C(N);
  REP(i,N) C[p[i]] = i;
  vector<int> sub(N - 1);
  REP(i,N - 1) sub[i] = C[i + 1] - C[i];

  vector<int> A(N - 1), B(N - 1);
  REP(i,N - 1) {
    if(sub[i] >= 0) {
      B[i] = 1;
      A[i] = sub[i] + 1;
    }else{
      A[i] = 1;
      B[i] = 1 - sub[i];
    }
  }

  vector<int> a(N), b(N);
  a[0] = 1;
  b[0] = 1e9;
  REP(i,N - 1) {
    a[i + 1] = a[i] + A[i];
    b[i + 1] = b[i] - B[i];
  }
  REP(i,N) {
    if(i) cout << " ";
    cout << a[i];
  }
  cout << endl;
  REP(i,N) {
    if(i) cout << " ";
    cout << b[i];
  }
  cout << endl;
  return 0;
}



Measured memory_bytes: 1152
#include <cstdio>

const int N = 100000;

int a[N];

int main()
{
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; ++ i) {
        scanf("%d", a + i);
    }
    int i = 0;
    while (i < n - 1 && a[i] + a[i + 1] < m) {
        i ++;
    }
    if (i == n - 1) {
        puts("Impossible");
    } else {
        puts("Possible");
        for (int j = 1; j <= i; ++ j) {
            printf("%d\n", j);
        }
        for (int j = n - 1; j > i + 1; -- j) {
            printf("%d\n", j);
        }
        printf("%d\n", i + 1);
    }
}


Measured memory_bytes: 1152
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
double n,m,a[1001][1001];
int cnt=0;
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>a[i][j];
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
		double ans=0;
			for(int k=1;k<=m;k++){
				ans+=pow(abs(a[i][k]-a[j][k]),2);
			}
			ans=sqrt(ans);
			if(ans==floor(ans)){
				cnt++;
			}
		}
	}
	cout<<cnt;
	return 0;
}

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

using namespace std;

void insertionSort(vector<int> &a, int n, int g, int &cnt){
	int v, j;
	for (int i = g; i < n; i++){
		v = a[i];
		j = i - g;
		while (j >= 0 && a[j] > v){
			a[j + g] = a[j];
			j -= g;
			cnt++;
		}
		a[j + g] = v;
	}
}

int shellSort(vector<int> &a, vector<int> G, int m, int n){
	int cnt = 0;
	for (int i = 0; i < m; i++){
		insertionSort(a, n, G[i], cnt);
	}
	return cnt;
}

int main(){
	int n, m = 0, cnt;
	cin >> n; 
	vector<int> a(n), G(100);
	for (int i = 0; i < n; i++) cin >> a[i];
	G[0] = 1;
	while (n >= G[m++]) G[m] = 3 * G[m - 1] + 1;
	m--;
	reverse(G.begin(), G.begin() + m);
	cout << m << endl;
	for (int i = 0; i < m; i++){
		cout << G[i];
		if (i != m - 1) cout << " ";
	}
	cnt = shellSort(a, G, m, n);
	cout << endl << cnt << endl;
	for (int i = 0; i < n; i++) cout << a[i] << endl;
}

Measured memory_bytes: 6716
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Library;
using static Library.Input;

namespace AtCoderTemplate
{
    class ProgramE
    {
        private class Key
        {
            public int A {get;set;}
            public int C {get;set;}
        }
        static void Main()
        {
            int n = NextInt, m = NextInt;
            var keys = new List<Key>();
            for (int i = 0; i < m; i++)
            {
                int a = NextInt, b = NextInt;
                keys.Add(new Key{A = a, C = IntList.Aggregate(0, (x, y) => x + (1 << (y - 1)))});
            }

            var dp = Enumerable.Repeat(int.MaxValue >> 2, 1 << n).ToArray();
            dp[0] = 0;
            for (int i = 0; i < (1 << n); i++)
            {
                foreach (var key in keys)
                {
                    dp[i | key.C] = Math.Min(dp[i] + key.A, dp[i | key.C]);
                }
            }

            if (dp[(1 << n) - 1] == (int.MaxValue >> 2)) System.Console.WriteLine(-1);
            else System.Console.WriteLine(dp[(1 << n) - 1]);
        }
    }
}

namespace Library
{
    class Input
    {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line => Console.ReadLine();

        public static string[] StrArr => Line.Split(' ');

        public static int NextInt => int.Parse(NextWord());

        public static long NextLong => long.Parse(NextWord());

        public static List<int> IntList => StrArr.Select(int.Parse).ToList();

        public static List<long> LongList => StrArr.Select(long.Parse).ToList();

        public static IEnumerable<long[]> TakeLine(int N)
        {
            return Enumerable.Repeat(0, N).Select(_ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray());
        }

        public static string NextWord()
        {
            while (!enumerator.MoveNext())
            {
                enumerator = StrArr.AsEnumerable().GetEnumerator();
            }
            return enumerator.Current;
        }
    }
}


Measured memory_bytes: 13504
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>

using namespace std;

int main(){
   int n;
   cin>>n;
   vector<int> a(n);
   int f=0;
   int t=0;
   for(int i=0;i<n;i++){
      cin>>a[i];
      if(a[i]%4==0){
         f++;
         continue;
      }
      if(a[i]%2==0)t++;
   }
   if(n/2<=f+t/2)cout<<"Yes"<<endl;
   else cout<<"No"<<endl;

}

Measured memory_bytes: 640
n,m=map(int,input().split())
l=0
r=10**10
for i in range(m):
    lx,rx = map(int,input().split())
    if l<lx:
        l=lx
    if r >rx:
        r=rx
if l>r:
    print(0)
else:
    print(r-l+1)

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

using namespace std;

#define long long long
#define INF ((long) 2e18)
#define MOD ((long) (1e9 + 7))
#define umap unordered_map

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

    long t = 1;
    //cin >> t;

    while (t--) {
        long n, d;
        cin >> n >> d;

        long d2 = d*d;
        long ans = 0;
        for (long i = 0; i < n; i++) {
            long x, y;
            cin >> x >> y;
            long dist = x*x + y*y;
            if (dist <= d2) {
                ans++;
            }
        }
        printf("%lld\n", ans);
    }
}


Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC(T, v) static_cast<T>(v)
#define SI(v) SC(int, v.size())
#define SL(v) SC( LL, v.size())
#define RF(e, v) for(auto & e: v)
#define ei else if
#define UR assert(false)

// ---- ----

int n, l[10];

int main() {
	cin >> n;
	inc(i, n) { cin>> l[i]; }
	
	int s = 0, ma = 0;
	inc(i, n) { s += l[i]; setmax(ma, l[i]); }
	
	cout << (ma < s - ma ? "Yes" : "No") << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main(int argc, char* argv[])
{

	int R;

	cin >> R;

	if(R < 1200){
		cout << "ABC" << endl;
	}else if(R < 2800){
		cout << "ARC" << endl;
	}else{
		cout << "AGC" << endl;
	}

	return 0;
}

Measured memory_bytes: 256