akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}

template<class T1, class T2> void chmin(T1 &a, T2 b) { if (a>b)a = b; }

template<class T1, class T2> void chmax(T1 &a, T2 b) { if (a<b)a = b; }
template<class T>
void Add(T &a, const T &b, const T &mod = 1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}
////////////////////////////////////////
int ans = 1e9;
int N, A, B, C;
int l[1010];
void dfs(int a,int b,int c,int d,int n) {
	if (n == N) {
		if (a == 0 || b == 0 || c == 0)return;
		int key = abs(a - A) + abs(b - B) + abs(c - C) + 10 * (d - 3);
		ans = min(ans, key);
		return;
	}
	dfs(a, b, c, d, n + 1);
	dfs(a + l[n], b, c, d + 1, n + 1);
	dfs(a, b + l[n], c, d + 1, n + 1);
	dfs(a, b, c + l[n], d + 1, n + 1);

}

int main() {
	cin >> N >> A >> B >> C;
	for (int i = 0; i < N; ++i)cin >> l[i];
	dfs(0,0,0,0,0);
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#!venv/bin/python
 
import math
import numpy as np
import random
import copy
import statistics 
import bisect
import heapq
from collections import defaultdict 

N, A, B, C, D = [ int(x) for x in input().split() ]
A -= 1
B -= 1
C -= 1
D -= 1
S = input() + "#"

A_blocker = False
B_blocker = False
pass_point = False

A_load = S[A:C+1]
B_load = S[B:D+1]
pass_load = S[B-1:D+2]
if '##' in A_load:
    A_blocker = True
if '##' in B_load:
    B_blocker = True
if '...' in pass_load:
    pass_point = True

if D < C:
    if (not A_blocker) and (not B_blocker) and pass_point:
        print ("Yes")
    else:
        print ("No")
else:
    if (not A_blocker) and (not B_blocker):
        print ("Yes")
    else:
        print ("No")


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

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

  int avail[102] = {0};

  if(!n) {cout << x; return 0;}

  for(int i = 1; i <= n; i++){
     int k; cin >> k;
     avail[k]++;
  }
  if(!avail[x]) {cout << x; return 0;}
  for(int i = x-1, j = x+1;i >= 0; i--,j++){
    if(!avail[i]) {cout << i; return 0;}
    if(!avail[j]) {cout << j; return 0;}
  }

  return 0;
}


Measured memory_bytes: 3588
#include<iostream>
#include<cmath>
#include<algorithm>

using namespace std;

int main(){
    long long k;
    long long a=0,b=0,ans=0;
    long long n,m;
    cin>>n>>m>>k;

    long long A[n],B[m];
    for(int i=0;i<n;i++)  cin>>A[i];
    
    for(int i=0;i<m;i++) {
        cin>>B[i];
        b+=B[i];
    }
    for(long long i=0;i<n+1;i++){
        if(a>k) break;

        while((a+b)>k){
            m-=1;
            b-=B[m];
        }

        ans=max(ans,m+i);
        if(i!=n) a+=A[i];
    }
    cout<<ans<<endl;
    return 0;
    
}


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

int main() {
  long long N, D, X;
  cin >> N >> D >> X;
  for (int i = 0; i < N; ++i) {
    long long A;
    cin >> A;
    long long start = 1;
    while (start <= D) {
      ++X;
      start += A;
    }
  }
  cout << X << endl;
}
    

