akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
//define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
// 許容する誤差ε
#define EPS (1e-10)
// 2つのスカラーが等しいかどうか
#define EQ(a,b) (abs((a)-(b)) < EPS)
// 2つのベクトルが等しいかどうか
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
//template
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
      }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void print(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void print(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
//typedef
typedef complex<double> Point;
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;



vector<int> G[200000];
int dfs(int u){
  int d = 0;
  vector<int> vec;
  rep(i,G[u].size()){
    vec.pb(dfs(G[u][i]));
  }
  sort(all(vec), greater<int>());
  rep(i,vec.size())chmax(d, vec[i]+i+1);
  return d;
}
signed main(){
  int n;cin >> n;
  repi(i,2,n+1){
    int x;cin >> x;
    G[x].pb(i);
  }
  int ans = dfs(1);
  cout << ans << endl;
	return 0;
}










Measured memory_bytes: 15872
#include <iostream>
#include <cmath>

using namespace std;

long long f(long long b, long long n){
    if(n < b){
        return n;
    }
    return f(b, n / b) + n % b;
}

int main(void){
    long long n;
    long long s;
    cin >> n >> s;
    
    if(n < s){
        cout << - 1 << endl;
        return 0;
    }
    if(n == s){
        cout << n + 1 << endl;
        return 0;
    }
    
    for(int b = 2; b < (int) sqrt(n) + 1; b++){
        if(f(b, n) == s){
            cout << b << endl;
            return 0;
        }
    }
    
    long long b = -1;
    for(int p = 1; p < (int) sqrt(n) + 1; p++){
        if((n - s) % p == 0){
            long long tmp_b = (n - s) / (long long) p + 1;
            if(f(tmp_b, n) == s){
                b = tmp_b;
            }
        }
    }
    
    if(b < 0){
        cout << - 1 << endl;
    } else {
        cout << b << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n, m;
	vector<double> l(20), a(20), b(20);
	cin >> n >> m;
	for (int i = 0; i < n; i++)
	{
		cin >> l[i] >> a[i] >> b[i];
	}
	double ans;
	for (int i = 0; i < (1 << n); i++)
	{
		int t = i;
		int cnt = 0;
		while (t > 0)
		{
			if (t & true)
				cnt++;
			t >>= 1;
		}
		if (cnt != m)
			continue;
		double tmp_ans = 0;
		for (int j = 0; j < n; j++)
		{
			for (int k = j + 1; k < n; k++)
			{
				if ((i >> j) & 1 && (i >> k) & 1)
				{
					tmp_ans += pow(l[j] - l[k], 2);
					tmp_ans += pow(a[j] - a[k], 2);
					tmp_ans += pow(b[j] - b[k], 2);
				}
			}
		}
		if (tmp_ans > ans)
			ans = tmp_ans;
	}
	cout << fixed << setprecision(6) << ans << endl;
	return 0;
}



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

using namespace std;
int main() {
    int h, w;
    string row [52];

    cin >> h >> w;

    row[0] = string(52, '.');
    for (int y = 0; y < h; y++) {
        string s;
        cin >> s;
        row[y+1] = "." + s +".";
    }
    row[h+1] = string(52, '.');

    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            int num_bomb = 0;

            if (row[y+1][x+1] == '#') {
                cout << '#';
                continue;
            }

            for (int dy = -1; dy <= 1; dy++) {
                for (int dx = -1; dx <= 1; dx++) {
                    if (row[y+1+dy][x+1+dx] == '#') {
                        num_bomb++;
                    }
                }
            }
            cout << num_bomb;
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 256
n=int(input())
s=input()

count = s.count('R')*s.count('B')*s.count('G')

for i in range(n-2):
    for j in range(i+1, n-1):
        k = 2*j-i
        if k > n-1:
            break
        if (s[i] != s[j]) and (s[i] != s[k]) and (s[j] != s[k]):
            count -= 1

print(count)

Measured memory_bytes: 9192
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define modulo 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60


using Edge = pair<int, long long>;
using Graph = vector<vector<Edge>>;


ll dist[100001]; // Kからの距離

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

	int N; cin >> N;
	Graph G(N + 1);

	for (int i = 0; i < N - 1; i++) {
		int a, b; ll weight;
		cin >> a >> b >> weight;
		G[a].push_back({ b,weight });
		G[b].push_back({ a,weight });
	}

	int Q, K; cin >> Q >> K;

	for (int i = 1; i <= N; i++) dist[i] = -1;

	// 深さ優先探索
	stack<int> S;
	dist[K] = 0;
	S.push(K);
	while (!S.empty()) {
		int current_pos = S.top();
		S.pop();
		for (auto e : G[current_pos]) {
			if (dist[e.first] == -1) {
				dist[e.first] = dist[current_pos] + e.second;
				S.push(e.first);
			}
		}
	}

	queue<ll> Ans;

	for (int i = 0; i < Q; i++) {
		int start, goal;
		cin >> start >> goal;
		Ans.push(dist[start] + dist[goal]);
	}

	while (!Ans.empty()) {
		cout << Ans.front() << endl;
		Ans.pop();
	}

	return 0;
}

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

int main() {
  int n, m, x, ans = INT_MAX;

  cin >> n >> m >> x;

  vector<vector<int>> c(n, vector<int>(m + 1));
  vector<int> a(m + 1, 0);

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m + 1; j++) {
      cin >> c.at(i).at(j);
    }
  }

  for (int bit = 0; bit < (1 << n); ++bit) {
    for (int i = 0; i < m + 1; i++) {
      a.at(i) = 0;
    }

    vector<int> S;

    for (int i = 0; i < n; ++i) {
      if (bit & (1 << i)) {
        S.push_back(i);
      }
    }
    int price = 0;

    for (int i = 0; i < (int)S.size(); ++i) {
      price += c.at(S.at(i)).at(0);
      for (int j = 1; j < m + 1; j++) {
        a.at(j) += c.at(S.at(i)).at(j);
      }
    }

    bool flag = true;
    for (int i = 1; i < m + 1; i++) {
      if (a.at(i) < x) {
        flag = false;
        break;
      }
    }

    if (flag == true && ans > price) ans = price;
  }

  if (ans == INT_MAX) {
    cout << -1;
    return 0;
  }
  cout << ans;

  return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; ++i)
typedef long long ll;
using namespace std;
const int INF = 1e9;

int main() {
    int D;
    cin >> D;
    int d[26];
    vector<int> last(26, 1);

    rep(i, 26) {
        cin >> d[i];
    }

    vector<vector<int>> s(D, vector<int>(26));
    rep(i, D) rep(j, 26) cin >> s[i][j];

    vector<int> ans(D);

    ll level = 0;
    rep(i, D) {
        ll now = 0;
        ll maxnow = -INF;

        if (i <= D - 3) {
            maxnow = -INF;
            rep(j, 26) {
                rep(k, 26) {
                    rep(l, 26) {
                        now = 0;
                        int t[3] = {j, k, l};
                        vector<int> tlast = last;

                        rep(m, 3) {
                            now += s[i + m][t[m]];
                            tlast[t[m]] = 0;

                            rep(n, 26) {
                                now -= d[n] * tlast[n];
                                tlast[n]++;
                            }
                        }

                        //更新
                        if (now > maxnow) {
                            maxnow = now;
                            ans[i] = j;
                            ans[i + 1] = k;
                            ans[i + 2] = l;
                        }
                    }
                }
            }
        }
        //計算
        level += s[i][ans[i]];
        last[ans[i]] = 0;
        rep(j, 26) {
            level -= d[j] * last[j];
            last[j]++;
        }
    }

    vector<int> koho(D);
    koho = ans;

    mt19937 rd(0);
    while (clock() * 1000 / CLOCKS_PER_SEC <= 1900) {
        koho = ans;
        vector<int> tlast(26, 1);
        koho[rd() % D] = rd() % 26;

        ll tmp = 0;
        rep(i, D) {
            tmp += s[i][koho[i]];
            tlast[koho[i]] = 0;

            rep(j, 26) {
                tmp -= d[j] * tlast[j];
                tlast[j]++;
            }
        }

        if (tmp > level) {
            ans = koho;
            level = tmp;
        }
    }

    rep(i, D) {
        cout << ans[i] + 1 << "\n";
    }

    return 0;
}


Measured memory_bytes: 3672
#include <iostream>
#include <string>
using namespace std;
int A[1005][1005]={};

int main() {
  int i,j,k,q;
  cin >> q;
  string a,b;
  for(i=0;i<q;i++) {
    cin  >> a >> b;
    int al = a.size();
    int bl = b.size();
    for(j=1;j<=al;j++) {
      for(k=1;k<=bl;k++) {
        if(a[j-1]==b[k-1]) {
          A[j][k]=A[j-1][k-1]+1;
        } else {
          A[j][k]=max(A[j][k-1],A[j-1][k]);
        }
      }
    }
    cout << A[al][bl] << endl;
  }
  return 0;
}


Measured memory_bytes: 7052
v = []
rem = []

A = int(input())
v.append(A)
rem.append(A % 10)

B = int(input())
v.append(B)
rem.append(B % 10)

C = int(input())
v.append(C)
rem.append(C % 10)

D = int(input())
v.append(D)
rem.append(D % 10)

E = int(input())
v.append(E)
rem.append(E % 10)

ind = 0
m = 150
count = 0
for i in rem:
    if i != 0 and m > i:
        m = i
        ind = count
    count += 1

count = 0
ans = 0
for i in v:
    if count == ind:
        ans += i
    else:
        if i % 10 != 0:
            tmp = (int(i/10)+1)*10
            ans += tmp
        else:
            ans += i
    count += 1

print(ans)

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

namespace A
{
    class Program
    {
        public static void Main(string[] args)
        {
            var s = ReadLineIntSpilit();

            var result = 0;

            var a = s[0] * s[1];
            var b = s[2] * s[3];

            Console.WriteLine(Math.Max(a, b));
            ReadLine();
        }

        /// <summary>
        /// コンビネーション
        /// </summary>
        /// <param name="n"></param>
        /// <param name="m"></param>
        /// <returns></returns>
        static int nCm(int n, int m)
        {
            if (m == 0) return 1;
            if (n == 0) return 0;
            return n * nCm(n - 1, m - 1) / m;
        }

        /// <summary>
        /// stringを一文字ずつintにキャストして配列に変換します。
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static int[] StringCharArrayIntArray(string str)
        {
            List<int> b = new List<int>();
            for (int i = 0; i < str.Length; i++) {
                b.Add( int.Parse(str[i].ToString()));
            }
            return b.ToArray();
        }

        public static string ReadLine()
        {
            return Console.ReadLine();
        }

        public static int ReadLineInt()
        {
            return int.Parse(Console.ReadLine());
        }

        public static string[] ReadLineStringSplit(char a = ' ')
        {
            return ReadLine().Split(a).ToArray();
        }

        public static int[] ReadLineIntSpilit(char a = ' ')
        {
            return ReadLine().Split(a).Select(x => int.Parse(x)).ToArray();
        }

        static string[] GetAplhaLowerArray() => new string[]{ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
        static string[] GetAplhaUpperArray() => new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
    }
}

Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
int dx[]={0,0,1,-1},dy[]={1,-1,0,0};
int v[505][505],dis[505][505];
int n;
void dfs(int x,int y){
	for(int asp=0;asp<4;++asp){
		int x1=x+dx[asp],y1=y+dy[asp];
		if(dis[x][y]+v[x][y]<dis[x1][y1]){
			dis[x1][y1]=dis[x][y]+v[x][y];
			dfs(x1,y1);
		}
	}
}
int main(){
	int n; scanf("%d",&n);
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j){
			v[i][j]=1;
			dis[i][j]=min({i-1,j-1,n-i,n-j});
		}
	int ans=0;
	for(int i=1;i<=n*n;++i){
		int t; scanf("%d",&t);
		int x=(t-1)/n+1,y=(t-1)%n+1;
		v[x][y]=0;
		ans+=dis[x][y];
		dfs(x,y);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 21168
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		int B = sc.nextInt();
		if(A == 2 || B == 2){
			System.out.println("No");
		} else {
			System.out.println("Yes");
		}
		
	}
}



Measured memory_bytes: 22612
//                             In The Name Of Allah                                           
#include <bits/stdc++.h>
#define	ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define se(n) cout << setprecision(n) << fixed
#define pb push_back
#define int long long
#define ld long double
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std; 
const int N = 1e5 + 100, OO = 1e9 + 7, K = 1e7 + 4, T = 22, M = 1e9 + 7, P = 6151, SQ = 1300, lg = 22;
typedef pair <int, int> pii;
int n, cnt, ans;
int a[N], b[N], x[N], y[N];
bool vis[N];
vector <int> Q[N];
map <int, int> d;

void dfs(int x) {
    vis[x] = 1;
    for(auto u : Q[x]) 
    	if(!vis[u]) 
			dfs(u);
}

int32_t main() {
	use_fast;
	cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
		a[n + 1] ^= a[i];
        if(!d[a[i]]) 
			d[a[i]] = ++cnt;
    }
    if(!d[a[n + 1]]) 
		d[a[n + 1]] = ++cnt;
    for(int i = 1; i <= n; i++) {
        cin >> b[i];
		b[n + 1] ^= b[i];
        if(!d[b[i]]) 
			d[b[i]] = ++cnt;
    }
    if(!d[b[n + 1]]) 
		d[b[n + 1]] = ++cnt;
    memcpy(x, a, sizeof x);
	memcpy(y, b, sizeof y);
    sort(x + 1, x + n + 2);
	sort(y + 1, y + n + 2);
    for(int i = 1; i <= n; i++) 
    	if(x[i] != y[i]) 
			return cout << -1, 0;
    for(int i = 1; i <= n + 1; i++) 
    	a[i] = d[a[i]], b[i] = d[b[i]];
    for(int i = 1; i <= n; i++) 
    	if(a[i] != b[i]) 
			ans++, Q[a[i]].pb(b[i]);
    if(a[n + 1] != b[n + 1]) 
		Q[a[n + 1]].pb(b[n + 1]);
    for(int i = 1; i < cnt; i++) 
    	if((int)Q[i].size() && !vis[i]) 
			dfs(i), ans++;
    if(!vis[cnt]) 
		ans++;
    cout << ans - 1 << endl;
	return 0;
}

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

