akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

int N, M, a[200009];

bool ok (int R)
{
    int p = 1, u = N / 2, mij, ras = 0;
    while (p <= u)
    {
        mij = (p + u) >> 1;
        bool finePref = 1;
        for (int i=1; i<=mij; i++)
            if (a[i] + a[2 * mij + 1 - i] > R)
            {
                finePref = 0;
                break;
            }
        if (finePref) ras = mij, p = mij + 1;
        else u = mij - 1;
    }
    ///the prefix can be anything from [0, 2 * ras]
    ///if the suffix is not fine because of a too small sum, then it can't be done
    for (int i=2 * ras + 1, j = N; i < j; i++, j--)
        if (a[i] + a[j] < M)
            return 0;
    ///ohterwise, I should decrease the values until all of them are <= M + R and if at that point it's fine, then it works
    ///otherwise not
    int ras2 = -1;
    p = 0, u = ras;
    while (p <= u)
    {
        mij = (p + u) >> 1;
        bool fineSuf = 1;
        for (int i=2 * mij + 1, j = N; i < j; i++, j--)
            if (a[i] + a[j] > M + R)
            {
                fineSuf = 0;
                break;
            }
        if (!fineSuf) u = mij - 1;
        else p = mij + 1, ras2 = mij;
    }
    if (ras2 == -1) return 0;
    for (int i=2 * ras2 + 1, j = N; i < j; i++, j--)
        if (a[i] + a[j] < M)
            return 0;
    return 1;
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d %d", &N, &M), N <<= 1;
for (int i=1; i<=N; i++)
    scanf ("%d", &a[i]);
sort (a + 1, a + N + 1);
int p = 0, u = M - 2, mij, ras = M - 1;
while (p <= u)
{
    mij = (p + u) >> 1;
    if (ok (mij)) ras = mij, u = mij - 1;
    else p = mij + 1;
}
printf ("%d\n", ras);
return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;

int main() {
  int N;
  cin >> N;
  ll A[N],B[N];
  ll num = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
  }
  for (int i = N-1; i >= 0; i--) {
    num += (B[i] - ((num + A[i]) % B[i])) % B[i];
  }
  cout << num << endl;
  return 0;
}

Measured memory_bytes: 5036
#include <iostream>
#include <string.h>
 
using namespace std;
string s, t;
int F[3001][3001];
 
int main()
{
    cin>>s>>t;
    int a, b;
    a=s.length();
    b=t.length();
    for(int i=1; i<=a; i++)
    {
        for(int j=1; j<=b; j++)
        {
            if(s[i-1]==t[j-1]) F[i][j]=F[i-1][j-1]+1;
            else F[i][j]=max(F[i-1][j], F[i][j-1]);
        }
    }
    string tmp;
    while(a*b!=0)
    {
        if(s[a-1]==t[b-1])
        {
            tmp+=t[b-1];
            a--;
            b--;
        }
        else
        {
            if(F[a-1][b]>F[a][b-1]) a--; else b--;
        }
    }
    for(int i=tmp.length(); i>=1; i--)
    {
        cout<<tmp[i-1];
    }
    return 0;
}

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

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

  vector<int> genius(k) ;

  if ( k % 2 == 0 || k % 5 == 0) {
    cout << -1 << endl ;
  }else if ( k == 1 || k == 7 ) {
    cout << 1 << endl ;
  }else{
    genius.at(0) = 7 % k ;
    for (int i = 1; i < k ; i++) {
      int d = genius.at(i-1) * 10 + 7 ;
      genius.at(i) = d % k ;
      if ( genius.at(i) == 0 ) {
        cout << i+1 << endl ;
        break ;
      }else if ( genius.at(i) == genius.at(0) ) {
        cout << -1 << endl ;
      }
    }
  }

  return 0 ;
}

Measured memory_bytes: 7196
import java.util.Scanner;

public class Main
{
	public static void main(String[] args) {
	    Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int m = s.nextInt();
        int lMax = 1;
        int rMin = n;
        for (int i = 0; i < m; i++) {
            int l = s.nextInt();
            int r = s.nextInt();
            lMax = (lMax < l ? l : lMax);
            rMin = (rMin > r ? r : rMin);
        }
        int res = rMin - lMax + 1;
        System.out.println((res < 0)? 0 : res);
	}
}

Measured memory_bytes: 62840
using System;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        // 入力
        long n = long.Parse(Console.ReadLine());
        long[] abcde = new long [5];
        abcde[0] = long.Parse(Console.ReadLine());
        abcde[1] = long.Parse(Console.ReadLine());
        abcde[2] = long.Parse(Console.ReadLine());
        abcde[3] = long.Parse(Console.ReadLine());
        abcde[4] = long.Parse(Console.ReadLine());

        //abcdeからMINを見つける
        long min = abcde.Min();

        //MINの時の最短時間を考える
        long ans = 5;
        if (n-1 > min)
        {
             ans += (n-1)/min;
             
        }
       
        Console.WriteLine(ans);

    }
}


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

