akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <iomanip>

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef long double LD;
typedef pair<LD, LD> PLDLD;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define CLR(a) memset((a), 0 ,sizeof(a))
#define ALL(a) a.begin(),a.end()

const double eps=1e-5;
const LL INF=(LL)1e9*(LL)1e9;


int main()
{
    LL n;
    cin>>n;
    vector<LL> a(n);
    REP(i,n)
        cin>>a[i];
    
    bool flag=1;
    LL cnt=0;
    while(flag)
    {
        flag=0;
        REP(i,n)
        {
            if(a[i]<=n-1) continue;
            flag=1;
            LL p=a[i]/n;
            cnt+=p;
            a[i]%=n;
            REP(j,n)
            {
                if(i==j) continue;
                a[j]+=p;
            }
        }

        /*REP(i,n)
            cout<<a[i]<<" \n"[i==n-1];*/
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int max = 0;
    int min = Integer.MAX_VALUE;

    for (int i = 0; i < n; i++) {
      int index = sc.nextInt();
      int value = sc.nextInt();
      max = Math.max(max, index);
      min = Math.min(min, value);
    }

    System.out.println(max + min);

  }
}

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

using namespace std;

inline long long read(){
	char ch=getchar();long long x=0,f=1;
    while(ch<'0' || ch>'9') {
       if(ch=='-') f=-1;
	  	  ch=getchar();
	}
    while(ch<='9' && ch>='0') {
	   x=x*10+ch-'0';
	   ch=getchar();
	}
    return x*f;
}

long long a[300000];

int main(){
	long long n=read();
	for(int i=1;i<=n;i++){
		a[i]=read();
		a[i]-=i;
	}
	sort(a+1,a+n);
	long long mid=a[n/2];
	long long ans=0;
	for(int i=1;i<=n;i++){
		ans+=abs(a[i]-mid);
	}
	long long ans1=0;
	mid=a[n/2+1];
	for(int i=1;i<=n;i++){
		ans1+=abs(a[i]-mid);
	}
	printf("%lld",min(ans1,ans));
	return 0;
}


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

