akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main {
    static MyReader in = new MyReader();

    public static void main(String[] args){
        int N = in.i();
        int A = in.i();
        int B = in.i();
        int[] h = in.ii(N);

        int ans = solve(N, A, B, h);
        out.println(ans);
    }

    static int solve(int N, int A, int B, int[] h) {
        int l = 1;
        int r = 1_000_000_000;
        while (l < r) {
            int m = (l + r) / 2;
            int tot = m;
            for (int i = N - 1; i >= 0; i--) {
                long c = h[i] - (long)B * m;
                tot -= (int)(c > 0 ? (c - 1) / (A - B) + 1 : 0);
                if (tot < 0) break;
            }
            if (0 <= tot) {
                r = m;
            } else {
                l = m + 1;
            }
        }
        return r;
    }

    static long max(int a, long b) {
        return a < b ? b : a;
    }

}

class MyReader extends BufferedReader {
    char[] cbuf = new char[1024];
    int head = 0;
    int tail = 0;

    MyReader() {
        super(new InputStreamReader(System.in));
    }

    char next() {
        if (head == tail) {
            try {
                tail = read(cbuf, 0, cbuf.length);
            } catch (IOException e) {}
            head = 0;
        }
        return cbuf[head++];
    }

    void back() {
        head--;
    }

    boolean minus() {
        boolean minus;
        while (true) {
            char c = next();
            if (c != ' ' && c != '\n' && c != '\r') {
                if (!(minus = c == '-')) back();
                return minus;
            }
        }
    }

    void skip() {
        while (true) {
            char c = next();
            if (c != ' ' && c != '\n' && c != '\r') {
                back();
                break;
            }
        }
    }

    char[] s(final int N) {
        skip();
        char[] s = new char[N];
        for (int i = 0; i < s.length; i++) {
            s[i] = next();
        }
        return s;
    }

    int i() {
        boolean minus = minus();
        int n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }

    int[] ii(final int N) {
        int[] a = new int[N];
        for (int j = 0; j < a.length; j++) a[j] = i();
        return a;
    }

    long l() {
        boolean minus = minus();
        long n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }
}


Measured memory_bytes: 35716
//
//  B.cpp
//  CodeForcesProblems
//
//  Created by Jacob Murry on 1/6/20.
//  Copyright © 2020 Jacob Murry. All rights reserved.
//

//#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <vector>

//Some constants don't work
#ifndef INT_MAX
#define INT_MAX 2147483647
#endif
#ifndef INT_MIN
#define INT_MIN -2147483648
#endif


using namespace std;

class Solution {
    
};

int main(int argc, char * argv[]) {
    int N = 0, K=0;
    cin >> N >> K;
    vector<int> dp(N, 0);
    vector<int> stones(N, 0);
    cin>>stones[0];
    for(int i=1; i<N; ++i) {
        int h;
        cin>>h;
        stones[i] = h;
        //dp[n] = min(dp[i-1]+abs(stones[i-1]-h), dp[i-2]+abs(stones[i-2]-h),...,dp[i-k]+abs(stones[i-k]-h))
        //base case is i==0 or i==1
        int min_cost = INT_MAX;
        for(int k=1; k<=K; k++) {
            if(i-k>=0) {
                min_cost = min(min_cost, dp[i-k]+abs(stones[i-k]-h));
            } else {
                break;
            }
        }
        dp[i] = min_cost;
        
    }
    cout << dp.back() << "\n";
    return 0;
}



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

