akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<list>
#include<bitset>
using namespace std;

class c {
public:
	c(int M, int N);
	~c();
	vector<vector<int>>& get();
private:
	int M;
	int N;
	vector<vector<int>> ans;
	void func(vector<int> d);
};

c::c(int M, int N) : M(M), N(N) {
	ans.clear();
}

c::~c() {
}

vector<vector<int>>& c::get() {
	vector<int> dum(1, 1);
	func(dum);
	return ans;
}

void c::func(vector<int> d) {
	if (d.size() == N) {
		ans.push_back(d);
	}
	else {
		vector<int> dum;
		for (int i = d[d.size() - 1]; i <= M; i++) {
			dum = d;
			dum.push_back(i);
			func(dum);
		}
	}
}

int main() {

	int N, M, Q;
	cin >> N >> M >> Q;

	vector<vector<int>> p(Q, vector<int>(4, 0));

	for (int i = 0; i < Q; i++) {
		cin >> p[i][0] >> p[i][1] >> p[i][2] >> p[i][3];
	}

	c cv(M, N);
	vector<vector<int>>& ans = cv.get();

	unsigned long long aa = 0;
	unsigned long long val = 0;
	for (int j = 0; j < ans.size(); j++) {
		val = 0;
		for (int i = 0; i < Q; i++) {
			if (ans[j][p[i][1] - 1] - ans[j][p[i][0] - 1] == p[i][2]) {
				val += p[i][3];
			}
		}
		if (aa < val) {
			aa = val;
		}
	}
	
	cout << aa << endl;

	return 0;
}



Measured memory_bytes: 6772
#include "bits/stdc++.h"

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

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

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

ll gcd(ll a, ll b){
  ll r = a%b;
  if(r==0) return b;
  else return gcd(b, a%b);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

struct UnionFind{
  ll N;
  llvec p;
  llvec cnt;
  UnionFind(ll n){
    N = n;
    p=llvec(N);
    cnt=llvec(N, 0);
    rep(i, N){
      p[i] = i;
      cnt[i] = 1;
    }
  }

  void con(ll a, ll b){
    P at = root(a);
    P bt = root(b);
    if(at.second!=bt.second){
      if(at.first>bt.first){
        swap(at, bt);
        swap(a, b);
      }
      p[at.second] = bt.second;
      cnt[bt.second]+=cnt[at.second];
      p[a]=bt.second;
    }
  }

  P root(ll a){
    ll atmp = a;
    ll c=0;
    while(atmp!=p[atmp]){
      atmp = p[atmp];
      c++;
    }
    p[a] = atmp;
    return {c, atmp};
  }

  bool is_con(ll a, ll b){
    P at=root(a);
    P bt=root(b);
    return at.second == bt.second;
  }
  
};

struct dijkstra{
  ll N;
  llvec d;
  vector<vector<edge>> e;
  dijkstra(ll n){
    N = n;
    //d = llvec(N, 1e18);
    e = vector<vector<edge>>(N);
  }

  void add_edge(ll from, ll to, ll cost){
    e[from].push_back({to, cost});
  }

  void run(ll start){
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, start});
    d = llvec(N, 1e18);
    d[start]=0;
    while(!que.empty()){
      P q = que.top();que.pop();
      ll dc = q.first;
      ll x = q.second;
      if(dc>d[x]){
        continue;
      }else{
        for(auto ip: e[x]){
          if(d[ip.x]<=d[x]+ip.c){
            continue;
          }else{
            d[ip.x]= d[x]+ip.c;
            que.push({d[ip.x], ip.x});
          }
        }
      }
    }
  }  
};


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N;
  cin >> N;
  llvec a(N);
  rep(i, N)cin >> a[i];
  ll ans = 1e18;
  for(ll i=-100;i<=100;i++){
    ll tmp =0;
    rep(j, N){
      tmp += pow(a[j]-i, 2);
    }
    ans = min(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}


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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

const int mod = 1000000007;
struct mint {
    long long x;
    mint(long long x = 0) : x((x % mod + mod) % mod) {}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return (*this) *= a.inv(); }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> G(H);
    rep(i, H) cin >> G[i];
    vector<vector<mint>> cnt(H + 1, vector<mint>(W + 1, 0));
    cnt[0][0] = 1;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (G[i][j] == '#') continue;
            if (i + 1 < H and G[i + 1][j] == '.') cnt[i + 1][j] += cnt[i][j];
            if (j + 1 < W and G[i][j + 1] == '.') cnt[i][j + 1] += cnt[i][j];
        }
    }
    cout << cnt[H - 1][W - 1].x << endl;
    return 0;
}

Measured memory_bytes: 13036
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

struct BIT{
    vector<ll> bit; //1-indexed
    int n;
    BIT(int n) : n(n), bit(vector<ll>(n+1, 0)) {}
    BIT(vector<ll> &v){
        n = v.size();
        bit = vector<ll>(n+1, 0);
        REP(i,n) add(i+1, v[i]);
    }
    ll sum(int i){
        ll s = 0;
        while(i > 0){
            s += bit[i];
            i -= i & -i;
        }
        return s;
    }
    void add(int i, int x){
        while(i <= n){
            bit[i] += (ll)x;
            i += i & -i;
        }
    }
};

