akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
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;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}

vector<ll> pw2(51,1);vector<ll> pw10(19,1);
ll high_order_bit(ll n){
    ll tmp=1,i=-1;
    while(tmp<=n){
        tmp*=2;
        i++;
    }
    if(n==0) return 0;
    else return i;
}
vector<ll> binary_expansion(ll n){
    vector<ll> B(high_order_bit(n)+1);
    ll tmp=n;
    for(ll i=high_order_bit(n);i>=0;i--){
        B[i]=tmp/pw2[i];
        tmp%=pw2[i];
    }
    return B;
}
vector<ll> divisor(ll x){
    vector<ll> div;
    for(int i=1;i*i<=x;i++){
        if(i*i!=x && x%i==0){
            div.pb(i);
            div.pb(x/i);
        }
        else if(x%i==0) div.pb(i);
    }
    sort(all(div));
    return div;
}
vector<ll> vectorprime(ll x){
    vector<bool> is_prime(x+1);
    vector<ll> prime;
    rep(i,x+1) is_prime[i]=true;
    is_prime[0]=is_prime[1]=false;
    for(int i=2;i<=x;i++){
        if(is_prime[i]){
            prime.pb(i);
        }
        for(int j=i*2;j<=x;j+=i) is_prime[j]=false;
    }
    return prime;
}

int main(){
    {rep1(i,50) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    
    ll N; cin>>N;
    ll ans=0;
    rep1(i,N){
        ll size=N/i;
        ans+=(((1+size)*size)/2)*i;
    }
    cout<<ans;
}


Measured memory_bytes: 3616
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

N, M = map(int, input().split())
uftree = UnionFind(N)
for i in range(M):
    X, Y, Z = map(int, input().split())
    uftree.union(X, Y)
dict = {}
for i in range(N):
    if uftree.find(i+1) not in dict:
        dict[uftree.find(i+1)] = 0

print(len(dict))
    

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

int main(void){
  int n,lank;
  bool A[4][14];
  char s;

  for(int i=0;i<4;i++)
    for(int j=1;j<=13;j++)
           A[i][j]=0;

  cin>>n;
  for(int i=0;i<n;i++){
  cin>>s>>lank;
  if(s=='S')A[0][lank]=1;
  if(s=='H')A[1][lank]=1;
  if(s=='C')A[2][lank]=1;
  if(s=='D')A[3][lank]=1;}

  for(int i=0;i<4;i++){
    for(int j=1;j<=13;j++){
      if(A[i][j])continue;
      if(i==0)s='S';
      if(i==1)s='H';
      if(i==2)s='C';
      if(i==3)s='D';
      cout<<s<<" "<<j<<endl;
    }
  }
  
}


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

bool judge(int *a, int n, int *p) {
    if(n == -1) {
        return true;
    }

    int new_a[n];
    int drop = 334;
    bool check = false;

    for(int j = n;0 <= j;j--) {
        if(a[j] == j + 1) {
            drop = j;
            check = true;
            break;
        }
    }
    if(!check) {
        return false;
    }

    int old_index = 0;
    int new_index = 0;

    p[n] = drop;

    bool unko = false;

    for(;new_index < n;old_index++) {
        if(unko || new_index != drop) {
            new_a[new_index] = a[old_index];
            new_index++;
        }else{
            unko = true;
        }
    }
    return judge(new_a, n - 1, p);
}

int main() {
    int N;
    scanf("%d", &N);
    int a[N];
    int p[N];
    p[0] = 0;
    for(int i = 0;i < N;i++) {
        scanf("%d", &a[i]);
    }
    bool hanbetu = judge(a, N - 1, p);
    if(hanbetu) {
        for(int i = 0;i < N;i++) {
            printf("%d\n", p[i] + 1);
        }
    }else{
        printf("-1\n");
    }
    return 0;
}


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

int main() {
  ll N,Max;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  Max = 0;
  rep(i, N) {
    for(ll j = i;j < N;j++) {
      Max = max(Max, abs(A[i] - A[j]));
    }
  }
  cout << Max << endl;
  return 0;
}


Measured memory_bytes: 3608
#include "bits/stdc++.h"
using namespace std;
/////////////////// TYPES & MACROS ///////////////////////////////
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define vv vector
#define exist(s,e) (s.find(e)!=s.end())
#define SZ(x) ((int)(x).size())
#define int ll
#define el '\n'
template<class T> bool rmn(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool rmx(T &a, T b) { return a < b ? (a = b, true) : false; }
typedef long long ll; typedef long double ld; typedef double dd; typedef pair<int, int> pii;
const ll INFLL=0x7f7f7f7f7f7f7f7f, MOD=1e9+7; const int INF=0x7f7f7f7f;

//////////////////// DEBUG /////////////////////////////////////////
#define D(x) cerr<<#x<<" is:\t"<<x<<'\n';
#define DD(x,y) cerr<<'('<<#x<<','<<#y<<") are:\t"<<x<<' '<<y<<'\n';
#define DDD(x,y,z) cerr<<'('<<#x<<','<<#y<<','<<#z<<") are:\t"<<x<<' '<<y<<' '<<z<<'\n';

/////////////////// VARIABLES & FUNCTIONS//////////////////////////
vv<vv<int>> adj; vv<int> vis, color; 
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1},dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};
inline ll mexp(ll x,ll n,ll m=MOD){ll res=1;x%=m;while(n){if(n&1)res=(res*x)%m;n>>=1;x=(x*x)%m;}return res;}
inline ll gcd(ll a, ll b){if(a<0) a=-a; if(b<0) b=-b; while (a>0 && b>0){if(a>b)a%=b;else b%=a;}return a+b;}