Measured memory_bytes: 3620
/*
オーダー
10**6	余裕を持って間に合う	
10**7	おそらく間に合う	余裕を持って間に合う
10**8	非常にシンプルな処理でない限り厳しい	おそらく間に合う
10**9		非常にシンプルな処理でない限り厳しい
logn	:OK
n		:10^7
nlogn	:10^6
n**2	:10^4
n**3	:300
2**n	:20
n!		:10



// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/

#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18
// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
 
ll gcd(ll a, ll b) {
	if(b == 0) return a;
	return gcd(b, a % b);
}

// const ll MAX_N = 1e5;
// ll N;
// ll h[MAX_N];
// ll dp[MAX_N+1]; // メモ化テーブル
 
// // i番目以降の品物から重さの総和がj以下になるように選ぶ
// void rec(ll i){
// 	if (i==0) dp[i] = 0;
// 	else if (i==1) dp[i] = abs(h[1]-h[0]);
// 	else dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
// 	return;
// }
 
 
int main() {
	// 入力
	ll K;
	cin >> K;
	ll A[K];
	for (ll i = 0; i < K; ++i) cin >> A[i];
 
	// 解法
	ll N_min[K]; ///i試合目前の残り人数
	ll N_max[K];
	ll flag =false;
	for (ll i = K-1; i >= 0; --i){
		if (i==K-1){
			N_min[i] = 2;
			N_max[i] = 3;
		}
		else{
			// N_min[i+1]をA[i]で割った商 x A[i] >= N_min[i]
			N_min[i] = ((N_min[i+1]-1)/A[i] + 1) * A[i];
			N_max[i] = ((N_max[i+1])/A[i] + 1) * A[i] - 1;
		}
		if (N_min[i]>N_max[i]){
			flag = true;
		}
	}
	// REP(i,K) printf("%lld: %lld-%lld\n", i, N_min[i],N_max[i]);
	
	//出力
	if (A[K-1]!=2) flag = true;
	if (flag) printf("-1\n", N_min[0], N_max[0]);
	else printf("%lld %lld\n", N_min[0], N_max[0]);
}


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

int main() {
  int N, sum=0, pre=0;
  cin >> N;
  vector<int> vec(N);
  
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
  for(int i=0; i<N; i++){
    if(pre == vec.at(i)){
      continue;
    }
    sum++;
    pre = vec.at(i);
  }
  cout << sum << endl;
}


Measured memory_bytes: 3616
judge :: Double -> Double -> String
judge t u
    | t < 35.50 && u < 71.00 = "AAA"
    | t < 37.50 && u < 77.00 = "AA"
    | t < 40.00 && u < 83.00 = "A"
    | t < 43.00 && u < 89.00 = "B"
    | t < 50.00 && u < 105.00 = "C"
    | t < 55.00 && u < 116.00 = "D"
    | t < 70.00 && u < 148.00 = "E"
    | otherwise               = "NA"

main :: IO ()
main = interact $ unlines . map (\[t, u] -> judge t u) . map (map read) . map words . lines

Measured memory_bytes: 4268
#include <bits/stdc++.h>
using namespace std;
int main(){
    int w,h,n,x,y,a;
    cin >>w>>h>>n;
    int xmin=0,xmax=w,ymin=0,ymax=h;
    for(int i=0;i<n;i++){
        cin >>x>>y>>a;
        if(a==1) xmin=max(xmin,x);
        else if(a==2) xmax=min(xmax,x);
        else if(a==3) ymin=max(ymin,y);
        else if(a==4) ymax=min(ymax,y);
    }
    if(xmin<=xmax&&ymin<=ymax) cout<<(xmax-xmin)*(ymax-ymin)<<endl;
    else cout<<0<<endl;
}

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

#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), end(x))
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

signed main() {
    int N;
    cin >> N;
    vint A(N + 1);
    rep(i, N + 1) { cin >> A[i]; }
    vint Accr(N + 1);
    for (int i = N - 1; i >= 0; i--) { Accr[i] = Accr[i + 1] + A[i + 1]; }
    int ans = 0, cur = 1;
    rep(i, N + 1) {
        ans += cur;
        if (cur < A[i]) { fin(-1); }
        cur -= A[i];
        cur *= 2;
        chmin(cur, Accr[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 5020
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
//#define ll __int128
#define ll long long
#define LEFT(a) ((a)<<1)
#define RIGHT(a) (LEFT(a) + 1)
#define MID(a,b) ((a+b)>>1)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))

/*
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/STACK: 20000000005")
*/

using namespace std;

const ll N = 200005, MOD = 1e9 + 7;

int n;
double a[N];

double C = 2;

main()
{
    //freopen ("in.in", "r", stdin);freopen ("out.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    sort (a + 1, a + n + 1);
    for (int i = 2; i <= n; i++)
        a[i] = (a[i] + a[i - 1]) / C;
    printf ("%.8f\n", a[n]);
    return 0;
}


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

ll solve() {
    ll N;
    cin >> N;

    auto PrimeTable = [](ll n) {
        vector<bool> pr(n+1, true) ;
        pr[0] = pr[1] = false;
        for ( ll k = 0; k <= n; k++ ) {
            if ( pr[k] ) {
                for ( ll h = 2 * k; h <= n; h+=k ) {
                    pr[h] = false;
                }
            }
        }
        return pr;
    };
    int c = 0, i = 2;
    auto pr = PrimeTable(55555);
    while ( c < N ) {
        if ( pr[i] ) {
            if ( i%5 == 1 ) {
                cout << i << " ";
                c++;
            }
        }
        i++;
    }
    cout << "\n";
    return 0;
}



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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll 			long long
#define vl 			vector<ll>
#define vi 			vector<int>
#define pi 			pair<int,int>
#define pl 			pair<ll,ll>
#define all(a)      a.rbegin(),a.rend()
#define mem(a,x)    memset(a,x,sizeof(a))
#define pb 			push_back
#define mp 			make_pair
#define F 			first
#define S 			second
#define trace(x) 	cerr<<#x<<":"<<x<<endl;
#define trace2(x,y) cerr<<#x<<":"<<x<<"|"<<#y<<":"<<y<<endl;
#define trace3(x,y,z) cerr<<#x<<":"<<x<<"|"<<#y<<":"<<y<<"|"<<#z<<":"<<z<<endl;
#define fast_io 	std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

using namespace std;


int main()
{
	fast_io;
	int n,k;
	vi has(2e5+7,0);
	cin>>n>>k;
	for(int i=0;i<n;i++)
		{
			int t;
			cin>>t;
			has[t]++;
	}
	sort(all(has));
	int same=0;int diff=0;
	for(int i=0;i<k;i++)
		{
			same+=has[i];
		}
	diff=n-same;
	cout<<diff;
	return 0;
}

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

