akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<stdio.h>//printf("%.*f\n",*********);
#include<vector>//s.erase(n),vector
#include<algorithm>//next_permutation
#include<set>
#include<string>//char('a'=32+'A')
//to_string,string,substr
#include<sstream>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>//min,max
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap

#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)//start==1
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)//end==1
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define Yay(ans) if(ans)cout<<"Yay!"<<rt;else cout<<":("<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(a,n) rep(i,n)cin>>a[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//昇順
#define reve(s) reverse(s.begin(),s.end())//反転
#define please return
#define AC 0
#define rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define pi 3.1415926535897932384626//pi
#define nine 1000000000//10^9

using namespace std;
typedef vector<int> vint;
typedef long double ldouble;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef vector<double> vdouble;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

int KETA(int n) { //Sum of Each Digit
	int sum = 0;
	while (n > 0) {
		sum += n % 10; n /= 10;
	}
	return sum;
}

unsigned ND(unsigned num) {//Number of Digits
	return std::to_string(num).length();//outmax=10
}

bool KIBN(string s) {
	rep(i, s.size() / 2) {
		if (s[i] != s[s.size() - 1 - i])return false;
	}
	return true;
}

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */

int main(void) {

	int n;
	cin >> n;
	vint a(n);
	vcin(a, n-1);
	vint ans(n);
	rep(i, n-1) {
		ans[a[i]-1]++;
	}
	rep(i, n) {
		cout << ans[i] << rt;
	}

	please AC;
}
//参考：---;

Measured memory_bytes: 4768
n = int(input())

res = 1

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

for i in a:
    res *= i
    
    if (res > 1000000000000000000):
        res = -1
        break
        

if res == -1:
    for i in a:
        if i == 0:
            res = 0
            break

print(res)

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

int main(void) {
	int n, x, m[100];
	int sum = 0, donut = 0, min_gram = 1000;
	cin >> n >> x;
	for (int i = 0; i < n; i++) {
		cin >> m[i];
		sum += m[i];
		donut++;
		min_gram = min(min_gram, m[i]);
	}
	cout << (x - sum) / min_gram + donut << endl;
	return 0;
}


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

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;


int main(void){
	string s;
	cin >> s;
	int n = s.size() - 1;
	ll ans = 0;

	rep(mask, 0, 1 << n) {
		int l = 0;
		int r;
		for(r = 0; r < n; r++) {
			if((mask & 1 << r)) {
				string t = s.substr(l, r - l + 1);
				ll tmp = stoll(t);
				ans += tmp;
				l = r + 1;
			}
		}
		string t = s.substr(l, r - l + 1);
		ll tmp = stoll(t);
		ans += tmp;
	}

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


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

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
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; }

using ll = long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class AHitachiString {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      string s; cin >> s;

      if (s == "hi" || s == "hihi" || s == "hihihi" || s == "hihihihi" || s == "hihihihihi") {
        cout << "Yes" << endl;
      } else {
        cout << "No" << endl;
      }

    }
};

signed main() {
  AHitachiString solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  string b;
  cin >>b;
  cout<<b.at(0)<<b.at(1)<<b.at(2)<<b.at(3)<<b.at(4)<<" "<<b.at(6)<<b.at(7)<<b.at(8)<<b.at(9)<<b.at(10)<<b.at(11)<<b.at(12)<<" "<<b.at(14)<<b.at(15)<<b.at(16)<<b.at(17)<<b.at(18)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)  for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define deb(x) cerr << #x <<": " << x << '\n';
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
typedef long long ll;

int main(){
    ios;
    int l, r, d; cin >> l >> r >> d;
    int cnt = 0;
    for(int i = l; i <= r; ++i){
        if(i % d == 0) cnt++;
    }
    cout << cnt;
    return 0;
}


