akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<string>
#include<cstring>
#include<utility>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<algorithm>
#include<vector>
#include<iostream>
#define ll long long
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define inf 0x7fffffff
using namespace std;
const int maxn=1e5+10;
pii b[maxn];
multiset<int> s;
ll sum()
{
	ll su=0;
	for(__typeof(s.begin()) it=s.begin();it!=s.end();it++)
	{
		su+=*it;
	}
	return su;
}
int main()
{
	int i,j,k,n,m,x,y;
	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++)
	{
		scanf("%d",&y);
		s.insert(y);
	}
	for(i=0;i<m;i++)
	{
		scanf("%d%d",&b[i].se,&b[i].fi);
		b[i].fi=-b[i].fi;
	}
	sort(b,b+m);
	for(i=0;i<m;i++)
	{
		b[i].fi=-b[i].fi;
	}
	x=0;
	for(i=0;i<m;i++)
	{
		for(j=0;j<b[i].se;j++)
		{
			if(x>n||*(s.begin())>=b[i].fi)
			{
				goto en;
			}
			s.erase(s.begin());
			s.insert(b[i].fi);
			x++;
		}
	}
	en:;
	printf("%lld",sum());
	return 0;
}

Measured memory_bytes: 5760
#include<iostream>
using namespace std;
int main(void) {
	int n;
	cin >> n;
	int l[200];
	for (int i(0); i < 2 * n; i++) {
		cin >> l[i];
	}
	for (int i(0); i < 2 * n-1; i++) {
		for (int j(i); j < 2 * n; j++) {
			if (l[i] > l[j])swap(l[i],l[j]);
		}
	}
	int sum(0);
	int cnt(0);
	for (int i(2*n-1); i >=0; i--) {
		if (i % 2 == 0) {
			sum += l[i];
			cnt++;
			if (cnt == n)break;
		}
	}
	cout << sum << 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;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
	int n, k, q;
	cin >> n >> k >> q;
	vector<int> a(q);
	rep(i, q) cin >> a[i];

	vector<int> b(n, 0);
	rep(i, q) b[a[i] - 1]++;

	rep(i, n) {
		if (k - (q - b[i]) > 0) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}

}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int n,k;
int ans=0;
vector<int> v;

void f(int m){
  int del=k-m;
 
  rep(i,m+1){
    int l=i,r=m-i;
    
    vector<int> a;
    rep(j,l){
      a.PB(v[j]);
    }
    for(int j=n-1;j>n-1-r;j--){
      a.PB(v[j]);
    }
    
    int res=0;
    sort(all(a));
    rep(j,m){
      res+=a[j];
    }
    ans=max(res,ans);
    rep(j,del){
      if(j>=a.size()) continue;
      res-=a[j];
      ans=max(res,ans);
    }
  }
}


