akhauriyash/Code-Regression huggingface dataset:
////////////////いろいろあるよ//////////////////////////////////
//include,namespace
 #include<bits/stdc++.h>
 #include<iostream>
 #include<bitset>
 using namespace std;
//REPmacro
 #define all(x) (x).begin(),(x).end()             //ソート
 #define FOR(i,x,n)for(int i=(x);i<(n);i++)
 #define FOR_R(i,x,n) for(int i=(n-1);i>=(x);i--)
 #define REP(i, n) FOR(i, 0, n)
 #define REP_R(i, n) FOR_R(i, 0, n)
//long long(define)
 using ll = long long;
 typedef long long ll;
 typedef long long int64;
 typedef long long lint;
 typedef long long lli;
////////////////いろいろあるよ//////////////////////////////////

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

Measured memory_bytes: 256
// {{{ Template
// Author:  wenxing
// Date:    2018-01-07 20:08 +0800
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
#define rep(i, l, r) for (int i = l; i < r; ++i)
#define per(i, r, l) for (int i = r; i >= l; --i)
#define repv(ele, vec) for (auto &ele : vec)
#define zero(mem) memset(mem, 0, sizeof(mem))
#define sd(_) scanf("%d", &_)
#define sdd(_, __) scanf("%d%d", &_, &__)
#define sddd(_, __, ___) scanf("%d%d%d", &_, &__, &___)
#define sdddd(_, __, ___, ____) scanf("%d%d%d%d", &_, &__, &___, &____)

#define sf(_) scanf("%f", &_)
#define sff(_, __) scanf("%f%f", &_, &__)
#define sfff(_, __, ___) scanf("%f%f%f", &_, &__, &___)
#define sffff(_, __, ___, ____) scanf("%f%f%f%f", &_, &__, &___, &____)

#define sl(_) scanf("%ld", &_)
#define sll(_, __) scanf("%ld%ld", &_, &__)
#define slll(_, __, ___) scanf("%ld%ld%ld", &_, &__, &___)
#define sc(_) scanf("%c", &_)
#define ss(_) scanf("%s", _)
#define mid(a, b) (((a) + (b)) >> 1)
#define lft(x) x << 1
#define rht(x) x << 1 | 1
#define inf 0x3f3f3f3f
#define mod 19260817
#define mp make_pair
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
// }}}

// - Pseudocode -

// {{{ Global Variables
int n, m, x, y, z;
int v[3] = {1, 5, 10};
// }}}

int main() {
    sdd(n, m);
    if (m % 1000 != 0)
        puts("-1 -1 -1");
    else {
        m /= 1000;

        int can = 0;
        for (x = 0; 10 * x <= m; ++x) {
            int c = m - n - 9 * x;
            if (c >= 0 && c % 4 == 0) {
                y = c / 4;
                z = n - x - y;
                if (z >= 0) {
                    can = 1;
                    break;
                }
            }
        }
        if (can)
            printf("%d %d %d\n", x, y, z);
        else
            puts("-1 -1 -1");
    }
    return 0;
}


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

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 110;

int n;
map<string, int> cnt;

int main()
{
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        cnt[s]++;
    }

    int maxa = 0;
    for(map<string, int>::iterator it = cnt.begin(); it != cnt.end(); it++)
        maxa = max(maxa, it->second);

    for(map<string, int>::iterator it = cnt.begin(); it != cnt.end(); it++)
        if(it->second == maxa)
            cout << it->first << endl;
    return 0;
}


Measured memory_bytes: 26240
import sys
sys.setrecursionlimit(1000000)

def MST(n, E):
    def par(m):
        if UF[m] == m:
            return m
        ret = par(UF[m])
        UF[m] = ret
        return ret
    
    UF = [i for i in range(n)]
    E = sorted(E, key=lambda x: x[2])
    ans = 0
    for i, j, d in E:
        if par(i) != par(j):
            ans += d
            UF[par(i)] = par(j)
    return ans

N = int(input())

X = []
for i in range(N):
    x, y = map(int, input().split())
    X.append((i, x, y))

F = []
Y = sorted(X, key = lambda x: x[1])
for i in range(len(Y)-1):
    F.append((Y[i][0], Y[i+1][0], abs(Y[i+1][1]-Y[i][1])))

Y = sorted(X, key = lambda x: x[2])
for i in range(len(Y)-1):
    F.append((Y[i][0], Y[i+1][0], abs(Y[i+1][2]-Y[i][2])))

print(MST(N, F))


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

int n,pos[N],f[N],invF[N];

int poww(int x, int e){
	int ret=1;
	while (e){
		if (e&1){
			ret=1ll*ret*x%mod;
		}
		x=1ll*x*x%mod;
		e>>=1;
	}
	return ret;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	f[0]=invF[0]=1;
	for (int i=1;i<=n+1;i++){
		f[i]=1ll*f[i-1]*i%mod;
		invF[i]=poww(f[i],mod-2);
	}
	int x;
	for (int i=1;i<=n+1;i++){
		cin >> x;
		if (pos[x]){
			for (int k=1;k<=n+1;k++){
				cout << (1ll*f[n+1]*
				invF[k]%mod*
				invF[n+1-k]%mod-
				(pos[x]-1+n+1-i<(k-1)?0:
				1ll*f[pos[x]-1+n+1-i]*
				invF[k-1]%mod*
				invF[pos[x]+n+1-i-k]%mod)
				+mod)%mod << "\n";
			}
			return 0;
		}
		pos[x]=i;
	}
}