int main(){
  string N;
  cin >> N;
  int cnt_7=0;
  for(int i=0; i<3; i++){
    if(N[i]=='7'){
      cnt_7++;
    }
  }
  if(cnt_7>0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3612
#require 'pp'
require 'prime'

MAX = 10 ** 6
n = gets.to_i
a_n = gets.split.map(&:to_i)
memo = Array.new(10 ** 6 + 1, 0)
primes = Array.new(10 ** 6 + 1, 0)
Prime.each(MAX) do |i|
    primes[i] = 1
end

#pp primes.tally

all_gcd = a_n[0]
1.upto(n-1) do |i|
    all_gcd = all_gcd.gcd(a_n[i])
end

# 全GCDが1でない場合どちらでもない
if all_gcd > 1
    puts "not coprime"
    exit 0
end

## ============
## 以下は全GCDは常に1前提
## ============

a_n.sort!
# 同じ数字が含まれている場合setwise
a_n.each_cons(2) do |a, b|
    if a == b && a != 1
        puts "setwise coprime"
        exit 0
    end
end

ok = true
a_n.each do |a|
    if primes[a] == 1
        if memo[a] == 1
            puts "setwise coprime"
            exit 0
        end

        memo[a] = 1
    else
        Prime.prime_division(a).each do |x, cnt|
            if memo[x] == 1
                puts "setwise coprime"
                exit 0
            end
            memo[x] = 1
        end
    end
end

puts "pairwise coprime"




Measured memory_bytes: 98868
// finish date: 2018/01/20
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define bigmod 1000000007
#define INF 500000000


int main() {
    int X,A,B;
    cin>>X>>A>>B;
    if(A-B>=0) cout<<"delicious"<<endl;
    else if(X+A-B>=0) cout<<"safe"<<endl;
    else cout<<"dangerous"<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<stdio.h>
#include<vector>
#include<string>
using namespace std;

int main(void){
    long long int i,N,A[100000],B[100000],ans=0;
    cin >> N;
    for(i=0;i<N;i++){
        cin >> A[i] >> B[i];
    }
    for(i=N-1;i>=0;i--){
        if((A[i]+ans)%B[i]!=0){
            ans+=B[i]-(A[i]+ans)%B[i];
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1920
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int totalL = 0;
        int max = 0;
        for(int i=0;i<N;i++){
            int L = scan.nextInt();
            totalL = totalL+L;
            if(L > max){
                max = L;
            }
        }
        scan.close();

        totalL = totalL - max;

        if(max < totalL){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 22996
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

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

    N = N % K;
    cout << min(N, K - N) << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;

public class Main {
	private static FastScanner sc = new FastScanner();

	public static void main(String[] args) {
		int n = sc.nextInt();
		
		int[] a = new int[3*n];
		for(int i=0; i<3*n; i++) {
			a[i] = sc.nextInt();
		}
		
		PriorityQueue<Integer> que = new PriorityQueue<>();
		
		long sum = 0;
		for(int i=0; i<n; i++) {
			que.add(a[i]);
			sum += a[i];
		}
		
		long[] r = new long[3*n];
		r[n] = sum;
		for(int i=n; i<2*n; i++) {
			que.add(a[i]);
			sum += a[i] - que.poll();
			r[i+1] = sum;
		}
		
		que = new PriorityQueue<>((x,y) -> y-x);
		
		sum = 0;
		for(int i=3*n-1; i>=2*n; i--) {
			que.add(a[i]);
			sum += a[i];
		}
		
		long[] b = new long[3*n];
		b[2*n] = sum;
		for(int i=2*n-1; i>=n; i--) {
			que.add(a[i]);
			sum += a[i] - que.poll();
			b[i] = sum;
		}
		
		long max = Long.MIN_VALUE;
		for(int i=n; i<=2*n; i++) {
			if(r[i] - b[i] > max) {
				max = r[i] - b[i];
			}
		}
		
		System.out.println(max);
	}

	static class FastScanner {
	    private final InputStream in = System.in;
	    private final byte[] buffer = new byte[1024];
	    private int ptr = 0;
	    private int buflen = 0;
	    private 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;
	    }
	    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
	    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
	    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
	    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
	    public String next() {
	        if (!hasNext()) throw new NoSuchElementException();
	        StringBuilder sb = new StringBuilder();
	        int b = readByte();
	        while(isPrintableChar(b)) {
	            sb.appendCodePoint(b);
	            b = readByte();
	        }
	        return sb.toString();
	    }
	    public long nextLong() {
	        return Long.parseLong(next());
	    }
	    public int nextInt(){
	    	return Integer.parseInt(next());
	    }
	}
}


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

int main(){
	int x, y, t;
    while(!cin.eof()){
      cin >> x >> y;
      if(x == 0 && y == 0){
        break;
      }
	  if (x > y){
	    t = x;
	    x = y;
	    y = t;
	  }
	  cout << x << " " << y << endl;
    }
}


Measured memory_bytes: 2980
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	ll a[n][n];
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cin >> a[i][j];
		}
	}
	ll ans=0;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			ans+=min(a[i][j],a[j][i]);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3300
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		if(a-2*b <= 0) {
			System.out.println(0);
		} else if(a-2*b > 0) {
			System.out.println(a-2*b);
		}
	}
}

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

using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 27
#endif

#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define sz(v) (int)(v.size())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ar array
#define forn(i, n) for(int i = 0; i < n ; ++i)
#define for1(i, n) for(int i = 1; i <=n ; ++i)
#define ford(i, n) for(int i = n-1; i>= 0;--i)
#define UNQ(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define mem(X,val) memset(X, val, sizeof((X)))

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>>  vvi ;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpi ;

const db PI = acos(-1);
const ll mod = 1e9+7;
template <class T>void smax(T& x,T y){ if(x<y)x=y;}
template <class T>void smin(T& x,T y){ if(x>y)x=y;}
template<typename T1, typename T2> T1 powz(T1 A, T2 B);
/***************************************************main code**************************************************************/
const int MXN=1e6+5;
const ll INF = 9e18+200;
const int inf = 1e9+100;
const int mxn = 2e5+20;

db dp[3000][3000];

void test_case()
{	
	int n; cin >> n;
	db p[n+1]; for1(i, n) cin >> p[i];
	forn(i, n+1) forn(j, n+1) dp[i][j] = 0.0;
	dp[0][0] = 1;
	dp[0][1] = 0;			     
	for1(i, n){
		for(int j = 0; j <= i; ++j){
			if(j > 0)
				dp[i][j] += dp[i-1][j-1]*p[i];
			dp[i][j] += dp[i-1][j]*(1-p[i]);
		}
	}
//	for1(i, n) forn(j, i+1) cout << dp[i][j]<<" \n"[j==i];
	db ans =0.0;
	for(int i = n/2+1 ; i<= n; ++i)
		ans += dp[n][i];	
   	cout << fixed << setprecision(10)<< ans;
}
/*************----------------------------******************/
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
#ifdef VIJY_DEFINE
    freopen("input.txt","r",stdin);
#endif
//  freopen("output.txt","w",stdout);
    int Tests = 1;
//  cin >> Tests;
    
    for(int tc = 1; tc <= Tests; ++tc){
        //cout <<"Case #"<<tc<<": ";
        test_case();
        cout<<'\n';
    }
#ifdef VIJY_DEFINE
    cerr << "Time elapsed: "<< 1.0*clock() / CLOCKS_PER_SEC <<"s.\n";
#endif   
}
template<typename T1, typename T2>
T1 powz(T1 X,T2 B)
{
    ll A = X;
    ll res=1;
        A%=mod; 
        assert(B>=0); 
    for( ; B ; B>>=1){
        if(B&1)res=res*A%mod;
        A= A*A%mod;
    }
    return res;
}


Measured memory_bytes: 74064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e8;
const ll INF = 1e16;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

const int MAX_V = 5e5;

struct binary_indexed_tree{
    ll n, bit[MAX_V+1];
    //要素数N(0〜N-1)のBITを構築
    binary_indexed_tree(int N){
        n = 1;
        while(n < N) n *= 2;
        fill_n(bit, n+1, 0);
    }
    //i番目(0から数える)の要素にx加える
    void add(int i, ll x){
        i++;
        while(i <= n){
            bit[i] += x;
            i += (i & -i);
        }
    }
    //sum(i)で[0,i)の和を取得
    ll sum(int i){
        ll s = 0;
        while(i > 0){
            s += bit[i];
            i -= (i & -i);
        }
        return s;
    }
    //query(l,r)で[l,r)の和を取得
    ll query(int l, int r){
        return sum(r) - sum(l);
    }
};

int main(){
    //英小文字を整数に対応させる
    map<char, int> ctoi;
    rep(i, 26) ctoi[alpha[i]] = i;
    string S;
    cin >> S;
    int N = S.size();
    //各アルファベットの最初のインデックスを記録
    vector<int> id[26];
    rep(i, N) id[ctoi[S[i]]].pb(i);
    //奇数個出現する英小文字の数
    int cnt = 0;
    //相方の初期位置
    int p[N];
    rep(i, 26){
        int n = id[i].size();
        if(n%2 == 1) cnt++;
        rep(j, n){
            p[id[i][j]] = id[i][n-1-j];
        }
    }
    if(cnt >= 2){
        cout << -1 << endl;
        exit(0);
    }
    //最初i番目だった文字が最終的に何文字目になるか
    int l[N];
    int now = 0;
    rep(i, N){
        if(p[i] == i) l[i] = N/2;
        elif(p[i] > i){
            l[i] = now;
            now++;
        }
        else l[i] = N-1-l[p[i]];
    }
    //数列lの転倒数が答え
    ll ans = 0;
    binary_indexed_tree bit(N);
    rep(i, N){
        ans += bit.query(l[i], N);
        bit.add(l[i], 1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 6788
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H& b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H & b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H & b) const { return x == b.x && y == b.y; }
	bool operator!=(const H & b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P& b) const { return cost < b.cost; }
	bool operator>(const P& b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E& b) const { return cost < b.cost; }
	bool operator>(const E& b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T & a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T & a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n, m;
int a[200000];
signed main() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int l = read(), r = read();
		a[l]++;
		a[r + 1]--;
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		a[i] += a[i - 1];
		if (a[i] == m) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
/*
 _ _ _   _    _   _    _   _ _ _   _    _   _ __ _   __       __
|  _ _| | |  | | | |  | | |  _  | | |  | | |  __  | |   \   /   |
| |_ _  | |__| | | |  | | | |_| | | |__| | | |__| | | |\ \_/ /| |
|_ _  | |  __  | | |  | | |  _ <  |  __  | |  __  | | | \   / | |
 _ _| | | |  | | | |__| | | |_| | | |  | | | |  | | | |  \_/  | |  _   _   _
|_ _ _| |_|  |_| |_ __ _| |_ _ _| |_|  |_| |_|  |_| |_|       |_| |_| |_| |_|

*/

#include <bits/stdc++.h>
using namespace std;

#define ll long long int
#define fi first
#define se second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define debug(a) cout << #a << " = " << a << " ";
#define endl "\n"
const int  MOD=1000000007;

void solve(){
    int n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++){
    	cin>>a[i];
    }

    ll maxx=a[0],ans=0;
    for(int i=1;i<n;i++){
    	if(a[i]<maxx){
    		ans+=maxx-a[i];
    	}
    	maxx=max(a[i],maxx);
    }
    cout<<ans<<endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long int t = 1;
    // cin>>t;
    for (long int tt = 1; tt <= t; tt++) {
        solve();
    }
    return 0;
}


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

#define rep(i, m, n) for(int(i) = (int)(m); i < (int)(n); ++i)
#define rep2(i, m, n) for(int(i) = (int)(n)-1; i >= (int)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
using tp = tuple<ll, ll, ll>;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
//constexpr long long MOD = (ll)1e9 + 7;
constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

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

//グラフ関連
struct Edge {
    ll to, cap, rev;
    Edge(ll _to, ll _cap, ll _rev) {
        to = _to;
        cap = _cap;
        rev = _rev;
    }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph &G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
    G[from].push_back(Edge(to, cap, (ll)G[to].size()));
    if(revFlag)
        G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve() {
    ll n;
    cin >> n;
    vec<ll> a(3 * n);
    REP(i, 3 * n) {
        cin >> a[i];
    }

    vvec<ll> dp(n + 1, vec<ll>(n + 1, -1));
    vec<ll> mak(n + 1, -1);

    dp[a[0]][a[1]] = 0;
    dp[a[1]][a[0]] = 0;
    mak[a[0]] = 0;
    mak[a[1]] = 0;
    ll all = 0;
    ll ma = 0;
    REP(i, n - 1) {
        vec<tp> ndp;
        vec<ll> b({a[i * 3 + 2], a[i * 3 + 3], a[i * 3 + 4]});
        if(b[0] == b[1] and b[1] == b[2]) {
            all++;
            continue;
        }

        REP(j, 3) {
            //どれか二つを使う
            if(b[(j + 1) % 3] == b[(j + 2) % 3]) {
                rep(k, 1, n + 1) {
                    if(dp[b[(j + 1) % 3]][k] == -1)
                        continue;
                    ndp.push_back({b[j], (ll)k, dp[b[(j + 1) % 3]][k] + 1});
                }
            }

            //どれか一つだけ使う
            if(dp[b[j]][b[j]] != -1)
                ndp.push_back({b[(j + 1) % 3], b[(j + 2) % 3], dp[b[j]][b[j]] + 1});

            //どれか一つだけすてる
            ndp.push_back({b[(j + 1) % 3], b[(j + 2) % 3], ma});

            //どれか二つをすてる
            rep(k, 1, n + 1) {
                if(mak[k] == -1)
                    continue;
                ndp.push_back({b[j], (ll)k, mak[k]});
            }
        }
        for(auto [x, y, num] : ndp) {
            chmax(ma, num);
            chmax(mak[x], num);
            chmax(mak[y], num);
            chmax(dp[x][y], num);
            chmax(dp[y][x], num);
        }
    }
    chmax(ma, dp[a[3 * n - 1]][a[3 * n - 1]] + 1);
    cout << ma + all << en;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /*
    ll t;
    cin >> t;
    while(t--)*/
    solve();

    return 0;
}


Measured memory_bytes: 35220
/*
 ╔═══╦═══╦═══╗
 ║╔═╗║╔══╩╗╔╗║
 ║║░║║╚══╗║║║║
 ║║░║║╔══╝║║║║
 ║╚═╝║╚══╦╝╚╝║
 ╚══╗╠═══╩═══╝
 ░░░╚╝░░░░░░░░
 */

#include <bits/stdc++.h>
#define ll                    long long
#define debug(x)            { cerr << #x << " = " << x << endl; }
#define MOD                    1000000007
#define MAX                    1e9
#define MIN                 -1e9
#define vi                    vector<int>
#define vii                    vector<vi>
#define max(x,y)            (x>y)?x:y
#define mid(s,e)            (s+(e-s)/2)
#define MAXND                11
using namespace std;

int main() {
    ios::sync_with_stdio(false);
     cin.tie(0);
    int N;
    cin>>N;
    vector<int> A(N);
    vector<int> ans(N);
    for(int i=0; i<N; i++) {
        cin>>A[i];
    }
	 ans[0] = 0;
	for(int j=0; j<N; j++) {
		if(j%2 == 0)
			ans[0] += A[j];
		else 
			ans[0] -= A[j];
	}
	cout<<ans[0] << " ";
	
	for(int i=1; i<N; i++) {
		ans[i] = 2*(A[i-1] - ans[i-1]/2);
		cout<<ans[i] << " ";
	}


    return 0;
}




Measured memory_bytes: 2176
s = input()
t = input()
result = 0
con1 = len(s) >= 1 and len(s) <= 200000
con2 = len(t) >= 1 and len(t) <= 200000
if con1 == True and con2 == True and len(s) == len(t):
    for i in range (0, len(s)):
        if s[i] != t[i]:
            result = result + 1
        else:
            continue
    print(result)
else:
    print()


Measured memory_bytes: 9180
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <string>
#include <deque>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    string s;
    cin >> s;
    int q;
    cin >> q;
    
    int f,t;
    char c;
    
    bool flag = true;

    rep(i,q){
        cin >> f;
        if(f == 1){
            flag = !flag;
        }else{
            cin >> t >> c;
            if(t == 1){
                if(flag){
                    s = c + s;
                }else{
                    s += c;
                }
            }else{
                if(flag){
                    s += c;
                }else{
                    s = c + s;
                }
            }
        }
    }


    if(flag) cout << s << endl;
    else {
        reverse(s.begin(),s.end());
        cout << s << endl;
    }
    
    return 0;
}

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

signed main(){
    int n,a,b;cin>>n>>a>>b;
    if((b-a)%2==0){cout<<(b-a)/2<<endl;return 0;}
    int on=a-1;
    int ob=b-on;
    on+=(ob-1)/2 + !((ob-1)%2==0);
    int nn=n-b;
    int na=a+nn;
    nn+=(n-na)/2 + !((n-na)%2==0);
    cout<<min(on,nn)<<endl;
}

Measured memory_bytes: 256
#include <string>
#include <iostream>
#include <vector>
#include <stack>
#include <stdio.h>
#include <math.h>
#include <utility>
#include <algorithm>

using namespace std;

int main() {
	int k, n;
	cin >> n >> k;
	int cnt = n - k + 1;
	cout << cnt;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define inf 1000000000 //1E+9
using namespace std;	

int main(){
	int a=0;
	string s;cin>>s;
	for(int i=0;i<4;i++)if(s[i]=='+')a++;else a--;
	cout<<a<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<math.h>
#include<algorithm> 
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18
#define chmax(x,y) x = max(x, y)

int main() {
    ll r, d, x ;
    cin >> r >> d >> x ;
    rep(i, 10){
        x = r*x - d ;
        cout << x << endl ;
    }
} 

Measured memory_bytes: 3596
import java.io.*;

class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int N=Integer.parseInt(br.readLine());
		StringBuilder sb=new StringBuilder();
		int i=1;
		do{
			int x=i;
			if(x%3==0||check3(i, Integer.toString(i).length())) sb.append(" "+i);
		}while(++i<=N);
		System.out.println(sb);
	}
	
	private static boolean check3(int n, int k){
		boolean res=false;
		int t=(int)Math.pow(10, k-1);
		if(n/t==3){
			res=true;
		}else if(k>1){
			res=check3(n%t, k-1);
		}
		return res;
	}
}

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

def _rot(c,N):
    if 'A' <= c and c <= 'Z':
        c = chr((ord(c) - ord('A') + N) % 26 + ord('A'))
    if 'a' <= c and c <= 'z':
        c = chr((ord(c) - ord('a') + N) % 26 + ord('a'))
    return c

def rot(S,N):
    g = (_rot(c,N) for c in S)
    return ''.join(g)

print(rot(S,N))


Measured memory_bytes: 3064
N, M = gets.split.map(&:to_i)
ns = (1..N).map { gets.split.map(&:to_i) }
ms = (1..M).map { gets.split.map(&:to_i) }

result = []
ns.each do |a, b|
  distance = 10**9
  _index = nil
  ms.each_with_index do |(c, d), index|
    tmp = (a - c).abs + (b - d).abs
    if distance > tmp
      distance = tmp
      _index = index + 1
    end
  end
  result << _index
end
result.each { |i| p i }

Measured memory_bytes: 2044
#include<iostream>
#include<string>
using namespace std;
int main()
{
	char ch;
	int n;
	cin>>n;
	cin.get(ch);
	for(int i=0;i<n;i++)
	{
		string str;
		while(1)
		{
			cin.get(ch);
			if(ch=='\n')break;
			str+=ch;
		}
		while(1)
		{
			int idx=str.find("Hoshino");
			if(idx==-1)break;
			str[idx+6]='a';
		}
		cout<<str<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
<?php
fscanf(STDIN, '%d %d %d %d', $h, $w, $a, $b);
for ($i = 0; $i < $b; $i++) echo str_repeat('1', $a) . str_repeat('0', $w - $a) . PHP_EOL;
for ($i = $b; $i < $h; $i++) echo str_repeat('0', $a) . str_repeat('1', $w - $a) . PHP_EOL;

Measured memory_bytes: 5624
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
       string s;
       cin>>s;
       
       for(int i=0;i<s.size();i++)
       {
             if(s[i]=='1')
             s[i]='9';
             else if(s[i]=='9')
             s[i]='1';
       }
       cout<<s<<endl;
}


Measured memory_bytes: 768
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

typedef long long ll;

int main(void) {
  int n, a, b;
  scanf("%d%d%d", &n, &a, &b);
  printf("%d\n", min(a*n, b));
  return 0;
}


Measured memory_bytes: 256
#include "stdio.h"

int main(void){

  int D;
  if(scanf("%d", &D) ==EOF)
    return 0;
  if(D==25)
    puts("Christmas");
  
  else if(D==24)
  	puts("Christmas Eve");
    
  else if(D==23)
    puts("Christmas Eve Eve");
  
  else if(D==22)
    puts("Christmas Eve Eve Eve");
    
}


Measured memory_bytes: 128
import sys

def S():
	return sys.stdin.readline().rstrip()

def I():
	return int(sys.stdin.readline().rstrip())

def main():
	K = I()
	word = S()
	if len(word) <= K:
		print(word)
	else:
		print(word[:K] + "...")

if __name__ == "__main__":
	main()

Measured memory_bytes: 9172
#include <algorithm>
#include <vector>
#include <cfloat>
#include <string>
#include <cmath>
#include <set>
#include <cstdlib>
#include <map>
#include <ctime>
#include <iomanip>
#include <functional>
#include <deque>
#include <iostream>
#include <cstring>
#include <queue>
#include <cstdio>
#include <stack>
#include <climits>
#include <sys/time.h>
#include <cctype>

using namespace std;

typedef long long ll;

int dp1[1000000+1], dp2[1000000+1][5]; // 奇数　そうでない
int main() {

  memset(dp1, -1, sizeof(dp1));
  memset(dp2, -1, sizeof(dp2));
  vector <int> memo;
  int cnt = 0;
  for (ll i = 1; i*(i+1)*(i+2)/6 <= 1000000; i++) {
    int val = i*(i+1)*(i+2)/6;
    memo.push_back(i*(i+1)*(i+2)/6);
    if (val%2) {
      cnt++;
    }
  }

  for (int i = 0; i < memo.size(); i++) {
    if (memo[i]%2) {
      dp1[memo[i]] = 1;
    }
    dp2[memo[i]][0] = 1;
  }


  for (int i = 1; i <= 1000000; i++) {
    for (int j = 0; j < memo.size() && memo[j] < i; j++) {
      if (memo[j]%2) {
	if (dp1[i-memo[j]] != -1) {
	  if (dp1[i] == -1) {
	    dp1[i] = dp1[i-memo[j]]+1;
	  }else {
	    dp1[i] = min(dp1[i], dp1[i-memo[j]]+1);
	  }
	}
      }

      for (int k = 1; k < 5; k++) {
	if (dp2[i-memo[j]][k-1] != -1) {
	  if (dp2[i][k] == -1) {
	    dp2[i][k] = dp2[i-memo[j]][k-1]+1;
	  }else {
	    dp2[i][k] = min(dp2[i][k], dp2[i-memo[j]][k-1]+1);
	  }
	}
      }
    }
  }

  int n;
  while(true) {
    cin >> n;
    if (n == 0) break;

    int ans2;
    ans2 = 10000000;
    for (int i = 0; i < 5; i++) {
      if (dp2[n][i] != -1) {
	ans2 = min(ans2, dp2[n][i]);
      }
    }

    std::cout << ans2 << " " << dp1[n] << std::endl;
  }
}

Measured memory_bytes: 24660
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);
            Console.WriteLine(((1 + b - a) * (b - a) / 2) - b);
        }
    }
}
//int[] N = Console.ReadLine().Split(" ").Select(x => int.Parse(x)).ToArray();

