akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <string>
#include <cmath>
#include <string>
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
#include <iomanip>
#include <tuple>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i, a, n) for (int i=a;i<n;++i)
#define repeq(i, a, n) for(int i=a;i<=n;++i)
#define per(i, a, n) for (int i=n-1; i>=a;--i)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()

// C - Traveling Plan
int N;
vector<int> ans;
int A[101000] = {};
int sum = 0;

int main(){
    cin >> N;
    repeq(i, 1, N){
        cin >> A[i];
        sum += abs(A[i] - A[i-1]);
    }
    sum += abs(A[N]);

    repeq(i, 1, N){
        if(A[i+1] > A[i] && A[i] < A[i-1]){
            int tmp;
            tmp = (abs(A[i] - A[i-1]) < abs(A[i] - A[i+1])) ? 2*abs(A[i-1] - A[i]) : 2*abs(A[i+1] - A[i]);
            ans.push_back(sum - tmp);
        }else if(A[i+1] < A[i] && A[i] > A[i-1]){
            int tmp;
            tmp = (abs(A[i] - A[i-1]) < abs(A[i] - A[i+1])) ? 2*abs(A[i-1] - A[i]) : 2*abs(A[i+1] - A[i]);
            ans.push_back(sum - tmp);
        }else{
            ans.push_back(sum);
        }
    }

    rep(i, 0, N){
        cout << ans[i] << endl;
    }
    return 0;
}




Measured memory_bytes: 2168
#include<stdio.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head, tail, n;

void enqueue(P x){
  Q[tail] = x;
  if(tail + 1 == LEN) tail = 0;
  else tail++;
}

P dequeue(){
  P u;
  u = Q[head];
    if(head + 1 == LEN) head = 0;
    else head++;
  return u;
}


int main(){
  P u;
  int elaps = 0;
  int i, q;
  scanf("%d %d", &n, &q);

  for ( i = 0; i < n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head = 0;
  tail = n;
  while(head != tail){
    if(Q[head].t - q > 0){
      u = dequeue();
      u.t -= q;
      elaps += q;
      enqueue(u);
    }
    else{
      u = dequeue();
      elaps += u.t;
      printf("%s %d\n",u.name,elaps);
    } 
  }
  
  return 0;
}



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


vector<int> adj[100005];
int dp[100005];

int dfs(int node)
{
  int res = 0;
  if(dp[node] != -1)
    return dp[node];

  for(int i=0;i<adj[node].size();i++)
      res = max(res, dfs(adj[node][i]) + 1);

  dp[node] = res;
  return res;
}

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

  memset(dp, -1, sizeof dp);

  int n, m, x, y;
  cin>>n>>m;

  for(int i=0;i<m;i++)
  {
    cin>>x>>y;
    adj[x].push_back(y);
  }

  y = 0;
  for(int i=1;i<=n;i++)
    y = max(y, dfs(i));
  cout<<y<<endl;
  return 0;
}


Measured memory_bytes: 8192
N=int(input())
S=input()
L=[[0 for j in range(10)]for i in range(N+1)]
R=[[0 for j in range(10)]for i in range(N+1)]
for i in range(N):
    for j in range(10):
        L[i+1][j]=L[i][j]
    L[i+1][int(S[i])]=1
for i in range(N-1,-1,-1):
    for j in range(10):
        R[i][j]=R[i+1][j]
    R[i][int(S[i])]=1
ans=[[[0 for k in range(10)]for j in range(10)] for i in range(10)]
num=[0 for k in range(10)]
for t in range(N):
    X=[]
    Y=[]
    k=int(S[t])
    for x in range(10):
        if L[t][x]==1:
            X.append(x)
    for y in range(10):
        if R[t+1][y]==1:
            Y.append(y)
    for i in X:
        for j in Y:
            if ans[i][j][k]==0:
                ans[i][j][k]=1
                num[k]+=1
print(sum(num))

Measured memory_bytes: 60380
//
// Created by 10034 on 2020/7/24.
//

#include <iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    int cnt=0;
    for(int i=1;i<=n;++i){
        int x;
        cin>>x;
        if(i%2&&x%2) cnt++;
    }
    cout<<cnt;
    return 0;
}

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

using namespace std;

int is_square(int n) {
    int s = floor(sqrt(n));
    return (s * s == n);
}

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

  while(N > 0) {
    if (is_square(N)) {
      break;
    }
    N--;
  }
  cout << N << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    int n;
    char num[10][8] = {
        {"0111111"},
        {"0000110"},
        {"1011011"},
        {"1001111"},
        {"1100110"},
        {"1101101"},
        {"1111101"},
        {"0100111"},
        {"1111111"},
        {"1101111"}
    };
    while(cin >> n, n != -1){
        char display[8] = {"0000000"};
        while(n--){
            int inp;
            cin >> inp;
            rep(i,7){
                if(display[i] == num[inp][i]){
                    cout << '0';
                }else{
                    cout << '1';
                }
            }
            cout << endl;
            strcpy(display, num[inp]);
        }
    }
}

Measured memory_bytes: 1156
#include <iostream>
#include <string>

using namespace std;

typedef long long ll;

int min(int a, int b, int c) {
	int d = (a > b ? b : a);
	return d > c ? c : d;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string s1, s2;
	int dp[1001][1001];
	cin >> s1 >> s2;
	
	int size1 = s1.size();
	int size2 = s2.size();
	for (int i = 0; i <= size1; i++) {
		for (int j = 0; j <= size2; j++) {
			if (i == 0 || j == 0) {
				dp[i][j] = (i > j ? i : j);
			} else if (s1[i-1] == s2[j-1]) {
				dp[i][j] = dp[i - 1][j - 1];
			}  else {
				dp[i][j] = min(dp[i-1][j-1] + 1,
							dp[i-1][j] + 1, dp[i][j-1] + 1);
			}
		}
	}
	cout << dp[size1][size2] << endl;
	return 0;
}

