akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

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;
}

signed main() {
  init();
  ll N;
  cin >> N;
  vll A(N);
  rep(i, N) {
    cin >> A[i];
  }

  ll ans = 0;
  rep(i, N) {
    rep2(j, i + 1, N) {
      ll a = abs(A[i] - A[j]);
      ans = max(ans, a);
    }
  }
  COUT(ans);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
map<int,int>mp;
int main()
{
    int n;
    cin>>n;
    for(int i = 0 ; i<n ; ++i)
    {
        int x;
        scanf("%d" , &x);
        mp[x]++;
        mp[x-1]++;
        mp[x+1]++;
    }
    int maxi = 0;
    for(int i = -1 ; i<=1e5 ; ++i)
        maxi = max(maxi , mp[i]);
    cout<<maxi<<endl;
    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

ll factorial(ll n) {
  ll answer = 1;
  while (n > 1) {
    answer *= n;
    answer %= mod;
    n--;
  }
  return answer;
}

ll combination(ll n, ll r) {
  return factorial(n) / (factorial(r) * factorial(n - r));
}

ll permutation(ll n, ll r) { return factorial(n) / factorial(n - r); }

template <typename T>
void remove(std::vector<T>& vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n] = 1;
  return ret;
}
// for (auto p : prime_factor(n)) {
//	while (p.second--) {
//		cout << p.first << endl;
//	}
//}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

int main() {
  int h, w;
  cin >> h >> w;
  char s[h][w];
  REP(i, h) {
    REP(j, w) { cin >> s[i][j]; }
  }

  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      if (s[i][j] == '#') {
        if (s[i - 1][j] != '#' && s[i][j + 1] != '#' && s[i + 1][j] != '#' &&
            s[i][j - 1] != '#') {
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }

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

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

int main(){

    int N, a[100];
    cin >> N;
    for( int i = 0; i < N; i++ ) cin >> a[i];

    int num[9] = {};
    int type = 0;

    for( int i = 0; i < N; i++ ){
        for( int j = 0; j < 8; j++ ){
            if( 400*j <= a[i] && a[i] < 400*(j+1) ) num[j]++;
        }
        if( 3200 <= a[i] ) num[8]++;
    }

    for( int j = 0; j < 8; j++ ){
        if( num[j] != 0 ) type++;
    }

    if( type == 0 ) cout << 1 << " " << num[8] << endl;
    else cout << type << " " << type + num[8] << endl;

    return 0;
}

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

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

  string a = "Sunny";
  string b = "Cloudy";
  string c = "Rainy";

  if(S == a) {
    cout << b << endl;
  } else if (S == b) {
    cout << c << endl;
  } else {
    cout << a << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long  
#define mod 1000000007
#define am 998244353
#define INFi 2147483647
#define INFl 9223372036854775807LL
#define fi first
#define se second
#define be begin()
#define en end()
int abs(int a,int b){ 
  int c=max(a,b)-min(a,b);
  return c;
}
int gcd(int a,int b){//最大公約数
  int c=a%b;
  while(true){
    if(c==0) break;
    a=b;
    b=c;
    c=a%b;
  }
  return b;
}
bool IsPrime(int num){
  if (num < 2) return false;
  else if (num == 2) return true;
  else if (num % 2 == 0) return false;
  double sqrtNum = sqrt(num);
  for(int i=3;i<=sqrtNum;i+=2){
    if(num%i==0){
      return false;
    }
  }
}
int lcm(int a,int b){//最小公倍数
    return (a*b)/gcd(a,b);
}	    
signed main(){
// __builtin_ctz(N);      Nを２で何回割り切れるかを返す
//(n+1)*n/2;              １からNまでの総和を求める式
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c,d,l=1,p=0;
    vector<pair<int,int> > q;
    cin>>a>>b;
    for(int i=0;i<a;i++){
	cin>>c>>d;
	q.push_back(make_pair(c,d));
    }
    sort(q.be,q.en);
    if(q[0].se>=b) cout<<q[0].fi*b<<"\n";
    else{
	b-=q[0].se;
	p=q[0].fi*q[0].se;
	while(true){
	    if(q[l].se>=b){
		cout<<p+q[l].fi*b<<"\n";
		break;
	    }
	    p+=q[l].fi*q[l].se;
	    b-=q[l].se;
	    l++;
	    
	}
    }
}


Measured memory_bytes: 2420
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
typedef long long ll;

using namespace std;

int main() {
	ll value, n; cin >> value >> n;
	vector<ll> v(n);
	rep(i, n) cin >> v[i];
	ll k = -1;
	ll ans=0;
	while (1) {
		k++;
		ans =value+k;
		vector<ll> v2;
		while (ans > 0) {
			v2.push_back(ans % 10);
			ans /= 10;
		}
		bool flag = true;
		for(auto a:v)
			for (auto b : v2)
				if (a == b) {
					flag = false;
					break;
				}
		if (flag) break;
	}
	cout << value + k << endl;
}

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

using namespace std;

int main (void) {
    int N;
    cin >> N;
    vector<int> a(N+1);
    for ( int i=1; i<=N; i++ )
        cin >> a.at(i);

    int ans = 1;
    int next = a.at(1);
    while ( next != 2 ) {
        if ( next == a.at(next) ) {
            ans = -1;
            break;
        }
        next = a.at(next);
        ans++;
        if ( ans > N ) {
            ans = -1;
            break;
        }
    }

    cout << ans << endl;

    return 0;
}


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

int main(){
    using namespace std;

    unsigned long H1, M1, H2, M2, K;
    cin >> H1 >> M1 >> H2 >> M2 >> K;

    cout << 60 * H2 + M2 - 60 * H1 - M1 - K << endl;

    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vvl = vector<vl>;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define per(i,n) for(int i = (n)-1; i >= 0; --i)
#define rng(i,a,b) for(int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main() {
    ll a, b, x; cin >> x;
    rng(i,-200,200) rng(j,-200,200) {
        a = pow(i,5LL), b = pow(j,5LL);
        if (a - b == x) {
            cout << i << " " << j << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 4060
#include<bits/stdc++.h>
using namespace std;
int main(){
    long int N,A,B;
    cin >> N >> A >> B;
    long int ans=N/(A+B)*A;
    if(N%(A+B)<A){
        ans=ans+N%(A+B);
    }else{
        ans=ans+A;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
list_b = list(map(int,input().split()))
b_len = len(list_b)
ans_list = [0]*n
ans_list[0] = list_b[0]
dum = 0
for i in range(1,b_len):
    dum = min(list_b[i-1],list_b[i])
    ans_list[i] = dum
ans_list[n-1] = list_b[b_len-1]
#print(ans_list)
print(sum(ans_list))


Measured memory_bytes: 38256
import java.text.DecimalFormat;
import java.util.stream.LongStream;
import java.util.stream.IntStream;
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        AtCoder problem = new AtCoder(sc);
        problem.solve(out);

        out.flush();
    }

}

class AtCoder {

    final int D;
    int r, x;

    AtCoder(FastScanner sc) {
        r = sc.nextInt();
        D = sc.nextInt();
        x = sc.nextInt();
    }

    void solve(PrintWriter out) {
        for (int i = 0; i < 10; i++) {
            x = r * x - D;
            out.println(x);
        }
    }

}

// https://qiita.com/p_shiki37/items/a0f6aac33bf60f5f65e4
class FastScanner {

    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte()) {
            return buffer[ptr++];
        } else {
            return -1;
        }
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
            ptr++;
        }
        return hasNextByte();
    }

    public String next() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
            throw new NumberFormatException();
        }
        return (int) nl;
    }

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


Measured memory_bytes: 21460
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
ll gcd(ll a,ll b){ while(b^=a^=b^=a%=b); return a;}
string biggerIsGreater(string s){

	int n,l=-1,i,j,k,r=-3;
	char ch;
	n=s.size();
	r=n-1;
       i=n-2;
       while(i>=0 && s[i]>=s[i+1])i--;
       if(i<0)return s;
        j=n-1;
        while(j>i &&  s[j]<=s[i])j--;
        ch=s[j];s[j]=s[i];s[i]=ch;
        i++;
        j=n-1;
        while(i<j){
        	ch=s[j];s[j]=s[i];
        	s[i]=ch;
        	i++;j--;

        }
        return s;


}
ll bigmod(ll x,ll n,ll m)
{
    ll r=1;
    while(n>0)
    {
        if(n % 2 ==1)
            r=(r * x)%m;
        x=(x*x)%m;
        n=n/2;
    }
    return r;
}



int main(){
ll n;
while(cin>>n){
	ll mod=1000000007;
	ll k=bigmod(10,n,mod);
	ll p=2*bigmod(9,n,mod);
	ll m=bigmod(8,n,mod);
	k=((k%mod)-(p%mod)+mod)%mod;
	k+=(m%mod);
	k%=mod;



cout<<k<<endl;

}


	return 0;
}


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


using namespace std;


int D[102][2];
int N;

int main()
{
	cin>>N;
	for(int i = 1; i <= N; ++i)
	{
		cin>>D[i][0]>>D[i][1];
	}
	for(int i = 1; i <= N - 2; ++i)
	{
		if(D[i][0] == D[i][1] 
			&& D[i+1][0] == D[i+1][1]
			&& D[i+2][0] == D[i+2][1])
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
}


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

using namespace std;

const int N = 2e5 + 5;

int n, q, st[N], en[N], cnt = 0;
vector <int> g[N];
long long f[N];

void dfs (int u, int p) {
    st[u] = ++cnt;
    for (auto v: g[u]) {
        if (v == p) continue;
        dfs(v, u);
    }

    en[u] = cnt;
}

int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> q;
    for (int i = 1; i <= n - 1; i++) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    dfs(1, 1);
    while (q--) {
        int p, x;
        cin >> p >> x;
        f[st[p]] += x;
        f[en[p] + 1] -= x;
    }

    for (int i = 1; i < N; i++) f[i] += f[i - 1];
    for (int i = 1; i <= n; i++) cout << f[st[i]] << " ";
    return 0;
}


Measured memory_bytes: 25856
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include <sstream>
#include<iomanip>
#include <ctype.h>
using namespace std;

//#include<bits/stdc++.h>


int main() {
	int a, b;
	cin >> a >> b;
	int c = pow(100, a);
	if (b == 100)b++;
	cout << c*b << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
using namespace std ;
char s[100010] ;
char t[100010] ;
long long sum = 0 ; 
vector<int>c[30] ;
int main () {
	scanf("%s %s",s,t) ;
	int n = strlen(s) ;
	int m = strlen(t) ;
	for(int i = 0 ; i < n ; i ++) {
		c[s[i]-'a'].push_back(i+1) ;
	}
	int x = t[0] - 'a' , j ;
	if(!c[x].size()) {
		puts("-1") ;
		return 0 ;
	}
	int k = c[x][0] ;
	sum += k ;
	for(int i = 1 ; i < m ; i ++) {
		x = t[i] - 'a' ;
		if(!c[x].size()) {
			puts("-1") ;
			return 0 ;
		}
		j = upper_bound(c[x].begin() ,c[x].end(),k) - c[x].begin() ;
		if(j == c[x].end()-c[x].begin() ) {
			sum += c[x][0] + n - k ;
			k = c[x][0] ;
		}else {
			sum += c[x][j] - k ;
			k = c[x][j] ;
		}
	}
	cout << sum << endl ;
	return 0 ;
}

Measured memory_bytes: 1024
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
template<class Read>void in(Read &x){
    x=0;
    int f=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        f|=(ch=='-');
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    x=f?-x:x;
    return;
}
struct Node{
    int to;
    int next;
}a[100005];
int n,m,top,ans,head[100005],ru[100005],b[100005],f[100005];
queue<int>q;
void add(int x,int y){
    a[++top].to=y;
    a[top].next=head[x];
    head[x]=top;
}
int main(){
    in(n);in(m);
    for(int i=1;i<=m;i++){
        int x,y;
        in(x);in(y);
        add(x,y);
        ru[y]++;
    }
    for(int i=1;i<=n;i++)if(ru[i]==0)q.push(i),b[++b[0]]=i;
    while(!q.empty()){
        int x=q.front();
        q.pop();
        for(int i=head[x];i;i=a[i].next){
            int y=a[i].to;
            ru[y]--;
            if(ru[y]==0)q.push(y),b[++b[0]]=y;
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=head[b[i]];j;j=a[j].next){
            int k=a[j].to;
            f[k]=max(f[k],f[b[i]]+1);
        }
    }
    for(int i=1;i<=n;i++)ans=max(ans,f[i]);
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 2816
from collections import deque

n = int(input())
ab = [(0, 0) for _ in range(n)]

for i in range(n):
    ab[i] = tuple(map(int, input().split()))
    
def mergesort(ab, l, r):
    if r - l == 1:
        return [ab[l]]
    m = (l + r) // 2
    ab1 = mergesort(ab, l, m)
    ab2 = mergesort(ab, m, r)
    res = []
    i1, i2 = 0, 0
    while i1 < len(ab1) or i2 < len(ab2):
        if i1 == len(ab1):
            res.append(ab2[i2])
            i2 += 1
        elif i2 == len(ab2):
            res.append(ab1[i1])
            i1 += 1
        else:
            if ab1[i1][1] <= ab2[i2][1]:
                res.append(ab1[i1])
                i1 += 1
            else:
                res.append(ab2[i2])
                i2 += 1
    return res
    
sorted_ab = mergesort(ab, 0, n)

now = 0
flag = True
for task in sorted_ab:
    now += task[0]
    if now > task[1]:
        print('No')
        flag = False
        break

if flag:
    print('Yes')


Measured memory_bytes: 108748
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)

















int main(){
    ll n;
    string s;
    cin >> n >> s;
    ll mn = 0, cnt = 0;
    REP(i, n){
        if(s[i] == '(') cnt++;
        else{
            cnt--;
            mn = min(mn, cnt);
        }
    }
    REP(i, -mn){
        s = '(' + s;
    }
    cnt = 0;
    REP(i, s.size()){
        if(s[i] == '(') cnt++;
        else cnt--;
    }
    REP(i, cnt){
        s += ')';
    }
    cout << s << endl;
}

Measured memory_bytes: 256
N,H,W = map(int,input().split())
A = []
B = []
for i in range(N):
	a,b = map(int,input().split())
	A.append(a)
	B.append(b)
cnt = 0
for i in range(N):
	if A[i] >= H and B[i] >= W:
		cnt+=1
print(cnt)

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N, W;
int A[10000];
int dp0[10001][201];
int dp1[10001][201];

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N >> W;
  rep(i, N) cin >> A[i];
  sort(A, A+N);

  dp0[0][0] = 1;
  rep(i, N) {
    rep(w, W+1) {
      rep(k, N+1) dp1[w][k] = 0;
    }
    // k>0
    for (int k=1; k<=i; k++) {
      for (int w=W; w>=A[i]; w--) {
        dp1[w][k] += dp0[w-A[i]][k];
        if (dp1[w][k] >= MOD) dp1[w][k] -= MOD;
      }
      rep(w, W+1) {
        dp1[w][k] += dp0[w][k];
        if (dp1[w][k] >= MOD) dp1[w][k] -= MOD;
      }
    }
    // k=0
    rep(w, W+1) {
      dp1[w][i+1] += dp0[w][0];
      dp1[w][i+1] %= MOD;
      if (dp1[w][i+1] >= MOD) dp1[w][i+1] -= MOD;
    }
    for (int w=W; w>=A[i]; w--) {
      dp1[w][0] += dp0[w-A[i]][0];
      dp1[w][0] %= MOD;
      if (dp1[w][0] >= MOD) dp1[w][0] -= MOD;
    }
    rep(w, W+1) swap(dp0[w], dp1[w]);
  }
  int s = 0;
  rep(k, N+1) {
    rep(w, W+1) {
      if (dp0[w][k] == 0 || (k>0&&w+A[k-1]<=W)) continue;
      s += dp0[w][k];
      if (s >= MOD) s -= MOD;
    }
  }
  cout << s << "\n";
  return 0;
}

Measured memory_bytes: 18828
//c++ -std=gnu++14 a.cpp
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <climits>
#include <fstream>
#include <random>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define revrep(i, n) for(int i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);
#define sz(x) ((int)(x).size())

//const ll INFL = LLONG_MAX;//10^18 = 2^60
const ll INFL = 1LL<<60;
//const int INF = INT_MAX;
const int INF = 1 << 30;//10^9
const ll MOD = 1000000007;
//const ll MOD = 998244353;
double EPS = 1e-10;

vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};

void pres(double A){printf("%.9lf\n", A);}
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}
ll cnt_bit(ll x){return __builtin_popcountll(x);}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x; k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

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

ll lcm(ll x, ll y){
  ll res = x / gcd(x, y);
  res *= y;
  return res;
};


//コンビネーション
const int MAXcomb = 2000010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; 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;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}

