akhauriyash/Code-Regression huggingface dataset:
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
int n, m;
vector<int> a;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    //同じ数で一個のグループができたら死
    int maxa=0, mina=INF;
    map<int,int> m;
    for (int i = 0; i < n; i++)
    {
        int temp;
        cin >> temp;
        a.push_back(temp);
        m[temp]++;
        chmax(maxa,temp);
        chmin(mina,temp);
    }
    sort(ALL(a));
    if(maxa-mina>1)return no,0;
    if(maxa-mina==0){
        if(a[0]==n-1)return yes,0;
        if(n/a[0]>=2){
            return yes,0;
        }
    }
    else{
        if(m[a[n-1]]<2){
            return no,0;
        }
        if(m[a[0]]+m[a[n-1]]/2>=a[n-1]&&m[a[0]]+1<=a[n-1])return yes,0;
    }
    no;
}



Measured memory_bytes: 5368
#include<iostream>
#include<vector>
#include<string>
#include<cmath>


using namespace std;



int main() {
	string s;
	cin >> s;
	int count = 0;
	int maxcount = 0;

	for (int i = 0; i < s.size(); i++) {
		count = 0;
		for (int j = i; j < s.size(); j++) {
			if (s[j] == 'A' || s[j] == 'C' || s[j] == 'G' || s[j] == 'T') {
				count += 1;
			}
			else
			{
				if (count > maxcount)
					maxcount = count;

				break;
			}
		}
		if (count > maxcount)
			maxcount = count;
	}

	cout << maxcount;
}

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

using namespace std;
static const int N = 100;

void printArray(int a[], int n){
    int k = 0;
    while(1){
        if(k==n-1) break;
        else{
            printf("%d ", a[k]);
        }
        k++;
    }
    printf("%d\n", a[n-1]);
}

int main(int argc, char const *argv[])
{
    int A[N];
    int v,j,n;

    cin >> n;

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

    printArray(A, n);
    for (int i = 1; i < n; ++i)
    {
        v = A[i];
        j = i-1;
        while(j>=0 && A[j]>v) {
            A[j+1] = A[j];
            A[j] = v;
            j--;
        }
        printArray(A,n);
    }

    return 0;
}

Measured memory_bytes: 1144
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector<int> X(N);
    REP(i, N){
        cin >> X[i];
    }

    int max_por = MAX(X), min_por = MIN(X);

    ll res = 0, ans = 1e+9;
    FOR(i, min_por, max_por){
        res = 0;
        REP(j, N){
            res += pow(X[j]-i, 2);
        }
        ans = min(ans, res);
    }
    cout << ans << endl;
}

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

int main(){
  
  int a,b;
  cin >> a;
  
  if( a%1000 == 0 ){
    
    b = a/1000;
    
    cout << 1000*b-a << endl;
    
  }
  
   else if( a >= 1000){
    
    b = a/1000+1;
    
    cout << 1000*b-a << endl;
    
  }
  
  else{
    
    cout << 1000-a << endl;
    
  }
  
}
    
    
   


Measured memory_bytes: 3676
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
/*
struct Edge
{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
*/
using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

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 { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

struct combination
{
    vector<mint> fact, ifact;
    combination(int n) : fact(n + 1), ifact(n + 1)
    {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i)
            fact[i] = fact[i - 1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i)
            ifact[i - 1] = ifact[i] * i;
    }
    mint operator()(int n, int k)
    {
        if (k < 0 || k > n)
            return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }
    mint p(int n, int k)
    {
        return fact[n] * ifact[n - k];
    }
} c(1000005);

vector<pair<long long, int>> factorize(long long N)
{
    vector<pair<long long, int>> res;
    for (long long i = 2; i * i <= N; i++)
    {
        if (N % i != 0)
            continue;
        res.emplace_back(i, 0);
        while (N % i == 0)
        {
            N /= i;
            res.back().second++;
        }
    }
    if (N != 1)
        res.emplace_back(N, 1);
    return res;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N, M;
    cin >> N >> M;
    vector<pair<ll, int>> factor = factorize(M);
    mint ans = 1;
    for (auto it : factor)
    {
        // cerr << it.second + 1 << endl;
        ans *= c(it.second + N - 1, it.second);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 18628
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <set>
#include <utility>
#include <bitset>
#include <queue>
#define N 110000
#define M 210000
#define inf 1000000007
using namespace std;
struct edge 
{
    int v,w,x;
}E[M*2];

int n,m,e;
int gh[N],vis[N];
long long dis[N],tmp[N];
int col[N];
long long mind = 0, maxd = 0;
void addedge(int u,int v,int w) 
{
    E[e].v=v, 
    E[e].x=gh[u], 
    E[e].w=w, 
    gh[u]=e++;
}
void dfs(int u,long long d, int c) 
{
    if (vis[u]) return;
    vis[u] = 1; 
    dis[u] = d; 
    if (mind>d)mind=d;
    if (maxd<d)maxd=d;
    col[u] = c;
    for (int p = gh[u]; p >= 0; p = E[p].x) 
        dfs(E[p].v, d+E[p].w, c);
}
int main() 
{
    memset(gh,255,sizeof(gh));
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        int l,r,x;
        scanf("%d%d%d",&l,&r,&x);
        addedge(l,r,x);
        addedge(r,l,-x);
    }
    int flag=1;
    for(int i=1;i<=n;i++)
        if (!vis[i]) 
        {
            dfs(i,0,i);
            if (maxd-mind>1000000000)
            {
                flag=0;
                break;
            }
            tmp[i] = -mind;
        }
    if (!flag){ puts("No"); return 0;}
    for(int i=1;i<=n;i++)dis[i]+=tmp[col[i]];
    for(int i=0;i<=e-1;i++)
    {
        int u = E[i^1].v, v=E[i].v,w=E[i].w;
        if (dis[v]-dis[u] != w) 
        {
            puts("No");
            return 0;
        }
    }
    puts("Yes");
    return 0;
}

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

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0; i<ll(n); i++)
#define FOR(i,m,n) for(ll i=ll(m); i<ll(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VP vector<pair<ll,ll>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
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 int  INF = (1 << 30) - 1;
const ll INFL = 1LL << 60;
const ll mod = 10000000007;



