akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

int main() {

	int a,p;
	cin>>a>>p;

	a=a*3;

	cout<<(a+p)/2<<endl;
	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)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

int gcd(int a, int b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;  cin >> n >> k;
    vector<int> x(n);
    rep(i, n) {
      cin >> x[i];
    }
    int ans = 0;
    rep(i, n) {
      ans += min(x[i] * 2, abs(x[i] - k) * 2);
    }
    cout << ans << '\n';

    return 0;
}


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

using namespace std;

long long GCD(long long a, long long b)
{
	if (max(a, b) % min(a, b) == 0) { return min(a, b); }

	return GCD(min(a, b), max(a, b) % min(a, b));
}

long long LCM(long long a, long long b)
{
	return a / GCD(a, b) * b;
}

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

	vector<int> a(N);

	for (int i = 0; i < N; i++)
		cin >> a[i];

	for (int i = 1; i < N; i++)
		a[i] = LCM(a[i], a[i - 1]);

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

	return 0;
}

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

int main(){
  int a[5];
  int k;
  bool flag = true;
  for (int i=0;i<5;i++){
    cin >> a[i];
  }
  cin >> k;
  if (a[4] - a[0] > k) flag = false;

  if (flag) cout << "Yay!" << endl;
  else cout << ":(" << endl;

  return 0;
}


Measured memory_bytes: 256
var
 i,x,s,sum:longint;
begin
 for i:=1 to 3 do
  begin
   read(x);
   if x=5 then inc(s);
   if x=7 then inc(sum);
  end;
 if (s=2) and (sum=1) then writeln('YES')
                           else writeln('NO');
end.

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

using namespace std;

bool is_odd(int n) {
    int cnt  = 0;
    while(n) {
        n /= 10;
        cnt++;
    }
    return (cnt % 2 == 1);
}
int main() {
    int n; cin >> n;
    int res = 0;
    for(int i = 1; i <= n; i++) {
        res += is_odd(i);
    }
    cout << res;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,char> P;
int partition(P* A,int p,int r){
  int x=A[r].first;
  int i=p-1;
  for(int j=p;j<r;j++){
    if(A[j].first<=x){
      i++;
      swap(A[i],A[j]);
    }
  }
  swap(A[i+1],A[r]);
  return i+1;
}
void quicksort(P* A,int p,int r){
  if(p<r){
    int q=partition(A,p,r);
    quicksort(A,p,q-1);
    quicksort(A,q+1,r);
  }
}
signed main(){
  int n;
  cin>>n;
  P A[n];
  for(int i=0;i<n;i++) cin>>A[i].second>>A[i].first;
  map<int,string> m1,m2;
  for(int i=0;i<n;i++) m1[A[i].first]+=A[i].second;
  quicksort(A,0,n-1);
  for(int i=0;i<n;i++) m2[A[i].first]+=A[i].second;
  bool flag=1;
  for(int i=0;i<n;i++) flag&=m1[A[i].first]==m2[A[i].first];
  if(flag) cout<<"Stable"<<endl;
  else cout<<"Not stable"<<endl;
  for(int i=0;i<n;i++){
    cout<<A[i].second<<" "<<A[i].first<<endl;
  }
  return 0;
}

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

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)

int main() {
    int n,r;
	cin >> n>>r;
    if(n>=10){
        cout<<r;
    }else{
        cout<<r+100*(10-n);
    }
	return 0;
}

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

int main(){
    string s;
    cin >> s;
    int n = s.size();
    bool b1 = true, b2 = true, b3 = true;
    for(int i=0; i<n; i++){
        if(s[i] != s[n-1-i]){
            b1 = false;
        }
    }
    for(int i=0; i<(n-1)/2; i++){
        if(s[i] != s[(n-1)/2-1-i]){
            b2 = false;
        }
    }
    for(int i=0; i+(n+3)/2-1<n; i++){
        if(s[i+(n+3)/2-1] != s[n-1-i]){
            b3 = false;
        }
    }
    if(b1 && b2 && b3) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main() {
    int n, m;
    int a[10], count[10], tmp[10];
    string id;
    cin >> n >> id >> m;
    for (int i = 0; i < m; ++i) {
        cin >> a[i];
    }
    count[0] = 1;
    for (int i = 1; i < 10; ++i) {
        count[i] = 0;
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 10; ++j) {
            tmp[j] = 0;
        }
        if ((n - i) % 2 == 0) {
            if (id[i] == '*') {
                for (int j = 0; j < m; ++j) {
                    for (int k = 0; k < 10; ++k) {
                        int x = (a[j] < 5? a[j] * 2: a[j] * 2 - 10 + 1);
                        tmp[(k + x) % 10] += count[k];
                    }
                }
            } else {
                for (int j = 0; j < 10; ++j) {
                    int x = (id[i] < '5'? (id[i] - '0') * 2: (id[i] - '0') * 2 - 10 + 1);
                    tmp[(j + x) % 10] += count[j];
                }
            }
        } else {
            if (id[i] == '*') {
                for (int j = 0; j < m; ++j) {
                    for (int k = 0; k < 10; ++k) {
                        tmp[(k + a[j]) % 10] += count[k];
                    }
                }
            } else {
                for (int j = 0; j < 10; ++j) {
                    tmp[(j + id[i] - '0') % 10] += count[j];
                }
            }
        }
        for (int j = 0; j < 10; ++j) {
            count[j] = tmp[j];
        }
    }
    cout << count[0] << endl;

    return 0;
}

Measured memory_bytes: 1332
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
using namespace std;
int main(void){
  int x;
  cin>>x;
  if(x<1200){
    cout<<"ABC"<<endl;
  }else{
    cout<<"ARC"<<endl;
  }
}

Measured memory_bytes: 256
from sys import stdin


