akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

#define X first
#define Y second

//#include <boost/unordered_map.hpp>
//using namespace boost;

/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
rbtree T;
*/

namespace io{
	const int L = (1 << 20) + 1;

	char buf[L], *S , *T, c;

	char getchar() {
		if(__builtin_expect(S == T, 0)) {
			T = (S = buf) + fread(buf, 1, L, stdin);
			return (S == T ? EOF : *S++);
		}
		return *S++;
	}

	int inp() {
		int x = 0, f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}

	unsigned inpu()
	{
		unsigned x = 0; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar());
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x;
	}

	ll inp_ll() {
		ll x = 0; int f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}

	char B[45], *outs=B+40, *outr=B+40;
	template<class T>
	inline void print(register T a,register char x=0){
		if(x) *--outs = x, x = 0;

		if(!a)*--outs = '0';
		else
			while(a)
				*--outs = (a % 10) + 48, a /= 10;

		if(x)
			*--outs = x;

		fwrite(outs, outr - outs , 1, stdout);
		outs = outr;
	}
};

using io :: print;
using io :: inp;
using io :: inpu;
using io :: inp_ll;

using i32 = int;
using i64 = long long;
using u8 = unsigned char;
using u32 = unsigned;
using u64 = unsigned long long;
using f64 = double;
using f80 = long double;
//using i128 = __int128_t;
//using u128 = __uint128_t;
using i128 = i64;
using u128 = u64;

ll power(ll a, ll b, ll p)
{
	if (!b) return 1;
	ll t = power(a, b/2, p);
	t = t*t%p;
	if (b&1) t = t*a%p;
	return t;
}

ll exgcd(ll a, ll b, ll &x, ll &y)
{
	if (b == 0)
	{
		x = 1;
		y = 0;
		return a;
	}
	ll px, py;
	ll d = exgcd(b, a%b, px, py);
	x = py;
	y = px-a/b*py;
	return d;
}

template<class T>
inline void freshmin(T &a, const T &b)
{
	if (a > b) a = b;
}

template<class T>
inline void freshmax(T &a, const T &b)
{
	if (a < b) a = b;
}

const int MOD = 1000000007;
const int INF = 1000000000;

typedef long long ll;

const int MAXN = 200010;

int main()
{
	
	string s;
	cin >> s;
	int n = s.size();
	int cnt = 0;
	for (int i = 0; i < n; ++ i)
		cnt += s[i] == 'o';
	cnt += 15-n;
	puts(cnt >= 8 ? "YES" : "NO");
	
	return 0;
}


Measured memory_bytes: 256
read a b c
read d e f
read g h i
a=$[b-a]
b=$[c-b]
d=$[e-d]
e=$[f-e]
g=$[h-g]
h=$[i-h]
[ $a -eq $d -a $d -eq $g -a $b -eq $e -a $e -eq $h ]&&echo Yes||echo No