int main() {

	int n;
	cin >> n;
	if (n >= 30)cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 3592
/*

連立方程式「ax+by=c, dx+ey=f」の解を求めよ。

結果：Time limit exceeded

連立方程式を解くのに苦労した。
タイムリミットと言われても、どうしたものか。

----------------------------------------------------------------------

13:35 2013/01/19

10027の例に倣い、配列ではなくした。これで軽くなっただろう。
・・・それでも駄目だった。

結果：Time limit exceeded

----------------------------------------------------------------------

23:06 2013/02/06

式の変形をすると、

x=(ce-bf)/(ae-bd);
y=(cd-af)/(bd-ae);

だ、そうで。

サンプルと同じ結果は出るものの、送ったらWAが返ってきた。はて。

結果：Wrong answer

*/
#include <stdio.h>
#include <math.h>

double yosute00(double n, int i);									//指定した整数の桁で四捨五入を行う関数。（1→小数点第一位、2→小数点第二位、.....-1→1の位、-2→2の位）

int main()
{
	double a,b,c,d,e,f,x,y;
	int i=0,count=0;
	double sp;
	int cal,ret;
	while(1){
		ret=scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f);
		if(ret==EOF){
			break;
		}
		x = ((c*e)-(b*f)) / ((a*e)-(b*d));
		y = ((c*d)-(a*f)) / ((b*d)-(a*e));
		x = yosute00(x, 4);
		y = yosute00(y, 4);
		printf("%.3f %.3f\n",x,y);
	}
	return 0;
}

double yosute00(double n, int i)
{
	switch(i){
		case -5:
			n/=100000;
			n+=0.5;
			n=floor(n);
			n*=100000;
			break;
		
		case -4:
			n/=10000;
			n+=0.5;
			n=floor(n);
			n*=10000;
		
		case -3:
			n/=1000;
			n+=0.5;
			n=floor(n);
			n*=1000;
		
		case -2:
			n/=100;
			n+=0.5;
			n=floor(n);
			n*=100;
		
		case -1:
			n/=10;
			n+=0.5;
			n=floor(n);
			n*=10;
		
		case 1:
			n+=0.5;
			n=floor(n);
			break;
		
		case 2:
			n*=10;
			n+=0.5;
			n=floor(n);
			n/=10;
			break;
		
		case 3:
			n*=100;
			n+=0.5;
			n=floor(n);
			n/=100;
			break;
		
		case 4:
			n*=1000;
			n+=0.5;
			n=floor(n);
			n/=1000;
			break;
		
		case 5:
			n*=10000;
			n+=0.5;
			n=floor(n);
			n/=10000;
			break;
	}
	return n;
}

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

#define sz(a) ((int)a.size())
#define forn(i,n) for(int i=0;i<(int)n;i++)
#define forse(i,s,e) for(int i=(int)s;i<(int)e;i++)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second

using dbl=double;
using ll=long long;
using pii=pair<int, int>;
using pll=pair<ll, ll>;

dbl PI=3.141592653589793;



void solve(){
	int n,m,k;
	cin >> n >> m >> k;
	vector<vector<char>> inp(n,vector<char>(m));
	forn(i,n)
		forn(j,m) cin >> inp[i][j];
	int out=0;
	forn(i,(1<<n)){
		forn(j,(1<<m)){
			int ctot=0;
			forn(in,n){
				forn(jn,m){
					if((i&(1<<in))&&(j&(1<<jn))){
						ctot+=(inp[in][jn]=='#');
					}
				}
			}
			if(ctot==k) out++;
		}
	}	
	cout << out;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); 
	int T=1;
//	cin >> T;
	for(int c=1;c<=T;c++){
		solve();
	}
}


Measured memory_bytes: 3652
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int x,y;
	cin>>x>>y;
	if(x%y) cout<<x<<endl;
	else cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
#define REP(i,n) for(int i=0;i<(int)n;++i)
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
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; }
template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
string num2bit(ll num, ll len){
    string bit = "";
    REP(i, len){
    bit += char('0'+(num>>i & 1));
    }
    return bit;
}

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

    ll K, A, B;
    cin >> K >> A >> B;
    bool ok = false;

    for(int i=A;i<=B;i++){
        if(i%K==0) ok = true;
    }

    cout << (ok?"OK":"NG") << endl;

    return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define int long long 