Measured memory_bytes: 2432
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
using namespace std;
template <class T> void setmax(T & a, T const & b) { if (a < b) a = b; }
int main() {
    // input
    int n; cin >> n;
    vector<vector<int> > g(n);
    repeat (i,n-1) {
        int p, q; cin >> p >> q; -- p; -- q;
        g[p].push_back(q);
        g[q].push_back(p);
    }
    // compute
    int total_leaves = 0;
    repeat (i,n) if (g[i].size() == 1) total_leaves += 1;
    int ans = 0;
    vector<int> middle(n), terminal(n); // dp on tree
    function<void (int, int)> go = [&](int i, int parent) {
        // prepare
        int sum_middle = 0;
        vector<int> terminals;
        vector<int> diff;
        for (int j : g[i]) if (j != parent) {
            go(j, i);
            sum_middle += middle[j];
            terminals.push_back(terminal[j]);
            diff.push_back(terminal[j] - middle[j]);
        }
        diff.push_back(0);
        diff.push_back(0);
        sort(diff.rbegin(), diff.rend());
        terminals.push_back(0);
        terminals.push_back(0);
        sort(terminals.rbegin(), terminals.rend());
        // result
        middle[i] = max(1, sum_middle);
        terminal[i] = max(1 + terminals[0], sum_middle + diff[0]);
        setmax(ans, 1 + terminals[0] + terminals[1]);
        setmax(ans, total_leaves + diff[0] + diff[1]);
    };
    go(0, -1);
    // output
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6784
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
struct rpr{
  in x,y;
  rpr(in a=0, in b=0){
    x=a;
    y=b;
  }
  rpr sp()const{
    return rpr(y,x);
  }
  bool operator<(const rpr cp)const{
    if(x!=cp.x)
      return x<cp.x;
    return y<cp.y;
  }
};
const in ulm=in(1e10)+9;
const in crt=2500;
in sm=0;
map<rpr,in> mp;
void pr(in n){
  VI pm,pw;
  for(in i=2;i<=crt && i<=n;++i){
    if(n%i)
      continue;
    pm.PB(i);
    pw.PB(0);
    while(n%i==0){
      n/=i;
      ++pw.back();
    }
    pw.back()%=3;
  }
  if(n!=1 && n<crt*crt){
    pm.PB(n);
    pw.PB(1);
    n=1;
  }
  if(n>=crt*crt){
    in mn=crt-1;
    in mx=1e6;
    in md;
    while(mx-mn>1){
      md=(mx+mn)/2;
      if(md*md<=n)
	mn=md;
      else
	mx=md;
    }
    if(mn*mn!=n){
      ++sm;
      return;
    }
    pm.PB(mn);
    pw.PB(2);
    n=1;
  }
  in tx=1;
  in ty=1;
  forv(i,pm){
    forn(j,pw[i])
      tx*=pm[i];
    forn(j,(3-pw[i])%3){
      ty*=pm[i];
      if(ty>ulm){
	++sm;
	return;
      }
    }
  }
  ++mp[rpr(tx,ty)];
  mp[rpr(ty,tx)];
}
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  in n;
  cin>>n;
  in s;
  forn(i,n){
    cin>>s;
    pr(s);
  }
  in t=0;
  fors(i,mp){
    if(i->first.x==1)
      ++sm;
    else
      t+=max(i->second,mp[i->first.sp()]);
  }
  sm+=t/2;
  cout<<sm<<endl;
  return 0;
}


Measured memory_bytes: 10624
#include <bits/stdc++.h>
#define INF  10000000000000000
using namespace std;
long long l[300005],r[300005];
vector<int> v(300005);
int main()
{
	long long n;
	cin>>n;
	for(long long int i=0;i<3*n;i++)
	cin>>v[i];
	
	priority_queue<int> pq;
	priority_queue<int, vector<int>, greater<int> > pq2;
	
	long long csum=0;
	
	for(long long i=0;i<3*n;i++){
		
		pq2.push(v[i]);
		csum+=v[i];
		if(pq2.size()>n)
		{
			csum-=pq2.top();
			pq2.pop();
		}
		if(pq2.size()==n)
		l[i]=csum;
		else
		l[i]=-INF;
		
	}
	
	csum=0;
	
	for(long long i=3*n-1;i>=0;i--){
		
		pq.push(v[i]);
		csum+=v[i];
		if(pq.size()>n)
		{
			csum-=pq.top();
			pq.pop();
		}
		if(pq.size()==n)
		r[i]=csum;
		else
		r[i]=INF;
		
	}
	
	long long ans=-INF;
	for(long long i=0;i<3*n-1;i++){
		ans=max(ans,l[i]-r[i+1]);
	}
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 7032
n = int(input())
dp=[0]*3
cost=[0]*3
for _ in range(n):
    l = list(map(int, input().split()))
    for i in range(3):
        for j in range(3):
            if i!=j:
                dp[i]=max(dp[i],l[i]+cost[j])
    cost=dp.copy()
print(max(dp[0],max(dp[1],dp[2])))



Measured memory_bytes: 3064
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_imports)]
use std::collections::HashSet;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::VecDeque;
use std::cmp::{max, min};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        s: chars,
        t: chars,
    }
    let mut ass = Vec::new();
    for i in 0..s.len() - t.len() + 1 {
        let mut may_in = true;
        for j in 0..t.len() {
            if s[i + j] == t[j] || s[i + j] == '?' {
            } else {
                may_in = false;
            }
        }
        if may_in == true {
            let mut st = String::new();
            for j in 0..i {
                if s[j] == '?' {
                    st.push('a');
                } else {
                    st.push(s[j]);
                }
            }
            for j in 0..t.len() {
                st.push(t[j])
            }
            for j in i + t.len()..s.len() {
                if s[j] == '?' {
                    st.push('a');
                } else {
                    st.push(s[j]);
                }
            }
            ass.push(st);
        }
    }
    if ass.is_empty() {
        println!("UNRESTORABLE");
    } else {
        ass.sort();
        println!("{}", ass[0]);
    }
}

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

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

  int n;
  cin >> n;

  vector<ll> a(n);
  vector<ll> num_cnt(100100);

  ll sum = 0;
  rep(i,n) {
    cin >> a[i];
    num_cnt[a[i]]++;
    sum += a[i];
  }

  int q;
  cin >> q;
  while(q--) {
    int b,c;
    cin >> b >> c;

    ll diff = c - b;
    ll val_diff = diff * num_cnt[b];
    num_cnt[c] += num_cnt[b];
    num_cnt[b] = 0;

    sum += val_diff;
    cout << sum << '\n';
  }
  return 0;
}


