akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cstring>
using namespace std;
int s[200005], cal[400005], tot = 0;
int main() {
	int n; scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &s[i]);
	sort(s+1, s+n+1);
	cal[0] = s[n];
	for (int i = n-1; i >= 1; i--) {
		cal[++tot] = s[i];
		cal[++tot] = s[i];
	}
	long long int ans = 0; 
	for (int i = 0; i < n-1; i++) ans += cal[i];
	cout << ans << endl;
	return 0;
}

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

struct Edge {
	int from, to;
	Edge(int f, int t) : from(f), to(t) {}
};

using Edges = vector<Edge>;
using Graph = vector<Edges>;

vector<int> ArticulationPoint(const Graph& g) {
	int n = g.size(), idx = 0;
	vector<int> low(n), ord(n), art;
	function<void(int)> dfs = [&](int v) {
		low[v] = ord[v] = ++idx;
		for (auto& e : g[v]) {
			int w = e.to;
			if (ord[w] == 0) {
				dfs(w);
				low[v] = min(low[v], low[w]);
				if ((ord[v] == 1 && ord[w] != 2) || (ord[v] != 1 && low[w] >= ord[v]))
					art.push_back(v);
			}
			else
				low[v] = min(low[v], ord[w]);
		}
	};
	for (int u = 0; u < n; ++u) {
		if (ord[u] == 0) {
			idx = 0;
			dfs(u);
		}
	}
	sort(art.begin(), art.end());
	art.erase(unique(art.begin(), art.end()), art.end());
	return art;
}

int main()
{
	int V, E;
	cin >> V >> E;
	Graph G(V);
	for (int i = 0, s, t; i < E; i++) {
		cin >> s >> t;
		G[s].emplace_back(s, t);
		G[t].emplace_back(t, s);
	}
	auto ap = ArticulationPoint(G);
	for (auto v : ap) {
		cout << v << endl;
	}
	return 0;
}

Measured memory_bytes: 5144
#include <stdio.h>

int main(void) {

  long s,c;
  scanf("%ld %ld", &s, &c);
  long scc;
  if (s*2 >= c) {
    scc = c/2;
  } else {
    scc = s;
    c -= s*2;
    scc += c/4;
  }
  printf("%ld\n", scc);

  return 0;
}

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

int main() {
  int k,s;
  cin>>k>>s;
  int count=0;
  rep(x,k+1)
    rep(y,k+1){
    if(s-x-y>=0&&s-x-y<=k)
      count++;
    }
  cout<<count<<endl;
  }
  

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

int main()
{
  int a, b;
  string str;

  cin >> a >> b;
  if (a == 1){
    str = "Alice";
  }
  else if (b == 1){
    str = "Bob";
  }
  else if (a < b){
    str = "Bob";
  }
  else if (a > b){
    str = "Alice";
  }
  if (a == b){
    str = "Draw";
  }
  cout << str << endl;
}

Measured memory_bytes: 256
b=[[0,6,10,12,14,27,33],
   [6,0,7,9,12,23,30],
   [13,7,0,5,8,20,27],
   [18,12,5,0,5,17,26],
   [23,17,10,5,0,12,23],
   [43,37,30,25,20,0,10],
   [58,52,45,40,35,15,0]]