Measured memory_bytes: 3792
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll A, B, C, X, Y; cin >> A >> B >> C >> X >> Y;
  ll ans = 1e9;
  /*if (X >= Y) {
    ll x[3] = {0, X-Y, X};
    for (int a = 0; a < 3; a++) {
      ll y[2] = {0, Y};
      for (int b = 0; b < 2; b++) {
        ll c = max(X-x[a], Y-y[b])*2;
        ans = min(ans, A*x[a]+B*y[b]+C*c);
      }
    }
  } else {
    ll y[3] = {0, Y-X, Y};
    for (int b = 0; b < 3; b++) {
      ll x[2] = {0, X};
      for (int a = 0; a < 2; a++) {
        ll c = max(X-x[a], Y-y[b])*2;
        ans = min(ans, A*x[a]+B*y[b]+C*c);
      }
    }
  }*/
  for (int c = 0; c <= max(X, Y)*2; c += 2) {
    ll a, b;
    c/2 <= X ? a = X-c/2 : a = 0;
    c/2 <= Y ? b = Y-c/2 : b = 0;
    ans = min(ans, A*a+B*b+C*c);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<stack>
#include<vector>
#include <cmath>
using namespace std;
const long long N = 105;
long long M = 1000000007;

int main() {
	int a, b;
	cin >> a >> b;
	if (a % b != 0)cout << 1;
	else cout << 0;

}

Measured memory_bytes: 256
#include <stdio.h>
 
int p, m;
 
void x1(int a, int b)
{
    if (b == 0) p = m = 0;
    else if (b > 0) p = 0, m = 1;
    else p = 1, m = 0;
}
 
void x2(int a, int b, int c)
{
    if (c == 0) {
        x1(a, b);
        return;
    }
    if (b*b-4*a*c < 0) p = m = 0;
    else {
        if (c < 0) p = m = 1;
        else if (b > 0) p = 0, m = 2;
        else p = 2, m = 0;
    }
}
 
void x(int a, int b, int c, int d)
{
    int e, f1, f2;
     
    if (a < 0) {
        x(-a, -b, -c, -d);
        return;
    }
    if (d == 0) {
        x2(a, b, c);
        return;
    }
     
    long long df = (long long)b*b*c*c - 4*(long long)a*c*c*c - 4*(long long)b*b*b*d - 27*(long long)a*a*d*d + 18*(long long)a*b*c*d;
     
    e = b*b - 3*a*c;
     
    f1 = f2 = 0;
    if (b*b < e) f1 = f2 = 1;
    else f1 = b < 0, f2 = b > 0;
     
    if (df >= 0) {
        if (e == 0) {
            if (b > 0) p = 0, m = 3;
            else p = 3, m = 0;
            return;
        }
        if (d > 0) {
            if (!f1) p = 0, m = 3;
            else p = 2, m = 1;
        } else {
            if(!f2) p = 3, m = 0;
            else p = 1, m = 2;
        }
    } else {
        if (d > 0) p = 0, m = 1;
        else p = 1, m = 0;
    }
}
 
int main(void){
    int n, a, b, c, d;
     
    scanf("%d",&n);
    while(n-- > 0) {
        scanf("%d%d%d%d", &a, &b, &c, &d);
        x(a, b, c, d);
        printf("%d %d\n", p, m);
    }
    return 0;
}


Measured memory_bytes: 2108
#include<iostream>
using namespace std;
int main()
{
  int a,b,c,a5=0,a7=0;
  cin>>a>>b>>c;
  if(a==5)
    a5++;
  if(a==7)
    a7++;
   if(b==5)
    a5++;
  if(b==7)
    a7++;
   if(c==5)
    a5++;
  if(c==7)
    a7++;
  if(a5==2 && a7==1)
    cout<<"YES";
  else
    cout<<"NO";
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int c[110];
int main() {
  int n;
  cin>>n;
  int b[110];
  for (int i=0; i<n; i++) {
    scanf("%d",b+i);
    if (b[i]>i+1) {
      cout<<-1<<endl;
      return 0;
    }
  }

  for (int i=n-1; i>=0; i--) {
    if (b[i]==c[i]+1) {
      printf("%d\n",b[i]);
      for (int j=i; j<n; j++) {
	c[j]++;
      }
      i=n;
    }
  }
  return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
 
K = int(read())
 
x = np.arange(1, K + 1)
nums = np.gcd.outer(np.gcd.outer(x, x), x)
print(nums.sum())

Measured memory_bytes: 89744
'''
https://atcoder.jp/contests/abc065/tasks/arc076_b
最小全域木を考える際にある頂点について他の頂点への最小コストを
考えて繋げていくのは間違い(全域木になる保証がない)
考えたいのはあくまでも全辺のコスト

今回はxとyでそれぞれソートして隣り合う2点のコストのみを考えれば良い
'''
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 1000000007

    N = int(input())
    xy = []
    for i in range(N):
        x,y = map(int, input().split())
        xy.append([x, y, i])
    x_sort = sorted(xy, key=lambda x: x[0])
    y_sort = sorted(xy, key=lambda x: x[1])

    #[cost, 頂点1, 頂点2]
    cost = []
    for i in range(N-1):
        cost.append([abs(x_sort[i][0]-x_sort[i+1][0]), x_sort[i][2], x_sort[i+1][2]])
        cost.append([abs(y_sort[i][1]-y_sort[i+1][1]), y_sort[i][2], y_sort[i+1][2]])
    cost = sorted(cost, key=lambda x: x[0])

    def find(x):
        if par[x] < 0:
            return x
        else:
            par[x] = find(par[x])
            return par[x]
    
    def unite(x,y):
        x = find(x)
        y = find(y)
        if x == y:
            return False
        else:
            if par[x] > par[y]:
                x,y = y,x
            par[x] += par[y]
            par[y] = x
            return True
    
    def same(x,y):
        return find(x) == find(y)

    par = [-1]*N

    res = 0
    for c, v1, v2 in cost:
        if not same(v1, v2):
            unite(v1, v2)
            res += c
    print(res)


if __name__ == '__main__':
    main()

Measured memory_bytes: 127964
import copy
def bubblesort(card,maisu):
    for i in range(maisu):
        for j in reversed(range(i+1,maisu)):
            if card[j][1]<card[j-1][1]:
                card[j-1],card[j]=card[j],card[j-1]

def selectionsort(card,maisu):
    for i in range(maisu):
        mini=i
        for j in range(i,maisu):
            if card[j][1]<card[mini][1]:
                mini=j
        card[i],card[mini]=card[mini],card[i]

def output(card,maisu):
    joutai="Stable"
    for i in range(maisu):
        if i>0:
            print(" ",end="")
        print(card[i][0]+card[i][1],end="")
        if i<=maisu-2:
            if card[i][1]==card[i+1][1] and card[i][2]>card[i+1][2]:
                joutai="Not stable"
    print()
    print(joutai)
    
maisu=int(input())
card=list(map(str,input().split()))
for i in range(maisu):
    a=[]
    for j in card[i]:
        a.append(j)
    a.append(i)
    card[i]=a
    
card_bubble=copy.deepcopy(card)
card_selection=copy.deepcopy(card)

bubblesort(card_bubble,maisu)
output(card_bubble,maisu)

selectionsort(card_selection,maisu)
output(card_selection,maisu)



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

bool binarySearch(const vector<int>& A, int key) {
    int left = 0;
    int right = A.size();

    while (left < right) {
        int mid = (left + right)/2;

        if (A[mid] == key) {
            return true;
        } else if (key < A[mid]) {
            right = mid;
        } else {
            left = mid + 1;
        }
    }

    return false;
}

int main(void) {
    int n, q;
    cin >> n;

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

    cin >> q;
    int cnt = 0;
    for (int i = 0; i < q; i++) {
        int key;
        cin >> key;

        if (binarySearch(S, key)) {
            cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 1524
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main(void)
{
	char s[10],p[1000];
	int i, count=0;

	scanf("%s",s);

	for(i=0;i<strlen(s);i++){
		s[i]=tolower(s[i]);
		}

	while(1){
		scanf("%s",p);
		if(strcmp(p,"END_OF_TEXT") ==0)
			break;
		for(i=0;i<strlen(p);i++){
			p[i]=tolower(p[i]);
		}
		if(strcmp(p,s)==0)
			count++;
		}
		printf("%d\n",count);
	return 0;
}

Measured memory_bytes: 552
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        ArrayList<Integer> A = new ArrayList<>();
        A.add(0);
        for (int i = 0; i < N; i++) {
            A.add(scanner.nextInt());
        }
        scanner.close();
        A.add(0);

        int d = 0;
        for (int i = 0; i + 1 < N + 2; i++) {
            d += Math.abs(A.get(i + 1) - A.get(i));
        }

        for (int i = 0; i < N; i++) {
            System.out.println(d - Math.abs(A.get(i + 2) - A.get(i + 1)) - Math.abs(A.get(i + 1) - A.get(i))
                    + Math.abs(A.get(i + 2) - A.get(i)));
        }
    }

}

Measured memory_bytes: 73580
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int calc(int[] a) {
    a.sort();

    int index = -1;
    long sum = 0;
    for (int i = 0; i < a.length; i++) {
        if (2 * sum < a[i]) {
            index = i;
        }
        sum += a[i];
    }
    return cast(int) a.length - (index + 1) + 1;
}

void main() {
    readint;
    auto a = readints;
    writeln(calc(a));
}


Measured memory_bytes: 4348
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP2(i, a, b) for(int i = a;i <= b;i++)
#define REPR(i, a, b) for(int i = a; i >= b; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define PI 3.14159265358979323846
#define vi vector<int>
#define vll vector<ll>
#define vi2 vector<vector<int>>
#define eb emplace_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define sz(x) int(x.size())
using namespace std;
using P = pair<ll,ll>;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};
#define INT(name) int name;cin >> name;
#define VEC(type,name,n) vector<type> name(n);REP(i,n) cin >> name[i];

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

vector<long long> fact, fact_inv, inv;
 
/*  init_nCk :二項係数のための前処理
    計算量:O(n)
*/
void init_nCk(int SIZE) {
    fact.resize(SIZE + 5);
    fact_inv.resize(SIZE + 5);
    inv.resize(SIZE + 5);
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < SIZE + 5; i++) {
        fact[i] = fact[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % MOD;
    }
}
 
/*  nCk :MODでの二項係数を求める(前処理 int_nCk が必要)
    計算量:O(1)
*/
long long nCk(int n, int k) {
    assert(!(n < k));
    assert(!(n < 0 || k < 0));
    return fact[n] * (fact_inv[k] * fact_inv[n - k] % MOD) % MOD;
}
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

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

int main()
{
  ll N,K;
  cin >> N >> K;
  VEC(ll,A,N);
  sort(ALL(A));
  init_nCk(N);
  mint ans = 0;
  REP(i,N-K+1){
    ans+=nCk(N-i-1,K-1)*A[N-1-i];
  }
  REP(i,N-K+1){
    ans-=nCk(N-i-1,K-1)*A[i];
  }

  cout << ans << endl;
}

Measured memory_bytes: 6428
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int ans = 0;
    for(int i = 0; i < n; i++) {
      int l = sc.nextInt();
      int r = sc.nextInt();
      ans += (r - l + 1);
    }
    System.out.println(ans);
  }
}

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

int main() {
    int N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    vector<int> count(N+1);
    count[0] = 0;
    for (int i = 1; i < N; i++) {
        count[i+1] = count[i];
        if (S.at(i-1) == 'A' && S.at(i) == 'C') count[i+1]++;
    }
    rep(i, Q) {
        int l, r;
        cin >> l >> r;
        int ans;
        if (S.at(l-1) == 'C') ans = count[r] - count[l];
        else ans = count[r] - count[l-1];
        cout << ans << "\n";
    }
}

Measured memory_bytes: 1408
fun main(args: Array<String>) {
    val A = readLine()!!.toLong()
    var Sosu :Long = A

    loop@while (true){
        var Count : Long = 2
        while (true){
            if (Sosu % Count == 0L && Sosu != Count){
                break
            }else if (Sosu == Count){
                break@loop
            }
            Count++
        }
        Sosu++
    }


    println(Sosu)
}

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

int main()
{
	int i, j;
	long int sum = 0;
	long int min, max;

	cin >> j;

	long int a;

	min = 1000000;
	max = -1000000;

	for(i=0;i<j;i++){
		cin >> a;
		sum += a;
		if(min > a)
			min = a;
		if(max < a)
			max = a;
	}

	cout << min <<' '<< max <<' '<< sum << '\n';

	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
using lint=int64_t;
using namespace std;

pair<int,int> mp(int x,int y)
{
	return make_pair(min(x,y),max(x,y));
}

int N;
int A[1010][1010];

map<pair<int,int>,int> num;
int cnode;

vector<int> graph[1000010];
int in[1000010];

queue<int> que;
bool visited[1000010];
int dist[1000010];
int ans;

int main()
{
	cin >> N;
	for(int i=0;i<N;i++)
	{
		for(int j=0;j<N-1;j++)
		{
			cin >> A[i][j];
			A[i][j]--;
		}
	}

	for(int i=0;i<N;i++)
	{
		for(int j=i+1;j<N;j++)
		{
			num[mp(i,j)]=cnode;
			cnode++;
		}
	}

	for(int i=0;i<N;i++)
	{
		for(int j=0;j<N-2;j++)
		{
			int prev,next;
			prev=num[mp(i,A[i][j])];
			next=num[mp(i,A[i][j+1])];

			graph[prev].push_back(next);
			in[next]++;
		}
	}

	for(int i=0;i<cnode;i++)
	{
		dist[i]=-1;
		if(in[i]==0)
		{
			que.push(i);
			visited[i]=true;
			dist[i]=1;
		}
	}
	if(que.empty())
	{
		cout << -1 << endl;
		return 0;
	}
	while(!que.empty())
	{
		int cur=que.front();
		que.pop();

		for(auto&& next:graph[cur])
		{
			if(visited[next])
			{
				cout << -1 << endl;
				return 0;
			}

			in[next]--;
			if(in[next]==0)
			{
				visited[next]=true;
				dist[next]=dist[cur]+1;
				que.push(next);
			}
		}
	}

	for(int i=0;i<cnode;i++)
	{
		if(dist[i]==-1)
		{
			ans=-1;
			break;
		}
		ans=max(ans,dist[i]);
	}
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 83200
#include <bits/stdc++.h>
using namespace std;
//using Graph = vector<vector<edge>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

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; }

#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
//#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvector(name,typ,m,n)vector<vector<typ> > name(m,vector<typ> (n))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define res resize
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout << a<<" "<<b <<" "<< c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define ssum(a) accumulate(a,0ll) 

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
//typedef long long T;
ll ceil(ll a,ll b){
    return ((a+b-1)/b);
}
const int INF = 1000000000;
const ll INF64 = 9223372036854775807ll;
const ll MOD = 1000000007ll;
const dou pi=3.141592653589793;
//mapは、if関数などで覗いただけで構成されるので注意しよう！

int main(){
    int n,k;
    std::cin >> n>>k;
    VEC(int,a,n);
    std::set<int> s;
    int ans=n-k+1;
    rep(i,k){
        s.insert(a[i]) ;
    }
    std::vector<int> c(n);
    rep(i,n-1){
        if(a[i]>a[i+1])c[i+1]++;
    }
    rep(i,n-1)c[i+1]+=c[i];
   // erep(i,c)std::cout << i <<' ';
    //std::cout  << std::endl;
    int d=0;
    if(c[k-1]-c[0]==0){
        d++;
    }
    rrep(i,1,n-k+1){
        s.insert(a[i+k-1]);
        //std::cout << s.size() << std::endl;
        bool bo=1;
       // ppri(a[i-1],a[i+k-1]);
        if(*s.begin()==a[i-1]&&*s.rbegin()==a[i+k-1]){
            
            ans--;
            bo=0;
        }
        s.erase(a[i-1]);
        if(bo&&c[i+k-1]-c[i]==0){
            d++;
            
        }
        
    }
    //std::cout << d << std::endl;
    if(d)d--;
   // std::cout << d << std::endl;
    std::cout << ans-d << std::endl;
}


Measured memory_bytes: 11136
#include <stdio.h>
#include <stdlib.h>

typedef struct{
    int num;
    int count;
}NC;

int comp(NC *a, NC *b){
    return a->num - b->num;
}
int main(void){
    long long int n, k, pos = 0;
    int i;
    NC nc[100000];
    
    scanf("%lld%lld", &n, &k);
    
    for(i = 0; i < n; i++){
        scanf("%d%d", &nc[i].num, &nc[i].count);
    }
    qsort(nc, n, sizeof(NC), comp);
    
    for(i = 0; i < n; i++){
        if(pos + nc[i].count >= (long long int)k){
            printf("%d\n", nc[i].num);
            break;
        }
        pos += (long long int)nc[i].count;
    }
    return 0;
}


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

using namespace std;

int main(){
    string S, T;
    cin >> S >> T;

    long long count = 0;
    for (int i = 0; i < S.length(); i++)
    {
        if(S[i] != T[i]){
            count++;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 3920
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<numeric>
#include<cctype>
#include<random>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long int I;

int keta(int a){
    int count=0;
    while(a!=0){
        a/=10;
        count++;
    }
    return count;
}


int main(){
    string s,t,u;
    int a,b;

    cin>>s>>t;
    cin>>a>>b;
    cin>>u;

    if(s==u){
        a--;
    }
    else{
        b--;
    }
    cout<<a<<' '<<b<<endl;

    return 0;
} //カモンAC

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

int main(){
  int N,i;
  long int x=0;
  long double xb=0;
  char u[4];
  long double tmp;
  
  cin >> N;
  for(i=0;i<N;i++){
  cin >> tmp >>u;
    if(strcmp(u,"JPY")==0){
      x+=(int)tmp;
    }else{
      xb+=(long double)tmp;
    }
  }
  cout << (long double)x+xb*380000.0 << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
// #define ll long long int
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define eb emplace_back
#define pii pair<int, int>
#define endl '\n'
#define all(x) x.begin(),x.end()
#define f(i,j,l) for(i=j;i<l;i++)
#define smax(a,b) a=max(a,b)
// #if !defined(ONLINE_JUDGE)
// #include "debugging.h"
// #endif
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
// erase,insert same as normal set

// int const mod = 7340033;
// int const mod = 998244353;
int const mod = 1e9+7;
int power(int a,int b,int m){
    int res = 1;
    while(b){
        if(b&1){
            res = res*a;
            res %= m;
        }
        a=a*a;
        a%=m;
        b=b/2;
    }
    return res;
}

int inverse(int x , int m){
    return power(x,m-2,m);
}

int const N = 5005;
int const inf = 2e16;


void solve(){  
    int i,j,l;
    int n;
    cin >> n;
    int a[n];
    for(i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    int ans = a[n-1];
    j = 2;
    i = n-2;
    while(j < n){
        ans = ans + a[i];
        j++;
        if(j < n) ans = ans + a[i];
        j++;
        i--;
    }
    cout<<ans<<endl;
}           


int32_t main(){
    IOS;
    int t;
    t = 1;
    // precompute();
    // cin>>t;
    for(int tt=1;tt<=t;tt++){
        solve();
    }
    return 0;
}


/*




*/

Measured memory_bytes: 5140
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        String HWD = br.readLine();
        int H = Integer.parseInt(HWD.split(" ")[0]);
        int W = Integer.parseInt(HWD.split(" ")[1]);
        int D = Integer.parseInt(HWD.split(" ")[2]);
     
        int[] Hei = new int[H*W+1];
        int[] Wid = new int[H*W+1];
        
        for(int i = 0; i < H; i++){
            String[] line = br.readLine().split(" ");
            for(int j = 0; j < W; j++){
                int temp = Integer.parseInt(line[j]);
                Hei[temp] = i;
                Wid[temp] = j;
            }
        }
        
        int[] leng = new int[H*W+1];
        
        for(int x = D+1; x <= H*W; x++){
            leng[x] = leng[x-D] + Math.abs(Hei[x] - Hei[x-D]) + Math.abs(Wid[x] - Wid[x-D]);
        }
        
        int Q = Integer.parseInt(br.readLine());
        while(Q-- > 0){
            String str = br.readLine();
            int start = Integer.parseInt(str.split(" ")[0]);
            int end = Integer.parseInt(str.split(" ")[1]);
            
            System.out.println(leng[end] - leng[start]);
        }
    }

}


Measured memory_bytes: 57548
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N ((ll)301*1000)
#define MOD ((ll)1e9+7)

ll n,m;
ll one,biprt,odd;
ll cnt,c[N];
bool cycle;
vector <ll> e[N];

void dfs(ll x)
{
	cnt++;
	for(auto u:e[x])
	{
		if(c[u])
		{
			if(c[u]==c[x])cycle=1;
			continue;
		}
		c[u]=2/c[x];
		dfs(u);
	}
}

int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		ll v,u;
		cin>>v>>u;
		e[v].push_back(u);
		e[u].push_back(v);
	}
	for(int i=1;i<=n;i++)
		if(!c[i])
		{
			cnt=cycle=0;
			c[i]=1;
			dfs(i);
			if(cnt==1)one++;
			else if(cycle)odd++;
			else biprt++;
		}
	ll ans=0;
	ans+=2*biprt+odd+one;
	ans+=odd*biprt*2;
	ans+=one*(n-one)*2;
	ans+=odd*(odd-1)/2*2;
	ans+=biprt*(biprt-1)/2*4;
	ans+=one*(one-1)/2*2;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 17408
#include <stdio.h> 
 #include <string.h> 
 #define MAX 100 
 
 
 int main(){ 
     int n; 
     int t_point=0, h_point=0; 
     char tarou[MAX], hanako[MAX]; 
 
 
     scanf("%d", &n); 
     for(;n>0;n--){ 
         scanf(" %s %s", tarou, hanako); 
         if(strcmp(tarou, hanako)>0){ 
             t_point+=3; 
         }else if(strcmp(tarou, hanako)==0){ 
             t_point+=1; 
             h_point+=1; 
         }else if(strcmp(tarou, hanako)<0){ 
             h_point+=3; 
         } 
     } 
     printf("%d %d\n", t_point, h_point); 
 
 
     return 0; 
 } 



Measured memory_bytes: 2068
import java.util.Scanner;

public class Main {
    public static void main(String [] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int q = scanner.nextInt();
        String s = scanner.next();
        int [] l = new int[q];
        int [] r = new int[q];
        for (int i = 0; i < q; ++i) {
            l[i] = scanner.nextInt();
            r[i] = scanner.nextInt();
        }
        int [] sum = new int[n];
        for (int i = 0; i  + 1 < s.length(); i++) {
            if (s.charAt(i) == 'A' && s.charAt(i + 1) == 'C') {
                sum[i + 1]++;
            }
            sum[i + 1] += sum[i];
        }

        for (int i = 0; i < q; ++i) {
            int left = l[i] - 1;
            int right = r[i] - 1;
            if (s.charAt(left) == 'C') {
                int res = sum[right] - sum[left];
                System.out.println(res);
            } else {
                int res = sum[right];
                if (left - 1 >= 0) {
                    res -= sum[left - 1];
                }
                System.out.println(res);
            }
        }

    }

}


Measured memory_bytes: 102636
N = int(input())
info = [list(map(int,input().split())) for i in range(N)]
# dp[i+1][j] = max(dp[i][k(!=j)]) + info[i][j]
dp = [[0,0,0] for i in range(N+1)]
dp[1] = info[0]
for i in range(1,N):
    for j in range(3):
        for k in [_ for _ in range(3) if _ != j]:
            if dp[i][k] + info[i][j] > dp[i+1][j]:
                dp[i+1][j] = dp[i][k] + info[i][j]
print(max(dp[N]))

Measured memory_bytes: 47320
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;

public class Main {

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

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();

		HashMap<String, Integer> hs = new HashMap<String, Integer>();

		int maxOccured = 0;
		int maxLen = 0;
		String maxOccuredWord = "";
		String maxLenWord = "";

		for (String word : line.split(" ")) {
			if (!hs.containsKey(word)) {
				hs.put(word, 1);
			} else {
				hs.put(word, hs.get(word) + 1);
			}
			// 発生回数と単語を確認して更新
			if (maxOccured < hs.get(word)) {
				maxOccured = hs.get(word);
				maxOccuredWord = word;
			}
			// 文字数と単語を確認して更新
			// 文字数確認済みの単語は確認しない
			if (hs.get(word) == 1 && maxLen < word.length()) {
				maxLen = word.length();
				maxLenWord = word;
			}
		}
		System.out.println(maxOccuredWord + " " + maxLenWord);
	}
}

Measured memory_bytes: 15056
from math import sin,cos,radians
a,b,c=map(int,input().split())
c=radians(c)
s=a*b*sin(c)*0.5
for i in[s,a+b+(a*a+b*b-2*a*b*cos(c))**0.5,s/a*2]:print('%5f'%i)

Measured memory_bytes: 7920
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
 
int dp[3030][3030][2];
 
int main(){
  int n, t;
  cin >> n >> t;
  vector<P> p;
  rep(i,n) {
    int a, b;
    cin >> a >> b;
    p.push_back({a,b});
  }
  //sort(p.begin(), p.end());
 
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < t; j++) {
      for (int k = 0; k < 2; k++) {
        if (k == 0) dp[i+1][j][1] = max(dp[i+1][j][1], dp[i][j][0] + p[i].second);
   
        if (j + p[i].first < t) {
            dp[i+1][j+p[i].first][k] = max(dp[i+1][j+p[i].first][k], dp[i][j][k] + p[i].second);
        }
 
        dp[i+1][j][k] = max(dp[i+1][j][k], dp[i][j][k]);
      }
    } 
  }
  cout << dp[n][t-1][1] << endl;
  return 0;
} 

Measured memory_bytes: 71936
using System;

namespace Aizu
{
    class OnlineJudge
    {
        public static void Main()
        {
            var p = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int xr1 = p[2] + p[4], xr2 = p[2] - p[4], yr1 = p[3] + p[4], yr2 = p[3] - p[4];
            Console.WriteLine((p[0] >= xr1 && 0 <= xr2 && p[1] >= yr1 && 0 <= yr2) ? "Yes" : "No");
        }
    }
}

Measured memory_bytes: 19652
#define MAX 100005
#define NIL -1
 
typedef struct{

  int parent, left, right;

}Node;
 
Node Tree[MAX];
int Depth[MAX];
int Height[MAX];
int degree[MAX];

int h;
 
int getDepth(int);
int getHeight(int);
void print(int);
 
 
int main(void){

  int i, n;
  int vertex;
  int child[2];
 
 
  scanf("%d", &n);
 
  for ( i = 0; i < n; i++ ) {
    Tree[i].parent = NIL;
    Tree[i].left = NIL;
    Tree[i].right = NIL;
  }
 
  for ( i = 0; i < n; i++ ){
    scanf("%d %d %d", &vertex, &child[0], &child[1]);
 


    if(child[0] == NIL && child[1] == NIL)
      degree[vertex] = 0;
 
  

    else if(child[0] == NIL && child[1] != NIL){
      degree[vertex] = 1;
      Tree[child[1]].parent = vertex;
      Tree[vertex].right = child[1];
    }
     
    else if(child[0] != NIL && child[1] == NIL){
      degree[vertex] = 1;
      Tree[child[0]].parent = vertex;
      Tree[vertex].left = child[0];
    }
 

    else{
      degree[vertex] = 2;
      Tree[child[0]].parent = vertex;
      Tree[child[1]].parent = vertex;
       
      Tree[vertex].left = child[0];
      Tree[vertex].right = child[1];
    }
  }
 
  for(i = 0;i < n; i++){
    Height[i] = getHeight(i);
  }
 
  for ( i = 0; i < n; i++ )
    Depth[i] = getDepth(i);
   
  for ( i = 0; i < n; i++ )
    print(i);
   
  return 0;
}
 
int getHeight(int u){
  int l = Tree[u].left;
  int r = Tree[u].right;
  int heightL = 0;
  int heightR = 0;
 
  if(l == NIL && r == NIL){
    return 0;
  }
 
  if(l != NIL){
    heightL = getHeight(l) + 1;
  }
 
  if (r != NIL){
    heightR = getHeight(r) + 1;
  }
 
  if(heightL < heightR){
    return heightR;
  }
  else{
    return heightL;
  }
}
 
 
int getDepth(int u){
  int d = 0;
 
  while(Tree[u].parent >= 0){
    u = Tree[u].parent;
    d++;
  }
 
  return d;
}
 
void print(int u){
  int index = Tree[u].parent;
 
  printf("node %d: parent = %d, ",u, Tree[u].parent);
  if(index == NIL){
    printf("sibling = %d, ",NIL);
  }
  else if(Tree[index].right != u){
    printf("sibling = %d, ",Tree[index].right);
  }
  else if(Tree[index].left != u){
    printf("sibling = %d, ",Tree[index].left);
  }
     
  printf("degree = %d, depth = %d, height = %d, ",degree[u], Depth[u], Height[u]);
 
  if(Tree[u].parent == NIL)
    printf("root\n");
 
  else if(degree[u] == 0)
    printf("leaf\n");
 
 
  else if(2 >= degree[u] && degree[u] >= 1)
    printf("internal node\n");
 
   
}
 




 

Measured memory_bytes: 624
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string word,wordL;
	cin>>word;
	int len=word.length(),lenPart=len/2;
	for(int i=0;i<(len-1)/2;i++)
		if(word[i]==word[len-i-1])
			continue;
		else 
			{
				cout<<"No"<<endl;
				return 0;
			}
	for(int i=0;i<lenPart;i++)
		wordL[i]=word[i];
	if(lenPart==2){
			if(wordL[0]==wordL[1]);
			else
			{	cout<<"No"<<endl;
				return 0;
			}
	}
	else {
	for(int i=0;i<(lenPart-1)/2;i++)
		if(wordL[i]==wordL[lenPart-i-1])
			continue;
		else 
			{
				cout<<"No"<<endl;
				return 0;
			}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 384
// ~/BAU/ACM-ICPC/Teams/Rampage/MMZA
// ~/sudo apt-get verdict Accepted
// practice...
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef long long ll;
typedef vector<pair<int, int>> vp;
typedef vector<vector<pair<int, int>>> vvp;
typedef unsigned long long ull;
typedef long double ld;
const int Mod = 1000000007;

int main()
{
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif
string s;
cin>>s;
bool ok=1;
int cee=0;
if(s[0]!='A')ok=0;
for(int i=2;i<s.size()-1;i++){
if(s[i]=='C')cee++;
else 
if((s[i]>='A' &&s[i]<='Z'))ok=0;
}
if((s[s.size()-1]>='A'&&s[s.size()-1]<='Z')||(s[1]>='A'&&s[1]<='Z'))ok=0;
if(ok&&cee==1)puts("AC");
else puts("WA");

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
using Pair = System.Tuple<int, int>;
using Edge = System.Tuple<int, int, long>;
//using Debug;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        //Solve();
        WriteLine(Solve());
    }
    static long Solve()
    {
        var num = Input.num;
        var tk = Input.ar;
        var ao = Input.ar;
        var res = 1L;
        for (var i = 0; i < num; i++)
        {
            var ist = true;
            var isa = true;
            if(i!=0)ist = tk[i] != tk[i - 1];
            if(i!=num-1)isa = ao[i] != ao[i + 1];
            if ((ist && isa && tk[i] != ao[i]) ||
                (ist && ao[i] < tk[i]) ||
                (isa && ao[i] > tk[i])) return 0;
            if (ist || isa) continue;
            res *= Min(tk[i], ao[i]);
            res %= Input.MOD;
        }
        return res;
    }
}

public class Input
{
    public static string read => ReadLine();
    public  static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
    public  static int num => ToInt32(read);
    public static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
    public  static long numL => ToInt64(read);
    public static char[][] gred(int h) 
        => Enumerable.Repeat(0, h).Select(v => read.ToCharArray()).ToArray();
    public static int[][] ar2D(int num)
        => Enumerable.Repeat(0, num).Select(v => ar).ToArray();
    public static long[][] arL2D(int num)
        => Enumerable.Repeat(0, num).Select(v => arL).ToArray();
    public const long Inf = (long)1e18;
    public const double eps = 1e-6;
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}


Measured memory_bytes: 38236
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    double R;
    cin >> R;
    cout << 2*R*3.1415 << endl;
    return 0;
}

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