const int MAXkai = 500010;
ll kai_memo[MAXkai];
ll kai(ll N){
  if(kai_memo[N] != 0) return kai_memo[N];
  if(N <= 1) return 1;
  return kai_memo[N] = N * kai(N-1) % MOD;
}

ll disit(ll s, ll base = 10){
  ll res = 0;
  while(s){
    res++;
    s /= base;
  }
  return res;
}


void solve(){
  ll N;
  cin >> N;
  ll ans = 0;
  for(ll i = 1; i <= N; i++){
    ans += N * (N+1) / 2 - (i-1) * i / 2 - (N-i) * (N-i+1) / 2;
  }
  rep(i, N-1){
    int a, b;
    cin >> a >> b;
    if(a > b) swap(a, b);
    ans -= a * (N - b + 1);
  }
  cout << ans << endl;
}


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


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pf push_front
#define mod 1000000007
#define endl '\n'
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);


int main()
{
    ll arr[3][3],ans[3][3],i,j;
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            cin>>arr[i][j];
            ans[i][j]=0;
        }
    }


    ll n;
    cin>>n;
    while(n--)
    {
        ll a;
        cin>>a;
        for(i=0;i<3;i++)
        {
            for(j=0;j<3;j++)
            {
                if(arr[i][j]==a)
                {
                    ans[i][j]=1;
                }
            }
        }
    }

    ll flag=0,sum=0;

    for(i=0;i<3;i++)
    {
        sum=0;
        for(j=0;j<3;j++)
        {
            sum+=ans[i][j];
        }
        if(sum==3)
        {
            flag=1;
            break;
        }
    }


    for(i=0;i<3;i++)
    {
        sum=0;
        for(j=0;j<3;j++)
        {
            sum+=ans[j][i];
        }
        if(sum==3)
        {
            flag=1;
            break;
        }
    }

    sum=0;
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            if(i==j)
            {
                sum+=ans[i][j];
            }
        }
    }
    if(sum==3)
    {
        flag=1;
    }

    if(ans[0][2]+ans[1][1]+ans[2][0]==3)
    {
        flag=1;
    }

    if(flag)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
