akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define BUGAVOID(x) x
#define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define sz(c) (int)(c.size())
#define all(c) c.begin(),c.end()
#define ms(a,v) memset(a,v,sizeof(a))
#define mp make_pair
#define write(x) cout<<(x)<<endl
using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; }return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; }return 0; }
constexpr ll pow2(const int n) { return 1ll << n; }
const int INF = 1 << 28; const ll LINF = 1ll << 60;
const int MAX = 1e5 + 5; const int MOD = 1e9 + 7; const double EPS = 1e-6;
const int dy[4] = { 0,1,0,-1 }; const int dx[4] = { 1,0,-1,0 };
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

int main() {
    int N, M;
    cin >> N;
    multiset<string> blue, red;
    rep(i, N) {
        string s;
        cin >> s;
        blue.insert(s);
    }
    cin >> M;
    rep(i, M) {
        string s;
        cin >> s;
        red.insert(s);
    }

    int ans = 0;
    for (const string& s : blue) {
        int diff = blue.count(s) - red.count(s);
        chmax(ans, diff);
    }
    
    write(ans);
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        var abn = Console.ReadLine().Split().Select(long.Parse).ToArray();
        var a = abn[0];
        var b = abn[1];
        var n = abn[2];

        var x = Min(b - 1, n);
        //for (int x = 0; x <= n; x++)
        {
            Console.WriteLine(a * x / b - a * (x / b));
        }
    }
}

Measured memory_bytes: 28184
#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <cmath>
#include <ctime>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector< vector<int> > vvi;
typedef vector<ll> vl;
typedef vector< vector<ll> > vvl;

#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define forv(i, v) forn(i, v.size())
#define all(v) v.begin(), v.end()
#define mp make_pair
#define pb push_back

int main() {
#ifdef NEREVAR_PROJECT
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n;
    ll x;
    cin >> n >> x;
    vl a(n);
    forn(i, n) cin >> a[i];
    vl c = a;
    ll ans = 0;
    forn(i, n) ans += c[i];
    for (int k = 1; k < n; k++) {
        ll sum = 0;
        forn(i, n) {
            c[i] = min(c[i], a[(i - k + n) % n]);
            sum += c[i];
        }
        ans = min(ans, sum + x * k);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[2] = {0, 1};
ll dy[2] = {1, 0};

int main(void){
    ll n;
    cin >> n;
    vector<ll> c(n+1, 0);
    for(ll i = 0; i < n-1; i++){
        ll a;
        cin >> a;
        c[a]++;
    }
    for(ll i = 1; i <= n; i++)
        cout << c[i] << endl;
    return 0;
}


Measured memory_bytes: 4844
#入力
N = int(input())
a_list = []
a_list = list(map(int,input().split()))

#変数を用意
g_list = [0]*9

#グループ1の要素があるか確認
for i in range(N):
    if 1 <= a_list[i] <= 399:
        g_list[0] = 1
        break

#グループ2から8の要素があるか確認
for j in range(1,8):
    for k in range(N):
        if 400*j <= a_list[k] <= (400*(j+1)-1):
            g_list[j] = 1
            break

#グループ1から8の要素数をgに代入
g = 0
for m in range(8):
    g += g_list[m] 

#グループ9の要素がいくつあるか数える
g_list[8] = 0
for l in range(N):
    if a_list[l] >= 3200:
        g_list[8] += 1

#条件分岐して数える
if g_list[8]==0:
    print(g,g)

elif g==0:
    print(1,g_list[8])

else:
    print(g,g+g_list[8])


Measured memory_bytes: 3064
#include <stdio.h>
int main()
{
    int x, i;
    
    i = 1;
    
    while (i > 0) {
        scanf ("%d", &x);
        if (x == 0) {
            break;
        }
        printf ("Case %d: %d\n", i, x);
        i++;
    }
    
    return 0;
}

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

int main() { 
  int PAIR = 0;
    string S;
    cin >> S;
  
  for (int i = 0; i < 3; i++) {
     for (int j = i; j < 3; j++) {
     if (S.at(i) == S.at(j+1))
     PAIR++;     
    } 
  }
  if (PAIR == 2)
  cout << "Yes" << endl;
  else
  cout << "No" << endl;
} 

Measured memory_bytes: 256
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	stack := []int{}
	for {
		b := sc.Scan()
		if !b {
			err := sc.Err()
			if err == nil {
				break
			} else {
				panic(err)
			}
		}
		switch term := sc.Text(); term {
		case "+":
			stack = calc(add, stack)
		case "-":
			stack = calc(subtract, stack)
		case "*":
			stack = calc(multiply, stack)
		default:
			x, err := strconv.Atoi(term)
			if err != nil {
				panic(err)
			}
			stack = append(stack, x)
		}
	}
	fmt.Println(stack[0])
}

type Operator func(x int, y int) int

func calc(operator Operator, stack []int) []int {
	x, y := stack[len(stack)-2], stack[len(stack)-1]
	return append(stack[0:len(stack)-2], operator(x, y))
}

func add(x int, y int) int {
	return x + y
}

func subtract(x int, y int) int {
	return x - y
}

func multiply(x int, y int) int {
	return x * y
}



Measured memory_bytes: 1144
n = int(input())
L = list(map(int,input().split()))
L.sort(reverse = True)
#print(L)
from itertools import combinations
cnt = 0
for v in combinations(L,3):
    #print(v)
    if (v[0]!=v[1] and v[1] != v[2]) and v[0] < v[1] + v[2]:
        cnt +=1
print(cnt)

Measured memory_bytes: 9184
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()    // 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例：sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

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>
T GCD(T a, T b) { if (b == 0) return a; else return GCD(b, a % b); }
template<class T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

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

	int cnt[4] = {};

	rep(i, n) {
		string s;
		cin >> s;

		if (s == "AC") cnt[0]++;
		else if (s == "WA") cnt[1]++;
		else if (s == "TLE") cnt[2]++;
		else if (s == "RE") cnt[3]++;
	}

	cout << "AC x " << cnt[0] << endl;
	cout << "WA x " << cnt[1] << endl;
	cout << "TLE x " << cnt[2] << endl;
	cout << "RE x " << cnt[3] << endl;
}

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