#define pii pair<int,int>
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define all(x) x.begin(),x.end()
#define fast  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
signed main(){
    fast;
    int n;
    cin>>n;
    int a[n+1];
    for(int i = 1;i<=n;i++)
    	cin>>a[i];
    map<int,int> mp;
    int ans = 0;
    for(int i = 1;i<=n;i++){
    	int curr = i - a[i];
    	if(mp.count(curr)){
    		ans+=mp[curr];
    	}
    	mp[i+a[i]]++;
    }
    cout<<ans;
}

Measured memory_bytes: 17660
<?php

fscanf(STDIN, '%d', $n);

for ($i = 1; $i <= $n; $i++) {
    if ($i % 3 === 0) {
        printf(' %d', $i);
        continue;
    }

    $m = $i;

    while ($m) {
        if ($m % 10 === 3) {
            printf(' %d', $i);
            break;
        }
        $m = (int)$m / 10;
    }
}

echo PHP_EOL;

Measured memory_bytes: 6572
from math import sqrt
N=int(input())
l=[list(map(int, input().split())) for i in range(N)]
s=0
for i in range(N-1):
    for j in range(i+1,N):
        s+=sqrt((l[i][0]-l[j][0])**2+(l[i][1]-l[j][1])**2)
print(s*2/N)


Measured memory_bytes: 3060
#include<stdio.h>

int main(void)
{
	int  x[10000], y;
	int i = 0;
	while (1)
	{
		scanf("%d", &y);
		x[i] = y;
		i++;

		if (y == 0)
		{
			break;
		}
	}
		i = 0;
		while (x[i] != NULL)
		{
			printf("Case %d: %d\n", i + 1, x[i]);
			i++;
		}
	
	return 0;
}


Measured memory_bytes: 2024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {

    public static void main(String[] args) throws Exception {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;

        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }
}

class Task {

    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int[] a = new int[n];
        int ans = 0;
        int cur = 1;
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
            if (a[i] != cur) {
                ans++;
            } else {
                cur++;
            }
        }
        out.println(ans == n ? -1 : ans);
    }


}

class InputReader {

    private final BufferedReader reader;
    private StringTokenizer      tokenizer;

    public InputReader(InputStream stream){
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }

    public String nextLine() {
        try {
            return reader.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(nextLine());
        }
        return tokenizer.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }

}


