akhauriyash/Code-Regression huggingface dataset:
//https://atcoder.jp/contests/abc119/tasks/abc119_c
//2019-02-24
#include <bits/stdc++.h>
using namespace std;
int N, A, B, C;
vector<int> l(8);
int DFS(int i, int a, int b, int c){
    if(i == N){
        if(a*b*c > 0){
            return abs(a-A) +abs(b-B) + abs(c-C) - 30;
        }
        return 10000000;
    }
    int ret0 = DFS(i + 1 ,a , b, c);
    int ret1 = DFS(i + 1, a + l.at(i) , b, c) + 10;
    int ret2 = DFS(i + 1, a , b + l.at(i), c) + 10;
    int ret3 = DFS(i + 1, a , b, c + l.at(i)) + 10;
    return min(min(ret0, ret1), min(ret2, ret3));
}
int main(){
    cin >> N >> A >> B >> C;
    for (int i = 0; i < N; i++) {
        cin >> l.at(i);
    }
    cout << DFS(0, 0, 0, 0) << endl;
}


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

int main(){
  int n,ans=0;cin>>n;
  vector<int> x(n,0);
  REP(i,n){
    cin>>x.at(i);
    ans+=x.at(i);
  }
  sort(x.begin(),x.end(),greater<int>());

  cout<<ans-x.at(0)/2;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(long long i=x;i<y;i++)
typedef long long ll;
using namespace std;

int main()
{
	int N;
	cin >> N;
	set<string>st;
	fore(i,0,N){
		string t;
		cin >> t;
		st.insert(t);
	}
	cout << st.size() << endl;
}

Measured memory_bytes: 15608
n=int(input())
l=[int(x) for x in input().split()]
dp=[[0 for i in range(n+1)] for j in range(n+1)] 
for i in range(n-1,-1,-1):
	for j in range(0,n,1):
		if i==j:
			dp[i][j]=l[i]
		else:
			dp[i][j]=max(l[i]-dp[i+1][j],l[j]-dp[i][j-1])
		#print(i,j)

#print(dp)
print(dp[0][n-1])

Measured memory_bytes: 120156
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

int main(void){
    ll n, p;
    cin >> n >> p;

    ll ans = 0;
    rep(i, 1, sqrt(p) + 1){
        if(p % i == 0){
            ll j = p / i;
            if(p >= pow(i, n) && p % (ll)pow(i, n) == 0){
                ans = max(ans, i);
            }
            if(p >= pow(j, n) && p % (ll)pow(j, n) == 0){
                ans = max(ans, j);
            }
        }
    }

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


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

using namespace std;
using ll = long long;
using uint = unsigned;
using ull = unsigned long long;
using P = pair<int,int>;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

int main() {
    int n, m; cin >> n >> m;
    cout << (n*(n-1)/2+m*(m-1)/2) << endl;
    return 0;
}























Measured memory_bytes: 256
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iostream>

using namespace std;

int main(){
    string s,t;
    cin >> s >> t;
    bool ok = 1;
    for(int i = 0; i<s.size(); i++){
        if(s[i] != t[i]){
            ok = 0;
        }
    }
    if(ok == 1){
        cout << "Yes";
    }
    else{
        cout << "No";
    }
}


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

from  collections import Counter

dict_a = Counter(a)
s = sum(a)

for i in range(q):
  b, c = map(int, input().split())
  s -= b*dict_a[b]
  s += c*dict_a[b]
  dict_a[c] += dict_a[b]
  dict_a[b] = 0
  print(s)


Measured memory_bytes: 23928
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <cstdio>
#include <cmath>
#include <cassert>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
constexpr lnt INF = 2e18;
/*-*/

struct P
{
	int x,y,c;
	P(int x, int y, int c) : x(x),y(y),c(c) {}
};

int main() {
	int h,w,d;
	std::cin >> h >> w >> d;
	std::vector<std::vector<int> > g(2*h+d,std::vector<int>(2*w+d,-1));
	auto dec = [] (int c) -> char {
		if(c==0) return 'R';
		if(c==1) return 'Y';
		if(c==2) return 'G';
		if(c==3) return 'B';
		return 'x';
	};
	if(d&1) {
		rep(i,h) rep(j,w) {
			g[i][j] = (i%2)*2+(j%2);
		}
		rep(i,h) {
			rep(j,w) std::cout << dec(g[i][j]);
			std::cout << EL;
		}
	} else {
		std::queue<P> que;
		for(int i=0;i*d<2*h+d;i++) {
			for(int j=0;j*d<2*w+d;j++) {
				int c = (i%2)^(j%2);
				g[i*d][j*d] = c;
				que.emplace(i*d,j*d,c);
				if(i*d+1<2*h+d) {
					g[i*d+1][j*d] = c;
					que.emplace(i*d+1,j*d,c);
				}
			}
		}
		for(int i=0;i*d+d/2<2*h+d;i++) {
			for(int j=0;j*d+d/2<2*w+d;j++) {
				int c = (i%2)^(j%2)+2;
				g[i*d+d/2][j*d+d/2] = c;
				que.emplace(i*d+d/2,j*d+d/2,c);
				if(i*d+1+d/2<2*h+d) {
					g[(i*d+1+d/2)][j*d+d/2] = c;
					que.emplace((i*d+1+d/2),j*d+d/2,c);
				}
			}
		}
		while(!que.empty()) {
			auto p = que.front(); que.pop();
			int x=p.x,y=p.y,c=p.c;
			for(int dx=-1;dx<=1;dx++) {
				for(int dy=-1;dy<=1;dy++) {
					if(dx*dy!=0) continue;
					if(dx==0&&dy==0) continue;
					if(dx+x<0||dx+x>=2*h+d) continue;
					if(dy+y<0||dy+y>=2*w+d) continue;
					if(g[dx+x][dy+y]!=-1) continue;
					g[dx+x][dy+y]=c;
					que.emplace(dx+x,dy+y,c);
				}
			}
		}
		rep(i,h) {
			rep(j,w) std::cout << dec(g[i+d][j+d]);
			std::cout << EL;
		}
	}
}


Measured memory_bytes: 16384
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#define X first
#define Y second
#define MAX 1003
using namespace std;

struct state{
	state():num(0), max(-1), mindex(0){}
	int num;
	int max;
	int mindex;
};

state dp[MAX][MAX];
bool sosuu[1000001];
map<int, pair<int, int> > pos;
int dx[] = {0, -1, 0, 1};
int dy[] = {-1, 0, 1, 0};
int ddx[] = {-1, 0, 1};

//素数判定用
void era(){
	fill(sosuu, sosuu+1000001, true);
	sosuu[0] = false;
	sosuu[1] = false;
	for(int i = 2; i <= 1000000; i++){
		if(sosuu[i]){
			for(int j = 2*i; j <= 1000000; j+=i) sosuu[j] = false;
		}
	}
}

//螺旋状に数字を配置する
void fillNum(){
	int rect = 3, count = 1;
	int x = MAX/2, y = MAX/2;
	pos[count] = pair<int, int>(x, y);
	dp[y][x].num = count++;
	while(count <= MAX*MAX-1){
		pos[count] = pair<int, int>(++x, y);
		dp[y][x].num = count++;
		for(int i = 0; i < 4; i++){
			for(int j = (i==0)?1:0; j < rect-1; j++){
				x += dx[i];
				y += dy[i];
				pos[count] = pair<int, int>(x, y);
				dp[y][x].num = count++;
			}
		}
		rect+=2;
	}
}

//洞穴数は毎回変わるので、入力時にその範囲だけ初期化
void Init(int n){
	for(int i = 0; i < MAX; i++){
		for(int j = 0; j < MAX; j++){
			if(n>=dp[i][j].num){
				dp[i][j].max = -1;
				dp[i][j].mindex = 0;
			}
		}
	}
}
  
//メモ化再帰
//スタートからした三方向に対して再帰回して
//戻ってきたらそこまでの素数洞穴の和を各洞穴に記録していく
int dfs(int x, int y, int n){
	if(dp[y][x].max>=0) return dp[y][x].max;
	int add = 0;
	for(int i = 0; i < 3; i++){
		if(dp[y+1][x+ddx[i]].num>n) continue;//範囲外の洞穴にアクセスしようとしたら止める
		//三方向に対して再帰を行って、もっとも素数洞穴数が多い場所を採用
		//その際、同じ数が複数あった場合はその中で一番大きい素数洞穴を踏んだ経路を採用
		int tmp = dfs(x+ddx[i], y+1, n);
		if(add<tmp){
			add = tmp;
			dp[y][x].mindex = dp[y+1][x+ddx[i]].mindex;
		}
		else if(add == tmp){ 
			dp[y][x].mindex = dp[y][x].mindex<dp[y+1][x+ddx[i]].mindex?dp[y+1][x+ddx[i]].mindex:dp[y][x].mindex;
		}
	}
	//自分が素数だった場合1加算する
	dp[y][x].max = sosuu[dp[y][x].num]?add + 1:add;
	//自分が初めての素数洞穴だった場合
	if(!dp[y][x].mindex&&sosuu[dp[y][x].num]) dp[y][x].mindex = dp[y][x].num;
	return dp[y][x].max;
}

int main(){
	era();
	fillNum();
	int n, m;
	while(cin >> n >> m && (n!=0||m!=0)){
		Init(n);
		int x = pos[m].X, y = pos[m].Y;
		dfs(x, y, n);
		if(dp[y][x].max==0) cout << 0 << " " << 0 << endl;
		else cout << dp[y][x].max << " " << dp[y][x].mindex << endl;
	}
	return 0;
}

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

#define ll long long
#define mod 1000000007

using namespace std;



int main()
{
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,t,a,x;double y=1e18;
    cin>>n>>t>>a;
    ll h[n+1];
    for(int i=1;i<=n;i++){
        cin>>h[i];
        double av=t-(h[i]*0.006);
        if(abs(av-a)<y)y=abs(av-a),x=i;
    }
    cout<<x<<endl;
}


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

//namespace _2_D
//{
class Program
{
    static void Main(string[] args)
    {
        string a = Console.ReadLine();

        string[] b = a.Split(' ');
        int W = int.Parse(b[0]);
        int H = int.Parse(b[1]);
        int x = int.Parse(b[2]);
        int y = int.Parse(b[3]);
        int r = int.Parse(b[4]);

        //x??¨y?????§?¨????(0,0)??\?????§????????¨???
        if((x-r) < 0 || (y - r) < 0)
        {
            Console.WriteLine("No");
        }
        // x + ?????????W???????????§????????¨???, y + ?????????H???????????§??????
        else if((x+r) > W || (y+r) > H)
        {
            Console.WriteLine("No");
        }
        else
        {
            Console.WriteLine("Yes");
        }

    }
}
//}

Measured memory_bytes: 8864
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <limits.h>
#include <cmath>
#include <queue>
#include <map>
#include <iomanip>
#include <random>
#include <fstream>
#include <cassert>
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI 3.14159265358979323846
#define MOD 1000000007
#define vi vector<int>
using namespace std;
using ll = long long;

// ----ここから下は以前競プロをやっていた時に使っていたものです----　

const int MAX = 1000000;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll gcd(ll a, ll b)
{
  ll r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}

template <class T> struct cord{
  T x,y;
};

template <class T> double dist(cord<T> a, cord<T> b){
  T dx=a.x-b.x;
  T dy=a.y-b.y;
  return sqrt(dx*dx+dy*dy);
}

struct s{
  int p,i,r;
};

//比較関数（降順）
bool cmpP(const s &a, const s &b){
  return a.p > b.p;
}

//比較関数（昇順）
bool cmpI(const s &a, const s &b){
  return a.i < b.i;
}

// ----本問について----
// 問題：Square Route
// 問題文URL：https://onlinejudge.u-aizu.ac.jp/problems/2015
// 所要時間：
// 学んだこと：
// 　
// ------------------

// ----ここから本問のソースコード----

// グローバル変数（入力）
int h[1510],w[1510],N,M;

int solve() {
  int answer=0;
  int sum=0;

  // 入力
  rep(i,N){
    cin >> h[i];
    sum += h[i];
  }
  vector<int> hWidth(sum+1);
  sum = 0;
  rep(i,M){
    cin >> w[i];
    sum += w[i];
  }
  vector<int> wWidth(sum+1);
  rep(i,N){
    for (int j=i; j<N; j++){
      sum=0;
      for (int k=i; k<=j; k++){
        sum += h[k];
      }
      hWidth[sum]++;
    }
  }
  rep(i,M){
    for (int j=i; j<M; j++){
      sum=0;
      for (int k=i; k<=j; k++){
        sum += w[k];
      }
      wWidth[sum]++;
    }
  }
  rep(i,min(hWidth.size(),wWidth.size())){
    answer += hWidth[i]*wWidth[i];
  }

  return answer;
}

int main()
{

  //cout << fixed << setprecision(10);
  while (cin >> N >> M && N>0){
    cout << solve() << endl;
  }


  return 0;
}



Measured memory_bytes: 6940
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    ll N;
    cin >> N;
    string s;
    map<string, ll> mp;
    rep(0, i, N)
    {
        cin >> s;
        mp[s]++;
    }

    vector<string> S(4);
    S = {"AC", "WA", "TLE", "RE"};
    rep(0, i, 4)
    {
        mp[S.at(i)];
        for (auto m : mp)
        {
            if (S.at(i) == m.first)
            {
                cout << m.first << ' ' << 'x' << ' ' << m.second << endl;
            }
        }
    }
}

Measured memory_bytes: 3640
#include <iostream>
 
int main(void) {
	int N;
  	std::cin >> N;
  	for(int a = 9; a > 0; --a) {
      	if(N%a != 0) continue;
      	int b = N/a;
      	if(b >= 10) {
          std::cout << "No" << std::endl;
          break;
        }
      	else {
          std::cout << "Yes" << std::endl;
          break;
        }
    }
  	return 0;
}

Measured memory_bytes: 256
/*
 AUTHOR : ANSHU BABU RAJPUT
 
    JAI MAA SARASWATI
    OM NAMAH SHIVAY
    JAI SHRI KRISHNA
    JAI SHRI RAM
    BHARAT MATA KI JAI

    #PKMKB	
    #CKMKB
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define int  long long 
#define endl    ("\n")
#define ff       first
#define ss      second
#define pb   push_back
#define pf  push_front
#define ppb   pop_back
#define ppf  pop_front
#define mp   make_pair
#define mod 1000000007

#define L(x)    x.length()
#define B(x)     x.begin()
#define E(x)       x.end()
#define F(x)     x.front()
#define SZ(x)     x.size()
#define CLR(x)   x.clear()

#define all(x)                      x.begin(),x.end()
#define sortD(x) sort(x.begin(),x.end(),greater<int>)
#define rev(x)             reverse(x.begin(),x.end())

#define intV vector<int>

#define PI          (3.141592653589)
#define PMAX     priority_queue<int>
#define PMIN             priority_queue<int,vi,greater<int>>
#define setbits(x)                   __builtin_popcountll(x)
#define zrobits(x)                        __builtin_ctzll(x)

#define KING(i, n) for (int(i) = 0; (i) < n; (i)++)
#define MAHAKAL(i, n) for (int(i) = n-1; (i) >= 0; (i)--)

#define Anshu        int t; cin>>t; while(t--)
#define SITARAM(n,type) type* input=new type[n]

mt19937                          rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void ViLiFY_KiNG()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt","w",stderr);
#endif
}
 
int32_t main()
{
    ViLiFY_KiNG();
    int n;
    cin>>n;

  
    int sum = 0;
    map<int,int> m;
    KING(i,n) {
        int num;
        cin>>num;

        m[num] = m[num]+1;
        sum += num;
    }

    int q;
    cin>>q;

    KING(i,q) {
        int num1,num2;
        cin>>num1>>num2;
        int temp = m[num1];
        m[num1] = 0;
        m[num2] += temp;
        if(num1>num2) {
            sum -= (num1-num2)*temp;
        } else {
            sum += (num2-num1)*temp;
        }
        cout<<sum<<endl;
    }
    return 0;
}

Measured memory_bytes: 9468
from math import ceil
n,h = map(int,input().split())
a,b = [],[]
for _ in range(n):
    a_,b_ = map(int,input().split())
    a.append(a_)
    b.append(b_)
mx_a = max(a)
b.sort(reverse=True)
cnt = 0
tmp = 0
for b_ in b:
    if b_ >= mx_a:
        tmp += b_
        cnt += 1
        if tmp >= h:
            print(cnt)
            exit()
    else:
        break
print(cnt+ceil((h-tmp)/mx_a))

Measured memory_bytes: 11296
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
int solve(string S){
    set<string> st;
    st.insert(S);
    rep(i,1,S.size()){
        string a = S.substr(0,i);
        string b = S.substr(i);
        st.insert(a + b);
        st.insert(b + a);
        reverse(a.begin(), a.end());
        st.insert(a + b);
        st.insert(b + a);
        reverse(b.begin(), b.end());
        st.insert(a + b);
        st.insert(b + a);
        reverse(a.begin(), a.end());
        st.insert(a + b);
        st.insert(b + a);
    }
    return st.size();
}
main(){
    int N;
    cin >> N;
    string S;
    rep(i,0,N){
        cin >> S;
        cout << solve(S) << endl;
    }
}


Measured memory_bytes: 3276
#python3
def main():
    s = list(input())
    n = len(s)
    ans = [0 for _ in range(n)]
    for _ in range(2):
        c = 0
        for i in range(n):
            if s[i] == 'R': 
                c += 1    
            else:
                ans[i-1] += (c+1)//2
                ans[i] += c//2 
                c = 0

        s.reverse()        
        ans.reverse()
        for i in range(n):
            if s[i] == 'R':
                s[i] = 'L'
            else:
                s[i] = 'R'

    for i in range(n):
        if i == n-1:
            print(ans[i])
        else:
            print(ans[i], end=' ')
main()

Measured memory_bytes: 5544
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		sc.close();

		int ans = 0;
		if(b>=a) {
			ans = a;
		} else {
			ans = a - 1;
		}

		System.out.println(ans);
	}


}

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

void c_p_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
int solve(int *arr,int n,int k)
{
	int dp[n+1];
	dp[1]=0;
	for(int i=2;i<=n;i++)
	{
		dp[i]=INT_MAX;
		for(int j=i-1;(j>=1&&j>=i-k);j--)
		{
			dp[i] = min(dp[i],abs(arr[i]-arr[j])+dp[j]);
		}
	}
	return dp[n];
}
int main()
{
	c_p_c();
	int n,k;
	cin>>n>>k;
	int arr[n+1];
	for(int i=1;i<=n;i++)
	{
		cin>>arr[i];
	}
	cout<<solve(arr,n,k);

	return 0;
}

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

int main()
{
	int n,m,k;
	cin>>n>>m>>k;
	long long sum=(n*k)-m;
	for(int i=0;i<10;i++)
	{   cout<<sum<<endl;
		sum=(sum*n)-m;
		
	}
	return 0;
}

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

int main() {
  int n, m, x, y;
  cin >> n >> m >> x >> y;

  int xs[n], ys[m];
  for (int i = 0; i < n; ++i) {
    cin >> xs[i];
  }
  for (int i = 0; i < m; ++i) {
    cin >> ys[i];
  }
  
  sort(xs, xs+n);
  sort(ys, ys+m);

  int z = xs[n-1] + 1;
  if (x < z && z <= y && ys[0] >= z) {
    cout << "No War" << endl;
    return 0;
  }

  z = ys[0];
  if (x < z && z <= y && xs[n-1] < z) {
    cout << "No War" << endl;
    return 0;
  }

  cout << "War" << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main
{
  public static void main(String args[]) {
 Scanner sc =new Scanner(System.in);
  	int n = sc.nextInt();
  	int[]a = new int[n];
  	for(int i =0;i <a.length; i++) {
  		a[i] = sc.nextInt();
  	}
  	Arrays.sort(a);
  	int sum = 0;
  	for(int i =0; i<a.length-1; i++) {
  		sum= sum + a[i];
  		
  	}
  	if(sum<=a[a.length-1]) {
  		System.out.println("No");
  	}
  	else {
  		System.out.println("Yes");
  	}
  	
  }
  
}

Measured memory_bytes: 35748
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#define VIZ2 {printf("graph G{\n"); for(int i=1;i<=n;i++) for es(i,e) if(vb[e]>=i)printf("%d--%d;\n",i,vb[e]); puts("}");}
#define SZ 666666
const int MOD=1e9+7;
ll fac[SZ],rfac[SZ];
ll qp(ll a,ll b)
{
	ll x=1; a%=MOD;
	while(b)
	{
		if(b&1) x=x*a%MOD;
		a=a*a%MOD; b>>=1;
	}
	return x;
}
ll cnt[4005][4005];
int n,a[SZ],b[SZ];
int main()
{
	fac[0]=1;
	for(int i=1;i<SZ;++i)
		fac[i]=fac[i-1]*i%MOD;
	rfac[SZ-1]=qp(fac[SZ-1],MOD-2);
	for(int i=SZ-1;i>=1;--i)
		rfac[i-1]=rfac[i]*i%MOD;
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	{
		scanf("%d%d",a+i,b+i);
		++cnt[2001-a[i]][2001-b[i]];
	}
	for(int i=1;i<=4002;++i)
		for(int j=1;j<=4002;++j)
		{
			cnt[i][j]+=cnt[i][j-1]+cnt[i-1][j];
			(cnt[i][j]>=MOD)?(cnt[i][j]-=MOD):0;
			(cnt[i][j]>=MOD)?(cnt[i][j]-=MOD):0;
			(cnt[i][j]>=MOD)?(cnt[i][j]-=MOD):0;
		}
	ll ans=0,t=0;
	for(int i=1;i<=n;++i)
	{
		(ans+=cnt[2001+a[i]][2001+b[i]])%=MOD;
		t+=fac[a[i]+a[i]+b[i]+b[i]]
		*rfac[a[i]+a[i]]%MOD*rfac[b[i]+b[i]]%MOD;
	}
	const ll i2=(MOD+1)/2;
	t%=MOD; (ans-=t)%=MOD;
	ans=ans*i2%MOD;
	ans=(ans%MOD+MOD)%MOD;
	printf("%d\n",int(ans));
}


Measured memory_bytes: 139904
import math
Q=int(input())
l=[0 for i in range(Q)]
r=[0 for i in range(Q)]
M=0
for i in range(Q):
    l[i],r[i]=map(int,input().split())
    if M<r[i]:
        M=r[i]
P=[True for i in range(M+1)]
P[0]=False
P[1]=False
S=[False for i in range(M+1)]
for i in range(2,int(math.sqrt(M))+1):
    if P[i]:
        for j in range(i*2,M+1,i):
            P[j]=False
R=[0 for i in range(M+1)]
k=0
for i in range(M+1):
    if P[i] and i%2==1:
        if P[(i+1)//2]:
            S[i]=True
            k+=1
    R[i]=k
for i in range(Q):
    print(R[r[i]]-R[l[i]-1])


Measured memory_bytes: 14168
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) obj.begin(),obj.end()
#define pb(obj) push_back(obj)
#define REP(i,N) for(ll i=0;i<N;i++)
typedef long long ll;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A,P;
    cin>>A>>P;
    cout<<(3*A+P)/2<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
const ll N = 105, INF = 1e18;
int n, source, sink;
ll a[N], par[N];
ll cap[N][N];
vector<int> adj[N];
 
ll bfs(int source, int sink) {
	memset(par, -1, sizeof par);
	par[source] = -2;
	queue<pair<int, ll>> q;
	q.push({source, INF});
	while(!q.empty()) {
		ll u = q.front().first, flow = q.front().second;
		q.pop();
		for(auto& v : adj[u]) {
			if(par[v] == -1 && cap[u][v]) {
				par[v] = u;
				ll new_flow = min(flow, cap[u][v]);
				if(v == sink) return new_flow;
				q.push({v, new_flow});
			}
		}
	}
	return 0;
}

ll maxflow(int source, int sink) {
	ll flow = 0;
	ll newFlow;
	while((newFlow = bfs(source, sink))) {
		flow += newFlow;
		int u = sink;
		while(u != source) {
			int v = par[u];
			cap[v][u] -= newFlow;
			cap[u][v] += newFlow;
			u = v;
		}
	}
	return flow;
}
 
int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	source = n+1; sink = n+2;
	ll ideal = 0;
	for(int i = 1; i <= n; i++)
		cin >> a[i], ideal += (a[i]>0)?a[i]:0;
	memset(cap, 0, sizeof cap);
	for(int i = 1; i <= n; i++) {
		if(a[i] < 0) adj[source].push_back(i), adj[i].push_back(source), cap[source][i] = -a[i];
		else adj[i].push_back(sink), adj[sink].push_back(i), cap[i][sink] = a[i];
	}
	for(int i = 1; i <= n; i++) {
		for(int j = 2*i; j <= n; j+=i)
			adj[i].push_back(j), adj[j].push_back(i), cap[i][j] = INF;
	}
	ll mf = maxflow(source, sink);
	ll ans = ideal - mf;
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 3740
#include <stdio.h>
int main(void){
    // Your code here!
    char buf[100];
    int a, b, c;
    fgets(buf, sizeof(buf), stdin);
    sscanf(buf, "%d %d %d", &a, &b , &c);
    if (c <= b && c >= a) {
        printf("%s", "Yes");
    } else {
        printf("%s", "No");
    }
    return 0;
}


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

int main(){
	int n; string s; cin>>n>>s;
	string s2=s;
	sort(all(s2));
	int cnt=0;
	rep(i,n){
		if(s2[i]!=s[i]) cnt++;
	}
	cout<<cnt/2<<endl;
}

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

using namespace std;
typedef pair<int, int> P;

int n, m;
int ans = 0;
vector<P> score;
bool used[36];
P ctom[36];

int convert(int a, int b) {
	//チームaとチームbの試合の通し番号 a < b
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (i == a && b == j) {
				return cnt;
			}
			cnt++;
		}
	}
	return cnt;
}

void dfs(int match, vector<P> S){

	if (match == (n - 1) * n / 2) {
		for (int i = 0; i < n; i++) {
			if (S[i].first != S[i].second)return;
		}
		ans++;
		return;
	}

	if (used[match]) {
		dfs(match + 1, S);
		return;
	}

	int a = ctom[match].first, b = ctom[match].second;
	//a勝b敗
	auto Scpy = S;
	if (Scpy[a].first < (n - 1) / 2 && Scpy[b].second < (n - 1) / 2) {
		Scpy[a].first++, Scpy[b].second++;
		dfs(match + 1, Scpy);
	}

	//b勝a敗
	Scpy = S;
	if (Scpy[b].first < (n - 1) / 2 && Scpy[a].second < (n - 1) / 2) {
		Scpy[b].first++, Scpy[a].second++;
		dfs(match + 1, Scpy);
	}

}

int main() {
	while (1) {
		cin >> n;
		if (n == 0)break;
		cin >> m;
		score.resize(n);
		{
			int cnt = 0;
			for (int i = 0; i < n; i++) {
				for (int j = i + 1; j < n; j++) {
					ctom[cnt] = P(i, j);
					cnt++;
				}
			}
		}
		for (int i = 0; i < m; i++) {
			int a, b;
			cin >> a >> b;
			a--, b--;
			score[a].first++, score[b].second++;
			used[convert(min(a, b), max(a, b))] = true;
		}
		
		dfs(0, score);
		
		cout << ans << endl;

		score.clear();
		for (int i = 0; i < 36; i++)used[i] = false;
		ans = 0;
	}
	return 0;
}


Measured memory_bytes: 3116
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>

using namespace std;



template<typename T, typename D>
struct Edge {
    T to;
    D distance;
};


template<typename T, typename D, D nonval>
class Gr {
public:
    using edge = std::unordered_map<T, D>;

    using vertex_iterator = typename std::unordered_map<T, edge>::iterator;

    void set(T from, T to, D distance) {
        mat_[from][to] = distance;
    }

    D distance(T from, T to) const {
        if (mat_.find(from) != mat_.end()) {
            if (mat_[from].find(to) != mat_[from].end()) {
                return mat_[from][to];
            }
        }
        return nonval;
    }

    vertex_iterator vertex_begin() {
        return mat_.begin();
    }
    vertex_iterator vertex_end() {
        return mat_.end();
    }

    typename edge::iterator edge_begin(T from) {
        return mat_[from].begin();
    }
    typename edge::iterator edge_end(T from) {
        return mat_[from].end();
    }

private:

    std::unordered_map<T, edge> mat_;
};




int main()
{
    size_t N, M;
    std::cin >> N >> M;

    Gr<int, int, INT_MAX> g;
    for (size_t i = 0; i < M; ++i) {
        int L, R, D;
        std::cin >> L >> R >> D;
        L--;
        R--;
        g.set(L, R, D);
        g.set(R, L, D * -1);
    }

    std::vector<int> X(N);
    std::fill(std::begin(X), std::end(X), INT_MIN);


    for (auto&& itr = g.vertex_begin(); itr != g.vertex_end(); ++itr) {
        auto f = [&g, &X](auto F, int v, int pos) -> bool {
            if (X[v] != INT_MIN) {
                return pos == X[v];
            }
            X[v] = pos;

            for (auto jtr = g.edge_begin(v); jtr != g.edge_end(v); ++jtr) {
                auto to = jtr->first;
                auto d = jtr->second;

                if (!F(F, to, X[v] + d)) {
                    return false;
                }
            }
            return true;
        };

        if (X[itr->first] == INT_MIN && !f(f, itr->first, 0)) {
            std::cout << "No" << std::endl;
            return 0;
        }
    }

    std::cout << "Yes" << std::endl;

    return 0;
}


Measured memory_bytes: 30500
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
 
int main() {
    int N;
    cin >> N;
    map<long long int,long long int> mp;

    vector<long long int> vec(N);
    for(int i=0; i<N; i++){
        cin >> vec[i];
        mp[i+vec[i]]++;
    }

    long long int ans=0;
    for(int i=0; i<N; i++){
        ans += mp[i-vec[i]];
    }

    cout << ans << endl;
}

Measured memory_bytes: 27464
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long
#define inf 999999999999
#define mx 200005
#define gcd __gcd
#define pb push_back
#define mk make_pair
#define bs binary_search
#define ub upper_bound
#define lb lower_bound
#define endl "\n"
#define vl vector<ll>
#define vs vector<string>
using namespace std;

bool isp[mx];

void sv(){

	ll i,j;
	memset(isp, true, sizeof(isp));
	
	isp[1]= false;
	for(i=2;i*i<mx;i++){
		if(isp[i]){
			for(j=i*i;j<mx;j+=i)
			isp[j]= false;
		}
	}
}

ll powr(ll a,ll b)
{
	ll res=1;
	while(b)
	{
		if(b&1)res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	//sv();
	ll n,m,i,j,a[mx];
	pair<ll, ll> p[mx];
	cin>>n>>m;
	for(i=0;i<n;i++)
	cin>>a[i];
	
	for(i=0;i<m;i++)
	cin>>p[i].second>>p[i].first;
	
	sort(a,a+n);
		sort(p,p+m);
	reverse(p,p+m);
	
	/*for(i=0;i<m;i++)
	cout<<p[i].second<<" "<<p[i].first<<endl;*/
	
	
	ll k=0, cnt=0;
	for(i=0;i<m;i++)
	{
		for(j=k;j<k+p[i].second; j++)
		{
			if(a[j]>= p[i].first)
			break;
			
			a[j]=p[i].first;
			//cnt++;
		}
		k=j;
	}
	ll ans=0;
	for(i=0;i<n;i++)
	{
		//cout<<a[i]<<" ";
		ans+=a[i];
	}
	
	cout<<ans;//<<" "<<cnt;
    return 0;
}























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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true; } return false; }
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true; } return false; }

