akhauriyash/Code-Regression huggingface dataset:
/*      Chill raho be kuch nhi rakha sadness me. 
               Author: Maskman_lucifer                   */
               
#include <bits/stdc++.h>   
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long 
#define pll pair<ll,ll>
#define pb push_back
#define M 1000000007
#define lc '\n'
using namespace std;
ll dp[3006][3006];
string s,t;
ll l,r;
ll solve(ll ind1,ll ind2)
{
    if(ind1==-1 or ind2==-1)
    {
        return 0;
    }
    else
    {
        if(dp[ind1][ind2]!=-1)
        {
            return dp[ind1][ind2];
        }
        if(s[ind1]==t[ind2])
        {
            ll val=solve(ind1-1,ind2-1);
            dp[ind1][ind2]=val+1;
            return dp[ind1][ind2];
        }
        else
        {
            ll val;
            val=solve(ind1-1,ind2);
            val=max(val,solve(ind1,ind2-1));
            dp[ind1][ind2]=val;
            return dp[ind1][ind2];
        }
    }
}
int main()
{
    IO
    cin>>s>>t;
    memset(dp,-1,sizeof(dp));
    l=s.length();
    r=t.length();
    ll p=solve(l-1,r-1);
    string s1="";
    for(ll i=l-1;i>=0;i--)
    {
        for(ll j=r-1;j>=0;j--)
        {
            if(s[i]==t[j] and dp[i][j]==p)
            {
                s1+=s[i];
                p--;
                break;
            }
        }
    }
    reverse(s1.begin(),s1.end());
    cout<<s1<<lc;
    return 0;
}

Measured memory_bytes: 74496
from sys import stdin
readline = stdin.buffer.readline
read = stdin.buffer.read

# import numpy as np
# from numba import jit
# stdin = open('sample.txt')

def main():
    S = readline().rstrip()  
    T = readline().rstrip()
    ls = len(S)
    lt = len(T)
    ans = lt
    for i in range(ls - lt + 1):
        cnt = lt
        for j in range(lt):
            if S[j + i] == T[j]:
                cnt -= 1
        ans = min(ans, cnt)
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 64856
#include<iostream>

using namespace std;

int main() {

	int n;
	int a[200000];
	long long int sum = 0;

	cin >> n;

	for (int i = 0; i < n; i++) cin >> a[i];

	for (int i = 1; i < n; i++) {
		if (a[i] < a[i - 1]) {
			sum += a[i - 1] - a[i];
			a[i] = a[i - 1];
		}
	}

	cout << sum << endl;

	return 0;
}

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

int N;

int main(void)
{
    cin >> N;

    int cnt=0;

    while(N!=0)
    {
        if(N%10==2)
        {
            cnt++;
        }

        N=N/10;
    }

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

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <vector>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstdio>
using namespace std;
int main(){
string a[2];
cin>>a[0]>>a[1]>>a[2];
cout<<a[0][0]<<a[1][1]<<a[2][2];
system("pause");
return 0;
}

Measured memory_bytes: 504
// Etavioxy
#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<string>
#include<map>
#define il inline
#define ll long long
#define rep(i,s,t) for(register int i=(s);i<=(t);i++)
#define rev_rep(i,s,t) for(register int i=(s);i>=(t);i--)
#define each(i,u) for(int i=head[u];i;i=bow[i].nxt)
#define file(s) freopen(s".in" ,"r",stdin),freopen(s".out","w",stdout)
#define pt(x) putchar(x)
using namespace std;
il int ci(){
	register char ch;int f=1;
	while(!isdigit(ch=getchar()))f=ch=='-'?-1:1;
	register int x=ch^'0';
	while(isdigit(ch=getchar()))x=(x*10)+(ch^'0');
	return f*x;
}

map<string,int> m;
string s;
int main(){
	int n=ci();
	int ans = 0;
	rep(i,1,n){
		cin>>s;
		ans = max(ans,++m[s]);
	}
	for(map<string,int>::iterator i=m.begin();i!=m.end();i++){
		if( i->second==ans ) cout<<i->first<<endl;
	}
	return 0;
}


Measured memory_bytes: 26368
// Peace Of SHIT
#include<bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int, int> pii;
const int maxn = 1e5 + 5;
int n, si[maxn];
int sum = 0;
vector<int> e[maxn];
pii d[maxn];

void impossible() {
	cout << -1;
	exit(0);
}

void dfs(int u, int x) {
	sum += x;
	for(int i = 0; i < e[u].size(); i++) {
		dfs(e[u][i], x + 1);
	}
}

int32_t main() {
	scanf("%lld", &n);
	for(int i = 0; i < n; i++) {
		int a;
		scanf("%lld", &a);
		d[i] = {a, i};
	}
	sort(d, d + n);
	reverse(d, d + n);
	
	vector <pii> k (d, d + n);
	
	for(int q = 0; q < n - 1; q++) {
		int leaf = d[q].second;
		int parD = d[q].first - (n - (2 * (si[leaf] + 1)));
		auto it = lower_bound(k.rbegin(), k.rend(), pii(parD, 0));
//		cout << "PAR : " <<it->first << " : " << parD << '\n';
		if(it -> first != parD) {
//			cerr << "AVALI\n";
			impossible();
		}
		int par = it -> second;
		si[par] += si[leaf] + 1;
		if((si[leaf] + 1) * 2 > n) {
//			cout << "DOVOMI\n";
			impossible();
		}
		//SEVOMI HAM MISHE D[I] ROOT OK E ?
		e[par].push_back(leaf);
	}
	int D = d[n - 1].second;
	dfs(D, 0);
	if(sum != d[n - 1].first)
		impossible();
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < e[i].size(); j++) {
			printf("%lld %lld\n", i + 1, e[i][j] + 1);
		}
	}
	return 0;
}

