akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ // これを消す
#ifdef DEBUG_
#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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

    template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int mod = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);
const long double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899;
int dx[] = {0,0,-1,1};
int dy[] = {-1,1,0,0};

void solve(){
    int D;
    cin >> D;
    LL C[26] = {};
    REP(i,26) cin >> C[i];
    VVL S(D,VL(26));
    REP(i,D) REP(j,26) cin >> S[i][j];
    VI T(D);
    REP(i,D) {
        cin >> T[i];
        T[i]--;
    }

    // last days
    LL L[26] = {};

    LL score = 0;
    REP(day,D){
        score += S[day][T[day]];
        L[T[day]] = day+1;
        REP(i,26){
            score -= C[i] * (day+1 - L[i]);
        }

        cout << score << "\n";

    }

}


signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);

    solve();

}

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

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

    char cOld; cin >> cOld;
    char c;
    int combine = 0;

    for (int i=1; i<N; i++) {
        cin >> c;
        if (c == cOld) {
            combine++;
        }
        cOld = c;
    }
    int ans = N - combine;
    cout << ans << endl;
    return 0;
}



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

#define INF (1e9)
#define INF_LL (1e17)
#define YJ 1145141919810

using LL = long long;
using ULL = unsigned long long;

using namespace std;

#define MAX_N 50
#define MAX_M 50

int N, M;
int A[MAX_N], B[MAX_N];
int C[MAX_M], D[MAX_M];

int main()
{
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
  }

  for (int i = 0; i < M; i++) {
    cin >> C[i] >> D[i];
  }

  for (int i = 0; i < N; i++) {
    int len = 1145141919;
    int index = -1;
    for (int j = 0; j < M; j++) {
      int l = abs(A[i] - C[j]) + abs(B[i] - D[j]);
      if(len > l){
        len = l;
        index = j+1;
      }
    }
    cout << index << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int i,k,a,b;
    cin >> k >> a >> b;
    for(i = a;i <= b;i++)
    {
        if(i%k == 0)
            break;
    }
    if(i <= b) cout << "OK" << endl;
    else cout << "NG" << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
#define ll long long
#define PL pair<long long, long long>
#define P pair<int,int>
#define mk make_pair
#define en endl;
#define WHITE 0
#define BLACK 2
#define GRAY 1
#define RE return 0;
#define HERE cout<<"here"<<en
#define _out(value) cout<<"      "<<value<<en
#define out(value) cout<<value<<en

#define MAX 100005
int half_1[MAX],half_2[MAX];

int main(){
  int n,m;
  while(cin>>n>>m&&n&&m){
    int p[n];
    vector<ll> v;
    v.push_back(0);
    for(int i=0; i<n; i++){
      cin>>p[i];
      v.push_back(p[i]);
    }
    
    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++){
        if(p[i]+p[j]<=m){
          v.push_back(p[i]+p[j]);
        }
      }
    }
    
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()),v.end());
    
    ll  ans=0;
    for(int i=0; i<v.size(); i++){
      ll lb=lower_bound(v.begin(), v.end(), (ll)m-v[i])-v.begin()-1;
      if(v[i]+v[lb]<=m) ans=max(ans,v[i]+v[lb]);
    }
    
    out(ans);
  }
}



Measured memory_bytes: 18956
//Jai Bhole Ki
#include <bits/stdc++.h>
using namespace std;
#define fast static int fastline = []() { std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }();
#define ll long long
#define LL unsigned ll
#define pb push_back
#define pi pair<ll,ll>
#define debug(x) cout<<x<<"\n";
#define debug cout<<"debugged\n";
#define minval -2e9
#define maxval 2e9
long double PI =3.14159265358979323846;
 