while 1:
    d=int(input())
    if d==0:break
    e,f=map(int,input().split())
    t=e*60+f
    a=int(input())
    e,f=map(int,input().split())
    _t=e*60+f
    if d>a:d,a=a,d
    d-=1;a-=1
    print((b[d][a]//2+b[d][a]%2)*50if b[a][d]<=40 and ((17*60+30<=t<=19*60+30)or(17*60+30<=_t<=19*60+30))else b[d][a]*50) 

Measured memory_bytes: 7680
s = input()
K = int(input())

for i in range(0, len(s)):
	if (s[i] != 'a'):
		if (122 - ord(s[i]) + 1 <= K):
			K -= (122 - ord(s[i]) + 1)
			s = s[:i] + 'a' + s[i+1:]
			if (K == 0):
				break

if (K >= 0):
	K %= 26
	x = ord(s[len(s) - 1]) + K
	lc = chr(x) if x <= 122 else chr(x - 26)
	s = s[:len(s) - 1] + lc

print (s)

Measured memory_bytes: 3512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(std::unique(all(x)), x.end());
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;
const double PI=acos(-1);
using namespace std;
vector<int> dx={1,0,-1,0};
vector<int> dy={0,1,0,-1};
template<class T>bool chmax(T &a, const T &b) { if (a<=b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<=a) { a=b; return 1; } return 0; }
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    int n;
    ll k;
    cin>>n>>k;
    vector<ll> a(n);
    ll sum=0;
    rep(i,n) {
        cin>>a[i];
        sum+=a[i];
    }
    
    bool smaller=false;
    ll ans=0;
    rrep(d,42) {
        int now=(bool)(k&(1LL<<d));
        
        ll c0=0,c1=0;
        rep(i,n) {
            if(a[i]&(1LL<<d)) c1++;
            else c0++;
        }
        if(smaller) {
            ans+=(ll)(1LL<<d)*max(c0,c1);
        }
        else {
            if(now==1 && (c1>=c0)) smaller=true;
            
            if(now==1) ans+=(ll)(1LL<<d)*max(c0,c1);
            else ans+=(ll)(1LL<<d)*c1;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds;
using namespace std;

typedef long long int lli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<lli> vli;
typedef vector<pii> vii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> OrderedSet;

const int MOD	= 1e9 + 7;
const double PI = acos(-1.0);

#define fastio			ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto &i : c)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define fill(a)  memset(a, 0, sizeof (a))
#define error(x) cerr << #x << " = " << (x) << endl
#define errorp(p) cerr << #p << " = " << (p.first) << ", " << (p.second) << endl

template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template <typename T> T lcm(T a, T b){return (a*b)/gcd(a,b); }
int mul(int a, int b, int c){lli res=(lli)a*b;return (int)(res>=c?res%c:res);}
template<typename T>T power(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mul(x,p,m);p=mul(p,p,m);n>>=1;}return x;}
int mod_neg(int a, int b, int c){int res;if(abs(a-b)<c)res=a-b;else res=(a-b)%c;return(res<0?res+c:res);}
template<typename T>T extended_euclid(T a, T b, T &x, T &y){T xx=0,yy=1;y=0;x=1;while(b){T q=a/b,t=b;b=a%b;a=t;\
t=xx;xx=x-q*xx;x=t;t=yy;yy=y-q*yy;y=t;}return a;}
template<typename T>T mod_inverse(T a, T n){T x,y,z=0;T d=extended_euclid(a,n,x,y);return(d>1?-1:mod_neg(x,z,n));}
template <class T>  inline void smax(T &x,T y){ x = max((x), (y));}
template <class T>  inline void smin(T &x,T y){ x = min((x), (y));}


int main(){
    // #ifndef ONLINE_JUDGE
	// 	freopen("test", "r", stdin);
	// #endif
    fastio;
    
    string S;
    cin >> S;
    // reverse(all(S));

    lli md = 2019;
    lli r = 0;
    vi dp(md, 0);
    lli ans = 0;
    dp[S[0] - '0'] = 1;
    int N = (int) S.size();
    repA(i, 1, N - 1){
        vi tdp(md, 0);
        tdp[S[i] - '0'] = 1;
        rep(j, md){
            if(dp[j] > 0){
                lli rem = (10LL * j + S[i] - '0') % md;
                if(rem == r) ans += dp[j];
                tdp[rem] += dp[j];
            }
        }
        rep(j, md){
            dp[j] = tdp[j];
        }
    }

    cout << ans << endl;

    return 0;
}


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

#include <math.h>
#include <stdlib.h>


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

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

//INT_MAX	2,147,483,647 = 2*1.0e9

bool PN[100010];
int sum[100010];

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int Q; cin >>Q;
    vector<int> r(Q), l(Q);
    for(int i = 0; i <Q; i++) cin >> l[i] >> r[i];

    
    vector<bool> PN(100010, true);
    PN[0] = false;
    PN[1] = false;

    vector<int> sum(100010, 0);
    for(int i = 2; i < 100010; i++){
        for(int k = 2; k * k <= i; k++){
            if(i % k == 0){
                PN[i] = false;
                break;
            }
        }
    }

    for(int i = 1; i < 100010; i++){
        sum[i] = sum[i-1];
        if(i%2 == 1 && PN[i] && PN[(i+1)/2]) sum[i]++;
    }  

    for(int i = 0; i <Q; i++) cout << sum[r[i]] - sum[l[i]-1] << endl;

    return 0;
}


Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(in.readLine());
    int k = Integer.parseInt(in.readLine());
    int ans = 1;
    for(int i=0; i<n; i++) {
      ans = Math.min(ans*2,ans+k);
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 32500
n=int(input())
da=[input() for i in range(n)]
st='MARCH'
gg=[0 for i in range(5)]
for i in da:
    for j in range(5):
        if i[0]==st[j]:
            gg[j]+=1
ans=0
for i in range(2,5):
    for j in range(1,i):
        for k in range(0,j):
            ans+=gg[i]*gg[j]*gg[k]
print(ans)



Measured memory_bytes: 9752
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define ALL(v) v.begin(), v.end()

int main(int argc, char const *argv[])
{
    string s, t;
    cin >> s >> t;
    set<string> ss;
    for (ll i = 0; i < s.size() - t.size() + 1; i++)
    {
        string temp = s;
        for (ll k = 0; k < t.size(); k++)
        {
            if (temp[i + k] == t[k])
            {
            }
            else
            {
                if (temp[i + k] == '?')
                    temp[i + k] = t[k];
                else
                {
                    break;
                }
            }
            if (k == t.size() - 1)
            {
                for (ll m = 0; m < temp.size(); m++)
                {
                    if (temp[m] == '?')
                        temp[m] = 'a';
                }
                ss.insert(temp);
            }
        }
    }
    if (ss.empty())
    {
        cout << "UNRESTORABLE" << endl;
    }
    else
    {
        cout << *ss.begin() << endl;
    }
}

Measured memory_bytes: 256
N, W = list(map(int, input().split()))

wv = [list(map(int, input().split())) for i in range(N)]

dp = [[0] * (W+1) for i in range(N)]

for i in range(N):
  w, v = wv[i]
  for j in range(W, 0, -1):
    if j - w < 0:
      dp[i][j] = dp[i-1][j]
    else:
      dp[i][j] = max(dp[i-1][j-w]+v, dp[i-1][j])

print(dp[N-1][W])


Measured memory_bytes: 119788
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <limits>
#include <algorithm>
#include <array>
#include <random>
#include <complex>
#include <regex>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define fcout cout << fixed << setprecision(10)
#define rep(i,n)    for(int i=0; i<(int)n; i++)
#define mp(a,b) make_pair(a,b)
#define pb push_back
const ll inf = 1e18;
const ll mod = 1e9 + 7;

ll pow (ll x, ll n){
    ll ans = 1;
    while(n>0){
        if(n & 1 == 1){
            ans *= x;
        }
        x = x * x;
        n >>= 1;
    }
    return ans;
}

int main(){
    ll n; cin >> n;
    ll ans ;
    if(n%2==0){
        ans = n;
    }else{
        ans = n*2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
using namespace std;
typedef long long ll;

int main(){
map<char,ll> m;
ll n;cin>>n;
for(int i=0;i<n;i++){
    string s;cin>>s;
    m[s[0]]++;
}
vector<ll> v(5);
v[0]=m['M'];
v[1]=m['A'];
v[2]=m['R'];
v[3]=m['C'];
v[4]=m['H'];
ll ans=0;
for(int i=0;i<5;i++)for(int j=i+1;j<5;j++)for(int z=j+1;z<5;z++){
   ans+=ll(v[i]*v[j]*v[z]);
}
cout<<ans;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define DEBUG true
#ifdef ONLINE_JUDGE
#undef DEBUG
#define DEBUG false
#endif 

using namespace std;

#define MAXN ((int)2e5+5)
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9 + 9)
#define ll long long
#define _ << " " <<
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define TRACE(x) if(DEBUG) cerr << #x << " = " << x << endl;
#define TRACE2(x,y) if(DEBUG) cerr << #x << " = " << x << " | " << #y << " = " << y << endl;
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl "\n"
#define pii pair<int,int>
#define mid ((l+r)/2)

ll n;

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

	ll sq_n = sqrt(n);


	for (ll i = sq_n; i >= 1; --i)
	{
		if(n % i == 0)
		{
			cout << i + n/i - 2 << endl;
			return 0;
		}
	}

	cout << n-1 << endl;
}

Measured memory_bytes: 256
s = input()
res_1 = 0
res_2 = 0
s_1 = s[0]
s_2 = None

for i in range(1, 4):
    if s[i] == s_1:
        res_1 += 1
    elif s[i] == s_2:
        res_2 += 1
    elif not s_2:
        s_2 = s[i]


if res_1 == 1 and res_2 == 1:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
import * as fs from "fs";

const [line1, line2, ..._] = fs.readFileSync("/dev/stdin", "utf8").split("\n");
const [N, A, B] = line1.split(" ").map(Number);

let passedInternational = 0, passed = 0;


for(let i=0; i<N; i++) {
	if (passed < A+B && line2[i] != 'c') {
		if (line2[i] == 'a') {
			passed += 1;
			console.log('Yes');
		} else if (line2[i] == 'b' && passedInternational < B) {
			passedInternational += 1;
			passed += 1;
			console.log('Yes');
		} else {
			console.log('No');
		}
	} else {
		console.log('No');
	}
}


Measured memory_bytes: 37300
#include<iostream>
#include<algorithm>
#include<cstring>
#include<iomanip>
#include<cmath>
#define ll long long
using namespace std;
const int N=100010;


int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(NULL);
    std::cout.tie(NULL);
    int n,m;
    int a[N];
    int ans=0;
    cin>>n>>m;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]>=m)
            ans++;
    }
     cout<<ans<<endl;

    return 0;
}



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


