akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define print(n) cout<<n<<endl
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vector<ll>>
#define vvi vector<vector<int>>
const int M=200111;
const int inf=1000000007;
const int MOD=1000000007;
const double PI = 3.1415926535897932384626433;
const long long INF=1e18;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};


struct UnionFind {
	vector<int> par;
	UnionFind(int n) : par(n, -1) { }

	int root(int x) {
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool same(int x, int y) {
		return root(x) == root(y);
	}

	bool merge(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y); // merge technique
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x) {
		return -par[root(x)];
	}
};

vvl comb(int n) {
	vvl v(n + 1,vl(n + 1, 0));
	for (int i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int j = 1; j < v.size(); j++) {
		for (int k = 1; k < j; k++) {
			v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
		}
	}
	return v;
}

void sosu(ll x,bool f[]){
	ll y=x;
	for(ll i=2;i<=sqrt(y);i++){
		if(x%i==0){
			x/=i;
			f[i]=true;
			i--;
		}
	}
}

ll __gcd(ll x,ll y){
	if(x<y)swap(x,y);
	while(1){
		ll tmp=x%y;
		x=y;
		y=tmp;
		if(y==0)break;
	}
	return x;
}

int keta(ll a){
	int ke=1;
	while(a/=10)ke++;
	return ke;
}

vector<long long> enum_divisors(long long N) {
	vector<long long> res;
	for (long long i = 1; i * i <= N; ++i) {
		if (N % i == 0) {
			res.push_back(i);
			// 重複しないならば i の相方である N/i も push
			if (N/i != i) res.push_back(N/i);
		}
	}
	// 小さい順に並び替える
	sort(res.begin(), res.end());
	return res;
}

ll zyou(ll x,ll n){
	ll y=1;
	rep(i,0,n){
		y*=x;
	}
	return y;
}

int ans=0;
int n,m,h[M],a,b;
vi g[M];
void tansaku(ll look){
	bool f=true;
	for(auto next:g[look]){
		if(h[look]<=h[next]){
			f=false;
			break;
		}
	}
	if(f)ans++;
//	if(f)print(h[look]);
}