ll In(string s){
    if(s=="Vacant")
        return -1;
    else if(s=="Male")
        return 0;
    else
        return 1;
}

int main() {
    init();
    ll N;
    cin >> N;
    cout << 0 << endl
         << flush;
    string s;
    cin >> s;
    ll p = In(s);
    if (p == -1) return 0;

    ll l = 0, r = N;
    rep(i,19){
        ll m = (l + r) / 2;
        cout << m << endl
             << flush;
        cin >> s;
        ll st = In(s);
        if (st == -1) return 0;
        
        //右回りの偶奇の距離で×を含む方をチェック
        if((m%2==0 and st!=p) or (m%2==1 and st==p)){
            r = m;
        }
        else{
            l = m;
        }
    }
}

Measured memory_bytes: 852
#include <bits/stdc++.h>
#define int long long
//#define double long double
#define endre getchar();getchar();return 0
#define moder (int)(1e9+7)
#define inf (int)(5*1e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int kai(int x) {
	if (x == 0)return 1;
	return (kai(x - 1)*x) % moder;
}
int comb(int x, int y) {
	return kai(x)*mod_pow(kai(x - y), moder - 2, moder) % moder*mod_pow(kai(y), moder - 2, moder) % moder;
}
struct edge { int from, to, cost; };
int dx[5] = { 0,1,0,-1 }, dy[5] = { 1,0,-1,0 };
map<int, int>factor(int x) {
	map<int, int>res;
	for (int i = 2; i*i <= x; i++) {
		while (x%i == 0) {
			x /= i;
			res[i]++;
		}
	}
	if (x != 1)res[x]++;
	return res;
}
/*--------Library Zone!--------*/