int n,c[500],s[500],f[500],r;

int main() {
    
  cin>>n;
  for(int i=0;i<n-1;i++){
    cin>>c[i]>>s[i]>>f[i];
  }
  
  for(int i=0;i<n-1;i++){
    r=s[i];
    for(int j=i;j<n-1;j++){
      r=max(r,s[j]);
      while(r%f[j])r++;
      r+=c[j];
      
    }
    cout<<r<<endl;
  }
  cout<<0<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

VL b, p;

ll dfs(ll x, int i){
    ll half = (b[i]+1) / 2;
    if (x <= 0) return 0;
    if (b[i] == x){
        return p[i];
    }
    else if (half == x){
        return (p[i]+1) / 2;
    }
    else if (half < x){
        return (p[i] + 1) / 2 + dfs(x-half, i-1);
    }else{
        return dfs(x-1, i-1);
    }
}

int main(){
    int n;
    ll x;
    cin >> n >> x;
    b.resize(n+1);
    p.resize(n+1);
    b[0] = 1;
    p[0] = 1;
    for(int i = 1; i <= n; i++){
        b[i] = (b[i-1] * 2) + 3;
        p[i] = (p[i-1] * 2) + 1;
    }
    ll ans = dfs(x, n);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3544
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

K, A, B = MAP()

if A+1 >= B or A >= K:
	print(1+K)
else:
	ans = A
	K -= A-1
	n, left = divmod(K, 2)
	ans += n*(B-A)+left
	print(ans)


Measured memory_bytes: 5144
#include <iostream>

using namespace std;

int main() {
  int N;
  while (cin >> N) {
    int a[100000];
    int ans[100000];
    for (int i = 0; i < N; i++) {
      cin >> a[i];
    }
    long long sum = 0;
    for (int i = 0; i < N; i++) {
      if (i & 1) {
        sum -= a[i];
      } else {
        sum += a[i];
      }
    }
    ans[0] = sum;
    for (int i = 1; i <= N; i++) {
      ans[i] = 2 * a[i-1] - ans[i-1];
    }
    ans[N-1] = 2 * a[N-1] - ans[0];
    for (int i = 0; i < N; i++) {
      if (i != 0) cout << ' ';
      cout << ans[i];
    }
    cout << endl;
  }
}


Measured memory_bytes: 2048
fun main(args:Array<String>) {
    val n = readLine()!!.toInt()
    val otoshidama = (1..n).map { readLine()!!.split(" ") }
    val jpy = otoshidama.filter { it[1] == "JPY" }.map { it[0].toInt() }.sum()
    val btc = otoshidama.filter{ it[1] == "BTC" }.map { it[0].toDouble() }.sum()
    val ans = jpy + (btc*380000)
    println(ans)

}




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

//
class Node {
private:
	int key;
	Node *p_next = NULL;
	Node *p_prev = NULL;
public:
	Node(int k);
	void linkNext(Node *n);
	void linkPrev(Node *n);
	Node *getNext();
	Node *getPrev();
	bool hasKey(int k);
	void printKey();
};

Node::Node(int k)
{
	key = k;
}

void Node::linkNext(Node *p_n)
{
	p_next = p_n;
}

void Node::linkPrev(Node *p_n)
{
	p_prev = p_n;
}

Node *Node::getNext()
{
	return p_next;
}

Node *Node::getPrev()
{
	return p_prev;
}

bool Node::hasKey(int k)
{
	return key == k;
}

void Node::printKey()
{
	cout << key;
}

//
class LinkedList {
private:
	Node *p_dummy;
	void linkNode(Node *p_n1, Node *p_n2);
public:
	LinkedList();
	void insertNode(int key);
	void deleteNode(int x);
	void deleteFirst();
	void deleteLast();
	void print();
};

LinkedList::LinkedList()
{
	p_dummy = new Node(-1);
	linkNode(p_dummy, p_dummy);
}

void LinkedList::linkNode(Node *p_n1, Node *p_n2)
{
	p_n1->linkNext(p_n2);
	p_n2->linkPrev(p_n1);
}

void LinkedList::insertNode(int key)
{
	Node *p_n = new Node(key);
	linkNode(p_n, p_dummy->getNext());
	linkNode(p_dummy, p_n);
}

void LinkedList::deleteNode(int x)
{
	Node *p_n = p_dummy->getNext();
	while (!p_n->hasKey(x)) {
		if (p_n->hasKey(-1)) return;
		p_n = p_n->getNext();
	}
	
	linkNode(p_n->getPrev(), p_n->getNext());
	delete p_n;
}

void LinkedList::deleteFirst()
{
	linkNode(p_dummy, p_dummy->getNext()->getNext());
}

void LinkedList::deleteLast()
{
	linkNode(p_dummy->getPrev()->getPrev(), p_dummy);
}

void LinkedList::print()
{
	Node *p_n = p_dummy->getNext();
	if (p_n->hasKey(-1)) return;
	while (1) {
		p_n->printKey();
		p_n = p_n->getNext();
		if (p_n->hasKey(-1)){
			cout << endl;
			break;
		} else {
			cout << " ";
		}
	}
}

//
int main(void)
{	
	LinkedList list;
	
	int n;
	cin >> n;
	
	for (int i = 0; i < n; i++) {
		char command[12] = "\0";
		cin >> command;
		if (strcmp(command, "insert") == 0) {
			int key;
			cin >> key;
			list.insertNode(key);
		} else if (strcmp(command, "delete") == 0) {
			int key;
			cin >> key;
			list.deleteNode(key);
		} else if (strcmp(command, "deleteFirst") == 0) {
			list.deleteFirst();
		} else {
			list.deleteLast();
		}
	}

	list.print();
	
	return 0;
}

Measured memory_bytes: 37452
#include "bits/stdc++.h"
using namespace std;

#define MOD 1000000007

int main() {
	int N, count = 0;
	string S, T;
	long long ans = 1;
	bool B;
	cin >> N >> S >> T;
	if (S[0] == T[0]) ans = 3, count = 1, B = true;
	else ans = 6, count = 2, B = false;
	while (count < N) {
		if (S[count] == T[count]) {
			if (B) ans *= 2;
			else ans *= 1;
			ans = ans % MOD;
			count++;
			B = true;
		}
		else {
			if (B) ans *= 2;
			else ans *= 3;
			ans = ans % MOD;
			count += 2;
			B = false;
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    vector<int>key;
    for(int i=0;i<n;i++){
      int a;cin>>a;
      key.pb(a);
    }
    string s;cin>>s;
    string str="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    str=str+str;
    str=str+str;
    string ans="";
    map<char,int>alfa;
    for(char c='a';c<='z';c++)
      alfa[c]=(52+c-'a');
    for(char c='A';c<='Z';c++)
      alfa[c]=(52+26+c-'A');
    for(int i=0;i<s.size();i++){
      char c=str[alfa[s[i]]-key[i%n]];
      ans+=c;
    }
    cout<<ans<<endl;
  }
  return 0;
}



Measured memory_bytes: 3084
#include <stdio.h>

int main(void){

  int n,m,q;
  scanf("%d %d %d", &n, &m, &q);
  int a[q],b[q],c[q];
  long d[q];
  for (long i = 0; i < q; i++) {
    scanf("%d %d %d %ld", &a[i], &b[i], &c[i], &d[i]);
  }
  long max = 0;
  long score;
  int sequence[n];
  for (int i = 0; i < n; i++) {
    sequence[i] = 1;
  }
  while (1) {
    score = 0;
    for (int i = 0; i < q; i++) {
      if (sequence[b[i]-1]-sequence[a[i]-1] == c[i]) {
        score += d[i];
      }
    }
    if (score > max) {
      max = score;
    }
    if (sequence[1] == m) {
      break;
    }
    for (int i = n-1; i > 0; i--) {
      if (sequence[i] < m) {
        sequence[i]++;
        for (int j = i+1; j < n; j++) {
          sequence[j] = sequence[i];
        }
        break;
      }
    }
  }
  printf("%ld\n", max);

  return 0;
}

Measured memory_bytes: 1712
#include <iostream>
#include <map>
#include <set>

using namespace std;

const long long int MOD=1e9+7;

int main() {
    long long int N;
    cin >> N;
    map<long long int, long long int> mp;
    for(long long int n=1; n<=N; n++) {
        long long int tmp=n;
        for(long long int i=2; i<=n; i++) {
            while(tmp%i==0) {
                mp[i]++;
                tmp/=i;
            }
            if(tmp==1) break;
        }
    }
    mp[1]=0;
    long long int ans=1;
    for(auto itr=mp.begin(); itr!=mp.end(); itr++) {
        ans *= itr->second+1;
        ans %= MOD;
    }
    cout << ans << endl;


    return 0;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string t,s;
int ans;
int main(){
	cin>>s;
	cin>>t;
	for(int i=0;i<s.size();i++){
		if(s[i]!=t[i]) ans++;
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
  int N,M;
  
  cin >> N;
  vector<string> blue(N);
  for (int i=0; i<N; i++){
    cin >> blue.at(i);
  }
  
  cin >> M;
  vector<string> red(M);
  for (int i=0; i<M; i++){
    cin >> red.at(i);
  }
  
  int Sum, Answer=0;

  for (int i=0; i<N; i++){
    Sum = 0;
    for (int j=0; j<N; j++){
      if(blue.at(i) == blue.at(j)) Sum++;
    }
    for (int j=0; j<M; j++){
      if(blue.at(i) == red.at(j)) Sum--;
    }
    if(Sum > Answer)
      Answer = Sum;
  }
  cout << Answer << endl;
}


Measured memory_bytes: 3616
#include <stdio.h>

int main(){
    int n,m;
    int count,count_max;
    int i;
    int answer = 1;
    
    scanf("%d",&n);

    count_max = 0;

    for(i = 1;i <= n;i++){
        count = 0;

        m = i;
        while(m % 2 == 0){
            count++;
            m = m / 2;
            if(count > count_max){
                count_max = count;
                answer = i;
            }
        }
    }

    printf("%d",answer);
}

Measured memory_bytes: 128
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Convert;
using static System.Console;
using static System.Math;

namespace AtCorder
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }


        public void Solve(ConsoleInput cin)
        {
            var X = cin.ReadInt;
            var Y = cin.ReadInt;
            var Z = cin.ReadInt;
            var ans = X / (Y + Z);
            if (X - (Y + Z) * ans < Z) ans--;

            WriteLine(ans);
        }


        public class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;
            public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }
            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }
            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        }
    }
}


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

