akhauriyash/Code-Regression huggingface dataset:
N = int(input())
A = list(map(int,input().split(' ')))
ans = set()

for i in range(N-1,-1,-1):
  a = A[i]
  for j in range(i+1,N+1,i+1):
    if j in ans:
      a += 1
  if a % 2:
    ans.add(i+1)
print(len(ans))
print(*ans)

Measured memory_bytes: 15764
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;
using namespace std;

int main(){
    int t[13] = {0,1,2,1,3,1,3,1,1,3,1,3,1};
    
    int x,y;
    cin>>x>>y;
    if(t[x]==t[y]){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
 
return 0;
}

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

std::string s;

int main() {
  std::cin >> s;
  std::sort(s.begin(), s.end());
  if (s == (std::string)"abc") {
    puts("Yes");
  } else {
    puts("No");
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static boolean[][] g;
	static boolean[] vis;
	static int n, m, ans = 0;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		m = sc.nextInt();
		int[] a = new int[m];
		int[] b = new int[m];
		g = new boolean[n][n];
		vis = new boolean[n];
		for(int i = 0 ; i < m ; i++) {
			a[i] = sc.nextInt() - 1;
			b[i] = sc.nextInt() - 1;
			g[a[i]][b[i]] = g[b[i]][a[i]] = true;
		}
		vis[0] = true;
		dfs(0, 0);
		System.out.println(ans);
	}

	static void dfs(int x, int pos) {
		if(pos == n - 1) {
			boolean ok = true;
			for(int i = 0 ; i < n ; i++) {
				if(!vis[i]) ok = false;
			}
			if(ok) ans++;
			return;
		}
		for(int i = 0 ; i < n ; i++) {
			if(!vis[i] && g[x][i]) {
				vis[i] = true;
				dfs(i, pos + 1);
				vis[i] = false;
			}
		}
	}

}


Measured memory_bytes: 23636
#include <bits/stdc++.h>	
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ld long double
#define pii pair <int, int>
#define sz(a) (int)(a.size()) 
#define resize(v) v.resize(unique(all(v)) - v.begin()); 
#define all(a) a.begin(), a.end()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it ++)

// random_device rd; mt19937 g(rd());    
                                        	
using namespace std;
using namespace __gnu_pbds;
 
void Fast_Read_Out()
{
    ios_base::sync_with_stdio(0);
    cin.tie(), cout.tie();
}
 
void Random()
{
    unsigned int seed;                                                                        
    asm("rdtsc" : "=A" (seed));
    srand(seed);        
}
 
unsigned int Time()
{
     unsigned int time = clock() / 1000.00;                           
     return time;
}

template <typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>; 
 
const int mod = (int)1e9 + 7;
const int N = (int)2e5 + 123;

int n, p;
char c[N];
map <int, int> d;
int cur;
int t[N];
long long res;

int mult(int a, int b)
{
	return 1ll * a * b % p;
}

int add(int a, int b)
{
	a += b;
	if(a >= p) a %= p;
	return a; 
}

main ()
{
	#ifdef JUDGE
		freopen("input.txt", "r", stdin);
	#endif		
	Fast_Read_Out();
	Random();
	cin >> n >> p;
	t[0] = 1;
	for(int i = 1; i <= n; i++) cin >> c[i], t[i] = mult(t[i - 1], 10);
	if(p != 2 && p != 5)
	{
		d[0]++;
		for(int i = n; i >= 1; i--) 
		{
			cur = add(cur, mult(t[n - i], c[i] - '0'));
			res += d[cur];
			d[cur]++;
		}
	}
	else
	{
		for(int i = n; i >= 1; i--) 
		{
			if((c[i] - '0') % p == 0) cur++;
			res += cur;
		}
	}
	cout << res;
}      

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

#define rep(i,n) for(long long (i)=0;(i)<(n);(i)++)
#define reps(i,s,n) for(long long (i)=(s);(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n)-1;(i)>=0;(i)--)
#define all(v) (v).begin(),(v).end()
#define chmax(a, b) a = max((a),(b))
#define chmin(a, b) a = min((a),(b))
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define inf 1000000000
#define llinf 1000000000000000


typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;



int main(){
    int n;
    cin>>n;
    vint a(n);
    rep(i,n)cin>>a[i];
    int maxa=0;
    int maxa2=0;
    rep(i,n){
        maxa=max(maxa,a[i]);
    }
    int count=0;
    rep(i,n){
        if(maxa==a[i]){
            count++;
        }
        else{
            maxa2=max(maxa2,a[i]);
        }
    }
    rep(i,n){
        if(a[i]<maxa){
            cout<<maxa<<endl;
        }
        else if(count>=2){
            cout<<maxa<<endl;
        }
        else{
            cout<<maxa2<<endl;
        }
    }
}

Measured memory_bytes: 2432
#include  <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define P pair<int,int>
//P pa(114,514);   ,vector<P>vec(N,0);
//vector<vector<int>> vec(縦, vector<int>(横));
#define REP(i,N) for(int i=0;i<N;i++)
int gcd(int a, int b) {
    if(a>b){
        swap(a,b);
        }
    while(b%a!=0){
        b%=a;
        swap(a,b);
    }
    return a;
}
//cout << setprecision(123);
int main(){
  int r,g,b,N,ans=0;
  cin>>r>>g>>b>>N;
  REP(i,N/r+1){
    REP(j,(N-r*i)/g+1){
      if((N-i*r-g*j)%b==0){
        ans++;
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstdlib>
using namespace std;
int n, a[55], b[55], pos[55];
struct cmpFunctor {
    inline bool operator() (const int& a, const int& b) const {
        return a < b;
    }
};
bool check() {
    for (int i = 1; i <= n; i++) {
        if(a[i] != b[i])
            return false;
    }
    return true;
}
int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%d", &a[i]), b[i] = a[i];
    sort(b + 1, b + n + 1, cmpFunctor());
    int L = 1;
    for (int i = 1; i <= n; i++) {
        if(a[i] != b[i])
            pos[L++] = i;
    }
    if(L == 1) {
        puts("YES");
        return 0;
    }
    for (int i = 1; i <= L - 1; i++) {
        for (int j = i + 1; j <= L; j++) {
            swap(a[pos[i]], a[pos[j]]);
            bool now = check();
            if(now) {
                puts("YES");
                return 0;
            }
            swap(a[pos[i]], a[pos[j]]);
        }
    }
    puts("NO");
    return 0;
}

Measured memory_bytes: 128
N = int(input())
*A, = map(lambda x: int(x) - 1, input().split())
*B, = map(int, input().split())
*C, = map(int, input().split())
ans = sum(B)
for i in range(N-1):
    if A[i] == A[i+1]-1:
        ans += C[A[i]]
print(ans)

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(){
        int N,Q;
        cin >> N >> Q;
        char S[N + 1];
        int num[N + 1];
        num[0] = 0;
        S[0] = 'B';
        for(int i = 1; i <=N; i++){
                cin >> S[i];
        }
        int l[Q + 1], r[Q + 1];
        for(int i = 1; i <= Q; i++){
                cin >> l[i] >> r[i];
        }
        for(int i = 1; i <= N; i++){
                if(S[i] == 'C' and S[i - 1] == 'A') num[i] = num[i-1] + 1;
                else num[i] = num[i-1];
        }
        for(int i = 1; i <=Q; i++){
                cout << num[r[i]] - num[l[i]] << endl;
        }
        return 0;
}

Measured memory_bytes: 2048
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        Console.WriteLine(Solve());
        //Solve();
        return;
    }

    public static string Solve()
    {
        int[] first = ReadInts();
        int[] second = ReadInts();
        if(first[0] == second[0])
        {
            return "0";
        }
        else
        {
            return "1";
        }        
    }


    private static string Read() { return Console.ReadLine(); }
    private static int ReadInt() { return int.Parse(Read()); }
    private static long ReadLong() { return long.Parse(Read()); }
    private static double ReadDouble() { return double.Parse(Read()); }
    private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
    private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
    private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i = (a);i<=(b);i++)
#define ROF(i,a,b) for(int i = (a);i>=(b);i--)
#define MST(a,x) memset(a,x,sizeof(a))
#define ll long long
#define PB push_back
#define PH push
#define MP make_pair
#define FT first
#define SD second
#define N 505
#define M 10005
#define INF 1000000007
#define MOD 1000000007
#define MOD2 1000000009
#define eps 1e-7
using namespace std;

string a[N];
int main()
{
    //cin.tie(0);
    //ios::sync_with_stdio(false);
    int n,m;
    while(cin>>n>>m)
    {
        FOR(i,0,n-1)cin>>a[i];
        FOR(i,0,n-1)
        {
            FOR(j,0,m-1)
            {
                if(i == 0)cout<<'#';
                else if(i == n-1)cout<<'.';
                else if(a[i][j] == '#')cout<<'#';
                else if(j%2)cout<<'#';
                else cout<<'.';
            }
            cout<<endl;
        }
        cout<<endl;

        FOR(i,0,n-1)
        {
            FOR(j,0,m-1)
            {
                if(i == 0)cout<<'.';
                else if(i == n-1)cout<<'#';
                else if(a[i][j] == '#')cout<<'#';
                else if(j%2)cout<<'.';
                else cout<<'#';
            }
            cout<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }



int main() {
    int n;
    cin >> n;
    
    vector<double> p(n);
    rep(i, n) cin >> p[i];
    
    double dp[n + 1];
    fill_n(dp, n + 1, inf);
    
    dp[0] = 1;
    double dp2[n + 1];
    fill_n(dp2, n + 1, 0);
    
    rep(i, n) {
        rep(j, n) {
            if (dp[j] == inf) continue;
            dp2[j + 1] += dp[j] * p[i];
            dp2[j] += dp[j] * (1 - p[i]);
        }
        // rep(j, n + 1) cout << dp2[j] << " "; cout << endl;
        rep(j, n + 1) dp[j] = dp2[j];
        fill_n(dp2, n + 1, 0);
    }
    double ans = 0;
    double tmp = 0;
    rep(i, n + 1) tmp *= dp[i];
    // cout << tmp << endl;
    // rep(i, n + 1) cout << dp[i] << " "; cout << endl;
    rep3(i, (n % 2 == 0 ? n / 2 : n / 2 + 1), n + 1) {
        ans += dp[i];
    }
    cout << fixed << setprecision(10) << ans << endl;
}


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


#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()

#define int long long

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second

#define mod 1000000007

template <typename T>
void print(T x)
{
	std::cout << x <<" " ;
}


template <typename T>
void println(T x)
{
	std::cout << x << "\n";
}

int f(int x) {
	if (x == 1)return 1;
	return 2 * f(x / 2) + 1;
}

signed main(void) {
	int n;
	cin >> n;
	int ans = f(n);
	print(ans);
}

Measured memory_bytes: 256
import fractions

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    #divisors.sort()
    return divisors

a, b = map(int,input().split())
new_gcd = fractions.gcd(a, b)

new_a = a//new_gcd
new_b = b//new_gcd

tmp = make_divisors(new_gcd)
tmp = list(set(tmp))
tmp.sort()

new_tmp = []
for i in range(len(tmp)):
    flg = 0
    for j in range(1,len(tmp)-i):
        if tmp[-i]%tmp[j]==0:
            flg = 1
            break
    if flg == 0:
        new_tmp.append(tmp[-i])
        
print(len(new_tmp))

Measured memory_bytes: 5984
def ApproveOrDeny(number_list):
  for num in number_list:
    if num % 2 == 0:
      if num % 3 != 0 and num % 5 != 0:
        return 'DENIED'
  return 'APPROVED'
 
N = int(input())
number_list = list(map(int, input().split()))
print (ApproveOrDeny(number_list))

Measured memory_bytes: 2940
#include<stdio.h>
#include<math.h>
int main() 
{
  int n=0,ans=0,i,j,temp,b;
  int a[10000];
    scanf("%d",&n);
    for (i = 0; i < n; i++) {
      scanf("%d",&a[i]);
    }
    for(i = 0;i < n;i++){
      temp=0;
      b = sqrt(a[i]);
      for(j = 2; j <= b; j++) {
        if(a[i] %j==0){
            temp=1;
          }
       if(temp == 1) {
        break;
      }
    }
    if(temp == 0){
      ans++;
    }
  }
  printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 1848
t=[0]*5
for i in range(5):
    t[i]=int(input())
ans=0
min=10
c=6
for i in range(5):
    if t[i]%10!=0 and t[i]%10<min:
        c=i
        min=t[i]%10
for i in range(5):
    if i==c:
        ans+=t[i]
    elif t[i]%10==0:
        ans+=t[i]
    else:
        ans+=t[i]-t[i]%10+10
print(ans)

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

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    pair<pair<string, int>, int> p[110];
    for(int i=0; i<n; i++) {
        string s;
        int point;
        cin >> s >> point;
        p[i] = make_pair(make_pair(s,-point), i);
    }
    sort(p, p+n);

    for (int i = 0; i < n; i++)
    {
        cout << p[i].second + 1 << endl;
    }
    
    return 0;
}


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

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

  int A[N], B[N], C[N - 1];
  for (int i = 0; i < N; i++) cin >> A[i];
  for (int i = 0; i < N; i++) cin >> B[i];
  for (int i = 0; i < N - 1; i++) cin >> C[i];

  int satisfaction = 0;
  int previous_number_meal = N;
  for (int i = 0; i < N; i++) {
    int number_meal = A[i];
    satisfaction += B[number_meal - 1];
    if (previous_number_meal + 1 == number_meal) satisfaction += C[previous_number_meal - 1];
    previous_number_meal = number_meal;
  }

  cout << satisfaction << endl;

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int W,D,H2,i,t,R;
int main()
{
	for(;scanf("%d%d",&W,&D),W;)
	{
		int H1[21]={0};
		for(i=R=0;i<W;R+=t,H1[t]++,i++)
			scanf("%d",&t);
		for(i=0;i<D;i++)
		{
			scanf("%d",&H2);
			if(H1[H2]>0)
				H1[H2]--;
			else
				R+=H2;
		}
		printf("%d\n",R);
	}
	return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
 
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////

int main(){
  int a,b,c,d;
  C4(a,b,c,d);
  int sum = 0;
  
  for(int i = 0 ; i <= 100 ; i++){
    if(i > a && i<=b && i>c && i<=d)
      sum++;
  }

  P(sum);
  ret 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=1000010;
const ll mod=1e9+7;

int main(){  
  int w,h,n;
  cin >> w >> h >> n;
  int x1=0, x2=w, y1=0, y2=h;
  rep(i,n){
    int x,y,a; cin>>x>>y>>a;
    if(a==1){ x1=max(x1,x); continue; }
    if(a==2){ x2=min(x2,x); continue; }
    if(a==3){ y1=max(y1,y); continue; }
    if(a==4){ y2=min(y2,y); continue; }
  }
  int ans = (x2-x1)*(y2-y1);
  if(x2-x1<=0 ||y2-y1<=0){ans=0;}
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
from heapq import heappush,heappop,heapify

N=int(sys.stdin.readline().strip())
V=[]    #頂点の集合 (x座標、y座標、頂点番号)
for v in range(N):   #v:頂点番号
    x,y=tuple(map(int, sys.stdin.readline().split()))
    V.append((x,y,v+1))

#頂点をy軸でソート
V.sort(key=lambda x:(x[0]) )
E=[]    #辺の集合 (辺の長さ、頂点番号、頂点番号)
for i in range(N-1):
    fro_x,fro=V[i][0],V[i][2]
    to_x,to=V[i+1][0],V[i+1][2]
    E.append( (abs(fro_x-to_x),fro,to))

#頂点をx軸でソート
V.sort(key=lambda x:(x[1]) )
for i in range(N-1):
    fro_y,fro=V[i][1],V[i][2]
    to_y,to=V[i+1][1],V[i+1][2]
    E.append( (abs(fro_y-to_y),fro,to))

#隣接リスト
al=[[] for _ in range(N+1)]
for cost,fro,to in E:
    al[fro].append((cost,to))
    al[to].append((cost,fro))

#確定した頂点のリスト
fixed_v=[ 0 for _ in range(N+1) ]
hq=[]   #最短の辺を取得するためのヒープキュー
V=[1]   #次に処理する頂点が常に1つだけ入る、頂点1が常にスタート地点

ans=0
while V:
    cur=V.pop()
    #確定した頂点の更新
    fixed_v[cur]=1
    #頂点curから出て行く辺を全てhqに入れる
    for cost,to in al[cur]:
        heappush(hq,(cost,to))
    while hq:
        #hqから辺を取り出す
        cost,to=heappop(hq)
        #未確定の頂点が見つかれば、次に見る頂点としてVにappendし、whileループはbreak
        if fixed_v[to]==0:
            ans+=cost
            V.append(to)
            break
        #確定済みの頂点の場合は、#未確定の頂点が見つかるまでheapqからpopする

print ans

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

using namespace std;

const double delta = 1e-9;

double dist(long long x, long long y) {
	return sqrt(x*x + y*y);
}

int main() {
  	int n, d, x, y, count = 0;
  	cin >> n >> d;
  	for(int i = 0; i < n; i++) {
    	cin >> x >> y;
      	if(dist(x, y) < d + delta) count++;
    }
  	cout << count;
	return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll t, n;std::cin >> n;
  set<ll> s;
  re(i, n) {
    std::cin >> t;
    s.insert(t);
  }
  if(s.size()%2==0) std::cout << s.size()-1 << '\n';
  else std::cout << s.size() << '\n';
  return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
typedef long long int ll;

ll a[50];

int main(){
    int n; cin >> n;
    a[0]=1; a[1]=1;
    for(int i=2;i<50;i++){
        a[i]=a[i-1]+a[i-2];
    }
    cout << a[n] << endl;
}


Measured memory_bytes: 3104
use std::io;
use std::cmp;

fn main() {
    let mut line = String::new();
    io::stdin().read_line(&mut line);
    let mut line = line.split_whitespace();
    let n = line.next().unwrap().parse::<i64>().unwrap();
    let t = line.next().unwrap().parse::<i64>().unwrap();
    
    let mut a = [0i64; 200_000];
    let mut line = String::new();
    io::stdin().read_line(&mut line);
    let mut line = line.split_whitespace();
    for i in 0..n {
        let l = line.next();
        let ll = l.unwrap();
        let lll = ll.parse::<i64>();
        a[i as usize] = lll.unwrap();
    }

    let mut delta = [0i64; 199_999];
    for i in 0..(n-1) {
        delta[i as usize] = cmp::max(0i64, a[i as usize + 1usize] - a[i as usize] - t);
    }
    let mut x = a[n as usize - 1usize] + t;
    
    for i in 0..(n-1) {
        x -= delta[i as usize];
    }

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

Measured memory_bytes: 9468
import java.io.*;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    String[] data = br.readLine().split(" ");
    long a = Integer.parseInt(data[0]);
    long b = Integer.parseInt(data[1]);
    long c = Integer.parseInt(data[2]);
    String result = a+b+lessThanSqrt(a*b) < c ? "Yes" : "No";
    
    System.out.println(result);
  }

  
  private static long lessThanSqrt (long a) {
    return longSqrt(a);
  }
  
  private static long longSqrt (long a) {
    long b = 2*(long)Math.sqrt(a);
    while (true){
      if (b*b >= 4*a && (b-1)*(b-1) >= 4*a){
        b--;
      } else if(b*b <= 4*a && (b+1)*(b+1) <= 4*a){
        b++;
      } else {
        break;
      }
    }
    return b;
  }
}

Measured memory_bytes: 23124
#include <iostream>

using namespace std;
long long n,s,dp[11][1001];
int main(void){
    dp[0][0] = 1;
    
    for(int i=0;i<101;i++)
        for(int j=9;j>=0;j--)
            for(int k=0;i+k<1001;k++)
                dp[j+1][k+i]+=dp[j][k];
    while(cin >> n >> s, n|s)
        cout << dp[n][s] << endl;
    
    return 0;
}

Measured memory_bytes: 1236
x = 'KIHBR'
T = []
for i in range(1<<6):
    t = ''
    for j in range(6):
        if i&(1<<j) and j != 1 and j != 2:
            t += 'A'
        if j != 5:
            t += x[j]
    T.append(t)
S = input()
if S in T:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 3060
n = int(input())
A =list(map(int, input().split()))
d = {}

for a in A:
    if a in d:
        d[a] += 1
    else:
        d[a] = 1

d2 = {}
d3 = {}
for k, v in d.items():
    if v < 2:
        d2[k] = 0
    else:
        d2[k] = v*(v-1)//2
    if v-1 < 2:
        d3[k] = 0
    else:
        d3[k] = (v-1)*(v-2)//2
s = sum(list(d2.values()))

for i in range(n):
    print(s-d2[A[i]]+d3[A[i]])

Measured memory_bytes: 103756
while True:
    n=int(input())
    if n==0:
        break
    l=(input().split())
    for i in range(n):
        l[i]=int(l[i])
    m=sum(l)/n
    a=0
    for i in range(n):
        if l[i]<=m:
           a+=1
    print(a)


Measured memory_bytes: 6348
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int adj[10][10];
int n, m;
int ans = 0;

void bfs(bitset<8> bs, int pos) {
    int f = 1;
    imfor(i, n) {
        if (bs[i] == 0) {
            f = 0;
        }
    }
    if (f == 1) {
        ans++;
        return;
    }

    imfor(i, n) {
        if (adj[pos][i] == 1 && bs[i] == 0) {
            bs.set(i);
            bfs(bs, i);
            bs.reset(i);
        }
    }
}

int main() {
    cin >> n >> m;
    imfor(i, n) {
        imfor(j, n) {
            adj[i][j] = 0;
        }
    }
    imfor(i, m) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        adj[a][b] = 1;
        adj[b][a] = 1;
    }
    bitset<8> b(1);
    bfs(b, 0);
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int number = scanner.nextInt();
        final long[] longs = new long[number];

        for (int i = 0; i < longs.length; i++) {
            longs[i] = scanner.nextLong();
        }

        final long[][] dpTable = new long[4][number];

        /*
        0 直前，今回ともに操作なし
        1 直前に操作なし，今回は操作あり
        2 直前も今回も操作あり
        3 直前に操作あり，今回は操作なし
         */

        dpTable[0][0] = longs[0];
        dpTable[1][0] = -longs[0];
        dpTable[2][0] = -longs[0];
        dpTable[3][0] = longs[0];

        for (int i = 0; i < number - 2; i++) {
            dpTable[0][i + 1] = Math.max(dpTable[0][i] + longs[i + 1], dpTable[3][i] + longs[i + 1]);
            dpTable[1][i + 1] = Math.max(dpTable[0][i] - longs[i + 1], dpTable[3][i] - longs[i + 1]);
            dpTable[2][i + 1] = Math.max(dpTable[1][i] + longs[i + 1], dpTable[2][i] + longs[i + 1]);
            dpTable[3][i + 1] = Math.max(dpTable[1][i] - longs[i + 1], dpTable[2][i] - longs[i + 1]);
        }

        dpTable[0][number - 1] = dpTable[0][number - 2] + longs[number - 1];
        dpTable[1][number - 1] = dpTable[1][number - 2] - longs[number - 1];
        dpTable[2][number - 1] = dpTable[2][number - 2] - longs[number - 1];
        dpTable[3][number - 1] = dpTable[3][number - 2] + longs[number - 1];

        System.out.println(Math.max(Math.max(dpTable[0][number - 1], dpTable[1][number - 1]), Math.max(dpTable[2][number - 1], dpTable[3][number - 1])));
    }
}


Measured memory_bytes: 63024
//by xxj
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define ll long long
#define pii pair<int,int>
#define lowbit(x) x&-x
using namespace std;
const int inf=1e9+7;
const double eps=1e-10;
const ll linf=1e18+7;
const ll hh=523;
//const int mod=;
ll dp[(1<<17)];
int a[17][17];
int n;
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	scanf("%d",&n);
	for (int i=0;i<n;i++){
		for (int j=0;j<n;j++){
			scanf("%d",&a[i][j]);
//			cout<<i<<' '<<j<<' '<<a[i][j]<<endl;
		}
	}
	for (int i=0;i<(1<<n);i++){
		for (int j=0;j<n;j++){
			if (!(i & (1<<j))){
				continue;
			}
//			cout<<i<<' '<<j<<endl;
			for (int k=j+1;k<n;k++){
				if (i & (1<<k)){
//					cout<<i<<' '<<j<<' '<<k<<endl;
					dp[i]+=a[j][k];
				}
			}
		}
	}
//	cout<<dp[(1<<n)-1]<<endl;
	for (int i=0;i<(1<<n);i++){
		for (int j=i;j;j=(j-1)&i){
//			cout<<(i-j)<<' '<<(i^j)<<endl;
			dp[i]=max(dp[i],dp[j]+dp[i^j]);
		}
	}
	printf("%lld\n",dp[(1<<n)-1]);
	return 0;
}
/*
input:
*/

Measured memory_bytes: 768
#include<iostream>

using namespace std;

int main() {
	long a, b;
	long ans[2];
	while (cin >> a >> b) {
		if (a > b) {
			long temp = a;
			a = b;
			b = temp;
		}

		long i = 1;
		while ( (b * i) % a != 0 ) {
			i++;
		}
		ans[1] = b * i;

		long n = b, m = a, r = 1;

		while (r!=0){
			r = n % m;
			n = m;
			m = r;
		}
		ans[0] = n;

		cout << ans[0] << " " << ans[1] << endl;
	}
}


Measured memory_bytes: 2992
x,y=gets.split.map(&:to_i)
if x >= 0 && y >= 0
  if x < y
    puts y - x
  else
    puts [x + y + 1, x - y + 2].min
  end
elsif x <= 0 && y >= 0
  if x.abs < y
    puts [y + x + 1, y - x].min
  else
    puts [x.abs - y + 1, y - x].min
  end
elsif x >= 0 && y <= 0
  if x > y.abs
    puts x + y + 1
  else
    puts y.abs - x + 1
  end
else
  if x < y
    puts y - x
  else
    puts y.abs - x.abs + 2
  end
end


Measured memory_bytes: 1788
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

"""
逆順に見る，2つで長さL以上のものが作れればOKそうでなければ不可

最初dequeで解こうとしたけど，純粋に間違ってた
"""
def main():
    mod=10**9+7
    N,L=MI()
    A=LI()
    t=-1 #最後に外すとこ
    for i in range(N-1):
        # 結び目iを見る
        temp=A[i]+A[i+1]
        if temp >= L:
            t=i
            break
        
    if t==-1:
        print("Impossible")
    else:
        print("Possible")
        ans=[]
        for i in range(t):
            ans.append(i)
        for i in range(N-2,t,-1):
            ans.append(i)
        ans.append(t)
        
        for i in ans:
            print(i+1)
            
    
    
    

main()


Measured memory_bytes: 92056
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#include <fstream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#define endl '\n'
//#define ll long long
#define mod 1000000007
#define NCONS 200001
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
#define MCONS 2001
#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0
#define toRadian(degree) ((degree) * (M_PI / 180.))
#define toDegree(radian) ((radian) * (180. / M_PI))
using namespace std;
struct Point{int x; int y;};
struct PPoint{Point x; Point y;};
typedef long long ll;
ll gcd(ll a, ll b) { if(a < b) swap(a, b); if(b <= 0) return a; return gcd(b, a % b); }

int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    string s; cin >> s;
    sort(s.begin(), s.end());
    if(s[0] == s[1] && s[2] == s[3] && s[1] != s[2])
        cout << "Yes";
    else
        cout << "No";
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define space ' '
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

const int maxn = 100000;

int main(){
    
    int a,b;
    cin >> a>>b;
    if(a<10&&b<10){
        cout << a*b<<endl;
    }else{
        cout << -1<<endl;
    }
    
    return 0;
}


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

int main(){
  int n,l;
  cin>>n>>l;
  int r = l+n-1;
  int ans=(l+r)*n/2;
  if(l>0&&r>0) ans-=l;
  if(l<0&&r<0) ans-=r;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
n = input()

v = [[0, 0] for i in range(n)]
for i in range(n):
	v[i] = map(int, raw_input().split(' '))

a, b = 1, 1

for i in range(n):
	change = v[i][0] * b - a * v[i][1]
	while change != 0:
		if change < 0:
			additions = (-change + v[i][0] - 1) / v[i][0]
			change += additions * v[i][0]
			b += additions
		if change > 0:
			additions = (change + v[i][1] - 1) / v[i][1]
			change -= additions * v[i][1]
			a += additions

print a + b


Measured memory_bytes: 2692
#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
using ld=long double;
using VI=vector<ll>;
using VD=vector<ld>;
using VVI=vector<VI>;
using VC=vector<char>;
using VB=vector<bool>;
using VVC=vector<VC>;
using VS=vector<string>;
using PLL =pair<ll,ll>;
using PLD=pair<ld,ld>;
using VPLL=vector<PLL>;
#define print(x) std::cout<<x<<"\n"
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repd(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SZ(x) ((ll)(x).size())
#define MAX(x) *max_element((x).begin(),(x).end())
#define MIN(x) *min_element((x).begin(),(x).end())
#define SORTR(x) sort((x).rbegin(),(x).rend())
#define SORT(x) sort((x).begin(),(x).end())
#define SUM(x) accumulate((x).begin(),(x).end(), 0)
#define FILL(x,a) fill(x.begin(),x.end(),a)
#define EACH(i,x) for(typeof((x).begin()) i=(x).begin(); i!=(x).end(); ++i)
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

const ll INF = 1e18;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template <class BidirectionalIterator>
bool next_partial_permutation(BidirectionalIterator first, BidirectionalIterator middle,BidirectionalIterator last){reverse(middle, last); return next_permutation(first , last);}
ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll GCD(VI v){ll a = v[0]; for (ll i = 1; i<SZ(v); i++) {a = gcd(a, v[i]);} return a;}
ll LCM(VI v){ll a = v[0]; for (ll i = 1; i<SZ(v); i++) {a = lcm(a, v[i]);} return a;}
VI Bit2Vector(const ll bit, ll n) {	VI s;	rep(i,n) if (bit & (1 << i)) s.push_back(i); return s;}


void Main()
{
	ll n,m,l; ll res=0;
	string sres="YES";

	ll a,b,v,w,t;

	cin>>a>>v;
	cin >>b>>w;
	cin>>t;
	//距離はaとbの位置の差の絶対値
	ll distance=abs(a-b);
	//速度の差分
	ll diffvelo=v-w;
	//速度がーになるときはいっか
	if(diffvelo<=0) {
		print("NO");
		return ;
	}
	res=distance-diffvelo*t;
	if(res>0) sres="NO";

	cout << sres << "\n";
	return;
}

int main()
{
	std::cin.tie(0);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}


Measured memory_bytes: 3640
N, X = [int(a) for a in input().split()]
ans = 0
now_level = N
num_list = [2 ** (n + 2) - 3 for n in range(N + 1)]
while X > 0:
    if X <= now_level:
        break
    num_list = [2 ** (n + 2) - 3 for n in range(now_level + 1)]
    plus_base = [a + now_level - b for a, b in zip(num_list, range(now_level + 1))]
    eat_num = max([a for a in plus_base if a <= X])
    eat_level = plus_base.index(eat_num)
    now_level = eat_level
    ans += int((num_list[eat_level] + 1) / 2 + 0.1)
    X -= eat_num
    if X > 0:
        X -= 1
        ans += 1
print(str(ans))

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int primary[1000];
int main(){
  int n;cin>>n;
  for(int j = n; 1 < j; j--){
    int nn = j;
    for(int i = 2; nn != 1; i++){
      if(nn % i == 0){
        primary[i]++;
        nn = nn / i;
        i--;
      }
    }
  }

  long long ans = 1;
  for(int i = 0; 1000 > i; i++){
    if(primary[i] == 0)continue;
    ans = ans*(primary[i]+1) % 1000000007;
  }
  cout << ans << endl;
}

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

using namespace std;
using ll = long long;


int main()
{
	string s, t; cin >> s >> t;
	int n = s.size(), m = t.size();
	int nin = 1e9;
	for(int i = 0; i <= n - m; i++) {
		string k = s.substr(i, m);
		int cnt = 0;
		for(int j = 0; j < m; j++)if(k[j] != t[j])cnt++;
		nin = min(nin, cnt);
	}
	cout << nin << endl;
}

Measured memory_bytes: 3632
while True:
    x,y,s=map(int,input().split())
    if x==y==s==0:
        break
    ans=0
    for i in range(1,s):
        for j in range(i,s):
            if i*(x+100)//100+j*(x+100)//100==s:
                s2=i*(y+100)//100+j*(y+100)//100
                if s2>ans:
                    ans=s2
    print(ans)


Measured memory_bytes: 5596
#include <iostream>
using namespace std;
int main(){
  char c;
  for(int i = 0; i < 3; i++){
    cin >> c;
    if(c== '7'){
      cout << "Yes" << endl;
      exit(0);
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3568
#include<iostream>
#include<string>
using namespace std;
int main() {
	string s, t, u;
	int a, b;
	cin >> s >> t >> a >> b >> u;

	if (s == u) {
		a--;
	}
	else {
		b--;
	}

	cout << a << " " << b << endl;
}

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

using std::max;
using std::pair;
using std::vector;

typedef long long ll;

int main()
{
  int n;
  std::cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    std::cin >> v.at(i);
  }
  vector<pair<ll, ll>> memo(n);
  memo.at(1).first = v.at(0) + v.at(1);
  memo.at(1).second = -v.at(0) - v.at(1);
  for (int i = 2; i < n; i++) {
    memo.at(i).first = max(memo.at(i-1).first, memo.at(i-1).second) + v.at(i);
    memo.at(i).second = max(memo.at(i-1).first - 2*v.at(i-1), memo.at(i-1).second + 2*v.at(i-1)) - v.at(i);
  }
  std::cout << max(memo.at(n-1).first, memo.at(n-1).second) << '\n';
  return 0;
}


Measured memory_bytes: 2176
#include<iostream>
#include <string>
#include<vector>
#include<algorithm>
typedef long long ll;

using namespace std;
int main()
{
	int n,x;
	cin >> n>>x;
	vector<int> ms(n);
	for (int i = 0; i < n; i++) {
		cin >> ms[i];
	}

	int sum=0;
	for (int i = 0; i < n; i++) {
		sum += ms[i];
	}
	int min_m=*min_element(ms.begin(), ms.end());
	cout << (x - sum) / min_m + n;
	return 0;
}

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

using namespace std;

int main()
{
    int n, sum = 0, suml = 0, ans = 100;
    cin >> n;
    vector<int> w(n);
    for (int i = 0; i < n; i++)
    {
        cin >> w[i];
        sum += w[i];
    }
    for (int i = 0; i < n; i++)
    {
        suml += w[i];
        ans = min(abs(sum - 2 * suml), ans);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
using namespace std;

void solve() {
	string S, T;
	int counter = 0;
	cin >> S >> T;
	for (int n = 0; n < 3; n++) {
		if (S[n] == T[n])counter++;
	}
	cout << counter << endl;
	return;
}

//////////////////////////////
//////////////////////////////

int main() {
#ifdef DEBUGTIME
	for (int time = 0; time < DEBUGTIME; time++) {
		solve();
		cout << "####################" << endl;
	}
#else
	solve();
#endif
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
main()
{
	long long int a, b,n, i, ans = 0, res=0;
	cin >> a >>b >> n;
 long long int cnt = min(n, b);
 long long int br = 1e8;
 
 while(cnt>=4 && br>4)
 {
 long long int x = (a*cnt)/b;
   
 long long int y = (cnt/b);
    
 ans = x-(a*y);
res = max(res, ans);
br--;
cnt--;
}

	cout << res << endl;
	return 0;
}

Measured memory_bytes: 3568
#include <stdio.h>
#include <math.h>
 
int main(void){
  int N,T,A,H[1000],i,cite;
  double min = 1000;
  scanf("%d %d %d",&N,&T,&A);
  for(i=0;i<N;i++){
    scanf("%d",&H[i]);
    if(min > fabs((double)T - H[i]*0.006 - (double)A)){
      min = fabs((double)T - H[i]*0.006 - (double)A);
      cite = i + 1;
    }
  }
  printf("%d",cite);
  return 0;
}

Measured memory_bytes: 1696
from bisect import bisect_left
n = int(input())
l = list(map(int,input().split()))
l = sorted(l)
cnt = 0
for i in range(n):
    for j in range(i+1,n):
        #print(l[i],l[j])
        cnt += bisect_left(l, l[i] + l[j]) - (j + 1)
print(cnt)

Measured memory_bytes: 9340
def dfs(i, f, sum):
    if i == 3:
        if sum == 7:
            # 答えは1つ出力すれば良いので =7 になれば終了
            print(f + "=7")
            exit()

    else:
        # 式 f の末尾に符号と次の数字を追加し、その分 sum に加減する
        dfs(i + 1, f + "-" + s[i + 1], sum - int(s[i + 1]))
        dfs(i + 1, f + "+" + s[i + 1], sum + int(s[i + 1]))


s = input()

dfs(0, s[0], int(s[0]))

Measured memory_bytes: 9128
#include<stdio.h>
int main()
{
	int H[300],W[300],i=0,j=0,k,l=0;
	for(l=0;l<300;l++)
	{
		scanf("%d %d",&H[l],&W[l]);
		if(H[l]==0&&W[l]==0)
			break;
	}
	for(k=0;k<l;k++)
	{
		for(i=1;i<=H[k];i++)
		{
			for(j=1;j<=W[k];j++)
			{
				if(i==1)
				{
					if(j==W[k])
						printf("#\n");
					else
						printf("#");
				}
				else if(j==1)
					printf("#");
				else if(j==W[k])
					printf("#\n");
				else if(i==H[k])
				{
					if(j==W[k])
						printf("#\n");
					else
						printf("#");
				}
				else
					printf(".");
			}
		}
		printf("\n");
	}
	return 0;
}

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

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

    int a, b;
    cin >> a >> b;
    
    for (int i = 0; i < 10000; i++){
        int x = floor(i * 0.08), y = floor(i * 0.1);

        if (x == a && y == b){
            cout << i << '\n';
            return 0;
        }
    }

    cout << -1 << '\n';

    return 0;
}


Measured memory_bytes: 256
#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''


def sol(n,l):
    import bisect
    l.sort()
    ans = 0
    #print(l)
    for i in range(n-1):
        for j in range(i+1,n):
            ji = l[j]+l[i]
            ind = bisect.bisect_left(l,ji)
            #print(i,j,ind,ind-j-1)
            ans += ind-j-1
    return ans


def main():
    import sys
    input = sys.stdin.readline
    n = int(input())
    l = list(map(int, input().split()))
    print(sol(n,l))

        
if __name__ == "__main__":
    main()


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

using namespace std;

int main(){
  int N, r=0;
  string S;
  stack<char> s;
  cin >> N >> S;

  for (int i = 0; i < N; i++){
    if(S[i] == '('){
      s.push('(');
    }else{
      if(s.empty() == 0){
        s.pop();
      }else{
        r++;
      }
    }
  }

  for (int i = 0; i < r; i++){
    S.insert(S.begin(),'(');
  }
  
  for (int i = 0; i < s.size(); i++){
    S.insert(S.end(),')');
  }
  
  printf("%s\n",S.c_str());
}


Measured memory_bytes: 3644
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }

int main() {
	int N;
	while(~scanf("%d", &N)) {
		vector<int> A(N - 1);
		for(int i = 0; i < N - 1; ++ i)
			scanf("%d", &A[i]);
		int sumA = accumulate(A.begin() + 2, A.end(), 0);
		int S = sumA + *max_element(A.begin() + 2, A.end());
		deque<int> deq;
		rep(k, S)
			deq.push_back(k);
		reu(i, 2, N - 1) {
			rep(j, A[i])
				deq.push_front(deq[1 + j * 2]);
			while((int)deq.size() >= S)
				deq.pop_back();
		}
		int M;
		scanf("%d", &M);
		rep(i, M) {
			int X;
			scanf("%d", &X);
			int ans = (X >= S ? X - sumA : deq[X]) + (A[0] - A[1]);
			printf("%d\n", ans);
		}
	}
	return 0;
}


Measured memory_bytes: 14608
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int n,n1,n2,c1,c2;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        int x;
        scanf("%d",&x);
        if(n1==0||x==n1) n1=x,c1++;
        else if(n2==0||x==n2) n2=x,c2++;
        else {printf("No\n");return 0;}
    }
    if(n2==0)
    {
        if(n1==n-1||n/n1>=2) printf("Yes\n");
        else printf("No\n");
    }
    else
    {
        if(n1<n2) swap(n1,n2),swap(c1,c2);
		if(n1-n2!=1) {printf("No\n");return 0;}
        n-=c2;
        n1-=c2;
        if(n1!=0&&n/n1>=2) printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 256
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let h: usize = read();
    let w: usize = read();
    let mut mas = vec![vec!['.'; w + 2]; h + 2];

    for i in 1..h + 1 {
        for (j, c) in read::<String>().chars().enumerate() {
            mas[i][j + 1] = c;
        }
    }

    for i in 1..h + 1 {
        for j in 1..w + 2 {
            if mas[i][j] == '#'
                && ![mas[i - 1][j], mas[i + 1][j], mas[i][j - 1], mas[i][j + 1]]
                .iter()
                .any(|&c| c == '#')
                {
                    println!("No");
                    return;
                }
        }
    }
    println!("Yes");
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
 
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    }    
 Graph g(100005);
 lint dista[100005];
 lint distb[100005];
  void dfs(lint to,lint from,lint dist,lint arr[]){
            arr[to]=dist;
            for(lint x:g[to]){
                if(x==from)continue;
                dfs(x,to,dist+1,arr);
            }
  }
  int main(){
        lint n;
        cin>>n;
        rep(i,n-1){
            lint a,b;
            cin>>a>>b;
            --a;--b;
            g[a].push_back(b);
            g[b].push_back(a);
        }
        dfs(0,-1,0,dista);
        dfs(n-1,-1,0,distb);
        lint counta=0,countb=0;
        rep(i,n){
            if(dista[i]>distb[i])countb++;
            else counta++;
        }
    if(counta>countb)cout<<"Fennec";
    else cout<<"Snuke";
  }
  
  
     
  

Measured memory_bytes: 13568
n = int(input())
ans = False
zoro = 0
for _ in range(n):
    one, two = map(int,input().split())
    if one == two:
        zoro += 1
        if zoro == 3:
            ans = True
            break
    else:
        zoro = 0
        
if ans == True:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9204
#include <iostream>
#include <vector>
#include <utility>

using namespace std;

int main() {
    while(true) {
        int N;
        cin >> N;
        if(!N) break;

        vector<pair<int, int> > stones;
        for(int i = 1; i <= N; ++i) {
            int c;
            cin >> c;
            if(stones.empty()) stones.push_back(make_pair(c, 1));
            else {
                if(i % 2 == 0) {
                    if(stones.back().first == c) ++stones.back().second;
                    else {
                        for(int j = stones.size()-1; j >= 0; --j) {
                            if(stones[j].first == c) break;
                            stones[j].first = c;
                        }
                        ++stones.back().second;
                    }
                }
                else {
                    if(stones.back().first == c) ++stones.back().second;
                    else stones.push_back(make_pair(c, 1));
                }
            }
        }
        int sum = 0;
        for(int i = 0; i < stones.size(); ++i) {
            if(stones[i].first == 0) sum += stones[i].second;
        }
        cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		int k = sc.nextInt();
		long i = 0;
		for(i = a; i < a + k && i <= b; i++) {

			System.out.println(i);
		}
		for(long j = i; j < b + 1; j++) {
			if(j <= b - k + 1) {
				j = b - k + 1;
			}
			System.out.println(j);
		}
	}

}


Measured memory_bytes: 22612