typedef long long ll;

int main(){
  ll N, M;
  std::cin >> N >> M;
  std::vector<ll> H(N);
  std::vector<ll> A(M);
  std::vector<ll> B(M);
  for(int i = 0 ; i < N ; i++) std::cin >> H[i];
  for(int i = 0 ; i < M ; i++){
    std::cin >> A[i] >> B[i];
    A[i]--;
    B[i]--;
  }

  std::vector<bool> judge(N, true);
  for(int i = 0 ; i < M ; i++){
    if(H[ A[i] ] > H[ B[i] ]){
      judge[ B[i] ] = false;
      continue;
    }
    if(H[ A[i] ] < H[ B[i] ]){
      judge[ A[i] ] = false;
      continue;
    }
    if(H[ A[i] ] == H[ B[i] ]){
      judge[ A[i] ] = judge[ B[i] ] = false;
      continue;
    }
  }
  ll resa = std::count(judge.begin(), judge.end(), true);
  std::cout << resa << std::endl;
  return 0;
}


Measured memory_bytes: 5592
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n;
    cin>>n;
    vector<long long>a(n),b(n),diff(n);
    for(long long i=0;i<n;i++)
        cin>>a[i];
    for(long long i=0;i<n;i++)
        cin>>b[i];
    for(long long i=0;i<n;i++)
        diff[i]=a[i]-b[i];
    long long x=0;
    for(long long i=0;i<n;i++)
        if(a[i]<b[i])
        x=1;
    if(x==0)
    {
        cout<<"0";
        return 0;
    }
    else
    {
        long long asum=0,bsum=0;
        for(long long i=0;i<n;i++)
        {
            asum+=a[i];
            bsum+=b[i];
        }
        if(bsum>asum)
        {
            cout<<"-1";
            return 0;
        }
        else
        {
            /*for(auto i :diff)
                cout<<i << " ";
            cout<<"\n\n\n";*/
            sort(diff.begin(),diff.end());
            vector<long long>xx(diff);
           /* for(auto i :diff)
                cout<<i << " ";
            cout<<"\n\n\n";*/
            long long i=0,j=n-1,x,y;
            while(i<j)
            {
                //cout<<i <<" "<< j <<"\n";
                if(diff[i]>=0 && diff[j]>=0)
                    break;
                if(abs(diff[i])<diff[j])
                {
                    diff[j]+=diff[i];
                    diff[i]=0;
                    ++i;
                }
                else
                {
                    if(abs(diff[i])==diff[j])
                    {
                        diff[i]=0;
                        diff[j]=0;
                        ++i;
                        --j;
                    }
                    else
                    {
                        if(abs(diff[i])>diff[j])
                        {
                            diff[i]+=diff[j];
                            diff[j]=0;
                            --j;
                        }
                    }
                }
            }
            if(diff[i]==xx[i] && diff[j]!=xx[j] && i!=j)
            {
                j--;
            }
            if(diff[i]!=xx[i] && diff[j]==xx[j] && i!=j)
            {
                 i++;
            }
            if(diff[i]!=xx[i] && diff[j]!=xx[j] && i!=j)
            {
                 i++;
                 j--;
            }
            if(i==j && diff[i]!=xx[i])
                i++;
            cout<<(n-(j-i+1));
        }
    }
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x ,n) for(int i = x; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main(){
    int n;
    cin >> n;
    int a[n],b[n];
    rep(i,n){cin >> a[i];b[i]=a[i];}
    
    sort(b,b+n,greater<int>());
    rep(i,n){
        if(a[i]==b[0])cout << b[1] << endl;
        else cout << b[0] << endl;
    }
    
    
    
	return 0;
}

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

int main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("input.txt","r",stdin);
    string s1,s2;
    cin>>s1>>s2;
    for(int i=0;i<s1.size();i++){
        if(s1[i]==s2[i])continue;
        else{
            cout<<"No\n";
            return 0;
        }
    }
    cout<<"Yes\n";
    return 0;
}


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