int n;
string s;
signed main() {
	cin >> n >> s;
	rep(i, 4) {
		char c[114514];
		if (i & 1)c[0] = 'W';
		else c[0] = 'S';
		if (i & 2)c[1] = 'W';
		else c[1] = 'S';
		for (int j = 1; j < n - 1; j++) {
			if ((c[j] == 'S'&&s[j] == 'o'&&c[j - 1] == 'S') || (c[j] == 'S'&&s[j] == 'x'&&c[j - 1] == 'W') || (c[j] == 'W'&&s[j] == 'o'&&c[j - 1] == 'W') || (c[j] == 'W'&&s[j] == 'x'&&c[j - 1] == 'S')) {
				c[j + 1] = 'S';
			}
			else {
				c[j + 1] = 'W';
			}
		}
		if ((c[n - 1] == 'S'&&s[n - 1] == 'o'&&c[n - 2] == c[0]) || (c[n - 1] == 'S'&&s[n - 1] == 'x'&&c[n - 2] != c[0]) || (c[n - 1] == 'W'&&s[n - 1] == 'o'&&c[n - 2] != c[0]) || (c[n - 1] == 'W'&&s[n - 1] == 'x'&&c[n - 2] == c[0])) {
			if ((c[0] == 'S'&&s[0] == 'o'&&c[1] == c[n - 1]) || (c[0] == 'S'&&s[0] == 'x'&&c[1] != c[n - 1]) || (c[0] == 'W'&&s[0] == 'o'&&c[1] != c[n - 1]) || (c[0] == 'W'&&s[0] == 'x'&&c[1] == c[n - 1])) {
				rep(j, n)cout << c[j];
				cout << endl;
				endre;
			}
		}
	}
	cout << -1 << endl;
	endre;
}


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