Measured memory_bytes: 13056
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template<typename T,T MOD,T B>
struct RollingHash{
  vector<T> hash,p;
  RollingHash(){}
  RollingHash(const string &s){
    int n=s.size();
    hash.assign(n+1,0);
    p.assign(n+1,1);
    for(int i=0;i<n;i++){
      hash[i+1]=(hash[i]*B+s[i])%MOD;
      p[i+1]=p[i]*B%MOD;
    }
  }
  //S[l, r)
  T find(int l,int r){
    T res=hash[r]+MOD-hash[l]*p[r-l]%MOD;
    return res>=MOD?res-MOD:res;
  }
};


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;

//INSERT ABOVE HERE
signed main(){
  int n;
  string s;
  cin>>n>>s;

  using ll = long long;
  const ll MOD1 = 1e9+9;
  const ll MOD2 = 1e9+7;
  const ll B = 1777771;
  RollingHash<ll, MOD1, B> rh1(s);
  RollingHash<ll, MOD2, B> rh2(s);

  auto check=
    [&](int len)->int{
      using P = pair<ll, ll>;
      set<P> hs;
      for(int i=n-len;i>=0;i--){
        if(i+len+len<=n)
          hs.emplace(rh1.find(i+len,i+len+len),rh2.find(i+len,i+len+len));
        if(hs.count(P(rh1.find(i,i+len),rh2.find(i,i+len))))
          return 1;
      }
      return 0;
    };

  int l=0,r=n/2+1;
  while(l+1<r){
    int m=(l+r)>>1;
    if(check(m)) l=m;
    else r=m;
  }

  cout<<l<<endl;
  return 0;
}


Measured memory_bytes: 768
#include "bits/stdc++.h"
    using namespace std;
    typedef long long ll;
     
    //gcd
    template<typename T>
    T gcd(T a, T b) {
        return b ? gcd(b, a%b) : a;
    }
     
    int f(int x) {
        int cnt = 0;
        while ((x & 1) == 0) {
            x >>= 1;
            cnt++;
        }
        return cnt;
    }
     
    int main() {
        int n, m; cin >> n >> m;
        vector<int> a(n);
        ll k = 1;
        int p = -1;
        for (int i = 0; i < n; i++) {
            cin >> a[i];
            a[i] >>= 1;
            if (p == -1) p = f(a[i]);
            else if (p != f(a[i])) {
                cout << 0 << endl;
                return 0;
            }
            k = k / gcd(k, (ll)a[i]) * a[i];
            if (m < k) {
                cout << 0 << endl;
                return 0;
            }
        }
        if (m >= k) {
            cout << (m / k + 1) / 2<< endl;
        }
        else {
            cout << 0 << endl;
        }
        return 0;
    }

Measured memory_bytes: 640
////////////////////////////////////////////
///                                      ///
///         Template ver. 1 rapel        ///
/// Fear is Temporary, Regret is Forever ///
///          Must Try and Get AC         ///
///                                      ///
////////////////////////////////////////////
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>
 
#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
 
#include <math.h>
#include <complex>
 
#include <assert.h>
#include <time.h>
//#include <chrono>
//#include <random>
 
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <bitset>
 
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define endl '\n'
using namespace std;
 
typedef long long LL;
typedef unsigned long long ULL;
 
void desperate_optimization(int precision){
  	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(precision);
}
 
const int N = 10;
LL arr[N + 5][N + 5];
set<int> st;
set<int> nx;
vector<int> vec;
 
void hora(int tc) {
	int n;
	cin>>n;
	st.insert({1, 2, 4, 7, 12, 20, 29, 38, 52, 73});
//	for(int i = 1;i < n;i++) {
//		nx.clear();
//		for(auto x: st) {
//			nx.insert(x);
//			for(auto y: st) {
//				if(x == y) continue;
//				nx.insert(x + y);
//			}
//		}
//		int mx = -1;
//		int now = 0;
//		for(auto x: nx) {
//			if(x != now + 1) {
//				mx = now + 1;
//				break;
//			}
//			now = x;
//		}
//		if(mx == -1) mx = now + 1;
//		st.insert(mx);		
//	}
//	for(auto x: st) cout<<x<<endl;
	LL maxi = 0;
	vec.PB(0);
	for(int i = 1;i < n;i++) {
		int j = 0;
		for(auto x: st) {
			if(i == j) break;
			arr[i][j] = arr[j][i] = (maxi + 1) * x;
			j++;
		}
		vec.PB(i);
		sort(vec.begin(), vec.end());
		do{
			LL tots = 0;
			for(int i = 1;i < vec.size();i++) tots += arr[vec[i - 1]][vec[i]];
			maxi = max(maxi, tots);
		}while(next_permutation(vec.begin(), vec.end()));
	}
	for(int i = 0;i < n;i++) {
		for(int j = 0;j < n;j++) {
			if(j) cout<<" ";
			cout<<arr[i][j];
		}
		cout<<endl;
	}
}
 