Measured memory_bytes: 47964
def solve(n, a_lst):
    dic = {}

    for i in range(1, n + 1, 2):
        j = n - i
        dic[j] = 1 if j == 0 else 2

    for i in a_lst:
        if i not in dic:
            return 0

        dic[i] -= 1

        if dic[i] < 0:
            return 0

    return pow(2, n // 2) % (pow(10, 9) + 7)


if __name__ == '__main__':
    n = int(input())
    a_lst = [int(x) for x in input().split()]
    print(solve(n, a_lst))

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

//#define int long long
#define X first
#define Y second
#define mp make_pair
#define pr pair
#define vc vector
#define sz(v) (int) v.size()

using namespace std;

typedef long long ll;
typedef long double ld;

signed main() {
#ifdef LOCAL
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n;
    string s;
    cin >> n >> s;
    int ans = 1;
    for (int i = 1; i < n; ++i) ans += (s[i] != s[i - 1]);
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

int main()
{
  int N;
  ll res=0;
  cin >> N;

  bool fizz=false;
  FOR(i,1,N) {
    if(i%3 == 0 || i%5==0) {
      continue;
    }
    else { res+= (ll)i; }
  }

  cout << res << endl;
}


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

int main(){
  
  double pi = 3.1415926535;
  int R;
  cin >> R;
  float cir = 2 * pi * R;
  cout << cir << endl;
  
  return 0;
}

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

int main() {
  long long int a,b,c,n,r;
  while(cin >> a >> b >> c) {
    if((a==0)&&(b==0)&&(c==0)) break;
    cin >> n;
    for(int i=0;i<n;i++) {
      cin >> r;
      if((a*a + b*b < 4*r*r) || (b*b + c*c < 4*r*r) || (c*c + a*a < 4*r*r)) {
        cout << "OK" << endl;
      }
      else
        cout << "NA" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 0
import collections
import sys
import numpy as np
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
MOD = 10**9+7
import itertools
import math

o = input()
e = input()
ans = ""
for i in range(len(e)):
    ans += o[i] + e[i]
if len(o)>len(e):
    ans += o[-1]
print(ans)

Measured memory_bytes: 12504
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }

int m;
struct Monoid {
  using T = lint;
  static T op(const T& lhs, const T& rhs) { return lhs * rhs % m; }
  static constexpr T e() { return 1; }
};

template<class Monoid> struct SegmentTree {
  using M = Monoid;
  using T = typename M::T;

  const int n;

  SegmentTree(int n, const T& a = M::e()) : n(n), val(2 * n, a) {
    build();
  }

  template<class Itr> SegmentTree(Itr first, Itr last) :
    n(distance(first, last)), val(2 * n, M::e()) {
    copy(first, last, next(begin(val), n));
    build();
  }

  T& operator[](int i) {
    assert(0 <= i and i < n);
    return val[i + n];
  }

  void build() {
    for (int i = n - 1; i > 0; --i) {
      val[i] = M::op(val[2 * i], val[2 * i + 1]);
    }
  }

  T get(int l, int r) const {
    l = max(l, 0), r = min(r, n);
    T resl = M::e(), resr = M::e();
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) resl = M::op(resl, val[l++]);
      if (r & 1) resr = M::op(val[--r], resr);
    }
    return M::op(resl, resr);
  }

  void set(int i, const T& a) {
    assert(0 <= i and i < n);
    for (val[i += n] = a, i >>= 1; i > 0; i >>= 1) {
      val[i] = M::op(val[2 * i], val[2 * i + 1]);
    }
  }

private:
  V<T> val;
};

using ST = SegmentTree<Monoid>;

int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int n; cin >> n >> m;
  VV<> g(n);
  for (int i = 0; i < n - 1; ++i) {
    int u, v; cin >> u >> v, --u, --v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  V<lint> dp(n, 1);
  VV<> chi(n);
  auto dfs = [&](const auto& dfs, int v, int p) -> void {
    for (int w : g[v]) if (w != p) {
      dfs(dfs, w, v);
      (dp[v] *= dp[w]) %= m;
      chi[v].push_back(w);
    }
    dp[v] = (dp[v] + 1) % m;
  };
  dfs(dfs, 0, -1);
  for (int v = 0; v < n; ++v) {
    sort(begin(chi[v]), end(chi[v]));
  }
  V< unique_ptr<ST> > st(n);
  for (int v = 0; v < n; ++v) {
    st[v] = make_unique<ST>(chi[v].size());
    for (int i = 0; i < st[v]->n; ++i) {
      (*st[v])[i] = dp[chi[v][i]];
    }
    st[v]->build();
  }
  V<lint> dp1(n, 1), dp2(n, 1);
  auto dfs1 = [&](const auto& dfs1, int v, int p) -> void {
    for (int w : chi[v]) {
      (dp1[v] *= dp[w]) %= m;
    }
    if (p != -1) {
      // for (int u : chi[p]) if (u != v) {
      //   (dp2[v] *= dp[u]) %= m;
      // }
      int i = distance(begin(chi[p]), lower_bound(begin(chi[p]), end(chi[p]), v));
      (dp2[v] *= st[p]->get(0, i)) %= m;
      (dp2[v] *= st[p]->get(i + 1, st[p]->n)) %= m;
      (dp2[v] *= dp2[p]) %= m;
      (dp2[v] += 1) %= m;
    }
    (dp1[v] *= dp2[v]) %= m;
    for (int w : chi[v]) {
      dfs1(dfs1, w, v);
    }
  };
  dfs1(dfs1, 0, -1);
  for (int v = 0; v < n; ++v) {
    cout << dp1[v] << '\n';
  }
}

Measured memory_bytes: 26240
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a,b,k;
  cin >> a >> b >> k;
  long long x = min(a,k);
  a -= x;
  k -= x;
  b -= min(b,k);
  cout << a <<" " <<b << endl;
  
}

Measured memory_bytes: 3608
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<string>
#include<map>

using namespace std;

int main(void) {
	int N;
	cin >> N;
	vector<int>v(N);
	for (int i = 0; i < N; i++) {
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	float ans = v[0];
	for (int i = 0; i < N; i++) {
		ans = (ans + v[i]) / 2;
	}
	cout << (float)ans;
	return 0;
}

Measured memory_bytes: 256
import sys

stdin = sys.stdin

ni = lambda: int(ns())
ns = lambda: stdin.readline().rstrip()
na = lambda: list(map(int, stdin.readline().split()))

# code here

S = ns()

min_a = 753
for i in range(len(S)-2):
    a = abs(753 - int(S[i:i+3]))
    min_a = min(a, min_a)

print(min_a)

Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <iomanip>
#include <algorithm>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>

#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	int64 nn, tmp, ma, ans = 0;
	cin >> nn;
	vector<int64> aa;
	set<int64> ss;
	for(int64 ii = 0;ii < nn;ii++)
	{
		cin >> tmp;
		aa.push_back(tmp);
	}
	sort(aa.begin(), aa.end());
	for(int64 ii = 1;ii < nn;ii++)	//重複している要素をメモする
	{
		if(aa[ii] == aa[ii - 1])
		{
			ss.insert(aa[ii]);
		}
	}
	ma = aa[nn - 1];	//	最大値をメモ
	bool memo[ma + 1];
	for(int64 ii = 1;ii <= ma;ii++)
	{
		memo[ii] = true;
	}
	for(int64 ii = 0;ii < nn;ii++)	//aa[]の倍数をfalseにする
	{
		if(memo[aa[ii]])
		{
			for(int64 jj = 2;jj * aa[ii] <= ma;jj++)
			{
				memo[jj * aa[ii]] = false;
			}
		}
	}
	for(int64 ii = 0;ii < nn;ii++)
	{
		if(memo[aa[ii]] && 0 == ss.count(aa[ii]))
		{
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main()
{
#ifdef LOCAL
    // 以降 cin の入力元が 'xxx.txt' になる
    std::ifstream in("b_in.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

    int K, X;
    cin >> K >> X;

    int left = -1000000;
    int right = 1000000;


    left = X -K + 1;
    right = X + K - 1;

    for (int i = left; i <= right; i++)
    {
        cout << i << " ";
    }
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
using namespace std;

#define N 500000

int n;
int A[N+1];

int parent(int i){
	return i/2;
}
int left(int i){
	return 2*i;
}
int right(int i){
	return 2*i+1;
}
int inside(int i){
	if(i>=1&&i<=n) return 1;
	else return 0;
}

int main(){
	cin >> n;
	for(int i=1; i<=n; i++){
		cin >> A[i];
	}
	for(int i=1; i<=n; i++){
		printf("node %d: ", i);
		printf("key = %d, ", A[i]);
		if(inside(parent(i))) printf("parent key = %d, ", A[parent(i)]);
		if(inside(left(i))) printf("left key = %d, ", A[left(i)]);
		if(inside(right(i))) printf("right key = %d, ", A[right(i)]);
		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define ll long long int
#define vec vector<ll>
#define mat vector<vec>

using namespace std;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

vector<ll> bunkai(ll a){
  if(a<=0) return {};
  if(a==1) return {{1,1}};
  vector<ll> f;
  ll b=a;
  for(ll i=2;i*i<=a;i++){
    if(b%i==0){
      f.push_back(i);
      b=b/i;
      i--;
    }
  if(b==1)break;
  }
  if(b!=1)f.push_back(b);

  return f;
}

int main(){

  ll n;
  cin >> n;

  vec a;
  vector<bool> b(600000);
  for(ll i=2;i<=500000;i++){
    vec v=bunkai(i);
    if(v.size()==1){
      a.push_back(i);
      b[i]=1;
    }
  }

  //cout << 5 << endl;

  vec ans;
  ll p=0;
  for(ll i=0;i<a.size();i++){
    if(a[i]%10==1)ans.push_back(a[i]);
  }
  
  for(ll i=0;i<n;i++)cout << ans[i] << " ";
  cout << endl;


}

Measured memory_bytes: 3988
#include <algorithm>
#include <iostream>
#include<cstring>
#include<vector>
#include<cstdio>
using namespace std;

int main()
{
    string s, t;
    cin >> s >> t;
    int res = s.length();
    for (int i = 0; i < s.length() - t.length() + 1;i++){
        int tmp = 0;
        for (int j = 0; j < t.length();j++)
            if(s[i+j] != t[j])
                tmp++;
        res = min(res, tmp);
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 3568
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		boolean judje = true;

		Scanner scan = new Scanner(System.in);

		char[] S = scan.next().toCharArray();
		char[] T = scan.next().toCharArray();

		for(int i = 0; i < S.length; i++)
			if(S[i] != T[i])
				judje = false;

		if(T.length - S.length != 1)
			judje = false;

		System.out.println((judje ? "Yes" : "No"));
	}

}


Measured memory_bytes: 35620
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define ALL(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef priority_queue<int> p_que;
typedef priority_queue<int, vector<int>, greater<int>()> p_que_rev;
const int INF = INT_MAX;
const lint LINF = LLONG_MAX;
const int MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};


int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    lint n;
    cin >> n;
    vector<lint> a(n);
    lint ans = 1;
    for (int i=0; i<n; ++i){
        scanf("%lld", &a[i]);
    }
    int flag = 0; // 1 : <=, 2 : >=, 0 : undefined
    int l = 0;
    int r = 1;
    while(r < n){
        while(r < n){
            if(a[l] == a[r]){
                r++;
                continue;
            }
            else if(a[l] < a[r]){
                flag = 1;
                break;
            }
            else if(a[l] > a[r]){
                flag = 2;
                break;
            }
        }
        while(r < n){
            if(flag == 1){
                if(a[r-1] > a[r]){
                    ans++;
                    break;
                }
                else {
                    r++;
                }
            }
            else if(flag == 2){
                if(a[r-1] < a[r]){
                    ans++;
                    break;
                }
                else {
                    r++;
                }
            }
        }
        // debugpair(l, r);
        l = r;
        r++;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

LL n,m;
vector<LL> v1,v2;

bool check(LL x){
	LL a,b,c;
	a=distance(v2.begin(),upper_bound(v2.begin(),v2.end(),x));
	b=0;
	for(int i=0;i<n;i++){
		if(v1[i]==0){
			if(x>=0)b+=n;
			continue;
		}
		if(v1[i]>0){
			if(x>=0)c=x/v1[i];
			else c=-((-x-1)/v1[i]+1);
			b+=distance(v1.begin(),upper_bound(v1.begin(),v1.end(),c));
		}else{
			if(x>=0)c=x/v1[i];
			else c=(-x-1)/(-v1[i])+1;
			b+=distance(lower_bound(v1.begin(),v1.end(),c),v1.end());
		}
	}
	if(b-a>=2*m)return true;
	return false;
}

int main(){
	int i,j,k;
	LL a,b,c;
	cin>>n>>m;
	for(i=0;i<n;i++){
		cin>>a;
		v1.push_back(a);
		v2.push_back(a*a);
	}
	sort(v1.begin(),v1.end());
	sort(v2.begin(),v2.end());
	LL z[3]={-((LL)1<<60),(LL)1<<60};
	while(z[1]-z[0]>1){
		z[2]=(z[1]+z[0])/2;
		if(check(z[2]))z[1]=z[2];
		else z[0]=z[2];
	}
	cout<<z[1]<<endl;
}

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

int main(void){
    int N,M,P,X;
    while(cin>>N>>M>>P, N|M|P){
        int sum=0,winner;
        rep1(i,N){
            cin>>X;
            sum+=X;
            if(i==M)winner=X;
        }
        if(winner)cout<<sum*(100-P)/winner<<endl;
        else cout<<0<<endl;
    }

    return 0;
}

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

int main(){
  int m,f,b;
  cin >> m >> f >> b;
  if (b > m+f){
    //二人合わせても買えない
    cout << "NA" << endl;
    return 0;
  }
  if (m >= b){
    //自分だけで買える
    cout << 0 << endl;
    return 0;
  }
  cout << b - m << endl;
  return 0;
}



Measured memory_bytes: 3100
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int a, b;

int main() {

	cin >> a >> b;

	cout << a * b - a - b + 1 << endl;

	return 0;
}




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

int main(){
    int n;cin>>n;
    vector<int> a(n);for(int i=0;i<n;i++){cin>>a.at(i);}
    int ans=0;
    for(int i=1;i<=n-2;i++){
      if((a.at(i-1)<=a.at(i)&&a.at(i)<=a.at(i+1))||(a.at(i-1)>=a.at(i)&&a.at(i)>=a.at(i+1))){
			++ans;      
      }
    }
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {

    int n;
    scanf("%d", &n);

    if (n % 4 == 0 && n % 7 == 0) {
        puts("Yes");
        return 0;
    }

    int num1 = n / 4;
    int num2 = n / 7;


    for (int i = 1; i <= num1; i++) {
        int nokori = n - 4 * i;
        if (nokori % 7 == 0) {
            puts("Yes");
            return 0;
        }
    }

    for (int j = 1; j <= num2; j++) {
        int nokori = n - 7 * j;
        if (nokori % 4 == 0) {
            puts("Yes");
            return 0;
        }
    }

    puts("No");


    return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;

#define ul unsigned long long
#define ll long long

int main()
{
  ul n;
  int a[100];
  cin>>n;
  for (size_t i = 0; i < n; i++)
  {
    cin>>a[i];
  }
  sort(a,a+n,greater<int>());
  ul ct=0;
  for (size_t i = 0; i < n; i++)
  {
    ct+=(i%2?-1:1)*a[i];
  }
  cout<<ct<<endl;
  

  return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
#define INF 2e9
using namespace std;
const int N=1e6+1;
const int mod=1e9+7;
ll fastexp(ll base,ll exp){
	base%=mod;
	ll ans=1;
	while(exp>0){
		if(exp&1){
			ans*=base;
			ans%=mod;
		}
		base*=base;
		base%=mod;
		exp/=2;
	}
	return ans;
}
ll gcd(ll a,ll b){
	if(b==0) return a;
	return gcd(b,a%b);
}
stack<char> x;
ll arr[N];
int main() {
	ll t;
	cin >> t;
	while(t--){
		x.push('a'+(t%26));
		t /= 26;
		
	}


	while(!x.empty()){
		cout << x.top();
		x.pop();
	}

	
	return 0;
}
   






   






   






   







Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
int N,A,B;
 //各桁の数字の和?
int cunt_digit(int n){   
    int a=0;
    while(n){
        a+=n%10;
        n/=10;
    }

    return a;
}

int main(){

    cin>>N>>A>>B;
    int sum=0;
    for(int i=1;i<=N;i++){
       if(!(cunt_digit(i)>=A&&cunt_digit(i)<=B))continue;
       sum+=i;
    }
    cout<<sum<<"\n";

    return 0;
}



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

int main() {
  string S;
  cin >> S;
  vector<int> base(S.size());
  for (int i = 0; i < S.size(); i++) {
    if (i == 0) {
      base.at(i) = 1;
    }
    else {
      base.at(i) = base.at(i - 1) * 10 % 2019;
    }
  }
  vector<int> mod(S.size());
  for (int i = 0; i < S.size(); i++) {
    if (i == 0) {
      string s;
      s = s + S.at(S.size() - 1);
      int ai = stoi(s);
      mod.at(i) = ai;
    }
    else {
      string s;
      s = s + S.at(S.size() - i - 1);
      int ai = stoi(s);
      mod.at(i) = (mod.at(i - 1) + base.at(i) * ai) % 2019;
    }
  }
  int count = 0;
  for (int i = 0; i < 2019; i++) {
    int sum = 0;
    for (int j = 0; j < S.size(); j++) {
      if (mod.at(j) == i) {
        sum += 1;
      }
    }
    if (i == 0) {
      count += sum * (sum - 1) / 2 + sum;
    }
    else {
      count += sum * (sum - 1) / 2;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 5200
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define put(arr,v) fil(all(arr) , v)
#define precise(num)  cout<<fixed; cout << std::setprecision(num)
#define sort(v) sort(all(v));
#define fill_vec(v,val)  fill(all(v) , val)
#define fill_arr(ar,n,val) fill(ar , ar+n ,val)
#define nl cout<<"\n";
#define input_i(v) generate(all(v),nxt_i);
#define input_s(v) generate(all(v),nxt_s);
#define vst vector<string>
#define vi vector<int>
#define pi pair<int,int>

// namespace ohuefmi{
    
//     int nxt_i(){
//         int x;
//         cin>>x;
//         return x;
//     }
//     string nxt_s(){
//         string x;
//         cin>>x;
//         return x;
//     }
//     void print(vector<int>v){
//         for(auto i : v){
//             cout<<i<<" ";
//         }nl;
//     }
//      void print(vector<string>v){
//         for(auto i : v){
//             cout<<i<<" ";
//         }nl;
//     }
    
//     string binary(int n)
//     {
//         bitset<32>b(n) ;
//         string p =b.to_string();
//         return p;

//     }
//     int decimal(string s)
//     {
//         int res = 0;
//         for(int i = 0; i < s.size() ; i++ ){
//             if(s[i] == '1')
//             res = res + pow(2,s.size() - i -1);
//         }
//         return res;
//     }
//     bool isPrime(int n){
//         if (n <= 1) return false; if (n <= 3) return true;
//     if (n % 2 == 0 || n % 3 == 0) 
//         return false;
//     for (int i = 5; i * i <= n; i = i + 6) 
//         if (n % i == 0 || n % (i + 2) == 0) 
//             return false; 
  
//     return true; 
//     }
    
//      int pow (int x, int n,int mod) {//calculate x^n
//     if (n == 0) return 1;

//       int res = pow (x, n / 2,mod);

//     res = (res * res) % mod;
//     if (n % 2) res = (res * x ) % mod;

//     return res;
//     }
    
// }

// using namespace ohuefmi;
int32_t main(){
    
    
        ios_base::sync_with_stdio(cin.tie(NULL));
        cout.tie(NULL);
    
        int tc = 1; 
        // tc = nxt_i();

        while(tc -- ){
        
                int n,m;
                cin>>n>>m;
                
                int res = n*(n-1);
                int res2 = m*(m-1);
                
                int ans = (res+res2)/2;
                cout<<ans<<endl;
            
        }       
       
      
      
}


Measured memory_bytes: 256
N, K = map(int, input().split())
A=list(map(int, input().split()))
L=[0 for _ in range(40)]
ans=0

for a in A:
    i=0
    while a:
        if a&1==1:
            L[i]+=1
        a=a>>1
        i+=1
opt=0
mask=1

for l in L:
    if l<N-l:
        opt = opt | mask
    mask=mask<<1

ans=sum(a^K for a in A)
for i in range(0,40):
    x=0
    for j in range(0,40):
        if j<i:
            x+=(opt>>j&1)*(2**j)
        elif j>i:
            x+=(K>>j&1)*(2**j)

    if x<=K:
        tmp=sum(a^x for a in A)
        ans=max(tmp,ans)

print(ans)

Measured memory_bytes: 14620
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

// BEGIN CUT HERE
template<class Z> Z ext_gcd(Z a, Z b, Z& x, Z& y) {
  Z u = y = 0, v = x = 1; 
  while (b) {
    Z q = a / b;
    swap(a -= q * b, b);
    swap(x -= q * u, u);
    swap(y -= q * v, v);
  }
  return a;
}
// END CUT HERE

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  lint a, b; cin >> a >> b;
  lint x, y;
  ext_gcd(a, b, x, y);
  V< pair<lint, lint> > res;
  for (int k = -1; k <= 1; ++k) {
    lint nx = x - k * b, ny = y + k * a;
    res.emplace_back(nx, ny);
  }
  sort(begin(res), end(res), [](const auto& l, const auto& r) {
    return abs(l.first) + abs(l.second) != abs(r.first) + abs(r.second) ? abs(l.first) + abs(l.second) < abs(r.first) + abs(r.second) : l.first < r.first;
  });
  cout << res[0].first << ' ' << res[0].second << '\n';
}


Measured memory_bytes: 3192
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpl()
a.sort()
ln = len(bin(a[-1])) - 2
bit = [defaultdict(int) for i in range(ln)]
res = 0
for i in a:
    tmp = bin(i)
    for _,j in enumerate(tmp[:1:-1]):
        # print(_,j)
        bit[_][j] += 1
# pprint.pprint(bit)
for i,j in enumerate(bit):
    x = j['0']
    y = j['1']
    if x+y < n:
        x = n - y
    # print(i,x,y)
    c = pow(2,i)
    res += x * y * c
    res %= mod
print(res)

Measured memory_bytes: 127084
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vec=vector<ll>;
using mat=vector<vec>;
#define For(i,a,b) for(ll i=a;i<b;i++)
#define bFor(i,a,b) for(ll i=a;i>=b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define mod 1000000007
#define endl "\n"
#define output(v) do{bool f=0;for(auto i:v){cout<<(f?" ":"")<<i;f=1;}cout<<endl;}while(0)
using datas=pair<ll,ll>;
using tdata=pair<ll,datas>;
struct unionfind{
  vector<int> par,treesize;
  unionfind(int N) :par(N){
    for(int i=0;i<N;i++)par[i]=i;
    treesize.resize(N);
    for(int i=0;i<N;i++)treesize[i]=1;
  }
  int root(int x){
    int r;
    if(par[x]==x)return x;
    r=root(par[x]);
    if(par[x]!=r){
      treesize[r]+=treesize[x];
      treesize[x]=0;
      par[x]=r;
    }
    return r;
  }
  void unite(int x,int y){
    int px=root(x);
    int py=root(y);
    if(px!=py){
      par[px]=py;
      treesize[py]+=treesize[px];
      treesize[px]=0;
    }
  }
  bool parcheck(int x,int y){
    int px=root(x);
    int py=root(y);
    return px==py;
  }
  int size(int x){
    int px=root(x);
    return treesize[px];
  }
};

int main(){
  ll N,M,ans=0,a,b;
  cin>>N>>M;
  vec v(N);
  unionfind tree(N);
  rep(i,N){
    cin>>v[i];v[i]--;
  }
  rep(i,M){
    cin>>a>>b;
    tree.unite(a-1,b-1);
  }
  rep(i,N){
    if(tree.parcheck(v[i],i))ans++;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1792
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	if ((tmp & ma0) ^ ma0) {
		int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
		tmp = tmp << dig & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += (72 - dig >> 3);
	}
	else {
		tmp = tmp & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += 8;
		if ((ct = *ci++) >= '0') {
			tmp = tmp * 10 + ct - '0';
			if (*ci++ == '0') {
				tmp = tmp * 10;
				ci++;
			}
		}
	}
	return tmp;
}
const int mod = 1e9 + 7;
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);

	int N = getint();
	int A[200000];
	ll kei = 0;
	__int128 kei2 = 0;
	rep(i, N) {
		kei += (A[i] = getint());
		kei2 += (ll)A[i] * A[i];
	}
	kei %= mod;
	kei = kei * kei % mod;

	int kari = kei2 % mod;
	kei = (kei - kari + mod) % mod;

	kei = kei * (mod / 2 + 1) % mod;

	printf("%d\n", kei);


	Would you please return 0;
}

Measured memory_bytes: 1832
#include <stdio.h>
int main(void)
{
  int x, y, z, t;
  scanf("%d" ,&x); scanf("%d" ,&y); scanf("%d" ,&z);
  t=x;
  x=y;
  y=t;
  
  t=x;
  x=z;
  z=t;
  printf("%d %d %d\n" ,x, y, z);
  
  return 0;
}

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

using vi = std::vector<int>;
using vvi = std::vector<vi>;

vvi edges;
std::vector<bool> visited;
std::vector<int64_t> counter;

void dfs(int, int64_t);

int main()
{
	int N, Q;
	scanf("%d%d", &N, &Q);
	edges.resize(N);
	for (int i{}; i < N - 1; i++)
	{
		int a, b;
		scanf("%d%d", &a, &b);
		a--; b--;
		edges[a].push_back(b);
		edges[b].push_back(a);
	}
	counter.resize(N);
	for (int i{}; i < Q; i++)
	{
		int p, x;
		scanf("%d%d", &p, &x);
		p--;
		counter[p] += x;
	}

	visited.resize(N);
	dfs(0, 0ll);
	for (int i{}; i < N; i++)
		printf("%lld%c", counter[i], i + 1 == N? '\n': ' ');

	return 0;
}

void dfs(int index, int64_t sum)
{
	if (visited[index]) return;
	visited[index] = true;
	counter[index] += sum;
	for (auto& e: edges[index])
		dfs(e, counter[index]);
	return;
}

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

int main()
{
    int N;
    cin >> N;
    vector<int> vec(N);
    for (int i = 0; i < N; i++)
    {
        cin >> vec.at(i);
    }
    int result = 0;
    for (int i = 0; i < N; i++)
    {
        int dec = 2;
        while(vec[i] % dec == 0){
            dec = dec * 2;
            result++;
        }
    }
    cout << result << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); // cin, cout の高速化
#define MOD 1000000007
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP1(i, n) for (int i = 1; i <= (n); i++)

const ll INF = 1e15;

int main()
{
    string N;
    cin >> N;
    int a = 0;
    REP(i,N.length()){
        a+=N[i] - '0';
    }
    if(stoi(N) % a){
        cout << "No";
    }else{
        cout << "Yes";
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
int main() {
    int n;
    cin>>n;
    ll ans=0;
    for(int i = 1;i <= n;++i) {
        if(i%3==0||i%5==0)continue;
        else ans+=i;
    }
    cout<<ans<<endl;
    return 0;
}

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

void Main()
{
    int x;
    cin >> x;
    for(int i = 1;;i++)
        if(x*i % 360 == 0)
        {
            cout << i << endl;
            return;
        }
}

int main(int argc, char **argv)
{
    Main();
    return 0;
}


Measured memory_bytes: 3572
n = int(input())

a = tuple(map(int,input().split()))

ans = 0

c = 0
for i in range(1,n):
  if a[i]<=a[i-1]:
    c+=1
  else:
    ans = max(ans,c)
    c = 0
ans = max(ans,c) 
print(ans)


Measured memory_bytes: 14352