main(){
  cin>>n>>k;
  v.resize(n);
  rep(i,n){
    cin>>v[i];
  }

  FOR(i,1,k+1){
    if(i>n) break;
    f(i);
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 256
def input_from_console():
    a, b, c, d = map(int, input().split())
    return a, b, c, d

def gcd(i,j):
    i, j = max(i,j), min(i,j)
    if i % j == 0:
        return j
    else:
        while i % j !=0:
            k = i % j
            i, j = j, k
        else:
            return k

def solve(a, b, c, d):
    def how_many(to, divide):
        if to >= divide:
            n = to // divide
        else:
            n = 0
        return n
    count_by_c = how_many(b, c) - how_many(a - 1, c)
    count_by_d = how_many(b, d) - how_many(a - 1, d)
    # print('gcd', int(c*d / math.gcd(c,d)))
    count_by_cd = how_many(b, int(c*d / gcd(c,d))) - how_many(a - 1, int(c*d / gcd(c,d)))
    result = b - a + 1 - (count_by_c + count_by_d - count_by_cd)
    # print(count_by_c,  count_by_d, count_by_cd)

    # print(result)
    return result

def main():
    a, b, c, d = input_from_console()
    print(solve(a, b, c, d))


if __name__ == "__main__":
    import sys

    if sys.gettrace():  # Check if the python interpreter is in debug mode or not.
        check_cases()
    else:
        main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define  N 200005
using namespace std;
struct edge{
	int t,next;
}e[N*2];int ecnt,head[N];
void addedge(int f,int t){
	e[++ecnt]=(edge){t,head[f]};head[f]=ecnt;
}

int DFS(int u){
	vector<int> v;
	for(int i=head[u];i;i=e[i].next)
		v.push_back(DFS(e[i].t));
	if(v.size()!=0)sort(v.begin(),v.end());
	int ret=0;
	for(int i=v.size()-1,t=1;i>=0;i--,t++) ret=max(ret,v[i]+t);
	return ret;
}

int n;
int main(){
	scanf("%d",&n);
	for(int i=2,v;i<=n;i++){
		scanf("%d",&v);
		addedge(v,i);
	}
	int ans=DFS(1);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 10752
// 1 から N までの数のうち 2/3 程度が 2 か 3 で割り切れる
// 6k + 2, 6k + 3, 6k + 4, 6k + 6
// 2 と 3 を両方選べば、選んだ要素の gcd は必ず 1 となる

#include <bits/stdc++.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)    FOR (i,0,n)
#define ALL(f,x,...) ([&](decltype((x)) ALL) {                          \
            return (f)(begin(ALL), end(ALL), ## __VA_ARGS__); })(x)

using namespace std;

set<int> st;

int f[4] = {2, 3, 4, 6};

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

    if (N == 3) cout << "2 5 63" << endl;
    else if (N == 4) cout << "2 5 20 63" << endl;
    else if (N == 5) cout << "2 5 20 30 63" << endl;
    else
    {
        int S = 0;
        int tmp = 0;
        REP(i, N)
        {
            tmp = 6 * (i / 4) + f[i % 4];
            S += tmp;
            st.insert(tmp);
        }

        int mod6 = S % 6;
        if (mod6 != 0)
        {
            int t = ((tmp / 6) + 1) * 6;

            if (mod6 == 2) st.erase(8);
            else if (mod6 == 3) st.erase(9);
            // 5 mod 6
            else
            {
                if (tmp < t - 2) t -= 2;
                else t += 4;

                st.erase(9);
            }
            st.insert(t);
        }

        int flg = true;
        for (auto&& s :st)
        {
            if (flg) cout << s;
            else cout << ' ' << s;
            flg = false;
        }
    }

    cout << endl;
    return 0;
}


Measured memory_bytes: 1280
#include<stdio.h>
main(){
  int N, A[100], i, j, minj, a, x=0, y=0;
  scanf("%d", &N);
  for(i = 0; i < N; i++){
    scanf("%d", &A[i]);
  }
  for(i = 0; i < N; i++){
    minj = i;
    for(j = i; j < N; j++){
      if(A[j] < A[minj]){
	minj = j;
	y = 1;
      }
    }
    a = A[i];
    A[i] = A[minj];
    A[minj] = a;
    x += y;
    y = 0;
  }
  
  for(i = 0; i < N; i++){
    if(i == N-1){
      printf("%d\n", A[i]);
    }
    else  printf("%d ", A[i]);
  }
  printf("%d\n", x);
  return 0;
}

Measured memory_bytes: 600
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
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;
}
///////////////////////////////////////////////////////////////

#include <bits/stdc++.h>
using namespace std;

template<class Abel> struct WeightedUnionFind {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;

    WeightedUnionFind(int n = 1, Abel SUM_UNITY = 0) {
        init(n, SUM_UNITY);
    }

    void init(int n = 1, Abel SUM_UNITY = 0) {
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(int x) {
        root(x);
        return diff_weight[x];
    }

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

    bool merge(int x, int y, Abel w) {
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }
};

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

    int N,M; cin >> N >> M;
    vector<int> L(M),R(M);
    vector<ll> D(M);
    rep(i,M) {
        cin >> L[i] >> R[i] >> D[i];
        L[i]--; R[i]--;
    }

    WeightedUnionFind<ll> uf(N);
    bool ok = true;
    rep(i,M) {
        if (uf.issame(L[i],R[i])) {
            if (uf.diff(L[i],R[i]) != D[i]) {
                ok = false;
                break;
            }
        } else uf.merge(L[i],R[i],D[i]);
    }

    cout << (ok ? "Yes" : "No") << endl;
}

Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <queue>
#include <iomanip> 
#include <math.h>
#include <unordered_map>
#include <set>
#include <stack>
#include <functional> 

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define all(x) x.begin(),x.end() 
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if (x < y) x = y; }

using namespace std;

int used[8888], ans[88888];


int main() {

	int n, a, b;
	
	cin >> n >> a >> b;
	
	int xx = abs(a - b);
	
	if (!(xx & 1))
		cout << "Alice" << endl;
	else
		cout << "Borys" <<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
int main(void){
    // Your code here!
    string s;
    cin>>s;
    long long int count=0;
    int fl=0;
    s='0'+s;
    for(int i=s.length()-1;i>=0;i--){
        int tmp=s[i]-'0'+fl;
        fl=0;
        if(tmp==5){
            if(s[i-1]>=5+'0'){
                s[i-1]++;
            }
        }if(tmp>5){
            count+=10-tmp;
            fl=1;
        }else{
            count+=tmp;
        }
    }
    count+=fl;
    cout<<count;
    return 0;
}


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

using namespace std;

#define ll long long int
#define ull unsigned long long int
#define REPL(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define radrad(a)  180.0 * a / M_PI
#define pow(x) x*x
static const int MAX = 200010;
static const ll INFTY = 1e12;
static const int NUMMAX = 300;


int main() {

  int r;

  cin >> r;

  cout << r*r << endl;


  return 0;

}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <stack>
#include <complex>
#include <functional>
#include <tuple>

using namespace std;

#define Rep(i,a,b) for(ll i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")

using ll = long long;

constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 998244353;
// 0~3までは右下左上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, 1, 0, -1, -1, 1, 1, -1 };

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

    void Cout(long long x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const T& x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const std::vector<T>& x, const char* sep = " ", const char* end = "\n") { for (std::size_t i = 0, sz = x.size(); i < sz; ++i) { std::cout << x[i] << (i == sz - 1 ? end : sep); } }

    // 標準入出力
    struct inp {
        std::size_t szi, szj;
        inp(std::size_t _szi = 1, std::size_t _szj = 1) : szi(_szi), szj(_szj) {}
        template <typename T> operator T () const { T a; std::cin >> a; return a; }
        template <typename T> operator std::vector<T>() const { std::vector<T> a(szi); for (std::size_t i = 0; i < szi; ++i) std::cin >> a[i]; return a; }
        template <typename T> operator std::vector<std::vector<T>>() const {
            std::vector<std::vector<T>> a(szi, std::vector<T>(szj));
            for (std::size_t i = 0; i < szi; ++i) for (std::size_t j = 0; j < szj; ++j) cin >> a[i][j]; return a;
        }
    };
    inp inp1;
}

int main() {

    ll n, s;
    cin >> n >> s;
    vector<ll> a = inp(n);

    // 普通にナップザック
    int kMax = s + 1;
    vector<vector<ll>> dp(n + 1, vector<ll>(kMax, 0LL));

    dp[0][0] = 1LL;

    rep(i, n) {
        rep(j, kMax) {
            dp[i + 1][j] += dp[i][j] * 2;
            dp[i + 1][j] %= mod;
            if (j + a[i] >= kMax) continue;
            dp[i + 1][j + a[i]] += dp[i][j];
            dp[i + 1][j + a[i]] %= mod;
        }
    }

    //rep(i, n + 1) {
    //    rep(j, kMax) {
    //        cout << dp[i][j] << " ";
    //    }
    //    cout << endl;
    //}

    Cout(dp[n][s]);

    return 0;
}


Measured memory_bytes: 73748
#無限ループと標準入力両方0だったらおわる
while True:
    a,b = map(int,input().split())
    if a == 0 and b == 0:break
    kei = [0 for _ in range(a)]
    
    #標準入力をし入力値を合計する
    for i in range(b):
        line = list(map(int,input().split()))
        for j in range(0,a):
            kei[j] += line[j]
    
    #一番大きい数を出力する
    print(max(kei))


Measured memory_bytes: 5656
module Main where

import           Control.Applicative
import           Data.Monoid

main :: IO ()
main = solve <$> getLine >>= putStrLn

solve :: String -> String
solve x = let res = oddJudge x in if res then "Yes" else "No"

evenJudge :: String -> Bool
evenJudge []       = True
evenJudge (x : xs) = (x == 'L' || x == 'U' || x == 'D') && oddJudge xs

oddJudge :: String -> Bool
oddJudge []       = True
oddJudge (x : xs) = (x == 'R' || x == 'U' || x == 'D') && evenJudge xs


Measured memory_bytes: 380
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
typedef long long ll;

void solve() {
    int N;
    cin >> N;
    int mai = (N+1000-1)/1000;
    cout << 1000*mai-N << endl;
}

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

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <stack>
#include <bitset>
#include <utility>
#include<iomanip>
// #include <numeric>
using namespace std;



typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector<vector<ll>> vvint;
typedef vector<string> vstring;
typedef vector<vector<string>> vvstring;
typedef vector<char> vchar;
typedef vector<vector<char>> vvchar;
typedef vector<long double> vdouble;
typedef vector<vector<long double>> vvdouble;
typedef vector<vector<vector<long double>>> vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define INT_MAX 2147483647
#define LLONG_MAX 9223372036854775807
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())
#define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>())
#define DIVIDER 1000000007


