akhauriyash/Code-Regression huggingface dataset:
import itertools
N = int(input())
L = map(int, input().split())
ans = 0
for c in itertools.combinations(L, 3):
  c = sorted(c)
  if c[0] < c[1] and c[1] < c[2] and c[0]+c[1] > c[2] and c[1]+c[2] > c[0] and c[2]+c[0] > c[1]:
    ans += 1
    
print(ans)

Measured memory_bytes: 68416
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int n, K;
  cin >> n >> K;
  vl a(n);
  rep(i, n) cin >> a[i];
  ll ans = 1e18;
  rep(k, 1 << n) {
    ll cnt = 0, yen = 0, mh = 0;
    rep(i, n) {
      if(k >> i & 1) {
        yen += max(0LL, mh - a[i] + 1);
        mh = max(mh + 1, a[i]);
        cnt++;
      } else if(mh < a[i]) {
        mh = a[i];
        cnt++;
      }
    }
    if(cnt >= K) ans = min(ans, yen);
  }
  cout << ans << endl;
}

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

int main()
{
	long long int n,m,correct=0,penalty=0;
	cin>>n>>m;
	vector<vector<long long int> >v(n,vector<long long int>(2,0));
	for(long long int i=0;i<m;i++)
	{
		long long int q;
		string s;
		cin>>q>>s;
		q=q-1;
		if(s=="AC")
		{
			if(v[q][0]!=1)
			{
				correct++;
				v[q][0]=1;
			}
		}
		else{
			if(v[q][0]!=1)
			{
				v[q][1]++;
			}
		}
	}
	for(long long int i=0;i<n;i++)
	{
		if(v[i][0]==1)
		{
			penalty=penalty+v[i][1];
		}
	}
	cout<<correct<<" "<<penalty;
	return 0;
}


Measured memory_bytes: 5760
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

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

	vector<int> ans;
	for (int i = 0; i < K; i++)ans.push_back(S);
	int ume = 1000000000;
	if (S == ume)ume--;
	for (int i = 0; i < N - K; i++)ans.push_back(ume);

	for (int i = 0; i < N; i++)cout << ans[i] << " ";
	cout << endl;

	return 0;
}

Measured memory_bytes: 1784
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int h = scan.nextInt();
		int w = scan.nextInt();
		String[] s = new String[h];
		for (int i = 0; i < h; i++) {
			s[i] = scan.next();
		}
		for (int i = 0; i < h; i++) {
			System.out.println(s[i]);
			System.out.println(s[i]);
		}
	}
}


Measured memory_bytes: 22612
/* Bismillahirrahmanirrahim */
/* Author : Jehian Norman Saviero (@Reiva5) */
#include <bits/stdc++.h>
 
// MACROS SAMPAH
#define Jehian using
#define Norman namespace
#define Saviero std
 
Jehian Norman Saviero;
 
// MACROS TYPE
typedef long l;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int,int> pi;
typedef pair<l,l> pl;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<l> vl;
typedef vector<ll> vll;
 
// MACROS FOR PRINT
#define nl printf("\n")
#define sp printf(" ")
 
// MACROS FOR ATTRIBUTE
#define fi first
#define se second
 
// MACROS FOR FUNCTION AND METHOD
#define eb emplace_back
#define mp make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ALL(x) (x).begin(), (x).end()
#define ALLN(x,n) (x), (x)+(n)
#define CUBE(x) (SQR(x)*(x))
#define SET(x,y) for (int _qwe = sizeof(x)/sizeof(x[0]); _qwe; ) x[--_qwe] = (y)
#define SQR(x) ((x)*(x))
#define SSORT(x,sz) sort(ALLN(x,sz))
#define RESET(x) memset((x), 0, sizeof(x))
#define VSORT(x) sort(ALL(x))
 
// MACROS READ INPUT
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%ld", &x)
#define scll(x) scanf("%lld", &x)
#define scul(x) scl(x)
#define scull(x) scll(x)

pll adjust(pll A) {
	if (A.fi == 0) {
		return {0, 1};
	}
	if (A.se == 0) {
		return {1, 0};
	}
	ll gcd = __gcd(A.fi, A.se);
	A = {A.fi/gcd, A.se/gcd};
	return A;
}

map<pll,ll> cnt;

const ll MD = 1e9+7;
inline ll ADD(ll a, ll b) {
	a %= MD;
	b %= MD;
	return (a + b + MD) % MD;
}

inline ll MUL(ll a, ll b) {
	return (a * b) % MD;
}

inline ll powMod(ll a, ll p) {
	ll res = 1;
	for (; p; p >>= 1, a = MUL(a,a)) {
		if (p & 1) res = MUL(res,a);
	}
	return res;
}

map<pll, bool> visited;
ll xceptional = 0;

int main() {
	ll N;
	scll(N);
	for (int i = 0; i < N; ++i) {
		ll A, B;
		scll(A), scll(B);
		if (A == 0 && B == 0) {
			++xceptional;
			continue;
		}
		pll tmp = adjust({A, B});
		++cnt[tmp];
	}
	vector<pll> proc;
	ll asu = 0;
	for (auto &it : cnt) {
		pll curr = it.fi;
		if (visited[curr]) continue;
		visited[curr] = 1;
		ll num = it.se;
		pll anti = adjust({-curr.se, curr.fi});
		visited[anti] = 1;
		if (cnt.find(anti) != cnt.end()) {
			ll num_anti = cnt[anti];
			proc.pb({num, num_anti});
		} else {
			asu += num;
		}
	}
	ll res = 1;
	for (auto &it : proc) {
		res = MUL(res, ADD(ADD(powMod(2, it.fi)-1, powMod(2, it.se)-1),1));
	}
	res = MUL(res, powMod(2, asu));
	printf("%lld\n", ADD(ADD(res, -1), xceptional));
	return 0;
}

