akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define f first
#define int long long
#define INTMAX 1e15+5
#define mp make_pair
#define N 1000005
#define pb push_back
#define pencho ios_base::sync_with_stdio(false);cin.tie(NULL);
#define s second
/*STL:
       (1) PRIORITY_QUEUE pq:
       -> priority_queue < int > pq; // max_heap
       -> priority_queue < int , vector < int > , greater < int > > pq; // min_heap
       -> pq.top()   --> returns the maximum or minimum element
       -> pq.push()  --> push element into the queue
       -> pq.pop()   --> remove top most element
       -> pq.empty() --> checks whether queue is empty or not

       (2) set / multiset  ss;
       --> ss.insert(key); (insertion)
       --> ss.erase(ss.find(key)) .. (deletion)
       --> ss.find(key) != ss.end() ..existence check
       --> ss.lower_bound(x) -> smallest value which is greater than or equals to x
       --> ss.upper_bound(x) --> first value strictly greater than x
       --> multiset< data_type , greater<data_type> > ms; // for max ordering

       (3) common functions
       lower_bound(v.begin(),v.end(),x) - v.begin() --> smallest value greater than or equals to x
       upper_bound(v.begin(), v.end(),x)- v.begin() --> smallest value greater than x
       memset(dp , val , sizeof(dp)) -> sets the value of array dp to val

       (4)    Comparator for set
                     struct comp {
                            bool operator()(pair<int, int>a, pair<int, int>b) {
                     };
};
*/
int mod = 1000000007;
int bp(int x, int y) {int ans = 1; x %= mod; while (y) {if (y & 1) ans = ans * x % mod; x = x * x % mod; y >>= 1;} return ans;}
int mod_inverse(int x) {return bp(x, mod - 2); }
int gcd (int a, int b) { while (b) {a %= b; swap(a, b);} return a;}
int max(int a, int b) {     if (a < b)    swap(a, b);   return a;}
int min(int a, int b) { if (a > b) swap(a, b); return a;}
int countSetBits(int n) {int count = 0; while (n) {count += n & 1; n >>= 1;} return count;}



void solve() {
       int n;  cin >> n;
       int h[n], dp[n];
       for (int i = 0; i < n; i++)  cin >> h[i], dp[i] = INTMAX;
       dp[0] = 0;
       for (int i = 0; i < n - 1; i++) {
              dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
              if (i + 2 < n)dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
       }
       cout << dp[n - 1] << endl;
}




signed main()
{
#ifndef ONLINE_JUDGE
       freopen("input.txt", "r", stdin);
       freopen("o.txt", "w", stdout);
#endif

       solve();
}

Measured memory_bytes: 5100
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		System.out.println(b - a == c - b ? "YES" : "NO");
	}
}


Measured memory_bytes: 23124
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
    unsigned A, B, C, K;

    cin >> A >> B >> C >> K;

    unsigned* major = &A;

    if(B > *major) major = &B;
    if(C > *major) major = &C;

    for(int i = 0; i < K; i++)
    {
        *major *= 2;
    }

    cout << A + B + C << endl;
    return 0;
}


Measured memory_bytes: 256
def p(n):
    return (2**(n+1) - 1)

def h(n):
    return (2**(n+2) - 3)

def lune(n,x):
    if n == 0 and x > 0:
        return 1
    for i in range(1,n+1):
        if x > h(n-i) + i:
            return (p(n-i) + 1 + lune(n-i, x - (h(n-i) + i) - 1))
    if x > n:
        return 1
    else:
        return 0

def main():
    n,x = map(int, input().split())
    if x >= (h(n) + 1) // 2:
        print(p(n) - lune(n, h(n) - x))
    else:
        print(lune(n,x))

if __name__ == "__main__":
    main()

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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<int>> vvint;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<int, vector<int>, greater<int>> spqint; //小さい順に取り出し
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;     //小さい順に取り出し
typedef priority_queue<int, vector<int>, less<int>> bpqint;    //大きい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;        //大きい順に取り出し

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define PF push_front
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)

int INF = 1e9;
int NIL = -1;
ll MOD = 1000000007;
ll LINF = 1e18;
double EPS = 1e-9;
double PI = M_PI;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}
//-----------------------------------------

//-----------------------------------------
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::chrono::system_clock::time_point start,end;
    start = std::chrono::system_clock::now();

    int n ;
    cin >> n ;
    vll a(n) ;
    vll b(n) ;
    vll c(n) ;
    ll tk ;
    ll ao ;
    tk = ao = 0 ;
    vector<tuple<ll,ll,ll>> vec(n) ;
    REP(i,n){
        cin >> a[i] >> b[i] ;
        c[i] = a[i] + b[i] ;
        vec[i] = MT(c[i], a[i], b[i]) ;
    }
    sort(ALL(vec)) ;
    reverse(ALL(vec)) ;
    REP(i,n){
        if(i%2==0){
            tk += get<1>(vec[i]) ;
        }
        else{
            ao += get<2>(vec[i]) ;
        }
    }
    cout << tk -ao <<endl;





    end = std::chrono::system_clock::now();
    auto elapsed = std::chrono::duration_cast< std::chrono::milliseconds >(end - start).count();
    //std::cout << elapsed <<"ms"<< std::endl;

    

    return 0;
}



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