Measured memory_bytes: 3648
//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<queue>
using namespace std;

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

  int count = 0;
  int m = 0;
  for(int i=n;i>0;i--){
    count = 0;
    for(int j=1;j<=n/i;j++){
      count += b[i*j];
    }
    if(count%2 == a[i]%2) b[i] = 0;
    else{
      b[i] = 1;
      m += 1;
    }
  }

  cout << m << endl;
  for(int i=1;i<n+1;i++){
    if(b[i] > 0) cout << i << ' ';
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 2432
use std::io::prelude::*;

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

fn main() {
    let n: usize = input();
    let s: Vec<char> = input::<String>().chars().collect();

    let mut x = 0;
    let mut ans = 0;
    for i in 0..n {
        if s[i] == 'I' {
            x += 1;
        } else {
            x -= 1;
        }
        ans = std::cmp::max(ans, x);
    }
    println!("{}", ans);
}


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

int main() {
  int k, a, b;
  cin >> k;
  cin >> a >> b;

  bool x = false;
  for (int i = a; i <= b; i++) {
    if (i%k == 0) {
      x = true;
      break;
    }
  }
  
  if (x == true) {
    cout << "OK" << endl;
  } else {
    cout << "NG" << endl;
  }
}


Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
	int count=0;
	string s;
	cin>>s;
	cout<<s[0];
	for(int i=0;i<s.size();i++){
		count++;
	}
	count-=2;
	cout<<count;
	cout<<s[s.size()-1]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef  long long  ll;
ll inf=1000000000000000,mod=1000000007;
ll power(ll a,ll b){
    ll res=1;
    a%=mod;
    while(b){
        if(b&1)
        res=(res*a)%mod;
        a=(a*a)%mod;
        b/=2;
    }
    return res;
}
int main(){
    ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        
        ll n;
        cin>>n;
        ll arr[n];
        for(ll i=0;i<n;i++)cin>>arr[i];
        ll dp[n][2];
        for(ll i=0;i<n;i++)for(ll j=0;j<2;j++)dp[i][j]=0;
        //0 i+1/2 1 i+1/2+1
        dp[0][0]=0;dp[0][1]=arr[0];
        dp[1][0]=max(arr[0],arr[1]);dp[1][1]=-inf;
        for(ll i=2;i<n;i++){
            if(i%2==0){
                dp[i][0]=dp[i-1][0];
                dp[i][0]=max(arr[i]+dp[i-2][0],dp[i][0]);
                dp[i][1]=arr[i]+dp[i-2][1];
            }
            else{
                dp[i][0]=dp[i-1][1];
                dp[i][0]=max(dp[i][0],arr[i]+dp[i-2][0]);
                dp[i][1]=-inf;
            }
        }
        cout<<max(dp[n-2][1],dp[n-1][0]);

}


Measured memory_bytes: 8296
#include<bits/stdc++.h>
#include <stdio.h>
using namespace std;
#define M1 (ll)1000000007
#define M2 (ll)998244353
#define Pi 3.141592653
#define exp 2.71828
#define ll long long
#define ull unsigned long long
#define pi pair<int,int>
#define pl pair<ll,ll> 
#define vi vector<int>
#define vl vector<ll>
#define di deque<int>
#define dl deque<ll>
#define dii deque<pi>
#define dll deque<pl>
#define vvi vector<vi>
#define vvl vector<vl>
#define vii vector<pi>
#define vll vector<pl>
#define pb push_back
#define pp pop_back
#define pf push_front
#define pt pop_front
#define mp make_pair
#define in insert
#define er erase
#define ff first
#define ss second
#define ub upper_bound
#define lb lower_bound
#define rp(i,a,b) for(int i=a;i<b;i++)
#define rpt(i,a,b,t) for(int i=a;i<b&&t<1;i++)
#define rep(i,n) for(int i = 0 ; i<n ; i++)
#define rept(i,n,t) for(int i = 0 ; i<n&&t<1 ; i++)
#define repr(i,n) for(int i = n-1 ; i>=0 ; i--)
#define reprt(i,n,t) for(int i=n-1;i>=0&&t<1;i--)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define SORT(v) sort(v.begin(),v.end())
using namespace std;
bool cmp(pair<int,int> i,pair<int,int> j){
    return i.first<j.first;
}
int main() {
    fast
    int n;
    ll w;
    cin>>n>>w;
    int v[n+1][2];
    for(int i=1;i<n+1;++i) cin>>v[i][0]>>v[i][1];
    ll value=0;
    for(int i=1;i<n+1;++i) value += v[i][1];
    // cout<<value<<'\n';
    ll dp[value+1][n+1];
    bool flag[value+1][n+1];
    for(int i=0;i<value+1;++i) for(int j=0;j<n+1;++j) dp[i][j]=INT_MAX,flag[i][j]=false;
    // flag[0][0] = 1;
    for(int i=0;i<n+1;++i) flag[0][i]=true,dp[0][i]=0;
    for(int i=1;i<value+1;++i){
        for(int j=1;j<n+1;++j){
            if(flag[i][j-1]){
                //  if(i==30 && j==1) cout<<"gotcha1"<<'\n'; 
                dp[i][j] = dp[i][j-1],flag[i][j]=true;
            }
            if(i-v[j][1]>=0 && flag[i-v[j][1]][j-1]){
                //  if(i==30 && j==1) cout<<"gotcha2"<<'\n'; 
                dp[i][j] = min(dp[i][j],dp[i-v[j][1]][j-1]+v[j][0]),flag[i][j]=true;
            }
            // if(i==30 && j==1) cout<<dp[i][j]<<'\n';  80 2 30 1
        }
    }
    int result = 0;
    for(int i=1;i<value+1;++i){
        for(int j=1;j<n+1;++j){
            if(flag[i][j] && dp[i][j]<=w) result = max(result,i);
        }
    }
    // for(int i=0;i<value+1;++i){
    //     for(int j=0;j<n+1;++j){
    //         cout<<flag[i][j]<<" ";
    //     }
    //     cout<<'\n';
    // }
    // cout<<'\n';
    // cout<<flag[30][1]<<" "<<dp[30][1];
    cout<<result;
}


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

int main(){
    long long n;
    cin >> n;
    long long a[n];
    for(int i=0;i<n;i++) cin >> a[i];
    long long count=0;
    for(int i=0;i<n;i++){
        while(a[i]%2==0&&a[i]!=0){
            count++;
            a[i]=a[i]/2;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
struct SegTree {
    int N;
    vector<double> A;
    SegTree(int n) {
        N = 1; while (N < n) N *= 2;
        A.resize(2*N, 1.0);
    }
    void add(int idx, int p) {
        idx += N;
        A[idx] *= 1.0 - (0.1 * p);
        idx /= 2;
        while (idx > 0) {
            A[idx] = A[2*idx+0] * A[2*idx+1];
            idx /= 2;
        }
    }
    double get(int L, int R) {
        L += N, R += N;
        double ans = 1.0;
        while (L < R) {
            if (L & 1) ans *= A[L++];
            if (R & 1) ans *= A[--R];
            L /= 2, R /= 2;
        }
        return ans;
    }
};
int main() {
    int N; cin >> N;
    vector<int> T(N), A(N); for (int i = 0; i < N; i++) cin >> T[i] >> A[i];
    int Q; cin >> Q;
    vector<int> L(Q), R(Q); for (int i = 0; i < Q; i++) cin >> L[i] >> R[i];
    vector<int> I(N); iota(begin(I), end(I), 0);
    set<int> S;
    for (int i = 0; i < N; i++) S.insert(T[i]);
    map<int, int> M;
    auto it = S.begin();
    for (int i = 0; i < S.size(); i++) {
        M[*it] = i;
        ++it;
    }
    SegTree st(S.size());
    for (int i = 0; i < N; i++) {
        st.add(M[T[i]], A[i]);
    }
    cout << fixed << setprecision(9);
    for (int i = 0; i < Q; i++) {
        int left, right;
        auto it = M.lower_bound(L[i]);
        if (it == M.end()) {
            left = S.size();
        } else {
            left = it->second;
        }
        it = M.lower_bound(R[i]);
        if (it == M.end()) {
            right = S.size();
        } else {
            right = it->second;
        }
        cout << 1e9 * st.get(left, right) << '\n';
    }
    return 0;
}



Measured memory_bytes: 16244
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int MAXN = 234;
int edge[MAXN][MAXN];
char s[MAXN];
int color[MAXN], visit[MAXN];

int dfs(int cur, int flg, int N) {
    color[cur] = flg;
    visit[cur] = 1;
    for (int i = 0; i < N; i++) {
        if (i == cur) continue;
        if (edge[cur][i]) {
           if (visit[i]) {
              if (color[i] == color[cur]) return 0;
           } else if (!dfs(i, flg ^ 1, N)) return 0;
        }
    }
    return 1;
}

int check(int cur, int N) {
    vector<int> qu;
    memset(visit, 0, sizeof(visit));
    qu.push_back(cur);
    visit[cur] = 1;
    int ans = 0;
    while (!qu.empty()) {
          vector<int> nqu;
          for (int i : qu) {
              for (int j = 0; j < N; j++) {
                  if (!edge[i][j] || j == i || visit[j]) continue;
                  visit[j] = 1;
                  nqu.push_back(j);
              }
          }
          qu = nqu;
          ans++;
    }
    return ans;
}

int main() {
    int N;
    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        scanf("%s", s);
        for (int j = 0; j < N; j++) {
            if (s[j] == '1') edge[i][j] = 1;
        }
    }
    if (!dfs(0, 0, N)) puts("-1");
    else {
       int ans = 0;
       for (int i = 0; i < N; i++) {
           ans = max(ans, check(i, N));
       }
       printf("%d\n", ans);
    }
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;


int main() {
  int N,Z,W;
  cin >> N >> Z >>W;
  vint a(N);
  repeat(i,N){
    cin >> a[i];
  }
  int ans = (N==1)? abs(W-a[N-1]):max(abs(W-a[N-1]),abs(a[N-1]-a[N-2]));
  cout << ans << endl;
  return 0;
}


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

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


char H[M][L];

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

long long getKey(char *str) {
    long long sum = 0, p = 1;
    for (int 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() {
    int i, n, h;
    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: 16052
#include <bits/stdc++.h>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = INT_MAX / 2;

// 3234566667

vector<int64_t> ans;

void dfs(deque<int8_t>& val) {
  auto insert = [](deque<int8_t> val){
    auto digits = std::accumulate(val.begin(), val.end(), 0LL, [](auto acc, auto digit){
      return 10 * acc + digit;
    });
    ans.push_back(digits);
  };

  if (val.size() == 9) {
    REP(i, 1, 4) if (abs(val[0] - i) <= 1) {
      val.push_front(i);
      insert(val);
      val.pop_front();
    }
  }
  else {
    rep(i, 10) if (val.empty() || abs(val[0] - i) <= 1) {
      val.push_front(i);
      if (i) {
        insert(val);
      }
      dfs(val);
      val.pop_front();
    }
  }
}

int main() {
  deque<int8_t> val;
  dfs(val);
  sort(ans.begin(), ans.end());
  int K; cin >> K;
  assert(K <= ans.size());
  cout << ans[K - 1] << "\n";
}


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

int main(int argc, char *argv[]) {
    int n;
    cin >> n;
    n=n%10;
    if(n==3) cout << "bon" << endl;
    else if(n==0 || n==1 || n==6 || n==8) cout << "pon" << endl;
    else cout << "hon" << endl;
    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
int dy[] = {1,0,0,-1};
int dx[] = {0,1,-1,0};
typedef pair<int,int> P;

int w,h;
char c[100][100];
bool used[100][100];
int g[100][100];

int INF = 1000000000;
int d[100][100];
int bfs(P s,P e) {
    rep(i,h)rep(j,w)d[i][j] = INF;

    queue<P> que;

    que.push(s);
    d[s.first][s.second] = 0;

    while(!que.empty()) {
        P p = que.front();
        que.pop();

        rep(i,4) {
            int y = p.first + dy[i],x = p.second + dx[i];
            if(0 <= y && y < h && 0 <= x && x < w && d[y][x] == INF && c[y][x] != 'x') {
                d[y][x] = d[p.first][p.second] + 1;
                que.push(P(y,x));
            }
        }
    }
    return d[e.first][e.second];
}

int main() {
    while(true) {
        cin >> w >> h;
        if(w==0)break;

        rep(i,h)cin >> c[i];

        vector<P> dt;
        rep(i,h)rep(j,w)if(c[i][j] == '*')dt.push_back(P(i,j));
        if(dt.size() == 0){
            cout << 0 << endl;
            continue;
        }

        int perm[dt.size()];

        rep(i,dt.size()) perm[i] = i;

        P s;
        rep(i,h)rep(j,w) if(c[i][j] == 'o')s = P(i,j);

        rep(i,dt.size()) {
            g[dt.size()][i] = g[i][dt.size()] = bfs(s,dt[i]);
        }
        rep(i,dt.size()) {
            for(int j = i + 1;j < dt.size();j++) {
                g[i][j] = g[j][i] = bfs(dt[i],dt[j]);
            }
        }
        /*rep(i,dt.size()+1) {
            rep(j,dt.size()+1) {
                cout << g[i][j] << " ";
            }
            cout << endl;
        }*/

        int ans = INF;
        do {
            int sum = g[dt.size()][perm[0]];
            if(sum >= INF)break;

            rep(i,dt.size()-1) {
                sum += g[perm[i]][perm[i+1]];
                if(sum >= INF)break;
            }
            if(sum >= INF)break;
            ans = min(ans,sum);
        }while(next_permutation(perm,perm+dt.size()));
        if(ans < INF)
            cout << ans << endl;
        else
            cout << -1 << endl;
    }
}


Measured memory_bytes: 3152
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from itertools import combinations 
def main():
    N = int(readline())
    L = [int(i) for i in readline().split()]

    #ソートしておく
    L.sort()

    #最長以外の二辺を先に決める
    #インデックスで二辺を選ぶ。最長の辺はjよりインデックスが大きいものとなることが保証される
    #jより後ろでc<a+bとなる最長の辺cの数を求めれば良い。二分探索で条件を満たす最大の辺を見つけるとよい

    #インデックス用の値を用意
    p = [i for i in range(N)]

    #組みを作る
    idxPairs = [(i, j) for i,j in combinations(p, 2)]

    #jよりインデックスが大きい辺の中から最長の辺を見つける
    ans = 0
    for i, j in idxPairs:
        #j以降を二分探索で調べる
        #最長の辺をL[j]と選ぶと必ず三角形を作ることができる
        l = j
        r = N 
        while r-l>1:
            mid = (r+l)//2
            if L[mid] < L[i]+L[j]:
                l = mid
            else:
                r = mid
        ans += l-j
    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 213936
S = []
N,M = [int(i) for i in input().split(" ")]

for  _ in range(M):
    s,c = input().split(" ")
    S.append([int(s)-1,c])

start = 0 if N == 1  else 10**(N-1)
ans = -1
for num in range(start,10**N):
    flag = True
    s_num = str(num)
    for s in S:
        if (s_num[s[0]] != s[1]):
            flag = False
            break
    if (flag):
        ans = num
        break

print (ans)


Measured memory_bytes: 38256
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int A = in.nextInt();
            int B = in.nextInt();
            int C = in.nextInt();
            if (A == B) {
                System.out.println(C);
            } else if (A == C) {
                System.out.println(B);
            } else {
                System.out.println(A);
            }
        }
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

const ll N=1e7+10;
vec al(N);
vec all(N);
vec so;
ll n;

ll dfs(ll m, ll cur, ll id) {
  ll res=m*cur;
  for(ll i=id;i<so.size()&&so[i]*m<=n;i++) {
    ll cnt=1;
    if(i==id) {
      ll tm=m;
      while(tm&&tm%so[id]==0) {
        tm/=so[id];
        cnt++;
      }
    }
    res+=dfs(so[i]*m,cur/cnt*(cnt+1),i);
  }
  return res;
}

int main() {
  cin >> n;
  al[1]=1;
  for(ll i=2;i<=n;i++) {
    if(all[i]) continue;
    ll tmp=2;
    so.push_back(i);
    while(i*tmp<=n) {
      all[i*tmp]=1;
      tmp++;
    }
  }
  ll ans=dfs(1,1,0);
  cout << ans << endl;
}

Measured memory_bytes: 167832
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
#define ALL(X) X.begin(), X.end()
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef std::pair<LL,LL> PLL;//
typedef std::pair<int,int> PII;//
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	int N;
	cin >> N;
	vector<int> A(N+1);
	vector<bool> use(N+1,false);
	use[1] = true;

	for(int i=1;i<=N;++i){
		cin >> A[i];
	}
	int now = 1;
	int ans = 0;
	bool flag = false;
	for(int i=1;i<=N;++i){
		now = A[now];
		++ans;
		if( now == 2 ){
			flag = true;
			break;
		}
		if( use[now] ){//ループ
			break;
		}
		use[now] = true;
	}

	if( flag == false ){
		cout << -1 << endl;
	}else{
		cout << ans << endl;
	}
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <queue>
using namespace std;
typedef long long int ll;
const int INF = 100000000;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
int main(){
    const int n = 10;
    vector <int> m(n);
    rep(i, n) cin >> m[i];
    sort(m.begin(), m.end());
    for(int i = n-1; i >= n-3; --i){
        cout << m[i] << endl;
    }
    return 0;
}

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

/* short names and const
using ll = long long;
using vll = vector<long long>;
using df = vector<vector<long long>>;
df data(n, vector<long long>(m));
const int MOD = 1e9 + 7;
const long long INF = 1e18;
*/

/* Boost!
#include <boost/algorithm/string/classification.hpp> // is_any_of
#include <boost/algorithm/string/split.hpp>
using boost::algorithm::split; // split(result, s, boost::is_any_of(","));
#include <boost/algorithm/string/join.hpp>
using boost::algorithm::join; // string s = join(arr, "");
#include <boost/algorithm/string/replace.hpp>
using boost::algorithm::replace_all; // replace_all(s, "AtCoder", "A");
#include <boost/range/algorithm.hpp> // boost::sort(arr)
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;
*/

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

/* fast cin and precise cout
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  getline(cin, s);
  cout << fixed << setprecision(15);
*/

/* sum function
int sum(vector<int> &arr) {
  int res = accumulate(arr.begin(), arr.end(), 0);
  return res;
}
*/

int main() {
  int a, b;
  cin >> a >> b;
  cout << (a - 1) + (b >= a) << endl;
}


Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] a = new int[N];

        Map<Integer, Integer> count = new HashMap<>();

        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
            if (!count.containsKey(a[i])) count.put(a[i], 0);
            count.put(a[i], count.get(a[i]) + 1);
        }

        int numValues = count.keySet().size();

        if (numValues == 1) {
            System.out.println(count.containsKey(0) ? "Yes" : "No");
            return;
        }

        if (numValues == 2 && N % 3 == 0 && count.containsKey(0)) {
            String sol = "Yes";
            for (int x : count.keySet()) {
                if (x == 0 && count.get(x) != N / 3) sol = "No";
                if (x != 0 && count.get(x) != 2 * (N / 3)) sol = "No";
            }
            System.out.println(sol);
            return;
        }

        if (numValues == 3 && N % 3 == 0) {
            String sol = "Yes";
            int xor = 0;
            for (int x : count.keySet()) xor ^= x;
            if (xor != 0) sol = "No";
            for (int c : count.values()) {
                if (c != N / 3) sol = "No";
            }
            System.out.println(sol);
            return;
        }

        System.out.println("No");
    }
}


Measured memory_bytes: 61020
N,M = map(int,input().split())
L =[]
R =[]

for i in range(M):
    l,r = map(int,input().split())
    L.append(l-1)
    R.append(r)

x = min(R) - max(L)
if x>=0:
    print(x)
else:
    print(0)


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

const int INF = 1e9+7;

vector<int> g[1005];
int dp[1005], x[1005];

void dfs(int v, int p = -1) {
    vector<int> cur(x[v] + 1, INF);
    cur[0] = 0;
    for (int u : g[v]) {
      if (u == p) continue;
      dfs(u,v);
      vector<int> prev = move(cur);
      cur.assign(x[v]+1, INF);
      rep(w, prev.size()) {
        if (prev[w] < INF) {
          if (w + x[u] <= x[v]) chmin(cur[w + x[u]], prev[w] + dp[u]);
          if (w + dp[u] <= x[v]) chmin(cur[w + dp[u]], prev[w] + x[u]);
        }
      }
    }
    dp[v] = *min_element(cur.begin(), cur.end());
}

int main() {
  int n;
  cin >> n;
  rep(i,n-1) {
    int p;
    cin >> p;
    --p;
    g[p].push_back(i+1);
  }
  rep(i,n) cin >> x[i];

  dfs(0);
  bool res = dp[0] < INF;
  if (dp[0] < INF) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;
  return 0;
}

Measured memory_bytes: 8776
#include <iostream>

using namespace std;

int main() {
	string s;
	cin >> s;
	int r = 0, p = 0;
	int sc = 0;
	for (int i = 0; i < s.size(); i++) {
		if (r == p) {
			r++;
			if (s[i] == 'p') sc--;
		} else {
			p++;
			if (s[i] == 'g') sc++;
		}
	}
	cout << sc << endl;
}

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

using namespace std;

typedef long long int ll;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"

const ll L = 1e5+5;

vector <ll> a(L);

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    string S;
    cin >> S;

    for(ll i=0; i<(ll)S.size(); i++)
    {
        a[i] = S[i] - 48;
    }

    ll ans = 0;
    for(ll i=1; i<(ll)S.size(); i++)
    {
        if(a[i]==a[i-1])
        {
            ans++;
            a[i]^=1;
        }
    }

    cout << ans << endl;

    return 0;
}

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

l = [0] * n

for i in range(k):
    d = int(input())
    a = map(int,input().split())
    for j in a:
        l[j-1] += 1
ans = 0
for i in l:
    if i == 0:
        ans +=1
print(ans)


Measured memory_bytes: 9180
// #include <bits/stdc++.h>
#include <iostream>
#include <vector>

#define rep(i, s, n) for (int i = s; i < (int)(n); i++)
using namespace std;
// using ll = long long int;

void inv(vector<int>& v) {
    int length = v.size();
    for (int i = 0; i < length; i++) {
        cin >> v[i];
    }
}
void inv(vector<int>& v, int length) {
    for (int i = 0; i < length; i++) {
        cin >> v[i];
    }
}

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

    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (i % 2 != 1) continue;

        int cnt = 0;
        for (int j = 1; j <= i; j++) {
            if (i % j == 0) cnt++;
        }
        if (cnt == 8) ans++;
    }

    cout << ans << endl;

    return 0;
}


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

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

