akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//登録しよう！→ https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define gre greater //sortを降順にする
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示

void solve(long long N, std::vector<long long> d){
  sort(all(d));
  ll x = d[floor(N/2)] , y = d[floor(N/2)-1];
  cout << (x != y ? abs(x-y) : 0) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> d(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&d[i]);
    }
    solve(N, std::move(d));
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define uint unsigned int
#define ull  unsigned long long
typedef string str;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define fi first
#define se second
#define ins insert
#define all(x) (x).begin(), (x).end()
#define fr(i, n) for(int i = 0; i < n; i++)
#define rall(x) (x).rbegin(), (x).rend()
#define speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
const int INF = 1e9 + 5;
 
 
void solve(){
    string s;
    cin >> s;
    fr(i, s.size()){
        if(s[i] == '7'){
            cout << "Yes";
            return;
        }
    }
    cout << "No";
    
    
}
 
 
int main(){
    speed();
    int t = 1;
    // cin >> t;
    while(t--)solve();
}

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

struct pr{int to,cost;};

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int h,w; cin>>h>>w;
	vector<vector<int>>c(10,vector<int>(10)); for(auto&i:c)for(auto&j:i)cin>>j;
	vector<int>mn(10); for(int i=0;i<10;++i)mn.at(i)=c.at(i).at(1);
	for(int y=0;y<10;++y){
		queue<pr>q; pr pus,rec;
		int least=mn.at(y);
		for(int x=0;x<10;++x){
			if(y!=x&&c.at(y).at(x)<least){
				pus.to=x,pus.cost=c.at(y).at(x);
				q.push(pus);
			}
		}
		while(q.size()){
			rec=q.front(); q.pop();
			if(rec.to==1)least=mn.at(y)=min(mn.at(y),rec.cost);
			else for(int x=0;x<10;++x){
				int yy=rec.to,spend=rec.cost;
				if(x==yy)continue;
				int tcost=spend+c.at(yy).at(x);
				if(tcost<least){
					pus.to=x,pus.cost=tcost;
					q.push(pus);
				}
			}
		}
	}
	int ans=0;
	for(int i=0;i<h;++i){
		for(int j=0;j<w;++j){
			int a; cin>>a;
			if(a<0)continue;
			ans+=mn.at(a);
		}
	}
	cout<<ans<<"\n"s;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
 
using namespace std;
 
int main(){
    double a,b,c,degree,S;
    scanf("%lf %lf %lf",&a,&b,&degree);
    S = (0.5)*a*b*sin(M_PI*degree/180);
    c = sqrt(a*a+b*b-2*a*b*cos(M_PI*degree/180));
    printf("%.8lf\n",S);
    printf("%.8lf\n",a+b+c);
    printf("%.8lf\n",2*S/a);
}


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

int n;
float ans;

void input(){
  cin >> n;
}

void solve(){
  input();
  if(n % 2 == 0){
    ans = (double)1/2;
  }else{
    ans = (((double)n+1)/2)/n; 
  }
  cout << fixed << setprecision(10);
  cout << ans << endl;
}

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


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int N,M;
main()
{
    while(cin>>M>>N,N)
    {
        vector<int>s(M);
        int ans=0;
        for(int i=0;i<N;i++)
        {
            for(int j=0;j<M;j++)
            {
                int a;cin>>a;ans=max(ans,s[j]+=a);
            }
        }
        cout<<ans<<endl;
    }
}


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

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

int main() {
  int cnt = 1;
  while(true) {
    int x;
    cin >> x;
    if (x == 0) break;
    printf("Case %d: %d\n", cnt, x);
    cnt++;
  }
  return 0;
}



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

typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;

#define pb push_back
#define mp make_pair
#define all(_c) _c.begin(), _c.end()

const int N = 3001;