//
// struct Node{
//   vint children;
//   ll index;
//   ll prop;
// };



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

// ll X,Y,Z,K;
// ll pmax = 30000000000;
// vint A,B,C;




// int binary_search(int key){
//  //isOKを満たす要素のうち最小のインデックスを返す。（要ソート）
//   int left = -1;
//   int right = N;
//
//   while(right - left > 1){
//     int mid = left + (right - left)/2;
//
//     if(isOK(mid, key)) right=mid;
//     else left=mid;
//   }
//
//   return right;
// }

// ll gcd(ll m, ll n){
//   if(m<n) swap(m,n);
//   if(n==0) return m;
//   return gcd(n, m%n);
// }




int main() {
  cout<<fixed<<setprecision(10);

  ll N,K;
  cin>>N>>K;
  string S;cin>>S;
  S[K-1] = 'a'+S[K-1]-'A';

  cout << S << endl;
}

















//


Measured memory_bytes: 256
def examA():
    N = I()
    H = LI()
    dp = [inf]*(N)
    dp[0] = 0
    for i in range(N-1):
        dp[i+1] = min(dp[i+1],dp[i]+abs(H[i+1]-H[i]))
        if i<N-2:
            dp[i + 2] = min(dp[i + 2], dp[i]+abs(H[i + 2] - H[i]))
    ans = dp[-1]
    print(ans)
    return

def examB():
    N, K = LI()
    H = LI()
    dp = [inf]*N
    dp[0] = 0
    for i in range(N):
        for k in range(1,K+1):
            if i+k>=N:
                break
            if dp[i+k]>dp[i]+abs(H[i+k]-H[i]):
                dp[i+k] = dp[i]+abs(H[i+k]-H[i])
    ans = dp[-1]
    print(ans)
    return

def examC():
    N = I()
    A = [0]*N; B = [0]*N; C = [0]*N
    for i in range(N):
        A[i],B[i],C[i] = LI()
    dp = [[0]*3 for _ in range(N+1)]
    for i in range(N):
        dp[i+1][0] = max(dp[i][1],dp[i][2]) + A[i]
        dp[i + 1][1] = max(dp[i][0], dp[i][2]) + B[i]
        dp[i + 1][2] = max(dp[i][1], dp[i][0]) + C[i]
    ans = max(dp[N])
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examC()

"""

"""

Measured memory_bytes: 35164
N = int(input())
A = [int(i) for i in input().split()]

ans = 0
check = [2**i for i in range(1, 50)]
for i in range(49):
    for x in A:
        if x % check[i] != 0:
            break
    else:
        ans = i + 1
print(ans)

Measured memory_bytes: 3060
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main(void){
  long long x,i,res;
  cin>>x;
  res=(x/11)*11;
  i=(x/11)*2;
  while(res<x){
    res+=i%2?5:6;
    i++;
  }

  cout<<i<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

#define M 1046257
#define NIL (-1)
#define L 14

char H[M][L];

int getChar(char ch) {
  if ( ch == 'A' ) return 1;
  else if ( ch == 'C' ) return 2;
  else if ( ch == 'G' ) return 3;
  else if ( ch == 'T' ) return 4;
  return 0;
}

long long getKey(char str[]) {
  long long sum = 0, p = 1, i;
  for(i=0;i<strlen(str);i++) {
    sum += p*(getChar(str[i]));
    p*= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M-1)); }

