akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n-1); i >= 0; i--)
#define all(v) (v).begin(),(v).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a/gcd(a,b)*b; }
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

int main() {
	int n;
	cin >> n;
    vector<int> w(n);
    int sum = 0;
    rep(i,n) {
        cin >> w[i];
        sum += w[i];
    }
    int cum = 0, ans = INF;
    rep(i,n) {
        cum += w[i];
        ans = min(ans, abs(sum-cum-cum));
    }
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fi first
#define se second
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define caset int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define get(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
const ll mod=10000;
const int Max = 1e6+10;
const double pi = acos(-1);
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
void solve(){
    double r;
    cin >> r;
    cout<<2*r*pi;
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//caset{
		solve();
	//}
  	return 0;
}






Measured memory_bytes: 3792
#include <stdio.h>

int main() {
    int W,H,x,y,r;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    if(x+r <= W && x-r >= 0 && y+r <= H && y-r >= 0){
    printf("Yes\n");
    }else{
    printf("No\n");
    }
    return 0;
}

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


int main()
{
    ll n,i,j,f=0,t,r,x,c;
    string s;
    cin>>s;
    for(i=0;i<s.size();i++)
    {
        if((i+1)%2==0)
        {
            if(s[i]=='R')
                {
                    f=1;
                }
        }
        else
        {
            if(s[i]=='L')
                {
                    f=1;
                }
        }
    }
    if(f)cout<<"No\n";
    else cout<<"Yes\n";

}


Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int h = sc.nextInt();
		
		int area = (a + b) * h / 2;
		
		System.out.println(area);
		
		sc.close();
	}
}



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

const int MAX = 110;

int main()
{
    int N, tmp;
    set<int> d;
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        cin >> tmp;
        d.insert(tmp);
    }
    cout << d.size() << endl;
}


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

int n,k;
int op[3];
char t[100005];
int col[100005];
int dp[100005][3];

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n>>k;
    cin>>op[0]>>op[1]>>op[2];
    cin>>t+1;
    for(int i=1;i<=n;i++){
        if(t[i]=='r')col[i]=0;
        if(t[i]=='s')col[i]=1;
        if(t[i]=='p')col[i]=2;
    }
    for(int i=1;i<=k;i++){
        for(int j=0;j<3;j++){
            dp[i][j]=(bool((j+1)%3==col[i]))*op[j];
        }
    }
    for(int i=k+1;i<=n;i++){
        for(int j=0;j<3;j++){
            for(int pr=0;pr<3;pr++){
                if(j!=pr){
                    dp[i][j]=max(dp[i][j],dp[i-k][pr]+(bool((j+1)%3==col[i]))*op[j]);
                }
            }
        }
    }
    int ans=0;
    for(int i=1;i<=k;i++){
        int j=i;while(j+k<=n)j+=k;
        ans+=max(dp[j][0],max(dp[j][1],dp[j][2]));
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
#define rep(i, x, n) for(int i = x; i < n; i++)
#define repr(i, x, n) for(int i = x; i > n; i--)
#define pii pair<int,int>
#define ll long long
const long long iinf = 1e18;
const int inf = 1e9;
const int MOD = (1e6+3);
int dir4[4][2] = {{1,0},{-1,0},{0,1},{0,-1}};
int knight[8][2] = {{2,1},{2,-1},{-2,1},{-2,-1},{1,2},{-1,2},{1,-2},{-1,-2}};

using namespace std;

void solve()
{
    int n; cin >> n;
    int ans = 0;
    int xors[n+5];
    for(int i = 0; i < n ; i++){
        cin >> xors[i];
        ans ^= xors[i];
    }
    for(int i = 0; i < n; i++){
        cout << (ans^xors[i]) << " ";
    }
    
}
//new line is printed in main()

int main()
{
    int t = 1;
        // cin >> t; // comment out if no test case is required
    int i = 1;
    while(t--){
        //cout << "Case " << i++ << ": ";
        solve();
        // printf("\n");
    }
    return 0;
}


Measured memory_bytes: 4400
// inputに入力データ全体が入る
function Main(input) {
     input = input.split("\n");
     var n= parseInt(input[0], 10);
 console.log(n*n*n);
   }    //    1    
     
  //*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
  


Measured memory_bytes: 7372
#include<bits/stdc++.h>
#define N 200050
#define int long long
#define pb push_back
#define x first
#define y second
#define all(v) v.begin(),v.end()
#define coffee prince
#define sz(a) (int)a.size()
using namespace std;

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s;
    cin>>s;
    if(s[2]==s[3]&&s[4]==s[5])cout<<"Yes";
    else cout<<"No";
    
        return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static Scanner scn = new Scanner(System.in);

	public static void main(String[] args) {
		int n = scn.nextInt();
		int m = scn.nextInt();
		int ans1 = 0;
		if (n > 1) {
			ans1 = n * (n - 1) / 2;
		}
		int ans2 = 0;
		if (m > 1) {
			ans2 = m * (m - 1) / 2;
		}
		System.out.println(ans1 + ans2);
	}
}


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