Measured memory_bytes: 7108
while True:
    H,W = map (int,input().split())   

    if H == 0 and W == 0:
        break

    else:
        for h_size in range(H):
            for w_size in range(W): 
                if h_size == 0 or h_size == H-1:
                    print("#",end="")
                elif w_size == 0 or w_size == W-1:
                    print("#",end="")
                else:
                    print(".",end="")
            print("")
        print("")


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

long long st[200010];
int vis[200010];

int main() {
	int x, m;
	long long n;
	scanf("%lld%d%d", &n, &x, &m);
	memset(vis, -1, sizeof(vis));
	long long ans = 0;
	int i;
	long long j;
	for (i = 0, j = x; vis[j] == -1; ++i, j = j * j % m)
		vis[j] = i, st[i] = j;
	if (n <= vis[j]) {
		for (int k = 0; k < n; ++k)
			ans += st[k];
		printf("%lld\n", ans);
		return 0;
	}
	for (int k = 0; k <	vis[j]; ++k)
		ans += st[k];
	long long sum = 0;
	for (int k = vis[j]; k < i; ++k)
		sum += st[k];
	for (int k = 0; k < (n - vis[j]) % (i - vis[j]); ++k)
		ans += st[k + vis[j]];
	printf("%lld\n", ans + (n - vis[j]) / (i - vis[j]) * sum);
	return 0;
}



Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
int main() {
  string num;
  cin >> num;
  
  if (num[0]==num[1] && num[1]==num[2]) cout << "Yes" << endl;
  else if (num[1]==num[2]&& num[1]==num[3]) cout << "Yes" << endl;
  else cout << "No" << endl;
  
}

Measured memory_bytes: 256
h, w = map(int, input().split())
a = [0]*h
for i in range(h):
  a[i] = [int(x)%2 for x in input().split()]

ans = 0
ans_list = []
key = 0
for i in range(h):
  if i%2 == 0:
    for j in range(w):
      p = a[i][j]
      if key == 0:
        if p == 0:
          pass
        else:
          key = 1
      else:
        if p == 0:
          key = 1
          ans += 1
          if j == 0:
            ans_list.append([i, j+1, i+1, j+1])
          else:
            ans_list.append([i+1, j, i+1, j+1])
        else:
          key = 0
          ans += 1
          if j == 0:
            ans_list.append([i, j+1, i+1, j+1])
          else:
            ans_list.append([i+1, j, i+1, j+1])
        
      
  else:
    for j in range(w-1, -1, -1):
      p = a[i][j]
      if key == 0:
        if p == 0:
          pass
        else:
          key = 1
      else:
        if p == 0:
          key = 1
          ans += 1
          if j == w-1:
            ans_list.append([i, j+1, i+1, j+1])
          else:
            ans_list.append([i+1, j+2, i+1, j+1])
        else:
          key = 0
          ans += 1
          if j == w-1:
            ans_list.append([i, j+1, i+1, j+1])
          else:
            ans_list.append([i+1, j+2, i+1, j+1])

print(ans)
for i in range(ans):
  print(*ans_list[i])

Measured memory_bytes: 30128
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