Measured memory_bytes: 4712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
struct edge{long long to,cost;};
const int inf = 1 << 27;
// const long long INF = 100;
const long long INF = 1LL << 60;
const int COMBMAX = 1001001;
const long long MOD = 1000000007;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define eachdo(v, e) for(const auto& e : (v))
#define all(v) (v).begin(), (v).end()
#define lower_index(v, e) (long long)distance((v).begin(), lower_bound((v).begin(), (v).end(), e))
#define upper_index(v, e) (long long)distance((v).begin(), upper_bound((v).begin(), (v).end(), e))
long long mpow(long long a, long long n, long long mod = MOD){long long res = 1; while(n > 0){if(n & 1)res = res * a % mod; a = a * a % mod; n >>= 1;} return res;}
void yn(bool j){cout << (j ? "Yes" : "No") << endl; return;}
template<class Head> void pt(Head&& head){cout << head << endl; return;}
template<class Head, class... Tail> void pt(Head&& head, Tail&&... tail){cout << head << " "; pt(forward<Tail>(tail)...);}
template<class T> void debug(T v){rep(i, v.size()) cout << v[i] << " " ; cout << endl;}
template<class T> void debug2(T v){rep(i, v.size()){rep(j, v[i].size()) cout << v[i][j] << " " ; cout << endl;}}
template<class T1, class T2> long long bcount(T1 v, T2 a){return upper_index(v, a) - lower_index(v, a);} 
template<class T1, class T2> inline bool chmin(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}
template<class T1, class T2> inline bool chmax(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}
ll ma1 = 210000;

ll N;
vector<ll> a(ma1);
vector<ll> lis(ma1, INF);
vector<ll> ans(ma1);
vector<P> ope(ma1);
vector<P> ope_inv(ma1);
vector<vector<ll>> g(ma1, vector<ll>());

void dfs(ll par, ll node){
    ll update = lower_index(lis, a[node]);
    ope_inv[node] = make_pair(update, lis[update]);
    ope[node] = make_pair(update, a[node]);
    lis[ope[node].first] = ope[node].second;
    ans[node] = lower_index(lis, INF) - 1;
    // pt(node, par);
    // debug(lis);
    // ans[node] = update;
    // if (0 < par) chmax(ans[node], ans[par]);


    eachdo(g[node], e){
        if (e == par) continue;
        dfs(node, e);
    }
    lis[ope_inv[node].first] = ope_inv[node].second;
    return;
}

int main(){
    cin >> N;
    rep(i, N) cin >> a[i];
    rep(i, N - 1){
        ll a, b; cin >> a >> b;
        g[--a].push_back(--b);
        g[b].push_back(a);
    }
    lis[0] = -INF;
    dfs(-1, 0);
    rep(i, N) pt(ans[i]);
    return 0;
}

Measured memory_bytes: 34496
#include <bits/stdc++.h>
#define sp ' '
#define nyan "(=^・ω・^=)"
#define mkp make_pair
#define intmax 2147483647
#define llmax 9223372036854775807
#define lP pair<ll,ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;
const int mod = 1000000007;

int L, t;
vector<pair<pair<int, int>, int>>v;