int main()
{
   ios_base::sync_with_stdio(0);
   cin.tie(0);cout.tie(0);
   string s1,s2;
   cin>>s1>>s2;
   int l1=s1.length(),l2=s2.length(),i,j;
   int t[l1+1][l2+1];
   for(i=0;i<l1+1;i++)
   {
       for(j=0;j<l2+1;j++)
       {
           if(i==0||j==0){t[i][j]=0;continue;}
           if(s1.at(i-1)==s2.at(j-1))
           {
               t[i][j]=t[i-1][j-1]+1;
           }
           else
           {
               t[i][j]=max(t[i-1][j],t[i][j-1]);
           }
       }
   }
   string v;
   i=l1;j=l2;
   while(i!=0&&j!=0)
   {
       if(s1.at(i-1)==s2.at(j-1))
       {
            v.push_back(s1.at(i-1));
            i--;j--;
       }
       else if(t[i-1][j]>t[i][j-1])
       {
           i--;
       }
       else
       {
           j--;
       }
   }
   reverse(v.begin(),v.end());
   cout<<v<<endl;
}


Measured memory_bytes: 38780
#include <stdio.h>
#include <string.h>
#include <math.h>
#define rep(i,l,n) for(i=l;i<n;i++)

int main(void){
	int n,i,j,a[105],minj,k,c;
	
	scanf("%d",&n);
	rep(i,0,n) scanf("%d",&a[i]);
	
	k=0;
	rep(i,0,n){
		minj=i;
		rep(j,i,n){
			if(a[j]<a[minj]) minj=j;
		}
		if(minj!=i){
			k++;
			c=a[i];
			a[i]=a[minj];
			a[minj]=c;
		}
	}
	rep(i,0,n-1) printf("%d ",a[i]);
	printf("%d\n",a[n-1]);
	printf("%d\n",k);
	return 0;
}