const ll M=1e9+7;
const ll inf=1e18;
const ll ms=2e5+5;
fast;
ll ans,n,chk;
map<string,ll> mp;
void solve()
{
    cin>>n;
    for(int i=0;i<n;i++)
    {
        string a;
        cin>>a;
        chk=max(chk,++mp[a]);
    }
    for(auto it:mp)
    {
        if(chk==it.second)
            cout<<it.first<<endl;
    }
}
int main()
{
 // freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
    //int t;cin>>t;while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 23808
#include <stdio.h>
#include <math.h>
int main ()
{
    int  i;
    long long int n, out, s;
    scanf("%lld", &n);
    
    s = sqrt(n);
    for(i=s; i>0; i--){
        if(n%i==0){
            out = (n/i) + i - 2;
            printf("%lld", out);
            return 0;            
        }
    }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;
  cin >> a;
  cin >> b;

  if (a * b % 2 == 1) {
    cout << "Odd" << endl;
  }
  else cout << "Even" << endl;
  // ここにプログラムを追記
}

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

typedef long long int ll;
typedef vector<long long>lve;
typedef vector<pair<ll,ll> > lvp;

#define sp         ' '
#define endl       '\n'
#define F          first
#define S          second
#define pp         pop_back`
#define pb         push_back
#define mp         make_pair 
#define GCD(x,y)   __gcd(x,y)
#define PI         2*acos(0.0)
#define lb         lower_bound
#define bs         binary_search
#define all(x)     x.begin(),x.end()
#define LCM(x,y)   ((x*y)/__gcd(x,y))
#define btpc       __builtin_popcountll
#define spc(x)     cout<<fixed<<setprecision(x)

const   long long  cs=2e5+5;
const   long long  inf=1e18;
const   long long  mod=1e9+7;
void solve()
{
    int64_t t,n,m,a,b,c,d,e,i,j,k,x,y,cnt=0,cnt1=0;
    bool flag = false;   
    
    cin>>n;
    lve v(n);
    for(auto &ss:v) cin>>ss;
    lve v1{all(v)};
    sort(all(v1));
    reverse(all(v1));
    for(i=0;i<n;i++)
    {
        if(v[i]!=v1[0]) cout<<v1[0]<<endl;
        else cout<<v1[1]<<endl;
    }
    
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);    cout.tie(NULL);

    // freopen ("input.txt","r",stdin);
    // freopen ("output.txt","w",stdout);

    // int32_t tc;
    // cin>>tc;
    // while(tc--)
    solve();

    return 0;
}


Measured memory_bytes: 6304
#include <iostream>
#include <vector>

int main()
{
    int n;
    std::cin >> n;
    std::vector<int> l(n);
    for (int i = 0; i < n; i++) {
        std::cin >> l[i];
    }
    for (int i = n-1; i > 0; i--) {
        if (l[i-1] == l[i] + 1) {
            l[i-1]--;
        }
        else if (l[i-1] <= l[i]) {

        } else {
            std::cout << "No" << std::endl;
            return 0;
        }
    }
    std::cout << "Yes" << std::endl;
    return 0;
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vll = vector<ll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	for (auto &u : v) os << u << el;
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}

string S;
ll dp[1000005][2];
int main() {
	cin >> S;
	S = "0" + S;
	fill_n(*dp, 1000005 * 2, LLINF);

	dp[0][0] = 0;
	for (int i = 0; i < S.size(); i++) {
		ll val = S[i] - '0';
		//j = 0に対する処理
		chmin(dp[i+1][0], dp[i][0] + val);
		for (ll k = val + 1; k <= 9; k++) {
			chmin(dp[i+1][1], dp[i][0] + k + (k - val));
		}
		//j = 1に対する処理
		for (ll k = 0; k <= 9; k++) {
			if (k < val) chmin(dp[i+1][1], dp[i][1] + k + (9 + k - val) % 10);
			else if (k > val) chmin(dp[i+1][1], dp[i][1] + k + (10 + k - val) % 10);
			else chmin(dp[i+1][0], dp[i][1] + k);
		}
	}
	cout << min(dp[S.size()][0], dp[S.size()][1]) << endl;
	return (0);
}

Measured memory_bytes: 16944
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
use std::collections::BinaryHeap;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

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

struct UnionFind{
    v: Vec<usize>
}

impl UnionFind{
    fn new(n: usize) -> UnionFind{
        let mut v: Vec<usize> = Vec::new();
        for i in 0..n{
         v.push(i);
        }
        UnionFind{v:v}
    }

    fn find(&mut self, i: usize) -> usize{
        if self.v[i] == i{
            i
        }else{
            let ni = self.v[i];
            self.v[i] = self.find(ni);
            self.v[i]
        }
    }

    fn union(&mut self, i: usize, j: usize){
        let root_i = self.find(i);
        let root_j = self.find(j);
        self.v[root_i] = root_j;
    }

}

//00:27
fn main(){
    let n: usize = read_as_vec()[0];
    //                  i,     x,      y
    let mut towns: Vec<(usize, i64, i64)> = vec![];
    for i in 0..n{
        let line = read_as_vec::<i64>();
        towns.push((i, line[0], line[1]));
    }

    let mut y_towns = towns.clone().iter().map(|x| (x.0, x.2)).collect::<Vec<(usize, i64)>>();
    y_towns.sort_by_key(|x| x.1);
    //                    diffs,  town,   town
    let mut y_diffs: Vec<(i64, usize, usize)> = vec![];

    for i in 0..y_towns.len()-1{
        y_diffs.push((-(y_towns[i+1].1 - y_towns[i].1), y_towns[i].0, y_towns[i+1].0));
    }
    y_diffs.sort();


    let mut x_towns = towns.clone().iter().map(|x| (x.0, x.1)).collect::<Vec<(usize, i64)>>();
    x_towns.sort_by_key(|x| x.1);
    let mut x_diffs: Vec<(i64, usize, usize)> = vec![];
    for i in 0..x_towns.len()-1{
        x_diffs.push((-(x_towns[i+1].1 - x_towns[i].1), x_towns[i].0, x_towns[i+1].0));
    }

    x_diffs.sort();
    let mut heap = BinaryHeap::new();

    for elem in y_diffs{
        heap.push(elem);
    }
    for elem in x_diffs{
        heap.push(elem);
    }

    let mut uf = UnionFind::new(n);
    let mut cost = 0;
    while let Some(x) = heap.pop(){
        let (diff, town_i, town_j) = (-x.0, x.1, x.2);
        if uf.find(town_i) == uf.find(town_j){
            continue;
        }
        cost += diff;
        uf.union(town_i, town_j);
    }

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


Measured memory_bytes: 25764
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int input_number = Integer.parseInt(scan.next());
    int h = (input_number / 3600);
    int m = (input_number / 60 % 60);
    int s = (input_number % 60);
    System.out.println(h + ":" + m + ":" + s);
	}
}