int main() {
	cin>>n>>m;
	//1-index.
	rep(i,1,n+1)cin>>h[i];
	rep(i,0,m){
		cin>>a>>b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	rep(i,1,n+1)tansaku(i);
	print(ans);




}

Measured memory_bytes: 11596
while True:
    H,W = list(map(int,input().split(" ")))
    if H == 0 and W == 0:
        break
    else:
        for i in range(H):
            if i % 2 == 0:#0行目、2行目。。
                rec = ""
                for j in range(W):
                    if j % 2 == 0:#0個め、2個目、、
                        rec += "#"
                    else:
                        rec += "."
                print(rec)
            else:
                rec = ""
                for j in range(W):
                    if j % 2 == 0:#0個め、2個目、、
                        rec += "."
                    else:
                        rec += "#"
                print(rec)
        print("")


Measured memory_bytes: 5616
/**
 *      ///----- My Info -----///
 *      Code by: Unk
 *      Codeforces User: Ernest0_0Abreu
 *      Country: Cuba
 *      E-mail: ernestoabreup@gmail.com
 *      CopyRight
**/
#include <bits/stdc++.h>
#ifdef Ernest0_0Abreu 
#include <debug/to_string.h>
#endif
#pragma GCC optimize("Ofast")
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using namespace std;
        ///----- My Template -----///
///===================================================================================================================================
/// Debug
#define _end cout << "\n"
#ifndef Ernest0_0Abreu
#define db(x) ;
#define dbrange(x,begin,end) ;
#define dbname(x) ;
#define dbnamerange(x,begin,end) ;
#define dbmat(x,begin_n,end_n,begin_m,end_m) ;
#define dbST(x,end) ;
#define db_end ;
#endif
///Function
#define pi ( acos(-1) )
#define lg2(x) ( 31-__builtin_clz(x) )
#define lgx(x,n) ( log(n) / log(x) )
/// Macros
#define fst first
#define scd second
#define left (node<<1)
#define right ((node<<1)+1)
#define _sz(x) (int)(x.size())
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
/// Typedef
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/// Constant
const int MAXN = 1e6+7;
const int MOD = 1e9+7;
const ull BASE = 311;
const ld EPS = 1e-9;
const int INF = ((1<<30)-1);
const ll INFLL = ((1ll<<62ll)-1ll);
const ll oo = 2e18;
/// Hash Prime Numbers: 2, 277, 293, 307, 331, 337, 1009, 2027, 3079, 10079;
/// Module Prime Numbers: 3, 200017, 1000033, 998244353, 1000000007, 1000000009, 1000000021;
#define int long long
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
///===================================================================================================================================
        ///----- My code -----///

int a[10], b[10], p[10];

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

	int N;
	cin >> N;
	for(int i = 1; i <= N; ++i)
		cin >> a[i];
	for(int i = 1; i <= N; ++i)
		cin >> b[i];
	for(int i = 1; i <= N; ++i)
		p[i] = i;

	int cnt = 0, A, B;
	do{
		bool mka = true, mkb = true;
		cnt++;
		for(int i = 1; i <= N; ++i){
			if(p[i] != a[i]) mka = false;
			if(p[i] != b[i]) mkb = false;
		}
		if(mka) A = cnt;
		if(mkb) B = cnt;

	}while(next_permutation(p+1,p+N+1));

	cout << abs(A-B);

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001001001;

int main(){
  int n;cin>>n;
  string s,t;cin>>s>>t;
  string a;
  
  rep(i,n){
    a+=s.at(i);
    a+=t.at(i);
  }
  
  cout<<a<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<ctype.h>
#include<string>
#include<cmath>
using namespace std;

class Dice{
    private:
    int face[7];
    
    public:
    
    void SetFace(){
        for(int i=1;i<sizeof(face)/sizeof(int);++i){
            cin>>face[i];
        }
    }
    void Up(){
        int buf=face[1];
        face[1]=face[2];
        face[2]=face[6];
        face[6]=face[5];
        face[5]=buf;
    }
    void Down(){
        int buf=face[1];
        face[1]=face[5];
        face[5]=face[6];
        face[6]=face[2];
        face[2]=buf;
    }
    void Right(){
        int buf=face[1];
        face[1]=face[4];
        face[4]=face[6];
        face[6]=face[3];
        face[3]=buf;
    }
    void Left(){
        int buf=face[1];
        face[1]=face[3];
        face[3]=face[6];
        face[6]=face[4];
        face[4]=buf;
    }
    void RightRolling(){
        int buf=face[2];
        face[2]=face[3];
        face[3]=face[5];
        face[5]=face[4];
        face[4]=buf;
    }
    void Rolling(char d){
        if(d=='N'){
            Up();
        }
        else if(d=='S'){
            Down();
        }
        else if(d=='E'){
            Right();
        }
        else if(d=='W'){
            Left();
        }
        else if(d=='R'){
            RightRolling();
        }
    }
    int GetFaceNum(int i){
        return face[i];
    }
};

Dice dice;
int q;
int main(){
    dice.SetFace();
    cin>>q;
    for(int i=0;i<q;++i){
        int face1Num,face2Num;
        cin>>face1Num>>face2Num;
        while(1){
            if(dice.GetFaceNum(1) == face1Num)break;
            for(int j=2;j<=6;++j){
                if(dice.GetFaceNum(j) == face1Num){
                    if(j==2 || j==5 || j==6){
                        dice.Up();
                    }
                    else{
                        dice.Right();
                    }
                }
            }
        }
        while(1){
            if(dice.GetFaceNum(2) == face2Num)break;
            for(int j=3;j<=5;++j){
                dice.RightRolling();
            }
        }
        cout<<dice.GetFaceNum(3)<<endl;
    }
    return 0;
}



Measured memory_bytes: 3064
#include <iostream>
#include <set>
#include <bitset>
using namespace std;
enum dim{
    x = 0,
    y,
    z,
    size,
};


class Signs {
public:
    static size_t constexpr size = 1 << dim::size;
private:
    bitset<dim::size> signs[size];
public :
    Signs() {
        size_t i = 0;
        for (bitset<dim::size>& target : signs) {
            target = i;
            i++;
        }
    }

    bitset<dim::size> const& operator[](size_t const i) const {return signs[i];}
};

class Point {
    int64_t p[dim::size];
public:
    Point(int64_t x, int64_t y, int64_t z) {p[dim::x] = x, p[dim::y] = y, p[dim::z] = z;}

    int64_t GetTotal(bitset<dim::size> const& sign) const {
        int64_t val = 0;
        for (size_t i = 0; i < dim::size; i++) val += sign[i] ? p[i]  : -p[i];
        return val;
    }
};

class Bests {
    multiset<int64_t> bests;
    size_t num;
public :
    Bests(size_t const M = 0) : num(M) {}
    bool insert(int64_t val) {
        bool const inserted = bests.size() < num || (*bests.cbegin() < val);
        if (inserted) bests.insert(val);
        if (num < bests.size()) bests.erase(bests.begin());
        return inserted;
    }

    int64_t GetTotal() const {
        int64_t ret = 0;
        for (multiset<int64_t>::const_iterator ite = bests.cbegin(); ite != bests.cend(); ite++) {ret += *ite;}
        return ret;
    }
};

int main() {
    size_t N, M;
    cin >> N >> M;
   
    Signs signs;
    Bests bests[signs.size];
    
    for (Bests& target : bests) target = Bests(M);
    int64_t x, y, z;
    size_t last_idx = M - 1;
    for(size_t i = 0; i < N; i++) {
        cin >> x >> y >> z;
        Point p(x, y, z);
        
        for (size_t j = 0; j < signs.size; j++) {
            int64_t const total = p.GetTotal(signs[j]);
            bests[j].insert(total);
        }
    }
    
    int64_t ret = 0;
    for (Bests const& target : bests) {
        int64_t const val = target.GetTotal();
        ret = max<int64_t>(ret, val);
    }

    cout << (int64_t)ret << endl;
    return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
  
#define REP(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) REP(i,0,n)
#define INF (1<<30)
#define INFLL (1LL<<62LL)
  
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
  
int dx[8] = {0, 1, 0, -1, 1, -1, 1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, -1, 1};
  
#define DOWN   0
#define RIGHT 1
#define UP       2
#define LEFT   3
  
struct State {
    int x, y;
    int mem;
    int dir;
  
    State() :
            x(0),
            y(0),
            mem(0),
            dir(RIGHT) {}
  
    State(int x, int y, int mem, int dir) :
            x(x),
            y(y),
            mem(mem),
            dir(dir) {}
  
    bool operator<(const State & rhs) const {
        if (x == rhs.x && y == rhs.y && mem == rhs.mem) return dir < rhs.dir;
        if (x == rhs.x && y == rhs.y) return mem < rhs.mem;
        if (x == rhs.x) return y < rhs.y;
        return x < rhs.x;
    }
};
  
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int R, C;
    cin >> R >> C;
    vector<string> prog(R);
    rep(i, R) cin >> prog[i];
  
    set<State> visited;
    queue<State> Q;
    ll ok = false;
  
    Q.push(State());
    while (!Q.empty()) {
        State st = Q.front();
        Q.pop();
  
        st.x = (st.x + C) % C;
        st.y = (st.y + R) % R;
  
        if (visited.find(st) != visited.end())
            continue;
          
        visited.insert(st);
  
        char p;
        p = prog[st.y][st.x];
  
        if (p == '@') {
            ok = true;
            break;
        }
  
        switch (p) {
            case '0'...'9':
                st.mem = p - '0';
                break;
            case '_':
                if (st.mem == 0) st.dir = RIGHT;
                else st.dir = LEFT;
                break;
            case '|':
                if (st.mem == 0) st.dir = DOWN;
                else st.dir = UP;
                break;
            case '+':
                st.mem = (st.mem + 1) % 16;
                break;
            case '-':
                st.mem = st.mem - 1;
                if (st.mem < 0) st.mem += 16;
                break;
            case '^':
                st.dir = UP;
                break;
            case 'v':
                st.dir = DOWN;
                break;
            case '<':
                st.dir = LEFT;
                break;
            case '>':
                st.dir = RIGHT;
                break;
        }
  
        if (p != '?') {
            Q.push(State(st.x + dx[st.dir], st.y + dy[st.dir], st.mem, st.dir));
        } else {
            Q.push(State(st.x + dx[LEFT],     st.y + dy[LEFT],   st.mem, LEFT));
            Q.push(State(st.x + dx[RIGHT],   st.y + dy[RIGHT], st.mem, RIGHT));
            Q.push(State(st.x + dx[UP],         st.y + dy[UP],       st.mem, UP));
            Q.push(State(st.x + dx[DOWN],     st.y + dy[DOWN],   st.mem, DOWN));
        }
    }
      
    if (ok) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 4772
#include <bits/stdc++.h>
#define MAXN 2550
#define pii pair<int, int>
#define ff first
#define ss second
#define ll long long
#define in_range(x, y, n) (x >= 0 and x < n and y >= 0 and y < n)
using namespace std;
const ll mod = 1e9 + 7;


int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;

    vector<int> v(n);

    for (int& x: v) cin >> x;

    ll ans = 0;

    for (int i=0; i<n; i++){
        for (int j=i+1; j<n; j++){
            ans+= v[i]*v[j];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3564
# def makelist(n, m):
# 	return [[0 for i in range(m)] for j in range(n)]

# n = int(input())
# a, b = map(int, input().split())
# s = input()



a, b, c = map(int, input().split())

def check(n):
	return n % 2 == 0

if check(a) or check(b) or check(c):
	print(0)
else:
	tmp = min(a*b, b*c)
	tmp = min(tmp, c*a)
	print(tmp)


Measured memory_bytes: 3064
#include<cstdio>

int main(void){
int i,j;
bool card[4][13];
for(i=0;i<4;i++){
	for(j=0;j<13;j++){
		card[i][j]=true;
	}
}
int n;
scanf("%d",&n);
//printf("%d\n",n);
char s[n][10],c[n];
int a[n];
int x[n];
for(i=0;i<n;i++){
	scanf("%s",s[i]);
	//printf("%s\n",s[i]);
	scanf("%d",&a[i]);
	a[i]--;
	//printf("%d\n",a[i]);
	c[i]=s[i][0];
	//printf("%c\n",c[i]);	
	//printf("a[%d]=%d\n",i,a[i]);
	if(c[i]=='S'){
		x[i]=0;
	}else if(c[i]=='H'){
		x[i]=1;
	}else if(c[i]=='C'){
		x[i]=2;
	}else if(c[i]=='D'){
		x[i]=3;
	}
	card[x[i]][a[i]]=false;
}
for(j=0;j<13;j++){
	if (card[0][j]==true){
		printf("S %d\n",j+1);
	}
}
for(j=0;j<13;j++){
	if(card[1][j]==true){
		printf("H %d\n",j+1);
	}
}
for(j=0;j<13;j++){
	if(card[2][j]==true){
		printf("C %d\n",j+1);
	}
}
for(j=0;j<13;j++){
	if(card[3][j]==true){
		printf("D %d\n",j+1);
	}
}
return 0;
}

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

int main() {
	int N;
	cin >> N;
	vector<int> v(N);
	rep(i, N) {
		cin >> v.at(i);
	}

	vector<int> dp(N);
	dp[1] = abs(v[1]-v[0]);
	rep2(i, N) {
		dp[i] = min(dp[i-1] + abs(v[i]-v[i-1]), dp[i-2] + abs(v[i]-v[i-2]));
	}
	cout << dp[N-1] << '\n';
}


Measured memory_bytes: 3980
/*
 * author :Sadik Hassan
 *  
 * created : 21.01.2020 17:28:06
 * 
 * 
 * 
*/
#include "bits/stdc++.h"
using namespace std;
#define ll            long long
#define nl            "\n"
#define PB            push_back
#define fi            first
#define se            second
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define rep(i,n)      for(int i=0;i<n;i++)
#define repn(i,n)     for(int i=1;i<=n;i++)
#define rrep(i,n)     for(int i=n-1;i>=0;i--)
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
const int N = 1e9+10;

int main()
{
    _SAD()
    string s,ss="CODEFESTIVAL2016";
	int cnt=0;
	cin>>s;
	for(int i=0;i<SZ(s);i++)
	{
		if(s[i]!=ss[i])
		{
			cnt++;
		}
	}
	cout<<cnt<<nl;
    return 0;
}


Measured memory_bytes: 256
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
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<class Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion


void Main();
void solve(long long N, long long M, long long K, std::vector<long long> A, std::vector<long long> B);

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

void Main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    std::vector<long long> B(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&B[i]);
    }
    solve(N, M, K, std::move(A), std::move(B));
}

void solve(long long N, long long M, long long K, std::vector<long long> A, std::vector<long long> B){
    vec<ll> RA(N+1), RB(M+1);
    ll mn=LONG_LONG_MAX, mna_i=0;
    REP(i, N){
        RA[i + 1] = RA[i] + A[i];
        if(RA[i+1] <= K){
            mna_i = i + 1;
        }
    }
    REP(i, M){
        RB[i + 1] = RB[i] + B[i];
    }
    ll mx_cnt = 0;
    ll bnow = 0;
    REPR(i, mna_i){
        while(bnow+1 <= M && RA[i]+RB[bnow+1] <= K){
            bnow++;
        }
        chmax(mx_cnt, i+bnow);
    }
    cout << mx_cnt << el;
}



Measured memory_bytes: 9636
#include <iostream>

void swap(int& a,int& b);

using namespace std;

int main()
{
    int N,t[100];
    int num=0,m=0;
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>t[i];
    }
    for(int i=0;i<N;i++){
        m=i;
        for(int j=i+1;j<N;j++){
            if(t[m]>t[j]){
                m=j;
            }
        }
        if(i!=m){
            swap(t[i],t[m]);
            num++;
        }
    }
    cout<<t[0];
    for(int i=1;i<N;i++){
        cout<<" "<<t[i];
    }
    cout<<endl;
    cout<<num<<endl;
}
void swap(int& a,int& b)
{
    int c;
    c=a;
    a=b;
    b=c;
}

Measured memory_bytes: 1164
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

def test(x):
  return x % 2 == 1 and sum(x % y == 0 for y in range(1, x+1)) == 8

N = read()
print(sum(test(x) for x in range(1, N+1)))

Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define nl cout<<endl
#define MOD 1000000007
#define loop(i,start,end) for(ll i=start;i<end;i++)
#define N 100001
#define all(v) v.begin(),v.end()
#define oa(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" ";nl
#define ov(a) for(int i=0;i<a.size();i++)cout<<a[i]<<" ";nl
int main() 
{
    fastio();

    int k,x;
    cin>>k>>x;
    if(k*500>=x)
        cout<<"Yes";
    else cout<<"No";
    return 0;
}

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

ichi = str(x)
ichi = int(ichi[-1])

for i in range(1000):
  test = -(ichi - i)
  for j in range(100):
    for k in range(100):
#      print(test+j*10, i+k*10)
      if test+j*10**5 - i+k*10**5 == x:
        print(test+j*10, i+k*10)
        break
      elif (-1*test+j*10)**5 - (-1*i+k*10)**5 == x:
        print(-1*test+j*10, -1*i+k*10)
        break
    else:
      continue
    break
  else:
    continue
  break

Measured memory_bytes: 67764
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#include<queue>
#include <sstream>
#include <set>

const long long INF = 1000000007;
using namespace std;
typedef long long llong;

//int isalpha(char ch): ch がアルファベットなら true を返す
//int isdigit(char ch): ch が数字なら true を返す
//int islower(char ch): ch が小文字なら true を返す
//int isupper(char ch): ch が大文字なら true を返す
//int tolower(char ch): ch の小文字を返す
//int toupper(char ch): ch の大文字を返す

//string型
//size()	文字数を返す
//Insert()	（指定した場所に）文字・文字列を挿入する
//erase()	（指定した場所の）文字・文字列を削除する
//clear()	すべての文字を削除する
//substr()	文字列の（指定した）部分文字列を返す
//replace()	（指定した）部分文字列を新しい文字列に置換する
//c_str()変換
//文字列の比較は、<=や==などを使え
//replace関数を使い、簡単に文字列を置換
//リバース関数：reverse(str.begin(), str.end());
//map<type, type> dict;で宣言
//グラフ理論用変数
//vector<vector<llong> > graph(N);

//ソート
//降順sort(v.begin(), v.end(), std::greater<Type>());

//大文字から小文字へんかん
//w[i] = w[i]-'A'+'a';

//vector
//assignメソッド　引数：サイズ、値
//与えられたサイズと値でvectorを初期化する

//queueクラス
//find()次に取り出す値の表示をする。
//pop()値を取り出す。戻り値はなし
//push()キューに値をプッシュする

//priority_queueクラス

//切り上げ
//ceil
//floor

int main(){
    string S;
    cin >> S;
    llong ans=-1;
    llong cnt=0;
    for(int i=0; i<S.size(); i++){
        if(S[i]!='A'){
            continue;
        }
        cnt++;
        while(i<S.size()){
            cnt++;
            i++;
            if(S[i]=='Z'){
                ans = max(cnt, ans);
                continue;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))
#define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl))
#define deg2rad(x) (((x)*PI) / (180.0))
#define rad2deg(x) (((x) * (180.0)) / PI)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;
template <class T> using vec = vector<T>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);
template <class T> T mod(T a, T m);

int main(int argc, char* argv[]) {
  long long N;
  scanf("%lld", &N);
  long long T;
  scanf("%lld", &T);
  std::vector<long long> t(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &t[i]);
  }

  ll ans = T;
  rep(i, 1, N) {
    ll duration = t[i] - ((i == 0) ? 0 : t[i - 1]);
    ans += (duration <= T) ? duration : T;
  }

  put(ans);
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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

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

template <class T> inline T gcd(T a, T b) { return __gcd(a, b); }

template <class T> inline T lcm(T a, T b) {
  T c = min(a, b), d = max(a, b);
  return c * (d / gcd(c, d));
}

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}

template <class T> T mod(T a, T m) { return (a % m + m) % m; }


Measured memory_bytes: 1792
#include <cstdio>
#include <algorithm>
using namespace std;
#define INF 1000000
int C[15][15];
int main()
{
    int n;
    while(scanf("%d",&n),n)
    {
        for(int i=0;i<15;++i){
            for(int j=0;j<15;++j){
                C[i][j]=i==j?0:INF;
            }
        }
        int m=0;
        for(int i=0;i<n;++i){
            int a,b,c;
            scanf("%d%d%d",&a,&b,&c);
            m=max(m,max(a,b));
            C[a][b]=C[b][a]=c;
        }
        m++;
        for(int k=0;k<m;++k){
            for(int i=0;i<m;++i){
                for(int j=0;j<m;++j){
                    C[i][j]=min(C[i][j],C[i][k]+C[k][j]);
                }
            }
        }
        int ln=INF,lc=INF;
        for(int i=m-1;i>=0;--i){
            int c=0;
            for(int j=0;j<m;++j){
                c+=C[i][j];
            }
            if(c<=lc){
                ln=i;
                lc=c;
            }
        }
        printf("%d %d\n",ln,lc);
    }
    return 0;
}

Measured memory_bytes: 1028
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>

using namespace std;



int main()
{
    ios_base::sync_with_stdio(false);
    int N;
    cin>>N;
    long long K;
    cin>>K;
    vector<int> v(N);
    for(int c=0;c<N;c++) {
        cin>>v[c];
        v[c]--;
    }


    vector<int> cycles(N,-1);

    int current = 0;
    long long it = 0;
    while(it<K){


        if(cycles[current] != -1) {
            long long length = it-cycles[current];
            long long add = ((K - it)/length);
            add*=length;
            it += add;
        }
        cycles[current] = it;
        if(it == K) break;
        it++;
        current = v[current];
    }
    cout<<current+1;


}


Measured memory_bytes: 4840
<?php
error_reporting(0);
$A = trim(fgets(STDIN));
//$A = explode(" ",trim(fgets(STDIN)));
//list($N,$M) = explode(" ",trim(fgets(STDIN)));
if (strpos($A,"AC")!==false) {
  printf("Yes\n");
}
else {
  printf("No\n");
}


Measured memory_bytes: 3700
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include <functional>
#include <set>
using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

#define inf INT_MAX/3
#define INF INT_MAX/3
#define PB push_back
#define pb push_back
#define MP make_pair
#define mp make_pair
#define ALL(a) (a).begin(),(a).end()
#define all(a) (a).begin(),(a).end()
#define SET(a,c) memset(a,c,sizeof a)
#define CLR(a) memset(a,0,sizeof a)
#define PII pair<int,int>
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define pi 2*acos(0.0)
#define INFILE() freopen("in0.txt","r",stdin)
#define OUTFILE()freopen("out0.txt","w",stdout)
#define in scanf
#define out printf
#define LL long long
#define ll long long
#define ULL unsigned long long
#define ull unsigned long long
#define eps 1e-14
#define FST first
#define SEC second

set <int> D;
int N,K;

int main(){

	cin >> N >> K;

	REP(i,K){
		int a;
		cin >> a;
		D.insert(a);
	}

	bool flag = true;
	N--;
	while(flag){
		N++;
		int N1 = N;
		flag = false;
		while(N1>0){
			if(D.count(N1%10)){
				flag = true;
				break;
			}
			N1 /= 10;
		}
	}
	cout << N;
}

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

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

    vector<int> d(n);
    for(int i=0; i<n; i++){
        cin>>d[i];
    }
    
    sort(d.begin(),d.end());
   
    int count=0;
    
    /*for(int i=d[n]; i<d[n-1]+1; i++){
        int arc=0,abc=0;
        for(int j=0; j<n; j++){
            if(d[j]>=i){
                arc++;
            }else{
                abc++;
            }
        }
        if(arc==abc){
            count++;
        }
    }*/

    for(int i=d[(n-2)/2]+1; i<=d[n/2]; i++){
        count++;
    }

    cout<<count<<endl;
}

Measured memory_bytes: 640
/*
 Author: LargeDumpling
 Email: LargeDumpling@qq.com
 Edit History:
	2017-12-10	File created.
*/

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int MAXN=2000000;
int n,k,cnt[MAXN+50];
int main()
{
	int x,num=0;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&x);
		cnt[x]++;
	}
	sort(cnt+1,cnt+MAXN+1);
	for(int i=0;i<k;i++)
		num+=cnt[MAXN-i];
	printf("%d",n-num);
	fclose(stdin);
	fclose(stdout);
	return 0;
}