#define ll long long
#define pb push_back
#define sz(x) (int)(x).size()
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& a) {
	os << '{';
	for(int i=0;i<sz(a);i++)
	{
		if(i>0&&i<sz(a)-1)
			os << ", ";
		os << a[i];
	}
	os << '}';
    return os;
}
const int N=16,M=(1<<16);
ll dp[M];
int number[M];
vector<int> yes[N+1];
ll a[N][N];
ll sum[M];
int main()
{
    for(int i=0;i<M;i++)
        dp[i]=-1;
    sum[0]=0;
    dp[0]=0;
    int n;
    scanf("%i",&n);
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            scanf("%lld",&a[i][j]);
    for(int i=0;i<(1<<n);i++)
    {
        int k=__builtin_popcount(i);
        yes[k].pb(i);
    }
    for(int i=1;i<=n;i++)
    {
        for(auto p:yes[i])
        {
            for(int j=0;j<n;j++)
            {
                if((1<<j)&p)
                {
                    sum[p]=sum[(1<<j)^p];
                    for(int l=j+1;l<n;l++)
                    {
                        if((1<<l)&p)
                        {
                            sum[p]+=a[j][l];
                        }
                    }
                    break;
                }
            }
        }
    }
    for(int i=1;i<(1<<n);i++)
        for(int j=i;j;j=(j-1)&i)
            dp[i]=max(dp[i],dp[i^j]+sum[j]);
    printf("%lld\n",dp[(1<<n)-1]);
    return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

#define MAX_M 100002

bool space_sort(const pair<int, int>& p1, const pair<int, int>& p2) {
	return p1.second > p2.second;
}

int main() {
	int N, M;
	cin >> N >> M;
	int X[MAX_M] = {0};
	for (int i = 0; i < M; i++) {
		cin >> X[i];
	}
	if (N >= M) {
		cout << 0 << endl;
	} else {
		sort(X, X+M);

		int space[MAX_M] = {0};
		for (int i = 1; i < M; i++) {
			space[i] = X[i]-X[i-1];
		}

		sort(space, space+M, greater<int>());

		int sum = X[M-1]-X[0];

		for (int i = 0; i < N-1; i++) {
			sum -= space[i];
		}

		cout << sum << endl;
	}
}


Measured memory_bytes: 1024
/*ヽ｀、ヽ｀｀、ヽ｀ヽ｀、、ヽ ｀ヽ 、ヽ｀｀ヽヽ｀ヽ、ヽ｀
ヽ｀、ヽ｀｀、ヽ 、｀｀、 ｀、ヽ｀ 、｀ ヽ｀ヽ、ヽ ｀、ヽ｀｀、
ヽ、｀｀、｀、ヽ｀｀、 、ヽヽ｀、｀、、ヽヽ、｀｀、 、 ヽ｀、
ヽ｀｀、 ヽ｀ヽ｀、、ヽ ｀ヽ 、 ヽ｀｀｀｀ヽヽヽ｀、、ヽ｀、、ヽ*/
#include <bits/stdc++.h> 
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long   ll;
typedef long double ld;
typedef complex< ld > cd;
 
typedef pair<int, int> pi;
typedef pair<ll, ll>   pl;
typedef pair<ld, ld>   pd;
 
typedef vector< int > vi;
typedef vector< ld >  vd;
typedef vector< ll >  vl;
typedef vector< pi >  vpi;
typedef vector< pl >  vpl;
typedef vector< cd >  vcd;
 
#define l00p(i, a, b) for (int i=a; i<(b); i++)
#define loop(i, a)    for (int i=0; i<(a); i++)
#define rep1(i, a, b) for (int i = (b)-1; i >= a; i--)
#define rep(i, a)     for (int i = (a)-1; i >= 0; i--)
#define trav(a, x)    for (auto& a : x)
#define uid(a, b)     uniform_int_distribution<int>(a, b)(rng)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f  first
#define s  second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
//#define MOD 998244353
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
map<int,int> ma,mb;
map<int,int> fac(ll n)
{
	map<int,int> f;
	while(n%2==0)
	{
		n/=2;
		f[2]++;
	}
	for(int i=3;i<=sqrt(n);i+=2)
	{
		while(n%i==0)
		{
			n/=i;
			f[i]++;
		}
	}
	if(n>1)
	f[n]++;
	return f;
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); 
	ll a,b;
	cin>>a>>b;
	ma=fac(a);
	mb=fac(b);
	ll ans=0;
	trav(i,ma)
	{
		if(i.s!=0 && mb[i.f]!=0)
		{
			ans++;
			//cout<<i.s<<nl;
		}
	}
	cout<<ans+1;
	return 0;
}
// read the question correctly (ll vs int)
// template by bqi343

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

#define dbg(a)  cerr << __LINE__ << ": " << #a << " = " << a << '\n'

typedef long long ll;

