akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdlib.h>
#include<set>

using namespace std;

int main(void)
{
    int N,M;
    cin>>N>>M;
    int flag=0;
    int a[M];
    for(int i=0;i<M;i++){
        cin>>a[i];
        if(i>0){
            if(a[i]-a[i-1]==1){
                flag=1;
            }
        }
    }
    
    if(flag==1){
        cout<<0<<endl;
    }
    else{
    if(N==1 && M==1){
        cout<<0<<endl;
    }
    else if(N==1 && M==0){
        cout<<1<<endl;
    }
    else if(N==2 && M==0){
        cout<<2<<endl;
    }
    else if(N==2 && M==1){
        cout<<1<<endl;
    }
    else if(N==2 && M==2){
        cout<<0<<endl;
    }
    else{
        
            long int n_1=1,n_2=2;
            long int n;
            int k=0;
        
            if(M>0 && a[0]==1){
                n_1=0;
                n_2=1;
                k=1;
                if(a[1]==2){
                    n_2=0;
                    k=2;
                }
            }
            else if(M>0 && a[0]==2){
                n_2=0;
                k=1;
            }
        
            for(int i=3;i<=N;i++){
                n=(n_1+n_2)%1000000007;
                if(M>0 && k<M){
                    if(a[k]==i){
                        n=0;
                        k++;
                    }
                }
                n_1=n_2;
                n_2=n;
            }
            cout<<n<<endl;
        
    }
}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

const int MOD = 1000000007;


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

    int red_count=0;
    rep(i,N){
        if (c[i] == 'R') red_count++;
    }
    int ans = 0;
    for(int i = 0; i < red_count;i++){
        if (c[i] == 'W') ans++;
    }

    cout << ans << endl;

}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define siz(v) (ll)(v).size()
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define repr(i, a, n) for (ll i = n - 1; (ll)a <= i; i--)
#define lb lower_bound
#define ub upper_bound
typedef pair<ll, ll> P;
typedef pair<ll, ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 + 99);
vector<ll> dx = {-1, 1, 0, 0}, dy = {0, 0, -1, 1};
template <typename T, typename U>
void chmin(T &t, const U &u)
{
    if (t > u)
        t = u;
}
template <typename T, typename U>
void chmax(T &t, const U &u)
{
    if (t < u)
        t = u;
}
template <typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <typename T>
T mpow(T a, T n)
{
    T res = 1;
    for (; n; n >>= 1)
    {
        if (n & 1)
            res = res * a;
        a = a * a;
    }
    return res;
}

//cin.tie(0);ios::sync_with_stdio(false);
//cout<<fixed<<setprecision(20);

signed main()
{
    string s;
    cin >> s;
    ll ans = 0, cnt = 1;
    vector<ll> v(0);
    rep(i, 1, siz(s))
    {
        if (s[i] == s[i - 1])
        {
            cnt++;
        }
        else
        {
            v.pb(cnt);
            cnt = 1;
        }
    }
    v.pb(cnt);


    bool f = (s[0] == '<'); //山
    if (f)
    {
        rep(i, 1, siz(v))
        {
            ll mx = max(v[i - 1], v[i]), mn = min(v[i - 1], v[i]);
            ans += mx * (mx + 1) / 2;
            ans += (mn - 1) * mn / 2;
            i++;
        }
    }
    else
    {
        rep(i, 2, siz(v))
        {
            ll mx = max(v[i - 1], v[i]), mn = min(v[i - 1], v[i]);
            ans += mx * (mx + 1) / 2;
            ans += (mn - 1) * mn / 2;
            i++;
        }

        ans += v[0] * (v[0] + 1) / 2;
    }
    if (s.back() == '<')
    {
        ans += v.back() * (v.back() + 1) / 2;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (ll)(n); i++)

int main() {
  ll n, y; cin >> n >> y;
  bool flag = 1;
  rep(i, n+1) {
    rep(j, n+1-i) {
      ll m = n-i-j;
      if (10000*i+5000*j+1000*m == y) {
        cout << i << ' ' << j << ' ' << m << endl;
        flag = 0;
        break;
      }
    }
    if (!flag) break;
  } 
  if (flag) cout << -1 << ' ' << -1 << ' ' << -1 << endl;
}

Measured memory_bytes: 3608
<?php
  $s = trim(fgets(STDIN));
  
  $flag = $s[0]==$s[1] && $s[2]==$s[3] && $s[0]!=$s[2];
  if(!$flag){
    $flag = $s[0]==$s[2] && $s[1]==$s[3] && $s[1]!=$s[2];
  }
  if(!$flag){
    $flag = $s[0]==$s[3] && $s[1]==$s[2] && $s[0]!=$s[2];
  }

  if($flag){
    echo "Yes\n";
  }else{
    echo "No\n";
  }

Measured memory_bytes: 4856
package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	a, b, t := nextInt(), nextInt(), nextInt()

	fmt.Println(b * (t / a))
}


Measured memory_bytes: 640
#include <iostream>
#include <stdlib.h>
using namespace std;
typedef long long ll;
int main(){
    ll n,k;
    cin >> n >> k;
    ll x = n % k;
    if (x < abs(x-k)) {
        cout << x;
    } else {
        cout << abs(x-k);
    }

    return 0;
}

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

using namespace std;

