akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;

public class Main {
    private static IO io = new IO();
    public static void main(String[] args) {
        
        int n = io.nextInt();
        int z = io.nextInt();
        int w = io.nextInt();
        int a[] = new int[n+1];
        for (int i=1; i<=n; i++) a[i] = io.nextInt();
        if (n==1) System.out.println(Math.abs(a[1]-w));
        else System.out.println(Math.max(Math.abs(a[n]-w), Math.abs(a[n-1]-a[n])));
        
    }

    static class IO extends PrintWriter {
        private final InputStream in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;

        IO() {
            this(System.in);
        }

        IO(InputStream source) {
            super(System.out);
            this.in = source;
        }

        boolean hasNextByte() {
            if (ptr < buflen) return true;
            else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) return false;
            }
            return true;
        }
        int readByte() {
            if (hasNextByte()) return buffer[ptr++];
            else return -1;
        }
        boolean isPrintableChar(int c) {return 33<=c &&c <=126;}
        void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr]))ptr++;}
        boolean hasNext() {
            skipUnprintable();
            return hasNextByte();
        }

        long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) throw new NumberFormatException();
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) return minus ? -n : n;
                else throw new NumberFormatException();
                b = readByte();
            }
        }

        int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }

        public void close() {
            super.close();
            try {
                in.close();
            } catch (IOException ignored) {
            }
        }
    }
}

Measured memory_bytes: 21460
n,m=map(int,input().split())
l=[0]*m
for i in range(n):
    L=[int(i) for i in input().split()]
    del L[0]
    for i in range(len(L)):
        l[L[i]-1]+=1
ans=0
for i in range(m):
    if l[i]==n:ans+=1
print(ans)

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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999

using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int iy[]={0, 0, 1, -1};
int ix[]={1, -1, 0, 0};

int n, i, ans;

int main(){
	cin >> n;
	for(i=0;i<n;i++){
		int l, r;
		cin >> l >> r;
		ans += r-l+1;
 	}
	cout << ans<< endl;
	return 0;
}

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

int main() {
    //
    long long a, b, c, d;
    long long kekka = 0;
    cin >> a >> b >> c >> d;

    kekka = a * c;
    kekka = max(kekka, a * d);
    kekka = max(kekka, b * c);
    kekka = max(kekka, b * d);

    cout << kekka;
    //
}


Measured memory_bytes: 3632
using System;
public class Program
{
    public static void Main(string[] args)
    {
        // 整数の入力
        string[] input = Console.ReadLine().Split(' ');
        int b = int.Parse(input[0]);
        int c = int.Parse(input[1]);
        //出力
        Console.WriteLine(b>10 ? c : c+(100*(10-b)));
    }
}


Measured memory_bytes: 11092
using System;
using System.Collections.Generic;//list用
using System.Text;//StringBuilder用
using System.Collections;//ハッシュテーブル用
using System.Linq;

class Program
{
    //Hashtable ht = new Hashtable();
    static List<int> A = new List<int>();
      static List<int> B = new List<int>();
      static List<int> C = new List<int>();
    static decimal result;
    static int N;
    //StringBuilder strresult= new StringBuilder("");//Append(str ○○)関数で文字を追加していく



    static void Main()
    {
        //Modular mo = new Modular(0);//素数で割った余りを出せで使う。()内が初期値。★使い方：Modular型で宣言すると、その時点でのその素数で割った余りを保持する変数になる（powべき乗、Fac累乗、nCr組み合わせも関数として存在）
        //Node no = new Node<>();//UnionFind★Find関数で根っこの値を返す（根っこの値が一緒なら同グループ）、Unite関数で二つの木をくっつける
        //Permutation pe = new Permutation<>();//配列＆リストを並べ替えた場合の全ケースを出力★All関数でリスト形式で返す。
        //Treap tr = new Treap<>();//平衡二分木★Insert()関数で挿入、FindIndex()関数で該当する大きさの物が入るべき配列番号を返す。
        // delegate int CFunc();//下関数に使うデリゲータ。コイツと同じ引数と戻り値で関数作って、下の評価式の部分に関数名を入れる。
        //PriorityQueue pr = new PriorityQueue<int,int>();//優先度付キュー★Add(key,value)で格納、Dequeue()で取りだし。keyが小さいものから取り出す。
        Read1();
        Read2(N);
      int before=-999;
for(int i=0;i<N;i++){result+=B[A[i]-1];if(before==A[i]-2){result+=C[A[i]-2];}before=A[i]-1;}
      
      
        Console.WriteLine(result.ToString());
    }


    static void Read1()
    {
        string tmp = Console.ReadLine();
        N = int.Parse(tmp);
    }

    static void Read2(int kosuu)
    {
        string[] tmp = Console.ReadLine().Split(' ');
        for (int i = 0; i < kosuu; i++) { A.Add(int.Parse(tmp[i])); }
              string[] tmp2 = Console.ReadLine().Split(' ');
        for (int i = 0; i < kosuu; i++) { B.Add(int.Parse(tmp2[i])); }
              string[] tmp3 = Console.ReadLine().Split(' ');
        for (int i = 0; i < kosuu-1; i++) { C.Add(int.Parse(tmp3[i])); }
      C.Add(0);
    }

}

Measured memory_bytes: 13268
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  int X, A, B; cin >> X >> A >> B;

  string result;
  if (B<=A) result = "delicious";
  else if (B<=A+X) result = "safe";
  else result = "dangerous";
  cout << result << endl;
  return 0;
}

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

