akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long       ll;
#define PI                acos(-1)
#define pb                push_back
#define mp                make_pair
#define mt                make_tuple
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define F first
#define S second
#define fore(i,b,e)		  for(int i=(int)b;i<(int)e;++i)
#define forr(i,b,e)		  for(int i=(int)b;i<(int)e;++i)
#define deb(x)			  cerr << "# " << (#x) << " = " << (x) << endl;
#define sz(x)             (int)x.size()
int faster_in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;

typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
const int INF = 1234567890;

const int tam = 1e6 + 10;

int divs[tam];

int main()
{
    std::ios::sync_with_stdio(false); cin.tie(0);
    //freopen("","r",stdin);
    //freopen("","w",stdout);
    fore(i, 1, tam) {
        for (int d = 1; d*d <= i; d++) {
            if (i%d > 0) continue;
            divs[i]++;
            if (d*d < i) divs[i]++;
        }
    }
    int n;
    cin >> n;
    ll res = 0;
    fore(c, 1, n) {
        res += divs[n-c];
    }
    cout << res << '\n';
    return 0;
}
// Dinosaurs are cool!

Measured memory_bytes: 7516
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

map<ll,ll>a;
int main() {
	ll n;
	cin>>n;
	for(int i=0;i<n;i++){
		ll x,y;
		cin>>x>>y;
		a[y]+=x;
	}
	ll now=0;
    for(auto itr = a.begin(); itr != a.end(); ++itr) {
        now+= itr->second;
        ll sime= itr->first;
        if(now>sime){
        	cout <<"No";
        	return 0;
        }
    }
    cout << "Yes";
}

Measured memory_bytes: 12800
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	void run(){
		for(;;){
			int n=sc.nextInt();
			if(n==0){
				break;
			}
			int[] h=new int[7];
			for(int i=0; i<n; i++){
				int a=sc.nextInt();
				for(int k=0; k<7; k++){
					if(a<(k+1)*10||k==6){
						h[k]++;
						break;
					}
				}
			}
			for(int i=0; i<7; i++){
				println(""+h[i]);
			}
		}
		System.out.flush();
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 12000
x,n = map(int, input().split())
a = list(map(int, input().split()))
lis = [True]*102
for i in a:
    lis[i] = False
ho = 0
while True:
    if not x-ho < 0:
        if lis[x-ho]:
            print(x-ho)
            exit()
    if not x+ho > 101:
        if lis[x+ho]:
            print(x+ho)
            exit()
    ho+=1

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

using namespace std;

int main() {
    int N,D,X;
    cin >> N >> D >> X;
    vector<int> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];

    int ans = X;
    for (int i = 0; i < N; ++i) {
        ans += (D-1) / A[i] + 1;
    }

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


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

#ifdef _MSC_VER
#include <Windows.h>
#else
#include <unistd.h>
#endif

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))


