akhauriyash/Code-Regression huggingface dataset:
/*----------------by syr----------------*/
/*
  -----  -----  -----
  |   |  |---|    _/
  |   |  | \_    /
  -----  |   \  -----

  |---\  \   /  |\  /|
  |   |   \_/   | \/ |
  |   |   / \   |    |
  |---/  /   \  |    |
*/
#include<bits/stdc++.h>

using namespace std;

#define PH push
#define MP make_pair
#define PB push_back
#define fst first
#define snd second
#define FOR(i,x,y) for(int i=(x);i<(y);++i)
#define REP(i,x,y) for(int i=(x);i<=(y);++i)
#define x0 x0123456789
#define y0 y0123456789
#define x1 x1234567890
#define y1 y1234567890
#define x2 x2345678901
#define y2 y2345678901
typedef double db;
typedef long long ll;
typedef long double ldb;
typedef pair<int,int> pii;

const int INF=1e9+7;
const int maxn=3e3+5;

int n;
int sum[maxn];
int dp[maxn][maxn];
char s[maxn];

int main(){
	scanf("%d",&n);
	scanf("%s",s);
	dp[0][0]=1;sum[0]=1;
	FOR(i,1,n){
		REP(j,0,i){
			if(s[i-1]=='>') dp[i][j]=(sum[i-1]-(j?sum[j-1]:0)+INF)%INF;
			if(s[i-1]=='<'&&j) dp[i][j]=sum[j-1];
		}
		sum[0]=dp[i][0];
		REP(j,1,i) sum[j]=(sum[j-1]+dp[i][j])%INF;
	}
/*	FOR(i,0,n){
		FOR(j,0,n) printf("%d ",dp[i][j]);
		puts("");
	}
*/	printf("%d\n",sum[n-1]);
	return 0;
}

Measured memory_bytes: 34176
#include <iostream>

int main() {
    char x, y;
    std::cin >> x >> y;

    if(x > y) {
        std::cout << '>' << std::endl;
    } else if(x < y) {
        std::cout << '<' << std::endl;
    } else {
        std::cout << '=' << std::endl;
    }
}

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

int main () {
    vector<char> word;
    int n;
    cin >> n;
    for (int i=0;i<n;i++){
        char letter;
        cin >> letter;
        word.push_back(letter);
    }

    bool isEqual = true;
    if (n%2!=0){
        isEqual=false;
    } else {
        int h= n/2;
        for (int i=0; i<h; i++){
            if (word[i] != word[i+h]){
                isEqual = false;
                break;
            }
        }
    }

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

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>
#include<stack>
#include<iomanip>
#include<cstdint>
#include<bits/stdc++.h>
using namespace std;

#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPL(i,a,n) for(ll i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define SORTVG(v) sort(v.begin(),v.end(),greater<>())
#define SORTV(v) sort(v.begin(),v.end())
#define ALL(v) (v).begin(),(v).end()
//#define MOD 1000000007
#define MOD 998244353
#define INF LLONG_MAX/2
#define int long long

typedef long long ll;
typedef tuple<int,int,bool> Tb;
typedef pair<int,int> Pii;
typedef vector<int> Vi;

template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}
template<class T> void YesNo(T& a) {if(a){cout << "Yes" << ENT;}else{cout << "No" << ENT;}}
template<class T> void YESNO(T& a) {if(a){cout << "YES" << ENT;}else{cout << "NO" << ENT;}}
template<class T> void AorB(T& a, string A,string B) {if(a){cout << A << ENT;}else{cout << B << ENT;}}

int atcoder(){
    int a,b,c,d,n;
    cin>>a>>b>>c>>d>>n;
    int ans = n/2 * min({8*a,4*b,2*c,d});
    if(n%2==1) ans += min({4*a,2*b,c});
    cout<<ans<<ENT;
    return 0;
}


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


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int W,H,x,y,r;
	cin>>W>>H>>x>>y>>r;
	if(x+r<=W&&y+r<=H&&x-r>=0&&y-r>=0){
	cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3100
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;

namespace AOJ
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long cnt = 0;
        static void Main(string[] args)
        {
            var N = Sarray()[0];
            var Ai = Sarray();
            var pi = partition(Ai, 0, (int)N - 1);
            StringBuilder sb=new StringBuilder();
            for (var i = 0; i < N; ++i)
            {
                if (i != pi)
                { sb.Append($"{Ai[i]} "); }
                else
                { sb.Append($"[{Ai[i]}] "); }
            }
            WriteLine(sb.ToString().Trim());
        }
        static void swap<T>(ref T  a,ref T b)
        {
            var t = a;
            a = b;
            b = t;
        }
        static int partition(long[] A,int p, int r)
        {
            var x = A[r];
            var i = p - 1;
            for (var j = p; j < r;++j)
            {
                if(A[j]<=x)
                {
                    ++i;
                    swap<long>(ref A[i], ref A[j]);
                }
            }
            swap<long>(ref A[i + 1], ref A[r]);
            return i + 1;
        }
    }
}



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

namespace aaa
{
	class Program
	{
		static void Main(string[] args)
		{
			long n = long.Parse(Console.ReadLine());

			long ans = n;

			for (long i = 1;i<=Math.Sqrt(n);i++)
			{
				if (n % i == 0)
				{
					long j = n / i;

					if (ans > i + j - 2)
					{
						ans = i + j - 2;
					}
				}
			}
			Console.WriteLine(ans);
			Console.ReadKey(true);
		}
	}
}


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

int main(){
  int a1,a2,a3;
  cin >> a1 >> a2 >> a3;
  if(a1+a2+a3>=22){
    cout << "bust" << endl;
  }else{
    cout << "win" << endl;
  }
}

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

vector<int> par(100000);

int root(int x) {
    if (par[x] == x) return x;
    par[x] = root(par[x]);
    return par[x];
}

void unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx == ry) return;
    par[rx] = ry;
    return;
}