Measured memory_bytes: 26056
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
    Scanner reader=new Scanner(System.in);
  /*  String s1 =reader.next();
    String s2 =reader.next();
    String s3 =reader.next();
    String s= s1.substring(0,1)+s2.substring(0,1)+s3.substring(0,1);
    System.out.print(s.toUpperCase());
	}*/
	int A=reader.nextInt();
	int B=reader.nextInt();
	if(A==B) {
		System.out.println("Draw");
	}
	
	else if(A<B && A!=1) {
		System.out.println("Bob");
	}
	else if (B==1){
		System.out.println("Bob");
		
	}
	else {
		System.out.println("Alice");
	}
	}									
	

}


Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;

int main() {
	int N, A, B; cin >> N >> A >> B;
	cout << min(A, B) << ' ';
	if(A+B>N) cout << A+B-N << endl;
	else cout << 0 << endl;
	return 0;
}


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

int main()
{
   int x,y,i,z;
  scanf("%d%d%d",&x,&y,&z);
   for(i=0;;i++)
   {
       if(i*y+(i+1)*z-x>0)
        break;
   }
   printf("%d\n",i-1);
             return 0;
}


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

int main() {
  int a,b;
  cin >> a >> b;

  vector<int> c(a);
  for (int i = 0; i < a; i++) {
    cin >> c.at(i);
  }

  sort(c.begin(), c.end());

  int g = 0;

  for (int i = 0; i < b; i++) {
    g += c.at(i);
  }

  cout << g << endl;

}

Measured memory_bytes: 3624
#include<stdio.h>
int main()
{
	int n,i,x=0;
	char s[100000];
	scanf("%d %s",&n,s);
	for(i=0;i<n;i++){
		if(s[i]!=s[i+1]){
			x++;
		}
	}
	printf("%d\n",x);
	return 0;
}


Measured memory_bytes: 1828
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
 
using namespace std;
typedef long long ll;
 
int main(){
  ll N,K;
  cin >> N >> K;
  vector<ll> A(N);
  vector<ll> F(N);

  for(int i=0;i<N;i++) cin >> A[i];
  for(int i=0;i<N;i++) cin >> F[i];

  sort(A.begin(),A.end());
  sort(F.begin(),F.end(),greater<ll>());

  ll l=-1,r=1000000000100;

  while(l+1!=r){
    ll v=(l+r)/2;
    ll k=0;
    for(int i=0;i<N;i++){
      k+=max((ll)0,A[i]-v/F[i]);
    }
    //cout << v << " " << k << endl;
    if(k<=K){
      r=v;
    }else{
      l=v;
    }
  }

  cout << r << endl;

  return 0;
}


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

#ifdef DEBUG
#define PRINT(x)\
    cout << "func " << __func__ << ": line " << __LINE__ << ": " << #x << " = " << (x) << endl;
#define PRINTA(a, begin, end)\
    cout << "func " << __func__ << ": line " << __LINE__ << ": " << #a << "[" << (begin) << ", " << (end) << ")" << endl;\
    for (int i = (begin); i < (end); ++i) {\
        cout << #a << "[" << i << "] = " << (a)[i] << endl;\
    }
#else
#define PRINT(x)
#define PRINTA(a, begin, end)
#endif

#define MAX_R 100005

using namespace std;

vector<int> primes;
bool isPrime[MAX_R];
int n2017like[MAX_R]; // n2017like[i] = #{ n | n < i, n: 2017-like }

void init()
{
    primes.push_back(2);
    isPrime[2] = true;
    for (int i = 3; i < MAX_R; i += 2) {
        bool flag = true;
        for (int j = 0; primes[j] * primes[j] <= i; j++) {
            if (i % primes[j] == 0) {
                flag = false;
                break;
            }
        }
        if (flag) {
            primes.push_back(i);
            isPrime[i] = true;
        }
    }
}

bool is2017like(int n)
{
    if (n <= 2 || n % 2 == 0) {
        return false;
    }
    if (isPrime[n] && isPrime[(n+1)/2]) {
        return true;
    }
    return false;
}