class UnionFind(object):
    def __init__(self, n):
        self.parent = {i: i for i in range(1, n + 1)}
        self.size = {i: 1 for i in range(1, n + 1)}

    def find(self, a):
        if self.parent[a] != a:
            self.parent[a] = self.find(self.parent[a])
        return self.parent[a]

    def unite(self, a, b):
        a = self.find(a)
        b = self.find(b)
        if a == b:
            return
        if self.size[a] > self.size[b]:
            self.size[a] += self.size[b]
            self.parent[b] = a
        else:
            self.size[b] += self.size[a]
            self.parent[a] = b

    def isunited(self, a, b):
        return self.find(a) == self.find(b)


n, m = [int(x) for x in stdin.readline().rstrip().split()]
l = [tuple(int(x) for x in stdin.readline().rstrip().split()) for _ in range(m)][::-1]

uf = UnionFind(n)
ans = []
v = n * (n - 1) // 2

for a, b in l:
    ans.extend([v])
    if not uf.isunited(a, b):
        v -= uf.size[uf.find(a)] * uf.size[uf.find(b)]
    uf.unite(a, b)

print(*ans[::-1], sep="\n")

Measured memory_bytes: 128984
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
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; }
#define ALL(v) v.begin(), v.end()
typedef long long ll;



int main(){
    string s;cin>>s;
    int ans=0;

    for(int i=0;i<s.length()/2;i++){
        if(s[i]!=s[s.length()-i-1])ans++;
    }
    cout << ans << endl;
    
    return 0;
}





Measured memory_bytes: 256
package main

import (
  "fmt"
)

func main() {
  var (
    a,b,k int
    tmp int
  )
  fmt.Scan(&a)
  fmt.Scan(&b)
  fmt.Scan(&k)

  tmp = a
  if a > b {
    tmp = b;
  }

  count:=0
  for i:=tmp;i>0;i-- {
    if a % i == 0 && b % i == 0 {
      count++
    }
    if count == k {
      fmt.Println(i)
      break
    }
  }
}


Measured memory_bytes: 512
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	a := scanInts(n)

	m := 1000
	k := 0
	for i := 0; i < n-1; i++ {
		if a[i] < a[i+1] {
			k += m / a[i]
			m -= (m / a[i]) * a[i]
		}
		if a[i] > a[i+1] {
			m += k * a[i]
			k = 0
		}
	}
	m += k * a[n-1]
	fmt.Fprintln(wr, m)
}


Measured memory_bytes: 1784
n, a, b = map(int,input().split())
lists =[]

for i in range(1, n+1, 1):
  lists.append(i)

z = 0
for j in lists:
  h = str(j)
  x = 0
  for k in h:
    x += int(k)
  if x >=a and x <= b:
    z += j
print(z)