bool same(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
}

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> p(N);
    rep(i, N) {
        cin >> p[i];
        --p[i];
    }
    vector<int> x(M), y(M);
    rep(i, M) {
        cin >> x[i] >> y[i];
        --x[i];
        --y[i];
    }
    
    rep(i, N) par[i] = i;
    rep(i, M) unite(x[i], y[i]);
    int cnt = 0;
    rep(i, N) if (same(i, p[i])) ++cnt;
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

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

using namespace std;
int main() {
    int N; cin >> N;
    for (int i = 111; i < 1000; i += 111) {
        if(i >= N) {
            cout << i << endl;
            return 0;
        }
    }
}


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


int gcd(int a, int b, int c) {
    // a > b の確認
    if (a < b) {
        int tmp = a;
        a = b;
        b = tmp;
    }

    int r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }

    //  b > c の確認
    if (b < c) {
        int tmp = b;
        b = c;
        c = tmp;
    }
    r = b % c;
    while (r != 0) {
        b = c;
        c = r;
        r = b % c;
    }
    return c;
}

int main() {
    int n;
    cin >> n;
    ll ans=0;

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            for (int k = 1; k <= n; k++) {
                ans += gcd(i, j, k);
            }
        }
    }
    cout << ans << endl;

}


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

mt19937 rnd(time(0));
const int maxn=200005;
int n;
int a[maxn*2],rt[maxn*2];
vector<int>idx;

namespace Treap{
	int tot;
	class Node{
	public:
		int l,r,fix,sz,v,vr;
	}t[maxn];
	int newnode(int _v){
		tot++;
		t[tot].l=t[tot].r=0;
		t[tot].fix=rnd();
		t[tot].v=t[tot].vr=_v;
		t[tot].sz=1;
		return tot;
	}
	void pushup(int cur){
		t[cur].vr=t[cur].v;
		if(t[cur].r)t[cur].vr=t[t[cur].r].vr;
		t[cur].sz=t[t[cur].l].sz+t[t[cur].r].sz+1;
	}
	void split(int cur,int &x,int &y,int val){
		if(!cur)x=y=0;
		else if(t[cur].v<=val){
			x=cur;
			split(t[cur].r,t[x].r,y,val);
			pushup(x);
		}
		else{
			y=cur;
			split(t[cur].l,x,t[y].l,val);
			pushup(y);
		}
	}
	void merge(int &cur,int x,int y){
		if(!x||!y)cur=x?x:y;
		else if(t[x].fix<t[y].fix){
			cur=x;
			merge(t[cur].r,t[x].r,y);
			pushup(cur);
		}
		else{
			cur=y;
			merge(t[cur].l,x,t[y].l);
			pushup(cur);
		}
	}
	void print(int cur){
		if(!cur)return;
		print(t[cur].l);
		printf("%d ",t[cur].v);
		print(t[cur].r);
	}
}

namespace Segtree{
	int mx[maxn*8];
	void update(int cur,int l,int r,int k){
		if(l==r){
			mx[cur]=a[l];
			return;
		}
		int mid=l+r>>1;
		if(k<=mid)update(cur<<1,l,mid,k);
		else update(cur<<1|1,mid+1,r,k);
		mx[cur]=max(mx[cur<<1],mx[cur<<1|1]);
	}
	void query(int cur,int l,int r,int &x,vector<int>&pos){
		if(mx[cur]<=x)return;
		if(l==r){
			pos.push_back(l);
			x=mx[cur];
			return;
		}
		int mid=l+r>>1;
		query(cur<<1,l,mid,x,pos);
		query(cur<<1|1,mid+1,r,x,pos);
	}
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		rt[i]=Treap::newnode(a[i]);
		Segtree::update(1,1,2*n,i);
	}
	for(int i=n+1;i<=2*n;i++){
		idx.clear();
		int last=0;
		Segtree::query(1,1,2*n,last,idx);
		for(int j=0;j<int(idx.size());j++){
			int p=idx[j];
			int x,y;
			Treap::split(rt[p],x,y,Treap::t[rt[i]].vr);
			rt[p]=x;
			a[p]=Treap::t[x].vr;
			Segtree::update(1,1,2*n,p);
			Treap::merge(rt[i],rt[i],y);
		}
		if(Treap::t[rt[i]].sz==n){
			printf("%d\n",i-n-1);
			return 0;
		}
		a[i]=Treap::t[rt[i]].vr;
		Segtree::update(1,1,2*n,i);
	}
	return 0;
}

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

int main() {
    int N, M; cin >> N >> M;

    if(M == 1) {
        cout << "1 2\n";
        return 0;
    }

    int l = 1, r = M + 2;
    for(int diff=M; diff>0; --diff) {
        cout << l << ' ' << l + diff << '\n';
        ++l;
        swap(l, r);
    }
}

Measured memory_bytes: 3584
n,q = map(int,input().split())
s = input()

li = [0]*(n)
ans = 0

for i in range(n-1):
    if s[i:i+2] == "AC":
        ans += 1
    li[i+1] = ans

for i in range(q):
    x,y = map(int,input().split())
    print(li[y-1] - li[x-1])


Measured memory_bytes: 6188
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
#define REP(i,n) for(int i=0;i<(int)(n);i++)
 
 
int main()
{
    long long int n;
    int keta[500]={};
    scanf("%lld",&n);
    int j=1;
    int p=0;
    if(n==0)
    {
        printf("0\n");
        return 0;
    }
    while(n!=0)
    {
        if(n%2==0)
        {
            keta[p]=0;
            n=n/2;
        }
        else
        {
            keta[p]=1;
            n=(n-j)/2;
        }
        j=-j;
        p++;
    }
    REP(i,p)printf("%d",keta[p-1-i]);
    printf("\n");
    return 0;
}

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