using namespace std;

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

    if (n < b)
    {
        f = floor(a * n/ b);
    }
    else
    {
        f = floor(a * (b-1) / b);
    }

    cout << f << endl;
    return 0;
}

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


typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;

typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;

#define _  %  MOD
#define __ %= MOD

#define      each(it,s)        for(auto it = s.begin(); it != s.end(); ++it)
#define      sortA(v)          sort(v.begin(), v.end())
#define      sortD(v)          sort(v.begin(), v.end(), greater<auto>())
#define      fill(a)           memset(a, 0, sizeof (a))

#define      swap(a,b)        {a=a+b;b=a-b;a=a-b;}
#define      rep(i, n)         for(int i = 0; i < (n); ++i)
#define      repA(i, a, n)     for(int i = a; i <= (n); ++i)
#define      repD(i, a, n)     for(int i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) <<endl

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define fbo find_by_order
#define ook order_of_key

ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);}
ll power(ll x,ll y){ll res=1; while(y>0){if(y&1) res=res*x;y=y>>1;x=x*x;}return res;} // modular exponent
ll n,m;
ll dp[100005];
bool vis[100005];
void dfs(ll node, vector<ll> v[])
{
    vis[node]=true;
    for(ll i=0;i<v[node].size();i++)
    {
        if(!vis[v[node][i]]) dfs(v[node][i],v);
        dp[node]=max(dp[node],1+dp[v[node][i]]);
    }
}
ll longestpath(vector<ll> v[])
{
    for(ll i=1;i<=n;i++)
    {
        if(!vis[i]) dfs(i,v);
    }
    ll ans=0;
    for(ll i=1;i<=n;i++)
    {
        ans=max(ans,dp[i]);
    }
    return ans;
}
int main()
{
    ios_base::sync_with_stdio(false); // don't use printf and scanf
    cin.tie(NULL); // cout<<fixed<<setprecision
    cin>>n>>m;
    vector<ll> v[n+1];
    for(ll i=0;i<m;i++)
    {
        ll val1,val2;
        cin>>val1>>val2;
        v[val1].pb(val2);
    }
    fill(dp);
    memset(vis, false, sizeof (vis));
    ll ans=longestpath(v);
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 8704
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  int n;
  ll k;
  cin>>n>>k;
  ll sum[100001];
  rep(i,0,100001){
    sum[i]=0;
  }
  rep(i,0,n){
    int a,b;
    cin>>a>>b;
    sum[a]+=b;
  }
  ll cur=0;
  int i=0;
  while(cur<k){
    i++;
    cur+=sum[i];
  }
  cout<<i<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
#include<string>
#include<iomanip>
#include <numeric>
#include <limits>
using namespace std;
 
int main()
{
int x,a,b,m; cin>>x>>a>>b;
m=(x-a);
while(m>=b) m-=b;
cout<<m;
return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include <bits/stdc++.h>
#include<stdio.h>
#include <stdlib.h>
#include<string>
#include<queue>
#include<algorithm>
#include<math.h>
using namespace std;

int main(){
	int N,K,h[100000],a,ans=2000000000;
	priority_queue<int> q; 
	cin>>N>>K;
	for(int i=0;i<N;i++){
		cin>>a;
		q.push(a);
	}
	for(int i=0;i<N;i++){
		h[i]=q.top();
		q.pop();
	}
	for(int i=0;i<=N-K;i++){
		if(ans>h[i]-h[i+K-1]){
			ans=h[i]-h[i+K-1];
		}
		if(ans==0){
			break;
		}
	}
	cout<<ans<<endl;
}

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

using namespace std;


int main () {

	ios_base::sync_with_stdio(false); cin.tie(NULL);


	int a, p;
	cin >> a >> p;

	int pieces = 3 * a + p;
	int pies = pieces / 2;


	cout << pies << '\n';



	return 0;
}


Measured memory_bytes: 256
#include<queue>
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
#include<functional>
#include<deque>
#include<list>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
int main(){
  int i,j,n,k,a[2010];
  cin >> n >> k;
  k=k%mod;
  for(i=0;i<n;i++){
    cin >> a[i];
  }
  mint x=0;
  for(i=0;i<n;i++){
    for(j=i+1;j<n;j++){
      if(a[i]>a[j]){
        x=x+1;
      }
    }
  }
  mint y=0;
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(a[i]>a[j]){
        y=y+1;
      }
    }
  }
  y=mint((k-1))*mint(k)/mint(2)*y;
  x=x*k;
  x=x+y;
  printf("%lld\n",x);
  return 0;
}

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

