akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
using namespace std;
#define fi first
#define se second
typedef long long lli;
typedef pair<int, int> pii;
int M, D;

void ReadInput()
{
    cin >> M >> D;
}

void Solve()
{
    int ans = 0;
    for(int m = 1; m <= M; ++m)
        for(int d = 10; d <= D; ++d)
        {
            int d1 = d % 10;
            int d2 = (d / 10) % 10;
            if(d1 >= 2 && d2 >= 2 && d1 * d2 == m) ++ans;
        }
    cout << ans << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ReadInput();
    Solve();
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
	long long a,b,x,ans,num;
	cin>>a>>b>>x;
    ans=b/x;
    num=a/x;
    if(a%x==0)
    ans+=1;
    cout<<ans-num<<endl;
    return 0;
} 

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount
	
#define rep(i, n) for (int i = 0; i < n; ++i)

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;


int main()
{
	int n, p[64];
	while (scanf("%d", &n), n)
	{
		rep (i, n)
			scanf("%d", p + i);
		p[n++] = -1;
		int from = 0;
		for (int i = 1; i < n; ++i)
		{
			if (p[i - 1] + 1 != p[i])
			{
				if (i - from == 1)
					printf("%d", p[from]);
				else
					printf("%d-%d", p[from], p[i - 1]);

				printf("%c", i + 1 == n ? '\n' : ' ');
				from = i;
			}
		}
	}
}

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

#define ll long long int
#define floop(i,a,b) for(ll i=a;i<b;i++)
#define all(v) v.begin(),v.end()
int solve(){
 
     ll k,a,b; cin>>k>>a>>b;
     for(ll i=a;i<=b;i++){
        if(i%k==0) return cout<<"OK"<<endl,0;
     }

     return cout<<"NG"<<endl,0;

return 0;
}

int main()
{ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); 

    ll t; t=1;
    //cin>>t;

    while(t--)
       solve();
    return 0;
}

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


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

    int N,K,ans;
    cin >> N >> K;
    ans = 0;
    for (int i=0; i<N; i++){
        int h;
        cin >> h;
        if (h>=K){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <cmath>
#define INF 100000000000
#define MOD 1000000007
#define ll long long int
using namespace std;

int main(){
  string S; cin>>S;
  vector <int> num;
  ll cnt_q = 0;
  ll fixed = 0;
  ll ten = 1;
  for(int i=S.size()-1;i >= 0;i--){
    if(S[i] != '?') {fixed += ten * (S[i] - '0');ten = ten * 10;ten = ten % 13; fixed = fixed % 13;continue;}
    
    num.push_back(ten);
    ten = ten * 10 % 13;
    cnt_q++;

  }

  if(cnt_q == 0){cout<< (fixed % 13 == 5 ? 1 : 0) << endl;return 0;}

  ll dp[cnt_q + 10][13];

  for(int i=0;i<=cnt_q+5;i++){
    for(int j=0;j<=12;j++){
      dp[i][j] = 0;
    }
  }

  for(int i=0;i<=9;i++){
    dp[0][num[0] * i % 13]++;
  }

  for(int i=1;i<cnt_q;i++){
    vector <int> left(13,0);
    for(int j=0;j<=9;j++){
      left[num[i] * j % 13]++;
    }

    for(int j=0;j<=12;j++){
      for(int k = 0;k<=12;k++){
        dp[i][(j + k) % 13] += dp[i-1][j] * left[k] % MOD;
        dp[i][(j + k) % 13] = dp[i][(j + k) % 13] % MOD;

      }
    }
  }

  cout<<dp[cnt_q-1][(13 + 169 + 5 - fixed) % 13] <<endl;
 // cout<<fixed<<endl;
  //cout<<num[0]<<endl;
 /* 
  for(int i=0;i<=12;i++){
    cout<<i<<" "<<dp[cnt_q-1][i]<<endl;
  }

  cout<<fixed<<endl;
*/
  return 0;

}

Measured memory_bytes: 11128
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long
using namespace std;
int cmp(ll a,ll b)
{
    return a>b;
}
int main()
{
    vector<ll>w;
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    w.push_back(a*c);
    w.push_back(a*d);
    w.push_back(b*c);
    w.push_back(b*d);
    sort(w.begin(),w.end(),cmp);
    printf("%lld",w[0]);
    return 0;
}


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

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

    int N;
    cin >> N;
    vector<int> L(N);
    int tmp;
    for (int i = 0; i < N; i++) {
        cin >> tmp;
        L[i] = tmp;
    }

    sort(L.begin(), L.end());
    int largest = L.back();
    L.pop_back();
    int sum = accumulate(L.begin(), L.end(), 0);
    if (largest < sum) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n;
  cin>>n;
  int cnt=0;
  int target=1;
  for(int i=0;i<n;i++){
    int data;
    cin>>data;
    if(data==target){
      target++;
    }else{
      cnt++;
    }
  }
  if(cnt==n){
    cout<<-1<<endl;
  }else{
    cout<<cnt<<endl;
  }
  return(0);
}


Measured memory_bytes: 256
s = input()
acgt = ['A', 'C', 'G', 'T']
if s[0] in acgt:
  tmp = 1
else:
  tmp = 0
res = tmp
for i in range(len(s)-1):
  if s[i+1] in acgt:
    tmp += 1
    res = max(res, tmp)
  else:
    tmp = 0
print(res)

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

#define rep(i,n) for(ll i=0;i<(n);++i)
#define reps(i,n) for(ll i=1;i<=(n);++i)
using ll = long long;
using str = string;
constexpr long long INF = (1LL<<60);
constexpr long long MOD = (1e9+7);
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
inline void dump(){cout<<endl;}
template<class Head,class... Tail>inline void dump(Head&& head, Tail&&... tail){cout<<head<<", ";dump(forward<Tail>(tail)...);}
template<typename T>inline istream &operator>>(istream&input,vector<T>&v){for(auto &elemnt:v)input>>elemnt;return input;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}

main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout<<fixed<<setprecision(10);

  ll n;
  cin>>n;
  vector<string> s(n);
  cin>>s;

  vector<ll> deg(n);
  vector<vector<ll>> adj(n);
  rep(i,n)rep(j,n){
    if(s[i][j]=='1'){
      deg[i]++;
      adj[i].push_back(j);
    }
  }
  vector<pair<ll,ll>> degv(n);
  rep(i,n)degv[i]=make_pair(deg[i],i);
  sort(degv.begin(),degv.end());

  ll res=-1;
  auto solve = [&](ll idx){
    vector<vector<ll>> V(n);
    vector<ll> prev_v(n,-1);
    vector<bool> visited(n,false);
    queue<ll> que;
    que.emplace(degv[idx].second);
    prev_v[degv[idx].second]=0;
    while(!que.empty()){
      ll now_v = que.front();
      que.pop();
      if(visited[now_v])continue;
      visited[now_v]=true;
      V[prev_v[now_v]].push_back(now_v);
      for(auto next_v:adj[now_v]){
        prev_v[next_v]=prev_v[now_v]+1;
        que.emplace(next_v);
      }
    }
    ll ans=0;
    rep(i,n){
      if(V[i].size()>0)ans=i+1;
    }
    bool ok=true;
    rep(i,n)rep(j,n){
      if(s[i][j]=='1'){
        if(abs(prev_v[i]-prev_v[j])!=1)ok=false;
      }
    }
    //cout<<(ok?ans:-1)<<endl;
    if(ok)chmax(res,ans);
  };

  rep(i,n)solve(i);
  cout<<(res)<<endl;


}


