akhauriyash/Code-Regression huggingface dataset:
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    n, m, k = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    total = 0
    a_idx = 0 # A[a_idx] は含まれない
    while a_idx < n and total + A[a_idx] <= k:
        total += A[a_idx]
        a_idx += 1
    b_idx = 0
    while b_idx < m and total + B[b_idx] <= k:
        total += B[b_idx]
        b_idx += 1

    ans = a_idx + b_idx
    while a_idx - 1 >= 0:
        a_idx -= 1
        total -= A[a_idx]
        while b_idx < m and total + B[b_idx] <= k:
            total += B[b_idx]
            b_idx += 1
        ans = max(ans, a_idx + b_idx)

    print(ans)
resolve()

Measured memory_bytes: 110920
N = int(input())
*A, = map(int, input().split())

Asum = [a for a in A]
for i in range(N-1, -1, -1):
    Asum[i] += Asum[i+1]

ans = 0
v = 1  # 子になれる頂点数
for i in range(N+1):
    if v < A[i]:
        ans = -1
        break

    ans += v
    p = v-A[i]
    if i < N:
        if p > Asum[i+1]:
            ans = -1
            break
        v = min(Asum[i+1], 2*p)

print(ans)


Measured memory_bytes: 86588
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

bool palim(string s){
  int n = s.size();
  bool res = true;
  REP(i, (n - 1) / 2 + 1){
    if(s[i] == s[n - 1 - i])continue;
    res = false;
  }
  return res;
}

int main(){
  string s;
  cin>>s;
  int n = s.size();
  int m = (n - 1) / 2;
  bool ans = palim(s);
  if(!ans){
    cout<<"No"<<endl;
    return 0;
  }
  string t = s.substr(0, (n - 1) / 2);
  string r = s.substr((n + 1) / 2, (n - 1) / 2);
  ans = palim(t);
  if(!ans){
    cout<<"No"<<endl;
    return 0;
  }
  ans = palim(r);
  if(!ans){
    cout<<"No"<<endl;
    return 0;
  }
  cout<<"Yes"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int a, b, c, tmp;
	scanf("%d %d %d", &a, &b, &c);
	if(a>b){tmp = b; b=a; a = tmp;};
	if(b>c){tmp = c; c=b; b = tmp;};
	if(a>b){tmp = b; b=a; a = tmp;};
	printf("%d %d %d\n", a, b, c);
	return 0;
}

Measured memory_bytes: 596
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

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

		int n = Integer.parseInt(br.readLine());

		if (n % 2 == 0)
			System.out.println(n / 2 - 1);
		else
			System.out.println(n / 2);
	}
}


Measured memory_bytes: 21204
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System;

public class P
{
    public List<int> to { get; set; }
    public int d { get; set; }
    public int from { get; set; }
}

public class P2
{
    public int from { get; set; }
    public int to { get; set; }
}

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var m = int.Parse(line[1]);
        var ps = new P[n];
        for (int i = 0; i < n; i++) ps[i] = new P { to = new List<int>(), d = -1 };
        for (int i = 0; i < m; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
            var a = int.Parse(line[0]) - 1;
            var b = int.Parse(line[1]) - 1;
            ps[a].to.Add(b);
            ps[b].to.Add(a);
        }
        goBfs(n, m, ps);
        getAns(n, ps);
    }
    static void getAns(int n, P[] ps)
    {
        var sb = new StringBuilder();
        Console.WriteLine("Yes");
        for (int i = 1; i < n; i++) sb.Append(ps[i].from.ToString() + "\n");
        Console.Write(sb);
    }
    static void goBfs(int n, int m, P[] ps)
    {
        var q = new Queue<P2>();
        ps[0].d = 0;
        foreach (var x in ps[0].to)
            q.Enqueue(new P2 { from = 0, to = x });
        while (q.Count() > 0)
        {
            var w = q.Dequeue();
            if (ps[w.to].d == -1)
            {
                ps[w.to].d = ps[w.from].d + 1;
                ps[w.to].from = w.from + 1;
                foreach (var x in ps[w.to].to)
                    if (ps[x].d == -1) { q.Enqueue(new P2 { from = w.to, to = x }); }
            }
        }
    }
}



Measured memory_bytes: 57488
#include<cstdio>