int main()
{
    ll a, b;
    cin >> a >> b;
    if(a == b){
        cout << 1 << endl;
        return 0;
    }
    ll l;
    for(l = 61; l >= 0; l--){
        if(((a >> l) & 1) != ((b >> l) & 1)) break;
    }
    a %= (1ll << (l + 1));
    b %= (1ll << (l + 1));
    ll k;
    for(k = l - 1; k >= 0; k--){
        if((b >> k) & 1) break;
    }
    ll s = (1ll << (k + 1)) - 1;
    if(s >= a){
        cout << (1ll << l) - a + (1ll << l) << endl;
    }
    else{
        cout << ((1ll << l) - a) * 2 + s + 1 << endl;
    }
}


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

int main(){
    string s;
    cin>>s;
    if(s == "SUN")cout<<7<<endl;
    else if(s =="MON")cout<<6<<endl;
    else if(s =="TUE")cout<<5<<endl;
    else if(s =="WED")cout <<4<<endl;
    else if(s =="THU")cout<<3<<endl;
    else if(s =="FRI")cout<<2<<endl;
    else if(s =="SAT")cout<<1<<endl;
}

Measured memory_bytes: 256
// BROWNIE TK
 
#include <bits/stdc++.h>
 
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define pb push_back
#define popb pop_back()
#define pf push_front
#define popf pop_front()
#define si size()
#define be begin()
#define en end()
#define all(v) v.be, v.en
#define le length()
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
 
#define forz(i, n) for (int i = 0; i < n; i++)
#define bui(i, m, n) for (int i = m; i < n; i++)
#define rforz(i, n) for (int i = n - 1; i >= 0; i--)
#define mui(i, m, n) for (int i = n - 1; i >= m; i--)
#define deci(n) fixed << setprecision(n)
#define high(n) __builtin_popcount(n)
#define parity(n) __builtin_parity(n)
#define ctz(n) __builtin_ctz(n)
#define lb lower_bound
#define ub upper_bound
#define er equal_range
#define maxe *max_element
#define mine *min_element
#define mod 1000000007
#define mod2 998244353
#define kira ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
 
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
 
#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define osetlli tree<lli, null_type,less<lli>, rb_tree_tag,tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
#define ofk order_of_key
#define fbo find_by_order

using namespace std;
 
/*STD fucntions*/
lli power(lli x,lli y,lli p)
{
    lli res=1;
    x=x%p;
    while(y>0)
    {
        if(y&1)
            res=(res*x)%p;
        //y must be even now
        y=y>>1; //y=y/2
        x=(x*x)%p;
    }
    return res;
}
lli gcd(lli a, lli b)
{
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
lli lcm(lli a, lli b)
{ return a * b / gcd(a, b); }
lli modi(lli a,lli m)
{
// fermat little thm where m is prime
return power(a,m-2,m);
}
/*CODE BEGINS*/
int main()
{
 kira;
 lli n,k;
 cin>>n;
 k=2;
 lli a[n];
 forz(i,n)cin>>a[i];
 lli inf=1e9+5;
 lli dp[n+1];
 memset(dp,inf,sizeof(dp));
 dp[0]=0;
 for(int i=0;i<=n;i++)
 {
   for(int j=1;j<=k;j++)
   {
     if(i-j>=0)
     {dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));}
   }
   //p1(dp[i]);
 }
 cout<<dp[n-1];
 return 0;
}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;

const long MOD = 1000000007;
typedef pair<int, int> P;

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

    long dp[L.length()][2][2];
    for(int i=0; i<L.length(); i++){
        for(int j=0; j<2; j++){
            dp[i][j][0] = 0;
            dp[i][j][1] = 0;
        }
    }
    dp[0][1][1] = 2;
    dp[0][0][0] = 1;
    
    for(int i=0; i<L.length()-1; i++){
        if(L[i+1] == '0'){
            dp[i+1][0][1] = max(dp[i][0][1], dp[i][1][1]);
        }else{
            dp[i+1][1][1] = max(dp[i][0][1], dp[i][1][1])*2;
            dp[i+1][1][1] %= MOD;
            dp[i+1][0][0] += max(dp[i][0][1], dp[i][1][1]);
            dp[i+1][0][0] %= MOD;
        }
        dp[i+1][0][0] += dp[i][0][0] + dp[i][1][0];
        dp[i+1][0][0] %= MOD;
        dp[i+1][1][0] += (dp[i][0][0] + dp[i][1][0])*2;
        dp[i+1][1][0] %= MOD;
    }

    long ans = 0;
    for(int i=0; i<2; i++){
        for(int j=0; j<2; j++){
            ans += dp[L.length()-1][i][j];
            ans %= MOD;
        }
    }

    cout << ans << endl;

    return 0;
}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