using namespace std;
typedef long long ll;

int main() {
  ll N; cin >> N;
  ll K; cin >> K;
  vector<ll> h(N);
  for (ll j=0; j < N; ++j) cin >> h[j];
  sort(h.begin(), h.end());
  ll ans = 0;
  for (ll j=0; j < N; ++j) {
    if (h[j] >= K) ans++;
  }
  cout << ans << endl;
  return 0;
}


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

namespace you {
    string to_string(char val) {
        return string(1,val);
    }
}


int main(void) {
    int a,b,count=0;
    cin>>a>>b;
    std::vector<std::vector<string>> vec(a+2,vector<string>(b+2));
    char c;
    for (int i=0;i<a+2;i++) {
        for (int j=0;j<b+2;j++) {
            if (i==0||j==0||i==a+1||j==b+1) {
                vec.at(i).at(j)="0";
            } else {
                cin>>c;
                auto s = you::to_string(c);
                vec.at(i).at(j)=s;
            }
        }
    }
    for (int k=1;k<a+1;k++) {
        for (int l=1;l<b+1;l++) {
            if (vec.at(k).at(l)==".") {
                if (vec.at(k-1).at(l-1)=="#") {
                    count++;
                }
                if (vec.at(k-1).at(l)=="#") {
                    count++;
                }
                if (vec.at(k-1).at(l+1)=="#") {
                    count++;
                }
                if (vec.at(k).at(l-1)=="#") {
                    count++;
                }
                if (vec.at(k).at(l+1)=="#") {
                    count++;
                } 
                if (vec.at(k+1).at(l-1)=="#") {
                    count++;
                }
                if (vec.at(k+1).at(l)=="#") {
                    count++;
                }
                if (vec.at(k+1).at(l+1)=="#") {
                    count++;
                }
                string str = to_string(count);
                vec.at(k).at(l)=str;
                count=0;
            }
        }
    }
    for (int hoge=1;hoge<a+1;hoge++) {
        for (int piyo=1;piyo<b+1;piyo++) {
            cout<<vec.at(hoge).at(piyo);
        }
        cout<<endl;
    }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  string s,t;cin>>s>>t;
  string res;

  int p = -1;
  for(int i=0;i<s.size();i++){
    if(t.size()+i>s.size())break;
    bool ok=true;
    for(int j=0;j<t.size();j++){
      if(s[i+j]=='?'||s[i+j]==t[j]){
      }else{ok=false;}
    }
    if(ok){
      p=i;
    }
  }
  if(p==-1){
    cout<<"UNRESTORABLE"<<endl;
  }else {
    for(int i=0;i<s.size();i++){
      if(i==p){
        cout<<t;
        i+=t.size()-1;
      }else if(s[i]=='?') {
        cout<<'a';
      }else{
        cout<<s[i];
      }
    }
    cout<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <sstream>


using namespace std;


using ll = long long;


int main()
{
    stack<int> s;
    ll ch;
    string line, tok;

    getline(cin, line);
    istringstream iss(line);

    while (iss >> tok) {
        ll x, y;
        if (tok == "+") {
            x = s.top(); s.pop();
            y = s.top(); s.pop();
            s.push(x + y);
        } else if (tok == "-") {
            x = s.top(); s.pop();
            y = s.top(); s.pop();
            s.push(y - x);
        } else if (tok == "*") {
            x = s.top(); s.pop();
            y = s.top(); s.pop();
            s.push(x * y);
        } else {
            ch = stoll(tok);
            s.push(stoll(tok));
        }
    }
    cout << s.top() << endl;
}



Measured memory_bytes: 3216
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  int ans=0;
  cin >>a>>b;
  if(b < a){
    ans = a-1;
  }else if(a!=1){
    ans = a;
  }else if(a == 1 && b == 1){
    ans = 1;
  }
  cout <<ans<<endl;
  
  
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	string a, b;
	int answer = 1000;

	cin >> a;
	cin >> b;

	int size_a = a.size();
	int size_b = b.size();

	for (int i = 0; i < size_a - size_b + 1; i++) {
		int current_candidate = 0;

		for (int j = i; j < i + size_b; j++){
			if (a[j] != b[j - i]) {
			   	current_candidate++;
			}
		}
		if (current_candidate < answer) answer = current_candidate;

	}

	cout << answer << endl;
}


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

#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define MOD 1000000007

int main(){
	#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
	string a,b;
	cin>>a>>b;
	ll N=a.size(),M=b.size();
	ll ans=M;
	for(ll i=0;i<=N-M;i++){
		ll temp=0;
		for(ll j=i;j<i+M;j++){
			if(a[j]!=b[j-i])
				temp++;
		}
		ans=min(ans,temp);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3624
#include <stdio.h>

int main(void) {
	int n, x;
	int i, j;
	int count = 0;

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf("%d", &x);
		//偶奇判定
		if (x % 2 != 0 && x > 2) {
			//素数判定
			for (j = 3; j <= x; j += 2) {
				if (j == x || j * j > x) {
					count++;
					break;
				}
				if (x % j == 0) {
					break;
				}
			}
		}
		else if (x == 2) {
			count++;
		}
	}
	printf("%d\n", count);

	return 0;
}



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

int main(){
	while(true) {
		int m, f, r;
		scanf("%d%d%d", &m, &f, &r);
		int s = m + f;
		if(m == -1 && f == -1  && r == -1) break;
		if(m == -1 || f == -1)
			printf("F\n");
		else if(s >= 80)
			printf("A\n");
		else if(s >= 65)
			printf("B\n");
		else if(s >= 50)
			printf("C\n");
		else if(s >= 30) {
			if(r >= 50)
				printf("C\n");
			else
				printf("D\n");
		}else
			printf("F\n");
	}
}



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

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	string s;	cin>>s;
	int count=0;
	for(int i=0;i<s.length();i++){
		if(s[i]=='2')	count++;
	}
	cout<<count<<"\n";
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
struct UnionFind{
    vector<int> data;

    UnionFind(int sz){
        data.assign(sz, -1);
    }

    bool unite(int x, int y){
        x = find(x), y = find(y);
        if(x == y) return(false);
        if(data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return(true);
    }

    int find(int k){
        if(data[k] < 0) return(k);
        return(data[k] = find(data[k]));
    }

    int size(int k){
        return(-data[find(k)]);
    }
};
int main(){
    int N,M;
    while(cin>>N>>M,N)
    {
        vector<int>h(N);
        vector<pair<int,int> >hh(N);
        for(int i=0;i<N;i++)
        {
            cin>>h[i];
            hh[i]=make_pair(h[i],i);
        }
        sort(hh.begin(),hh.end());
        reverse(hh.begin(),hh.end());
        vector<pair<pair<int,int>,pair<int,int> > >E;
        for(int i=0;i<M;i++)
        {
            int a,b,c;cin>>a>>b>>c;
            a--,b--;
            E.push_back(make_pair(make_pair(min(h[a],h[b]),-c),make_pair(a,b)));
        }
        sort(E.begin(),E.end());
        reverse(E.begin(),E.end());
        UnionFind uf(N);
        int id=0,H=0;
        for(int i=0;i<N;i++)
        {
            int nowh=hh[i].first;
            while(id<M&&E[id].first.first>=nowh)
            {
                uf.unite(E[id].second.first,E[id].second.second);
                id++;
            }
            if(uf.size(hh[i].second)<=i)
            {
                H=i;
            }
        }
        if(H==N-1)
        {
            cout<<0<<endl;
            continue;
        }
        H=hh[H+1].first;
        vector<pair<pair<int,int>,pair<int,int> > >F;
        for(pair<pair<int,int>,pair<int,int> >p:E)
        {
            F.push_back(make_pair(make_pair(min(H,p.first.first),p.first.second),p.second));
        }
        sort(F.begin(),F.end());
        reverse(F.begin(),F.end());
        long long ans=0;
        UnionFind P(N);
        for(pair<pair<int,int>,pair<int,int> >p:F)
        {
            if(P.unite(p.second.first,p.second.second))
            {
                ans-=p.first.second;
            }
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 4156
from bisect import bisect,bisect_left,insort
dic = {}
l = []
for i in range(int(input())):
    order = list(input().split())

    if order[0] == "0":
        if not order[1] in dic:
            dic[order[1]] = []
            insort(l,order[1])
        dic[order[1]].append(int(order[2]))
    elif order[0] == "1":
        if order[1] in dic:
            for i in dic[order[1]]:
                print(i)
    elif order[0] == "2":
        if order[1] in dic:
            dic[order[1]] = []

    elif order[0] == "3":
        L = bisect_left(l,order[1])
        R = bisect(l,order[2])
        for i in range(L,R):
            for j in dic[l[i]]:
                print(l[i],j)


Measured memory_bytes: 39204
<?php
fscanf(STDIN,"%d %d",$N,$X);
$L = trim(fgets(STDIN));
$L = explode(' ',$L);
// echo $L[0];
$bounces = 1;
$Coordinate = 0;
for($i=0;$i<$N;$i++){
$Coordinate = $Coordinate + $L[$i];
if ($Coordinate <= $X) {
    $bounces++;
}
}
// echo $L[1];
echo $bounces;
?>


Measured memory_bytes: 4856
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

const int MAX_V = 2e3;
vector<int> es[MAX_V];
int d[MAX_V][MAX_V];

void dfs(int root, int now, int pre){
    if(now == root) d[root][now] = 0;
    else d[root][now] = d[root][pre]+1;
    for(auto &e: es[now]){
        if(e != pre) dfs(root, e, now);
    }
}

int main(){
    int N, K;
    cin >> N >> K;
    rep(i, N-1){
        int u, v; cin >> u >> v; u--, v--;
        es[u].pb(v), es[v].pb(u);
    }
    rep(i, N) dfs(i, i, -1);
    int ans = N;
    if(K%2 == 0){
        rep(i, N){
            int tmp = 0;
            rep(j, N){
                if(d[i][j] > K/2) tmp++;
            }
            chmin(ans, tmp);
        }
    }
    else{
        rep(i, N){
            for(auto &e: es[i]){
                int tmp = 0;
                rep(j, N){
                    if(d[i][j] > K/2 && d[e][j] > K/2) tmp++;
                }
                chmin(ans, tmp);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 19380
import sys
input = sys.stdin.readline

import numpy as np

N = int(input())
A = np.array(input().split(), dtype=np.int64)

def test(T):
    # T回操作をやるとして上手くいくか
    # ひとつひとつの数は、何もしないとa + T になってしまう
    # 1回やるとそこから N+1 減る。最低回数が分かる。
    # (a + T - N + 1) / (N+1) の切り上げ
    # (a + T + 1) // (N+1)
    x = np.maximum(0, (A + T + 1) // (N + 1))
    return x.sum() <= T

# とりあえずひとつ見つける
left = -1
right = 10 ** 18
while right > left + 1:
    mid = (left + right) // 2
    if test(mid):
        right = mid
    else:
        left = mid

for x in range(max(0, right - 5000), right + 1):
    if test(x):
        answer = x
        break

print(answer)

Measured memory_bytes: 12424
#!/usr/bin/env python3
import math
a, b, x = map(int, input().split())
V = a*a*b

if V/2 >= x: # 三角形
    c = 2 * x / a / b
    print(math.degrees(math.atan2(b,c)))
else: # 台形
    c = 2 * (V-x) / a / a
    print(math.degrees(math.atan2(c,a)))


Measured memory_bytes: 2940
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
ll mod = 1000000007;
ll mod9 = 1000000009;

signed main(){
    ll n;
    cin>>n;
    string s;
    ll sm=0;
    rep(i,n){
        if((i+1)%15 == 0) s = "FizzBuzz";
        else if((i+1)%3 == 0) s = "Fizz";
        else if((i+1)%5 == 0) s = "Buzz";
        else sm += (i+1);
    }
    cout<<sm<<endl;
}


Measured memory_bytes: 3628
class UnionFind():
    def __init__(self, N):
        self.par = [i for i in range(N)]
        self.rank = [0 for _ in range(N)]
        self.size = [1 for _ in range(N)]

    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 x != y:
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            elif self.rank[x] < self.rank[y]:
                x, y = y, x
            self.par[y] = x
            self.size[x] += self.size[y]

    def is_same(self, x, y):
        return self.find(x) == self.find(y)
    
    def get_size(self, x):
        x = self.find(x)
        return self.size[x]

n, m = map(int, input().split())
uf = UnionFind(n)
for i in range(m):
    x, y, z = map(int, input().split())
    x, y = x-1, y-1
    uf.union(x, y)

s = set()
for i in range(n):
    parent = uf.find(i)
    s.add(parent)
print(len(s))

Measured memory_bytes: 80288
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll D, T, S;
  cin>>D>>T>>S;
  if(S*T>=D) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}



Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>
#define NIL -1

typedef struct node{
  int left;
  int right;
  int parent;}node;

int getSibling(int);
int getDegree(int);
int getDepth(int);
int getHeight(int);
void printTree(void);

node *tree;
int n;

int main(){
  int i,id,left,right;

  scanf("%d",&n);

  tree = (node *)malloc(sizeof(node)*n);
  for(i=0;i<n;i++){
    tree[i].parent = NIL;
  }
  for(i=0;i<n;i++){
    scanf("%d %d %d",&id,&left,&right);
    tree[id].left = left;
    tree[id].right = right;
    tree[tree[id].left].parent = id;
    tree[tree[id].right].parent = id;
  }

  printTree();

  return 0;
}




int getSibling(int c){
  int left,right;
  if(tree[c].parent!=-1){
    left = tree[tree[c].parent].left;
    right = tree[tree[c].parent].right;

    if(left!=-1&&c!=left) return left;
    else if(right!=-1&&c!=right) return right;
  }
  return -1;
}

int getDegree(int c){
  int d=0;
  if(tree[c].left!=-1) d++;
  if(tree[c].right!=-1) d++;

  return d;
}

int getDepth(int c){
  int d=0;
  while(tree[c].parent!=-1){
    c=tree[c].parent;
    d++;
  }
  return d;
}

int getHeight(int c){
  int d=0;
  if(tree[c].left==-1&&tree[c].right==-1) return 0;
  if(tree[c].left==-1) return getHeight(tree[c].right)+1;
  if(tree[c].right==-1) return getHeight(tree[c].left)+1;
  if(getHeight(tree[c].left)<getHeight(tree[c].right))
    return getHeight(tree[c].right)+1;
  else return getHeight(tree[c].left)+1;
  return d;
}





void printTree(){
  int i,dep,h;
  for(i=0;i<n;i++){
    dep=getDepth(i);
    h=getHeight(i);
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",i,tree[i].parent,getSibling(i),getDegree(i),dep,h);
    if(dep==0) printf("root\n");
    else if(h==0) printf("leaf\n");
    else printf("internal node\n");
  }

  return;
}


Measured memory_bytes: 2104
package main

import (
		"fmt"
)

func main() {
		var a, b int
		fmt.Scan(&a, &b)

		sum := a + b

		if sum == 3 {
				fmt.Println(3)
				return
		}

		if sum == 4 {
				fmt.Println(2)
				return
		}

		fmt.Println(1)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
char str[100][101];
int movex[4]={1,0,-1,0},movey[4]={0,1,0,-1},h,w;
void serch(int x,int y,char a)
{
    str[y][x]='0';
    for(int i=0;i<4;i++){
        int mx=x+movex[i],my=y+movey[i];
        if(a==str[my][mx]&&my>-1&&mx>-1&&my<h&&mx<w)serch(mx,my,a);
    }
}
int main()
{
    while(cin>>h>>w,h){
        for(int i=0;i<h;i++)cin>>str[i];
        int sum=0;
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if(str[i][j]!='0'){
                    serch(j,i,str[i][j]);
                    sum++;
                }
            }
        }
        cout<<sum<<endl;
    }
}

Measured memory_bytes: 1636
MOD = 1000000007

def m():
    N = int(input())
    if N == 1:
        return 3
    s = str(input())
    s2 = str(input())
    a = []
    past = s[0]
    point = 0
    while point<len(s):
        if point == N-1:
            a.append('x')
            point+=1
        elif s[point] == s[point+1]:
            a.append('y')
            point+=2
        else:
            a.append('x')
            point+=1

    ans = 0
    if a[0] == 'x':
        ans = 3
    else:
        ans = 6

    for j in range(1, len(a)):
        if a[j-1] == 'x' and a[j] == 'x':
            ans *=2 % MOD
        elif a[j-1] == 'y' and a[j] == 'x':
            ans *=1 % MOD
        elif a[j-1] == 'x' and a[j] == 'y':
            ans *=2 % MOD
        elif a[j-1] == 'y' and a[j] == 'y':
            ans *=3 % MOD

    return ans % MOD

print(m())

Measured memory_bytes: 3064