void _main() {
    int A, B;
    cin >> A >> B;
    for (int i = 1; i < 20000; ++i) {
        if (i * 8 / 100 == A && i / 10 == B) {
            cout << i << endl;
            return;
        }
    }
    cout << -1 << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

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

int main(int argc, char* argv[]){
    int h, w;
    cin >> h >> w;

    vector<string> s(h);

    loop(i, h) cin >> s[i];

    loop(i, h){
        loop(j, w){
            if(s[i][j] == '.'){
                int cnt = 0;
                for(int ii = i - 1; ii <= i + 1; ii++){
                    for(int jj = j - 1; jj <= j + 1; jj++){
                        if(ii < 0 || ii >= h || jj < 0 || jj >= w)continue;
                        if(s[ii][jj] == '#'){
                            cnt++;
                        }
                    }
                }
                s[i][j] = cnt + '0';
            }
        }
    }
    loop(i, h){
        cout << s[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
X,K,D = map(int,input().split())
X = abs(X)
#0またがない
if X > K*D:
    ans = X - K*D
#0またぐ
else:
    time = X//D + 1
    K = K - time
    X = X - time*D
    if K % 2 == 0:
        ans = abs(X)
    if K % 2 != 0:
        ans = X+D

print(ans)

Measured memory_bytes: 9044
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M,X=0,Y=0;
  vector<int>vec(3);
  bool A = false;
  cin >> N >> M;
  for (X=0; X<=N; X++){
    for (Y=0; Y<=N; Y++){
      if (X+Y<=N){
        int Z = N-X-Y;
        if (X+Y+Z == N && X*10000+Y*5000+Z*1000 == M){
          vec={X,Y,Z};
          A=true;
        }
      }
    }
  }
  if (A == true){
    cout << vec.at(0) << " " << vec.at(1) << " " << vec.at(2) << endl;
    return 0;
  }
    cout << -1 << " " << -1 << " " << -1 <<endl;

}


Measured memory_bytes: 3620
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>
#include<deque>

using namespace std;
typedef long long int ll;

#define C cout<<
#define E <<endl
#define CE cout<<endl
#define pb push_back

ll n,m,a,b,c,x,y,z,aa[200010],ab[200010],ac[200010];
ll xa,xb,ua,ub;
bool r,ra,rb,rc[200010];
string s,sa,sb,sc;
char ca,cb,cc,cd[1010][1010];
vector<ll> va,vb,vc,vd,ve,vaa,vbb;
set<ll> st;

#define SIZ 200010


vector<vector<ll>> dp;

vector<vector<ll>> v2vec(int x,int y,int value=0){ return vector<vector<ll>>(y,vector<ll>(x,value)); }

template<typename MAIN>
ostream & operator<<(ostream & osys,vector<MAIN> vtar){
    osys<<"[";
    for(int i=0;i<vtar.size();i++)osys<<vtar[i]<<(i==vtar.size()-1 ? "":",");
    osys<<"]";
    return osys;
}

template<typename MAIN>
void intovec(MAIN * star,vector<MAIN> & vtar,int size){
    vtar.clear();
    for(int i=0;i<size;i++){
        vtar.pb(star[i]);
    }
}

int main(){
    cin>>n>>m;
    
    for(int i=0;i<n;i++){
        cin>>aa[i];  
    }

    intovec(aa,va,n);
    vb=vector<ll>(n);
    vb[n-1]=va[n-1];
    for(int i=n-2;i>=0;i--){
        vb[i]=max(vb[i+1],va[i]);
        
    }
    //m=0;
    c=0;
    a=0;
    for(int i=0;i<n;i++){
        vb[i]-=va[i];
        if(vb[i]>c){
            c=vb[i];
            a=1;
        }
        else if(vb[i]==c){
            a++;
        }
    }
    C a E;

    
}


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

int main() {
  int a;
  int b;
  string op;
  int ans;
  cin >> a >> op >> b;

  if (op == "+") {
    ans = a + b;
  } else {
    ans = a - b;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3628
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define veci vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vec>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))


using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
//template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
//template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x:vec) is >> x;
    return is;
}
const ll INF=1e10+100;

class DisjointSet{
    public:
    vector<ll> rank,p;
    DisjointSet(){}
    DisjointSet(ll size){
        rank.resize(size,0);
        p.resize(size,0);
        rep(i,size){
            makeSet(i);
        }
    }
    void makeSet(ll x){
        p[x]=x;
        rank[x]=0;
    }
    bool same(ll x,ll y){
        return findSet(x)==findSet(y);
    }
    void unite(ll x,ll y){
        link(findSet(x),findSet(y));
    }
    void link(ll x, ll y){
        if(rank[x]>rank[y]){
            p[y]=x;
        }
        else{
            p[x]=y;
            if(rank[x]==rank[y]){
                rank[y]++;
            }
        }
    }
    ll findSet(ll x){
        if(p[x]!=x){
            p[x]=findSet(p[x]);
        }
        return p[x];
    }
};

int main()
{
    ll n,m;
    cin >> n >> m;
    vector<ll> a(m);
    vector<ll> b(m);
    rep(i,m){
        ll s,t;
        cin >> s >> t;
        s--;
        t--;
        a[i]=s;
        b[i]=t;
    }
    ll ans=0;
    rep(i,m){ //i番目の辺を使わない
        DisjointSet dis=DisjointSet(n);
        bool flag=true; //trueならばグラフは連結
        rep(j,m){
            if(j==i) continue;
            dis.unite(a[j],b[j]);
        }
        rep(p,n){
            for(ll q=p+1;q<n;q++){
                if(!dis.same(p,q)){
                    flag=false;
                    break;
                }
            }
        }
        if(!flag) ans++;
    }
    cout << ans << endl;
    return 0;
} 

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


int main (){
    int a,b,c,K,surp,temp,sum,save_a,save_b,save_c;
    sum = 0;
    cin >> K;

    for(int a = 1;a<=K;a++){
        for(int b = 1;b<=K;b++){
            for(int c = 1;c<=K;c++){
                save_a = a;
                save_b = b;
                save_c = c;
                if(a<b){
                    temp = a;
                    a = b;
                    b = temp;
                }
                surp = a%b;
                while(surp!=0){
                    a = b;
                    b = surp;
                    surp = a % b ;
                }
                //bにaとbの最大公約数が入っている
                if(b<c){
                    temp = b;
                    b = c;
                    c = temp;
                }
                surp = b%c;
                while(surp!= 0){
                    b = c;
                    c = surp;
                    surp = b%c;
                }
                //ここでcにb,cの最大公約数が入っている
                sum = sum+c;
                a = save_a;
                b = save_b;
                c = save_c;
            }
        }
    }

                cout << sum<<'\n';


    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define RREP(i,b,e) for(int i=(b)-1;i>=e;--i)
#define rep(i,e) for(int i=0;i<(e);++i)

constexpr int MOD = 1000000007;
constexpr int INF = 1LL << 30;
constexpr long long LLINF = 1LL << 60;

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    if (it != vec.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }

template<typename T>
vector<vector<T>> warshall_floyd(const vector<vector<pair<int, T>>> &graph) {
  int n = graph.size();
  vector<vector<T>> dists(n, vector<T>(n, numeric_limits<T>::max()));
  for (int i = 0; i < n; ++i) {
    dists[i][i] = 0;
    for (auto e : graph[i]) {
      int nx; T cost;
      tie(nx, cost) = e;
      dists[i][nx] = cost;
    }
  }
  for (int k = 0; k < n; ++k) {
    for (int i = 0; i < n; ++i) if (dists[i][k] != numeric_limits<T>::max()) {
      for (int j = 0; j < n; ++j) if (dists[k][j] != numeric_limits<T>::max()) {
        dists[i][j] = min(dists[i][j], dists[i][k]+dists[k][j]);
      }
    }
  }
  return dists;
}

int main() {
  int n, m; cin>>n>>m;
  vector<vector<pair<int, int>>> g(n);
  rep(i, m) {
    int a, b, c; cin>>a>>b>>c;
    --a; --b;
    g[a].emplace_back(b, c);
    g[b].emplace_back(a, c);
  }
  auto dists = warshall_floyd(g);
  int ans = 0;
  rep(i, n) {
    for (auto x: g[i]) {
      if (x.first <= i) continue;
      if (x.second > dists[i][x.first]) ++ans;
    }
  }
  print(ans);
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
struct FIO{FIO(){std::cin.tie(0);std::cout.tie(0);std::ios_base::sync_with_stdio(0);std::cout<<std::setprecision(15);}}fIO;
template<typename T> using V = std::vector<T>;
template<typename T> void fill(V<T>&v) { for(T&e:v) std::cin >> e; }
/*-*/

int main() {
	int n;
	std::cin >> n;
	V<lnt> l(n),r(n);
	rep(i,n) std::cin >> l[i] >> r[i];
	std::sort(l.rbegin(),l.rend());
	std::sort(all(r));
	lnt ans=0;
	lnt max=0;
	rep(i,n) {
		ans+=2*l[i]-2*r[i];
		max=std::max({max,ans,ans+2*r[i],ans-2*l[i]});
	}
	print(max);
}


Measured memory_bytes: 4792
#include <stdio.h>
int main(void){

    int n;
  	char c;
    scanf("%d",&n);
  	for(int i= 0;i<n;i++){
      	scanf(" %c",&c);
  		if(c == 'Y') {printf("Four"); return 0;}
    }
  
    printf("Three");
  
    return 0;
}

Measured memory_bytes: 128
N, K = map(int, input().split())
S = input()

target = ''
if S[K - 1] == 'A':
    target = 'a'
elif S[K - 1] == 'B':
    target = 'b'
elif S[K - 1] == 'C':
    target = 'c'
print(S[:K - 1] + target + S[K:])


Measured memory_bytes: 2940
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
struct tree{
    int left;
    int key;
    int right;
}tr[30];
bool cmp(tree t1,tree t2);
void preorder(tree t);
void inorder(tree t);
void postorder(tree t);
int pre[30],ino[30],pos[30];
int j,k,l;
int main(){
    int n;
    while(~scanf("%d",&n)){
        int i;
        memset(tr,0,sizeof(tr));
        for(i=0;i<n;i++)
            scanf("%d %d %d",&tr[i].key,&tr[i].left,&tr[i].right);
        sort(tr,tr+n,cmp);
        for(i=0;i<n;i++){
            for(j=0;j<n;j++){
                if(tr[i].key==tr[j].left||tr[i].key==tr[j].right)
                    break;
            }
            if(j==n)break;
        }
        j=0;k=0;l=0;
        preorder(tr[i]);
        inorder(tr[i]);
        postorder(tr[i]);
        printf("Preorder\n");
        for(i=0;i<j;i++)
            printf(" %d",pre[i]);
        printf("\nInorder\n");
        for(i=0;i<k;i++)
            printf(" %d",ino[i]);
        printf("\nPostorder\n");
        for(i=0;i<l;i++)
            printf(" %d",pos[i]);
        printf("\n");
    }
}
void preorder(tree t){
    if(t.key!=-1){
        pre[j++]=t.key;
        if(t.left!=-1)
            preorder(tr[t.left]);
        if(t.right!=-1)
            preorder(tr[t.right]);
    }
    else return;
}
void inorder(tree t){
    if(t.key!=-1){
        if(t.left!=-1)
            inorder(tr[t.left]);
        ino[k++]=t.key;
        if(t.right!=-1)
            inorder(tr[t.right]);
    }
    else return;
}
void postorder(tree t){
    if(t.key!=-1){
        if(t.left!=-1)
            postorder(tr[t.left]);
        if(t.right!=-1)
            postorder(tr[t.right]);
        pos[l++]=t.key;
    }
    else return;
}
bool cmp(tree t1,tree t2){
    return t1.key<t2.key;
}





Measured memory_bytes: 2800
#include <iostream>
#include <stdio.h>
using namespace std;

int main()
{
    char a;
    int count[26] = { 0 };
    a = getchar();
    while (a != EOF)
	{
        if ('a' <= a && a <= 'z')
		{
			count[a- 'a']++;
		}
        if ('A' <= a && a <= 'Z')
		{
			count[a- 'A']++;
		}
        a = getchar();
    }
    for (int i=0 ; i < 26 ; i++)
	{
        cout<<char(i + 'a')<<" : "<<count[i]<<endl;
    }
	return 0;
}

Measured memory_bytes: 3056
#include <iostream>

using namespace std;
int main() {
	string S[] = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",
			"U",
			"V", "W", "X", "Y", "Z"};
	string s;
	int a = 0;
	cin >> s;
	for (int i = 0; i <= 25; i++) {
		if (s == S[i]) {
			a = 1;
		}
	}
	if (a == 0) {
		cout << "a" << endl;
	} else {
		cout << "A" << endl;
	}
}

Measured memory_bytes: 3628
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define forn(i, n) for (int i = 0; i < int(n); ++i)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef vector<pii> vii;
#define sz(c) (int)(c).size()
#define ALL(c) (c).begin(), (c).end()

const int mod = (int)1e9 + 7;
int mult (int a, int b)
{
    return (ll)a * b % mod;
}
void add (int &a, int b)
{
    a += b;
    if (a >= mod)
        a -= mod;
}

const ll inf = (ll)1e18 + 10;
struct segtree
{
    vll vals;
    int tsz;

    segtree (const vll &d)
    {
        tsz = 1;
        while (tsz <= sz(d))
            tsz *= 2;

        vals.assign(2 * tsz, inf);
        forn (i, sz(d))
            vals[i + tsz] = d[i];

        for (int i = tsz - 1; i >= 1; i--)
            vals[i] = min(vals[2 * i], vals[2 * i + 1]);
    }

    ll getmin (int l, int r)
    {
        ll ans = inf;
        for (l += tsz, r += tsz; l < r; l >>= 1, r >>= 1)
        {
            if (l & 1)
                ans = min(ans, vals[l++]);
            if (r & 1)
                ans = min(ans, vals[--r]);
        }
        return ans;
    }
};

void solve (int n)
{
    ll a, b;
    cin >> a >> b;
    vll s(n);
    forn (i, n) cin >> s[i];

    vll d(n - 1);
    forn (i, n - 1) d[i] = s[i + 1] - s[i];
    segtree data(d);

    vvi ptr(n, vi(2, -1));
    for (int i = n - 1; i >= 0; i--)
    for (int j = 0; j < 2; j++)
    {
        ll step = (j == 0 ? a : b);
        ll other = (j == 0 ? b : a);
        int pos = lower_bound(ALL(s), s[i] + step) - s.begin() - 1;
        ll tmin = data.getmin(i + 1, pos);
        if (tmin < other)
        {
            ptr[i][j] = -1;
            continue;
        }
        assert(pos >= i && pos != n);
        assert(s[pos] < s[i] + step);
        assert(pos + 1 == n || s[pos + 1] >= s[i] + step);

        if (pos + 1 == n)
            ptr[i][j] = n;
        else if (pos != i)
            ptr[i][j] = ptr[pos][j ^ 1];
        else
            ptr[i][j] = pos + 1;
    }

    vi dp(n + 1);
    dp[n] = 1;

    for (int i = n - 1; i >= 0; i--)
    forn (j, 2) if (ptr[i][j] != -1)
    {
        add(dp[i], dp[ptr[i][j]]);
        if (j == 1)
        {
            //forn (k, 2) fprintf(stderr, "ptr[%d][%d] = %d\n", i, k, ptr[i][k]);
            //fprintf(stderr, "dp[%d] = %d\n", i, dp[i]);
        }
    }

    cout << dp[0] << endl;
    //exit(0);
}

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

    int n;
    while (cin >> n)
        solve(n);
}


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

int main() {
  int text1;
  int text2;
  int text3;
  int text4;
  int sumc;
  cin >> text1 >> text2 >> text3 >> text4;
  if (text4 >= text1){
    text4 -= text1;
    sumc += text1;
    if(text4 > text2){
    text4 -= text2;
    sumc -= text4;}
  }else{sumc += text4;}
  cout << sumc;
}



Measured memory_bytes: 3632
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;
lint p=1e9+7;

lint pow_mod(lint a,lint b,lint p){
  if(b==0)return 1;
  if(b%2==0){
    lint d=pow_mod(a,b/2,p);
    return (d*d)%p;
  }else{
    return (a*pow_mod(a,b-1,p))%p;
  }
}

//x / a mod p=x * inv_mod(a,p) 
lint inv_mod(lint a,lint p){
  return pow_mod(a,p-2,p);//(a^(p-2))mod p
}


int main(){
  int N;
  cin>>N;
  lint A[N];
  REP(i,N)cin>>A[i];
  lint ans=0;
  lint S=0;
  REP(i,N)S+=A[i];
  S%=p;
  S*=S;
  S%=p;
  REP(i,N){
    S-=A[i]*A[i];
    S%=p;
    if(S<0)S+=p;
  }
  S*=inv_mod(2,p);
  S%=p;
  cout<<S<<endl;

  return 0;
}


Measured memory_bytes: 5196
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <deque>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

P f(int x) {
  int a = x % 10;
  int b;
  while(x) {
    b = x;
    x/=10;
  }
  return P(a, b);
}

int main() {
  int N; cin >> N;
  map<P, int> mp;
  for(int i = 1; i <= N; i++) {
    P p = f(i);
    mp[p]++;
  }

  ll ans = 0LL;
  for(int i = 1; i <= N; i++) {
    P p = f(i);
    P q(p.second, p.first);
    ans += mp[q];
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
a,b,c,k=map(int,input().split())
sum=0
if k>=a:
    sum=a
    rem=k-a
else:
    sum=k
    rem=0
if rem==0:
    print(sum)
else:
    if rem>=b:
        rem=rem-b
    else:
        rem=0
        print(sum)
    if rem!=0:
        sum=sum-rem
        print(sum)
    else:
        print(sum)





Measured memory_bytes: 9172
#include <bits/stdc++.h>
#include <fstream>
#define inputtxt() std::ifstream in("input.txt"); std::cin.rdbuf(in.rdbuf())
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define foreach(e, v) for (auto e : v)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define collect(arr, size) rep(i,size) cin >> arr[i];

vector<bool> is_ACGT('Z'+1,false);
int main(){
    is_ACGT['A'] = is_ACGT['T'] = is_ACGT['C'] = is_ACGT['G'] = true;
    string s; cin >> s;
    vector<bool> ACGTarea(s.length());
    rep(i,s.length()) ACGTarea[i] = is_ACGT[s[i]];
    int mx = 0, now = 0;
    rep(i,s.length()){
        if(ACGTarea[i]){
            now++;
        }else{
            mx = max(mx,now);
            now = 0;
        }
    }
    mx = max(mx,now);
    now = 0;
    cout << mx << endl;
    return 0;
}

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

A = map(int, input().split())
B = map(int, input().split())
C = map(int, input().split())

L = []
L.extend(((x, 3)  for x in A))
L.extend(((x, 2)  for x in B))
L.extend(((x, 1)  for x in C))

L = sorted(L, reverse=True)

cnt_C = 0
cnt_B = 0
cnt_A = 0
for x, i in L:
    if i == 1:
        cnt_C += 1
    elif i == 2:
        cnt_B += cnt_C
    elif i == 3:
        cnt_A += cnt_B

print(cnt_A)


Measured memory_bytes: 121904
#define LOCAL
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second	
#define db 0
#define EPS (1e-7)    //0.0000001 the value
#define PI (acos((ld)-1.0))
#define MAXN (300006)
#define ll long long int 
#define ld long double
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
#define space " "
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define ph push
#define btinpct(x) __builtin_popcountll((x))
#define MSB(bm) ((bm==0)?-1:(63-__builtin_clzll((bm))))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
string to_string(char c) {string s(1,c);return s;}string to_string(bool b){return (b ? "true" : "false");}template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}template <typename A>string to_string(A v) {bool first = true;string res = "{";for (const auto &x : v) {if (!first) {res += ", ";}first = false;res += to_string(x);}res += "}";return res;}void degug_out() { cerr << endl; }template <typename Head, typename... Tail>void degug_out(Head H, Tail... T) {cerr << " " << to_string(H);degug_out(T...);}inline ll gcd(ll a,ll b){if(a>b)swap(a,b);if(a==0)return b;return gcd(b%a,a);}
#ifdef LOCAL
// #define degug(...) cerr << "[" << #__VA_ARGS__ << "]:", degug_out(__VA_ARGS__)
#else
// #define degug(...) 663
#define cerr if(0)cout
#endif
#warning "// FOR has been inclusive now!!!!"
ll n, k, A[2006], ans;
const ll MOD=1e9+7;
int main()
{
	FAST
	cin>>n>>k;
	FOR(i,1,n) cin>>A[i];
	FOR(i,1,n) {
		ll more=0, lol=0;
		FOR(j,i+1,n) if(A[j]<A[i]) ++more;
		FOR(j,1,n) if(A[j]<A[i]) ++lol;
		ans+=more*k%MOD; ans%=MOD;
		ans+=lol*((k*(k-1)/2)%MOD)%MOD; ans%=MOD;
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace lainxi
{
    class Program
    {
        static void Main(string[] args)
        {
           
            string S = Console.ReadLine(); ;

            if (S[0] != S[1] && S[1] != S[2] && S[2] != S[0])

            {
                Console.WriteLine("Yes");

            }
            else
            {
                Console.WriteLine("No");
                
            }
            Console.ReadKey();
        }
    }
}


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

int main()
{
	vector<string> S(3),T(3);
	cin >> S.at(0);

	int N = S.at(0).size();

	T.at(0) = S.at(0);
	reverse(T.at(0).begin(), T.at(0).end());

	if (S.at(0) == T.at(0)) {
		S.at(1) = S.at(0).substr(0, (N - 1) / 2);
		T.at(1) = S.at(1);
		reverse(T.at(1).begin(), T.at(1).end());
		if (S.at(1) == T.at(1)) {
			S.at(2) = S.at(0).substr((N+3)/2-1, N-(N+3)/2+1);
			T.at(2) = S.at(2);
			reverse(T.at(2).begin(), T.at(2).end());
			if (S.at(2) == T.at(2)) {
				cout << "Yes" << endl;
			}
			else { cout << "No" << endl; }
		}
		else { cout << "No" << endl; }
	}
	else { cout << "No" << endl; }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N,M,sum=0,ans;
    int A[10001];
    scanf("%d %d",&N,&M);
    for(int i=0;i<M;i++)
    {
        scanf("%d",&A[i]);
    }
    for(int i=0;i<M;i++)
    {
        sum = sum + A[i];
    }
        if(N-sum==0)
    {
        printf("0\n");
    }
    else if(N-sum>0)
    {
        printf("%d\n",N-sum);
    }
    else
    {
        printf("-1\n");
    }
    return 0;
}


Measured memory_bytes: 3784
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int[] sArray = new int[10001];
		int[] qArray = new int[501];
		int count = 0;

		// 入力を受け取る
		int num = scan.nextInt();
		for(int i = 0; i < num; i++) {
			sArray[i] = scan.nextInt();
		}
		int q = scan.nextInt();
		for(int i = 0; i < q; i++) {
			qArray[i] = scan.nextInt();
		}

		// 線形探索を行う
		for(int i = 0; i < q; i++) {
			// 番兵の設置
			sArray[num] = qArray[i];
			int j = 0;
			while(sArray[j] != qArray[i]) {
				j++;
			}
			if(j == num) {
				continue;
			}
			count++;
		}

		System.out.println(count);

	}
}



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

int main(){
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    int sum=0;
    vector<bool> ac(n, false);
    for(int i = 0; i < n-1; i++)
    {
        if(s[i]=='A'&&s[i+1]=='C') {
            ac[i]=true;
            sum++;
        }
    }
    vector<pair<int, int>> len(n);
    len[0]= make_pair(0, sum);
    for(int i = 1; i < n; i++)
    {
        if(ac[i-1]){
            len[i]= make_pair(len[i-1].first+1, len[i-1].second-1);
        }
        else
        {
            len[i]= make_pair(len[i-1].first, len[i-1].second);
        }
        
    }
    


    int l[q], r[q];
    for(int i = 0; i < q; i++)
    {
        cin >> l[i] >> r[i];
        l[i]--;
        r[i]--;
        int num = sum-len[r[i]].second-len[l[i]].first;
        cout << num << endl;
    }
    
    
    
    return 0;
}

Measured memory_bytes: 2560
import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** -10

def popcount(i):
    return bin(i).count('1')

N = INT()
S = list(map(int, input()))[::-1]

pcnt1 = S.count(1) - 1
pcnt2 = S.count(1) + 1
base1 = base2 = 0
for i in range(N):
    if S[i]:
        if pcnt1 != 0:
            base1 += pow(2, i, pcnt1)
        base2 += pow(2, i, pcnt2)

ans = [0] * N
for i in range(N):
    if S[i] and pcnt1 == 0:
        ans[i] = 0
        continue
    cur = 0
    if S[i]:
        cur += (base1 - pow(2, i, pcnt1)) % pcnt1
    else:
        cur += (base2 + pow(2, i, pcnt2)) % pcnt2
    cnt = 1
    while cur:
        cur %= popcount(cur)
        cnt += 1
    ans[i] = cnt
for a in ans[::-1]:
    print(a)


Measured memory_bytes: 14248
#include <stdio.h>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>


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; }
//constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;
const long double PI = acos((long double)(-1));

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;


int bfs(int start, vector<int>& d, vector<vector<int>>& g) {
	d[start] = 0;
	int last = -1;
	queue<int> q;
	q.push(start);
	while (!q.empty()) {
		int cur = q.front();
		q.pop();
		last = cur;
		for (int next : g[cur]) {
			if (d[next] != -1) continue;
			d[next] = d[cur] + 1;
			q.push(next);
		}
	}
	return last;
}
int main()
{

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int n; cin >> n;
	vector<int> p(n); for (int i = 0; i < n; i++) cin >> p[i];
	vector<vector<int>> to(30, vector<int>(n));
	for (int i = 0; i < n; i++) {
		int nxt = i + p[i];
		to[0][i] = nxt;
	}
	for (int i = 1; i < 30; i++) {
		for (int j = 0; j < n; j++) {
			to[i][j] = to[i - 1][to[i - 1][j]];
		}
	}
	vector<vector<int>> g(n);
	for (int i = 0; i < n; i++) {
		for (int k = 1; k <= 6; k++) {
			int nxt = min(i + k, n - 1);
			if (p[to[29][nxt]] != 0) continue;
			nxt = to[29][nxt];
			g[i].emplace_back(nxt);
		}
	}
	vector<int> d(n, -1);
	bfs(0, d, g);
	cout << d[n - 1] << endl;
}




Measured memory_bytes: 22596
#include <stdio.h>

int main(void)
{
  int i, j, n, d[101], total = 0;
  
  scanf("%d", &n);
  for( i = 0; i < n; i++ ){
    scanf("%d", &d[i]);
  }
  
  for( i = 0; i < n; i++ ){
    for( j = i+1; j < n; j++ ){
      total += d[i]*d[j];
    }
  }
  
  printf("%d\n", total);
  
  return 0;
}

Measured memory_bytes: 128
n,m=map(int, input().split())
l=[list(map(int, input().split())) for i in range(n)]
food=[]
for i in range(1, m+1):
    a=0
    for j in range(n):
        a+=l[j][1:l[j][0]+1].count(i)
    if a==n:
        food.append(a)
    else:
        continue
print(len(food))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) 
#define rep2(i, n, m) for (ll i = n; i <= (ll)(m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (ll)(m); --i)

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

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);

  ll a, b, k; cin >> a >> b >> k;
  
  rep(i, k) {
    if (i % 2 == 0) {
      a = a / 2;
      b += a;
    } else {
      b = b / 2;
      a += b;
    }
  }

  cout << a << " " << b << endl;

  return (0);
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
int main(){
  
  int N; cin >> N;
  int a[100001], b[100001], c[100001];
  for(int i=1; i<=N; i++) cin >> a[i] >> b[i] >> c[i];
  
  int dp[100001][3];
  dp[1][0] = a[1]; dp[1][1] = b[1]; dp[1][2] = c[1];
  
  for(int i=2; i<=N; i++){
    dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a[i];
    dp[i][1] = max(dp[i-1][2], dp[i-1][0]) + b[i];
    dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c[i];
  }
  
  cout << max(max(dp[N][0], dp[N][1]), dp[N][2]) << endl;
  
}