int main()
{
  int h, n;
  cin >> h >> n;
  
  vector<int> a(n);
  for (int i = 0; i < n; i ++)
    cin >> a.at(i);
  
  sort(a.begin(), a.end(), greater<int>());
  
  for (int i = 0; i < n; i ++)
  {
    h -= a.at(i);
    if (h <= 0)
    {
      cout << "Yes" << endl;
      return 0;
    }
  }
  
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 640
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
#define out(args...){vector<string> a_r_g_s=s_p_l_i_t(#args, ','); e_r_r(a_r_g_s.begin(), args); }
vector<string> s_p_l_i_t(const string &s, char c){vector<string> v;int d=0,f=0;string t;for(char c:s){if(!d&&c==',')v.pb(t),t="";else t+=c;if(c=='\"'||c=='\'')f^=1;if(!f&&c=='(')++d;if(!f&&c==')')--d;}v.pb(t);return move(v);}
void e_r_r(vector<string>::iterator it) {}
template<typename T, typename... Args> void e_r_r(vector<string>::iterator it, T a, Args... args){ if(*it==" 1"||*it=="1") cerr<<endl; else cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; e_r_r(++it, args...);}
template<typename T>vector<T> table(int n, T v){ return vector<T>(n, v);}
template <class... Args> auto table(int n, Args... args){auto val = table(args...); return vector<decltype(val)>(n, move(val));}
const ll MOD=1e9+7;

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
	string s;
	cin>>s;
	s+="aaaaaaaaa";
	cout<<(s.substr(0,4)=="YAKI"?"Yes":"No")<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main()
{
  int s;
  cin >> s;
  
  int ss[4];
  int i;
  for(i=0; i<4; i++){
    ss[i] =  s % 10;
    s /= 10;
  }

  bool flag = true;
  int tmp = ss[0];
  
  for(i=1; i<4; i++){
    if(ss[i] == tmp){
      flag = false;
      break;
    }
    tmp = ss[i];
  }

  if(flag == true)
    cout << "Good";
  else
    cout << "Bad";
  cout << endl;
  
  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

n = int(input())

connect_list = [ [] for i in range(n) ]
distance_list = [ -1 for i in range(n) ]
color_list = [ "Gray" for i in range(n) ]
distance_list[0] = 0

for i in range(n-1):
	u, v, w = [ int(v) for v in input().split() ]
	w %= 2
	connect_list[u-1].append((v-1,w))
	connect_list[v-1].append((u-1,w))
	

search_list = [0]


while search_list != []:
	s = search_list[0]
	for i in connect_list[s]:
		if distance_list[i[0]] == -1:
			distance_list[i[0]] = (distance_list[s] + i[1]) % 2
			search_list.append(i[0])
	del search_list[0]

for i in distance_list:
	print(i)

Measured memory_bytes: 67760
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    int c[10][5];
    int a[3];
    int b[3];
    bool flag=false;
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin>>c[i][j];
        }
    }
    for(int i=0;i<=100;i++){
        for(int j=0;j<=100;j++){
            for(int k=0;k<=100;k++){
                a[0]=i;
                b[0]=c[0][0]-a[0];
                a[1]=j;
                b[1]=c[1][1]-a[1];
                a[2]=k;
                b[2]=c[2][2]-a[2];
                if(a[0]+b[1]==c[0][1] && a[0]+b[2]==c[0][2] && a[1]+b[0]==c[1][0] && a[1]+b[2]==c[1][2] && a[2]+b[0]==c[2][0] && 
                a[2]+b[1]==c[2][1]){
                    flag=true;
                }
            }
        }
    }
    if(flag)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include<set> 
#include<math.h>
#define pai arccos(-1);
#define keta(n) cout << fixed << setprecision((n));
#define ll long long;

int main(){
  int n,l;
  cin>>n>>l;
  vector<string> s(n);
  rep(i,n)cin>>s[i];
  sort(s.begin(),s.end());
  rep(i,n){
    cout<<s[i];
  }
  
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define x first
#define y second
#define ndl '\n'
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define up_b upper_bound
#define low_b lower_bound
#define sz(x) (int)x.size()
#define bit __builtin_popcount
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;
using namespace __gnu_pbds;

template<typename T> using indexed_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<int, ull> piu;
typedef vector<vector<int>> matrix;

const ll INF = 1e18 + 123;
const ld EPS = 1e-9;
const int inf = 1e9 + 123;
const int MOD = 998244353;
const int N = 5e5 + 13;
const int M = 1e6 + 123;
const double pi = acos(-1.0);
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};

int binpow(int a, int b){
    int res = 1;
    while (b){
        if (b&1){
            res = res * 1ll * a % MOD;
        }
        b >>= 1;
        a = 1ll * a * a % MOD;
    }
    return res;
}

int cnt[N];