int main(){
	int K, N;
	scanf("%d %d", &K, &N);
	int A[N];
	for (int i = 0; i < N; ++i) scanf("%d", A + i);
	{
		/* code */
	}
	int max = K + A[0] - A[N-1];
	for (int i = 1; i < N; ++i){
		if(A[i] - A[i-1] > max) max = A[i] - A[i-1];
	}
	printf("%d\n", K - max);
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
 
int main () {
  
  string S;
  cin >> S;

  int a = 0, b = 0;

  for (int i = 0; i < S.length(); i++) {
      if (i % 2 == 0) {
          if (S[i] != '0') {
              a++;
          }
      } else {
          if (S[i] != '1') {
              a++;
          }
      }
  }

  for (int i = 0; i < S.length(); i++) {
      if (i % 2 == 0) {
          if (S[i] != '1') {
              b++;
          }
      } else {
          if (S[i] != '0') {
              b++;
          }
      }
  }

  cout << min(a, b) << endl;
  
}

Measured memory_bytes: 512
s = input()
x, y = map(int, input().split())

# Tで区切り、各Tの前にFが何文字あるか数える
steps = []
cnt = 0
for i in range(len(s)):
    if s[i] == "F":
        cnt += 1
    elif s[i] == "T":
        steps.append(cnt)
        cnt = 0
# 最後のブロックについて
if cnt > 0:
    steps.append(cnt)
AX = steps[0::2]
AY = steps[1::2]

# X軸方向の最大値
max_X = sum(AX)
# dpX[i][j] = X軸方向の移動をi回行って、jに到達できるか
# j = 0, 1, ..., 2*max_X だが、実際のX座標は -max_X, ..., 0, ..., max_X
# 原点(x=0)は、j = max_Xに相当する
dpX = [[0 for _ in range(2 * max_X + 1)] for _ in range(len(AX) + 1)]
dpX[0][max_X] = 1
# 最初に右へ移動する場合
if s[0] == "F":
    dpX[1][max_X + AX[0]] = 1
    for i in range(1, len(AX)):
        for j in range(2 * max_X + 1):
            if dpX[i][j] == 1:
                # +X方向に移動
                if j + AX[i] <= 2 * max_X:
                    dpX[i + 1][j + AX[i]] = 1
                # -X方向に移動
                if 0 <= j - AX[i]:
                    dpX[i + 1][j - AX[i]] = 1
# 最初に回転する場合
else:
    for i in range(len(AX)):
        for j in range(2 * max_X + 1):
            if dpX[i][j] == 1:
                # +X方向に移動
                if j + AX[i] <= 2 * max_X:
                    dpX[i + 1][j + AX[i]] = 1
                # -X方向に移動
                if 0 <= j - AX[i]:
                    dpX[i + 1][j - AX[i]] = 1
# Y軸方向の最大値
max_Y = sum(AY)
# dpY[i][j] = Y軸方向の移動をi回行って、jに到達できるか
# j = 0, 1, ..., 2*max_Y だが、実際のY座標は -max_Y, ..., 0, ..., max_Y
# 原点(y=0)は、j = max_Yに相当する
dpY = [[0 for _ in range(2 * max_Y + 1)] for _ in range(len(AY) + 1)]
dpY[0][max_Y] = 1
for i in range(len(AY)):
    for j in range(2 * max_Y + 1):
        if dpY[i][j] == 1:
            # +Y方向に移動
            if j + AY[i] <= 2 * max_Y:
                dpY[i + 1][j + AY[i]] = 1
            # -Y方向に移動
            if 0 <= j - AY[i]:
                dpY[i + 1][j - AY[i]] = 1

if -max_X <= x <= max_X and -max_Y <= y <= max_Y:
    if dpX[-1][x + max_X] == 1 and dpY[-1][y + max_Y] == 1:
        print("Yes")
        exit()
print("No")


Measured memory_bytes: 206376
import math

n,d = map(int,input().split())

s = []
for _ in range(n):
    s.append(list(map(int,input().split())))
    #print(s[-1])

ans = 0
for i in range(n):
    if math.sqrt(s[i][0] ** 2 + s[i][1] ** 2) <= d:
        ans = ans + 1
    
    
print(ans)

Measured memory_bytes: 45456
def main():
    h, w, n = map(int, input().split())
    sr, sc = map(int, input().split())
    s = input()
    t = input()

    # LR
    left_limit = 0
    right_limit = w
    for i in range(n-1, -1, -1):
        if t[i] == 'L' and right_limit < w:
            right_limit += 1
        elif t[i] == 'R' and left_limit > 0:
            left_limit -= 1
        if s[i] == 'L':
            left_limit += 1
        elif s[i] == 'R':
            right_limit -= 1
        if left_limit == right_limit:
            print('NO')
            return

    if sc <= left_limit or sc > right_limit:
        print('NO')
        return

    # UD
    up_limit = 0
    down_limit = h
    for i in range(n-1, -1, -1):
        if t[i] == 'U' and down_limit < h:
            down_limit += 1
        elif t[i] == 'D' and up_limit > 0:
            up_limit -= 1
        if s[i] == 'U':
            up_limit += 1
        elif s[i] == 'D':
            down_limit -= 1
        if up_limit == down_limit:
            print('NO')
            return

    if sr <= up_limit or sr > down_limit:
        print('NO')
        return

    print('YES')

if __name__ == '__main__':
    main()


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=acos(-1);
const ll MOD=1e9+7;

int main() {
    int m;
    cin>>m;
    ll k=0,s=0;
    //桁数と桁和
    ll d,c;
    rep(i,m){
        cin>>d>>c;
        k+=c;
        s+=d*c;
    }
    ll ans=k-1+(s-1)/9;
    cout<<ans<<endl;
    return 0;
}

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

int main(){
    string S, T;
    cin >> S >> T;

    int count = 0;

    for (int i = 0; i < 3; i++){
        if (S[i] == T[i]){
            count++;
        }
    }

    cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(v) v.begin(),v.end()
#define UN(v) sort(ALL(v)),v.erase(unique(ALL(v)))
#define FILL(x,y) memset(x,y,sizeof(x))
#define EACH(v,it) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define FIO ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef unsigned int uint;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
const string M="Male",F="Female",N="Vacant";
int n;
map<int,int> mp;
/*---main code---*/ 

int get(int x)
{
	if(mp.find(x)!=mp.end())
	{
		return mp[x];
	}
	printf("%d\n",x);
	fflush(stdout);
	string s;
	cin>>s;
	if(s==N)
	{
		exit(0);
	}
	mp[x]=(s==M);
	return mp[x];
}

int main()
{
	FIO;
	cin>>n;
	int L=0,R=n-1;
	while(R-L>=2)
	{
		int mid=(L+R)>>1;
		if(get(mid)^(mid%2)!=get(L)^(L%2))
		{
			R=mid;
		}
		else
		{
			L=mid;
		}
	}
	for(int i=L;i<=R;i++)
	{
		get(i);
	}
	return 0;
}


Measured memory_bytes: 852
#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); }

int main() {
    init();

    int n;
    cin >> n;
    VI a(n), sorted;
    FOR(i, 0, n)cin >> a[i];
    sorted = a, SORT(sorted);
    map<int, int> map;
    FOR(i, 0, n)map[sorted[i]] = i;
    FOR(i, 0, n)a[i] = map[a[i]];

    int ans = 0;
    FOR(i, 0, n)ans += abs(a[i] - i) % 2;
    cout << ans / 2 << "\n";
}

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

#define int long long
#define endl '\n'

signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    #ifdef LOCAL
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w", stdout);
    #endif
    
    int n; cin>>n;
    map<string, int> mp;
    vector<string> v = {"AC", "WA","TLE", "RE"};
    for (int i = 0; i < n; i++) {
        string s; cin>>s;
        mp[s]++;
    }
    for (auto s: v) {
        cout<<s<<" x "<<mp[s]<<endl;
    }
}

Measured memory_bytes: 3664
#include "bits/stdc++.h"
using namespace std;
int main() {
    
    int n, l;
    cin >> n >> l;

    int s = 0; //りんごの味の総和＝つまみ食いなしのパイの味
    int m = 1e9; // 絶対値が最も小さいりんごの味
    int t; // りんご一個あたり(i番目)の味

    for (int i = 0; i < n; i++) {
        t = l + ( i + 1 ) - 1;  // (i + 1)は、i = 0にしているから
        s += t;
        
        if (abs(t) < abs(m)) m = t;
     }

     cout << s - m << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>

#define For(i, a, b) for (int i = a, bb = b; i <= bb; ++i)

const int MaxN = 45, MaxS = 14e4 + 5, mod = 1e9 + 7;
int f[MaxN][MaxS], g[MaxS][15], n, x, y, z, cz; 

template <class T>
inline void get(T &res)
{
	char ch;
	bool bo = false;
	while ((ch = getchar()) < '0' || ch > '9')
		if (ch == '-') bo = true;
	
	res = ch - '0';
	while ((ch = getchar()) >= '0' && ch <= '9')
		res = (res << 1) + (res << 3) + ch - '0';
	
	if (bo) res = ~ res + 1;
	return;
}

template <class T>
inline void put(T x)
{
	if (x < 0)
	{
		putchar('-');
		x = ~ x + 1;
	}
	if (x > 9) put(x / 10);
	putchar(x % 10 + '0');
	return;
}

inline void Plus(int &x, const int &y)
{
	x += y;
	if (x >= mod) x -= mod;
	return;
}

int main()
{
	get(n), get(x), get(y), get(z);
	y += x, z += y;
	cz = 1 << z;
	
	For(s, 1, cz)
	For(i, 1, 10)
	if (s == cz) g[s][i] = cz;
	else
	{
		g[s][i] = 1;
		
		For(j, 0, z)
		if (s & (1 << j) && j + i <= z && 
			!(j + i > x && j < x) && !(j + i > y && j < y))
			g[s][i] |= 1 << i + j;
		
		if (g[s][i] > cz) g[s][i] = cz;
	}
	
	f[0][1] = 1;
	For(i, 0, n - 1)
	For(s, 0, cz)
	if (f[i][s])
	For(j, 1, 10)
		Plus(f[i + 1][g[s][j]], f[i][s]);
	
	put(f[n][cz]);
	putchar('\n');
	
	return 0;
}

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

int main(){
    scanf("%*d");
    int b,c;
    int cnt = 0;

    while(scanf("%d%d",&b,&c) != EOF){
        cnt += c - b + 1;
    }
    printf("%d\n", cnt);

    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long int
using namespace std;

int main()
{
    ll a[100000+9],n,i,x=-99999999,s=0,p=0;
  cin>>n;

    for(i=0;i<n;i++)
    {
        cin>>a[i];
        s+=a[i];
    }
    sort(a,a+n);
    p=a[n-1]/2;
    s=s-p;
    cout<<s<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 505;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
char s[MAXN][MAXN];
int main() {
	int n; read(n);
	for (int i = 1; i <= n; i++)
		scanf("\n%s", s[i] + 1);
	int ans = 0;
	for (int p = 1; p <= n; p++) {
		bool flg = true;
		for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			flg &= s[i][j] == s[j][i];
		if (flg) ans += n;
		for (int i = 1; i <= n; i++) {
			char c = s[i][1];
			for (int j = 1; j <= n - 1; j++)
				s[i][j] = s[i][j + 1];
			s[i][n] = c;
		}
	}
	writeln(ans);
	return 0;
}

Measured memory_bytes: 384
#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<complex>
#include<sstream>
#include<climits>
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double, int> pbi;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 1000;
ll N, xs, ys, xt, yt;
ll x[MAX_N+1], y[MAX_N+1], r[MAX_N+1];


                            
struct edge { 
  int to; 
  double cost; 
  edge(int u, double c) {
    to = u; cost = c;
  };
};

const int MAX_V = MAX_N+2;
const double INF = 1e12;

int V;
vector<edge> G[MAX_V];
double d[MAX_V];

void dijkstra(int s) {
  for (int i = 0; i <= N+1; ++i) d[i] = INF;
  priority_queue<pbi, vector<pbi>, greater<pbi> > pque;
  d[s] = 0;
  pque.push(pbi(0, s));


  while (!pque.empty()) {
    pbi p = pque.top(); pque.pop();
    int v = p.second;
    if (d[v] < p.first) continue;
    for (int i = 0; i < (int)G[v].size(); ++i) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost; 
        pque.push(pbi(d[v]+ e.cost, e.to));
      }
    }
  }
}


int main() {
  cin >>  xs >> ys >> xt >> yt;
  cin >> N;
  for (int i = 1; i <= N; ++i) cin >> x[i] >> y[i] >> r[i];

  for (int i = 1; i <= N; ++i) {
    double dist = sqrt((xs-x[i])*(xs-x[i]) + (ys-y[i])*(ys-y[i]));
    if (dist <= (double)r[i]) G[0].push_back(edge(i, 0));
    else G[0].push_back(edge(i, dist-(double)r[i]));
  }

  for (int i = 1; i <= N; ++i) {
    for (int j = i+1; j <= N; ++j) {
      double dist = sqrt((x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]));
      if (dist <= double(r[i]+r[j])) {
        G[i].push_back(edge(j, 0));
        G[j].push_back(edge(i, 0));
      } else {
        G[i].push_back(edge(j, dist-(double)r[i]-(double)r[j]));
        G[j].push_back(edge(i, dist-(double)r[i]-(double)r[j]));

      }
    }
  }
  for (int i = 1; i <= N; ++i) {
    double dist = sqrt((xt-x[i])*(xt-x[i]) + (yt-y[i])*(yt-y[i]));
    if (dist <= (double)r[i]) G[i].push_back(edge(N+1, 0));
    else G[i].push_back(edge(N+1, dist-(double)r[i]));
  }

  double dist = sqrt((xs-xt)*(xs-xt) + (ys-yt)*(ys-yt));
  G[0].push_back(edge(N+1,dist));

  /*
  for (int i = 0; i <= N+1; ++i) {
    cout << "v = " << i << endl;
    for (int k = 0; k < G[i].size(); ++k) {
      printf("(to, cost) = (%d, %.10f), ", G[i][k].to, G[i][k].cost);
    }
    cout << endl;
  }
  */

  dijkstra(0);

  printf("%.13f\n", d[N+1]);

  return 0;
}



Measured memory_bytes: 22256
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int n;
int a[222222];
int pos[222222];
bool u[222222];

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

  for (int i = 0; i < n; i++) {
    scanf("%d", a+i);
    pos[a[i]] = i;
  }

  vector<int> x;
  for (int i = 0; i < n; i++) {
    int v = a[i];
    int c = 1;
    if (!u[v]) {
      u[v] = true;
      while (pos[v+1] > pos[v]) {
        v = v + 1;
        u[v] = true;
        ++c;
      }
      x.push_back(c);
    }
  }

  printf("%d\n", n - *max_element(x.begin(), x.end()));
  return 0;
}