int find(char str[]) {
  long long key, i, h;
  key = getKey(str); 
  for(i=0; ;i++) {
    h = (h1(key) + i*h2(key)) % M;
    if( strcmp(H[h],str) == 0) return 1;
    else if ( strlen(H[h]) == 0 ) return 0;
  }
  return 0;
}

int insert(char str[]) {
  long long key, i, h;
  key = getKey(str); 
  for(i=0; ; i++) {
    h = (h1(key) + i * h2(key)) %M;
    if(strcmp(H[h],str) == 0) return 1;
    else if(strlen(H[h]) == 0) {
      strcpy(H[h],str);
      return 0;
    }
  }
  return 0;
}

int main(void) {
  int i, n;
  char str[L], com[9];
  for(i=0;i<M;i++) H[i][0] = '\0';
  scanf("%d",&n);
  for(i=0;i<n;i++) {
    scanf("%s %s",com,str);
    if(com[0] == 'i') {
      insert(str);
    } else {
      if(find(str)){
        printf("yes\n");
      } else {
        printf("no\n");
      }
    }
  }
  return 0;
}


Measured memory_bytes: 16028
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,i,j;
	string s;
	cin>>n;
	int a[n];
	for(i=0;i<n;i++)
	cin>>s[i];
	for(i=0;i<n;i++)
	a[i]=s[i];
	if(n%2==1)
	{
		cout<<"No"<<endl;
		return 0;
	}
	j=n/2;
	for(i=0;i<n/2;i++)
	{
		if(a[i]!=a[j])
		{
			cout<<"No"<<endl;
			return 0;
		}
		j++;
	}
	cout<<"Yes"<<endl;
	return 0; 
}

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

#define loop(s, e, i) for (int i = s; i < e; ++i)
#define print(s) cout << s << endl;
#define DIV 1000000007
#define ll long long
using namespace std;

/*
浮動小数点の入力
cout << fixed << setprecision(9) << endl;
*/

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

  int H, W;
  cin >> H >> W;
  vector<vector<int>> MAP(W, vector<int>(H, 0));
  vector<vector<int>> DIST(W, vector<int>(H, -1));

  int black_count = 0;
  loop(0, H, j) {
    loop(0, W, i) {
      char tmp;
      cin >> tmp;
      if (tmp == '.') {
        MAP[i][j] = 0;
      } else {
        MAP[i][j] = 1;
        black_count++;
      }
    }
  }
  int lsx[] = {-1, 0, 1, 0};
  int lsy[] = {0, -1, 0, 1};

  queue<pair<int, int>> Q;
  Q.push(make_pair(0, 0));
  DIST[0][0] = 1;

  while(!Q.empty()) {
    auto top = Q.front();
    Q.pop();
    int x = top.first;
    int y = top.second;
    int d = DIST[x][y];

    loop(0, 4, i) {
      int nx = x + lsx[i];
      int ny = y + lsy[i];
      if (0 <= nx && nx < W && 0 <= ny && ny < H) {
        if (MAP[nx][ny] == 1) continue;
        if (DIST[nx][ny] == -1 || DIST[nx][ny] > d+1) {
          Q.push(make_pair(nx, ny));
          DIST[nx][ny] = d + 1;
        }
      }
    }
  }
  int result = DIST[W-1][H-1];
  if (result == -1) {
    print(-1);
  } else {
    print(W*H - black_count - result);
  }
}


Measured memory_bytes: 3688
#include <iostream>
#include <cctype>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;

int comp(const void* a, const void* b){
	return *(int*)a - *(int*)b;
}

int main() {
	int n;
	cin >> n;
	int s = n;
	while(1){
		if(s % 2 == 0){
			if(s % n == 0){
				break;
			}else{
				s += 2;
			}
		}else{
			if(s % n == 0 && s % 2 == 0){
				break;
			}else{
				if(s == n){
					s++;
				}else{
					s += 2;
				}
			}
		}
	}
	cout << s << endl;
}

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

int main(void){
    long int a, b;
    scanf("%ld %ld", &a, &b);
    int c[50];
    for(int i = 0;i < 50;i++){
        c[i] = 0;
    }
    int aa[50];
    int bb[50];
    long int t = a;
    for(int j = 0;j < 50;j++){
        if(t % 2 == 0)aa[j]=0;
        else aa[j]=1;
        t = t / 2;
    }
    t = b;
    for(int j = 0;j < 50;j++){
        if(t % 2 == 0)bb[j]=0;
        else bb[j]=1;
        t = t / 2;
    }
    int c0 = 0;
    if(a%4 == 2 || a%4 == 3)c0++;
    if(b%4 == 1 || b%4 == 2)c0++;
    c[0] = c0 % 2;
    for(int i = 1;i < 50;i++){
        int ci = 0;
        if(aa[i] == 1 && aa[0] == 1)ci++;
        if(bb[i] == 1 && bb[0] == 0)ci++;
        c[i] = ci % 2;
    }

    long int d = 0;
    for(int i = 0;i < 50;i++){
        d += pow(2, i) * (c[i] % 2);
    }
    printf("%ld\n", d);
    return 0;
}

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

