akhauriyash/Code-Regression huggingface dataset:
n = int(input())
x = list(map(float, input().split()))
y = list(map(float, input().split()))
##절대값 내장함수 abs!
for k in range(1,4):
    print('{0:.6f}'.format(pow(sum(abs((x[i] - y[i])**k)for i in range(n)),1/k)))

print('{0:.6f}'.format(max(abs((x[i] - y[i]))for i in range(n))))
## p =infinity 인경우에는 수학적으로 생각하면 차의 절대값의 최대값이 답임


Measured memory_bytes: 5676
#include <bits/stdc++.h>
using namespace std;
#define ll long long
void A(){
    int x;
    cin>>x;
    if(x>=30) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}
void B(){
    ll n,d;
    cin>>n>>d;
    int res=0;
    for(int i=0;i<n;i++){
        ll x,y;
        cin>>x>>y;
        if(x*x+y*y<=d*d) res++;
    }
    cout<<res<<endl;
}
void C(){

}
void D(){
    int n;
    string s;
    cin>>n;
    cin>>s;
    stack<int>st;
    for(int i=0;i<n;i++){
        if(s[i]=='R') st.push(i);
    }
    int l=0,r=n-1;
    int res=0;
    for(int i=0;i<n&&!st.empty();i++){
        if(i>=st.top()) break;
        if(s[i]=='W'){
            st.pop();
            res++;
        }
    }
    cout<<res<<endl;
}
void E(){

}
void F(){

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


Measured memory_bytes: 4304
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(void){
  //int型の配列seq
  int seq[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  
  //int型変数 K
  int K;
  char num[1000];

  //Kに値を格納する
  fgets(num, sizeof(num), stdin);
  sscanf(num, "%d", &K);
  
  printf("%d\n", seq[K - 1]);  
  return 0;
}


Measured memory_bytes: 2136
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
#define INF int(1e9)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define REPONE(i, n) for(int i = 1; i <= (int)(n); i++)
#define EACH(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(int i = m;i < n;i++)

const int MAX_N = int(1e5);
int N;
string S[MAX_N];
unordered_map<char, ll> mp;

void solve() {
    ll ans = 0;
    EACH(i, mp) {
        EACH(j, mp) {
            EACH(k, mp) {
                if (i.first == j.first || j.first == k.first || k.first == i.first) continue;
                ans += i.second * j.second * k.second;
            }
        }
    }
    cout << ans / 6 << endl;
}

int main() {
    cin >> N;
    REP(i, N) {
        cin >> S[i];
        if (S[i][0] == 'M' || S[i][0] == 'A' || S[i][0] == 'R' || S[i][0] == 'C' ||
            S[i][0] == 'H') {
            mp[S[i][0]]++;
        }
    }
    solve();
    return 0;
}

Measured memory_bytes: 6144
#include "bits/stdc++.h"
/* Properties of modulo:
	(a/b)%m ,where m is prime  = (a%m) * (b^(m-2))%m
*/
    /*ROLLING HASH
    Rabin-Karp algorithm for pattern matching in a string in O(n) time
    Calculating the number of different substrings of a string in O(n2logn)
    Calculating the number of palindromic substrings in a string.
    */
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define IOS { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define ll long long
#define pb push_back
#define gcd __gcd
#define nl cout<<"\n"
#define endl "\n"
#define all(c) (c).begin(),(c).end()
#define trav(a,x) for(auto a = x.begin() ; a != x.end() ; a++)
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second
//template<typename T>
//#define o_set(T) tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>
// o_set(ll) name ; -- defining ordered set
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set - returns iterator
bool compare(ll a, ll b){
    return a > b;
}
ll power(ll x, ll ex , ll md) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % md;
        ex >>= 1ll;
        x = (x * x) % md;
    }
    return ans;
}
void solve(){
    ll a , b,n;
    cin >> a>> b >> n;
    ll p1 , p2;
    ll ans1 = LLONG_MIN;
    ll ans2 = LLONG_MIN;
    ll ans = LLONG_MIN;
    if(b - 1 <= n){
         p1 = (a*(b - 1))/b;
         ans1 = p1;
         ans = max(ans , ans1);
    }
    if(b <=n){
        p1 = (a*(b))/b;
         ans1 = p1 - a;
         ans = max(ans , ans1);
    }
         p1 = (a*n)/b;
         p2 = n/b;
         ans2 = p1 - a*p2;
         ans = max(ans , ans2);
        ll d =0 ;
        ans = max(ans , d);
        cout << ans << endl;
}
int main(){
    IOS;
    ll T=1;
    //cin>>T;
    ll t=0;
    while(t++<T){
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


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

//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

#define rep(i,n) for(i=1;i<=n;i++)
#define Rep(i,n) for(i=0;i<n;i++)
#define For(i,a,b) for(i=a;i<=b;i++)

#define pb(x) push_back(x)
#define sz(x) (int)x.size()

#define mem(ara,val) memset(ara,val,sizeof(ara))
#define eps 1e-9

#define si(x) scanf("%d",&x)
#define sii(x,y) scanf("%d %d",&x,&y)
#define siii(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sll(x,y) scanf("%lld %lld",&x,&y)
#define slll(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define ss(str) scanf("%s",str)
#define pi(x) printf("%d",x)
#define pii(x,y) printf("%d %d",x,y)
#define piii(x,y,z) printf("%d %d %d",x,y,z)
#define pl(x) printf("%lld",x)
#define pll(x,y) printf("%lld %lld",x,y)
#define plll(x,y,z) printf("%lld %lld %lld",x,y,z)
#define NL printf("\n")
#define Max 505
#define INF 1e9
#define un(x) x.erase(unique( x.begin() , x.end() ), x.end())
#define mod 1000000007

#define FI freopen("in.txt","r",stdin)

#define D(x) cout << #x << " = " << x << endl
#define DD(x,y) cout << #x << " = " << x << "   " << #y << " = " << y << endl
#define DDD(x,y,z) cout << #x << " = " << x << "   " << #y << " = " << y << "   " << #z << " = " << z << endl

typedef long long LL;
typedef unsigned long long ULL;

using namespace std;

int setb(int n,int pos)
{
    return n=n | (1 << pos);
}
int resb(int n,int pos)
{
    return n=n & ~(1 << pos);
}
bool checkb(int n,int pos)
{
    return (bool)(n & (1 << pos));
}

LL bigmod(LL b,LL p,LL m)
{
    if( p == 0 ) return 1;
    LL ret = bigmod(b,p/2,m);
    ret = ( ret * ret ) % m;
    if( p & 1 ) ret = ( ret * b ) % m;
    return ret;
}

LL n,ara[1000005];

void solve()
{
    if( ara[n] != 2 ) return;
    LL l = 2, r = 3;
    for(int i = n - 1; i >= 1; i--)
    {
        LL mx = r / ara[i];
        LL mn = l / ara[i];
        if( l % ara[i] ) mn++;
        if( mn > mx ) return;
        LL new_l = ara[i] * mn;
        LL new_r = ara[i] * mx + ara[i] - 1;
        l = new_l;
        r = new_r;
    }
    printf("%lld %lld\n",l,r);
    exit(0);
}

int main()
{
    //FI;
    LL i;
    sl(n);
    rep(i,n) sl(ara[i]);
    solve();
    puts("-1");
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>

using namespace std;
using ll = long long;

int main()
{
    string s;
    cin >> s;
    if(s[0] == s[2]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3596
n,k=map(int,input().split())

if k%2==0:
    nsum=0
    for i in range(1,n+1):
        ia=i%k
        k2=k/2
        if ia==0:
            nb=(n-ia)//k
            nsum=nsum+nb**2
        elif ia==k2:
            nb=(n-ia)//k+1
            nsum=nsum+nb**2
        
else:
    nsum=0
    for i in range(1,n+1):
        ia=i%k
        if ia==0:
            nb=(n-ia)//k
            nsum=nsum+nb**2

print(nsum)    
    

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

using namespace std;


int main(void) {
    long long A,B,ans=-1;

    cin>>A>>B;

    for(int i=1;i<=10000;i++){
        if(int(0.08*i) == A && int(0.10*i) == B){
            ans=i;
            break;
        }
    }

    cout<<ans<<endl;



	return 0;
}

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

int main(){
    const int MOD = 1000000007;
    int N;
    cin >> N;
    bool isEven = N%2 ==0;
    int A[N];
    for(int i=0; i<N; i++){
        cin >> A[i];
    }

    int check[N];
    for(int i=0; i<N; i++){
        check[i] = 2;
    }

    for(int i=0; i<N; i++){
        if(isEven){
            if(A[i] % 2 == 0){
                cout << 0 << '\n';
                return 0;
            }else{
               check[A[i]]--;
               if(check[A[i]]<0) {
                    cout << 0 << '\n';
                    return 0;
               }
            }
        }else{
            if(A[i] % 2 != 0){
                cout << 0 << '\n';
                return 0;
            }else{
               check[A[i]]--;
               if(check[A[i]]<0) {
                    cout << 0 << '\n';
                    return 0;
               }
            }
        }
    }
    if(isEven){
        if(check[0]!=2){
            cout << 0 << '\n';
            return 0;
        }
    }else{
        if(check[0]!=1){
            cout << 0 << '\n';
            return 0;
        }
    }

    int level = N/2;
    int ans = 1;
    for(int i=0; i<level; i++){
        ans = (ans*2)%MOD;
    }
    cout << ans << '\n';
}

Measured memory_bytes: 3884
fun main(args: Array<String>) {
    val (m1, n1) = readIntegerList()
    val (m2, n2) = readIntegerList()
    if (m1 == m2) {
        println(0)
    } else {
        println(1)
    }
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)


Measured memory_bytes: 37888
N,Y=map(int,input().split())
flg=0
for i in range(N+1):
    for j in range(N+1-i):
        k=N-i-j
        if 10000*i+5000*j+1000*k == Y:
            flg=1
            print(i,j,k)
            break
    if flg==1:
        break

if flg==0:
    print(-1,-1,-1)

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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

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

  bool a = false;
  bool b = false;
  each (i, s) {
    if (i == 'A') a = true;
    if (i == 'B') b = true;
  }

  if (a && b) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int n, a, b, q;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	cin >> n >> a >> b >> q;
	vector<pair<int, char>> xs;
	rep(i, a){ int x; char c; cin >> x >> c; xs.emplace_back(--x, c); }
	
	vector<pi> ys;
	rep(i, b){ int y, h; cin >> y >> h; ys.emplace_back(--y, --h); }
	if(ys.size() && ys.back().second >= 0) ys.emplace_back(n, -1);
	
	map<pi, int> left;
	rep(i, ys.size()){
		if(ys[i].second < 0) continue;
		int L = ys[i].first, R = ys[i + 1].first;
		int l = ys[i].second, r = l + R - L, d = L - l;
		left[pi(L, R)] = d;
	}
	
	auto move = [&](int p){
		map<pi,int>::iterator it = left.lower_bound(pi(p + 1, 0));
		if(it == left.begin()) return p;
		--it;
		
		if(!(it->first.first <= p && p < it->first.second)) return p;
		int l = it->first.first - it->second, t = (p - l) / it->second;
		return p - t * it->second;
	};
	
	unordered_map<int, char> cs;
	for(auto i : xs){
		int p = i.first;
		for(int nxt = p; p != (nxt = move(p)); p = nxt);
		cs[p] = i.second;
	}
	/*
	for(auto p : cs) dbg(p.first, p.second);
	for(auto p : left) dbg(p.first, p.second);
	*/
	string ans;
	while(q--){
		int p; cin >> p;
		for(int nxt = --p; p != (nxt = move(p)); p = nxt);
		ans += cs.count(p) ? cs[p] : '?';
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3364
#
import sys
import math
import numpy as np
import itertools


# ひとつ入力
n = int(input())
# リストに入れる
a = [int(i) for i in input().split()] 

fugou = 0
saishou = 999999999999
goukei = 0

for i in range(n):
    if a[i] < 0:
        fugou += 1
    goukei += abs(a[i])
    saishou = min(saishou,abs(a[i]))
if fugou % 2 == 0:
    print(goukei)
else:
    print(goukei - 2*saishou)


Measured memory_bytes: 23316
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
    auto val = table(args...);
    return vector<decltype(val)>(n, move(val));
}
const ll INF = (1ll<<31)-1;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 200005;
int nx[4] = {0,-1,0,1};
int ny[4] = {1,0,-1,0};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int a1[n+1],a2[n+1],c;
    a1[0] = 0;
    a2[0] = 0;
    rep(i,n){
        cin >> c;
        a1[i+1] = a1[i]+c;
    }
    rep(i,n){
        cin >> c;
        a2[i+1] = a2[i]+c;
    }
    int ans = 0;
    rep(i,n){
        chmax(ans,a1[i+1]+a2[n]-a2[i]);
    }
    PRINT(ans);
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

int main()
{
	long long int n, k;
	cin >> n >> k;
	vector<pair<int, int> > num;
	for(int i = 0; i < n; i++){
		int a, b;
		cin >> a >> b;
		num.push_back(make_pair(a, b));
	}
	sort(num.begin(), num.end());
	long long int now = 0;
	int i = 0;
	while(now + num[i].second < k){
		now += num[i].second;
		i++;
	}
	cout << num[i].first << endl;
}

Measured memory_bytes: 1400
#include<stdio.h>
#define N 100000
#define Q 50000
int binarySearch(int);

int s[N],n;

int main(){
  int t,q[Q],count=0;;
  int i;

  scanf("%d",&n);
  for(i=0;i<n;i++) {
    scanf("%d",&s[i]);
  }
  scanf("%d",&t);
  for(i=0;i<t;i++){
    scanf("%d",&q[i]);
    if(binarySearch(q[i])==1){
      count++;
    }
  }
     printf("%d\n",count);
  return 0;
}

int binarySearch(int key){
  int left=0;
  int right=n;
  int mid;
  while(left<right){
    mid = (left+right)/2;
    if(s[mid]==key) return 1;
    else if(key<s[mid]) right= mid;
    else left = mid+1;
  }
  return 0;
}

Measured memory_bytes: 1184
/*
Author- Aasav Badera
Time- Sun Mar 22 17:30:45 2020
*/
#include<bits/stdc++.h> 
#define ll                 long long                            
#define pb                 push_back                                                     
#define s                  second
#define mii                map<ll ,ll >
#define dbg(x)             { cerr<<#x<<": "<<x<< endl; }
#define dbg2(x,y)          { cerr<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl; }
#define rep(i, a, b)         for(ll  i=a;i<b;i++)
#define pii                pair<ll ,ll >
#define ppb                pop_back
#define f                  first 
#define vi                 vector<ll >
#define vii                vector<pair<ll , ll >>
#define si                 set <ll>
#define all(a)             (a).begin(),(a).end()
#define sz(x)              (ll )x.size()
#define hell               1000000007
#define mp                 make_pair
#define yes                cout << "YES" << endl;
#define no                 cout << "NO" << endl;
#define inf                1e18L+1
#define endl               '\n' 
using namespace std;
#define N  300005
ll checkpalindrome(string s)
{
    ll m = sz(s);
    rep(i, 0, m/2+1)
    {
        if(s[i] == s[m-1-i])
        {
            ;
        }
        else return 0;
    }
    return 1;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll tests = 1;
    // cin >> tests;
    while(tests--)
    {
        string s;
         cin >>s;
         ll n =sz(s);
         if(n%2)
         {
            ll key = 1;
            if(checkpalindrome(s) && checkpalindrome(s.substr(0, (n-1)/2)) && checkpalindrome(s.substr((n+1)/2, (n-1)/2)))
                key = 1;
            else key = 0;
            if(key)
            {
                cout << "Yes" << endl;
            }
            else
            {
                cout << "No" << endl;
            }
         }
         else
         {
            cout << "No" << endl;
         }
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char **args) {
	int a, b, t;
	int biscuit_cnt;

	scanf("%d%d%d", &a, &b, &t);
	biscuit_cnt = ((t / a) * b);

	printf("%d", biscuit_cnt);
	return 0;
}


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

signed main() {
  
  int N, P;
  cin >> N >> P;
  
  if( N == 1 ){
    cout << P << endl;
    return 0;
  }
  
  int waru = 2;
  int A = P;
  int cnt = 0;
  int ans = 1;
  while( waru <= sqrt(P) ){
    cnt = 0;
    while( A % waru == 0 ){
      cnt++;
      A /= waru;
      if( cnt == N ){
        ans *= waru;
        cnt = 0;
      }
    }
    waru++;
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    const ll d[2][2] = {{0, 1}, {1, 0}};
    const ll MAXV = 80 * (80 + 80);
    ll h, w;
    cin >> h >> w;
    vector<vector<ll>> a(h, vector<ll>(w)), b(h, vector<ll>(w));
    rep(i, h) rep(j, w) cin >> a[i][j];
    rep(i, h) rep(j, w) cin >> b[i][j];
    vector<vector<vector<bool>>> dp(h, vector<vector<bool>>(w, vector<bool>(MAXV + 1, false)));
    dp[0][0][abs(a[0][0] - b[0][0])] = true;
    queue<pair<ll, ll>> q;
    q.push(make_pair(0, 0));
    vector<vector<bool>> seen(h, vector<bool>(w, false));
    seen[0][0] = true;
    while(!q.empty()) {
        pair<ll, ll> p = q.front(); q.pop();
        ll x = p.second, y = p.first;
        rep(i, 2) {
            ll nx = x + d[i][1];
            ll ny = y + d[i][0];
            if ((nx >= w) || (ny >= h)) continue;
            rep(j, MAXV + 1) {
                if (!dp[y][x][j]) continue;
                dp[ny][nx][j + abs(a[ny][nx] - b[ny][nx])] = true;
                dp[ny][nx][abs(j - abs(a[ny][nx] - b[ny][nx]))] = true;
            }
            if (!seen[ny][nx]) {
                seen[ny][nx] = true;
                q.push(make_pair(ny, nx));
            }
        }
    }
    ll ans = LONG_LONG_MAX;
    rep(i, MAXV + 1) {
        if (dp[h - 1][w - 1][i]) {
            ans = i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  vector<int>x(5);
  for(int i = 0 ; i < 5 ; i++){
  	cin >> x.at(i);
  }

  for(int i = 0 ; i < 5 ; i++){
 	if(x.at(i)==0){
    	cout << i+1 ;
    }
  }
  
  cout << endl;
  
  
  return 0;
  
}


Measured memory_bytes: 3596
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
using namespace std;
int main()
{
    char a[1001];
    int s=0;
    cin>>a;
    s=strlen(a);
    cout<<a[0]<<s-2<<a[s-1];
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n,d;
    cin>>n>>d;
    ll z=n;
    ll c=0;
    while(n--)
    {
        ll x,y;
        cin>>x>>y;
        double ans=(x*x)+(y*y);
        ans=sqrt(ans);
        if(ans>d)
        {
            //cout<<ans<<endl;
            c++;
        }

    }
    cout<<abs(z-c)<<endl;
    return 0;
}


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

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

using namespace std;

using ll = long long;

ll n;

int main(){
  cin >> n;
  ll k = n / 11;
  ll r = n % 11;
  cout << 2 * k + (r <= 6 ? r > 0 : 2) << endl;
  return 0;
}

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

int search(vector<int>& a,int n,int key){
    int left=0;
    int right=n;
    while(left<right){
        int mid=(left+right)/2;
        if(a[mid]==key)
            return 1;
        else if(a[mid]>key)
            right=mid;
        else
            left=mid+1;
    }
    return 0;
}

int main(){
    int n,q;
    cin>>n;
    vector<int> s(n+1,0);
    rep(i,n) cin>>s[i];
    cin>>q;
    int key;
    int ans=0;
    rep(i,q){
        cin>>key;
        if(search(s,n,key)) ans++;
    }
    
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 3140
from numba import njit
import numpy as np

N = int(input())
A = list(map(int, input().split()))

@njit
def main(A):
  count = np.zeros(10**6 + 10, np.int32)
  
  for i in range(N):
    a = A[i]
    if count[a] > 1:
      continue
    count[::a] += 1
    
  ans = 0
  for i in range(N):
    ans += count[A[i]] == 1
    
  #print(count[:100])
  return ans
  
print(main(np.array(A, np.int32)))

Measured memory_bytes: 129028
#include <bits/stdc++.h>
                using namespace std;
                typedef long long ll;
                #define INPUT()              freopen("input.txt", "r", stdin)
                #define OUTPUT()             freopen("output.txt", "w", stdout)
                #define F                    first
                #define S                    second
            //Templatefunctions
                template<typename T>T gcd(T x, T y) { if (y == 0)return x; else return gcd(y, x%y);}
                template <class T> T euclideanDistance(T x1 , T x2 , T y1 , T y2){return sqrt(( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ));}
                template <class T> T digitSum(T n){T sum = 0;while(n > 0)sum += n % 10,n /= 10;return sum;}
            //datatypes
                typedef long long int ll;
                typedef unsigned long long int ull;
                typedef long double ld;
            //constants
                const double INF = 1e+9;
                const double INFLL = 1e+18;
                const double EPS = 1e-9;
                const double PI = acos(-1);
                const int knightDir[8][2] = {{-2,-1},{-2,1},{-1,2},{1,2},{2,-1},{2,1},{-1,-2},{1,-2}};
                       //const int dx[]={0,0,0,1,1,1,-1,-1,-1};
                       //const int dy[]={-1,0,1,-1,0,1,-1,0,1};
                const int dx[] = {0 , 1 , 0 , -1};
                const int dy[] = {1 , 0 , -1 , 0};
            //helpers
                //#define MOD         1000000007LL
                #define MAX         1000005
                const ll MOD = 1000000000 + 7;
                int arr[MAX];
            //Global Variables


                int manhattanDis(int  x , int y , int x1 , int y1)
                {
                    return abs(x - x1) + abs(y - y1);
                }
                int main()
                {
                   int a,b,c;
                   scanf("%d%d%d",&a,&b,&c);
                   int mul = a;
                   int t = 10000;
                   if(a == 1)
                   {
                        printf("YES\n");
                        return 0;
                   }
                   while(t--)
                   {
                        //printf("%d\n",mul % b);
                        if(mul % b == c)
                        {
                            printf("YES\n");
                            return 0;
                        }
                        mul += a;
                        mul %= b;
                   }
                   printf("NO\n");

                }


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
 
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <fstream>
#include <set>
#include <utility>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <numeric>
#include <sstream>
#include <list>
#include <map>
#include <functional>
#include <iterator>
 
 
#define rep(i,p,n) for(int i=(int)p;i<(int)n;i++)
#define repp(i,p,n) for(int i=(int)p;i>=(int)n;i--)
#define Sort(x) sort(x.begin(),x.end());
#define PSort(x) sort(begin(x), end(x), pairCompare)
#define ll long long
#define INF 2000000000
 
using namespace std;
 
int main() {
	int n,nn;
	cin >> n;
	nn = n;
	int ans = 0;
	while (nn > 0) {
		ans += nn % 10;
		nn /= 10;
	}
	if (n%ans == 0)cout << "Yes" << endl;
	else cout << "No" << endl;
 
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>


int main(){
	int N,H,W;
	int configuration;
	
	scanf("%d",&N);
	scanf("%d",&H);
	scanf("%d",&W);
	
	configuration = (N+1-H)*(N+1-W);
	
	if((H > N) || (W > N)){
		configuration = 0;
	}
	
	
	printf("%d\n",configuration);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
#include <map>
#include <queue>
#include <cctype>
using namespace std;
using ll = long long;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[100001];
//char str[1010][1010];
//typedef pair<ll,ll> A;
//vector<A> pc;
//int ABS(int a){return max(a,-a);}
ll a[100000];
ll dom[100001];

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

int main(){
  int n;
  cin>>n;
  for(int i=1;i<=9;i++){
    for(int j=1;j<=9;j++){
      if(i*j==n){
        cout<<"Yes";
        return 0;
      }
    }
  }
  cout<<"No";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds; 
using namespace std;
#define int long long
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mll map<ll,ll>
#define mii map<int,int>
#define mp make_pair
#define pb push_back
#define rep(i,b) for(ll (i)=0;i<(b);i++)
#define all(c) (c).begin(), (c).end()
#define F first
#define S second
#define CLR(p) memset(p, 0, sizeof(p))
#define SET(p) memset(p, -1, sizeof(p))
#define DEBUG true
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
//typedef long long int ll;
typedef tree<int, null_type, less<int>, rb_tree_tag, 
tree_order_statistics_node_update> new_data_set; 
const int MAX=1e6+5;
#define MOD 1000000007
/*std::cout << std::fixed;
std::cout << std::setprecision(6);*/
//(a%mod-b%mod+mod)%mod



/************************************


 
*************************************/

vector<vector<ll>>v;
ll T=0;
ll cnt1=0,cnt0=0;
vector<ll>dep;
bool visited[MAX];
vector<ll>par;
vector<ll>tin,tout;
vector<ll>col;

int countDivisibles(int A, int B, int M) 
{ 
    
    if (A % M == 0) 
        return (B / M) - (A / M) + 1; 
  
    // A is not divisible by M 
    return (B / M) - (A / M); 
} 







signed main(){
    int t=1;
    // cin>>t;
    while(t--){
        int x;
        cin>>x;
        for(int i=0;i<=150;i++){
            for(int j=-150;j<=150;j++){
                int a = pow(i,5);
                int b = pow(j,5);
                // cout<<a<<" "<<b<<" ## ";
                if(a-b==x){
                    cout<<i<<" "<<j<<endl;
                    return 0;
                }

            }
        }
    }
    return 0;
}


Measured memory_bytes: 4108
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <math.h>

int rate_range[8][2] = {
	{1,399},
	{400,799},
	{800,1199},
	{1200,1599},
	{1600,1999},
	{2000,2399},
	{2400,2799},
	{2800,3199},
};

#define ANY_COLOR_RATE 3200

int main(void)
{
	int N,n;
	scanf("%d\n",&N);
	int any_count = 0;
	int fix_count = 0;
	int rate_occurrence[8];
	memset(rate_occurrence,0,sizeof(rate_occurrence));
	for (n=0;n<N;n++){
		int a;
		scanf("%d ",&a);
		if (a >= ANY_COLOR_RATE){
			any_count++;
		}
		else {
			int i=0;
			for (i=0;i<8;i++){
				if ((rate_range[i][0] <= a) && (a <= rate_range[i][1])){
					break;
				}
			}
			assert(i<8);
			if (rate_occurrence[i]==0)fix_count++;
			rate_occurrence[i]=1;
		}
	}
	int ans_min;
	int ans_max;
	ans_min = fix_count;
	if (ans_min <= 0)ans_min = 1;
	ans_max = fix_count + any_count;
	//assert(ans_max>0);
	//if (ans_max > 8)ans_max=8;
	printf("%d %d\n",ans_min,ans_max);
	return 0;
}


Measured memory_bytes: 128
import re

while True :
    try :
        Q = re.split("[+=]", input())
        A = Q[0]
        B = Q[1]
        S = Q[2]
        start = 0
        ans = "NA"
        
        if((A[0] == "X" and len(A) > 1) or (B[0] == "X" and len(B) > 1)
            or (S[0] == "X" and len(S) > 1)) :
                start = 1
                
        for i in range(start, 10) :
            a = A.replace("X", str(i))
            b = B.replace("X", str(i))
            s = S.replace("X", str(i))
            
            if(int(a) + int(b) == int(s)) :
                ans = i
                break
            else :
                pass
        
        print(ans)
        
    except :
        break


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

int main(){
  int k,n;
  cin>>k>>n;
  vector<int> a(n);
  rep(i,n) cin>>a[i];
  vector<int>  b(n);
  for(int i = 1;i < n;i++){
    b[i] = a[i] - a[i-1];
  }
  b[0] = a[0]+k-a[n-1];
  
  int mi = 0;
  rep(i,n){
    mi=max(mi,b[i]);      
  }
  cout << k-mi << endl;
  
}
  
  

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	
	cin>>s;
	
	int y=(s[5]-'0')*10+s[6]-'0';
	
	if(y<=4){
		cout<<"Heisei"<<endl;
	}else{
		cout<<"TBD"<<endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
typedef long long ll;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    map<string,int> m;
    int mx =0;
    rep(i,n){
        string s;
        cin >> s;
        m[s]++;
        mx = max(mx,m[s]);
    }
    for(auto p:m){
        if(p.second==mx){
            cout << p.first << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 23808
O = input()
E = input()
ans = ''
if len(O) == len(E):
    for i in range(len(O)):
        ans += O[i]
        ans += E[i]
else:
    for i in range(len(E)):
        ans += O[i]
        ans += E[i]
    ans += O[-1]
print(ans)

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << "\n";
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define endl "\n"
// gcj print用
#define Case(x) printf("Case #%d: ", x);

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<int>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<vector<vector<PI>>> vvvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<vector<vector<PLL>>> vvvpl;

int POWINT(int x, int n) {
  int ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

ll POWLL(ll x, int n) {
  ll ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

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

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

void print() {
  cout << endl;
}

template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
}

template <class T>
void print(vector<T> &vec, ll k){
   ll n = vec.size();
   k = min(k, n);
   rep(i, 0, k-1) cout << vec[i] << " ";
   cout << vec[k-1] << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
    print(vec);
  }
}

template<class T, class U>
void print(pair<T,U> &p){
  cout << p.first << " " << p.second << "\n";
}

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

  int N;
  cin >> N;
  vl A1(N);

  map<ll, ll> mp;
  ll ans = 0;

  rep(j, 0, N) {
    ll a;
    cin >> a;
    A1[j] = a+j;
    ans += mp[j-a];
    mp[a+j]++;
  }

  cout << ans << endl;

  return 0;
};


Measured memory_bytes: 27400
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, K;
  cin >> N >> K;
  vector<vector<int>> vec(N,vector<int>(2));
  for(int i=0; i<N; i++){
    for(int j=1; j>=0; j--){
      cin >> vec.at(i).at(j);
    }
  }
  sort(vec.rbegin(),vec.rend());
  map<int,bool> mp;
  priority_queue<int> PQ;
  int64_t ans = 0;
  
  for(int i=0; i<K; i++){
    int x = vec.at(i).at(0);
    int y = vec.at(i).at(1);
    if(mp.count(y)){
      PQ.push(-1*x);
    }
    else{
      mp[y] = true;
    }
    ans += x;
  }
  int64_t M = mp.size();
  
  vector<int> chance(0);
  for(int i=K; i<N; i++){
    int x = vec.at(i).at(0);
    int y = vec.at(i).at(1);
    if(mp.count(y)){
      continue;
    }
    else{
      chance.push_back(x);
      mp[y] = true;
    }
  }
  int64_t ans_x = ans;
  int64_t ans_c = ans + M*M;
  
  
  for(int i=0; i<chance.size(); i++){
    if(!PQ.size()){
      break;
    }
    int a = PQ.top();
    PQ.pop();
    M++;
    ans += chance.at(i) + a;
    ans_x = M*M + ans;
    ans_c = max(ans_c,ans_x);
  }
  cout << ans_c << endl;
}

Measured memory_bytes: 10620
#include <iostream>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

int main(int argc, const char * argv[]) {
  
  char b;
  cin >> b;
  if (b == 'A') {
    cout << 'T' << endl;
  }else if (b == 'T'){
    cout << 'A' << endl;
  }else if (b == 'C'){
    cout << 'G' << endl;
  }else{
    cout << 'C' << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
N = gets.to_i
xs = N.times.map{gets.split.map(&:to_i)}
ans = 0
xs.permutation(N) do |es|
    es.each_cons(2) do |a,b|
        ans += ((a[0]-b[0])**2 + (a[1]-b[1])**2)**(0.5)
    end
end
puts ans/((1..N).to_a.inject(&:*))


Measured memory_bytes: 2172
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

struct Edge {
    ll to, id;
};

vector<vector<Edge>> G;
vl ans;

void dfs(ll v, ll color = -1, ll p = -1) {

    ll num = 1;
    rep(i, G[v].size()) {

        ll u = G[v][i].to;
        ll ei = G[v][i].id;

        if(u == p) {
            continue;
        }

        if(num == color) {
            num++;
        }

        ans[ei] = num;
        num++;

        dfs(u, ans[ei], v);
    }

}

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

    G.resize(n);
    ans.resize(n-1);

    rep(i, n-1) {
        ll a, b;
        cin >> a >> b;
        a--;  b--;
        G[a].push_back((Edge){b,i});
        G[b].push_back((Edge){a,i});
    } 
    
    dfs(0);

    ll K = 0;
    rep(i, n) {
        chmax(K, (ll)G[i].size());
    }

    out(K);

    rep(i, n-1) {
        out(ans[i]);
    }

    re0;
}

Measured memory_bytes: 9728
def ii():return int(input())
def mi():return map(int,input().split())

a=[]
for _ in range(3):
  a+=list(mi())
n=ii()
b=[]
for i in range(n):
  b+=ii(),

def ana(x):
  if x in b:
    return 1
  else:
    return 0

c=[ana(aa) for aa in a]

oks="012 345 678 036 147 258 048 246".split()

for ok in oks:
  res=1
  for j in list(ok):
    res*=c[int(j)]
  if res==1:
    print("Yes")
    exit()
print("No")
      

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define dbg(x) cout<<#x" = "<<(x)<<ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

// dp[i]が0でないとき、i番目の頂点から距離dp[i]以内の頂点は既に何かの色で塗ってあることを表す 0ならまだ何色でも塗ってない
int n, m, a, b, q, v[114514], d[114514], c[114514], p[114514], dp[114514];
vi e[114514];

void paint(int v, int d, int c) {
	if (!p[v]) p[v] = c;
	if (dp[v]>=d) return;
	dp[v] = d;
	rep(i,e[v].size()) paint(e[v][i], d-1, c);
}

int main() {
	cin >> n >> m;
	rep(i,m) {
		cin >> a >> b;
		e[a].pb(b), e[b].pb(a);
	}
	cin >> q;
	rep(i,q) cin >> v[i] >> d[i] >> c[i];
	// クエリを逆に見れば色の上書きをしなくて済む
	// dpも使って枝刈り
	repr(i,q-1) paint(v[i], d[i], c[i]);
	repst(i,1,n) cout << p[i] << ln;
}

Measured memory_bytes: 8952
#include "stdio.h"

int num;
int a[100000];
int log[100000];

int main(void){
	int N;
	int i, j;
	int cnt = 0;

	scanf("%d", &N);

	for(i=0;i<N;i++){
		scanf("%d", &num);
		if(num>100000){
			cnt++;
			continue;
		};

		for(j=0;j<N;j++){
			if(a[j]==0||a[j]==num){
				log[j]++;
				a[j] = num;
				break;
			}
		}
	}

	for(j=0;j<N;j++){
		if(log[j]>=a[j]){
			cnt += log[j]-a[j];
		}
		else
		{
			cnt += log[j];
		}
	}

	printf("%d\n", cnt);
	return 0;
}

Measured memory_bytes: 128
use std::io::Read;
use itertools::Itertools;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let mut n: usize = iterator.next().unwrap().parse().unwrap();

    let mut result = String::new();
    while n > 0 {
        n -= 1;
        let amari = n % 26;
        let c = ('a' as u8 + amari as u8) as char;
        result.push(c);
        n /= 26;
    }

    let result = result.chars().rev().map(|c| c.to_string()).join("");
    return result;
}


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

using namespace std;
 
#define IOS		    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ld 		    long double
#define ll 		    long long int
#define ull 	   	    unsigned long long int
#define pb		    push_back
#define mp		    make_pair
#define F		    first
#define S		    second
#define lb		    lower_bound
#define ub		    upper_bound
#define deb(x)      	    cout<<"#x "<<x<<"\n";
#define trace(x,y)  	    cout<<"#x "<<x<<" #y "<<y<<"\n";
#define cn          	    cout<<"\n";


bool SBF(const pair <int,int>& a, const pair<int,int>& b){return a.F<b.F;}
bool SBS(const pair <int,int>& a, const pair<int,int>& b){return a.S<b.S;}


const long double PI  = 3.1415926535;
const long long   mod = 1e9+ 7; 
const int 	  mxN = 1000;
const long long   INF = 1e9;









int n , a, b;


void solve(){
 
	cin >> n;
	if(n <1200)cout<<"ABC\n";
	else cout<<"ARC\n";
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) ;
#define MOD 1000000007
#define int long long 
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vpii vector<pair<int,int>>
#define ff first
#define ss second
#define INF (1LL<<61)

using namespace std;

int n ;
int a[100010][3];
int dp[100010][3];



int32_t main(){   

fastio
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt","w", stdout);
// #endif

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

dp[1][0] = a[1][0];
dp[1][1] = a[1][1];
dp[1][2] = a[1][2];
for(int i =2 ; i<=n ; i++){
    dp[i][0] = max(a[i][0] + dp[i-1][1] , a[i][0] + dp[i-1][2]);
    dp[i][1] = max(a[i][1] + dp[i-1][0] , a[i][1] + dp[i-1][2]);
    dp[i][2] = max(a[i][2] + dp[i-1][1] , a[i][2] + dp[i-1][0]);
}

cout<<max({dp[n][0] , dp[n][1] , dp[n][2]})<<'\n';




return 0;
}


Measured memory_bytes: 8292
#define _USE_MATH_DEFINES

#include <bits/stdc++.h>

#define len(x) (int)((x).size())
#define endl '\n'
#define x first
#define y second
#define int long long
#define all(a) (a).begin(), (a).end()
#ifdef LOCAL
	#define dbg(x) cout << #x << " = " << x << endl;
#else 
	#define dbg(x)
#endif 

using namespace std;

void solve(); signed main() {
#ifdef LOCAL
    freopen("file1.txt", "r", stdin);                                       
    freopen("file2.txt", "w", stderr);
#endif
    srand(time(0));
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(6);
    solve();
}                         

void solve() {                                                                                         
	int n;
	cin >> n;
	vector<int> p(n), id(n + 1);
	for (int i = 0; i < n; ++i) {
	 	cin >> p[i];
	 	id[p[i]] = i;
	}

	multiset<int> set;
	set.insert(-1); set.insert(-1);
	set.insert(n); set.insert(n);
	
	int ans = 0;
	for (int num = n; num >= 1; --num) {
		int i = id[num];
		auto it = set.upper_bound(i);
		int e1 = *it;
		it++;
		int e2 = *it;
		it--; it--; 
		int s1 = *it;
		it--;
		int s2 = *it;
		dbg(s2 << " " << s1 << " " << e1 << " " << e2);
		ans += num * ((e2 - e1) * (i - s1) + (s1 - s2) * (e1 - i));
		set.insert(i);
	}

	cout << ans << endl;
		
}               	

Measured memory_bytes: 6528
import sys
from networkx.utils import UnionFind
def input(): return sys.stdin.readline().rstrip()


def main():
    n,m=map(int, input().split())
    lang=[[] for i in range(m+1)]
    for i in range(1,n+1):
        for talk in list(map(int, input().split()))[1:]:
            lang[talk].append(i)
    uf = UnionFind()
    for langs in lang:
        if len(langs) >=1:
            uf.union(*langs)
    print('YES' if len(list(uf.to_sets()))==1 else 'NO')
    




if __name__ == '__main__':
    main()


Measured memory_bytes: 81148
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
using namespace std;
using ll = long long;
const int INF = +100100100;
typedef pair<ll,int> P;
const ll MO = 1000000007;

const vector<int> dx = {-1,0,1,0};
const vector<int> dy = {0,-1,0,1};


int main(){
    int h, w;
    cin >> h>> w;
    vector<string> s(h);
    rep(i,h)cin>>s[i];
    // rep(i,h){
    //     cout <<"s size: "<< s[i].size() << endl;
    // }
    int maxi = -1*INF;
    rep(i,h){
        rep(j,w){
            if(s[i][j]=='#')continue;
            queue<P> q;
            vector<vector<int>> d(h,vector<int>(w,INF));
            auto push = [&](int pi, int pj, int c){
                if(d[pi][pj]!=INF || s[pi][pj]=='#')return;
                q.emplace(pi,pj);
                d[pi][pj]=c;
            };
            push(i,j,0);
            // cout << i << " j:" << j << endl;
            while(!q.empty()){
                int si,sj;
                si = q.front().first;sj=q.front().second;
                // cout << si << " :sj" << sj << endl;
                q.pop();
                rep(dir,4){
                    int y = si+dx[dir];
                    int x = sj+dy[dir];
                    // cout << "x:" << x << "y:" << y << endl;
                    
                    if(x<0||x>=w||y<0||y>=h)continue;
                    if(s[y][x]=='#')continue;
                    // cout << s[y][x] << endl;
                    // cout << "here" << endl;

                    push(y,x,d[si][sj]+1);
                    maxi=max(d[si][sj],maxi);
                }
            }
        }
    }
    cout << maxi << endl;
    return 0;

}

Measured memory_bytes: 384