int main() {
	cin >> L;
	for (int i = 1; i != 19; ++i) {
		v.push_back(mkp(mkp(i, i + 1), 0));
		v.push_back(mkp(mkp(i, i + 1), 1 << (i - 1)));
	}
	if (L&(1 << 19)) {
		v.push_back(mkp(mkp(19, 20), 0));
		v.push_back(mkp(mkp(19, 20), 1 << 18));
		t += 1 << 19;
	}
	for (int i = 19; i; --i) {
		if (L&(1 << i - 1)) {
			v.push_back(mkp(mkp(i, 20), t));
			t += 1 << i - 1;
		}
	}
	cout << 20 << sp << v.size() << endl;
	for (int i = 0; i != v.size(); ++i)
		cout << v[i].first.first << sp << v[i].first.second << sp << v[i].second << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin
 
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
s = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n = ni()
c = 0
for i in range(n):
    l, r = na()
    c += (r - l) + 1

print(c)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

using namespace std::chrono;

int main(void)
{
    IOS
    const int A = 26;
    const int M = 10000;
    const int TL = 1800;
    auto stime = system_clock::now();
    int D; cin >> D;
    vector<int> c(A);
    REP(i,A) cin >> c[i];
    vector<vector<int>> s(D,vector<int>(A));
    REP(i,D) REP(j,A) cin >> s[i][j];

    vector<int> last(A,-1);
    vector<int> base(D);
    REP(i,D) {
        int mx = 0,a = -1;
        REP(j,A) {
            int tmp = (i-last[j])*c[j] + s[i][j];
            if (mx < tmp) {
                mx = tmp;
                a = j;
            }
        }
        base[i]=a;
        last[a] = i;
    }
    auto calc = [&](const vector<int> &a){
        vector<int> l(A,-1);
        int score = 0;
        REP(i,D) {
            score += s[i][a[i]];
            l[a[i]] = i;
            REP(j,A) {
                score -= c[j]* (i-l[j]);
            }
        }
        return score;
    };

    int maxscore = calc(base);
    vector<int> ans(base);

    random_device seed_gen;
    mt19937 engine(seed_gen());
    int loopcount = 0;
    while(true) {
        // time count
        auto time = system_clock::now();
        int t = duration_cast<milliseconds>(time-stime).count();
        if (t >= TL) break;

        int mx = maxscore;
        vector<int> a1(base);
        REP(_,M) {
            vector<int> a2(a1);
            a2[engine()%D] = engine() % A;
            int tmp = calc(a2);
            if (mx < tmp) {
                a1=a2;
                mx = tmp;
            }
        }
        if (maxscore < mx) {
            ans=a1;
            maxscore = mx;
        }
        loopcount++;
    }

    //cerr << loopcount << endl;
    REP(i,D) OUT(ans[i]+1)

    return 0;
}

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

#define ll long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()
ll inf = 1e9+7;
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n; cin >>n;
    ll ans = 1;
    rep(i,1,n+1){
        ans = ans * i %inf;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

public class Main {
	public static void main (String[] args) throws IOException{
	    InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
	    BufferedReader in = new BufferedReader(reader);
	    String[] str1 = in.readLine().split(" ");
	    int num1 = Integer.parseInt(str1[0]);
	    int num2 = Integer.parseInt(str1[1]);

	    if(num2==0) {
			System.out.println(num1);
	    }else {
		    String[] str2 =in.readLine().split(" ");
		    List<Integer> arrays = new ArrayList<Integer>();
		    for(int i = 0; i<num2; i++) {
		    	arrays.add(Integer.parseInt(str2[i]));
		    }
			if(!arrays.contains(num1)) {
				System.out.println(num1);
			}else {
				for(int i=1; i<num2+1; i++) {
					if(num1>0) {
					}
					if(!arrays.contains(num1-i)) {
						System.out.println(num1-i);
						break;
					}else if(!arrays.contains(num1+i)) {
						System.out.println(num1+i);
						break;
					}
				}
			}
	    }
	}
}

Measured memory_bytes: 32704
// #Badhi moh maya chhe!
/*
AUTHOR NAME:
	         ,--.                         ____                          ,--.
	       ,--.'|   ,---,               ,'  , `.   ,---,              ,--.'|
	   ,--,:  : |  '  .' \           ,-+-,.' _ |  '  .' \         ,--,:  : |
	,`--.'`|  ' : /  ;    '.      ,-+-. ;   , || /  ;    '.    ,`--.'`|  ' :
	|   :  :  | |:  :       \    ,--.'|'   |  ;|:  :       \   |   :  :  | |
	:   |   \ | ::  |   /\   \  |   |  ,', |  '::  |   /\   \  :   |   \ | :
	|   : '  '; ||  :  ' ;.   : |   | /  | |  |||  :  ' ;.   : |   : '  '; |
	'   ' ;.    ;|  |  ;/  \   \'   | :  | :  |,|  |  ;/  \   \'   ' ;.    ;
	|   | | \   |'  :  | \  \ ,';   . |  ; |--' '  :  | \  \ ,'|   | | \   |
	'   : |  ; .'|  |  '  '--'  |   : |  | ,    |  |  '  '--'  '   : |  ; .'
	|   | '`--'  |  :  :        |   : '  |/     |  :  :        |   | '`--'  
	'   : |      |  | ,'        ;   | |`-'      |  | ,'        '   : |      
	;   |.'      `--''          |   ;/          `--''          ;   |.'      
	'---'                       '---'                          '---'        

*/



#include <bits/stdc++.h>

using namespace std;
#define endl "\n"
#define ll long long
#define ld long double
#define pll pair<long long,long long>
#define vll vector<long long>
#define all(x) x.begin(),x.end()
#define pb push_back
#define Fo(i,k,n) for(ll i=k;i<=n;i+=1)
#define deb(x) cout << #x << "=" << x << endl
#define in(a,n) Fo( i,0,n-1)cin>>a[i]
#define out(a,n) Fo( i,0,n-1)cout<<a[i]<<" ";cout<<endl
#define IOS     ios_base::sync_with_stdio(0); cin.tie(NULL);

ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
void fileio()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
}


int main() {
	IOS
    ll t=1;
	//cin>>t;	
	
	while(t--)
	{
	 ll n,m;
	 cin>>n>>m;
	 ll ans=n*(n-1)/2+m*(m-1)/2;\
	 cout<<ans;
	
	}
	
    
}

Measured memory_bytes: 256
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
rp = list(range(1,n+1))
rq = list(range(1,n+1))
import math
f = math.factorial(n)
ansp = 0
ansq = 0
for i in range(n):
  f //= (n-i)
  pi = rp.index(p[i])
  qi = rq.index(q[i])
  ansp += f*(pi)
  ansq += f*(qi)
  rp.remove(p[i])
  rq.remove(q[i])
print(abs(ansq-ansp))

Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp {
    char name[100];
    int t;
} P;

P Q[LEN];
int head, tail, n;

void enqueue(P x) {
    Q[tail] = x;
    tail = (tail + 1) % LEN;
}

P dequeue() {
    P x = Q[head];
    head = (head + 1) % LEN;
    return x;
}

int min(int a, int b) { return a < b ? a : b; }

int main() {
    int elaps = 0, c;
    int i, q;
    P u;
    scanf( "%d %d", &n, &q);
    for ( i = 1; i <= n; i++ ) {
        scanf("%s", Q[i].name);
        scanf("%d", &Q[i].t);
    }
    head = 1; tail = n + 1;
    
    while ( head != tail ) {
        u = dequeue();
        c = min(q, u.t);
        u.t -= c;
        elaps += c;
        if ( u.t > 0 ) enqueue(u);
        else {
            printf("%s %d\n",u.name, elaps);
        }
    }
    
    return 0;
}
    



Measured memory_bytes: 12708
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,m;
int a[1000];
int cnt[1000][10];
int main(void){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		cnt[i][0]=1;
	}
	for(int i=0;i<m;i++){
		scanf("%d",&a[i]);
		cnt[a[i]][0]=0;
	}
	int sum=0,s=1,to=0;
	while(s<n){
		for(int j=0;j<n/s;j+=2){
			if(cnt[j][to]+cnt[j+1][to]==2){
				sum++;
				cnt[j/2][to+1]++;
			}else if(cnt[j][to]+cnt[j+1][to]==1){
				cnt[j/2][to+1]++;
			}
		}
		s*=2;
		to++;
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 3164
using System;
using System.Linq;

class Program {
    static void Main(string[] args) {
        int N = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split().Select(int.Parse).ToArray();

        //それぞれの数を数えておく
        var counter = new int[a.Max() + 2];


        for (int i = 0; i < a.Count(); i++) {
            if (a[i] > 0) {
                counter[a[i] - 1]++;
            }
            counter[a[i]]++;
            counter[a[i] + 1]++;
        }


        Console.WriteLine(counter.Max());
    }
}

Measured memory_bytes: 18528
/*/ Author:amar1503/*/
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("Ofast")
#define fio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ull unsigned long long
#define ll long long
#define inf INT_MAX
#define mninf INT_MIN
#define Mod 1000000007
#define endl "\n"
#define cp(x) cout<<(x)<<" "
#define cl(x) cout<<(x)<<endl
#define nl   cout<<endl
//const double PI=3.1415926535897932384626433832;
//looping
#define For(i,n) for(int i=0;i<n;i++)
#define For1(i,n) for(int i=1;i<=n;i++)
#define test(t)  int (t); cin>>(t); while((t)--)
#define array(a,n) int (n); cin>>(n); int a[n]; for(int i=0;i<(n);i++) cin>>a[i];
#define trace(x) clog<<#x<<": "<<x<<" "<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define printa(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
#define printv(v)  for(int i=0;i<(v).size();i++) cout<<v[i]<<" "
//containers
#define F first
#define S second
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define all(v) (v).begin(),(v).end()
#define mp make_pair
#define itr(it, a) for(auto it = (a).begin(); it != (a).end(); it++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ers(v)    sort(all(v)); (v).erase(unique(all(v)),(v).end())
typedef vector<int> vi;
typedef vector< vector< int > > vvi;
typedef pair <int, int> pii;
typedef vector < pair <int, int> > vpii;
//#define int long long
/*/-----------------------------Code begins----------------------------------/*/

int main(){
int n,m;
cin>>n>>m;
char a[n+1][m+1];
for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++)
    cin>>a[i][j];
int ways[n+1][m+1];
memset(ways,0,sizeof(ways));
for(int i=1;i<=n;i++)
{
    if(a[i][1]=='#')
        break;
    else ways[i][1]=1;
}
for(int i=1;i<=m;i++)
{
    if(a[1][i]=='#')
        break;
    else ways[1][i]=1;
}
for(int i=2;i<=n;i++){
    for(int j=2;j<=m;j++){
        if(a[i][j]=='#')
            continue;
        if(a[i-1][j]!='#')
            ways[i][j]=(ways[i][j]+ways[i-1][j])%Mod;
        if(a[i][j-1]!='#')
            ways[i][j]=(ways[i][j-1]+ways[i][j])%Mod;
    }
}
cout<<ways[n][m];
return 0;}















Measured memory_bytes: 5120
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int calc(int rows, int cols, string[] g) {
    auto t = new int[][](rows, cols);
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < cols; j++) {
            t[i][j] = int.max;
        }
    }

    int[][] q;
    q ~= [0, 0, 0];
    while (q.length > 0) {
        auto s = q[0];
        q = q[1..$];

        int r = s[0];
        int c = s[1];
        int cost = s[2];
        if (t[r][c] <= cost) continue;
        t[r][c] = cost;

        for (int i = -1; i <= 1; i++) {
            for (int j = -1; j <= 1; j++) {
                if (abs(i) + abs(j) == 1) {
                    int row = r + i;
                    int col = c + j;
                    if (0 <= row && row < rows && 0 <= col && col < cols) {
                        if (g[row][col] == '#') continue;
                        q ~= [row, col, cost + 1];
                    }
                }
            }
        }
    }

    assert(t[rows-1][cols-1] != int.max);
    int last = t[rows-1][cols-1];
    if (last == int.max) return -1;

    int ans = 0;
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < cols; j++) {
            int cost = t[i][j];
            if (cost == int.max && g[i][j] == '#') continue;

            ans++;
        }
    }
    return ans - last - 1;
}