//方針: 一番小さいやつと一番大きいやつを交換して、交換できなくなったらおわり
//元のほうが大きい
int main(){
    int N,M;
    cin >> N >> M;

    long long res = 0;
    vector<pair<int, int> > pairs(M);

    vector<int> A(N);
    REP(i,N){
        
        cin >> A[i];
    }
    //sort 昇順
    sort(A.begin(),A.end());

    //Cでsortしたいので、cをfirstにする
    REP(i,M){
        cin >> pairs[i].second >> pairs[i].first;
    }
    //cの降順ソート
 //   sort(pairs.begin(),pairs.end(),greater<vector<pair<int, int> >>());
    sort(pairs.rbegin(), pairs.rend());


    int i_kokan = 0;
    bool flg = true;
    //pairをとりだしていく
    for ( auto item : pairs) {

            //item.first 値
            //item.second 何回交換できるか
            //戦闘ひとつなら交換可能
        for(int i = i_kokan; i <= i_kokan + item.second - 1; i++){
            //iがN以上か
            if(i >= N){
                flg = false;
                break;
            }

            if(A[i] < item.first)
            {
                A[i] = item.first;
            }
            else{
                //途中で力尽きたか
                flg = false;
                break;
            }
        }

        if(flg == false)break;
        i_kokan += item.second;//次の交換さきに設定

        
    }

    //res = accumulate(A.begin(), A.end(), 0);
    for ( auto item : A) {
        res += item;
    }

    cout << res << endl;

    return 0;
}



Measured memory_bytes: 1408
#include<stdio.h>
#include<utility>
#include<math.h>
#include<algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
const int INF =1001001001;
int M,N;
FILE *fp;
int P[10002];
int C[502];
int E[502]; 
int dp[2][10002];//jコめの箱まででk個以上はいるようにした時の箱の価格の合計最小値(不可能な際はinf)
int change=1;//0のときは[1]を編集、1のときは[0]を編集

int main(){
	//fp=fopen("F:\\1JOI本選\\2014\\joi2014-ho-data\\joi2014-ho-data\\2014-ho-t2\\in\\03-09.txt","r");
	scanf("%d %d",&M,&N);
	rep(i,M)scanf("%d",&P[i]);
	rep(i,N)scanf("%d %d",&C[i],&E[i]);
	sort(P, P + M);//Pは値段がひくい順
	rep(i,N+1){
		change=(bool)(change==0);
		rep(j,M+1){
			if(i==0){
				dp[change][j]=INF;
				dp[change][0]=0;
			}else{
				if(j==0)dp[change][j]=0;
				else dp[change][j]=min(dp[change==0][j],dp[change==0][max(0,j-C[i-1])]+E[i-1]);
			}
		}
	}
	int ans=0;
	rep(i,M+1){//もちを詰める個数
		int inin=0;
		rep(j,i){inin+=P[M-j-1];}
		ans=max(ans,inin-dp[change][i]);
	}
	printf("%d\n",ans);
	return 0;
}

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

int main (){
	int i;
	char str[10];
	scanf("%s", str);
	for(i = 0; i < 3; ++i){
		if(str[i] == '1' || str[i] == '9')
			str[i] = '1' + '9' - str[i];
	}
	puts(str);
	return 0;
}


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

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
using namespace __gnu_pbds;
using namespace std;

using key=pair<int,int>;
using Tree=tree<key,null_type,less<key>,rb_tree_tag,tree_order_statistics_node_update>;

struct Query{
    int index;
    int l,r;
};