int main(){
    #ifdef KAZAKH
        freopen("input.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, d;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i++){
        cin >> d;
        if (!d){
            if (i != 1) ans = 0;
            else ans = 1;
        }
        cnt[d]++;
    }
    for (int i = 1; i <= n; i++){
        //cout << binpow(cnt[i-1], cnt[i]) << " ";
        ans = 1ll * ans * binpow(cnt[i-1], cnt[i]) % MOD;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<iomanip>
#include<cstdio>

#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>

#include<algorithm>
#include<cmath>

using namespace std;
typedef long long ll;
template <class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template <class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
const int INF = 1e9;

int N,K;


int main() {
    cin >> N >> K;
    double res = 0;
    for (int i = 1; i <= N; i++) {
        int count = 0;
        int j = i;
        while (j < K) {
            j *= 2;
            count++;
        }
        res += 1.0 / (1 << count);
    }
    printf("%.12lf\n",res / N);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
long long int arr[500005];
long long int size1[500005];
long long int m = 1000000007;
bool vis[200005] = {0};
vector<pair<ll, ll>> vec[300005];
ll count1 = 0;
vector<pair<ll, pair<ll, ll>>> vec1;
ll count2 = 0;
long long int fin(long long int node)
{
    if (node == arr[node])
        return node;
    node = arr[arr[node]];
}

void union1(long long int x, long long int y)

{
    long long int node1 = fin(x);
    long long int node2 = fin(y);

    if (size1[node1] > size1[node2])
    {
        size1[node1] += size1[node2];
        arr[node2] = node1;
    }
    else
    {
        size1[node2] += size1[node1];
        arr[node1] = node2;
    }
}
long long int fastexpo(long long int a, long long int b)
{
    long long int ans = 1;
    while (b)
    {
        if (b & 1)
            ans = (ans * a) % m;
        b = b / 2;
        a = (a * a) % m;
    }
    return ans;
}
void dfs(ll node)
{
    vis[node] = 1;
    //  vec1.push_back({count1, {node1, node}});

    size1[node] = count1;
    count1++;
    for (int i = 0; i < vec[node].size(); i++)
    {

        // arr[vec[node][i]] = count1;
        if (!vis[vec[node][i].first])
        {
            dfs(vec[node][i].first);
            arr[node] += arr[vec[node][i].first];
        }
    }
    count1--;
}
void dijkstra(ll s, vector<pair<ll, ll>> vec2[], ll dis5[])
{
    priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq;
    pq.push(make_pair(0, s));
    dis5[s] = 0;
    while (!pq.empty())
    {
        ll u = pq.top().second;
        //  vis[u] = 1;
        pq.pop();
        for (ll i = 0; i < (ll)vec2[u].size(); i++)
        {

            ll q = vec2[u][i].second;
            ll w = vec2[u][i].first;

            if (dis5[u] + w < dis5[q])
            {
                dis5[q] = dis5[u] + w;
                pq.push(make_pair(dis5[q], q));
            }
        }
    }
}
int main()
{
    ll n, m;
    cin >> n >> m;
    ll a[m];
    ll sum = 0;
    for (int i = 0; i < m; i++)
    {
        cin >> a[i];
        sum += a[i];
    }
    sum = n - sum;
    if (sum >= 0)
        cout << sum;
    else
        cout << -1;

    return 0;
}

Measured memory_bytes: 10736
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <map>
using namespace std;

void solve(void){

//  long long int N,M;
  string S;
  cin >> S;
  
  size_t N=(int)(S.length());
  
  int i=0,j=0;
  
  string str=S;
  reverse(str.begin(), str.end());
  
  if(S!=str){
//    cout << "1" << endl;
  cout << "No" <<endl;
    return;
  }
  for(i=0,j=(N+3)/2;i<(N-1)/2;i++,j++){
 //       cout << "2" << endl;
  if(S[i]!=S[j-1]){
  cout << "No" <<endl;
    return;
  }
    
  }
  
  cout << "Yes" << endl;
  
return;
}

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

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
 
  long	A[200000+1];
  long	N;
  long	i, j;
  long	max=0;
  long  max_i=0;
  
  scanf("%ld", &N);
  for(i=0;i<N;i++){ scanf("%ld", &A[i]); }
  
  for(i=0;i<N;i++){
    if( A[i]>max ){ max = A[i];		max_i = i; }
  }
  
  for(i=0;i<N;i++){
    if( i != max_i ){ printf("%ld\n", A[max_i]); }
    else{
      max = 0;
      for(j=0;j<N;j++){
        if( i==j ){ continue; }
        if( A[j]>max ){ max = A[j]; }
      }
      printf("%ld\n", max);
    }
  }
  return 0;
}

Measured memory_bytes: 3072
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sr = new Scanner(System.in);
    int L = sr.nextInt();
    int R = sr.nextInt();
    int d = sr.nextInt();
    System.out.println(((R-(R%d))/d)-(((L-1)-(L-1)%d)/d));
  
  }

}

Measured memory_bytes: 35668
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "random"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 0.00000001;
const long double PI = 3.1415926535897932384626433;

long long int N, M, K, H, W, L, R;

vector<vector<int>>nx;
vector<int>dp;