struct DSU {
	vector<int> e;
	DSU(int n) : e(n, -1) {}
	bool same_set(int a, int b) { return find(a) == find(b); }
	int size(int x) { return -e[find(x)]; }
	int find(int x) { return e[x] < 0 ? x : e[x] = find(e[x]); }
	bool merge(int a, int b) {
		a = find(a), b = find(b);
		if (a == b) return false;
		// make a as parent of b
		if (e[a] > e[b]) swap(a, b); // size of dsu(a) is -e[a] 
		e[a] += e[b]; e[b] = a;
		return true;
	}
};
///////////////////// MAIN STARTS //////////////////////////////////
int32_t main(void){
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
cout<<fixed;cerr<<fixed; cout<<setprecision(10); cerr<<setprecision(3);
mt19937 genr(chrono::high_resolution_clock::now().time_since_epoch().count());

int n,m; cin>>n>>m;
vv<int> v(n); for(auto& i: v) cin>>i;
DSU d(n);
while(m--){
	int x,y; cin>>x>>y;
	d.merge(x-1,y-1);	
}
int ans=0;
for(int i=0;i<n;++i){
	ans+=d.same_set(i,v[i]-1);
}
cout<<ans<<el;

return 0;
}


Measured memory_bytes: 1792
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
using ll = long long;
using P = pair<ll,ll>;

int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
string s;
cin >> s;
cout << s.substr(0,3) << endl;
}

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

char s[200010];

