akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card {
     char suit;
     int value;
     };

struct Card L[MAX / 2 + 2], R[MAX / 2 + 2];
void merge(struct Card A[], int n, int left, int mid, int right) {
    int i, j, k;
     int n1 = mid - left;
     int n2 = right - mid;
     for ( i = 0; i < n1; i++ ) L[i] = A[left + i];
     for ( i = 0; i < n2; i++ ) R[i] = A[mid + i];
     L[n1].value = R[n2].value = SENTINEL;
     i = j = 0;
     for ( k = left; k < right; k++ ) {
         if ( L[i].value <= R[j].value ) {
             A[k] = L[i++];
             } else {
                 A[k]=R[j++];
                 }
         }
     }

 void mergeSort(struct Card A[], int n, int left, int right) {
    int mid;
     if( left+ 1<right){
         mid = (left + right) /2;
         mergeSort(A, n, left, mid);
         mergeSort(A, n, mid, right);
         merge(A, n, left, mid, right);
     }
 }

int partition(struct Card A[], int n, int p, int r){
 int i, j;
 struct Card t, x;
 x = A[r];
 i = p - 1;
 for ( j = p; j < r; j++ ) {
     if ( A[j].value <= x.value ) {
         i++;
         t = A[i];
         A[i] = A[j];
         A[j] = t;
     }
 }
    t = A[i + 1];
    A[i + 1] = A[r];
    A[r] = t;
    return i + 1;
}

void quickSort(struct Card A[], int n, int p, int r) {
    int q;
    if ( p < r ) {
        q = partition(A, n, p, r);
        quickSort(A, n, p, q - 1);
        quickSort(A, n, q + 1, r);
    }
}

int main(){
    int n, i, v;
    struct Card A[MAX],B[MAX];
    char S[10];
    int stable=1;
    
    scanf("%d",&n);
    
    for(i=0; i<n; i++){
        scanf("%s %d", S, &v);
        A[i].suit = B[i].suit= S[0];
        A[i].value = B[i].value =v;
    }
    mergeSort(A, n, 0, n);
    quickSort(B, n, 0, n-1);
    
    for(i=0; i<n; i++){
        // マージソートとクイックソートの結果を比べる
        if(A[i].suit != B[i].suit) stable=0;
    }
    if(stable ==1) printf("Stable\n");
    else printf("Not stable\n");
    for(i=0; i<n; i++){
        printf("%c %d\n", B[i].suit, B[i].value);
    }
    return 0;
}

    




Measured memory_bytes: 4132
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef unsigned long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = (LL)1 << 32;

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

  int N;
  cin >> N;
  for(int t=0;t<N;++t){
	LL n[9];
	REP(i,9) cin >> hex >> n[i];
	LL ans = 0;
	int k = 0;
	for(int b=0;b<32;++b){
	  int sum = 0;
	  REP(i,8) sum += (n[i] >> b) & 1;
	  if((sum + k) % 2 == ((n[8] >> b) & 1)){}
	  else{
		ans |= (1 << b);
		sum = 8 - sum;
	  }
	  k = (sum + k) / 2;
	}

	cout << hex << (ans % MOD) << endl;
  }

  return 0;
}

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

struct Edge {
    int to, id;
};

vector<vector<Edge>> g;
vector<int> ans;

void dfs(int v, int c=-1, int p=-1) {
    int k = 1;
    rep(i,g[v].size()) {
        int u = g[v][i].to, ei = g[v][i].id;
        if (u == p) continue;
        if (k == c) k++;
        ans[ei] = k; k++;
        dfs(u,ans[ei],v);
    }
}

int main() {
    int n;
    cin >> n;
    g.resize(n);
    ans = vector<int>(n-1);
    rep(i,n-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back((Edge){b,i});
        g[b].push_back((Edge){a,i});
    }
    dfs(0);
    int mx = 0;
    rep(i,n) mx = max(mx, int(g[i].size()));
    cout << mx << endl;
    rep(i,n-1) cout << ans[i] << endl;
    return 0;
}

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

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

using namespace std;

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if(a >= b && a >= c) {
    cout << 10*a + b + c << endl;
    return 0;
  }
  if(b >= a && b >= c) {
    cout << 10*b + a + c << endl;
    return 0;
  }
  if(c >= a && c >= b) {
    cout <<10*c + a + b << endl;
  }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long  fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y){
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
vector<long long int >meguru;
bool isOK(int index, int key) {
	if (meguru[index] >= key) return true;
	else return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = (int)meguru.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key)) right = mid;
		else left = mid;
	}
	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}
int main() {
	long long int h;
	cin >> h;
	long long int ans = 0;
	long long int sum = 0;
	while (h > 0) {
		h = h / 2;
		long long int a = pow(2, sum);
		ans = ans + a;
		sum++;
	}
	cout << ans;
}


Measured memory_bytes: 384
while(true) do
    sq= Array.new(2)
    sq= gets.split(" ")
    if (sq[0].to_i==0 && sq[1].to_i==0) then
        break
    end

    sq[0].to_i.times{
        sq[1].to_i.times{
            print "#"
        }
        print("\n")
    }
    print "\n"
end

Measured memory_bytes: 8844
import sys

def sumItUp(List):
    result = []
    for i in range(0,len(List)):
        result.append(sum(List[0:i+1]))
    return sum(result)

List = []
for i in sys.stdin:
    List.append(i)