Measured memory_bytes: 3316
#include<iostream>
#include<string>
using namespace std;
int main(){
	string n;
	cin>>n;
	for(int i=0;i<n.size();i++){
		if(n[i]=='1')n[i]='9';
		else if(n[i]=='9')n[i]='1';
	}
	cout<<n<<endl;
	return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//  競技20190629

#include <iostream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
#define ll long long int

int br(){
    printf("\n");
    return 0;
}
ll combi(int n, int k) {
    if (n == k || k == 0)
        return 1;
    else {
        return combi(n - 1, k - 1) + combi(n - 1, k);
    }
}
int gcd(int a,int b){//最大公約数
    if(b==0){
        return a;
    }else{
        return gcd(b,a%b);
    }
}


//sort(a,a+100,greater<int>());大きい順
//sort(a,a+100);小さい順
/*
 int N;
 cin >> N;
 vector<int> d(N);
 int i = 0;
 int n = N;
 while(n--){
 cin >> d[i];
 i++;
 }
 
 sort(d.begin(),d.end());
 d.erase( unique(d.begin(),d.end()), d.end());隣り合った重複を削除し、き消し多分要素数を詰める
 cout<<d.size()<<endl;
 return 0;
*/

int X(){
    string s;
    cin >> s;
    size_t size = s.length();
    
    string ans;
    
    for(int i=0;i<size;i++){
        if(i%2==0){
            ans = ans+s[i];
            
        }
    }
    cout << ans << endl;
    
    return 0;
}

int Ap(){
    string s;
    cin >> s;
    if(s[0]==s[1] && s[1]==s[2] && s[2]==s[3]){return printf("No\n");}
    if(s[0]==s[1] && s[2]==s[3]){return printf("Yes\n");}
     if(s[0]==s[2] && s[1]==s[3]){return printf("Yes\n");}
     if(s[0]==s[3] && s[1]==s[2]){return printf("Yes\n");}
  return printf("No\n");
}

int mymid(int a,int b,int c){
    if(a>=b && b>=c )return b;
    if(a<=b && b<=c )return b;
    return -1;
}

int Bp(){
    int N;
    cin >> N;
    int p[N];
    for(int i=0;i<N;i++){cin >> p[i];}
    int ans=0;
    for(int i=1;i<N-1;i++){
        if(mymid(p[i-1],p[i],p[i+1])==p[i])ans++;
    }
    printf("%d\n",ans);
    return 0;
}

int Cp(){
    int N;
    cin >> N;
    vector<int> d(N);
    int i = 0;
    int nn = N;
    while(nn--){
        cin >> d[i];
        i++;
    }
    sort(d.begin(),d.end());
    printf("%d\n",d[N/2]-d[N/2-1]);
    return 0;
}


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


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int mod=1e9+7;
int f(int n){
	if(n==0) return 1;
	if(n==1) return 2;
	return (long long int)(f(n/2)%mod)*(long long int)(f(n-n/2)%mod)%mod;
}
int main(){
	int n;
	cin>>n;
	vector<int>a(n,0);
	int tmp;
	for(int i=0;i<n;i++){
		cin>>tmp;
		a[tmp]++;
	}
	for(int i=0;i<n;i++){
		if(n%2==0){
			if((i%2==1&&a[i]!=2)||(i%2==0&&a[i]!=0)){
				cout<<"0"<<endl;
				return 0;
			}
		}else{
			if((i==0&&a[i]!=1)||(i%2==1&&a[i]!=0)||(i!=0&&i%2==0&&a[i]!=2)){
				cout<<"0"<<endl;
				return 0;
			}
		}
	}
	n=(n%2==1)?(n-1)/2:n/2;
	cout<<f(n)<<endl;
	return 0;
}

Measured memory_bytes: 640
N=int(input())
A=sorted([int(i) for i in input().split()],reverse=True)
B=[2**(len(bin(i))-2) for i in A]
D=dict()
for i in range(N):
    if not(A[i] in D):
        D[A[i]]=1
    else:
        D[A[i]]+=1
ans=0
for i in range(N):
    if D[A[i]]<=0:
        continue
    if B[i]==2*A[i]:
        if D[A[i]]>=2:
            D[A[i]]-=2
            ans+=1
    else:
        if (B[i]-A[i]) in D:
            if D[B[i]-A[i]]!=0:
                D[A[i]]-=1
                D[B[i]-A[i]]-=1
                ans+=1
print(ans)


Measured memory_bytes: 41292
#include<bits/stdc++.h>
using namespace std;
int main(){

    int n;cin>>n;
    long long l[n];
    for(int i=0;i<n;i++) cin>>l[i];
    int ans = 0;
    sort(l,l+n);
    for(int i=0;i<n;i++){
        for(int j=0;j<i;j++){
            for(int k=0;k<j;k++){
                if(l[k]!= l[j] and l[j] != l[i] and l[k]+l[j] > l[i]){
                    ans++;
                }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()

Int INF = 1e18;
Int mod = 1e9+7;
//Int mod = 998244353;

typedef struct {
    double y, x;
} p_t;

string to_str(Int x) {
    string s = "";
    while (x > 0) {
        char a = '0' + (x % 10);
        s = a + s;
        x /= 10;
    }
    return s;
}

int main() {
    Int h, a;
    cin >> h >> a;
    dump(h / a + (h % a == 0 ? 0 : 1));
    return 0;
}


Measured memory_bytes: 256
(let* ((n (read))
       (m (read))
       (k (read))
       (a (make-array `(,(1+ n)) :initial-element 0))
       (b (make-array `(,(1+ m)) :initial-element 0))
       (bestj m)
       (ans 0))
  ; read
  (loop :with acc := 0
        :for i :from 1 :to n
        :do (setf (aref a i) (incf acc (read))))
  (loop :with acc := 0
        :for i :from 1 :to m
        :do (setf (aref b i) (incf acc (read))))
  ;
  (loop :for i :from 0 :to n
        :do (loop :named inner
                  :for j :downfrom bestj :to 0
                  :if (<= (+ (aref a i) (aref b j)) k)
                  :do (progn
                        (setf ans (max ans (+ i j)))
                        (setf bestj j)
                        (return-from inner))))
  (format t "~A~%" ans))


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

const long long INF = 1LL<<60;

long long dp[100010];

int main() {
    int n;
    cin >> n;
    vector<long long> h(n);
    for(int i = 0; i < n; i++)
    {
        cin >> h.at(i);
    }
    for(int i = 0; i < 100010; i++)
    {
        dp[i] = INF;
    }
    
    dp[0] = 0;
    for(int i = 1; i < n; i++)
    {
        dp[i] = min(dp[i], (dp[i - 1] + abs(h.at(i) - h.at(i - 1))));
        if (i > 1) dp[i] = min(dp[i], dp[i - 2] + abs(h.at(i) - h.at(i - 2)));
    }

    cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1792
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        string A = Console.ReadLine();
        string B = Console.ReadLine();
        if (A.Length > B.Length)
        {
            Console.WriteLine("GREATER");
            return;
        }
        else if (A.Length < B.Length)
        {
            Console.WriteLine("LESS");
            return;
        }

        for(int i = 0; i < A.Length; i++)
        {
            if(A[i] > B[i])
            {
                Console.WriteLine("GREATER");
                return;
            }
            else if (A[i] < B[i])
            {
                Console.WriteLine("LESS");
                return;
            }
        }
        Console.WriteLine("EQUAL");
    }
}


Measured memory_bytes: 13140
n, m = map(int, input().split())
ex = [0 for i in range(n)]
fri = {}

for i in range(m):
    a, b = map(int, input().split())
    if ex[a-1] == 0 and ex[b-1] == 0:
        if a > b:
            a, b = b, a
        ex[a-1] = a
        ex[b-1] = a
        fri[a] = [a, b]
    elif ex[a-1] == 0:
        ex[a-1] = ex[b-1]
        fri[ex[b-1]].append(a)
    elif ex[b-1] == 0:
        ex[b-1] = ex[a-1]
        fri[ex[a-1]].append(b)
    elif ex[a-1] == ex[b-1]:
        continue
    else:
        shozoku = min(ex[a-1], ex[b-1])
        mu = max(ex[a-1], ex[b-1])
        for j in range(len(fri[mu])):
            ex[fri[mu][j]-1] = shozoku
        fri[shozoku].extend(fri.pop(mu))

ans = 1
for key in fri:
    ans = max(ans, len(fri[key]))
print(ans)

Measured memory_bytes: 27744
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int n;cin>>n;
  	int gokei=0;
  	vector<int> a(2*n);
  	for(int i=0;i<2*n;i++) cin>>a.at(i);
  	sort(a.begin(),a.end());
  	for(int i=0;i<2*n;i++){
    	if(i%2==0) gokei+=a.at(i);
    }
  	cout<<gokei<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
using pr = pair<ll, ll>;
 
ll KnapsackDP(vector<pr>&sack, int w) {
	vector<vector<ll>>dp(sack.size() + 1, vector<ll>(w + 1, 0));
	sort(sack.begin(), sack.end());

	ll m = 0;

	for (int i = 0; i < sack.size(); ++i)
		for (int j = 0; j <= w; ++j) {
			if (j - sack[i].first >= 0)
				dp[i + 1][j] = max(dp[i][j], dp[i][j - sack[i].first] + sack[i].second);
			else
				dp[i + 1][j] = dp[i][j];
			m = max(m, dp[i + 1][j]);
		}

	return m;
}
 
int main() {
	/*fio;
	int n = 10;
	vector<vector<short>>board(n, vector<short>(n, 0));
 
	MoveOfAKnight(board, 0, 0);
 
	for (auto &x : board) {
		for (auto y : x)
			cout << ((y < 10) ? "0" : "") << y << " ";
		cout << endl;
	}*/
	int N, W, w, c;
	cin >> N >> W;
	vector<pr>sack;
	for (int i = 0; i < N; ++i) {
		cin >> w >> c;
		sack.push_back({ w, c });
	}
	cout << KnapsackDP(sack, W) << endl;
}

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

int main(){
  int n, m;  scanf("%d%d", &n, &m);
  int maxl = 0, minr = n;
  for(int i=0; i<m; i++){
    int l, r;  scanf("%d%d", &l, &r);
    maxl = max(maxl, l);
    minr = min(minr, r);
  }
  int ans = minr - maxl + 1;
  ans = ans>0 ? ans : 0;
  printf("%d\n", ans);
  
  return 0;
}


Measured memory_bytes: 128
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		try (Scanner sc = new Scanner(System.in);) {
			
			String W = sc.next();
			
			List<String> list = new ArrayList<>();
			
			while(true) {
				String word = sc.next();
				
				if(word.equals("END_OF_TEXT")) break;
				
				word = word.toLowerCase();
				
				if(word.endsWith(".")) {
					word = word.substring(0, word.length() - 1);
				}
				
				list.add(word);
			}
			
			long count = list.stream().filter(e -> e.equals(W)).count();
			
			System.out.println(count);
		}
	}
}


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

typedef long long ll;
#define int ll
#define pb push_back
const int INF = 1e18, MOD = 1e9+7;

signed main(){

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

	int n,k;
	cin>>n>>k;
	int arr[n+1];
	for(int i=1;i<=n;i++)
		cin>>arr[i];

	vector<int> dp(k+1,1), next(k+1,0);
	for(int i=1;i<=n;i++){
		next[0]= 1;
		for(int j=1;j<=k;j++){
			int left = max(0ll, j-arr[i]);
			next[j] = (left == 0) ? dp[j]: dp[j] - dp[left-1];
		}
		for(int j=1;j<=k;j++)
			next[j] = (next[j] + next[j-1])%MOD;
		for(int j=0;j<=k;j++)
			dp[j] = next[j];
	}


	if (k!= 0) cout<<(dp[k]-dp[k-1] + MOD)%MOD;
	else cout<<1;

	return 0;
}

Measured memory_bytes: 1792
N = int(input())
S = input()

n = s = e = w = 0
for c in S:
  if 'A' <= c <= 'M':
    n += 1
  elif 'N' <= c <= 'Z':
    s += 1
  elif 'a' <= c <= 'm':
    e += 1
  else:
    w += 1

my = min(n,s)
n -= my
s -= my
mx = min(e,w)
e -= mx
w -= mx

ans = 'A'*n + 'N'*s + 'a'*e + 'n'*w
print(len(ans))
print(ans)


Measured memory_bytes: 5784
#include <stdio.h>

int main(void)
{
    int a, b;

    scanf("%d", &a);
    scanf("%d", &b);

    if(a == b){
        printf("a == b\n");
    }else if(a < b){
        printf("a < b\n");
    }else{
        printf("a > b\n");
    }
    return 0;
}


Measured memory_bytes: 2052
#include <stdio.h>

int main() {
  int i, j, tmp;
  int heights[10];

  for (i = 0; i < 10; i++)
    scanf("%d", &heights[i]);

  for (i = 0; i < 9; i++)
    for (j = i + 1; j < 10; j++)
      if (heights[i] < heights[j]) {
        tmp = heights[i];
        heights[i] = heights[j];
        heights[j] = tmp;
      }

  printf("%d\n%d\n%d\n", heights[0], heights[1], heights[2]);

  return 0;
}

Measured memory_bytes: 0
from scipy.sparse.csgraph import dijkstra, csgraph_from_dense
import numpy as np

H, W = map(int, input().split())
S = [input() for _ in range(H)]

v_id_dict = {}
dista = np.ones((400, 400)) * np.inf

for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            v_id_dict[i, j] = len(v_id_dict)

            if (i > 0) and (S[i - 1][j] == "."):
                dista[v_id_dict[(i, j)], v_id_dict[(i - 1, j)]] = 1

            if (j > 0) and (S[i][j - 1] == "."):
                dista[v_id_dict[(i, j)], v_id_dict[(i, j - 1)]] = 1

dist_mat = dijkstra(
    csgraph_from_dense(dista[: len(v_id_dict), : len(v_id_dict)]),
    directed=False,
    unweighted=False,
)

print(int(dist_mat.max()))


Measured memory_bytes: 19780
N,K = map(int,input().split())
D = list(map(int,input().split()))
ans = N
while ans <= 10**6:
  flg = True
  for i in range(len(str(ans))):
    if int(str(ans)[i]) in D:
      flg = False
  if flg == True:
    print(ans)
    exit()
  else:
    ans += 1

Measured memory_bytes: 3060
const Main = (input) => {
  const line = input.split('\n')
  const weather = line[0].toString()
  let count = 0

  if (weather.match(/R/g)) { 
    count = 1
  }
  if (weather.match(/RR/g)) { 
    count = 2
  }
  if (weather.match(/RRR/g)) { 
    count = 3
  }

  console.log(count)
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 29684
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)

typedef long long int ll;

std::vector<ll> enum_div(ll n);
long long comb(int n, int r);
bool IsPrime(int num);
bool dp[110][10010];
class UnionFind;
using Graph = vector<vector<int>>;

//自作関数一覧---------------------------
ll gcd(ll a, ll b); //最小公倍数の導出
ll lcm(ll x, ll y); //最大公約数の導出
ll bur(ll N, ll X); //??
//---------------------------------------

//UF木
class UnionFind {
public:
	//親
	vector<int> Parent;

	//初期状態
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//サイズ確認
	int size(int A) {
		return -Parent[root(A)];
	}

	int connect(int A, int B) {
		//root同氏をくっつける
		A = root(A);
		B = root(B);

		//結合済み
		if (A == B) {
			return false;
		}
		//大きいほうに小さいほうをくっつける
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズ更新
		Parent[A] += Parent[B];
		//Bの親をAに
		Parent[B] = A;

		return true;
	}

};

int main(void) {

	ll N = 0;
	ll A = 0;
	ll B = 0;
	ll C = 0;
	ll D = 0;


	string S, T;
	char fi[50], fv[50];
	char board[4][4];
	bool start = false;
	ll left = 0, right = 0;

	
	cin >> A >> B;
	//vector<ll> mo(N);

	if (A < B * 2)
		cout << 0 << endl;
	else
		cout << A - B * 2 << endl;
	



	return 0;
}


std::vector<ll> enum_div(ll n)//nの約数を列挙
{
	vector<ll> res;
	for (int i = 1; i*i <= n; ++i) {
		if (n % i != 0) continue;
		res.push_back(i);
		if (n / i == i) continue; // 上の行で追加済み。
		res.push_back(n / i);
	}
	return res;
}








bool IsPrime(int num)
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}



//combination
long long comb(int n, int r) {
	std::vector<std::vector<long long>> v(n + 1, std::vector<long long>(n + 1, 0));
	for (int i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int j = 1; j < v.size(); j++) {
		for (int k = 1; k < j; k++) {
			v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
		}
	}
	return v[n][r];
}


ll gcd(ll a, ll b) {

	/* 自然数 a > b を確認・入替 */
	if (a<b) {
		ll tmp = a;
		a = b;
		b = tmp;
	}
	ll x = b;
	ll y = a;
	/* ユークリッドの互除法 */
	ll r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}


	return y / b*x;
}