int main() {
  int n;
  cin >> n;
  int d = 0;
  for (int ncopy = n; ncopy > 0; ncopy /= 10) d++;
  int ans = 0;
  for (int i = 0; i < pow(3, d); i++) {
    int x = 0, k = i;
    for (int j = 0; j < d; j++) {
      x += (2 * (k % 3) + 3) * pow(10, j);
      k /= 3;
    }
    bool contains7 = false, contains5 = false, contains3 = false;
    for (int xcopy = x; xcopy > 0; xcopy /= 10) {
      if (xcopy % 10 == 7) {
        contains7 = true;
      } else if (xcopy % 10 == 5) {
        contains5 = true;
      } else {
        contains3 = true;
      }
    }
    if (not (contains7 && contains5 && contains3)) continue;
    if (x > n) break;
    ans++;
  }
  for (int i = 3; i < d; i++) {
    ans += pow(3, i) - 3 * pow(2, i) + 3;
  }
  cout << ans << endl;
}


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

const ll INF = 1001001001;

int main(){
  ll n,x,y;
  cin >> n >> x >> y;
  queue<int> q;
  vector<int> ans(n);//1~n-1までを使う
  for(int i=1;i<=n;i++){//頂点1~n
    vector<int> dist(n+1,INF);//1~nまでを使う
    auto push = [&](int v, int d ){
      if( dist.at(v) != INF ) return;
      dist.at(v) = d;
      q.push(v);
    };
    push(i,0);
    while( !q.empty() ){
      int v = q.front(); q.pop();
      int d = dist.at(v);
      if( v-1 > 0 ) push(v-1,d+1);
      if( v+1 <= n ) push(v+1,d+1);
      if( v == x ) push(y,d+1);
      if( v == y ) push(x,d+1);
    }
    for(int j=1;j<=n;j++) ans.at(dist.at(j))++;
  }
  for(int i=1;i<n;i++){
    cout << ans.at(i)/2 << endl;
  }
  return 0;
}

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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

    int N;
    cin >> N;

    vi x(N), y(N);
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> y[i];
    }

    for (int i = 0; i < N; i++) {
        vector<double> ang;
        for (int j = 0; j < N; j++) {
            if (j != i) ang.push_back(atan2(y[j] - y[i], x[j] - x[i]));
        }
        sort(all(ang));

        double large = M_PI;
        large = max(large, ang.front() + 2 * M_PI - ang.back());
        for (int j = 1; j < ang.size(); j++) {
            large = max(large, ang[j] - ang[j-1]);
        }
        printf("%.15f\n", (large - M_PI) / (2 * M_PI));
    }

    return 0;
}