int main() {
  string S;
  cin >> S;
  int N = S.size();
  //cout << N;
  
  for(int i=0; i<N/2; i++){
    if(S.at(i) != S.at(N-1-i)){
      cout <<"No" << endl;
      return 0;
    }
  }
  
  for(int i=0; i<(N-1)/4; i++){
    if(S.at(i) != S.at((N-1)/2-1-i)){
      cout <<"No"<<endl;
      return 0;
    }
  }
  
  for(int i=((N+3)/2)-1; i<((N+3)/2)-1+(N/4); i++){
    if(S.at(i)!= S.at(N-1-i)){
      cout << "No" << endl;
      return 0;
    }
  }
  
  cout << "Yes" << endl;
}


// int型の2次元配列(3×4要素の)の宣言
  //vector<vector<int>> data(3, vector<int>(4));
 
  // 入力 (2重ループを用いる)
  //for (int i = 0; i < 3; i++) {
    //for (int j = 0; j < 4; j++) {
      //cin >> data.at(i).at(j);
   // }
  //}


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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

struct edge{
    int v;
    ll c,r;
    // u->v cap() u<-v
};

int N;
vl a;
ll anse = 0;
vector< vector<edge> > e; // e[u] : e.first = u->v ; e.second = cap(u);
vector< bool > used;


void addedge(int a, int b, int c){
    e[a].push_back( edge{b,c,(int)e[b].size()} );
    e[b].push_back( edge{a,0,(int)e[a].size()-1} );
}

void scan(){

    Scd(N);
    e.assign( N*2+4, vector<edge>(0) );
    a.resize( N+1 );
    Rep(i,N){
        Scll( a[i+1] );
        anse += max(0LL,a[i+1]);
    }

}

void build(){

    // N+1 = source(S)
    // N+2 = sink(T)
    Rep(i,N){
        if( a[i+1] > 0 ) addedge( i+1, N+2, a[i+1] );
        else addedge( N+1, i+1, -a[i+1] );
    }
    Repe(i,N+1,1){
        for( int k = 2*i; k < N+1; k += i ){
            addedge( i, k, INF*INF );
        }
    }

}

// v:now , t:sink , c:capacity
ll dfs( int v, int t, ll c){
    if( v==t ) return c;
    used[v] = true;
    // Ford-Fulkerson algorithm
    for( int ei = 0; ei < e[v].size(); ei++ ){
        edge &ez = e[v][ei];
        if( !used[ez.v] && ez.c > 0){
            ll d = dfs( ez.v,t,min(c,ez.c));
            if( d>0 ){
                ez.c -= d;
                e[ez.v][ez.r].c += d;
                return d;
            }
        }
    }
    return 0;
}

ll ans( int s , int t ){
    ll flow = 0;
    while(1){
        used.assign( N*2+2, false );
        ll f = dfs(s,t,INF);
        if( f ) flow+=f;
        else break;
    }
    return flow;
}