Measured memory_bytes: 8064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = "";

        while ((line = br.readLine()) != null && !line.isEmpty()) {
            char[] str = line.toCharArray();
            char c;
            int u;
            for (int i = 0; i < str.length / 2; i++) {
                c = str[i];
                u = str.length - 1 - i;
                str[i] = str[u];
                str[u] = c;
            }
            System.out.println(str);
        }
    }
}

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

int main(){
    string s; cin>>s;
    string ans="No";
    for(int i=0;i<s.length()-1;i++){
        if(s[i]=='A'&&s[i+1]=='B'){
            ans="Yes";
            break;
        }
        else if(s[i]=='B'&&s[i+1]=='A'){
            ans="Yes";
            break;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}


class RollingHash {
public:
	typedef pair<long long,long long> hash_type;
	long long base1, base2;
	long long mod1, mod2;
	vector<long long> hash1, hash2;
	vector<long long> pow1, pow2;

	RollingHash() {}
	RollingHash(const string &s) : base1(1009), base2(1007), mod1(1000000007), mod2(1000000009) {
		int n = s.size();

		hash1.assign(n + 1,0);
		hash2.assign(n + 1,0);
		pow1.assign(n + 1,1);
		pow2.assign(n + 1,1);

		rep(i,n){
			hash1[i + 1] = (hash1[i] + s[i]) * base1 % mod1;
			hash2[i + 1] = (hash2[i] + s[i]) * base2 % mod2;
			pow1[i + 1] = pow1[i] * base1 % mod1;
			pow2[i + 1] = pow2[i] * base2 % mod2;
		}
	}

	hash_type get(int l, int r) { // 区間[l,r)のハッシュ値を計算する
		long long t1 = ((hash1[r] - hash1[l] * pow1[r - l]) % mod1 + mod1) % mod1;
		long long t2 = ((hash2[r] - hash2[l] * pow2[r - l]) % mod2 + mod2) % mod2;
		return make_pair(t1, t2);
	}

	hash_type concat(hash_type h1, hash_type h2, int h2_len) {
		return make_pair((h1.first * pow1[h2_len] + h2.first) % mod1, (h1.second * pow2[h2_len] + h2.second) % mod2);
	}
};

RollingHash::hash_type getHash(string& s, int type){
	RollingHash hash(s);
	if(type == 0) return hash.get(1,s.size());
	if(type == 1) return hash.get(0,s.size() - 1);
	return hash.get(0,s.size());
}

int containQuest(const string& s){
	rep(i,s.size()){
		if(s[i] == '?') return i;
	}
	return -1;
}


void serarch(vector<int>& ans, map<RollingHash::hash_type, int >& h, string& s, int type, int idx){
	int p = containQuest(s);
	if(p == -1){
		ans[idx] += h[getHash(s, type)];
	}else{
		for (char i = 'a'; i <= 'z'; i++) {
			s[p] = i;
			ans[idx] += h[getHash(s, type)];
		}
		s[p] = '?';
	}
}

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

	vector<RollingHash> hash(n);
	vector<int> size(n), ans(m,0);
	rep(i,n){
		string s;
		cin >> s;
		hash[i] = RollingHash(s);
		size[i] = s.size();
	}

	vector<string> query(m);
	rep(i,m){
		cin >> query[i];
	}

	range(len,1,201){
		map<RollingHash::hash_type, int> h, rh, kh;
		rep(i,n){
			if(size[i] < len) continue;
			if(len == size[i]) kh[ hash[i].get(0,len) ]++;
			h[ hash[i].get(0,len) ]++;
			rh[ hash[i].get(size[i] - len, size[i]) ]++;
		}

		rep(i,m){
			string& s = query[i];
			if(s.front() == '*'){
				if(s.size() - 1 != len) continue;
				serarch(ans, rh, s, 0, i);
			}else if(s.back() == '*'){
				if(s.size() - 1 != len) continue;
				serarch(ans, h, s, 1, i);
			}else{
				if(s.size() != len) continue;
				serarch(ans, kh, s, 2, i);
			}
		}
	}

	for(auto i : ans) cout << i << endl;
	return 0;
}



Measured memory_bytes: 100460
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);  
	int t;