Measured memory_bytes: 768
#include <iostream>

using namespace std;

int main(){
    int N;
    int h[101];
    int ans = 0;
    h[0] = 0;
    cin >> N;
    for(int i = 1; i <= N; i++){
        cin >> h[i];
    }
    for(int i = 1; i <= 100; i++){
        int cnt = 0;
        for(int j = 1; j <= N; j++){
            if(h[j-1] < i && h[j] >= i)cnt++;
        }
        ans += cnt;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
double ps(int a , int b, int c, int d) {
  double x=sqrt((a-c)*(a-c)+(b-d)*(b-d));
  CST(8);
  return x;
}

ll PS( ll c) {
ll a=1;
  repl(i,1,c+1) {
    a*=i;
  }
  return a;
}

int main() {
  int n;
  cin >>n;
  vector<int> x(n);
  vector<int> y(n);
  rep(i,n) {
cin >>x.at(i)>>y.at(i);
  }
  
 ll  a[109]; 
  ll b[PS(n)][n];
for (ll i = 0; i < n; i++) {
 a[i]=i+1;
}
  ll count=0;

  
do {
    for (ll i = 0; i < n; i++) {
        if (i+1) 
        
         
     b[count][i]=a[i];
    }
  

  count++;
} while(next_permutation(a, a + n)); 
    
  
  
  double c[PS(n)][n+n];
  rep(i,PS(n)) {
rep(j,n) {
  c[i][j]=b[i][j];
}
  }
 

  
 rep(k,PS(n)) {
    rep(j,n-1) {
   c[k][n+j]=ps(x.at(c[k][j]-1),y.at(c[k][j]-1),x.at(c[k][j+1]-1),y.at(c[k][j+1]-1));
    }
  }
rep(m,PS(n)) {
    double sum=0;
    rep(i,n-1) {
sum +=c[m][n+i];
    }
    
    c[m][2*n-1]=sum;
  }
                
      double tot=0;
 rep(j,PS(n)) {
tot +=c[j][2*n-1];
 }
                
    double finale=(double)tot/(double)PS(n);
                CST(7);
                cout<< finale <<endl;
                }

  
  
  
  
 

Measured memory_bytes: 7808
#include "iostream"
using namespace std; 

int main() {
	int a[2] = {0,0};
  	for (int i = 0; i < 3; ++i) {
    	int x; cin >> x; 
      	if (x == 7) ++a[0];
      	if (x == 5) ++a[1];
    }
  
	(a[1] == 2 and a[0] == 1) ? puts("YES") : puts("NO");
}

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

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

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

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

	return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <array>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <list>
#include <cmath>
#include <stack>
#include <queue>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using namespace std;

const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x% mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};

struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
} comb(2000005);