int main(){
    int x,y;
    cin>>x>>y;
    int cnt=0;
    if(x<=y||x==-y){
        if(abs(y+x)<abs(y-x)){
            cnt++;
            x=-x;
        }
        cnt+=abs(y-x);
    }else if(x<0&&y<0){
        cnt=2;
        cnt+=abs(y-x);
    }else if(x>0&&y>0){
        cnt=1;
        x=-x;
        cnt+=min(abs(y-x),abs(-y-x)+1);
    }else{
        cnt=1;
        x=-x;
        cnt+=abs(y-x);
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<vector>
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<string.h>
#define ll long long int
#define MOD 1000000007LL
using namespace std; 
int main() {
    int N,C;
    cin>>N>>C;
    int tt[214514]={};
    int ttt[214514]={};
    int s[114514]={};
    int t[114514]={};
    int c[114514]={};
    for(int i=0;i<N;i++){
        cin>>s[i]>>t[i]>>c[i];
    }
    for(int i=1;i<=C;i++){
        for(int j=0;j<=214514;j++){
            ttt[j]=0;
        }
        for(int j=0;j<N;j++){
            if(c[j]==i){
                ttt[s[j]*2-1]++;
                ttt[t[j]*2]--;
            }
        
        }
        for(int j=1;j<=214514;j++){
            ttt[j]+=ttt[j-1];
        }
        for(int j=0;j<=214514;j++){
            if(ttt[j]>0){
                tt[j]++;
            }
        }
    }
    int ans=0;
    for(int i=0;i<210000;i++){
        if(ans<tt[i]){
            ans=tt[i];
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  ll n, a, b;
  cin >> n >> a >> b;

  ll ans = n / (a + b) * a;
  cout << ans + min(n % (a + b), a) << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		
		if (C>=A && C<=B){
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		
		sc.close();
	}

}


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

int main() {
  int mi,ma,ct=0;
  cin >> mi >> ma;
  vector<int> vec(5);
  for(int a=mi;a<=ma;a++){
    int va = a;
    for(int i=0;i<5;i++){
      vec.at(i) = va -(va/10)*10;
      va /=10;
    }
    if (vec.at(0)==vec.at(4) && vec.at(1)==vec.at(3)){
      ct++;
    }
  }
  cout << ct ;
}


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

mn = 10**10
for i in range(n):
    if mn > abs(a - (t - h[i] * 0.006)):
        mn = min(mn, abs(a - (t - h[i] * 0.006)))
        ans = i+1
print(ans)

Measured memory_bytes: 3060
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <iostream>
#include <set>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define grt() greater<int>()
#define grtl() greater<long long>()

int main () {
    int n, k;
    cin >> n >> k;

    vector<int> d(k);
    vector<vector<int>> a(k);

    for (int i = 0; i < k; i++) {
        cin >> d[i];
        for (int j = 0; j < d[i]; j++) {
            int c;
            cin >> c;
            a[i].push_back(c);
        }
    }

    
    set<int> kid;
    for (int i = 0; i < k; i++)
    {
        for (int j = 0; j < d[i]; j++) {
            kid.insert(a[i][j]);
        }
    }

    cout << n - kid.size() << endl;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main() {
    int n,m;
    cin >> n >> m;
    vector<vector<int>> t(n);
    rep(i,m){
        int a,b;
        cin >> a >> b;
        t[a-1].push_back(b-1);
        t[b-1].push_back(a-1);
    }
    for(auto a : t)cout << a.size() << endl;
    return 0;
}
/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

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

int n,k,cnt;
vector<int> G[2000];

void dfs(int v,int par,int d){
	if(d > k / 2) cnt++;
	for(int to : G[v]){
		if(to == par) continue;
		dfs(to,v,d + 1);
	}
}

int main(){
	int a[2000],b[2000];
	cin >> n >> k;
	for(int i = 0;i < n - 1;i++){
		cin >> a[i] >> b[i]; a[i]--;b[i]--;
		G[a[i]].push_back(b[i]);
		G[b[i]].push_back(a[i]);
	}
	int mi = 3000;
	if(k % 2){
		for(int i = 0;i < n - 1;i++){
			cnt = 0;
			dfs(a[i],b[i],0);
			dfs(b[i],a[i],0);
			mi = min(mi,cnt);
		}
	}else{
		for(int i = 0;i < n;i++){
			cnt = 0;
			dfs(i,-1,0);
			mi = min(mi,cnt);
		}
	}
	cout << mi << endl;
	return 0;
}

Measured memory_bytes: 512
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=min(a)+min(b)

for _ in range(M):
  x,y,c=map(int,input().split())
  ans=min(ans,a[x-1]+b[y-1]-c)
  
print(ans)

Measured memory_bytes: 18736
#include <bits/stdc++.h>
using namespace std;
    #define fio ios_base::sync_with_stdio(false), cin.tie(NULL)
    #define ll long long
    #define int long long 
    #define ull unsigned long long 
    #define ld long double
    #define sb __builtin_popcount
    #define vi vector<int>
    #define vc vector<char>
    #define ii pair<int, int>
    #define pq priority_queue<ii, vector<ii>, greater<ii>>
    #define vii vector<ii>
    #define sz(a) int((a).size())
    #define f(a, b) for (int i = a; i < b; i++)
    #define fr(a, b) for (int i = a - 1; i >= b; i--)
    #define tr(x, m) for (auto x : m)
    #define in(a, b) (b.find(a) != string::npos)
    #define minin(a) *min_element(all(a))
    #define maxin(a) *max_element(all(a))
    #define X first
    #define Y second
    #define fill(a, x) memset(a, x, sizeof(a))
    #define pb push_back
    #define pf push_front
    #define mp make_pair
    #define all(v) v.begin(), v.end()
    #define rall(v) reverse(v.begin(), v.end())
    #define unq(v) v.erase(unique(all(v)), v.end())
    #define el "\n"
    #define mx3(a, b, c) max(max(a, b), c)
    #define mn3(a, b, c) min(min(a, b), c)
    #define S(v) accumulate(all(v), (ll)0)
    #define SP(n) cout.precision(n)
    const ld PI = atan(1.0) * 4.0;
    const ll MOD = 1e9 + 7;
    const ll INF = 1e18;
    const ld EPS = 0.0000001;



        int32_t main() {
            fio;
            SP(10);
            ld r;
            cin>>r;
            ld ans= 2*PI*r;
            cout<<ans<<el;
            return 0;
        }


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

using namespace std;

int main()
{
	int n, r = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a, k;
		cin >> a >> k;
		for (;;) {
			int b = a % k % (a / k + 1);
			if (!b) break;
			a += b - a / k - a % k - 1;
		}
		r ^= a / k;
	}
	cout << (r ? "Takahashi" : "Aoki") << endl;
	return 0;
}


Measured memory_bytes: 384
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

class UnionFindTree {
public:
    this(size_t n) {
        parent = iota(n).array();
        rank = new size_t[](n);
    }
    size_t find(size_t n) {
        if(n == parent[n]) {
            return n;
        } else {
            parent[n] = find(parent[n]);
            return parent[n];
        }
    }
    void unite(size_t n, size_t m) {
        auto p1 = find(n);
        auto p2 = find(m);
        if(n == m) {
            return;
        }
        if(rank[p1] < rank[p2]) {
            swap(p1, p2);
        }
        if(rank[p1] == rank[p2]) {
            ++rank[p1];
        }
        parent[p2] = p1;
    }
private:
    size_t[] parent;
    size_t[] rank;
}
unittest {
    auto uft = new UnionFindTree(10);
    foreach(i; iota(10)) {
        assert(uft.find(i) == i);
    }
    foreach(i; iota(10).filter!(a => a%3 == 0).drop(1)) {
        uft.unite(i, i-3);
    }
    foreach(i; iota(10).filter!(a => a%3 == 0)) {
        assert(uft.find(0) == uft.find(i));
    }
    foreach(i; iota(10).filter!(a => a%3 != 0)) {
        assert(uft.find(0) != uft.find(i));
    }
}

const real eps = 1e-10;

const long p = 1_000_000_000 + 7;

void main(){
    auto n = readLong();
    auto a = readLongs();

    //dp[i]: n+i番目までで前半を最大にするように取ったときの最大値
    auto dp1 = new long[](n+1);
    dp1[0] = a[0..n].sum(0L);
    auto q1 = redBlackTree!true(a[0..n]);
    foreach(i; iota(n)) {
        q1.insert(a[n+i]);
        dp1[i+1] = dp1[i] + a[n+i] - q1.front();
        q1.removeFront();
    }

    //後ろから
    auto dp2 = new long[](n+1);
    dp2[0] = a[2*n..$].sum(0L);
    auto q2 = redBlackTree!true(a[2*n..$]);
    foreach(i; iota(n)) {
        q2.insert(a[2*n-i-1]);
        dp2[i+1] = dp2[i] + a[2*n-i-1] - q2.back();
        q2.removeBack();
    }
    
    auto ans = long.min;
    foreach(i; iota(n+1)) {
        ans = max(ans, dp1[i] - dp2[n-i]);
    }
    writeln(ans);
}



Measured memory_bytes: 36836
import sys
input = sys.stdin.readline
from collections import *

N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda t: t[0])
ans = 0

for A, B in AB:
    if M-B>=0:
        ans += A*B
        M -= B
    else:
        ans += A*M
        break

print(ans)

Measured memory_bytes: 88104
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int N = int.Parse(str[0]);
		int M = int.Parse(str[1]);
		int V = int.Parse(str[2]);
		int P = int.Parse(str[3]);
		int[]A = new int[N];
		string[] str2 = Console.ReadLine().Split();
		for(var i=0;i<N;i++){
			A[i] = int.Parse(str2[i]);
		}
		Array.Sort(A,(x,y)=>y-x);
		var dic = new Dictionary<int,int>();
		for(var i=0;i<N;i++){
			if(!dic.ContainsKey(A[i])){
				dic[A[i]] = i;
			}
		}
		long[]S = new long[N];
		long sum = 0;
		for(var i=N-1;i>=0;i--){
			sum += A[i];
			S[i] = sum;
		}
		int min = P;
		int max = N;
		while(min<max){
			int m = (min+max)/2;
          	//Console.Error.WriteLine(min+" "+max+" "+m+" "+A[m]);
			long a = A[m]+M;
			int min2 = 0;
			int max2 = m;
			while(min2<max2){
				int m2 = (min2+max2)/2;
				if(A[m2]>a){
					min2 = m2+1;
				} else {
					max2 = m2;
				}
			}
			//Console.Error.WriteLine(min2);
			int m1 = min2;
			m1 = Math.Max(P-1,m1);
			long ct = a * (m-m1) - (S[m1] - S[m]);
			//Console.Error.WriteLine(m+" "+m1+" "+ct);
			ct += (long)Math.Min(V,(N-m)+(P-1))*M;
			//Console.Error.WriteLine(ct);
			if(ct >= (long)M * V && a >= A[P-1]){
				min = m+1;
			} else {
				max = m;
			}
		}
		Console.WriteLine(min);
	}
}

Measured memory_bytes: 27488
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<string>
using namespace std;
int main() {
  int X,t;
  cin >> X >> t;
  int ans = X - t;
  if (ans <= 0) cout << 0 << endl;
  else cout << ans << endl;
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
    
    int main(){
        long  n;
        cin >> n;
        long ans = 0; 
        long odd = 0 , even = 0;
        long a;
        for(int i = 0 ; i < n ; i++){
            cin >> a;
            if(a % 2 == 0){
                even += 1;
            }else{
                odd += 1;
            }
            
        }
        if(odd == 0){
            cout << "YES" << endl;
            return 0;
        }
        if(odd % 2 == 0){
            cout << "YES" << endl;
            return 0;
        }
        cout << "NO" << endl;
        return 0;
    }

Measured memory_bytes: 384
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

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

int main() {
    vector<int> num(4);
    string in_num;
    cin >> in_num;
    rep(i, 4) num[i] = in_num[i] - '0';
    //cout << "test" << endl;
    rep(i, 1<<3) {
        int sum = num[0];
        string ans = "";
        ans += in_num[0];
        rep(j, 3) {
            //cout << in_num[j+1] << endl;
            if (i>>j & 1) {
                sum += num[j+1];
                ans += '+';
                ans += in_num[j+1];
            }
            else {
                sum -= num[j+1];
                ans += '-';
                ans += in_num[j+1];
            }
            //cout << ans << endl;
        }
        //cout << sum << endl;
        if (sum == 7) {
            cout << ans + "=7" << endl;
            return 0;
        }
    }
    return 0;
}

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

int main(){
    int A,B,K;
    cin>>A>>B>>K;
    if(2*K>=B-A+1){
        for(int i=A;i<=B;i++) cout<<i<<'\n';
    }
    else{
        for(int i=A;i<=A+K-1;i++) cout<<i<<"\n";
        for(int i=A+K;i<=B;i++){
            if(i>=B-K+1) cout<<i<<"\n";
        }
    }
    return 0;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, A, B;
  cin >> n >> A >> B;
  vector<int> x(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }  
  long long ans = 0;
  for (int i = 0; i < n - 1; i++) {
    ans += min(A * 1LL * (x[i + 1] - x[i]), B * 1LL);
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000



int main(){
	
	int N;
	cin>>N;
	
	vector<double> x(N),y(N);
	
	vector<int> a(N);
	
	for(int i=0;i<N;i++){
		cin>>x[i]>>y[i];
		a[i]=i;
	}
	
	double ans = 0.0;
	
	do{
		double now = 0.0;
		for(int i=0;i<N-1;i++){
			now += sqrt(pow(x[a[i]]-x[a[i+1]],2)+pow(y[a[i]]-y[a[i+1]],2));
		}
		ans += now;
	}
	while(next_permutation(a.begin(),a.end()));
	
	for(int i=0;i<N;i++){
		ans /= (double)(i+1);
	}
	
	cout<<fixed<<setprecision(10)<<ans<<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;

int main() {
  vector<vector<int>> a(3, vector<int>(3));
  rep(i,3){
    rep(j,3) {
      cin >> a.at(i).at(j);
    }
  }
  
  vector<vector<bool>> c(3,vector<bool>(3,false));
  
  int n;
  cin >> n;
  int b;
  rep(i,n) {
    cin >> b;
    rep(j,3) {
      rep(k,3) {
        if (b == a.at(j).at(k)) {
          c.at(j).at(k) = true;
        }
      }
    }
  }
  
  rep(i,3) {
    if (c.at(i).at(0) && c.at(i).at(1) && c.at(i).at(2)) {
      cout << "Yes" << endl;
      return 0;
    }
    if (c.at(0).at(i) && c.at(1).at(i) && c.at(2).at(i)) {
      cout << "Yes" << endl;
      return 0;
    }
    if (c.at(0).at(0) && c.at(1).at(1) && c.at(2).at(2)) {
      cout << "Yes" << endl;
      return 0;
    }
    if (c.at(0).at(2) && c.at(1).at(1) && c.at(2).at(0)) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, K;
  cin >> A >> B >> K;
  for (int i =min(A, B); i>= 1; --i){
    if (A % i == 0 && B % i == 0){
      K--;
      if (K == 0){
        cout << i << endl;
      }
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
//#define _GLIBCXX_DEBUG

signed main() {
  int N; cin >> N;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  
  unordered_map<int,int> map;
  rep(i, N) map[A[i]]++;
  
  int ans = 0;
  for(auto p : map) ans += p.second*(p.second-1)/2;
  
  rep(i, N) {
    cout << ans-map[A[i]]+1 << endl;
  }

}

Measured memory_bytes: 9160
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	int n, m;
	int c, cnt;
	char b[1000000];
	while (cin >> n, n)
	{
		cin >> m;
		cnt = 0;
		//cout << "AA" << endl;
		for (int i = 0;i<m;i++)
		{
			cin >> b[i];
		}
		//cout << "BB" << endl;
		for (int i = 0;i<m;i++)
		{
			//cout << "CC" << i;
			c = 0;
			while (b[i] == 'I'&&i < m)
			{
				//cout << "DD" << i;
				i++;
			}
			while (b[i] == 'O'&&i<m - 1)
			{
				//cout << "EE" << i;
				if (b[i - 1] == 'I' && b[i + 1] == 'I')
				{
					c++;
					//cout << "E1";
					i += 2;
				}
				else
				{
					//cout << "E2";
					i++;
					break;
				}
			}
			if (c + 1 - n>0) cnt += c + 1 - n;
		}
		cout << cnt << endl;
	}
	return 0;
}

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

#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//以降 cin の入力元が 'input.txt' になる
//std::ifstream in("input.txt");
//std::cin.rdbuf(in.rdbuf());

signed main()
{
    gearup;
    int n; cin >> n;
    vl d(n);
    vl num(13);
    num[0] = 1; //すでに0時にはいる
    rep(i,n){
        cin>>d[i]; //0~12
        num[d[i]]++;
    }
    rep(i,13){
        if(i == 0 || i == 12){
            if(num[i] >= 2){
                out(0);
                return 0;
            }
        }
        else{
            if(num[i] >= 3){
                out(0);
                return 0;
            }
        }
    }

    //numが1個の場合をbit全探索
    ll res = 0;
    rep(i,1<<12){
        vl table(24);
        table[0] = 1;
        table[12] = num[12];
        rep1(j,12){ //1~11まで
            if(num[j] == 2)table[24-j] = table[j] = 1;
            else if(num[j] == 1){
                if( (i >> j) & 1) table[j] = 1;
                else table[24-j] = 1;
            }
        }

        ll mi = L_INF;
        rep(ii,24){
            for(int jj = ii+1;jj<24;jj++){
                if(table[ii] && table[jj]){
                    mi = min(mi,abs(jj-ii));
                    mi = min(mi,24-abs(jj-ii));
                }
            }
        }
        res = max(res,mi);
    }
    out(res);
}

Measured memory_bytes: 3640
#include <stdio.h>
int main(){
    int N;
    scanf("%d", &N);
    char S[N+1];
    int K;
    scanf("%s %d", S, &K);
    S[N] = '\0';
    char x = S[K-1];
    for(int i=0;i<N;i++){
        if((S[i]-x)!=0){
            S[i] = '*';
        }
    }
    printf("%s", S);
    return 0;
}

Measured memory_bytes: 128
// We only fail when we stop trying
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define endl '\n'
#define D(x) cerr << #x << " = " << (x) << '\n'
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()

const int N = 2e5 + 5;
const int Mod = 1e9 + 7;

int n;
vector<int> g[N];
int sub[N];
long long fact[N], invFact[N], inv[N];
long long psub[N], ans[N];

long long mypow(int a, int b) {
  if(!b) return 1;
  long long r = mypow(a, b >> 1);
  r = r * r % Mod;
  if(b & 1) r = (r * a) % Mod;
  return r;
}

long long inver(int a) {
  return mypow(a, Mod - 2);
}

long long C(int n, int k) {
  return fact[n] * invFact[k] % Mod * invFact[n - k] % Mod;
}

void dfs(int u, int p) {
  sub[u] = 1;
  for(int v : g[u])
    if(v != p) {
      dfs(v, u);
      sub[u] += sub[v];
    }
  psub[u] = 1;
  int cur = sub[u] - 1;
  for(int v : g[u]) {
    if(v == p) continue;
    psub[u] *= C(cur, sub[v]) * psub[v] % Mod;
    psub[u] %= Mod;
    cur -= sub[v];
  }
}

void dfs2(int u, int p) {
  if(p == -1) ans[u] = psub[u];
  else ans[u] = ans[p] * inver(C(n - 1, sub[u])) % Mod * C(n - 1, sub[u] - 1) % Mod;
  for(int v : g[u])
    if(v != p) {
      dfs2(v, u);
    }
}

int main()
{
  inv[1] = 1;
  for(int i = 2 ; i < N ; i++)
    inv[i] = Mod - Mod / i * inv[Mod % i] % Mod;
  fact[0] = invFact[0] = 1;
  for(int i = 1 ; i < N ; i++) {
    fact[i] = (fact[i - 1] * i) % Mod;
    invFact[i] = (invFact[i - 1] * inv[i]) % Mod;
  }
  cin >> n;
  for(int i = 1 ; i < n ; i++) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    g[a].pb(b);
    g[b].pb(a);
  }
  dfs(0, -1);
  // for(int i = 0 ; i < n ; i++)
  //   cout << psub[i] << " ";
  // cout << endl;
  dfs2(0, -1);
  for(int i = 0 ; i < n ; i++)
    cout << ans[i] << endl;
  return 0;
}


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

int main()
{
    int A, B, C;
    cin >> A >> B >> C;
    if(A == B) cout << C << endl;
    else if(B == C) cout << A << endl;
    else cout << B << endl;
    return 0;
}

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

#define endl '\n'

map <int, int> cnt;

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

    int n;
    cin >> n;
    for(int i = 0; i < n; i++) {
        int v;
        cin >> v;
        cnt[v]++;
    }
    long long res = 0;
    for(auto v : cnt) {
        int a = v.first;
        int b = v.second;
        if(a > b) {
            res += b;
        }
        else if(a < b) {
            res += b - a;
        }
    }
    cout << res;

    return 0;
}

Measured memory_bytes: 4736
n,q = map(int,input().split())
s = input()
ans = [0,0]
for i in range(1,len(s)):
    ans.append(ans[i])
    if(s[i - 1:i + 1]=="AC"): ans[i + 1] += 1
for i in range(q):
    l,r = map(int,input().split())
    l -= 1
    x = ans[r] - ans[l]
    if(s[l - 1:l + 1]=="AC"): x -= 1
    print(x)

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0; i<N; i++){
    cin >> A.at(i);
  }
  
  bool judge=true;
  for(int i=0; i<N; i++){
    if(A.at(i)%2==0 && A.at(i)%3!=0 && A.at(i)%5!=0){
      judge=false;
      break;
    }
  }
  
  if(judge){
    cout << "APPROVED" << endl;
  }
  else{
    cout << "DENIED" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define speedio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;

typedef long long       ll;
typedef long double     ld;

typedef vector<int>     vi;
typedef vector<bool>    vb;
typedef vector<ll>      vll;
typedef vector<vi>      vvi;
typedef vector<vll>     vvll;
typedef vector<string>  vs;

typedef pair<int, int>  pii;
typedef pair<ll, int>   pli;
typedef pair<ll, ll>    pll;
typedef vector< pii >   vpi;
typedef vector< pll >   vpll;

// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;

#define pb           push_back
#define mod          1000000007
#define INF          1e17
#define mini         INT_MIN
#define maxo         INT_MAX
#define eb           emplace_back
#define ff           first
#define ss           second
#define re           return 
#define endl         "\n" 

#define all(c)       c.begin(),c.end()
#define be           begin()
#define en           end()
#define sz(x)        (ll)x.size()
#define mem(a,val)   memset(a,val,sizeof(a))
#define mk(x,y)      make_pair(x,y)
#define mid(s,e)     ((s)+((e)-(s))/2) 

#define fo(i,a,b)     for(ll i = (ll)(a); i <= (ll)(b); i++)
#define rf(i,a,b)    for(ll i = (ll)(a); i >= (ll)(b); i--)
#define read(a,n)    for(int i=0;i<n;i++)cin>>a[i];
#define show(a,n)    for(int i=0;i<n;i++)cout<<a[i]<<' ';cout<<endl;
#define p2(n)        (1LL << (n))
#define deb(x) cout <<#x << " = " << x << " | " << "LINE: "<<__LINE__<< endl;
template<typename... T> void rd(T&... args) { ((cin >> args), ...); }
template<typename... T> void pp(T... args) { ((cout << args << " "), ...); cout<<"\n"; }

void add(ll &x, ll y){ x += y; if(x>=mod) x %= mod; if(x<0) x = x%mod + mod; }

//============== *** START OF CODE ***




void solve()
{
       ll h,a;
    rd(h,a);
    ll ans = 0;
    if(h%a!=0)ans++;
    ans+=h/a;
    pp(ans);
    
}


void prep(){}

//=============== *** END OF CODE ***

int main(){
    speedio; cout<<fixed<<setprecision(12);

// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif

    prep();
    int t = 1;
    // cin >> t;
    while(t--)
        solve();

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

Measured memory_bytes: 3576
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
using namespace std;
class key2{
public:
    string s,t;
    key2(string a,string b){
        if(a>b){
            swap(a,b);
        }
        s=a;
        t=b;
    }
};

bool operator<(const key2 &a,const key2 &b){
    return a.s<b.s||(a.s==b.s&&a.t<b.t);
}

class data{
public:
    string s,t;
    int num;
    data(key2 a,int b){
        s=a.s;
        t=a.t;
        num=b;
    }
    void out(){
        cout<<s<<" "<<t<<endl;
    }
};

int main(){
    int N,F;
    cin>>N>>F;
    map<key2,int> use;
    for(int i=0;i<N;++i){
        int time;
        cin>>time;
        vector<string> buylist(time);
        for(int j=0;j<time;++j){
            cin>>buylist[j];
        }
        for(int j=0;j<time;++j){
            for(int k=j+1;k<time;++k){
                key2 d(buylist[j],buylist[k]);
                map<key2,int>::iterator itr = use.find(d);
                if(itr==use.end()){
                    use[d]=1;
                }else{
                    ++use[d];
                }
            }
        }
    }
    int ans=0;
    vector<data> anslist;
    for(map<key2,int>::iterator itr=use.begin();itr!=use.end();++itr){
        if(itr->second>=F){
            anslist.push_back(data(itr->first,itr->second));
            ++ans;
        }
    }
    cout<<ans<<endl;
    for(int i=0;i<ans;++i){
        anslist[i].out();
    }
}

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

bool is_yymm(unsigned, unsigned);

int main()
{
    unsigned s;
    cin >> s;
    unsigned upper = s / 100;
    unsigned lower = s % 100;

    if (is_yymm(upper, lower))
    {
        if (is_yymm(lower, upper))
        {
            cout << "AMBIGUOUS" << endl;
        }
        else
        {
            cout << "YYMM";
        }
    }
    else if (is_yymm(lower, upper))
    {
        cout << "MMYY";
    }
    else
    {
        cout << "NA";
    }

    return 0;
}

bool is_yymm(unsigned yy, unsigned mm)
{
    return (yy >= 0 && yy <= 99) && (mm >= 1 && mm <= 12);
}

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

using namespace std;
using namespace __gnu_pbds; 

# define ll long long
# define pll pair<ll,ll>
# define F first
# define S second
# define pb push_back
# define ld long double
# define vll vector<ll>
# define vpll vector<pll>
# define ppll pair<pll,ll>
ll M=1000000007;
ll MAX=LONG_LONG_MAX;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2){
			ans*=a;
			ans%=(mod);
		}
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}

int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        ll t=1;
      //  cin>>t;
        while(t--)
        {
         ll n,i,j,k,x=INT_MAX,m,a;
         cin>>n>>k;
         vector<ll>v(n);
         vector<bool>dp(k+1,0);
         for(i=0;i<n;i++)
         {
             cin>>a;
             v[i]=a;
             x=min(x,a);
             dp[a]=1;
         }
         for(i=x+1;i<=k;i++)
         {
             if(dp[i])
             continue;
             for(j=0;j<n;j++)
             {
                 if(i-v[j]<0)
                 break;
                 if(dp[i-v[j]]==0)
                 {
                     dp[i]=1;
                     break;
                 }
             }
         }
         if(dp[k])
         cout<<"First\n";
         else
         cout<<"Second\n";
         
         
         
         
       
        }
        
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

vector<vector<pii> > g;
vector<bool> color;

int dfs(int u, int p, ll dist) {
  color[u] = dist&1;
  for (auto ed : g[u]) {
  	if (ed.first != p) {
      dfs(ed.first, u, dist+ed.second);
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  
  int n;
  cin >> n;
  color.assign(n, 0);
  g.assign(n, vector<pii>());
  for (int i = 0, u, v, w; i < n-1; ++i) {
  	cin >> u >> v >> w;
    g[u-1].push_back({v-1, w});
    g[v-1].push_back({u-1, w});
  }
  dfs(0, -1, 0);
  for (int c : color) {
  	cout << c << "\n";
  }
}

Measured memory_bytes: 7808
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n,sum=1;
	cin>>n;
	if(n==1) {
		cout<<1<<endl;
		return 0;
	}
	for(int i=1; i<=100; i++) {
		sum=sum*2;
		if(n>=sum&&n<sum*2) {
			cout<<sum<<endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
N=int(input())
K=int(input())

from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

L=len(str(N))
ans=0
if L-1>=K:
    ans=cmb(L-1,K)*(9**K)

List=[]
for i in range(1,10):
    List.append(i*10**(L-1))

import sys
if K==1:
    for i in List:
        if i<=N:
            ans+=1
        else:
            print(ans)
            sys.exit()
    print(ans)
elif K==2:
    for i in List:
        for j in range(L-1):
            for k in range(1,10):
                T=i+k*10**j
                if T<=N:
                    ans+=1
                else:
                    print(ans)
                    sys.exit()
    print(ans)
elif K==3:
    for i in List:
        for j in range(L):
            for k in range(j+1,L-1):
                T=i+9*10**j+9*10**k
                if T<=N:
                    ans+=81
                else:
                    for l in range(1,10):
                        for m in range(1,10):
                            T=i+m*10**j+l*10**k
                            if T<=N:
                                ans+=1
                            else:
                                continue
    print(ans)
else:
    print(0)

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
int n,t,a[1000010],now,maxx;
long long ans;
int main(void)
{
	scanf("%d%d",&n,&t);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
	{
		ans+=a[i]+t-max(maxx,a[i]);
		maxx=a[i]+t;
	}
	cout<<ans;
}

Measured memory_bytes: 1024
S = input()
N = len(S)
if S == S[::-1] and S[:int((N-1)/2)] == S[:int((N-1)/2)][::-1] and S[(int((N+3)/2)-1):] == S[(int((N+3)/2)-1):][::-1]:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

    public class Program
    {
        public static void Main(string[] args)
        {
            new B().test();
        }
    }
	public class B
	{
		public void test()
		{
			// N日とM個
			var inputDay = CommonRead.ReadIntL();
			// M個の宿題のかかる日数
			var inputDays = CommonRead.ReadIntL();

			var resultDay = inputDay[0];

			var sumDay = inputDays.Sum();

			if (resultDay >= sumDay)
			{
				Console.WriteLine(resultDay - sumDay);
			}
			else
			{
				//出力
				Console.WriteLine("-1");
			}

		}
	}
static class CommonRead
{
    public static string ReadStr()
    {
        return Console.ReadLine();
    }
    public static string[] ReadStrA()
    {
        return ReadStr().Split(' ');
    }
    public static List<string> ReadStrL()
    {
        return ReadStrA().ToList();
    }
    public static int ReadInt()
    {
        return Convert.ToInt32(ReadStr());
    }
    public static int[] ReadIntA()
    {
        return ReadStrA().Select(s => Convert.ToInt32(s)).ToArray();
    }
    public static List<int> ReadIntL()
    {
        return ReadStrA().Select(s => Convert.ToInt32(s)).ToList();
    }
    public static long ReadLong()
    {
        return Convert.ToInt64(ReadStr());
    }
    public static long[] ReadLongA()
    {
        return ReadStrA().Select(s => Convert.ToInt64(s)).ToArray();
    }
    public static List<long> ReadLongL()
    {
        return ReadStrA().Select(s => Convert.ToInt64(s)).ToList();
    }

    public static decimal ReadDecimal()
    {
        return Convert.ToDecimal(ReadStr());
    }
    public static decimal[] ReadDecimalA()
    {
        return ReadStrA().Select(s => Convert.ToDecimal(s)).ToArray();
    }
    public static List<decimal> ReadDecimalL()
    {
        return ReadStrA().Select(s => Convert.ToDecimal(s)).ToList();
    }

    public static double ReadDouble()
    {
        return Convert.ToDouble(ReadStr());
    }
    public static double[] ReadDoubleA()
    {
        return ReadStrA().Select(s => Convert.ToDouble(s)).ToArray();
    }
    public static List<double> ReadDoubleL()
    {
        return ReadStrA().Select(s => Convert.ToDouble(s)).ToList();
    }

}




Measured memory_bytes: 20480
import java.io._
import scala.io.StdIn.{readInt, readLine}

object Main {
  val out:BufferedWriter =
    new BufferedWriter(new OutputStreamWriter(new FileOutputStream(java.io.FileDescriptor.out), "ASCII"), 512)
  var count = 0
  class Node(var key:Int, var left:Node = null, var right:Node = null) { }

  def insert(node:Node, keyNode:Node):Unit =
    if(node.key > keyNode.key) {
      if(node.left == null) node.left = keyNode
      else insert(node.left, keyNode)
    } else {
      if(node.right == null) node.right = keyNode
      else insert(node.right, keyNode)
    }

  def inOrder(tree:Node):Unit =
    if(tree == null) return
    else {
      inOrder(tree.left)
      out.write(" ")
      out.write(tree.key.toString)
      if(count<100) count += 1
      else {
        out.flush
        count = 0
      }
      inOrder(tree.right)
    }

  def preOrder(tree:Node):Unit =
    if(tree == null) return
    else {
      out.write(" ")
      out.write(tree.key.toString)
      if(count<100) count += 1
      else {
        out.flush
        count = 0
      }
      preOrder(tree.left)
      preOrder(tree.right)
    }

  def main(args:Array[String]) = {
    val n = readInt
    val tree = new Node(-1)

    for(i<-0 until n) {
      val s = readLine.split(" ")
      s(0) match {
        case "insert" =>
          if(tree.key == -1) tree.key = s(1).toInt
          else insert(tree, new Node(s(1).toInt))
        case _ => {
          inOrder(tree)
          out.write("\n")
          out.flush()
          preOrder(tree)
          out.write("\n")
          out.flush()
        }
      }
    }
  }
}

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

namespace ABCO087A
{
    class Program
    {
        static void Main(string[] args)
        {
            int x, a, b, c;

            x = int.Parse(Console.ReadLine());
            a = int.Parse(Console.ReadLine());
            b = int.Parse(Console.ReadLine());

            c = (x - a) % b;

            Console.WriteLine(c);

            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
#define int long long 

int32_t main() {
  ios::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);

  int n;
  cin >> n;

  vector<vector<int>> g(n);
  for (int i = 1; i < n; ++i) {
    int u, v;
    cin >> u >> v;
    --u; --v;

    if (u > v) swap(u, v);
    g[u].push_back(v);
  }
  
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    ans += i * (i + 1) / 2;
  }
  for (int i = 0; i < n; ++i) {
    for (auto j : g[i]) {
      ans -= (i + 1) * (n - j);
    }
  }
  cout << ans << '\n';
}


Measured memory_bytes: 14268
#include <bits/stdc++.h>
#define f(i,n) for(int i=0;i<n;i++)
#define P pair<int,int>
#define F first
#define S second
#define int long long
#define mod 1000000007
#define mmod 998244353
#define all(v) v.begin(), v.end()
#define INF LLONG_MAX/3
using namespace std;
int mypow(int a, int b, int c) {
	if (b == 0)return 1;
	if (b % 2)return mypow(a, b - 1, c)*a%c;
	int z = mypow(a, b / 2, c);
	return z * z%c;
}
signed main() {
	int a, b;
	cin >> a >> b;
	cout << a * (a - 1) / 2 + b * (b - 1) / 2 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<tuple>
#include<ctime>
#include<functional>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p; 
#define rep(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))

int main(){
    ll N,K,d[1010]={0},A[1010]={0},cnt[1010]={0},t=0;
    cin>>N>>K;
    for(ll i=1;i<=K;i++){
        cin>>d[i];
        for(ll j=1;j<=d[i];j++){
            cin>>A[j];
            cnt[A[j]]++;
        }
    }
    for(ll i=1;i<=N;i++) {
        if(cnt[i]==0) t++;
    }
    p(t);

}

Measured memory_bytes: 3660
import scala.io.StdIn
import scala.collection.mutable

object Main extends App {
  val Array(n, k, q)  = StdIn.readLine().split(" ").map(_.toInt)

  var cnt : mutable.Map[Int, Int] = mutable.Map()

  (1 to q).foreach { i =>
    val j =  StdIn.readLine().toInt
    val v = cnt.getOrElse(j, 0)
    cnt += (j -> (v + 1))

  }

  (1 to n).map { i =>

    val condition = cnt.getOrElse(i, 0) + k - q
    if (condition > 0) "Yes" else "No"
  }.foreach { v => println(v) }
}


Measured memory_bytes: 45936
#include <iostream>
#include <cstdio>
#include <map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

const int maxn=100000;

int main(){
    
    ll cnt=0;
    ll ans=0;
    ll mini=INF;
    int n;
    cin >> n;
    
    rep(i,n){
        ll a;
        cin >> a;
        ans+=abs(a);
        if(a<0)cnt++;
        mini=min(mini,abs(a));
    }
    
    //cout << ans<<endl;
    
    if(cnt%2==0){
        cout << ans<<endl;
    }else{
        cout << ans-2*mini<<endl;
    }
    
    
    
    return 0;
}


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

using namespace std;

int main(){
	long long w,h,i,j;
	
	while(1){
		cin>>w>>h;
		if(w==0 && h==0) break;
		for(i=1;i<=w;i++){
			for(j=1;j<=h;j++){
				cout<<"#";
			}
			cout<<"\n";
		}
		cout<<"\n";
	}
}


Measured memory_bytes: 3036
#include<iostream>
#include<algorithm>
#define INF 1000000000
using namespace std;
int N;
long long W,w[110],v[110];
long long dp[110][100100];//dp[i][j],i-1番目まで選んでvがjであるときの重さの最小値
int sum = 0;
int main(void){
    cin >> N >> W;
    for(int i = 0; i < 110; i++){
        for(int j = 0; j < 100100; j++){
            dp[i][j] = INF;
            }
        }
    dp[0][0] = 0;
    for(int i = 0; i < N; i++){
        cin >> w[i] >> v[i];
        sum += v[i];
        }
    for(int i = 0; i < N; i++){
        for(int s = 0; s <= sum; s++){
            if(s - v[i] >= 0)dp[i + 1][s] = min(dp[i][s - v[i]] + w[i], dp[i][s]);
            dp[i + 1][s] = min(dp[i + 1][s], dp[i][s]);
            }
        }
    int maxs = 0;
    for(int i = 0; i <= sum; i++){
        if(dp[N][i] > W) continue;
        maxs = max(i, maxs);
        }
    cout << maxs << "\n";
    }

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

int main(){
  string s;
  int k;
  cin >> s >> k;
  set<string> st;
  int n = s.size();
  for(int i=0; i<n; ++i) for(int j=1; i+j<=n && j <= 5; ++j){
    string ns = s.substr(i,j);
    if(st.size() >5){
      if(*st.rbegin() > ns){
        st.insert(ns);
        st.erase(*st.rbegin());
      }
    }
    else st.insert(ns);
  }
  auto it = st.begin();
  for(int i=1; i<k; ++i) ++it;
  cout << *it << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lowbit(a) ((a) & -(a))
#define clean(a, b) memset(a, b, sizeof(a))
#define eps (-1e8)
#define make_pair P
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int maxn = 3e5 + 9;

int _;



int main()
{
    string s,t;
    cin>>s>>t;
    int lens=s.size();
    int lent=t.size();
    int ans=inf;
    for(int i=0;i<lens;i++)
    {

    		int flag=0,num=0;//yes
    		for(int j=0;j<lent;j++)
    		{
    			if(i+j>=lens)
    			{
    				flag=1;
    				break;
				}
    			if(s[i+j]!=t[j]) 
				{
					num++;
				}
			}
			if(!flag) ans=min(ans,num);
	}
	printf("%d\n",ans);
    return 0;
}
 

Measured memory_bytes: 3728
#include <stdio.h>

void swap(int* a,int* b);

int main(void) {

  int w,n;
  int seq[50];
  int a,b;
  int i;
  
  scanf("%d",&w);

  for(i=0;i<w;i++) {
    seq[i]=i+1;
  }
  
  scanf("%d",&n);

  for(i=0;i<n;i++) {
    scanf("%d,%d",&a,&b);
    swap(&seq[a-1],&seq[b-1]);
  }

  for(i=0;i<w;i++) {
    printf("%d\n",seq[i]);
  }

  return 0;
}

void swap(int* a,int* b) {
  int temp;

  temp=*a;
  *a=*b;
  *b=temp;
}

Measured memory_bytes: 0