void main() {
    auto hw = readints;
    int rows = hw[0], cols = hw[1];

    string[] g;
    for (int i = 0; i < rows; i++) {
        g ~= readln.chomp;
    }
    int ans = calc(rows, cols, g);
    writeln(ans);
}

Measured memory_bytes: 636
use std::cmp::{max, min};
use std::io::{Read, StdinLock};
use std::str::{from_utf8, FromStr};
use std::vec::Vec;

struct StdinReader<'a> {
    reader: StdinLock<'a>,
}

impl<'a> StdinReader<'a> {
    pub fn new(reader: StdinLock<'a>) -> StdinReader {
        StdinReader { reader: reader }
    }

    pub fn read<T: FromStr>(&mut self) -> T {
        fn is_whitespace(ch: u8) -> bool {
            ch == 0x20 || ch == 0x0a || ch == 0x0d
        }

        let token: Vec<u8> = self.reader
            .by_ref()
            .bytes()
            .map(|ch| ch.expect("failed to read a byte"))
            .skip_while(|ch| is_whitespace(*ch))
            .take_while(|ch| !is_whitespace(*ch))
            .collect();
        let token_str = from_utf8(&token)
            .unwrap_or_else(|_| panic!(format!("invalid utf8 sequence: {:?}", token)));
        token_str
            .parse()
            .unwrap_or_else(|_| panic!(format!("failed to parse input: {}", token_str)))
    }
}