int main(void)
{
    init();
    for (int i = 1; i < MAX_R; i++) {
        n2017like[i] = n2017like[i - 1] + is2017like(i - 1);
    }
    int Q;
    cin >> Q;
    while (Q--) {
        int l, r;
        cin >> l >> r;
        cout << n2017like[r + 1] - n2017like[l] << endl;
    }
    return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

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

    UnionFind tree(N);

    for(int i = 0; i < M; i++) {
        int x, y;
        cin >> x >> y;
        tree.unite(x-1, y-1); // x-1の木とy-1の木を併合する
    }

    int cnt = 0;
    for(int i = 0; i < N; i++) {
        if (tree.same(i, P[i]-1)) { //iとP[i]-1が同じ木に属するなら，カウンタに1追加
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N, fx = 0, digit = 0;
    cin >> N;
    int tmp = N;
    while(tmp != 0){
        fx += tmp % 10;
        tmp /= 10;
    }
    if(N % fx == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0; 
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

vector<vector<int>> dist(30, vector<int>(30, 1e9));

void warshall_floyd(int n){
    for(int k=0; k<n; k++){
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
}

int main(){
    int n, m; cin>>n>>m;
    for(int i=0; i<n; i++){
        dist[i][i] = 0;
    }

    char c1, c2, c3;
    for(int i=0; i<m; i++){
        int a, b, c, d;
        cin>>a>>c1>>b>>c2>>c>>c3>>d;
        a--;
        b--;
        dist[a][b] = c;
        dist[b][a] = d;
    }

    int s, g, v, p; cin>>s>>c1>>g>>c2>>v>>c3>>p;
    s--, g--;
    warshall_floyd(n);

    cout << v - p - dist[s][g] - dist[g][s] << endl;
}


Measured memory_bytes: 3088
#!/usr/bin/python
# -*- coding: UTF-8 -*-

import sys


def calc_p(a, b, c):
    u = {a, b, c}
    if len(u) == 3:
        return 6
    if len(u) == 2:
        return 3
    if len(u) == 1:
        return 1
    else:
        raise


def std_in():
    return sys.stdin.readline().strip()


def _main():
    N = int(std_in())
    fn = [0] * (N + 1)
    if N == 1:
        x_max = 1
    else:
        x_max = int(pow(N, 0.5)) - 1

    n2 = [i**2 for i in range(1, x_max + 1)]

    ij = [[0 for _ in range(1, x_max + 1)] for _ in range(1, x_max + 1)]
    for i in range(x_max):
        for j in range(i, x_max):
            ij[i][j] = (i+1) * (j+1)

    for x in range(1, x_max + 1):
        y_min = x
        x2 = n2[x-1]
        for y in range(y_min, x_max + 1):
            z_min = y
            y2 = n2[y-1]
            xy = ij[x-1][y-1]
            tmp_n = x2 + xy + y2
            if tmp_n > N:
                break
            for z in range(z_min, x_max + 1):
                z2 = n2[z-1]
                yz = ij[y-1][z-1]
                zx = ij[x-1][z-1]
                n = tmp_n + z2 + yz + zx
                if n > N:
                    break
                fn[n] += calc_p(x, y, z)

    for i in range(1, N + 1):
        print(fn[i])


if __name__ == "__main__":
    _main()


Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF (((ll)1<<31)-1)
#define eps LDBL_EPSILON
#define moder (1000000007)
#define pie 3.141592653589793238462643383279
#define P std::pair<int,int>
#define prique priority_queue
#define ggr getchar();getchar();return 0;
using namespace std;
int n,m;
char c;
signed main(){
    while(true){
        cin>>n;
        if(!n)break;
        map<char,char> mp;
        rep(i,n){
            char a,b;
            cin>>a>>b;
            mp[a]=b;
        }
        cin>>m;
        rep(i,m){
            cin>>c;
            if(mp[c])cout<<mp[c];
            else cout<<c;
        }
        cout<<endl;
    }
    ggr;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)    for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define rrep(i, n)   for(int i=(n-1); i>=0; --i)
#define all(v)       v.begin(), v.end()
#define rall(v)      v.rbegin(), v.rend()
#define int          long long
template<typename T>
using vv  =  vector<vector<T>>;
using vi  = vector<int>;
using vvi = vector<vector<int>>;
using P   = pair<int, int>;
using ll  = long long;
constexpr ll INF = 1LL << 60;

bool is_prime(int x) {
    if(x < 2) return false;
    for(int i = 2; i * i <= x; ++i) {
        if(x % i == 0) return false;
    }
    return true;
}

class Prime{
public:
    int n;
    vector<int> factor, primes;    
    // エラストテネスの篩
    Prime(int n=100000) : n(n), factor(n+1){
        factor[0] = factor[1] = -1;
        for(int i=2; i <= n; ++i){
            if(factor[i]){
                continue;
            }
            primes.push_back(i);
            factor[i] = i;
            for(int j = i*i; j <= n; j += i){
                if(!factor[j]){
                    factor[j] = i;
                }
            }
        }
    }
    // 素数判定
    bool is_prime(int x){
        return factor[x] == x;
    }
    // 約数列挙
    vector<int> factorList(int x){
        vector<int> ret;
        while(x != 1){
            ret.push_back(factor[x]);
            x /= factor[x];
        }
        return ret;
    }
    // 素因数分解
    vector<P> factorize(int x){
        vector<int> fl = factorList(x);
        if(fl.size() == 0){
            return {};
        }
        vector<P> res(1, P(fl[0], 0));
        for (int p : fl) {
            if (res.back().first == p) {
                res.back().second++;
            }
            else {
                res.emplace_back(p, 1);
            }
        }
        return res;
    }
};

signed main(){

    int n;
    cin >> n;

    if(is_prime(n)){
        cout << 1 << endl;
        return 0;
    }
    map<int, int> mp;
    Prime prime(1000000);
    if(n > 1000000){
        rep(i, 1000000){
            if(prime.is_prime(i) && n % i == 0){
                mp[i] = 1;
                n /= i;
                if(n < 1000000){
                    break;
                }
            }
        }
    }

    for(int i = 2; i <= n; ++i){
        if(i >= 1000000){
            cout << mp.size() + 1 << endl;
            return 0;
        }
        if(!prime.is_prime(i)){
            continue;
        }
        for(int j = i; j <= n; j*=i){
            if(n % j == 0){
               //cout << j << endl;
                if(mp[j] == 1){
                    continue;
                }
                mp[j] = 1;
                n /= j;
            }
        }
    }
    cout << mp.size() << endl;

    return 0;
}


Measured memory_bytes: 12092
#include <iostream>
#include <algorithm>
using namespace std;
const int MAXN=101;
const int MAXW=10001;

int main()
{
    int N,W,v[MAXN],w[MAXN],T[MAXN][MAXW];
    cin>>N>>W;
    for(int i=1;i<=N;i++)
        cin>>v[i]>>w[i];
    v[0]=w[0]=0;
    for(int i=0;i<=N;i++)
        for(int j=0;j<=W;j++)
            T[i][j]=0;
    for(int i=1;i<=N;i++)
        for(int j=1;j<=W;j++)
        {
            if(j>=w[i])
                T[i][j]=max(T[i-1][j],T[i-1][j-w[i]]+v[i]);
            else
                T[i][j]=T[i-1][j];
        }
        
            
    cout<<T[N][W]<<endl;
    return 0;
}



Measured memory_bytes: 7064
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,j,k,l,m,n,sum=0;
    string s;
    cin>>n;
    cin>>s;
  for(i=0;i<n-1;i++)
  {
      if(s[i]==s[i+1])
        s[i]='0';
  }
   for(i=0;i<n;i++)
  {
     if(s[i]!='0')
        sum++;

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


}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define print(v) cout<<v<<endl;
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;

ll H,W;

vector<vector<char>> A(1000, vector<char>(1000));
vector<vector<ll>> dp(1000, vector<ll>(1000, -1));

int main(){
    cin >> H;
    cin >> W;
    for(ll i=0;i<H;i++)
        for(ll j=0;j<W;j++)cin>>A[i][j];
    
    queue<P> qu;
    for(ll i=0;i<H;i++)
        for(ll j=0;j<W;j++){
            if(A[i][j]=='#')qu.emplace(P(i,j));
        }
    qu.emplace(P(INF,INF));
    ll count=0;
    while(qu.size()>1){
        P x=qu.front();qu.pop();
        ll i=x.first; ll j=x.second;
        if(x==P(INF,INF)){
            count++;qu.emplace(P(INF,INF));continue;
        }
        
        if(i>0&&A[i-1][j]=='.'){qu.emplace(P(i-1,j));A[i-1][j]='#';}
        if(j>0&&A[i][j-1]=='.'){qu.emplace(P(i,j-1));A[i][j-1]='#';}
        if(i<H-1&&A[i+1][j]=='.'){qu.emplace(P(i+1,j));A[i+1][j]='#';}
        if(j<W-1&&A[i][j+1]=='.'){qu.emplace(P(i,j+1));A[i][j+1]='#';}

    }
    print(count);


    return 0;
}

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

class MyClass
{
    public static int count = 0;
    public static void Merge(ref int[] A, int left, int mid, int right)
    {
        var n1 = mid - left;
        var n2 = right - mid;
        var L = new int[n1 + 1];
        var R = new int[n2 + 1];
        for (int k = 0; k < n1; k++)
        {
            L[k] = A[left + k];
        }
        for (int k = 0; k < n2; k++)
        {
            R[k] = A[mid + k];
        }
        L[n1] = int.MaxValue;
        R[n2] = int.MaxValue;
        var i = 0;
        var j = 0;
        for (int k = left; k < right; k++)
        {
            count++;
            if (L[i] <= R[j])
            {
                A[k] = L[i];
                i++;
            }
            else
            {
                A[k] = R[j];
                j++;
            }
        }
    }
    public static void MergeSort(ref int[] A, int left, int right)
    {
        if (left + 1 < right)
        {
            var mid = (left + right) / 2;
            MergeSort(ref A, left, mid);
            MergeSort(ref A, mid, right);
            Merge(ref A, left, mid, right);
        }
    }

    public static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var S = Console.ReadLine().Split().Select(int.Parse).ToArray();
        MergeSort(ref S, 0, n);
        Console.WriteLine(string.Join(" ", S));
        Console.WriteLine(count);
    }
}


Measured memory_bytes: 84724
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)

struct INIT{
    INIT(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(0);
        cout << fixed << setprecision(13);
    }
}INIT;

const LL MOD = 1000000007;
LL combi(LL N_, LL C_) {
	const int NUM_ = 1010101;
	static LL fact[NUM_ + 1], factr[NUM_ + 1], inv[NUM_ + 1];
	if (fact[0] == 0) {
		inv[1] = fact[0] = factr[0] = 1;
		for (int i = 2; i <= NUM_; ++i) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
		for (int i = 1; i <= NUM_; ++i) fact[i] = fact[i - 1] * i%MOD, factr[i] = factr[i - 1] * inv[i] % MOD;
	}
	if (C_<0 || C_>N_) return 0;
	return factr[C_] * fact[N_] % MOD*factr[N_ - C_] % MOD;
}

LL hcomb(int P_, int Q_) { return (P_ == 0 && Q_ == 0) ? 1 : combi(P_ + Q_ - 1, Q_); }

LL modpow(LL a, LL n = MOD - 2) {
	LL r = 1;
	while (n) r = r*((n % 2) ? a : 1) % MOD, a = a*a%MOD, n >>= 1;
	return r;
}

int n, k;

int main(){
    cin >> n >> k;
    for(int i = 1;i <= k;i++){
        cout << combi(n - k + 1, i) * combi(k - 1, i - 1) % MOD << endl;
    }
}

Measured memory_bytes: 23936
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int N, ans = 0, max = 0;;
	int H[150];
	H[0] = 0;
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> H[i];
	}

	for (int i = 1; i <= N; i++) {
		/*if (H[i - 1] <= H[i]) {
			ans++;
			cout << H[i - 1] << H[i] << endl;
		}*/
		max = 0;
		for (int j = 0; j <= i; j++) {
			if (max <= H[j]) {
				max = H[j];
			}
		}
		if (max <= H[i]) {
			ans++;
		}
	}

	cout << ans << endl;
}


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

const int N = 200005;
bitset < N > vet, tem;

int main(){
	int n;
	scanf("%d", &n);
	int x;
	for (int i=1; i<=n; i++){
		scanf("%d", &x);
		vet[i] = x;
		tem[i] = 0;
	}
	vector < int > ans;
	for (int i=n; i>0; i--){
		int qtd = 0;
		for (int j=i+i; j<=n; j+=i){
			qtd += tem[j];
		}
		if(qtd%2 != vet[i]){
			tem[i] = 1;
			ans.push_back(i);
		}
	}
	printf("%d", (int)ans.size());
	for (int i=0; i<ans.size(); i++){
		if(i) printf(" ");
		else printf("\n");
		printf("%d", ans[i]);
	}
	puts("");
	return 0;
}


Measured memory_bytes: 1784
#include<bits/stdc++.h>
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define ll long long

template<class T> ostream& operator<<(ostream &os,vector<T> V){
	os<<"[ ";for(auto v:V)os<<v<<" ";return os<<" ]";
}
template<class L,class R> ostream& operator<<(ostream &os,pair<L,R> P){
	return os<<"("<<P.first<<","<<P.second<<")";
}
ll mxm(){return LLONG_MIN;}
template<typename... Args>
ll mxm(ll a,Args... args){return max(a,mxm(args...));}
ll mnm(){return LLONG_MAX;}
template<typename... Args>
ll mnm(ll a,Args... args){return min(a,mnm(args...));}

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__,__VA_ARGS__)
template<typename Arg1>
void __f(const char* name,Arg1&& arg1){
	cout<<name<<" : "<<arg1<<endl;
}
template<typename Arg1,typename... Args>
void __f(const char* names,Arg1&& arg1,Args&&... args){
		const char* comma=strchr(names+1,',');cout.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1,args...);
}
#else
#define trace(...) 1
#endif