//	cin>>t;
//	while(t--!=0){
//		//template
//	}  	
	int a,b,c;
	cin>>a;
	cin>>b;
	cin>>c;
	int temp1=a;
	a=b;
	b=temp1;
	int temp2=a;
	a=c;
	c=temp2;
	cout<<a<<" "<<b<<" "<<c<<"\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define y1 zzz
#define fi first
#define se second
#define PII pair<int,int>
#define PII2 pair<int,PII >
#define PII3 pair<PII,int >
#define PII4 pair<PII,PII >
#define all(x) (x).begin(),(x).end()
#define pb push_back
int dp[410][410],sum[410],x,n;
int f(int l,int r)
{
     if(l==r)return 0;
     if(dp[l][r])return dp[l][r];
     dp[l][r]=1e18;
     for(int i=l;i<r;i++)
         dp[l][r]=min(dp[l][r],f(l,i)+f(i+1,r)+sum[r]-sum[l-1]);
     return dp[l][r];
}
void solve()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        sum[i]=sum[i-1]+x;
    }
    cout<<f(1,n);
}
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //freopen("XORQUERY.inp","r",stdin);
    //freopen("XORQUERY.out","w",stdout);
    //int t;cin>>t;while(t--)
    solve();
    return 0;
}


Measured memory_bytes: 1536
#include "bits/stdc++.h"
using namespace std;