int main(){
	desperate_optimization(10);
	int ntc = 1;
	//cin>>ntc;
	for(int tc = 1;tc <= ntc;tc++) hora(tc);
	return 0;
}
 

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
typedef std::pair<int,int> P;
using namespace std;
using ll = long long;



int main(){
    int n,k;
    cin >> n >> k;
    int mx = ((n-1)*(n-2))/2;
    if (mx < k) {
        cout << "-1"; rn 0;
    }
    
    vector<P> ans;
    rep(i,n-1){
        ans.pb(mp(i+1,n));
    }
    int add = mx - k;
    vector<P> edge;
    rep(i,n-1) rep(j,i) edge.pb(mp(i+1,j+1));
    rep(i,add) ans.pb(edge[i]);
    cout << ans.size() << endl;
    rep(i,ans.size()){
        cout << ans[i].fi << " "  << ans[i].se << endl;
    }
    rn 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n,h,w;
  cin >> n >> h >> w;
  int cnt = 0;
  REP(i,n){
    int a,b; cin >> a >> b;
    if(h<=a && w<=b) cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
typedef pair<int,int> pii;
const int NSIZ=1000010;
const int MSIZ=1000010;
const int mxint=-1u/2;
int n, m, o, re=0;
int a[NSIZ], b[NSIZ];
bool chk[NSIZ];
int main(){
	int i, j, k, l;
	scanf("%d %d", &n, &m);
	for(i=1; i<=n; i++){
		a[i]=1;
	}
	chk[1]=1;
	for(i=0; i<m; i++){
		scanf("%d %d", &j, &k);
		a[k]++;
		a[j]--;
		if(chk[j]==1)chk[k]=1;
		if(a[j]==0)chk[j]=0;
	}
	for(i=1; i<=n; i++){
		re+=chk[i];
	}
	printf("%d\n", re);
	return 0;
}

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

int N;

void dfs(string s,char c){
    int n = s.length();
    if(n == N){
        cout << s << endl;
    }else{
        for(char C = 'a';C<=c;C++){
            if(C == c){
                dfs(s + C , (char)(c+1));
            }else{
                dfs(s + C , c);
            }
        }
    }
}

int main(){
    cin >> N;
    dfs("",'a');
    return 0;
}

Measured memory_bytes: 1536
import math
a,b,x = map(int,input().split())
if 2 * x >= a ** 2 * b:
    A = a
    B = 2 * ((b - (x / (a ** 2))))
else:
    A = (2 * x) / (a * b)
    B = b
#print(A,B)
rad = math.atan2(B,A)
ans = math.degrees(rad)
print(ans)

Measured memory_bytes: 3188
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx2")
#include <bits/stdc++.h>
using namespace std ;
#define ll long long
void FastInputOutput(){
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}

inline int D(){
    int t ;
    scanf( "%d" , &t ) ;
    return t ;
}
inline ll LLD(){
    ll t ;
    scanf( "%lld" , &t ) ;
    return t ;
}

ll power(ll x, ll p, ll m){
    ll res = 1;
    while(p){
        if(p&1)    res = (res * x)%m;
        x = (x * x)%m;
        p >>= 1;
    }
    return res;
}


const int N = 1e5 + 5;
vector<int> v[3];
int a[35][35];
ll cost[3][32];
int n, c;

int main(){
    n = D(), c = D();
    for(int i = 1; i <= c; ++i)
        for(int j = 1; j <= c; ++j)
            a[i][j] = D();
    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= n; ++j)
            v[(i + j) % 3].push_back(D());
    
    for(int i = 0; i < 3; ++i){
        for(int cc = 1; cc <= c; ++cc){
            ll t = 0;
            for(int j = 0; j < v[i].size(); ++j){
                t += a[v[i][j]][cc];
            }
            cost[i][cc] = t;
        }
        
    }
    
    ll ans = 1e11;
    for(int i = 1; i <= c; ++i){
        for(int j = 1; j <= c; ++j){
            if(i == j)
                continue;
            for(int k = 1; k <= c; ++k){
                if(i == k || j == k)
                    continue;
                ans = min(ans, cost[0][i] + cost[1][j] + cost[2][k]);
            }
        }
    }
    printf("%lld", ans);
    return 0;
}


Measured memory_bytes: 1520
def resolve():
    import sys
    input = sys.stdin.readline
    # 整数 1 つ
    # n = int(input())
    # 整数複数個
    n, w = map(int, input().split())
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    # N = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    A = [list(map(int, input().split())) for i in range(n)]

    Knap = [[0] * (w+1) for _ in range(n+1)]
#    Knap = [[0] * (110) for _ in range(10**5+10)]

    for i in range(n):
        for k in range(w+1):
            if k + A[i][0] <= w:
#                point = k + A[i][0]
                Knap[i+1][k+A[i][0]] = max(Knap[i+1][k+A[i][0]], (Knap[i][k] + A[i][1]))

            Knap[i+1][k] = max(Knap[i][k], Knap[i+1][k])

#    knapmax = 0
    # for i in range(n):
    #     knapmax = max(knapmax, max(Knap[i+1]))
    print(Knap[n][w])
#    print(*Knap, sep="\n")
resolve()

Measured memory_bytes: 119280
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

/*
dp(i) = i保留してる
*/

ll n,tmp=0,ans=1,mod=1e9+7;
string s;

void init(){
	cin>>n>>s;
}

int main(void){
	init();
	rep(i,2*n){
		ll a=0;
		if(s[i]=='B')a=1;
		if((tmp+a)%2==0){
			// 受ける
			ans=(ans*tmp)%mod;
			tmp-=1;
		}else{
			// 出す
			tmp+=1;
		}
	}
	// cerr<<tmp<<endl;
	if(tmp!=0)ans=0;
	reg(i,1,n)ans=(ans*i)%mod;
	cout<<ans<<endl;
	return 0;
}

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

int main(){
    int N;
    cin >> N;
    map<string, int> cnt;
    
    rep(i,N){
        string s;
        cin >> s;
        cnt[s]++;
    }

    int max = 0;
    for(const auto& x: cnt){
        int tmp = x.second;
        if(tmp > max) max = tmp;
    }

    for(auto it = cnt.begin(); it != cnt.end(); it++){
        if(it->second == max) cout << it->first << endl;
    }
}

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

int main() {
    int a, b, c;
    cin >> a >> b >> c;

    if (a > b) {
        if (c < a && c > b) cout << "Yes" << endl;
        else cout << "No" << endl;
    } else {
        if (c > a && c < b) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}


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

#define NMAX 101

using namespace std;

ifstream fin("f.in");
ofstream fout("f.out");

int dist, prevDist;
int n, l, x;
int cntr;

int main()
{
    cin >> n >> x;
    cntr = 1;
    prevDist = 0;
    for(int i = 1; i <= n; i++)
    {
        cin >> l;
        dist = prevDist + l;
        if(dist <= x) cntr++;
        prevDist = dist;
    }
    cout << cntr << '\n';
    return 0;
}


Measured memory_bytes: 256
function main(lines) {
    const input = lines.split('\n').map(Number)[0]
    var count = 0
    for(var i=1; i<=input; i+=2){
        // if(input%i === 0){
            var tmpCount = 0;
            // console.log(i)
            for(var k=1; k<=i; k++){
                if(i%k === 0){
                    tmpCount++
                }
            }
            if(tmpCount === 8){
                count++
            }
        // }
    }
    console.log(count)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7372
import java.util.*;
public class Main {
   static Scanner sc = new Scanner(System.in);
   static Scanner sc2 = new Scanner(System.in);
   public static void main(String[] args) {
      int N = sc.nextInt();
      int T = sc.nextInt();
      int[] c = new int[N];
      int[] t = new int[N];
      int min = 10000;

      for (int i = 0; i < N; i++) {
         c[i] = sc.nextInt();
         t[i] = sc.nextInt();
      }

      for (int i = 0; i < N; i++) {
         if (T >= t[i]) {
            min = min > c[i] ? c[i] : min;
         }
      }

      if (min == 10000) {
         System.out.println("TLE");
      } else {
         System.out.println(min);
      }
   }

}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pil = pair<int,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,v.size())i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(v.size())o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const double eps = 1e-6;
const ll LINF = 100200300400500600ll;
const int INF = 1001001001;
//--------------------------------------------------------
#define fastio cin.tie(nullptr); std::ios::sync_with_stdio(false);
#define myio ifstream iofi; if(argc>1){iofi.open(argv[1]); std::cin.rdbuf(iofi.rdbuf());}
#define myloopset int loop = 1; if(argc>2) loop =stoi(argv[2]); rep(i,loop)
//--------------------------------------------------------------
template <class T> T chmin(T &a,T b){if(a>b){a=b; return 1;}else return 0;}
template <class T> T chmax(T &a,T b){if(a<b){a=b; return 1;}else return 0;}
const int dx[4] = {0,1,0,-1};
const int dy[4] = {-1,0,1,0};
const int mod = 1000000007;

void Main(){
  int a,b;
  cin>>a>>b;
  rep(i,2000){
    int p = 0.08*i;
    int q = 0.10*i;
    if(abs(p-a)<1 and abs(q-b)<1){
      cout<<i<<endl;
      return;
    }
  }
      cout<<-1<<endl;
      return;
} signed main(int argc,char** argv)
{fastio; myio; myloopset Main();}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;
#define all(x) (x).begin(),(x).end()

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

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

ll fac(ll n){
    ll t = 1;
    rep1(i, n + 1)t *= i;
    return t;
}

int main()
{
    ll n,ans = 1,g = 0;
    cin >> n;
    vector<ll> a(n);
    rep0(i, n)cin >> a[i];
    rep0(i, n - 1){
        if (g == 0) {
            if (a[i] < a[i + 1]) {
                g = 1;
            }else if (a[i] > a[i + 1]){
                g = 2;
            }
        }else if (g == 2 && a[i] < a[i + 1]){
            ++ans;
            g = 0;
        }else if(g == 1 && a[i] > a[i + 1]){
            ++ans;
            g = 0;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    ll n, ans = 0;
    cin >> n;
    vector<ll> a(n);
    vector<bool> b(1000010, true);
    rep(i, n)cin >> a[i];
    map<ll, ll> mp;
    rep(i, n)mp[a[i]]++;
    sort(all(a));
    a.erase(unique(all(a)), a.end());
    rep(i, a.size()){
        if(mp[a[i]] == 1 && b[a[i]]){
            ans += mp[a[i]];
        }
        ll now = a[i];
        while(now <= 1000000){
            b[now] = false;
            now += a[i];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 17516
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <math.h>
#include <algorithm>
#include <deque>
#include <queue>
#include <climits>
using namespace std;
#define rep(i,l,r) for(int i=l;i<r;i++)
#define repb(i,r,l) for(int i=r;i>l;i--)
#define ll long long
#define ull unsigned long long
#define ve vector
#define umap unordered_map
#define iter iterator 
int MOD = 1e9+7;
void solve() {
    int a,b;
    cin>>a>>b;
    ll res=1;
    if(a>b) swap(a,b);
    if(a==b) {
        for(int i=1;i<=a;i++) res = res*i % MOD;
        res = res*res %MOD;
        res = res*2 %MOD;
    } else if(a==b-1) {
        for(int i=1;i<=a;i++) res = res*i %MOD;
        res = res*res %MOD;
        res = res*b %MOD;
    } else res=0;
    cout<<res<<endl;
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define REP(i, n) for (long long i = 0; i < (n); i++)
struct UnionFind {
    vector<int> parent, size;
    UnionFind(int n) {
        parent.resize(n, -1);
        size.resize(n, 1);
    }
    void unite(int x, int y) {
        if (same(x, y)) {
            return;
        }
        x = root(x);
        y = root(y);
        if (size[x] <= size[y]) {
            swap(x, y);
        }
        parent[y] = x;
        size[x] += size[y];
    }
    bool same(int x, int y) { return (root(x) == root(y)); }
    int root(int x) {
        while (parent[x] != -1) {
            x = parent[x];
        }
        return x;
    }
    int getsize(int x) { return size[root(x)]; }
};
vector<vector<P>> mst(vector<vector<P>> graph) {
    vector<pair<ll, P>> as;
    REP(i, graph.size()) {
        REP(j, graph[i].size()) { as.push_back({graph[i][j].second, {i, graph[i][j].first}}); }
    }
    sort(as.begin(), as.end());
    UnionFind uf(graph.size());
    vector<vector<P>> ans(graph.size());
    REP(i, as.size()) {
        if (!uf.same(as[i].second.first, as[i].second.second)) {
            ans[as[i].second.first].push_back({as[i].second.second, as[i].first});
            ans[as[i].second.second].push_back({as[i].second.first, as[i].first});
            uf.unite(as[i].second.second, as[i].second.first);
        }
    }
    return ans;
}
signed main() {
    int v, e;
    cin >> v >> e;
    vector<vector<P>> graph(v);
    vector<vector<P>> ans(v);
    REP(i, e) {
        ll s, t, w;
        cin >> s >> t >> w;
        graph[s].push_back({t, w});
        graph[t].push_back({s, w});
    }
    ans = mst(graph);
    ll sum = 0;
    REP(i, v) {
        REP(j, ans[i].size()) { sum += ans[i][j].second; }
    }
    cout << sum / 2 << endl;
}


Measured memory_bytes: 17772
#include <iostream>
//#include <iomanip>
#include <string>
//#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}
//void chmin(ll &a,ll b){if(a>b) a = b ;}

int main(){
	string s ; cin >> s ;
	deque<char> dq1,dq2 ;
	for(int i=0;i<s.size();i++){
		if(i<s.size()/2) dq1.push_back(s.at(i)) ;
		else dq2.push_back(s.at(i)) ;
	}
	while(1){
		dq2.pop_back() ;
		dq2.pop_back() ;
		dq2.push_front(dq1.back()) ;
		dq1.pop_back() ;
		if(dq1==dq2){
			cout << dq1.size()*2 << endl ;
			return 0 ;
		}
	}
}


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

using namespace std;
using pii=pair<int,int>;
using ll=long long;

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

    int n,d;
    cin>>n>>d;
    vector<vector<int>> p(n,vector<int>(d));
    int answer=0;
    for(int i=0; i<n; i++) for(int j=0; j<d; j++) cin>>p[i][j];
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            int sum=0;
            for(int k=0; k<d; k++) sum+=(int)pow(p[i][k]-p[j][k],2);
            int sq=sqrt((double)sum);
            if(sq*sq==sum) answer+=1;
            sq+=1;
            if(sq*sq==sum) answer+=1;
        }
    }

    cout<<answer;

    return 0;
}


Measured memory_bytes: 256
import itertools
factorDictionary = {}
plist = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
for p in plist:
    factorDictionary[p] = 0
N = int(input())
for i in range(1,N+1):
    x = i
    for p in plist:
        while x%p == 0:
            factorDictionary[p] += 1
            x /= p
triples = itertools.combinations(plist,3)
doubles = itertools.combinations(plist,2)
answer = 0
for triple in triples:
    addedValue = 0
    for a,b,c in itertools.permutations(triple,3):
        p = factorDictionary[a]
        q = factorDictionary[b]
        r = factorDictionary[c]
        if p>=4 and q>=4 and r>=2:
            addedValue += 1
    answer += addedValue//2
for double in doubles:
    for a,b in itertools.permutations(double,2):
        p = factorDictionary[a]
        q = factorDictionary[b]
        if p>=14 and q>=4:
            answer +=1
        if p>=24 and q>=2:
            answer +=1
for a in plist:
    if factorDictionary[a] >= 74:
        answer += 1
print(answer)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using P = pair<int,int>;
using vl = vector<ll>; using vvl = vector<vl>;
#define mp make_pair
#define pb push_back
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for (int i=(n-1);i >= 0;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)((v).size())
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
#define Sort(v) sort(all(v))
#define Rev(v) reverse(all(v))
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,w) vector<vector<type>>name(h,vector<type>(w));in(name)
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cout << H << " ";
    debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
    for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
    return os;
}
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
template<class T>bool chmax(T &a, const T &b) {if(a<b){a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if(b<a){a=b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const int dx[8] = {1,0,-1,0,1,1,-1,-1}; const int dy[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int d,s,t;
    cin >> d >> t >> s;
    if(d <= s*t) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define square(x) pow(x,2.0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define max_queue(x) priority_queue<x>
#define min_queue(x) priority_queue<x, vector<x>, greater<x>>
#define big_sort(v) sort(all(v), [](int a, int b) { return a > b; })//大きい順にソート
using ll = long long;
using vi = vector<ll>;
using vvi = vector<vi>;
using vs = vector<string>;
using vd = vector<long double>;
#define co(x) cout << x << endl;
#define cins(n,v) rep(i,n){cin >> v.at(i);}
#define couts(v) rep(i,v.size()){cout << v.at(i) << endl;}
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
/*
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
*/
int main() {
  double d,t,s;
  cin >> d>>t>>s;
  if(d/s<=t) {co("Yes");return 0;}
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3724
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n = ni()
a = nl()

dp=[0]*(n+1)
dp[0] = 1000

for i in range(1,n):
  dp[i]=dp[i-1]
  for j in range(i):
    v = dp[j] // a[j]
    w = dp[j] + (a[i]-a[j])*v
    dp[i] = max(dp[i],w)
print(dp[n-1])


Measured memory_bytes: 64372
#include <bits/stdc++.h>
#ifdef ONLINE_JUDGE
#define endl "\n"
#endif
using namespace std;
typedef unsigned long long int lu;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> v;
typedef vector<v> vv;
typedef vector<ld> vld;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
const ll MOD = 1e9 + 7;
const v dx = {1, -1, 0, 0};
const v dy = {0, 0, 1, -1};
#define yes cout << "YES\n";
#define no cout << "NO\n";
#define yesno(f) \
    if (f)       \
        yes else no;
#define noo \
    { no return; }
#define amax(x, y) \
    if (y > x)     \
        x = y;
#define amin(x, y) \
    if (y < x)     \
        x = y;
#define sz(x) (ll) x.size()
#define sq(x) ((x) * (x))

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

template <typename T = ll>
vector<T> ga(ll n, bool oneIndexed = false) {
    vector<T> a = vector<T>(n + oneIndexed);

    for (ll i = 0; i < n; i++) {
        T p;
        cin >> p;
        a[i + oneIndexed] = p;
    }

    return move(a);
}

template <typename T, typename A>
void pa(vector<T, A> const &a, ll begin = 0, ll end = -1) {
    if (end == -1)
        end = sz(a) - 1;
    for (ll i = begin; i <= end; i++) {
        cout << a[i] << " ";
    }
    cout << endl;
}

void solve() {
    ll n, m;
    cin>>n>>m;
    cout << n * (n - 1) / 2 + m * (m - 1) / 2 << endl;
}

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    // ll t;cin >> t;while(t--)
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
using namespace std;
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int, int>;

const int INF = 100100100;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) {
    cin >> a[i];
    --a[i];
  }

  vector<int> dist(n, INF);
  dist[0] = 0;

  queue<P> q;
  q.push(P(a[0], dist[0]));  // a[0]をIN　距離は０

  while (!q.empty()) {
    int num = q.front().first;   // index
    int dis = q.front().second;  // a[0]からの距離
    q.pop();

    if (dist[num] == INF) {
      dist[num] = dis + 1;
      q.push(P(a[num], dist[num]));
      // cout << dist[num];
    }
  }

  cout << (dist[1] == INF ? -1 : dist[1]);
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>

using namespace std;
typedef long long lint;

int a, b;
string ans;

void resolve()
{
    cin >> a >> b;

    ans = (a < b) ? string(b, to_string(a)[0]) : string(a, to_string(b)[0]);

    cout << ans << endl;
}

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


Measured memory_bytes: 256
//const int N = 1e5+5;
//vi adj[N];
//int sz[N],par[N],depth[N];
//void dfs(int u, int p = 0){
//    sz[u] = 1;
//    for(int v : adj[u]){
//        if(v == p) continue;
//        depth[v] = depth[u]+1;
//        par[v] = u;
//        dfs(v,u);
//        sz[u] += sz[v];
//    }
//}
//string _(){
//    int n;
//    cin >> n;
//    rep(i,1,n-1){
//        int u,v;
//        cin >> u >> v;
//        adj[u].pb(v);
//        adj[v].pb(u);
//    }
//    dfs(1);
//    int up  = depth[n]-(depth[n]+2)/2;
//    int take = n;
//    while(up--){
//        take = par[take];
//    }
//    if(sz[take]*2 >= n)
//        return "Snuke";
//    return "Fennec";
//}
#include <iomanip>
#include <vector>
#include <utility>
#include <iostream>
#include <string>
#define pb push_back
#define REP_INT(i,l,r) for(int i = l; i <= r; ++i)
#define GET_REP_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define rep(...) GET_REP_MACRO(__VA_ARGS__,REP_ANY,REP_INT)(__VA_ARGS__)
#define all(v) (v).begin(), (v).end()
#define T1 template<typename T> static
using namespace std;
typedef vector<int> vi;
T1 ostream& operator<<(ostream& stream, const vector<T>& t);
T1 istream& read(T, T, istream& = cin);
const int N = 1e5+5;
vi adj[N];
int sz[N],par[N],depth[N];
void dfs(int u, int p = 0){
    sz[u] = 1;
    for(int v : adj[u]){
        if(v == p) continue;
        depth[v] = depth[u]+1;
        par[v] = u;
        dfs(v,u);
        sz[u] += sz[v];
    }
}
string _(){
    int n;
    cin >> n;
    rep(i,1,n-1){
        int u,v;
        cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    dfs(1);
    int up  = depth[n]-(depth[n]+2)/2;
    int take = n;
    while(up--){
        take = par[take];
    }
    if(sz[take]*2 >= n)
        return "Snuke";
    return "Fennec";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
        cout << _() << '\n';
}


Measured memory_bytes: 13184
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define ll long long
#define INF 1<<31-1
#define LNF 9223372036854775807
#define PI 3.14159265358979
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define MOD 1000000007
//#define MOD 998244353
#define NUM 200010
 
void swap(int* a,int* b){int tmp=*a;*a=*b;*b=tmp;}
int abs(int a){if(a<0)return -a;return a;}
int dup(int a,int d){if(a%d==0)return a/d;else return a/d+1;}
int mod(int a,int m){if(a<0)return a%m+m;else return a%m;}

void swapl(ll* a,ll* b){ll tmp=*a;*a=*b;*b=tmp;}
ll absl(ll a){if(a<0)return -a;return a;}
ll dupl(ll a,ll d){if(a%d==0)return a/d;else return a/d+1;}
ll modl(ll a,ll m){if(a<0)return a%m+m;else return a%m;}

ll GCD(ll a,ll b){ll c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
ll LCM(ll a,ll b){return a*b/GCD(a,b);}

ll factorial(ll n, ll m) {return n < m ? 1 : n*factorial(n-1, m);}

int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

// ll dp[]
ll list[11];
ll n, m, q;
ll a[100], b[100], c[100], d[100];
ll max_cost=0;

ll search(ll len, ll max){
    ll cost = 0;
    if (max > m) return;
    if (len == n)
    {
        for (int i = 0; i < q; i++)
        {
            if(list[b[i]-1] - list[a[i]-1] == c[i]) cost += d[i];
        }
        if (cost > max_cost) max_cost = cost;
        return;
    }
    list[len] = max;
    search(len+1, max);
    search(len, max+1);
    return;
}

int main(){

  scanf("%lld%lld%lld", &n, &m, &q);

  for (int i = 0; i < q; i++)
  {
      scanf("%lld%lld%lld%lld", a+i, b+i, c+i, d+i);
  }
  
  search(0, 1);
  printf("%lld\n", max_cost);

  return 0;
}

Measured memory_bytes: 1732
#include <iostream>
#include <map>
//#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

int N,K,L;
int p[200010] = {0},r[200010] = {0};
int q[200010] = {0},s[200010] = {0};

void init_road(int N){
	for(int i=0;i<=N;++i) p[i] = i;
}

int root_road(int a){
	if(p[a] == a) return a;
	return (p[a] = root_road(p[a]));
}

bool is_same_set_road(int a,int b){
	return root_road(a) == root_road(b);
}

void unite_road(int a, int b){
	a = root_road(a);
	b = root_road(b);
	if(a==b) return;
	if(r[a]<r[b]){
		p[a] = b;
	}else{
		p[b] = a;
		if(r[a] == r[b]) r[a]++;
	}
}

void init_line(int N){
	for(int i=0;i<=N;++i) q[i] = i;
}

int root_line(int a){
	if(q[a] == a) return a;
	return (q[a] = root_line(q[a]));
}

bool is_same_set_line(int a,int b){
	return root_line(a) == root_line(b);
}

void unite_line(int a, int b){
	a = root_line(a);
	b = root_line(b);
	if(a==b) return;
	if(s[a]<s[b]){
		q[a] = b;
	}else{
		q[b] = a;
		if(s[a] == s[b]) s[a]++;
	}
}


int main(){
	cin >> N >> K >> L;
	init_road(N);
	init_line(N);
	//vector<pair<int,int>> road(K+1);
	//vector<pair<int,int>> line(L+1);
	for(int i=1;i<=K;i++){
		int p,q;
		cin >> p >> q;
		unite_road(p,q);
		//road[i] = make_pair(p,q);
	}
	for(int i=1;i<=L;i++){
		int p,q;
		cin >> p >> q;
		unite_line(p,q);
		//line[i] = make_pair(p,q);
	}
	map<pair<int,int>,int> m;
	for(int i=1;i<=N;i++){
		m[make_pair(root_road(p[i]),root_line(q[i]))]++;
	}
	for(int i=1;i<=N;i++){
		int ans = m[make_pair(root_road(p[i]),root_line(q[i]))];
		if(i != N) cout << ans << " ";
		else cout << ans << endl;
	}
}

Measured memory_bytes: 13696
#include <iostream>
#include <cstdlib>
#include <map>
#include <vector>

using namespace std;

int main () {
  while( 1 ) {
    int n;
    cin >> n;
    if( !n ) { return EXIT_SUCCESS; }
    
    vector<int> seq;
    
    seq.reserve( n );
    for( int i = 0; i < n; i++ ) {
      cin >> seq[ i ];
    }
    
    int ct;
    for( ct = 0; ; ct++ ) {
      map<int, int> m;
      for( int i = 0; i < n; i++ ) {
        if( m.find( seq[ i ] ) == m.end() ) {
          m[ seq[ i ] ] = 1;
        } else {
          m[ seq[ i ] ]++;
        }
      }

      bool changed = false;
      for( int i = 0; i < n; i++ ) {
        if( seq[ i ] != m[ seq[ i ] ] ) { changed = true; }
        seq[ i ] = m[ seq[ i ] ];
      }
      /*
      // <for-debug>
      for( int i = 0; i < n; i++ ) {
        cout << seq[ i ] << flush;
        if( i == n - 1 ) { cout << endl; }
        else { cout << " " << flush; }
      }
      // </for-debug>
      */
      if( !changed ) { break; }
    }

    cout << ct << endl;
    for( int i = 0; i < n; i++ ) {
      cout << seq[ i ] << flush;
      if( i == n - 1 ) { cout << endl; }
      else { cout << " " << flush; }
    }
  }
}

Measured memory_bytes: 1196
N = int(input())
A = list(map(int, input().split()))
A.insert(N, 0)
A.insert(0, 0)
cost_sum = 0
for i in range(1, len(A)):
	cost_sum += abs(A[i] - A[i-1])
for i in range(1, len(A) - 1):
	print(cost_sum + abs(A[i-1] - A[i+1]) - abs(A[i-1] - A[i]) - abs(A[i+1] - A[i]))

Measured memory_bytes: 13920
#include<bits/stdc++.h>
using namespace std;
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    string s, t;
    cin>>s>>t;
    int ans = 0;
    f(i, 3) {
        if(s[i] == t[i]) ans++;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
typedef struct n{
  char s[101];
}n;
int main(){
  int a,b;
  scanf("%d %d",&a,&b);
  n c[a];
  for(int i=0; i<a; i++){
    scanf("%s",c[i].s);
  }
  for(int i=0; i<b+2; i++){
    printf("#");
  }
  printf("\n");
  for(int i=0; i<a; i++){
    printf("#%s#\n",c[i].s);
  }
  for(int i=0; i<b+2; i++){
    printf("#");
  }
  return 0;}

Measured memory_bytes: 128
import java.util.*;

public class Main {


    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int time_1 = 100000;
        int time_2 = 10;

        int D = sc.nextInt();
        int[] c = new int[27];
        int[] t = new int[D + 1];
        int[] last_day = new int[27];
        Arrays.fill(last_day, 0);
        int[][] s = new int[D + 1][27];
        for (int i = 1; i <= 26; i++) {
            c[i] = sc.nextInt();
        }
        for (int i = 1; i <= D; i++) {
            for (int j = 1; j <= 26; j++) {
                s[i][j] = sc.nextInt();
            }
        }

        for (int i = 1; i <= D; i++) {
            Random random = new Random();
            t[i] = 1 + random.nextInt(26);
        }
        int[] last_array = t;

        long last_sum = 0;
        for (int j = 0; j < time_1; j++) {
            long tmp_sum = 0;
            Arrays.fill(last_day,0);
            for (int k = 0; k < time_2; k++) {
                Random random = new Random();
                int d = 1 + random.nextInt(D);
                int q = 1 + random.nextInt(D);
                int tmp = t[d];
                t[d] = t[q];
                t[q] = tmp;
            }
            for (int i = 1; i <= D; i++) {
                last_day[t[i]] = i;
                tmp_sum += calcS(c, s, t[i], i, last_day);
            }
            if (tmp_sum > last_sum) {
                last_array = t;
                last_sum = tmp_sum;
            } else {
                t = last_array;
            }
        }


        for (int i = 1; i <= D; i++) {
            System.out.println(t[i]);
        }

    }

    private static long calcS(int[] c, int[][] s, int kaisai, int day, int[] last_day) {

        long loss = 0;
        for (int i = 1; i <= 26; i++) {
            if (i == kaisai) {
                last_day[i] = day;
                continue;
            }
            loss -= c[i] * (day - last_day[i]);
        }

        long plus = s[day][kaisai];
        return plus + loss;
    }

}


Measured memory_bytes: 47112