int Search(int n) {
	if (dp[n] != INT_MAX) {
		return dp[n];
	}
	bool flag = true;
	int box = INT_MAX;
	for (int i = 0; i < 26; i++) {
		if (nx[n][i] == INT_MAX) {
			flag = false;
			dp[n] = 0;
			return dp[n];
		}
		box = min(box, Search(nx[n][i]));
	}
	if (flag) {
		dp[n] = box+1;
	}
	return dp[n];
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	string s;
	cin >> s;
	s = '0' + s;
	N = s.size();
	nx.resize(N + 1, vector<int>(26, INT_MAX));
	dp.resize(N + 1,INT_MAX);
	for (int i = N - 1; i >= 0; i--) {
		for (int j = 0; j < 26; j++) {
			nx[i][j] = min(nx[i][j], nx[i + 1][j]);
		}
		if (i) {
			nx[i - 1][s[i] - 'a'] = i;
		}
	}
	Search(0);
	string ans;
	queue<int>Q;
	Q.push(0);
	while (!Q.empty()) {
		int cn = Q.front();
		Q.pop();
		for (int i = 0; i < 26; i++) {
			if (nx[cn][i]==INT_MAX) {
				ans += char('a' + i);
				cout << ans << endl;
				return 0;
			}
		}
		int box = dp[nx[cn][0]];
		char add = 'a';
		for (int i = 1; i < 26; i++) {
			if (box > dp[nx[cn][i]]) {
				box = dp[nx[cn][i]];
				add = char('a' + i);
			}
		}
		Q.push(nx[cn][add - 'a']);
		ans += add;
	}
	return 0;
}


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