template<int64 mod>
struct ModInt{
  int64 x;
  constexpr ModInt(int64 y = 0):x((y%mod+mod)%mod){}
  constexpr ModInt& operator+=(const ModInt& a){
    if((x += a.x) >= mod) x -= mod;
    return *this;
  }
  constexpr ModInt& operator-=(const ModInt& a){
    if((x -= a.x) < 0)x += mod;
    return *this;
  }
  constexpr ModInt& operator*=(const ModInt& a){
    x = x * a.x % mod;
    return *this;
  }
  constexpr ModInt& operator/=(const ModInt& a){
    *this *= a.inv();
    return *this;
  }
  constexpr ModInt operator-() const {
    return ModInt(-x);
  }
  constexpr ModInt operator+(const ModInt& a) const {
    return ModInt(*this) += a;
  }
  constexpr ModInt operator-(const ModInt& a) const {
    return ModInt(*this) -= a;
  }
  constexpr ModInt operator*(const ModInt& a) const {
    return ModInt(*this) *= a;
  }
  constexpr ModInt operator/(const ModInt& a) const {
    return ModInt(*this) /= a;
  }
  constexpr ModInt operator++(){
    *this += ModInt(1);
    return *this;
  }
  constexpr ModInt operator++(int){
    ModInt old = *this;
    ++*this;
    return old;
  }
  constexpr ModInt operator--(){
    *this -= ModInt(1);
    return *this;
  }
  constexpr ModInt operator--(int){
    ModInt old = *this;
    --*this;
    return old;
  }
  constexpr bool operator==(const ModInt& a) const {
    return x == a.x;
  }
  constexpr bool operator!=(const ModInt& a) const {
    return x != a.x;
  }
  constexpr ModInt pow(int64 r) const {
    if(!r)return 1;
    ModInt res = pow(r>>1);
    res *= res;
    if(r & 1) res *= *this;
    return res;
  }
  constexpr ModInt inv() const {
    return pow(mod-2);
  }
  friend istream& operator>>(istream& is, ModInt& a){
    int64 t;
    is >> t;
    a = ModInt(t);
    return is;
  }
  friend ostream& operator<<(ostream& os, const ModInt& a){
    return os << a.x;
  }
};
using mint = ModInt<MOD>;

mint dp[55][55][2555];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n,k;
    cin >> n >> k;
    dp[0][0][0] = 1;
    REP(i,n)REP(j,i+1)REP(l,k+1){
        dp[i+1][j][l+j*2] += dp[i][j][l];
        dp[i+1][j+1][l+(j+1)*2] += dp[i][j][l];
        dp[i+1][j][l+j*2] += dp[i][j][l] * j * 2;
        if(j - 1 >= 0)
           dp[i+1][j-1][l+(j-1)*2] += dp[i][j][l] * j * j;
    }
    ANS(dp[n][0][k]);
    return 0;
}

Measured memory_bytes: 55552
import java.util.Scanner;

public class Main {

    static int H, W;
    static char[][] grid;
    static int[][] visited;
    static int[][] dir = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        H = sc.nextInt();
        W = sc.nextInt();
        grid = new char[H][W];
        for(int i = 0; i < H; i++) grid[i] = sc.next().toCharArray();
        sc.close();
        visited = new int[H][W];
        long ans = 0;
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                long[] ret = new long[2];
                ret = dfs(i, j);
                ans += ret[0] * ret[1];
            }
        }
        System.out.println(ans);

    }
    private static long[] dfs(int i, int j) {
        long[] ret = new long[2];
        if(visited[i][j] == 1) return ret;
        visited[i][j] = 1;
        if(grid[i][j] == '.') ret[0]++;
        else ret[1]++;
        for(int[] d:dir){
            int ni = i +d[0];
            int nj = j +d[1];
            if(ni >=0 && ni <H && nj >=0 && nj <W){
                if(visited[ni][nj] == 0 && grid[ni][nj] != grid[i][j]){
                    long[] ret2 = dfs(ni, nj);
                    ret[0] += ret2[0];
                    ret[1] += ret2[1];
                }
            }
        }

        return ret;
    }

}


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

using namespace std;

#define MAX 100000
const int NIL = -1;

int n;
vector<int> G[MAX];
int color[MAX];
void assignColor();
void bfs(int,int);

int main(){
  int s,t,m,q,i;
  cin >> n >> m;
  for(i = 0; i < m; i++){
    cin >> s >> t;
    G[s].push_back(t);
    G[t].push_back(s);
  }
  assignColor();
  cin >> q;
  for(i = 0; i < q; i++){
    cin >> s >> t;
    if( color[s] == color[t]){
      cout << "yes" << endl;
    }
    else{
      cout << "no" << endl;
    }
  }
  return 0;
}

void bfs(int r, int c){
  stack<int> S;
  S.push(r);
  int u,v,i;
  color[r] = c;
  while( !S.empty() ){
    u = S.top();
    S.pop();
    for(i = 0; i < G[u].size(); i++){
      v = G[u][i];
      if( color[v] == NIL){
        color[v] = c;
        S.push(v);
      }
    }
  }
}

void assignColor(){
  int id = 1;
  int i,u;
  for(i = 0; i < n; i++){
    color[i] = NIL;
  }
  for(u = 0; u < n; u++){
    if( color[u] == NIL){
      bfs(u,id++);
    }
  }
}

Measured memory_bytes: 9028
class DisjointSetUnion():
    def __init__(self, n):
        self.n = n
        self.par_size = [-1] * n

    def merge(self, a, b):
        #assert 0 <= a < self.n
        #assert 0 <= b < self.n
        x = self.leader(a)
        y = self.leader(b)
        if x == y: return x
        if -self.par_size[x] < -self.par_size[y]: x, y = y, x
        self.par_size[x] += self.par_size[y]
        self.par_size[y] = x
        return x

    def same(self, a, b):
        #assert 0 <= a < self.n
        #assert 0 <= b < self.n
        return self.leader(a) == self.leader(b)

    def leader(self, a):
        #assert 0 <= a < self.n
        x = a
        while self.par_size[x] >= 0:
            x = self.par_size[x]
        while self.par_size[a] >= 0:
            self.par_size[a] = x
            a = self.par_size[a]
        return x

    def size(self, a):
        #assert 0 <= a < self.n
        return -self.par_size[self.leader(a)]

    def groups(self):
        leader_buf = [0] * self.n
        group_size = [0] * self.n
        res = [[] for _ in range(self.n)]
        for i in range(self.n):
            leader_buf[i] = self.leader(i)
            group_size[leader_buf[i]] += 1
        for i in range(self.n):
            res[leader_buf[i]].append(i)
        res = [res[i] for i in range(self.n) if res[i]]
        return res