#define ll          long long
#define pb          push_back
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define rs(v,n)     v.resize(n)
#define hell        1000000007
#define peak        9123372036854775807
#define pii         acos(-1)
#define clr(a,x)    memset(a,x,sizeof(a))
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template<class x,class y> x sum(x a,y b){return a+b;}
template<class x,class y> x mul(x a,y b){return a*b;}
template<class x,class y> x sub(x a,y b){return a-b;}
template<class x,class y> x divi(x a,y b){return a/b;}

template<class x,class y>
istream &operator>>(istream &in,pair<x,y> &p) 
{ 
    in>>p.F>>p.S;
    return in;
}
template<class x>
istream &operator>>(istream &in,vector<x> &v) 
{
    for(auto& i:v)
        in>>i;
    return in;
}
template<class x,class y>
ostream &operator<<(ostream &out,pair<x,y> &p) 
{ 
    out<<"("<<p.F<<","<<p.S<<") ";
    return out; 
}
template<class x>
ostream &operator<<(ostream &out,vector<x> &v) 
{ 
    out<<v.size()<<endl;
    for(auto i:v)
        out<<i<<" ";
    out<<endl;
    return out; 
}
#define N  1000005

int main()
{
    ios;
    ll tt=1;
    // cin>>tt;
    while(tt--)
    {
    	ll i,j,k,l,m,n;
    	cin>>n;
    	vi a(n);
    	cin>>a;
    	map<ll,ll> ma1,ma2;
    	for(i=0;i<n;i++)
    	{
    		ma1[-a[i]+(i+1)]++;
    		ma2[a[i]+i+1]++;
    	}
    	ll ans=0;
    	for(auto i:ma1)
    	{
    		ans+=i.S*ma2[i.F];
    	}
    	cout<<ans;
    }
    return 0;
}