int dp[3001][3001];
//string res[3001][3001];
int memo[3001][3001];
int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);

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

	memset(dp,-1,sizeof(dp));
	memset(memo,-1,sizeof(memo));
	int n = s.length();
	int m = t.length();

	dp[0][0] = 0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(s[i-1]==t[j-1])
			{
				dp[i][j] = max(dp[i][j],dp[i-1][j-1] + 1);
				//res[i][j] = res[i-1][j-1] + s[i-1];
				memo[i][j] = 2;
			}
			else
			{
				if(dp[i-1][j] < dp[i][j-1])
				{
					memo[i][j] = 1;
					//res[i][j] = res[i][j-1];
					dp[i][j] = dp[i][j-1];
				}
				else
				{
					//res[i][j] = res[i-1][j];
					memo[i][j] = 0;
					dp[i][j] = dp[i-1][j];
				}
			}
		}
	}

	string res = "";
	int l = n;
	int r = m;
	while(1)
	{
		if(l<=0 || r<=0)
		{
			break;
		}
		if(memo[l][r]==0)
		{
			l-=1;
		}
		else if(memo[l][r]==1)
		{
			r-=1;
		}
		else
		{
			res = s[l-1] + res;
			l-=1;
			r-=1;
		}
	}

	cout << res << '\n';
	
	return 0;
}


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

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