mint g(int r, int c) {
	return comb(r + c + 2, r + 1) - 1;
}

int ire[200010];
long long a[200010];
long twice[200010];
long single[200010];

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

	for (int i = 0; i <= n; i++)
	{
		if (a[i] <= 2)
		{
			single[i] = 0;
			if (a[i] <= 1)
			{
				twice[i] = 0;
			}
			else
			{
				twice[i] = 1;
			}
			continue;
		}
		twice[i] = a[i] * (a[i] - 1) / 2;
		single[i] = (a[i] - 1) * (a[i] - 2) / 2;
	}

	long long sum = 0;
	for (int i = 1; i <= n; i++)
	{
		sum += twice[i];
	}

	for (int i = 1; i <= n; i++)
	{
		sum -= single[i - 1];
		sum += twice[i - 1];
		
		sum -= twice[i];
		sum += single[i];

		a[i] = sum;
	}

	for (int i = 0; i < n; i++)
	{
		int ch = ire[i];
		cout << a[ch] << endl;
	}
}


Measured memory_bytes: 40064
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
const int N=200020;
int n,son[N][2];
ll mx,dep[N];
vector<pii>V[N],t1,t2;
bool solve(ll mxlen){
    for(int x=n;x;x--){
        V[x].clear();
        if(son[x][0]==0){V[x].pb(mp(dep[x],dep[x]));continue;}
        if(V[son[x][0]].size()>V[son[x][1]].size())swap(son[x][0],son[x][1]);
        //swap不影响复杂度，但是左儿子大小上界是严格的，右儿子不一定。所以小的放左边可以压常数。
        for(int i=0,j=0;i<V[son[x][0]].size();i++){
            while(j<V[son[x][1]].size()&&V[son[x][0]][i].first+V[son[x][1]][j].second-2*dep[x]>mxlen)j++;
            //因为数对是有序的，而显然有(x,y)就有(y,x)，所以取first和second都是等价的。
            //而双指针则要求左子树的单调性和右子树相反。
            //而右子树取second时，指针j右推遇到的第一个满足点时，first的值是最小的，符合最优的性质。这样比较好写。
            if(j==V[son[x][1]].size())break;
            t1.pb(mp(V[son[x][1]][j].first,V[son[x][0]][i].second));
        }
        if(t1.empty())return false;
        for(int i=0;i<t1.size();i++) if(!i||t1[i].second<t2[t2.size()-1].second) t2.pb(t1[i]); t1.clear();
        for(int i=0,j=t2.size()-1;;){
            if(j<0&&i==t2.size())break;
            else if(j<0)V[x].pb(t2[i++]);
            else if(i==t2.size())V[x].pb(mp(t2[j].second,t2[j].first)),j--;
            else if(t2[i]<mp(t2[j].second,t2[j].first))V[x].pb(t2[i++]);
            else V[x].pb(mp(t2[j].second,t2[j].first)),j--;
        }t2.clear();
    }
    return true;
}
int main(){
    scanf("%d",&n);
    for(int x,l,i=2;i<=n;i++){
        scanf("%d%d",&x,&l);
        if(son[x][0])son[x][1]=i;
        else son[x][0]=i;
        dep[i]=dep[x]+l;
        mx=max(mx,dep[i]);
    }
    ll l=0,r=mx<<1,mid;
    while(l<r){
        mid=l+r>>1;
        if(solve(mid))r=mid;
        else l=mid+1;
    }
    printf("%lld\n",l);
}