int main(){
    int A[3][3];
    rep(i, 3)rep(j, 3) cin>>A[i][j];
    int n;
    cin >> n;
    int B;
    int ok[3][3]={0};
    rep(i, n){
        cin >> B;
        rep(j, 3)rep(k, 3){
            if(A[j][k]==B) ok[j][k]=1;
        }
    }

    bool ans=false;
    if(ok[0][0]==1 && ok[0][1]==1 && ok[0][2]) ans=true;
    if(ok[1][0]==1 && ok[1][1]==1 && ok[1][2]) ans=true;
    if(ok[2][0]==1 && ok[2][1]==1 && ok[2][2]) ans=true;
    if(ok[0][0]==1 && ok[1][0]==1 && ok[2][0]) ans=true;
    if(ok[0][1]==1 && ok[1][1]==1 && ok[2][1]) ans=true;
    if(ok[0][2]==1 && ok[1][2]==1 && ok[2][2]) ans=true;
    if(ok[0][0]==1 && ok[1][1]==1 && ok[2][2]) ans=true;
    if(ok[2][0]==1 && ok[1][1]==1 && ok[0][2]) ans=true;

    if(ans) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

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

long long n, k, a[200005], h[200005], len, tot, ju = 1;

long long jump(int n) 
{
    int o = 1;
    for (int i = 1; i <= n; ++i) {
        o = a[o];
    }
    return o;
}

int main() {
    cin>>n>>k;
    for (int i = 1; i <= n; ++i) 
	{
        cin>>a[i];
    }
    if (k <= n) {
        cout<<jump(k)<<endl;
        return 0;
    }
    for (int i=1;i<=k;++i) 
	{
        if (h[ju]!=0) {
            len=i-h[ju];
            tot=jump(h[ju]-1+(k-h[ju]+1)%len);
            break;
        }
        h[ju]=i;
        ju=a[ju];
    }
    cout<<tot;
    return 0;
}

Measured memory_bytes: 6700
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>
#include <ciso646>
#include <cassert>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;

inline bool check(ll x, ll y, ll xMax, ll yMax) { return x >= 0 && y >= 0 && xMax > x && yMax > y; }
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string tostring(T x) { ostringstream sout; sout << x; return sout.str(); }
template<class T> inline T sqr(T x) { return x*x; }
template<class T> inline T mypow(T x, ll n) { T res = 1; while (n > 0) { if (n & 1)res = res * x;	x = x * x;	n >>= 1; }return res; }
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

#define For(i,a,b)	for(ll (i) = (a);i < (b);(i)++)
#define rep(i,n)	For(i,0,n)
#define rFor(i,a,b)	for(ll (i) = (a-1);i >= (b);(i)--)
#define rrep(i,n)	rFor(i,n,0)
#define each(i,n)	for(auto &i : n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define sz(a)		(sizeof(a))
#define tostr(a)	tostring(a)
#define dump(val) 	cerr << #val " = " << val << endl;
#define Fill(a,v)	fill((int*)a,(int*)(a+(sz(a)/sz(*(a)))),v)

const ll dx[8] = { 1, 0, -1, 0, 1, 1, -1, -1 }, dy[8] = { 0, -1, 0, 1, -1, 1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = 1e17 + 9;

#define int ll
#define double ld

int dp[51][2501][51];

signed main() {
	
	int n, a;
	cin >> n >> a;
	vector<int> x(n);
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}	
	dp[0][0][0] = 1;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= 2500 - x[i]; j++) {
			for (int k = 0; k <= n; k++) {
				dp[i + 1][j + x[i]][k + 1] += dp[i][j][k];
				dp[i + 1][j][k] += dp[i][j][k];
			}
		}
	}

	int ans = 0;
	for (int j = 0; j <= 2500; j++) {
		for (int k = 1; k <= n; k++) {
			if (j % k == 0 && j / k == a) {
				ans += dp[n][j][k];
			}
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 50048
#include <bits/stdc++.h>
#include <unistd.h>
#define inf 1000000007LL
#define INF 1000000000000000007LL
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define st first
#define nd second
#define ll long long
#define ld long double
#define pii pair<int,int>
#define vi vector<int>
#define vll vector<long long>
#define vpii vector< pair<int,int> >
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define LOG(x) (63-__builtin_clzll(x))
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i, n) for(int i=1; i<=(n); ++i)
#define endr cerr<<'\n'
#define endl '\n'
#ifdef DEBUG
#define pv(...) cerr<<'\n',dbg(#__VA_ARGS__, __VA_ARGS__)
#define ps(x) {cerr<<'\n'<<#x<<":\n:";for(auto _q:(x)){cerr<<_q<<" ";}cerr<<'\n';}
#define pa(x, xs) {cerr<<'\n'<<#x<<":\n:";for(int _q=0; _q<=(xs); ++_q){cerr<<x[_q]<<" ";}cerr<<'\n';}
#define pal(x, xs) {cerr<<'\n'<<#x<<":\n";for(int _q=0; _q<=(xs); ++_q){cerr<<_q<<": "<<setw(_q? 3-(int32_t)log10(_q):3)<<x[_q]<<'\n';}cerr<<'\n';}
#define ppii(x, xs) {cerr<<'\n'<<#x<<":\n";for(int _q=0; _q<=(xs); ++_q){cerr<<_q<<": "<<setw(_q? 6-(int32_t)log10(_q):6)<<x[_q].first<<" "<<setw(5)<<x[_q].second<<'\n';}cerr<<'\n';}
#define pm(x, xn, xm) {cerr<<'\n'<<#x<<":\n";for(int _qa=0; _qa<=(xn); ++_qa){for(int _qb=0; _qb<=(xm); ++_qb){cerr<<setw(6)<<x[_qa][_qb]<<" ";}cerr<<'\n';}cerr<<'\n';}
#else
#define cerr if(0)cout
#define pv(...) if(0)endr
#define ps(x) if(0)endr
#define pa(x, xs) if(0)endr
#define pal(x, xs) if(0)endr
#define ppii(x, xs) if(0)endr
#define pm(x, xn, xm) if(0)endr
#endif
using namespace std;
template<class T> void dbg(const char* xn, T x){cerr<<xn<<": "<<x<<"\n";} template<class T, class... TA> void dbg(const char* xn, T x, TA... t){while(*xn!=',')cerr<<*xn++;cerr<<": "<<x<<",";dbg(xn+1, t...);}
template<class T> inline bool upd_max(T &x, T y){return y>x?x=y,true:false;} template<class T> inline bool upd_min(T &x, T y){return y<x?x=y,true:false;}
const int N = 1000007;
#define int long long

int n, m, A[N], mn = INF, comps = 0, rst = 0, small = 0;
vi G[N];
bitset<N> vis;
multiset<int> S;


void DFS(int v)
{
  vis[v] = 1;
  upd_min(mn, A[v]);
  S.insert(A[v]);

  for (auto u : G[v])
  {
    if (vis[u]) continue;
    DFS(u);
  }
}

void solve()
{
  cin>>n>>m;
  rep(i, n) cin>>A[i];
  rep1(i, m)
  {
    int a, b; cin>>a>>b;
    G[a].pb(b);
    G[b].pb(a);
  }

  for (int i=0; i<n; ++i)
  {
    if (vis[i]) continue;

    mn = INF;
    DFS(i);
    ++comps;

    S.erase(S.find(mn));
    rst += mn;
  }

  if (comps == 1) cout<<0, exit(0);

  if (sz(S) < comps-2) cout<<"Impossible", exit(0);
  for (int i=1; i<=comps-2; ++i)
  {
    rst += *S.begin();
    S.erase(S.begin());
  }

  cout<<rst;
}

int32_t main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
cout<<fixed<<setprecision(10);

  solve();

return 0;
}


Measured memory_bytes: 33024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64,i64> P;
#define rep(i,s,e) for(int i = (s);i <= (e);i++)

int x;