int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    vector<int>left(n+1,0);
    vector<int>right(n+1,0);
    int max=0;
    int min=0;
    
    for(int i=0;i<n;i++) left[i+1]=GCD(left[i],a[i]);
    for(int i=n-1;i>=0;i--) right[i]=GCD(right[i+1],a[i]);
    
    for (int i=0;i<n;i++) {
        int l = left[i];
        int r = right[i+1];
        if(GCD(l, r)>min) min=GCD(l,r);
    }
    
    cout<<min<<endl;
}



Measured memory_bytes: 1408
gets
cards = gets.chomp.split(" ").map(&:to_i).sort.reverse!
alice = 0
bob = 0
0.step(cards.size - 1, 2) { |i| alice += cards[i] }
1.step(cards.size - 1, 2) { |i| bob += cards[i] }
puts alice - bob

Measured memory_bytes: 1788
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };

struct MyStruct
{
	int list[13];
};


signed main() {
	int i, j, k, n, sum = 0, cnt = 0;
	string s, s1, s2;
	bool flag = false;
	vector<bool>list(100000,false);
	int a, b;
	


	while (cin >> a >> b ) {
		if ( a == 0 && b == 0 ) break;
		vector<tuple<int, int, int>>tlist;
	

		for (i = 1; i <= a; i++) {
			for (j = 1; j <= a; j++) {
				if (j == i) continue;

				for (k = 1; k <= a; k++) {
					if (j == k || k == i) continue;

					if (i + j + k == b && list[i]==false && list[j] == false && list[k] == false ) {
				
						vector<int>list3;
						list3 = { i,j,k };
						sort(list3.begin(), list3.end());

						tlist.push_back(make_tuple(list3[0], list3[1], list3[2]));
					}
				}
			}
		}
		
		sort(tlist.begin(), tlist.end());
		tlist.erase(unique(tlist.begin(), tlist.end()), tlist.end());
		/*auto itr = unique(tlist.begin(), tlist.end());
		tlist.erase(itr, tlist.end());
*/
		cout << tlist.size() << endl;

	}











	getchar();
	getchar();
	return 0;
}


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