int main() {

    scan();
    build();
    printf ("%lld\n", anse-ans(N+1,N+2) );

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int inf=1e9;
int main(void)
{
    int ans=1;
    int N;
    cin >> N;
    for(int i=0;i<3;i++)
    {
        ans=ans*N;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
MOD = 10**9 + 7
N = int(input())
arr = list(map(int, input().split()))
arr_sum = sum(arr)
arr2 = [0]*N
for i in range(N):
    arr2[i] = arr_sum - arr[i]
ans = 0
for i in range(N):
    ans += arr2[i]*arr[i]
print((ans//2)%MOD)

Measured memory_bytes: 94128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vpi;
typedef double dl;
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define MOD 1e9+7
#define lb lower_bound
#define ub upper_bound
#define SZ(x) (int)x.size()
#define INF 1000000000

vi adjList[100100], rep[100100];
int useless[100100];
int col[100100];
int d[100100];
int p[100100];
int N,a,b,T;
string st;
int furthest;

void dfs(int x){
    if (adjList[x].size() == 1 && x != 1){
      useless[x] = !col[x]; // Returns 1 if it is white
      return;
    }
    bool bad = !col[x];
    for (auto i : adjList[x]){
      if (p[i] != -1)continue;
      p[i] = x;
      dfs(i);
      if (!useless[i])bad = 0;
    }
    useless[x] = bad;
}

void dfs2(int x){
  if (col[x])d[x]++;
  for (auto i : rep[x]){
    if (d[i] != -1)continue;
    d[i] = d[x];
    dfs2(i);
  }  
}

int R,P;
int32_t main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  // freopen("input.txt","r",stdin);
  cin >> N;
  for (int i =1;i<N;++i){
    cin>>a>>b;
    adjList[a].pb(b);
    adjList[b].pb(a);
  }
  cin>>st;
  for(int i=1;i<=N;++i)col[i] = (st[i-1] == 'W');
  memset(p,-1,sizeof(p));
  p[1] = 0;
  for (int i=1;i<=N;++i)d[i]=-INT_MAX;
  dfs(1);
  d[1] = 0;
  for (int i =1; i <= N; ++i){
    if (!useless[i]){
      ++R;
      for (auto it : adjList[i]){
        if (useless[it])continue;
        rep[i].pb(it);
      }
    }
  }
  int root = 1;
  while (rep[root].size() == 1 && col[root] == 0){
    int p =root;
    root = rep[root][0];
    --R;
    // cout << "FF\n";
    useless[p] = 1;
    rep[root].erase(find(rep[root].begin(),rep[root].end(),p));
  }
  if (R == 0){
    cout << 0;
    return 0;
  }
  --R;R*=2;
  for (int i = 1;i<=N;++i){
    if(useless[i])continue;
      if (!useless[i]){++P;}
    if (rep[i].size()%2)col[i] = 1-col[i];
    // cout << col[i] << ' ';
    if (col[i])++R;
  }
  // for (int i=1;i<=N;++i)cout<<col[i];cout<<'\n';
  // cout <<R  << '\n';
  if (P == 1 && col[root] == 1){
    cout << 1;
    return 0;
  }
  // cout <<'n';
  memset(d,-1,sizeof(d));
  d[1] = 0;
  dfs2(1);
  int ind = max_element(d+1,d+N+1) - d;
  memset(d,-1,sizeof(d));
  d[ind] = 0;
  dfs2(ind);
  // cout << R << '\n';
  cout << R - 2*(*max_element(d+1,d+N+1));
}

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

int main(int argc, const char * argv[]) {
    int A, B;
    int result = 0;
    cin >> A >> B;
    for (int i = 0; i < 2; i++) {
        if (A > B) {
            result += A;
            A--;
        } else {
            result += B;
            B--;
        }
    }
    
    cout << result << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int D,N;
    cin >> D >> N;
    
    if(D == 0){
        if( N < 100){
        cout << N << endl;
        }
        else{
            cout << N+1 << endl;
        }
    }
    else if(D == 1){
        if( N < 100){
        cout << N * 100 << endl;
        }
        else{
            cout << (N+1) * 100<< endl;
        }
    }
    else if(D == 2){
        if( N < 100){
        cout << N * 100 * 100<< endl;
        }
        else{
            cout << (N+1) * 100 * 100 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{

public static void main(String args[]){

Scanner scan = new Scanner(System.in);

int a = scan.nextInt();

int b = scan.nextInt();

 if(a>b){

System.out.println("a > b");

 }else if(a==b){

System.out.println("a == b");

 }else{

System.out.println("a < b");

 }
 }
 }


Measured memory_bytes: 26360
#include <stdio.h>

using namespace std;
int main(){
    int W,H,x,y,r;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    if((x >=r && x <=W-r)&&(y >=r && y<=H-r))
    printf("Yes\n");
    else{
        printf("No\n");
    }
}


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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) cerr<<(#v)<<":";for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;
#define printVS(vs) cerr<<(#vs)<<":"<<endl;for(auto(s):(vs)){cerr<<(s)<< endl;}
#define printVV(vv) cerr<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;}
#define printP(p) cerr<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cerr<<(#vp)<<":"<<endl;for(auto(p):(vp)){cerr<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cerr << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cerr << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1ll << 60;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;

int h;
int w = 5;
vvi a;

void fall() {
    for (int i = h - 1; i > 0; i--) {
        rep(j, w) {
            if (a[i][j]) continue;
            int k = i;
            while (k >= 0 && !a[k][j]) {
                k--;
            }
            if (k >= 0) {
                a[i][j] = a[k][j];
                a[k][j] = 0;
            }
        }
    }
}

int check() {
    int ret = 0;
    rep(i, h) {
        rep(j, w) {
            if (!a[i][j]) continue;
            int l = 0;
            while (j + l < w && a[i][j] == a[i][j + l]) {
                l++;
            }
            if (l >= 3) {
                rep2(k, j, j + l) {
                    ret += a[i][k];
                    a[i][k] = 0;
                }
            }
        }
    }

    fall();

    return ret;
}

void solve() {
    a.clear();
    a.resize(h);
    rep(i, h) a[i].resize(w);
    rep(i, h) rep(j, w) cin >> a[i][j];

    int ans = 0;
    int t;
    // printVV(a);
    while (true) {
        t = check();
        // printVV(a);
        if (!t) break;
        ans += t;
    }

    cout << ans << endl;
}

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

    while (cin >> h, h) solve();
}

Measured memory_bytes: 3144
N = int(input())
B = list(map(int, input().split()))

def solve(arr):
  ret = []
  while len(arr) > 0:
    before = len(arr)
    for i in reversed(range(len(arr))):
      if arr[i] == i + 1:
        ret.append(arr.pop(i))
        break
    if len(arr) == before:
      return None
  return list(reversed(ret))

A = solve(B)
#print(A)

if A == None:
  print(-1)
else:
  for a in A:
    print(a)

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
long long n,a,b,l,r;
int main()
{
	cin>>n>>a>>b;
	if(a>b){puts("0");return 0;}
	l=b+(n-1)*a,r=a+(n-1)*b;
	cout<<max(0ll,r-l+1)<<endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
L = list(map(int,input().split()))
L.sort()

c=0
n=len(L)
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if L[i]==L[j] or L[j]==L[k]:
                continue
            if L[i]+L[j]>L[k] :
                c+=1           
print(c)

Measured memory_bytes: 9128
#include<iostream>
#include<string>
#include<vector>
using namespace std;


int main() {

	int n,q;
	int b, c;

	int a[100005];
	long long x[100005] = { 0 };
	long long sum = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		x[a[i]]++;
		sum += a[i];
	}
	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> b >> c;

		if (x[b] == 0) {}
		else {
			sum = sum - x[b] * b + c * x[b];
			x[c] += x[b];
			x[b] = 0;
			
		}
		cout << sum << endl;
	}
}

Measured memory_bytes: 4804
#include<cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

ll solve(ll x, ll y) {
	if (x == 0 || y == 0) return 0;

	if (x < y && y % x == 0)return (y / x)*x * 2 - x;
	if (y < x && x % y == 0)return (x / y)*y * 2 - y;

	if (x < y)
		return solve(x, y - (y / x)*x) + (y / x)*x * 2;
	else if (x > y)
		return solve(x - (x / y)*y, y) + (x / y)*y * 2;
	else
		return x;
}

int main()
{
	ll N, X;
	cin >> N >> X;
	ll ans = solve(X,N-X)+N;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
n = input()
s = len(n)-1


for i in range(2**s):
  op = ""
  for j in range(s):
    if (i>>j)&1:
      op += "+"
    else:
      op += "-"
  ans =int(n[0])
  for j in range(len(op)):
    if op[j]=="+":
      ans += int(n[j+1])
    else:
      ans -= int(n[j+1])
  if ans == 7:
      ret = ""
      for k in range(len(op)):
        ret += n[k]
        ret += op[k]
      ret += n[-1]
      ret += "=7"
      print(ret)
      exit(0)

Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;
typedef pair<Int,Int> P;

int main(){
    int N; cin >> N;
    set<int> A;
    vector<int> kosuu(1000010, 0);

    rep(i,N){
        int a; cin >> a;
        A.insert(a);
        kosuu[a]++;
    }

    vector<bool> flag(1000010, true);

    int ans = 0;
    for(int x : A){
        if(!flag[x]){
            continue;
        } else {
            int now = x;
            while(now < 1000010){
                flag[now] = false;
                now += x;
            }
            if(kosuu[x] <=1 ) ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 16644
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#define int long long
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")

using namespace std;

const int N = 100777;
int n, m;
int a[N];
int s0, s1;


signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    cin >> n >> m;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
        a[i] /= 2;
        if (a[i] % 2 == 0){
            s0++;
        }
        else {
            s1++;
        }
    }

    if (s0 > 0 && s1 > 0){
        cout << 0 << endl;
        return 0;
    }

    int g = a[1];
    int mul = a[1];

    for (int i = 2; i <= n; i++){
        g = __gcd(mul, a[i]);
        mul = (mul * a[i]) / g;
        if (mul > m || mul < 0){
            cout << 0 << endl;
            return 0;
        }
    }
    


    //cout << mul << endl;

    int k = m / mul;

    if (s1 > 0){
        if (k % 2 == 0){
            cout << k / 2 << endl;
        }
        else {
            cout << k / 2 + 1 << endl;
        }
    }
    else {
        for (int i = 1; i <= n; i++){
            int t = mul / a[i];
            if (t % 2 == 0){
                cout << 0 << endl;
                return 0;
            }
        }
        if (k % 2 == 0){
            cout << k / 2 << endl;
        }
        else {
            cout << k / 2 + 1 << endl;
        }
    }



    return 0;
}


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

int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string S;
  cin>>S;
  int cnt=0;
  for (int i=0; i<3; i++) {
    if (S[i]=='o') {
      cnt++;
    }
  }
  cout<<700+100*cnt<<endl;
  return 0;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
mod=10**9+7
ll=[0]*(n+1)
ml=[0]*(n+1)
ml[0]=n
ans=0
for i in range(1,n+1):
  ll[i]=ll[i-1]+i
  ml[i]=ml[i-1]+n-i
for i in range(k-1,n+1):
  ans+=ml[i]-ll[i]+1
print(ans%mod)

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 2e5 + 5;

vi g[MAXN];

ll cnt[MAXN][2];

char label[MAXN];
int deleted[MAXN];

set<pair<ll, int> > st;

void solve(){
	int n, m, a, b;
	scanf("%d%d%s", &n, &m, &label[1]);
	REP(i, 0, m) {
		scanf("%d%d", &a, &b);
		g[a].pb(b);
		g[b].pb(a);
		cnt[a][label[b] - 'A']++;
		cnt[b][label[a] - 'A']++;
	}
	REPN(i, 1, n) {
		//printf("%d %lld %lld\n", i, cnt[i][0], cnt[i][1]);
		st.insert(mp(cnt[i][0] * cnt[i][1], i));
	}
	while(!st.empty()) {
		a = st.begin()->_2;
		//printf("# %d %lld %lld\n", a, cnt[a][0], cnt[a][1]);
		if (cnt[a][0] > 0 && cnt[a][1] > 0) {
			printf("Yes\n");
			return;
		}
		st.erase(st.begin());
		deleted[a] = 1;
		REP(i, 0, SZ(g[a])) {
			b = g[a][i];
			if (deleted[b]) {
				continue;
			}
			st.erase(mp(cnt[b][0] * cnt[b][1], b));
			cnt[b][label[a] - 'A']--;
			st.insert(mp(cnt[b][0] * cnt[b][1], b));
		}
		
	}
	printf("No\n");
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 26240
a = 0
l = []
f = 0
N, M = map(int, input().split())
for i in range(N):
    A, B = map(int, input().split())
    l.append([A, B])
l_sorted = sorted(l, key=lambda x: x[0])
while True:
    if l_sorted[f][1] < M:
        a += l_sorted[f][1] * l_sorted[f][0]
        M -= l_sorted[f][1]
        f += 1
    else:
        a += M * l_sorted[f][0]
        break
print(a)


Measured memory_bytes: 21984
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
    string a;
    int b=0, ans=0;
    cin >> a;
    for(int i=0; i<a.size(); i++)
    {
        if(a[i]=='A'||a[i]=='C'||a[i]=='G'||a[i]=='T')
        {
            b++;
            ans=max(ans,b);
        }
        else
            b=0;
    }
    cout << ans << '\n';
}

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

int tw(int x){
    return x*x;
}

signed main(){
    int n;cin>>n;
    int t[n][2];
    rep(i,n)cin>>t[i][0]>>t[i][1];
    int o[n];
    rep(i,n)o[i]=i;
    double sum=0;
    do{
        int b[2]={t[o[0]][0],t[o[0]][1]};
        for(int i=1;i<n;i++){
            sum+=sqrt(tw(b[0]-t[o[i]][0])+tw(b[1]-t[o[i]][1]));
            b[0]=t[o[i]][0],b[1]=t[o[i]][1];
        }
    }while(next_permutation(o,o+n));
    int av=1;
    rep(i,n)av*=i+1;
    printf("%.10lf\n",sum/av);
}

Measured memory_bytes: 256
s = input()
s = s[::-1]
i = 0
while(i != len(s)):
    if s[i: i+5] == 'maerd':
        i = i + 5
        continue
    elif s[i: i+7] == 'remaerd':
        i = i + 7
        continue
    elif s[i: i+5] == 'esare':
        i = i + 5
        continue
    elif s[i: i+6] == 'resare':
        i = i + 6
        continue
    else:
        print('NO')
        exit()

print('YES')


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

long long cnt;
int l;
int A[1000000];
int n;
vector<int> G;

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

void shellSort(int A[], int n)
{
  for (int h = 1;;)
  {
    if (h > n)
      break;
    G.push_back(h);
    h = 3 * h + 1;
  }

  for (int i = G.size() - 1; i >= 0; i--)
  {
    insertionSort(A, n, G[i]);
  }
}

int main()
{
  cin >> n;
  for (int i = 0; i < n; i++)
  {
    scanf("%d", &A[i]);
    cnt = 0;
  }

  shellSort(A, n);

  cout << G.size() << endl;
  for (int i = G.size() - 1; i >= 0; i--)
  {
    printf("%d", G[i]);
    if (i)
      printf(" ");
  }
  printf("\n");
  printf("%d\n", cnt);
  for (int i = 0; i < n; i++)
  {
    printf("%d\n", A[i]);
  }
  return 0;
}


Measured memory_bytes: 7140
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++);
#define FOR(i, m, n) for(int i = m; i < n; i++);
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef long long ll;

int main(){
    string s, t, u;
    int a, b;
    cin >> s >> t >> a >> b >> u;
    if(s == u){
        cout << a-1 << " " << b;
    }else {
        cout << a << " " << b-1;
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 101
int datanum;
void print(int a[]){
  int i;
  for(i=0;i<datanum;i++){
    if(i)printf(" ");
    printf("%d",a[i]);
  }
  printf("\n");
}








int main(){
  int v,i,j;
  int a[MAX];
  scanf("%d",&datanum);
  for(i=0;i<datanum;i++){
    scanf("%d",&a[i]);
  }
  print(a);
  for(i=1;i<datanum;i++){
    v = a[i];
    j = i-1;
    while(j >= 0 && a[j] > v){
      a[j+1] = a[j];
      j--;
    }
    a[j+1] = v;
    print(a);
  }
  
  return 0;
}



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

int main(void)
{
    char str[200];
    int i;
    
    scanf("%[^\n]%*c", str);
    for (i = 0; i < strlen(str); i++) {
        if (str[i] == ' ' || str[i] == '.') {
            continue;
        }
        str[i] -= 32;
    }
    printf("%s\n", str);
    return 0;
}

Measured memory_bytes: 520
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int x = sc.nextInt();
		int y = sc.nextInt();
		
		for (int i = 0; i <= x; i++) {
			if (i * 2 + (x - i) * 4 == y) {
				System.out.println("Yes");
				return;
			}
		}
		
		System.out.println("No");
		
		sc.close();
	}
}




Measured memory_bytes: 27104
using System;
using System.Collections.Generic;

namespace MyProgram{
    class AtCoder{
        static void Main(string[] args){
            long[] input = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
            long N = input[0];
            long M = input[1];
            List<Shop> shop = new List<Shop>();
            
            for(var i=0;i<N;i++){
                long[] input1 = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
                Shop s = new Shop();
                s.A = input1[0];
                s.B = input1[1];
                shop.Add(s);
            }
            shop.Sort(delegate(Shop a,Shop b){return (int)(a.A-b.A);});
        
            long sum_money=0;
            long count=0;
            for(var i=0;i<N;i++){
                for(var j=0;j<shop[i].B;j++){
                    sum_money += shop[i].A;
                    count++;
                    if(count>=M)goto END;
                }
            }
            END:
            Console.WriteLine(sum_money);
        }
    } 
    public class Shop{
        public long A;
        public long B;
    }
}

Measured memory_bytes: 23872
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BGoldenApple solver = new BGoldenApple();
        solver.solve(1, in, out);
        out.close();
    }

    static class BGoldenApple {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt(), d = in.nextInt();
            d = (2 * d + 1);
            int answer = n / d;
            if (answer * d < n)
                answer++;

            out.println(answer);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 21460
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	static int[][] map;
	static int[][] directions8 = { { -1, -1 }, { -1, 0 }, { -1, 1 }, { 0, -1 }, { 0, 1 }, { 1, -1 }, { 1, 0 },
			{ 1, 1 } };
	static int[][] directions4 = { { -1, 0 }, { 1, 0 }, { 0, -1 }, { 0, 1 } };
	static int ans;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int p = sc.nextInt();
		int q = sc.nextInt();

		q = q / gcd(p, q);

		ans = 1;
		int idx = 2;
		boolean[] divided = new boolean[q + 1];
		if (isPrime(q)) {
			System.out.println(q);
		} else {
			while (q != 1) {
				if (!divided[idx] && q % idx == 0) {
					ans *= idx;
					while (q % idx == 0) {
						q /= idx;
					}
					for (int i = idx; i * i <= q; i += idx) {
						divided[i] = true;
					}
				}
				idx++;
			}

			System.out.println(ans);
		}
	}

	// longの素数判定
	static boolean isPrime(long n) {
		if (n == 2)
			return true;
		if (n < 2 || n % 2 == 0)
			return false;

		int i = 3;
		while (i <= Math.sqrt(n)) {
			if (n % i == 0)
				return false;
			else
				i += 2;
		}
		return true;
	}

	// BFS用に二つの配列を足し算する
	static int[] addArrayElms(int[] a, int[] b) {
		int[] c = new int[a.length];
		for (int i = 0; i < a.length; i++) {
			c[i] = a[i] + b[i];
		}
		return c;
	}

	// //二分探索
	// k <= num となる最小の配列要素kのインデックスを返す
	static private int binarySearch(long num, long[] orderedArray) {
		int lowerBorder = -1;
		int upperBorder = orderedArray.length;
		int mid;

		while (upperBorder - lowerBorder > 1) {
			mid = (upperBorder + lowerBorder) / 2;
			if (orderedArray[mid] <= num) {
				lowerBorder = mid;
			} else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	// 二分探索
	// k <= num となる最小のList要素kのインデックスを返す
	static private int binarySearch(long num, ArrayList<Long> orderedList) {
		int lowerBorder = -1;
		int upperBorder = orderedList.size();
		int mid;

		while (upperBorder - lowerBorder > 1) {
			mid = (upperBorder + lowerBorder) / 2;
			if (orderedList.get(mid) <= num) {
				lowerBorder = mid;
			} else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	// aとbの最小公倍数を求める
	public static int gcd(int a, int b) {
		return b == 0 ? a : gcd(b, a % b);
	}

	public static long gcd(long a, long b) {
		return b == 0 ? a : gcd(b, a % b);
	}
}



Measured memory_bytes: 1006652
#include<cstdio>
#include<algorithm>
#define MOD 1000000007
#define MAXN 2000006
using namespace std;
long long fac[MAXN],inv[MAXN],ans;
int x1,x2,x3,x4,x5,x6,y1,y2,y3,y4,y5,y6;
long long C(int m,int n)
{
	return (fac[n]*inv[m]%MOD)*inv[n-m]%MOD;
}
long long ksm(long long a,long long b)
{
	if(!b) return 1;
	long long nex=ksm(a,b/2);
	nex=nex*nex%MOD;
	if(b%2) nex=nex*a%MOD;
	return nex;
}
long long sum(int x1,int y1,int x2,int y2,int x3,int y3)
{
	long long re=0;
	for(int i=y1;i<=y2;i++)
		re=((C(x3-x2-1,x3-x2-1+y3-i)*C(x2-x1,x2-x1+i-y1)%MOD)*(x2-x1+1+i-y1)+re)%MOD;
	for(int i=x1;i<=x2;i++)
		re=(re+(C(y3-y2-1,y3-y2-1+x3-i)*C(y2-y1,y2-y1+i-x1)%MOD)*(y2-y1+1+i-x1))%MOD;
	return re;
}
long long cont(int a1,int b1,int a2,int b2)
{
	long long re=0;
	re+=sum(a1,b1,x4,y4,a2,b2);
	re+=sum(a1,b1,x3-1,y3-1,a2,b2);
	re-=sum(a1,b1,x3-1,y4,a2,b2);
	re-=sum(a1,b1,x4,y3-1,a2,b2);
	return re;
}
long long work(int x,int y)
{
	long long re=0;
	re+=cont(x,y,x6+1,y6+1);
	re+=cont(x,y,x5,y5);
	re-=cont(x,y,x6+1,y5);
	re-=cont(x,y,x5,y6+1);
	return (re%MOD+MOD)%MOD;
}
int main()
{
	scanf("%d%d%d%d%d%d",&x1,&x2,&x3,&x4,&x5,&x6);
	scanf("%d%d%d%d%d%d",&y1,&y2,&y3,&y4,&y5,&y6);
	fac[0]=1;
	for(int i=1;i<MAXN;i++)
		fac[i]=fac[i-1]*i%MOD;
	inv[MAXN-1]=ksm(fac[MAXN-1],MOD-2);
	for(int i=MAXN-2;i>=0;i--)
		inv[i]=inv[i+1]*(i+1)%MOD;
	ans+=work(x1-1,y1-1);
	ans+=work(x2,y2);
	ans-=work(x1-1,y2);
	ans-=work(x2,y1-1);
	ans=(ans%MOD+MOD)%MOD;
	printf("%lld\n",ans);
}

Measured memory_bytes: 31488
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    string S; cin >> S;
    string out="";
    for(int i=0;i<26;i++){
        bool f=true;
        for(int j=0;j<S.size();j++){
            if(S[j]=='a'+i){
                f=false;
            }
        }
        if(f){
            out = 'a'+i;
            break;
        }
    }
    if(out=="") cout << "None" << endl;
    else  cout << out << endl;
    return 0;
}


Measured memory_bytes: 512
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**9)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

a,b,c = na()

if c-a-b > 0 and (4*a*b) < (c-a-b)*(c-a-b):
	print('Yes')
else:
	print('No')

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

using namespace std;
const int N = 3e5;

int n;
int size[N], color[N], col[N], res[N];
vector < int > a[N];

int sum(int x) {
	return x * (x+1) / 2;
}

int read(void)
{
	int s = 0, w = 0; char c = getchar();
	while (c < '0' || c > '9') w |= c == '-', c = getchar();
	while (c >= '0' && c <= '9') s = s*10+c-48, c = getchar();
	return w ? -s : s;
}

void dfs(int x,int fa)
{
	size[x] = 1;
	int temp = col[color[x]], c = color[x];
	for (int i=0;i<a[x].size();++i)
	{
		int y = a[x][i];
		if (y == fa) continue;
		int t = col[c];
		dfs(y,x);
		int Ad = col[c] - t;
		size[x] += size[y];
		res[c] -= sum(size[y] - Ad);
	}
	col[c] = temp + size[x];
	return;
}

signed main(void)
{
	n = read();
	for (int i=1;i<=n;++i) color[i] = read();
	for (int i=1,x,y;i<n;++i)
	{
		x = read(), y = read();
		a[x].push_back(y);
		a[y].push_back(x);
	}
	for (int i=1;i<=n;++i) res[i] = sum(n);
	dfs(1,0);
	for (int i=1;i<=n;++i) 
		printf("%lld\n", res[i] - sum(n-col[i]));
	return 0;
}

Measured memory_bytes: 41960
def main():
    A = int(input())
    P = [int(x) for x in input().split()]

    count = 0
    for idx in range(len(P)):
        if P[idx] != idx+1:
            if P[P[idx]-1] == idx+1:
                count += 1
                if count == 3:
                    print('NO')
                    return
            else:
                print('NO')
                return

    print('YES')


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
using namespace std;

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

  string s;
  ll k;
  cin >> s >> k;

  char ans = '1';
  ll minl = min(k, (ll)s.length());
  for(int i = 0; i < minl; ++i) {
    if(s[i]!='1') {
      ans = s[i];
      break;
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn main() {
    let m: usize = read();
    let k: usize = read();
    
    let max = 2usize.pow(m as u32);
    if max <= k {
        println!("-1");
        return;
    }
    if m == 1 && k == 1 {
        println!("-1");
        return;
    }

    print!("0");
    if k != 0 {
        print!(" {}", k);
    }
    print!(" 0");
    for i in 1..max {
        if i != k {
            print!(" {}", i);
        }
    }
    if k != 0 {
        print!(" {}", k);
    }
    for i in (1..max).rev() {
        if i != k {
            print!(" {}", i);
        }
    }
    println!();
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


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

int main(){
  int n, m; cin >> n >> m;
  vector<vector<int>> s(m);
  for (int i = 0; i < m; i++){
    int k; cin >> k;
    for (int j = 0; j < k; j++){
      int t; cin >> t; t--;
      s.at(i).push_back(t);
    }
  }
  vector<int> p(m);
  for (int i = 0; i < m; i++){
    cin >> p.at(i);
  }

  int ans = 0;
  for (int i = 0; i < (1 << n); i++){
    bitset<10> b(i);
    bool ok = true;
    for (int j = 0; j < m; j++){
      int sum = 0;
      for (int k : s.at(j)) if (b.test(k)) sum++;
      if (sum%2 != p.at(j)){
        ok = false;
        break;
      }
    }
    if (ok) ans++;
  }
  cout << ans << endl;
}

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

using namespace std;
int main(){
	int N;
	char S[1000];
	int count=0;
	cin >> N;
	for(int i=1; i<=N; i++){
		cin >> S[i];
	}
	for(int j=1; j<=(N-1); j++){
		std::vector<char> v;
		int k=0;
		for(int l=1; l<=j; l++){
		for(k=(j+1); k<=N; k++){
				if(S[l]==S[k]) v.push_back(S[l]);
			}
		}
		std::sort(v.begin(), v.end());
		v.erase(std::unique(v.begin(), v.end()), v.end());
        int temp = v.size();
		if(count < temp) count = temp;
      
	}
	cout << count<< endl;

	return 0;
}

Measured memory_bytes: 256