int main() {
	int N;
	bool ok=0;
	cin >> N;

	rep(i,30)
		rep(j,30)
			if(i*4+j*7 == N)
				ok = 1;

	if(ok)
		cout << "Yes";
	else
		cout << "No";
	cout << endl;
}

Measured memory_bytes: 256
import math
import heapq
from bisect import bisect_right, bisect_left
from collections import defaultdict, Counter
import itertools
import sys
sys.setrecursionlimit(10**7)
MOD = 10**9 + 7
INF = float("inf")


def main():
    n, k, q = map(int, input().split())
    a = [int(input()) for i in range(q)]
    d = Counter(a)

    for i in range(1, n+1):
        if k - q + d[i] > 0:
            print("Yes")
        else:
            print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 62680
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yassin
 */

#include <bits/stdc++.h>

using namespace std;

class agc024b {
public:
    void solve(istream& in, ostream& out) {
        int N;
        in >> N;
        vector<int> P(N);
        for (int i = 0; i < N; ++i) {
            in >> P[i];
        }
        map<int, int> m;
        int mx = 1;
        for (int i = 0; i < N; ++i) {
            if (m.count(P[i] - 1)) {
                m[P[i]] = m[P[i] - 1] + 1;
                mx = max(mx, m[P[i]]);
            } else {
                m[P[i]] = 1;
            }
        }
        out << N - mx << "\n";
    }
};

int main() {
	std::ios::sync_with_stdio(false); cin.tie(nullptr);
	agc024b solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 10368
#include<stdio.h>

int memo[45];

int fibonacci(int n){
  if(n == 0 || n == 1) return 1;
  if(memo[n] != -1) return memo[n];
  return memo[n] = fibonacci(n-2) + fibonacci(n-1);
}

int main(){
  int n, i;

  for(i = 0; i < 45; i++){
    memo[i] = -1;
  }

  scanf("%d", &n);
  printf("%d\n", fibonacci(n));

  return 0;
}
    



Measured memory_bytes: 2044
S = input()

s1 = int(S[0] + S[1])
s2 = int(S[2] + S[3])

if s1 > 12: #YY
    if 0 < s2 <= 12:
        print('YYMM')
    else:
        print('NA')
elif s2 > 12: #YY
    if 0 < s1 <= 12:
        print('MMYY')
    else:
        print('NA')
else:
    if s1 == 0 and s2 == 0:
        print('NA')
    elif s1 == 0 and 0 < s2 <= 12:
        print('YYMM') 
    elif s2 == 0 and 0 < s1 <= 12:
        print('MMYY') 
    else:
        print('AMBIGUOUS')

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

char arr[4];
int freq[30]={};

int main() {
	
	for (int i=0;i<4;i++){cin>>arr[i];}
	for(int i = 0 ; i < 4 ; ++i)    freq[arr[i] - 'A']++;
	for (int i=0;i<30;i++){
		
	 if (freq[i]==1||freq[i]>2){
	 	cout << "No" <<endl;
	 	return 0;
	}
	
	}
	cout<<"Yes"<<endl;
	return 0;
}


Measured memory_bytes: 3592
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner stdIn=new Scanner(System.in);
		Deque<Integer> ans = new ArrayDeque<Integer>();
		int N=stdIn.nextInt();
		int A[]=new int[N];
		int B[]=new int[N+1];
		int z=0,y=2,x=0;
		while(z<N){
			A[z]=stdIn.nextInt();
			z++;
		}z=N-1;
		while(z>=0){
			if(z<N/2)
				break;
			if(A[z]==1){
				ans.add(z+1);x++;
				B[z+1]=1;
			}
			z--;
		}z=N/2;
		while(z>1){
			while(y<=z){
				if(z*y>N)
					break;
				B[z]+=B[z*y];
				if(z!=y)
					B[y]+=B[z*y];
				y++;
			}y=2;
			if(B[z]%2==0&&A[z-1]==1){
				ans.add(z);x++;B[z]=1;
			}
			else
				if(B[z]%2==1&&A[z-1]==0){
					ans.add(z);x++;B[z]=1;
				}
				else
					B[z]=0;
			z--;
		}z=0;
		if(x%2==1&&A[0]==0)
			ans.add(1);
		if(x%2==0&&A[0]==1)
			ans.add(1);
		System.out.println(ans.size());
		x=ans.size();
		while(z<x){
			System.out.println(ans.removeLast());
			z++;
		}
	}
}

Measured memory_bytes: 90108
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                  as A
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as AU
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Int
import qualified Data.IntMap                 as IM
import           Data.List
import qualified Data.Map                    as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Set                    as S
import           Data.Time
import qualified Data.Vector                 as V
import qualified Data.Vector.Mutable         as VM
import qualified Data.Vector.Unboxed         as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt :: IO [Int]
readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readInts :: Int -> IO [[Int]]
readInts n = replicateM n readInt

readInteger :: IO [Integer]
readInteger = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

readIntegers :: Int -> IO [[Integer]]
readIntegers n = replicateM n readInteger

readString :: IO [String]
readString = map BS.unpack . BS.words <$> BS.getLine

readStrings :: Int -> IO [[String]]
readStrings n = replicateM n <$> readString

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

count :: Eq a => a -> [a] -> Int
count a as = length $ filter (== a) as

main = do
  [n, t] <- readInt
  a <- readInt
  print $ solve a t

solve a t = length $ head $ group $ sortOn Down $ f (tail a) (head a) []

f [] _ acc     = acc
f (a:as) m acc = f as (min m a) (a - m : acc)


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