Measured memory_bytes: 27384
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
const int MAXN = 3e3 + 5;
const int MAXM = 3e3 + 5;

int a[MAXN][MAXN];

int main(void)
{
	int n,m,d;
	scanf("%d%d%d",&n,&m,&d);
	for(int i=1; i<=d; ++i)
	{
		int x,y,v;
		scanf("%d%d%d",&x,&y,&v);
		a[x][y] = v;
	}
	
	static ll f[MAXN][MAXM][5];
	for(int i=1; i<=n; ++i)
		for(int j=1; j<=m; ++j)
		{
			ll lst = max(max(f[i-1][j][0], f[i-1][j][1]), max(f[i-1][j][2], f[i-1][j][3]));
			
			f[i][j][0] = max(f[i][j-1][0], lst);
			f[i][j][1] = max(f[i][j-1][1], f[i][j][0] + a[i][j]);
			f[i][j][2] = max(f[i][j-1][2], f[i][j-1][1] + a[i][j]);
			f[i][j][3] = max(f[i][j-1][3], f[i][j-1][2] + a[i][j]);
		}
	
	printf("%lld\n",max(max(f[n][m][0], f[n][m][1]), max(f[n][m][2], f[n][m][3])));
	return 0;
}

Measured memory_bytes: 389024
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Edge = pii;
using Graph = vector<vector<Edge>>;
int n;
Graph G;