for i in range(1,len(List),2):
    List[i] = List[i].split()
    for j in range(0,len(List[i])):
        List[i][j] = int(List[i][j])
    List[i] = sorted(List[i])
    print(sumItUp(List[i]))


Measured memory_bytes: 5728
n, x, y = [0] * 3

def format_input(filename = None):
	global n, x, y
	if filename == None:
		n, x, y = list(map(int, input().split()))

	elif filename == '__random__':
		from random import randint as rng
		n = rng(3, 2 * 10**3)
		x = rng(1, n-1)
		y = rng(x+1, n)
		print(n, x, y)

def distance(i, j):
	return min(abs(j - i), abs(x - i) + abs (y - j) + 1)

def get_answer():
	num_dist = [0] * n
	for i in range(1, n):
		for j in range(i+1, n+1):
			num_dist[distance(i, j)] += 1

	for k in range(1, n):
		print(num_dist[k])

if __name__ == '__main__':
	format_input()

	get_answer()


Measured memory_bytes: 3444
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    int a[][] = new int[3][3];
    
    for(int i = 0; i < 3; i++){
      for(int j = 0; j < 3; j++){
        a[i][j] = sc.nextInt();
      }
    }
    
    int n = sc.nextInt();
    
    int b[] = new int[n];
    
    for(int i = 0; i < n; i++){
      b[i] = sc.nextInt();
    }
    
    int count = 0;
    
    for(int i = 0; i < 3; i++){
      for(int j = 0; j < 3; j++){
        for(int t = 0; t < n; t++){
          if(a[i][j] == b[t]){
            a[i][j] = 101;
          }
        }
      }
    }
    
    for(int i = 0; i < 3; i++){
      if((a[i][0] == 101) && (a[i][1] == 101) && (a[i][2] == 101)){
        count++;
      }
    }
    
    for(int i = 0; i < 3; i++){
      if((a[0][i] == 101) && (a[1][i] == 101) && (a[2][i] == 101)){
        count++;
      }
    }
    
    if((a[0][0] == 101) && (a[1][1] == 101) && (a[2][2] == 101)){
      count++;
    }
    
    if((a[0][2] == 101) && (a[1][1] == 101) && (a[2][0] == 101)){
      count++;
    }
    
    if(count == 0){
      System.out.println("No");
    }else{
      System.out.println("Yes");
    }
        
    sc.close();
     
  }
}


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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 10;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;

bool contain(set<P> &s, P a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);


void print_line(vector<ll> &line) {
    if (line.size() == 0ll) {
        cout << endl;
        return;
    }
    for (ll i = 0; i < line.size(); i++) {
        cout << line[i];
        if (i == line.size() - 1) cout << endl;
        else cout << ' ';
    }
}


typedef priority_queue<long long, vector<long long>, greater<long long>> PQ_ASK;
const int mod = 1000000007;

int main() {
    multiset<ll> a;
    int q;
    cin >> q;
    rep(i, q) {
        int command;
        ll x;
        cin >> command >> x;

        if (command == 0) {
            a.insert(x);
            cout << a.size() << endl;
        } else if (command == 1) {
            cout << a.count(x) << endl;
        } else if (command == 2) {
            a.erase(x);
        } else if (command == 3) {
            ll l, r;
            l = x;
            cin >> r;
            for (auto it = a.lower_bound(l); it != a.end() && *it <= r; it++) {
                cout << *it << endl;
            }
        }

    }

}



Measured memory_bytes: 12276
#include<iostream>
#include<math.h>

using namespace std;

int main()
{
	int n;

	cin>>n;

	int *weight = new int[n];
	
	for(int i=0; i<n; i++)
		cin>>weight[i];

	int s1=0, s2=0, sd=0;
	for(int t=0; t<n; t++)
	{
		s1 = 0, s2=0;
		for(int j=0; j<=t; j++)
		{
			s1=s1+weight[j];
		}
		for(int j=t+1; j<n; j++)
		{

			s2 = s2+weight[j];
		}
		int s = abs(s1-s2);
		if(t==1)
			sd = abs(s1-s2);
		else if(sd>abs(s1-s2))
			sd = abs(s1-s2);
	}
		cout<<sd<<endl;
		delete[] weight;

return 0;
}



Measured memory_bytes: 256
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
ab.sort()
ans = 0
while m > 0:
    for x,y in ab:
        if y <= m:
            ans += x*y
            m -= y
        else:
            ans += x*m
            m -= y
        
        if m <= 0:
            break
print(ans)

Measured memory_bytes: 27884
loop do
  h, w = gets.split.map(&:to_i)
  break if h == 0 && w == 0
  ans = '#'*w + "\n"
  (h-2).times {ans << '#' + '.'*(w-2) + "#\n"}
  ans << '#'*w + "\n"
  puts ans + "\n"
end

Measured memory_bytes: 6224
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

int calc(int y, int m, int d){ //1/1/1 = 1からの日数
	int res = 0;
	int a = (y - 1) / 3, b = y - 1 - a;
	res += a * 200 + b * 195;
	res += (m - 1) * 20 - (y % 3 != 0 ? (m - 1) / 2 : 0);
	res += d;
	return res;
}

int main(){
	
	int goal = calc(1000, 1, 1);
	int n;
	cin >> n;
	while(n--){
		int y, m, d;
		cin >> y >> m >> d;
		cout << goal - calc(y, m, d) << endl;
	}
	return 0;
}

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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