Measured memory_bytes: 2560
N = gets.chomp.to_i
num_arr = gets.chomp.split(" ").map(&:to_i).sort
initial = (num_arr[0] + num_arr[1])/2.to_f
num = 0

num_arr.sort.each_with_index do |n, i|
  next if i == 0 || i == 1
  if i == 2
    num = (num_arr[i] + initial)/2.to_f
  else
    num = (num_arr[i] + num)/2.to_f
  end
end

if N == 2
  puts initial
else
  puts num
end

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
  int x;
  cin >> x;
  if (x == 3 || x == 5 || x == 7) cout << "YES";
  else cout << "NO";
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3576
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string S, T;
    int count=0;
    cin >> S >> T;
    for(int i=0; i<3; i++)
        if(S.at(i) == T.at(i))
            count++;
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
h,w,k = map(int,input().split())
ab = []
check_y = []
check_y1 = []
for i in range(h):
    a = list(input())
    ab.append(a)
    flag = True
    for j in a:
        if j == '#':
            flag = False
            break
    if flag:
        check_y.append(i)

count = 0
dp = [[0 for a in range(w)] for b in range(h)]

for y in range(h):
    if y in check_y:
        for x in range(w):
            dp[y][x] = dp[y-1][x]
    else:
        count += 1
        counti = 0
        for x in range(w):
            if ab[y][x] == '#':
                counti += 1
                if counti > 1:
                    count += 1
            dp[y][x] = count