vector <vector <int> > dp(N, vector <int> (N, 0));
vector <vector <int> > last(N, vector <int> (N, -1));

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

    string s, t;
    cin >> s >> t;

    for (int i = 1; i <= s.length(); i++)
        for (int j = 1; j <= t.length(); j++) {
            if (s[i - 1] == t[j - 1]) {
                dp[i][j] = 1 + dp[i - 1][j - 1];
                last[i][j] = 2;
            } else {
                last[i][j] = (dp[i - 1][j] > dp[i][j - 1]);
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
        }
    
    // 0 -> -1 -1
    // 1 -> -1  0
    // 2 ->  0 -1
    string ans = "";
    for (int i = s.length(), j = t.length(); i > 0 and j > 0; ) {
        if (last[i][j] == 2) {
            ans += s[i - 1];
            i--, j--;
        } else if (last[i][j] == 1) {
            i--;
        } else
            j--;
    }

    reverse(all(ans));
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 72832
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>

using namespace std;

typedef long long ll;

int main(){
 	//freopen("input.txt", "r", stdin);
 	//freopen("output.txt", "w", stdout);

	std::ios_base::sync_with_stdio(false), cin.tie(0);

	int n, m, diff;
	string first, last;
	cin >> n >> m;
	int fr[n + 1];
	string ans[m];
	pair<int, pair<int, int>> p[m];
	memset(fr, 0, sizeof(fr));
	for(int i = 0 ; i < m ; i++){
		cin >> p[i].first >> p[i].second.first;
		p[i].second.second = i;
	}
	string res;
	sort(p, p + m);
	for(int i = 0 ; i < m ; i++){
		res = "";
		++fr[p[i].first];
		first = to_string(p[i].first);
		last = to_string(fr[p[i].first]);
		diff = 6 - (int)first.size();
		while(diff--) res += '0';
		res += first;
		diff = 6 - (int)last.size();
		while(diff--) res += '0';
		res += last;
		ans[p[i].second.second] = res;
	}
	for(int i = 0 ; i < m ; i++){
		cout << ans[i] << '\n';
	}
	return 0;
}


Measured memory_bytes: 9728
import sys


def input():
    return sys.stdin.readline().strip()


def solve():
    N = int(input())
    inc_chunks = []
    dec_chunks = []
    for _ in range(N):
        depth = 0
        level = 0
        for c in input():
            if c == '(':
                level += 1
            else:
                level -= 1
                depth = min(depth, level)
        if level > 0:
            inc_chunks.append((depth, level))
        else:
            dec_chunks.append((depth - level, -level))

    inc_chunks.sort(reverse=True)
    dec_chunks.sort(reverse=True)
    inc_level = 0
    for depth, level in inc_chunks:
        if inc_level + depth < 0:
            return 'No'
        inc_level += level
    dec_level = 0
    for depth, level in dec_chunks:
        if dec_level + depth < 0:
            return 'No' 
        dec_level += level
    if inc_level != dec_level:
        return 'No'
    return 'Yes'


print(solve())


Measured memory_bytes: 80292
def main():
    import sys
    input = sys.stdin.readline

    # Dinic's algorithm
    from collections import deque
    class Dinic:
        def __init__(self, N):
            self.N = N
            self.G = [[] for i in range(N)]

        def add_edge(self, fr, to, cap):
            forward = [to, cap, None]
            forward[2] = backward = [fr, 0, forward]
            self.G[fr].append(forward)
            self.G[to].append(backward)

        def add_multi_edge(self, v1, v2, cap1, cap2):
            edge1 = [v2, cap1, None]
            edge1[2] = edge2 = [v1, cap2, edge1]
            self.G[v1].append(edge1)
            self.G[v2].append(edge2)

        def bfs(self, s, t):
            self.level = level = [None] * self.N
            deq = deque([s])
            level[s] = 0
            G = self.G
            while deq:
                v = deq.popleft()
                lv = level[v] + 1
                for w, cap, _ in G[v]:
                    if cap and level[w] is None:
                        level[w] = lv
                        deq.append(w)
            return level[t] is not None

        def dfs(self, v, t, f):
            if v == t:
                return f
            level = self.level
            for e in self.it[v]:
                w, cap, rev = e
                if cap and level[v] < level[w]:
                    d = self.dfs(w, t, min(f, cap))
                    if d:
                        e[1] -= d
                        rev[1] += d
                        return d
            return 0

        def flow(self, s, t):
            flow = 0
            INF = 10 ** 9 + 7
            G = self.G
            while self.bfs(s, t):
                *self.it, = map(iter, self.G)
                f = INF
                while f:
                    f = self.dfs(s, t, INF)
                    flow += f
            return flow

    inf = 1<<40
    N = int(input())
    A = list(map(int, input().split()))
    dinic = Dinic(N+2)
    ans = 0
    for i, a in enumerate(A):
        if a > 0:
            ans += a
            #dinic.add_edge(0, i+1, 0)
            dinic.add_edge(i+1, N+1, a)
        else:
            dinic.add_edge(0, i+1, -a)
            #dinic.add_edge(i+1, N+1, 0)
    for i in range(1, N+1):
        for k in range(1, N+1):
            if i*k > N:
                break
            dinic.add_edge(i, i*k, inf)

    print(ans - dinic.flow(0, N+1))


if __name__ == '__main__':
    main()

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

int main() {
   char a,b;
   cin >> a >> b;
   if(a=='H'){
      if(b=='H')cout << 'H';
      else cout << 'D';
   }else{
      if(b=='H')cout << 'D';
      else cout << 'H';
   }
   return 0;
}


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

int main(void){

    int i;
    int k;
    int a = 7;
    scanf("%d", &k);



    for(i = 0; (i < k) && (k % 2 == 1); i ++){
        if(a % k == 0){
            printf("%d\n", i + 1);
            break;
        }
        a = 10 * a + 7;
        a = a % k;
    }
    if((i == k) || (k % 2 == 0))
        printf("%d\n", -1);


    return 0;
}

Measured memory_bytes: 1732
def fast_pow(x, y):
    if y == 0:
        return 1
    p = fast_pow(x, y // 2)
    p = p * p
    if y % 2:
        p = p * x
    return p


n, a = list(map(int, input().split()))
maxM = 1
d = 1
while n >= d:
    maxM += 1
    d *= 2

r = n
l = 0
while r - l > 1:
    mid = (r + l) // 2

    for m in range(2, maxM + 1):
        if (mid + a) % m == 0:
            if (mid + a) // m - a < 1:
                continue
            if fast_pow((mid + a) // m - a, m) >= n:
                r = mid
                break
        else:
            a1 = (mid + a + m - 1) // m - a
            a2 = (mid + a) // m - a
            if a1 < 1 or a2 < 1:
                continue

            if fast_pow(a1, (mid + a) % m) * fast_pow(a2, m - (mid + a) % m) >= n:
                r = mid
                break
    else:
        l = mid
print(r)


Measured memory_bytes: 66088
# Sの先頭の文字は大文字のAである。
# Sの先頭から3文字目と末尾から2文字目の間（両端含む）に大文字のCがちょうど1個含まれる。
# 以上のA, Cを除くSのすべての文字は小文字である。

x = input()


def b_mon(S):
    if not S[0] == 'A':
        return 'WA'
    if not S[2:-1].count('C') == 1:
        return 'WA'

    c_index = S[2:-1].find('C') + 2
    S = S[1:c_index] + S[c_index + 1:]
    if False in list(map(lambda char: char.islower(), S)):
        return 'WA'

    return 'AC'

print(b_mon(x))


Measured memory_bytes: 3060
from collections import deque
h,w = map(int,input().split())
s = [input() for _ in range(h)]
ans = 0

def bfs(sh,sw):
    dh = (1,-1,0,0)
    dw = (0,0,1,-1)
    dist = [[-1 for _ in range(w)] for _ in range(h)]
    queue = deque()
    queue.append((sh,sw))
    dist[sh][sw] = 0
    while len(queue) != 0:
        ch,cw = queue.popleft()
        for i in range(4):
            nh,nw = ch+dh[i],cw+dw[i]
            if not (0 <= nh <= h-1 and 0 <= nw <= w-1): continue
            if s[nh][nw] == "#": continue
            if dist[nh][nw] != -1: continue
            queue.append((nh,nw))
            dist[nh][nw] = dist[ch][cw]+1
    return dist[ch][cw]

for sh in range(h):
    for sw in range(w):
        if s[sh][sw] == "#":
            continue
        ans = max(ans,bfs(sh,sw))
        
print(ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -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 (a>b) { a=b; return 1; } return 0; }



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

  string s, t;
  cin >> s >> t;

  cout << (s == t.substr(0, s.length()) ? "Yes" : "No") << '\n';




  
  return 0;
}

Measured memory_bytes: 3656
import java.util.*;

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

		System.out.println((c>a+b && ((c-a-b)*(c-a-b) > 4*a*b)) ? "Yes" : "No");
		sc.close();
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >>N;
  string s;
  cin >>s;
  stable_sort(s.begin(), s.end());
  for(int i=1; i<N; i++){
    string t;
    cin >>t;
    for(int j=0; j<s.size(); j++){
      for(int k=0; k<t.size(); k++){
        if(s[j]==t[k]){
          t[k]=0;
          break;
        }
        if(k==t.size()-1){
          s.erase(s.begin()+j);
          j--;
        }
      }
    }
  }
  cout<<s<<endl;
}

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

int main() {
    int x[6];
    int a;
    erep1(i, 5) cin >> x[i];
    erep1(i, 5) {
        if (x[i] == 0) {
            a = i;
            break;
        }
    }
    cout << a << endl;
}

Measured memory_bytes: 3424
#include <bits/stdc++.h>
#define fast_io()                \
    ios::sync_with_stdio(false); \
    std::cin.tie(0);
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> two;

bool cmp(ll a, ll b) { return a > b; }

int main() {
    fast_io();
    ll n, k;
    cin >> n >> k;
    vector<ll> all(n);
    for (ll i = 0; i < n; i++) {
        cin >> all[i];
    }
    sort(all.begin(), all.end(), cmp);
    ll cnt{};
    for (ll i = k; i < n; i++) {
        cnt += all[i];
    }
    cout << cnt;

    return 0;
}


Measured memory_bytes: 1792
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<atcoder/all>
#include<iostream>
#include<cstdint>
#include<cstddef>
using namespace std;
using namespace atcoder;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using usize = uint_fast64_t;
#define rep(i, n) for (usize i = 0; i < (usize)(n); i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using P = pair<i64,i64>;

int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
i64 n,m;
cin >> n >> m;
dsu d(n);
rep(i,m){
    i64 a,b;
    cin >> a >> b;
    d.merge(a - 1,b - 1);
}
i32 cnt = 0;
for(i32 i = 1; i < n; i++){
    if(!d.same(0,i)){
        cnt++;
        d.merge(0,i);
    }
}
cout << cnt << endl;
}