const int vmax=100010;
struct node{ll to,cost;};

vector<node> graph[vmax];

ll dist[vmax];
ll cmax[vmax];
int ans[vmax];

void tree_height(int n){
	function<void(int,int,int)> dfs=[&dfs](int v,int p,ll c){
		dist[v]=c;
		for(auto &e:graph[v]) if(e.to!=p) dfs(e.to,v,c+e.cost);
	};
	dfs(0,-1,0LL);
	int u=max_element(dist,dist+n)-dist;
	dfs(u,-1,0LL);
	int v=max_element(dist,dist+n)-dist;

	function<void(int,int,ll,int)> dfs2=[&dfs2](int v,int p,ll c,int s){
		if((cmax[v]<c)||(cmax[v]==c&&ans[v]>s)) cmax[v]=c,ans[v]=s;
		for(auto &e:graph[v]) if(e.to!=p) dfs2(e.to,v,c+e.cost,s);
	};
	dfs2(u,-1,0LL,u);
	dfs2(v,-1,0LL,v);
}

int main(void){
	int n;
	scanf("%d",&n);
	rep(i,n-1){
		int a,b,c;
		scanf("%d %d %d",&a,&b,&c);
		graph[a].pb({b,c});
		graph[b].pb({a,c});
	}
	tree_height(n);
	rep(i,n) printf("%d\n",cmax[i]);
	return 0;
}

Measured memory_bytes: 4992
import java.io.BufferedInputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner stdin = new Scanner(new BufferedInputStream(System.in));
		List<String> output = new ArrayList<String>();
		while (stdin.hasNext()) {
			String input = stdin.nextLine();
			String[] inputs = input.split(" ");
			int h = Integer.parseInt(inputs[0]);
			int w = Integer.parseInt(inputs[1]);
			if (h == 0 && w == 0) {
				break;
			} else {
				if (h >= 1 && h <= 300 && w >= 1 && w <= 300) {
                    for (int j = 1; j <= h; j++) {
                        String result = "";
                        for (int i = 1; i<= w; i++) {                        	
                        	if(j ==1 || j==h || i==1 || i==w){
                        		 result += "#";
                            }
                            else{   
                            	 result += ".";
                            }
                            }
                        output.add(result);
                        } 
                    }
                 output.add("");
				}
			}		
		for (String out : output) {
            System.out.println(out);
        }


	}

}

Measured memory_bytes: 49092
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;
using ll = long long;

int gcm( int a, int b ){  //最大公約数を返す
  while( b != 0 ){
    a = a % b;
    swap( a, b );
  }
  return a;
};

ll lcm( ll a, ll b ){  //最小公倍数を返す
  ll init_a = a, init_b = b;
  while( b != 0 ){
    a = a % b;
    swap( a, b );
  }
  return init_a * init_b / a;
};