//INT_MAX	2,147,483,647 = 2*1.0e9

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;

    if(X > Y){
        swap(A,B);
        swap(X,Y);
    }

    int min2 = min(A+B, 2 *C);
    int ans = 0;
    ans += X * min2;

    int rest = Y - X;
    int min3 = min(B, 2 * C);
    ans += min3 * rest;

    cout << ans << endl;

    return 0;
}


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

// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;

# define ll long long int
#define M 1000000007
#define pb push_back
#define ss second
#define ff first
#define inf 1000000000000000


 

													//nestedcode



int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll d,t,s;
    cin>>d>>t>>s;
    if(s*t >= d){
    	cout<<"Yes";
	}else{
		cout<<"No"<<endl;
	}
}


Measured memory_bytes: 3600
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

char table[3][4];

bool check(int number){

	int length = 0,index = 0,array[10];

	while(number > 0){
		array[index++] = number%10;
		number /= 10;
	}

	length = index;

	for(int i = 0; i < length/2; i++){
		if(array[i] != array[length-1-i]){
			return false;
		}
	}

	return true;
}

int main(){

	int A,B;
	scanf("%d %d",&A,&B);

	int ans = 0;

	for(int i = A; i <= B; i++){
		if(check(i) == true){
			ans++;
		}
	}

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

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define rep1(i,n)for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=(int)(n)-1;0<=i;i--)
#define rrep1(i,n) for(int i=(int)(n);1<=i;i--)