int main() {
	int R, C;
	int A[110][110] = {};
	cin >> R >> C;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) {
			cin >> A[i][j];
			A[i][C] += A[i][j];
			A[R][j] += A[i][j];
			A[R][C] += A[i][j];
		}
	}
	for (int i = 0; i <= R; i++) {
		for (int j = 0; j <= C; j++) {
			if (j != 0) cout << " ";
			cout << A[i][j];
		}
		cout << endl;
	}
}


Measured memory_bytes: 3160
import java.util.*;

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

		Scanner sc=new Scanner(System.in);

		int a=sc.nextInt();
		int b=sc.nextInt();
		if(a>8 || b>8){
			System.out.println(":(");
		}else{
			System.out.println("Yay!");
		}


	}
}


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

typedef long long ll;

#define rep(i, n) for (int i = 0; i < (ll)n; ++i)
#define repr(i, n) for (int i = n - 1; i >= 0; --i)
#define INF 10e7
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
using namespace std;

void solve(void)
{
    int n;
    string s;
    cin >> n >> s;
    int cta = 0; //ctaは白の数
    rep(i, n) if (s[i] == '.') cta++;
    int ans = min(n - cta, cta);
    int b = 0, w = 0;
    rep(i, n - 1)
    {
        if (s[i] == '#')
            b++;
        else
            w++;
        if (s[i] != s[i + 1])
        {
            int x = b;
            int y = cta - w;
            ans = min(ans, x + y);
        }
    }
    cout << ans << endl;
}