typedef long long int ll;

int main()
{
	ll n,k;
	scanf("%lld %lld",&n,&k);
	ll arr[n+1],brr[n+1];
	for(ll i=1;i<=n;i++)
	{
		scanf("%lld",&arr[i]);
		brr[i]=0;
	}
	brr[1]=0;
	ll count=1,flag=0,flag2=0;
	if(k<=n)
	{
		for(ll i=1;i<=k;i++)
		{
			//              brr[count]=i;
			count=arr[count];
			if(brr[count]>0)
			{
				flag2=brr[count];
				flag=i;
				i=n+1;
			}
			//              printf("%lld\n",i);
			brr[count]=i;
		}
		printf("%lld\n",count);
	}
	else
	{
		for(ll i=1;i<=n;i++)
		{
			//		brr[count]=i;
			count=arr[count];
			if(brr[count]>0)
			{
				flag2=brr[count];
				flag=i;
				i=n+1;
			}
			//		printf("%lld\n",i);
			brr[count]=i;
		}
		//	printf("flag2=%lld flag=%lld\n",flag2,flag);
		{
			ll counter=count;
			if((k-flag2+1)%(flag-flag2)==0)
			{
				for(ll i=1;i<(flag-flag2);i++)
					counter=arr[counter];
			}
			else
			{
				for(ll i=2;i<=((k-flag2+1)%(flag-flag2));i++)
				{
					//		printf("i=%lld enter\n",i);
					counter=arr[counter];
				}
			}
			printf("%lld\n",counter);
		}
	}
}


Measured memory_bytes: 6908
K = int(input())
A = list()
i = 1
mod = 7%K
while i <= 10**6+5:
    if mod ==0:
        break
    else:
        mod = ((mod*10) + 7)%K
        i += 1
if i >= 10**6+1:
    i = -1
print(i)

Measured memory_bytes: 9172
n= int(input())
d= list(map(int,input().split()))
sum=0
k=0
while k<=n-1:
  sum+=int(d[k])
  k+=1
#ここまででたこ焼きの数とおいしさの総和を得る
main= sum-d[0]
piled=0
p=0
while p<=n-2:
  piled+= main*d[p]
  p+=1
  main-=d[p]
  

  
print(piled)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define reg register
#define ll long long
#define inf 0x3f3f3f3f3f3f3f3fll
#define next liuyifan_next
using namespace std;
const ll p=1e9+7;
ll n,m,g[10000005],f[10000005],pow2[10000005],x,y,ans;
inline ll add(reg ll x,reg ll y) 
{
    return (x+=y)>p?x-p:x;
}
int main()
{
    cin>>n>>m;
    f[0]=pow2[0]=1; 
    for(reg ll i=1;i<=m;i++)pow2[i]=(pow2[i-1]<<1)%p; 
    for(reg ll i=1;i<=m;i++)
	{
		cin>>x>>y;
		x--;
		y--;
		g[x]|=(1<<y);
	} 
    for(reg ll s=1;s<1<<n;s++)
	if((s&1)==(s>>1&1))
    for(reg ll u=s;u;u=u-1&s) 
	if((u&1)==(u>>1&1)) 
    {
        ans=1;
        for(reg ll i=0;i<n;i++) 
		if(s>>i&1) 
        {
            if(u>>i&1)ans=ans*pow2[__builtin_popcount(g[i]&(s^u))]%p;
            else ans=ans*(pow2[__builtin_popcount(g[i]&u)]-1)%p; 
        }
        f[s]=add(f[s],f[s^u]*ans%p); 
    }
    cout<<(pow2[m]-f[(1<<n)-1]+p)%p<<endl;
    return 0;
}