int main(void)
{
    int N;
    cin >> N;
    vector<ll> a(N), b(N);
    REP(i, N) cin >> a[i];
    REP(i, N) cin >> b[i];
    reverse(ALL(b));
    BIT A(a), B(b);
    ll ans = 0;
    REP(i, N){
        ans = max(ans, A.sum(i+1) + B.sum(N-i));
    }
    pr(ans);
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# E

import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect
input = sys.stdin.readline

# 再起回数上限変更
# sys.setrecursionlimit(1000000)

n = int(input())
a = list(map(int, input().split()))

res = 0
for a_ in a:
    res = a_ ^ res

for a_ in a:
    print(a_ ^ res, end=' ')
print()


Measured memory_bytes: 92476
import math

num = int(input())

dic = {}
manykey = []


for i in range(num):
  s = input()
  s = "".join(sorted(s))
  
  if s in dic.keys():
    if dic[s] == 1:
      manykey.append(s)
    dic[s] += 1
  else:
    dic[s] = 1

ans = 0
for key in manykey:
  c = dic[key]
  ans += math.factorial(c)//math.factorial(c-2)//math.factorial(2)
    
print(ans)

Measured memory_bytes: 17928
#include<iostream>
#include<string>
#include<sstream>
using namespace std;

typedef long long ll;

string s;

ll stol(string str){
  stringstream ss(str);
  ll n;
  ss >> n;
  return n;
}

ll parse(int l, int r){
  int n = 0, i;
  for(int i=r-1;i>=l;i--){
    if(s[i] == ')')n++;
    if(s[i] == '(')n--;
    if(!n){
      if(s[i] == '+')return parse(l,i) + parse(i+1,r);
      if(s[i] == '-')return parse(l,i) - parse(i+1,r);
    }
  }
  for(int i=r-1;i>=l;i--){
    if(s[i] == ')')n++;
    if(s[i] == '(')n--;
    if(!n){
      if(s[i] == '*')return parse(l,i) * parse(i+1,r);
      if(s[i] == '/')return parse(l,i) / parse(i+1,r);
    }
  }

  if(s[l] == '(' && s[r-1] == ')')return parse(l+1,r-1);
  return stol( s.substr(l,r-l) );
}

int main(){
  int n;
  cin >> n;
  while(n--){
    cin >> s;
    cout << parse(0,(int)s.size()-1) << endl;
  }
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>

using namespace std;
double sikin_tan(double,int,int,double);
double sikin_huku(double,int,int,double);

int main(){
	int m;
	cin>>m;
	int n,nensuu,tan_huku,tesuu;
	double money,kinri,maxi=0.0;
	for(int i=0;i<m;i++){
		cin>>money;
		cin>>nensuu;
		cin>>n;
		for(int j=0;j<n;j++){
			cin>>tan_huku>>kinri>>tesuu;	//0のとき単利、1のとき複利
			if(tan_huku==0)
				maxi=max(maxi,sikin_tan(money,nensuu,tesuu,kinri));
			else if(tan_huku==1)
				maxi=max(maxi,sikin_huku(money,nensuu,tesuu,kinri));
		}
		cout<<(int)maxi<<endl;
		maxi=0;
	}
}
double sikin_tan(double money,int nensu,int tesu,double kinri){
	int risi=0;
	for(int i=0;i<nensu;i++){
		risi+=money*kinri;
		money-=(double)tesu;
	}
	return money+risi;
}
double sikin_huku(double money,int nensu,int tesu,double kinri){
	int risi=0;
	for(int i=0;i<nensu;i++){
		risi=money*kinri;
		money+=risi;
		money-=(double)tesu;
	}
	return money;
}

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

#define LET(name, value) __typeof(value) name = value
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define FOREQ(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOREACH(i, c) for (LET(i, (c).begin()); i != (c).end(); ++i)

struct Panel {
  char name[1024];
  int x1, y1, x2, y2;
  vector<Panel*> children;
};

pair<Panel*, const char*> parse(const char* input) {
  Panel* panel = new Panel;
  sscanf(input, "<%[^>]>%d,%d,%d,%d",
      panel->name, &panel->x1, &panel->y1, &panel->x2, &panel->y2);
  input = strchr(input+1, '<');
  while (input[1] != '/') {
    pair<Panel*, const char*> p = parse(input);
    panel->children.push_back(p.first);
    input = p.second;
  }
  return make_pair(panel, strchr(input, '>')+1);
}

inline bool point_in_rect(int x, int y, int x1, int y1, int x2, int y2) {
  return x1 <= x && x <= x2 && y1 <= y && y <= y2;
}

void dfs(Panel* panel, int x, int y) {
  bool b = true;
  FOREACH(it, panel->children) {
    Panel* child = *it;
    if (point_in_rect(x, y, child->x1, child->y1, child->x2, child->y2)) {
      dfs(child, x, y);
      b = false;
    }
  }
  if (b) { printf("%s %zd\n", panel->name, panel->children.size()); }
}

int main() {
  int n;
  while (scanf("%d", &n), n) {
    char input[1024]; scanf("%s", input);
    pair<Panel*, const char*> p = parse(input);
    Panel* root = p.first;
    assert(*p.second == 0);
    REP(i, n) {
      int x, y; scanf("%d%d", &x, &y);
      if (point_in_rect(x, y, root->x1, root->y1, root->x2, root->y2)) {
        dfs(root, x, y);
      } else {
        puts("OUT OF MAIN PANEL 1");
      }
    }
  }
}

Measured memory_bytes: 0
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,a,b,c = inpl()
a = [a,b,c]
s = [input() for _ in range(n)]
res = []
for i,x in enumerate(s):
    if x == 'AB':
        x,y = 0,1
    elif x == 'AC':
        x,y = 0,2
    else:
        x,y = 1,2
    if a[x] > a[y]:
        a[x] -= 1
        a[y] += 1
        res.append(y)
    elif a[x] < a[y]:
        a[x] += 1
        a[y] -= 1
        res.append(x)
    elif a[x] == a[y] == 1 and i != n-1:
        nx,ny = list(s[i+1])
        nx = ord(nx) - ord('A')
        ny = ord(ny) - ord('A')
        if (x,y) == (nx,ny):
            a[x] -= 1
            a[y] += 1
            res.append(y)
        elif x == nx:
            a[nx] += 1
            a[y] -= 1
            res.append(nx)
        elif y == nx:
            a[nx] += 1
            a[x] -= 1
            res.append(nx)
        elif x == ny:
            a[ny] += 1
            a[y] -= 1
            res.append(ny)
        else:
            a[ny] += 1
            a[x] -= 1
            res.append(ny)
    else:
        a[x] -= 1
        a[y] += 1
        res.append(y)
    if a[x] < 0 or a[y] < 0:
        print('No')
        quit()
print('Yes')
for i,x in enumerate(res):
    print(chr(ord('A') + x))


Measured memory_bytes: 95544
/*
3 0: 1

x1 + x2 + .... xn = n

0<=xj<=min(n, k+1)

*/

#include <bits/stdc++.h>

#define pb push_back

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const ll INF = 1<<30;
const ll MOD = 1e9+7;

ll x, y;

ll extended_gcd(ll a, ll b){
	if(b==0){
		x = 1;
		y = 0;
		//printf("%lld*%lld + %lld*%lld = %lld\n", a, x, b, y, a); 
		return a;
	}
	else{
		ll g = extended_gcd(b, a%b);
		/*
			b*x + y*(a - a/b*b) = g
			a*y + b*(x - a/b*y) = g
		*/
		ll tmp = x;
		x = y;
		y = tmp-a/b*y;
		//printf("%lld*%lld + %lld*%lld = %lld\n", a, x, b, y, g);
		return g;
	}
}


ll modinverse(ll a){
	ll g = extended_gcd(a, MOD);
	//cout<<g<<"\n";
	while(x<0)
		x+=MOD;
	return x;
}

int main(){
	vector<ll> inv;
	vector<ull> fact;
	int n;
	ll k;
	cin>>n>>k;
	inv.assign(n+1, 0);
	fact.assign(n+1, 0);

	fact[0] = 1;
	for(int i=1;i<=n;i++)
		fact[i] = (fact[i-1]*i)%MOD;
	
	ull ans = 0;
	for(int m=0;m<min(k+1, (ll)n);m++){
		ull tmp = fact[n];
		tmp = (tmp*modinverse(fact[m]))%MOD;
		tmp = (tmp*modinverse(fact[n-m]))%MOD;
		tmp = (tmp*fact[n-1])%MOD;
		tmp = (tmp*modinverse(fact[m]))%MOD;
		tmp = (tmp*modinverse(fact[n-m-1]))%MOD;
		ans = (ans+tmp)%MOD;
	}

	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
struct edge{int from, to;};
int alpha[26]={};
int main(){
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++){
        alpha[s[i]-'a']=1;
    }
    for(int i=0;i<26;i++){
        if(alpha[i]==0) {
            cout << char(i+'a') << endl;
            return 0;
        }
    }
    cout << "None"<<endl;
    
    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#include <stdbool.h>
int main(){
   int A,B,C,D;
   scanf("%d %d %d %d",&A,&B,&C,&D);
   bool a=true;
while (A>0 &&C>0)
{
   if (a){
      C -= B;
   }else{
      A -= D;
   }
    a = !a;
}
if (A>0){
   printf("Yes");
}else{
  printf("No");
}
return 0;
}


Measured memory_bytes: 1712
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String a=scan.next();
		String b=scan.next();
		if(a.charAt(0)==b.charAt(2)&&a.charAt(1)==b.charAt(1)&&a.charAt(2)==b.charAt(0)) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> VI;
typedef vector<VI> VVI;
typedef pair<ll, ll> P;
#define FOR(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const ll INF = numeric_limits<ll>::max();
int main()
{
    ll n; cin >> n;
    ll s = 0;
    VI a(n);
    rep(i, n) {
        cin >> a[i];
        s ^= a[i];
    }
    rep(i, n) {
        cout << (s^a[i]) << " ";
        
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 4744
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("-Ofast")
#include <bits/stdc++.h>
using namespace std;

typedef int in;
#define int long long
#define pb push_back
#define f first
#define s second
#define double long double
const int MAX=2e5+5;
const int MAX2=2e6+4;
const int MAAX=2e9+5;
const int MOD=1e9+7;
in main()
{
   int n;
   cin>>n;
   cout<<(n+1)/2<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public void output(){
		Scanner scan = new Scanner(System.in);
		int sum = 0;
		for (int i = 0; i < 10; i++){
			int x = scan.nextInt();
			sum += x;
		}
		System.out.println(sum);
	}
	
	public static void main(String[] args){
		Main m = new Main();
		m.output();
	}

}

Measured memory_bytes: 17320
//CODE FESTIVAL 2016 qual A A
#include <bits/stdc++.h>
#include <string>
using namespace std;

int main(){
	char s[17];
	for(int i=0; i<17; i++){
		s[i] = 0;
	}
	scanf("%s", s);
	string str = s;
	str.insert(str.begin()+4 , ' ');
	printf( "%s\n", str.c_str() ); 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k;
    cin>>k;
    queue<long long>q;
    for(long long i=1;i<=9;i++)
    q.push(i);
    while(!q.empty())
    {
        long long int j=q.front();
        q.pop();
        k--;
        if(k==0)
        {
            cout<<j;
            return 0;
        }
        long long int l=j%10;
        if(l==0){
        q.push(j*(long long)10);
        q.push(j*(long long)10+(long long)1);}
        if(l==9){
        q.push(j*(long long)10+(long long)8);
        q.push(j*(long long)10+(long long)9);}
        if(l>0 && l<9)
        {
            q.push(j*(long long)10+l-(long long)1);
            q.push(j*(long long)10+l);
            q.push(j*(long long)10+l+(long long)1);
        }
    }
}

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

using namespace std;

#define int long long
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define INF 1e9
#define LINF 1e18

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;
typedef pair<P, P> PP;

const int MOD = 1e9 + 7;
const int dy[]={0, 0, 1, -1};
const int dx[]={1, -1, 0, 0};

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

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

    int n, y;
    cin >> n >> y;
    rep(i, 2001) rep(j, 4001) {
        if(i * 10000 + j * 5000 + (n - i - j) * 1000 == y && n - i - j >= 0) {
            cout << i << " " << j << " " << n - i - j << endl;
            return 0;
        }
    }
    cout << - 1 << " " << -1 << " " << -1 << endl;
    return 0;
}


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

using namespace std;

int main()
{
    int n,a[1001],i,flag=0;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]%2==0)
        {
            if(a[i]%3&&a[i]%5)
                flag=1;
        }
    }
    if(flag)
        cout<<"DENIED";
    else
        cout<<"APPROVED";
    return 0;
}

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

ht=h[-1]
ans="Yes"
for i in reversed(h):
  if 0 <= i <= ht+1:
    if ht+1 == i:
      ht = i-1
    else:
      ht = i
  else:
    ans="No"
    break
    
print(ans)

Measured memory_bytes: 14252
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#define max(a, b)	(((a) > (b)) ? (a) : (b))		/* ２個の値の最大値 */
#define min(a, b)	(((a) < (b)) ? (a) : (b))		/* ２個の値の最小値 */
#define ENTER		printf("\n")					/* 改行プリント */
/********************************************************************************************************************************/
/* main *************************************************************************************************************************/
/********************************************************************************************************************************/
int DEBUG = 0;										/* デバッグプリント 提出時は0 */

int main()
{
	int		i,j,k,ans=0,n,x;
	int		a[10000] = { 0 };

	while(1) {
		scanf("%d %d", &n, &x);
		if ((n==0)&&(x==0)) break;
		for(i=1;i<=n-2;i++) {
			for(j=i+1;j<=n-1;j++) {
				for(k=j+1;k<=n;k++) {
					if (i+j+k==x) a[ans]++;
				}
			}
		}
		ans++;
	}

	for(n=0;n<ans;n++) {
		printf("%d\n",a[n]);
	}

	return 0;
}



Measured memory_bytes: 2044
#include <stdio.h>

int main()
{
	int n,a,b;
	scanf("%d %d %d",&n,&a,&b);
	int max,min;
	if(a>b){
		max=b;
		min=a-(n-b);
	}else{
		max=a;
		min=b-(n-a);
	}

	if(min<0)min=0;
	printf("%d %d",max,min);
	return 0;
}


Measured memory_bytes: 128
import java.util.*;

class Main{
	public static void main(String[] $){
		System.err.println();
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int[]l=new int[n];
		Arrays.setAll(l,i->s.nextInt());
		Arrays.sort(l);

		int p=0;
		for(int i=0;i<n-2;i++)
			for(int j=i+1;j<n-1;j++)
				for(int k=j+1;k<n;k++)
					if(l[j]<l[k]+l[i]&&l[k]<l[i]+l[j])
						++p;

		System.out.println(p);
	}
}


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

using namespace std;
vector <int> tezine , vrijednosti , rezultati;
const int inf=1000000001;
const int granica=100010;

int main(){
	int N , W , tezina , vrijednost;
	cin>>N>>W;
	rezultati.insert(rezultati.begin(),granica,inf);
	for (int i=0;i<N;i++){
		cin>>tezina>>vrijednost;
		tezine.push_back(tezina);
		vrijednosti.push_back(vrijednost);
	}
	
	int pomVri;
	rezultati[0]=0;
	
	for (int i=0;i<N;i++){
		for (int j=granica-1;j>=0;j--){
			pomVri=vrijednosti[i];
			if (pomVri+j<granica){
				rezultati[j+pomVri]=min(tezine[i]+rezultati[j],rezultati[j+pomVri]);	
			}
		}
	}
				
	for (int i=granica-1;i>=0;i--){
		if (rezultati[i]<=W){
			cout<<i;
			break;
		}
	}
	
	return 0;
}


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

int main() {
  int n, k, s;
  cin >> n >> k >> s;
  vector<int64_t> v(n);
  rep(i, n){
    if(i < k) v[i] = s;
    else if(s < 1000000000) v[i] = s + 1;
    else(v[i] = s - 1);
  }
  rep(i, n){
    cout << v[i];
    if(i != n-1) cout << " ";
    else cout << endl;
  }
}

Measured memory_bytes: 2048
import sys
from collections import defaultdict, deque
import math

# import copy
from bisect import bisect_left, bisect_right
# import heapq

# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

    def update(self):
        for i in range(len(self.par)):
            self.par[i] = self.find(i)

def solve():
    n,m = getList()
    nums = getList()
    uf = UnionFind(n)
    for i in range(m):
        x, y = getList()
        uf.union(x, y)
    uf.update()
    st1 = [[] for i in range(n + 1)]
    st2 = [[] for i in range(n + 1)]
    for i in range(n):
        st1[uf.par[i+1]].append(i+1)
        st2[uf.par[i+1]].append(nums[i])

    ans = 0
    for s1, s2 in zip(st1, st2):
        ans += len(list(set(s1) & set(s2)))



    print(ans)
def main():
    n = getN()
    for _ in range(n):
        solve()


if __name__ == "__main__":
    # main()
    solve()

Measured memory_bytes: 141196
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const int MOD=1e9+7;
const int INF=2e9;
const double PI=acos(-1);


int main() {
    ios_base::sync_with_stdio(false);

    ll x,k,d;
    cin >> x >> k >> d;
    x=(x>0)?x:(-x);
    ll ans;
    if (k>1e16/d) {
        ll i=x%d;
        ll flag=(ll(x/d)%2==k%2);
        if (flag) ans=i;
        else ans=d-i;
    } else if (x>=k*d) ans=x-k*d;
    else {
        ll i=x%d;
        ll flag=(ll(x/d)%2==k%2);
        if (flag) ans=i;
        else ans=d-i;
    }
    cout << ans << endl;
        
    
    return 0;   
}

Measured memory_bytes: 3648
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
using namespace std;
typedef long long int ll;
typedef pair<ll, int> P;

int main()
{
	int n, m;
	cin>>n>>m;
	ll sa[5000];
	sa[0]=0;
	for(int i=1; i<=n-1; i++){
		ll a;
		cin>>a;
		sa[i]=sa[i-1]+a;
	}
	ll sm[5001][5001]={};
	ll b[200][5000];
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			cin>>b[j][i];
		}
	}
	for(int i=0; i<m; i++){
		 P p[5000];
		 for(int j=0; j<n; j++){
			 p[j]=P(b[i][j], j);
		 }
		 sort(p, p+n, greater<P>());
		 set<int> st;
		 st.insert(-1); st.insert(n);
		 for(int j=0; j<n; j++){
			 int j0=p[j].second;
			 auto itr=st.upper_bound(j0);
			 int j2=*itr;
			 itr--;
			 int j1=*itr;
			 sm[j1+1][j0]+=p[j].first;
			 sm[j0+1][j2]+=p[j].first;
			 sm[j0+1][j0]-=p[j].first;
			 sm[j1+1][j2]-=p[j].first;
			 st.insert(j0);
		 }
	}
	for(int i=0; i<=n; i++){
		for(int j=1; j<n; j++){
			sm[i][j]+=sm[i][j-1];
		}
	}
	for(int j=0; j<n; j++){
		for(int i=1; i<n; i++){
			sm[i][j]+=sm[i-1][j];
		}
	}
	ll ans=-1e18;
	for(int i=0; i<n; i++){
		for(int j=i; j<n; j++){
			ans=max(ans, sm[i][j]-(sa[j]-sa[i]));
		}
	}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 203776
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define set_bits(a) __builtin_popcount(a)
#define pb push_back
#define pf push_front
#define mod 1000000007
#define M 998244353
#define fi first
#define se second
#define endl '\n'
#define INF 1e18
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);