Measured memory_bytes: 30312
#include <iostream>
#include <string>
#include <algorithm>
#include <fstream>
#include <cmath>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define dum(x) cout<<#x<<'='<<x<<endl
#define INF 2000000000

int a[100010];

int main() {
    long long N;
    cin >> N;
    int ans = INF;

    for (long long A = 1; A <= sqrt(N); A++) {
        if (N % A == 0) {
            long long  B = N / A;
            string b = to_string(B);
            ans = min(ans, (int)b.size());
        }
    }
    cout << ans << endl;
}

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

int main(){
  int a,b,a1,b1;
  cin >> a >> b;
  for(int i = 1;i < 1000000001;i++){
    a1 = abs(a - i);
    b1 = abs(b - i);
    if(a1 == b1){
      cout << i << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cmath>

using namespace std;

int main()
{
	long long N, X, m[1000], min=100000;

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

	for (i = 0; i < N; i++) {
		if (min > m[i])
			min = m[i];
	}

	cout << N + X / min << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  int n;
  cin>>n;
  map<int,int> mp;
  int a;
  REP(i,n){
    cin>>a;
    mp[a-1]++;
    mp[a]++;
    mp[a+1]++;
  }
  int ans=0;
  for(auto p:mp){
    ans = max(ans,p.second);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 4736
#include<iostream>
using namespace std;
int main()
{
  int w,h,x,y,r;
  cin >>w >>h >>x >>y >>r;

  if(r <= x && x <= w-r && r <= y && y <= h-r){
      cout << "Yes";
  }else{
      cout << "No";
  }

  cout << endl;
}



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

using namespace std;

const int MOD=(int)1e9+7;

inline int add(int a,int b)
{
    a+=b;
    if(a>=MOD)
    {
        a-=MOD;
    }
    if(a<0)
    {
        a+=MOD;
    }
    return a;
}

inline int mul(int a,int b)
{
    return a*(long long)b%MOD;
}


typedef long long ll;
typedef long double ld;

const int N=21;

int n;
bool a[N][N];
int dp[(1<<N)];
int aux[(1<<N)];
int j;

vector<int>w[N+1];
int bts[(1<<N)][N],tot[(1<<N)];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            cin>>a[i][j];
        }
    }
    for(int i=0;i<(1<<n);i++)
    {
        for(int j=0;j<n;j++)
        {
            if(i&(1<<j))
            {
                bts[i][tot[i]++]=j;
            }
        }
        w[tot[i]].push_back(i);
    }
    aux[0]=1;
    for(int i=0;i<n;i++)
    {
        for(auto &mask:w[i+1])
        {
            for(int bt=0;bt<=i;bt++)
            {
                j=bts[mask][bt];
                if(a[i][j])
                {
                    dp[mask]=add(dp[mask],aux[mask-(1<<j)]);
                }
            }
            aux[mask]=dp[mask];
        }
    }
    cout<<dp[(1<<n)-1]<<"\n";
    return 0;
}



Measured memory_bytes: 206268
def merge(A, l, m, r):
  L = A[l:m]
  L.append((1e10, None))
  R = A[m:r]
  R.append((1e10, None))
  i, j = 0, 0
  for k in range(l, r):
    if L[i][0] <= R[j][0]:
      A[k] = L[i]
      i += 1
    else:
      A[k] = R[j]
      j += 1

def msort(A, l, r):
  if r-l > 1:
    m = (l+r)//2
    msort(A, l, m)
    msort(A, m, r)
    merge(A, l, m, r)

def partition(A, l, r):
    v = A[r-1]
    i = l - 1
    for j in range(l, r-1):
        if A[j][0] <= v[0]:
            i += 1
            t = A[i]
            A[i] = A[j]
            A[j] = t
    q = i+1
    A[r-1] = A[q]
    A[q] = v
    return q

def qsort(A, l, r):
    if r-l > 1:
        q = partition(A, l, r)
        qsort(A, l, q)
        qsort(A, q+1, r)

N = int(input())
A, B = [], []
for _ in range(N):
    c, n = input().split()
    n = int(n)
    A.append((n, c))
    B.append((n, c))
qsort(A, 0, N)
msort(B, 0, N)
print('Stable' if A == B else 'Not stable')
for n, c in A:
    print(c, n)


Measured memory_bytes: 23948
n = int(input())
h = list(map(int,input().split()))
ans = 1
for i in range(1,n):
    flag = 1
    for j in range(i):
        if h[j] > h[i]:
            flag = 0
            break
        else:
            pass
    if flag:
        ans += 1
print(ans)


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

#define se second
#define fi first
#define mk(a,b) make_pair(a,b)

typedef pair<int,int> pii;

int N,N_,Q;
int sum[200010];
pii que[200010];
int seg[2][800010];
int INF = 1001001001;
int ans = INF,cnt;

void init()
{
    N_ = 1;
    while(N_ <= N + 1)N_ *= 2;
    for(int i = 0; i < N_ * 2 - 1; i++)seg[0][i] = seg[1][i] = INF;
    return;
}

void update(int id,int k,int x)
{
    k += N_ - 1;
    seg[id][k] = x;
    while(k)
    {
        k = (k - 1) / 2;
        seg[id][k] = min(seg[id][k * 2 + 1],seg[id][k * 2 + 2]);
    }
    return;
}

int get_min(int id,int a,int b,int k = 0,int l = 0,int r = N_)
{
    if(a <= l && r <= b)return seg[id][k];
    if(b <= l || r <= a)return INF;
    int L = get_min(id,a,b,k * 2 + 1,l,(l + r) / 2);
    int R = get_min(id,a,b,k * 2 + 2,(l + r) / 2,r);
    return min(L,R);
}

int main()
{
    ///1index
    scanf("%d",&N);
    for(int i = 1; i <= N; i++)
    {
        int a;
        scanf("%d",&a);
        if(a)cnt++;
        if(a)sum[i] = sum[i - 1] - 1;
        else sum[i] = sum[i - 1] + 1;
    }
    scanf("%d",&Q);
    for(int i = 0; i < Q; i++)
    {
        int l,r;
        scanf("%d%d",&l,&r);
        que[i] = mk(l,r);
    }

    sort(que,que + Q);

    init();
    update(0,0,0);
    update(1,0,0);

    for(int i = 0; i < Q; i++)
    {
        int res = get_min(1,que[i].fi,que[i].se + 1) + sum[que[i].se];
        res = min(res,get_min(0,0,que[i].fi) + sum[que[i].se] - sum[que[i].fi - 1]);
        if(res < get_min(0,que[i].se,que[i].se + 1))
        {
            update(1,que[i].se,res - sum[que[i].se]);
            update(0,que[i].se,res);
        }
    }

    for(int i = 0; i <= N; i++)ans = min(ans,get_min(0,i,i + 1));

    printf("%d\n",ans + cnt);

    return 0;
}


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

using namespace std;
#define inf             0x3f3f3f3f
#define INF             2e18
#define eps             1e-9

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define fRead           freopen("input.txt","r",stdin)
#define fWrite          freopen("output.txt","w",stdout)

#define LL              long long
#define ull            unsigned long long
#define PI              acos(-1.0)
#define pb              push_back
#define mk              make_pair
#define pii             pair<int,int>
#define pLL             pair<LL,LL>
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define SQR(a)          ((a)*(a))
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define vi              vector <int>
#define vL              vector <LL>
#define LB(a,x)         (lower_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which does not compare less than val.
#define UB(a,x)         (upper_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which compares greater than val.
#define prec(n)         fixed << setprecision(n)

#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())

#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define IT(it,x)	    for(it=x.begin();it!=x.end();it++)
int main()
{
   LL x,k,d;
   cin>>x>>k>>d;
  x=abs(x);
  if(k<x/d)
    cout<<x-k*d;
  else
  {
      if((x/d)%2==k%2)
        cout<<x%d;
      else
        cout<<d-x%d;
  }

}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
     
    using namespace std;
     
    typedef long long ll;
     
    int main() {
      int n, m; cin >> n >> m;
      map <int, int> mp;
      vector <int> ok(n + 1, 0);
      int cnt = 0;
      for(int i = 0; i < m; i++) {
        int p; cin >> p;
        string s; cin >> s;
        if(mp.count(p)) continue;
        if(s == "WA") {
          cnt++;
          ok[p]++;
        }
        else mp[p] = 1;
      }
      for(int i = 1; i <= n; i++) {
        if(mp.count(i) == 0) cnt -= ok[i];
      }
      cout << mp.size() << ' ' << cnt << '\n';
    }

Measured memory_bytes: 5376
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
using namespace std;


int main() {
	map<int, int> mp;
	long long int n=0,e=0,w=0,s=0;
	string str;
	cin >> str;
	for (int i = 0; i < str.length(); i++) {
		if (str[i] == 'E') {
			e=1;
		}
		else if (str[i] == 'W') {
			w=1;
		}
		else if (str[i] == 'S') {
			s=1;
		}
		else if (str[i] == 'N') {
			n=1;
		}
	}
	if ((n + s) % 2 == 0 && (e + w) % 2 == 0) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
}


Measured memory_bytes: 256