Measured memory_bytes: 41240
n = input()
li = []
count = 0
s = ""
for i in range(len(n)):
    if n[i] == "A" or n[i] == "G" or n[i] == "C" or n[i] == "T":
        s += "a"
    else:
        s += "b"
for i in range(len(n)):
    if s[i] == "a":
        count += 1
    else:
        li.append(count)
        count = 0
li.append(count)
print(max(li))

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

int main(){
  string S;
  cin>>S;
  
  int l=S.size();
  int num=1<<(l-1);
  int64_t results=0;
  rep(tmp, num){
    bitset<16> bits(tmp);
    
    int64_t t_sum=0, digit=1;
    // cout<<bits<<endl;
    
    rep(i, l){
      t_sum+=digit*(S[l-1-i]-'0');
      // cout<<i<<' '<<digit*(S[l-1-i]-'0')<<' '<<t_sum<<endl;
      digit = (bits[i]) ? 1 : digit*10;
    }
    // cout<<t_sum<<endl;
    results+=t_sum; 
  }
  cout<<results;
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
//#define int ll
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<string> vst;
typedef vector<vst> vvst;
typedef pair<ld, ld> pld;
typedef complex<double> base;

#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define mp(a,b) make_pair(a,b)
#define modsum(a, b) ((a) + (b) >= M ? (a) + (b) - M : (a) + (b))
#define modsubtract(a, b) ((a) - (b) < 0 ? (a) - (b) + M : (a) - (b))
#define modmultiply(a, b) (((a) * (b)) % M)
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for(int i = 0; i < int(n); ++i)
#define cint const int &
#define SZ(a) ((int)(a.size()))
#define watch(x) cout << (#x) << " = " << x << endl;

const double PI = 2 * acos(0.0);

const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";


template<class T>
ostream & operator << (ostream &out, vector<T> &a) {
    out << "(";
    for (auto x : a) out << x << " ";
    return out << ")";
}

void smain();

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


#ifdef MAX_HOME
    freopen("input.txt", "r", stdin);
    clock_t start = clock();
#endif
    cout << setprecision(12) << fixed;
    smain();
#ifdef MAX_HOME
    cout << "\n\n\n\n";
    cout << "TOTAL EXECUTION TIME: " << float( clock () - start ) /  CLOCKS_PER_SEC << endl;
#endif
}





void smain() {

    ll a, b, c;
    cin >> a >> b >> c;
    ll m = min(b, c);
    ll ans = 2LL * m;
    b -= m;
    c -= m;
    m = min(c, a);
    ans += m;
    c -= m;
    a -= m;
    ans += b;
    b = 0;
    ans += min(c, 1LL);
    cout << ans;
}

Measured memory_bytes: 256
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input()) # n=1
def inpm(): return map(int,input().split()) # x=1,y=2
def inpl(): return list(map(int, input().split())) # a=[1,2,3,4,5,...,n]
def inpls(): return list(input().split())  # a=['1','2','3',...,'n']
def inplm(n): return list(int(input()) for _ in range(n)) # x=[] 複数行
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return sorted([list(map(int, input().split())) for _ in range(n)]) # [[1,1,1,1],[2,2,2,2],[3,3,3,3]] 

def main():
    n = list(input())
    l = len(n)
    ans = 0
    for i in range(l):
        n[i] = int(n[i])
    for i in range(l-1,-1,-1):
        if n[i] <= 4:
            ans += n[i]
        elif n[i] == 5 and (i == 0 or n[i-1] <= 4):
            ans += n[i]
        else:
            ans += 10 - n[i]
            n[i] = 0
            if i != 0:
                n[i-1] += 1
        if i == 0 and n[i] == 0:
            ans += 1
    print(ans)

if __name__ == "__main__":
    main()

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  string S;
  cin >> N;
  cin >> S;
  if (N % 2 == 1) {
    cout << "No" << endl;
    return 0;
  }
  if (S.substr(0, N / 2) == S.substr(N / 2)) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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


public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        char[] element = new char[N];
        String S = sc.next();
        for(int i=0;i<N;i++){
            element[i] = S.charAt(i);
        }
        ArrayList<Character> result = new ArrayList<>();
        int l = 0;
        for(int i=0;i<N;i++){
            if(element[i] == '('){
                l++;
                result.add('(');
            }
            else{
                if(l>0){
                    l--;
                    result.add(')');
                }
                else{
                    result.add(')');
                    result.add(0,'(');
                }
            }
        }
        for(int i=0;i<l;i++){
            result.add(')');
        }
        for(char e : result){
            System.out.print(e);
        }
    }
}

Measured memory_bytes: 23892
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl

const ll mod = 1e9 + 7;
const ll inf = 1e18;