template <class Abel> struct BIT {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0;                     // to be set
    
    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }
    
    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }
    
    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

int main() {
    int N; cin >> N;
    int Q; cin >> Q;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];
    vector<int> lefts(Q), rights(Q), ids(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> lefts[i] >> rights[i];
        --lefts[i];
        ids[i] = i;
    }
    sort(ids.begin(), ids.end(), [&](int i, int j) {
            return rights[i] < rights[j];});

    BIT<int> bit(N+5);
    vector<int> prev(1100000, -1);
    vector<int> res(Q, 0);
    int r = 0;
    for (auto i : ids) {
        for (; r < rights[i]; ++r) {
            bit.add(prev[a[r]]+2, r+2, 1);
            prev[a[r]] = r;
        }
        int tmp = bit.sum(lefts[i]+1, lefts[i]+2);
        res[i] = max(res[i], tmp);
    }
    for (int i = 0; i < Q; ++i) cout << res[i] << endl;
}

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

int main() {
  int N, D;
  cin >> N >> D;
  vector<long long>X(N);
  vector<long long>Y(N);

  long long ans=0;

  for(int i = 0; i < N; i++) {
      cin >> X.at(i);
      cin >> Y.at(i);
    }

  for(int i=0; i<N; i++){
    if(D>=(long double)pow((X.at(i)*X.at(i))+(Y.at(i)*Y.at(i)),0.50)){
    ans++;
    }
  }

  cout << ans << endl;

return 0;
}


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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define MOD 1000000007