int main()
{
    cin>>x;
    if(x < 1200)
    {
        cout << "ABC";
    }
    else
    {
        cout << "ARC";
    }
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<ll>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

//Range Minimum Query
struct segment {
    int n;
    vvi dat;
    // n_は範囲
    segment(int n_) { // nはn_以上の2^?
        n = 1<<(32-__builtin_clz(n_));
        if(n == 2*n_) n >>= 1;
        dat.assign(2*n-1, vi(26));
    }
    inline int chld(int i) {return 2*i+1;}
    inline int chrd(int i) {return 2*i+2;}
    //初期化(初期状態はINT64_MAX)
    inline void init(string& s) {
        int num = s.size();
        rep(i, num) {
            dat[i+n-1][s[i]-'a']++;
        }
        rep(i, n-1) {
            int cl = chld(n-2-i), cr = chrd(n-2-i);
            rep(j, 26) {
                dat[n-2-i][j] = dat[cl][j] + dat[cr][j];
            } 
        }
    }
    // k番目の値をbからaに変更
    void update(int k, char b, char a) {
        k = n-1+k;
        // 登りながら更新
        while(k>0) {
            dat[k][b-'a']--;
            dat[k][a-'a']++;
            k = (k-1)/2;
        }
        dat[0][b-'a']--;
        dat[0][a-'a']++;
    }
    //kは節点の番号, [l, r)に節点が対応
    // (a, b, 0, 0, n)で呼ぶ
    void query_(int a, int b, int k, int l, int r, vi &y) {
        if(a>=r || l>=b) return;
        if(a<=l && r<=b) {
            rep(i, 26) {
                y[i] += dat[k][i];
            }
        }
        else {
            int chl = k*2+1;
            int chr = k*2+2;
            query_(a, b, chl, l, (l+r)/2, y);
            query_(a, b, chr, (l+r)/2, r, y);
        }
    }
};

int main() {
    int n, q;
    string s;
    cin >> n >> s >> q;
    segment seg(s.size());
    seg.init(s);
    /*rep(i, seg.dat.size()) {
        rep(j, 26) {
            cout << seg.dat[i][j] << (j == 25 ? '\n':' ');
        }
    }*/
    while(q--) {
        int x, ii;
        cin >> x >> ii;
        if(x == 1) {
            char c;
            cin >> c;
            seg.update(ii-1, s[ii-1], c);
            s[ii-1] = c;
        } else {
            int r;
            cin >> r;
            vi y(26);
            seg.query_(ii-1, r, 0, 0, seg.n, y);
            int ans = 0;
            rep(i, 26) {
                if(y[i]) ans++;
            }
            cout << ans << '\n';
        }
    }
}

Measured memory_bytes: 254724
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mpair make_pair
#define pm(first, second) pb(mpair(first, second))
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()
#define rall(X) (X).rbegin(), (X).rend()
#define divcel(a, b) (((a) + ((b) - 1)) / (b))

int main(){

	int a;
	cin >> a;
	cout << a + a*a + a*a*a << endl;

	return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

template<class U, class V>
ostream& operator <<(ostream& out, pair<U, V>& p) {
    return out << p.first << " " << p.second;
}

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

const lint MOD = 1000000007;

lint modpow(lint a, lint x)
{
    if (x == 0)
        return 1;

    if (x % 2 == 1)
        return a * modpow(a, x - 1) % MOD;

    lint ret = modpow(a, x / 2);
    return ret * ret % MOD;
};

lint modinv(lint a)
{
    return modpow(a, MOD - 2);
};

VEC(lint) pascalsAss(int N, int K)
{
    // KcK, (K + 1)cK ... NcK
    VEC(lint) ret;
    lint tmp = 1;
    FOR(k, K, N + 1) {
        ret.push_back(tmp);
        // tmp = k choose K
        // (k + 1) choose K = (k + 1) / (k + 1 - K ) * tmp
        tmp = tmp * (k + 1) % MOD;
        tmp = tmp * modinv(k + 1 - K) % MOD;
    }

    return ret;
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N, K;
    cin >> N >> K;
    VEC(lint) A(N);
    READVEC(A);
    sort(ALL(A));

    lint ret = 0;
    VEC(lint) facs = pascalsAss(N, K - 1);
    FOR(i, 0, N) {
        lint fac1 = i >= K - 1 ? facs[i - K + 1] : 0;
        lint fac2 = (N - 1 - i) >= K - 1 ? facs[N - i - K] : 0;
        ret += fac1 * (MOD + A[i] % MOD) % MOD;
        ret += fac2 * (MOD - A[i] % MOD) % MOD;
        ret %= MOD;
    }

    cout << ret << endl;
    return 0;
};

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

int main() {
    string str; cin >> str;
    int q; cin >> q;

    for (int i = 0; i < q; i++) {
        string command; cin >> command;
        int a, b; cin >> a >> b;

        if (command == "print") {
            for (int j = a; j <= b; j++) {
                cout << str[j];
            }
            cout << endl;
        } else if (command == "reverse") {
            while (a < b) {
                char tmp = str[a];
                str[a] = str[b];
                str[b] = tmp;
                a++; b--;
            }
        } else if (command == "replace") {
            string p; cin >> p;
            str.replace(a, b - a + 1, p);
        }
    }

    return 0;
}


Measured memory_bytes: 3208
n = int(input())
v = list(map(int, input().split()))

v = [v[::2], v[1::2]]

from collections import Counter
from operator import itemgetter
from itertools import product
c = list(map(Counter, v))
s = [sorted(d.items(), key=itemgetter(1), reverse=True) for d in c]
s = [(d + [(0, 0)])[:2] for d in s]
keep = 0
for e, o in product(*s):
    if e[0] == o[0]:
        continue
    tmp = e[1] + o[1]
    if tmp > keep:
        keep = tmp
ans = n - keep
print(ans)

Measured memory_bytes: 20888
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define piii pair<int,pii>
#define pll pair<ll,ll>
#define plii pair<ll,pii>
#define vi vector<int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define mx 100001
#define eps 0.00000000001
#define mod 1000000007
#define pi acos(-1)
#define inf 100000000
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    fio;
    ll a,b,n;
    cin>>a>>b>>n;
    ll i = 0;
    if(n<b-1)
        i = n;
    else
        i = b-1;
    ll ans = (a*i)/b  - a*(i/b);
    cout<<ans<<"\n";

    return 0;
}



Measured memory_bytes: 3652
import java.util.Scanner;

class Main {

	public static void main(String args[]){

		Scanner scan = new Scanner(System.in);
		long a, b, x;
		a = scan.nextLong();
		b = scan.nextLong();
		x = scan.nextLong();
		
		long low, high;
		low = (a % x == 0 ? a / x : a / x + 1);
		high = b / x;
		
		System.out.println(high - low + 1 >= 0 ? high - low + 1: 0);
		
	}
}

Measured memory_bytes: 23764
def gengo(y, m):
        if y < 2019:
                return 'Heisei'
        elif y > 2019:
                return 'TBD'
        if m <= 4:
                return 'Heisei'
        return 'TBD'


y, m, _ = [int(v) for v in input().split('/')]
print(gengo(y, m))

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  int h,w,n,sx,sy;
  string s,t;
  cin >> h >> w >> n >> sx >> sy >> s >> t;
  sx--,sy--;
  {
    int x=sx;
    rep(i,n) {
      if(s[i]=='U') x--;
      if(x<0) {
        pr("NO");
        return;
      }
      if(t[i]=='D') x=min(x+1,h-1);
    }
  }
  {
    int x=sx;
    rep(i,n) {
      if(s[i]=='D') x++;
      if(x>=h) {
        pr("NO");
        return;
      }
      if(t[i]=='U') x=max(x-1,0);
    }
  }
  {
    int x=sy;
    rep(i,n) {
      if(s[i]=='L') x--;
      if(x<0) {
        pr("NO");
        return;
      }
      if(t[i]=='R') x=min(x+1,w-1);
    }
  }
  {
    int x=sy;
    rep(i,n) {
      if(s[i]=='R') x++;
      if(x>=w) {
        pr("NO");
        return;
      }
      if(t[i]=='L') x=max(x-1,0);
    }
  }
  pr("YES");
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 920
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {

	int n; cin >> n;

	int cnt = 0;
	for (int i = 0; i < n; i++) {
		int a; cin >> a;
		if (a != (i + 1))cnt++;
	}

	if (cnt == 0 || cnt == 2) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

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

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

const ll MOD = 1000000007;
ll dp[100005][2];

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

  int n = s.size();

  dp[0][0] = 1;

  rep(i,n) {
    if (s[i] == '0') {
      dp[i+1][0] = dp[i][0];
      dp[i+1][1] = 3*dp[i][1]%MOD;
    }
    else {
      dp[i+1][0] = 2*dp[i][0]%MOD;
      dp[i+1][1] = (dp[i][0]+3*dp[i][1])%MOD;
    }
  }
  cout << (dp[n][0] + dp[n][1])%MOD << endl;
  return 0;
}


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

int main(){
  int N,a,b,c;
  scanf("%d",&N);
  a=N/100;
  b=(N-a*100)/10;
  c=N-a*100-b*10;
  if(a==7||b==7||c==7){
    printf("Yes");
  }else{
    printf("No");
  }
}


Measured memory_bytes: 3828
<?php
$n = fgets(STDIN);
$a = explode(' ', fgets(STDIN));
$min = 30;
for ($i = 0; $i < $n; $i++) {
    for ($j = 0; $a[$i] % 2 === 0; $j++) {
        $a[$i] /= 2;
    }
    $min = min($j, $min);
}
echo $min;
?>

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

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	long long N, A, B; cin >> N >> A >> B;
	assert(A != B);
	if (A > B) swap(A,B);
	assert(A < B);
	if (A % 2 == B % 2) {
		cout << (B-A) / 2 << '\n';
	} else {
		cout << min((N-B) + 1 + (N-A), (A-1) + 1 + (B-1)) / 2<< '\n';
	}

	return 0;
}