int unit_sum(int n){
    int sum = 0;
    while(n > 0){
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

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

    // input
    int N, A, B;
    cin >> N >> A >> B;

    int answer = 0;
    FOR(i, 1, N+1){
        int sum = unit_sum(i);
        if(A<=sum && sum <= B){
            answer += i;
        }
    }   

    p(answer);
    return 0;
}

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

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const vector<T> &v) {
    for (auto e : v) cout << e << ' ';
    cout << endl;
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

void solve() {
    int N, C; cin >> N >> C;
    vector<vector<int> > D(C+1, vector<int>(C+1));
    for (int i = 1; i <= C; i++) {
        for (int j = 1; j <= C; j++) {
            cin >> D[i][j];
        }
    }

    vector<vector<int> > costs(3, vector<int>(C+1));
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            int c; cin >> c;
            for (int k = 1; k <= C; k++) {
                costs[(i+j)%3][k] += D[c][k];
            }
        }
    }

    int ans = 1000000000;
    for (int i = 1; i <= C; i++) {
        for (int j = 1; j <= C; j++) {
            for (int k = 1; k <= C; k++) {
                if (i == j || j == k || k == i) continue;
                int tmp = costs[0][i] + costs[1][j] + costs[2][k];
                ans = min(ans, tmp);
            }
        }
    }

    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    solve();

    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <cstdint>
#include <unordered_set>
#include <ctime>
typedef long long int llint;

int main(void){

  int n;
  std::cin >> n;
  std::vector<std::array<int, 2> > ranges(n); // ed & st
  for(int i=0; i<n; i++){
    int x,l;
    std::cin >> x >> l;
    ranges[i][1] = std::max(x-l, 0);
    ranges[i][0] = x+l;
  }
  std::sort(ranges.begin(), ranges.end());

  int now = -1;
  int count = 0;
  for(int i=0; i<n; i++){
    if(ranges[i][1]>=now){
      count++;
      now = ranges[i][0];
    }
  }
  std::cout << count << std::endl;

  
  return 0;
}


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

int main()
{
    string s;
    cin >> s;
    sort(all(s));
    string ans = "No";
    if (s[0] == s[1] && s[2] == s[3] && s[1] != s[2])
        ans = "Yes";
    cout << ans << endl;
    return 0;
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);

    int n;
    cin >> n;

    vector<vector<int>> a(n,vector<int>(3));
    rep(i,n)rep(j,3) cin >> a[i][j];

    vector<vector<int>> dp(n,vector<int>(3));
    rep(i,3) dp[0][i] = a[0][i];

    for(int i = 1; i < n; i++){
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 3; k++){
                if(j == k) continue;
                dp[i][k] = max(dp[i][k],dp[i-1][j] + a[i][k]);
            }
        }
    }
    int ans = 0;
    rep(i,3) ans = max(ans,dp[n-1][i]);
    cout << ans << endl;
}



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

map<int,int> v;
map<int,int> u;
int main()
{
    int n , m , flag = 0;

    cin >> n >> m;

    for(int i = 1 ; i<=m ; i++)
    {
        int x , y;

        cin >> x >> y;

        if(x==1)
        {
            if(v[y]==1)
                flag = 1;
            v[y]=1;
        }
        if(y==n)
        {
            if(v[x]==1)
                flag = 1;
            v[x]=1;
        }
    }

    if(flag)
        cout << "POSSIBLE";
    else
        cout << "IMPOSSIBLE";
    return 0;
}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;cin>>N;
  vector<int>v(N);
  vector<string>Q(N);
  for(int X=0;X<N;X++){
    cin>>v[X];
  }
  string rast="";
  if(v[0]<v[1]){
      Q[0]="kai";
      rast="kai";
  }
  for(int X=0;X<N;X++){
    if(X>0&&X<N-1){
      if(v[X]>=v[X-1]&&v[X]>v[X+1]){
        Q[X]="uri";
        rast="uri";
      }
      else if(v[X]<=v[X-1]&&v[X]<v[X+1]){
        Q[X]="kai";
        rast="kai";
      }
    }
    else if(X==N-1&&rast=="kai"){
      Q[X]="uri";
    }
  }
  long long kabu=0;
  long long kane=1000;
  for(int X=0;X<N;X++){
    if(Q[X]=="kai"){
      if(kabu==0){
        kabu+=kane/v[X];
        kane-=kabu*v[X];
      }
    }
    else if(Q[X]=="uri"){
      kane+=kabu*v[X];
      kabu=0;
    }
  }
  cout<<kane<<endl;
}

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

typedef unsigned int ull;

const ull B1 = 9973;
const ull B2 = 100000007;

int main()
{
  int i, h, w, r, c, j;
  ull t1, t2, e;
  fscanf(stdin, "%d %d\n", &h, &w);
  char a[h][w+3];
  for (i=0; i<h; i++)  fgets(a[i], w+2, stdin);
  fscanf(stdin, "%d %d\n", &r, &c);
  char b[c+3];
  ull bh, tmp;
  bh = 0;
  t2 = 1;
  for (i=0; i<r; i++) {
    fgets(b, c+2, stdin);
    tmp = 0;
    for (j=0; j<c; j++) tmp = tmp * B1 + b[j];
    bh = bh * B2 + tmp;
    t2 *= B2;
  }

  ull *tmp2 = (ull*)malloc(sizeof(ull)*h*w);
  
  for (j=0; j<w; j++) {
    e = a[0][j];
    for (i=1; i<r; i++)   e = e * B2 + a[i][j];
    for (i=0; i+r<=h; i++) {
      *(tmp2+i*w+j) = e;
      if (i+r<h) e = e * B2 - t2 * a[i][j] + a[i+r][j];
    }
  }
  t1 = B1;
  for (i=1; i<c; i++) t1 *= B1;
  for (i=0; i+r<=h; i++) {
    e = *(tmp2+i*w);
    for (j=1; j<c; j++)  e = e*B1 + *(tmp2+i*w+j);
    for (j=0; j+c<=w; j++) {
      if (e==bh) printf("%d %d\n", i, j);
      if (j+c<w) e = e*B1 - t1 * *(tmp2+i*w+j) + *(tmp2+i*w+j+c);
    }
  
  }
  return 0;
}