int main(){
  ll A, B, C, D;
  cin >> A >> B >> C >> D;
  
  ll K = ( B - B/C - B/D + B/lcm(C,D) );
  ll L = ( (A-1) - (A-1)/C - (A-1)/D + (A-1)/lcm(C,D) );
  cout << K-L;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;

const double pie = acos(-1.0);
const ll MOD = 1e9 + 7;

// 最大公約数
ll gcd(ll a, ll b)
{
   if (a%b == 0) {
       return(b);
   } else {
       return(gcd(b, a%b));
   }
}

// 最小公倍数
ll lcm(ll a, ll b){
   return a / gcd(a, b) * b;
}

//素数判定
bool is_prime(const unsigned n){
    switch(n){
        case 0: // fall-through
        case 1: return false;
        case 2: // fall-through
        case 3: return true;
    } // n > 3 が保証された
    if(n % 2 == 0 || n % 3 == 0) return false;
    for(unsigned i = 5; i * i <= n; i += 6) {
        if(n % i     == 0) return false; // (6の倍数)-1
        if(n % (i+2) == 0) return false; // (6の倍数)+1
    }
    return true;
}

void solve() {
    ll n; cin >> n;
    Vl a(n);
    ll sum = 0;
    rep(i, 0, n){
        cin >> a[i];
        sum += a[i];
    }
    ll x = a[0], y = sum - x;
    ll ans = abs(x-y);
    rep(i, 1, n-1){
        x += a[i];
        y -= a[i];
        ans = min(ans, abs(x-y));
    }
    cout << ans << endl;
}

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

    solve();
    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
int main(){
    char s[100],d[100];
    int l=0,r=0,last=-1;
    bool f;
    for(int i=0;i<100;i++)s[i]=d[i]='\0';
    scanf("%s",s);
    scanf("%s",d);
    while(s[l]!='\0')l++;
    while(d[r]!='\0')r++;
    for(int i=0;i<l;i++){
            if(d[0]==s[i]||s[i]=='?'){
                f=true;
                for(int j=1;j<r&&f;j++)if(d[j]!=s[i+j]&&s[i+j]!='?')f=false;
                if(f){
                    last=i;
                }
            }
    }
        if(last!=-1){
    for(int j=0;j<r;j++)s[last+j]=d[j];
    for(int j=0;j<l;j++)if(s[j]=='?')s[j]='a';
    printf("%s\n",s);
            return 0;
        }
    printf("UNRESTORABLE\n");
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int N;
	double ar[1009];
	double sum = 0;
	double ans;
	cin>>N;
	for (int i = 0; i < N; ++i)
	{
		cin>>ar[i];
		sum += 1/ar[i];
		/* code */
	}
	ans = 1/sum;
	cout<<setprecision(10)<<ans<<endl;
	return 0;	
}

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

using namespace std;
using ll = long long;

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

int main() {
  int n;
  cin >> n;
  int p[n];
  rep(i, n) cin >> p[i];

  int ans = 0;
  for (int i = 1; i < n - 1; ++i) {
    if (p[i - 1] < p[i] && p[i] < p[i + 1]) ++ans;
    if (p[i + 1] < p[i] && p[i] < p[i - 1]) ++ans;
  }

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


Measured memory_bytes: 3588
import java.util.*;
	import java.util.Map.Entry;
	 
	 
	 class Main {
		 static int mod =  (int) (Math.pow(10,9)+7);
//		 static int mod =  (int) 998244353;
		 public static void main(String[] args) {
	    	
	        Scanner sc = new Scanner(System.in);
	        int H = sc.nextInt();
	        int W = sc.nextInt();
	        int D = sc.nextInt();
	        int[][] a = new int[H*W][2];
	        for(int i=0;i<H;i++) {
	        	for(int j=0;j<W;j++) {
	        		int tmp=sc.nextInt()-1;
	        		a[tmp][0] = i;
	        		a[tmp][1] = j;
	        	}
	        }
	        
	        int[][] m = new int[D][(H*W)/D+1];
	        for(int i=0;i<D;i++) {
	        	for(int j=i+D;j<H*W;j=j+D) {
	        		m[i][j/D]=m[i][j/D-1]+Math.abs(a[j-D][0]-a[j][0])+Math.abs(a[j-D][1]-a[j][1]);
	        	}
	        }
	        
	        int Q = sc.nextInt();
	        StringBuffer ans= new StringBuffer();
	        for(int i=0;i<Q;i++) {
	        	int l = sc.nextInt()-1;
	        	int r = sc.nextInt()-1;
	        	int tmp = m[r%D][r/D]-m[l%D][l/D];
	        	ans.append(tmp);
	        	ans.append("\n");
	        }
	        
	        System.out.print(ans);
	    }
	}


Measured memory_bytes: 98056
// Problem : D - Even Relation
// Contest : AtCoder - AtCoder Beginner Contest 126
// URL : https://atcoder.jp/contests/abc126/tasks/abc126_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣠⣶⡾⠏⠉⠙⠳⢦⡀⠀⠀⠀
⠀⠀⠀⣴⠿⠏⠀⠀⠀⠀⠀⠀⢳⡀⠀
⠀⠀⢠⣟⣋⡀⢀⣀⣀⡀⠀⣀⡀⣧⠀
⠀⠀⢸⣯⡭⠁⠸⣛⣟⠆⡴⣻⡲⣿⠀
⠀⠀⣟⣿⡭⠀⠀⠀⠀⠀⢱⠀⠀⣿⠀
⠀⠀⠙⢿⣯⠄⠀⠀⠀⢀⡀⠀⠀⡿⠀⠀
⠀⠀⠀⠀⠹⣶⠆⠀⠀⠀⠀⠀⡴⠃⠀⠀
⠀⠀⠀⠀⠀⢸⣷⡦⢤⡤⢤⣞⣁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⢀⣤⣴⣿⣏⠁⠀⠀⠸⣏⢯⣷⣖⣦⡀⠀⠀⠀⠀⠀⠀
⢀⣾⣽⣿⣿⣿⣿⠛⢲⣶⣾⢉⡷⣿⣿⠵⣿⠀⠀⠀⠀⠀⠀
⣼⣿⠍⠉⣿⡭⠉⠙⢺⣇⣼⡏⠀⠀⠀⣄⢸⠀⠀⠀⠀⠀⠀
⣿⣿⣧⣀⣿.........⣀⣰⣏⣘⣆⣀⠀
*/
#include <bits/stdc++.h> 
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define l00p(i, a, b) for (int i=a; i<(b); i++)
#define loop(i, a) for (int i=0; i<(a); i++)
#define rep1(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rep(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
#define imax INT_MAX
#define imin INT_MIN
//#define MOD 998244353
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

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

 
const int MOD = 1000000007;
const char nl = '\n';
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

int main() {
	 
	ios_base::sync_with_stdio(0); cin.tie(0); 
	int n;
	cin>>n;
	vpi a[n];
	loop(i,n-1)
	{
		int k, l,w;
		cin>>k>>l>>w;
		k--,l--;
		a[k].pb({l,w});
		a[l].pb({k,w});
	}
	queue<int> q;
	q.push(0);
	int ans[n];
	loop(i,n)
	ans[i]=-1;
	ans[0]=0;
	while(!q.empty())
	{
		int s=q.front();
		q.pop();
		trav(i,a[s])
		{
			if(ans[i.f]!=-1)
			continue;
			ans[i.f]=(ans[s]+i.s)%2;
			q.push(i.f);
		}
		
	}
	loop(i,n)
	cout<<ans[i]<<nl;
	return 0;
}
// read the question correctly (ll vs int)
// template by bqi343

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int res = max(min(b, d) - max(a, c), 0);
    cout << res << "\n";
    return 0;
}

Measured memory_bytes: 256
A,B = map(int, input().strip().split(' '))
strength = [2,3,4,5,6,7,8,9,10,11,12,13,1]
if strength.index(A) == strength.index(B):
  print('Draw')
elif strength.index(A) < strength.index(B):
  print('Bob')
else:
  print('Alice')

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iomanip>
using namespace std;
int n;
long long a[10000],b[10000];
long long z,f;
int main()
{
    cin>>n;
    for(int i = 0;i < n;i ++)
    {
        cin>>a[i];
    }
    for(int i = 0;i < n;i ++)
    {
        cin>>b[i];
        if(b[i] - a[i] < 0)f += a[i] - b[i];
        else if(b[i] - a[i] > 0)z += (b[i] - a[i]) / 2;
    }
    if(z >= f)cout<<"Yes";
    else cout<<"No";
}

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

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define rep(i,n) for(int i=0; i<(int)(n); i++)
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; }