// 最大公約数を求める関数
ll lcm(ll x, ll y)
{
	if (x == 0 || y == 0)  // 引数チェック
	{
		//fprintf(stderr, "引数エラーです。\n");
		return 0;
	}

	return (x * y / gcd(x, y));
}

ll bur(ll N, ll X) {
	ll pan = 1;
	ll pat = 1;
	ll burg = 0;



	if (X > burg) {
		if (N == 0)
			return pat;


		burg += pan;
		burg += bur(N - 1, X);
		burg += pat;
		burg += bur(N - 1, X);
		burg += pan;


	}

	return burg;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

struct edge {
	int to;			//?????????to
	long long cost;	//????????????cost
	edge(int _to, long long _cost) :to(_to), cost(_cost) {}
};
vector<edge> G[1010];	//??£??\?????????

int v, e, r;
long long d[1010];	//?§????r????????????????????¢

bool bellman_ford(int start) {
	bool f[1010] = {};
	for (int i = 0; i < v; i++)d[i] = 1e12;
	d[start] = 0;
	f[start] = 1;

	for (int i = 0; i < v; i++) {
		bool update = false;		//???????????¢?????´??°????????£???????????????
		for (int j = 0; j < v; j++) {
			int from = j;
			if (!f[from])continue;
			for (int k = 0; k < G[from].size(); k++) {
				edge e = G[j][k];
				if (d[from] != INF&&d[e.to] > d[from] + e.cost) {
					f[e.to] = 1;
					d[e.to] = d[from] + e.cost;
					update = true;
				}
			}
		}
		if (update == false)break;	//???????????¢?????´??°????????????????????£????????????
		if (i == v - 1)return true;
	}
	return false;
}

int main() {
	cin >> v >> e >> r;
	rep(i, e) {
		int s, t, d;
		cin >> s >> t >> d;
		G[s].push_back(edge(t, d));
	}

	if (bellman_ford(r)) {
		cout << "NEGATIVE CYCLE" << endl;
		return 0;
	}

	for (int i = 0; i < v; i++) {
		if (d[i] != 1e12)cout << d[i] << endl;
		else cout << "INF" << endl;
	}

}

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

int main() {
  int A, B, M;
  cin >> A >> B >> M;
  vector<int> a(A), b(B), x(M), y(M), c(M);
  for (int i = 0; i < A; i++)
    cin >> a[i];
  for (int i = 0; i < B; i++)
    cin >> b[i];
  for (int i = 0; i < M; i++)
    cin >> x[i] >> y[i] >> c[i];

  int ans = 1000000001;
  for (int i = 0; i < M; ++i)
    ans = min(a[x[i] - 1] + b[y[i] - 1] - c[i], ans);

  sort(a.begin(), a.end()), sort(b.begin(), b.end());
  ans = min(a[0] + b[0], ans);

  cout << ans << endl;
}

Measured memory_bytes: 2176
#include <iostream>
#include <string>

using namespace std;

int main(void)
{
    int N;
    string S;
    cin >> N;
    S = (N ? "" : "0");
    while (N)
    {
        if (N & 1) {
            S = "1" + S;
            N--;
        }
        else S = "0" + S;
        N /= -2;
    }
    cout << S << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#define VIZ2 {printf("graph G{\n"); for(int i=1;i<=n;i++) for es(i,e) if(vb[e]>=i)printf("%d--%d;\n",i,vb[e]); puts("}");}
#define SZ 666666
int mi[1005]; Edg
int x[SZ],rt[SZ],rr[1005][10005];
void dfs(int x)
{
	int*rs=rr[x];
	for(int j=0;j<=::x[x];++j) rs[j]=1e9; rs[0]=0;
	for esb(x,e,b)
	{
		dfs(b);
		for(int j=0;j<=::x[x];++j) rt[j]=1e9;
		for(int j=::x[x];j>=0;--j)
		{
			if(j+::x[b]<=::x[x])
				rt[j+::x[b]]=min(rt[j+::x[b]],rs[j]+mi[b]);
			if(j+mi[b]<=::x[x])
				rt[j+mi[b]]=min(rt[j+mi[b]],rs[j]+::x[b]);
		}
		for(int j=0;j<=::x[x];++j) rs[j]=rt[j];
	}
	int mi=1e9;
	for(int j=::x[x];j>=0;--j)
		mi=min(mi,rs[j]);
	::mi[x]=mi;
}
int n;
int main()
{
	scanf("%d",&n);
	for(int i=2;i<=n;++i)
	{
		int p; scanf("%d",&p);
		ad_de(p,i);
	}
	for(int i=1;i<=n;++i)
		scanf("%d",x+i);
	dfs(1);
	if(mi[1]<1e8) puts("POSSIBLE");
	else puts("IMPOSSIBLE");
}


Measured memory_bytes: 48128
use std::io;
use std::cmp::min;

fn main() {
    let l0 = read_ints();
    let t = l0[1];
    let ts = read_ints();
    println!("{}", solve(t, &ts));
}

fn solve(t: u64, ts: &[u64]) -> u64 {
    // can't figure out how to  have rust infer type for sum with any other means
    let times: u64 = ts.into_iter().zip(ts.into_iter().skip(1)).map(|(a, b)| min(b - a, t)).sum();
    times + t
}

fn read_ints() -> Vec<u64> {
    get_line().trim().split_whitespace().map(|n| n.parse().unwrap()).collect()
}

fn get_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

Measured memory_bytes: 10492
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
int main(){
	string s;
	cin>>s;
	int N = s.size();
	if(N==26){
		string ps = s;

		if(!next_permutation(all(s))){
			puts("-1");
		}else{
			while(s.size()>0 && ps.substr(0,ps.size()-1)<s.substr(0,s.size()-1)){
				s.pop_back();
				ps.pop_back();
			}
			cout<<s<<endl;
		}
	}else{
		bool is[26]={};
		rep(i,N) is[s[i]-'a']=1;
		rep(i,26) if(!is[i]){
			s += 'a'+i;
			break;
		}
		cout<<s<<endl;
	}
}


Measured memory_bytes: 764
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
using namespace std;

int main(){
  int n,m;
  int x,y;
  cin >> n >> m;
  vector<vector<int> > frag(n+1,vector<int> {0,1});
  frag[1][0]=1;//{frag,kosuu}
  for(int i=0;i<m;i++){
    cin >> x >> y;
    frag[x][1] -=1;
    frag[y][1] +=1;
    if(frag[x][0]==1){
      frag[y][0]=1;
      if(frag[x][1]==0) frag[x][0]=0;
    }
  }
  int output=0;
  for(int i=1;i<=n;i++){
    if(frag[i][0]==1) output+=1;
  }
  cout << output << endl;
  return 0;
}


Measured memory_bytes: 5760
import java.util.*;
import java.math.*;
public class Main {
    static final int MOD = 1_000_000_007; // 10^9+7
    //static final int MAX = 2_147_483_646; // intの最大値
    static final int INF = 1_000_000_000; // 10^9
    static final int MAX = 10_000_000;
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        char[] str = s.toCharArray();
        if(str[0]==str[1]){
            if(str[2]==str[3]&&str[1]!=str[2]){
                System.out.println("Yes");
            }else{
                System.out.println("No");
            }
        }else if(str[0]==str[2]){
            if(str[1]==str[3]){
                System.out.println("Yes");
            }else{
                System.out.println("No");
            }
        }else if(str[0]==str[3]){
            if(str[1]==str[2]){
                System.out.println("Yes");
            }else{
                System.out.println("No");
            }
        }else{
            System.out.println("No");
        }
    }       
}






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

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

	ll n, sum = 0;
	cin >> n;
	for(int i=1; i<=n; i++){
		if(i%5 == 0 || i%3 == 0){}
		else sum += i;
	}
	cout << sum;

	return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int A, B; cin >> A >> B;
  int ans = A*B-A-B+1;
  cout << ans << endl;
}