int main()
{

    int dp[10000 + 1] = { 0 };
    int N, W;
    cin >> N; cin >> W;
    vector<int> v, w;
    for (int i = 0; i < N; i++) {
        int v_tmp, w_tmp;
        cin >> v_tmp; cin >> w_tmp;
        v.push_back(v_tmp); w.push_back(w_tmp);
    }

    for (int i = 0; i < N; i++) {
        for (int j = W; j >= w[i]; j--) {
            dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
        }
    }

    cout << dp[W] << endl;
    return 0;
}

Measured memory_bytes: 3180
#include <stdio.h>
int main(void){

char a;
int b;

for(b=1;b<1200;b++){
a = getchar( );

////////////////////////////
if(a=='a'){
a='A';
}
else{
if(a=='b'){
a='B';
}
else{
if(a=='c'){
a='C';
}
else{
if(a=='d'){
a='D';
}
else{
if(a=='e'){
a='E';
}
else{
if(a=='f'){
a='F';
}
else{
if(a=='g'){
a='G';
}
else{
if(a=='h'){
a='H';
}
else{
if(a=='i'){
a='I';
}
else{
if(a=='j'){
a='J';
}
else{
if(a=='k'){
a='K';
}
else{
if(a=='l'){
a='L';
}
else{
if(a=='m'){
a='M';
}
else{
if(a=='n'){
a='N';
}
else{
if(a=='o'){
a='O';
}
else{
if(a=='p'){
a='P';
}
else{
if(a=='q'){
a='Q';
}
else{
if(a=='r'){
a='R';
}
else{
if(a=='s'){
a='S';
}
else{
if(a=='t'){
a='T';
}
else{
if(a=='u'){
a='U';
}
else{
if(a=='v'){
a='V';
}
else{
if(a=='w'){
a='W';
}
else{
if(a=='x'){
a='X';
}
else{
if(a=='y'){
a='Y';
}
else{
if(a=='z'){
a='Z';
}
////////////////////////
else{
if(a=='A'){
a='a';
}
else{
if(a=='B'){
a='b';
}
else{
if(a=='C'){
a='c';
}
else{
if(a=='D'){
a='d';
}
else{
if(a=='E'){
a='e';
}
else{
if(a=='F'){
a='f';
}
else{
if(a=='G'){
a='g';
}
else{
if(a=='H'){
a='h';
}
else{
if(a=='I'){
a='i';
}
else{
if(a=='J'){
a='j';
}
else{
if(a=='K'){
a='k';
}
else{
if(a=='L'){
a='l';
}
else{
if(a=='M'){
a='m';
}
else{
if(a=='N'){
a='n';
}
else{
if(a=='O'){
a='o';
}
else{
if(a=='P'){
a='p';
}
else{
if(a=='Q'){
a='q';
}
else{
if(a=='R'){
a='r';
}
else{
if(a=='S'){
a='s';
}
else{
if(a=='T'){
a='t';
}
else{
if(a=='U'){
a='u';
}
else{
if(a=='V'){
a='v';
}
else{
if(a=='W'){
a='w';
}
else{
if(a=='X'){
a='x';
}
else{
if(a=='Y'){
a='y';
}
else{
if(a=='Z'){
a='z';
}
else{if(a=='\n'){break;}}
}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
printf("%c",a);
}
printf("\n");
return 0;
}

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

int main(){
    int c[3][3];
    for(int i =0; i < 3; i++){
        for(int j =0; j < 3; j++){
            cin >> c[i][j];
        }
    }
    bool Possible = true;
    for(int j =0; j < 2; j++){
        int d1 = c[0][j+1] - c[0][j];
        int d2 = c[1][j+1] - c[1][j];
        int d3 = c[2][j+1] - c[2][j];
        if(!(d1== d2 && d2 == d3)){
            Possible = false;
            break;
        }
    }
    for(int i =0; i < 2; i++){
        if(! Possible) break;
        int d1 = c[i+1][0] - c[i][0];
        int d2 = c[i+1][1] - c[i][1];
        int d3 = c[i+1][2] - c[i][2];
        if(!(d1== d2 && d2 == d3)){
            Possible = false;
            break;
        }
    }
    if(Possible) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    // 整数の入力
    int a,b;
    cin >> a>>b;
    // スペース区切りの整数の入
    int d[a][b]={};
    string s[a];
    for(int i=0;i<a;i++){
    cin>>s[i];
    }
    char c[a][b];
    /*for(int i=0;i<a;i++) {
        for(int j;j<b;j++) {
            c[i][j] = s[i][j];
        }
    }
     */
for(int i=0;i<a;i++){
    for(int j=0;j<b;j++){
        if(s[i][j]=='#') {
            cout<< '#';
            continue;
        }
            int count=0;
        if(i>0) {
            if (s[i - 1][j] == '#')count++;
            if(j<b-1)
                if  (s[i - 1][j + 1] == '#')count++;
            if(j>0)
                if (s[i - 1][j - 1] == '#')count++;
        }
        if(j<b-1)
            if(s[i][j+1]=='#')count++;
        if(j>0)
            if(s[i][j-1]=='#')count++;
        if(i<a-1) {
            if (s[i + 1][j] == '#')count++;
            if(j<b-1)
                if (s[i + 1][j + 1] == '#')count++;
            if (j > 0)
                if (s[i + 1][j - 1] == '#')count++;
        }
        d[i][j]=count;
        cout<<d[i][j];
    }
    printf("\n");

}
    // 文字列の入力

    // 出力


    //cout <<  " " << s" << endl;
   // / std::cout << "Hello, World!" << std::endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		double max = 0.0;
		double min = 0.0;
		int count = 0;
		while(sc.hasNext()){
			double high = sc.nextDouble();
			if(count == 0){
				max = high;
				min = high;
			}
			if(high > max) max = high;
			if(high < min) min = high;
			count++;
		}
		System.out.println(max - min);
		sc.close();
	}

}

Measured memory_bytes: 18672
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define MOD 1000000007
#define INF 1e18
#define fcout cout << fixed << setprecision(15)
#define int long long
#define endl "\n"
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
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;};



signed main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    cin >> s;
    int n = s.size();
    int ans = 0;
    rep(i, n) {
        if(s[i] == '?') s[i] = 'D';
    }
    cout << s << endl;
    return 0;
}

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

A_diff = []
for i in range(N-1):
    A_diff.append(A[i+1] - A[i])
A_diff.append(K-A[N-1] + A[0])

print(K - max(A_diff))


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

int deg[5];

int main() {
	for (int i = 0; i < 3; ++i) {
		int u, v;
		scanf("%d %d", &u, &v);
		++deg[u], ++deg[v];
	}
	for (int i = 1; i <= 4; ++i) {
		if (deg[i] > 2) {
			puts("NO");
			return 0;
		}
	} 
	puts("YES");
}


Measured memory_bytes: 256
def checkpal(s):
    if s == s[::-1]:
        return True
    else:
        return False


st=input()
n=len(st)
#print(st[0:(n-1)//2],st[(n+3)//2:n])
if checkpal(st) and checkpal(st[0:(n-1)//2]) and checkpal(st[(n+3)//2-1:n]):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <string>
#include <cmath>
using namespace std;
int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    while (1)
    {
        c -= b;
        if (c <= 0)
        {
            cout << "Yes" << endl;
            return 0;
        }
        a -= d;
        if (a <= 0)
        {
            cout << "No" << endl;
            return 0;
        }
    }
}

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

int main()
{
  // char C;
  // cin >> C;
  // C++;
  // cout << C << endl;
  // int N,K,M;
  // cin >> N >> K >> M;
  // vector<int> A(N);

  // for (int i;i < N-1; i++) {
  //   int point;
  //   cin >> point;
  //   A.at(i) = point;
  // }

  // int sum = accumulate(A.begin(), A.end(), 0);
  // if(M*N - sum <= 0) {
  //   cout << 0 << endl;
  // } else if (M * N - sum > K) {
  //   cout << -1 << endl;
  // } else {
  //   cout << M * N - sum << endl;
  // }

  int N,M;
  int correct_count = 0;
  int penalty = 0;
  cin >> N >> M;
  vector<int> answered(N+1, 0);
  vector<int> penalties(N+1, 0);
  for (int i=0;i < M;i++) {
    int question_num;
    cin >> question_num;
    string is_correct;
    cin >> is_correct;
    if (is_correct == "AC" && answered.at(question_num) == 0)
    {
      correct_count++;
      answered.at(question_num) = 1;
    }
    else if (is_correct == "WA" && answered.at(question_num) == 0)
    {
      penalties.at(question_num) += 1;
    }
  }
  for (int i = 1; i <= N; i++) {
    if (answered.at(i) == 1) {
      penalty += penalties.at(i);
    }
  }
  cout << correct_count << " " << penalty << endl;
}



Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstdlib>
#include <numeric>
using namespace std;
#define MAX_N 400

// Input
int X;

int main() {
  cin >> X;

  int ct_500 = X / 500;
  int sum = X - ct_500 * 500;
  int ct_5 = sum / 5;

  cout << ct_500 * 1000 + ct_5 * 5 << endl;
}


Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;
typedef pair<int, int> pii;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    /*
    8 
    1 10 19 100 198 199 299 129121 
    12 98 298 349 900 9384 19811 23223 
    */
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<pii> v(2 * N);
    REP(i, 0, N) {
        int a;
        cin >> a;
        v[i] = {a, 0};
    }
    REP(i, 0, N) {
        int b;
        cin >> b;
        v[i + N] = {b, 1};
    }

    sort(begin(v), end(v));

    lli ans = 1;
    lli mod = 1000000007;

    vector<int> stk[2];

    REP(i, 0, 2 * N) {
        int x, t;
        tie(x, t) = v[i];
        if (stk[!t].size() == 0) {
            stk[t].push_back(x);
        } else {
            ans = (ans * stk[!t].size()) % mod;
            stk[!t].pop_back();
        }
    }

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


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

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x)  cerr << #x << " = " << x << endl
using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ld PI = 3.14159265359;

const ll MOD = (ll) 1e9 + 7;
const ll MAXN = (ll) 1e5 + 10;
const ll INF = (ll) 9223372036854775;
const ld EPS = (ld) 1e-8;


ll H, W;
ll cnt[10];
map<pll, ll> mp;

bool valid(ll x, ll y){
	return ( (x + 2 <= H) and (0 < x) and (y + 2 <= W) and (0 < y) );
}

ll beshmor(ll x, ll y){
	ll ans = 0;
	for(int i2 = 0; i2 < 3; i2++){
		for(int j2 = 0; j2 < 3; j2++){
			if( mp.count({x + i2, y + j2}) == 1) ans ++;
		}
	}
	//debug(ans);
	return ans;
}

int main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll n;
	cin >> H >> W >> n;
	cnt[0] = (H - 2) * (W - 2);
	debug(n);
	ll a, b, res = 0;
	for(int k = 0; k < n; k++){
		cin >> a >> b;
		for(int i = 0; i < 3; i++){
			for(int j = 0; j < 3; j++){
				//debug(i);
				if(valid(a - i, b - j)){
					//debug("c");
					res = beshmor(a - i, b - j);
					//cerr << res << '\n';
					cnt[res] --;
					cnt[res + 1] ++;
				}
			}
		}
		mp[{a, b}] = 1;
	}
	for(int i = 0; i < 10; i++) cout << cnt[i] << '\n';
	return 0;
}


/*
                                 ____              ,----..               ,----..
   ,---,                       ,'  , `.           /   /   \             /   /   \
  '  .' \                   ,-+-,.' _ |          /   .     :           /   .     :
 /  ;    '.              ,-+-. ;   , ||         .   /   ;.  \         .   /   ;.  \
:  :       \            ,--.'|'   |  ;|        .   ;   /  ` ;        .   ;   /  ` ;
:  |   /\   \          |   |  ,', |  ':        ;   |  ; \ ; |        ;   |  ; \ ; |
|  :  ' ;.   :         |   | /  | |  ||        |   :  | ; | '        |   :  | ; | '
|  |  ;/  \   \        '   | :  | :  |,        .   |  ' ' ' :        .   |  ' ' ' :
'  :  | \  \ ,'        ;   . |  ; |--'         '   ;  \; /  |        '   ;  \; /  |
|  |  '  '--'          |   : |  | ,             \   \  ',  /          \   \  ',  /
|  :  :                |   : '  |/               ;   :    /            ;   :    /
|  | ,'                ;   | |`-'                 \   \ .'              \   \ .'
`--''                  |   ;/                      `---`                 `---`
                       '---'

*/




Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using pll = pair<ll, ll>;
using edge = pair<int, ll>;
using Graph = vector<vector<int>>; 
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main(){
  int n; cin >> n;
  vector<ll> a(n);
  for(int i = 0; i < n; ++i)cin >> a[i];

  ll now = 1, ans = 0;
  for(int i = 0; i < n; ++i){
    ans += a[i]/now;
    ll tmp = a[i]%now;
    if(tmp==0) --ans, tmp=now;
    if(now == a[i]) ++now;
    if(i==0)now= 2;
    //cout << ans << " " << now << endl;
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	private static Scanner sc;

	public static void main(String[] args) throws Exception {
		sc = new Scanner(System.in);
		int N = sc.nextInt();
		int Q = sc.nextInt();
		String S = sc.next();

		// 先にX文字目にACは何文字あったか、の数列をつくっておく。
		// ていうか問題の入力を始めてから回答を受け取るまでの時間を測ってるんだな。
		// 随時答えるほうがよいんだな。

		int[] t = new int[N];
		t[0] = 0;
		for (int i = 0; i < N - 1; i++) {

			t[i + 1] = t[i] + (S.substring(i, i + 2).equals("AC") ? 1 : 0);
		}

		question[] questions = new question[Q];

		for (int i = 0; i < Q; i++) {
			questions[i] = new question();
			questions[i].i = sc.nextInt();
			questions[i].r = sc.nextInt();
			// System.out.println(questions[i]);
		}

		for (question q : questions) {
			System.out.println(t[q.r - 1] - t[q.i - 1]);
		}

	}
}

class question {
	int i;
	int r;

	public String toString() {
		return "i:" + i + ",r:" + r;
	}
}

Measured memory_bytes: 101604
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;

ll prime[30]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
ll c[30];
ll cnt=0;

ll power(ll a,ll n){
    ll ans=1;
    while(0<n){
        if(n%2==0){
            a*=a;
            n>>=1;
        }else{
            ans*=a;
            n--;
        }
    }
    return ans;
}

int main(void){
    ll n;cin>>n;
    while(prime[cnt]<=n){
        ll x=prime[cnt];
        
        while(x<=n){
            c[cnt]+=(n/x);
            x*=prime[cnt];
            //cout<<x<<endl;
        }
        cnt++;
        if(cnt==25)break;
    }
    ll a4=0,a2=0,a14=0,a24=0,a74=0;
    for(int i=0;i<30;i++){
        if(c[i]>=2){a2++;/*cout<<prime[i]<<endl;*/}
        if(c[i]>=4){a4++;/*cout<<prime[i]<<endl;*/}
        if(c[i]>=14){a14++;/*cout<<prime[i]<<endl;*/}
        if(c[i]>=24){a24++;/*cout<<prime[i]<<endl;*/}
        if(c[i]>=74){a74++;/*cout<<prime[i]<<endl;*/}
    }
    //cout<<a2<<" "<<a4<<" "<<a14<<" "<<a24<<" "<<a74;
    cout<<a74+a24*(a2-1)+a14*(a4-1)+a4*(a4-1)/2*(a2-2)<<endl;
    
    return 0;
}


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

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

  int cnt = 1;
  int sgn = 0;
  int lA;
  cin >> lA;
  for (int i = 1; i < N; i++) {
    int A;
    cin >> A;

    if (sgn == 0) {
      sgn = A > lA ? 1 : A < lA ? -1 : 0;
    }

    if (sgn == 1 && A < lA || sgn == -1 && A > lA) {
      sgn = 0;
      cnt++;
    }
    lA = A;
  }

  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

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

using ll = long long;
using namespace std;

const ll 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 {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=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 {
    mint res(*this);
    return res/=a;
  }
};

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

ll N, K;
ll a[30];
mint dp[30][1010];

int main()
{
  scanf( "%lld%lld", &N, &K );
  
  combination comb( N );

  rep( i, K )
    scanf( "%lld", a+i );

  dp[0][0] = 1;

  rep( i, K ) rep( j, N+1 ) rep( k, N-j+1 )
    dp[i+1][j+k] += dp[i][j]*comb( N-j, k )*comb( N-k, a[i]-k );

  printf( "%lld\n", dp[K][N].x );

  return 0;
}

Measured memory_bytes: 512
def main():
    a, v = list(map(int, input().split()))
    b, w = list(map(int, input().split()))
    t = int(input())
    if w >= v:
        print('NO')
        exit()
    if abs(a - b) <= (v - w) * t:
        print('YES')
    else:
        print('NO')


if __name__ == '__main__':
    main()


Measured memory_bytes: 9184
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
  int K, N;
  cin >> K >> N;
  vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }

  int max_dist = 0;
  for (int i = 0; i < N - 1; ++i) {
    int dist = A[i + 1] - A[i];
    dist = min(dist, K - dist);
    max_dist = max(max_dist, dist);
  }

  int dist = A[N - 1] - A[0];
  dist = min(dist, K - dist);
  max_dist = max(max_dist, dist);

  cout << K - max_dist << endl;
  
  return 0;
}


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

#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
#define PI 3.14159265358979
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}
bool compare_by(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second > b.second;
    }
}

vector<pair<int,ll>> vec[100000];
ll cost[100000];
void dfs(int now,ll COST){
    cost[now]=COST;
    int next;
    REP(i,vec[now].size()){
        next=vec[now][i].first;
        if(cost[next]<0){
            dfs(next,COST+vec[now][i].second);
        }
    }
}
int counter(int x){
    if(!x)return 0;
    return counter(x>>1)+(x&1);
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    char c;
    cin>>c;
    c++;
    cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 3584
#include <stdio.h>
#include <iostream>
#include <vector>
// #include <bits/stdc++.h>
#include <queue>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cmath>

using namespace std;
typedef long long ll;

#define rep(i,k,n) for(ll i=k; i<(ll)(n); i++)


struct UnionFind {
    vector<ll> par; //par[a]=b: aの親がb

    UnionFind(ll N) : par(N) { //初めは全て根として初期化
        rep(i,0,N) par[i] = i;
    }

    ll root(ll x) { //xの属する根を求める
        if(par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(ll x, ll y) { //xとyの木を併合
        ll rx = root(x);
        ll ry = root(y);
        if(rx == ry) return; //根が同じときはそのまま
        par[rx] = ry;
    }

    bool same(ll x, ll y) { //x,y の属する木が同じならtrue
        return root(x) == root(y);
    }
};


int main(){
    ll n,m; cin >> n >> m;
    UnionFind tree(n);
    vector<ll> a(m),b(m);
    rep(i,0,m) {
        cin >> a[i] >> b[i];
        --a[i]; --b[i];
        tree.unite(a[i],b[i]);
    }

    ll ans = 0;
    vector<ll> group_size(n);
    rep(i,0,n) { //各グループの人数を数える
        group_size[tree.root(i)]++;
    }
    rep(i,0,n) {
        if(group_size[i] > 0) ans++;
    }

    cout << ans-1 << endl;

    return 0;
}

Measured memory_bytes: 6420
#include <cstdio>
#define repu(i,x,y) for (int i=x; i<=y; ++i)
#define repd(i,x,y) for (int i=x; i>=y; --i)
using namespace std;

const int p=1000000007;
int n,m,k,s0[21],s1[21],f[21][530000],nxt[21][530000],ans;

int main()
{
    scanf("%d%d%d",&n,&m,&k),--n;
    while (k--)
    {
        int a,b,c;
        scanf("%d%d%d",&a,&b,&c);
        (c?s1[a]:s0[a])|=1<<(b-1);
    }
    repu(i,0,n-1)
        repu(j,0,(1<<n)-1)
            if (j&(1<<i))
            {
                nxt[i][j]=j^(1<<i);
                repu(k,i+1,n-1)
                    if (!(j&(1<<k)))
                    {
                        nxt[i][j]^=1<<k;
                        break;
                    }
            }
    f[0][0]=1;
    repu(i,1,m)
    {
        static int g[21][530000];
        repu(j,0,(1<<n)-1)
            g[n][j]=f[i-1][j];
        repd(j,n-1,0)
            repu(k,0,(1<<n)-1)
            {
                g[j][k]=g[j+1][k];
                if (k&(1<<j))
                    (g[j][k]+=g[j+1][nxt[j][k]])%=p;
            }
        repu(j,0,(1<<n)-1)
            if (!(s0[i]&j) && (s1[i]&j)==s1[i])
                f[i][j]=g[0][j];
    }
    repu(i,0,(1<<n)-1)
        (ans+=f[m][i])%=p;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 127104
N = int(input())
X = list(map(int, input().split()))

Max = max(X)
p_min = 1000000
for i in range(1, 101):
    p = 0
    for j in range(len(X)):
        p += (X[j] - i)**2
    if  p < p_min:
        p_min = p
    else:
        p_min = p_min
print(p_min)


Measured memory_bytes: 3060
<?php
  list($a, $b, $x) = explode(" ", trim(fgets(STDIN)));

  if($x * 2 <= $a * $a * $b){
    $r = ($x * 2) / ($a * $b);
    echo 90 - rad2deg(atan($r/$b));
  }
  else{
    $x1 = $x - ($a * $a * $b / 2);
    $r = $b - (($x1 * 2) / ($a * $a));
    echo 90 - rad2deg(atan($a/$r));
  }


Measured memory_bytes: 16444
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int r,d,x,i;
    scanf("%d %d %d",&r,&d,&x);
    int p[10];p[0]=x;
    for(i=1;i<=10;i++)
    {
        p[i]=(r*p[i-1])-d;
        printf("%d\n",p[i]);
    }
}



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

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int N, X, T;
    cin >> N >> X >> T;
    int q = (N / X) + (N % X != 0);
    cout << q*T;

    return 0;
}


Measured memory_bytes: 3596
def main() :
    N,D = [int(i) for i in input().split()]

    # if (N <= 2*D+1) :
    #     print(1)

    # for i in range(N) :
    #     n = (1 + 2*D) * i
    #     if(N <= n) :
    #         print(i)
    #     break

    for i in range(N+1) :
        n = (1 + 2*D) * i
        if(N <= n) :
            print(i)
            break


main()

Measured memory_bytes: 2940
#include <algorithm>
#include <cstdio>
#include <cstring>
#define mid (l + r) / 2

const int N = 2e5 + 52;

int n, m, a[N];
bool check(int x) {
	for (int i = 0; i < m - 1; i++) {
		if ((a[m + i] <= x && a[m + i + 1] <= x) || (a[m - i] <= x && a[m - i - 1] <= x))
			return 1;
		if ((a[m + i] > x && a[m + i + 1] > x) || (a[m - i] > x && a[m - i - 1] > x))
			return 0;
	}
	return a[1] <= x;
}

int l, r;
int main() {
	scanf("%d", &n);
	m = n, n = n * 2 - 1;
	for (int i = 1; i <= n; i++) scanf("%d", a + i);
	for (l = 1, r = n; l <= r;)
		if (check(mid))
			r = mid - 1;
		else
			l = mid + 1;
	printf("%d", l);
}

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

/* 店の位置（近い順に並んでいる前提）*/
int pos[100001];

/* 店番号の範囲l～rの中のdstに一番近い店番号を返す */
static int search_nearest(int l, int r, int dst);

/* iの絶対値を返す */
int abs(int i);

/* a,bの小さい方を返す */
int min(int a, int b);

/* qsort用比較関数(int型値降順) */
int cmp_int(const void *a, const void *b);

int main(){
    int n,m,d,k;
    int sum,nearest,i;

    while( (scanf("%d",&d)>0) && (d>0) ){

        /* 入力 n m */
        scanf("%d",&n);
        scanf("%d",&m);

        /* 店の位置 (本店は位置0と位置dの2店舗扱いにする)*/
        pos[0] = 0;
        for(i=1;i<n;i++){
            scanf("%d",&pos[i]);
        }
        pos[n] = d;

        /*  */
        qsort(&pos[1], n-1, sizeof(int), cmp_int);

        /* 宅配毎の距離計算 */
        sum = 0;
        for(i=0;i<m;i++){
            scanf("%d",&k);
            nearest = search_nearest(0,n,k);
            sum += abs(pos[nearest] - k);
        }
        printf("%d\n",sum);
    }

    return 0;
}


static int search_nearest(int l, int r, int dst){
    int c,next_l,next_r;

    /* 再帰の終了条件：残り店舗候補が2つ */
    if(l+1==r){
        
        if(abs(pos[l]-dst)<abs(pos[r]-dst)){
            return l;
        }else{
            return r;
        }
    }else{
        /* 二分探索 */
        next_l = l;
        next_r = r;
        c = (l+r)/2;

        if(pos[c]<dst){
            next_l = c;
        }else{
            next_r = c;
        }

        return search_nearest(next_l,next_r,dst);
    }
}

int abs(int i){
    return (i<0)?i:-i;
}

int min(int a,int b){
    return (a<b)?a:b;
}


int cmp_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}



Measured memory_bytes: 2476
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <utility>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

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

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

bool cmp(const P &p1, const P &p2) {
    if (p1.first != p2.first) {
        return p1.first > p2.first;
    } else {
        return p1.second < p2.second;
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N, M, K, L;
    while (cin >> N >> M >> K >> L, N) {

        vector<P> anime(N);
        vector<P> fav(M);
        {
            map<string, ll> mp;
            REP(i, 0, N) {
                cin >> anime[i].second >> anime[i].first;
                mp[anime[i].second] = anime[i].first;
            }

            REP(i, 0, M) {
                cin >> fav[i].second;
                fav[i].first = mp[fav[i].second];
            }
        }
        sort(anime.begin(), anime.end(), cmp);
        sort(fav.begin(), fav.end(), cmp);
        if (N == K) {
            cout << M << endl;
            continue;
        }

        int l = 0, r = min(K, M);
        int ans = 0;
        while (l <= r) {
            auto cp = anime;
            int mid = (l + r) / 2;
            ll sum = 0;
            REP (i, 0, mid) {
                int p1 = i, p2 = K - mid + i;
                if (cmp(cp[p2], fav[p1])) {
                    sum += cp[p2].first - fav[p1].first;
                    sum += (cp[p2].second < fav[p1].second);
                    swap(cp[p2], cp[p2 + 1]);
                } 
            }
            if (sum <= L) {
                ans = mid;
                l = mid + 1;
            } else {
                r = mid - 1;
            }
        }
        cout << ans << endl;
    }

    return 0;
}



Measured memory_bytes: 22708
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)

ll gcd (ll a, ll b){ return b == 0? a : gcd(b, a % b); }
void solve(long long N, std::vector<long long> A){
    if(N==2) {
        cout << (A[0]>A[1]? A[0]:A[1]) << endl;
        return;
    }
    vll L(N, 0), R(N, 0);
    L[0] = A[0];
    for(ll i=1; i< N; i++){
        L[i] = gcd(L[i-1], A[i]);
    }
    R[N-1] = A[N-1];
    for(ll i=N-2; i>=0; i--){
        R[i] = gcd(R[i+1], A[i]);
    }
    ll ans = max(R[1], L[N-2]);
    for(ll i=1; i< N-1; i++){
        ans = max(ans, gcd(L[i-1], R[i+1]));
    }
    cout << ans << endl;

}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 2560
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn get<T: FromStr>() -> T
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }

    #[allow(dead_code)]
    pub fn get2<T: FromStr, U: FromStr>() -> (T, U)
    where
        <T as FromStr>::Err: Debug,
        <U as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    }

    #[allow(dead_code)]
    pub fn get3<S: FromStr, T: FromStr, U: FromStr>() -> (S, T, U)
    where
        <S as FromStr>::Err: Debug,
        <T as FromStr>::Err: Debug,
        <U as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    }
}

#[allow(unused_macros)]
macro_rules! debug {
    ($x: expr) => {
        println!("{}: {:?}", stringify!($x), $x)
    }
}

fn main() {
    let n: usize = util::get();
    let edges: Vec<Vec<usize>> = (0..n).map(|_| util::gets()).collect();

    let mut ans = 0;
    for i in 0..n - 1 {
        for j in i + 1..n {
            let e = edges[i][j];
            let mut need = true;

            for k in 0..n {
                if k == i || k == j {
                    continue;
                }
                match e.cmp(&(edges[i][k] + edges[k][j])) {
                    Ordering::Equal => {
                        need = false;
                    }
                    Ordering::Greater => {
                        println!("-1");
                        return;
                    }
                    _ => (),
                }
            }
            if need {
                ans += e;
            }
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
def main():

    n = int(input())
    list_rev = []
    temp = list(str(n))
    for i in range(len(temp)):
        list_rev.append(int(temp[-i-1]))
    ans = list_rev[0]
    for i in range(1,len(temp)):
        a = list_rev[i] + ans
        b = list_rev[i] - 1 + 9 * i
        ans = max(a,b)
    print(ans)


def digit_int(num, dig):
    str_num = str(num)
    list_num = list(str_num)
    return list_num[-dig]
if __name__ == '__main__':
    main()


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

int main() {
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
	cin>>a[i];
	sort(a,a+n);
	int count =0;
	for(int i=0;i<n;i++)
	{
		int m = i+2;
		for(int j=i+1;j<n;j++)
		{
			while(m<n&&(a[i]+a[j]>a[m]))
			m++;
			if(m>j)
			count+=m-j-1;
		}
	}
	cout<<count;
	return 0;
}

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

using namespace std;

typedef long long int ll;
#define pb push_back
#define ALL(a) (a).begin() , a.end()

int mod = 1e9 + 7;
int add(int a, int b){
	if(a + b >= mod)return a+ b - mod;
	return a + b;
}
int mul(int a, int b){
	return 1LL * a * b  % mod;
}
int power(int a, int b){
	int re = 1;
	while(b){
		if(b&1)re= mul(re, a);
		a = mul(a, a);
		b>>=1;
	}
	return re;
}
int const N = 100 *1001;

/********************i**********************************/
vector<int> edge[N];
int dp[N][2];
void dfs(int a, int par){
	int w = 1, b = 1;
	for(int bb : edge[a]){
		if(bb == par)continue;
		dfs(bb, a);
		w = mul(w, add(dp[bb][1], dp[bb][0]));
		b = mul(b, dp[bb][1]);
		// cout << " a - b " << a <<  " " << b << " w-b " << w <<  " " <<  b << endl;

	}
	dp[a][1] = w;
	dp[a][0] = b;
	// cout << a << " " << w << " " << b  << endl;

}
void solve(){
	int n;
	cin >> n;
	for(int x = 1; x<n; x++){
		int a, b; cin >> a >> b;
		edge[a].pb(b);
		edge[b].pb(a);
	}
	dfs(1, 0);
	cout << add(dp[1][1] , dp[1][0]) ;
}
/******************************************************/
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(nullptr);
	int t;
	t = 1;
	// cin >> t;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 13440
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


int N;

int main() {
  cin >>N;
  vector<vector<bool>> A(N, vector<bool>(N, 0));
  rep(i, N){
    int u,k; cin >>u >>k; u--;
    rep(j, k){
      int x; cin >>x; x--; A[u][x] = 1;
    }
  }
  rep(i, N){
    rep(j, N){
      cout <<A[i][j];
      if (j == N-1) cout <<endl;
      else cout <<" ";
    }
  }
}


Measured memory_bytes: 3108
#include <stdio.h>

int  main(){

  int n,s,i,j;
  int a[10];

  while(1){
    scanf("%d",&n);
    if(n==0)break;
    for(i=0;i<10;i++)a[i]=0;
    for(i=0;i<n;i++){
      scanf("%d",&s);
      a[s]++;
    }
    for(i=0;i<10;i++){
      if(a[i]==0)printf("-\n");
      else {
	for(j=a[i];j>0;j--)printf("*");
	printf("\n");
      }
    }
  }
  return 0;
}

Measured memory_bytes: 568
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int a,b,x,y;
    scanf("%d%d%d%d", &a, &b, &x, &y);
    printf("%lf %d\n",double(a)*double(b) / 2, x+x == a && y +y==b);
    return 0;
}

Measured memory_bytes: 256
/*{{{*/
#include "bits/stdc++.h"
using namespace std;

#define MT make_tuple
#define all(x) begin(x), end(x)
#define putchar(x) cout << (x)
static int fastio = [](){ ios_base::sync_with_stdio(false); cin.tie(0); cout.precision(17); return 0; }();
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template<typename ...T> string format(const string& fmt, T&&... args) {
    size_t sz = snprintf(nullptr, 0, fmt.c_str(), args...) + 1;
    unique_ptr<char[]> buf(new char[sz]);
    snprintf(buf.get(), sz, fmt.c_str(), args...);
    return string(buf.get(), buf.get() + sz - 1);
}

template<class T> struct rge { T b, e; auto begin() const { return b; } auto end() const { return e; } };
template<class T> rge<T> range(T i, T j) { return rge<T>{i, j}; }
template<class T> auto dud(T* x) -> decltype(cerr << *x, 0);
template<class T> char dud(...);

struct debug {
#ifdef LOCAL
    debug(int line) {
        if(line) cerr << "LINE(" << line << ") -> ";
    }
    template<class T> typename enable_if<sizeof dud<T>(0) != 1, debug&>::type operator<<(T i) {
        cerr << boolalpha << i; return * this;
    }
    template<class T> typename enable_if<sizeof dud<T>(0) == 1, debug&>::type operator<<(T i) {
        return *this << range(begin(i), end(i));
    }
    template<class T, class U> debug& operator<<(pair<T, U> d) {
        return *this << "(" << d.first << ", " << d.second << ")";
    }
    debug& operator<<(tuple<>&) { return *this << "()"; };
    template<class ...T> debug& operator<<(tuple<T...> d) {
        *this << "("; debug_tuple<sizeof...(T), 0>(d);
        return *this << ")";
    }
    template<size_t L, size_t I, class T> void debug_tuple(const T& t) {
        *this << (I == 0 ? "" : ", ") << get<I>(t);
        if(I + 1 < L) debug_tuple<L, (I + 1) % L>(t);
    }
    template<class T> debug & operator <<(rge<T> d) {
        *this << "[";
        for(auto it = d.b; it != d.e; ++it)
            *this << (it != d.b ?  ", " : "") << *it;
        return *this << "]";
    }
    debug& operator<<(ostream&(*pf)(std::ostream&)) {
        cerr << pf; return *this;
    }
#else
    debug(int) {}
    template<class T> debug& operator<<(T&&) { return *this; }
    debug& operator<<(ostream&(*)(std::ostream&)) { return *this; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ << ": " << (__VA_ARGS__) << "] "

#define debug0()  debug(__LINE__)
#define debug1(x) debug(0)
#define GET_MACRO(_0, _1, NAME, ...) NAME
#define debug(...) GET_MACRO(_0, ##__VA_ARGS__, debug1, debug0)(__VA_ARGS__)
/*}}}*/
using LL = long long;

const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const LL LLINF = 0x3f3f3f3f3f3f3f3f;
const int MAX_N = 200005;

void solve(int) {
    string S, T;
    cin >> S >> T;
    int n = S.size();
    int ans = 0;
    for(int i = 0; i < n; ++i) {
        ans += (S[i] != T[i]);
    }
    cout << ans << endl;
}

int main() {
    int T = 1;
    //cin >> T;
    for(int i = 1; i <= T; ++i) {
        solve(i);
    }
    return 0;
}


Measured memory_bytes: 3796
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

template<typename T>
T gcd(T a, T b){
    if(b > a) swap(a, b);
    T tmp;
    while(b != 0){
        tmp = a % b;
        a = b;
        b = tmp;
    }
    return a;
}

template<typename T>
T lcm(T a, T b){
    return a * b / gcd(a, b);
}

int N;
ll M;
ll a[100000];
ll l = 1;
signed main(){
    cin >> N >> M;
    int cnt = 0;
    rep(i, N){
        cin >> a[i];
        int tmp = 0;
        while(a[i] % 2 == 0){
            tmp++;
            a[i] /= 2;
        }
        a[i] = a[i] << (tmp-1);
        if(i == 0){
            cnt = tmp;
        }
        else if(tmp != cnt){
            cout << 0 << endl;
            return 0;
        }
        l = lcm(l, a[i]);
        if(l > M){
            cout << 0 << endl;
            return 0;
        }
    }
    cout << (M/l+1)/2 << endl;
}

/*
2 20
4 12
X=6 が半公倍数
*/

Measured memory_bytes: 1024