#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 

#define pcount __builtin_popcount
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())

#define dump(x)  cerr << #x << " = " << (x) << endl;

#define endl "\n"

template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}

typedef long long lint;

using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	cout<<(max({a,b,c})==a+b+c-max({a,b,c})?"Yes":"No")<<endl;
}

Measured memory_bytes: 256
(let ((fi '(1 3 5 7 8 10 12))
      (se '(4 6 9 11))
      (th '(2) )
      (x (read))
      (y (read)))
    (cond
        ((and (member x fi) (member y fi)) (princ "Yes"))
        ((and (member x se) (member y se)) (princ "Yes"))
        ((and (member x th) (member y th)) (princ "Yes"))
        (t (princ "No")))
    (princ #\LineFeed))

Measured memory_bytes: 12004
use std::io;

fn main() {
    let labels = (0..(1 << 4)).map(|mask| {
        let mut label = "".to_owned();
        if ((1 << 0) & mask) != 0 {
            label.push('A');
        }
        label.push('K');
        label.push('I');
        label.push('H');
        if ((1 << 1) & mask) != 0 {
            label.push('A');
        }
        label.push('B');
        if ((1 << 2) & mask) != 0 {
            label.push('A');
        }
        label.push('R');
        if ((1 << 3) & mask) != 0 {
            label.push('A');
        }
        label
    }).collect::<Vec<_>>();

    let s = read_line().trim().to_owned();

    if labels.contains(&s) {
        println!("YES");
    } else {
        println!("NO");
    }
}

fn read_line() -> String {
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).unwrap();
    buf
}

fn read<T>() -> T
    where T: std::str::FromStr,
          T::Err: std::fmt::Debug
{
    read_line().trim().parse().unwrap()
}

fn read_values<T>() -> Vec<T>
    where T: std::str::FromStr,
          T::Err: std::fmt::Debug
{
    read_line()
        .split(' ')
        .map(|a| a.trim().parse().unwrap())
        .collect()
}

Measured memory_bytes: 4352
a, b, c, x, y = gets.chomp.split(' ').map(&:to_i)
price = a * x + b * y
c_count = x >= y ? x : y

(c_count*2+1).times do |i|
  next if i.odd? || i.zero?

  a_count = x - i/2 > 0 ? x - i/2 : 0
  b_count = y - i/2 > 0 ? y - i/2 : 0
  tmp = a * a_count + b * (y - i/2).abs + c * i
#   puts "#{tmp}円: #{(x - i/2).abs}, #{ (y - i/2).abs}, #{i}"
  price = price > tmp ? tmp : price
end
puts price

Measured memory_bytes: 3836
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef pair<int, int> P;
const long long LINF = 1000000000000000018ll;
const int INF = 1000000009;
const int mod = 1000000007;
const int mod2 = 998244353;

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::cout << std::setprecision(20) << std::fixed;

  int N;
  cin >> N;

  vector<bool> table(N);
  for (int i = 0; i < N; i++) {
    int D1, D2;
    cin >> D1 >> D2;
    table[i] = D1 == D2;
  }

  for (int i = 0; i < N-2; i++) {
    bool f1 = table[i];
    bool f2 = table[i+1];
    bool f3 = table[i+2];
    if (f1 && f2 && f3) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 3612
using System;

class ABC150_A
{
    static void Main(string[] args)
    {
        string[] str = Console.ReadLine().Split(' ');
        int k = int.Parse(str[0]);
        int x = int.Parse(str[1]);

        if (500 * k >= x)
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath> 
using namespace std;

int main(){
    int N;
    cin >> N;
    int dig, num, sum = 0;

    num = N;

    while(num > 0){
        dig = num % 10;
        sum = sum + dig;
        num = num / 10;
    }

    if(N%sum == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    ll ans = 0;
    rep(i, n) {
        ans += (i + 1) * (n - i);
    }
    rep(i, n - 1) {
        ll u, v;
        cin >> u >> v;
        if (u > v) swap(u, v);
        ans -= u * (n - v + 1);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
// #define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
#define ITR(v,c) for(auto v=begin(c);v!=end(c);v++)
#define FORE(x,c) for(auto &x:c)
#define FOR(v,a,n) for(int v=a;v<(int)(n);v++)
#define REP(v,n) FOR(v,0,n)
#define RREP(v,n) for(int v=((int)(n)-1);v>=0;v--)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define SZ(c) ((int)c.size())
const int DX[9]={0,1,0,-1,1,1,-1,-1,0}, DY[9]={-1,0,1,0,-1,1,1,-1,0};
const int INF=1e9; const long long INFLL=1e18;
template<class T> ostream& operator << (ostream &os, const vector<T> &v) {
    ITR(i,v) os<<*i<<(i==end(v)-1?"":" "); return os; }
template<class T> istream& operator >> (istream &is, vector<T> &v) {
    ITR(i,v) is>>*i; return is; }
//------------------------------------------------------------------------------

signed main() {
    string s;
    cin>>s;
    bool c=false;
    REP(i,SZ(s)) {
        if(!c && s[i]=='C') {
            c=true;
        }
        if(c && s[i]=='F') {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    ll N; cin >> N;
    vector<ll> A(N);
    map<ll,ll> M;
    ll ma = 0;
    ll mi = pow(10,5);
    rep(i,N) {
        cin >> A.at(i);
        M[A[i]]++;
        mi = min(mi, A[i]);
        ma = max(ma, A[i]);
    }
    ll mid = 0;
    ll mma = 0;
    for (ll i = mi; i <= ma; i++) {
        ll tmp = M[i-1] + M[i] + M[i+1];
        if (tmp > mma) {
            mma = tmp;
            mid = i;
        }
    }
    cout << mma << endl;
}

Measured memory_bytes: 7296
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <set>

using namespace std;

int num[4];
string ope[] = {" + ", " - ", " * "};

int op(int o, int a, int b){
	
	if(o==0)
		return a+b;
	else if(o==1)
		return a-b;
	else 
		return a*b;
}

void solve(){
	
	sort(num, num+4);
	
	do{
		
		for(int o1=0; o1<3; ++o1){
			for(int o2=0; o2<3; ++o2){
				for(int o3=0; o3<3; ++o3){
					for(int par=0; par<5; ++par){
						
						if(par==0 && op(o1, num[0], op(o2, num[1], op(o3, num[2], num[3]))) == 10){
							cout << "(" <<num[0] << ope[o1] << "(" << num[1] << ope[o2] << "(" << num[2] << ope[o3] << num[3] << ")))" << endl;
							return;
						}
						if(par==1 && op(o1, op(o2, num[0], num[1]), op(o3, num[2], num[3])) == 10){
							cout << "((" << num[0] << ope[o2] << num[1] << ")" << ope[o1] << "(" << num[2] << ope[o3] << num[3] << "))" << endl;
							return;
						}
						if(par==2 && op(o1, num[0], op(o2, op(o3, num[1], num[2]), num[3])) == 10){
							cout << "(" << num[0] << ope[o1] << "((" << num[1] << ope[o3] << num[2] <<")"<< ope[o2] << num[3] << "))" <<endl;
							return;
						}
						if(par==3 && op(o1, op(o2, num[0], op(o3, num[1], num[2])), num[3]) == 10){
							cout << "(" <<num[0] << ope[o2] << "(" << num[1] << ope[o3] << num[2] <<")"<< ope[o1] <<num[3] << ")" <<endl;
							return;
						}
						if(par==4 && op(o1, op(o2, op(o3, num[0], num[1]), num[2]), num[3]) == 10){
							cout << "(((" <<num[0] << ope[o3] << num[1] << ")" << ope[o2] << num[2] << ")" << ope[o1] << num[3] <<")"<< endl;
							return;
						}
					}
				}
			}
		}
		
	}while(next_permutation(num, num+4));
	
	cout << 0 << endl;
	return;
}

int main(){
	
	while(cin>>num[0], num[0]){
		
		for(int i=1; i<4; ++i){
			cin>>num[i];
		}
		
		solve();
	}
	
}

Measured memory_bytes: 1224
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <deque>
#include <unordered_set>
#include <unordered_map>
#include <functional>
 
using namespace std;

int main() {
    int s,w;
    cin>> s>>w;
    if (w>=s)
        cout<<"unsafe";
    else
        cout<<"safe";
}

Measured memory_bytes: 3632
N = int(input())
A = [int(a) for a in input().split()]

RejectStones = N * (N+1) // 2
if sum(A) % RejectStones != 0: print("NO")
else:
    TotalOperation = sum(A) // RejectStones
    sumcheck = 0
    for i in range(N-1):
        if (TotalOperation - A[i+1] + A[i]) % N != 0 or TotalOperation < A[i+1] - A[i]:
            print("NO")
            break
        else:
            sumcheck += (TotalOperation - A[i+1] + A[i]) // N
    else:
        if (TotalOperation - A[0] + A[-1]) % N != 0 or TotalOperation < A[0] - A[-1]: print("NO")
        else: 
            sumcheck += (TotalOperation - A[0] + A[-1]) // N
            if sumcheck == TotalOperation: print("YES")
            else: print("NO")

Measured memory_bytes: 14588
# -*- coding: utf-8 -*-

n, m, c = map(int, input().split())

lst = []
for i in range(n+1):
    lst_1 = list(map(int, input().split()))
    lst.append(lst_1)
a=0
b=0
for j in range(n):
    for i in range(m):
        a = a + lst[0][i]*lst[j+1][i]
    if a+c>0:
        b=b+1
    a=0

print(b)


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


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

    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    ll ng = 0;
    ll ok = 1000000000;
    while (ok - ng > 1) {
        ll mid = (ok + ng) / 2;
        ll cut = 0;
        rep(i,N) {
            if (A[i] < mid) continue;
            cut += (A[i] - 1) / mid;
        }
        if (cut <= K) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
}




Measured memory_bytes: 4844
"""
D - Grid Components

２つの大きな領域を描画後、点を打っていけば良いらしい
"""

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

square_n = int((max(a, b) ** 0.5) * 2 + 1)

#print(square_n)

white_p = 1
black_p = 1
white_mat = [["." for n in range(square_n)] for m in range(square_n)]
black_mat = [["#" for n in range(square_n)] for m in range(square_n)]

#print(white_mat)
#print(black_mat)

def paint(target_p, current_p, matrix, char):
    for row in range(0, square_n, 2):
        for col in range(0, square_n, 2):
            # 交互になってるので塗る
            if current_p != target_p:
                #print(row, col)
                matrix[row][col] = char
                current_p += 1
            else:
                return

paint(a, white_p, black_mat, ".")
paint(b, black_p, white_mat, "#")

print(square_n*2, square_n)
#print(white_mat)
#print(black_mat)

for row in white_mat:
    print("".join(row))
for row in reversed(black_mat):
    print("".join(row))


Measured memory_bytes: 3064
#pragma GCC optimize("O3") 
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx") 
#define __USE_MINGW_ANSI_STDIO 0
#include<bits/stdc++.h>                               
using namespace std;

#define PI acos(-1)
#define pb push_back
#define fi first
#define se second
#define TASK ""
#define sz(a) (int)(a).size()
#define all(c) (c).begin(), (c).end()
#define TIMESTAMP fprintf(stderr, "Execution time: %.3lf s.\n", (double)clock()/CLOCKS_PER_SEC)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair <int, int> pii;
typedef vector <vi> vvi;
typedef vector <pii> vpii;
typedef vector <string> vs;

const int MAXN = 1e5 + 9;
const int MOD = (int)(1e9 + 7);
const int INF = 100500;

int di[] = {0, 1, 0, -1};
int dj[] = {1, 0, -1, 0};
ll n, m;
string s;

void input() {
	ll a, b;
	cin >> n >> a >> b;
	if(n == 1) {
		if(a == b) {
			cout << 1;
		}
		else {
			cout << 0;
		}
		return;
	}	
	else {
		if(a == b) {
			cout << 1;
			return;
		}
		ll l = a * (n - 1) + b;
		ll r = a + (n - 1) * b;
		cout << max(r - l + 1, 0LL) << endl;
	}
}

void solve() {

}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#ifdef LOCAL
	freopen("xxx.in", "r", stdin);
	freopen("xxx.out", "w", stdout);
#else
	//freopen(TASK".in", "r", stdin);
	//freopen(TASK".out", "w", stdout);
#endif	
	input();
	solve();
#ifdef LOCAL
	TIMESTAMP;
#endif	
	return 0;
}

Measured memory_bytes: 256
def getDistance( x, y, n, pow )
	dxy = 0
	for i in ( 0 ... n )
		dxy += ( x[i] - y[i] ).abs**pow
	end
	return dxy**(1.0/pow)
end
		

n = gets.to_i
x = gets.split( " " ).map { |val| val.to_f }
y = gets.split( " " ).map { |val| val.to_f }

puts( getDistance( x, y, n, 1 ) )
puts( getDistance( x, y, n, 2 ) )
puts( getDistance( x, y, n, 3 ) )
dxy = Array.new( n, 0 )
for i in ( 0 ... n )
	dxy[i] = ( x[i] - y[i] ).abs
end
puts( dxy.max )

Measured memory_bytes: 6200
# -*- coding: utf-8 -*-

import math

if __name__ == '__main__':
    N = int(input())
    A = []
    for i in range(N):
        A.append(int(input()))

    value = sorted(A)
    first = value[N-1]
    second = value[N-2]


    # print(A)

    for i in range(N):
        if A[i] != first:
            print(first)
        else:
            print(second)



Measured memory_bytes: 14160
n,m,c=map(int,input().split())
b=list(map(int,input().split()))
ans=0
for i in range(n):
    a=list(map(int,input().split()))
    now=0
    for j in range(m):now+=a[j]*b[j]
    if now>-c:ans+=1
print(ans)

Measured memory_bytes: 3060