Measured memory_bytes: 3572
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int n=sc.nextInt();
			if(n==0) break;
			String gomi=sc.nextLine();
			int[] num = new int[n];
			for(int i=0;i<n;++i){
				String data = sc.nextLine();
				num[i]=data.length();
			}
			for(int i=0;i<n-4;++i){
				boolean flag=true;
				int d=num[i],count=0,ans=i+1,m=i;
				while(flag){
					if(count==5){ System.out.println(ans); i=n; break; }
					if(count==0||count==2){
						if(5<d) flag=false;
						else if(d==5){ d=0; count++; }
						else { m++; d+=num[m]; }
					} else {
						if(7<d) flag=false;
						else if(d==7){ d=0; count++; }
						else { m++; d+=num[m]; }
					}
				}
			}
		}
	}
}



Measured memory_bytes: 34292
def is_sqnum(n)
    return ((n**0.5).to_i)**2 == n
end

n, d = gets.chomp.split(" ").map(&:to_i)
x = []
(0..n-1).each do |i|
    x.push(gets.chomp.split(" ").map(&:to_i))
end

sum = 0
(0..n-1).each do |i|
    (i..n-1).each do |j|
        next if i == j
        dist = 0
        (0..d-1).each do |k|
            dist += (x[i][k] - x[j][k]) ** 2
        end
        sum += 1 if is_sqnum(dist)
    end