typedef long long ll;

using namespace std;
int main()
{
    string S, T;
    int len = 3;
    cin >> S;
    cin >> T;
    int ans = 0;
    REP(i, len)
    {
        if (S[i] == T[i]) 
        {
            ans++;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
def resolve():
    W, H, N = list(map(int, input().split()))
    # (0,0)(W,H)を含む交点のx,y座標リスト
    white_W_list = list(range(W+1))
    white_H_list = list(range(H+1))
    for i in range(N):
        x, y, a = list(map(int, input().split()))
        if a == 1:
            white_W_list = [j for j in white_W_list if j >= x]
        elif a == 2:
            white_W_list = [j for j in white_W_list if j <= x]
        elif a == 3:
            white_H_list = [j for j in white_H_list if j >= y]
        elif a == 4:
            white_H_list = [j for j in white_H_list if j <= y]
    width = len(white_W_list) - 1
    length = len(white_H_list) - 1
    if width >= 1 and length >= 1:
        area = width * length
        print(area)
    else:
        print(0)

resolve()

Measured memory_bytes: 9224
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;
int main()
{
    // 文字列の入力
    string S;
	cin >> S;
	
	int n = 0;
	int nmax = 0;
	bool flag = false;
	
	for(int i = 0; i < 3; i++) {
		if(S[i] == 'R') {
			n++;
		} else {
			nmax = i;
		}
	}
	
	if(n == 2) {
		if(nmax == 1) {
			n = 1;
		} else {
			n = 2;
		}
	}
	
	printf("%d\n", n);
	
		
    return 0;
}

Measured memory_bytes: 3680
N = int(input())
A = list(map(int, input().split()))

A = sorted(A)

count_m = 0
count_z = 0
count_p = 0
sum_abs = 0

for i in range(N):
    if A[i] < 0:
        count_m += 1
        sum_abs -= A[i]
    elif A[i] == 0:
        count_z += 1
    else:
        count_p += 1
        sum_abs += A[i]

if count_m + count_z == 0:
    print(sum_abs-2*min(A))
    tmp = A[0]
    for i in range(N-2):
        print(tmp, A[i+1])
        tmp -= A[i+1]
    print(A[-1], tmp)

elif count_p + count_z == 0:
    print(sum_abs+2*max(A))
    tmp = A[-1]
    for i in range(N-1):
        print(tmp, A[i])
        tmp -= A[i]

elif count_p + count_m == 0:
    print(0)
    for i in range(N-1):
        print(0, 0)

else:
    print(sum_abs)
    cmz = count_m + count_z
    tmp = A[-1]
    for i in range(cmz - 1):
        print(tmp, A[i])
        tmp -= A[i]
    tmp_2 = A[cmz-1]
    if count_p != 0:
        for i in range(count_p-1):
            print(tmp_2, A[i+cmz])
            tmp_2 -= A[i+cmz]
        print(tmp, tmp_2)

Measured memory_bytes: 14020