Measured memory_bytes: 600
/*
!لَا أَبْرَحُ حَتَّىٰ أَبْلُغَ
فَصَبْرٌ جَمِيلٌ
*/
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define endl                         '\n'	
#define Ceil(x,y)             ((x+y-1)/y)
#define sz(s)               (int)s.size()
#define RT(x)           return cout<<x,0;
#define mem(x,y)    memset(x,y,sizeof(x))
#define all(v) ((v).begin()), ((v).end())
#define vi                    vector<int>
#define Rabe3_adel           file();
#define fr(x,y) for(int x=0; x<(y); ++x)
const double PI = acos(-1), EPS = 1e-7;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int dr[] { -1, -1, 0, 1, 1, 1, 0, -1 };
const int dc[] { 0, 1, 1, 1, 0, -1, -1, -1 };
ll gcd(ll x, ll y) { return (!y) ? x : gcd(y, x%y); }
ll lcm(ll x, ll y) { return ((x / gcd(x, y))*y); }
ll mod = 998244353;
ll power(ll x, ll y)
{
	if (y == 0)return 1;
	if (y == 1)return x;
	ll r = power(x, y / 2) % mod;
	return r%mod*r%mod*power(x, y % 2) % mod;
}
void file() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif  !ONLINEJUDGE
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

}

int rx[101];
int main()
{
	
	Rabe3_adel
		mem(rx, 0);
		int n, k,d,x; cin >> n>>k;
	fr(i, k)
	{
		cin >> d;
		fr(k, d)
		{
			cin >> x;
			rx[x] = 1;
			
		}

	}
	int ans = 0;
	for (int i = 1; i <= n; i++)
	{
		if (rx[i] != 1)ans++;

	}
	cout << ans;
}

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

int main(void){
	int N, M, a, b, cnt = 0;
	std::cin >> N >> M;
	std::vector<int> H(N+1, 0), ma(N+1, 0);

	for(int i = 1; i <= N; i++) std::cin >> H[i];

	for(int i = 0; i < M; i++){
		std::cin >> a >> b;
		ma[a] = std::max(ma[a], H[b]);
		ma[b] = std::max(ma[b], H[a]);
	}

	for(int i = 1; i <= N; i++)
		if(H[i] > ma[i]) cnt++;
	std::cout << cnt << std::endl;

	return 0;
}


Measured memory_bytes: 3940
//#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
//#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <list>
#include <queue>
#include <set>
using namespace std;

int main(void){

	bool check[260000] = { false };
	check[1] = true;

	for (int i = 2; i < 260000; i++){
		for (int j = 2; i*j < 260000; j++){
			check[i*j] = true;
		}
	}

	long int n;

	while (scanf("%d", &n) != EOF){
		if (n == 0) break;
		int count = 0;

		for (long int i = n + 1; i <= 2 * n; i++){
			if (!check[i]) count++;
		}

		cout << count << endl;
	}

	return 0;
}

/*
for(i=0;i<N;i++){
cin >> X[i];
}


for(i=0;i<N;i++){
for(j=0;j<N;j++){
cin >> X[i][j];
}
}
*/

Measured memory_bytes: 1468
#include <iostream>
#include <stdio.h>
int main(){
	int a,b,c,i,j,temp;
	std::cin >> a;
	std::cin >> b;
	std::cin >> c;
	
	int x[3]={a,b,c};
	int sort[3];
	for(i=0;i<3;i++){
		for(j=0;j<3;j++){
			if(x[i]>x[j]){
				temp=x[i];
				x[i]=x[j];
				x[j]=temp;
			}
		}
		sort[i]=x[i];
		x[i]=10001;
	}
		std::cout << sort[0] << " " << sort[1] << " " << sort[2] << std::endl;
	return 0;
}