#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define ii pair<int,int>
#define vi vector<int>
#define vpll vector<pll>
#define vii vector<ii>
#define vvi vector<vi>
#define vvll vector<vll>
#define vvpll vector<vpll>
#define vvii vector<vii>
#define vld vector<ld>
#define vvld vector<vld>
#define I insert
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(),x.end()
#define endl "\n"
#define siz(a)	((int)(a).size())

const int mod=1e9+7;
inline int add(int a,int b){a+=b;if(a>=mod)a-=mod;return a;}
inline int sub(int a,int b){a-=b;if(a<0)a+=mod;return a;}
inline int mul(int a,int b){return (a*1ll*b)%mod;}
inline int power(int a,int b){int rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}
inline int inv(int a){return power(a,mod-2);}

const int N=1e5+5;

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<<setprecision(25);
	int n;cin>>n;
	vi v(n);
	for(int i=0;i<n;i++)cin>>v[i];
	for(int i=0;i<n;i++){
		bool b=0;
		if(v[i]==i+1)continue;
		for(int j=i+1;j<n;j++){
			if(v[j]==i+1){
				swap(v[i],v[j]);
				b=1;break;
			}
		}
		if(b)break;
	}
	bool b=1;
	for(int i=1;i<n;i++)
		if(v[i]<v[i-1])
			b=0;
	if(b)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int mx2[] = {1,0};