if dp[0][0] == 0:
    for i in range(h):
        if dp[i][0] == 1:
            memo = i
            break
    for y in range(memo):
        for x in range(w):
            dp[y][x] = dp[memo][x]
            
for s in dp:
    print(*s)

Measured memory_bytes: 52700
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
typedef long long ll;

int main() {
  int N, K, R, S, P, res = 0;
  string T, h = "";
  cin >> N >> K >> R >> S >> P >> T;
  rep(i, N) {
    if(T[i] == 'r') {
      if(i >= K && h[i - K] == 'p')
        h += '-';
      else {
        res += P;
        h += 'p';
      }
    } else if(T[i] == 's') {
      if(i >= K && h[i - K] == 'r')
        h += '-';
      else {
        res += R;
        h += 'r';
      }
    } else {
      if(i >= K && h[i - K] == 's')
        h += '-';
      else {
        res += S;
        h += 's';
      }
    }
  }
  cout << res << endl;
}

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

int main(){
    ll n; cin >> n;
    vector<ll> a(200000);
    ll dis = 1000000007;
    ll tmp=0;
    for(ll i=0; i<n; i++){
        cin >> a[i];
        tmp += a[i];
    }

    ll ans =0;
    
    for(ll i=0; i<n; i++){
        tmp -= a[i];
        ans += (tmp%dis)*(a[i]%dis);
        ans = ans%dis; 
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4824
s = [int(input())]
if(s[0] in [1,2,4]):
  pass
else:
  while(s[-1]!=4):
    if(s[-1]%2==0):
      s.append(int(s[-1]/2))
    else:
      s.append((s[-1]*3+1))
print(len(s)+3)


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <tuple>
using namespace std;

int main(){
	int N;
	cin >>N;
	int W[N];
	int sum[N];
	for(int i=0;i<N;i++){
		cin >> W[i];
	}
	sum[0]=W[0];
	for(int i=1;i<N;i++){
		sum[i]=sum[i-1]+W[i];
	}
	int ans=100000;
	for(int i=0;i<N;i++){
		ans=min(ans,abs(sum[N-1]-2*sum[i]));
	}
	cout<<ans;
}


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

int main() {
  int A,B; cin >>A >>B;
  cout <<max({A+B,A-B,A*B}) <<endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace atcoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var buf = Console.ReadLine().Split(' ');
            int A = int.Parse(buf[0]);
            int B = int.Parse(buf[1]);
            int C = int.Parse(buf[2]);
            int D = int.Parse(buf[3]);

            while (true)
            {
                C -= B;
                if (C <= 0)
                {
                    Console.WriteLine("Yes");
                    break;
                }

                A -= D;
                if (A <= 0)
                {
                    Console.WriteLine("No");
                    break;
                }

            }
        }
    }
}


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