Measured memory_bytes: 1164
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
bool arr[1001];
int Nmax=1001;
void Eratosthenes(){
	for(int i = 0; i < Nmax; i++){
		arr[i] = true;
	}
	arr[0]=false; arr[1]=false;
	for(int i = 2; i < sqrt(Nmax); i++){
		if(arr[i]){
			for(int j = 0; i * (j + 2) < Nmax; j++){
				arr[i *(j + 2)] = false;
			}
		}
	}
}
int main(){
	Eratosthenes();
	vint prime;
	rep(i,Nmax){
		if(arr[i]) prime.push_back(i);
	}
	ll MOD=1e+9+7;
	ll N;
	ll ans=1;
	scan(N);
	rep(i,prime.size()){
		ll waru=prime[i];
		ll soinkosu=0;
		if(waru>N) break;
		while(N/waru){
			soinkosu+=N/waru;
			waru*=prime[i];
		}
		ans*=(soinkosu+1)%MOD;
		ans%=MOD;
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
int n,i,temp;
int ai[100];
scanf("%d", &n);
for(i=0; i<n; i++){
	scanf("%d", &ai[i]);
}

for(i=0; i<n/2; i++){
	temp=ai[i];
	ai[i]=ai[n-1-i];
	ai[n-1-i]=temp;
}

for(i=0; i<n; i++){
	
  if(i<n-1){
    printf("%d ", ai[i]);
  }else{
    printf("%d\n", ai[i]);
  }
}
return 0;

}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef set<ll> sl;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second

struct DJset {
	vi parent, rank, size;

	DJset(int n) : parent(n), rank(n, 1), size(n, 1) {
		rep(i,0,n) {
			parent[i] = i;
		}
	}

	int find(int i) {
		if(i == parent[i]) return i;
		return parent[i] = find(parent[i]);
	}

	void merge(int u, int v) {
		u = find(u); v = find(v);
		if(u == v) return;
		if(rank[u] > rank[v]) swap(u, v);
		parent[u] = v;
		if(rank[u] == rank[v]) ++rank[v];
		size[v] += size[u];
	}
};

// 

int n, k;
vi v;
si a;

int main(void) {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	//freopen("in.txt", "r", stdin);
	cin >> n >> k;
	v.resize(n);
	rep(i,0,n) {
		cin >> v[i];
	}

	int i = 0;
	int j = 0;
	vi record;
	while(i <= n - k) {
		if(j == 0) {
			j++;
			continue;
		}

		if(j < k && v[(i+j)] > v[(i+j-1)]) {
			j++;
		} else {
			if(j == k) {
				record.pb(i);
				i++;
				j--;
			} else {
				i++;
				j--;
			}
		}
	}
	
	DJset myset(n-k+1);
	if(record.size() > 1) {
		rep(i,1,sz(record)) {
			myset.merge(record[i], record[i-1]);
		}
	}

	rep(i,0,k) {
		a.insert(v[i]);
	}

	rep(i,1,n-k+1) {
		bool changed = false;
		if(v[i-1] != *a.begin()) {
			changed = true;
		}
		a.erase(v[i-1]);
		a.insert(v[i+k-1]);
		if(v[i+k-1] != *a.rbegin()) {
			changed = true;
		}
		if(!changed) {
			myset.merge(i-1, i);
		}
	}

	int ret = 0;
	rep(i,0,n-k+1) {
		if(myset.find(i) == i) {
			ret++;
		}
	}
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 10368
#include<stdio.h>
int main(void)
{
    int A, B, C, x;
    
    scanf("%d %d %d", &A, &B, &C);
    
    if(A-B<C)
    {
	x = C-(A-B);
    }
    else
    {
	x = 0;
    }
    
    
    printf("%d\n", x);
    
    return 0;
    
}

Measured memory_bytes: 128
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_STORE_MAX		100000									// 最大店数

// 内部構造体 - 店情報
typedef struct Store {
	int miVal;													// 価格
	int miCnt;													// 本数
} Store;

// 内部変数
static FILE *szpFpI;											// 入力
static Store sz1Store[D_STORE_MAX];								// 店
static int siSCnt;												// 店数
static int siNCnt;												// 必要数

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// ソート関数 - 価格昇順
int
fSortFnc(
	const void *pzpVal1			// <I> 値１
	, const void *pzpVal2		// <I> 値２
)
{
	Store *lzpVal1 = (Store *)pzpVal1;
	Store *lzpVal2 = (Store *)pzpVal2;

	// 価格昇順
	if (lzpVal1->miVal > lzpVal2->miVal) {
		return 1;
	}
	else if (lzpVal1->miVal < lzpVal2->miVal) {
		return -1;
	}

	return 0;
}

// 実行メイン
long long
fMain(
)
{
	int i;
	char lc1Buf[1024];

	// 店数・必要数 - 取得
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d%d", &siSCnt, &siNCnt);

	// 店 - 取得
	for (i = 0; i < siSCnt; i++) {
		fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
		sscanf(lc1Buf, "%d%d", &sz1Store[i].miVal, &sz1Store[i].miCnt);
	}

	// 店 - ソート
	qsort(sz1Store, siSCnt, sizeof(Store), fSortFnc);

	// 最小金額 - 取得
	long long llMin = 0;
	for (i = 0; siNCnt > 0; i++) {

		// 購入本数
		int liCnt;
		if (siNCnt < sz1Store[i].miCnt) {
			liCnt = siNCnt;
		}
		else {
			liCnt = sz1Store[i].miCnt;
		}

		// 購入
		llMin += (long long)sz1Store[i].miVal * (long long)liCnt;
		siNCnt -= liCnt;
	}

	return llMin;
}

// １回実行
int
fOne(
)
{
	long long llRet;
	char lc1Buf[1024], lc1Out[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	llRet = fMain();

	// 結果 - セット
	sprintf(lc1Out, "%lld\n", llRet);

	// 結果 - 表示
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, lc1Out)) {
		siRes = -1;
	}
#else
	printf("%s", lc1Out);
#endif

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne(0);
#endif

	return 0;
}



Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define rep(i, n) for (int (i) = 0; (i) <= (int)n; (i)++)

int a, b, c, x;
int cc = 0;

int main() {
    scanf("%d %d %d %d", &a, &b, &c, &x);
    rep(i, a) {
        rep(j, b) {
            rep(k, c) {
                if (500 * i + 100 * j + 50 * k == x) {
                    cc++;   
                }
            }
        }
    }
    printf("%d", cc);
    return 0;   
}

Measured memory_bytes: 256
a,b,c = int(input()),int(input()),int(input())
X = int(input())

res = 0
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      total = 0
      total = 500*i + 100*j + 50*k
      if total == X:
        res += 1
      
print(res)

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

int main() {
  string S;
  cin >> S;
  int a;
  if (S == "SUN"s) a = 7;
  if (S == "MON"s) a = 6;
  if (S == "TUE"s) a = 5;
  if (S == "WED"s) a = 4;
  if (S == "THU"s) a = 3;
  if (S == "FRI"s) a = 2;
  if (S == "SAT"s) a = 1;
  cout << a << endl;
}

Measured memory_bytes: 256
# include<bits/stdc++.h> 
#define ll long long 
#define pb push_back 
#define mk make_pair
#define vi vector<int> 
#define loop(i,j, k ) for(int i =j ;i < k ; ++i)
using namespace std ; 


int main() {
	int n, k  ; 
	cin >> n >> k ; 
	int a[n] ; 
	loop(i,0,n) cin >> a[i] ; 
	ll dp[n] ; 
	dp[0]=0 ;  
	for(int i = 1; i < n ; ++i) {
		dp[i] = INT_MAX ; 
		for(int j = 0; j <= k ; ++j)  {
			if(i-j>=0)
			dp[i] = min(dp[i], abs(a[i] - a[i-j]) + dp[i-j]) ; 
		}
	}
	 
	cout <<  dp[n-1] ; 
}


Measured memory_bytes: 1408
#include<iostream>
#include<cstdio>
#include<cstring>
#define x first
#define y second

inline void check_max(int a,int &b){if(a>b)b=a;}

typedef std::pair<int,int> pii;

const int N=1<<20;

pii add(pii A,pii B)
{
	 check_max(B.x,A.y);
	 if(A.y>A.x)std::swap(A.x,A.y);

	 check_max(B.y,A.y);
	 if(A.y>A.x)std::swap(A.x,A.y);

	 return A;
}

int A[N];
pii f[N];

int ans[N];

int n,tot;

int main()
{
	scanf("%d",&n);
	tot=1<<n;
	for(int i=0;i<tot;i++)
		scanf("%d",A+i),f[i]=pii(A[i],0);
	for(int k=0;k<n;k++)
	{
		int x=1<<k;

		for(int i=0;i<tot;i++)
			if(!(i&x))f[i|x]=add(f[i|x],f[i]);
	}
	for(int i=1;i<tot;i++)
		ans[i]=f[i].x+f[i].y;
	for(int i=1;i<tot;i++)
	{
		printf("%d\n",ans[i]);
		check_max(ans[i],ans[i+1]);
	}
	return 0;
}


Measured memory_bytes: 10240
#include <stdio.h>

int main() {
	int H,i,A[251];
	scanf("%d", &H);

	for (i = 1; i <= H; i++) scanf("%d",&A[i]);

	for (i = 1; i <= H; i++) {
		printf("node %d: key = %d, ", i, A[i]);
		if (i / 2 >= 1) printf("parent key = %d, ", A[i / 2]);
		if (2 * i <= H) printf("left key = %d, ", A[2 * i]);
		if (2 * i + 1 <= H) printf("right key = %d, ", A[2 * i + 1]);
		printf("\n");
	}
}



Measured memory_bytes: 2760
fun main() {
    val l = readLine()!!.split(" ").map { it.toInt() }
    if(l[3]<=l[0]){
        println(l[3])
    }else if(l[3]<=l[0]+l[1]){
        println(l[0])
    }else{
        println(l[0]-(l[3]-l[0]-l[1]))
    }
}

Measured memory_bytes: 36380
#include <cstdio>
#include <cstring>

#define Rep(i, n) for (int i = 1; i <= n; i ++)
#define Rep0(i, n) for (int i = 0; i <= n; i ++)

using namespace std;

typedef long long LL;
const int N = 110;

int d[N], cd;
LL f[N][N][2][2];

LL dfs(int l, int r, int g0, int g1, int gf)
{
	if (l < r) return (g0 == g1);
	if (l == r) {
		if (!(d[l] + g1 - g0 * 10)) return 10 - gf;
		return 0;
	}
	if (f[l][r][g0][g1] != -1) return f[l][r][g0][g1];
	LL ret = 0;
	Rep0(i, 9) {
		int tmp = d[r] + i + g1, tg1 = 0;
		if (tmp >= 10) tmp -= 10, tg1 = 1;
		if (!tmp && gf) continue;
		if (d[l] + tmp - g0 * 10 == i)
			ret += dfs(l - 1, r + 1, 0, tg1, 0); 
		if (d[l] + tmp - g0 * 10 + 1 == i)
			ret += dfs(l - 1, r + 1, 1, tg1, 0);
	}
	return f[l][r][g0][g1] = ret;
}

int main()
{
	int D;
	scanf("%d", &D);
	while (D) d[++ cd] = D % 10, D /= 10;
	
	memset(f, -1, sizeof(f));
	LL ans = 0;
	for (int i = cd; i <= 18; i ++){
		ans += dfs(i, 1, 0, 0, 1);
	//	printf("%d %lld\n", i, dfs(i, 1, 0, 0, 1));
	}
	printf("%lld\n", ans);
	
	return 0;
}
/*
45936
*/

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<32;;
int n,m;
ll dis[300][300];
int main()
{
    cin >> n >> m;
        int i,j,k;
        for(i = 0;i < n;i++)
            for(j = 0;j < n;j++)
			{
				if(i == j)
					dis[i][j] = 0;
				else
                    dis[i][j] = INF;
			}
        while(m--)
        {
            int a,b,c;
            cin >> a >> b >> c;
			dis[a][b] = c;
        }
        for(k = 0 ; k<n ; k++){
        for(i = 0 ; i<n ; i++){
            if(dis[i][k] == INF)
                continue;
            for(j = 0 ; j<n ; j++){
                if(dis[k][j] == INF)
                    continue;
                dis[i][j] = min(dis[i][j] , dis[i][k]+dis[k][j]);
            }
        }
    }
    bool flag = 0;
    for( i = 0 ; i<n ; i++)
    {
        if(dis[i][i] < 0)
        {
            flag = 1;
            break;
        }
    }
        if(flag == 1)
            cout << "NEGATIVE CYCLE" << endl;
        else
        {
        for(i = 0;i < n;i++)
        {
            for(j = 0;j < n;j++)
            {
                if(j == n-1)
                {
                    if(dis[i][j] == INF)
                        cout << "INF";
                    else
                        cout << dis[i][j];
                }
                else
                {
                    if(dis[i][j] == INF)
                        cout << "INF ";
                    else
                        cout << dis[i][j] << ' ';
                }
            }
            cout << endl;
        }
        }
    return 0;
}



Measured memory_bytes: 3352
#include <iostream>
#include <vector>
#define LIM 1000000007

using namespace std;

int main(void) {
	int N,M;
	cin >> N >> M;
	if (M > N) {
		swap(N,M);
	}

	if ((N-M) > 1) {
		cout << 0 << endl;
	}
	else {
		long long n = 1;
		long long m = 1;
		if (N == M) {
			for (int i = N; i > 1; --i) {
				n = (n * i)%LIM;
				m = (m * i)%LIM;
			}
			cout << (2*n*m)%LIM << endl;
		}
		else {
			for (int i = N-1; i > 1; --i) {
				n = (n * i)%LIM;
				m = (m * i)%LIM;
			}
			n = (n*N)%LIM;
			cout << (n*m)%LIM << endl;
		}
	}

	return 0;
}


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

int main() {
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  string s;
  cin>>s;
  string ans;
  for (int i=0; i<s.length(); i++) {
    if (s[i]=='0') {
      ans.append("0");
    } else if (s[i]=='1') {
      ans.append("1");
    } else {
      if (s[i]=='B'&&!ans.empty()) {
        ans.pop_back();
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
def find_min_m(s):
        a = s
        m = 1
        hist = set()
        while a not in hist:
                hist.add(a)
                a = a // 2 if a & 1 == 0 else 3 * a + 1
                m += 1
        return m


print(find_min_m(int(input())))

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


int main() {
   string s;
    cin >> s;
    int a = s.size();
    int count = 0;
  
    for(int i= 0; i < (s.size() / 2); i++) {
        if(s.at(i) != s.at(a - 1)) {
            count++;
        }
        a -= 1;
    }
    
    cout << count << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
#include<ext/pb_ds/priority_queue.hpp>
using namespace std;

const int maxn = 4004;
const int M = maxn * 2;
const int maxm = 2E5 + 20;
const int dx[2] = {0,1};
const int dy[2] = {1,0};
typedef long long LL;
const LL mo = 1000000007;

int n,Ans,f[maxn][maxn],Fac[M],Inv[M],A[maxm],B[maxm];

inline int Get(const int &k) {return k + 2001;}
inline int Mul(const LL &x,const LL &y) {return x * y % mo;}
inline int Add(const int &x,const int &y) {return x + y < mo ? x + y : x + y - mo;}
inline int Dec(const int &x,const int &y) {return x - y >= 0 ? x - y : x - y + mo;}
inline int C(const int &N,const int &M) {return Mul(Fac[N],Mul(Inv[M],Inv[N - M]));}

inline int getint()
{
	char ch = getchar(); int ret = 0;
	while (ch < '0' || '9' < ch) ch = getchar();
	while ('0' <= ch && ch <= '9')
		ret = ret * 10 + ch - '0',ch = getchar();
	return ret;
}

int ksm(int x,int y)
{
	int ret = 1;
	for (; y; y >>= 1)
	{
		if (y & 1) ret = Mul(ret,x);
		x = Mul(x,x);
	}
	return ret;
}

int main()
{
	#ifdef DMC
		freopen("DMC.txt","r",stdin);
	#endif
	
	n = getint();
	for (int i = 1; i <= n; i++)
	{
		A[i] = getint(); B[i] = getint();
		++f[Get(-A[i])][Get(-B[i])];
	}
	for (int i = 1; i <= 4001; i++)
		for (int j = 1; j <= 4001; j++)
		{
			f[i][j] = Add(f[i][j],f[i - 1][j]);
			f[i][j] = Add(f[i][j],f[i][j - 1]);
		}
	Fac[0] = 1; for (int i = 1; i < M; i++) Fac[i] = Mul(i,Fac[i - 1]);
	Inv[M - 1] = ksm(Fac[M - 1],mo - 2); for (int i = M - 2; i >= 0; i--) Inv[i] = Mul(Inv[i + 1],i + 1);
	for (int i = 1; i <= n; i++)
	{
		Ans = Add(Ans,f[Get(A[i])][Get(B[i])]);
		Ans = Dec(Ans,C((A[i] << 1) + (B[i] << 1),A[i] << 1));
	}
	cout << Mul(Ans,ksm(2,mo - 2)) << endl;
	return 0;
}

Measured memory_bytes: 64512
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<queue>
#define null NULL
using namespace std;
/** 区间表示：[p->dl,p->dr]
 *  从0开始计数，[0,n-1]
 *  线段树RSQ
 *
 */

struct Node
{
    int dl,dr,s;
    Node *pl,*pr;
};
int n,q;
static const int inf=(1<<31)-1;

void build(Node *&p,int l,int r)
{
    p=(Node *)malloc(sizeof(Node));
    p->dl=l,p->dr=r,p->s=inf;
    p->pl=null,p->pr=null;
    int mid=(l+r)/2;
    //到叶子节点处不需要再 继续分割，否则会无线循环下去，以为mid处没有值
    if(r>l)
    {
        build(p->pl,l,mid);
        build(p->pr,mid+1,r);//此处表示的都是闭区间
    }
}
int query(Node *&p,int l,int r)
{
    ///一个查询区间最终必然被分成若干个小的区间和，最后一个定会完全和区间贴合
    if(p->dl==l &&p->dr==r)
        return p->s;
    int mid=(p->dl+p->dr)/2;
    ///判断查询区间与当前区间的位置关系
    //全部位于左侧
    if(r<=mid)
        return query(p->pl,l,r);
    //全部位于右侧
    else if(l>mid)
        return query(p->pr,l,r);
    //两个都有
    else
        return min(query(p->pl,l,mid),query(p->pr,mid+1,r));
}

void update(Node *&p,int x,int data)
{
    if(p->dl==p->dr)//找到最后一个叶子节点
    {
        p->s=data;
        return;
    }
    int mid=(p->dl+p->dr)/2;
    if(x<=mid)
        update(p->pl,x,data);
    else
        update(p->pr,x,data);
    p->s=min(p->pl->s,p->pr->s);
}
int main()
{
    int i,type,tx,ty;
    Node *tree=null;
    scanf("%d%d",&n,&q);
    build(tree,0,n-1);
    for(i=0;i<q;i++)
    {
        scanf("%d%d%d",&type,&tx,&ty);
        if(type==0)
        {
            update(tree,tx,ty);
        }else
        {
            int ans=query(tree,tx,ty);
            printf("%d\n",ans);
        }
    }
    return 0;
}



Measured memory_bytes: 12584
n = int(input())
ans = 'Yes'
words = [input() for _ in range(n)]
said = set()
tail = words[0][0]
for w in words:
    if w in said or w[0] != tail:
        ans = 'No'
        break
    said.add(w)
    tail = w[-1]

print(ans)

Measured memory_bytes: 3064
while True:
  n = int(input())
  if n == 0:
    break
  targets = [tuple(map(int, input().split())) for _ in range(n)]
  m = int(input())
  x = y = 10
  direct = {"N":(0, 1), "S":(0,-1), "E":(1,0), "W":(-1,0)}
  for _ in range(m):
    d, i = input().split()
    dx, dy = direct[d]
    for dist in range(1, int(i) + 1):
      if (x + dist * dx, y + dist * dy) in targets:
        targets.remove((x + dist * dx, y + dist * dy))
    x += dx * int(i)
    y += dy * int(i)
  if targets:
    print("No")
  else:
    print("Yes")



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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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 vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  int n; cin >> n;
  vector<string> S(n); REP(i, n) cin >> S[i];
  vector<map<char, int>> m(n);
  map<char, int> a;
  for(char i = 'a'; i <= 'z'; ++i) {
    a[i] = 0;
  }
  REP(i, n) {
    REP(k, S[i].size()) {
      m[i][S[i][k]]++;
    }
  }
  REP(i, S[0].size()) {
    a[S[0][i]]++;
  }
  for(char i = 'a'; i <= 'z'; ++i) {
    for(int k = 1; k < n; ++k) {
      a[i] = min(a[i], m[k][i]);
    }
  }
  string ans = "";
  for(auto x : a) {
    for(int i = 0; i < x.second; ++i) {
      ans += x.first;
    }
  }
  cout << ans << endl;
}


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

int main(){
    string s;
    cin>>s;
    int a,b,c,d;
    d=s[3]-'0';
    c=s[2]-'0';
    b=s[1]-'0';
    a=s[0]-'0';
    int x[8];
    x[0]=a-b+c+d;
    x[1]=a-b-c+d;
    x[2]=a+b+c+d;
    x[3]=a+b-c+d;
    x[4]=a-b+c-d;
    x[5]=a-b-c-d;
    x[6]=a+b+c-d;
    x[7]=a+b-c-d;
    rep(i,8){
        if(x[i]==7){
            if(i==0){
                cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"=7\n";
                return 0;
            }
            else if(i==1){
                cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"=7\n";
                return 0;
            }else if(i==2){
                cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"=7\n";
                return 0;
            }
            else if(i==3){
                cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"=7\n";
                return 0;
            }
            else if(i==4){    
                cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"=7\n";
                return 0;
            }
            else if(i==5){
                cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"=7\n";
                return 0;
            }
            else if(i==6){
                cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"=7\n";
                return 0;
            }
            else if(i==7){    
                cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"=7\n";
                return 0;
            }
        }
    }
    
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c  = sc.nextInt();
		int x = sc.nextInt();
		int count = 0;
		for(int i = 0; i <= a;i++) {
			for(int j = 0; j <= b; j++) {
				int temp = x-i*500-j*100;
				if(temp%50== 0&& temp>=0 && temp <= c*50) {
					count++;
				}
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 23632
#include<iostream>

using namespace std;

long Gcd(long a, long b)
{
	int x = a, y = b;
	while (x % y != 0)
	{
		int z = x % y;
		x = y;
		y = z;
	}

	return y;
}
int main()
{
	long a, b;
	cin >> a >> b;
	cout << a * b / Gcd(a, b) << endl;
}

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

using namespace std;

typedef long long ll;

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

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

struct Edge {
    int v;
    int w;
};

vector<vector<struct Edge>> edges;
vector<int> colors;

// void solve(const int prev, const int prev_color, const int prev_dist, const int cur) {
void solve(const int prev, const int cur) {
    const int cur_color = colors[cur];
    for (auto &edge : edges[cur]) {
        // printf("prev: %d, cur: %d, edge.v: %d, edge.w: %d, cur_color: %d\n", prev, cur, edge.v, edge.w, cur_color);
        if (edge.v == prev) {
            continue;
        }
        if (edge.w % 2 == 0) {
            // even
            colors[edge.v] = cur_color;
        } else {
            colors[edge.v] = 0x1 ^ cur_color;
        }
        // solve(cur, cur_color, edge.w, edge.v);
        solve(cur, edge.v);
    }
}

int main(void) {
    int N;
    cin >> N;

    edges.resize(N);
    for (int i = 0; i < N - 1; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        u--;
        v--;
        edges[u].push_back({v, w});
        edges[v].push_back({u, w});
    }

    colors.resize(N);
    colors[0] = 0;

    solve(-1, 0);

    for (int i = 0; i < N; i++) {
        cout << colors[i] << endl;
    }


    return 0;
}


Measured memory_bytes: 8960