Measured memory_bytes: 39104
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>; // グラフ型
typedef long long ll;
#define _GLIBCXX_DEBUG



int main() {
  int X, N, ans, buf, buf1;
  cin >> X >> N;
  vector<int> p(N);
  vector<int> q;
  
  if(N==0){
    cout << X << endl;
    return 0;
  }


  if(N==100){
    if (X <=50){
      cout << 0 << endl;
      return 0;
    }else {
      cout << 101 << endl;
      return 0;
    }
  }


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

  sort(p.begin(), p.end());

  int tmp=0;
  for (int i=0; i<=101; i++){
    if(i == p[tmp]) tmp++;
    //else if (i == X) continue;
    else{
      q.push_back(i);
    }
  }

  sort(q.begin(), q.end());

  buf = 200;
  /*
  for (ll i=0; i<q.size(); i++){
    cout << q[i] << endl;
  }
  */

  ans = 0;
  for (int i=0; i<q.size(); i++){
    buf1 = abs(q[i] - X);
    if( buf > buf1){
      buf = buf1;
      ans = i;
    }else{
      break;
    }
  }
  cout << q[ans] << endl;
  
  return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
//const int MOD=998244353;
const int INF=1e9;
const long long LINF=1e18;
#define int long long
//template
template <typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}
//main
signed main(){
  int N;cin>>N;
  std::vector<int> v(N),w(40,1);
  for(int i=0;i<N;i++)cin>>v[i];
  int now=0;
  for(int i=0;i<N;i++)now^=v[i];
  set<int> s;
  for(int i=1;i<40;i++)w[i]=w[i-1]*2;
  for(int i=0;i<N;i++)
    for(int j=0;j<37;j++)
      if((((v[i]&(w[j+1]-1))|w[j])==w[j])&&(((v[i]&(w[j+1]-1))&w[j])==w[j]))s.insert(w[j]);
  //cout<<((v[0]&(w[1]-1))|w[0])<<endl;
  //cout<<v[0]<<" "<<(w[1]-1)<<" "<<(v[0]&(w[1]-1))<<endl;
  //for(int p:s)cout<<p<<" ";cout<<endl;
  int ans=0;
  for(int i=35;i>=0;i--){
    if((now&w[i])==0)continue;
    if(s.count(w[i])==0)fin(-1);
    ans++;
    now^=w[i+1]-1;
    //cout<<i<<" "<<now<<endl;
  }
  fin(ans);
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
//  vector<int> s(M);
//  vector<int> c(M);

  int s, c;
  bool flag = true;
  vector<int> set(N, -1);
  for(int i = 0; i < M; i++){
    cin >> s >> c;
    if(set[s-1] == -1 || set[s-1] == c){
      set[s-1] = c;
    }else{
      cout << -1 <<endl;
      return 0;
    }
  }

  if(N!=1 && set[0] == 0){
    cout << -1 << endl;
    return 0;
  }

  for(int i = 0; i < N; i++){
    if(i == 0 &&  N != 1){
      if(set[i] == -1) set[i] = 1;
    }else{
      if(set[i] == -1) set[i] = 0;
    }
    cout << set[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
mt19937 rnd;
#define F first
#define S second
#define pb push_back
#define pii pair<int,int>

const int mod = 1e9 + 7;
const int maxn = 1005;
int dp[maxn][maxn];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);  cout.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif // LOCAL

    int h,w;
    cin >> h >> w;
    char a[h+1][w+1];
    for (int i=1; i<=h; i++) {
        for (int j=1; j<=w; j++) {
            cin >> a[i][j];
        }
    }
    dp[1][1] = 1;
    for (int i=2; i<=h; i++) {
        if (a[i][1] == '#') {
            dp[i][1] = 0;
        }
        else {
            dp[i][1] = dp[i-1][1];
        }
    }
    for (int i=2; i<=w; i++) {
        if (a[1][i] == '#') {
            dp[1][i] = 0;
        }
        else {
            dp[1][i] = dp[1][i-1];
        }
    }
    for (int i=2; i<=h; i++) {
        for (int j=2; j<=w; j++) {
            if (a[i][j]=='#') {
                dp[i][j] = 0;
            }
            else {
                dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % mod;
            }
        }
    }
    cout << dp[h][w];

#ifdef LOCAL
    cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif // LOCAL
}


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  LL H, W;
  cin >> H >> W;
  LL ans = 1e18;
  if(H>=3) mini(ans, (H%3==0?0ll:W));
  if(W>=3) mini(ans, (W%3==0?0ll:H));

  for(LL x=1;x<W;++x){
	LL s1 = x*H, s2 = (W-x) * (H/2), s3 = (W-x) * ((H+1)/2);
	mini(ans, max({s1,s2,s3}) - min({s1,s2,s3}));
  }
  for(LL y=1;y<H;++y){
	LL s1 = W*y, s2 = (W/2) * (H-y), s3 = ((W+1)/2) * (H-y);
	mini(ans, max({s1,s2,s3}) - min({s1,s2,s3}));
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef  long long  ll;
typedef vector<ll> vll;
#define rall(s) s.rbegin(),s.rend()
typedef map<ll,ll> mll;
#define fr(n,x) for(ll n=0;n<x;n++)
#define pb push_back
#define EL cout<<'\n'
#define all(s) s.begin(),s.end()

void solve(){
    ios_base::sync_with_stdio(0); cin.tie(0);
	ll x,y,r,p,sc,n,k,res=0;
	string s,re;
	cin>>x>>y>>r>>sc>>p>>s;
	for(n=0;n<y;n++){
        if(s[n]=='r')re+='p';
        else if(s[n]=='p')re+='s';
        else re+='r';
	}
	for(n=y;n<x;n++){
        if(s[n]=='r')re+='p';
        else if(s[n]=='p')re+='s';
        else re+='r';
        if(re[n-y]==re[n]){
            re[n]='0';
        }
	}
	fr(n,re.size()){
        if(re[n]=='r')res+=r;
        else if(re[n]=='p')res+=p;
        else if(re[n]=='s') res+=sc;
        else res+=0;
    }
    cout<<res;
}

int main(){
    ll T=1;
    //cin>>T;
    while(T--)solve();
}


Measured memory_bytes: 640
import sys
## io
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))
## dp
INIT_VAL = 0
DP2 = lambda d1, d2: [[INIT_VAL]*d2 for _ in range(d1)]
DP3 = lambda d1, d2, d3: [[[INIT_VAL]*d3 for _ in range(d2)] for _ in range(d1)]
## math
DIVC = lambda x, y: -(-x//y)
DIVF = lambda x, y: x//y
from collections import Counter

def main():
    n = II()
    aa = MII()
    aa = [a-(i+1) for i, a in enumerate(aa)]
    aa.sort()
    m = aa[(n//2)]
    res = sum([abs(a-m) for a in aa])
    print(res)

if __name__ == '__main__':
    main()


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

#define V vector
typedef long long ll;
typedef unsigned long long ull;

typedef V<int> vi;
typedef V<ll> vll;
typedef V<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define f(i,a) for(int i = 0 ; i < a ; i++)
#define fll(i,a) for(ll i = 0 ; i < a ;i++)
#define forab(i,a,b) for(int i = a ; i < b ; i++)
#define prec(x) cout<<fixed<<setprecision(x)
#define ff first
#define ss second

#define pb push_back
#define mp make_pair
#define numberofdigits(x) floor(log10(x)) + 1

ll M = 1e7 + 7;

ll binpow(ll a, long long b) {
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = (res * a);
		a = (a * a);
		b >>= 1;
	}
	return res;
}



int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);


	int n;
	cin >> n;

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

	ll mx = a[0] ;
	ll ans = 0;

	for (int i = 1 ; i < n ; i++)
	{
		if (a[i] < mx)
			ans += mx - (ll)a[i];

		mx = max(mx , (ll)a[i]);
	}

	cout << ans << "\n";

	return 0;
}





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