import sys
input = sys.stdin.buffer.readline

N, Q = map(int, input().split())

dsu = DisjointSetUnion(N)
res = []

for _ in range(Q):
    t, u, v = map(int, input().split())
    if t:
        res.append(str(int(dsu.same(u, v))))
    else:
        dsu.merge(u, v)

print('\n'.join(res))

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

int main()
{
	int n;
	for (; cin >> n, n != 0;)
	{
		int sum = 0;
		int max = -1;
		int min = 1001;
		int s[100];
		for (int i = 0; i < n; i++)
		{
			cin >> s[i];
			max = (max < s[i]) ? s[i] : max;
			min = (min > s[i]) ? s[i] : min;
			sum += s[i];
		}
		cout << (sum - (max + min)) / (n - 2) << endl;
	}
	return 0;
}

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

int main() {
  int A, B, C, D, E, F;
  cin >> A >> B >> C >> D >> E >> F;
  vector<int> X, Y;
  for (int i = 0; 100 * A * i <= F; i++) {
    for (int j = 0; 100 * A * i + 100 * B * j <= F; j++) {
      if (100 * A * i + 100 * B * j != 0) {
        X.push_back(100 * A * i + 100 * B * j);
      }
    }
  }
  for (int i = 0; C * i <= F; i++) {
    for (int j = 0; C * i + D * j <= F; j++) {
      Y.push_back(C * i + D * j);
    }
  }
  int W = X.at(0), S = Y.at(0);
  for (int i = 0; i < X.size(); i++) {
    for (int j = 0; j < Y.size(); j++) {
      if (X.at(i) + Y.at(j) > F) continue;
      if (100 * Y.at(j) > X.at(i) * E) continue;
      if (W * Y.at(j) > X.at(i) * S) {
        W = X.at(i);
        S = Y.at(j);
      }
    }
  }
  cout << W + S << " " << S << endl;
}

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

using namespace std;

int main()
{
   int n;
   vector <int> a;
   int ans[100005];
   int a_temp;
   long long int answer=0;
   long long int answer_temp=0;
   cin >> n;
   
   
   
   for (int i=0;i<n;i++)
   {
       
       cin >>a_temp;
       a.push_back(a_temp);
       
   }
   
   sort(a.begin(),a.end());
   
   
   if (n==1)
   {
       cout << a[0]<<endl;
       return 0;
   }
   if (n%2==1)
   {
       int cnt =n-1;
       
       for (int i=1;i<n;i=i+2)
       {
           
           ans[i]=a[cnt];
           cnt-=1;
          
       }
       ans[0]=a[cnt];
       cnt-=1;
       ans[n-1]=a[cnt];
       cnt-=1;
       for (int i=2;i<n-1;i=i+2)
       {
           ans[i]=a[cnt];
           cnt-=1;
           
       }
       for(int i=0;i<n-1;i++)
       {
       answer+=abs(ans[i]-ans[i+1]);
       
       }
       
        cnt =0;
       
       for (int i=1;i<n;i=i+2)
       {
           
           ans[i]=a[cnt];
           cnt+=1;
          
       }
       ans[0]=a[cnt];
       cnt+=1;
       ans[n-1]=a[cnt];
       cnt+=1;
       for (int i=2;i<n-1;i=i+2)
       {
           ans[i]=a[cnt];
           cnt+=1;
           
       }
       
        for(int i=0;i<n-1;i++)
       {
       answer_temp+=abs(ans[i]-ans[i+1]);
       
       }
       
       answer=max(answer,answer_temp);
       
   }
   else
   {
       int cnt =n-1;
       
       for (int i=1;i<n;i=i+2)
       {
           
           ans[i]=a[cnt];
           cnt-=1;
          
       }
      
       for (int i=0;i<n;i=i+2)
       {
           ans[i]=a[cnt];
           cnt-=1;
           
       }
       for(int i=0;i<n-1;i++)
       {
       answer+=abs(ans[i]-ans[i+1]);
       
       }
       
       cnt =0;
       
       for (int i=1;i<n;i=i+2)
       {
           
           ans[i]=a[cnt];
           cnt+=1;
          
       }
       
       for (int i=0;i<n;i=i+2)
       {
           ans[i]=a[cnt];
           cnt+=1;
           
       }
       
        for(int i=0;i<n-1;i++)
       {
       answer_temp+=abs(ans[i]-ans[i+1]);
       
       }
       
       answer=max(answer,answer_temp);
      
   }
   
   
             cout <<answer<<endl; 
   
   
   
   return 0;
}

Measured memory_bytes: 1144
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};



int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    int n;
    cin>>n;
    vector<in> a(n);
    rep(i,n) cin>>a[i];
    int cnt_min=0;
    int abs_mini=inf;
    rep(i,n){
        if(a[i]<0) cnt_min ++;
        abs_mini=min(abs_mini,(int)abs(a[i]));
    }
    in ans=0;
    rep(i,n) ans +=abs(a[i]);
    if(cnt_min%2==1) ans -=2ll*abs_mini;
    cout<<ans<<endl;
}
//./problem.exe