Measured memory_bytes: 3796
#include <iostream>
using namespace std;
int a=0,b=0; 

int main() {
 while(1){
   cin >> a >> b;
   if(a==0 && b==0){
     break;
   }
   for(int i=0;i<a;i++){
     for(int y=0;y<b;y++){
       cout << "#" ;
     }
     cout << endl;
   }
   cout << endl;
 }
}


Measured memory_bytes: 3084
S = list(input())
S_r = []
Q = int(input())
R = True

for i in range(Q):
  q = list(input().split())
  if int(q[0]) == 1:
    R = not R
  else:
    if int(q[1]) == 1:
      if R:
        S_r.append(q[2])
      else:
        S.append(q[2])
    else:
      if R:
        S.append(q[2])
      else:
        S_r.append(q[2])

if not S_r:
  if R:
    print(''.join(S))
  else:
    print(''.join(S[::-1]))
else:
  if R:
    print(''.join(S_r[::-1]), end="")
    print(''.join(S))
  else:
    print(''.join(S[::-1]), end="")
    print(''.join(S_r))

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


	int main(){
		int n;
		double t,a;
		cin >> n >> t >> a;
		vector<int> v(n);
		rep(i,n) cin >> v[i];
		int id = 0;
		double now = 1e9;
		for (int i = 0;i < n;i++){
			if (abs(a - (t - double(v[i])*(0.006))) < now){
				id = i+1;
				now = abs(a -(t - double(v[i])*(0.006)));
			}
		}
		cout << id << endl;


		
		return 0; 
	}



Measured memory_bytes: 3696
a,b,c=map(int,input().split())
k=int(input())

for i in range(k):
  if ( a >= b):
    b=b*2
    continue
  elif ( b >= c ):
    c=c*2
    continue
  else:
    break
    
if (a<b and b<c):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9048
#include <iostream>
#include <vector>

using namespace std;