struct edge{int to;};
typedef pair<int,int> P;
vector<int> connection[100100];
bool used[100100];

int n;
int start;
int now = 0;
vector<edge> g[100100];
int inf = 2000000007;

void dfs(int c){
  used[c] = true;
  connection[start].push_back(c);
  for(int i = 0;i < g[c].size();i++){
    edge e = g[c].at(i);
    if(used[e.to] != true){
      dfs(e.to);
    }
  }
  return;
}

int main(){
  int m;
  cin >> n >> m;
  vector<int> p(n+1),x(m),y(m);
  for(int i = 1;i <= n;i++){
    cin >> p.at(i);
  }
  for(int i = 0;i < m;i++){
    cin >> x.at(i) >> y.at(i);
  }
  
  for(int i = 0;i < m;i++){
    edge e,f;
    e.to = y.at(i);
    f.to = x.at(i);
    g[x.at(i)].push_back(e);
    g[y.at(i)].push_back(f);
  }
  for(int i = 1;i <= n;i++){
    used[i] = false;
  }
  for(int i = 1;i <= n;i++){
    start = i;
    if(used[start] != true){
      dfs(start);
    }
  }
  int result = 0;
  for(int i = 1;i <= n;i++){
    if(connection[i].size() > 0){
      sort(connection[i].begin(),connection[i].end());
      for(int j = 0;j < connection[i].size();j++){
        /*int left = -1,right = connection[i].size();
        while(right - left > 1){
          int mid = (right - left) / 2;
          //cout << connection[i].size() << ' ' << connection[i].at(mid) << ' ' << p.at(connection[i].at(j)) << endl;
          if(connection[i].at(mid) >= p.at(connection[i].at(j))){
            right = mid;
          }
          else{
            left = mid;
          }
        }
        cout << right << endl;
        if(connection[i].at(right) == p.at(connection[i].at(j))){
          result++;
        }*/
        auto it = std::lower_bound(connection[i].begin(),connection[i].end(),p.at(connection[i].at(j)));
        if(*it == p.at(connection[i].at(j))){
          result++;
        }
      }
    }
  }
  cout << result << endl;
}