Measured memory_bytes: 256
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}
void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=readln.splitter;foreach(ref v;t){v=r.front.to!T;r.popFront;}}

void main()
{
  int n; readV(n);
  int k; readV(k);
  int[] x; readA(n, x);

  auto r = 0;
  foreach (xi; x) r += min(xi, k-xi);
  writeln(r*2);
}


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

int main(void){
	int i,j,sign=0;
	double s;
	
	int w,h,x,y;
	scanf("%d%d%d%d",&w,&h,&x,&y);
	
	s=(double)w*h/2;
	
	if(2*x==w&&2*y==h){
		sign=1;
	}
	
	printf("%lf %d\n",s,sign);
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define max_v(v) *max_element(all(v));
#define min_v(v) *min_element(all(v));
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl
template <typename T> istream& operator >> (istream& is, vector<T>& vec) {
    for(T& x : vec) is >> x;
    return is;
}
template<typename T> ostream& operator << (ostream& os, vector<T>& vec) {
    for(int i = 0; i < vec.size(); i++) {
        os << vec.at(i) << (i + 1 == vec.size() ? "" : " ");
    }
    return os;
}

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    cin >> A;

    int cnt = 0;
    rep(i, N) {
        int a = A.at(i);
        if((i + 1) % 2 == 1 && a % 2 == 1) cnt++;
    }

    cout << cnt << endl;
}

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