int main()
{
     ll n,i;
     cin>>n;
     ll arr[n],a[n];
     for(i=0;i<n;i++)
     {
         cin>>arr[i];
         a[i]= arr[i];
     }
     sort(arr,arr+n);
     ll med = arr[n/2];
     unordered_map<ll,ll>mp;

     for(i=0;i<n;i++)
     {
         if(i<n/2)
         {
             mp[arr[i]] = med;
         }
         else
         {
             mp[arr[i]] = arr[n/2-1];
         }
     }


     for(i=0;i<n;i++)
     {
         cout<<mp[a[i]]<<endl;
     }
}


Measured memory_bytes: 13384
use std::io::*;
use std::str::FromStr;
use std::cmp::min;

fn main() {
    let s: Vec<char> = read::<String>().chars().collect();
    if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2]) || (s[0] == s[2] && s[1] == s[3] && s[0] != s[1]) || (s[0] == s[3] && s[1] == s[2] && s[0] != s[1]) {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;

string s;

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> s;
	cout << "ABC" + s << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const int INF=1e9;
const ll MX = 1e18;
const ll MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
const string tr="abcdefghijklmnopqrstuvwxyz";
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define YN {puts("YES");}else{puts("NO");}
const ll MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {fac[0] = fac[1] = 1;finv[0] = finv[1] = 1;inv[1] = 1;for (ll 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(ll n, ll k){if (n < k) return 0;if (n < 0 || k < 0) return 0;return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;}
ll llpow(ll n,ll i){ll cnt=n;  for(ll j=0;j<i-1;j++){n*=cnt;}return n;}

int main(){
  ll x;
  cin>>x;
  ll ans=0;
  if(x%11==0){
    ans=(x/11)*2;
  }
  if(x%11>0&&x%11<=6){
    ans=(x/11)*2+1;
  }
  if(x%11>=7){
    ans=(x/11)*2+2;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int n;//モンスターの数
int a;//爆発の中心のダメージ
int b;//爆発の中心以外のダメージ
vector<long> h;//h[i]はi番目のモンスターの体力

//爆発魔法ii回で怪獣を殲滅できるか否か
bool enough(int ii) {

	//攻撃回数
	long long an = 0;

	//各モンスターごとに何回追加攻撃が必要か調べ合計を求める
	for (int i = 0; i < n; i++) {
		if (h[i] > b * ii) an += (h[i] - b * ii - 1) / (a - b) + 1;
	}
	return an <= ii;
}

int main() {

	cin >> n >> a >> b;

	h.reserve(n);
	long max = 0;
	for (int i = 0; i < n; i++) {
		cin >> h[i];
		if (max < h[i]) max = h[i];
	}

	//enough(i)=Yesとなる最小のiを二分探索で求める
	int r = 0, l = (max - 1) / b + 1;
	while (r != l) {
		int mid = (r + l) / 2;
		if (enough(mid)) l = mid;
		else r = mid + 1;
	}

	cout << r << endl;

	return 0;
}

Measured memory_bytes: 1024
import sys
read=sys.stdin.readline
class SEGTree:
    def __init__(self,n):
        self.Unit=0
        i=1
        while(i<n):
            i*=2
        self.SEG=[self.Unit]*(2*i-1)
        self.d=i
    def update(self,i,x):
        i+=self.d-1
        self.SEG[i]=1<<x
        while i>0:
            i=(i-1)//2
            self.SEG[i]=self.SEG[i*2+1]|self.SEG[i*2+2]
    def find(self,a,b,k,l,r):
        if r<=a or b<=l:
            return self.Unit
        if a<=l and r<=b:
            return self.SEG[k]
        else:
            c1=self.find(a,b,2*k+1,l,(l+r)//2)
            c2=self.find(a,b,2*k+2,(l+r)//2,r)
            return c1|c2
    def get(self,a,b):
        return self.find(a,b,0,0,self.d)
def bitcnt(x):
    res=0
    while x>0:
        if x&1:
            res+=1
        x//=2
    return res

n=int(input())
s=input()
q=int(input())
seg=SEGTree(n)
for i in range(n):
    seg.update(i,ord(s[i])-97)
for i in range(q):
    q,x,y=read().rstrip().split()
    if q=='1':
        seg.update(int(x)-1,ord(y)-97)
    else:
        x,y=int(x)-1,int(y)
        bit=seg.get(x,y)
        print(bitcnt(bit))

Measured memory_bytes: 92888
#include <bits/stdc++.h>
#include <stdint.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define endl "\n"
#define clr(x) memset(x, 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define int long long
typedef vector<int> vi;
typedef pair<int, int> pii;
const double PI = acos(-1.0);
const int mod = 1e9 + 7;
int pows(int a , int b){int res=1;for(int i=0; i<b; ++i){res*=a;}return res;}
const int N = 1e9+5;
void init() {
  ios_base::sync_with_stdio(false);
  std::cin.tie(NULL);
}

void solve(){
    int n ;
    cin >> n ;
    vector<int> a(n),b(n),c(n) ;
    rep(i,0,n)  cin >> a[i] >> b[i] >> c[i] ;
    int dp[n][3] ;
    dp[0][0] = a[0] ;
    dp[0][1] = b[0] ;
    dp[0][2] = c[0] ;
    rep(i,1,n){
        dp[i][0] = max(dp[i-1][1] , dp[i-1][2]) + a[i] ;
        dp[i][1] = max(dp[i-1][0] , dp[i-1][2]) + b[i] ;
        dp[i][2] = max(dp[i-1][1] , dp[i-1][0]) + c[i] ;
    }
    cout << max(dp[n-1][0] , max(dp[n-1][1] , dp[n-1][2])) << endl ;
}
int32_t main()
{
    init();
    int t=1;
    //cin>>t;
    clock_t launch=clock();

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

    clog<<((long double)(clock()-launch)/CLOCKS_PER_SEC)<<"\n";
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
const ll mod=1000000007;
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)

int main() {
  int h,w,a,b;cin >>h>>w>>a>>b;
  int m[h][w];
  for(int i=0;i<h;++i){
    for(int j=0;j<w;++j){
      if(i<b){
        if(j<a){
          m[i][j] = 1;
        } else {
          m[i][j] = 0;
        }
      } else {
        if(j<a){
          m[i][j] = 0;
        } else {
          m[i][j] = 1;
        }
      }
    }
  }
  for(int i=0;i<h;++i){
    for(int j=0;j<w;++j){
      cout << m[i][j];
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 5120
import sys
a, b, c = map(int, input().split())

if a == b and b == c:
    print(-1 if a % 2 == 0 else 0)
    sys.exit(0)

i = 0
while a % 2 == 0 and b % 2 == 0 and c % 2 == 0:
    a, b, c = (b + c) / 2, (c + a) / 2, (a + b) / 2
    i += 1

print(i)


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

using ll = long long;

#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z)                                                     \
  cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
       << endl
#define check(s) cerr << s << endl

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

const ll LINF = 2e18;
const int INF = 1e9 + 7;

void solve(ll N, ll M, ll K, std::vector<ll> A, std::vector<ll> B) {
  vector<ll> accA(N + 1, INF);
  vector<ll> accB(M + 1, INF);

  ll sum = 0;
  accA.at(0) = 0;
  FOR(i, 1, N + 1) {
    sum += A.at(i - 1);
    if (sum > K) break;
    accA.at(i) = sum;
  }
  sum = 0;
  accB.at(0) = 0;
  FOR(i, 1, M + 1) {
    sum += B.at(i - 1);
    if (sum > K) break;
    accB.at(i) = sum;
  }

  ll mx = 0;

  FOR(i, 0, N + 1) {
    if (accA.at(i) > K) {
      break;
    }
    auto idx = upper_bound(accB.begin(), accB.end(), K - accA.at(i)) -
               accB.begin() - 1;
    if (accB.at(idx) == INF) continue;
    mx = std::max(mx, (ll)i + idx);
  }

  cout << mx << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;
  scanf("%lld", &N);
  ll M;
  scanf("%lld", &M);
  ll K;
  scanf("%lld", &K);
  std::vector<ll> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  std::vector<ll> B(M);
  for (int i = 0; i < M; i++) {
    scanf("%lld", &B[i]);
  }
  solve(N, M, K, std::move(A), std::move(B));
  return 0;
}


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

double cos(double x){
	double c = 0.0;
	double y = 1.0;
	double n = 1;
	for(int i = 1; i < 30; i++){
		c += y / n;
		y = - y * x * x;
		n = 2 * i * (2 * i - 1) * n;
	}
	return c;
}

double sin(double x){
	double s = 0.0;
	double y = x;
	double n = 1;
	for(int i = 1; i < 30; i++){
		s += y / n;
		y = - y * x * x;
		n = 2 * i * (2 * i + 1) * n;
	}
	return s;
}

int main(){
	double x = 0.0, y = 0.0;
	double hosu;
	double angle = 90.0;
	double change;
	char c;
	while(cin >> hosu >> c >> change){
		if(hosu == 0 && change == 0) break;
		x += hosu * cos(angle / 180 * 3.14159);
		y += hosu * sin(angle / 180 * 3.14159);
		angle -= change;
	}
	cout << (int)x << endl;
	cout << (int)y << endl;
	return 0;
}

Measured memory_bytes: 0
import sys

for line in sys.stdin:
  H, W = map(int, line.split())

  if H == 0 and W == 0:
    break

  for i in range(H):
    if i == 0 or i == H-1:
      print( '#' * W )
    else:
      print( '#'+'.'*(W-2)+'#' )

  print("")

Measured memory_bytes: 7592
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,s,f) for(i=s;i<f;i++)
#define print(v) for(auto &z:v) cout<<z<<' ';cout<<'\n'
#define db cout<<"db: "
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define B begin()
#define E end()
#define all(v) v.B,v.E
#define sz(v) (int)((v).size())
#define vi vector<int>
#define vii vector<pair<int,int>>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define clk1 clock_t start_time=clock()
#define clk2 cout<<(clock()-start_time)/(double)CLOCKS_PER_SEC
#define clean(arr) memset(arr,0,sizeof(arr))
#define mod 1000000007
#define mod2 998244353
#define space 200005
//<<fixed << setprecision(9)

vi G[space];


int main()
{
    int n,i,j,t;
    boost;

    cin>>n;
    rep(i,0,n-1)
    {
        int u,v;
        cin>>u>>v;
        G[u].pb(v);
        G[v].pb(u);
    }
    rep(i,1,n+1) sort(all(G[i]));

    ll sum=1;
    ll prev=1;
    for(i=n-1;i>=1;i--)
    {
        ll temp=prev;
        int add=2,last=i;
        for(auto &z:G[i])
        {
            if(z>i)
            {
                add--;
                temp+= (z-last)*(ll)add;
                last=z;
            }
        }
        temp+= (n+1-last)*(ll)(add-1);
        // db<<sum<<'\n';
        sum+=temp;
        prev=temp;    
    }

    cout<<sum;
    return 0;
}

Measured memory_bytes: 14968
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) (a).begin(),(a).end()
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll h,w;cin>>h>>w;
  vector<lvector> A(h,lvector(w,0));rep(i,h)rep(j,w) cin>>A[i][j];
  vector<lvector> ans;
  ll xpos=0,ypos=0,xold=0,yold=0,sign=1;
  for(ll dy=0;dy<h;++dy) {
    ypos=dy;
    if(xold==w-1) {sign=-1;xpos++;}else {sign=1;xpos--;}
    for(ll dx=0;dx<w;++dx) {
      xpos+=sign;
      if(!(xpos==xold&&ypos==yold)&&A[yold][xold]%2==1) {
        A[yold][xold]--;A[ypos][xpos]++;
        ans.emplace_back(lvector{yold+1,xold+1,ypos+1,xpos+1});
      }
      xold=xpos,yold=ypos;
    }
  }
  print(ans.size());
  for(lvector v:ans) {
    rep(i,3) cout<<v[i]<<" ";
    cout<<v[3]<<endl;
  }
  return 0;
}


Measured memory_bytes: 12976
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define krep(i,k,n,m) for(int i=k;i<n;i+=m)
#define erep(i,k,n) for(int i=k;i<n;i++)
#define mod 1000000007;
//最大公約数
int gcd(int s,int b){
    if(b==0)return s;
    return gcd(b,s%b);
}
signed main(){
    int n;
    cin>>n;
    int a[n];
    rep(i,n){
        cin>>a[i];
    }
    int ans=0;
    rep(i,n-1){
        for(int j=i+1;j<n;j++){
            ans+=a[i]*a[j];
        }
    }
    cout<<ans<<endl;
}


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

typedef long long ll;
typedef int64_t i6;
typedef std::vector<std::vector<int64_t> > Graph;

#define rep(i, n) for (int64_t i = 0; i < n; ++i)
#define rep2(i, n) for (int64_t i = 1; i <= n; ++i)
#define ALL(v) (v).begin(), (v).end()
#define Sort(x) sort(ALL(x))
#define Sort_rev(x) Sort(x);reverse(ALL(x))
#define Push_back(p, a, b) (p).push_back( make_pair( (a), (b) ) )

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;  }
template<typename V,typename T> bool find_num(V v, T num) { if ( find(ALL(v), num) == v.end() ) { return false; } return true; }

// π M_PI
// deg = rad*180/M_PI

int main() {
    int64_t n, m;
    cin >> n >> m;
    cout << n*m << endl;
    return 0;
}


Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    String s = sc.next();
    System.out.println(s.charAt(0) + "" + (s.length() - 2) + "" + s.charAt(s.length() - 1));

  }
}

Measured memory_bytes: 38840
#include<stdio.h>
#define MAX 100000
int partition(int *,int, int);

int main(){
  int n,A[MAX];
  int i,j,result;
  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  
  result=partition(A,0,n-1);
  for(j=0;j<n;j++){
    if(j==result)printf("[");
    printf("%d",A[j]);
    if(j==result)printf("]");
    if(j!=n-1)printf(" ");
  }
  printf("\n");
  return 0;
  
}

int partition(int *A,int p,int r){
  int x,i,j,s;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i=i+1;
      s=A[j];
      A[j]=A[i];
      A[i]=s;
    }
  }
  s=A[r];
  A[r]=A[i+1];
  A[i+1]=s;
  return i+1;
}



Measured memory_bytes: 2188
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,k;
  cin>>n>>k;
  vector<int>h(n);
  for(int i=0;i<n;i++)
    cin>>h[i];
  vector<int>res(n);
  res[0]=0;
 // res[1]=abs(h[1]-h[0]);
  for(int i=1;i<=k;i++)
  {
    res[i]=INT_MAX;
    for(int j=0;j<i;j++)
    {
    	res[i]=min(res[i],res[j]+abs(h[i]-h[j]));
    }
  }
   for(int i=k+1;i<n;i++)
   {
     res[i]=INT_MAX;
     for(int j=i-1;j>=i-k;j--)
    	res[i]=min(res[i],res[j]+abs(h[i]-h[j]));
   }
  cout<<res[n-1];
}

Measured memory_bytes: 4032
#include<bits/stdc++.h>
// #include <boost/lexical_cast.hpp>
using namespace std;

#define ll long long int
#define vll vector<ll>
#define vllv vector<vector<ll>> 
#define vpii vector<pair<ll,ll>>
#define pll  pair<ll,ll>
#define sz size()
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll MOD=1000000000+7;
ll ceil1(ll n,ll m){if(n%m==0){return n/m;}return n/m +1;}
ll factor(ll n){
    vll ans;
	if(n==2)ans.pb(2);
	else
    {for(ll i=2;i*i<=n;i++){if(n%i==0 && n%i!=i){ans.pb(i);if(n/i!=i)ans.pb(n/i);}}ans.pb(n);}
    return ans.sz+1;
}
ll fact(ll n){ll res = 1;for (ll i = 2; i <= n; i++)res = res * i; 
    return res; } 
  
ll nCr(ll n, ll r){ return fact(n) / (fact(r) * fact(n - r)); } 
  
void dfs(vllv &v,ll k,vll &par,vll &dis,ll p)
{
    par[k]=p;
    dis[k]=dis[p]+1;
    for(ll i=0;i<v[k].sz;i++){
        if(v[k][i]!=p){
            dfs(v,v[k][i],par,dis,k);
        }
    }
}
bool sortbysec(const pair<string,int> &a,const pair<string,int> &b){return (a.second<b.second);} 

ll pow2(ll n,ll k){ll ans=1;
    while(k>0){
        if(k%2==1)ans=ans*n;n=n*n;k/=2;
    }return ans;}
bool prime(int n){
    int i,j;
    for(i=2;i<=sqrt(n);i++){
        if(n%i==0){
            return false;
        }
    }
    return true;
}

void solve()
{
	
	ll a,b;
	cin>>a>>b;
	if(a+b>=10)
		cout<<"error";
	else
		cout<<a+b;
}            
int main()
{
	fast;
    ll q;
    q=1;
    // cin>>q;
    while(q--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3668
N, M = map(int, input().split())
R = []
L = []
for _ in range(M):
  temp = list(map(int, input().split()))
  L.append(temp[0])
  R.append(temp[1])
minR = min(R)
maxL = max(L)
if minR < maxL:
  print(0)
else:
  print(minR - maxL + 1)

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef int64_t ll;

ll solve(const string& s, const string& t) {
  int ns = s.length();
  int nt = t.length();

  vector<vector<ll>> cnts(26);
  REP(i,ns) {
    cnts[s[i] - 'a'].emplace_back(i);
    cnts[s[i] - 'a'].emplace_back(i + ns);
  }
  REP(i,26) sort(ALL(cnts[i]));

  ll cnt = -1;
  REP(i,nt) {
    if (cnts[t[i] - 'a'].empty()) return -1;
    auto itr = upper_bound(ALL(cnts[t[i] - 'a']), cnt % ns);
    cnt += *itr - cnt % ns;
  }
  return cnt + 1;
}

int main(){
  string s, t;
  cin >> s >> t;
  cout << solve(s, t) << endl;
  return 0;
}



Measured memory_bytes: 2800
#include <iostream>
#include <string>

using namespace std;

int main() {
    string S;
    cin >> S;

    int A = (S[0] - '0') * 10 + (S[1] - '0');
    int B = (S[2] - '0') * 10 + (S[3] - '0');

    if (A <= 12 && B <= 12 && A > 0 && B > 0) cout << "AMBIGUOUS" << std::endl;
    else if (1 <= B && B <= 12) cout << "YYMM" << std::endl;
    else if (1 <= A && A <= 12) cout << "MMYY" << std::endl;
    else cout << "NA" << std::endl;
    return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
ss=set()
s3=set()
penality=0
l=[]
for _ in range(m):
  p,s=input().split()
  p=int(p)
  if s=="AC":
    s3.add(p)
  l.append([p,s])
for i in range(len(l)):
  p=l[i][0]
  s=l[i][1]
  if (p not in ss) and s=="WA" and (p in s3):
    penality+=1
  if s=="AC":
    ss.add(p)
print(len(ss),penality)


Measured memory_bytes: 32912