vector<int> build(ll n) {
    vector<int> r;

    if (n > 1) {
        if (n & 1) {
            r = build(n - 1);
            r.insert(r.begin(), int(r.size()) + 1);
        } else {
            r = build(n / 2);
            r.push_back(int(r.size()) + 1);
        }
    }

    return r;
}

int main() {
    ll n;
    scanf("%lld", &n);

    auto p = build(n + 1);
    int m = int(p.size());
    for (int i = 1; i <= m; i++) {
        p.push_back(i);
    }

    assert(p.size() <= 200);
    printf("%d\n", int(p.size()));
    for (int x: p) {
        printf("%d ", x);
    }
    printf("\n");
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = 99999999;
const ll linf = 999999999999999999;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////



int main(){
	int a,b,c,d;
	cin >> a >> b >> c >> d;

	if(b <= c || d <= a)P(0);
	else P(min(b,d) - max(a,c));
	return  0;
}

Measured memory_bytes: 256
from collections import Counter
n=input()
a=sorted(list(map(int,input().split())))[::-1]
ca=Counter(a).most_common()
if ca[1][1]<2:
    if ca[0][1]<4:print(0)
    else:print(ca[0][0]**2)
else:
    l=[]
    for i,j in ca:
        if j<2:break
        elif j<4:l.append(i)
        else:
            l.append(i)
            l.append(i)
    l.sort()
    print(l[-1]*l[-2])

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

void solve(long long K, long long N, std::vector<long long> A){
    ll minimum = A[N-1] - A[0];
    for (int i=1;i<N;i++){
        minimum = min(minimum,K -A[i] + A[i-1]);
    }
    printf("%lld\n",minimum);

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long K;
    scanf("%lld",&K);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(K, N, std::move(A));
    return 0;
}


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

int main() {
  string a,b,c;
  string kekka;
  cin >> a >> b >> c;
  
  kekka = toupper(a.at(0));
  kekka += toupper(b.at(0));
  kekka += toupper(c.at(0));
  cout << kekka;
}


Measured memory_bytes: 256
from collections import defaultdict as dd
from itertools import permutations as pe

d=dd(list)
n,m=map(int,input().split())

for _ in range(m):
  a,b=map(int,input().split())
  d[a].append(b)
  d[b].append(a)

c=0

for i in pe(range(2,n+1)):
  a=d[1]
  f=True
  for j in i:
    if not j in a:
      f=False
      break
    else:
      a=d[j]
  if f:c+=1

print(c)

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

int main()
{
  long long K, N;
  cin >> K >> N;
  
  vector<long long> A;
  rep(i, N)
  {
    long long tmp;
    cin >> tmp;
	A.push_back(tmp);
  }
  
  long long dist[N];
  dist[0] = A[0] + (K - A[N - 1]);
  
  long long max_dist = dist[0];
  long long max_index = 0;
  for (long long i = 1; i < N; i++)
  {
    dist[i] = A[i] - A[i - 1];
    if (max_dist < dist[i])
    {
      max_dist = max(max_dist, dist[i]);
      max_index = i;
    }
  }
  
  long long min_dist = 0;
  if (max_index != 0)
  {
    min_dist += dist[0];
  }
  
  for (long long i = 1; i < N; i++)
  {
	if (max_index != i)
    {
      min_dist += dist[i];
    }
  }
  
  cout << min_dist << endl;

  return 0;
}

Measured memory_bytes: 3440
#include <bits/stdc++.h>
using namespace std;
int main() {
	string S;
	cin >> S;
	vector<int> dp(S.size()+1);
	dp.at(0) = 1;
	for (size_t i = 0; i < S.size()+1; i++)
	{
		if ((i >= 5) && (dp.at(i - 5)))
		{
			if (S.substr(i - 5, 5) == "dream" || S.substr(i - 5, 5) == "erase")
			{
				dp.at(i) = 1;
			}
		}
		else if (i >= 6 && dp.at(i - 6) && S.substr(i - 6, 6) == "eraser") dp.at(i) = 1;
		else if (i >= 7 && dp.at(i - 7) && S.substr(i - 7, 7) == "dreamer")dp.at(i) = 1;
	}
	if (dp.at(S.size()) == 1)cout << "YES";
	else cout << "NO";
}

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

using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;

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

constexpr long long mod = 1000000007;

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

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

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

    sort(a.begin(), a.end());
    vll b(n / 2), c(n / 2);

    if (n % 2) {
        vll sum(4, 0);

        for (int i = 0; i < n / 2; i++) {
            b[i] = a[i];
            c[i] = a[i + n / 2 + 1];
        }

        ll t = a[n / 2];

        for (int i = 0; i < n / 2; i++) {
            sum[0] += abs(c[i] - b[i]);

            if (i + 1 < n / 2) {
                sum[0] += abs(b[i] - c[i + 1]);
            }
            if (i == 0) {
                sum[0] += abs(t - c[i]);
            }
        }

        for (int i = 0; i < n / 2; i++) {
            sum[1] += abs(c[i] - b[i]);

            if (i + 1 < n / 2) {
                sum[1] += abs(b[i] - c[i + 1]);
            } else {
                sum[1] += abs(b[i] - t);
            }
        }

        // sort(b.begin(), b.end(), greater<ll>());

        // for (int i = 0; i < n / 2; i++) {
        //     sum[2] += abs(b[i] - c[i]);

        //     if (i + 1 < n / 2) {
        //         sum[2] += abs(c[i] - b[i + 1]);
        //     } else {
        //         sum[2] += abs(c[i] - t);
        //     }
        // }

        // for (int i = 0; i < n / 2; i++) {
        //     sum[3] += abs(c[i] - b[i]);

        //     if (i + 1 < n / 2) {
        //         sum[3] += abs(b[i] - c[i + 1]);
        //     } else {
        //         sum[3] += abs(b[i] - t);
        //     }
        // }

        cout << *max_element(sum.begin(), sum.end()) << endl;

    } else {
        vll sum(4, 0);

        for (int i = 0; i < n / 2; i++) {
            b[i] = a[i];
            c[i] = a[i + n / 2];
        }

        for (int i = 0; i < n / 2; i++) {
            sum[0] += abs(c[i] - b[i]);

            if (i + 1 < n / 2) {
                sum[0] += abs(b[i] - c[i + 1]);
            }
        }

        for (int i = 0; i < n / 2; i++) {
            sum[1] += abs(b[i] - c[i]);

            if (i + 1 < n / 2) {
                sum[1] += abs(c[i] - b[i + 1]);
            }
        }

        // sort(b.begin(), b.end(), greater<ll>());

        // for (int i = 0; i < n / 2; i++) {
        //     sum[2] += abs(c[i] - b[i]);

        //     if (i + 1 < n / 2) {
        //         sum[2] += abs(b[i] - c[i + 1]);
        //     }
        // }

        // for (int i = 0; i < n / 2; i++) {
        //     sum[3] += abs(b[i] - c[i]);

        //     if (i + 1 < n / 2) {
        //         sum[3] += abs(c[i] - b[i + 1]);
        //     }
        // }

        cout << *max_element(sum.begin(), sum.end()) << endl;
    }
}