int main(void)
{
    solve();
}


Measured memory_bytes: 3756
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using E = System.Linq.Enumerable;
 
class Program
 {
  static int[] A;
        static void Main(string[] args)
        {
          //入力を受け取る
          var NK = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
          var A = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
          var N = NK[0];
          var K = NK[1];
          
          var ans = 0L;
          var dic = new Dictionary<int,int>();
          for(int i = 0; i < N ; i++){
            if(dic.ContainsKey(A[i])){
              dic[A[i]] += 1;
            }else{
              dic.Add(A[i],1);
            }
          }
          
          var SortedDic = dic.Values.ToList();
          SortedDic = SortedDic.OrderBy(a => -a).ToList();;
          
          var sum =0;
          for(int i = 0; i < K && i < dic.Count();i++){
            //Console.WriteLine(SortedDic[i]);
            sum += SortedDic[i];
          }

          Console.WriteLine(N-sum);
        }
  
}


Measured memory_bytes: 42692
import java.util.*;
public class Main{
	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
        int[] arr = new int[n];
      for(int i=0;i<arr.length;i++){
          arr[i]=in.nextInt();
      }
      
      int[] dp = new int[n];
		for(int i=1;i<n;i++){
          if(i==1){
            dp[i]=Math.abs(arr[1]-arr[0]);
          }else{
              dp[i]=Math.min(Math.abs(arr[i]-arr[i-1])+dp[i-1], Math.abs(arr[i]-arr[i-2])+dp[i-2]);
          }
        }
      
     
      