Measured memory_bytes: 3064
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

#define INF 100000

int main(){
  int h,w;
  cin >> h >> w;
  int c;
  int dist[10][10];
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      dist[i][j] = INF;
      if(i == j) dist[i][j] = 0;
    }
  }
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      cin >> c;
      dist[i][j] = c;
    }
  }
  for(int k=0;k<10;k++){
    for(int i=0;i<10;i++){
      for(int j=0;j<10;j++){
        dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]);
      }
    }
  }
  int count[10];
  for(int i=0;i<10;i++){
    count[i] = 0;
  }

  int ans = 0;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> c;
      if(c != 1 && c != -1) count[c] += 1;
    }
  }

  for(int i=0;i<10;i++){
    ans += count[i]*dist[i][1];
  }

  cout << ans << endl;


  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, A: "List[int]"):
    for idx in range(min(50,K)):
        B = [0] * (N+1)
        for i in range(N):
            B[max(i-A[i],0)] += 1
            B[min(i+A[i]+1,N)] -= 1
        
        add = 0
        for i in range(N):
            add += B[i]
            A[i] = add
    
    print(*A)

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 170180
#include<stdio.h>
int main()
{
    int a,i,j=0;
 
    scanf("%d",&a);
 
    int ar[a];
 
    for(i = 0;i < a; i++)
    {
        scanf("%d", &ar[i]);
 
        if(ar[i] != i+1)
            j++;
    }
 
    if(j > 2)
        printf("NO\n");
    else
        printf("YES\n");
 
    return 0;
}