int main(){
  string S, T;
  cin >> S >> T;
  
  int s = S.size();
  int t = T.size();
  vector<int> same(s-t+1);
  for (int i=0 ; i<s-t+1 ; i++){
    same.at(i) = 0;
    for (int j=0 ; j<t ; j++){
      if (S.at(i+j) == T.at(j))
        same.at(i)++;
    }
  }
  sort(same.begin(), same.end());
  cout << t-same.at(s-t) << endl;
}

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

int main()
{
	string input;
	while(1)
	{
		string tmp;
		getline (cin,tmp);
		input += tmp;
		if(cin.eof())
		{
			break;
		}
	}
	for(int i=0; i<input.length(); i++)
	{
		if('A'<=input[i] && input[i]<='Z')
		{
			input[i] = input[i]-'A'+'a';
		}
	}
	for(char i='a'; i<='z'; i++)
	{
		int count=0;
		for(int i2=0; i2<input.length(); i2++)
		{
			if(i == input[i2])
			{
				count +=1;
			}
		}
		cout << i << " : " << count << endl;
	}
	return 0;
}

Measured memory_bytes: 3144
#![allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main() {
    let (n, x, t) = {
        let t: Vec<i32> = read_vec();
        (t[0], t[1], t[2])
    };
    println!("{}", (n / x + (n % x != 0) as i32) * t);
}