using ll = long long;
using P = pair<ll, ll>;

//constexpr ll mod = 998244353;
constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, k; cin >> n >> k;
  int p = (n-1)*(n-2)/2;
  int r = p-k;
  if (r < 0) {
    cout << -1 << endl;
    return 0;
  }

  vector<P> graph;
  for(int i=2; i<=n; i++) {
    graph.emplace_back(1, i);
  }
  for(int i=2; i<=n; i++) {
    for(int j=i+1; j<=n; j++) {
      if (r > 0) {
        graph.emplace_back(i, j);
        r--;
      }
    }
  }

  cout << graph.size() << endl;
  for(auto e: graph) {
    cout << e.first << ' ' << e.second << endl;
  }

}

Measured memory_bytes: 512
// sort(b.begin(), b.end());//bという配列を小さい方からソート
//reverse(b.begin(), b.end());//bという配列を逆にソート 
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int64_t n;
  cin >> n;
  vector<int64_t>a(n);
  rep(i,n) cin >> a.at(i);
  sort(a.begin(), a.end());//bという配列を小さい方からソート
  int64_t count=0;
  rep(i,n-1){
    if(a.at(i) ==a.at(i+1) ){
      count++;
      i++;
    }
  }
  cout << n - count *2 <<endl;
}
/* 
  
  
  
  

  rep(i,n){
    if(b.at(a.at(i)) ==0 )b.at(a.at(i))=1;
    else b.at(a.at(i))=0;
  }
  int count=0;
  rep(i,100000){
    if(b.at(i) != 0 ) count++;
  }
  cout << count <<endl;
  
}
*/

Measured memory_bytes: 1024
#include <stdio.h>
int main(){
  int w,h,x,y,r;
  scanf("%d %d %d %d %d ",&w,&h,&x,&y,&r);
  if(x >= 0+r && x <= w-r && y >= 0+r && y <= h-r)printf("Yes\n");else printf("No\n");
  return 0;
}

Measured memory_bytes: 588
import java.util.*;
import java.io.*;
import java.math.BigInteger; 

 public class Main{
// taking inputs
static BufferedReader s1;
static BufferedWriter out;
static String read() throws IOException{String line="";while(line.length()==0){line=s1.readLine();continue;}return line;}
static int int_v (String s1){return Integer.parseInt(s1);}
static long long_v(String s1){return Long.parseLong(s1);}
static int[] int_arr() throws IOException{String[] a=read().split(" ");int[] b=new int[a.length];for(int i=0;i<a.length;i++){b[i]=int_v(a[i]);}return b;}
static long[] long_arr() throws IOException{String[] a=read().split(" ");long[] b=new long[a.length];for(int i=0;i<a.length;i++){b[i]=long_v(a[i]);}return b;}
static void assign(){s1=new BufferedReader(new InputStreamReader(System.in));out=new BufferedWriter(new OutputStreamWriter(System.out));}
// ends

//......................................@uthor_Alx..............................................

   public static void main(String[] args) throws  IOException{
	        		  assign();
              int r= int_v(read());
              double d=(double)2*r*Math.PI;
              out.write(d+"\n");
              out.flush();
	        		 
	}
	       
	          
}

	    

	
  





Measured memory_bytes: 36720
#include <stdio.h>
#include <iostream>

int main(int argc, char** argv)
{
    int P,Q,R;
    std::cin >> P;
    std::cin >> Q;
    std::cin >> R;

    int sum = P+Q;
    if(P+R<sum) sum=P+R;
    if(Q+R<sum) sum=Q+R;

    std::cout << sum;
    
    return 0;
}

Measured memory_bytes: 256
<?php

fscanf(STDIN, '%d', $N);
for ($i = 0; $i < $N; $i++) {
    fscanf(STDIN, '%s', $a);
    fscanf(STDIN, '%s', $b);
    //どちらかが80桁以上
    if (max(strlen($a), strlen($b)) > 80) {
        echo "overflow\n";
        continue;
    }

    //81桁の0埋め整数
    $arr = array_fill(0, 81, 0);
    $a = sprintf('%081s', $a);
    $b = sprintf('%081s', $b);
    //後方からなめていく
    for ($j = 80; $j > 0; $j--) {
        //arrには桁上りで1が入っている可能性があるので加算
        $n = $arr[$j] + $a[$j] + $b[$j];
        //桁上りする
        if ($n >= 10) {
            //1桁の値をarrに
            $arr[$j] = substr($n, 1);
            //一つ前の値を1にする
            $arr[$j - 1] += 1;
        } else {
            $arr[$j] = $n;
        }
    }

    //先頭から0が続いている場合は消す
    $result = preg_replace('/^0+(\d+)$/', '$1', implode('', $arr));
    if (strlen($result) > 80) {
        echo "overflow\n";
    } else {
        echo $result, PHP_EOL;
    }
}