Measured memory_bytes: 128
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int64_t n;
  cin >> n;
  int64_t Acount=0;
  int64_t Bcount=0;
  int64_t sum =0;
  vector<int> a(n);
  rep(i,n) cin >> a.at(i);
  int64_t sumA =0;
  int64_t sumB =0;
  int64_t num = 0;

//+-+- となるApata-nn
  for(int i=0;i<n;i++){//roop
    if(i%2==0){
      sumA += a.at(i);
      if(sumA<=0){
        num = 1 - sumA;
        sumA += 1-sumA;
        Acount += abs(num);
      }
    }
    else{
      sumA += a.at(i);
      if(sumA>=0){
        num = -1-sumA;
        sumA += -1-sumA;
        Acount += abs(num);
      }
    }
  }//roopend
//-+-+ となるBpata-nn
  for(int i=0;i<n;i++){
    if(i%2==0){
      sumB += a.at(i);
      if(sumB>=0){
        num = -1-sumB;
        sumB += -1-sumB;
        Bcount += abs(num);
      }
    }
    else{
      sumB += a.at(i);
      if(sumB<=0){
        num = 1 - sumB;
        sumB += 1-sumB;
        Bcount += abs(num);
      }
    }
  }
  if(Acount > Bcount) cout << Bcount << endl;
  else cout<< Acount << endl;
}