int main(){
	int n, a, b, c, d;
	cin >> n >> a >> b >> c >> d;
	scanf("%s", s + 1);
	if (d > c){
		for (int i = min(a, b); i < max(c, d); i++){
			if (s[i] == '#' && s[i + 1] == '#'){
				printf("No\n");
				return 0;
			}
		}
		printf("Yes\n");
		return 0;
	} else {
		for (int i = a; i < c; i++){
			if (s[i] == '#' && s[i + 1] == '#'){
				printf("No\n");
				return 0;
			}
		}
		for (int i = b - 1; i <= d - 1; i++){
			if (s[i] == '.' && s[i + 1] == '.' && s[i + 2] == '.'){
				printf("Yes\n");
				return 0;
			}
		}
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 384
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools
import queue
from collections import deque
from fractions import Fraction



def main():
    num = int(input())
    data = [list(map(int, input().split())) for i in range(num - 1)]

    node_data = defaultdict(set)
    for i in range(num - 1):
        a, b = data[i]
        node_data[a].add(b)
        node_data[b].add(a)

    ans_num = 0
    for i in range(1, num + 1):
        ans_num = max(ans_num, len(node_data[i]))

    edge_data = defaultdict(int)
    ans_count = 0

    for i in range(1, num + 1):
        now_list = list(node_data[i])
        now_list.sort()
        count = bisect.bisect_left(now_list, i) + 1

        use_set = set()
        for ele in now_list[:count - 1]:
            use_set.add(edge_data[(i, ele)])
        now_indx = 1

        for ele in now_list[count - 1:]:
            while now_indx in use_set:
                now_indx += 1

            edge_data[(i, ele)] = now_indx
            edge_data[(ele, i)] = now_indx
            use_set.add(now_indx)

        ans_count = max(ans_count, now_indx)

    print(ans_count)
    for i in range(num - 1):
        a, b = data[i]
        ans = edge_data[(a, b)]
        print(ans)








if __name__ == '__main__':
    main()



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

using namespace std;

template <class T>
using lim = numeric_limits<T>;

typedef long long ll;
typedef long double ld;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	ll a, b;
	cin >> a >> b;
	
	ll ans = 0;
	if (b-a < 4){
		for (ll i = a; i <= b; i++){
			ans ^= i;
		}
	}
	else {
		ll myB = b;
		ll right = (b-3)%4;
		
		for (ll i = 0; i < right; i++){
			ans ^= myB--;
		}
		
		ll myA = a;
		ll left = (a-3)%4;
		if (left == 0) left = 4;
		left = 5 - left;
		for (ll i = 0; i < left; i++){
			ans ^= myA++;
		}
	}
	
	
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define F first 
#define S second 
#define pb push_back 
#define mp make_pair 
#define f(i,n) for(int i=0;i<n;i++) 
#define fr(i,a,b) for(int i=a;i<b;i++) 
using namespace std; 

void test(){
	ll n;
	cin>>n;
	string a[n];
	f(i,n)cin>>a[i];
	map<string,int> m1;
	f(i,n)m1[a[i]]++;
	int c = 0;
	for(auto i=m1.begin();i!=m1.end();i++){
		c = max(c,(*i).S);
	}
	vector<string> s;
	for(auto i=m1.begin();i!=m1.end();i++){
		if(c==(*i).S)
			s.pb((*i).F);
	}
	sort(s.begin(),s.end());
	f(i,s.size())cout<<s[i]<<"\n";
	cout<<"\n";	
}

int main(){
	int t=1;
//	cin>>t;
	while(t-->0){
		test();
	}
}

Measured memory_bytes: 28404
#include<bits/stdc++.h>
using namespace std;
const double pi=acos(-1.0);
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};
#define ll long long
#define inf int(1e9+7)
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define l(s) s.size()
int n,m,k[15],q[15],a[15][15];
int ans;
int main()
{
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		cin>>k[i];
		for(int j=0;j<k[i];j++)
			cin>>a[i][j],a[i][j]--;
	}
	for(int i=0;i<m;i++)
		cin>>q[i];
	for(int i=0;i<(1<<n);i++)
	{
		int cnt[15];
		memset(cnt,0,sizeof(cnt));
		for(int j=0;j<m;j++)
			for(int l=0;l<k[j];l++)
				if(i>>a[j][l]&1)
					cnt[j]++;
		bool flag=1;
		for(int j=0;j<m;j++)
			flag&=(cnt[j]%2==q[j]);
		ans+=flag;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807
#define MOD 1000000007



void solve()
{
  int N;
  cin>>N;

  int count = 0;
  for (int i = 0; i <= N; i++)
  {
    if(i%2 == 1)
    {
      int count_f = 0;
      for (int j = 1; j <= i; j++)
      {
        if(i%j == 0)
        {
          count_f++;
        }
      }
      if(count_f == 8)
      count++;
      
    }
  }
  
  cout<<count;
}

int32_t main(int32_t argc, const char *argv[])
{
 
  solve();
 
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define all(in) in.begin(), in.end()
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int n; cin >> n;
    string s; cin >> s;
    int ans = 0; char lst = -1;
    for(auto c : s){
        if(lst == c) continue;
        lst = c; ++ans;
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
string s;
long n;
int main(){
    cin>>s;
    n=s.length();
    s=" "+s;
    for(int i=1;i<=n;i++){
    if(s[i]==s[i+2]) {cout<<i<<" "<<i+2;return 0;}
    if(s[i]==s[i+1]) {cout<<i<<" "<<i+1;return 0;}

}
    cout<<-1<<" "<<-1;
    return 0;}


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

using namespace std;
using ll = long long;

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    while(true) {
        C -= B;
        if(C <= 0) break;
        A -= D;
        if(A <= 0) break;
    }

    cout << (A <= 0 ? "No" : "Yes") << endl;
}

Measured memory_bytes: 3632
#include<stdio.h>

int main(){

  int i,j,n,s,count=0,mini,a[101];


  //load N
  scanf("%d",&n);
  //load number
  for(i=1;i<=n;i++){
    scanf("%d",&a[i]);
  }
  //Algorithm
  for(i=1;i<=n;i++){
    mini=i;
    for(j=i;j<=n;j++){
      if(a[j]<a[mini]){
	mini=j;
      }
    }
      //swap
      s=a[i];
      a[i]=a[mini];
      a[mini]=s;
      //count
      if(a[i]!=a[mini]) count++;
  }

  //print
  for(i=1;i<=n;i++){
    printf("%d",a[i]);
    if(i!=n){
      printf(" ");
    }
  }

  printf("\n");
  printf("%d\n",count);

  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cassert>
#define InfL 1000000000
#define InfLL 1000000000000000000LL
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=(n-1);(i)>=(0);(i)--)
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

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

	int ans = 0;
	set<string> Sset;
	rep(i, N) {
		string S;
		cin >> S;
		if (Sset.find(S) == Sset.end()) {
			Sset.insert(S);
			ans++;
		}
	}


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

Measured memory_bytes: 19256
#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};

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

using P = pair<int, int>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<P> ab(m);
    for(int i = 0; i < m; i++) {
        cin >> ab[i].first >> ab[i].second;
    }
    sort(ALL(ab),
         [](const auto &a, const auto &b) { return a.second < b.second; });
    int ans = 0;
    int last = 0;
    for(int i = 0; i < m; i++) {
        if(ab[i].first >= last) {
            last = ab[i].second;
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#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 IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

int N;
vector<int> ans(20, INF);
vector<int> X(20), Y(20), P(20);

void dfs(int depth, vector<int> &tate, vector<int> &yoko){
  if(depth == N){
    int ret = 0;
    int cnt = tate.size()+yoko.size();

    REP(i, N){
      int dist = min(abs(X[i]), abs(Y[i]));

      REP(j, tate.size()){
        chmin(dist, abs(X[i]-tate[j]));
      }
      REP(j, yoko.size()){
        chmin(dist, abs(Y[i]-yoko[j]));
      }
      ret += dist*P[i];
    }

    chmin(ans[cnt], ret);
    return;
  }


  REP(i, 3){
    if(i == 1) tate.emplace_back(X[depth]);
    if(i == 2) yoko.emplace_back(Y[depth]);

    dfs(depth+1, tate, yoko);
    
    if(i == 1) tate.pop_back();
    if(i == 2) yoko.pop_back();
  }
}

signed main() {
  cin >> N;
  REP(i, N) cin >> X[i] >> Y[i] >> P[i];


  vector<int> tate, yoko;
  dfs(0, tate, yoko);

  REP(i, N+1){
    cout << ans[i] << "\n";
  }

  return 0;
}

Measured memory_bytes: 3608
#include <stdio.h>
#define N 10000
#define Q 500

int main()
{
  int S[N],T[Q],C=0;
  int n,q,i,j,key;

  scanf("%d",&n);
  for(i=0; i<n; i++)
    scanf("%d",&S[i]);
  scanf("%d",&q);
  for(i=0; i<q; i++)
    scanf("%d",&T[i]);

  for(i=0; i<q; i++){
    j=0;
    S[n] = T[i];
    while(S[j] != T[i]){
      j++;
    }
    if(j < n) C++;  
  }
  printf("%d\n",C);
  return 0;
}

Measured memory_bytes: 636
#include <iostream>
#include <vector>
using namespace std;
int min(int& a, int& b){return a<b?a:b;}
void pre_calc(int target, vector<int>& V, vector<int>& dp){
    
    dp[0]=0;
    dp[1]=abs(V[1]-V[0]);

    for(int i=2;i<target;i++){
        dp[i]=min(dp[i-1]+abs(V[i]-V[i-1]), dp[i-2]+abs(V[i]-V[i-2]));
    }
}
int main(){
    int N;
    vector<int> V;
    vector<int> dp;

    
    cin>>N;
    V.assign(N,0);
    dp.assign(N,0);
    for(int i=0;i<N;i++)cin>>V[i];
    pre_calc(N, V, dp);

    cout<<dp[N-1]<<endl;


    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define PI acos(-1.0)
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//next_permutation(ALL(p));
//typedef priority_queue<int> pque;//これは大きい順
//typedef priority_queue<int, vector<int>, greater<int>> pque;//これは小さい順
//factorizeは、素因数分解用の関数

int main(){
	vector<int> a(5);
  rep(i,5) cin >> a[i];
  rep(i,5){
  if(a[i] == 0){
    cout << i+1 << endl;
  }}

  return 0;
}


Measured memory_bytes: 3628
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで
// -fsanitize=undefinedでオーバーフロー検出
#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};


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

    ll a,b,c,d,m,n,maxi=0,f=0,g=0,mini=INF,sum=0;
    ll k;
    string str,stra;
    
    cin>>str;
  rep(i,str.length()){
  if(str[i]=='x') sum++;
    //else cout<<str[a];
  }
  if(sum>=8) NO;
  else YES;
  ln;
    return 0;
}


Measured memory_bytes: 3592
#include <iostream>

using namespace std;

typedef long long ll;

ll dp[105][100005];
ll mod = 1e9 + 7;

int main(int argc, char *argv[])
{
	int N, K, a[100005];

	cin >> N >> K;

	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	for (int i = 0; i <= N; i++) {
		dp[i][0] = 1;
	}
	for (int i = 1; i <= N; i++) {
		for (int j =1; j <= K; j++) {
			dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
			if (j - a[i - 1] - 1 >= 0) {
				dp[i][j] = (dp[i][j] + mod - dp[i - 1][j - a[i - 1] - 1]) % mod;
			}
		}
	}

	cout << dp[N][K] << endl;

	return 0;
}

Measured memory_bytes: 79360
# -*- coding: utf-8 -*-

import sys
from itertools import accumulate

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

N, K = MAP()

ans = min(N % K, K - N % K)
print(ans)


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

int main() {
  long long N; cin >> N;
  for (long long h = 1; h <= 3500; h++) {
    for (long long n = 1; n <= 3500; n++) {
      long long a = N * h * n;
      long long b = 4 * h * n - N * n - N * h;
      if (b > 0 && a % b == 0) {
        long long w = a / b;
        cout << h << " " << n << " " << w << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 256
import sys
import itertools

input = sys.stdin.readline


def main():
    n = int(input())
    d_list = map(int, input().split())
    hoge = 0
    for a, b in itertools.combinations(d_list, 2):
        hoge += a * b
    print(hoge)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ldb = long double;
using pa = pair < ll, ll >;
using vec = vector < ll >;
#define pb push_back
#define F  first
#define S  second
#define int ll
#define f(i,x,n) for(ll i=x;i<n;i++) 
#define all(c) c.begin(),c.end()
#define edl "\n"
#define ceils(s,n) (s+n-1)/n
#define str string
#define add insert
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
const int MOD = 1e9 + 7, N = 5e5 + 10;
const ll LINF = LLONG_MAX;
int a1,a2,a3,ans,sum;
str s,s1,s2;
int32_t main() {
    fast();
    cin >> s1 >> s2;
    cout<<s2+s1;
    return 0;
}
 

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;

import static java.lang.StrictMath.abs;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] s = new int[2*n];
        int[] ss = new int[n];
        for(int i = 0; i< 2*n ; i++){
            s[i] = sc.nextInt();
        }
        Arrays.sort(s);
        for(int k =0; k< n;k++){
            ss[k] = Math.min(s[2*k], s[2*k +1]);
        }
        int sum=0;
        for(int j=0; j < n; j++){
            sum += ss[j];
        }
        System.out.println(sum);






    }
}


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

int main(void){
  while(1){
    int stone[50];
    for(int k = 0 ; k < 50 ; k++){stone[k] = 0;}

    int bowl;
    int n, p;  // n：候補者人数，p：小石の総数
    cin >> n;
    cin >> p;

    if(n == 0 && p == 0){return 0;}

    bowl = p;

    bool flg = true;
    int ans;

    for(int i = 0 ; flg ; i = (i+1) % n){

      if(bowl == 0){
        bowl = bowl + stone[i];
        stone[i] = 0;
      }else{
        stone[i]++;
        bowl--;
        if(bowl == 0 && stone[i] == p){ans = i; flg = false;}
      }
    }

    for(int i = 0 ; i < 1000000 ; i++){
        for(int j = 0 ; j < 1000000 ; j++){
            for(int k = 0 ; k < 1000000 ; k++){
                int K = i + j + k;
            }
        }    
    }


    cout << ans << endl;
  }
}



Measured memory_bytes: 3004
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <functional>
#include <string>
#include <array>
#include <vector>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#include <complex>
#include <bitset>
#define full(c) c.begin(), c.end()
#define vector2d(name,type,h,w,init) vector<vector<type>> name(h,vector<type>(w,init)) 
const int PRIME = 1000000007;
const int INT_INF = 2147483647;
const long long int LL_INF = 9223372036854775807;
const double PI = acos(-1);
const double EPS = 0.000000001;
typedef unsigned long long int ull;
typedef long long int ll;
using namespace std;

int main(){
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);
	string move;
	int i, sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	for (i = sx; i < tx; i++) move += 'R';
	for (i = sy; i < ty; i++) move += 'U';
	for (i = sx; i < tx; i++) move += 'L';
	for (i = sy; i < ty; i++) move += 'D';
	move += 'D';
	for (i = sx; i < tx; i++) move += 'R';
	move += 'R';
	for (i = sy; i < ty; i++) move += 'U';
	move += 'U';
	move += 'L';
	move += 'U';
	for (i = sx; i < tx; i++) move += 'L';
	move += 'L';
	for (i = sy; i < ty; i++) move += 'D';
	move += 'D';
	move += 'R';
	cout << move << endl;
	return 0;
}

Measured memory_bytes: 256
import math
from functools import reduce

def lcm_base(x,y):
    return (x*y)//math.gcd(x,y)

def lcm_list(numbers):
    return reduce(lcm_base,numbers,1)

n=int(input())
nums=[int(input()) for i in range(n)]

print(lcm_list(nums))


Measured memory_bytes: 9572
using namespace std;
#include<bits/stdc++.h>
// #include<iostream>
// #include<string>
// #include<vector>
// #include<set>
// #include<map>
// #include<algorithm>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0)
#define END return EXIT_SUCCESS
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define IN4(P1,P2,P3,P4) cin>>(P1)>>(P2)>>(P3)>>(P4)
#define INS(I,N,V) REP((I),(N))cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N))cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N))cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUT4(P1,P2,P3,P4) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<" "<<(P4)<<endl
#define OUTS(I,N,V) REP((I),(N))cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

int N,M,C,i,j,B[20],A[20][20],sum,cnt;
inline void solve(void){
  IN3(N,M,C);
  INS(i,M,B);
  REP(i,N){
    sum=C;
    REP(j,M){
      IN(A[i][j]);
      sum+=A[i][j]*B[j];
    }
    if(sum>0)cnt++;
  }
  OUT(cnt);
}

int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 256
#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;
}
/*qsort(array, array_size, sizeof(int), compare_int)*/

void sort_char(char *C, int string_long)
{
	int i;
	int num[string_long];
	for (i = 0; i < string_long; i++) {
		num[i] = (int)C[i];
	}
	qsort(num, string_long, sizeof(int), compare_int);
	for (i  =0; i < string_long; i++) {
		C[i] = (char)num[i];
	}
}
/*sort_char(array, strlen(array))*/

void change_int(int *a, int *b)
{
	int c = *a;
	*a = *b;
	*b = c;
}


void change_char(char *s, char *t)
{
	char u = *s;
	*s = *t;
	*t = u;
}

int diff_abso_value(int a, int b)
{
	if (a >= b)
		return a - b;
	else
		return b - a;
}

int main()
{
	int i;
	int n;
	char s;

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf("%c", &s);

		if (s == 'Y') {
			printf("Four\n");
			return 0;
		}

	}

	printf("Three\n");

	return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

class Program {
  static void Main() {
    int n = int.Parse(Console.ReadLine());
    var s = Enumerable.Repeat(0, n).Select(x => Console.ReadLine()).ToArray();
    int m = int.Parse(Console.ReadLine());
    var t = Enumerable.Repeat(0, m).Select(x => Console.ReadLine()).ToArray();
    int ans = 0;
    foreach (var str in s) {
      ans = Math.Max(ans, s.Count(x => x == str) - t.Count(x => x == str));
    }
    Console.WriteLine(ans);
  }
}

Measured memory_bytes: 13396
import java.io.*;
import java.util.*;

public class Main {
	
	int W, H, N;
	int[][] field = new int[16][16];

	int[] dx = {0, 1, 0, -1, 0};
	int[] dy = {1, 0, -1, 0, 0};

	short[][][] bfs = new short[16*16][16*16][16*16];
	int[][] graph = new int[16*16][6];
	Queue<int[]> Q = new ArrayDeque<>();
	public void solve() {
		Scanner sc = new Scanner(System.in);
		while(true){
			W = sc.nextInt();
			H = sc.nextInt();
			N = sc.nextInt();
			if(W == 0) break;
			int[] begin = new int[3];
			int[] end = new int[3];
			int idx = 1;
			sc.nextLine();
			for(int i = 0; i < H; i++){
				String str = sc.nextLine();
				for(int j = 0; j < W; j++){
					char c = str.charAt(j);
					if(c == '#') field[i][j] = 0;
					else{
						field[i][j] = idx++;
						if('A' <= c && c <= 'C') end[c - 'A'] = field[i][j];
						else if('a' <= c && c <= 'c') begin[c - 'a'] = field[i][j];
					}
				}
			}
			graph[0][0] = 0;
			graph[0][1] = -1;
			for(int i = 0; i < H; i++){
				for(int j = 0; j < W; j++){
					if(field[i][j] > 0){
						int cnt = 0;
						for(int k = 0; k < 5; k++){
							if(field[i + dy[k]][j + dx[k]] > 0){
								graph[field[i][j]][cnt++] = field[i + dy[k]][j + dx[k]];
							}
						}
						graph[field[i][j]][cnt] = -1;
					}
				}
			}
			
			for(int i = 0; i < idx; i++){
				for(int j = 0; j < idx; j++){
					for(int k = 0; k < idx; k++){
						bfs[i][j][k] = -1;
					}
				}
			}
			
			Q.clear();
			Q.add(begin);
			bfs[begin[0]][begin[1]][begin[2]] = 0;
			LOOP:
			while(!Q.isEmpty()){
				int[] t = Q.poll();
				for(int i = 0; graph[t[0]][i] != -1; i++){
					for(int j = 0; graph[t[1]][j] != -1; j++){
						for(int k = 0; graph[t[2]][k] != -1; k++){
							int n0 = graph[t[0]][i];
							int n1 = graph[t[1]][j];
							int n2 = graph[t[2]][k];
							if(
								bfs[n0][n1][n2] != -1 ||
								N >= 2 && t[0] == n1 && t[1] == n0 ||
								N >= 3 && t[0] == n2 && t[2] == n0 ||
								N >= 3 && t[1] == n2 && t[2] == n1 ||
								N >= 2 && n0 == n1 ||
								N >= 3 && n0 == n2 ||
								N >= 3 && n1 == n2
							){
								continue;
							}
							bfs[n0][n1][n2] = (short)(bfs[t[0]][t[1]][t[2]] + 1);
							if(n0 == end[0] && n1 == end[1] && n2 == end[2]) break LOOP;
							Q.add(new int[]{n0,n1,n2});
						}
					}
				}
			}
			System.out.println(bfs[end[0]][end[1]][end[2]]);
			
		}
	}
	private static PrintWriter out;

	public static void main(String[] args) {
		new Main().solve();
	}
}

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

using namespace std;

int main()
{	
	int n, k;
	cin >> n >> k;
	vector<long long> cost(n + 101, 0);
	vector<long long> v(n + 101, 0);
	
	for (int i = n; i <= n + 100; i++) {

		v[i] = 2e9;
		cost[i] = 2e9;
	}

	for (int i = 0; i < n; i++) {
		int h;
		cin >> h;
		v[i] = h;
	}

	for (int i = n - 2; i >= 0; i--) {

		long long c = cost[i + 1] + abs(v[i] - v[i + 1]);

		for (int j = 2; j <= k; j++) {

			c = min(c, cost[i + j] + abs(v[i] - v[i + j]) );
		}

		cost[i] = c;
	}

	cout << cost[0] << endl;

	return 0;
}


Measured memory_bytes: 1792
package main

import (
	"bufio"
	"fmt"
	"os"
)

func solution(a, b, c, d int) int {
	out := a * c
	max := func(x, y int) int {
		if x > y {
			return x
		}
		return y
	}
	out = max(out, b*d)
	out = max(out, b*c)
	out = max(out, a*d)
	return out
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var a, b, c, d int
	fmt.Fscan(r, &a, &b, &c, &d)
	fmt.Println(solution(a, b, c, d))
}


Measured memory_bytes: 1840
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define lcm(a,b) (a/__gcd(a,b)*b)

main() {
    int a, b, c, d, l;
    cin >> a >> b >> c >> d;
    a--,l = lcm(c,d);
    cout << b - b/c - b/d + b/l - a + a/c + a/d - a/l;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define SZ(X) ((int)(X).size())
#define endl "\n";
typedef long long ll;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	
   ll n,ans=0;
   cin>>n;
   for (ll i = 100; i <n; i+=i/100)
   {
   	
   	 ans++;
   }
   cout<<ans;
   return 0;
}


Measured memory_bytes: 3632
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;

public static class P
{
    public static void Main()
    {
        string s = Console.ReadLine();
        for (int i = s.Length - 1; i >= 0; i--)
        {
            var a = s.Substring(0, i);
            if (a.Substring(a.Length / 2) == a.Substring(0, a.Length / 2))
            {
                Console.WriteLine(i);
                return;
            }
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

struct SuffixArray{
    int N;
    vector<int> sa,rank;
    vector<int> ary;//int
    string str;//string

    SuffixArray(){}

    void build(const vector<int> &S){
        int k;//重要

        N=S.size();
        sa.resize(N+1,0);
        rank.resize(N+1,0);
        for(int i=0;i<=N;i++){
            sa[i]=i;
            rank[i]=(i<N ? S[i] : -1);
        }

        auto cmp = [&](int i,int j){
            if(rank[i]!=rank[j]) return rank[i]<rank[j];
            int ri=(i+k<=N ? rank[i+k] : -1);
            int rj=(j+k<=N ? rank[j+k] : -1);
            return ri<rj;
        };

        vector<int> tmp(N+1,0);
        for(k=1;k<=N;k*=2){
            sort(sa.begin(),sa.end(),cmp);

            tmp[sa[0]]=0;
            for(int i=1;i<=N;i++){
                tmp[sa[i]]=tmp[sa[i-1]]+(cmp(sa[i-1],sa[i]) ? 1 : 0);
            }
            rank=tmp;
        }

        //空文字を削除
        sa.erase(sa.begin());
        rank.pop_back();
        for(int i=0;i<rank.size();++i) --rank[i];
    }

    void initialize(const vector<int> &A){
        ary=A;
        build(A);
    }

    void initialize(const string &S){
        str=S;
        vector<int> A;
        for(int i=0;i<S.size();++i) A.push_back(S[i]);
        ary=A;
        build(A);
    }

    vector<int> lcp_array(const vector<int> &S,const vector<int> &sa){
        int N=S.size();
        vector<int> trans(N,0);
        for(int i=0;i<N;++i) trans[sa[i]]=i;

        vector<int> lcp(N-1,0);
        int len=0;
        for(int i=0;i<N;++i){
            len=max(0,len-1);
            int now=trans[i];
            if(now==N-1){
                len=0;
                continue;
            }

            int tar=sa[now+1];
            while(i+len<N&&tar+len<N){
                if(S[i+len]!=S[tar+len]) break;
                ++len;
            }
            lcp[now]=len;
        }
        return lcp;
    }

    int operator[](int i)const{
        return sa[i];
    }
};

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

  string S;
  cin>>S;
  ll N=S.size();

  SuffixArray SA;
  SA.initialize(S);
  vector<int> sa=SA.sa;

  ll ans=N*(N+1)/2;
  vector<int> lcp=SA.lcp_array(SA.ary,sa);
  for(auto x:lcp){
      ans-=x;
  }
  cout<<ans<<"\n";

  return 0;
}


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

int arr[100010];

int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	int ord=1,cnt=1;
	for(int i=1;i<n;i++){
		if(arr[i]>arr[i-1]){
			if(ord==0 || ord==1){
				if(arr[i]>arr[i-1])
					ord=0;
			}
			else{
				cnt++;
				ord=1;
			}
		}
		else if(arr[i]<arr[i-1]){
			if(ord==1 || ord==2){
				if(arr[i]<arr[i-1])
					ord=2;
			}
			else{
				cnt++;
				ord=1;
			}
		}
		else{
			;
		}
	}
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 640
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;

public class Main {

	static PrintWriter out;
	static InputReader ir;
	static int[] par, dep, ch;

	static void solve() {
		out.println(-ir.nextInt()+ir.nextInt()*2);
	}

	public static void main(String[] args) throws Exception {
		ir = new InputReader(System.in);
		out = new PrintWriter(System.out);
		solve();
		out.flush();
	}

	static class InputReader {

		private InputStream in;
		private byte[] buffer = new byte[1024];
		private int curbuf;
		private int lenbuf;

		public InputReader(InputStream in) {
			this.in = in;
			this.curbuf = this.lenbuf = 0;
		}

		public boolean hasNextByte() {
			if (curbuf >= lenbuf) {
				curbuf = 0;
				try {
					lenbuf = in.read(buffer);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return false;
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[curbuf++];
			else
				return -1;
		}

		private boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		private void skip() {
			while (hasNextByte() && isSpaceChar(buffer[curbuf]))
				curbuf++;
		}

		public boolean hasNext() {
			skip();
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (!isSpaceChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public int nextInt() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public char[][] nextCharMap(int n, int m) {
			char[][] map = new char[n][m];
			for (int i = 0; i < n; i++)
				map[i] = next().toCharArray();
			return map;
		}
	}
}


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

int main() {
	int n; cin >> n;
	string s; cin >> s;
	
	int ans = 0;
	int x = 0;
	for(int i=0; i<n; i++) {
		if (s[i] == 'I') {
			x++;
		}
		if (s[i] == 'D') {
			x--;
		}
		ans = max(ans,x);
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream> // {{{
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <cstdio> // }}}

#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,s,n) for(int i=s; i<n; i++)

using namespace std;

int main() {
    long x,y;
    cin >> x >> y;
    int num=0;
    for(long i=x;i<=y;i*=2)num++;
    cout << num << endl;
    return 0;
}


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li a[200200];
li n, k;

inline bool check(li x) {
    li res = 0;
    rin{
        res += (a[i] + x - 1) / x;
    }
    return res <= k + n;
}

int main() {
    cin >> n >> k;
    rin{
        cin >> a[i];
    }

    li l = 0, r = 1000000000ll;
    while (l + 1 < r) {
        li med = (l + r) / 2;
        if (check(med)) {
            r = med;
        } else {
            l = med;
        }
    }
    cout << r << endl;

    return 0;
}

Measured memory_bytes: 5084
#include <algorithm>
#include <cstdio>
#include <cstring>

// Definitions
#define MAXN 1010
#define elif else if
typedef long long int64;
#define File(s) freopen(#s ".in", "r", stdin), freopen(#s ".out", "w", stdout)

// Variables
int len;
char s[MAXN];

// Functions
inline void Process() {
  len = strlen(s);
}
inline void ReadIn() {
  scanf("%s", s);
}
inline void PrintAns() {
  printf("%s", s);
  if (s[len - 1] == 's') {
    puts("es");
  } else {
    puts("s");
  }
}

int main() {
#ifndef ONLINE_JUDGE
  File(data);
#endif
  ReadIn();
  Process();
  PrintAns();
  return 0;
}
/*

*/


Measured memory_bytes: 1728
n = int(input())
C = list(input())
l, r, c = 0, n-1, 0
while l < r:
    if C[l] == 'W' and C[r] == 'R':
        l += 1
        r -= 1
        c += 1
    elif C[l] != 'W': l += 1
    elif C[r] != 'R': r -= 1
print(c)


Measured memory_bytes: 10680
#include<stdio.h>
int main ()
{
      int a,b,d,r;
    double f;
    scanf("%d%d%d%d",&a,&b,&d,&r);
    d = a/b;
    r = a%b;
    f=(double)a/(double)b;
    printf("%d %d %.5f\n",d,r,f);
    }



Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define ll long long int
#define fin(x) scanf("%lld",&x)
#define fout(x) printf("%lld\n",x)
#define pll pair<ll,ll>
#define mp(x,y) make_pair(x,y)
#define cases int t;  scanf("%d",&t);   while(t--)
#define MOD 1000000007
#define MAXN 123456
#define read() freopen("lele.txt","r",stdin)
#define write() freopen("dede.txt","w",stdout)

using namespace std;

int main()
{	
	ll r, d, x0;
	fin(r); fin(d); fin(x0);
	for(ll i = 1; i <= 10; i++)
	{
		ll val = r * x0 - d;
		fout(val);
		x0 = val;
	}
	return 0;
}


Measured memory_bytes: 256