int main(){
    int n,m;
    cin>>n>>m;
    vector<pair<int,int>> lr(n);
    for(int i=0;i<n;i++){
        int l,r;
        cin>>l>>r;
        r++;
        lr[i]={l,r};
    }

    sort(lr.begin(),lr.end(),[](pair<int,int> &lhs,pair<int,int> &rhs){return lhs.first>rhs.first;});
    vector<int> ans(m,n);
    vector<Query> query;
    for(int i=0;i<m;i++){
        int d=i+1;
        for(int j=d;j-d<=m;j+=d){
            query.push_back(Query{i,j+1-d,j});
        }        
    }

    sort(query.begin(),query.end(),[](Query &a,Query &b){return a.l>b.l;});
    Tree t;

    int inde=0;
    for(int i=0;i<query.size();i++){
        while(inde<n && query[i].l<=lr[inde].first){
            t.insert({lr[inde].second,inde});
            inde++;
        }
        ans[query[i].index]-=t.order_of_key({query[i].r+1,-100});
    }
    for(int i=0;i<m;i++){
        cout<<ans[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 39140
#include<bits/stdc++.h>
#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
typedef long long ll;
using namespace std;

string s;
int N;
ll m,a,r,c,h;
ll D[5];
int P[10]={0,0,0,0,0,0,1,1,1,2};
int Q[10]={1,1,1,2,2,3,2,2,3,3};
int R[10]={2,3,4,3,4,4,3,4,4,4};
int  main() {
    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        cin >> s;
        if (s[0] == 'M')m++;
        if (s[0] == 'A')a++;
        if (s[0] == 'R')r++;
        if (s[0] == 'C')c++;
        if (s[0] == 'H')h++;
    }
    D[0] = m, D[1] = a, D[2] = r, D[3] = c, D[4] = h;
    ll res = 0;
    for (int d = 0; d < 10; d++)
        res += D[P[d]] * D[Q[d]] * D[R[d]];
    printf("% lld\n", res);
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int n, d, x;
  cin >> n >> d >> x;
  d -= 1;
  x += n;
  for (int i=0;i<n;i++) {
    int a;
    cin >> a;
    x += d/a;
  }
  cout << x << endl;
  return(0);
}


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

int main() {
    int64_t n, x, m;
    cin >> n >> x >> m;
    vector<int64_t> cnt(m, 0);
    queue<int64_t> rem;
    int64_t index = 1, sum = x, ans = 0, next = (x * x) % m,
            loop = 0;
    cnt[x] = index;
    rem.push(x);
    while (true) {
        if (cnt[next] != 0) break;
        cnt[next] = ++index;
        rem.push(next);
        sum += next, next = (next * next) % m;
    }
    for (auto i = 1; i < cnt[next]; i++) {
        ans += rem.front();
        rem.pop();
    }
    loop = rem.size();
    if (not rem.empty())
        ans += ((n - (cnt[next] - 1)) / loop) * (sum - ans);
    for (auto i = 0; i < (n - (cnt[next] - 1)) % loop;
         i++) {
        ans += rem.front();
        rem.pop();
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

typedef pair<double, double> pd;
typedef vector<pd> vpd;


#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> t chmax(t&a,u b){if(a<b)a=b; return a;};
template<class t, class u> t chmin(t&a,u b){if(a>b)a=b; return a;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

ll gcd(ll x, ll y){
  if(y==0) return x;
  return gcd(y, x-(x/y)*y);
}

bool check(ll A, ll B, ll C, ll D){
  if(A<B) return false;
  if(D<B) return false;
  if(C>=B) return true;
  // A>=B>C ? D>=B
  // A+(D-B)*x - ((A+(D-B)*x-C-1)/B)*B < B?

  if(D==B){
    ll tmp = A-(A/B)*B;
    if(tmp>C) return false;
    return true;
  }

  ll tmp = gcd(D-B, B);
  ll shift = (A-C-1)%B;
  ll k = ((B-shift+tmp-1)/tmp)*tmp;
  ll tmp2 = A+k - ((k+A-C-1)/B)*B;
  //debug_print(tmp, k, A+k, k+A-C-1, B, tmp2);
  if(tmp2<B) return false;
  return true;
}

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll T;
  IN(T);
  REP(i,T){
    ll A, B, C, D;
    IN(A,B,C,D);
    if(check(A,B,C,D)){
      OUT("Yes");
    }else{
      OUT("No");
    }
  }

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    int ans = 0;
    for (int i = 0, x = 1; i < n; ++i) {
        if (a[i] == x) {
            ++x;
        } else {
            ++ans;
        }
    }

    if (ans == n) ans = -1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <vector>
#include <queue>

using namespace std;

#define int_ int64_t
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define db double
#define lb long double
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PII pair<int, int>

const int N=10010,M=20010;
struct edge {
    int to,next,len,cost;
} e[M*2];
int head[N];
int tot=0;
void add_edge(int u,int v,int d,int c) {
    e[tot].to=v;
    e[tot].len=d;
    e[tot].cost=c;
    e[tot].next=head[u];
    head[u]=tot++;
}
int n,m,u,v,d,c;
int dis[N];

struct node {
    int idx,dis,cost;
    bool operator<(const node& rhs) const {
        if (dis==rhs.dis) {
            return cost>rhs.cost;
        }
        return dis>rhs.dis;
    }
};

int solve() {
    memset(dis,-1,sizeof(dis));
    priority_queue<node> pq;
    pq.push({1,0,0});
    int ans=0;
    while (!pq.empty()) {
        node cur=pq.top();
        pq.pop();
        if (dis[cur.idx]!=-1) continue;
        dis[cur.idx]=cur.dis;
        ans+=cur.cost;
        for (int i=head[cur.idx];i!=-1;i=e[i].next) {
            int to=e[i].to;
            if (dis[to]==-1) {
                pq.push({to,cur.dis+e[i].len,e[i].cost});
            }
        }
    }
    return ans;
}

int main()
{
    while (true) {
        scanf("%d%d",&n,&m);
        if (n==0&&m==0) break;
        tot=0;
        memset(head,-1,sizeof(head));
        for (int i=1;i<=m;i++) {
            scanf("%d%d%d%d",&u,&v,&d,&c);
            add_edge(u,v,d,c);
            add_edge(v,u,d,c);
        }
        printf("%d\n",solve());
    }
}


Measured memory_bytes: 4016
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>

using namespace std;

const int MX=100011;
struct Edge{int t,nxt;}e[MX<<1];
int ec,hed[MX];
int n,k;
int v[MX],L[MX],R[MX],typ[MX];
int ans[MX];

inline void ade(int f,int t){++ec;e[ec].nxt=hed[f];hed[f]=ec;e[ec].t=t;}

#define FE(i) for(int (i)=hed[k];(i);i=e[i].nxt)if(e[i].t!=f)

void dfs(int k,int f){
	if(~v[k])L[k]=R[k]=v[k],typ[k]=(1<<(v[k]&1));
	FE(i)dfs(e[i].t,k),L[k]=max(L[k],L[e[i].t]-1),R[k]=min(R[k],R[e[i].t]+1),typ[k]&=((~typ[e[i].t])?(typ[e[i].t]^3):-1);
}
void dfs2(int k,int f){
	FE(i)L[e[i].t]=max(L[e[i].t],L[k]-1),R[e[i].t]=min(R[e[i].t],R[k]+1),typ[e[i].t]&=((~typ[k])?(typ[k]^3):-1),dfs2(e[i].t,k);
}
void dfswk(int k,int f,int vf){
	ans[k]=(!f?L[k]:(vf-1<=R[k]&&vf-1>=L[k]?vf-1:vf+1));
	FE(i)dfswk(e[i].t,k,ans[k]);
}

#undef FE
int main(){
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		int A,B;
		scanf("%d%d",&A,&B);
		ade(A,B),ade(B,A);
	}
	scanf("%d",&k);
	memset(v+1,-1,sizeof(int)*n);
	for(int i=1;i<=k;i++){
		int x,V;
		scanf("%d%d",&x,&V);
		v[x]=V;
	}
	memset(L+1,0xc0,sizeof(int)*n);
	memset(R+1,0x3f,sizeof(int)*n);
	memset(typ+1,-1,sizeof(int)*n);
	dfs(1,0);dfs2(1,0);
	for(int i=1;i<=n;i++)if(L[i]>R[i]||!typ[i])return puts("No"),0;
	puts("Yes");
	dfswk(1,0,0);
	for(int i=1;i<=n;i++)printf("%d\n",ans[i]);
	return 0;
}


Measured memory_bytes: 9472
from math import cos
from math import pi

short, long, H, M = (int(x) for x in input().split())

angle = ((H*3600 + M*60) * pi/21600) - (M * 60 * pi/1800)

ans_2 = (short**2 + long**2 - 2*short*long*cos(angle)) ** (1/2)

print(ans_2)

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


int main(){
    int n;
    cin >> n;
    double ans;
    vector<int> num(n);
    for (int i = 0; i < n;i++){
        cin >> num.at(i);
        ans += (double)1 / (double)num.at(i);
    }
    ans = 1 / ans;
    printf("%.10lf\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main (){
	int a[105];
  	int b[105];
    int N,temp,i,j,ng;
  	int count = 0;
    
    scanf("%d",&N);
    
    for(j = 0;j < N;j++){
        scanf("%d",&a[j]);
     }
        
        
     temp = a[0];
       
     for(i = 0;i < N;i++){
        if(temp <= a[i]){
          	b[count] = a[i];
            count++;
        }
     }
    b[count] = 1000; 
  	for(j = 0;j < count;j++){
      	if(temp > b[j]){
       		ng++;
         }else if(temp < b[j]){
          temp = b[j];
        }
    }
  		if(count > ng){
          count = count - ng;
          printf("%d",count);
        }else{
          
          printf("1");
        }
        
        
        return 0;
  
}



Measured memory_bytes: 128
def main():
    s = input()
    cnts = 0
    cnt = 0
    for i in s:
        if i == 'S':
            cnts += 1
        elif cnts > 0:
            cnts -= 1
            cnt += 1
    print(len(s)-cnt*2)
if __name__ == '__main__':
    main()

Measured memory_bytes: 3500
# encoding: "utf-8"

from enum import Enum

class Unreachable(Exception):
    pass

class Type(Enum):
    VAL = 0
    PTR = 1


class Elem:
    def __init__(self, i, value, _type):
        self.idx = i
        self.value = value
        self.type = _type

    def set(self, value, _type):
        self.value = value
        self.type = _type
        

class SetManager:
    def __init__(self, n):
        self.data = list()
        for i in range(n):
            self.data.append(Elem(i, {i}, Type.VAL))

    def get(self, i):
        return self.data[i]

    def set(self, i, value):
        if isinstance(value, set):
            t = Type.VAL
        elif isinstance(value, int):
            t = Type.PTR
        self.data[i].set(value, t)

    def find_root(self, i):
        elem = self.get(i)
        if elem.type == Type.VAL:
            return (i, elem)
        elif elem.type == Type.PTR:
            j, root_elem = self.find_root(elem.value)
            self.set(i, j)
            return (j, root_elem)
        else:
            raise Unreachable

    def run(self, command):
        com, x, y = command
        if com == 0:
            self.unite(x, y)

        elif com == 1:
            if self.same(x, y):
                print(1)
            else:
                print(0)

        else:
            raise Unreachable

    def unite(self, x, y):
        i, elem_x = self.find_root(x)
        j, elem_y = self.find_root(y)
        if i != j:
            new_set = elem_x.value | elem_y.value
            self.set(i, new_set)
            self.set(j, i)

    def same(self, x, y):
        return y in self.find_root(x)[1].value


def main():
    n, q = [int(x) for x in input().split()]
    manager = SetManager(n)

    commands = list()
    for _ in range(q):
        com, x, y = [int(x) for x in input().split()]
        commands.append((com, x, y))
    
    for command in commands:
        manager.run(command)


if __name__ == "__main__":
    main()

Measured memory_bytes: 28196
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    cout << max({a * 10 + b + c, b * 10 + a + c, c * 10 + a + b});
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;
using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

bool msdf(pii x, pii y)
{
	if(x.F == y.F)
		return x.S > y.S;
	else
		return x < y;
}
pii a[N];
int main()
{
	int n, m;
	cin >> n >> m;
	for(int i = 1; i <= m; i ++)
	{
		int l, r;
		cin >> l >> r;
		a[i] = M(l, r);
	}
	sort(a + 1, a + m + 1, msdf);
	int ans = 0, mn = 1e9;
	for(int i = 1; i <= m; i ++)
	{
		umin(mn, a[i].S);
 		if(a[i].F >= mn)
			ans ++,
			mn = a[i].S;
		else
			umin(mn, a[i].S);
	}
	cout << ans+1;


	





	getchar();
	getchar();
	return 0;
	//ios::sync_with_stdio(false);
	//cin.tie(0);
}

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

using namespace std;

int now,al;
string s,str="abcdefghijk";

bool formula(void){
	
	if(s[now]=='T'){
		now++;	
		return true;
	}
	
	if(s[now]=='F'){
		now++;	
		return false;
	}
	
	for(int i=0;i<str.size();i++){
		if(s[now]==str[i]){
			now++;
			return (al>>i)&1;
		}
	}
	
	if(s[now]=='('){
		now++;
		bool res1=formula();
		
		if(s[now]=='*'){
			now++;
			bool res2=formula();
			if(s[now]==')')now++;
			return res1&res2;
		}
		if(s[now]=='+'){
			now++;
			bool res2=formula();
			if(s[now]==')')now++;
			return res1|res2;
		}
		if(s[now]=='-' && s[now+1]=='>'){
			now+=2;
			bool res2=formula();
			if(s[now]==')')now++;
			if(res1==true && res2==false)return false;
			return true;
		}
	}
	
	if(s[now]=='-'){
		now++;
		bool res=formula();
		return !res;
	}
}

bool equation(void){
	bool res1=formula();
	now++;
	bool res2=formula();
	return (res1==res2);
}

int main(void){
	
	while(cin >> s,s!="#"){
		bool fg=true;
		for(al=0;al<(1<<11);al++)now=0,fg&=equation();
		if(fg)cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

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

using namespace std;

using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FORE(i, a, b) for(int i=(a);i<=(b);++i)
#define rep(i, n) for(int i=0;i<(n);++i)
#define repe(i, n) for(int i=0;i<=(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define SP cout<<fixed<<setprecision(10)
typedef pair<int, int> P;
const int INF = (int) 1e9;
const int MOD = (int) 1e9 + 7;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n, k;
	cin >> n >> k;
	int h[n];
	rep(i, n) cin >> h[i];
	
	sort(h, h + n);
	
	int mindif = INF;
	repe(i, n - k) {
		mindif = min(h[i + k - 1] - h[i], mindif);
	}
	
	cout << mindif << endl;
	
	return 0;
}

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

int main(){
    int x;
    cin >> x;
    if(x==7||x==5||x==3) cout <<"YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


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

using namespace std;
typedef long long int lli;
#define MOD 1000000007
lli n,m;
lli dp[1004][1004];
char s[1004][1004];
lli solve(lli i,lli j);

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	cin>>n>>m;
	for (int i=0;i<n;i++){
		for (int j=0;j<m;j++) dp[i][j]=-1;
	}
	string sr;
	for (int i=0;i<n;i++){
		cin>>sr;
		for (int j=0;j<m;j++) s[i][j]=sr[j];
	}
	solve(0,0);
	cout<<dp[0][0]%MOD<<endl;
	
	return 0;
}

lli solve(lli i,lli j){
	if (i==n-1 && j==m-1) return 1;
	if (s[i][j]=='#') return 0;
	if (dp[i][j]!=-1) return dp[i][j];
	dp[i][j]=0;
	dp[i][j]=(dp[i][j]%MOD+solve(i+1,j)%MOD+solve(i,j+1)%MOD)%MOD;
	return dp[i][j]%MOD;  
}

Measured memory_bytes: 9216
#include <bits/stdc++.h>
#define int long long
using namespace std;
string S;
int c0=0,c1=0;
signed main(){
  cin >> S;
  for(int i=0;i<S.size();i++){
    if(S[i]=='0') c0++;
    else c1++;
  }
  cout << 2*min(c0,c1) << endl;
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
# define ll long long
# define int long long  //comment it out when MLE
//# define endl "\n"
#define gok ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
# define mo 1000000009
# define pi acos(-1)
# define fi first
# define se second
using namespace std;


signed main()
{
    gok
    int n;
    cin>>n;
    string s;
    cin>>s;
    int c1=0,c2=0,c3=0;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='R')
            c1++;
        else if(s[i]=='G')
            c2++;
        else
            c3++;
    }
    int an=c1*c2*c3;

    for(int i=1;i<n-1;i++)
    {
        int st=i-1,en=i+1;
        while(st>=0 && en<n)
        {
            if(s[st]!=s[i]&&s[i]!=s[en]&&s[st]!=s[en])
            {
                an--;
            }
            st--;
            en++;
        }
    }

    cout<<an<<endl;







      return 0;
    }


Measured memory_bytes: 3656
// Author : Mahmoud Tarek

#include <bits/stdc++.h>

using namespace std ;

#define sz(v) (int)v.size()
#define ll long long
#define all(v)  v.begin() , v.end()
#define rall(v)  v.rbegin() , v.rend()
#define pf push_front
#define pb push_back
#define fast FastInputOutput() ;
#define Clear( container , value ) memset( container , value , sizeof container )
#define forn( t , v , be , n ) for( t v = be ; v < n ; v++ )
#define fore( x , j ) for( auto x : j )
#define debug(x , y) cerr << #x << " = " << x << y ;

const ll Long_max = numeric_limits < ll > :: max() ;
const int Int_max = numeric_limits < int > :: max() ;

void File_input( string pathIn ) {
    freopen( pathIn.c_str(), "r", stdin ) ;
}

void File_output( string pathOut ) {
    freopen( pathOut.c_str(), "w", stdout ) ;
}

void FastInputOutput() {
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}

const int N = 2e5 + 5 ;
vector < int > adj[ N ] ;
ll cnt[ N ] ;
bool vis[ N ] ;
int n , q ;
int x , y ;

void BFS( ll u ){
queue < ll > a ;
a.push( u ) ;
vis[ u ] = 1 ;
while( sz( a ) ){
    int cur = a.front() ;
    a.pop() ;
    fore( i , adj[ cur ] ){
       if( !vis[ i ] ){
          cnt[ i ] += cnt[ cur ] ;
          a.push( i ) ;
          vis[ i ] = 1 ;
       }
    }
}
}

int main(){
 fast 
 cin >> n >> q ;
 forn( int , i , 0 , n - 1 ){
   cin >> x >> y ;
   adj[ x ].pb( y );
   adj[ y ].pb( x );
 }

 while( q-- ){
    cin >> x >> y ;
    cnt[ x ] += y ;
 }

 BFS( 1 ) ;
 forn( int , i , 1 , n + 1 ){
    cout << cnt[ i ] << " " ;
 }


 return 0 ;
}



Measured memory_bytes: 15884
#include <bits/stdc++.h>
#define lli long long int
#define ll long long
using namespace std;
int main()
 {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    lli k,flag=0,ans=0,i;
    cin>>k;
    for(i=1;i<=(1e7);i++)
    {
        ans=(ans*10+7)%k;
        if(ans==0)
        {
            flag=1;
            cout<<i<<"\n";
            break;
        }
    }
    if(flag!=1)
    cout<<-1<<"\n";
 }

Measured memory_bytes: 3660
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

type edge struct {
	to    int
	value int
}

var edges [][]edge
var vertex []int
var visited []bool

func fillNumber(x int) {
	visited[x] = true
	for _, e := range edges[x] {
		if !visited[e.to] {
			vertex[e.to] = vertex[x] + e.value
			fillNumber(e.to)
		} else if vertex[e.to] != vertex[x]+e.value {
			fmt.Println("No")
			os.Exit(0)
		}
	}
}

func main() {
	in := IOInitialize()
	n, m := Int(in), Int(in)

	if m == 0 || m == 1 {
		fmt.Println("Yes")
		return
	}

	edges = make([][]edge, n)
	for i := range edges {
		edges[i] = make([]edge, 0)
	}

	for i := 0; i < m; i++ {
		l, r, d := Int(in)-1, Int(in)-1, Int(in)
		edges[l] = append(edges[l], edge{to: r, value: d})
		edges[r] = append(edges[r], edge{to: l, value: -d})
	}

	vertex = make([]int, n)
	visited = make([]bool, n)

	for i := range visited {
		if !visited[i] {
			visited[i] = true
			fillNumber(i)
		}
	}
	fmt.Println("Yes")
}

//////////
//
//

func IOInitialize() *bufio.Scanner {
	t := bufio.NewScanner(os.Stdin)
	t.Split(bufio.ScanWords)
	return t
}

func Int(s *bufio.Scanner) int {
	if !s.Scan() {
		panic("\t\tThere is a FALSE not to want.")
	}

	value, err := strconv.Atoi(s.Text())
	if err != nil {
		panic("\t\tError:Failed to convert text to int,")
	}
	return value
}

func IntArray(s *bufio.Scanner, size int) []int {
	deepArray := make([]int, size)
	for i := range deepArray {
		deepArray[i] = Int(s)
	}
	return deepArray
}

func GraphSetByEdge(s *bufio.Scanner, v int) [][]int {
	g := make([][]int, v)
	for i := range g {
		g[i] = make([]int, 0)
	}
	for xxNonUsedInLoopI := 0; xxNonUsedInLoopI < v-1; xxNonUsedInLoopI++ {
		a, b := Int(s)-1, Int(s)-1
		g[a] = append(g[a], b)
		g[b] = append(g[b], a)
	}

	return g
}


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

using namespace std;

int W, H;
string C[70];

string ans;
string dp[70][70];

string strmax(string s, string t)
{
  if(s.size() != t.size()) return (s.size() > t.size() ? s : t);
  for(int i = 0; i < s.size(); i++){
    if(s[i] != t[i]) return (s[i] > t[i] ? s : t);
  }
  return s;
}

string dfs(int x, int y)
{
  if(x < 0 || W <= x || y < 0 || H <= y || C[y][x] < '0' || '9' < C[y][x]) return "";
  if(dp[y][x] != "") return dp[y][x];
  string ret = C[y][x] + strmax(dfs(x + 1, y), dfs(x, y + 1));
  return dp[y][x] = ret;
}

int main()
{
  while(cin >> W >> H, W || H){
    ans = "";
    for(int i = 0; i < 70; i++){
      for(int j = 0; j < 70; j++) dp[i][j] = "";
    }
    for(int i = 0; i < H; i++) cin >> C[i];
    for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
	if(C[i][j] != '0') ans = strmax(ans, dfs(j, i));
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1384
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min

val MOD = 1_000_000_007L
fun packUGraph(n: Int, from: IntArray, to: IntArray): Array<IntArray> {
  val p = IntArray(n)
  val m = from.size
  for (i in 0 until m) {
    ++p[from[i]]
    ++p[to[i]]
  }
  val g = Array(n){IntArray(p[it])}
  for (i in 0 until m) {
    g[from[i]][--p[from[i]]] = to[i]
    g[to[i]][--p[to[i]]] = from[i]
  }
  return g
}
class Solver(stream: InputStream, private val out: java.io.PrintWriter) {
  fun solve() {
    val N = ni()
    val (from, to) = na2(N - 1, - 1)
    val g = packUGraph(N, from, to)
    var edges = 0L
    var ans = 0L
    for (i in 0 until N) {
      for (j in g[i]) {
        if (j >= i) continue
        edges += j + 1
      }
      ans += (i + 1).toLong() * (i + 2) / 2
      ans -= edges
    }
    out.println(ans)
  }













































  private val isDebug = try {
    // なんか本番でエラーでる
    System.getenv("MY_DEBUG") != null
  } catch (t: Throwable) {
    false
  }

  private var tokenizer: StringTokenizer? = null
  private val reader = BufferedReader(InputStreamReader(stream), 32768)
  private fun next(): String {
    while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {
      tokenizer = StringTokenizer(reader.readLine())
    }
    return tokenizer!!.nextToken()
  }

  private fun ni() = next().toInt()
  private fun nl() = next().toLong()
  private fun ns() = next()
  private fun na(n: Int, offset: Int = 0): IntArray {
    return map(n) { ni() + offset }
  }
  private fun nal(n: Int, offset: Int = 0): LongArray {
    val res = LongArray(n)
    for (i in 0 until n) {
      res[i] = nl() + offset
    }
    return res
  }

  private fun na2(n: Int, offset: Int = 0): Array<IntArray> {
    val a  = Array(2){IntArray(n)}
    for (i in 0 until n) {
      for (e in a) {
        e[i] = ni() + offset
      }
    }
    return a
  }

  private inline fun map(n: Int, f: (Int) -> Int): IntArray {
    val res = IntArray(n)
    for (i in 0 until n) {
      res[i] = f(i)
    }
    return res
  }

  private inline fun debug(msg: () -> String) {
    if (isDebug) System.err.println(msg())
  }

  private fun debug(a: LongArray) {
    debug { a.joinToString(" ") }
  }

  private fun debug(a: IntArray) {
    debug { a.joinToString(" ") }
  }

  private fun debug(a: BooleanArray) {
    debug { a.map { if (it) 1 else 0 }.joinToString("") }
  }

  private fun debugDim(A: Array<LongArray>) {
    if (isDebug) {
      for (a in A) {
        debug(a)
      }
    }
  }
  private fun debugDim(A: Array<IntArray>) {
    if (isDebug) {
      for (a in A) {
        debug(a)
      }
    }
  }

  /**
   * 勝手にimport消されるのを防ぎたい
   */
  private fun hoge() {
    min(1, 2)
    max(1, 2)
    abs(-10)
  }
}

fun main() {
  val out = java.io.PrintWriter(System.out)
  Solver(System.`in`, out).solve()
  out.flush()
}


Measured memory_bytes: 62588
from functools import lru_cache

@lru_cache(maxsize = 10000)
def canProd(i,m):
     
    if m == 0:
        return True
    if i >= n:
        return False
 
    res = canProd(i+1,m) or canProd(i+1,m-a[i])
    return res
 
 
n = int(input())
a = [int(x) for x in input().split()]
q = int(input())
m = [int(x) for x in input().split()]
 
for i in m:
    if canProd(0,i):
        print("yes")
    else:
        print("no")

Measured memory_bytes: 13276
n=int(input())
p=list(map(int,input().split()))
count=0
for i in range(n-2):
    if((p[i]<p[i+1])and(p[i+1]<p[i+2])):
        count=count+1
    elif((p[i+2]<p[i+1])and(p[i+1]<p[i])):
        count=count+1
print(count)

Measured memory_bytes: 3060
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll N;
    cin >> N;
    vector<ll> x(N);
    for (ll i = 0; i < N; i++) {
        cin >> x[i];
    }
    ll L, Q;
    cin >> L >> Q;
    vector<ll> a(Q), b(Q);
    for (ll i = 0; i < Q; i++) {
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        if (a[i] > b[i]) {
            swap(a[i], b[i]);
        }
    }

    const ll MAX = (ll)ceil(log2(N)) + 1;

    //r[k][i] := i番目のホテルから2^k日以内に到達可能な最右のホテル番号
    vector<vector<ll>> r(MAX + 1, vector<ll>(N));
    for (ll i = 0; i < N; i++) {
        r[0][i] = upper_bound(x.begin(), x.end(), x[i] + L) - x.begin() - 1;
    }
    for (ll k = 0; k < MAX; k++) {
        for (ll i = 0; i < N; i++) {
            r[k + 1][i] = r[k][r[k][i]];
        }
    }

    auto isOK = [&](ll a, ll b, ll d) {
        //aからbへd日で行けるか？
        //d日で行ける最右のホテル番号を求める
        ll curr = a;
        while (d > 0) {
            ll n = 0;
            while ((1LL << n) <= d) {
                n++;
            }
            n--;

            curr = r[n][curr];
            if (curr >= b) {
                return true;
            }

            d -= (1LL << n);
        }
        return false;
    };

    for (ll i = 0; i < Q; i++) {
        ll ng = 0, ok = N;
        while (ng + 1 != ok) {
            ll mid = (ng + ok) / 2;
            (isOK(a[i], b[i], mid) ? ok = mid : ng = mid);
        }
        cout << ok << endl;
    }
}

Measured memory_bytes: 18304
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

typedef long long ll;

int n;
int a[100001];
int c[100001] = { 0 };
int res = 0;

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a, a + n);
	int j = 0;
	c[0]++;
	for (int i = 1; i < n; i++) {
		if (a[i - 1] != a[i]) {
			j++;
		}
		c[j]++;
	}
	for (int i = 0; i <= j; i++) {
		if (c[i] % 2 == 1) res++;
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 1024
def main():
    N = int(input())
    dp = [[0] * 3 for _ in range(2)]
    for i in range(N):
        a, b, c = map(int, input().split())
        now_i, next_i = i & 1, (i+1) & 1
        dp[next_i][0] = max(dp[now_i][1], dp[now_i][2]) + a
        dp[next_i][1] = max(dp[now_i][0], dp[now_i][2]) + b
        dp[next_i][2] = max(dp[now_i][0], dp[now_i][1]) + c
    print(max(dp[N & 1]))


if __name__ == '__main__':
    main()


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

using namespace std;

int main()
{
    string s, t;
    cin>>s>>t;
    
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());
    
    if(s < t) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
    return 0;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,M = map(int,readline().split())
PS = (line.split() for line in readlines())

ac = [False] * N
wa_cnt = [0] * N
penal = 0
for P,S in PS:
    p = int(P)-1
    if ac[p]:
        pass
    elif S == b'WA':
        wa_cnt[p] += 1
    else:
        ac[p] = True
        penal += wa_cnt[p]

ac = sum(ac)
print(ac, penal)

Measured memory_bytes: 10148
#include<bits/stdc++.h>
using namespace std;
int main () {
  int A, B;
  cin >> A >> B;
  if ( A % 2 == 1 && B % 2 == 1 ){
    cout << "Odd" << endl;
  }
  else {
    cout << "Even" << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int[] sum = new int[26];
		Arrays.fill(sum, Integer.MAX_VALUE);
		for(int i = 0; i < n; i++){
		    String s = sc.next();
		    int[] cnt = new int[26];
		    for(int j = 0; j < s.length(); j++){
		        cnt[s.charAt(j)-'a']++;
		    }
		    for(int j = 0; j < sum.length; j++){
		        sum[j] = min(sum[j], cnt[j]);
		    }
		}
		
		// 計算
		//String result = "";
		for(int i = 0; i < sum.length; i++){
		    for(int j = 0; j < sum[i]; j++){
		        System.out.print((char)(i + 'a'));
		    }
		}
		
		// 出力
		//System.out.println(result);
	}
}



Measured memory_bytes: 21716
#include<iostream>
#include<cstdio>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<map>
#include<numeric>
#include<stack>
#include<queue>
#include<functional>
#include<cassert>
#include<set>
#define rep(a,b) for(int a=0;a<b;++a)
#define REP(a,b,c,d) for(int a=b;a<c;a+=d)
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define mod 1000000007
using namespace std;
using ll = long long;
using p_i = pair<int, int>;
int main() {
	int H, W; cin >> H >> W;
	vector<vector<int>> A(H, vector<int>(W, 0));
	rep(i, H)rep(j, W)cin >> A[i][j];
	int ans = mod, num;
	rep(i, H) {
		rep(j, W) {
			num = 0;
			rep(k, H) rep(l, W) if (k != i && l != j) num += A[k][l] * min(abs(i - k), abs(j - l));
			ans = min(ans, num);
		}
	}
	cout << ans << endl;
	cin >> H;
}


Measured memory_bytes: 3164
def checklen(a,b,c):
    return a+b>c

n=int(input())
l=[int(i) for i in input().split()]

res=0

for i in range(n):
    for j in range(i):
        for k in range(j):
            a,b,c=l[i],l[j],l[k]
            if checklen(a,b,c) and checklen(b,c,a) and checklen(c,a,b) and len(set([a,b,c]))==3:
                res+=1

print(res)


Measured memory_bytes: 9196
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <tuple>
#include <stdlib.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define PI 3.14159265358979
typedef long long int ll;

const double pi=3.1415;
ll absc(ll a,ll b){return (a-b>0?a-b:b-a);
}
ll mini(ll a,ll b){return (a>b?b:a);}
ll gcd(ll a,ll b){
	if(a<b)swap(a,b);
	return (a%b?gcd(a%b,b):b);
}
int main()
{
   int n,k,d,a;
   cin>>n>>k;
   vector<int>snk(n,0);
   rep(i,k){
   	cin>>d;
   	rep(i,d){
   		cin>>a;
   		a--;
   		snk[a]++;
   	}
   }
   int ans=0;
   rep(i,n){if(snk[i]==0)ans++;}
   cout<<ans;
}


Measured memory_bytes: 3632