Measured memory_bytes: 640
import java.util.Scanner;
import java.util.Comparator;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringJoiner;
class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int K = scan.nextInt();
    String S = scan.next();
    int N = S.length();
    String[] split = S.split("");
    if (N <= K) {
      System.out.println(S);
    }
    else{
      String str[] = new String[K];
      for (int i = 0;i < K ;i++) {
        str[i] = split[i];
      }
      StringJoiner T = new StringJoiner("");
    for (String s : str) {
      T.add(s);
    }
      System.out.println(T + "...");
    }
  }
}



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

int main(){
	int N, T;
	cin >> N >> T;
	int c[N];
	int t[N];
	bool okemaru[N];
	for(int i = 0; i < N; i++) cin >> c[i] >> t[i];
	for(int i = 0; i < N; i++) okemaru[i] = t[i] <= T;
	int min_c = 1001;
	for(int i = 0; i < N; i++){
		if(c[i] < min_c && okemaru[i]) min_c = c[i];
	}
	if(min_c == 1001) cout << "TLE" << endl;
	else cout << min_c << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, L: int):
    
    taste_perfect_pi = 0
    firstTaste = L
    lastTast = L + N - 1

    for i in range(1, N + 1):
        taste_perfect_pi += L + i - 1

    if L >= 0:
        print(taste_perfect_pi - firstTaste)
    elif L + N -1 >= 0:
        print(taste_perfect_pi)
    else:
        print(taste_perfect_pi - lastTast)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    L = int(next(tokens))  # type: int
    solve(N, L)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
/* Author : Harshit Jain a.k.a. iharshit009 */
#include <bits/stdc++.h>
#define vi               vector<int>
#define pb(x)            push_back(x)
#define all(x)           x.begin(), x.end()
#define sortall(x)       sort(all(x))
#define sortrev(x)       sort(all(x), greater<int>())
#define debug(x)         cout << '>' << #x << ':' << x << endl;
#define int              long long
#define ld               long double
#define endl 			 "\n";
#define mp 				 make_pair
#define pii 			 <int, int>
#define lb 				 lower_bound
#define ub				 upper_bound
#define len(a)           int((a).size())
#define prec(n)          fixed<<setprecision(n)
#define cnt(n)           __builtin_popcountll(n)
#define pi               pair<int, int>
const int mod = 1000000007;
using namespace std;
using namespace std::chrono;
// const int N = 1e5 + 5; 
// int n;
// int a[N];



int32_t main(){
auto start = high_resolution_clock::now(); // starting clock
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t;
t = 1;
// cin >>t;
while(t--){


string n;
cin >> n;
int sum = 0;
for(int i = 0;i<n.size(); i++){
	sum += n[i]- '0';
}

if(sum%9== 0){
	cout << "Yes" << endl;
} 
else{
	cout << "No" << endl;
}







}
auto stop = high_resolution_clock::now(); // stop clock
auto duration = duration_cast<microseconds>(stop - start);  // printing duration
cerr << "Time taken by function: " << duration.count() << " milliseconds" << endl; 
return 0;
}

Measured memory_bytes: 3744
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;

int n,ans=1e9;

inline int f(int x){
	int res=0;
	while(x)
		res+=x%10,x/=10;
	return res;
}