fn main() {
    let stdin = std::io::stdin();
    let mut reader = StdinReader::new(stdin.lock());

    let a: i64 = reader.read();
    let b: i64 = reader.read();
    let c: i64 = reader.read();
    let x: i64 = reader.read();
    let y: i64 = reader.read();

    let mut min_cost = std::i64::MAX;

    for k in 0..(x + y + 1) {
        // ABピザを 2*k 個買う
        let i = max(x - k, 0);
        let j = max(y - k, 0);
        let cost = i * a + j * b + 2 * k * c;
        min_cost = min(min_cost, cost);
    }

    println!("{}", min_cost);
}


Measured memory_bytes: 4352
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)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 endl "\n"
#define pb push_back
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}
void judgement(int a){
  if(a){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  if(a){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}

int main(){
  ll i,j,N,H,W,ans;
  cin>>N;
  ans=N/2;
  if(N%2==0)ans--;
  cout<<ans<<endl;
  return 0;
}

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

vector<string> R(1);

void lun(string ns,int a){
  if(a==0){
    //cout<<ns<<endl;
    R.push_back(ns);
    return;
  }
  if(ns==""){
    for(int i=0;i<9;i++){
      char c='1'+i;
      lun(ns+c,a-1);
    }
  }else{
    char c=ns[ns.size()-1];
    for(int i=-1;i<=1;i++){
      if(c+i<'0'||c+i>'9')continue;
      char d=c+i;
      lun(ns+d,a-1);
    }
  }
}

int main() {
  long K;cin>>K;
  for(int i=1;i<=10;i++)lun("",i);
  cout<<R[K]<<endl;
}


Measured memory_bytes: 14064
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;

//#define int long long
using bll = boost::multiprecision::cpp_int;
using ll = long long;
//constexpr int INF = 1e9;//INT_MAX=(1<<31)-1=2147483647
constexpr ll INF = (ll)1e18;//(1LL<<63)-1=9223372036854775807
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-9;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
#ifdef LOCAL_ENV
	#define debug(var) std::cout<<#var" = "<<var<<std::endl
#else
	#define debug(var)
#endif
#define p(var) std::cout<<var<<std::endl
#define PI (acos(-1))
#define rep(i, n)   for(ll i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(ll i=1, i##_length=(n); i<=i##_length; ++i)
#define all(v) (v).begin(), (v).end()
#define uniq(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
template<typename T> inline T power(T x, T n){ return n ? power(x*x%MOD,n/2)*(n%2?x:1)%MOD : 1; }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
template<typename T1, typename T2>inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	for (int i = 0, len = v.size(); i < len; ++i){
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
	for (int i = 0, len = vv.size(); i < len; ++i){
		s << vv[i] << endl;
	}
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
	s << "{" << endl;
	for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr){
		s << "\t" << (*itr).first << " : " << (*itr).second << endl;
	}
	s << "}" << endl;
	return s;
}

/*-----8<-----8<-----*/

signed main() {
	ll N;
	scanf("%lld", &N);
	vector<ll> a(N,0);
	rep(i, N) scanf("%lld", &a[i]);

	multiset<ll> s;
	s.insert(0);
	s.insert(0);
	s.insert(N+1);
	s.insert(N+1);

	vector<pair<ll,ll>> v;
	rep(i,N){
		v.push_back({a[i],i+1});//{value,index}
	}
	sort(all(v));
	reverse(all(v));//valueの大きい順にソート
	debug(v);

	ll ans = 0;
	for(pair<ll,ll> p:v){
		ll value=p.first;
		ll index=p.second;
		auto it=s.lower_bound(index);//setの中でindex以上の位置を探す
		//value以上の値のうち、L2<L1<index<R1<R2
		ll R1=*it;
		it++;
		ll R2=*it;
		it--;
		it--;
		ll L1=*it;
		it--;
		ll L2=*it;
		ans+=value*(R2-R1)*(index-L1);
		ans+=value*(L1-L2)*(R1-index);
		s.insert(index);
	}

	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 7280
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
#include <map>
#include <cmath>
#include <type_traits>
using namespace std;

#define INF 1e18
#define int long long

signed main() {
    int n, k; cin >> n >> k;
    string s; cin >> s;
    int score = 0;
    for(int i = 0; i < n - 1; i++) {
        if(s[i] == s[i + 1]) score++;
    }

    int ans = min(score + 2 * k, n - 1);

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


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];
  vector<vector<int>> dp(1<<n, vector<int>(n, INF));
  dp[0][0] = 0;
  rep(i, 1<<n) rep(j, n) {
    int num = __builtin_popcount(i);
    if (num && (i>>j & 1) == 0)
      continue;
    int mx = 0;
    if (num) {
      if ((j-(num-1))%2)
        mx = b[j];
      else
        mx = a[j];
    }
    int cnt = 0;
    rep(k, n) {
      if ((i>>k & 1) == 0) {
        if ((k-num)%2 && b[k] >= mx)
          chmin(dp[i|1<<k][k], dp[i][j]+cnt);
        if ((k-num)%2 == 0 && a[k] >= mx)
          chmin(dp[i|1<<k][k], dp[i][j]+cnt);
        cnt++;
      }
    }
  }
  int ans = INF;
  rep(i, n)
    chmin(ans, dp[(1<<n)-1][i]);
  if (ans == INF)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}

Measured memory_bytes: 26880
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
const int INF = 10000000;
typedef struct state{
  int tx;
  int ty;
  int kx;
  int ky;
  int cost;
  state(int tx,int ty,int kx,int ky,int cost):
      tx(tx),ty(ty),kx(kx),ky(ky),cost(cost){}
}st;
int fie[52][52];
int check[52][52][52][52];
int X,Y;
int dtx[]={0,1,0,-1};
int dty[]={1,0,-1,0};
int dkx[]={0,-1,0,1};
int dky[]={-1,0,1,0};

void init(){
  for(int i=0;i<Y;i++){
    for(int j=0;j<X;j++){
      for(int ii=0;ii<Y;ii++){
	for(int jj=0;jj<X;jj++) check[j][i][jj][ii]=INF;
	//	cout <<check[j][i][0][ii]<<endl;
      }
    }
  }
}

int solve(int tx,int ty,int kx,int ky){
  queue <st> q;
  int cost;
  int ok=0;
  q.push(state(tx,ty,kx,ky,0));
  while(!q.empty()){
    st p=q.front(); q.pop();
    tx=p.tx;
    ty=p.ty;
    kx=p.kx;
    ky=p.ky;
    cost=p.cost;

    if(tx==kx && ty==ky){ ok=1;break;}
    if(cost>=100) break;
    //cout <<tx<<" "<<ty<<" "<<kx<<" "<<ky<<" "<<cost<<endl;

    for(int i=0;i<4;i++){
      int f=0;
      if(tx+dtx[i]<0 || tx+dtx[i]>=X || ty+dty[i]<0 || ty+dty[i]>=Y) f+=1;
      if(kx+dkx[i]<0 || kx+dkx[i]>=X || ky+dky[i]<0 || ky+dky[i]>=Y) f+=10;
      if(f==11) continue;
      if((f/10)){//かずゆきいけない時
	if(fie[tx+dtx[i]][ty+dty[i]]==1 ) f+=1;
      }else if((f%10)){//たかゆきいけない時
	if(fie[kx+dkx[i]][ky+dky[i]]==1 ) f+=10;
      }else{//両方いける時
	if(fie[tx+dtx[i]][ty+dty[i]]==1 ) f+=1;
	if(fie[kx+dkx[i]][ky+dky[i]]==1 ) f+=10;
      }
      if(f>=11) continue;

      if(f/10){//かずゆきがいけない時
	if(check[tx+dtx[i]][ty+dty[i]][kx][ky]!=INF) continue;
      }else if(f%10){//たかゆきイけないとき
	if(check[tx][ty][kx+dkx[i]][ky+dky[i]]!=INF) continue;
      }else{//両方いけるとき
	if(check[tx+dtx[i]][ty+dty[i]][kx+dkx[i]][ky+dky[i]]!=INF)continue;
      }

      if(f/10){//かずゆきがいけない時
	q.push(state(tx+dtx[i],ty+dty[i],kx,ky,cost+1));
	//cout << check[tx+dtx[i]][ty+dty[i]][kx][ky] <<" ";
	check[tx+dtx[i]][ty+dty[i]][kx][ky]=cost+1;
      }
      else if(f%10){//たかゆきイけないとき
	q.push(state(tx,ty,kx+dkx[i],ky+dky[i],cost+1));
	//cout << check[tx][ty][kx+dkx[i]][ky+dky[i]] <<" ";
	check[tx][ty][kx+dkx[i]][ky+dky[i]]=cost+1;
      }
      else{//両方いけるとき
	q.push(state(tx+dtx[i],ty+dty[i],kx+dkx[i],ky+dky[i],cost+1));
	//cout << check[tx+dtx[i]][ty+dty[i]][kx+dkx[i]][ky+dky[i]] <<" ";
	check[tx+dtx[i]][ty+dty[i]][kx+dkx[i]][ky+dky[i]]=cost+1;
      }
    }
  }
  if(!ok) return 100;
  return cost;
}
main(){
  int tx,ty,kx,ky;
  while(1){
    cin >> X >> Y;
    if(X==0 && Y==0) break;
    cin >> tx >> ty;
    cin >> kx >> ky;
    init();
    for(int i=0;i<Y;i++){
      for(int j=0;j<X;j++) cin >> fie[j][i];
    }
    int res=solve(tx-1,ty-1,kx-1,ky-1);
    if(res>=100) cout << "NA" << endl;
    else cout << res << endl;
  }
}

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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >
# define PQ priority_queue

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvs vector < vs >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

# define fr(a,b) for(int i = a; i < b; i++)
# define rep(i,a,b) for(int i = a; i < b; i++)

string vow = "aeiou";
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

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

const ld pie = 3.1415926535897932384626 ;
const ll mod = 1e9 + 7 ;

void solve(){

    ll h,w;
    cin >> h >> w;
    char s[h][w];
    rep(i,0,h){
        rep(j,0,w) {
        cin >> s[i][j];
        }
    }


    rep(i,0,2*h){
        rep(j,0,w) {
        cout << s[i/2][j];
        }
        line
    }
    return;

}

int main(){
	fast
	int tc=1;
	//cin >> tc;
	while(tc--){
             solve();
    }

	R 0;
}


Measured memory_bytes: 3604
X, Y = map(int,input().split())

if Y%2!=0:
    print('No')
    exit()

turu = (4*X-Y)/2
kame = (Y-2*X)/2

if turu >= 0 and turu.is_integer() and kame >= 0 and kame.is_integer():
    print('Yes')
else:
    print('No')

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

using namespace std;

typedef long long ll;

int main(){
  int N,M,i;
  int A[111111];
  cin >> N >> M;
  for(i=0;i<=N-1;i++)
    cin >> A[i];
  int sum = 0;
  for(i=0;i<=N-1;i++)
    sum += A[i];
  int count = 0;
  for(i=0;i<=N-1;i++)
    if(4*M*A[i] >= sum) count++;
  if(count >= M) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残すな
//数値計算 基本はdouble
#include <bits/stdc++.h>
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

int dig(int N) {//桁数
	int dig = 0;
	while (N) {
		dig++;
		N /= 10;
	}
	return dig;
}

int main() {
	int N, M; cin >> N >> M;
	vector<int> K(N + 1);
	int A[100][100];
	int cnt[100] = {};
	for (int i = 1; i <= N; i++) {
		cin >> K[i];
		for (int j = 1; j <= K[i]; j++) {
			cin >> A[i][j];
		}
	}

	for (int i = 1;i <= 30; i++) {
		for (int j = 1; j <= 30; j++) {
			cnt[A[i][j]]++;
		}
	}

	int ans = 0;
	for (int i = 1; i <= 30; i++) {
		if (cnt[i] == N)ans++;
	}

	cout << ans << endl;
}

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


def solve(N: int, p: "List[int]"):
    ans = sum(p) - max(p)/2
    print(int(ans))


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

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007
using namespace std;

int main(void){
	int a,b;
	cin>>a>>b;

	if(a+b >= a-b && a+b >= a*b)cout<<a+b<<endl;
	else if(a-b >= a+b && a-b >= a*b)cout<<a-b<<endl;
	else cout<<a*b<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

template <class T>
ostream &operator<<(ostream &os, const set<T> &st) {
	for (const auto &e : st) os << e << " ";
	return os;
}

template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}

template <class T1, class T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
	for (const auto &e : mp) os << e << " ";
	return os;
}

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];

	vector<int> ans, used(N);
	int loop = 0;
	while(loop < N){

		int tmp = -1, idx = -1, cnt = 1;
		for (int j = 0; j < N; j++) {
			if (!used[j]) {
				if (A[j] == cnt) {
					tmp = A[j];
					idx = j;
				}
				cnt++;
			}
		}
		if (idx == -1) break;
		ans.emplace_back(tmp);
		used[idx] = 1;
		loop++;
	}

	if (ans.size() != N) {
		cout << -1 << "\n";
		return 0;
	}
	reverse(ans.begin(), ans.end());
	for (const auto &e : ans) cout << e << "\n";

	return 0;
}

Measured memory_bytes: 256