Measured memory_bytes: 1024
n=int(input())
l=list(map(int,input().split()))
c=0
for i in range(0,n):
      for j in range(i,n):
       		for k in range(j,n):
       				if l[i]!=l[j] and l[j]!=l[k] and l[k]!=l[i]:
       						if l[i]+l[j]>l[k] and l[k]+l[j]>l[i] and l[i]+l[k]>l[j]:
       										c=c+1
print(c)


Measured memory_bytes: 9148
c = [list(map(int, input().split())) for _ in range(3)]

count = 0
x = c[0][1] - c[0][0]
y = c[0][2] - c[0][1]
z = c[0][0] - c[0][2]

for i in range(1,3):
    if (c[i][1] - c[i][0] != x):
        count += 1
    if (c[i][2] - c[i][1] != y):
        count += 1
    if (c[i][0] - c[i][2] != z):
        count += 1
        
X = c[0][0] - c[1][0]
Y = c[1][0] - c[2][0]
Z = c[2][0] - c[0][0]

for j in range(1,3):
    if (c[0][i] - c[1][i] != X):
        count += 1
    if (c[1][i] - c[2][i] != Y):
        count += 1
    if (c[2][i] - c[0][i] != Z):
        count += 1
        
if (count == 0):
    print("Yes")
else:
    print("No")    

Measured memory_bytes: 3064
use std::io;
use std::str::FromStr;
use std::collections::HashMap;

fn input<T:FromStr>() -> T {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().parse().ok().unwrap()
}

fn input_vec() -> Vec<u64> {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.split_whitespace().map(|s| s.parse().unwrap()).collect()
}

fn recur(i: usize, a_vec: &Vec<u64>, hats: &mut Vec<u64>, cache: &mut HashMap<(usize, Vec<u64>), u64>) -> u64 {
    // println!("{:?}", hats);
    if cache.contains_key(&(i, hats.to_vec())) {
        return *cache.get(&(i, hats.to_vec())).unwrap();
    }
    if i == a_vec.len() {
        return 1u64;
    }
    let mut res = 0u64;
    for j in 0..hats.len() {
        if hats[j] == a_vec[i] {
            let n = hats[j];
            hats[j] = n + 1;
            res += recur(i + 1, a_vec, hats, cache);
            hats[j] = n;
        }
    }
    if res >= 1000000007 {
        res %= 1000000007;
    }
    cache.insert((i, hats.to_vec()), res);
    res
}

fn main() {
    let n: u64 = input();
    let a_vec = input_vec();
    let mut cache: HashMap<(usize, Vec<u64>), u64> = HashMap::new();
    println!("{}", recur(0, &a_vec, &mut vec![0u64; 3], &mut cache));

}


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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);  
	int a, b;
	cin >> a >> b;
	int ans = 0;
	for(int i = a; i <= b; i++) {
		string s = to_string(i);
		bool ok = true;
		int n = s.length();
			//cerr << s << endl;
		for(int j = 0; j < n; j++) {
			if(s[j] != s[n - 1 - j]) ok = false;
		}
		if(ok) ans++;
	}
	cout << ans << endl;
	return 0;	
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cassert>
#include <functional>
#include <string>
#include <sstream>
#include <cctype>
#include <queue>
using namespace std;

int main(){
  string SA, SB, SC; cin >> SA >> SB >> SC;
  queue<char> A, B, C;
  for(int i = 0; i < SA.size(); i++){
    A.push(SA[i]);
  }
  for(int i = 0; i < SB.size(); i++){
    B.push(SB[i]);
  }
  for(int i = 0; i < SC.size(); i++){
    C.push(SC[i]);
  }
  char cur = 'a';
  char winner;
  while(true){
    if(cur == 'a'){
      if(!A.empty()){
        cur = A.front();
        A.pop();
      }else{
        winner = 'A';
        break;
      }
    }
    if(cur == 'b'){
      if(!B.empty()){
        cur = B.front();
        B.pop();
      }else{
        winner = 'B';
        break;
      }
    }
    if(cur == 'c'){
      if(!C.empty()){
        cur = C.front();
        C.pop();
      }else{
        winner = 'C';
        break;
      }
    }
  }
  cout << winner << endl;
}


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

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

template<class T> using v = std::vector<T>;
template<class T> using vv = v<v<T>>;

const int mod = 1000000007;
//const int mod = 998244353;

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

    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


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

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int r; cin >> r;
    cout << r*r << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
B = 0
for i in range(N):
  A = 0
  for j in range(i+1):
     if (i+1) % (j+1) == 0:
        A += 1
  if A == 8 and (i+1) % 2 == 1:
    B += 1
print(B)

Measured memory_bytes: 38896
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 1 << 100
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I()

if n % 2 == 0:
    ret = 0
    a = n // 10
    ret += a
    while a:
        a //= 5
        ret += a
    print(ret)
else:
    print(0)

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


void solve(long long N, long long K, std::vector<long long> h){
    long long res = 0;
  for (auto guy : h) {
    if (guy >= K) {
	res++;
    }
  }
  cout << res << 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);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> h(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&h[i]);
    }
    solve(N, K, std::move(h));
    return 0;
}


Measured memory_bytes: 1024
import datetime;

s = input();

time_format = datetime.datetime.strptime(s, "%Y/%m/%d");
time_heisei = datetime.datetime.strptime("2019/04/30", "%Y/%m/%d");