Measured memory_bytes: 6768
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(_i,_a,_n) for(int _i=_a;_i<=_n;++_i)
#define PER(_i,_a,_n) for(int _i=_n;_i>=_a;--_i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(_a) ({REP(_i,1,n) cout<<_a[_i]<<',';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head



#ifdef __APPLE__
const int N = 1e2+50;
#else
const int N = 1e6+50;
#endif


int n,a[N],dp[N],vis[N];

int main() {
	scanf("%d", &n);
	REP(i,1,n) { 
		scanf("%d",a+i);
		if (a[i]==a[i-1]) --i,--n;
	}
	dp[1] = vis[a[1]] = 1;
	REP(i,2,n) {
		dp[i] = (dp[i-1]+dp[vis[a[i]]])%P;
		vis[a[i]] = i;
	}
	printf("%d\n", dp[n]);
}








Measured memory_bytes: 9216
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

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

    ll a[n], b[n];
    ll MOD = 1e9+7;
    rep(i,n){
        cin >> a[i];
        b[i] = 1;
    }

    srep(k,2,1001){
        int c[n] = {};
        int ma = 0;
        rep(i,n){
            while(a[i] % k == 0){
                c[i]++;
                a[i] /= k;
            }
            ma = max(ma, c[i]);
        }
        if(ma > 0){
            rep(i,n){
                rep(j,ma - c[i]){
                    b[i] *= k;
                    b[i] %= MOD;
                }
            }
        }
    }

    rep(i,n){
        if(a[i] > 1){
            ll tmp = a[i];
            rep(j,n){
                if(a[j] % tmp == 0){
                    a[j] /= tmp;
                }else{
                    b[j] *= tmp;
                    b[j] %= MOD;
                }
            }
        }
    }

    ll ans = 0;
    rep(i,n)ans = (ans + b[i]) % MOD;
    cout << ans << endl;
    return 0;
}
 
 


Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 準備
            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();
            List<string> lstOrg = new List<string>() { "3", "5", "7" };
            List<string> lstAll = new List<string>() { "3", "5", "7" };
            List<int> lstAdd = new List<int>();
            for (int i = 0; i < lstAll.Count; i++) { lstAdd.Add(i); }
            while (true)
            {
                List<int> lstNew = new List<int>();
                int iCnt = lstAdd.Count;
                if (iCnt == 0) { break; }
                for (int j = 0; j < iCnt; j++)
                {
                    for (int i = 0; i < 3; i++)
                    {
                        lstAll.Add(lstAll[lstAdd[j]] + lstOrg[i]);
                        lstNew.Add(lstAll.Count - 1);
                    }
                }
                lstAdd.Clear();
                lstAdd.AddRange(lstNew);
                if (lstAll[lstAll.Count - 1].Length == 9) { break; }
            }
            List<int> lstAl2 = new List<int>();
            for (int i = 0; i < lstAll.Count; i++)
            {
                if (lstAll[i].Length > 2)
                {
                    if (lstAll[i].Contains("3") && lstAll[i].Contains("5") && lstAll[i].Contains("7"))
                    {
                        lstAl2.Add(int.Parse(lstAll[i]));
                    }
                }
            }
            //DebugDisp(lstAl2);

            // 入力
            int iN = int.Parse(System.Console.ReadLine().Trim());


            // 解析
            int iOut = 0;
            for (int i = 0; i < lstAl2.Count; i++)
            {
                if (iN >= lstAl2[i]) { iOut += 1; }
                else { break; }
            }

            // 出力
            System.Console.WriteLine("{0}", iOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

        // Debug表示
        private static void DebugDisp(List<int> lstAl2)
        {
            Console.WriteLine();
            Console.WriteLine("{0}", lstAl2.Count.ToString().Trim());
            for (int i = 0; i < lstAl2.Count; i++)
            {
                Console.WriteLine("{0}", lstAl2[i].ToString().Trim());
                if (i > 20) { break; }
            }
        }

}


Measured memory_bytes: 14432
#include <bits/stdc++.h>
using namespace std;
#define vsort(vec) sort(vec.begin(), vec.end())
#define vreverse(vec) reverse(vec.begin(), vec.end())
using ll =long long;
const ll INF =1001001001;

//最大公約数
ll gcd(ll a, ll b){
   if (a%b==0){
       return(b);
   }else{
       return(gcd(b,a%b));
   }
}
//最小公倍数
ll lcm(ll a, ll b){
   return a*b/gcd(a,b);
}

//素数判定
ll isprime(ll n){
  bool prime=true;
  for(int i=2;i<n;i++){
    if(n%i==0){
      prime=false; break;
    }
  }
if(prime){cout<<n<<" is prime"<<endl;
         }else{cout<<n<<" is not prime"<<endl;}

}
//階乗　20くらいが限界
ll factorial(ll n){
  ll a=1;ll b=n;
  for(int i=0;i<n;i++){
    a*=b;
    b--;
  }
  return a;
}

//組み合わせ　nCr
ll comb(ll a,ll b){
  ll c;
  c=factorial(a)/(factorial(a-b)*factorial(b));
  return c; 
}




/*10億7。　　　100000007
2*2行列 H*W
vector<vector<int>> vec(H,vector<int>(W));
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
cin>>vec[i][j];
  }
}

文字列→数列
string S;int A=atoi(S.c_str());
数列→文字列
int A;string S=to_string(A);
数字判定　isdigit(a)
pair宣言　pair<int,int> p(5,7);
ソート　sort(vec.begin(),vec.end());
*/