      System.out.print(dp[n-1]);
      
      
	}
}

Measured memory_bytes: 50484
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	if len(a) == 1 {
		fmt.Println(1)
		return
	}

	ans := 1
	m := a[1] - a[0]
	for i := 1; i < n; i++ {
		if m == 0 {
			m = a[i] - a[i-1]
			continue
		}

		if a[i-1] == a[i] {
			continue
		}
		if (0 < m && a[i-1] > a[i]) || (m < 0 && a[i-1] < a[i]) {
			m = 0
			ans++
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 5504
from collections import deque


H, W = map(int, input().split())
maze = [list(input()) for _ in range(H)]

black = 0
for i in range(H):
    for j in range(W):
        if maze[i][j] == '#':
            black += 1


def bfs(s):
    q = deque()
    q.append(s)
    maze[s[0]][s[1]] = 1

    while len(q):
        x, y = q.popleft()

        for dx, dy in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
            nx = x + dx
            ny = y + dy

            if (nx, ny) == (H - 1, W - 1) and maze[nx][ny] == '.':
                return maze[x][y] + 1
            elif (0 <= nx < H) and (0 <= ny < W) and maze[nx][ny] == '.':
                maze[nx][ny] = maze[x][y] + 1
                q.append((nx, ny))

    return 0


if maze[0][0] == '.':
    step = bfs((0, 0))
    if step:
        print(H * W - black - step)
    else:
        print(-1)
else:
    print(-1)


Measured memory_bytes: 40304
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;

int main(){

    string str;
    cin >> str;

    int n = str.size();

    int cnttemp = 0;
    long long cnttotal = 0;
    for(int i=n-1; i>=0; i--){
        if(str[i] == 'W'){
            cnttemp++;
        }
        else{
            cnttotal += cnttemp;
        }
    }
    
    cout << cnttotal << endl;

    return 0;
}

Measured memory_bytes: 640
import collections
n = int(input())
d = list(map(int, input().split()))
D = collections.defaultdict(int)
for i in d:
    D[i] += 1
m = int(input())
t = list(map(int, input().split()))
T = collections.defaultdict(int)
for i in t:
    T[i] += 1
for k,v in T.items():
    if k not in D or D[k] < v:
        print('NO')
        exit()
print('YES')

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

using namespace std;
using ll = long long;

class UF{
private:
    std::vector<long long> data; //data[i] : 頂点iの親
public:
    UF(int n){
        data.resize(n,-1);
    }
    //頂点iの親を返す
    int root(int i){
        if(data[i] < 0)return i;
        else return data[i] = root(data[i]);
    }
    //連結
    void unit(int i,int j){
        i = root(i);j = root(j);
        if(i != j){
            data[i] += data[j];
            data[j] = i;
        }
    }

    //頂点iの属する集合の頂点数
    int size(int i){
        i = root(i);
        return -data[i];
    }
};

int main()
{
    int n, m;
    cin >> n >> m;
    vector<vector<int>> lang(m);
    for(int i = 0; i < n; i++) {
        int k; cin >> k;
        for(int j = 0; j < k; j++) {
            int t; cin >> t; t--;
            lang[t].push_back(i);
        } 
    }
    UF uni(n);
    for(auto j : lang) {
        int num = j.size();
        //cerr << "yay" << endl;
        for(int i = 1; i < num; i++)uni.unit(j[i - 1], j[i]);
    }
    set<int> st;
    for(int i = 0; i < n; i++) {
        st.insert(uni.root(i));
        //cerr << uni.root(i) << " ";
    }


    cout << ((int)st.size() == 1 ? "YES" : "NO") << endl;
}

Measured memory_bytes: 4608
def run(N, C, XV):
    '''
    左回りでxまで食べた後に、右回りのyまで食べると考える
    yは、xの次の皿まで食べることが可能なので、事前に最大
    となる食べ方を計算しておく
    逆回りも同様に計算して最大のものをとる
    '''
    # ある位置まで食べた時のカロリー
    cal_l = [0]
    cal_r = [0]
    # ある位置までの中で最大のカロリーとなるカロリー
    cal_max_l = [0]
    cal_max_r = [0]
    cal = 0
    for i in range(N):
        cal += XV[i][1]
        cal_l.append(cal-XV[i][0]*2)
        cal_max = cal_max_l[i]
        if cal_max < cal-XV[i][0]:
            cal_max = cal-XV[i][0]
        cal_max_l.append(cal_max)
    cal = 0
    for i in range(N):
        cal += XV[N-i-1][1]
        cal_r.append(cal-(C-XV[N-i-1][0])*2)
        cal_max = cal_max_r[i]
        if cal_max < cal-C+XV[N-i-1][0]:
            cal_max = cal-C+XV[N-i-1][0]
        cal_max_r.append(cal_max)

    ret = 0
    # 左回りが先
    for i in range(len(cal_l)):
        ret = max(ret, cal_l[i]+cal_max_r[N-i])
    # 右回りが先
    for i in range(len(cal_r)):
        ret = max(ret, cal_r[i]+cal_max_l[N-i])
    return ret


def main():
    N, C = map(int, input().split())
    XV = []
    for i in range(N):
        XV.append(list(map(int, input().split())))
    print(run(N, C, XV))


if __name__ == '__main__':
    main()


Measured memory_bytes: 43284
#include<iostream>
#include<vector>
#include<set>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<map>
#include<queue>
#include<iomanip>
#define INF 1e9
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
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; }
const int MOD = 1000000007;
void add(long long &a, long long b){
  a += b;
  if(a >= MOD){
    a -= MOD;
  }
}
using namespace std;

int H,W,K;
long long solve(){
  K--;
  vector<vector<long long>> dp(H+1,vector<long long>(W,0));
  dp[0][0] = 1;
  for(int i = 0; i < H; i++){
    for(int j = 0;j < W; j++){
      for(int bit = 0; bit < 1<<(W-1); bit++){
        bool ok = true;
        for(int k=0;k<W-2;k++){
          if((bit & (1<<k)) && (bit & (1<<(k+1)))){
            ok = false;
          }
        }
        if(!ok){
          continue;
        }
        int nj = j;
        if( bit & (1 << j) ){
          nj = j + 1;
        }
        else if(j > 0 && (bit & (1 << (j-1)))){
          nj = j - 1;
        }
        add(dp[i+1][nj],dp[i][j]);
      }
    }
  }
  return dp[H][K];
}

signed main(){
  cin >> H >> W >> K;
  cout << solve() << endl;
  return 0;
}


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

#define print(x) cerr << #x << " is " << x << endl;
#define int long long int
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vpi vector<pair<int, int>>
#define all(v) (v).begin(), (v).end()
#define pii pair<int, int>
#define pb push_back
#define eb emplace_back
#define PI 3.1415926535897932384626
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define out cout << fixed << setprecision(12) <<

const int N = 2e5 + 10;
const int mod = 1e9 + 7;

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

    int a, b, c, d;
    cin >> a >> b >> c >> d;

    int a1, b1, c1, d1;

    a1 = a;
    int cnt = 0;
    while(a1 > 0){
        cnt++;
        a1 -= d;
    }
    int cnt2 = 0;
    c1 = c;
    while(c1 > 0){
        cnt2++;
        c1 -= b;
    }

    if(cnt >= cnt2){
        cout << "Yes\n";
    }
    if(cnt < cnt2){
        cout << "No\n";
    }
    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using ll = long long;
const int MOD = 1000000007;
#define rep(i,n) for (ll i=0; i < (n); i++)
using namespace std;
int get_gcd(int a, int b) {
  while(1) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    a %= b;
  }
}
int get_lcm(int a, int b){return a * b / get_gcd(a, b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

main () {
  int a, b;
  scanf("%d %d", &a, &b);

  int sashikomiguchi = 1;
  int ans = 0;
  while(sashikomiguchi < b) {
    ans++;
    sashikomiguchi += a - 1;
  }

  printf("%d\n", ans);

  return 0;
}


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

int main(){
    int n; //<=4000
    string s;
    cin >> n;
    cin >> s;
    long long ans = 0;

    vector<char> color = {'R', 'G', 'B'};
    vector<int> count(3);
    vector<vector<int>> vec = {{}, {}, {}};

    for (int i = 0; i < n; ++i){
        for (int j = 0; j < 3; ++j){
            if (s[i] == color.at(j)){
                count.at(j)++;
            }
        }
        for (int j = 0; j < 3; ++j){
            vec.at(j).push_back(count.at(j));
        }
    }

    for (int i = 0; i < n; ++i){
        char I = s[i];
        for (int j = i+1; j < n; ++j){
            char J = s[j];
            if (I != J){
                for (int k = 0; k < 3; ++k){
                    if (I != color.at(k) && J != color.at(k)){
                        ans += (vec.at(k).at(n-1) - vec.at(k).at(j));
                        if (2*j-i <= n-1){
                            if (color.at(k) == s[2*j-i]){
                                ans--;
                            }
                        }
                    }
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3720
#include <iostream>
using namespace std;
const int HW_MAX = 100;
int main (void) {
    int H, W;
    string s[HW_MAX];

    cin >> H >> W;
    for (int i = 0; i < H; i++) cin >> s[i];

    for (int i = 0; i < W + 2; i++) cout << "#";
    cout << endl;
    for (int i = 0; i < H; i++) {
        cout << "#";
        cout << s[i];
        cout << "#" << endl;
    }
    for (int i = 0; i < W + 2; i++) cout << "#";
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
def gcd(a, b):
    return a if b == 0 else gcd(b, a % b)


N = int(input())
a = map(int, input().split())

N_MAX = 1 << N.bit_length()

v = [0 for _ in range(2 * N_MAX - 1)]
# Segment Tree

for idx, aa in enumerate(a):
    idx += N_MAX - 1  # Segment Treeの葉ノードのIndexに変換
    v[idx] = aa
    while idx > 0:
        idx = (idx - 1) // 2  # 親ノードのIndexに変換
        v[idx] = gcd(v[idx * 2 + 1], v[idx * 2 + 2])  # ノードの値は、2つの子ノードの値の最大公約数

# print(v)

def query(a, b, k=0, l=0, r=N_MAX):
    # [a,b)の最大公約数
    # print(a, b, k, l, r)
    if r <= a or b <= l: return 0  # 交差しない
    if a <= l and r <= b: return v[k]  # 含まれる
    gcd_l = query(a, b, 2 * k + 1, l, (l + r) // 2)
    gcd_r = query(a, b, 2 * k + 2, (l + r) // 2, r)
    return gcd(gcd_l, gcd_r)


g = 0
for i in range(N):
    g = max(g, gcd(query(0, i), query(i + 1, N)))
print(g)


Measured memory_bytes: 90120