Measured memory_bytes: 1120
import java.util.Scanner;

public class Main {

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

        String s = sc.next();
        int answer = 0;

        while (true) {
            s = s.substring(0, s.length() - 1);

            int halfNum = s.length() / 2;

            String beforeHalf = s.substring(0, halfNum);
            String afterHalf = s.substring(halfNum, s.length());

            // 前後半長さが違うと遇文字列にならない
            if (beforeHalf.length() != afterHalf.length()) {
                continue;
            }

            if (beforeHalf.equals(afterHalf)) {
                answer = s.length();
                break;
            }
        }

        System.out.println(answer);
    }

}


Measured memory_bytes: 23764
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 200005
using namespace std;
char s[maxn];
int n,g[maxn];
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	for (int i=1;i<=n;i++){
		g[i]=1;
		if (i>1&&s[i]!=s[i-1]) g[i]=g[i-1]+1;
		if (i>=3) g[i]=max(g[i],g[i-3]+2);
	}
	printf("%d",g[n]);
	return 0;
}

Measured memory_bytes: 1152
import java.io.PrintWriter

fun main(args: Array<String>) {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}

fun solve(out: PrintWriter) {
    val L = readInteger()
    println(L * L * L / 27.0)
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


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

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

multiset<ll> s,r;


int main(){
    ll a,b,c,n;
    cin>>n>>a>>b>>c;
    string res="";
    string stmp="";
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        if(stmp!=""){
            if(stmp==s){
                res=res+s[0]+"\n"+s[1]+"\n";
                stmp="";
                continue;
            }else{
                if(stmp=="AB"){
                    if(s=="BC"){
                        res+="B\n";
                        a--;b++;
                    }else if(s=="AC"){
                        res+="A\n";
                        a++;b--;
                    }
                }else if(stmp=="AC"){
                    if(s=="AB"){
                        res+="A\n";
                        a++;c--;
                    }else if(s=="BC"){
                        res+="C\n";
                        a--;c++;
                    }
                }else{//BC
                    if(s=="AB"){
                        res+="B\n";
                        b++;c--;
                    }else if(s=="AC"){
                        res+="C\n";
                        b--;c++;
                    }
                }
            }
            stmp="";
        }
        ll *x,*y;
        if(s=="AB"){
                x=&a;
                y=&b;
        }else if(s=="AC"){
                x=&a;
                y=&c;
        }else{
                x=&b;
                y=&c;
        }
        if(*x==*y){
            if(*x==0){
                cout<<"No";
                return 0;
            }else{
                stmp=s;
            }
        }else if(*x>*y){
            (*x)--;(*y)++;
            res=res+s[1]+"\n";
        }else{
            (*x)++;(*y)--;
            res=res+s[0]+"\n";
        }
    }
    if(stmp!=""){
        res=res+stmp[0]+"\n";
    }
    cout<<"Yes"<<endl;
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 5308
N=int(input().rstrip())
X=list(map(int, input().rstrip().split())) #input parameters
work=[]
for i in range(N):
    work.append(X[i])
work.sort()
m=int(N/2)
for i in range(N):
    if X[i]<=work[m-1]:
        print(work[m])
    else:
        print(work[m-1])

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


#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define CON 1000000000000
#define SIX 1000000
using namespace std;

struct prefecture {
  int p;
  long long y;
  int i;

  // 最後のconstを忘れると"instantiated from here"というエラーが出てコンパイルできないので注意
   bool operator<( const prefecture& right ) const {
       return p == right.p ? y < right.y : p < right.p;
   }
};

int main() {
  int n,m,x=1,temp = 0;
  cin >> n >> m;
  const int count = m;
  const long long con = 1000000000000, six = 1000000;
  vector<prefecture> v(m);
  std::vector<long long> vec(m);
  int p[m];
  long long y[m];
  for (int i = 0; i < m; i++) {
    cin >> p[i] >> y[i];
    v[i].p = p[i];
    v[i].y = y[i];
    v[i].i = i;
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < count; i++) {
    // cout << "v[" << v[i].i << "] = {" << v[i].p << " : " << v[i].y << "} " << endl;
  }
  for (int i = 0; i < m; i++) {
    if(temp == v[i].p){
      x++;
    } else {
      x = 1;
    }
    temp = v[i].p;
    // cout << six * v[i].p << endl;
    vec[v[i].i] = con + x + six * v[i].p;
    // vec[v[i].i] = v[i].y;
  }
  for (int i = 0; i < count; i++) {
    cout << to_string(vec[i]).substr(1) << endl;
    // cout << vec[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 5760
from collections import defaultdict
s = list(input())[::-1]
n = len(s)
dic = defaultdict(int)
dic[0] = 1
t = 0
for i in range(n):
    t += int(s[i])*pow(10,i,2019) % 2019
    t %= 2019
    dic[t] += 1
ans = 0
for i in dic.keys():
    m = dic[i]
    ans += m*(m-1)//2
print(ans)


Measured memory_bytes: 79816
#include <iostream>
#include <set>

using namespace std;

int N;
set<int> s;

int main(void)
{
	cin >> N;
	int a;
	for(int i = 0; i < N; i++){
		cin >> a;
		s.insert(a);
	}
	
	int ans = s.size();
	if(ans % 2 == 0) ans--;
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4992
#include<cstdio>
#include<algorithm>
#include<vector>
#include<map>
#define ll long long
using namespace std;
int n;
map<int, int> mp;
int main()
{
	scanf("%d", &n);
	int dap = n;
	for (int i = 0; i < n; i++)
	{
		int q;
		scanf("%d", &q);
		mp[q]++;
		if (mp[q] == q)
			dap -= q;
	}
	printf("%d", dap);
}

Measured memory_bytes: 4736
#include <iostream>
#include <iomanip>

int main()
{
    double a, b, h, m;
    std::cin >> a >> b >> h >> m;

    double angle = abs((30.0 * h) + (0.5 * m) - (6.0 * m));
    if (angle > 180)
    {
        angle = 360 - angle;
    }

    double pi = 3.141592653589793;

    double length = sqrt((a * a) + (b * b) - (2 * a * b * cos(angle * pi / 180.0)));

    std::cout << std::fixed << std::setprecision(15) << length;
}

Measured memory_bytes: 3676
x;
char s[20];
d(int l,int r,int k){
    x=abs(s[l]-s[r]);
    return l<0||!s[r]?k:x&&x<3?d(l-1,r+1,k+2):fmax(d(l-1,r,k),d(l,r+1,k));
}
 
int main(){ 
    scanf("%s",s);
    x=strchr(s,'i')-s;
    printf("%d\n",d(x-1,x+3,3));
    exit(0);
}

Measured memory_bytes: 544
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,m,x,u=0,d=0,a;
  cin>>n>>m>>x;
  for(int i=0;i<m;i++){
    cin>>a;
    if(a<x)
      d++;
    else
      u++;
  }
  cout<<min(d,u);
}

Measured memory_bytes: 256
import sys

def main():
    N = int(input())
    
    cnt = 0
    for i in range(1, N+1, 2):
        prime_l = []
        for j in range(1, i+1, 2):
            if i%j==0:
                prime_l.append(j)
        if len(prime_l)==8:
            cnt+=1
    print(cnt)
main()

Measured memory_bytes: 2940
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A1 = sc.nextInt();
        int A2 = sc.nextInt();
        int A3 = sc.nextInt();
        
        if(A1+A2+A3 >=22) {
        	System.out.println("bust");
        } else {
        	System.out.println("win");
        }
 

	}
}






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

int main()
{
        int n,count;
        while(cin >> n){
                count = 0;
                for(int a=0;a<10;a++)
                        for(int b=0;b<10;b++)
                                for(int c=0;c<10;c++)
                                        for(int d=0;d<10;d++){
                                                if((a+b+c+d)==n)count++;
                                        }

                cout << count << "\n";
        }

        return 0;
}

Measured memory_bytes: 1160
import collections
n = int(input())
v = list(map(int,(input().split())))
even = []
odd =  []
for i in range(0,n,2):
    even.append(v[i])
for i in range(1,n,2):
    odd.append(v[i])

ce = collections.Counter(even)
co = collections.Counter(odd)

emax1,omax1 = ce.most_common()[0][1],co.most_common()[0][1]

if len(ce.most_common()) == 1:
    emax2 = 0
else:
    emax2 = ce.most_common()[1][1]
if len(co.most_common()) == 1:
    omax2 = 0
else:
    omax2 = co.most_common()[1][1]

if ce.most_common()[0][0] == co.most_common()[0][0]:
    ans = n - max(emax1+omax2, emax2+omax1)
else:
    ans = n - (emax1+omax1)
print(ans)

Measured memory_bytes: 83332
#include <bits/stdc++.h>
#define FASTIO
#define endl "\n" // Since endl forces a buffer flush which slows down large I/O operations.
#define ff first
#define ss second
#define pb push_back
#define input(c, n)             \
	for (int i = 0; i < (n); i++) \
		cin >> (c)[i];
#define exit_message(s) return 0 * printf(s)
#define show(c)           \
	for (auto i : (c))      \
		cout << i << " "; \
	cout << "\n";
#define display(c, n)           \
	for (int i = 0; i < (n); i++) \
		cout << (c)[i] << " ";    \
	cout << "\n";
#define forl(i, a, n) for (int (i) = (a); (i) < (n); (i)++)
#define dugbe(k) cout << "-\t> " << #k << " = " << k << "\n";

/* TIPS FOR DEBUGGING
 * Check if values are not overflowing (use long long where required)
 * Check if ranges are inclusive or not.
 * Check properly if greedy will work or not before using it.
 * Check EDGE CASES!! Seriously, even in 2B, saving 8 points by being
 * 2 minutes faster will bite you in the ass if you don't make sure
 * it works on edge cases.
 * Keep adding to this list.
*/

using namespace std;
typedef long long ll;
typedef pair<int, int> pr;
typedef pair<ll, ll> prll;
typedef vector<int> vi;
typedef vector<ll> vill;
typedef vector<pr> vpr;
ifstream in("input.txt");
const ll mod = 1e9 + 7;

ll mod_pow(ll a, ll b)
{
	if (b == 0)
		return 1LL;

	ll res = mod_pow(a, b >> 1);
	res = (res * res) % mod;
	if (b & 1LL)
		res = (res * a) % mod;

	return res;
}

const int N = 21 + 5;
const int SZ = 2100000;

int n;
int a[N][N];
int dp[SZ];

int solve(int mask)
{
	if (mask == (1 << n) - 1)
		return 1;

	int idx = 1;
	for (int i = 1; i <= mask; i *= 2)
		if (mask & i)
			idx++;

	int &memo = dp[mask];
	if (memo != -1)
		return memo;

	memo = 0;
	for (int i = 1; i <= n; i++)
	{
		int temp = 1 << (i - 1);
		// cerr << "temp : " << bitset<32>(temp) << " mask : " << mask << "\n";
		if (a[idx][i] == 1 && (mask & temp) == 0)
		{
			// cerr << "entry\n";
			mask ^= temp;
			memo += solve(mask);
			memo %= mod;
			mask ^= temp;
		}
	}
	// cerr << "idx : " << idx << " memo : " << memo << "\n";
	return memo;
}

int32_t main()
{
#ifdef FASTIO
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#endif
	// freopen("in.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	memset(dp, -1, sizeof dp);

	cin >> n;
	forl(i, 1, n + 1)
	{
		forl(j, 1, n + 1)
		{
			cin >> a[i][j];
		}
	}

	int mask = 0;
	int ans = solve(mask);
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 8448
import sys
from collections import Counter

input = sys.stdin.readline
N = int(input())
S = list(input().strip())
counter = Counter(S)
if len(counter) == 1:
    print(0)
else:
    ans = min(counter["."], counter["#"])
    # 操作後：境界に対して左は白、右は黒になる
    # 境界をどこにするかを全探索
    white = counter["."]
    black = counter["#"]
    left_w = 0
    left_b = 0
    for i in range(N):
        if S[i] == ".":
            left_w += 1
        else:
            left_b += 1
        ans = min(ans, left_b + white - left_w)
    
    print(ans)

Measured memory_bytes: 10996
#include <stdio.h>
#include <string.h>
int main(void){
    char s[200001],t[200001];
    int cnt=0;
    scanf("%s",s);
    scanf("%s",t);
    for(int i=0;i<strlen(s);i++){
        if(s[i]!=t[i]) cnt++;
    }
    printf("%d",cnt);
    return 0;
}

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

using namespace std;

template< typename Data, typename T >
struct ReRooting {

  struct Node {
    int to, rev;
    Data data;
  };

  using F1 = function< T(T, T) >;
  using F2 = function< T(T, int, int, Data) >; // ret, src, to, data


  vector< vector< Node > > g;
  vector< vector< T > > dp, ldp, rdp;
  vector< vector< int > > eval;
  const F1 f1;
  const F2 f2;

  ReRooting(int n, const F1 &f1, const F2 &f2) : g(n), ldp(n), rdp(n), dp(n), eval(n), f1(f1), f2(f2) {}

  void add_edge(int u, int v, const Data &d) {
    g[u].emplace_back((Node) {v, (int) g[v].size(), d});
    g[v].emplace_back((Node) {u, (int) g[u].size() - 1, d});
  }

  T dfs(int idx, int par) {

    if(par == -1 || !eval[idx][par]) {
      for(int i = 0; i < g[idx].size(); i++) {
        if(i == par) continue;
        if(exchange(eval[idx][i], true)) continue;
        dp[idx][i] = f2(dfs(g[idx][i].to, g[idx][i].rev), idx, g[idx][i].to, g[idx][i].data);
      }
      for(int i = 0; i < g[idx].size(); i++) {
        if(!eval[idx][i]) break;
        ldp[idx][i + 1] = f1(ldp[idx][i], dp[idx][i]);
      }
      for(int i = (int) g[idx].size() - 1; i >= 0; i--) {
        if(!eval[idx][i]) break;
        rdp[idx][i] = f1(rdp[idx][i + 1], dp[idx][i]);
      }
    }

    if(par <= 0) return rdp[idx][par + 1];
    return f1(ldp[idx][par], rdp[idx][par + 1]);
  }


  vector< T > solve() {
    for(int i = 0; i < g.size(); i++) {
      ldp[i].resize(g[i].size() + 1);
      rdp[i].resize(g[i].size() + 1);
      dp[i].resize(g[i].size());
      eval[i].resize(g[i].size());
    }
    vector< T > ret;
    for(int i = 0; i < g.size(); i++) {
      ret.push_back(dfs(i, -1));
    }
    return ret;
  }
};

using vi = vector< int >;

// これはうくですか？

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

  auto f1 = [](vi a, vi b) {
    for(auto &p : b) a.push_back(p);
    sort(a.rbegin(), a.rend());
    a.resize(min((int) a.size(), 2));
    return a;
  };
  auto f2 = [](vi a, int src, int to, int d) {
    a.push_back(0);
    return vi{*max_element(a.begin(), a.end()) + d};
  };

  ReRooting< int, vi > g(N, f1, f2);
  for(int i = 1; i < N; i++) {
    int s, t, w;
    cin >> s >> t >> w;
    g.add_edge(s, t, w);
  }

  auto v = g.solve();
  int ret = 0;
  for(auto &p : v) {
    if(p.size() >= 2) ret = max(ret, p[0] + p[1]);
    if(p.size() >= 1) ret = max(ret, p[0]);
  }
  cout << ret << endl;
}


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

int main(int argc, char const *argv[]) {
    int n;
    cin >> n;

    int n_ac = 0, n_wa = 0, n_tle = 0, n_re = 0;
    for (size_t i = 0; i < n; i++){
        string state;
        cin >> state;

        if (state == "AC") ++n_ac;
        else if (state == "WA") ++n_wa;
        else if (state == "TLE") ++n_tle;
        else if (state == "RE") ++n_re;
    }

    cout << "AC x " << n_ac << endl;
    cout << "WA x " << n_wa << endl;
    cout << "TLE x " << n_tle << endl;
    cout << "RE x " << n_re << endl;

    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <vector>
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define REPR(i, n) for (int i = n-1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTG(a) sort(ALL(a), greater<int>())
#define bit_search(bit, n) REP(bit, 1<<n)
#define bit_check(bit, i) (bit>>i) & 1
using namespace std;
using PII = pair<int, int>;
using VP = vector<PII>;
using VI = vector<int>;
using VVI = vector<VI>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
using ll = long long;
const int INF = 1e9;

vector<ll> memo(100, -1);

ll lucas(int x)
{
    if (x == 0) return memo.at(x) = 2;
    if (x == 1) return memo.at(x) = 1;
    if (memo.at(x) != -1) return memo.at(x);
    return memo.at(x) = lucas(x-1) + lucas(x-2);
}

int main()
{
    int N;
    cin >> N;
    cout << lucas(N) << endl;

    return 0;
}

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

int main(){
    string str;  
    cin >> str;
    vector<int> n;
    rep(i,str.length())n.push_back((int)(str[i] - '0'));
    int sum=0;
    rep(i,n.size()) sum = sum + n[i];
    if(sum%9 == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 4516
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>

using namespace std;

int main()
{
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<int> p(a), q(b), r(c);
    for (int i = 0; i < a; i++)
    {
        cin >> p[i];
    }
    for (int i = 0; i < b; i++)
    {
        cin >> q[i];
    }
    for (int i = 0; i < c; i++)
    {
        cin >> r[i];
    }
    sort(p.rbegin(), p.rend());
    sort(q.rbegin(), q.rend());
    sort(r.rbegin(), r.rend());

    vector<int> tmp(x + y + c);
    for (int i = 0; i < x; i++)
    {
        tmp[i] = p[i];
    }
    for (int i = x; i < x + y; i++)
    {
        tmp[i] = q[i - x];
    }
    for (int i = x + y; i < x + y + c; i++)
    {
        tmp[i] = r[i - x - y];
    }
    sort(tmp.rbegin(), tmp.rend());
    long long ans = 0;
    for(int i = 0; i < x+y;i++){
        //cout << tmp[i] << endl;
        ans += tmp[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define pii std::pair<int,int>
#define pli std::pair<ll,int>
#define pil std::pair<int,ll>
#define psi std::pair<string,int>
#define pll std::pair<ll,ll>
#define pci std::pair<char,int>
#define sll(x) scanf("%lld",&x)
#define prll(x) printf("%lld ",x)
#define pri(x) printf("%d ",x)
#define si(x) scanf("%d",&x)
#define pb push_back
#define vll std::vector<ll>
#define vpi std::vector<std::pair<int,int>>
#define vi std::vector<int>
#define vvi std::vector<std::vector<int>>
#define vvpil std::vector<std::vector<std::pair<int,ll>>>
#define vlpii std::vector<std::list<pii>>
#define vlpil std::vector<std::list<pil>>
#define li std::list<int>
#define lpil std::list<pil>
#define Endl printf("\n")
#define vli vector<list<int>>
#define vvll vector<vector<ll>>
#define mp make_pair
#define x first
#define y second
#define ull uint64_t
#define ma 100000000
#define imie(...) "[" << #__VA_ARGS__": " << (__VA_ARGS__) << "] "
const ll  INF=10000000000000;
const ll mod =  1e9 + 7;
using namespace std;
void add(ll& a , ll b){
	a += b;
	if(a >= mod) a -= mod;
}
ll mul(ll a , ll b){
	return (a * b) % mod;
}
ull Pow(ull a , ull b){
	if(b == 0) return 1 ;
	ull c = Pow(a , b / 2) ;
	if(b % 2) return (a * ((c * c) % mod)) % mod;
	return (c * c) % mod ;
}


int main(){
	IOS;
	cout.precision(30) ;
	int n , m ; cin >> n >> m;
	vll x(m);for(int i = 0 ; i < m ; i++) cin >> x[i] ;
	if(n >= m) return cout << 0 << endl , 0 ;
	sort(x.begin() , x.end()) ;
	ll ans = x[m - 1] - x[0] ;
	vll diff(m - 1) ;
	for(int i = 0 ; i < m - 1 ; i++) diff[i] = (x[i + 1] - x[i]) ;
	sort(diff.rbegin() , diff.rend()) ;
	for(int i = 0 ; i < n - 1 ; i++) ans -= diff[i] ;
	cout << ans << endl ;
	
	
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=200010;
const ll mod=1e9+7;


int main(){  
  int h,w;
  cin >> h >> w; h--; w--;
  cout << h*w << endl;
  return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
N = int(input())

# むずい！
anagrams = defaultdict(int)
for _ in range(N):
    chars = input()
    d = defaultdict(int)
    tuple_d = tuple(sorted(chars))
    anagrams[tuple_d] += 1

tmp = [i-1 for i in anagrams.values()]
print(sum([n*(n+1)//2 for n in tmp]))


Measured memory_bytes: 23904
#include <iostream>
#include <string>
using namespace std;
int main()
{
    string hitachi;
    cin>> hitachi;
    bool hit = true;
    for(int i= 0; i<hitachi.length(); i+=2){
        
        if(hitachi.substr(i,2) != "hi"){
            hit = false;
            break;
        }
    }
    if(hit == true){
        cout<< "Yes";
    }else{
        cout<< "No";
    }
    return 0;
}


Measured memory_bytes: 256
N = int(input())
h = list(map(int,input().split()))
count = 0
while(h.count(0)!=N):
    for k in range(N):
        if h[k]!=0:
            break
    for j in range(k,N):
        if h[j]==0:
            j-=1
            break
    for i in range(k,j+1):
        h[i]-=1
    count+=1
print(count)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
class Program
    {
            
        static int Gcd(int a, int b)
        {
            return (a < b) ? Gcd(b, a)
                : (b > 0) ? Gcd(b, a % b)
                    : a;
        }
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] s = Console.ReadLine().Split(' ');
            int[] a = new int[n];
            for (int i=0; i<n; i++) a[i] = int.Parse(s[i]);

            int[] gcdFromZero = new int[n];
            gcdFromZero[0] = a[0];
            for (int i=1; i<n; i++)
            {
                gcdFromZero[i] = Gcd(a[i], gcdFromZero[i-1]);
            }

            int[] gcdFromN = new int[n];
            gcdFromN[n-1] = a[n-1];
            for (int i=n-2; i>=0; i--)
            {
                gcdFromN[i] = Gcd(a[i], gcdFromN[i+1]);
            }

            int ans = Math.Max(gcdFromZero[n-2], gcdFromN[1]);

            for (int i=1; i<n-1; i++)
            {
                ans = Math.Max(ans, Gcd(gcdFromZero[i-1], gcdFromN[i+1]));
            }
            Console.WriteLine(ans);
        }
    }
    //mcs Main.cs
    //mono Main.exe

Measured memory_bytes: 25692
mod = 10**9+7
S = int(input())

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

N = 10**4
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

num = S
total = 0
for i in range(S//3):

    num = S-3*(i+1)+i

    total = (total+cmb(num,i,mod))%mod

print(total)


Measured memory_bytes: 67844
#include <cstdio>

int main() {
	int n;
	int a, b;
	
	scanf("%d", &n);
	for(a=1; a<=9; a++)
		for(b=1; b<=9; b++)
			if(n == a*b){
				printf("Yes\n");
				return 0;
			}
	printf("No\n");
	return 0; 
}

Measured memory_bytes: 128
#include<iostream>
#include<cmath>
#include<iomanip>
#include<vector>
#include<string>

using namespace std;

class Dice {
public:
  int a[6];
  Dice(){
    for(int i = 0; i < 6; i++)
      cin >> a[i];
  }
  void Roll(string s){
    int temp;

    for(string::size_type i = 0; i < s.length(); i++){
      if(s[i] == 'E'){
        temp = a[3];
        a[3] = a[5];
        a[5] = a[2];
        a[2] = a[0];
        a[0] = temp;
      }else if(s[i] == 'W'){
        temp = a[2];
        a[2] = a[5];
        a[5] = a[3];
        a[3] = a[0];
        a[0] = temp;
      }
      else if(s[i] == 'S'){
        temp = a[4];
        a[4] = a[5];
        a[5] = a[1];
        a[1] = a[0];
        a[0] = temp;
        // printCurrent();
      }else if(s[i] == 'N'){
        temp = a[1];
        a[1] = a[5];
        a[5] = a[4];
        a[4] = a[0];
        a[0] = temp;
      }
    } 
  }
  int serchNum(int n){
    int i;
    for(i = 0 ; i < 6;i++){
      if(n == a[i]) break;
    }
    return i;
  }
  void set0(int n){
    int index = serchNum(n);
    if(index == 0) return;
    else if(index == 1){
      // index == 1を上面にする
      Roll("N");
    }
    else if(index == 2){
      // index == 2を上面にする
      Roll("W");
    }
    else if(index == 3){
      // index == 3を上面にする
      Roll("E");
    }
    else if(index == 4){
      // index == 4を上面にする
      Roll("S");
    }
    else if(index == 5){
      // index == 5を上面にする
      Roll("WW");
    }
  }
  void printCurrent(){
    cout << "現在の状態" << endl;
    for(int i = 0; i < 6; i++)
      cout << a[i] << endl;
    cout << endl;
  }
  int getRightNumber(int n){
    if(n == a[1]){
      return a[2];
    }else if(n == a[2]){
      return a[4];
    }
    else if(n == a[4]){
      return a[3];
    }
    else if(n == a[3]){
      return a[1];
    }
    return -1;
  }
};

int main(){
  Dice dice1;
  string s;
  int q, n, rightNumber;
  vector<int> ans;
  cin >> q;
  for(int i = 0; i < q; i++){
    // 上面の数字
    cin >> n;
    dice1.set0(n);
    // 前面の数字
    cin >> n;
    rightNumber = dice1.getRightNumber(n);
    if(rightNumber == -1){
      cout << "error" << endl;
      continue;
    }
    ans.push_back(rightNumber);
  }
  for(vector<int>::size_type i = 0; i < ans.size(); i++){
    cout << ans[i] << endl;
  }
}


Measured memory_bytes: 3168
#include<stdio.h>

int isprime(int n){
	for(int i = 2; i * i <= n; i++){
		if( n % i == 0) return 0;
	}
	return 1;
}

int main(){
	int n, i;
	while(1){
		scanf("%d", &n);
		if( n == 0) break;
		int max = 0;
		for( i = n; i >=2; i--){
			if( isprime(i)){
				if(isprime( i - 2)){
					max = i;
					break;
				}
			}
		}
		printf("%d %d\n", max - 2, max);
	}
	return 0;
}

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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main()
{
    int r,g,h;
    cin >> r >> g >> h;
    int ans = r*100+g*10+h;
    if(ans%4==0)cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 256
n = int(input())
H = list(map(int, input().split(' ')))

def max_heapify(i):
    l = (i+1)*2-1
    r = (i+1)*2
    largest = i
    if l < n and H[l] > H[i]:
        largest = l
    else:
        largest = i
    if r < n and H[r] > H[largest]:
        largest = r

    if largest != i:
        H[i], H[largest] = H[largest], H[i]
        max_heapify(largest)

def print_elements(lst):
    for ele in lst:
        print(' {}'.format(ele), end='')
    print('')

for i in range(int(n/2), -1, -1):
    max_heapify(i)

print_elements(H)


Measured memory_bytes: 63696
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    ll cnt = 0;
    int n;
    scanf("%d",&n);
    vector<ll> a(n);
    for(int i = 0; i < n; i++)
    scanf("%lld",&a[i]);
    for(int i = 0; i < n; i++){
        while(a[i] % 2 == 0){
            cnt++;
            a[i] /= 2;
        }
    }
    printf("%lld\n",cnt);
}

Measured memory_bytes: 384
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <iostream>
#include <set>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

using namespace std;

int main(){
  const int n = getInt();
  const int q = getInt();
  string ans = "kogakubu10gokan";

  REP(i,n){
    int y; char b[128];
    scanf("%d%s", &y, b);
    if(y > q){ puts(ans.c_str()); return 0;}
    ans = b;
  }
  puts(ans.c_str());
  return 0;
}

Measured memory_bytes: 1200
use proconio::input;

fn main() {
    input! {
        n: usize,
        k: i64,
        c: i64,
        s: String,
    }

    let workable: Vec<_> = s.chars().map(|c| c == 'o').collect();

    let mut left = vec![false; n];
    let mut last_i = -(c + 1);
    for i in 0..(n as i64) {
        if last_i + c >= i {
            continue;
        }

        if workable[i as usize] {
            left[i as usize] = true;
            last_i = i;
        }
    }
    let left = left;
    let mut left_c = vec![0i64; n + 2];
    for i in 1..=n {
        left_c[i] = left_c[i - 1];
        if left[i - 1] {
            left_c[i] += 1;
        }
    }
    let left_c = left_c;

    let mut right = vec![false; n];
    let mut last_i = n as i64 + c;
    for i in (0..(n as i64)).rev() {
        if i + c >= last_i {
            continue;
        }

        if workable[i as usize] {
            right[i as usize] = true;
            last_i = i;
        }
    }
    let right = right;
    let mut right_c = vec![0i64; n + 2];
    for i in (1..=n).rev() {
        right_c[i] = right_c[i + 1];
        if right[i - 1] {
            right_c[i] += 1;
        }
    }
    let right_c = right_c;

    let mut ans = vec![];
    for i in 1..=n {
        let cap = left_c[i - 1] + right_c[i + 1];
        if cap < k {
            ans.push(i);
        }
    }

    for a in ans {
        println!("{}", a);
    }
}


Measured memory_bytes: 7768
#define _USE_MATH_DEFINES
 
#include <bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
using ld = long double;
 
constexpr ll MOD = 998244353;
 
#ifndef ONLINE_JUDGE
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " (" << x.first << " : " << x.second << ")" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "["; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "]"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "(" << obj.first << ", " << obj.second << ")"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print_sim_py(void) {cout << endl;}
template <class Head> void print_sim_py(Head&& head) {cout << head;print_sim_py();}
template <class Head, class... Tail> void print_sim_py(Head&& head, Tail&&... tail) {cout << head << " ";print_sim_py(forward<Tail>(tail)...);}


#define print(...) print_sim_py(__VA_ARGS__);
#else
#define print(...);
#endif

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
 
    ll n,k;
    ll ans=0;

    cin >> n >> k;

    vector<ll> l(k),r(k);
    vector<ll> dp(n,0);
    vector<ll> sum(n+1,0);

    for(ll i=0; i<k; i++){
        cin >> l[i] >> r[i];
    }

    dp[0] = 1;
    sum[1] = 1;
    for(ll j=2; j<n+1; j++){
        for(ll i=0; i<k; i++){
            ll li = max(j-l[i],0ll);
            ll ri = max(j-r[i]-1,0ll);
            ll s = sum[li]-sum[ri];
            s = s<0?s+MOD:s;
            dp[j-1] = (dp[j-1]+s)%MOD;
        }
        sum[j] = (sum[j-1]+dp[j-1])%MOD;
    }
    print(sum)
    print(dp)

    cout << dp[n-1] << endl;
 
    return 0;
}



Measured memory_bytes: 6340
/* Bismillahirrahmanirrahim */
/* Author : Jehian Norman Saviero (@Reiva5) */
#include <bits/stdc++.h>

// MACROS SAMPAH
#define Jehian using
#define Norman namespace
#define Saviero std

Jehian Norman Saviero;

// MACROS TYPE
typedef long l;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int,int> pi;
typedef pair<l,l> pl;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<l> vl;
typedef vector<ll> vll;

// MACROS FOR PRINT
#define nl printf("\n")
#define sp printf(" ")

// MACROS FOR ATTRIBUTE
#define fi first
#define se second

// MACROS FOR FUNCTION AND METHOD
#define eb emplace_back
#define mp make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ALL(x) (x).begin(), (x).end()
#define ALLN(x,n) (x), (x)+(n)
#define CUBE(x) (SQR(x)*(x))
#define SET(x,y) for (int _qwe = sizeof(x)/sizeof(x[0]); _qwe; ) x[--_qwe] = (y)
#define SQR(x) ((x)*(x))
#define SSORT(x,sz) sort(ALLN(x,sz))
#define RESET(x) memset((x), 0, sizeof(x))
#define VSORT(x) sort(ALL(x))

// MACROS READ INPUT
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%ld", &x)
#define scll(x) scanf("%lld", &x)
#define scul(x) scl(x)
#define scull(x) scll(x)

int main() {
	int cnt[4];
	RESET(cnt);
	for (int i = 0; i < 3; ++i) {
		int u, v;
		sci(u), sci(v);
		--u, --v;
		++cnt[u], ++cnt[v];
	}
	for (int i = 0; i < 4; ++i) {
		if (cnt[i] > 2) {
			puts("NO");
			return 0;
		}
	}
	puts("YES");
	return 0;
}

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

int main() {
    int a,b,c,d,e,k,ans=0;
    cin >> a ;
    cin >> b ;
    cin >> c ;
    cin >> d ;
    cin >> e ;
    cin >> k ;
    if(abs(a-b)>k) ans=1;
    else if(abs(a-c)>k) ans=1;
    else if(abs(a-d)>k) ans=1;
    else if(abs(a-e)>k) ans=1;
    else if(abs(b-c)>k) ans=1;
    else if(abs(b-d)>k) ans=1;
    else if(abs(b-e)>k) ans=1;
    else if(abs(c-d)>k) ans=1;
    else if(abs(c-e)>k) ans=1;
    else if(abs(d-e)>k) ans=1;
    if(ans==1) cout << ":(" << endl;
    else cout << "Yay!" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
//typedef pair<int,int> P;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, pair<int, int>>> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2147483600;//10^9
int INFM =100000000;
ll MOD  = 1000000007;
 

 
 
int main(){
  int sx, sy, tx,ty;
  int x,y;
  cin >> sx >> sy >> tx >> ty;
  x = tx - sx;
  y = ty - sy;
  cout << string(y, 'U') << string(x, 'R') << string(y, 'D') << string(x + 1, 'L');
  cout << string(y +1, 'U') << string(x +1, 'R') << 'D'  << 'R' << string(y +1 , 'D') << string(x +1, 'L') << 'U' << endl;
  
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		if (Math.abs(a - b) <= W) {
			System.out.println(0);
		} else {
			System.out.println(Math.abs(a - b) - W);
		}
	}
}


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

int main(){ 
  int h,w,n; cin >> h >> w >> n;
  int ans = 1e9;
  for(int x = 0; x <= h; x++){
    for(int y = 0; y <= w; y++){ 
      
      int res = x*w+y*h-x*y;
      
      if( res >= n ){ ans = min( ans, x+y );}
      
      
    }
  }
  
  cout << ans << endl;
  
  return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
//using Graph = vector<vector<Edge>>;
using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;
const double PI = acos(-1.0);

int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, dy[8] = {-1, 0, 1, 1, -1, 1, 0, -1};

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int H, W, D;
  cin >> H >> W >> D;
  // vector<vector<int>> A(H, vector<int>(W));
  vector<P> A(H * W);
  for (int i = 0; i < H; i++)
  {
    for (int j = 0; j < W; j++)
    {
      int a;
      cin >> a;
      a--;
      A[a].first = i;
      A[a].second = j;
    }
  }
  vector<int> S(H * W + 1);
  for (int i = 0; i < D; i++)
    S[i] = 0;
  for (int i = D; i < H * W; i++)
  {
    S[i] = S[i - D] + abs(A[i].first - A[i - D].first) + abs(A[i].second - A[i - D].second);
  }
  int Q;
  cin >> Q;
  vector<int> L(Q), R(Q);
  for (int i = 0; i < Q; i++)
  {
    cin >> L[i] >> R[i];
    L[i]--;
    R[i]--;
  }
  for (int i = 0; i < Q; i++)
  {
    ll ans = 0;
    if (L[i] == R[i])
      cout << ans << endl;
    else
    {
      ans = S[R[i]] - S[L[i]];
      cout << ans << endl;
    }
  }
  return 0;
}

// 累積和 Lは含まれないからLごと引く


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

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

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

#define MAXN 5500
ll score[MAXN][MAXN];

int main(){
  ll n,k;cin>>n>>k;
  vector<ll> p(n);
  rep(i, n){cin>>p[i]; p[i]--;}
  vector<ll>c(n);
  rep(i, n)cin>>c[i];

  vector<ll>loopc(n);

  // 各マスから始めた時のループに必要な操作数を算出
  int nex, now;
  rep(i, n){
    now = i;
    ll tr=0;
    rep1(j, n+1){
      ll nex = p[now];
      score[i][j] += score[i][j-1] + c[nex];
      now=nex;
      tr++;
      if(now==i){ loopc[i]=tr; break; }
    }
  }

  ll result = -INF;
  // 最初の一周目は全探索
  rep(i, n)rep1(j, loopc[i]){
    if(j>k)continue;
    result = max<ll>(result, score[i][j]);
  }

  // 2周以上可能な時
  rep(i, n){
    ll lc = loopc[i];

    // ループ1回の収支がプラスでも、ループの最後の一回を止めた方がスコアがデカい場合がある、そのためループ回数を最大から1減らして、その中で最大になるかを全チェック。k/lcが1以上無いと減らしたループ回数が負になるのでそのため分岐
    if(k/lc>=1){
      //可能回数-1回分ループを回す。
      ll base = score[i][lc]*(k/lc-1);
      rep1(j, lc)result = max<ll>(result, base+score[i][j]);

      // 普通にループを可能な回数だけ回す
      // 1ループ収支をループ可能数だけ加算
      ll tr = score[i][lc]*(k/lc);
      result = max<ll>(result, tr);
      // ループ終了後の余り部分の計算、余りで到達可能な全マスに対して行う。
      rep1(j, k%lc)result = max<ll>(result, tr+score[i][j]);
    }
  }

  cout<<result<<endl;

  return 0;

  cout<<endl;
  rep(i, n){
    rep(j, n+1)cout<<score[i][j]<<' ';
    cout<<endl;
  }

  for(auto t: loopc)cout<<t<<' ';cout<<endl;

  return 0;
}


Measured memory_bytes: 218600
n,k = input().split()
n = int(n)
k = int(k)
ans = [0]*n
count = 0
for i in range(k):
  a = int(input())
  str_list = list(input().split())
  for j in str_list:
    ans[int(j)-1] = ans[int(j)-1] + 1
for i in range(n):
  if ans[i] == 0:
    count = count + 1
print(count)

Measured memory_bytes: 9228
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
struct peo{
	string s;
}a[200005];
int b[200005];
bool cmp(peo a,peo b)
{
return a.s<b.s;
}
int main()
{
	int n,t=1,max=0;cin>>n;
	for(int i=0;i<n;++i)
	{
	cin>>a[i].s;
	}
	sort(a,a+n,cmp);
	for(int i=0;i<n;++i)
	{
		if(a[i].s==a[i+1].s)
		t++;
		else 
		{
		b[i]=t;	
		if(max<b[i]) 
		{max=b[i];
		}t=1;
		}
	}
	
	for(int i=0;i<n;++i)
	{
		if(b[i]==max)
		cout<<a[i].s<<endl;
	}
}

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

int x, y;

int min_path(int s, int g) {
  if (s <= x) {
    if (g >= y) {
      return (x - s) + (g - y) + 1;
    } else {
      int a = g - s;
      int b = (x - s) + (y - g) + 1;
      return min(a, b);
    }
  }
  
  else if (s > x && s < y) {
    if (g <= y) {
      int a = g - s;
      int b = (s - x) + 1 + (y - g);
      return min(a, b);
    } else {
      int a = g - s;
      int b = (s - x) + 1 + (g - y);
      return min(a, b);
    }
  }
  
  else {
    return g - s;
  }
}

int main() {
  int n;
  cin >> n >> x >> y;
  
  vector<int> cnt(n);
  
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      int z = min_path(i, j);
      cnt.at(z)++;
    }
  }
  
  for (int i = 1; i < n; i++) {
    cout << cnt.at(i) << endl;
  }
  
  
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		try(Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			char[] s = sc.next().toCharArray();
			char[] t = sc.next().toCharArray();
			StringBuilder sb = new StringBuilder();
			for(int i = 0 ; i < n ; i++) {
				sb.append(s[i]);
				sb.append(t[i]);
			}
			System.out.println(sb.toString());
		}

	}

}


Measured memory_bytes: 22740