void dfs(int n, int par, int pc, vector<int>& res){
  int color = 1;
  if(color == pc) color++;
  for(auto e: G[n]){
    if(res[e.second] != -1) continue;
    res[e.second] = color;
    dfs(e.first, n, color, res);
    color++;
    if(color == pc) color++;
  }
}

int main() {
  cin >> n;
  G.assign(n, vector<Edge>());
  rep(i, n-1){
    int a, b; cin >> a >> b; a--; b--;
    G[a].emplace_back(b, i);
    G[b].emplace_back(a, i);
  }

  int mx = 0;
  rep(i, n) chmax(mx, (int)G[i].size());

  vector<int> res(n, -1);
  dfs(0, -1, -1, res);

  cout << mx << ln;
  rep(i, n-1) cout << res[i] << ln;
}


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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()
#define vprint(v) for(auto e:v){cout<<e<<" ";};cout<<endl;
#define vvprint(vv) for(auto v:vv)vprint(v);

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20);

    string S;
    cin >> S;

    if(S=="ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;

}


Measured memory_bytes: 3608
#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(){
  long n;
  cin >> n;
  double x;
  do{
    x = sqrt(n);
    n--;
  }while(int(x) != x);
  
  P(++n);
  ret 0;
}

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

int main() {
    int N, K;
    cin >> N >> K;
    vector<bool> bad(10, false);
    for (int i = 0; i < K; i++) {
        int d;
        cin >> d;
        bad[d] = true;
    }

    for (int n = N; n < 1e9; n++) {
        int temp = n;
        bool ok = true;
        while (temp > 0) {
            if (bad[temp % 10]) {
                ok = false;
                break;
            }
            temp /= 10;
        }
        if (ok) {
            cout << n << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
x = int(input())
for i in range(1,x+1):
    y = i
    if y % 3 == 0:
        print(" %d" % i, end="")
        continue
    while True:
        if int(y) % 10 == 3:
            print(" %d" % i, end="")
            break
        y /= 10
        if int(y) == 0: break
print("")

Measured memory_bytes: 7928
import java.util.*;
import java.io.*;

class Main{
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st  = new StringTokenizer(br.readLine());

        int A = Integer.parseInt(st.nextToken());
        int B = Integer.parseInt(st.nextToken());
        int H = Integer.parseInt(st.nextToken());
        int M = Integer.parseInt(st.nextToken());

        int mins = 60*H+M;

        double M_angle = M*6;
        double H_angle = mins*0.5;

        double x1 = A*Math.cos(Math.toRadians(H_angle));
        double y1 = A*Math.sin(Math.toRadians(H_angle));
        double x2 = B*Math.cos(Math.toRadians(M_angle));
        double y2 = B*Math.sin(Math.toRadians(M_angle));

        System.out.println(Math.sqrt((x2-x1)*(x2-x1)  + (y2-y1)*(y2-y1)));



    }

}

Measured memory_bytes: 33420
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>

using namespace std;

typedef long long int lli;

int gcd(int a, int b) {
	return b != 0 ? gcd(b, a%b) : a;
}
lli gcd(lli a, lli b) {
	return b != 0 ? gcd(b, a%b) : a;
}
int lcm(int a, int b) {
	return a * b / gcd(a, b);
}
lli lcm(lli a, lli b) {
	return a * b / gcd(a, b);
}

#define N_MAX 100000
#define MOD 1000000007

void solv()
{
	int N, M; scanf("%d%d", &N, &M);
	int ac[N_MAX], pen[N_MAX];
	fill(ac, ac + N, 0);
	fill(pen, pen + N, 0);
	for (int i = 0; i < M; i++) {
		int p; char S[10];
		scanf("%d%s", &p, S);
		p--;
		if ('W' == S[0]) {
			if (0 == ac[p]) {
				pen[p]++;
			}
		}
		else {
			ac[p] = 1;
		}
	}

	int ret1 = 0, ret2 = 0;
	for (int i = 0; i < N; i++) {
		if (1 == ac[i]) {
			ret1++;
			ret2 += pen[i];
		}
	}

	printf("%d %d", ret1, ret2);

	return;
}

int main()
{
	FILE *fin = NULL, *fout = NULL;
	//fin = freopen("input.txt", "r", stdin);
	//fout = freopen("output.txt", "w", stdout);

	solv();

	//finalize
	if (NULL != fin) fclose(fin);
	if (NULL != fout) fclose(fout);

	return 0;
}


Measured memory_bytes: 896
a, b, c, d = map(int, input().split())
ans = 0


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    return (a*b)//gcd(a, b)


a -= 1
ans += (b//c - a//c)
ans += (b//d - a//d)
ans -= (b//lcm(c, d)-a//lcm(c, d))
ans = b-a-ans
print(ans)


Measured memory_bytes: 3060
use std::io::*;
use std::str::FromStr;

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

fn main() {
    let x: u32 = read();
    println!("{}", (x + 1) % 2);
}


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

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

	vector<vector<int>> a(2, vector<int>(n));
	
	int sum = 0;
	
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < n; j++) {
			cin >> a[i][j];
			sum += a[i][j];
		}
	}

	int ans = 0;
	for (int k = 0; k < n; k++) {
	
		int tmp = sum;

		for (int j = 0; j < n; j++) {			
			if (k < j) tmp -= a[0][j];		
		}
		for (int j = 0; j < n; j++) {
			if (j < k) tmp -= a[1][j];
		}

		ans = max(ans, tmp);

	}
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<ll, ll>
#define PP pair<P,P>
using namespace std;

int main(){
    int n,k,q; cin >> n >> k >> q;
    vector<int> check(n,0);
    rep(i,q){
        int a; cin >> a;
        check[a-1]++;
    }
    rep(i,n){
        if(check[i]+k-q>0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
return 0;
}




Measured memory_bytes: 1024
package main

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

func main() {
	N, M := ReadInt(), ReadInt()
	Ps := ReadInts(N)
	uf := InitUnionFind(N)
	for m := 0; m < M; m++ {
		x, y := ReadInt(), ReadInt()
		uf.Unite(x-1, y-1)
	}
	ans := 0
	for i := 0; i < N; i++ {
		if uf.Connected(Ps[i]-1, i) {
			ans++
		}
	}
	fmt.Println(ans)
}

func InitUnionFind(size int) UnionFind {
	parent := make([]int, size)
	for i := 0; i < size; i++ {
		parent[i] = i
	}
	return parent
}

type UnionFind []int

func (uf UnionFind) Unite(x, y int) {
	x = uf.Root(x)
	y = uf.Root(y)
	if x != y {
		uf[x] = y
	}
}

func (uf UnionFind) Connected(x, y int) bool {
	return uf.Root(x) == uf.Root(y)
}

func (uf UnionFind) Root(x int) int {
	if uf[x] == x {
		return x
	}
	uf[x] = uf.Root(uf[x])
	return uf[x]
}

func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }


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

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

int main (void) {
    int n, k, i;
    long long sum_h=0;
    scanf("%d%d", &n, &k);
    int h[n];
    for ( i=0; i<n; i++ ) {
        scanf("%d", &h[i]);
        sum_h += h[i];
    }

    qsort(h, n, sizeof(int), cmp);

    for ( i=0; i<k && i<n; i++ )
        sum_h -= h[i];

    printf("%lld\n", sum_h);

    return EXIT_SUCCESS;
}


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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if(c >= a && c <= b) cout << "Yes" << endl;
  else cout << "No"  << endl;
  
}

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



int main() {
    int n;
    cin >> n;
    
    int ans = 0;
    if(n >= 10) {
        ans += 9;
        if(n >= 1000) {
            ans += 900;
            if(n >= 100000) {
                ans += 90000;
            }
            else if(n >= 10000){
                ans += n - 9999;
            }
        }
        else if(n >= 100){
            ans += n - 99;
        }
    }
    else {
        ans += n;
    }
    
    cout << ans << endl;
    
    
    
    return 0;
}


Measured memory_bytes: 3556
//--- pC ---//
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main {
	public static void main (String[] args) throws java.lang.Exception {
		new Solution();
	}
}
class Solution {
	Reader reader;
	public Solution () {
		reader = new Reader();
		while (reader.hasNext()) {
			run_case();
		}
	}
	private void run_case() {
		// 2 * sq(ab) < c - a - b
		long a = Long.parseLong(reader.ns());
		long b = Long.parseLong(reader.ns());
		long c = Long.parseLong(reader.ns());
		// long t = c - a - b;
		// t /= 2;
		long ab = a * b;
		long t = c - a - b;

		if (t <= 0) {
			System.out.println("No");
			return;
		}


		// 4 * ab < t*t
		long L = 4L * ab;
		long R = t * t;
		if (L < R) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		return;
	}


}

class Reader {
	BufferedReader br;
	StringTokenizer st;
	public Reader(){
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			st = new StringTokenizer(br.readLine());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public String next() {
		if (st.hasMoreTokens()) return st.nextToken();
		try {
			st = new StringTokenizer(br.readLine());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return st.nextToken();
	}
	public boolean hasNext() {
		try {
			if (!st.hasMoreTokens() && !br.ready()) return false;
			else return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}
	public int ni() {return Integer.parseInt(this.next());}
	public String ns() {return this.next();}
}


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

using ll = long long;
#define ALL(c) (c).begin(), (c).end()
const int MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    int max_count = 0;
    int ans = 1;
    for (int i = 1; i <= n; i++) {
        bitset<8> bs(i);
        int c = 0;
        while (bs[c] == 0) {
            c++;
        }
        if (max_count < c) {
            max_count = c;
            ans = i;
        }
    }
    cout << ans << endl;
}


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

const int mod = 998244353;

int N, K, comb[4004][4004];

int mul(int a, int b){
	long long ret = 1ll*a * b;
	return ret%mod;
}

void preprocessing(){
	for(int i = 0; i <= 4000; i++)
		comb[i][0] = comb[i][i] = 1;
	for(int i = 2; i <= 4000; i++)
		for(int j = 1; j<i; j++)
			comb[i][j] = (comb[i-1][j] + comb[i-1][j-1])%mod;
}

int solve(int ii){
	long long ret = 0;
	int X = ii/2 - max(1, ii - K)+1;
	int pm = 1;
	for(int i = 0; i <= X; i++){
		if(N < i*2)	break;
		ret = (ret + mul(pm, mul(comb[K-i*2+N-1][N-i*2], comb[X][i])) + mod)%mod;
		pm *= -1;
	}
	return ret%mod;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	preprocessing();
	cin>>K>>N;
	for(int i = 2; i<=2*K; i++)
		cout<<solve(i)<<'\n';
	return 0;
}

Measured memory_bytes: 61440
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val N, K = sc.nextInt()
    val A = Array.fill(N)(sc.nextInt())

    // N個の建物が左から右へと一直線上に並んでいる
    // 左からi番目の建物は色iで塗られており,
    // 高さは現在aiです。
    // 左から見たときに、K色以上の色の建物が見えるという条件を満たして欲しいと思いました
    // 高さを増やすことができるが、減らすことはできない
    // 建物iが見えるとは, 建物iの前のjについて, iの高さ以上のものが存在しなこと
    // つまり, 連続した高さの建物の場合には, 左から見たときには１色にしか見えないということ
    // N個の建物があり, N < 15なので, 全ての建物について 高さを増やすか増やさないかを考えて
    // しかし, 増やすか増やさないかの判断はどうやるか
    // 手前から順番に増やすとして, それが最安になるかどうかは不明
    // N = Kの場合, 全ての場合に前のより多くすればいいが,
    // そうでないケースについては異なる
    // とりあえず, 見えるようにする建物を先に選ぶ
    // 選んだ後に, 今現在最も高い高さの建物のサイズを記録しておき, そのサイズ+1まで延ばす
    // 延ばしているときに, 今, 何色見えているかを記録しておき, K色以上見えないときは除去する

    val cost = (0 until Math.pow(2, N).toInt).foldLeft(Long.MaxValue)((min, s) => {
      val (colors, _, cost) = (0 until N).foldLeft((0, 0, 0L))((state, b) => {
        val (colors, maxHeight, cost) = state
        if ((s & (1 << b)) == (1 << b)) {
          if (A(b) <= maxHeight) (colors + 1, maxHeight + 1, cost + (maxHeight + 1) - A(b))
          else (colors + 1, A(b), cost)
        } else {
          if (A(b) <= maxHeight) (colors, maxHeight, cost)
          else (colors + 1, A(b), cost)
        }
      })
      if (colors < K) min
      else min min cost
    })

    println(cost)
  }

}

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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll A[100005];

int main()
{
    int N;
    cin >> N;
    REP(i, N)
    {
        cin >> A[i];
    }
    int n = 0;
    ll p = 0;
    FOR(i, N, 1)
    {
        ll q = A[i] - A[i - 1];
        if (q > 0)
        {
            //! 増加
            if (p < 0)
            {
                n++;
                p = 0;
                continue;
            }
            p = q;
        }
        else if (q < 0)
        {
            //! 減少
            if (p > 0)
            {
                n++;
                p = 0;
                continue;
            }
            p = q;
        }
    }
    cout << n + 1 << endl;
    return 0;
}

Measured memory_bytes: 1024
import collections

N = int(input())
A = list(map(int, input().split()))

ct = collections.Counter(A)

ret = []
total = 0
for k,count in ct.items():
    if count > 1:
        total += count * (count-1) // 2

for i,v in enumerate(A):
    if ct[v] > 1:
        count = ct[v]
        adjust = (count-1) * (count-2) // 2 - (count-1) * count // 2
        val = total + adjust
    else:
        val = total
    print(val)


Measured memory_bytes: 89932