int main()
{

    int n;
    cin >> n;
    vector<vector<int>> G(n, vector<int>(n,0));
    int u, k, v;
    for (int i = 0; i < n; ++i){
        cin >> u >> k;
        for (int j = 0; j < k; ++j)
        {
            cin >> v;
            G[u-1][v-1] = 1;
        }
    }

    for (int i = 0; i < n; ++i){
        for (int j = 0; j < n; ++j)
        {
            if(j != 0){
                cout << ' ';
            }
            cout << G[i][j];
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3192
#[allow(unused_imports)]
use {
    itertools::Itertools,
    proconio::{fastout, input, marker::*},
    std::cmp::*,
    std::collections::*,
    std::io::Write,
    std::ops::*,
};

#[allow(unused_macros)]
macro_rules! dbg { ($($e:expr),*) => { #[cfg(debug_assertions)] $({ let (e, mut err) = (stringify!($e), std::io::stderr()); writeln!(err, "{} = {:?}", e, $e).unwrap() })* }; }

#[fastout]
fn main() {
    input! {
        s: Chars,
    }
    print!("{}", s.iter().format(""));
    if s[s.len()-1] == 's' {
        println!("es");
    } else {
        println!("s");
    }
}


Measured memory_bytes: 2208
import java.util.*;

public class Main {
  
  public static int[] d;
  public static HashMap<Integer, ArrayList<Integer>> map;
  public static int[] c;
  public static int p;

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    int[] b = new int[n];
    map = new HashMap<Integer, ArrayList<Integer>>();
    for(int i = 0; i < n - 1; i++) {
      a[i] = sc.nextInt() - 1;
      b[i] = sc.nextInt() - 1;
      ArrayList<Integer> list1 = new ArrayList<Integer>();
      ArrayList<Integer> list2 = new ArrayList<Integer>();
      if(map.containsKey(a[i])) list1 = map.get(a[i]);
      if(map.containsKey(b[i])) list2 = map.get(b[i]);
      list1.add(b[i]);
      list2.add(a[i]);
      map.put(a[i], list1);
      map.put(b[i], list2);
    }
    c = new int[n];
    for(int i = 0; i < n; i++) {
      c[i] = sc.nextInt();
    }
    Arrays.sort(c);
    d = new int[n];
    p = n - 1;
    dfs(0, -1);
    int sum = 0;
    for(int i = 0; i < n - 1; i++) {
      sum += ((int)Math.min(d[a[i]], d[b[i]]));
    }
    System.out.println(sum);
    for(int i = 0; i < n; i++) {
      System.out.print(d[i]);
      if(i < n - 1) System.out.print(" ");
    }
  }

  public static void dfs(int m, int parent) {
    ArrayList<Integer> list = map.get(m);
    d[m] = c[p];
    p--;
    for(int i = 0; i < list.size(); i++) {
      int t = list.get(i);
      if(t != parent) {
        dfs(t, m);
      }
    }
  }
}

Measured memory_bytes: 45268
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
const int INF = 1000000000;

int n;
queue<int> a;
int gcd(int a, int b){
  if(a%b == 0) return b;
  return gcd(b, a%b);
}

int main(){
  cin >> n;
  rep(i, n){
    int u;
    cin >> u;
    a.push(u);
  }
  rep(i, n-1){
    int s, t;
    s = a.front();
    a.pop();
    t = a.front();
    a.pop();
    int c = gcd(s, t);
    a.push(c);
  }
  cout << a.front() <<endl;
}
  

Measured memory_bytes: 640
#include <stdio.h>
char arr[105], a;
int main()
{
	//从第二个循环开始一致(当输入字符串的字符一样，另讨论）
	int i = 1, flag = 0, hehe=0;
	long long n = 0, m = 0, k;
	while ((arr[i] = getchar()) != '\n')
	{
		i++;
	}
	for (int j = 1; j <= i - 2; j++)
	{
		if (arr[j] != arr[j + 1]) hehe = 1;
	}
//	printf("i=%d\n", i);
	scanf("%lld", &k);
	arr[0] = ' ';
	for (int j = 1; j <= i - 1; j++)
	{
//		printf("%c\n", arr[j]);
		if (arr[j - 1] == arr[j]&&flag==0)
		{
//			printf("!!");
			n++;
			flag = 1;
			continue;
		}
		if (arr[j - 1] != arr[j] || (arr[j - 1] == arr[j] && flag == 1))
		{
//			printf("@@");
			flag = 0;
			continue;
		}
	}
	if (hehe == 0)
	{
		if ((i-1) % 2 == 0) printf("%lld\n", n * k);
		else printf("%lld\n", n * ((k + 1) / 2) + (n + 1) * (k - (k + 1) / 2));
		return 0;
	}
//	printf("%d\n", n);
	if (flag == 0) arr[0] = arr[i - 1];
	if (flag == 1) arr[0] = ' ';
	flag = 0;																																	
	for (int j = 1; j <= i - 1; j++)
	{
//		printf("%c\n", arr[j]);
		if (arr[j - 1] == arr[j] && flag == 0)
		{
//			printf("!!!");
			m++;
			flag = 1;
			continue;
		}
		if (arr[j - 1] != arr[j] || (arr[j - 1] == arr[j] && flag == 1))
		{
//			printf("@@@");
			flag = 0;
			continue;
		}
	}
//	printf("%d\n", m);
	long long ans = n + (k - 1) * m;
	printf("%lld\n", ans);
	return 0;
}

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

int use[101]={0},value[101]={0};
long long table[101][100001]={0};

int main()
{
	int sum_use=0,num=0;
	cin>>num>>sum_use;
	for(int i=1;i<=num;i++)
	{
		cin>>use[i]>>value[i];
	}
	for(int i=use[1];i<=sum_use;i++)
	{
		table[1][i]=value[1];
	}
	for(int i=2;i<=num;i++)
	{
		for(int j=1;j<=sum_use;j++)
		{
			if(use[i]<=j)
			{
				table[i][j]=max(table[i-1][j-use[i]]+value[i],
			table[i-1][j]);
			}
			else
			{
				table[i][j]=table[i-1][j];
			}
		}
	}
	cout<<table[num][sum_use];
	return 0;
}

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

int n, m, a[110];

int main()
{
    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for (int k = 2; k <= m; k++)
    {
        for (int j = 0; j < n - 1; j++)
        {
            if (a[j] % k > a[j + 1] % k)
                swap(a[j], a[j + 1]);
        }
    }
    for (int i = 0; i < n; i++)
        cout << a[i] << endl;
}


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

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


if len(l) == 1:
    print(l)
else:
    sum = 0

    for i1 in range(len(l)):
        for i2 in range(i1+1, len(l)):
            sum += l[i1] * l[i2]

    print(sum)

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

int main()
{
  int A, B;
  cin >> A >> B;
  int l = 0, int_arr[B], pointer = 0;

  for (int i = 0; i < B; i++)
  {
    std::cin >> int_arr[i];
  }

  for (int j; j < B; j++)
  {

    l += int_arr[j];
    if (A > l)
    {
      pointer++;
    }
    else
    {
      pointer = 0;
      cout << "Yes";
      break;
    }

    if (pointer != 0 && j == B - 1)
    {
      cout << "No";
    }
  }

  return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(){
  int x,a,b,sum,n;
  
  scanf("%d%d%d",&x,&a,&b);
  
  sum=x-a;
  
  n=sum/b;
  
  sum=sum-b*n;
  
  printf("%d",sum);
  
  return 0;
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	    String str = br.readLine();
	    StringTokenizer st = new StringTokenizer(str, " ");

		int a  = Integer.parseInt(st.nextToken());
		int b  = Integer.parseInt(st.nextToken());
		int c  = Integer.parseInt(st.nextToken());

		if(a <= b && b <= c ) {
			System.out.println(a + " " + b + " " + c);

		}else if(a <= b && c <= b){
			System.out.println(a + " " + c + " " + b);

		}else if(b <= c && c <= a){
			System.out.println(b + " " + c + " " + a);

		}else if(b <= c && a <= c){
			System.out.println(b + " " + a + " " + c);

		}else if(c <= a && a <= b){
			System.out.println(c + " " + a + " " + b);

		}else if(c <= a && b <= a){
			System.out.println(c + " " + b + " " + a);
		}

	}

}

Measured memory_bytes: 24252
import itertools


n = int(input())

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

permutations = list(itertools.permutations(range(1,n+1),n))
permutations_n = len(permutations)

distances = []


for i in range(permutations_n):
    distance = 0
    
    for j in range(n-1):
        distance += (((grid[permutations[i][j]-1][0])-(grid[permutations[i][j+1]-1][0]))**2 + ((grid[permutations[i][j]-1][1])-(grid[permutations[i][j+1]-1][1]))**2)**(1/2)

    distances.append(distance)

print(sum(distances)/permutations_n)


Measured memory_bytes: 9460
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
using namespace std;
#define INT_MAX 2147483647
#define INT_MIN (-2147483647 - 1)
#define INF 100000000
#define _INF -100000000
#define INFLL (long long)1e14
#define _INFLL (long long)-1e14
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> P;

struct node {
	bool done;
	vi to;
	int id, from;
	int pre, low;
};

class lowlink {
	int ord;
public:
	vector<node> nodes;
	vector<P> bridges;
	set<int> arts; //articulation point
	lowlink(vector<node> A) {
		ord = 0;
		nodes = A;
	}
	void dfs(int a, int root) {
		nodes[a].done = 1;
		nodes[a].pre = nodes[a].low = ord;
		ord++;
		int cnt = 0;
		Loop(i, nodes[a].to.size()) {
			int b = nodes[a].to[i];
			if (b == nodes[a].from) continue;
			if (!nodes[b].done) {
				nodes[b].from = a;
				dfs(b, root);
				nodes[a].low = min(nodes[a].low, nodes[b].low);
				if (nodes[a].pre <= nodes[b].low) cnt++;
				if (nodes[a].pre < nodes[b].low) bridges.push_back({ a,b });
			}
			else {
				nodes[a].low = min(nodes[a].low, nodes[b].pre);
			}
		}
		if (cnt > (a == root ? 1 : 0)) arts.insert(a);
		return;
	}
	void find_bridges_and_arts() {
		Loop(i, nodes.size()) {
			if (!nodes[i].done) dfs(i, i);
		}
		Loop(i, bridges.size()) {
			if (bridges[i].first > bridges[i].second) swap(bridges[i].first, bridges[i].second);
		}
		sort(bridges.begin(), bridges.end());
	}
};

int main() {
	int v, e; cin >> v >> e;
	vector<node> nodes(v);
	Loop(i, v) nodes[i] = { 0,{}, i,-1,-1,-1 };
	Loop(i, e) {
		int s, t;
		cin >> s >> t;
		nodes[s].to.push_back(t);
		nodes[t].to.push_back(s);
	}
	lowlink lk(nodes);
	lk.find_bridges_and_arts();
	/*
	auto itr = lk.arts.begin();
	Loop(i, lk.arts.size()) {
		cout << *itr << endl;
		itr++;
	}*/
	Loop(i, lk.bridges.size()) {
		cout << lk.bridges[i].first << " " << lk.bridges[i].second << endl;
	}
	return 0;
}

Measured memory_bytes: 5940
#include <stdio.h>

int main()
{
	int i;
	int mark[2] = { 0 };
	int a, b, n;
	while ((scanf("%d", &n)) != EOF)
	{
		mark[0] = 0; mark[1] = 0;
		if (n == 0) break;
		for (i = 0; i < n; i++)
		{
			if (scanf("%d%d", &a, &b) == EOF) break;
			if (a < b) mark[1] += (a + b);
			else if (a > b) mark[0] += (a + b);
			else {
				mark[1] += a; mark[0] += a;
			}
		}
		printf("%d %d\n", mark[0], mark[1]);
	}
	return 0;
}

Measured memory_bytes: 2592
#include <iostream>
using namespace std;
typedef long long ll;
int main( void )
{
  ios::sync_with_stdio(false);
  int N;
  ll T, t;
  cin >> N >> T;
  ll ret = 0;
  ll st = 0;
  ll ed = 0;
  for( int i=0; i<N; i++ ){
    cin >> t;
    if( ed >= t ){
      ed = t + T;
    } else {
      ret += ed - st;
      st = t;
      ed = t + T;
    }
  }
  ret += ed - st;
  cout << ret << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

int main(){
  ll X,Y;
  cin >> X >> Y;
  int cnt = 0;
  while(X<=Y){
    cnt++;
    X *= 2;
  }
  cout << cnt << endl;
  return 0;
}

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

int main() {
	vector<int> v;
	int x = 0;
	while (cin >> x, x != 0) {
		v.push_back(x);
	}
    // ???????????????????????????????????????????????§???
    //while(cin >> x) {
    //    if(x == 0) {
    //        break;
    //    }
    //    v.push_back(x);
    //}
	for(int i = 0;i < (int)v.size(); i++) {
		cout << "Case" << " " << i + 1 << ": " << v[i] << endl;
	}
}

Measured memory_bytes: 3172
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using ll = long long;
using namespace std;
int main()
{
    int n, m;
    cin >> n >> m;
    vector<bool> b1(n, false), bn(n, false);
    REP(i, m) {
        int a, b;
        cin >> a >> b;
        if (min(a, b) == 1) {
            b1[max(a, b)] = true;
        }
        if (max(a, b) == n) {
            bn[min(a, b)] = true;
        }
    }
    REP(i, n) {
        if (b1[i] && bn[i]) {
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
}


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

const int Maxn = 100005;
bool f[Maxn];
int x;
int main()
{
	f[0] = 1;
	for (int i = 1; i <= 100000; i++)
		for (int j = 100; j <= 105; j++)
			if (i - j >= 0) f[i] |= f[i - j];
	scanf("%d", &x);
	printf("%d", (int)f[x]);
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>

using namespace std;
typedef long long ll;
#define i_7 1000000007
#define i_5 1000000005

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
#define inf 100000000/*10^8*/

/////////////////////////////////

int main(){
    int n;scanf("%d",&n);
    printf("0\n");fflush(stdout);
    int l=0,r=n;
    int lp=2,rp=2;
    char s[15];
    scanf("%s",s);
    if(s[0]=='V')return 0;
    if(s[0]=='M'){
        lp=1;rp=1;
    }
    
    while(1){
        int m=(l+r)/2;
        printf("%d\n",m);
        fflush(stdout);
        scanf("%s",s);
        if(s[0]=='V')return 0;
        int mp;
        if(s[0]=='M')mp=1;
        else mp=2;
        int a=0;
        if(lp==mp)a++;
        if((m-l)%2==0)a++;
        if(a==1){
            r=m;
            rp=mp;
        }else{
            l=m;
            lp=mp;
        }
    }
    return 0;
}


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

using namespace std;

int main(){
	int a,b;
	cin >> a >> b;
	int ans = max(a,b);
	if(ans == a){
		ans+=max(a-1,b);
	}
	else{
		ans+=max(a,b-1);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int isPrime(int*);

int main(){
  int n,*m,i,count=0;
  scanf("%d",&n);
  m = (int *)malloc(n * sizeof(int));
  for(i=0;i<n;i++){
    scanf("%d",&m[i]);
  }
  for(i=0;i<n;i++){
    if(isPrime(&m[i])==1)count++;
  }
  printf("%d\n",count);
  free(m);
  return 0;
}

int isPrime(int *n){
  int i=3;
  if(*n==2){
    return 1;
  }
  if(*n<2 || *n%2==0){
    return 0;
  }
  while(i<=sqrt(*n)){
    if(*n%i==0){
      return 0;
    }
    i=i+2;
  }
  return 1;
}


Measured memory_bytes: 2144
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
//    return *(long long*)a - *(long long*)b;
}
//  qsort(A, b, sizeof(int), compare_int);

long long  factorial(long long n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}

int min(int a, int b) {
    if (a > b)
        return b;
    else
        return a;
}

int distance(int a, int b) {
  return abs(a-b)*abs(a-b);
}

//int ()



int main()
{
  int a ,b, c, d, e, X, Y;
  //long long  a, b, c, d, e, X, Y;
  //  double  c;
  int  A[200003]={};
//  long long  A[100003]={};
//  long long  B[100003]={};
  int  C[100003][11]={};

  int  flg=0;

//  long long  a, b, c, d, X, Y;
  char s[101][101]={};
  char t[101]={};
//  int N, M;
//  int A[1000000001]={};
//  long long  C[101]={};
  int i,j,k;
  long long p,q;
//  int flag=0;
//  int tmp=0;
  char tmp[101]={};
//  long long min=10000000000;
//  long long min=100000001;
  int len=0;
  int l=0;
  int r=1000001;
  int cnt=0;
  int num=0;
  int min_num=0;
  int num2=0;
  long long ans=1;
  int max=0;
  int sum=0;
  int addr=0;
  int ptn=0;
//  bool on_off[100]={};
  
//  char alp[26]={'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'};

  //  a=0;
//  scanf("%lld %lld", &a, &b);
  scanf("%d%d", &a, &b);
//  cnt = strlen(t);
// printf("%d\n",a);
  
  for(i=0;i<a;i++){
    for(j=0;j<b;j++){
      scanf("%d", &C[i][j]);
    }
  }


  for(i=0;i<a-1;i++){
    for(k=i+1;k<a;k++){
      for(j=0;j<b;j++){
        sum=sum+distance(C[i][j],C[k][j]);
//      printf("%d ", sum);
      }
      if(sum==((int)sqrt(sum)*(int)sqrt(sum))) cnt++;
//      printf("sqrt(sum) = %lf \n", sqrt(sum));
      sum=0;
    }
  }
  printf("%d\n", cnt);

  

    
//    printf("%s %d %d\n", s[i],C[i][0],C[i][1]);
   // printf("%d\n", C[i][1]);
/*  for(i=0;i<addr;i++){
//  scanf("%lld%lld", &B[0][i],&B[1][i]);
//    ans=ans+A[i];
    printf("%lld ", A[i]);
  }
*/
//    printf("%d ", cnt);
   

return 0;
}


Measured memory_bytes: 4480
#include <iostream>
using namespace std;
int main()
{
	int a[100010];
	int selisih[10000];
	cin>>a[1]>>a[2]>>a[3];
	int kurang=999999999;

	int sama;
	int ans=0;
	bool sudah;
	while(sama!=3)
	{
		int to=max(max(a[1],a[2]),a[3]);
		sudah=0;
	sama=0;
	for(int x=1;x<=3;x++)
	{
		selisih[x]=to-a[x];
		if(a[x]==to)
		{
			sama++;
		}	
	}
	for(int x=1;x<=3;x++)
	{
		if(sama==1)
		{
			if(a[x]!=to)
			{
				a[x]+=1;
			if(sudah==0)
			{
				sudah=1;
				ans++;
			}
			}
		}
		else if(sama==2)
		{		
			if(a[x]!=to)
			{
				a[x]+=2;
				ans++;
			}
		}
	}
	}
	
	cout<<ans<<endl;
	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

vector<ll> divisor(ll n) {
    vector<ll> ret;
    for(ll i = 1; i * i <= n; i++) {
        if(n % i == 0) {
            ret.push_back(i);
            if(i * i != n)
                ret.push_back(n / i);
        }
    }
    sort(begin(ret), end(ret));
    return (ret);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, ans = 0;
    cin >> n;
    auto a = divisor(n);
    auto b = divisor(n - 1);
    vector<ll> v;
    for(auto i : a) {
        v.push_back(i);
    }
    for(auto i : b) {
        v.push_back(i);
    }
    sort(ALL(v));
    v.erase(unique(ALL(v)), v.end());
    for(auto k : v) {
        if(2 <= k && k <= n) {
            ll now = n;
            while(now >= k) {
                if(now % k == 0) {
                    now /= k;
                } else {
                    break;
                }
            }
            now %= k;
            if(now == 1) {
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
tailrec fun gcd(a: Long, b: Long): Long {
    return if (b == 0L) a else gcd(b, a % b)
}

val memo = hashMapOf<Int, Long>()
fun generatePrime(index: Int): Long {
    if (index == 0) {
        return 2
    }
    if (index == 1) {
        return 3
    }
    memo[index]?.let {
        return it
    }
    val prev = generatePrime(index - 1)
    var next = prev + 2
    var i = 0
    var prime = 0L
    var l = Math.sqrt(next.toDouble()).toLong()
    while (i < index - 1 && l > prime) {
        prime = generatePrime(++i)
        if (next % prime == 0L) {
            next += 2
            i = 1
            l = Math.sqrt(next.toDouble()).toLong()
        }
    }
    memo[index] = next
    return next
}

fun isPrime(candidate: Long): Boolean {
    var i = 0
    var prime = 0L
    val l = Math.sqrt(candidate.toDouble()).toLong()
    while (l > prime) {
        prime = generatePrime(++i)
        if (candidate % prime == 0L) {
            return false
        }
    }
    return true
}

fun main(args: Array<String>) {
    val (a, b) = readLine()?.split(" ")?.map(String::toLong) ?: return
    var l = gcd(a, b)
    var i = 0
    val primes = mutableSetOf<Long>()
    if (l != 1L && isPrime(l)) {
        println("2")
        return
    }
    var p = 0L
    val e = Math.sqrt(l.toDouble()).toLong()
    var end = false
    while ((l != 1L || p < e) && !end) {
        p = generatePrime(i)
        while (l % p == 0L) {
            l /= p
            primes.add(p)
            end = isPrime(l)
        }
        i++
    }
    if (l != 1L) {
        println((primes.size + 2).toString())
    } else {
        println((primes.size + 1).toString())
    }
}



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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using tsii = tuple<string, int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    int n,ans=0;
    cin>>n;
    vector<int> l(n);
    for (int i = 0; i < n; i++)
    {
        cin>>l[i];
    }
    for (int i = 0; i < n-2; i++)
    {
        if((l[i]<=l[i+1] && l[i+1]<=l[i+2]) ||(l[i]>=l[i+1] && l[i+1]>=l[i+2]))
        {
            ans++;
        }
    }
    
    cout<<ans<<endl;
    return 0;
}

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

int main() {
	int N; cin>>N;
	REPl(i,N){
		int Ans = 0;
		for(int x = 1; x*x + 1 + 1 + 2*x + 1 <= i; x++){
			for(int y = 1; (x*x + y*y + 1 + x*y + y + x <= i); y++){
				for(int z = 1; (x*x + y*y + z*z + x*y + y*z + z*x <= i); z++){
					if ((x*x + y*y + z*z + x*y + y*z + z*x) == i) {
						Ans++;
					}
				}
			}
		}
		cout << Ans << '\n';
	}
	return 0;
}


Measured memory_bytes: 3520
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		for(int x=0;x<=100;x++){
			for(int y=0;y<=100;y++){
				var h = new HashSet<long>();
				long ul = (long) 1e18;
				for(int i=0;i<N;i++){
					if(H[i] == 0){
						ul = Math.Min(ul, Math.Abs(X[i] - x) + Math.Abs(Y[i] - y));
					}
				}
				bool chk = true;
				for(int i=0;i<N;i++){
					if(H[i] == 0) continue;
					var height = Math.Abs(X[i] - x) + Math.Abs(Y[i] - y) + H[i];
					if(height == 0){
						chk = false;
						continue;
					}
					if(height > ul){
						chk = false;
						continue;
					}
					h.Add(height);
				}
				if(h.Count != 1 || !chk){
					continue;
				}
				
				var ha = h.ToArray();
				Console.WriteLine("{0} {1} {2}",x, y, ha[0]);
				return;
				
			}
		}
		
		
		
		
	}
	int N;
	int[] X,Y;
	long[] H;
	public Sol(){
		N = ri();
		X = new int[N];
		Y = new int[N];
		H = new long[N];
		for(int i=0;i<N;i++){
			var d = ria();
			X[i] = d[0]; Y[i] = d[1]; H[i] = d[2];
		}
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 15560
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

ll N, M;
struct room {ll fp; ll len; vector<ll> ne;};
vector<room> p;
queue<ll> q;


#define MOD 1000000007LL

int main()
{
  ll A, B;
  ll r;
  ll pos;

  cin >> N >> M;

  p.resize(N+1);
  for (int i=1; i<=M; i++) {
    cin >> A >> B;
    p[A].ne.push_back(B);
    p[B].ne.push_back(A);
  }

  q.push(1);
  while(!q.empty()) {
    r = q.front();
//printf("pop %lld\n", r);
    q.pop();
    pos = p[r].len;
    for (auto it = p[r].ne.begin(); it != p[r].ne.end(); it++) {
      if (p[*it].len == 0 || p[*it].len > pos+1) {
        p[*it].len = pos+1;
        p[*it].fp = r;
        q.push(*it);
      }
    }
  }

/*
  for (int i=2; i<=N; i++) {
    if (p[i].fp == 0) {
      printf("No\n");
      return 0;
    }
  }
  */
  printf("Yes\n");
  for (int i=2; i<=N; i++) {
    cout << p[i].fp <<endl;
  }

  return 0;
}


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

int main() {
  	int x, n; scanf("%d%d", &x, &n);
  	set<int> all;
  	for (int i = x-200; i <= x+200; i++) all.emplace(i);
  	while(n--) {
      	int k; scanf("%d", &k);
      	all.erase(k);
    }
  	
  	int ans = -10000;
  	for (int i : all) {
     	if (abs(i - x) < abs(ans - x)) ans = i;
    }
  	printf("%d\n", ans);
}


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

using fint64 = int_fast64_t;
template<fint64 MOD>
struct ModInt {
	fint64 x;
	ModInt():x(0){}
	ModInt(fint64 x):
		x(x>=0?x%MOD:(MOD-(-x)%MOD)%MOD)
		{}
	// 負号
	ModInt operator -() const{
		return ModInt(-x);
	}
	// 加算
	ModInt &operator +=(const ModInt &rhs){
		x+=rhs.x;
		if(x>=MOD) x-=MOD;
		return (*this);
	}
	ModInt operator +(const ModInt &rhs) const{
		return ModInt(*this)+=rhs;
	}
	// 減算
	ModInt &operator -=(const ModInt &rhs){
		x+=MOD-rhs.x;
		if(x>=MOD) x-=MOD;
		return (*this);
	}
	ModInt operator -(const ModInt &rhs) const{
		return ModInt(*this)-=rhs;
	}
	// 乗算
	ModInt &operator *=(const ModInt &rhs){
		x*=rhs.x;
		if(x>=MOD) x%=MOD;
		return (*this);
	}
	ModInt operator *(const ModInt &rhs) const{
		return ModInt(*this)*=rhs;
	}
	// 除算
	ModInt &operator /=(const ModInt &rhs){
		(*this)*=rhs.inverse();
		return (*this);
	}
	ModInt operator /(const ModInt &rhs) const{
		return ModInt(*this)/=rhs;
	}
	// 等号
	bool operator ==(const ModInt &rhs){
		return x==rhs.x;
	}
	bool operator !=(const ModInt &rhs){
		return x!=rhs.x;
	}
	// 累乗
	ModInt pow(fint64 n) const{
		fint64 tmp=x;
		fint64 ret=1;
		while(n>0){
			if(n&1) ret=ret*tmp%MOD;
			tmp=tmp*tmp%MOD;
			n>>=1ll;
		}
		return ModInt(ret);
	}
	// 逆元
	ModInt inverse() const{
		fint64 a=x,b=MOD,s=1,t=0;
		while(b>0){
			fint64 u=a/b;
			a-=u*b;
			s-=u*t;
			swap(a,b);
			swap(s,t);
		}
		return ModInt(s);
	}
	// 入出力
	friend istream &operator >>(istream &lhs,ModInt<MOD> &rhs){
		fint64 x; lhs>>x;
		rhs=ModInt<MOD>(x);
		return lhs;
	}
	friend ostream &operator <<(ostream &lhs,const ModInt<MOD> &rhs){
		return lhs<<rhs.x;
	}
};

constexpr int MOD = 998244353;
using mint = ModInt<MOD>;
mint dp[200010];
int main() {
	int n, k; cin >> n >> k;
	int l[k], r[k]; for(int i = 0; i < n; ++i) cin >> l[i] >> r[i];
	dp[0] = 1, dp[1] = -1;
	for(int i = 0; i < n; ++i) {
		if(i > 0) {
			dp[i] += dp[i - 1];
		}
		for(int j = 0; j < k; ++j) {
			if(i + l[j] < n) dp[i + l[j]] += dp[i];
			if(i + r[j] + 1 < n) dp[i + r[j] + 1] -= dp[i];
		}
	}
	cout << dp[n - 1] << '\n';
	return 0;
}


Measured memory_bytes: 5180
N = int(input())
H = list(map(int,input().split()))

h = [0 for i in range(N-1)]
ans = 0
for i in range(N-1):
    if H[i] >= H[i+1]:
        h[i] = 1

count = 0
ans = 0
for i in h:
    if i == 1:
        count += 1
        if ans < count:
            ans = count
    else:
        count = 0

print(ans)

Measured memory_bytes: 20364
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    ll n;
    cin >> n;
    vector<int> p(n);
    rep(i, n)cin >> p[i];
    vector<ll> a(n), b(n);
    REP(i, n)a[i-1] = n*i;
    for(int i = n-1; i >= 0; i--)b[i] = (n-i) * n;
    rep(i, n){
        b[p[i]-1] += i+1;
    } 
    rep(i, n)cout << a[i] << " ";
    cout << endl;
    rep(i, n)cout << b[i] << " ";
    cout << endl;
}      

Measured memory_bytes: 1024
#include <cstdio>
#include <vector>
#include <algorithm>
#define N 200005

int n;
int a[N], f[N], ans[N];
std::vector<int> v[N];

void dfs(int x, int fa) {
    int p = std::lower_bound(f, f + ans[fa], a[x]) - f;
    int t = f[p];
    f[p] = a[x];
    ans[x] = std::max(ans[fa], p + 1);
    for (int i : v[x])
        if (i != fa)
            dfs(i, x);
    f[p] = t;
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%d", a + i);
    for (int i = 1, x, y; i < n; ++i) {
        scanf("%d%d", &x, &y);
        v[x].push_back(y);
        v[y].push_back(x);
    }
    dfs(1, 0);
    for (int i = 1; i <= n; ++i) printf("%d\n", ans[i]);
    return 0;
}


Measured memory_bytes: 30036