using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	int sum = 0;
	for (int i = 0; i < m; i++) {
		int x;
		cin >> x;
		sum += x;
	}
	if (n - sum < 0) cout << -1;
	else cout << n - sum;

	return 0;
}

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

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

    int sum = 0;
    for(int i=0; i<n; i++){
        int a;
        cin >> a;
        sum += a;
    }

    cout << sum - n << endl;
    return 0;
}

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

#define LL long long
const int mod = 1e9 + 7, N = 500005;
LL fac[N], finv[N], inv[N];

LL nCr(LL n,LL k){
    if(n < k || n < 0|| k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < N; 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 n, k, ans; cin >> n >> k;

    for(LL i = 1; i <= k; i++) {
        ans =  nCr(n - k + 1, i);
        ans *= nCr(k - 1, i - 1);
        ans %= mod;
        cout << ans << '\n';
    }   
}

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

#define ii pair<int, int>
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define vi vector<int>
#define vii vector<ii>
#define vvi vector<vi>
#define INF int(1e9)

using namespace std;

int main () {
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;

    int ans = 0;

    ans+=1000*(n/500);
    n-=500*(n/500);
    ans+=5*(n/5);

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

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

typedef long long ll;

using namespace std;

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

template<class T>
using vt = vector<T>;
template<class T>
using vvt = vector<vector<T>>;

int edges[50][50];

int main(){
    int N,M;
    cin >> N >> M;
    rep(i,M) {
        int parent;
        int child;
        cin >> parent >> child;
        --parent;--child;
        edges[parent][child]++;
        edges[child][parent]++;
    }
    rep(i,N){
        int sum = 0;
        rep(j,50){
            sum += edges[i][j];
        }
        cout << sum << endl;
    }
    return 0;  
}



Measured memory_bytes: 256
import sys
import itertools
input = sys.stdin.readline

n = int(input())
s = str(n)

counter = 0

for l in range(3, len(s) + 1):
    for v in itertools.product([3, 5, 7], repeat = l):
        if 3 in v and 5 in v and 7 in v:
            p = [str(p) for p in v]
            p = int("".join(p))
            
            if p <= n:
                counter += 1
                
print(counter)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N=2e5+10;
int a[N];
int b[N];
int istop[N];

template<class _Ty = void>
struct more
    : public binary_function<_Ty, _Ty, bool>
{
    // functor for operator<
    bool operator()(const _Ty& _Left, const _Ty& _Right) const
    {
        // apply operator< to operands
        return (_Left > _Right);
    }
};

multiset<int, more<int> > s[N];
multiset<int> ss;
map<int,int>mp;
int main()
{

    int n;
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    for(int i=0;i<n;i++){
        mp[a[i]]=1;
    }
    int ans=n;
    for(int i=0;i<n;i++){
            if(a[i]==1e9) {
                ans--;
                continue;
            }
        if(a[i+1]==a[i]){
            ans--;
            if(a[i+2]!=a[i+1]){
                a[i+1]=1e9;
            }
            continue;
        }
        int flag=0;
        for(int j=1;j<=sqrt(a[i]);j++){
            if(a[i]%j==0){
                    //cout<<i<<" "<<j<<endl;
                if(mp[j]&&j!=a[i]){
                    flag=1;
                }
                if(j!=1&&mp[a[i]/j]) flag=1;
            }
            if(flag) break;
        }
        if(flag )ans--;
    }
    cout<<ans<<endl;

}


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

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;
const ll MOD = 1000000007;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int a, b;
	cin >> a >> b;

	int now = 1;

	int cnt = 0;
	while (now < b) {
		now--;
		now += a;
		cnt++;
	}

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


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reps(i,s,n) for(int (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 r;
    cin>>r;
    cout<<3*r*r<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int mod=1000000007;
const int maxn=100005;
int dp[maxn],a[maxn];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=0;i<=n;i++)
        dp[i]=mod;
    dp[0]=0;
    for(int i=0;i<n;i++)
    {
        if(i+1<n)
            dp[i+1]=min(dp[i+1],dp[i]+abs(a[i]-a[i+1]));
        if(i+2<n)
            dp[i+2]=min(dp[i+2],dp[i]+abs(a[i]-a[i+2]));
    }
    cout<<dp[n-1]<<endl;
    return 0;
}



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

int main(){
    int n;
    cin >> n;
    double ans;
    double b[n];
    double c = 1;
    for(int i=0;i<n;i++){
        int a;
        cin >> a;
        ans +=(double)(1)/(double)(a);
    }
    ans = (double)(1)/(double)(ans);
    printf("%.10lf\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define PI 3.141592653589793

int main() {
	int a, b;
	cin >> a >> b;
	cout << a * b;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
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 void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int x, y;
    cin >> x >> y;
    if (x * 2 > y or x * 4 < y) {
        cout << "No" << endl;
    } else {
        REP(i, x + 1) {
            if (2 * i + 4 * (x - i) == y) {
                cout << "Yes" << endl;
                return;
            }
        }
        cout << "No" << endl;
    }
}


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

int main()
{

        long long N;
        cin >> N;

        vector<long long> ans;

        for (int i = 0; i < N+1; ++i) {

                if (i == 0) {
                        ans.push_back(2);
                }
                else if (i == 1) {
                        ans.push_back(1);
                }
                else {
                        ans.push_back(ans[i-2] + ans[i-1]);
                }
        }
        cout << ans[N] << endl;


}


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

int main() {
  int h,w;
  cin>>h>>w;
  std::vector<string> v(h);
  for(int i=0;i<h;i++)cin>>v[i];
  for(int i=0;i<w+2;i++)cout<<'#';
  cout<<endl;
  for(int i=0;i<h;i++)cout<<'#'<<v[i]<<'#'<<endl;
  for(int i=0;i<w+2;i++)cout<<'#';
  cout<<endl;
}


Measured memory_bytes: 256
import sys
  
N = 1000000
primes = [1] * (N//2)
primes[0] = 0
  
for i in range(3,int(N**0.5),2):
    if primes[i//2]:
        primes[(i*i)//2::i] = [0] * len(primes[(i*i)//2::i])
  
for i in sys.stdin:
    n = int(i)
    if n < 3:
        print(n-1)
    else:
        print(sum(primes[:(n+1)//2])+1)

Measured memory_bytes: 16924
n,q = [int(x) for x in input().split()]
s = input()
lr = []
for _ in range(q):
    lr.append([int(x) for x in input().split()])

L = [0]*n
for i in range(1,n):
    if s[i-1] == "A" and s[i] == "C":
        L[i] = L[i-1] + 1
    else:
        L[i] = L[i-1]

for v in lr:
    print(L[v[1]-1] - L[v[0]-1])

Measured memory_bytes: 24472
#考え方
#（BについてCでもDでも割り切れない数の個数）-（についてCでもDでも割り切れない数の個数）
#↑それぞれは、B -（B//C + B//D - B//lcm(C,D)) 、　A -（A//C + A//D - A//lcm(C,D))で出せる

def gcd(x, y):
    if x%y == 0:
        return y

    else:
        return gcd(y,x%y)



A, B, C, D = map(int,input().split())

if C < D:
    t = C
    C = D
    D = t

max_ky = gcd(C,D)

#最小公倍数
lcm_c = C//max_ky
lcm_d = D//max_ky
lcm = max_ky * lcm_c * lcm_d

count_b = B - (B//C + B//D - B//lcm)
count_a = A - (A//C + A//D - A//lcm)
if(A%C != 0 and A%D != 0):
    count_a -= 1
ans = count_b - count_a

print(ans)






#りゅうせいの解答1 実行時間超過
#A, B, C, D = map(int,input().split())
# ans = 0
# j = A
# while j <= B:
#     count = 0
#     if j%C:
#         count += 1
#     if j%D:
#         count += 1
#
#     if count == 2:
#         ans += 1
#
#     j+= 1
#
# print(ans)




Measured memory_bytes: 3064
#include<stdio.h>
#include<stdbool.h>

int main(void){
   int N;
   scanf("%d",&N);
   int n[N];
   bool judge=true;
   for(int i=0;i<N;i++){
      scanf("%d",&n[i]);
   }
   for(int i=0;i<N;i++){
      if(n[i]%2==0){
         if(n[i]%3==0||n[i]%5==0){
      }else{
         judge=false;
         break;
      }
      }
   }
   if(judge){
      printf("APPROVED");
   }else{
      printf("DENIED");
   }
   return 0;
}


Measured memory_bytes: 1704
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll a,b,k,i;
    cin>>k>>a>>b;
    for(i=a;i<=b;i++){
        if(i%k==0){
            cout<<"OK"<<endl;
            return 0;
        }
    }
    cout<<"NG"<<endl;
    return 0;
}


Measured memory_bytes: 3652
point = []
while line = gets
p,s = line.split(",").map(&:to_i)
break if p == 0 && s ==0
point[p] = s
end

rpoint = point.uniq.compact.sort.reverse
phash = {}
(0...rpoint.size).each do |i|
  phash[rpoint[i]] = i+1
end
while line = gets
n = line.chomp.to_i
puts phash[point[n]]
end


Measured memory_bytes: 6840
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9+7;

int dp[105][4][2];

int main(){
  string s;
  int k;
  cin >> s >> k;
  int n = s.size();
  
  dp[0][0][0] = 1;

  for(int i = 0; i < n; i++){
    for(int j = 0; j < 4; j++){
      for(int m = 0; m < 2; m++){
        for(int d = 0; d < 10; d++){
          int x = s[i]-'0';
          int ni = i+1, nj = j, nm = m;
          if(d != 0) nj++;
          if(nj > k) continue;
          if(nm == 0){
            if(x > d) nm = 1;
            else if(x < d) break;
          }
          dp[ni][nj][nm] += dp[i][j][m];
        }
      }
    }
  }

  cout << dp[n][k][0]+dp[n][k][1] << endl;
  return 0;
}

Measured memory_bytes: 256
(defun solve ()
  (declare (optimize (speed 3) (debug 0) (safety 0)))
  (let* ((n (+ (read) 1))
         (m (read))
         (flag (make-array n :initial-element -1 :element-type 'fixnum))
         (sign (make-array n :initial-element -1 :element-type 'fixnum))
         (road (make-array n :initial-element nil)))
    (declare (type fixnum n m))
    (loop repeat m
          for a = (read)
          for b = (read)
          do (progn
               (push b (aref road a))
               (push a (aref road b))))
    (let ((stack nil))
      (push (cons 1 0) stack)
      (loop for i from 1
            while stack
            for next-stack = nil
            do (loop for (room . src) in stack
                     do (when (< (aref flag room) 0)
                          (setf (aref flag room) i)
                          (setf (aref sign room) src)
                          (loop for neis in (aref road room)
                              do (when (< (aref flag neis) 0)
                                   (push (cons neis room) next-stack)))))
            do (setf stack next-stack))
      (format t "Yes~%")
      (loop for i from 2 to (- n 1)
            do (format t "~a~%" (aref sign i))))))

(solve)


Measured memory_bytes: 87620
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        
        long power = 1;
        
        for(int i = 1; i <= N; i++) {
            power *= i;
            power %= 1000000007;
        }
        
        System.out.println(power);
    }
}


Measured memory_bytes: 23636
#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include <stdbool.h>
//#include <limits.h>
//#include <math.h>

int main() {
  int n;
  scanf("%d", &n);
  int d, x, a[n];
  scanf("%d%d", &d, &x);
  for (int i=0; i<n; i++) scanf("%d", a+i);
  int ans = x;
  for (int i=0; i<n; i++) ans += (d-1)/a[i] + 1;
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
n,m = map(int,input().split())
edg = [[] for i in range(n)]

for _ in range(m):
  a,b = map(int,input().split())
  a-=1
  b-=1
  edg[a].append(b)
  edg[b].append(a)
  
check1 = [0] * n
check0 = [0] * n

from collections import deque

q = deque()
q.append((0,1))
check0[0] = 1

while q:
  p,t = q.pop()
  for e in edg[p]:
    if t:
      if check1[e]:continue
      check1[e] = 1
      q.appendleft((e,0))
    else:
      if check0[e]:continue
      check0[e] = 1
      q.appendleft((e,1))
ans = 0
sc0 = sum(check0)
sc1 = sum(check1)
for i in range(n):
  if check0[i]:
    if check1[i]:
      ans += n - 1
    else:
      ans += sc1
  else:
      ans += sc0
print(ans//2 - m)
      


Measured memory_bytes: 64876
#include <iostream>
#include <algorithm>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
int main(){
    int n;
    cin >> n;
    int a[n];
    rep(i,n){
        cin >> a[i];
    }
    sort(a,a+n);
    cout << a[n-1] - a[0] << endl;
}

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

int main()
{
    int n;cin>>n;
    int a[105];
    int maxv=-1e9,minv=1e9;
    int maxid,minid;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(maxv<a[i])
        {
            maxv=a[i];maxid=i;
        }
        if(minv>a[i])
        {
            minv=a[i];minid=i;
        }
    }
    vector<pair<int,int> >ans;
    if(minv>=0)
    {
        for(int i=2;i<=n;i++)
        {
            ans.push_back(make_pair(i-1,i));
        }
    }
    else if(maxv<=0)
    {
        for(int i=n-1;i>0;i--)
        {
            ans.push_back(make_pair(i+1,i));
        }
    }
    else
    {
        if(maxv+minv>=0)
        {
            for(int i=1;i<=n;i++)
            {
                ans.push_back(make_pair(maxid,i));
            }
            for(int i=2;i<=n;i++)
            {
                ans.push_back(make_pair(i-1,i));
            }
        }
        else
        {
            for(int i=1;i<=n;i++)
            {
                ans.push_back(make_pair(minid,i));
            }
            for(int i=n-1;i>0;i--)
            {
                ans.push_back(make_pair(i+1,i));
            }
        }
    }
    cout<<ans.size()<<endl;
    for(int i=0;i<ans.size();i++)
        cout<<ans[i].first<<" "<<ans[i].second<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s; cin >> s;
  int K; cin >> K;
  int N = s.size(), i = 0;
  string ANS = "";
  while(K > 0){
    if(i == N - 1){
      ANS += 'a' + ((s[i] - 'a') + K % 26) % 26;
      break;
    }
    if(s[i] == 'a'){
      ANS += 'a';
      i++;
    }else{
      if('z' - s[i] + 1 <= K){
        ANS += 'a';
        K -= 'z' - s[i] + 1;
        i++;
        if(K == 0){
          while(i < N){
            ANS += s[i];
            i++;
          }
        }
      }else{
        ANS += s[i];
        i++;
      }
    }
  }
  cout << ANS << endl;
}

Measured memory_bytes: 720
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define int int64_t
#define double long double
#define rep(i, N) for(int i=0; i<N; i++)
#define repr(i, N) for(int i=N-1; i>=0; --i)
#define all(v) v.begin(),v.end() 
using namespace std;
//using pr = pair<int, int>;
using tup  = tuple<int, int, int>;
using vec  = vector<int>;
using vvec = vector<vec>;

//プロトタイプ宣言
bool has_divisor(int, int);

//グローバル変数
//const int MAX_N;
//const int MAX_M;
//vvec data(N, vec(M));
//const int INF = ;
//const int mod = ;

//関数：
/* yにxをn回乗じmodで割った余りを返す。
（素数pに対して x**p = x (mod p) が成り立つ。）*/
int mod_pow(int y, int x, int n, int mod) {
	int ans = y;
	rep(i, n) {
		ans *= x;
		ans %= mod;
	}
	return ans;
}

/* ユークリッドの互除法(mx > mn) */
int gcd(int mx, int mn) {
	if(mn == 0) return(mx);
	else gcd(mn, mx%mn);
}

/* 素数判定関数 */
bool is_prime(int n) {
	if (n == 1) return false;
	else if (n == 2) return true;
	else {
		return !has_divisor(n, 2);
	}
}

/* クイック・ソート（返し値：互換数） */
int64_t quicksort(vector<int> &arr, int left, int right) {
	int i, j, p;
	int64_t ans = 0;
	i = left; j = right;
	p = (arr[i]+arr[j]) / 2;
	while(i < j) {
		while(arr[i] < p) i++;
		while(arr[j] > p) j--;
		if (i < j) {
			swap(arr[i++], arr[j--]);
			ans += abs(i-j);
		}
		if(i == j) {
			if(arr[i] < p) i++;
			else if(arr[j] > p) j--;
		}
		if (i >= left+2) ans += quicksort(arr, left, i-1);
		if (j <= right-2) ans += quicksort(arr, j+1, right);
	}
	return ans;
}

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

	int r; cin >> r;
	int ans = r*r;
	
	cout << ans << endl;
	return 0;
}

// 以下の関数等は気にしない。
bool has_divisor(int n, int i) {
	//base case 1:
	if (i == n) return false;
	//base case 2:
	if (n % i == 0) return true;
	return has_divisor(n, i+1);
}

//std::string str;
//str = std::to_string(int i);
//bitset<3> s(N);
//int ans = (char)grid - '0';
//int id = lower_bound(all(arr), x) - arr.begin();

/*struct data {
	char *name;
	int age;
	int height;
	double weight;
};*/

/*string ans = w;
string &ref = ans;
rep(i, N) {
	ref[i] = arr[i];
}*/

/*map<int,int> mp;
for(auto p : mp) {
	ct += p.second*(p.second-1); }

map<int,int>::iterator itr;
for(itr = mp.begin(); itr != mp.end(); itr++) {
	ans += itr->second * (itr->second-1);
}*/


Measured memory_bytes: 256
from fractions import gcd
n,m = map(int, input().split())
a = list(map(int, input().split()))
b = []
lcm = 1
for i in a:
    b.append(i//2)
for i in b:
  lcm = lcm // gcd(lcm,i) * i
ans = m // lcm
sum = 0
for i in b:
  if (lcm // i) % 2 == 1:
    sum += 1
if sum != len(a):
  print(0)
elif ans%2 ==1:
    print((ans+1)//2)
else:
    print(ans//2)

Measured memory_bytes: 16280
s = int(input())

mod = 10 ** 9 + 7

answers = [1] * (s + 1)
# answers[0] = 1

for i in range(3):
    if len(answers) > i:
        answers[i] = 0


for i in range(0, s + 1):
    for d in range(s, 2, -1):
        if i - d >= 3:
            # print(i - d, "->", i, answers[i - d])
            answers[i] += answers[i - d]
    answers[i] %= mod

print(answers[s])


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

int main(){
        int N;
        cin >> N;
        vector<int> X(N);
        rep(i,N) cin >> X.at(i);
        sort(X.begin(),X.end());
        int ans = INT_MAX;

        int st = X.at(0);
        int en = X.at(N - 1);
        for(int i = st; i <= en; i++) {
                int sum = 0;
                rep(j,N) sum += ((X.at(j) - i) * (X.at(j) - i));
                ans = min(ans,sum);
        }

        cout << ans << endl;
}


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

int main(){
	while(2){
		int a, b, c;
		scanf("%d %d %d", &a, &b, &c);
		if(a == 0 && b == 0 && c == 0) break;

		vector<int> ans(a + b + c, 2);
		int n;
		scanf("%d", &n);
		
		int d[n][4];
		for(int i=0; i<n; i++){
			scanf("%d %d %d %d", &d[i][0], &d[i][1], &d[i][2], &d[i][3]);
		}

		for(int i=0; i<2; i++){
			for(int j=0; j<n; j++){
				if(d[j][3] == 1){
					ans[d[j][0]-1] = 1;
					ans[d[j][1]-1] = 1;
					ans[d[j][2]-1] = 1;
				}else{
					if(ans[d[j][0]-1] == 1 && ans[d[j][1]-1] == 1){
						ans[d[j][2]-1] = 0;
					}else if(ans[d[j][1]-1] == 1 && ans[d[j][2]-1] == 1){
						ans[d[j][0]-1] = 0;
					}else if(ans[d[j][2]-1] == 1 && ans[d[j][0]-1] == 1){
						ans[d[j][1]-1] = 0;
					}
				}
			}
		}

		for(int i=0; i<a+b+c; i++){
			printf("%d\n", ans[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 1048
#include<bits/stdc++.h>
#define int long long int
#define pb push_back
#define  fill(st,et,val,arr) for(int i=st;i<=et;i++)arr[i]=val;
#define all(v) v.begin(),v.end()
template <class T>
inline void read(T &x) {
    x = 0;
    char ch = getchar(), w = 0;
    while (!isdigit(ch)) w = ch == '-', ch = getchar();
    while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
    x = w ? -x : x;
    return;
}
 
const int M=1e9 + 7;
const int MAX=1e5+7;
using namespace std;
bool comp(pair<int,int> a,pair<int,int> b)
{	if(a.first!=b.first)
    {
    	return a.first<b.first;
	}
	return a.second<b.second;
}
void printQ(vector<int> q)
{   
    cout<<"v->  ";
	for(int i=0;i<q.size();i++)
	{
		cout<<q[i]<<" ";
	}
	cout<<endl;
}
int32_t main() 
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int h,a;
    cin>>h>>a;
    int ans=h/a;
    if(h%a)ans++;
    cout<<ans<<endl;
	return 0;
}













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

const int mod=(int)1e9+7;
const int maxn=(int)1e5+10;
vector<int> v[maxn];
long long dp[2][maxn];

void calc(int a, int f)
{
	if(v[a].size()==1 && f!=0)
		{ dp[0][a]=1; dp[1][a]=1; return; }
	for(auto it : v[a])
		if(it!=f)
			calc(it,a);
	dp[1][a]=1; dp[0][a]=1;
	for(auto it : v[a])
	{
		if(it!=f)
		{
			(dp[1][a]*=dp[0][it])%=mod;
			(dp[0][a]*=(dp[1][it]+dp[0][it]))%=mod;
		}
	}
}

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		int a,b;
		scanf("%d %d",&a, &b);
		v[a].push_back(b);
		v[b].push_back(a);
	}
	calc(1,0);
	printf("%lld",(dp[1][1]+dp[0][1])%mod);
}

Measured memory_bytes: 14208
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String [] args)throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int array[] = new int[3];
        for(int i = 0;i < 3;i++)
            array[i] = Integer.parseInt(st.nextToken());
        Arrays.sort(array);
        if(array[2] == array[0] + array[1])System.out.print("Yes");
        else System.out.print("No");
    }
}


Measured memory_bytes: 8276
/*
...........__________    							 |										    ___  __
.............|       |     						     |											 |   /
.............|       |     						     |									  		 |  /
.............|       |                               |                         __                | /      _______
.............|_______|  _______            _______   |______   ________   /|  /  |               |/       |      |
.............| \               | |      | |          |      |          | / | /   |               |\       |
.............|  \       _______| |      | |_______   |      |   _______|   |/    |               | \      |
.............|   \      |      | |      |         |  |      |  |       |   |     |               |  \     |
.........  __|    \__|  |______| |______| ________|  |      |_ |_______|   |     |__|           _|   \__ _|        .

*/
#include<bits/stdc++.h>
using namespace std ;
#define int 				long long
#define ull 				unsigned long long int
#define ld 					long double
#define vi 					vector<int>
#define vii 				vector<pair<int,int>>
#define vvi 				vector<vector<int>>
#define pf 					push_front
#define popb 				pop_back
#define pb 					push_back
#define eb 					emplace_back
#define pii 				pair<int,int>
#define prec(x) 			fixed<<setprecision(15)<<x
#define all(x) 				x.begin(),x.end()
#define rall(x) 			x.rbegin(),x.rend()
#define mset(a,b) 			memset(a,b,sizeof(a))
#define mcpy(a,b) 			memcpy(a,b,sizeof(a))
#define fo0(i,n) 			for(int i=0,i##end=n;i<i##end;i++)
#define fo1(i,n) 			for(int i=1,i##end=n;i<=i##end;i++)
#define fo(i,a,b) 			for(int i=a,i##end=b;i<=i##end;i++)
#define foe(i,x)			for(__typeof((x).end())i=(x).begin();i!=(x).end();++i)
#define fre(i,x)			for(__typeof((x).rend())i=(x).rbegin();i!=(x).rend();++i)
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0)
#define inf 1e18
const int mod=1e9+7;
const int N=4e5+10;

void raushan_kumar(){
	int n;cin>>n;
	int t=10;
	int sum=0;
	if(n%2){
		cout<<0;
		return;
	}
	while(true){
		sum+=n/t;
		t*=5;
		if(n/t==0)
			break;
	}
	cout<<sum;
}

int32_t main()
{
	fast;int t=1;
	//cin>>t;
	while(t--){
		raushan_kumar();
	}

}

Measured memory_bytes: 256
#include <stdio.h>
int input[101]={};
int n;

int main(void)
{
    scanf("%d",&n);
    int i,j;

    for(i=0;i<n;i++)
    {
        scanf("%d",&input[i]);
    }

    int flag=1;
    int count=0,compare=0;

    for(i=0;i<n;i++)
    {
        for(j=1;j<n-i;j++)
        {
            compare++;
            if(input[j-1]>input[j])
            {
                int c;
                c=input[j-1];
                input[j-1]=input[j];
                input[j]=c;
                count++;
            }
        }
    }

//    printf("%d\n%d\n",compare,count);
    for(i=0;i<n;i++)
    {
        printf("%d",input[i]);
        if(i<n-1)printf(" ");
    }
    printf("\n%d\n",count);


    return 0;
}

Measured memory_bytes: 604
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	int N, x;
	cin >> N >> x;
	int A[100];
	rep(i, N) cin >> A[i];
	sort(A, A + N);
	int tmp = 0;
	int ans = 0;
	int i = 0;
	while (true) {
		if (i == N - 1) {
			if (tmp + A[i] == x) {
				ans++;
			}
			break;
		}
		if (tmp + A[i] <= x) {
			tmp += A[i];
			ans++;
			i++;
		}
		else {
			break;
		}
	}
	cout << ans << endl;
		
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>


int main(){

 long long int N;
  scanf("%lld",&N);

/*
  char A[];
  scanf("%s",A);
  */

  /*
  long long int A[N+1];
  long long int i;
  for(i=1;i<=N;i++){
   scanf("%lld",&A[i]);
   }
  */
if(N%2==0){
  printf("%lld",N/2);
}

else{
  printf("%lld",N/2+1);
}






 return(0);
 }


Measured memory_bytes: 128
const t={input:require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/),n:(arg:number=0):any=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.n())}return a}else{const a=t.input[0];t.input.shift();return Number(a)}},s:(arg:number=0):any=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.s())}return a}else{const a=t.input[0];t.input.shift();return String(a)}},c:(arg:number=0):any=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.c())}return a}else{let a=t.input[0].split('');const b=a[0];a.shift();if(a.length>0){t.input[0]=a.join('')}else{t.input.shift()}return String(b)}},o:(...arg)=>{console.log(...arg)},abs:(a)=>{return Math.abs(a)},min:(...a)=>{return Math.min(...a)},max:(...a)=>{return Math.max(...a)},floor:(a)=>{return Math.floor(a)},asc:(ar:number[])=>{return ar.sort((a,b)=>{return a-b})},desc:(ar:number[])=>{return ar.sort((a,b)=>{return b-a})},sw:(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length;i+=2){if(eval(a+op+arr[i]))return arr[i+1];}return arr[arr.length-1]}};
const main=()=>{
  let [a,b,c]=t.n(3)
  for(let i=0;i<10;i++){
    c=c*a-b
    t.o(c)
  }
}
main()

Measured memory_bytes: 7756
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    ll a,b;
    ll unko=0;
    cin>>n;
    vector<pair<ll,ll> > v;
    for(int i=0;i<n;i++){
        cin>>a>>b;
        unko=max(unko,b-a+1);
        v.pb(make_pair(a,b));
    }
    sort(be(v));
    ll dp1[n];
    ll dp2[n];
    ll mi=0;
    ll ma=1e9;
    for(int i=1;i<n;i++){
        mi=max(mi,v[i-1].first);
        ma=min(ma,v[i-1].second);
        dp1[i]=ma-mi+1;
        dp1[i]=max(dp1[i],0LL);
    }
    mi=0;ma=1e9;
    for(int i=n-1;i>=1;i--){
        mi=max(mi,v[i].first);
        ma=min(ma,v[i].second);
        dp2[i]=ma-mi+1;
        dp2[i]=max(dp2[i],0LL);
    }
    ll ans=0;
    for(int i=1;i<n;i++){
        ans=max(ans,dp1[i]+dp2[i]);
    }



    for(int i=0;i<n;i++){
        swap(v[i].first,v[i].second);
    }
    sort(be(v));
    for(int i=0;i<n;i++){
        swap(v[i].first,v[i].second);
    }
    mi=0,ma=1e9;
    for(int i=1;i<n;i++){
        mi=max(mi,v[i-1].first);
        ma=min(ma,v[i-1].second);
        dp1[i]=ma-mi+1;
        dp1[i]=max(dp1[i],0LL);
    }
    mi=0;ma=1e9;
    for(int i=n-1;i>=1;i--){
        mi=max(mi,v[i].first);
        ma=min(ma,v[i].second);
        dp2[i]=ma-mi+1;
        dp2[i]=max(dp2[i],0LL);
    }
    for(int i=1;i<n;i++){
        ans=max(ans,dp1[i]+dp2[i]);
    }
    ans=max(ans,unko);
    vector<ll> ind;
    for(int i=0;i<n;i++){
        if(v[i].second-v[i].first+1>=unko){
            ind.pb(i);
        }
    }
    int maki=ind.size();
    for(int i=0;i<maki;i++){
        mi=0;ma=1e9;
        for(int j=0;j<n;j++){
            if(j!=ind[i]){
                ma=min(ma,v[j].second);
                mi=max(mi,v[j].first);
            }
        }
        ll niko=max(0LL,ma-mi+1);
        ans=max(ans,niko+v[ind[i]].second-v[ind[i]].first+1);

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


Measured memory_bytes: 3696
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int N, X;
  cin >> N >> X;
  VEC<int> L(N);
  REP(i, 0, N) cin >> L[i];
  int cnt = 1;
  int d = 0;
  REP(i, 0, N ) {
    d = d + L[i];
    // DUMP(d);
    if (d <= X) {
      cnt++;
    } else
      break;
  }
  cout << cnt << endl;

  return 0;
}


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

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

  map<int, vector<int>> graph;
  rep(i,0,M-1) {
    int a, b;
    cin >> a >> b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }

  map<int, int> route;
  queue<int> q;
  route[1] = 0;
  q.push(1);
  while (!q.empty()) {
    int v = q.front(); q.pop();
    for (int nv : graph[v]) {
      if (route.count(nv) == 0) {
        route[nv] = v;
        q.push(nv);
      }
    }
  }

  bool ok = true;
  rep(i,2,N-1) {
    if (route.count(i) == 0) ok = false;
  }

  if (!ok) cout << "No" << endl;
  else {
    cout << "Yes" << endl;
    rep(i,2,route.size()) {
      cout << route[i] << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 20216
n = int(input())
a = list(map(int, input().split()))

l1 = [0]* (n+1)

for i in range(n):
    l1[a[i]] += 1

l2 = [0] * (n+1)

for i in range(1, n+1):
    l2[i] = l1[i] * (l1[i]-1) // 2

l3 = [0] * (n+1)

for i in range(1, n+1):
    if l1[i] > 2:
        l3[i] = (l1[i]-2) * (l1[i]-1) // 2

x = sum(l2)

l4 = [0] * (n+1)

for i in range(1, n+ 1):
    l4[i] = x - l2[i] + l3[i]


for i in range(n):
    print(l4[a[i]])

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,K;
    cin >> n >> K;
    cout << (K == 1 ? 0 : n - K) << endl;
    return 0;
}

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

int main(void){
    int n; cin >> n;
    string S[n];
    for(int i=0; i<n; i++) cin >> S[i];

    string ans="";
    for(char c='a'; c<='z'; c++){
        int cnt=50;
        
        for(int i=0; i<n; i++){

            int tmp=0;
            for(int j=0; j<S[i].size(); j++){
                if(S[i][j]==c) tmp++;
            }
            cnt=min(cnt,tmp);
        }
        
        for(int i=0; i<cnt; i++) ans+=c;
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
char s[100005];
int dp[100005][13];
int main(){
    scanf("%s", s+1);
    int n = strlen(s+1);
    dp[0][0] = 1;
    for(int i=1;i<=n;i++){
        if(s[i] != '?'){
            s[i]-='0';
            for(int j=0;j<13;j++){
                dp[i][(j*10+s[i])%13] = (dp[i][(j*10+s[i])%13] + dp[i-1][j])%mod;
            }
        }
        else{
            for(int k=0;k<10;k++){
                for(int j=0;j<13;j++){
                    dp[i][(j*10+k)%13] = (dp[i][(j*10+k)%13] + dp[i-1][j])%mod;
                }   
            }
        }
    }
    printf("%d\n", dp[n][5]);
}

Measured memory_bytes: 5376
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i==n-1];};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll X,A,B;
    cin >> X >> A >> B;
    ll N;
    string S[1010];
    cin >> N;
    rep(i,0,N) cin >> S[i];
    ll ans = X;
    rep(i,0,N){
        if(S[i] == "karero"){
            ans = 0;
        }else if(S[i] == "nobiro"){
            ans = max(ans+A, 0LL);
        }else{
            ans = max(ans+B, 0LL);
        }
    }
    print(ans);

    
}


Measured memory_bytes: 3252
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;

/**
*  文字列を連結する
*
*  引数で受け取る文字列は「配列型」を期待
*  逆にポインタ型で定義するとエラーが発生するので注意
*/
char* str_concat(char *str1, const char *str2) {

    // str1の最初のアドレスを保持しておく
    char *top = str1;

    // 文字列終端までポインタを進める
    while (*(str1++) != '\0');

    // `\0`分を消すため、ポインタをひとつ戻す（連結のため）
    str1 -= 1;

    // 終端直前から、str2の文字を追加していく
    do {
        *(str1++) = *str2;
    } while (*(str2++) != '\0');

    return str1;
}

/**
*  文字列を置換する
*
*  @param src 評価する文字列
*  @param target  置き換え対象となる文字列
*  @param replace 置き換える文字列
*  @param result  置換後の文字列を返すポインタ
*/
void str_replace(const char *src, const char *target, const char *replace, char **result) {

    char *temp = (char*)malloc(sizeof(char) * 1000);
    if (temp == NULL) {
        printf("Cannot allocate memory.\n");
        return;
    }

    char *top = temp;

    // 操作できるようにコピーする
    char *work = (char*)malloc(sizeof(char) * strlen(src));
    strcpy(work, src);

    char *p;
    while ((p = strstr(work, target)) != NULL) {
        // 検知した位置に文字列終端文字を挿入
        *p = '\0';

        // 検知した位置＋対象文字数分の位置にポインタを移動
        p += strlen(target);

        // 該当文字列以降をいったんtempに退避
        strcpy(temp, p);

        // 前半文字列と置き換え文字列を連結する
        str_concat(work, replace);
        str_concat(work, temp);
    }

    free(temp);

    *result = work;
}


int main()
{
    char src[20];

    if (scanf("%s", src) < 1) return 0;

    char *replace = ",";
    char *target = " ";
    char *result;

    str_replace(src, replace, target, &result);
    printf("%s\n", result); // => "1. |his is a |es|."
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b=0,c=0,d[110];
  cin >>a;
  for(int n=0;n<a;n++){
    cin >>d[n];
  }
  sort(d,d+a,greater<int>());
  for(int n=0;n<a;n++){
    if(n%2==1) c+=d[n];
    else b+=d[n];
  }
  cout <<b-c<<'\n';
  return(0);
}


Measured memory_bytes: 256
ARGS=input().split()
A=int(ARGS[0])
B=int(ARGS[1])
C=int(ARGS[2])
D=int(ARGS[3])

while A > 0 and C > 0:
    C -= B
    if C <= 0:
        print('Yes')
        break
    A -= D
    if A <= 0:
        print('No')
        break

Measured memory_bytes: 9172
n = gets.to_i
l = gets.split(" ").map(&:to_i).sort.reverse
ans = 0
(n).times{ |i|
  i.upto(n-1){ |j|
    j.upto(n-1){ |k|
      if (l[i]!=l[j]) && (l[j]!=l[k]) && l[i]<(l[j]+l[k])
        ans += 1
      end
    }
  }
}
puts ans

Measured memory_bytes: 14392
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);
    static final int mod = 1000000007;

    public static void main(String[] args) {

      int n =sc.nextInt();
      int[] a = new int[n];
      for(int i =0; i<n; i++)
      a[i] = sc.nextInt();
      int high = a[0];
      long ans = 0;
           for(int i =1; i<n; i++)
           {
               if(a[i]>high)
               high = a[i];
         
           else if(a[i]<high)
            ans+= high-a[i];
            
           
           }
        
   System.out.println(ans);
        
       



    }
















    static int max(int a, int b)
    {
        return Math.max(a,b);
    }
    static int max(int a, int b, int c)
    {
        return Math.max(max(a,b), c);
    }
    static int max(int a, int b, int c, int d)
    {
        return Math.max(max(a,b), max(c,d));
    }

    static int min(int a, int b)
    {
        return Math.min(a, b);
    }

    static int min(int a, int b, int c )
    {
        return Math.min(a, min(b,c));
    }

    static int min(int a, int b, int c, int d )
    {
        return Math.min(min(a,d), min(b,c));
    }

    static boolean isPower(int a, int b)
    {
        double temp = Math.log(a)/Math.log(b);
        return temp == (int) temp;
    }
    static boolean isPrime(int n)
    {
        if(n==1) return false;
        if(n==2) return true;
        if(n%2==0) return false;

        if(n<9)return true;
        if(n%3==0) return false;

        int r = (int)Math.sqrt(n);

        for(int i = 5; i<=r; i +=6)
        {
            if(n%i==0) return false;
            if(n%(i+2)==0) return false;
        }
        return true;



    }
}


Measured memory_bytes: 59796
#include<stdio.h>
int F[45];
int fib(int n){
  if(n==0 || n==1)return 1;
  else if(F[n]!=-1)return F[n];
  else{
    F[n]=fib(n-1)+fib(n-2);
    return F[n];
  }
}
int main(){
  int n,i;
  
  scanf("%d",&n);
  F[0]=F[1]=1;
  for(i=2; i<=n; i++){
    F[i]=-1;
  };

  printf("%d\n",fib(n));
  

return 0;
}



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

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

const ll INF = 1e15;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

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

  ll ans = INF;
  for (ll i = 1; i * i <= N; i++) {
    if (N % i == 0) {
      ans = min(ans, i + (N / i));
    }
  }

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


Measured memory_bytes: 256