int my2[] = {0,1};

class EThisMessageWillSelfDestructIn5s {
public:
	void solve(istream& in, ostream& out) {
        int n;
        in >> n;
        vector<ll> a(n),l(n),r(n);
        map<ll,ll> mp;
        rep(i, n) {
            ll a;
            in >> a;
            l[i] = i + a;
            mp[l[i]]++;
            r[i] = i - a;
        }
        ll ans = 0;
        rep(i, n) {
            ans += mp[r[i]];
        }
        out << ans << endl;
    }
};

int main() {
	EThisMessageWillSelfDestructIn5s solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

Measured memory_bytes: 30500
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

const int N_MAX = 100;
const int M = 1024;
const int L = 10;
int v[N_MAX];
int P[N_MAX][M];
map<int,int> bc;

int bitcount(int x){
  if(bc.count(x)) return bc[x];
  int y = x;
  int count = 0;
  while(y!=0){
    count += y&1;
    y>>=1;
  }
  return bc[x] = count;
}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  rep(i,N)rep(j,L){
    int x;cin >> x;
    v[i]<<=1;
    v[i]+=x;
  }
  rep(i,N)rep(j,L+1) cin >> P[i][j];

  int maximum = MIN_I;
  repp(x,1,M){
    int profit = 0;
    rep(i,N){
      int bc = bitcount(v[i] & x);
      profit += P[i][bc];
    }
    maximum = max(maximum,profit);
  }
  cout << maximum << endl;
  return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <list>
#include <set>
using namespace  std;

#define int long long int

constexpr int INF = std::numeric_limits<int>::max();

vector<bool> memo(1000001, false);

int f(int a) {
    if (a % 2 == 0) {
        return a / 2;
    } else {
        return 3 * a + 1;
    }
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int s; cin >> s;
    memo[s] = true;

    int m = 2;
    while (true) {
        s = f(s);
        if (memo[s]) {
            break;
        }
        memo[s] = true;
        m++;
    }

    cout << m << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int row,colum;
    cin>>row>>colum;
    vector<char>rows;
    vector<char>columns;
    char field[row][colum];
    for(int i=0;i<row;i++){
        bool found=false;
        for(int j=0;j<colum;j++){
            char m;
            cin>>m;
            field[i][j]=m;
            if(m=='#'){
                found=true;
            }
        }
        if(!found){
            rows.push_back(i);
        }
    }
    for(int i=0;i<colum;i++){
        bool found=false;
        for(int j=0;j<row;j++){
            if(field[j][i]=='#'){
                found=true;
            }
        }
        if(!found){
            columns.push_back(i);
        }
    }
    sort(rows.begin(),rows.end());
    sort(columns.begin(),columns.end());
    for(int i=0;i<row;i++){
        bool dont=true;
        for(int j=0;j<colum;j++){
            if(!binary_search(rows.begin(),rows.end(),i)){
              if(!binary_search(columns.begin(),columns.end(),j)){
                cout<<field[i][j];
                dont=false;
              }
            }
        }
        if(!dont){
            cout<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<'\n';}}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}

int main(){
    ll n;cin>>n;
    vi v(n);
    vi s(n);
    rep(i,n){
        cin>>v[i];
        v[i]--;
        s[v[i]]++;
    }
    ll ans=0;
    rep(i,n)ans+=s[i]*(s[i]-1)/2;
    rep(i,n){
        out(ans-s[v[i]]*(s[v[i]]-1)/2+(s[v[i]]-1)*(s[v[i]]-2)/2);
    }
}

Measured memory_bytes: 5760
M = 10**9 + 7
L = 200000

Fm = {}
inverseFm = {}
x = 1
for i in range(L):
    Fm[i] = x
    x = x * (i + 1) % M

def inverseFm(x, cache={}):
    if x in cache:
        return cache[x]
    result = pow(Fm[x], M - 2, M)
    cache[x] = result
    return result

def C(n, r):
    result = Fm[n] * inverseFm(r) * inverseFm(n - r) % M
    return result

def solve(H, W, A, B):
    result = 0
    for i in range(B + 1, W + 1):
        result += C(i + H - A - 1 - 1, i - 1) * C(W - i + A - 1, W - i)
    return result % M

H, W, A, B = [int(_) for _ in input().split()]

print(solve(H, W, A, B))


Measured memory_bytes: 46588
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
ll a[100010];

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

  ll n;
  cin >> n;
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  if (sum % ((1 + n) * n / 2) != 0) {
    cout << "NO\n";
    return 0;
  }
  ll round = sum / ((1 + n) * n / 2);
  sum = 0;
  for (int i = 0; i < n; i++) {
    if (a[(i+1)%n] - a[i] > round || (round - a[(i+1) % n] + a[i]) % n != 0) {
      cout << "NO\n";
      return 0;
    }
    sum += (round - a[(i + 1)%n] + a[i]) / n;
  }
  cout << (sum == round? "YES" : "NO") << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
const int MAX = 100000;
typedef long long llong;
llong T[MAX];

int n,k;



int check(llong P)
{
	int i  =0 ;
	for(int  j = 0; j<k;j++)
	{
		llong s= 0;
		while(s+T[i]<=P)
		{
			s+=T[i];
			i++;
			if(i==n)return n;
		}
	}
	return i;
}

int solve()
{
	llong left = 0;
	llong right = 100000*100000;
	llong mid;
	while(right- left>1)
	{
		mid = (left+right)/2;
		if(check(mid)>=n) right = mid;
		else left = mid;
	}
	return right;
}


int main()
{
	cin >> n >> k;
	for(int i =0; i<n;i++)
		cin >> T[i];
	llong ans = solve();
	cout <<ans<<endl;
	
	
} 

Measured memory_bytes: 3884
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();
    int K = sc.nextInt();

    if((B - A) / 2.0 >= K){
      for(int i = 0; i < K; i++){
        System.out.println(A + i);
      }
      for(int i = 0; i < K; i++){
        System.out.println(B - K + i + 1);
      }
    }else{
      for(int i = 0; i < B - A + 1; i++){
        System.out.println(A + i);
      }
    }
  }
}


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