const int MOD=998244353;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int a[100][300000];
int main(){
	int n;ll K;cin>>n>>K;
	rep(i,n){
		scanf("%d",&a[0][i]);a[0][i]--;
	}
	for(int i=1;i<100;i++){
		rep(j,n)a[i][j]=a[i-1][a[i-1][j]];
	}
	int p=0;
	rep(i,62){
		if(K>>i&1){
			p=a[i][p];
		}
	}
	cout<<p+1<<endl;
}

Measured memory_bytes: 82264
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <cstring>
#include <string>
#include <cctype>
#include <cassert>
#include <stack>

using namespace std;

#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,b,e) for(int i = (b); i <= (e); i++)
#define INF (1001001001)
#define EPS (1e-15)

#define pr(x) do{cout << (#x) << " = " << (x) << endl;}while(0)
#define pri(x,i) do{cout << (#x) << "[" << i << "] = " << (x[i]) << endl;}while(0)
#define pra(x,n) rep(__i,n) pri(x,__i);
#define prar(x,b,e) repr(__i,b,e) pri(x,__i);

typedef long long llint;
typedef pair<int, int> pint;
typedef vector<int> vint;

struct V {
	vint e;
	int dim;
	bool alive;
	V():dim(0), alive(true){}
	void add_edge(int ee) {
		e.pb(ee);
		dim++;
	}
};

int in() {
	int a;
	scanf("%d ", &a);
	return a;
}

int main() {
	int N = in();
	vector<V> G(N);
	for (int i = 0; i < N - 1; i++) {
		int a = in() - 1;
		int b = in() - 1;
		G[a].add_edge(b);
		G[b].add_edge(a);
	}
	
	stack<int> leaves;
	for (int i = 0; i < N; i++) if (G[i].dim == 1) leaves.push(i);
	bool firstwins = false;
	while (! leaves.empty()) {
		int l = leaves.top();
		leaves.pop();
		V &v = G[l];
		if (! v.alive) continue;
		if (v.dim <= 0) {
			firstwins = true;
			break;
		}
		int par = -1;
		for (int i = 0; i < v.e.size(); i++) if (G[v.e[i]].alive) {
			par = v.e[i];
			break;
		}
		assert(par >= 0);
		v.alive = false;
		G[par].alive = false;
		for (int i = 0; i < G[par].e.size(); i++) {
			V &w = G[G[par].e[i]];
			if (w.alive) {
				w.dim--;
				if (w.dim <= 0) {
					firstwins = true;
					goto END;
				}
				if (w.dim == 1) {
					leaves.push(G[par].e[i]);
				}
			}
		}
	}END:;
	cout << (firstwins ? "First" : "Second") << endl;
	return 0;
}


Measured memory_bytes: 6784
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}
#define N 100010
int x, y, z, n;
PP A[N], B[N];

ll calc(int m){
	memcpy(B, A, sizeof(A));
	sort(B, B+m, [](const PP &x, const PP &y){return x.snd.fst-x.fst>y.snd.fst-y.fst;});
	sort(B+m, B+n, [](const PP &x, const PP &y){return x.snd.snd-x.fst>y.snd.snd-y.fst;});
	ll res = 0;
	rep(i, n){
		if(i<m) res += i<y?B[i].snd.fst:B[i].fst;
		else res += i-m<z?B[i].snd.snd:B[i].fst;
	}
	return res;
}

int main(){
	cin>>x>>y>>z; n = x+y+z;
	rep(i, n){
		ll a, b, c;
		cin>>a>>b>>c;
		A[i] = PP(a, P(b, c));
	}
	sort(A, A+n, [](const PP &x, const PP &y){return x.snd.fst-x.snd.snd>y.snd.fst-y.snd.snd;});
	/*cerr<<"DEBUG"<<endl;
	rep(i, n){
		cerr<<A[i].fst<<" "<<A[i].snd.fst<<" "<<A[i].snd.snd<<endl;
	}*/
	int lb = y, ub = x+y; //[lb, ub]
	while(ub-lb>10){
		ll lb2 = (lb*2+ub)/3, ub2 = (lb+ub*2+1)/3;
		ll a = calc(lb2), b = calc(ub2);
		if(a>b) ub = ub2;
		else lb = lb2;
	}
	ll res = 0;
	for(int i = lb; i <= ub; i++) res = max(res, calc(i));
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 4992