int main(){
cout<<fixed<<setprecision(10);


  int a,b;cin>>a>>b;
  if(a*b%2==0){
    cout<<"Even"<<endl;
  }else{
    cout<<"Odd"<<endl;}
  
  
  
  
}




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


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int n = sc.nextInt();

		for (int i = 0; 4 * i <= 100; i++) {
			for (int j = 0; 4 * i + 7 * j <= 100; j++) {
				if (4 * i + 7 * j == n) {
					pr.println("Yes");
					return;
				}
			}
		}
		
		pr.println("No");
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(INPUT == null ? System.in : new ByteArrayInputStream(INPUT.getBytes()));
		pr = new Printer(System.out);

		solve();

//		pr.close();
		pr.flush();
//		sc.close();
	}

	static String INPUT = null;

	private static class Printer extends PrintWriter {
		Printer(OutputStream out) {
			super(out);
		}
	}
}


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

#define Fast            ios_base::sync_with_stdio(false);cin.tie(nullptr);
#define LL              long long
#define ff              first
#define ss              second
#define pb              push_back
#define pii             pair<int,int>
#define all(a)          a.begin(),a.end()
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)

int main()
{
    int n;
    cin >> n;
    map<string,int>mp;
    int mx=0;
    REP(i,n){
        string s;
        cin >> s;
        mp[s]++;
        mx=max(mx,mp[s]);
    }
    for(auto p:mp) if(p.ss==mx) cout << p.ff << '\n';
}



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

#define int long long
int v[10000001],ans=1,a[10000001];

signed main(){
  int n;cin>>n;
  for(int i=0;i<=n;i++)v[i]=a[i]=i;
  for(int i=2;i<=n;i++){
    if(v[i]>1)a[i]*=2;
    ans+=a[i];
    if(v[i]==i)
      for(int j=i*i;j<=n;j+=i){
        int cnt=1;
        while(v[j]%i==0)cnt++,v[j]/=i;
        a[j]*=cnt;
      }
  }
  cout<<ans<<endl;
}


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