int main() {
    int N;
    scanf("%d", &N);

    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
    }
    bool f = false;
    int count = 0;

    while(!f) {
        for (int i = 0; i < N; i++) {
            if (A.at(i) % 2 == 0 & f == false) {
               A.at(i) = A.at(i) / 2;
                if (i == N - 1) {
                    count++;
                }
            } else {
                f = true;
                break;
            }
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
#define dup(x,y) (((x)+(y)-1)/(y))
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const int INTMAX = 2147483647;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

struct UnionFind {
    vector<int> d;
    UnionFind(int n): d(n,-1) {}
    int root(int x) {
        if (d[x] < 0) return x;
        return d[x] = root(d[x]);
    }
    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (d[x] > d[y]) swap(x,y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) { return root(x) == root(y);}
    int size(int x) { return -d[root(x)];}
};

int main(){
    int n,m;cin >> n >> m;
    UnionFind uf(n);
    rep(i,m){
        int a,b,c;cin >> a >> b >> c;
        --a;--b;
        uf.unite(a,b);
    }
    map<int,int> mp;
    rep(i,n) mp[uf.root(i)]++;
    cout << mp.size() << endl;
}

Measured memory_bytes: 5376
from itertools import permutations
N = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
li = [i+1 for i in range(N)]
for i, v in enumerate(permutations(li, N)):
    if v == p: a = i
    if v == q: b = i
print(abs(a-b))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int main() {
    init();

    int n;
    cin >> n;
    VI d(13, 0);
    int in;
    FOR(i, 0, n) {
        cin >> in;
        d[in]++;
    }
    d[0]++;

    int ans = 0;
    FOR(i, 0, 1 << 11) {
        VI p;
        FOR(j, 0, d[0])p.push_back(0);
        FOR(j, 0, 11)if (d[j + 1]) {
            if (d[j + 1] == 1) {
                if (i & (1 << j))p.push_back(j + 1);
                else p.push_back(23 - j);
            }
            else {
                p.push_back(j + 1);
                FOR(k, 1, d[j + 1])p.push_back(23 - j);
            }
        }
        FOR(j, 0, d[12])p.push_back(12);

        SORT(p);
        int Min = INF, size = p.size();
        FOR(j, 0, size) {
            if (p[j] && !p[(j + 1) % size])chmin(Min, abs(p[j] - 24)); 
            else chmin(Min, abs(p[j] - p[(j + 1) % size]));
        }
        chmax(ans, Min);
        //FOR(j, 0, size)cout << p[j] << (j == size - 1 ? "\n" : " ");
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256