Measured memory_bytes: 1920
# 解説放送
# https://atcoder.jp/contests/abc158/submissions/10643692
# dfsの代わりに親の頂点番号を配列で管理する方法
# PyPyでは通った

def main():
    from collections import deque, namedtuple
    from operator import attrgetter
    import sys
    input = sys.stdin.readline

    MOD = 998244353

    Robot = namedtuple('Robot', 'x d reach ind')

    N = int(input())

    robots = []
    for ind in range(N):
        X, D = map(int, input().split())
        robots.append(Robot(X, D, X + D, ind))
    robots.sort(key=attrgetter('x'), reverse=True)

    parents = [-1] * N
    to_candidates = deque()
    for robot_from in robots:  # x降順
        """
        右端に位置するロボットから順に「起点」と見なしていく
        既出のロボットで有向辺の行き先として一度も設定されていないものが
        to_candidatesにx昇順で溜められている
        to_candidatesに含まれるロボットで「起点」から接触範囲内のものがある限り、
        「起点」から有向辺を張り続ける
        to_candidatesの先頭候補(最も左側に位置する)に対して辺を張れない場合、
        それ以降の候補のxはより遠い座標で辺を張れないので
        「起点」から張れる辺がないとわかる
        すべてのロボットは「起点」から辺を張られてto_candidatesから外れるか
        to_candidatesに残り、グラフ(森)の各木のrootとなる
        """
        while to_candidates:
            robot_to = to_candidates[0]
            if robot_to.x < robot_from.reach:
                parents[robot_to.ind] = robot_from.ind
                to_candidates.popleft()
            else:
                break

        to_candidates.appendleft(robot_from)

    ret = 1
    count = [1] * N
    for robot in robots:  # x降順
        par = parents[robot.ind]
        count[robot.ind] += 1
        if ~par:
            count[par] = (count[par] * count[robot.ind]) % MOD
        else:
            ret = (ret * count[robot.ind]) % MOD
            # x降順で見ているのでpar==-1のrootのrobotを見る頃には
            # rootの子は全て見ているので安心してretにかけられる
    print(ret)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 57180
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a[6];
  int d[4]={0,0,0,0};
  for(int i=0;i<6;i++){
    cin >> a[i];
    d[a[i]-1]++;
  }
  if(d[0]<=2&&d[1]<=2&&d[2]<=2&&d[3]<=2)cout << "YES";
  else cout << "NO";
}

Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        n:usize,
        ss:[proconio::marker::Chars;n]
    };

    let mut t:Vec<(i32,i32,i32)> = ss.iter().map(|s|{
        let mut sum = 0;
        let mut lminv = 0;
        for c in s {
            sum+= match c {
                '(' => 1,
                _ => -1,
            };
            lminv = std::cmp::min(lminv,sum);
        }
        let mut iter = s.iter().rev();
        let mut rminv = 0;
        sum = 0;
        for c in iter {
            sum+= match c {
                '(' => 1,
                _ => -1,
            };
            rminv = std::cmp::min(rminv,-sum)
        }
        (sum,lminv,rminv)
    }).collect();

    t.sort_by_key(|&(sum,lminv,rminv)|
        if sum>0 {
            (-1,-lminv)
        }
        else if sum==0 {
            (0,0)
        }
        else {
            (1,rminv)
        }
    );
    let t = t;
    let mut sum = 0;
    for (plus,lminv,_) in t {
        if sum+lminv<0{
            println!("No");
            return;
        }
        sum+=plus;
    }
    if sum!=0{
        println!("No");
    }
    else {
        println!("Yes");
    }

    

    


}


Measured memory_bytes: 74588
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <climits>
#include <math.h>
#include <bitset>

#define P pair
#define X first
#define Y second
#define VSORT(v) sort(v.begin(), v.end())
#define VREV(v) reverse(v.begin(), v.end())
#define VMAX_P(v) max_element(v.begin(), v.end())
#define VMIN_P(v) min_element(v.begin(), v.end())
#define VMAX_IDX(v) distance(v.begin(), VMAX_P(v))
#define VMIN_IDX(v) distance(v.begin(), VMIN_P(v))
#define VCOPY(src, dst) copy(src.begin(), src.end(), back_inserter(dst))
#define SUPPER(src, dst) transform(src.begin(), src.end(), dst.begin(), toupper);
#define SLOWER(src, dst) transform(src.begin(), src.end(), dst.begin(), tolower);