end

puts sum

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

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

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

int dp[3001][3001];
int a[3000], b[3000];
int N, T, S;

int rec(int idx, int time){
  if(idx == N || time == T) return(0);
  if(~dp[idx][time]) return(dp[idx][time]);
  int ret = max( rec( idx + 1, time), rec( idx, time + 1));
  if((time + b[idx] <= S || time >= S) && time + b[idx] <= T){
    ret = max( ret, rec( idx + 1, time + b[idx]) + a[idx]);
  }
  return(dp[idx][time] = ret);
}

int main(){
  fill_n( *dp, 3001 * 3001, -1);
  cin >> N >> T >> S;
  for(int i = 0; i < N; i++){
    cin >> a[i] >> b[i];
  }
  cout << rec(0,0) << endl;
}

Measured memory_bytes: 36644
import java.util.*;
import java.io.*;
class Main{
	private static long getMaxSum(int i,int weights[],int values[],int n,int w,Long dp[][]){
		if(i>=n || w<=0)
			return 0;

		if(dp[i][w] != -1)
			return dp[i][w];
		long take = Long.MIN_VALUE;
		long notTake = Long.MIN_VALUE;
		if(weights[i]<=w)
			take = values[i]+ getMaxSum(i+1,weights,values,n,w-weights[i],dp);
		notTake = getMaxSum(i+1,weights,values,n,w,dp);
		dp[i][w]= Math.max(take,notTake);
		return dp[i][w];
	}
	public static void main(String[] args)throws Exception
	 {
	 	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String in[]=br.readLine().split(" ");
		int n = Integer.parseInt(in[0]);
		int w = Integer.parseInt(in[1]);
		int weights[]=new int[n];
		int values[]=new int[n];
		int i=0;
		while(i<n){
			String inp[]=br.readLine().split(" ");
			weights[i]=Integer.parseInt(inp[0]);
			values[i]=Integer.parseInt(inp[1]);
			i++;
		}
		Long dp[][]=new Long[n][w+1];
		for(Long a[]:dp)
			Arrays.fill(a,-1l);
		long maxSum = getMaxSum(0,weights,values,n,w,dp);
		System.out.println(maxSum);
	}
}

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