Measured memory_bytes: 4480
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int main()
{
    ll n;
    cin >> n;
    ll ans = (n / 11) * 2;
    if (n % 11 > 6) {
        cout << ans + 2 << endl;
    } else if (n % 11 > 0) {
        cout << ans + 1 << endl;
    } else {
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int c=0;
  for(int i=0;i<n;i++){
    int p;
    cin>>p;
    c+=(p!=i+1);
  }
  cout<<(c<=2?"YES":"NO")<<endl;
}


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

int main(){
    long double n, m, d, ans;
    cin >> n >> m >> d;
    if(d != 0) ans = 2*(m - 1)*(n - d)/n/n;
    else ans = (m-1)/n;
    cout << fixed << setprecision(10) << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//<<setprecision(30)
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define INF 1000000000000
#define MOD 1000000007
using ll = long long;
using Graph = vector<vector<int>>;

int main(){
  ll N,K; cin>>N>>K;
  ll res = 0;
  for(ll i = K; i <= N+1; i++){
    ll s = i*(i-1)/2;
    ll e = i*N - s;
    s%=MOD;
    //e%=MOD;
    //cout<<s<<" "<<e<<endl;
    res += (e-s+1)%MOD;
  }
  cout<<res%MOD<<endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <unordered_map>
#include <vector>
#include <set>
#include <algorithm>
#define ll long long
#define pr pair<int,int>
#define all vec.begin(),vec.end()
#define REP(i,a,b) for (int i = a; i < b; i++)
#define fi first
#define se second
#define pushb push_back
#define makep make_pair

using namespace std;

int main(){
	int n;
	cin >> n;	
	cout << (n*(n+1))/2;
	return 0;
}



Measured memory_bytes: 256
n, time = [int(_) for _ in input().split()]
c = []
t = []
for i in range(n):
    ci, ti = [int(_) for _ in input().split()]
    if ti <= time:
        c.append(ci)
        t.append(ti)

if len(t) == 0:
    print('TLE')
else:
    print(min(c))

Measured memory_bytes: 3060
# -*- coding: utf-8 -*-

"""
参考：https://img.atcoder.jp/arc095/editorial.pdf
"""

N = int(input())
aN = list(map(int, input().split()))
aN.sort(reverse=True)

n = aN[0]
r = aN[1]
for i in range(2, N):
    if abs(n / 2 - aN[i]) < abs(n / 2 - r):
        r = aN[i]
print(n, r)


Measured memory_bytes: 14428
def get_move(S):
    S = S.split("T")
    x_move = [len(x) for x in S[0::2]]
    y_move = [len(x) for x in S[1::2]]
    return x_move, y_move


def check(x, move):
    move.sort()
    while move:
        m = move.pop()
        if x >= 0:
            x -= m
        else:
            x += m
    return x == 0


if __name__ == "__main__":
    S = input()
    x, y = map(int, input().split())

    x_move, y_move = get_move(S)
    # 初手正方向に移動
    x -= x_move[0]

    if check(x, x_move[1:]) and check(y, y_move):
        ans = "Yes"
    else:
        ans = "No"

    print(ans)


Measured memory_bytes: 3188
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def main():
    N, M, K = map(int, input().split())
    f_uni = UnionFind(N)
    not_cand = [0] * N
    for _ in range(M):
        A, B = map(int, input().split())
        A -= 1
        B -= 1
        not_cand[A] += 1
        not_cand[B] += 1
        f_uni.union(A,B)
    
    for _ in range(K):
        C, D = map(int, input().split())
        C -= 1
        D -= 1
        if f_uni.same(C,D):
            not_cand[C] += 1
            not_cand[D] += 1
    ans = [0] * N
    for i in range(N):
        ans[i] = f_uni.size(i) - not_cand[i] - 1
    
    print(*ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 94296
#include <bits/stdc++.h>
#include <iostream>
#include <functional>
#include <vector>
#include <stdio.h>
#include <queue>
#include <string.h>
#include <math.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define rep1(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
#define per1(i,a,n) for (int i=a;i>n;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define endl "\n"
#define pi 3.14159265358979323846264338327950288419716939937510
#define IOS cin.sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll mod=1000000007;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
ll qpow(ll a,ll b){ll s=1;while(b>0){if(b%2==1){s=s*a;}a=a*a;b=b>>1;}return s;}
ll qpowmod(ll a, ll b, ll c){ll res, t;res=1;t=a%c;while(b){if(b & 1){res=res*t%c;}t=t*t%c;b>>=1;}return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline long long read(){long long k=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){k=k*10+ch-'0';ch=getchar();}return k*f;}
inline void write(long long x){if(x<0)x=-x,putchar('-');if(x>9)write(x/10);putchar(x%10+'0');}
// head
ll n,a[1000005];
int main()
{
    //IOS;
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    cin>>n;
    for(int i=1; i<=100; i++)
    {
        for(int j=1; j<=100; j++)
        {
            for(int k=1; k<=100; k++)
            {
                a[i*i+j*j+k*k+i*j+j*k+i*k]++;
            }
        }
    }
    for(int i=1; i<=n; i++)
    {
        cout<<a[i]<<endl;
    }
    return 0;
}
/*

*/


Measured memory_bytes: 4020
#include<stdio.h>
int main()
{
      int n;
      scanf("%d",&n);
      int a[n],i;
      for(i=0;i<n;i++){
            scanf("%d",&a[i]);
      }
      int j,k,x=0,ans=0,tm;
      for(i=0;i<n;i++){
            for(j=i+1;j<n;j++){
                  if(a[i]>a[j]){
                        tm=a[i];
                        a[i]=a[j];
                        a[j]=tm;
                  }
            }
      }
      for(i=0;i<n-2;i++){
            if(i>0 && a[i]==a[i-1]){
                  ans+=x;
                  ///printf("x = %d ans= %d \n",x,ans);
                  continue;
            }
            x=0;
            for(j=i+1;j<n;j++){
                  if(a[i]==a[j]) continue;
                  for(k=j+1;k<n;k++){
                        if(a[k]==a[j]) continue;
                        if(a[i]+a[j]>a[k] && a[i]+a[k]>a[j] && a[j]+a[k]>a[i]) x++;
                  }
            }
            ans+=x;
           /// printf("x = %d ans= %d \n",x,ans);
      }
      printf("%d\n",ans);
}


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

int main()
{
    int h = 0 , m = 0 , s ;
    cin >> s ;
    if(s >= 3600)
    {
        h = s/3600 ;
        s = s - (h*3600) ;
    }
    if(s >= 60)
    {
        m = s/60 ;
        s = s - (m*60) ;
    }
    cout << h << ":" << m << ":" << s << endl ;
}


Measured memory_bytes: 3032
N, X = map(int, input().split())
x = [int(i) for i in input().split()]
x.append(X)
x.sort()
dif_x = [x[i + 1] - x[i] for i in range(len(x) - 1)]
n = max(dif_x)  # の約数だけ調べる
divisors = []
for i in range(1, int(n ** 0.5) + 1):
    if n % i == 0:
        divisors.append(i)
        if i != n // i:
            divisors.append(n // i)
divisors.sort(reverse=True)
# print(divisors)
for i in divisors:
    frag = True
    for j in dif_x:
        if j % i == 0:
            continue
        else:
            frag = False
            break
    if frag:
        print(i)
        break


Measured memory_bytes: 14252
use std::cmp::{max, min};
use std::io::{stdin, Read};

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: ty),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    let s: Vec<_> = it.next().unwrap().chars().collect();
    let n = s.len() + 1;
    let mut a = vec![0usize; n];
    for i in 0..(n - 1) {
        if s[i] == '<' {
            a[i + 1] = max(a[i + 1], a[i] + 1);
        }
    }
    for i in (0..(n - 1)).rev() {
        if s[i] == '>' {
            a[i] = max(a[i], a[i + 1] + 1);
        }
    }
    println!("{}", a.iter().sum::<usize>());
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 10492
import scala.io.StdIn.readInt

object Main extends App {
  var maxProfit: Int = Integer.MIN_VALUE
  val n = readInt()
  var minValue = readInt()
  for (_ <- 2 to n) {
    val current = readInt()
    maxProfit = Math.max(maxProfit, current - minValue)
    minValue = Math.min(minValue, current)
  }
  println(maxProfit)
}



Measured memory_bytes: 63512
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <cstdlib>
using namespace std;

pair<string, int> process1, process2;
queue<pair<string, int> > Q;
int main()
{
	int j = 0, sum = 0;
	int n, t, flag = 0;
	cin >> n >> t;
	for (int i = 0; i<n; i++)
	{
		cin >> process1.first >> process1.second;
		Q.push(process1);
	}
	while (!Q.empty()) {
		process2 = Q.front(); Q.pop();
		if (process2.second > t) {
			process2.second -= t;
			sum += t;
			Q.push(process2);
		}
		else {
			sum += process2.second;
			cout << process2.first << " " << sum << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 6252
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


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



int main() {
	ll N, K;
	cin >> N >> K;
	cout << N - K + 1;

	system("PAUSE");
}


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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007

using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int iy[]={0, 0, 1, -1};
int ix[]={1, -1, 0, 0};

long long int n, x[101], y[101], h[101], cx, cy, ch, hh, hm;

int main(){
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> x[i] >> y[i] >> h[i];
	}
	for(int i=0;i<=100;i++){
		for(int j=0;j<=100;j++){
			hh = 0;
			hm = 1e+9 + 2000;
			for(int k=0;k<n;k++){
				if(h[k]==0){
					hm = min(hm, abs(x[k]-i) + abs(y[k]-j));
				}else{
					if(hh==0) hh = h[k] + abs(x[k]-i) + abs(y[k]-j);
					if(hh!=0&&hh!=h[k] + abs(x[k]-i) + abs(y[k]-j)) break; 
				}
				if(k==n-1&&hh<=hm){
					cx = i;
					cy = j;
					ch = hh;
				}
			}
		}
	}
	cout << cx << " " << cy << " " << ch << endl;
	return 0;
}

Measured memory_bytes: 256
n = gets.to_i
s = gets.strip.chars

count = 0

0.upto(n-2) do |i|
  (i+1).upto(n-1) do |j|
    k = 2 * j - i
    next if k >= n

    if s[i] != s[j] && s[i] != s[k] && s[j] != s[k]
      count += 1
    end
  end
end

r = s.count { |c| c == 'R' }
g = s.count { |c| c == 'G' }
b = s.count { |c| c == 'B' }

puts r * g * b - count

Measured memory_bytes: 14644
#include<iostream>
#include<string>
#include<cctype>
#include<algorithm>
using namespace std;

int main()
{
    string data_f, data_b;

    cin >> data_f;
    data_b += data_f[2];
    data_b += data_f[3];
    data_f.pop_back();
    data_f.pop_back();

    int num_f = stoi(data_f);
    int num_b = stoi(data_b);

    bool b = false, f = false, w = false;
    if(num_f <= 12 && num_f > 0)
    { 
        f = true;
    }
    if(num_b <= 12 && num_b > 0)
    {
        b = true;
    }
    if(b && f) w = true;


    if(w){
        cout << "AMBIGUOUS" << endl;
        return 0;
    }
    else if(f)
    {
        cout << "MMYY" << endl;
        return 0;
    }
    else if(b)
    {
        cout << "YYMM" << endl;
        return 0;
    }
    else{
         cout << "NA" << endl;
         return 0;
    }


}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int i,m=0;
	char s[16];
	scanf("%s",s);
	for(i=0;s[i]!=0;i++){
		if(s[i]=='x')m++;
	}
	if(m<8)puts("YES");
	else puts("NO");
	return 0;
}

Measured memory_bytes: 128
'''input
8
WWWWWEEE
'''
n = input()
s =raw_input().strip()
ee = [0]*(n+1)
ww = [0]*(n+1)
for i in xrange(n):
	if i == 0:
		if s[i] == 'E':
			ee[i] = 1
		continue
	if s[i] == 'E':
		ee[i] = ee[i-1]+1
	else:
		ee[i] = ee[i-1]
for i in xrange(n-1,-1,-1):
	if i == n-1:
		if s[i] == 'W':
			ww[i] = 1
		continue
	if s[i] == 'W':
		ww[i] = ww[i+1]+1
	else:
		ww[i] = ww[i+1]
ans = 10**10
for i in xrange(1,n-1):
	ans = min(ans,n-ee[i-1]-ww[i+1]-1)
print min(ans,n-ww[1]-1,n-ee[n-2]-1)




Measured memory_bytes: 37740
#include <stdio.h>

int a, b, n, ng[16][16], dp[16][16];

int main(void){
    int i, x, y;
    while(1){
        scanf("%d %d", &a, &b);
        if(a == 0 && b == 0) break;
        for(x = 0; x < a; x++){
            for(y = 0; y < b; y++){
                ng[x][y] = 0;
            }
        }
        scanf("%d", &n);
        for(i = 0; i < n; i++){
            scanf("%d %d", &x, &y);
            ng[x-1][y-1] = 1;
        }
        for(x = 0; x < a; x++){
            for(y = 0; y < b; y++){
                if(ng[x][y]) dp[x][y] = 0;
                else if(x == 0 && y == 0) dp[x][y] = 1;
                else if(x == 0) dp[x][y] = dp[x][y-1];
                else if(y == 0) dp[x][y] = dp[x-1][y];
                else dp[x][y] = dp[x-1][y] + dp[x][y-1];
            }
        }
        printf("%d\n", dp[a-1][b-1]);
    }
    return 0;
}

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

typedef long long ll;

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

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

int main() {
	ll N, M; cin >> N >> M;
	string s, t; cin >> s >> t;

	ll gcdNum = gcd(N, M), lcmNum = lcm(N, M);
	ll  n = N / gcdNum, m = M / gcdNum;
	
	bool ok = true;
	for (ll i = 0; i < gcdNum; i++) {
		if (s[i * n] != t[i * m]) { ok = false; break; }
	}
	cout << (ok?lcmNum:-1) << endl;

	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned ll
#define PI acos(-1)
#define vi vector<int>
#define pi pair<int, int>
#define pl pair<ll, ll>
template<typename T> using v2 = vector<vector<T>>;
template<typename T> using v3 = vector<vector<vector<T>>>;
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int MOD = 1e9 + 7;
const int INF = 1e9 + 200;
const ll INFLL = 2e18 + 200;

int main() {
    int ans = 0, tmp = 0;
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) {
        int a, b;
        cin >> a >> b;
        if (a == b) {
            tmp++;
            ans = max(ans, tmp);
        } else tmp = 0;
    }
    cout << (ans >= 3 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define decimal(x) cout<<fixed<<setprecision(x)
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
map<ll, ll>dp;
ll n, a, b, c, d;
ll f(ll nw){
	if(nw==0) return 0;
	if(nw==1) return d;
	if(dp.count(nw)) return dp[nw];
	ll l2=(nw/2)*2, r2=((nw+1)/2)*2;
	ll l3=(nw/3)*3, r3=((nw+2)/3)*3;
	ll l5=(nw/5)*5, r5=((nw+4)/5)*5;

	ll rs=1e18;
	if(nw<rs/d) rs=nw*d;
	rs=min(rs, min(llabs(nw-l2)*d+a+f(l2/2), llabs(r2-nw)*d+a+f(r2/2)));
	rs=min(rs, min(llabs(nw-l3)*d+b+f(l3/3), llabs(r3-nw)*d+b+f(r3/3)));
	rs=min(rs, min(llabs(nw-l5)*d+c+f(l5/5), llabs(r5-nw)*d+c+f(r5/5)));
	dp[nw]=rs;
	return rs;
}
int main(){ fast;
	int t; cin>>t;
	while(t--){
		cin>>n>>a>>b>>c>>d;
		dp.clear();
		cout<<f(n)<<endl;
	}
}

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

int main() {
    int n,m;
    cin >> n >> m;
    vector<bool> used(n,false);
    vector<vector<int> > edge(n);
    int start, end;
    for(int i = 0; i < m; i++){
        int a,b;
        cin >> a >> b;
        a--; b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
        start = a, end = b;
    }
    used[start] = true, used[end] = true;
    deque<int> dq;
    dq.push_back(start);
    dq.push_back(end);
    for(int cnt = 0; cnt < n; cnt++){
        bool met = true;
        for(int i : edge[start]){
            if(!used[i]){
                met = false;
                start = i;
                dq.push_front(start);
                used[start] = true;
                break;
            }
        }
        if(!met) continue;

        for(int i : edge[end]){
            if(!used[i]){
                met = false;
                end = i;
                dq.push_back(end);
                used[end] = true;
                break;
            }
        }

    }
    cout << dq.size() << endl;
    while(!dq.empty()){
        cout << dq.front() + 1;
        dq.pop_front();
        if(!dq.empty()) cout << " ";
    }
    cout << endl;
}

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

typedef long long ll;
typedef pair<int,int> P;

int main(){
	ll N,D,A;
	cin >> N >> D >> A;
	vector<P> E(N);
	rep(i,N){ int x,h; cin >> x >> h; E[i]=P(x,h); }
	sort(E.begin(),E.end());

	ll cnt = 0;
	int num = 0;
	ll range = D*2;
	ll dam = 0;
	queue<pair<ll,ll>> q;
	while(num < N){
		int loc = E[num].first;
		int hp = E[num].second;
		
		while(q.size() &&  q.front().first < loc){
			dam -= q.front().second;
			q.pop();
		}
		hp -= dam;
		if(hp>0){
			ll c = (hp+A-1)/A;
			cnt += c;
			ll damage = c * A;
			dam += damage;
			q.emplace(loc+range, damage);
		}
		num++;
	}

	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 3456
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstring>
#include <cstdlib>

#define rep(i, n)     for (int (i) = 0; (i) < (n); (i)++)
#define rep1(i, n)    for (int i = 1; i <= (int)(n); i++)

using namespace std;
typedef long long ll;

const double sixty = M_PI * 60.0 / 180.0;

struct Point {
   double x, y;
};

void koch(int n, Point a, Point b) {
   if (n == 0) return;

   Point s, t, u;
   s.x = (a.x * 2.0 + b.x * 1.0) / 3.0;
   s.y = (a.y * 2.0 + b.y * 1.0) / 3.0;
   t.x = (a.x * 1.0 + b.x * 2.0) / 3.0;
   t.y = (a.y * 1.0 + b.y * 2.0) / 3.0;
   u.x = (t.x - s.x) * cos(sixty) - (t.y - s.y) * sin(sixty) + s.x;
   u.y = (t.x - s.x) * sin(sixty) + (t.y - s.y) * cos(sixty) + s.y;

   koch(n - 1, a, s);
   printf("%.8f %.8f\n", s.x, s.y);
   koch(n - 1, s, u);
   printf("%.8f %.8f\n", u.x, u.y);
   koch(n - 1, u, t);
   printf("%.8f %.8f\n", t.x, t.y);
   koch(n - 1, t, b);
}

int main() {
   Point a, b;
   int n;

   cin >> n;
   a.x = 0.0;
   a.y = 0.0;
   b.x = 100.0;
   b.y = 0.0;

   printf("%.8f %.8f\n", a.x, a.y);
   koch(n, a, b);
   printf("%.8f %.8f\n", b.x, b.y);

   return(0);
}



Measured memory_bytes: 3180
def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    total = 0
    count = [0 for _ in range(10**5)]
    for i in range(n):
        count[a[i] - 1] += 1
        total += a[i]

    q = int(input())
    for _ in range(q):
        b, c = list(map(int, input().split()))
        count_b = count[b - 1]
        count[b - 1] = 0
        count[c - 1] += count_b

        total -= count_b * (b - c)
        print(total)


if 'unittest' not in globals():
    resolve()

Measured memory_bytes: 83680
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main() {
	long long int N, W;
	cin >> N >> W;
	vector<long long int> w(N);
	vector<long long int> v(N);
	for (int i = 0; i < N; i++) {
		cin >> w[i] >> v[i];
	}
	vector<vector<long long int>> dp(N+1, vector<long long int>(100100,99999999999));
	dp[0][0] = 0;
	for (int i = 0; i < N; i++) {
		for (int g = 0; g < 100100; g++) {
			if (g - v[i] >= 0) {
				dp[i + 1][g] = min(dp[i + 1][g], dp[i][g - v[i]]+w[i]);
			}
			dp[i + 1][g] = min(dp[i + 1][g], dp[i][g]);
		}
	}
	int ans;
	for (int i = 0; i < 100100; i++) {
		if (dp[N][i] <= W) {
			ans = i;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 80256
#include<iostream>
using std::cin;
using std::cout;
using std::endl;
 
#include<map>
using std::map;
 
#include<string>
using std::string;
 
#include<stdlib.h>
long long int P=1000000007;
 
int main(void){
unsigned long long int ans;
long long int m,n;
scanf("%lld %lld",&m,&n);
if((m==1)||(n==1)){printf("1"); return 0;}
ans=(m*n+1)/2;
printf("%lld",ans);
}

Measured memory_bytes: 256
S = input()
A = S[0]
B = S[1]
C = S[2]
D = S[3]

mark = ["+", "-"]

for m1 in mark:
  for m2 in mark:
    for m3 in mark:
      if eval("{0} {1} {2} {3} {4} {5} {6}".format(A,m1,B,m2,C,m3,D)) == 7:
        print("{0}{1}{2}{3}{4}{5}{6}=7".format(A,m1,B,m2,C,m3,D))
        exit()

Measured memory_bytes: 3064
//#pragma GCC optimize("trapv")
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <chrono>
#include <tuple>
#include <random>
#include <cmath>

using namespace std;

typedef long long ll;
typedef long double ld;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

const ll SIZE = 1e7, INF = 1e9 * 1e9 + 10, INF2 = 1e9 + 100;

bool simp[SIZE];
ll ans[600][600];
bool used[600][600];

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

int main() {
	fastInp;

	ll n;
	cin >> n;

	if (n == 2) {
		cout << "4 7\n23 10";
		return 0;
	}
	ll cnt = 0;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if ((i + j) % 2 == 0) cnt++;
		}
	}

	deque<ll> d;
	ll c = 0;

	cnt += 3 * n;
	for (ll i = 2; true; i++) {
		if (simp[i]) continue;

		c++;
		
		d.push_back(i);
		if (c >= cnt) break;
		for (ll j = (i * i); j < SIZE; j += i) {
			simp[j] = 1;
		}
	}

	ll c1 = 0, c2 = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if ((i + j) % 2 == 0) {
				if (i % 2 == 0) {
					c1++;
				}
				else {
					c2++;
				}
			}
		}
	}

	deque<ll> vec1, vec2, al = d;
	while (c1 && c2) {
		c1--;
		c2--;
		vec1.push_back(d.back());
		d.pop_back();
		vec2.push_back(d.back());
		d.pop_back();
	}

	while (c1) {
		c1--;
		vec1.push_back(d.back());
		d.pop_back();
	}

	while (c2) {
		c2--;
		vec2.push_back(d.back());
		d.pop_back();
	}


	d = al;
	map<ll, ll> bal;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if ((i + j) % 2 == 0) {
				if (bal.find(j - i) != bal.end()) {
					ans[i][j] = bal[j - i];
				}
				else {
					ans[i][j] = d.front();
					bal[j - i] = d.front();
					d.pop_front();
				}
			}
		}
	}
	
	bal.clear();
	for (int i =  n - 1; i >= 0; i--) {
		for (int j = n - 1; j >= 0; j--) {
			if ((i + j) % 2 == 0) {
				if (bal.find(j + i) != bal.end()) {
					ans[i][j] *= bal[j + i];
				}
				else {
					ans[i][j] *= d.front();
					bal[j + i] = d.front();
					d.pop_front();
				}
			}
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if ((i + j) % 2 != 0) {
				ll ml = 1;
				if (i > 0) ml = (ml * ans[i - 1][j]) / gcd(ml, ans[i - 1][j]);
				if (j > 0) ml = ml * (ans[i][j - 1] / gcd(ml, ans[i][j - 1]));
				if (i < n - 1) ml = ml * (ans[i + 1][j] / gcd(ml, ans[i + 1][j]));
				if (j < n - 1) ml = ml * (ans[i][j + 1] / gcd(ml, ans[i][j + 1]));

				if (ml < 0) {
					cout << "";
				}
				ans[i][j] = ml + 1;
			}
			cout << ans[i][j] << " ";
		}
		cout << "\n";
	}

	return 0;
}

Measured memory_bytes: 18832
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <algorithm>
#include <unordered_map>
#define int                long long
#define pb                 push_back
#define pi                 pair<int,int>
#define vi                 vector<int>
#define all(v)             v.begin(),v.end()
#define MOD                1000000007
#define F                  first
#define S                  second
#define FOR(i,r)           for(int i=0;i<r;i++)
#define REP(i,l,r)         for(int i=l;i<r;i++)
#define RER(i,l,r)         for(int i=l;i>=r;i--)
#define print(v)           for(auto i : v)cout << i << ' ';
#define FASTIO             ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mem(arr,k)         memset(arr,k,sizeof(arr));
#define pii                acos(-1.0)
#define PI                 3.1415926535897932385
#define Sin(a)             sin((pi*a)/180)
#define test()             int x;cin >> x;while(x--)
using namespace std;
int32_t main(){

	FASTIO;
	vector<int>g[100005],deg(100005,0);
	int n,m,u,v;
	cin >> n >> m;
	REP(i,0,m){
		cin >> u >> v;
		g[u].pb(v);
		//g[v].pb(u);
		deg[v]++;
	}
	queue<int>q;
	REP(i,1,n+1){
		if(deg[i]==0)
			q.push(i);
	}
	int dp[n+1] = {0};
	while(!q.empty()){
		int f = q.front();
		q.pop();
		for(auto i : g[f])
		{
			dp[i] = max(dp[i],dp[f]+1);
			deg[i]--;
			if(deg[i]==0)
				q.push(i);
		}
	}
	cout << *max_element(dp,dp+n+1) << endl;
    return 0;

}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define met(s) memset(s,0, sizeof(s))
const int mod=100000007;
const int maxn=1000000;
const int inf = 0x3f3f3f3f;
int main()
{
    int ans=0,now,n,cnt=0;
    scanf("%d",&n);
    n--;
    scanf("%d",&now);
    for(int i=0;i<n;i++)
    {
        int x;
        scanf("%d",&x);
        if(x<=now) cnt++;
        else cnt=0;
        ans=max(ans,cnt);
        now=x;
    }
    ans=max(cnt,ans);
    printf("%d\n",ans);
    return 0;
}

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

using namespace std;
typedef long long ll;

#define INF (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

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



int main(void)
{
  ll n; cin >> n;
  vector<ll> a(n);
  REP(i, n) cin >> a[i];
  ll cm = 0;
  ll mm = INF;
  ll su = 0;
  REP(i, n) {
    if(a[i] < 0) {
      cm ++;
      a[i] = -a[i];
    }
    if(a[i] < mm) {
      mm = a[i];
    }
    su += a[i];
  }
  //  cout << "su:" << su << " mm:" << mm << endl;
  if(cm % 2 == 1) {
    su -= mm * 2;
  }
  cout << su << endl;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define rsort(v) sort(all(v)); reverse(all(v))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template<typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template<typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template<typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template<typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template<typename T> inline T power(T x, i64 n) { T r = 1; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template<typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }

struct UnionFind {
  vi32 par;
  UnionFind(int n) {
    par = vi32(n + 1);
    iota(all(par), 0);
  }
  int root(int x) {
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return;
    par[x] = y;
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
};

void solve() {
  int n, m;
  cin >> n >> m;
  auto uf = UnionFind(n);
  rep(i, m) {
    int x, y, z;
    cin >> x >> y >> z;
    uf.unite(x, y);
  }
  unordered_set<int> s;
  reps(i, n) {
    uf.root(i);
    s.insert(uf.par[i]);
  }
  cout << s.size() << '\n';
}


Measured memory_bytes: 4772