Measured memory_bytes: 2076
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld  = long double;
using pll = pair<ll, ll> ;
using pld = pair<ld, ld>;
const int INF=1e9+7;
const ll LINF=1LL<<60;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld EPS = 1e-9; //微調整用（EPSより小さいと0と判定など）
 
#define gcd __gcd //llは受け取ってくれない
int lcm(int a, int b){return a / gcd(a, b) * b;}
#define ALL(a) a.begin(),a.end() //sort(ALL(vec));
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define PB push_back
#define SZ(x) ((int)(x).size) //size()がunsignedなのでエラー避けに
 
//最大値、最小値を更新する。aよりbのが大きい（小さい）か等しければaを更新してtrueを返す。そうでなければ何もせずfalseを返す chmax(nowmax,x);
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}
// ----- template end ---- //
 
// ------- library ------- //



// ----- library end ----- //



int main() {

  ll A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;

  //とりあえず、A+B<=2*CならABを買う必要は無い
  if (A+B<=2*C){
    cout << A*X + B*Y << endl;
    return 0;
  }
  else{ //そうでなければ2*Cのが安いので、とりあえずABを買っていく
    ll ans = 0;
    ans += min(X,Y) * 2*C;
    if (X==Y){ //必要数が同じならこれで全て買えている
    }
    else if (X>Y){ //残りの必要なXを買う ただし2*Cのが安ければABを買えばいい
      ans += (X-Y)*min(A,2*C);
    }
    else{
      ans += (Y-X)*min(B,2*C);
    }
    cout << ans << endl;
  }

// -- main() end -- //
}


 

Measured memory_bytes: 256