int main() {
  int N, Z, W;
  vector<int> a;
  cin >> N >> Z >> W;
  a.push_back(-1);  // Places a dummy for one-based index;
  for (int i = 1; i <= N; ++i) {
    a.push_back(-1);
    cin >> *--a.end();
  }
  if (N == 1) {
    cout << abs(a[1] - W) << endl;
  } else if (N >= 2) {
    cout << max(abs(a[N] - W), abs(a[N - 1] - a[N])) << endl;
  }
}


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

template<class I, class BiOp = I (*) (I, I)>
class SegTree {
private:
  int n;
  std::vector<I> dat, lazy;
  BiOp op;
  I e;

public:
  SegTree(int n_) {
    n = 1;
    while (n < n_) n *= 2;
    dat.resize(2 * n - 1, INT_MAX);
    lazy.resize(2 * n - 1, -1);
  }

  void eval(int k, int l, int r) {
    if (lazy[k] == -1) return;
    // cerr << "eval: k = " << k << ", l = " << l << ", r = " << r << endl;

    dat[k] = lazy[k];
    if (k < n - 1) {
      lazy[2 * k + 1] = lazy[k];
      lazy[2 * k + 2] = lazy[k];
    }
    lazy[k] = -1;
  }

  void update(int a, int b, I x, int k = 0, int l = 0, int r = -1) {
    if (r == -1) r = n;
    // cerr << "update: a = " << a << ", b = " << b << ", x = " << x << ", k = " << k << ", l = " << l << ", r = " << r << endl;
    eval(k, l, r);
    if (b <= l || r <= a) return;
    if (a <= l && r <= b) {
      // cerr << "hey!" << endl;
      lazy[k] = x;
      eval(k, l, r);
    }
    else {
      update(a, b, x, 2 * k + 1, l, (l + r) / 2);
      update(a, b, x, 2 * k + 2, (l + r) / 2, r);
      // dat[k] = dat[2 * k + 1] + dat[2 * k + 2];
    }
  }

  I query(int a, int k = 0, int l = 0, int r = -1) {
    if (r == -1) r = n;
    // cerr << "query: a = " << a << ", k = " << k << ", l = " << l << ", r = " << r << endl;
    eval(k, l, r);
    if (r - l == 1) return dat[k];
    int m = (l + r) / 2;
    if (a < m) {
      return query(a, 2 * k + 1, l, m);
    }
    else {
      return query(a, 2 * k + 2, m, r);
    }
  }

  void print() {
    int j = 2;
    for (int i = 0; i < 2 * n - 1; i++) {
      cerr << "(" << dat[i] << ", " << lazy[i] << ")";
      if (i == j - 2) {
        cerr << endl;
        j *= 2;
      }
      else {
        cerr << " ";
      }
    }
  }
};

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

  int n, q;
  cin >> n >> q;
  SegTree<ll> seg(n);

  // seg.print();

  rep(i, q) {
    // cerr << "i = " << i << endl;

    int t;
    cin >> t;
    if (t == 0) {
      int a, b, x;
      cin >> a >> b >> x;
      seg.update(a, b + 1, x);
    }
    else {
      int a;
      cin >> a;
      cout << seg.query(a) << endl;
    }

    // seg.print();
    // cerr << endl;
  }

  return 0;
}



Measured memory_bytes: 6996
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