if time_format <= time_heisei:
    print("Heisei");
else:
    print("TBD");

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

int main() {
  int n;
  cin >> n;
  vector<int> L(n);
  rep(i,n) cin >> L[i];
  sort(L.begin(), L.end());
  int ans = 0;
  //a,bは何番目かを表す
  for (int b=0;b<n;++b){
    for (int a=0;a<b;++a){
    int ab = L[a]+L[b];
    int r = lower_bound(L.begin(), L.end(), ab) - L.begin();//ab以上の最小の要素を二分探索で検索。イテレータが返るからL.begin()を引くと添字に変換可能。
    int l=b+1;//番目だから+1
    // c = [l,r)
    ans += r-l;
    }
  }
  cout << ans << endl;
  return 0;
}
//ex)2,3(=L[a]),4,6(=L[b]),|6,7,|10
//r=7,l=4+1だからr-l=7-5=2


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  string s;
  cin >> s;
  int siz = s.length();
  string t = "";
  rep(i,siz) {
    if (s[i] != 'x') t += s[i];
  }
  string rt = t;
  reverse(all(rt));
  if (t != rt) { //x無しで回文にならない
    cout << -1 << endl;
    return 0;
  }
  //ラングレス圧縮でtの間に入ってるxの個数を求める
  vector<int> nums((int)t.size() + 1);
  int idx = 0;
  rep(i,siz) {
    int j = i;
    while (j < siz && s[j] == 'x') j++;
    nums[idx++] = j-i;
    i = j;
  }
  for (auto x : nums) debug(x);
  int left = 0, right = nums.size()-1;
  int ans = 0;
  while (right-left >= 1) {
    if (nums[left] != nums[right]) {
      ans += fabs(nums[left] - nums[right]); //一致しなかったら不足分だけ挿入
    }
    left++; right--;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 976
#include <bits/stdc++.h>
#define TABLE_SIZE 16777216
using namespace std;

int arr[128];
char s1[10],s2[15];

int translate(char buf[])
{
    int sum = -1, mul = 1;
    for (int i = 0; buf[i] != '\0'; i++)
    {
        sum += arr[buf[i]] * mul;
        mul *= 4;
    }
    return sum;
}

 int hash_table[TABLE_SIZE];
int main()
{

    arr['A'] = 1;
    arr['C'] = 2;
    arr['T'] = 3;
    arr['G'] = 4;
   
    
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> s1;
        if(s1[0]=='i'){
            cin >> s2;
            hash_table[translate(s2)] = 1;
        }
        if(s1[0] == 'f'){
            cin >> s2;
            if(hash_table[translate(s2)] == 1) cout << "yes" << endl;
            else cout << "no" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 8548
#include<iostream>

using namespace std;

int main(void){
	int N ;
	int M ;
	cin >> N ;
	int sum = 0;
	
	M = N ;
	
	while(M){
		sum += M % 10 ;
		M = M / 10 ;
	}
	
	if(N % sum == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	
	return 0;
}

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

int main() {
    ll n,k;
    cin >> n >> k;
    vector<pair<int,int>> p;
    vector<int> v;
    rep(i,n) {
        int a;
        scanf("%d",&a);
        p.push_back(make_pair(i+1,a));
    }
    //for(auto c : p) cout << c.first << " " << c.second << endl;
    ll start = p[0].second;
    v.push_back(1);
    set<int> S;
    ll counter;
    while(true) {
        ll size_before = S.size();
        v.push_back(start);
        S.insert(start);
        if(S.size() == size_before) {
            counter = S.size();
            break;
        }
        start = p[start-1].second;
    }
    ll turn = v[counter+1];
    ll xx;
    rep(i,v.size()) {
        if(v[i] == turn) {
            xx = i;
            break;
        }
    }
    //cout << xx << endl;
    ll h = counter - xx + 1;
    //cout << "h= " << h << endl;
    if(k >= xx) {
    k -= xx;
    ll rem = k % h;
    //rep(i,20) cout << v[i] << " ";
    //cout << endl;
    cout << v[rem+xx] << "\n";
    } else {
        cout << v[k] << endl;
    }
}

Measured memory_bytes: 14728
#include <stdio.h>

int main(void){
    int N,i;
    scanf("%d",&N);
    for(i=0;i<=N/7;i++){
        if((N-7*i)%4==0){
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    int a, b, c, d;
    a = N/1000;
    b = N/100 - a*10;
    c = N/10 - a*100 - b*10;
    d = N - a*1000 - b*100 - c*10;
    if(b == c) {
        if (a == b || c == d) {
            cout << "Yes" << endl;;
            return 0;
        }
    } 
    cout << "No" << endl;
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  int A = 0 , B = 0;
  vector<int> vec(N);
  for (int i = 0; i < N; i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  for (int i = 0; i < N; i++){
    if (i % 2 == 0){
      A += vec.at(i);
    }else{
      B += vec.at(i);
    }
  }
  cout << A - B<< endl;
}


Measured memory_bytes: 256
#実験をしっかりとしよう
X,Y,Z,K = (int(_) for _ in input().split())
A = (int(_) for _ in input().split())
B = (int(_) for _ in input().split())
C = (int(_) for _ in input().split())
#この手の問題はまずsortする(今回は大きい順の方がすっきり)
A = sorted(A)
B = sorted(B)
C = sorted(C)
#Aのa位とb位とc位ならその上にはa*b*c-1(自分以外)が上にいる。
A.reverse()
B.reverse()
C.reverse()

ABC = []
for i in range(len(A)):
    for j in range(len(B)):
        if (i+1)*(j+1) > K:
            break
        for k in range(len(C)):
            if (i+1)*(j+1)*(k+1) > K:
                break
            ABC.append(A[i]+B[j]+C[k])
ABC.sort()
ABC.reverse()

for i in range(K):
    print(ABC[i])
#pythonだとTLEになる?


Measured memory_bytes: 8688
#include<iostream>
#include<stack>

int field[15][15];
int w,h;
int dfs(int x0,int y0);

int main()
{
	while(1)
	{
		std::cin>>w>>h;
		if(w==0&&h==0)break;
		for(int y=0;y<h;y++)
		{
			for(int x=0;x<w;x++)
			{
				std::cin>>field[x][y];
			}
		}
		
		int count=0;
		for(int x=0;x<w;x++)
		{
			if(field[x][0]==0)
			{
				count+=dfs(x,0);
			}
		}
		std::cout<<count<<std::endl;
	}
	return 0;
}

int dfs(int x0,int y0)
{
	std::stack<std::pair<int,int> > stk;
	int count=0;
	stk.push(std::pair<int,int>(x0,y0));
	while(!stk.empty())
	{
		int x=stk.top().first,y=stk.top().second;
		
		stk.pop();
		
		if(y>=h-1&&field[x][y]!=1)
		{
			count++;
		}
		else
		{
			if(field[x][y]==2)
			{
				stk.push(std::pair<int,int>(x,y+2));
			}
			else if(field[x][y]==0)
			{
				if(x>0&&field[x-1][y+1]==0){stk.push(std::pair<int,int>(x-1,y+1));}
				if(x<w-1&&field[x+1][y+1]==0){stk.push(std::pair<int,int>(x+1,y+1));}
				if(field[x][y+1]!=1){stk.push(std::pair<int,int>(x,y+1));}
			}
		}
	}
	return count;
}

Measured memory_bytes: 1200
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back

signed main(){
    int n,h;
    cin>>n>>h;
    vector<int> a(n),b(n);
    rep(i,n)cin>>a[i]>>b[i];
    
    int at = *max_element(all(a));
    
    sort(all(b),greater<int>());
    
    int t = 0;
    rep(i,b.size()){
        if(b[i]>at){
            h-=b[i];
            t++;
        }
        if(h<=0){
            cout<<t<<endl;
            return 0;
        }
    }
    
    cout<<t+(h+at-1)/at<<endl;
}


Measured memory_bytes: 1792
/*
[arc102] D - All Your Paths are Different Lengths
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MAX_N = 20;

int L;

void solve() {
    int n = 0;
    while ((1 << n) <= L) {
        n++;
    }
    int m = (n - 1) * 2;

    int paths[MAX_N];
    fill(paths, paths + n, -1);
    int done_l = (1 << (n - 1));
    for (int i = n - 1; i > 0; i--) {
        int b = 1 << (i - 1);
        if (L & b) {
            m++;
            paths[i] = done_l;
            done_l = done_l | b;
        }
    }

    int pow2 = 1;
    cout << n << " " << m << endl;
    for (int i = 1; i < n; i++) {
        cout << i << " " << i + 1 << " " << 0 << endl;
        cout << i << " " << i + 1 << " " << pow2 << endl;
        pow2 *= 2;
        if (paths[i] >= 0) {
            cout << i << " " << n << " " << paths[i] << endl;
        }
    }
}

int main() {
    cin >> L;

    solve();

    return 0;
}


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

typedef long long ll;
typedef pair<int, int> P;

const ll mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 1152921504606846976

int main()
{
    int n; cin >> n;
    int a[n];
    rep(i,n) a[i] = 0;
    rep(i,n-1){
        int k; cin >> k;
        a[k-1]++;
    }
    rep(i,n) cout << a[i] << endl;
}

Measured memory_bytes: 4416
import java.io.*;
import java.util.Arrays;

public class Main{
	public static void main(String[] args) throws IOException{ 
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while(true){
			int count = 0;
			String line = br.readLine();
			String[] spl = line.split(" ");
			int n = Integer.parseInt(spl[0]);
			int x = Integer.parseInt(spl[1]);
			if(n == 0 && x == 0){break;}
			for (int i = 1 ; i <= (n-2) ; i++ ) {
				for (int j = i+1 ; j<= (n-1) ; j++ ) {
					for (int k = j+1 ; k <= n ; k++) {
						if(i + j + k == x){
							count++;
						}
					}
				}
			}
			System.out.println(count);
		}
	}
}

Measured memory_bytes: 24860
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	result := 1
	first := nextInt()
	last := nextInt()
	for i := 0; i < n-2; i++ {
		next := nextInt()
		if first == last {
			last = next
			continue
		} else if first > last {
			if last >= next {
				last = next
				continue
			}
		} else if first < last {
			if last <= next {
				last = next
				continue
			}
		}
		first = next
		last = nextInt()
		i = i + 1
		result++
	}
	fmt.Println(result)
}

// 引数処理
func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}

func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}

func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}


Measured memory_bytes: 2304
// Why am I so dumb? :c
#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair

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

#define fi first
#define se second

using namespace std;

typedef long long ll;

const int MAXN = (int)1e5 + 5;

int cnt[MAXN];

int n, m;

void solve() {                   
	scanf("%d %d", &n, &m);

    for (int i = 1, l, r; i <= m; ++i) {
    	scanf("%d %d", &l, &r);

    	if (l > r) {
    		swap(l, r);
    	}

    	++cnt[l];
    	--cnt[r];
    }            

	for (int i = 2; i <= n; ++i) {
		cnt[i] += cnt[i - 1];
	}

	for (int i = 1; i <= n; ++i) {
		if (cnt[i] & 1) {
			printf("NO\n");
			return;
		}
	}

	printf("YES\n");
}

int main() {    
    int tt = 1;

    while (tt--) {
        solve();
    }

    return 0;
}

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

#define mp make_pair
#define pb push_back

#define int int64_t

const int MOD = 1e9+7;
 
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n,m;
    cin>>n>>m;
    int x[n];
    int y[m];
    for(int i=0;i<n;i++)
        cin>>x[i];
    for(int j=0;j<m;j++)
        cin>>y[j];

    int rows=0,cols=0;
    for(int i=0;i<n;i++) {
        rows+=(i-(n-i-1))*x[i];
        rows%=MOD;
    }
    for(int i=0;i<m;i++) {
        cols+=(i-(m-i-1))*y[i];
        cols%=MOD;
    }
    //rows=(rows+MOD)%MOD;
    //cols=(cols+MOD)%MOD;
    cout<<(cols*rows)%MOD;

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for (int i=(n-1);i >= 0;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)((v).size())
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
using namespace std; using ll = long long; using P = pair<int,int>;
using vl = vector<ll>; using vvl = vector<vl>;
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cout << H << " ";
    debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
    for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
    return os;
}
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
template<class T>bool chmax(T &a, const T &b) {if(a<b){a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if(b<a){a=b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const int dx[8] = {1,0,-1,0,1,1,-1,-1}; const int dy[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    string s; cin >> s;
    if(s[1]=='B') cout << "ARC" << endl;
    else cout << "ABC" << endl;
}

Measured memory_bytes: 3652
n=int(input())
h=list(map(int,input().split()))
dp=[0]*n
dp[0]=0
dp[1]=abs(h[1]-h[0])
for i in range(2,n):dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[n-1])

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

int main() {
	// your code goes here
	int n,m,l;
	cin>>n>>m>>l;
	if(n>=m){
		if(n>=l){
			if(m>=l){
				cout<<l<<" "<<m<<" "<<n<<endl;
			}else{
				cout<<m<<" "<<l<<" "<<n<<endl;
			}
		}else{
			cout<<m<<" "<<n<<" "<<l<<endl;
		}
	}else{
		if(m>=l){
			if(n>=l){
				cout<<l<<" "<<n<<" "<<m<<endl;
			}else{
				cout<<n<<" "<<l<<" "<<m<<endl;
			}
		}else{
			cout<<n<<" "<<m<<" "<<l<<endl;
		}
	}
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M,K;
string S,T;



void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M>>K;
	cin>>S>>T;
	reverse(ALL(S));
	reverse(ALL(T));
	while(S.size()<2010000) S+='0';
	while(T.size()<2010000) T+='0';
	FORR(c,S) c-='0';
	FORR(c,T) c-='0';
	
	for(i=1000000;i>=0;i--) if(S[i]&&T[i]) {
		S[i]=T[i]=0;
		int Z=K-1,X=3;
		for(j=i+1;;j++) {
			assert(S[j]+T[j]<2);
			if(S[j]==0 && T[j]==0) {
				if(X==2) {
					S[j]=1;
					break;
				}
				else if(X==1) {
					T[j]=1;
					break;
				}
				else {
					if(--Z<0) {
						S[j]=T[j]=1;
						break;
					}
				}
				
			}
			else if(S[j]==1 && T[j]==0) {
				if(X&2) {
					S[j]=0;
					T[j]=X&1;
					X=2;
				}
				else {
					if(--Z<0) {
						S[j]=T[j]=1;
						break;
					}
					S[j]=0;
					X=3;
				}
			}
			else {
				if(X&1) {
					S[j]=(X>>1)&1;
					T[j]=0;
					X=1;
				}
				else {
					Z--;
					if(Z<0) {
						S[j]=T[j]=1;
						break;
					}
					T[j]=0;
					X=3;
				}
			}
			
		}
	}
	
	int out=0;
	reverse(ALL(S));
	FORR(c,S) {
		if(c==1) out=1;
		if(out) cout<<(int)c;
	}
	cout<<endl;
	out=0;
	reverse(ALL(T));
	FORR(c,T) {
		if(c==1) out=1;
		if(out) cout<<(int)c;
	}
	cout<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 10136
#include<iostream>
#include<vector>
using namespace std;
vector<int> l,r;
int main()
{
    int size1=0, size2=0, value=100;
    long long n;
    cin >> n;
    n++;
    while(n > 1)
    {
        if(n & 1) {
            l.push_back(value);
            size1 ++;
            n--;
        }
        else {
            r.push_back(value);
            n>>=1;
            size2 ++;
        }
    value--;
    }
    cout << (size1+size2<<1) << endl;
    for(int i=0; i<size1; i++)
        cout << l[i] << ' ';
    for(int i=size2-1; i>=0; i--)
        cout << r[i] << ' ';
    for(int i=101-size1-size2; i<101; i++)
        cout << i << ' ';
    return 0;
}

Measured memory_bytes: 256