using namespace std;
using ll = long long;

int main(int argc, const char *argv[])
{
    ll n, k, q;
    cin >> n >> k >> q;

    vector<ll> r(n);
    ll x;
    for (ll i = 0; i < q; i++)
    {
        cin >> x;
        r[x - 1]++;
    }

    for (ll i = 0; i < n; i++)
    {
        if (k - (q - r[i]) > 0)
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }
}


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

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

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

#define MAX 100005
#define INF 1001001001

int main(int, char**)
{
  ull x, y; cin >> x >> y;
  bitset<32> a(x), b(y);
  cout << (a&b) << endl;
  cout << (a|b) << endl;
  cout << (a^b) << endl;

  return 0;
}



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

using namespace std;

const int MAXN = 222;

int N, C, result, cur;
int cnt[MAXN];
int depth[MAXN];
int color[MAXN];

vector<int> components[MAXN];

bool visited[MAXN];

char graph[MAXN][MAXN];

void dfs( int node ) {

	visited[node] = true;
	
	cnt[C]++;
	color[node] = C;
	components[C].push_back(node);

	for( int i=1 ; i <= N ; i++ ) {
		if ( graph[node][i] == '1' && i != node && !visited[i] ) {
			dfs(i);
		}
	}
}

inline int create( int node ) {

	int rev = 0;
	queue<int> Q;

	Q.push(node);

	visited[node] = true;

	while (!Q.empty()) {

		node = Q.front();
		Q.pop();

		rev = max(rev, depth[node]);

		for( int i=1 ; i <= N ; i++ ) {
			if ( graph[node][i] == '1' && !visited[i] ) {
				Q.push(i);
				depth[i] = depth[node] + 1;
				visited[i] = true;
			} else if (graph[node][i] == '1' && visited[i] && depth[i] != depth[node] - 1 && depth[i] != depth[node] + 1) {
				return 0;
			}
		}
	}

	return rev + 1;
}

inline int f( int c ) {

	int res = 0;

	for ( int node : components[c] ) {

		memset(visited, false, sizeof visited);
		memset(depth, 0, sizeof depth);

		res = max(res, create(node));
		// cerr << node << " " << res << endl;
	}

	return res;
}

int main() {

	scanf("%d", &N);

	for( int i=1 ; i <= N ; i++ ) {
		scanf("%s", graph[i] + 1);
	}

	for( int i=1 ; i <= N ; i++ ) {
		if (!visited[i]) {
			C++;
			dfs(i);
		}
	}

	for( int i=1 ; i <= C ; i++ ) {

		int tmp = f(i);

		result += tmp;

		if (tmp == 0) {
			puts("-1");
			return 0;
		}
	}

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

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

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

    if(s.length() > k) {
        cout << s.substr(0, k);
        cout << "..." << endl;
    }else{
        cout << s << endl;
    }

    return 0;
}


Measured memory_bytes: 3632
N=int(input())
S=input()
ans=[S[0]]
if len(S)==1:
  print(1)
  exit()
for i in range(1,N):
  if S[i]==S[i-1]:
    continue
  elif S[i]!=S[i-1]:
    ans.append(S[i])
print(len(ans))

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

using ll=long long;

ll f(ll b,ll n){
    if(b<=1 || n<1) return -1;
    ll res=0;
    while(n){
        res+=n%b;
        n/=b;
    }
    return res;
}
int main(){
    ll n,s;
    cin>>n>>s;
    if(n<s){
        cout<<-1<<endl;
        return 0;
    }
    if(n==s){
        cout<<n+1<<endl;
        return 0;
    }
    for(ll b=2;b*b<=n;b++){
        if(f(b,n)==s){
            cout<<b<<endl;
            return 0;
        }
    }    
    
    vector<ll> divs;
    divs.push_back(1);
    divs.push_back(n-s);
    for(ll d=2;d*d<=n-s;d++){
        if((n-s)%d==0){
            divs.push_back(d);
            divs.push_back((n-s)/d);
        }
    }
    sort(divs.begin(),divs.end(),greater<>());
    for(auto d:divs){
        ll b=(n-s)/d+1;
        if(f(b,n)==s){
            cout<<b<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys
from math import fabs

if __name__ == '__main__':
    epsilon = 1e-9
    # ??????????????\?????¨???????????????
    for line in sys.stdin:
        a, b, e, c, d, f = [int(x) for x in line.strip().split(' ')]
        x = 1/(a*d-b*c) * (d*e - b*f)
        y = 1/(a*d-b*c) * (-c*e + a*f)
        # ?¨????????????¨?????? -0.0 ???????????´???????????¶?????? 0.0 ?????????
        if fabs(x) < epsilon:
            x = 0.0
        if fabs(y) < epsilon:
            y = 0.0
        print('{0:.3f} {1:.3f}'.format(x, y))

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

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

  int m[N];
  int sumX=0;
  for(int i=0; i<N; ++i)
    {
      cin >> m[i];
      sumX=sumX+m[i];
    }

  sort(m, m+N);

  int kosuu = N + (X-sumX) / m[0];

  cout << kosuu;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  string s;
  cin >> s;
  int ans = 0;
  rep(i, 0, s.size()) {
    if (s[i] == '+')
      ans++;
    else
      ans--;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256