vector<int> G[20010];

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

	int N, X, Y;
	cin >> N >> X >> Y;
	X--, Y--;
	rep(i, 0, N)
	{
		if (0 < i)G[i].push_back(i - 1);
		if (i < N - 1)G[i].push_back(i + 1);
	}
	G[X].push_back(Y);
	G[Y].push_back(X);

	vector<int> ans(N,0);
	rep(i, 0, N)
	{
		vector<bool> used(N, false);
		used[i] = true;
		queue<pii> q;
		q.push(mp(i, 0));
		while (!q.empty())
		{
			auto p = q.front();
			q.pop();
			for (auto e : G[p.first])
			{
				if (used[e])continue;
				used[e] = true;
				ans[p.second + 1]++;
				q.push(mp(e, p.second + 1));
			}
		}
	}

	rep(i, 1, N)
	{
		cout << ans[i] / 2 << endl;
	}

	return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9+7;
constexpr lint mod2 = 998244353;

lint gyaku(lint a, lint mod){
  lint s = 1, tmp = a, t = mod - 2;
  while(t > 0){
    if(t % 2 == 1){
      s *= tmp;
      s %= mod;
    }
    t /= 2;
    tmp *= tmp;
    tmp %= mod;
  }
  return s;
}

int main(){
  int n, k; scanf("%d %d", &n, &k); lint s = 0;
  v1li v(n+1, 1), u(n+1, 1);
  rep(i, n){
    v[i+1] = v[i]*(i+1); v[i+1] %= mod1;
    u[i+1] = u[i]*gyaku(i+1, mod1); u[i+1] %= mod1;
  }
  rep(i, min(k+1, n)){
    lint t = v[n];
    t *= u[i]; t %= mod1;
    t *= u[n-i]; t %= mod1;
    t *= v[n-1]; t %= mod1;
    t *= u[n-i-1]; t %= mod1;
    t *= u[i]; t %= mod1;
    s += t;
    s %= mod1;
  }
  printf("%lld\n", s);
  return 0;
}

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

int main() {
	int n, x;
	scanf("%d%d", &n, &x);
	if(x == 1 || x == 2 * n - 1) {
		printf("No\n");
	} else if(n > 2) {
		printf("Yes\n");
		if(x != 2) {
			int ptr = 1;
			for(int i = 1; i < n - 1; ++i, ++ptr) {
				if(ptr == x - 2) ptr = x + 2;
				printf("%d\n", ptr);
			}
			printf("%d\n%d\n%d\n%d\n", x - 2, x, x + 1, x - 1);
			for(int i = 1; i < n - 2; ++i, ++ptr) {
				if(ptr == x - 2) ptr = x + 2;
				printf("%d\n", ptr);
			}
		} else {
			int ptr = 1;
			for(int i = 1; i < n - 1; ++i, ++ptr) {
				if(ptr == x - 1) ptr = x + 3;
				printf("%d\n", ptr);
			}
			printf("%d\n%d\n%d\n%d\n", x + 2, x, x - 1, x + 1);
			for(int i = 1; i < n - 2; ++i, ++ptr) {
				if(ptr == x - 1) ptr = x + 3;
				printf("%d\n", ptr);
			}
		}
	} else {
		printf("Yes\n1\n2\n3\n");
	}
	return 0;
}

Measured memory_bytes: 1536
#include<stdio.h>

long long x[100000],y[100000];

int main(int argc, char const *argv[]){
	long n,m,i;
	long long w=0,h=0,ans=0,p=1000000007,s;
	scanf("%ld %ld",&n,&m);
	for(i=0;i<n;i++){
		scanf("%lld",&x[i]);
	}
	for(i=0;i<m;i++){
		scanf("%lld",&y[i]);
	}
	for(i=1;i<m;i++){
		h+=i*(m-i)%p*(y[i]-y[i-1])%p;
		h%=p;
	}
	for(i=1;i<n;i++){
		w+=i*(n-i)%p*(x[i]-x[i-1])%p;
		w%=p;
	}
	printf("%lld\n",w*h%p);
	return 0;
}

Measured memory_bytes: 1664
N = int(input())
H = list(map(int, input().split()))
count = 0
m = H[0]
for n in range(N-1):
    if H[n+1] - H[n] >= 0:
        if H[n+1] > m:
            count += 1
            m = H[n+1]
        elif H[n+1] == m:
            count += 1
print(count+1)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
int N,M;
long long a[300001]={};
using namespace std;


int main() {

	cin>>N;
	for(int i=0;i<3*N;++i)cin>>a[i];
	sort(a,a+3*N);

	long long R=0;
	for(int i=3*N-2;i>N-1;i=i-2)R+=a[i];

	cout << R<< endl;
	return 0;
}


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

int searchKey(int a[], int size, int x) {
  int L = 0, R = size; //[L, R): lower bound
  while (R - L > 1) {
    int C = L + (R - L) / 2;
    if (x < a[C]) {
      R = C;
    } else if (x == a[C]) {
      return C;
    } else {
      L = C;
    }
  }
  if (a[L] == x) {
    return L;
  }
  return (-L) - 1;
}

int n, q, S[100000];

void solve() {
  scanf("%d", &n);
  rep(i,0,n)
  {
    scanf("%d", &S[i]);
  }
  scanf("%d", &q);

  int sum = 0, key;
  rep(i,0,q)
  {
    scanf("%d", &key);
    if (searchKey(S, n, key) >= 0) {
      sum++;
    }
  }
  printf("%d\n", sum);
}

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



Measured memory_bytes: 3496
let () =
  Scanf.scanf "%d" @@ fun n ->
  let h = Array.init n (fun _ -> Scanf.scanf " %d" ((+) 0)) in
  let dp = Array.make n max_int in
  dp.(0) <- 0;
  dp.(1) <- abs (h.(0) - h.(1));
  for i = 2 to n-1 do
    dp.(i) <-
      min (dp.(i-2) + abs (h.(i-2) - h.(i)))
          (dp.(i-1) + abs (h.(i-1) - h.(i)))
  done;
  Printf.printf "%d\n" dp.(n-1)


Measured memory_bytes: 6016