Measured memory_bytes: 6636
// GRL_1_A????????????
// ????????????????????? + ????????????????????????

#include <iostream>
#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 <climits>
#include <ctime>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF INT_MAX

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

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

// ????????¨???????????????????¨???????????§???????
struct Edge {
    int to, cost;
    Edge(int s, int d) : to(s), cost(d) {}
};

// 1??????????????????????????????????????±????????????????????????????????? vector
// Edges????????????????????????????????????????????°??????????????????
typedef vector<Edge> Edges;

// ???????????±??????????????? vector
// Graph??????????????????????????°?????????????????§??? V ??§?????????
typedef vector<Edges> Graph;

vector< vector<int> > warshall(Graph &G) {
    int V = G.size();
    vector< vector<int> > d(V);
    rep(i,0,V) rep(j,0,V) {
        if(i == j) d[i].push_back(0);
        else d[i].push_back(INF);
    }

    rep(i,0,V) rep(j,0,G[i].size()) {
        Edge e = G[i][j];
        d[i][e.to] = e.cost;
    }

    rep(k,0,V) rep(i,0,V) rep(j,0,V)
        if(d[i][k] != INF && d[k][j] != INF)
            d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    return d;
}

namespace std {
    bool operator<(const P a, const P b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int main() {
    int V, E;
    cin >> V >> E;
    Graph G(V);
    int s, t, d;
    rep(i,0,E) {
        cin >> s >> t >> d;
        G[s].push_back(Edge(t,d));
    }
    vector< vector<int> > ans = warshall(G);
    bool minus = false;
    rep(i,0,V) if(ans[i][i] < 0) minus = true;

    /*
    rep(i,0,V) {
        rep(j,0,V) {
            if(ans[i][j] >= INF) cout << "INF ";
            else printf("%3d ", ans[i][j]);
        }
        cout << endl;
    }
    */

    if(minus) cout << "NEGATIVE CYCLE" << endl;
    else {
        rep(i,0,V) {
            rep(j,0,V) {
                if(j == 0) {
                    (ans[i][j] >= INF) ? cout << "INF" : cout << ans[i][j];
                }
                else {
                    (ans[i][j] >= INF) ? cout << " INF" : cout << " " << ans[i][j];
                }
            }
            cout << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1372
import java.util.*;
import java.io.*;
//atcoder
public class Main {
    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        int n = scanner.nextInt();
        TreeMap<Integer, Integer> mapping = new TreeMap<>();
        for(int i = 0; i < (1 <<n); i++) {
            int next = scanner.nextInt();
            if (!mapping.containsKey(next)) mapping.put(next, 0);
            mapping.put(next, mapping.get(next) + 1);
        }
        ArrayList<Integer> list = new ArrayList<>();
        list.add(mapping.lastKey());
        mapping.put(list.get(0), mapping.get(list.get(0))-1);
        if (mapping.get(list.get(0)) != 0) {
            System.out.println("No");
            return;
        }
        else mapping.remove(list.get(0));
        for(int round = 1; round <= n; round++) {
            int sz = list.size();
            for(int j = 0; j < sz; j++) {
                int i = list.get(j);
                Integer lower = mapping.lowerKey(i);
                if (lower == null) {
                    System.out.println("No");
                    return;
                }
                else {
                    mapping.put(lower, mapping.get(lower)-1);
                    if (mapping.get(lower) == 0) mapping.remove(lower);
                    list.add(lower);
                }
            }
        }
        out.println("Yes");
        out.flush();
    }
    
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        
        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }
        
        public FastScanner() {
            this(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
        
        String readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 83264
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <bitset>
using namespace std;
using ll = long long;

class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x<lhs.x;}void operator++(){++x;}};I i,n;
public:range(int n):i({0}),n({n}){}range(int i,int n):i({i}),n({n}){}I& begin(){return i;}I& end(){return n;}};

typedef bitset<2024> B;

int main() {
  int N, K;
  while (cin >> N >> K) {
    vector<vector<int>> g(N);
    for (int i : range(N - 1)) {
      int a, b;
      cin >> a >> b;
      a--;
      b--;
      g[a].push_back(b);
      g[b].push_back(a);
    }

    vector<B> bs(N);
    for (int i : range(N)) {
      queue<pair<int, int>> q;
      q.push({i, 0});
      while (!q.empty()) {
        int v = q.front().first;
        int d = q.front().second;
        q.pop();

        if (bs[i][v]) continue;
        bs[i][v] = 1;

        if (d >= K / 2) continue;
        for (int u : g[v]) {
          if (bs[i][u]) continue;
          q.push({u, d + 1});
        }
      }
    }

    int res = N;
    for (int i : range(N)) {
      if (K % 2 == 0) {
        res = min(res, N - static_cast<int>(bs[i].count()));
      } else {
        for (int j : g[i]) {
          res = min(res, N - static_cast<int>((bs[i] | bs[j]).count()));
        }
      }
    }

    cout << res << endl;
  }
}


Measured memory_bytes: 896
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
#define pb push_back
#define inf 10000000000000000
#define N 1000000007
#define speed ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
template<class L,class R> ostream& operator<<(ostream& cout,pair<L, R> P)
{return cout<<'('<<P.x<<','<< P.y<<')';}
template<class T> ostream& operator<<(ostream& cout,vector<T> V)
{cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';}


int get(vector<vector<int> > inp, int k)
{
	int n=inp.size();
	int m=inp[0].size();
	vector<int> sums(n,0);
	int ret=0;
	for(int i=0;i<m;++i)
	{
		bool bl=0;
		for(int j=0;j<n;++j)
		{
			if(sums[j]+inp[j][i]>k){bl=1;}
		}
		if(bl==1)
		{
			++ret;
			for(int j=0;j<n;++j)
			{
				sums[j]=inp[j][i];
			}
		}
		else
		{
			for(int j=0;j<n;++j)
			{
				sums[j]+=inp[j][i];
			}	
		}
	}
	return ret;
}
//edge cases when n=1 , m=1. wrong variable in loop. if<->while
signed main()
{
	speed
	int h,w,k;cin>>h>>w>>k;
	vector<string>str(h);
	for (int i = 0; i < h; ++i)
	{
		cin>>str[i];
	}
	vector<vector<int> > inp(h,vector<int> (w));
	for(int i=0;i<h;++i)
	{
		for(int j=0;j<w;++j)
		{
			inp[i][j]=(str[i][j]=='1');
		}
	}
	int lim=((1<<(h-1)));
	int ans=inf;
	for(int mask=0;mask<lim;++mask)
	{
		bool bl=1;
		
		vector<int> v;
		for(int bit=0;bit<(h-1);++bit)
		{
			if((1<<bit)&mask)
			{
				v.push_back(bit+1);
			}
		}
		int tans=v.size();
		v.push_back(h);
		int row=0;
		vector<vector<int> > vecs;
		for(auto it:v)
		{
			vector<int> r(w,0);
			while(row<it)
			{
				for(int i=0;i<w;++i)
				{
					r[i]+=inp[row][i];
					if(r[i]>k){bl=0;}
				}
				++row;
			}
			int tmp=0;
			if(bl==0){break;}
			vecs.push_back(r);
		}
		if(bl==0){continue;}
		tans+=get(vecs,k);
		ans=min(ans,tans);
	}
	cout<<ans<<"\n";

}

Measured memory_bytes: 560
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

vector<int> parse(int n, string& s) {
    char c = s[0];
    int tmp = 1;
    vector<int> res;
    for (int i = 1; i < n; i++) {
        if (s[i] != c) {
            c = s[i];
            res.push_back(tmp);
            tmp = 1;
        } else {
            tmp++;
        }
    }
    res.push_back(tmp);
    return res;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int ans = parse(s.size(), s).size() - 1;
	cout << ans << endl;
	return 0;
}

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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

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

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    string str; cin >> str;
    ll n = str.size();
    reverse(str.begin(), str.end());
    ll dp[n+1][2]; // dp[i][0]: nocarry, dp[i][1]: carry
    dp[0][0] = 0; dp[0][1] = 1e18;
    for(int i=0;i<n;i++){
        ll d = ll(str[i] - '0');

        if(d == 9){
            dp[i+1][0] = dp[i][0] + d;
        }else{
            dp[i+1][0] = min(dp[i][0] + d, dp[i][1] + d + 1);
        }
        dp[i+1][1] = min(dp[i][0] + (10 - d), dp[i][1] + (10 - (d + 1)));
    }
    cout << min(dp[n][0], dp[n][1] + 1) << endl;
}

Measured memory_bytes: 17052
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    s1 = input()
    s2 = input()
    s3 = input()
    print(s1[0]+s2[1]+s3[2])
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 3828
#pragma GCC optimize("Ofast")  
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define int long long 
#define endl "\n"
#define all(x) (x).begin(),(x).end()
const int MOD = 1e9+7;
const int mxN = 2e5+3;

void solve(){
	int x;
	cin >> x;
	if(x >= 400 and x <= 599)cout << 8 << endl;
	else if(x >= 600 and x <= 799)cout << 7 << endl;
	else if(x >= 800 and x <= 999)cout << 6 << endl;
	else if(x >= 1000 and x <= 1199)cout << 5 << endl;
	else if(x >= 1200 and x <= 1399)cout << 4 << endl;
	else if(x >= 1400 and x <= 1599)cout << 3 << endl;
	else if(x >= 1600 and x <= 1799)cout << 2 << endl;
	else cout << 1 << endl;
}

int32_t main(){
	IO;
	
	int nT = 1;
	//cin >> nT;
	for(int i = 1; i <= nT; ++i)
		solve();
	return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <limits>
#include <iomanip>

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define in(v) cin>>v;
#define out(v) cout<<v<<"\n"
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

  int l[N+2], r[N+2], v[N+2];
  l[0] = l[1] = 0;
  r[0] = 0;
  rep(i, N) {
    int t; in(t);
    l[i+2] = r[i+1] = t + l[i+1];
  }
  int T = r[N];
  l[N+1] = r[N+1] = T;

  v[0] = v[N+1] = 0;
  rep(i, N)
    in(v[i+1]);

  double ans = 0;
  rep(a, 2*T) {
    double v_x = numeric_limits<double>::max();
    rep(i, N+2) {
      auto v_a = [&](int a) {
        if (a <= 2 * l[i])
          return (double)v[i]+(l[i]-a/2.0);
        else if (2*l[i] <= a && a <= 2*r[i])
          return (double)v[i];
        else
          return (double)v[i]+(a/2.0-r[i]);
      };
      chmin(v_x, 0.25*(v_a(a) + v_a(a+1)));
    }
    ans += v_x;
  }
  out(fixed << setprecision(15) << ans);

  return 0;
}


Measured memory_bytes: 256
n, t_limit= map(int, input().split())
cost = []
time = []
for i in range(n):
    c, t = map(int, input().split())
    if t <= t_limit:
        cost.append(c)
        time.append(t)

if len(time)==0:
    print("TLE")
else:
    print(min(cost))

Measured memory_bytes: 3060
s = input()
letter = set(s)

for x in letter:
    tmp1 = ''
    tmp2 = ''
    for i in range(len(s)):
        if s[i] == tmp1:
            print(i, i+1)
            exit()
        elif s[i] == tmp2:
            print(i-1, i+1)
            exit()
        else:
            tmp2 = tmp1
            tmp1 = s[i]
else:
    print(-1, -1)


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int INF=1001001001;
const int INFLL=1001001001001001001ll;
const int mod=1000000007;
inline void am(int &a,int b){
    a+=b;
    if(a>=mod)a-=mod;
}
signed main(){
    int N,M;
    cin>>N>>M;
    if(N>M)swap(N,M);
    if(M-N>1){
        cout<<0<<endl;
        return 0;
    }

    int f=1;
    for(int i=1;i<=N;i++)f=f*i%mod;

    if(N==M){
        cout<<f*f%mod*2%mod<<endl;
    }
    else{
        cout<<f*f%mod*M%mod<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <memory.h>
#include <functional>


using namespace std;
static const double EPS = 1e-9;
typedef long long ll;
typedef unsigned long long ull;
#define rep(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a,0,sizeof(a))
#define minus(a) memset(a,0xff,sizeof(a))
#define chmax(a,b) a=min((a),(b))
#define chmin(a,b) a=max((a),(b))


#define MOD 1000000007


typedef pair<int,int> P;														// pairは小文字



class uf {
public:
	vector<int> par;//
	vector<int> level;

	void init(int n) {
		par.resize(n);
		level.resize(n);
		rep(i, n) {
			par[i] = i;
			level[i] = 0;
		}

	}

	int find(int x) {
		if (par[x] == x)
			return x;
		else {
			return par[x] = find(par[x]);
		}
	}

	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y)return;

		if (level[x] < level[y])
			par[x] = y;
		else {
			par[y] = x;
		}
		if (level[x] == level[y])level[x]++;

	}

	bool same(int x, int y) {
		return find(x) == find(y);
	}
};

int n, k, l;

int main(){
	int a, b;
	scanf("%d %d %d ", &n, &k, &l);
	uf uf1, uf2;
	uf1.init(n); uf2.init(n);
	rep(i, k) {
		scanf("%d %d ", &a, &b);
		a--; b--;//
		uf1.unite(a, b);
	}
	rep(i, l) {
		scanf("%d %d ", &a, &b);
		a--; b--;
		uf2.unite(a, b);
	}
	map<P, int> m;
	rep(i, n) {
		a = uf1.find(i);
		b = uf2.find(i);
		m[P(a, b)]++;
	}
	rep(i, n) {
		a = uf1.find(i);
		b = uf2.find(i);
		cout << m[P(a, b)] << " ";
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 15104
def main():
    N = int(input())
    A = sorted([int(value) for value in input().split(" ")], reverse=True)
    result = 1
    if 0 in A:
        print(0)
        exit()
    for value in A:
        result *= value
        if result>10**18:
            print(-1)
            exit()
    
    print(result)


if __name__=="__main__":
    main()

Measured memory_bytes: 21644
#include<iostream>
#include<limits.h>
#define SENTINEL INT_MAX //SENTINELをとても大きい値で初期化する
using namespace std;
typedef long long ll;
ll counter=0;
void Merge(long long S[],int left,int mid,int right){//擬似コードに従った、Merge
  int n1 = mid-left;
  int n2 = right-mid;
  ll L[n1+1];
  ll R[n2+1];

  for(int i=0;i<n1;i++){
    L[i] = S[left+i];
  }
  for(int i=0;i<n2;i++){
    R[i]=S[mid+i];
  }
  L[n1]=R[n2]=SENTINEL;//番兵設置
  int i=0;
  int j=0;
  for(int k=left;k<right;k++){
    if(L[i]<=R[j]){
      S[k]=L[i];
      i=i+1;
      counter++;
    }
    else{
      S[k]=R[j];
      j=j+1;
      counter++;
    }
  }
}

void Merge_Sort(long long S[],int left,int right){//擬似コードに従った,Merge_Sort
 
  if(left+1<right){
    int mid = (left+right)/2;
    Merge_Sort(S,left,mid);
    Merge_Sort(S,mid,right);
    Merge(S,left,mid,right);
  }
}



int main(){
  int n;
  ll S[600000];

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

    Merge_Sort(S,0,n);

    for(int i=0;i<n;i++){
      cout << S[i];
      if(i != n-1)cout << " ";
    }
    cout << endl;
    cout << counter << endl;

  return 0;
}

Measured memory_bytes: 8680
#include <bits/stdc++.h>
using namespace std;
using pp=pair<int, int>;

int main() {
  int N;
  string S;
  cin >> N >> S;
  int m=0;
  for (int i=0; i<N; i++) {
    set<char> E;
    for (int j=0; j<i; j++) {
      for (int k=i; k<N; k++) {
        if (S[j]==S[k]) {
          E.insert(S[j]);
        }
      }
    }
    m=max(m, (int)E.size());
  }
  cout << m << endl;
 }


Measured memory_bytes: 3640
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef pair<int, int> PI;
/*
 * Union-Find tree
 * header requirement: vector
 */
class UnionFind {
private:
  std::vector<int> disj;
  std::vector<int> rank;
public:
  UnionFind(int n) : disj(n), rank(n) {
    for (int i = 0; i < n; ++i) {
      disj[i] = i;
      rank[i] = 0;
    }
  }
  int root(int x) {
    if (disj[x] == x) {
      return x;
    }
    return disj[x] = root(disj[x]);
  }
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) {
      return;
    }
    if (rank[x] < rank[y]) {
      disj[x] = y;
    } else {
      disj[y] = x;
      if (rank[x] == rank[y]) {
	++rank[x];
      }
    }
  }
  bool is_same_set(int x, int y) {
    return root(x) == root(y);
  }
};


int main(void) {
  int n, m;
  cin >> n >> m;
  vector<PI> edges;
  REP(i, 0, m) {
    int u, v;
    cin >> u >> v;
    edges.push_back(PI(u - 1, v - 1));
  }
  int tot = 0;
  REP(i, 0, m) {
    UnionFind uf(n);
    REP(j, 0, m) {
      if (j == i) { continue; }
      uf.unite(edges[j].first, edges[j].second);
    }
    set<int> conn;
    REP(i, 0, n) {
      conn.insert(uf.root(i));
    }
    if (conn.size() > 1) tot += 1;
  }
  cout << tot << endl;
}


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int l = A + B;
  int r = C + D;
  if(l > r) {
    cout << "Left" << endl;
  } else if(l < r) {
    cout << "Right" << endl;
  } else {
    cout << "Balanced" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
numk={1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}
dp=[0]+[-1]*(N+1)
for i in range(N):
    for j in A:
        if i+numk[j]<=N:
            dp[i+numk[j]]=max(dp[i+numk[j]],dp[i]+1)
m=N
ans=[]
while m>0:
    for i in A:
        if m-numk[i]>=0 and dp[m-numk[i]]+1==dp[m]:
            ans.append(str(i))
            m-=numk[i]
            break
print(''.join(ans))

Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll tmp1,tmp2,tmp3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;
void swap(ll *x,ll *y){
  ll tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}

int main(){
  ll n;
  string s;
  cin >> n;
  cin >> s;
  string tmp = "";
  ll sum = 0;
  rep(i,10){
    rep(j,10){
      rep(k,10){
        tmp = "";
        tmp = to_string(i) + to_string(j) + to_string(k);
        ll argstr = 0;
        bool can = false;
        rep(l,n){
          if(s[l] == tmp[argstr]){
            argstr++;
            if(argstr == 3){
              can = true;
              break;
            }
          }
        }
        if(can){sum++;}

      }
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>

using namespace std;
typedef long long ll;

int gcd(int x, int y) {
  if (x < y) swap(x, y);
  while (y > 0) {
    int r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//for(int i = ; i < ; i++){}

int main(){
    int a,b;
    cin>>a>>b;
    int d = b-a;
    int sum = 0;
    for(int i = d; i>0; i--){
        sum+=i;
    }
    cout<<sum-b<<endl;
    return 0;
}


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

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

  vector<char> S(N);
  for(int i = 0; i < N; i++)
    cin >> S.at(i);


  if(S.at(K-1) == 'A') S.at(K-1) = 'a';
  else if(S.at(K-1) == 'B') S.at(K-1) = 'b';
  else S.at(K-1) = 'c';

  for(int i = 0; i < N; i++)
    cout << S.at(i);
  cout << endl;
}

Measured memory_bytes: 256
/**
*    author:  souzai32
*    created: 02.08.2020 18:27:17
**/

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

int main() {

    int n;
    cin >> n;
    vector<int> b;
    int a;

    rep(i,n){
        cin >> a;
        if(i%2){
            b.push_back(a);
        }
        else{
            auto it=b.begin();
            it=b.insert(it,a);
        }
    }
    if(n%2==0) reverse(b.begin(),b.end());

    rep(i,n-1) cout << b.at(i) << ' ';
    cout << b.at(n-1) << endl;

    return 0;
}

Measured memory_bytes: 4296
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c;
    cin>>a>>b>>c;
    cout<<min(min(a+b,b+c),c+a)<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<math.h>
using namespace std;
int main() {
	int N, K;	cin >> N >> K;
	vector<int> l(N);
	for (int i = 0; i < N; ++i) {
		cin >> l[i];
	}
	sort(l.rbegin(), l.rend());
	int ans = 0;
	for (int i = 0; i < K; ++i) {
		ans += l[i];
	}
	cout << ans << endl;
	cin >> N;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    
    
double x, y, z, v;

	scanf("%lf%lf%lf%lf", &x, &y, &z, &v);

double s = ((z - x)*(z - x) + (v - y)*(v - y));

	printf("%lf\n", pow(s, 0.5));

    return 0;
}


Measured memory_bytes: 2052
import java.lang.*;
import java.io.*;
import java.math.*;

public class Main{
    public static void main(String[] args)throws IOException{
	InputStreamReader isr = new InputStreamReader(System.in);
	BufferedReader br=new BufferedReader(isr);
	int r;
	boolean flag = true;
	double x=0,y=0,theta=0;
	String stL= br.readLine();
	String[] st =stL.split(",");
	r = Integer.parseInt(st[0]);
	if("0".equals(st[0])&&"0".equals(st[1]))
	    flag=false;
	while(flag){
	    x+=r*(Math.cos(theta));
	    y+=r*(Math.sin(theta));
	    theta+=Math.toRadians(Integer.parseInt(st[1]));
	    stL =br.readLine();
	    st = stL.split(",");
	    r=Integer.parseInt(st[0]);
	    if("0".equals(st[0])&&"0".equals(st[1]))
		flag=false;
	    
	}
	System.out.println((int)y);
	System.out.println((int)x);
    }
}

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

int main() {
    int N;
    cin >> N;
    string s;
    int a;
    //Restaurantというペア型（string,int）の配列を用意して
    //入力の値（市の名前 , 点数）を順番にRestaurant配列へ登録していく
	vector<pair<string , int>> Restaurant;
    for(int i = 0; i < N; i++){
        cin >> s >> a;
    	Restaurant.push_back(make_pair(s, a));
    }
    pair<string , int> temp; //Restaurant配列の中身を一時的に保存するためのペア型の変数
    int count; //N個のレストランの中の何番目なのかを表す変数
    vector<int> Result(N); //入力の値（市の名前 , 点数）が何番目なのかを記録するための配列
    for(int i = 0; i < N; i++){
        count = 1;
    	temp = Restaurant.at(i);
        for(int j = 0; j < N; j++){
            //それぞれの市の名前を比較して、tempの市名がRestaurant.at(i)の市名より、辞書順で後だったらcountを1増やす
        	if(temp.first > Restaurant.at(j).first ){
            	count++;
            }
            //もしtempの市名とRestaurant.at(i)の市名が同じだった場合に、
            //tempの点数がRestaurant.at(i)の点数より低かったらcountを1増やす
            else if(temp.first == Restaurant.at(j).first){
            	if(temp.second < Restaurant.at(j).second){
                	count++;
                }
            }
        }
        //入力の値（市の名前 , 点数）が何番目なのかを記録する
        Result.at(i) = count;
    }
    //入力の値（市の名前 , 点数）の中で順位の早いものから[要素番号 + 1] の値を出力していく
    for(int i = 0; i < N ; i++){
    	for(int j = 0; j < N; j++){
        	if(Result.at(j) == i + 1){
            	cout << j + 1 << endl;
            }
        }
    }
}

Measured memory_bytes: 3576
"""
https://abc094.contest.atcoder.jp/tasks/abc094_b
"""
[n,m,x]=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
b=0
c=0
for i in a:
    if 0<i and i<x:
        b=b+1
    if x<i and i<n:
        c=c+1
print(min(b,c))


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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int n,k; cin >> n >> k;
  vector<int> l(n); rep(i,n) cin >> l[i];
  sort(l.begin(),l.end());
  reverse(l.begin(),l.end());

  int ans = 0;
  rep(i,k) ans += l[i];

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


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

int main() {
    int N;
    cin >> N;
    vector<int>A(N);
    for (int i = 0; i < N; ++i) {
      cin >> A[i];
    }
    double ans = 0;
    for (int i = 0; i < N; ++i) {
        ans = ans + 1.0 / A[i];
    }
    ans = 1.0 / ans;
    cout << setprecision(10) << ans;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int mod = 1e9 + 7;
const int MAX = 510000;
const int V = 100005;
ll dy[8] = {1,0,-1,0,1,-1,1,-1};
ll dx[8] = {0,1,0,-1,1,-1,-1,1};

int main(){
    ll h,w; cin >> h >> w;
    char s[h+2][w+2];
    rep(i,h+2) rep(j,w+2) s[i][j] = '.';
    rep(i,h){
        rep(j,w) cin >> s[i+1][j+1];
    }
    char ans[h][w];
    rep(i,h){
        rep(j,w){
            if(s[i+1][j+1]=='#'){
                ans[i][j] = '#';
                continue;
            }
            ll cnt = 0;
            rep(k,8){
                if(s[i+1+dy[k]][j+1+dx[k]]=='#') cnt++;
            }
            ans[i][j] = cnt + '0';
        }
    }
    rep(i,h){
        rep(j,w) cout << ans[i][j];
        cout << endl;
    }
}

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 int ll;
typedef pair<int, int> P;
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; }

map<ll, ll> prime_factor(ll n){
	map<ll, ll> res;
	for(ll i = 2; i*i <= n; i++){
		while(n%i == 0){
			res[i]++;
			n /= i;
		}
	}
	if(n != 1) res[n] = 1;
	return res;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	map<ll, ll> mp;
	for(int i = 1; i <= n; ++i){
		for(auto p : prime_factor(i)){
			mp[p.first] += p.second;
		}
	}
	int c3 = 0, c5 = 0, c15 = 0, c25 = 0, c75 = 0;
	for(auto p : mp){
		if(p.second >= 74) ++c75;
		if(p.second >= 24) ++c25;
		if(p.second >= 14) ++c15;
		if(p.second >= 4) ++c5;
		if(p.second >= 2) ++c3;
	}
	ll ans = c75 + c25 * (c3 - 1) + c15 * (c5 - 1) + c5 * (c5 - 1) * (c3 - 2) / 2;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256