int main() {
  int N = 0;
  int A = 0;
  int a =0;
  cin >> N >> A;
  a = N % 500;
  if (a <= A) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
a = map(int, raw_input().split())

for i in range(len(a)):
	point = a[i:].index(min(a[i:])) + i
	temp = a[i];
	a[i] = a[point]
	a[point] = temp
print '%s %s %s' % (str(a[0]), str(a[1]), str(a[2]))

Measured memory_bytes: 6348
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CakesAndDonuts
{
    class Program
    {
        static void Main(string[] args)
        {
            var total = int.Parse(Console.ReadLine());
            var num4 = 0;
            var found = false;

            while(true)
            {
                var num7 = 0;
                if (4 * num4 == total)
                {
                    found = true;
                    break;
                }
                if (4 * num4 > total)
                {
                    break;
                }

                while (true)
                {
                    var sum = 4 * num4 + 7 * num7;
                    if(sum == total)
                    {
                        found = true;
                        break;
                    }
                    if(sum > total)
                    {
                        break;
                    }
                    num7++;
                }
                num4++;
            }
            Console.WriteLine(found ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define debug(x)  cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;

int main() {
  int W, H, N; cin >> W >> H >> N;
  vi x(N), y(N), a(N); rep(i,N) cin >> x.at(i) >> y.at(i) >> a.at(i);
  
  int xs = 0, ys = 0;
  int xe = W, ye = H;
  
  rep(i,N) {
    if (a.at(i) == 1) 
      xs = max(xs, x.at(i));
    else if (a.at(i) == 2)
      xe = min(xe, x.at(i));
    else if (a.at(i) == 3)
      ys = max(ys, y.at(i));
    else
      ye = min(ye, y.at(i));
  }
  
  cout << max(xe-xs,0)*max(ye-ys,0) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod107 1000000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
#define grepq priority_queue<double, std::vector<double>, std::greater<double>>
#define all(v) v.begin(), v.end()
#define PI acos(-1)
const ll INF = 10010001010;
const int inf = 1000034000;
typedef vector<ll> vecl;
typedef vector<int> veci;
typedef tuple<string, int, int> TUP;

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

int main()
{
    string S,T;
    cin >> S;
    cin >> T;
    int N = S.size();
    bool ok = false;
    for (int i = 0; i < N;i++)
    {
        char s = S[N-1];
        for (int j = N - 1; j >= 0; j--)
        {
            S[j + 1] = S[j]; 
        }
        S[0] = s;
        if (S == T)
        {
            ok = true;
        }
    }
    if(ok){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define INF 1e18
#define MOD 1000000007
#define PI M_PI
#define ll long long
#define vi vector<int>
#define all(v) v.begin(), v.end()
#define FOR(i, a, b) for (int i=a; i<b; i++)
#define REP(i, n) for (int i=0; i<n; i++)
#define REPD(i, n) for (int i=n-1; i>=0; i--)
#define print(x) cout << x << endl;
#define debug(x) cout << #x << " = " << endl;

using namespace std;

void solve()
{
    ll N;
    cin >> N;
    
    ll ans = N*(N-1)/2;
    
    print(ans);
}

int main()
{
    solve();

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
using P = pair<int,int>;
typedef long long ll;
const ll mod = 1e9+7;
#define all(x) (x).begin(),(x).end()

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(10);
    int N;
    cin >> N;
    int answer = (N+1)/2;
    cout <<answer<< "\n";
}

Measured memory_bytes: 256
def examC():
    N, M = LI()
    A = [I() for _ in range(M)]
    A.append(N+1)
    fib = [1]*(N+2)
    for i in range(1,N):
        fib[i+2] = fib[i+1] + fib[i]
    fib[0] = 0
#    print(fib)
    ans = fib[A[0]]%mod
    for i in range(M):
        ans *= fib[A[i+1]-A[i]-1]
        ans %=mod
    print(ans)
    return

def examD():
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,inf
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examC()


Measured memory_bytes: 464456
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
using namespace __gnu_pbds;
using namespace std;
/*
int dx[]={-1,1,0,0};
int dy[]={0,0,-1,1};
*/
#define ull unsigned long long int
#define ll long long int
#define MAX 1000000007
//1e9+7
#define pll pair<ll,ll>
#define pii pair<int,int>
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FO ifstream fin("a.in");ofstream fout("a.out");
#define TEST int testcase;cin>>testcase;while(testcase--)
#define all(x) (x).begin(),(x).end()
#define mset0(x) memset((x), 0, sizeof((x)));
#define mset1(x) memset((x), -1, sizeof((x)));
#define endl "\n"
#define plll pair<ll,pll>
typedef tree<ll,null_type,less<ll>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
FO
void solve(){
    int n;
    cin>>n;
    int arr[10001];
    memset(arr,0,sizeof arr);
    for(int x=1;x<=100;x++){
        for(int y=1;y<=100;y++){
            for(int z=1;z<=100;z++){
                int a=(x+y),b=(y+z),c=(z+x);
                if((a*a+b*b+c*c)%2==0 && (a*a+b*b+c*c)<=20000) arr[(a*a+b*b+c*c)/2]++;
            }
        }
    }
    for(int i=1;i<=n;i++){
        cout<<arr[i]<<endl;
    }
    return;
}
int main(){
    //IO FO
    //TEST
    solve();

    return(0);
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H, W = 1;
  
  while( W > 0){
    cin >> H >> W;
    if(H == 0 && W == 0){
      break;
    }
    else{
      for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
        if((i + j) % 2 == 0){
          cout << "#";
        }
        else{
        cout << ".";
      }
      }
      cout << endl;
      }
      cout << endl;
    }    
    
  }
  
}


Measured memory_bytes: 3060
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <list>
#include <cmath>
using namespace std;
typedef long long ll;
#define rep(i,m,n) for (int i = (int) (m); i < (int) (n); i++)
#define rep1(i,m,n) for (int i = (int) (m); i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
ll gcd(ll x,ll y){
    if(y==0)return x;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
    return x*y/gcd(x,y);
}
int main(void){
    int S,W;
    cin>>S>>W;
    if(S>W)cout<<"safe"<<endl;
    else cout<<"unsafe"<<endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
  int s;
  cin>>s;
  int ok[11000];
  bool fin=false;
  int ans=0;
  while(!fin){
    ans++;
    //cout<<s<<endl;
    if(ok[s]==1) {
     // cout<<" "<<s<<endl;
      fin=true; 
      
    }
    else{
    ok[s]=1;
      if(s%2==0) s/=2;
      else s=3*s+1;
    }
  }
  cout<<ans<<endl;
}




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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

vector<ll> A,B;
ll N,M,K;

int main(){
    cin >> N >> M >> K;
    A.push_back(0);
    B.push_back(0);
    for(int i=0;i<N;i++){
        ll a;
        cin >> a;
        A.push_back(a);
    }
    for(int i=0;i<M;i++){
        ll b;
        cin >> b;
        B.push_back(b);
    }
    for(int i=1;i<=N;i++) A[i] += A[i-1];
    for(int j=1;j<=M;j++) B[j] += B[j-1];
    ll ans = 0;
    for(int i=0;i<=N;i++){
        if(A[i] > K) break;
        ll t = upper_bound(B.begin(),B.end(),K-A[i]) - B.begin() - 1;
        ans = max(ans, t + i);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7972
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    int n, k; cin >> n >> k;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    sort(ALL(p));
    int ans = 0;
    rep(i, k) ans += p[i];
    cout << ans << endl;
}

Measured memory_bytes: 3600
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static int dfs(int p, int q, int a, int n, int low, int pr) {
		if (p == 0) return 1;
		int res = 0;
		for (int i=low; i*pr<=a; i++) {
			if (i*p > n*q) break;
			if (i*p >= q) {
				res += dfs(i*p - q, i*q, a, n-1, i, pr*i);
			}
		}
		return res;
	}

	static boolean solve() {
		int p = in.nextInt();
		int q = in.nextInt();
		int a = in.nextInt();
		int n = in.nextInt();
		if (p + q + a + n == 0) return false;

		out.println(dfs(p, q, a, n, 1, 1));

		return true;
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();

		while(solve());
		out.flush();

		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

Measured memory_bytes: 33592
#include<iostream>
#include<vector>
using namespace std;
#define df 0
typedef long int li;
const li MAX=10000000000;
#define rep(i,n) for(int i=0;i<n;i++)
#define dist(a,b) max((a)-(b),(b)-(a))

int hypo(int cx,int cy,vector<int>* height,int n){
  int h=height[2].at(0)+dist(cx,height[0].at(0))+dist(cy,height[1].at(0));
  rep(i,n){
    int temp=h-dist(cx,height[0].at(i))-dist(cy,height[1].at(i));
    if(height[2].at(i)!=max(temp,0))return 0;
  }
  return h;
}



int main(){
  if(df) printf("*debug mode*\n");
  int n;cin >>n;
  vector<int> height[3];
  int f=-1;
  for(int i=0;i<n;i++){
    int x,y,z; cin >>x >>y >>z;
    if(z>0)f=i;
    height[0].push_back(x);
    height[1].push_back(y);
    height[2].push_back(z);
  }
  rep(i,3){
    swap(height[i].at(0),height[i].at(f));
  }
  if(df){
    printf(" %d %d %d\n",height[0].at(0),height[1].at(0),height[2].at(0));
  }
  rep(cx,101)rep(cy,101)if(f=hypo(cx,cy,height,n)){
    printf("%d %d %d\n",cx,cy,f);
    return 0;
  }
}

/// confirm df==0 ///


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <tuple>
#include <cstring>
#include <map>
#include <iomanip>
#include <ctime>
#include <complex>
#include <cassert>
#include <climits>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _ << " " <<
#define all(X) (X).begin(), (X).end()
#define len(X) (X).size()
#define Pii pair<int, int>
#define Pll pair<ll, ll>
#define Tiii tuple<int, int, int>
#define Tlll tuple<ll, ll, ll>

int main() {
    ll a, b;
    cin >> a >> b;
    ll ans = 0;
    vector<ll> p(a), q(b);
    for (int i = 0; i < a; i++) {
        cin >> p[i];
        ans += p[i];
    }
    for (int i = 0; i < b; i++) {
        cin >> q[i];
        ans += q[i];
    }
    sort(all(q));
    vector<ll> s(b + 1, 0);
    for (int i = 0; i < b; i++) s[i + 1] = s[i] + q[i];

    for (int i = 0; i < a; i++) {
        int l = -1, r = b;
        while (r - l > 1) {
            int m = (l + r) / 2;
            if (q[m] > p[i]) r = m;
            else l = m;
        }
        ans += s[l + 1] + (b - l - 1) * p[i];
        //cerr << "l: " << l << endl;
    }
    cout << ans << endl;



}


Measured memory_bytes: 2560
import sys
# input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    s = input()
    k = int(input())

    if len(s) == 1:
        print(k//2)
        exit()

    cnt = 1
    ans = 0
    for i in range(len(s)-1):
        if s[i] == s[i+1]:
            cnt += 1
        else:
            ans += cnt // 2
            cnt = 1
    ans += cnt // 2

    cnt2 = 1
    ans2 = 0
    s2 = s*2
    for i in range(len(s2)-1):
        if s2[i] == s2[i+1]:
            cnt2 += 1
        else:
            ans2 += cnt2 // 2
            cnt2 = 1
    ans2 += cnt2 // 2

    if s.count(s[0]) == len(s) and len(s) % 2 != 0:
        if k % 2 == 0:
            print(ans2*k//2)
        else:
            print(ans2*(k-1)//2+ans)
        exit()

    if ans * 2 != ans2:
        print(ans*k+k-1)
        exit()

    print(ans*k)


if __name__ == '__main__':
    main()


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

using namespace std;

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

  int a[n], brojac = 0;
  for (int i=0; i<n; i++) {
    cin >> a[i];
    brojac += a[i];
  }

  if (brojac>=h)
    cout << "Yes\n";
  else
    cout << "No\n";

  return 0;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
long long A, B;
long long Log(long long x)
{
    long long k = 60;
    long long pw = (1LL << 60);
    while(pw > x)
    {
        pw /= 2;
    }
    return pw;
}
long long Solve(long long A, long long B)
{
    if(A == B)
        return 1;
    if(A == 0)
        return(Solve(A + 1, B) + 1);

    long long pw = Log(B);
    if(pw <= A)
    {
        B -= pw;
        A -= pw;
        return Solve(A, B);
    }
    if(B > pw)
    {
        long long ans = 0;
    ans += pw - A;
    long long newA = A + pw;
    long long pw2 = Log(B - pw);
    pw2 *= 2;
    ans += pw2;
    pw2--;
    pw2 += pw;
     if(newA > pw2)
        ans += pw - A;
    else
        ans += pw + pw - 1 - pw2;
    return ans;
    }
    else
    {
        long long ans = (B - A) * 2 + 1;
        return ans;
    }
}
int main()
{
    cin >> A >> B;
    cout << Solve(A, B) << "\n";
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
	String a = sc.next();
    if (a.equals("a") || a.equals("e") || a.equals("i") || a.equals("o") || a.equals("u")){
      System.out.println("vowel");
    } else {
      System.out.println("consonant");
    }
  }
}

Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
ll qpow(ll x, ll n);
ll c(ll n, ll m);
ll f(ll n, ll m);
int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    ll ans = 0;
    ans = qpow(2, n);
    ans = (ans - 1 + mod + mod - f(n, a) - f(n, b) + mod) % mod;
    cout << ans;
}
ll qpow(ll x, ll n) {
    ll res = 1;
    x %= mod;
    while (n) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}
ll c(ll n, ll m) {
    if (n < m) return 0;
    ll res = 1;
    for (int i = 1; i <= m; i++) {
        ll a = (n + i - m) % mod;
        ll b = i % mod;
        res = res * (a * qpow(b, mod - 2) % mod) % mod;
    }
    return res;
}

ll f(ll n, ll m) {
    if (m == 0) return 1;
    return c(n % mod, m % mod) * f(n / mod, m / mod) % mod;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define M 998244353
#define MOD 1000000007
int pwr(int n,int p)
{
    int temp=n,ans=1;
    while(p>0)
    {
        if(p%2==1)
        {
            ans*=temp;
            ans%=MOD;
            --p;
        }
        else
        {
            temp=temp*temp;
            temp%=MOD;
            p/=2;
        }
    }
    return ans;
}
signed main()
{
    SPEED;
    int n,k;
    cin>>n>>k;
    int dp[k+1]={0},cnt=k;
    dp[k]=1;
    for(int i=k-1;i>0;i--)
    {
        int sum=0;
        for(int j=2*i;j<=k;j+=i)
        {
            sum+=dp[j];
            sum%=MOD;
        }
        dp[i]=(pwr((k/i),n)-sum+MOD)%MOD;
        cnt+=dp[i]*i;
        cnt%=MOD;
    }
    cout<<cnt;
}

Measured memory_bytes: 4440
using System;
using System.Collections;
using System.Collections.Generic;

class Program
{
	static long nCombination2(int n)
	{
		long ans = (n * (n - 1)) / 2;
		return ans;
	}
	static IEnumerable<long> Solve(int N, int[] A)
	{
		var dict = new Dictionary<int, int>();
		foreach (var a in A)
		{
			if (!dict.ContainsKey(a)) dict.Add(a, 0);
			dict[a]++;
		}
		long sum = 0;
		foreach (var value in dict.Values)
			sum += Math.BigMul(value, value - 1) / 2;
		var values = new long[N];
		for (int k = 0; k < N; k++)
		{
			int value = dict[A[k]];
			values[k] = sum - Math.BigMul(value, value - 1) / 2 + Math.BigMul(value - 1, value - 2) / 2;
		}

		return values;
	}
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		int[] A = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
		var values = Solve(N, A);
		foreach (var value in values)
			Console.WriteLine(value);
	}
}

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

using namespace std;




int main () {

	ios_base::sync_with_stdio(false); cin.tie(NULL);

	string s, t;
	cin >> s >> t;

	vector < int > x (26), y (26);
 
	for (int i = 0; i < s.size(); ++i) {
		x[s[i] - 'a']++;
		y[t[i] - 'a']++;
	}

	sort (x.begin(), x.end());
	sort (y.begin(), y.end());

	for (int i = 0; i < 26; ++i) {
		if (x[i] != y[i]) {
			cout << "No" << '\n';
			return 0;
		}
	}

	cout << "Yes" << '\n';


	return 0;
}


Measured memory_bytes: 916
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

void solve(){
    ll K;
    cin >> K;
    ll res = 0;
    rep(i,1,10000001){
        ll v = res * 10 + 7;
        v %= K;
        if(v == 0){
            print(i);
            return;
        }
        res = v;
    }
    print(-1);
    

}

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

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

int main() {
    string s;
    cin >> s;
    int n = s.size();
    int ans = 500000;
    int c = 0;
    for(int i=0; i<n; i++){ //0 1 0 1 
        if(i%2 != s.at(i) - '0') c++;
        else continue;
    }
    ans = min(ans,c);
    c = 0;
    for(int i=1; i<=n; i++){ // 1 0 1 0
        if(i%2 != s.at(i-1) - '0') c++;
        else continue;
    }
    ans = min(ans,c);
    cout << ans << endl;
}

Measured memory_bytes: 512
//#include <stdio.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>

using namespace std;

#define ll long long
vector<vector<ll>> dp;
vector<ll> w, v;
ll N, W;

void solve()
{
    cin >> N >> W;
    dp = vector<vector<ll>>(N + 1, vector<ll>(W + 1, 0));
    w = vector<ll>(N);
    v = vector<ll>(N);
    for (ll i = 0; i < N; i++)
    {
        cin >> w.at(i) >> v.at(i);
    }

    for (ll i = N - 1; i >= 0; i--)
    {
        for (ll j = 0; j <= W; j++)
        {
            if (w.at(i) > j)
            {
                dp.at(i).at(j) = dp.at(i + 1).at(j);
            }
            else
            {
                dp.at(i).at(j) = max(dp.at(i + 1).at(j), dp.at(i + 1).at(j - w.at(i)) + v.at(i));
            }
        }
    }
    cout << dp.at(0).at(W) << endl;

    // for (auto aa : dp)
    // {
    //     for (auto bb : aa)
    //     {
    //         cout << bb << " ";
    //     }
    //     cout << endl;
    // }

    return;
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 80256
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <random>
#include <string>
#include <bitset>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <cstring>
#include <cstdlib>
#include <cctype>

#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPR(i, n) for(int i = n; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define FORR(i, m, n) for(int i = m; i >= n; --i)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define INF 999999999

using namespace std;

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

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

llong pow(int x, int n) {
    llong ans = x;
    if (n == 0) return 1;

    for(int i = 0; i < n - 1; i++) {
        ans *= x;
    }

    return ans;
}

void swap(int *X, int *Y){
    int t = *X; *X = *Y; *Y = t;
}

const static int MAX = 50;
int main() {
    int n, m;
    cin >> n >> m;
    char tmp1, tmp2;
    if (n == 1 && m == 1) {
        cin >> tmp1 >> tmp2;
        cout << ((tmp1 == tmp2) ? "Yes" : "No") << endl;
        return 0;
    }
    char N[MAX][MAX];
    char M[MAX][MAX];
    string in;
    REP(i, n) {
        cin >> in;
        REP(j, in.size()) {
            N[i][j] = in[j];
        }
    }
    REP(i, m) {
        cin >> in;
        REP(j, in.size()) {
            M[i][j] = in[j];
        }
    }

    bool flag_1 = false, flag_2 = false;
    int cnt = 0;
    REP(i, n) {
        REP(j, n) {
            if (N[i][j] == M[0][0] && (n - j) >= m && (n - i) >= m) {
                for (int k = 0; k < m; ++k) {
                    for (int l = 0; l < m; ++l) {
                        if (N[i + k][j + l] == M[k][l]) {
                            cnt += 1;
                        } else {
                            flag_1 = true;
                            cnt = 0;
                            break;
                        }
                    }
                    if (flag_1) break;
                }
            }
            flag_1 = false;
            if (cnt == m * m) {
                flag_2 = true;
                break;
            }
        }
        if (flag_2) break;
    }

    if (flag_2) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(a,n) for (int a = 0; a < (n); ++a)
using namespace std;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<P,ll> PP;
typedef vector<vector<ll> > Graph;
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; }
const ll INF = 1e18;

Graph g;
ll n;
vector<ll>dist;

/*トポロジカルソートを行う
DAGでない場合にはsize０のvectorを返す*/

struct TopologicalSort{
    int v;
    vector<vector<int> >g,g_len;
    vector<int>deg,res;//degは頂点に入ってくる辺の数
    TopologicalSort(int n) : v(n),g(v),deg(v,0),g_len(v){}
    void add_edge(int from,int to){
        g[from].push_back(to);
        g_len[to].push_back(from);
        deg[to]++;
    }
    vector<int> solve(){
        queue<int>que;
        rep(i,v){
            if(deg[i]==0){
                que.push(i);
            }
        }
        while(!que.empty()){
            int p = que.front();
            que.pop();
            res.push_back(p);
            for(int v:g[p]){
                if(--deg[v]==0){
                    que.push(v);
                }
            }
        }
        if(*max_element(deg.begin(),deg.end())==0){
            return res;
        }
        else{
            return vector<int>();
        }
    }
    bool unique(){//解の一意性を判定する
        for(int i=0;i<v-1;i++){
            int from = res[i];
            int to = res[i+1];
            bool flg = false;
            for(int x:g[from]){
                if(x==to)flg=true;
            }
            if(!flg){
                return false;
            }
        }
        return true;
    }
    int longest_len(){
        vector<int>dist(v,0);
        for(int i=0;i<v;i++){
            for(int x:g_len[res[i]]){
                dist[res[i]]=max(dist[res[i]],dist[x]+1);
            }
        }
        return *max_element(dist.begin(),dist.end());
    }
};

int main(){
    cin >> n;
    TopologicalSort tps(n*n);
    rep(i,n){
        int past = 0;
        rep(j,n-1){
            int a;
            cin >> a;
            a--;
            int l = min(i,a);
            int r = max(i,a);
            int nx = l*n+r;
            tps.add_edge(past,nx);
            past = nx;
        }
    }
    //DAGの判定
    auto vec = tps.solve();
    if(vec.size()==0){
        cout << -1 << endl;
        return 0;
    }
    cout << tps.longest_len() << endl;
    return 0;
}


Measured memory_bytes: 99044
#include<bits/stdc++.h>
using namespace std;
int main(){
    int d,n;
    cin >> d >> n;
    if(d == 0)
    {if(n <= 99)
        cout << n << endl;
        if(n == 100)
        cout << 101 << endl;
    }
    else if(d == 1){
        if(n <= 99)
        cout << n * 100 << endl;
        if(n == 100)
        cout << 10100 << endl;
            }
            else {
                if(n <= 99)
                cout << 10000 * n << endl;
                if(n == 100)
                cout << 1010000 << endl;
            }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(c-(a-b)>0)cout<<c-(a-b)<<endl;
    else cout<<0<<endl;
}

Measured memory_bytes: 256
import numpy as np

k,n = map(int,input().split())
a = list(map(int,input().split()))
temp =a[0]
a.append(temp)
base = np.empty(n)

for i in range(n):
  if i == n-1:
    base[i] = (k-a[i]) + a[0]
    break
    
  base[i] = a[i+1] - a[i]
  
print(k - int(np.max(base)))


Measured memory_bytes: 34160
import sys


def resolve():
    readline = sys.stdin.readline    # 1行だけ文字列にする

    N = int(readline())
    NN = 2 * N + 1

    # 青色はx座標をlistのindex,y座標をlistのvalueとして入力，赤は逆
    red = [[] for _ in [0] * NN]
    blue = [[] for _ in [0] * NN]
    for _ in [0] * N:
        a, b = map(int, readline().split())
        red[b].append(a)
    for _ in [0] * N:
        c, d = map(int, readline().split())
        blue[c].append(d)

    # 青色でvalueのy座標について降順(大きい順)でソート
    # 赤色ではvalueのx座標について降順でソート
    # これで青色はx座標は昇順(index)，y座標は降順(value)にソートされる
    # 赤色はy座標が昇順(index)，x座標が降順(value)
    for i in range(NN):
        r = red[i]
        b = blue[i]
        r.sort(reverse=True)
        b.sort(reverse=True)
        r[0:0] = [i]
        b[0:0] = [i]

    # 青点はx座標の昇順で，赤点はy座標の降順
    # 最小のxの青点で最大のyを持つ赤点を選択
    ans = 0
    flag = False
    while blue:
        cd_blue = blue.pop(0)
        c = cd_blue.pop(0)
        if cd_blue:
            for d in cd_blue:
                for ba_red in red[::-1]:
                    b = ba_red[0]
                    if ba_red[1:]:
                        for i in range(1, len(ba_red)):
                            a = ba_red[i]
                            if a <= c and b <= d:
                                ans += 1
                                del red[b][i]
                                flag = True
                                break
                        if flag:
                            break
                if flag:
                    flag = False
                    break
    print(ans)


resolve()


Measured memory_bytes: 9228
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.io.UncheckedIOException;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        LightScanner in = new LightScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AAirportBus solver = new AAirportBus();
        solver.solve(1, in, out);
        out.close();
    }

    static class AAirportBus {
        public void solve(int testNumber, LightScanner in, PrintWriter out) {
            int n = in.ints(), c = in.ints(), k = in.ints();
            int[] t = in.ints(n);
            Arrays.sort(t);

            int arrival = t[0];
            int cap = 0;
            int ans = 1;
            for (int i = 0; i < n; i++) {
                if (t[i] <= arrival + k && cap < c) {
                    cap++;
                } else {
                    arrival = t[i];
                    cap = 1;
                    ans++;
                }
            }
            out.println(ans);
        }

    }

    static class LightScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public LightScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        public String string() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int ints() {
            return Integer.parseInt(string());
        }

        public int[] ints(int length) {
            return IntStream.range(0, length).map(x -> ints()).toArray();
        }

    }
}



Measured memory_bytes: 39056
import heapq

n = int(input())
g = [[] for i in range(n)]
for i in range(n-1):
    a, b, c = map(int, input().split())
    g[a-1].append((b-1, c))
    g[b-1].append((a-1, c))
q, k = map(int, input().split())
qs = [tuple(map(int, input().split())) for i in range(q)]

INF = float('inf')
dist = [INF for i in range(n)]
dist[k-1] = 0
hq = [(0, k-1)]
while hq:
    cost, node = heapq.heappop(hq)
    if cost > dist[node]:
        continue
    for n_node, n_cost in g[node]:
        d = dist[node] + n_cost
        if d < dist[n_node]:
            dist[n_node] = d
            heapq.heappush(hq, (dist[n_node], n_node))

for i in range(q):
    print(dist[qs[i][0]-1] + dist[qs[i][1]-1])

Measured memory_bytes: 59708
#include <stdio.h>

int main(void) {
  int sec;
  int h, m, s;

  scanf("%d", &sec);

  h = sec / (60*60);
  sec = sec - h * (60*60);

  m = sec / 60;
  sec = sec - m * 60;

  s = sec;
  
  printf("%d:%d:%d\n", h, m, s);
  return 0;
}


Measured memory_bytes: 2040
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
int getDigit(int n);            // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;

// code
// ------------------------------------------------
int main() {
  
  ll n;
  cin >> n;
  vector<ll> a(n+1),b(n);
  rep(i,n+1) cin >> a[i];
  rep(i,n) cin >> b[i];

  ll sum = 0;

  rep(i,n)
  {
    ll f = min(a[i],b[i]);
    if(a[i] > f)
    {
      a[i] -= f;
      sum += f;
    }
    else
    {
      sum += a[i];
      a[i] = 0;
    }
    b[i] = f > b[i] ? 0 : b[i] - f;

    ll s = min(a[i+1],b[i]);
    if(a[i+1] > s)
    {
      a[i+1] -= s;
      sum += s;
    }
    else
    {
      sum += a[i+1];
      a[i+1] = 0;
    }
    b[i] = s > b[i] ? 0 : b[i] - s;
  }

  cout << sum << endl;

  return 0;
}
// funcの実体
// ------------------------------------------------
int getDigit(int n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 1)
      break;
    i++;
  }
  return i;
}
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define MAX_N 510
#define rep(i, n) for(int i=0; i<n; i++)
int n, k, c[MAX_N][MAX_N];

int around(int a, int b){
    return c[(a>0)?a-1:n-1][b] + c[a][(b>0)?b-1:n-1] + c[(a+1<n)?a+1:0][b] + c[a][(b+1<n)?b+1:0];
}

template <size_t N, size_t M>
bool check(int (&c)[N][M]){
    rep(i, k){
        int csum = -1;
        rep(a, n){
            rep(b, n){
                if(c[a][b] == i){
                    if(csum == -1) csum = around(a, b);
                    else if(around(a, b) != csum) return false;
                }
            }
        }
    }
    return true;
}

int solve(int k){
    if(k == 1){
        cout << 1 << endl;
        cout << 1 << endl;
        return 0;
    }
    n = k / 2;
    n += (k%2==0)?0:1;
    if(n%2==1) n++;
    int _k = 2 * n;

    rep(i, n) rep(j, n) c[i][j] = (j % 2 == 0) ? (i + j) % n : (i + j) % n + n;
    while(_k >= k){
        rep(a, n){
            rep(b, n){
                if(c[a][b] == _k) c[a][b] -= n;
            }
        }
        _k--;
    }

    cout << n << endl;
    rep(i, n){
        rep(j, n) cout << c[i][j] + 1 << " ";
        cout << endl;
    }
}

int main(void){
    cin >> k;
    solve(k);
    return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const int nmax = 8;
bool graph[nmax][nmax];
 
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;
}
 
ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}
int dfs(int v, ll N, bool visited[nmax])
{
    bool all_visited = true;
 
    for (int i = 0; i < N; i++)
    {
        if (!visited[i])
        {
            all_visited = false;
        }
    }
 
    if (all_visited)
    {
        return 1;
    }
    int ret = 0;
    for (size_t i = 0; i < N; i++)
    {
        if (!graph[v][i])
        {
            continue;
        }
        if (visited[i])
        {
            continue;
        }
 
        visited[i] = true;
        ret += dfs(i, N, visited);
        visited[i] = false;
    }
 
    return ret;
}

void solve(long long N, long long K){
    ll ans = K;
    for(int i = 1; i < N; i++)
    {
        ans *= K-1;
    }
    cout << ans << endl;
    
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    solve(N, K);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>

using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> A(n);
    vector<int> B(n);
    vector<int> C(n);
    int count=0;
    for(int i=0;i<n;i++){
        int x;
        cin >> x;
        x--;
        A[i]=x;
    }
    for(int i=0;i<n;i++){
        cin >> B[i];
    }
    for(int i=0;i<n-1;i++){
        cin >> C[i];
    }
    count += B[A[0]];
    for(int i=1;i<n;i++){
        count += B[A[i]];
        if(A[i]-A[i-1]==1){
            count += C[A[i-1]];
        }
    }
    cout<<count<<endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;
int main(){
  int n;
  cin>>n;
  int count=0;
  for(int i=1;i<=n;i++){
    if(i%2==0) continue;
    int hoge=0;
    for(int j=1;j<=i;j++)
      if(i%j==0)hoge++;
    if(hoge==8) count++;
     
  }
  cout<<count<<endl;
  return 0;
}


Measured memory_bytes: 256
s = input()
r = "".join(reversed(s))
if s != r:
    print("No")
else:
    a = (len(s)-1)//2
    b = (len(s)+3)//2 - 1
    te = "".join(reversed(s[:a]))
    te2 = "".join(reversed(s[b:]))
    if s[:a] == te and s[b:] == te2:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string S;
  cin >> S;
  int N = S.size();
  int min=0;
  int max=0;

  for(int i=0;i<N;i++){
    if(S.at(i) == 'A'){
      min = i;
      break;
    }
  }
  
  for(int i=0;i<N;i++){
    if(S.at(N-i-1) == 'Z'){
      max = N-i;
      break;
    }
  }
   
  cout << max-min;
  
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;int gcd(int a, int b)
{
    if (a < b) {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    
    return b ? gcd(b, a % b) : a;
}

int lcm(int a, int b)
{
    return a * b / gcd(a, b);
}

int main(){
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  ll ans =b-a+1;
  ans-=(b/c)-((a-1)/c);
  ans-=(b/d)-((a-1)/d);
  ll x=(c*d)/__gcd(c,d);
  ans+=(b/x)-((a-1)/x);
  cout<<ans<<endl;

}

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

using namespace std;

#define ll long long
#define endl '\n'

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    cout << (n > 1 ? (n * (n - 1)) / 2 : 0) + (m > 1 ? (m * (m - 1)) / 2 : 0) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int a[1000000];

int pow10(int n){
    int res = 1;
    for(int i = 0; i < n; i++) res *= 10;
    return res;
}

int main()
{
    while(true){
        int n, l;
        cin >> n >> l;
        if(n == 0 && l == 0) break;
        fill(a, a + pow10(l), 0);
        int i = 1;
        while(true){
            if(a[n]) break;
            a[n] = i;
            i++;
            int cmax[6], cmin[6];
            for(int j = 0; j < l; j++){
                cmax[j] = cmin[j] = n % 10;
                n /= 10;
            }
            sort(cmax, cmax + l, greater<int>());
            sort(cmin, cmin + l);
            n = 0;
            for(int j = 0; j < l; j++){
                n = n + pow10(l - 1 - j) * (cmax[j] - cmin[j]);
            }
        }
        cout << a[n] - 1 << " " << n << " " << i - a[n] << endl;
    }
}


Measured memory_bytes: 7068
#include<bits/stdc++.h>
using namespace std;
const int N=5e3+10;
const int mod=1e9+7;

int gi() {
	int x=0,o=1;char ch=getchar();
	while(!isdigit(ch)&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x*o;
}

int add(int a,int b) {
	return a+b>=mod?a+b-mod:a+b;
}

int n,a,b,f[N][N][2],g[N],sum[N][N][2];

int getsum(int i,int j,int k) {
	if(i<0||j<0) return 0;
	if(sum[i][j][k]!=-1) return sum[i][j][k];
	return sum[i][j][k]=add(f[i][j][k],getsum(i-1,j-1,k));
}

int main() {
	cin>>n>>a>>b;if(a>b) swap(a,b);
	memset(sum,-1,sizeof(sum));
	f[0][0][0]=f[0][0][1]=g[0]=1;
	for(int i=1;i<=n;i++)
		for(int j=0;j<b;j++) {
			f[i][j][1]=getsum(i-1,j-1,0);
			if(j) f[i][j][0]=getsum(i-a,j-a,1);
			else for(int k=0;k<a&&k<=i;k++) f[i][j][0]=add(f[i][j][0],g[i-k]);
			g[i]=add(g[i],f[i][j][1]);
		}
	int ans=0;
	for(int i=0;i<b;i++) ans=(0ll+ans+f[n][i][0]+f[n][i][1])%mod;
	int bin=1;
	for(int i=1;i<=n;i++) bin=2ll*bin%mod;
	cout<<(bin-ans+mod)%mod;
	return 0;
}


Measured memory_bytes: 395360
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	int h[n];
	for(int i=0;i<n;i++)
	{
	    cin>>h[i];
	}
	int ans[n];
	ans[0]=0;
	ans[1]=abs(h[1]-h[0]);
	int j,jump;
	for(int i=2;i<n;i++)
	ans[i]=INT_MAX;
	for(int i=2;i<n;i++)
	{
	    for(j=i-1,jump=0;j>=0 && jump<k;j--,jump++)
	    ans[i]=min(ans[i],ans[j]+abs(h[j]-h[i]));
	}
	cout<<ans[n-1]<<"\n";
}
	
	

Measured memory_bytes: 1024
// https://atcoder.jp/contests/abc067/tasks/abc067_b
"use strict";
function Main(input) {
  const params = input.split("\n");
  // const [N, K] = params[0].split(" ").map(Number);
  const K = params[0].split(" ").map(Number)[1];
  const ln = params[1]
    .split(" ")
    .map(Number)
    .sort((a, b) => b - a);

  let len = 0;
  for (let i = 0; i < K; i++) {
    len += ln[i];
  }

  console.log(len);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 21192
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll n, m;

int main(){
	cin >> n >> m;
	if(m%n == 0){cout << n+m << endl;}
	else{cout << m-n << endl;}

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int n,m,a[105],sum[105]={0};
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		sum[i]=sum[i-1]+a[i];
	}
	scanf("%d",&m);
	while(m--){
		int p,x;
		scanf("%d%d",&p,&x);
		printf("%d\n",sum[n]-a[p]+x);
	}
	return 0;
}

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

int main(){
  double L;
  cin >> L;
  double hen = L/3;
  cout << fixed << setprecision(15) << hen*hen*hen << endl;
}

Measured memory_bytes: 3760
#include<algorithm>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(void){
	int n,l,r,ans=0,i;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>l>>r;
		ans+=r-l+1;
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>
#include <climits>
#include <set>
#include <list>
#include <cmath>
#include <map>

using namespace std;
typedef long long ll;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
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;
	}
};

int main()
{
	int S;
	cin >> S;
	int kMax = S / 3;
	
	mint NN[2002];
	NN[0] = 1;
	for(int i = 1; i <= S; i++){
		NN[i] = NN[i-1] * i;
	}
	
	mint ans = 0;
	for(int k = 1; k <= kMax; k++){
		int r = S - k * 3;
		ans += NN[r+k-1] / (NN[r] * NN[k-1]);
	}
	cout << ans.x << endl;
	
	return 0;
}


Measured memory_bytes: 3652
l,r=map(int,input().split())
a=[]
if r//2019!=l//2019 or r%2019==0 or l%2019==0:
	print(0)
else:
	rr=r%2019
	ll=l%2019
	for i in range(ll,rr+1):
		for k in range(ll,rr+1):
			if i<k:
				a.append(i*k%2019)
	print(min(a))


Measured memory_bytes: 75416