Measured memory_bytes: 12028
package main
import (
  "fmt"
)

func main() {
  var b string

  fmt.Scan(&b)

  if b == "A" {
    fmt.Println("T")
  } else if b == "T" {
    fmt.Println("A")
  } else if b == "C" {
    fmt.Println("G")
  } else {
    fmt.Println("C")
  }

}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define _size(X) (int)((X).size())
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 20;
int N;
int H[MAX_N];

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

  cin >> N;
  rep(i, N) cin >> H[i];

  int ans = 1;
  int max = H[0];
  for (int i = 1; i < N; ++i) {
      if (max <= H[i]) {
          ++ans;
          max = H[i];
      }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 888
N = int(raw_input())
S = list(raw_input())

ans = N
min_ans = N
for i in range(N):
    if i == 0:
        ans = S[1:].count('E')
        min_ans = ans
    else:
        if S[i-1] == 'W':
            ans += 1
        if S[i] == 'E':
            ans -= 1
        min_ans = min(min_ans, ans)

print(min_ans)

Measured memory_bytes: 17112
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
int n;
long long a, b, l;
int main(){
    scanf("%d", &n);
    while(n--){
        scanf("%lld%lld", &a, &b);
        if(a>b)std::swap(a, b);
        if(a==b)printf("%d\n", a*2-2);
        else if(a+1==b)printf("%d\n",a*2-2);
        else{
            l=floor(sqrt(a*b));
            while(l*l<a*b)l++;
            l--;
            if(l*(l+1)>=a*b)printf("%d\n", l*2-2);
            else printf("%d\n", l*2-1);
        }
    }
    return 0;
}

Measured memory_bytes: 128