int main(){
  int a, b, c, d; cin >> a >> b >> c >> d;
  int t = ceil(1.0*c/b);
  int s = ceil(1.0*a/d);
  if(t <= s)  cout << "Yes" << endl;
  else  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
using namespace std;
const int C_MAX = 30;
const int D_MAX = 1000;
const int INF = 1100000000;

int main() {
	int n, c;
	cin >> n >> c;
	int D[C_MAX][C_MAX];
	for (int i = 0; i < c; i++) {
		for (int j = 0; j < c; j++) {
			cin >> D[i][j];
		}
	}
	int v[3][C_MAX] = {{0}};
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			int c;
			cin >> c;
			c--;
			v[(i+j)%3][c]++;
		}
	}
	long long ans = INF;
	for (int c0 = 0; c0 < c; c0++) {
		for (int c1 = 0; c1 < c; c1++) {
			for (int c2 = 0; c2 < c; c2++) {
				if (c0 == c1 || c1 == c2 || c0 == c2) continue;
				long long now = 0;
				vector<int> colors = {c0, c1, c2};
				for (int i = 0; i < 3; i++) {
					for (int j = 0; j < c; j++) {
						now += v[i][j] * D[j][colors[i]];
					}
				}
				ans = min(ans, now);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <set>
#include <map>
#include <queue>
#include <stack>

using namespace std;

#define INF 1010001000
#define EPS 1e-10
#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef pair<int, int> i_i;
typedef long long int llong;
typedef pair<llong, llong> ll_ll;
typedef struct edge {int f, t;}Edge;


int main()
{
    int n;
    while (cin >> n, n) {
        vector<int> in(n);
        rep(i, n) {
            string st;
            cin >> st;
            in[i] = st.length();
        }
        bool ret = false;
        rep(i, n) {
            int tnk = 0, state = 0;
            if (ret) {
                break;
            }
            for (int j = i; j < n; j++) {
                if (state == 0) {
                    tnk += in[j];
                    if (tnk == 5) {
                        state++;
                        tnk = 0;
                    } else if (tnk > 5) {
                        break;
                    }
                } else if (state == 1) {
                    tnk += in[j];
                    if (tnk == 7) {
                        state++;
                        tnk = 0;
                    } else if (tnk > 7) {
                        break;
                    }
                } else if (state == 2) {
                    tnk += in[j];
                    if (tnk == 5) {
                        state++;
                        tnk = 0;
                    } else if (tnk > 5) {
                        break;
                    }
                } else if (state == 3) {
                    tnk += in[j];
                    if (tnk == 7) {
                        state++;
                        tnk = 0;
                    } else if (tnk > 7) {
                        break;
                    }
                } else if (state == 4) {
                    tnk += in[j];
                    if (tnk == 7) {
                        cout << i+1 << endl;
                        ret = true;
                        break;
                    } else if (tnk > 7) {
                        break;
                    }
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3112
#include"bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
    int a;
    cin >> a;
    cout << 3 * a * a << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
static const int M = 100;
static const int INF = (1<<21);
static const int W = 0;
static const int G = 1;
static const int B = 2;

int n, m[M][M];

int prim() {
	int u, minv,sum=0;
	int i,v,d[M], p[M], c[M];

	for (i = 0; i < n; i++) {
		d[i] = INF;
		p[i] = -1;
		c[i] = W;
	}
	d[0] = 0;
	while (1) {
		minv = INF;
		u = -1;
		for (i = 0; i < n; i++) {
			if (minv > d[i] && c[i] != B) {
				u = i;
				minv = d[i];
			}
		}
		if (u == -1) {
			break;
		}
		c[u] = B;
		for (v = 0; v < n; v++) {
			if (c[v] != B && m[u][v] != INF) {
				if (d[v] > m[u][v]) {
					d[v] = m[u][v];
					p[v] = u;
					c[v] = G;
				}
			}
		}
	}
	for (i = 0; i < n; i++) {
		if (p[i] != -1) {
			sum += m[i][p[i]];
		}
	}
	return sum;
}

int main(void) {
	int i,j,e;
	cin >> n;
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			cin >> e;
			m[i][j] = (e == -1) ? INF : e;
		}
	}
	cout << prim() << endl;
	return 0;
}



Measured memory_bytes: 3156
#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
	cin >> s;
	if (s == "SAT")cout << 1 << endl;
	if (s == "SUN")cout << 7 << endl;
	if (s == "MON")cout << 6 << endl;
	if (s == "TUE")cout << 5 << endl;
	if (s == "WED")cout << 4 << endl;
	if (s == "THU")cout << 3 << endl;
	if (s == "FRI")cout << 2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
#define MOD 1000000007LL
#define endl "\n"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N;
  cin >> N;
  vector<string> s(N);
  ll ans = 0;
  ll acount = 0, bcount = 0, abcount = 0;
  for(int i = 0; i < N; i++){
    cin >> s.at(i);
    ll n = s.at(i).size();
    for(int j = 0; j < n; j++){
      if(s.at(i).substr(j, 2) == "AB") ans++;
    }
    if(s.at(i).at(0) == 'B' && s.at(i).at(n-1) == 'A') abcount++;
    else if(s.at(i).at(0) == 'B') bcount++;
    else if(s.at(i).at(n-1) == 'A') acount++;
  }
  if(abcount == 0) ans += min(acount, bcount);
  else if(acount > 0 && bcount > 0) ans += min(acount, bcount) + abcount;
  else if(acount > 0 || bcount > 0) ans += abcount;
  else ans += abcount - 1;
  cout << ans << endl;
}

Measured memory_bytes: 768
import collections

n = int(input())
a_list = list(map(int, input().split()))
max_cnt = 0

c = collections.Counter(a_list)

for i in range(max(c.keys()) + 1) :
    cnt = c[i] + c[i + 1] + c[i + 2]
    
    if max_cnt < cnt :
        max_cnt = cnt

print(max_cnt)

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

int main(void){
    int N;
    cin >> N;
    string s;
    cin >> s;
    vector<int> w(N), e(N);
    
    w[0] = (s[0] == 'W' ? 1 : 0);
    e[N-1] = (s[N-1] == 'E' ? 1 : 0);
    
    for(int i=1; i<N; i++) {
        if(s[i] == 'W') w[i] = w[i-1]+1;
        else w[i] = w[i-1];
        
        if(s[N-i-1] == 'E') e[N-i-1] = e[N-i]+1;
        else e[N-i-1] = e[N-i];
    }
    
    //for(int i=0; i<N; i++) cout << e[i] << endl;
    
    int minf = e[1];
    for(int i=1; i<N-1; i++) {
        minf = min(minf, w[i-1]+e[i+1]);
        //cout << minf << endl;
    }
    minf = min(minf, w[N-2]);
    cout << minf << endl;
    
    return 0;    
}


Measured memory_bytes: 3076
import sys
input = sys.stdin.readline
from math import sqrt

x=int(input())

DIV=[]

for i in range(1,int(sqrt(x))+2):
    if x%i==0:
        DIV.append(i)
        DIV.append(x//i)

ANS=[]
for d in DIV:
    if d==1:
        continue
    k=x
    while k%d==0:
        k//=d
    if k%d==1:
        ANS.append(d)

t=x-1
for i in range(1,int(sqrt(t))+2):
    if t%i==0:
        ANS.append(i)
        ANS.append(t//i)

print(len(set(ANS))-1)

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

using namespace std;

const int N = 188; 

int dpR[2][N][N][N];
int dpD[2][N][N][N];

// when range [l, r), has property P~notP, want last P.
// when return l-1, means not found.
template <typename T>
inline
T bs_last(T l, T r, function<bool (T)> f) {
    assert(l < r);
    T mid;
    while (l != r) {
        mid = (l+r)/2;
        if (f(mid)) {
            l = mid + 1;
        }else {
            r = mid;
        }
    }
    return r-1;
}

void solve() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> a(n+1, vector<int>(m+1, 0));
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            char c; cin >> c;
            if (c == '#') a[i][j] = 1;
        }
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            a[i][j] += a[i][j-1];
        }
    }
    for (int j = 1; j <= m; j++) {
        for (int i = 1; i <= n; i++) {
            a[i][j] += a[i-1][j];
        }
    }
    auto sum = [&](int x, int y, int u, int v){
        return a[u][v] - a[x-1][v] - a[u][y-1] + a[x-1][y-1];
    };
    auto mono = [&](int x, int y, int u, int v){
        int tmp = sum(x, y, u, v);
        return tmp == 0 || tmp == (u-x+1)*(v-y+1);
    };
    for (int x = 1; x <= n; x++) {
        for (int y = 1; y <= m; y++) {
            for (int u = x; u <= n; u++) {
                dpR[0][x][y][u] = bs_last<int>(y, m+1, [&](int v){
                        return mono(x, y, u, v);
                        });                
            }
            for (int v = y; v <= m; v++) {
                dpD[0][x][y][v] = bs_last<int>(x, n+1, [&](int u){
                        return mono(x, y, u, v);
                        });
            }
        }
    }
    for (int res = 0; ; res++) {
        if (dpR[0][1][1][n] == m) {
            cout << res; break;
        }
        for (int x = 1; x <= n; x++) {
            for (int y = 1; y <= m; y++) {
                for (int u = x; u <= n; u++) {
                    int v = dpR[0][x][y][u];
                    if (v < m) v = dpR[0][x][v+1][u];
                    dpR[1][x][y][u] = v;
                }
                for (int v = y; v <= m; v++) {
                    int u = dpD[0][x][y][v];
                    if (u < n) u = dpD[0][u+1][y][v];
                    dpD[1][x][y][v] = u;
                }
            }
        }
        for (int x = 1; x <= n; x++) {
            for (int y = 1; y <= m; y++) {
                for (int u = x; u <= n; u++) {
                    int v = dpR[1][x][y][u];
                    while (v < m && dpD[1][x][y][v+1] >= u) {
                        v++;
                    }
                    dpR[0][x][y][u] = v;
                }
                for (int v = y; v <= m; v++) {
                    int u = dpD[1][x][y][v];
                    while (u < n && dpR[1][x][y][u+1] >= v) {
                        u++;
                    }
                    dpD[0][x][y][v] = u;
                }
            }
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 103936
#include <bits/stdc++.h>
using namespace std;
char inp[200];
int main()
{
	scanf(" %s", inp);
	if (inp[0] == 'Y' && inp[1] == 'A' && inp[2] == 'K' && inp[3] == 'I') printf("Yes\n");
	else printf("No\n");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int x, n, y, z=1, i, t=1;
	scanf("%d", &n);
	if(n>=1 && n<=100){
			z=800*n;
		if(n>15){
			i=n/15;
			t=z-(i*200);
			printf("%d", t);
		}
		else{
			printf("%d", z);
		}
	}
	else{
		printf("Error");
	}
	return 0;
}

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

int main()
{
    int h1,h2,k1,k2,a,b,c,d;
    cin >> h1 >> h2 >> k1 >> k2 >> a >> b >> c >> d;
    int n=0,m=0;
    n+=h1*a+h2*b+(h1/10) *c+(h2/20)*d;
    m+=k1*a+k2*b+(k1/10) *c+(k2/20)*d;
    if(n>m)
        cout << "hiroshi" << endl;
    else if(n<m)
        cout << "kenjiro" << endl;
    else
        cout << "even" << endl;
    return 0;
}



Measured memory_bytes: 3100
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

#define d(s, e) distance(s, e)
typedef vector<int> v;
typedef v::iterator vi;
int c = 0;

void mm(vi l, vi m, vi r)
{
	v L(d(l, m));
	copy(l, m, L.begin());
	vi cp = L.begin();

	for (vi i = l; i != r; i++) {
		if (cp == L.end()) {
			c += d(i, r);
			break;
		} else if (m == r) {
			c += d(i, r);
			copy(cp, L.end(), i);
			break;
		} else if(*cp <= *m)
			*i = *cp, cp++;
		else
			*i = *m, m++;
		c++;
	}


}

void ms(vi l, vi r)
{
	if (l + 1 < r) {
		vi m = l + d(l, r) / 2;
		ms(l, m);
		ms(m, r);
		mm(l, m, r);
	}
}

int main()
{
	int n;
	scanf("%d", &n);
	v S(n);
	for (int &x :S)
		scanf("%d", &x);

	ms(S.begin(), S.end());

	for (int &x: S)
		printf("%s%d", &x == &S[0] ? "": " ", x);
	puts("");
	printf("%d\n", c);
}


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

using namespace std;


int main() {
    
    // cinを高速にするためのおまじない
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    //Write code below
    
    string str;
    
    cin >> str;
    
    for (int i = 0; i < 3; i++) {
        if(str.at(i) == str.at(i + 1)) {
            cout << "Bad" << endl;
            exit(0);
        }
    }
    
    cout << "Good" << endl;

}


Measured memory_bytes: 256
M=10**9+7
q=->a,b{b<1?1:a**b[0]*q[a*a%M,b/2]}
f=->r,c{s=t=1
c.times{|i|t=t*-~i%M
s=s*(r+c-i)%M}
s*q[t,M-2]%M}
eval"A,B,C,D="+`tr \\  ,`
p (f[A,B]-f[C+=1,B]-f[A,D+=1]+f[C,D])%M

Measured memory_bytes: 2136
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <functional>
#include <utility>
#include <queue>
#include <vector>
#include <string>
#include <stack>
#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;
typedef long long int ll;
const ll  MOD = 1000000007;
typedef pair<ll,ll> P;
const ll INF = 100100100100100100;

string s;
int main(){
  cin >> s;
  if(s.size() >= 4 && s[0] == 'Y' && s[1] == 'A' && s[2] == 'K' && s[3] == 'I'){
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;

}


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

int main() {
  // ここにプログラムを追記
  string s;
  cin >> s;
  if(s[0]==s[1]&&s[1]==s[2]||s[1]==s[2]&&s[2]==s[3]){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int w,n,a,b,l[30],r,i;
	scanf("%d",&w);
	scanf("%d",&n);
	for(i=0;i<w;i++)
		l[i]=i+1;
	for(;n;n--)
	{
		scanf("%d,%d",&a,&b);
		a--,b--;
		r=l[a];
		l[a]=l[b];
		l[b]=r;
	}
	for(i=0;i<w;i++)
		printf("%d\n",l[i]);
return 0;
}

Measured memory_bytes: 0
#include <cstdio>

#define ll long long int
#define mx 10000007

ll* num_f;

int main(){
    int N;
    scanf("%d",&N);
    num_f=new ll[N+1];
    for(int i=1;i<=N;i++) num_f[i]=1;

    for(int i=2;i<=N;i++){
        if(num_f[i]==1){
            num_f[i]=2;

            int f=2*i;
            while(f<=N){
                int fc=0;
                int ff=f;
                while(ff%i==0){
                    ff/=i;
                    fc++;
                }
                num_f[f]*=(fc+1);

                f+=i;
            }
        }
    }
    
    ll ans=0;
    for(int i=1;i<=N;i++){
        ans+=(num_f[i]*i);
    }

    printf("%lld\n",ans);
}


Measured memory_bytes: 81368
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define REPS(i,n) for(int i=1;i<=(n);i++)
#define RREPS(i,n) for(int i=(n);i>0;i--)
#define mp make_pair
#define pb(a) push_back(a)
typedef long long ll;
int main(){
  ll X,Y;
  cin >> X >> Y;
  if(abs(X-Y) <= 1) cout << "Brown" << endl;
  else cout << "Alice" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#define	MOD = 1000000007;
using namespace std;

int main()
{
	int K, S;
	cin >> K >> S;

	int count = 0;
	for (int X = 0; X <= K; X++) {
		for (int Y = 0; Y <= K; Y++) {
			int Z = S - X - Y;
			if (Z >= 0 && Z <= K)
			{
				count++;
			}
		}
	}

	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 20010;

int main(){
    lint X;
    int K;
    scanf("%lld%d", &X, &K);
    lint r[K+1];
    r[0] = 0;
    rep(i, K) scanf("%lld", &r[i+1]);
    lint A[K+1], B[K+1], C[K+1];
    A[0] = 0; B[0] = X; C[0] = 0;
    For(i, 1, K+1){
        lint d = r[i] - r[i-1];
        if(i%2 == 1){
            lint x = d + A[i-1] - C[i-1];
            if(B[i-1]-A[i-1]+C[i-1] <= d){
                A[i] = B[i] = 0; C[i] = 0;
            }
            else if(C[i-1] <= d){
                A[i] = x; B[i] = B[i-1]; C[i] = 0;
            }
            else{
                A[i] = A[i-1]; B[i] = B[i-1]; C[i] = C[i-1] - d;
            }
        }
        else{
            lint x = X-d + A[i-1] - C[i-1];
            if(X-d <= C[i-1]){
                A[i] = B[i] = 0; C[i] = X;
            }
            else if(X-d <= B[i-1]-A[i-1]+C[i-1]){
                A[i] = A[i-1]; B[i] = x; C[i] = C[i-1] + d;
            }
            else{
                A[i] = A[i-1]; B[i] = B[i-1]; C[i] = C[i-1] + d;
            }
        }
    }
    int q;
    scanf("%d", &q);
    int cur = 0;
    rep(_, q){
        lint t, a;
        scanf("%lld%lld", &t, &a);
        while(cur <= K && r[cur] <= t) ++cur;
        lint ans;
        if(a <= A[cur-1]) ans = C[cur-1];
        else if(a <= B[cur-1]) ans = a - A[cur-1] + C[cur-1];
        else ans = B[cur-1] - A[cur-1] + C[cur-1];

        if(cur % 2 == 1) ans = max(0LL, ans - (t - r[cur-1]));
        else ans = min(X, ans + (t - r[cur-1]));

        printf("%lld\n", ans);
    }
}

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

import numpy as np
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix

def main():
  n, m, l = map(int, input().split())
  F = np.zeros((n, n))
  for _ in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    F[a, b] = c
    F[b, a] = c
  csr = csr_matrix(F)
  A = floyd_warshall(csr)
  G = np.zeros((n, n))
  for i in range(n-1):
    for j in range(i+1, n):
      if A[i][j] <= l:
        G[i, j] = 1
        G[j, i] = 1
  ncsr = csr_matrix(G)
  B =  floyd_warshall(ncsr)
  q = int(input())
  for _ in range(q):
    s, t = map(int, input().split())
    k = B[s-1][t-1]
    if k == float("inf"):
      print(-1)
    else:
      print(int(k)-1)
      
if __name__ == "__main__":
  main()

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

#define MAX_N 100
#define MAX_U 10000

int main(){
	int n,u;
	cin>>n>>u;
 
	vector<int> v(n),w(n);	//??????n???vector?????£?¨?
	for(int i=0;i<n;i++){
		cin>>v[i]>>w[i];
	}
 
	//dp?????£?¨???¨?????????
	int dp[MAX_U+1];
	for(int i=0;i<MAX_U+1;i++){
		dp[i]= 0;
	}
 
	//???????????§????????´??°
	for(int i=1;i<=n;i++){
		for(int j=u;j>=1;j--){
			if( j-w[i-1]>=0 ){	//j-w[i-1]???<0??\????????¨??????????????§????????????????????§?????§??????
				dp[j] = max( dp[j-w[i-1]]+v[i-1] , dp[j] );
			}
		}
	}
 
	cout<<dp[u]<<endl;
}

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

int main() {
	// your code goes here
	int i,s,a,b,c,d;
	cin >> s;
	a=(s-s%100)/100;
	b=s-100*a;
	if(1<=a&&a<=12&&1<=b&&b<=12) cout << "AMBIGUOUS" << endl;
	else if(1<=a&&a<=12) cout << "MMYY" << endl;
	else if(1<=b&&b<=12) cout << "YYMM" << endl;
	else cout << "NA" << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<queue>
using namespace std;
queue<int> q;
struct E
{
	int to,y;
}e[400010];
int g[200010],tmp,dis1[200010],disn[200010];
void build (int u,int v)
{
	e[++tmp].y=v;
	e[tmp].to=g[u];
	g[u]=tmp;
}
int main()
{
	int n,u,v;
	scanf("%d",&n);
	for (int i=1;i<n;i++)
	{
		scanf("%d%d",&u,&v);
		build (u,v);
		build (v,u);
	}
	q.push(1);
	while (!q.empty())
	{
		int nx=q.front(); q.pop();
		for (int i=g[nx];i;i=e[i].to)
		if (dis1[e[i].y]==0&&e[i].y!=1)
		{
			dis1[e[i].y]=dis1[nx]+1;
			q.push(e[i].y);
		}
	}
	q.push(n);
	while (!q.empty())
	{
		int nx=q.front(); q.pop();
		for (int i=g[nx];i;i=e[i].to)
		if (disn[e[i].y]==0&&e[i].y!=n)
		{
			disn[e[i].y]=disn[nx]+1;
			q.push(e[i].y);
		}
	}
	int f=0,s=0;
	for (int i=1;i<=n;i++)
	if (dis1[i]<=disn[i]) f++;
	else s++;
	if (f<=s) puts("Snuke");
	else puts("Fennec");
	return 0;
}

Measured memory_bytes: 3456
# ABC141D - Powerful Discount Tickets
from heapq import heapify, heapreplace


def main():
    N, M, *A = map(int, open(0).read().split())
    H = [-i for i in A]
    heapify(H)
    for _ in range(M):
        x = H[0]
        heapreplace(H, x // 2 + x % 2)
    ans = -sum(H)
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 14180
//url:
//problem name:

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long,long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long,long>>;

int main() {
    int N;cin >> N;
    ll x; cin >> x;
    vecl A(N);
    REP(i,N) cin >> A.at(i);
    sort(A.begin(),A.end());
    int ans = 0;
    for(int i = 0; i < N; i++) {
        if(x - A.at(i) >= 0) {
            ans++;
            x -= A.at(i);
        } else break;
    }
    if(ans == N) {
        if(x != 0) ans--;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007

int main(){
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i,n) cin >> p.at(i);
  int ans = 0;
  rep(i,n){
    if(p.at(i) == i+1){
      if(i == n-1){
        ans++;
        break;
      }else{
        ans++;
        swap(p.at(i),p.at(i+1));
      }
    }
  }
  cout << ans << endl;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;

template <typename T>
bool chmax(T& a, const T& b) {
	if (a < b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}

template <typename T>
bool chmin(T& a, const T& b) {
	if (a > b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}


int main() {
	string bus;
	cin >> bus;
	bool a = false, b=false;
	for (auto s : bus) {
		if (s == 'A')a = true;
		if (s == 'B')b = true;
	}

	if (a && b)cout << " Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <cstdio>

using namespace std;

const long long INF = 100000000;
const long long MOD = 1000000007;

std::vector<bool> IsPrime;

void sieve(size_t max)
{
  if (max + 1 > IsPrime.size())
  {                                // resizeで要素数が減らないように
    IsPrime.resize(max + 1, true); // IsPrimeに必要な要素数を確保
  }
  IsPrime[0] = false; // 0は素数ではない
  IsPrime[1] = false; // 1は素数ではない

  for (size_t i = 2; i * i <= max; ++i)     // 0からsqrt(max)まで調べる
    if (IsPrime[i])                         // iが素数ならば
      for (size_t j = 2; i * j <= max; ++j) // (max以下の)iの倍数は
        IsPrime[i * j] = false;             // 素数ではない
}

class Pointer{
public:
  long long p;
  long long w;
};

int main()
{
  string s;
  cin >> s;
  for (int i=0;i<s.length();i+=2){
    cout << s[i];
  }
  cout << endl;
}


Measured memory_bytes: 512
#define D(x) cout << #x " = " << x << endl
#define DD(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define DDD(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl
#define DV(v) for (auto __macro_vi : v){ cout << __macro_vi << " ";} cout << endl;
#define DA(a, n) for (int __macro_i = 0; __macro_i < n; ++__macro_i) { cout << a[__macro_i] << " "; } cout << endl;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) (v).begin(), (v).end()
#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p){ os << "(" << p.first << ", " <<  p.second << ")"; return os; }

using namespace std;
int n;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    vector<int> p(n);
    REP(i, n) cin >> p[i];
    int ans = 0;
    for (int i = 1; i < n - 1; ++i) {
        vector<int> k({p[i - 1], p[i], p[i + 1]});
        sort(k.begin(), k.end());
        // DV(k);
        if (k[1] == p[i]) {ans++;}
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
"""ABC133_C"""
l,r = map(int,input().split())
ans = 999999
if r-l<672:
    for i in range(l,r):
        for j in range(i+1,r+1):
            if((i*j)%2019 < ans):
                ans = (i*j)%2019
else:
    ans = 0
print(ans)

Measured memory_bytes: 38768
#include<bits/stdc++.h>
using namespace std;
int main()
 {
    int t=1;
    while(t--){
        int n;
        cin>>n;
        vector<int> a(n);
        for(int i=0;i<n;i++)
            cin>>a[i];
        long long ans=0;
        map<vector<int>,int> m;
        for(int i=0;i<n;i++){
            for(int j=0;j<i;j++){
                for(int k=0;k<j;k++){
                    if((a[i]+a[j]>a[k] && a[j]+a[k]>a[i] && a[i]+a[k]>a[j])&& a[i]!=a[j] && a[j]!=a[k] && a[i]!=a[k])
                    {  
                       ans++;
                        
                    }
                }
            }
        }cout<<ans;
    }
	return 0;
}

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

int main(){
  int a[3];
  for(int i=0;i<3;i++) cin>>a[i];
  sort(a,a+3);
  int ans;
  if(a[0]%2==a[1]%2 && a[2]%2==a[1]%2) ans=(a[2]-a[0])/2+(a[2]-a[1])/2;
  else if(a[2]%2!=a[1]%2 && a[0]%2==a[1]%2) ans=(a[2]-a[0])/2+(a[2]-a[1])/2+1;
  else{
    if(a[2]%2==a[0]%2) ans=(a[2]-a[0])/2+(a[2]-a[1])/2+2;
    else ans=(a[2]-a[1])/2+(a[2]-a[0])/2+2;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define INF 1000000000000
typedef long long ll;

vector<char> c;

int main()
{
  int n, w = 0, r = 0;
  char tempC;
  cin >> n;
  REP(i, n)
  {
    cin >> tempC;
    c.push_back(tempC);
  }

  REP(i, n)
  {
    if (c[i] == 'R')
    {
      r++;
    }
  }
  int result = max(w, r);
  REP(i, n)
  {
    if (c[i] == 'W')
    {
      w++;
    }
    else if (c[i] == 'R')
    {
      r--;
    }
    int now = max(w, r);
    result = min(result, now);
  }
  cout << result << endl;
}

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


int main() {
int h,w;
cin>>h>>w;
string s[h];
for(int i=0;i<h;i++){
    cin>>s[i];
}
int m[h+2][w+2] ={0};

for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
        if(s[i][j]=='#'){
            for(int k=i;k<i+3;k++){
                for(int l=j;l<j+3;l++){
                    m[k][l]+=1;
                }
            }
        }
    }
}
for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
        if(s[i][j]=='#'){
            cout<<'#';
        }else{
            cout<<m[i+1][j+1];
        }
    }
    cout<<endl;
}
	return 0;
}

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

int main(){
  int a,b;
  cin >> a >> b;
  int numb = b-a;
  int tmp = 0;
  for(int i=0; i<numb; i++){
    tmp += i;
  }
  cout << tmp-a << endl;
}
  

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

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

  if (N % 1110 <= 9) {
    cout << "Yes" << endl;
  }
  else if ((N % 1000) % 111 == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[100005],c[100005],s,cnt;
char st[5];
int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i=0;i<m;i++){
        int x;
        scanf("\n%d %s",&x,st);
        if(st[0]=='W')a[x]++;
        else if(!c[x]){
            c[x]=1;
            s+=a[x];
            cnt++;
        }
    }
    printf("%d %d",cnt,s);
}

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

int n,m;

struct UnionFind{
  vector<int> par;
  UnionFind(int n):par(n){
    rep(i,n) par[i]=i;
  }
  int root(int x){
    if(par[x]==x) return x;
    return par[x]=root(par[x]);
  }
  void unite(int x,int y){
    if(root(x)==root(y)) return;
    par[root(x)]=root(y);
  }
  bool same(int x,int y){
    return root(x)==root(y);
  }
};

int main(){
  cin>>n>>m;
  vector<int> a(n);
  
  UnionFind tree(n);
  rep(i,m){
    int x,y,z;
    cin>>x>>y>>z;
    x--; y--;
    tree.unite(x,y);
  }
  int res=0;
  vector<int> seen(n);
  rep(i,n){
    if(seen[tree.root(i)]!=0) continue;
    seen[tree.root(i)]=1;
    res++;
  }
  cout<<res<<endl;
}

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


int main(){
     
     int n;
     cin>>n;
     map<string,int>m;
     set<string>s;
     int maxi=0;
     for(int i=0;i<n;i++){
     	string a;
     	cin>>a;
     	if(auto it=m.find(a)!=m.end()){
     		m[a]++;
     		maxi=max(maxi,m[a]);
     	}
     	else{
     		m[a]=1;
     		maxi=max(maxi,m[a]);
     	}
     }
     for(auto it=m.begin();it!=m.end();it++){
     	if(maxi==it->second){
     		s.insert(it->first);
     	}
     }
     for(auto it=s.begin();it!=s.end();it++){
     	cout<<*it<<endl;
     }
}		



Measured memory_bytes: 34780
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
  bool b=false;
  string s,t;
  cin>>s>>t;
  for(int i=s.size()-t.size();i>=0;i--){
    rep(j,t.size()){
      if(t[j]!=s[i+j] && s[i+j]!='?') break;
      else if(j==t.size()-1){
	b=true;
	rep(k,t.size()){
	  s[i+k]=t[k];
	}
      }
    }
    if(b) break;
  }
  if(b){
    rep(i,s.size()) if(s[i]=='?') s[i]='a';
  }else s="UNRESTORABLE";
  cout<<s<<endl;
  return 0;
}










Measured memory_bytes: 256
n, k = map(int, input().split())
kkn = [list(map(int, input().split())) for _ in range(k)]
MOD = 998244353

dp = [0]*(n+1)
dp[1] = 1
dpac = [0]*(n+1)
dpac[1] = 1
for i in range(2, n+1):
    for kl, kr in kkn:
        l = i-kr
        r = i-kl
        if r < 0: continue
        l = max(l, 0)
        dp[i] += dpac[r] - dpac[l-1]
        dp[i] %= MOD
    dpac[i] = dpac[i-1] + dp[i]
    dpac[i] %= MOD
print(dp[n])

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

int calc_sat(int D, int N, vector<int> c, vector<vector<int>> s, vector<int> t) {
	vector<int> last(N,-1);
	int sat = 0;  // 満足度
	rep(d,D) {
		last[t[d]] = d;
		sat += s[d][t[d]];
		rep(i,N) {
			sat -= c[i] * (d-last[i]);
		}
	}
	return sat;
}

int main() {
	int D;
	cin >> D;
	const int N = 26; // コンテストの種類
	vector<int> c(N);
	rep(i,N) cin >> c[i];
	vector<vector<int>> s(D, vector<int>(N));
	rep(i,D) rep(j,N) cin >> s[i][j];

	vector<int> t(D); // 開催するコンテスト

	int c_max = 0; // c[i]が最も大きいコンテスト
	rep(i,N) if (c[c_max]<c[i]) c_max = i;

	// 初期解
	rep(i,D) {
		t[i] = rand() % 26;
	}

	// 改善

	// 出力
	rep(i,D) {
		printf("%d\n", t[i]+1);
	}

	return 0;
}


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

def z_algo(S):
    N = len(S)
    A = [0]*N
    i = 1; j = 0
    A[0] = l = len(S)
    while i < l:
        while i+j < l and S[j] == S[i+j]:
        	j += 1
        if not j:
            i += 1
            continue
        A[i] = j
        k = 1
        while l-i > k < j - A[k]:
            A[i+k] = A[k]
            k += 1
        i += k; j -= k
    return A
ans = 0
for i in range(n-1):
	tmp = z_algo(s[i:])
	for j,zj in enumerate(tmp):
		if j+1 > zj:
			ans = max(ans,zj)

print(ans)


Measured memory_bytes: 49756
import numpy as np
N, K = map(int, input().split(" "))
H = np.array([int(i) for i in input().split(" ")])

cost = np.array([0] + [10**9 for _ in range(N-1)])
for i in range(1,N):
    cost[i] = np.min(cost[max(0,i-K):i] + np.abs(H[max(0,i-K):i] - H[i]))

print(cost[-1])

Measured memory_bytes: 24836
#include "bits//stdc++.h"
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 998244353;

#define rep(i,n) for (int i = 0; i < (n); i++)
#define ALL(v) v.begin(), v.end()

int main() {
	ll r, D, x;
	cin >> r >> D >> x;
	for (int i = 1; i <= 10; i++) {
		x = r * x - D;
		cout << x << endl;
	}
}

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

int n, m, a[50], b[50], c[50], d[50];

int calc(int n, int m) {
    return abs(a[n] - c[m]) + abs(b[n] - d[m]);
}

int main(void){
    cin >> n >> m;
    for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
    for (int i = 0; i < m; i++) cin >> c[i] >> d[i];
    for (int i = 0; i < n; i++) {
        int ans = 0;
        for (int j = 1; j < m; j++) if (calc(i, ans) > calc(i, j)) ans = j;
        cout << ans + 1 << endl;
    }
}


Measured memory_bytes: 256
import math
a,b,c = map(float,input().split())
s = 0.5*a*b*math.sin(math.radians(c))
l = a+b+math.sqrt(a*a+b*b-2*a*b*math.cos(math.radians(c)))
h = 2*s/a
print(s,l,h, sep='\n')



Measured memory_bytes: 5696
def calc_digit_sum(n):
    return sum(list(map(int, list(str(n)))))

n = int(input())
ans = 10000000
for i in range(1, int(n/2) + 1):
    ans = min(calc_digit_sum(i) + calc_digit_sum(n-i), ans)
print(ans)

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

using namespace std;
using ll = long long;

ll dp[200005][4];

int main() {
	int n, m, sum = 0;
	cin >> n >> m;
	vector<int> a(n);
	rep(i, n) {
		cin >> a[i];
		sum += a[i];
	}
	sort(a.begin(), a.end());
	string ans;
	a[n - m] >= (4 * m + sum - 1) / (4 * m) ? ans = "Yes" : ans = "No";
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3632
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1


N = int(input())
info_list = []

for i in range(N):
    city, point = map(str, input().split())
    info_list.append([city, int(point), i+1])

# Point-Sort => City Sort
info_list.sort(key=lambda x: x[1], reverse=True)
info_list.sort(key=lambda x: x[0])

for info in info_list:
    print(info[2])


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

int main(void) {
  int n, a, b;
  cin >> n >> a >> b;
  cout << min(a, b) << " ";
  int res = a + b - n;
  if (res < 0) res = 0;
  cout << res << endl; 
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int lt;
int main()
{
    lt N;
    cin>>N;
    lt H[N];
    for(lt i=0; i<N; i++)
    {
        cin>>H[i];
    }
    lt diff[N],x,y;
    diff[0]=0;
    diff[1]=abs(H[1]-H[0]);
    for(lt i=2;i<N;i++)
    {
        x=(diff[i-1]+abs(H[i]-H[i-1]));
        y=(diff[i-2]+abs(H[i]-H[i-2]));
        diff[i]=(   (x>y)   ?   y:x);
    }
   /* for(lt i=0; i<N; i++)
    {
        cout<<H[i]<<"\t";
    }
    cout<<endl;
    
    for(lt i=0; i<N; i++)
    {
        cout<<diff[i]<<"\t";
    }*/
    cout<<diff[N-1];
    
    return 0;
}

Measured memory_bytes: 1792
import java.util.*;


public class Main {

	/**
	 * @param args
	 */

	Scanner sc = new Scanner(System.in);
	int moto,z=1,sua[]=new int[4],sub[]=new int[4],total[]=new int[16],out[]=new int[4],tc=0,count=0;
	String info[] = {"1","i","j","k"},tinfo[] = new String[16];

	void in(){

		moto = sc.nextInt();

		while(0 != moto){
			if(count >= moto){
				moto = sc.nextInt();
				count = 0;
			}else{
				for(int t=0;t<moto;t++){
					for(int i=0;i<4;i++){
						sua[i] = sc.nextInt();
					}
					for(int i=0;i<4;i++){
						sub[i] = sc.nextInt();
					}
					count++;
					syori();

					Arrays.fill(out, 0);
					tc = 0;
				}
			}
		}
	}

	void syori(){
		for(int l=0;l<4;l++){
			for(int y=0;y<4;y++){
				total[tc] = sua[l] * sub[y];
				tinfo[tc] = info[l] + info[y];
				tc++;
			}
		}
		for(int n=0;n<16;n++){
			if("11".equals(tinfo[n])){
				out[0] += total[n];
			}else{
				if("ii".equals(tinfo[n])|| "kk".equals(tinfo[n])|| "jj".equals(tinfo[n])){
					out[0] -= total[n];
				}else{
					if("1i".equals(tinfo[n])|| "i1".equals(tinfo[n])|| "jk".equals(tinfo[n])){
						out[1] += total[n];
					}else{
						if("1j".equals(tinfo[n]) || "j1".equals(tinfo[n]) || "ki".equals(tinfo[n])){
							out[2] += total[n];
						}else{
							if("1k".equals(tinfo[n]) || "k1".equals(tinfo[n]) || "ij".equals(tinfo[n])){
								out[3] += total[n];
							}else{
								if("ji".equals(tinfo[n])){
									out[3] -= total[n];
								}else{
									if("ik".equals(tinfo[n])){
										out[2] -= total[n];
									}else{
										if("kj".equals(tinfo[n])){
											out[1] -= total[n];
										}
									}
								}
							}
						}
					}
				}
			}
		}
		for(int u=0;u<4;u++){
			System.out.print(out[u]);
			if(u < 3){
				System.out.print(" ");
			}else{
			}
		}
		System.out.println();
	}



	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Main q = new Main();
		q.in();
	}

}

Measured memory_bytes: 23848