int main( void )
{
    int n, k, x, y;
    int ans = 0;
    cin >> n >> k >> x >> y;
    for ( int i = 0; i < n; i++ )
    {
        if ( i < k )
        {
            ans += x;
        }
        else
        {
            ans += y;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <tuple>

using ll = long long;
using namespace std;
#define modmod 1000000007

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


int main(){
    int N;
    cin >> N;
    ll a[N];

    ll count_p = 0;
    ll count_m = 0;
    ll count;
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }

    // minus始まり
    ll sum_m = 0;
    for(int i = 0; i < N; i++){
        sum_m += a[i];
        if(i%2 == 0){
            // minus
            if(sum_m < 0){
                continue;
            }else{
                count_m += sum_m + 1;
                sum_m = -1;
            }
        }else{
            // plus
            if(sum_m > 0){
                continue;
            }else{
                count_m += abs(sum_m) + 1;
                sum_m = 1;
            }
        }
    }

    // plus始まり
    ll sum_p = 0;
    for(int i = 0; i < N; i++){
        sum_p += a[i];
        if(i%2 != 0){
            // minus
            if(sum_p < 0){
                continue;
            }else{
                count_p += sum_p + 1;
                sum_p = -1;
            }
        }else{
            // plus
            if(sum_p > 0){
                continue;
            }else{
                count_p += abs(sum_p) + 1;
                sum_p = 1;
            }
        }
    }

    count = min(count_m,count_p);

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 1152
#include <stdio.h>
#include <string.h>
#define max(a, b) ((a) > (b) ? (a) : (b))

int main(void)
{
    long ans = 0;

    char s[500001];
    scanf("%s", s);

    int a[strlen(s) + 1] = {0};
    for (int i = 0; i < strlen(s); i++)
        if (s[i] == '<')
            a[i + 1] = max(a[i] + 1, a[i + 1]);
    /*
    for (int i = 0; i < strlen(s) + 1; i++)
        printf("%d ", a[i]);
    printf("\n");
    */

    for (int i = strlen(s); i > 0; i--)
        if (s[i - 1] == '>')
            a[i - 1] = max(a[i] + 1, a[i - 1]);
    /*
    for (int i = 0; i < strlen(s) + 1; i++)
        printf("%d ", a[i]);
    printf("\n");
    */

    for (int i = 0; i < strlen(s) + 1; i++)
        ans += a[i];
    printf("%ld\n", ans);

    return 0;
}

Measured memory_bytes: 2560
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextssort(n,a){return a?cin.slice(cid,cid+=n).map(a=>+a).sort((a,b)=>b-a):cin.slice(cid,cid+=n).map(a=>+a).sort((a,b)=>a-b);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}
var streams=[];function print(s){streams.push(s);}
var mod = 1e9+7;
function mul(){for(var a=arguments,r=a[0],i=a.length;--i;)r=((r>>16)*a[i]%mod*65536+(r&65535)*a[i])%mod;return r;}
var fac=[],finv=[],invs=[],pow2=[];
function fset(n){
  fac.length=n+1,fac[0]=fac[1]=1;
  for(var i=2;i<=n;)fac[i]=mul(fac[i-1],i++);
  finv.length=n+1,finv[0]=finv[1]=1,finv[n]=inv(fac[n]);
  for(i=n;2<i;)finv[i-1]=mul(finv[i],i--);
  //invs.length=n+1,invs[0]=invs[1]=1;
  //for(i=2;i<=n;)invs[i]=mul(fac[i-1],finv[i++]);
  //pow2.length=n+1,pow2[0]=1;
  //for(i=1;i<=n;i++)pow2[i]=pow2[i-1]*2%mod;
}
function inv(b){for(var a=mod,u=0,v=1,t;b;v=t)t=a/b|0,a-=t*b,u-=t*v,t=a,a=b,b=t,t=u,u=v;u%=mod;return u<0?u+mod:u;}
function pow(a,n){for(var r=1;n;a=mul(a,a),n>>=1)if(n&1)r=mul(a,r);return r;}
function ncr(n,r){return mul(fac[n],finv[r],finv[n-r]);}
function npr(n,r){return mul(fac[n],finv[n-r]);}
function mput(n){return (n%mod+mod)%mod;}


var myOut = main();
if(myOut !== undefined)console.log(String(myOut));
if(streams.length)console.log(streams.join("\n"));

function main(){
  var s = next();
  var dp = xArray(0,s+1);
  dp[0] = 1;
  for(var i = 0; i < s; i++){
    for(var j = 3; j <= s; j++){
      if(i+j > s)break;
      dp[i+j] += dp[i];
      dp[i+j] %= mod;
    }
  }
  return dp[s];
}

Measured memory_bytes: 32436
#include <stdio.h>
int n, r;
int main() {
	scanf("%d", &n); r = n;
	for(int i = 2; i * i <= n; i++) {
		if(n % i == 0) r = 1LL * r * (i - 1) / i;
		while(n % i == 0) n /= i;
	}
	if(n != 1) r = 1LL * r * (n - 1) / n;
	printf("%d\n", r);
	return 0;
}

Measured memory_bytes: 2728
a = list(input())
b = list(input())
a_l = len(a)
b_l = len(b)
f = False
for i in range(1,a_l-b_l+2):
    f = True
    for j in range(1,b_l+1):
        if not(b[b_l-j] == a[a_l-i-j+1] or a[a_l-i-j+1] == "?"):
            f = False
            break
    if f:
        for j in range(1,b_l+1):
            a[a_l-i-j+1] = b[b_l-j]
        break
 
if f:
    print("".join(a).replace("?", "a"))
else:
    print("UNRESTORABLE")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int a[200001], arr[200001];
long long comb[200001];
int n;
int main(){
	memset(a,0,sizeof(a));
	memset(comb,0,sizeof(comb));
	cin >> n;
	for(int i = 0 ; i < n ;i++)
	{
		cin >> arr[i];
		a[arr[i]]++;
	}

    long long int sum = 0;
    for(int i = 1 ;i <= 2e5 ; i++){
    	if(a[i] > 1){
    		comb[i] = (long long)a[i]*(a[i]-1)/2;
    		sum += comb[i];
    	}
    }
    for(int i = 0 ; i< n ;i++){
    	if(a[arr[i]] == 1)cout<<sum<<"\n";
    	else {
    		cout<<sum-a[arr[i]]+1<<"\n";
    	}
    }
    cout<<"\n";
	
}

Measured memory_bytes: 5760
using System;

namespace ABC099
{
    class Program
    {
        static void Main(string[] args)
        {
            int input = int.Parse(Console.ReadLine());

            if (input<1000)
            {
                Console.WriteLine("ABC");
            }
            else
            {
                Console.WriteLine("ABD");
            }

        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
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 EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

// https://atcoder.jp/contests/dp/tasks/dp_i

double dp[3500][3500];

int main() {
  int N; cin >> N;
  double p[N]; REP(i, N) cin >> p[i];

  dp[0][0] = 1.0;
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j <= i; j++) {
      if(j>0)dp[i][j] += dp[i-1][j-1] * p[i-1];
      dp[i][j] += dp[i-1][j] * (1-p[i-1]);
    }
  }

  double ans = 0;
  for (int i = N/2+1; i <= N; i++) {
    ans+=dp[N][i];
  }
  printf("%0.12f\n", ans);


  return 0;
}


Measured memory_bytes: 50272
#include <cstdio>
#include <algorithm>
#include <vector>

int main() {
  size_t n, m;
  int X, Y;
  scanf("%zu %zu %d %d", &n, &m, &X, &Y);

  std::vector<int> x(n), y(m);
  for (size_t i=0; i<n; ++i)
    scanf("%d", &x[i]);

  for (size_t i=0; i<m; ++i)
    scanf("%d", &y[i]);

  std::sort(x.begin(), x.end());
  std::sort(y.begin(), y.end());

  if (x[n-1] >= y[0])
    return !printf("War\n");

  bool ok=false;
  for (int Z=X+1; Z<=Y; ++Z)
    if (x[n-1] < Z && Z <= y[0]) ok = true;

  if (ok) printf("No ");
  printf("War\n");
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <functional>
#include <map>
using namespace std;

string S; int c1 = 0, c2 = 0;

int main() {
	cin >> S;
	for (int i = 0; i < S.size(); i++) {
		char B = '0'; if (i % 2 == 1) B = '1';
		if (S[i] == B) c2++;
		else c1++;
	}
	cout << min(c1, c2) << endl;
	return 0;
}

Measured memory_bytes: 512