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

#define forn(i, a, b) for (int i = a; i <= b; ++i)
#define forr(i, a, b) for (int i = a; i >= b; --i)

using namespace std;

const int N = (int)1e5 + 1;
const int INF = 1e9 + 7;

typedef long long ll;
typedef long double ld;

typedef pair < int, int > pii;
typedef pair < ll, ll > pll;

ll x, y;
int main (){
  scanf ("%lld %lld", &x, &y);
  int ans = 1;
  while (x * 2 <= y){
    x *= 2;
    ans++;
  }
  printf ("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

memo = {}
for i in range(n):
    if a[i] not in memo:
        memo[a[i]] = 1
    else:
        memo[a[i]] += 1

if len(memo) == 1:
    tmp = [i for i in memo]
    if tmp[0] == 0:
        print("Yes")
        exit()

if len(memo) == 2:
    tmp = [i for i in memo]
    if tmp[0] == 0:
        if memo[tmp[0]]*2 == memo[tmp[1]]:
            print("Yes")
            exit()
    if tmp[1] == 0:
        if memo[tmp[1]]*2 == memo[tmp[0]]:
            print("Yes")
            exit()
            
if len(memo) == 3:
    tmp = [i for i in memo]
    if memo[tmp[0]] == memo[tmp[1]] and memo[tmp[1]] == memo[tmp[2]]:
        if tmp[0] ^ tmp[1] ^ tmp[2] == 0:
            print("Yes")
            exit()

print("No")

Measured memory_bytes: 60784
#include <bits/stdc++.h>
#define ll long long int
#define F first
#define S second
#define pub push_back
#define pob pop_back
#define M 1000000007
#define pii pair<ll,ll>
#define mp make_pair
using namespace std;
vector<pii >p;
int main()
{
    ios_base::sync_with_stdio(false);
    ll n,m,i,u,v,ans=0;
    cin>>n>>m;
    for(i=0;i<n;i++)
    {
    	cin>>u>>v;
    	p.pub(mp(u,v));
    }
    sort(p.begin(),p.end());
    for(i=0;i<n;i++)
    {
    	if(p[i].S<=m){ans+=p[i].F*p[i].S;m-=p[i].S;}
    	else {ans+=p[i].F*m;m=0; break;}

    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 2420
from collections import defaultdict
from itertools import permutations
# from math import gcd

def gcd(a, b):
    # ユークリッドの互除法による最大公約数
    if b == 0:
        return a
    return gcd(b, a % b)


def make_key2(i, j):
    return '-'.join([str(val) for val in sorted([i, j])])


def make_key3(i, j, k):
    return '-'.join([str(val) for val in sorted([i, j, k])])


if __name__ == '__main__':
    K = int(input())
    ans = 0
    mem2 = defaultdict()
    mem3 = defaultdict()
    for i in range(1, K + 1):
        for j in range(i, K + 1):
            for k in range(j, K + 1):

                set_ijk = list(set([i,j,k]))
                if len(set_ijk) == 1:
                    ans += i

                elif len(set_ijk) == 2:
                    key2 = make_key2(*set_ijk)
                    if key2 in mem2:
                        gcd1 = mem2[key2]
                    else:
                        gcd1 = gcd(*set_ijk)
                        mem2[key2] = gcd1
                    ans += gcd1 * 3
                else:
                    key3 = make_key3(*set_ijk)
                    if key3 in mem3:
                        gcd2 = mem3[key3]
                    else:
                        key2 = make_key2(i, j)
                        if key2 not in mem2:
                            gcd1 = gcd(i, j)
                            mem2[key2] = gcd1
                        else:
                            gcd1 = mem2[key2]

                        key2 = make_key2(gcd1, k)
                        if key2 not in mem2:
                            gcd2 = gcd(gcd1, k)
                            mem2[key2] = gcd2
                        else:
                            gcd2 = mem2[key2]
                    ans += gcd2 * 6

    print(ans)


Measured memory_bytes: 83820
#include<iostream>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
int DS[100010];
int DF[100010];
bool D[100010];
std::vector<int> G[100010];
int F, S;
int main() {
	int N;
	std::cin >> N;
	for (int i = 1; i <= N; i++) {
		DS[i] = 1 << 30;
	}
	for (int i = 1; i <= N; i++) {
		DF[i] = 1 << 30;
	}
	for (int i = 1; i < N; i++) {
		int a, b;
		std::cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	std::queue<int> q;
	q.push(N);
	DS[N] = 0;
	while (!q.empty()) {
		int t = q.front();
		q.pop();
		for (auto u : G[t]) {
			if (DS[u]>DS[t]+1) {
				DS[u] = DS[t] + 1;
				q.push(u);
			}
		}
	}
	q.push(1);
	DF[1] = 0;
	while (!q.empty()) {
		int t = q.front();
		q.pop();
		for (auto u : G[t]) {
			if (DF[u]>DF[t]+1) {
				DF[u] = DF[t] + 1;
				q.push(u);
			}
		}
	}
	for (int i = 1; i <= N; i++) {
		if (DF[i] == DS[i])F++;
		if (DF[i] > DS[i])S++;
		if (DF[i] < DS[i])F++;
	}
	std::cout << (F > S ? "Fennec" : "Snuke") << std::endl;
	return 0;
}

Measured memory_bytes: 6656
# 1 <= N <= 1000000
N = int(input())

total = []

# N項目までに含まれる->N項目は含まない。だからN項目は+1で外す。
for x in range(1, N+1):
    if x % 15 == 0:
        "FizzBuzz"
    elif x % 5 == 0:
        "Buzz"
    elif x % 3 == 0:
        "Fizz"
    else:
        total.append(x) #リストに加える
print(sum(total))

Measured memory_bytes: 30012
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

public class Main {

    void run() {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt(), a = sc.nextInt() - 1, b = sc.nextInt() - 1, c = sc.nextInt() - 1, d = sc.nextInt() - 1;
        String s = sc.next();

        UnionFind uf = new UnionFind(n);
        for (int i = 0; i < n - 2; i++) if (s.charAt(i) != '#' && s.charAt(i + 2) != '#') {
            uf.union(i, i + 2);
        }
        for (int i = 0; i < n - 1; i++) if (s.charAt(i) != '#' && s.charAt(i + 1) != '#') {
            uf.union(i, i + 1);
        }

        boolean ok = false;
        if (uf.same(a, c) && uf.same(b, d)) {
            if (c > d) {
                for (int i = b - 1; i < Math.min(d, n - 2); i++) {
                    if (s.charAt(i) != '#' && s.charAt(i + 1) != '#' && s.charAt(i + 2) != '#') {
                        ok = true;
                    }
                }
            }
            else {
                ok = true;
            }
        }
        System.out.println(ok ? "Yes": "No");
    }

    class UnionFind {
        private int n;
        private int[] parent, rank;

        public UnionFind(int n) {
            this.n = n;
            this.parent = new int[n];
            this.rank = new int[n];
            Arrays.fill(rank, 1);
            for (int i = 0; i < n; i++) parent[i] = i;
        }

        public void union(int x, int y) {
            int xr = find(x);
            int yr = find(y);

            if (xr > yr) {
                parent[yr] = xr;
            } else if (xr < yr) {
                parent[xr] = yr;
            } else {
                parent[yr] = xr;
                rank[yr]++;
            }

        }

        public int find(int x) {
            if (x != parent[x]) {
                parent[x] = find(parent[x]);
            }
            return parent[x];
        }

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

    }


    void debug(Object...os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 33336
#include<bits/stdc++.h>
using namespace std;
int main() 
{
	string s;
	cin>>s;
	long long res=0;
	for(int t=0; t<(1<<(s.size()-1)); t++)
	{
		long long tmp=s[0]-'0';
		for(int i=0; i<s.size()-1; i++)
		{
			if(t&(1<<i))
				res+=tmp, tmp=0;
			tmp*=10, tmp+=s[i+1]-'0';
		}
		res+=tmp;
	}
	cout<<res;
	return 0;
}


Measured memory_bytes: 256
#![allow(
  non_snake_case,
  unused_variables,
  unused_assignments,
  unused_mut,
  unused_imports,
  unused_macros,
  dead_code
)]
//use proconio::fastout;
use proconio::{input, marker::*};
use std::cmp::*;
use std::collections::*;
macro_rules! debug {
  ($($a:expr),* $(,)*) => {
      #[cfg(debug_assertions)]
      eprintln!(concat!($("| ", stringify!($a), "={:?} "),*, "|"), $(&$a),*);
  };
}
fn main() {
  input! {
    n:usize, A:[String;n]
  }
  // ip:整数部分, dp:小数部分
  // 1/512で0.001_953_125 で下9桁に届いてしまう。
  let mut cnt = vec![vec![0; 22]; 50];
  let mut p2 = vec![0; n];
  let mut p5 = vec![0; n];
  let A: Vec<String> = A;
  for i in 0..n {
    let s = A[i].clone();
    let mut ip = 0usize;
    let mut dp = 0;
    if let Some(i) = s.find('.') {
      // 小数の場合
      ip = s[0..i].parse().unwrap();
      let ss = s[(i + 1)..].to_string() + "0000000000";
      dp = ss[0..9].parse::<usize>().unwrap()
    } else {
      ip = s.parse::<usize>().unwrap();
    }
    let mut x = ip * 1_000_000_000 + dp;
    while x % 2 == 0 {
      x /= 2;
      p2[i] += 1;
    }
    while x % 5 == 0 {
      x /= 5;
      p5[i] += 1;
    }
    p2[i] = min(p2[i], 18);
    p5[i] = min(p5[i], 18);
    cnt[p2[i]][p5[i]] += 1;
  }

  let mut ans = 0usize;
  for i in 0..n {
    let remain2 = 18 - p2[i];
    let remain5 = 18 - p5[i];
    for j in remain2..50 {
      for k in remain5..22 {
        ans += cnt[j][k];
      }
    }
    if p2[i] >= remain2 && p5[i] >= remain5 {
      ans -= 1;
    }
  }
  println!("{}", ans / 2);
}


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

//struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((int)((a) + (b) - 1)/(int)(b))
#define int long long

signed main(){
    int r;
    cin >> r;
    printf("%.10f\n", M_PI * r * 2);
}

Measured memory_bytes: 3764
#include <map>
#include <algorithm>
#include <cassert>
#include <climits>
#include <complex>
#include <cstdio>
#include <string>
#include <iostream>
#include <queue>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
template<class T> bool chmin(T &a, T b) { return a>b?(a=b,true):false; }
template<class T> bool chmax(T &a, T b) { return a<b?(a=b,true):false; }
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
#define FOR(i,x,y) for(int i=(x);i<(int)(y);i++)
#define FORP(i,x,y) for(int i=(x);i<=(int)(y);i++)
#define REP(i,y) for(int i=0;i<(int)(y);i++)
#define REPP(i,y) for(int i=1;i<=(int)(y);i++)
#define REPB(i,n) for(int i=(int)(n)-1;i>=0;i--)

const int MAX_N = 100100;
int n,m;

// node 0 からの重み
int weights[MAX_N];

int main() {
  cin>>n>>m;
  REP(i,m)
  {
    int a,b;cin>>a>>b;a--,b--;
    if (a!=0) weights[a]++;
    if (b!=0) weights[b]++;
  }
  FOR(i,1,n)
  {
    if (weights[i]%2!=0)
    {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int N=100005;
ll a[N];
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  int k;
  cin>>k;
  rep(i,1,k+1) cin>>a[i];
  if(a[k]!=2)
    {
      cout<<-1<<endl;
      return 0;
    }
  ll mn=1,mx=1,mod=2;
  repv(i,1,k)
    {
      ll l=mn*mod,r=mx*mod+mod-1;
      if((r/a[i]-((l-1)/a[i]))==0)
	{
	  cout<<-1<<endl;
	  return 0;
	}
      ll f=(l+a[i]-1)/a[i];
      ll s=r/a[i];
      mn=f; mx=s; mod=a[i];
    }
  cout<<mn*mod<<" "<<mx*mod+mod-1<<endl;
  return 0 ;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define lli long long int
#define mod 1000000007
#define pb push_back
#define pf push_front
#define ulli unsigned long long int
#define what_is(x) cerr << #x << " is " << x << endl;
#define pi 2*acos(0.0)
#define F  first
#define S  second
#define endl '\n'
#define all(x) x.begin(),x.end()
using namespace std;
/*ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}*/
int main()
{
//cout.precision(9);
//cout.setf(ios::fixed,ios::floatfield);
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
	lli T=1;
    //cin>>T;
	while(T--)
	{
        lli n,i,w,j,k,l,wt,v;
        cin>>n>>w;
        lli dp[w+1]={0};
        for(i=0;i<n;i++)
        {
            cin>>wt>>v;
            for(j=w-wt;j>=0;j--)
            {
                dp[j+wt]=max(dp[j+wt],dp[j]+v);
            }
        }
        cout<<*max_element(dp,dp+w+1)<<endl;
    }
}


Measured memory_bytes: 1024
//  @ /\/\ BESH //

#include <bits/stdc++.h>
#define inp_out_work ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define testCase    int T; cin>>T; while(T--)
#define fr(i,n) for(int i=0;i<n;i++)
#define fro(i,s,e) for(int i=s;i<=e;i++)
#define endl '\n'
#define debug(P) cout<<#P<<" = "<<P<<endl;
#define pb push_back
#define FILE freopen("in.txt","r",stdin); freopen("out.txt","w",stdout);


using namespace std;

typedef long long ll;
typedef long double ld;

const int MAXN = 1000001;
const int mod = 1e9 + 7;


int main(){
    int n, m;
    cin>>n>>m;
    string s[n];
    fr(i,n)cin>>s[i];
    int N = n*m;

    ll a[N][N];

    fr(i,N)fr(j,N)a[i][j] = (i==j)? 0 : INT_MAX;

    fr(i,n){
        fr(j,m){
            if(s[i][j] == '.' && i+1 < n && s[i+1][j] == '.'){
                a[i*m + j][(i+1)*m + j] = 1;
                a[(i+1)*m + j][i*m + j] = 1;
            }
            if(s[i][j] == '.' && j+1 < m && s[i][j+1] == '.'){
                a[i*m + j][i*m + j+1] = 1;
                a[i*m + j+1][i*m + j] = 1;
            }
        }
    }

    //Floyd Warshall
    for(int k = 0; k < N; ++k){
        for(int i = 0; i < N; ++i){
            for(int j = 0; j < N; ++j){
                if(a[i][j] > a[i][k] + a[k][j]){
                    a[i][j] = a[i][k] + a[k][j];
                }
            }
        }
    }

    ll ans = 0;
    for(int i = 0; i < N; ++i){
        for(int j = 0; j < N; ++j){
            if(a[i][j] != INT_MAX)ans = max(ans, a[i][j]);
        }
    }

    cout<< ans << endl;

}


Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef pair<int,int> pint;
typedef pair<long long,long long> pll;
typedef long long ll;
const int inf   = 1<<29;
const ll  longinf = 1LL<<60;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};

int main(){
  int n;
  ll cap;
  cin>>n>>cap;
  vector<ll> a[4];
  ll v[n],w[n];
  rep(i,n){
    cin>>w[i]>>v[i];
    a[w[i]-w[0]].push_back(v[i]);
  }
  rep(i,4){
    sort(a[i].begin(),a[i].end());
    a[i].push_back(0);
    reverse(a[i].begin(),a[i].end());
    rep(j,a[i].size()-1)
      a[i][j+1]+=a[i][j];
    }
  ll ans=0;
  rep(i,a[0].size())rep(j,a[1].size())rep(k,a[2].size()){
    ll wsum=w[0]*i+(w[0]+1)*j+(w[0]+2)*k,vsum=a[0][i]+a[1][j]+a[2][k];
    if(wsum>cap)continue;
    ll x=a[3].size();
     x=min(x,(cap-wsum)/(w[0]+3));
    vsum+=a[3][x];
    ans=max(ans,vsum);
    }
  cout<<ans<<endl;
  return 0;
  }   


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

		int W = sc.nextInt();
		int H = sc.nextInt();
		int x = sc.nextInt();
        int y = sc.nextInt();
        int r = sc.nextInt();

        if(W==x || H==y) {
            System.out.printf("No\n");
        } else if(x-r<0 || x+r>W || y-r<0 || y+r>H){
            System.out.printf("No\n");
        } else {
             System.out.printf("Yes\n");
        }
    } 
}


Measured memory_bytes: 26364
from sys import stdin
import sys
import numpy as np
import collections
from functools import cmp_to_key

##  input functions for me
def rsa(sep = ''):
    if sep == '' :
        return input().split() 
    else: return input().split(sep)
def rip(sep = ''):
    if sep == '' :
        return map(int, input().split()) 
    else: return map(int, input().split(sep))
def ria(sep = ''): 
    return list(rip(sep))
def ri(): return int(input())
def rd(): return float(input())
def rs(): return input()
##
def main():
    H, W, A, B = rip()
    a = [['0'] * W for i in range(H)]
    for i in range(B):
        for j in range(A):
            a[i][j] = '1'
    for i in range(B,H):
        for j in range(A,W):
            a[i][j] = '1'
    for i in range(H):
        print(''.join(a[i]))


if __name__ == "__main__":
    main()


Measured memory_bytes: 21196
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD 1000000007
using Graph = vector<vector<int>>;
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
int main (){
  int N;
  cin>>N;
  vector<Bint>A(N);
  rep(i,N) cin>>A[i];
  Bint ans=1;
  sort(A.begin(),A.end());
  rep(i,N){
    ans*=A[i];
      if(ans>1000000000000000000){ 
    cout<<-1;
    return 0;
  }

  }

   cout<<ans;
}


Measured memory_bytes: 6504
#include<iostream>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;

int N, K, sum[200001], ans;

int main() {
    cin >> N >> K;
    rep(i, N) {
        cin >> sum[i+1];
        sum[i+1] += sum[i] + 1;
    }
    rep(i, N - K + 1) {
        ans = max(ans, sum[i + K] - sum[i]);
    }
    printf("%f\n", ans / 2.0);
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#define N 37

typedef struct {
  char a;
  int num;
}data;

data *BubbleSort(data *,int);
data *SelectionSort(data *,int);
void swap(data*,data*);
int cheak(data*,data*,int);

int main(){
  data member[N],member2[N],*result,*result2;
  int i,n;

  scanf("%d",&n);
 

  for(i=0;i<n;i++){
    scanf(" %c%d",&member[i].a,&member[i].num);   
  }
 for(i=0;i<n;i++){
 member2[i]=member[i];
 }

result=BubbleSort(member,n);

 

for(i=0;i<n;i++){
printf("%c%d",result[i].a,result[i].num);
if(i!=n-1)
printf(" ");
}
printf("\n");

  printf("Stable\n");


result2=SelectionSort(member2,n);

for(i=0;i<n;i++){
printf("%c%d",result2[i].a,result2[i].num);
if(i!=n-1)
printf(" ");
}
printf("\n");
if(cheak(result2,result,n)==0){
  printf("Stable\n");
} else printf("Not stable\n");


return 0;
}

data* BubbleSort(data *da,int n){
  data *change;
  int i,j;
  change=da;
  for(i=0;i<n;i++){
    for(j=n-1;j>0;j--){
      if(change[j].num<change[j-1].num)
      swap(&change[j],&change[j-1]);
      }
  }
  return change;
}

data* SelectionSort(data *dai,int n){
  data *change;
  int i,j,minj;
  change=dai;

  for(i=0;i<n;i++){
    minj=i;
    for(j=i;j<n;j++){
      if(change[j].num<change[minj].num)
      minj=j;
    }
  
   if(i!=minj)
    swap(&change[i],&change[minj]);
  }
return change;
}


void swap(data *x,data *y){
 data change;

 change=*x;
 *x=*y;
 *y=change;
}

int cheak(data *x,data *a,int n){
  int i;
   for(i=0;i<n;i++){
    if(x[i].a!=a[i].a)
    return 1;
  }
  return 0;
}


Measured memory_bytes: 1996
#include <iostream>

using namespace std;

int main()
{ 
	int a[100000];
	bool f[100000] = {};
	int n, l = 0, c = 0;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}

	while (l != 1 && f[l] != true){
		f[l] = true;
		l = a[l] - 1;
		c++;
	}
	if (l == 1) cout << c << endl;
	else cout << -1 << endl;

	return (0);
}


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

int main()
{
    int A, B;
    cin >> A >> B;

    int R;
    R = A - 2 * B;
    if (R >= 0) {
        cout << R << endl;
    }
    else {
        cout << 0 << endl;
    }

    return 0;
}

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

int main(){
	string A;
	cin >> A;
	int bit = 0;
	vector<int> par;
	for(int i = A.size() - 1; i >= 0; --i){
		int t = A[i] - 'a';
		bit |= (1<<t);
		if(bit + 1 == (1<<26)){
			par.push_back(i);
			bit = 0;
		}
	}
	int len = par.size();
	vector<char> ans;
	int now = 0;
	for(int i = len; i >= 0; --i){
		if(i != len){
			while(A[now] != ans[ans.size() - 1]) now++;
			now++;
		}
		bit = 0;
		if(i != 0){
			for(; now < par[i-1]; ++now){
				int t = A[now] - 'a';
				bit |= (1<<t);
			}
			for(int j = 0; j < 26; ++j){
				if(!(bit & (1<<j))){
					char c = 'a' + j;
					ans.push_back(c);
					break;
				}
			}
		}else{
			for(; now < A.size(); ++now){
				int t = A[now] - 'a';
				bit |= (1<<t);
			}
			for(int j = 0; j < 26; ++j){
				if(!(bit & (1<<j))){
					char c = 'a' + j;
					ans.push_back(c);
					break;
				}
			}
		}
	}
	
	for(int i = 0; i < ans.size(); ++i) cout << ans[i];
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
char mp[3][3][4];
string str[10];
bool used[9];long long cnt,ans;
void saiki2(int num){
  int ex[] ={0,0,2,2};
  int ey[] ={2,0,0,2};
  int tx[4][2] = {{1,0},{0,1},{-1,0},{0,-1}};
  int ty[4][2] = {{0,-1},{1,0},{0,1},{-1,0}};
  if(num == 4) ans++;
  else
    for(int i=0;i<9;i++){
      if(used[i] == 1) continue;
      for(int j=0;j<4;j++){
	int nx = ex[num]+tx[num][0];
	int nx2 = ex[num]+tx[num][1];
	int ny = ey[num]+ty[num][0];
	int ny2 = ey[num]+ty[num][1];
	if(abs(str[i][j] - mp[ny][nx][(num+3)%4])=='a'-'A' &&
	   abs(str[i][(j+3)%4] - mp[ny2][nx2][(num+2)%4]) == 'a'-'A'){
	  used[i] = 1;
	  saiki2(num+1);
	  used[i] = 0;
	}	 
      }
    }
}

void saiki(int num){
int dx[] = {0,-1,0 ,1};
int dy[] = {1,0,-1,0};
  if(num == 4) {
    saiki2(0);
    return;
  }
  for(int i=0;i<9;i++){
    if(used[i] == 1) continue;
    for(int j=0;j<4;j++)
      if(abs(mp[1][1][(num+2)%4] - str[i][j])=='a'-'A') {
	for(int k=0;k<4;k++) mp[1+dy[num]][1+dx[num]][(k+num)%4] = str[i][(j+k)%4];
	used[i] = 1;
	saiki(num+1);
	used[i] = 0;
      }
  }
}

int main(){
  int n;
  cin >> n;
  while(n--){
    ans = 0;
  for(int i=0;i<9;i++) cin >> str[i];
  for(int i=0;i<=9;i++){
    for(int j=0;j<4;j++) mp[1][1][j] = str[i][j];
    used[i] = 1;
    saiki(0);
    used[i] = 0;
  }
  cout << ans*4<<endl;
  }
  return 0;     
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
#include <string>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define pii pair<int, int>
#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
//#define ordered_multiset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long
#define jai_shree_ram  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i, a, b, d) for (int i = a; i <= b; i += d)
#define brep(i, a, b, d) for (int i = a; i >= b; i -= d)
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl '\n'
int MAX = 1e5 + 5;
int MOD = 1e9 + 7;
////////////////////////////////
int n;
vector <int> g[100005];
int dp[100005][2];

int dfs(int x, int pp, int col){
    if(dp[x][col]) return dp[x][col];

    int ans = 1;
    if(g[x].size() == 1 and g[x][0] == pp) return 1;
    if(n == 1) return 1;

    for(auto y: g[x]){
        if(y == pp) continue;
        if(!col) ans *= (dfs(y, x, 0) + dfs(y, x, 1))%MOD;
        else ans *= dfs(y, x, 0);  
        ans %= MOD;
    }

    return dp[x][col] = ans%MOD;
}

int32_t main(){
    jai_shree_ram
    cin >> n;
    rep(i,1,n-1,1){
        int u, v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    cout << (dfs(1, 0, 0) + dfs(1, 0, 1))%MOD << endl;
    return 0; 
}

Measured memory_bytes: 14208
#include <bits/stdc++.h>
using namespace std;
using Pi = pair<int, int>;
bool solve() {
    int N;
    cin >> N;
    if (N == 0) return (false);
    int bm;
    int X[15], Y[15];
    vector<Pi> base[8];
    
    auto rotate = [](int &x, int &y) {
        swap(y = -y, x);
    };
    
    cin >> bm;
    for (int i = 0; i < bm; i++) cin >> X[i] >> Y[i];

    for (int i = 1; i < bm; i++) {
        int x = X[i] - X[0], y = Y[i] - Y[0];
        for (int j = 0; j < 4; j++) {
            base[j].emplace_back(x, y);
            rotate(x, y);
        }
    }

    for (int i = bm - 2; i >= 0; i--) {
        int x = X[i] - X[bm - 1], y = Y[i] - Y[bm - 1];
        for (int j = 4; j < 8; j++) {
            base[j].emplace_back(x, y);
            rotate(x, y);
        }
    }

    for (int i = 0; i < N; i++) {
        int m, bx, by;
        cin >> m;
        cin >> bx >> by;
        vector<Pi> comp;
        bool flag = false;
        for (int i = 0; i < m - 1; i++) {
            int x, y;
            cin >> x >> y;
            x -= bx, y -= by;
            comp.emplace_back(x, y);
        }
        if (m != bm) continue;
        for (int i = 0; i < 8; i++) {
            if (comp == base[i]) flag = true;
        }
        if (flag) cout << i + 1 << endl;
    }
    cout << "+++++" << endl;
    return (true);
}

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


Measured memory_bytes: 3092
def main():
    n = int(input())
    a = list(map(int, input().split()))
    alice, bob = 0, 0
    a = sorted(a)
    for i, x in enumerate(a[::-1]):
        if i % 2 == 0:
            alice += x
        else:
            bob += x
    print(alice - bob)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9176
#include <iostream>
#include <cmath>
#include <cstdio>

using namespace std;

int main()
{
    int x,sum,i,j,z,y;
    sum=0;
    cin>>x;
    if(x==1)
        cout<<1<<endl;
    else
    {
        for(i=2; pow(i,2)<=x; i++)
            for(j=2; pow(i,j)<=x; j++)
            {
                if(pow(i,j)>=sum)
                {
                    sum=pow(i,j);
                    z=i;
                    y=j;
                }
            }
        cout<<pow(z,y)<<endl;
    }
    return 0;
}


Measured memory_bytes: 512
// Author : Rifayat Samee (Sanzee)
// Problem :
// Algorithm:

/*

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

int main(){

	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
    int n,k;
    scanf("%d %d",&n,&k);
    vector<int>A(n+1);
    for(int i=0;i<n;i++){
        scanf("%d",&A[i]);
    }
    vector<bool>dp(k+5,false);
    for(int val = 1;val<=k;val++){
        for(int i = 0;i<n;i++){
            if(val-A[i]>=0){
                dp[val] = dp[val] | !(dp[val-A[i]]);
            }
        }
    }
    if(dp[k]) printf("First\n");
    else
        printf("Second\n");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e3 + 5;
//head
ll n, a[5];
int main() {
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
    while(cin >> n) {
        for(int i = 0; i < 5; ++i) cin >> a[i];
        sort(a, a + 5);
        if(n <= a[0]) cout << 5 << endl;
        else {
            ll ans = (n-1)/a[0] + 1;
            ans += 4;
            cout << ans << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
<?php
     fscanf(STDIN, "%s", $n);
     $n = str_split($n);
     $cnt = 0;
     $len = count($n);
     for($i=0; $i<$len; $i++){
         $cnt += $n[$i];
      }

      if($cnt%9==0){
          echo "Yes";
      }else{
          echo "No";
      }

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

using namespace std;
using ll = long long;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

const int mod = 1e9 + 7;
ll dp[100005][2];

int main() {
  string s;
  cin >> s;
  int n = s.size();
  dp[0][0] = 1;
  rep(i, n) {
    if (s[i] == '0') {
      (dp[i + 1][0] += dp[i][0]) %= mod;
      (dp[i + 1][1] += dp[i][1] * 3 % mod) %= mod;
    } else {
      (dp[i + 1][0] += dp[i][0] * 2 % mod) %= mod;
      (dp[i + 1][1] += (dp[i][0] + dp[i][1] * 3 % mod) % mod) %= mod;
    }
  }
  cout << (dp[n][0] + dp[n][1]) % mod << endl;
  return 0;
}


Measured memory_bytes: 5300
n, k =  [ int(v) for v in input().split() ]
num_list = [ int(v) for v in input().split() ]

count_list = [ 0 for i in range(n) ]
for i in num_list:
	count_list[i-1] += 1
count_list.sort(reverse = True)
print(n-sum(count_list[:k]))

Measured memory_bytes: 25604
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

int main(){
	int N,K; cin>>N>>K;
	string s; cin>>s;
	vector<pair<char,int>> rang;
	rang.push_back(make_pair(s[0], 1));
	int ans = 0;
	for(int i = 1; i<N; ++i){
		char c = rang[rang.size()-1].first;
		if(s[i] == s[i-1])ans ++;
		if(c != s[i]){
			rang.push_back(make_pair(s[i], 1));
		}else{
			rang[rang.size()-1].second++;
		}
	}
	int nax = rang.size()/2;
	cout<<min(ans + 2*K, N-1)<<endl;
}

// int N, K;
// string s;

// int solve(vector<pair<char,int>> rang, char t, int type){
// 	vector<P> cnt;
// 	rep(i,rang.size()){
// 		if(rang[i].first != t){
// 			cnt.push_back(make_pair(rang[i].second, i));
// 		}
// 	}
// 	if(type)sort(all(cnt)); else sort(all(cnt), greater<P>());
// 	int lp = min((int)cnt.size(), K);
// 	rep(i,lp){
// 		rang[cnt[i].second].first = t;
// 	}
// 	cout<<lp<<' '<<cnt.size()<<endl;

// 	// cout<<line<<endl;
// 	// rep(i,rang.size()){
// 	// 	if(rang[i].first == t)continue;
// 	// 	printf("%c, %d\n", rang[i].first, rang[i].second);
// 	// }

// 	int ans = 0;
// 	rep(i,rang.size()){
// 		int e_ans = rang[i].second;
// 		while(rang[i].first == rang[i+1].first){
// 			e_ans += rang[++i].second;
// 		}
// 		ans += e_ans-1;
// 		// cout<<e_ans<<endl;
// 	}
// 	// cout<<ans<<endl;
// 	return ans;
// }

// int main(){
// 	cin>>N>>K>>s;
// 	vector<pair<char, int>> rang;
// 	rang.push_back(make_pair(s[0], 1));
// 	int i;
// 	for(i = 1; i<N; ++i){
// 		char c = rang[rang.size()-1].first;
// 		if(c != s[i]){
// 			rang.push_back(make_pair(s[i], 1));
// 		}else{
// 			rang[rang.size()-1].second++;
// 		}
// 	}
// 	cout<<rang.size()<<endl;
// 	int x = 0;
// 	rep(i,rang.size())x += rang[i].second;
// 	cout<<x<<endl;
// 	cout<<max({solve(rang, 'R', 0), solve(rang, 'R', 1), solve(rang, 'L', 0), solve(rang, 'L', 1)})<<endl;
// 	return 0;
// }

Measured memory_bytes: 1528
#include<stdio.h>
#include<stdlib.h>
    
#define MIN_VALUE 3
#define MAX_VALUE 300
#define IS_ERR(n) (n < MIN_VALUE || n > MAX_VALUE)
    
typedef struct _Rect {
    int w;
    int h;
    struct _Rect *next;
} Rect;
    
int main(void)
{
    
    int w, h;
    Rect *rect;
    Rect *pre_rect;
    Rect *start_rect;
    
    pre_rect = (Rect *)malloc(sizeof(Rect));
    pre_rect->w = 0;
    pre_rect->h = 0;
    pre_rect->next = NULL;
    
    start_rect = pre_rect;
    
    while(1)
    {
        scanf("%d %d", &h, &w);
  
        if(w == 0 && h == 0) break;
        if(IS_ERR(w) || IS_ERR(h)) return -1;
    
        rect = (Rect *)malloc(sizeof(Rect));
        rect->w = w;
        rect->h = h;
        rect->next = NULL;
    
        pre_rect->next = rect;
        pre_rect = rect;
    }
    
    rect = start_rect->next;
    
    while(1)
    {
        for(int i=0;i<(rect->h);i++)
        {
            for(int j=0;j<(rect->w);j++)
            {
                if(i == 0 || i == (rect->h - 1) || j == 0 || j == (rect->w - 1))
                {
                    printf("#");
                }
                else
                {
                    printf(".");
                }
            }
            printf("\n");
        }
    
        printf("\n");
    
        rect = rect->next;
        if(rect == NULL) break;
    }
    
    return 0;
}


Measured memory_bytes: 1912
///#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
///#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,popcnt,avx,avx2,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

/*
    zet:
        find_by_order(k): k-stat [k > 0]
        order_of_key(k) : {el < k}

    gp_hash_table<key, val, custom_hash>

    rope<T>:
        iterators: mutable_begin, ..
        methods  : erase, insert, substr, ..
*/

#define all(x) (x).begin(), (x).end()
#define size(x) (int)((x).size())
#define em_back emplace_back

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

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

template<typename T>
using zet = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

mt19937 eng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e5 + 4;

struct slide {
    int l, r;
    deque<pll> d;

    slide() {
        l = r = 0;
    }

    void push_back(ll x) {
        while (size(d) && d.back().second <= x) {
            d.pop_back();
        }
        d.push_back(pll(r + 1, x));
        ++r;
    }

    void pop_front() {
        if (d.front().first == l) {
            d.pop_front();
        }
        ++l;
    }

    ll getMax() {
        if (size(d) == 0) {
            return 0;
        }
        return d.front().second;
    }
};

int n, m, k, a[N];
ll dp[N][2];

void solve() {
    cin >> n >> m >> k;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }

    int it = 1;
    for (int i = 1; i <= k; ++i) {
        slide window;
        for (int j = 1; j <= n; ++j) {
            if (j >= i) {
                dp[j][it] = window.getMax() + (ll)i * a[j];
            }

            if (j >= i - 1) {
                window.push_back(dp[j][it ^ 1]);
                if (window.r - window.l == m) {
                    window.pop_front();
                }
            }
        }
        it ^= 1;
    }

    ll res = 0;
    for (int i = k; i <= n; ++i) {
        res = max(res, dp[i][it ^ 1]);
    }

    cout << res << "\n";
}

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

    int z = 1;
    /// cin >> z;

    while (z--) {
        solve();
    }

    return 0;
}



Measured memory_bytes: 5580
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define era(t) t.erase(unique(be(t)),t.end())
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    string s;
    int r[m],l[m];
    cin>>s;
    int a[n];
    a[0]=0;
    for(int i=1;i<n;i++){
        a[i]=a[i-1];
        if(s[i]=='C'&&s[i-1]=='A'){
            a[i]++;
        }
    }
    for(int i=0;i<m;i++){
        cin>>l[i]>>r[i];
        
    }
    for(int i=0;i<m;i++){
        cout << a[r[i]-1]-a[l[i]-1]<<endl;
    }
    return 0;
}


Measured memory_bytes: 2256
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("avx")
#include <bits/stdc++.h>
#define re return
#define pb push_back
#define po pop_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define ss second.second
#define sf second.first
#define ff first.first
#define fs first.second
#define si size
#define sqrt(x) sqrt(abs(x))
#define mp make_pair
#define pi 3.14159265359
#define er erase
#define in insert
#define em empty
#define ft front
#define fo(i,n) for(i = 0; i < n; i++)
#define ro(i,n) for(i = n - 1; i >= 0; i--)
#define fr(i,j,n) for(i = j; i < n; i++)
#define rf(i,j,n) for(i=n-1;i>=j;i--)
typedef std::vector<int> vi;
typedef std::vector<vi> vvi;
typedef std::pair<int,int> ii;
typedef std::vector<ii> vii;
typedef std::vector<std::string> vs;
typedef double dl;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<ll, ll> pll;
typedef std::vector<ll> vll;
#define filename ""
using namespace std;
    string a[5];
int main()
{
    /*
	freopen(filename".in","r",stdin);
	freopen(filename".out","w",stdout);
	*/
	/*
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    */
    /*
    ios::sync_with_stdio(0);
    */
    string s;
    cin>>s;
    int i,j;
    int k;
    fo(i,5)
    {
        a[i]="{";
    }
    cin>>k;
    string t;
    int q,w;
    fo(i,s.length())
    {
        fr(j,1,6)
        {
            t=s.substr(i,j);
            fo(q,5)
            {
                if (t==a[q]) break;
                if (t<a[q])
                {
                    rf(w,q+1,5)
                    {
                        a[w]=a[w-1];
                    }
                    a[q]=t;
                    break;
                }
            }
        }
    }
    /*fo(i,5)
    {
        cout<<a[i]<<' ';
    }*/
    cout<<a[k-1];
}

Measured memory_bytes: 256
module Main where

import Control.Applicative
import Control.Monad
import Data.List (transpose)

compress :: [String] -> [String]
compress ass = filter (not . all (== '.')) ass

main :: IO ()
main = do
    [h, w] <- fmap read . words <$> getLine :: IO [Int]
    ass <- replicateM h getLine
    let ans = transpose . compress . transpose $ compress ass
    putStrLn $ unlines ans

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

#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define rep(i, st, n) for (int i = (st); i < (n); ++i)
#define repinv(i, st, n) for (int i = ((n)-1); i >= (st); --i)
#define MEM(a, b) memset(a, b, sizeof(a));
#ifdef LOCAL
#define debug(x) std::cerr << #x << ": " << x << endl
#else
#define debug(x) 860111
#endif
#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileIO(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;

//mt19937 mrand(random_device{}());
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod=1e9+7;
//int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
pii operator+(const pii&x, const pii&y) { return mp(x.X+y.X, x.Y+y.Y);}
pii operator-(const pii&x, const pii&y) { return mp(x.X-y.X, x.Y-y.Y);}
//INT_MAX, ULLONG_MAX, LLONG_MAX or numeric_limits<int>::min()

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

//------------------------------------------------------------------------//
int T;
const int maxn = 2e5+7;
int n;
//ll a[maxn];

//check T
void solve()
{
	//cin >> n; rep(i, 0, n) cin >> a[i];
  int n, m;
  cin >> n >> m;
  cout << (n ? n*(n-1)/2 : 0) + (m ?  m*(m-1)/2 : 0) << endl;
  return;
}


signed main()
{
  fastIO();
  T = 1;
  //cin >> T; //this
  while(T--) solve();
  return 0;
}


Measured memory_bytes: 256
# 文字列の入力
S = str(input())

if S == 'SAT':
    print(1)
elif S == 'SUN':
    print(7)
elif S == 'MON':
    print(6)
elif S=='TUE':
    print(5)
elif S=='WED':
    print(4)
elif S=='THU':
    print(3)
else:
    print(2)

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int m;
  cin >> m;
  
  vector<long long> d(m), c(m);
  for(int i = 0; i < m; i++) cin >> d.at(i) >> c.at(i);
  
  long long ans = 0;
  for(int i = 0; i < m; i++) ans += c.at(i);
  ans--;
  
  long long keep = 0;
  for(int i = 0; i < m; i++){
    keep += d.at(i) * c.at(i);
  }
  ans += (keep - 1) / 9;
  
  cout << ans << "\n";
}

Measured memory_bytes: 3328
use std::cmp;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        h: [i32; n],
    }

    let mut memo = vec![-1; 100000]; // -1が10個
    memo[0] = 0;
    memo[1] = (h[1] - h[0]).abs();
    let r = dp(n-1, &mut memo, &h);
    println!("{}", r);
}

fn dp(i: usize, memo: &mut Vec<i32>, h: &Vec<i32>) -> i32 {
    if memo[i] != -1 {
        // println!("{}: {}", i, memo[i]);
        return memo[i];
    }

    let v = cmp::min(dp(i-1, memo, h) + (h[i] - h[i-1]).abs(), dp(i-2, memo, h) + (h[i] - h[i-2]).abs());
    // println!("{}: {}", i, v);
    memo[i] = v;
    return v
}


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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
    cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args&&... args) {
    const char *comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#define pi 3.141592653589
#define MOD 1000000007
#define to() int t; cin>>t; while(t--)
#define pb push_back
#define in insert
#define mp make_pair
#define ff first
#define ss second
#define si(s) s.size()
#define fori(it,v) for(it=v.begin();it!=v.end(); it++) 
#define for1(low,high,k) for(int i=low;i<high;i+=k)
#define for11(low,high,k) for(int j=low;j<high;j+=k)
#define for2(low,high,k) for(int i=low;i<=high;i+=k)
#define rev(high,low,k)  for(int i=high;i>=low ;i-=k)
#define all(x) x.begin(), x.end()
#define fil(x,i) memset(x,i,sizeof(x));
#define setbits(x) __builtin_popcount(x)
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define read freopen("input.txt","r",stdin)
#define write freopen("output.txt","w",stdout) 
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;


int main()
{
	boost;
	int n; cin>>n;
	vector<ll>v(n);
	for1(0,n,1) cin>>v[i];
	ll sum=0,maxi=v[0];
	for1(1,n,1){
		if(maxi>v[i]){
			sum+=maxi-v[i];
		}
		else
			maxi=v[i];
	}
	cout<<sum<<endl;
	
	
return 0;
}


Measured memory_bytes: 4780
var n:longint;
    i,k:longint;
    a,b,c,d:array[0..201000]of int64;
    m0,m1:int64;
    ans,x,y:int64;
procedure qs(l,r:longint);
var i,j,m,t:longint;
begin
  i:=l;
  j:=r;
  m:=c[(l+r)>>1];
  repeat
    while c[i]<m do inc(i);
    while c[j]>m do dec(j);
    if i<=j then
    begin
      t:=c[i];c[i]:=c[j];c[j]:=t;
      inc(i);
      dec(j);
    end;
  until i>j;
  if l<j then qs(l,j);
  if i<r then qs(i,r);
end;
function find(x:int64):longint;
var l,r,m:longint;
begin
  l:=1;
  r:=n;
  while l<=r do
  begin
    m:=(l+r)>>1;
    if c[m]<x then l:=m+1 else r:=m-1;
  end;
  exit(l);
end;

begin
  read(n);
  for i:=1 to n do
  read(a[i]);
  for i:=1 to n do
  read(b[i]);
  c[0]:=-1;
  c[n+1]:=1 << 45;
  for k:=1 to 29 do
  begin
    x:=1 << k;
    y:=1 << (k-1);
    for i:=1 to n do
    begin
      c[i]:=a[i] and (x-1);
      d[i]:=b[i] and (x-1);
    end;
    qs(1,n);
    m0:=0;
    m1:=0;
    for i:=1 to n do
    begin
      m1:=m1+find(x-d[i])-find(y-d[i]);
      m1:=m1+n+1-find(x+y-d[i]);
    end;
    if m1 and 1 =1 then ans:=ans+y;
  end;
  writeln(ans);
end.



Measured memory_bytes: 6400
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(x) (x).begin(),(x).end()
#define dup(x,y) (((x)+(y)-1)/(y))
#define sz(x) (int)(x).size()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(){
    string s;
    int a = 0;
    cin >> s;
    rep(i,4){
        if(s[i] == '+') a++;
        else a--;
    }
    cout << a << endl;
    return 0;
}

Measured memory_bytes: 256
//void __(){
//    ll n,k;
//    cin >> n >> k;
//    ll ans = 0;
//    rep(mod,k+1,n){
//        rep(times,0,n/mod){
//            ll lo = times*mod+k;
//            lo = max(lo,1ll);
//            ll hi = (times+1)*mod-1;
//            hi = min(hi,n);
//            if(lo > hi)
//                continue;
//            ans += hi-lo+1;
//        }
//    }
//    print ans;
//}
//
#include <iomanip>
#include <algorithm>
#include <cassert>
#include <vector>
#include <utility>
#include <iostream>
#include <string>
#define REP_INT(i,l,r) for(int i = l; i <= r; ++i)
#define GET_REP_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define rep(...) GET_REP_MACRO(__VA_ARGS__,REP_ANY,REP_INT,REP_ZERO_INT)(__VA_ARGS__)
#define all(v) (v).begin(), (v).end()
#define sz(v) ll(v.size())
#define T1 template<typename T> static
using namespace std;
typedef long long ll;
T1 ostream& operator<<(ostream& stream, const vector<T>& t);
T1 istream& read(T, T, istream& = cin);
struct _print {
    string sep,end;
    bool space;
    ostream &stream;
    _print(string _sep=" ",string _end="\n",
            ostream &_stream = cout)
        : sep(_sep),end(_end),space(false),
            stream(_stream) {}
    ~_print() { stream << end; }
    template <typename T>
        _print &operator , (const T &t) {
            if (space) stream << sep;
            space = true;
            stream << t;
            return *this;
        }
};
#define print _print(),
void __(){
    ll n,k;
    cin >> n >> k;
    ll ans = 0;
    rep(mod,k+1,n){
        rep(times,0,n/mod){
            ll lo = times*mod+k;
            lo = max(lo,1ll);
            ll hi = (times+1)*mod-1;
            hi = min(hi,n);
            if(lo > hi)
                continue;
            ans += hi-lo+1;
        }
    }
    print ans;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
        __();
}


Measured memory_bytes: 256