int main(){
	int a,b;
	cin>>n;
	for(int i=1;i<n;++i){
		ans=min(ans,f(i)+f(n-i));
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
N_s,M_s=input().split()
K=int(M_s)
N=int(N_s)

if N==0:
    print(N)
elif N>=K:
    #print("1")
    x1=N%K
    x2=abs(N%K-K)
    print(min(x1,x2))
else:
    #print("2")
    x1=N
    x2=abs(N-K)
    print(min(x1,x2))

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

typedef long long ll;
int main(){
  ll x;
  cin >> x;
  ll tmpans = 1;
  for(ll i = 1; i <= x; i++){
    ll tmp;
    for(ll j = 2; j < 10; j++){
      tmp = pow(i,j);
      if(tmp > x){
        break;
      }
      if(tmp > tmpans){
        tmpans = tmp;
      }
    }
  }
  
  cout << tmpans << endl;
  
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  string T;
  cin >> T;
  for (int i = 0; i < T.size(); i++) {
    if (T[i] == '?') {
      T[i] = 'D';
    }
  }
  cout << T << endl;
  return 0;
}


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

#define int long long
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)

void init() {}

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

int N, M;
char A[202][202];
bool vis[202][202];
int cnt[202][202];
bool dfs(int i, int j, int dir, int res) {
    // cout << i << " " << j << endl;
    if (i == 0 && j == 0 && res == 3) return true;
    if (vis[i][j] && res > cnt[i][j]) return false;
    vis[i][j] = true;
    if ((i == N - 1 && j == M - 1) || (i == N - 1 && j == 0) || (i == 0 && j == M - 1)) res++;
    cnt[i][j] = res;
    {
        int k = 1;
        int d = (dir + k) % 4;
        int nx = i + dx[d];
        int ny = j + dy[d];
        if (nx >= 0 && nx < N && ny >= 0 && ny < M && A[nx][ny] != '#') {
            if (dfs(nx, ny, d, res))
                return true;
            else
                return false;
        }
    }
    {
        int k = 0;
        int d = (dir + k) % 4;
        int nx = i + dx[d];
        int ny = j + dy[d];
        if (nx >= 0 && nx < N && ny >= 0 && ny < M && A[nx][ny] != '#') {
            if (dfs(nx, ny, d, res))
                return true;
            else
                return false;
        }
    }
    {
        int k = 3;
        int d = (dir + k) % 4;
        int nx = i + dx[d];
        int ny = j + dy[d];
        if (nx >= 0 && nx < N && ny >= 0 && ny < M && A[nx][ny] != '#') {
            if (dfs(nx, ny, d, res))
                return true;
            else
                return false;
        }
    }
    {
        int k = 2;
        int d = (dir + k) % 4;
        int nx = i + dx[d];
        int ny = j + dy[d];
        if (nx >= 0 && nx < N && ny >= 0 && ny < M && A[nx][ny] != '#') {
            if (dfs(nx, ny, d, res))
                return true;
            else
                return false;
        }
    }
    // FOR(k, 1, 5) {
    //     int d = (dir + k) % 4;
    //     if (d == (dir + 2) % 4) continue;
    //     int nx = i + dx[d];
    //     int ny = j + dy[d];
    //     if (nx >= 0 && nx < N && ny >= 0 && ny < M && A[nx][ny] != '#') {
    //         if (dfs(nx, ny, d, res)) return true;
    //     }
    // }
    vis[i][j] = false;
    return false;
}
bool solve() {
    cin >> N >> M;
    if (N == 0) return false;
    REP(i, N) {
        REP(j, M) {
            cin >> A[i][j];
            vis[i][j] = false;
            cnt[i][j] = 0;
        }
    }
    if (dfs(0, 0, 3, 0))
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return true;
}
signed main() {
    init();
    while (solve())
        ;
}


Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


int main(){
    int n;
    cin >> n;
    string s1, s2;
    cin >> s1 >> s2;
    vector<pair<char, char>> s(n);
    rep(i, n) {
        s[i] = P(s1[i], s2[i]);
    }
    
    mint ans = 1;
    rep(i, n) {
        if (i>0 && s[i]==s[i-1]) continue;
        int now = 3;
        if (i==0) {
            if (s[i].first!=s[i].second) now = 6;
        }
        if (i>0) {
            if (s[i].first==s[i].second) {
                if (s[i-1].first==s[i-1].second) now = 2;
                else now = 1;
            }
            else {
                if (s[i-1].first==s[i-1].second) now = 2;
                else now = 3;
            }
        }
        ans *= now;
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3600
import collections
import itertools
import numpy as np
import sys
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,A,B = IL()

if (B-A)%2 == 0:
    print("Alice")
else:
    print("Borys")

Measured memory_bytes: 12496
import sys

N,Y=map(int,input().split())

for i in range(N+1):
    for j in range(N-i+1):
        if i*10000+j*5000+(N-i-j)*1000==Y:
            print(i,j,N-i-j)
            sys.exit()

print(-1,-1,-1)

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

int main(void){
  ll n;
  cin >> n;
  vector<ll> a(n);
  cin >> a[0];
  ll ans = 0;
  for(int i = 1; i < n; i++){
    cin >> a[i];
    if(a[i-1] > a[i]){
      ll tmp = a[i-1] - a[i];
      ans += tmp;
      a[i] = a[i-1];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4760
/*
AtCoder Beginner Contest 178 - D - Redistribution
https://atcoder.jp/contests/abc178/tasks/abc178_d
*/

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<vl> vvl;

double EPS=1e-9;
int INF=1000000005;
long long INFF=1000000000000000005ll;
double PI=acos(-1);
int dirx[8]={ -1, 0, 0, 1, -1, -1, 1, 1 };
int diry[8]={ 0, 1, -1, 0, -1, 1, -1, 1 };
const ll MOD = 1000000007;

ll sum() { return 0; }
template<typename T, typename... Args>
T sum(T a, Args... args) { return a + sum(args...); }

#define DEBUG fprintf(stderr, "====TESTING====\n")
#define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
#define OUT(x) cout << x << endl
#define OUTH(x) cout << x << " "
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define READ(x) for(auto &(z):x) cin >> z;
#define FOR(a, b, c) for (int(a)=(b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a)=(b); (a) <= (c); ++(a))
#define FORD(a, b, c) for (int(a)=(b); (a) >= (c); --(a))
#define FORSQ(a, b, c) for (int(a)=(b); (a) * (a) <= (c); ++(a))
#define FORC(a, b, c) for (char(a)=(b); (a) <= (c); ++(a))
#define EACH(a, b) for (auto&(a) : (b))
#define REP(i, n) FOR(i, 0, n)
#define REPN(i, n) FORN(i, 1, n)
#define MAX(a, b) a=max(a, b)
#define MIN(a, b) a=min(a, b)
#define SQR(x) ((ll)(x) * (x))
#define RESET(a, b) memset(a, b, sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define PERMUTE next_permutation
#define TC(t) while (t--)
#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define what_is(x) cerr << #x << " is " << x << endl;

void solve() {

}

int main()
{
    FAST_INP;
//    #ifndef ONLINE_JUDGE
//    freopen("input.txt","r", stdin);
//    freopen("output.txt","w", stdout);
//    #endif

//    int tc; cin >> tc;
//    TC(tc) solve();
	int s;
	cin >> s;
	int dp[2005]; 
	dp[0]=dp[1]=dp[2]=0;
	dp[3]=1; // {3}
//	dp[4]=1; // {4}
//	dp[5]=1; // {5}
//	dp[6]=2; // {6}, {3,3}
//	dp[7]=3; // {7}, {3,4}, {4,3}
	FORN(i,4,s) {
		dp[i]=dp[i-1]+dp[i-3];
		dp[i]%=MOD;
	}
	OUT(dp[s]);
    return 0;
}

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

int min(int a, int b){
	if(a < b){
		return a;
	}
	else{
		return b;
	}
}

int main(){
	int N, K, i, j;
	scanf("%d%d", &N, &K);
	int *a = (int *)malloc(sizeof(int) * N);
	int inf = N;
	for(i = 0; i < N; i++){
		scanf("%d", &a[i]);
	}
	int *inc = (int *)malloc(sizeof(int) * K);
	int *dec = (int *)malloc(sizeof(int) * K);
	for(i = 1; i < K; i++){
		inc[i] = inf;
		dec[i] = inf;
	}
	inc[0] = -1;
	dec[0] = -1;
	int sum = 0;
	for(i = 0; i < N; i++){
		sum = min(sum + a[i], K - 1);
		for(j = sum; j >= a[i]; j--){
			if(inc[j - a[i]] != inf && inc[j] == inf){
				inc[j] = i;
			}
		}
	}
	sum = 0;
	for(i = N - 1; i >= 0; i--){
		sum = min(sum + a[i], K - 1);
		for(j = sum; j >= a[i]; j--){
			if(dec[j - a[i]] != inf && dec[j] == inf){
				dec[j] = i;
			}
		}
	}
	int need = 0, k, l;
	for(i = 0; i < N; i++){
		for(k = 0, l = K - 1;;){
			while(inc[k] >= i){
				k++;
				if(k >= K){
					break;
				}
			}
			while((dec[l] <= i || dec[l] == inf) && dec[l] != -1){
				l--;
				if(l < 0){
					break;
				}
			}
			if(k >= K || l < 0 ){
				break;
			}
			if(k + l < K - a[i]){
				k++;
			}
			else if(k + l >= K){
				l--;
			}
			else{
				need++;
				break;
			}
		}
	}
	printf("%d\n", N - need);
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<ll> sum(n + 1, 0);
  rep(i,n) {
    ll num = 0;
    cin >> num;
    sum[i + 1] = sum[i] + num;
  }
  map<ll, ll> cnt;
  ll ans = 0;
  rep(i, n + 1){
    ans += cnt[sum[i]];
    cnt[sum[i]]++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 14336
n=int(input())
a=list(map(int,input().split()))
ans=0
b=[0]*(n+1)
for i in range(n):
    b[a[i]]+=1
for k in b:
    ans+=k*(k-1)//2
for i in range(n):
    print(ans-b[a[i]]+1)

Measured memory_bytes: 25644
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;

typedef long long LL;
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = (int)1e9;
const long long mod = (long long)1e9 + 7;
const double pi = acos(-1.0);

#define Sort(a) sort(a.begin(),a.end())
#define ReSort(a) sort(a.rbegin(),a.rend())
#define Reverse(a) reverse(a.begin(),a.end())
#define Sum(a) accumulate(a.begin(),a.end(),0)
#define SumLL(a) accumulate(a.begin(),a.end(),0LL)

//INPUT//
void CINPUT() {}
template<class H, class ...T> void CINPUT(H&& h, T&& ...t) { cin >> h; CINPUT(forward<T>(t)...); }
#define in(...) int __VA_ARGS__; CINPUT(__VA_ARGS__);
#define In(T,...) T __VA_ARGS__; CINPUT(VA_ARGS__);
#define Vin(T,name,n) int n; cin>>n; vector<T> name(n); rep(i,n)cin>>name[i];
#define VIn(T,name,n) vector<T> name(n); rep(i,n)cin>>name[i];

//OUTPUT//
void print() { cout << endl; }
template <class H> void print(H&& h) { cout << h << endl; }
template <class H, class... T> void print(H&& h, T&& ... t) { cout << h << " "; print(forward<T>(t)...); }
#define yes(flag) puts((flag) ? "yes" : "no");
#define Yes(flag) puts((flag) ? "Yes" : "No");
#define YES(flag) puts((flag) ? "YES" : "NO");
#define Yay(flag) puts((flag) ? "Yay!" : ":(");
#define poss(flag) puts((flag) ? "possible" : "impossible");
#define Poss(flag) puts((flag) ? "Possible" : "Impossible");
#define POSS(flag) puts((flag) ? "POSSIBLE" : "IMPOSSIBLE");
#define out(n) cout << (n) << endl;
#define Vout(a) rep(i, sz(a))cout << a[i] << (i==sz(a)-1?"\n":" ");

int main() {
	in(a, b);
	out(a == b ? a * 2 : max(a, b) * 2 - 1);
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
#define int long long

signed main() {
    int n;
    cin >> n;
    vector<int> v(n);
    rep(i, n) cin >> v[i];
    sort(v.begin(), v.end());
    int sum = 0;
    for (auto a = v.begin(); a != v.end(); a++) {
        auto c = a;
        c++;
        for (auto b = c; b != v.end(); b++) {
            auto it = b;
            it++;
            auto d = lower_bound(it, v.end(), *a + *b);
            sum += distance(b, d) - 1;
        }
    }
    cout << sum << endl;
}

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

#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;

ll n, l;

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin >> n >> l;
	bool pos = false;
	int index = 0;
	vector<ll> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		if (i && a[i] + a[i - 1] >= l) {
			pos = true;
			index = i;
		}
	}
	
	if (!pos) {
		cout << "Impossible";
	} else {
		cout << "Possible\n";
		for (int i = 1; i < index; ++i) cout << i << '\n';
		for (int i = n - 1; i > index; --i) cout << i << '\n';
		cout << index;
	}
}


Measured memory_bytes: 3980
import java.util.Scanner;

public class Main {

    static final int max = 200000;
    public static void main(String[]args){
        int R[] = new int[max];
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        for (int i = 0; i<n; i++)
        {
            R[i]= scanner.nextInt();
        }

        int maxv = -2000000000; //设置一个足够小的值
        int minv = R[0];

        for (int i = 1; i<n; i++){
            maxv = Math.max(maxv,R[i]-minv);
            minv = Math.min(minv,R[i]);
        }
        System.out.println(maxv);
    }
}



Measured memory_bytes: 101048
// 基本テンプレート
 
#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>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

int N, Q;
 
signed main() {
    cin >> N >> Q;

    int L = 2*N;
    vector<int> A(L), B(L);
    for(int i=0; i<L; i++) cin >> A[i];
    for(int i=0; i<L; i++) cin >> B[i];

    int asum = accumulate(A.begin(), A.end(), 0LL);
    set< pair<int, int> > more, less;

    // B - A >= 0 全部取った時の和
    int cur_max = 0;
    for(int i=1; i<L-1; i++) {
        int diff = B[i] - A[i];
        if(diff >= 0) {
            more.insert(make_pair(diff, i));
            cur_max += diff;
        }
        else {
            less.insert(make_pair(-diff, i));
        }
    }

    for(int i=0; i<Q; i++) {
        int p, x, y; cin >> p >> x >> y; p--;
        asum -= A[p];

        if(p != 0 && p != L-1) {
            pair<int, int> elem_more = make_pair(B[p] - A[p], p);
            pair<int, int> elem_less = make_pair(A[p] - B[p], p);
            if(more.count(elem_more)) {
                more.erase(elem_more);
                cur_max -= B[p] - A[p];
            }
            if(less.count(elem_less)) {
                less.erase(elem_less);
            }
        }

        A[p] = x, B[p] = y;
        asum += A[p];

        if(p != 0 && p != L-1) {
            int diff = B[p] - A[p];
            if(diff >= 0) {
                more.insert(make_pair(diff, p));
                cur_max += diff;
            }
            else {
                less.insert(make_pair(-diff, p));
            }
        }

        int sz = more.size(), tmp_max = cur_max;
        for(auto it=more.begin(); it!=more.end(); it++) {
            if(sz % 2 == 0) break;
            sz--;
            // printf("reduce: %lld\n", it -> first);
            tmp_max -= it -> first;
        }
        if(more.size() % 2 == 1 && less.size()) chmax(tmp_max, cur_max - less.begin()->first);

        // printf("asum = %lld, tmp_max = %lld\n", asum, tmp_max);
        cout << asum + tmp_max << endl;
    }
    return 0;
}

Measured memory_bytes: 17280
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define REVETSE(c) reverse((c).begin(),(c).end())
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define ALL(a)  (a).begin(),(a).end()
// int gcd(int a,int b){return b?gcd(b,a%b):a;}
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> T maxt(T x,T y) {
    if (x>y) return x;
    else return y;
}
template<class T> T mint(T x,T y) {
    if (x>y) return y;
    else return x;
}
//sort(v.rbegin(), v.rend(), [](auto& x, auto& y){return x[1] < y[1];});
//cout << fixed << setprecision(10) << ans << defaultfloat << endl;
typedef long long ll;
typedef vector<int> Vi;
typedef vector<ll> Vl;
typedef vector<double> Vd;
typedef vector<string> Vs;

/* //約数列挙
vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}*/

int main() {
  int A,B;
  cin >> A >> B;
  cout << A/gcd(A,B)*B << endl;
}

Measured memory_bytes: 256