akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

#define maxN 100011

int n, i, R, vv;
ll A, B, C;
vector< pair<int, ll> > list[maxN];
int cnt[maxN];
ll ans;
ll mini = 1LL << 60;

int dfs(int node, int root) {
    bool ok = true;
    cnt[node] = 1;

    for (auto to : list[node]) {
        if (to.first == root) continue;
        int ans = dfs(to.first, node);
        if (ans != 0) return ans;

        cnt[node] += cnt[to.first];
        ok &= (cnt[to.first] <= n / 2);
    }

    ok &= (n - cnt[node] <= n / 2);
    if (ok && cnt[node] == n / 2) vv = root;

    if (ok) return node;
    return 0;
}

void dfs2(int node, int root, ll depth) {
    ans += 2LL * depth;
    for (auto to : list[node]) {
        if (to.first == root) continue;
        dfs2(to.first, node, depth + to.second);
    }
}

int main()
{
    //freopen("test.in","r",stdin);

    cin >> n;
    for (i = 1; i < n; i++) {
        cin >> A >> B >> C;
        list[A].pb(mp(B, C));
        list[B].pb(mp(A, C));
    }

    R = dfs(1, 0);
    dfs2(R, 0, 0);

    for (auto to : list[R])
        mini = min(mini, to.second);

    if (vv != 0) {
        for (auto to : list[vv])
            if (to.first == R)
                mini = to.second;
    }

    cout << ans - mini;


    return 0;
}


Measured memory_bytes: 14976
#include<bits/stdc++.h>
#include<iomanip>
#include<numeric>

using namespace std;
using ll = long long;
constexpr int mo = 1000000007;
constexpr int  mod = mo;
constexpr ll inf = 1ll<<62;
int main(){
    int n;
    cin>>n;
    vector<int> v(n);
    for(auto &a : v) cin>>a;
    int count = 0;
    for(int i=0;i<n;++i){
        if(i+1 != v[i])count++;
    }
    if(count == 2 or count == 0){
        cout << "YES" << endl;
    }else cout << "NO" << endl;
    return 0;
}



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

const long long INF = 1LL << 60;

int N;
int a[3009];

long long dp[3009][3009];

long long solve(int l, int r) {
    if(l == r) return a[l];
    if(dp[l][r] != INF) return dp[l][r];
    return dp[l][r] = max(a[l] - solve(l + 1, r), a[r] - solve(l, r - 1));
}

int main() {
    cin >> N;
    for(int i = 1; i <= N; i++)
        cin >> a[i];

    for(int i = 0; i < 3009; i++)
        for(int j = 0; j < 3009; j++)
            dp[i][j] = INF;

    cout << solve(1, N) << endl;
}

Measured memory_bytes: 71168
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef double db;
const int N = 200010;
ll a[N],b[N],k,x,s; // a b=-a
int n;
int les(ll* arr,int L,int R,ll y) {
    int M,B=-1;
    while(L<=R) {
        M=(L+R)>>1;
        if(arr[M]<y) B=M,L=M+1;
        else R=M-1;
    }
    return B;
}
int lar(ll *arr,int L,int R,ll y) {
    int M,B=-1;
    while(L<=R) {
        M=(L+R)>>1;
        if(arr[M]>y) B=M,R=M-1;
        else L=M+1;
    }
    return B;
}
ll ceild(ll a,ll b){
    if(a%b==0||a<0&&b>0||a>0&&b<0) return a/b;
    return a/b+1;
}
ll floord(ll a,ll b){
    if(a%b==0||a>0&&b>0||a<0&&b<0) return a/b; 
    return a/b-1;
}
int check(ll val) {
    ll ls=0,lr=0,eq;
    int tmp;
    // cout<<ls<<" "<<lr<<endl;
    for(int i=1;i<=n;i++) {
        // printf("a[%d]=%lld\n",i,a[i]);
        if(a[i]>0){
            tmp=les(a,i+1,n,ceild(val,a[i]));
            if(tmp!=-1) ls+=(ll)(tmp-i);
            // printf("+less tmp : %d ls:%d\n",tmp,ls);
            tmp=lar(a,i+1,n,floord(val,a[i]));
            if(tmp!=-1) lr+=(ll)(n-tmp+1);
            // printf("+large tmp : %d lr:%d\n",tmp,lr);
        }
        else if(a[i]<0){
            tmp=lar(a,i+1,n,floord(val,a[i]));
            if(tmp!=-1) ls+=(ll)(n-tmp+1);
            // printf("-less tmp : %d ls:%d\n",tmp,ls);
            tmp=les(a,i+1,n,ceild(val,a[i]));
            if(tmp!=-1) lr+=(ll)(tmp-i);
            // printf("-large tmp : %d lr:%d\n",tmp,lr);
        }
        else {
            if(val>0)ls+=(ll)(n-i);
            if(val<0)lr+=(ll)(n-i);
        }
    }
    eq=s-lr;
    // cout<<ls<<" _ "<<eq<<" _ "<<lr<<endl;
    if(k<=ls) return 1;// less
    if(k<=eq) return 2;// eq
    return 3;//large
}
int main() {
    scanf("%d%lld",&n,&k);
    s=(n-1ll)*n/2ll;
    for(int i=1;i<=n;i++) {
        scanf("%lld",&x);
        a[i]=x;
    }
    sort(a+1,a+n+1);
    ll L=-1e18,R=1e18,M,ans;
    while(L<=R) {
        M=(L+R)>>1;
        int d=check(M);
        // cout<<L<<" "<<R<<" "<<M<<" "<<d<<endl;
        if(d==2) {ans=M;break;}
        else if(d==1) R=M-1;
        else L=M+1,ans=M;
        // system("pause");
    }
    printf("%lld\n",ans);
}

Measured memory_bytes: 4776
#include <iostream>
#include <vector>
#include <fstream>
#include <stdio.h>
#include <algorithm>
#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 INF 1e9
//#define ALL(v) v.begin(), v.end()

using namespace std;
//typedef long long ll;

int main() { //int argc, const char * argv[]

    cin.tie(0);
    ios::sync_with_stdio(false);

    //std::cout << "Hello, World!\n";
    
    int N, p, minp=200001, tmp=0, ans=0;
    cin >> N;
    REP(i, N){
        cin >> p;
        if (p < minp){
            ans++;
            minp = p;
        }
    }

    std::cout << ans;
    return 0;
}


Measured memory_bytes: 256
n=input()
s=[[1 for i in range(13)] for j in range(4)]
for i in range(n):
  a,b=map(str,raw_input().split())
  b=int(b)
  if a=='S':s[0][b-1]=0
  elif a=='H':s[1][b-1]=0
  elif a=='C':s[2][b-1]=0
  else:s[3][b-1]=0
for i in range(4):
  for j in range(13):
    if s[i][j]:
      if i==0:print'S',j+1
      if i==1:print'H',j+1
      if i==2:print'C',j+1
      if i==3:print'D',j+1

Measured memory_bytes: 4256
import java.io.*;
import java.util.*;
public class Main{

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int N = Integer.parseInt(br.readLine());
		
		StringTokenizer st = new StringTokenizer(br.readLine());
		
		HashMap<Integer, Integer> set = new HashMap<Integer, Integer>();
		HashSet<Integer> stuff = new HashSet<Integer>();
		
		for(int i = 1; i<=N; i++) {
			int n = Integer.parseInt(st.nextToken());
			stuff.add(n);
			if(set.containsKey(n)) {
				set.put(n, set.get(n)+1);
			}
			else {
				set.put(n, 1);
			}
		}
		int count = 0;
		for(int n : stuff) {
			if(set.get(n) < n) count += set.get(n);
			else if(set.get(n) > n) count += set.get(n) - n;
		}
		
		System.out.println(count);
		
	}

}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
//#define int ll
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<string> vst;
typedef vector<vst> vvst;
typedef pair<ld, ld> pld;
typedef complex<double> base;

#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for(int i = 0; i < int(n); ++i)
#define SZ(a) ((int)((a).size()))
#define triple(T) tuple<T, T, T>
#define quad(T) tuple<T, T, T, T>
#define watch(x) cerr << (#x) << " = " << (x) << endl;

#ifdef MAX_HOME
#define cerr cout
#else
#define cerr if (false) cerr
#endif

const double PI = 2 * acos(0.0);
#define rand shittttty_shit
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());

const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";

template <class T0, class T1>
inline ostream & operator << (ostream &out, pair<T0, T1> &a) {
    return out << "{" << a.first << ", " << a.second << "}";
}

template <class T0, class T1, class T2>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << "}";
}

template <class T0, class T1, class T2, class T3>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2, T3> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << ", " <<  get<3>(a) << "}";
}

template<class T>
inline ostream & operator << (ostream &out, vector<T> &a) {
    out << "[";
    fori (i, a.size())
        out << a[i] << vector<string>{", ", "]  "}[i + 1 == a.size()];
    return out;
}



void smain();

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

#ifdef MAX_HOME
    freopen("input.txt", "r", stdin);
    clock_t start = clock();
#endif
    cout << setprecision(12) << fixed;
    smain();
#ifdef MAX_HOME
    cout << "\n\n\n\nTOTAL EXECUTION TIME: " << float( clock () - start ) /  CLOCKS_PER_SEC << endl;
#endif
    return 0;
}


void smain() {

    int n;
    cin >> n;
    vector<pii> points(n);
    fori (i, n) {
        cin >> points[i].first >> points[i].second;
    }
    sort(ALL(points));
    map<pii, int> cnt;
    fori (i, n) {
        fori (j, i) {
            cnt[{points[i].first - points[j].first, points[i].second - points[j].second}]++;
        }
    }
    int mx = 0;
    for (auto x : cnt) {
        inmax(mx, x.second);
    }
    cout << n - mx;
}


Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main(){	
  	int A,B,K;
  	cin>>A>>B>>K;
  	if(B-A<2*K)for(int i=A;i<=B;i++)cout<<i<<endl;
  	else for(int i=A;i<=B;i++)if(i<A+K||B-K<i)cout<<i<<endl;
  	return 0;
}


Measured memory_bytes: 256
// ncrModせいぜい10^6とかだった気がするので無理
// これは悔しいですね クソが

package main
import "fmt"
func main(){
	var N, A, B int
	fmt.Scan(&N, &A, &B)
	MOD := int(1e9)	+ 7
  // repModP、「どっちも選ばない」を含むのでそれを-1
	ans := (repModP(2, N, MOD) - 1 - nCrModP(N, A, MOD) - nCrModP(N, B, MOD))%MOD
	if ans < 0{
		ans += MOD
	}
	fmt.Println(ans)
}

func repModP(a, n, mod int)int{
	if n==1{
		return a % mod
	}
	if n % 2 == 1{
		return a * repModP(a, n-1, mod) % mod
	}
	ret := repModP(a, n/2, mod) % mod
	ret = (ret * ret) % mod
	if ret < 0{
		ret += mod
	}
	return ret
}

func nCrModP(n, r, mod int)int{
	ret := 1
	for i:=n-r+1; i<=n; i++{
		ret *= i
		ret %= mod
	}
	for i:=2; i<=r; i++{
		ret *= repModP(i, mod-2, mod)
		ret %= mod
	}
	ret %= mod
	if ret < 0{
		ret += mod
	}
	return ret
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;

class q2
{
    static void Main (string[] args)
    {
        string[] str = Console.ReadLine().Split(' ');

        int k = int.Parse(str[0]);
        int x = int.Parse(str[1]);

        int max, min;
        var num = new List<int>();

        // 塗られ得る座標は x - k + 1 から x + k - 1 まで
        if ( x - k + 1 <= -1000000)
        {
            min = -1000000;
        } else
        {
            min = x - k + 1;
        }

        if ( x + k - 1 >= 1000000)
        {
            max = 1000000;
        } else
        {
          max = x + k - 1;
        }

        for (int i = 0; i < max - (min - 1); i++)
        {
            num.Add( min + i );
        }
        Console.WriteLine(string.Join(" ", num));
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
int main()
{
  long long int n;
  string ans="";
  //int i=0;
  cin >> n;
  while(n>0)
  {
    long long  int tmp=n%26;
    tmp=tmp+96;
    if(tmp==96)
    {
        ans=ans+"z";
        n=n-1;
    }
    else
    {
    char ch= (char)tmp;
    ans=ans+ch;
    }
    n=n/26;
  }
  reverse(ans.begin(),ans.end());
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;

int a[200005];

int main()
{ios_base::sync_with_stdio(false);
int n;
cin>>n;
rep(i,0,n-1)cin>>a[i];

int ff=1;
rep(i,1,n-1)
{
	if(a[i]<=a[i-1])ff=0;
}
if(ff)
{
	ol("1");
	return 0;
}
int lo=2,hi=n,mid,ans=n;

while(lo<=hi)
{
	mid=(lo+hi)/2;
	int foo=1;
	set<pii> s;
	rep(i,1,n-1)
	{
		if(a[i]<=a[i-1])
		{
			while(1)
			{
				set<pii> :: iterator it=s.end();
				if(s.size()==0)break;
				it--;
				if((it->ff)<=a[i])break;
				s.erase(it);
			}
			if(s.size()==0)
			{
				s.insert(mp(a[i],2));
				continue;
			}
			int lst=a[i];
			while(1)
			{
				if(lst<=0)
				{
					foo=0;break;
				}
				set<pii> :: iterator it=s.lower_bound(mp(lst,-1));
				if(it==s.end()||it->ff!=lst)
				{
					s.insert(mp(lst,2));
					break;
				}
				else
				{
					if((it->ss)!=mid)
					{
						s.erase(it);
						s.insert(mp(lst,(it->ss)+1));
						break;
					}
					else
					{
						s.erase(it);
						lst--;
					}
				}
			}
		}
		if(foo==0)break;
	}
	if(foo)
	{
		hi=mid-1;ans=mid;
	}
	else
	{
		lo=mid+1;
	}
}
ol(ans);
return 0;
}



Measured memory_bytes: 1024
#include<cstdio>
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
const long long Maxn=200000+10;
long long a[Maxn],b[Maxn],c[Maxn];
map <long long,long long> id;
long long n,ans,idcnt;
inline long long read()
{
	long long s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0' && ch<='9')s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*w;
}
inline bool cmp(long long x,long long y)
{
	return x>y;
}
int main()
{
	n=read();
	for(long long i=1;i<=n;++i)
	a[i]=b[i]=read();
	sort(a+1,a+1+n,cmp);
	sort(b+1,b+1+n,cmp);
	long long cnt=0;
	for(long long i=1;i<=n;++i)
	{
		b[++cnt]=b[i];
		id[b[cnt]]=cnt;
		long long j=i+1;
		while(b[i]==b[j] && j<=n)++j;
		i=j-1;
	}
	long long pos=2,cur=1;
	while(a[pos]==a[pos-1])++pos;
	ans+=(pos-2)*a[1];
	c[id[a[1]]]=pos-1;
	for(long long i=pos;i<=n;++i)
	{
		while(!c[cur])++cur;
		ans+=b[cur];
		--c[cur],c[id[a[i]]]+=2;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 20936
double d,r,s,z[];main(i){for(;~scanf("%lf",z-i--%6);!i|i%6||puts(d>r+s?"0":r>d+s?"2":s>d+r?"-2":"1"))r=z[2],s=z[5],d=hypot(*z-z[3],z[1]-z[4]);}

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

using namespace std;

#define INF 1e9

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

    while(1){
        int a,L;
        cin>>a>>L;

        if(a==0 && L==0)break;

        vector<int> x(L);

        vector<int> v;
        v.push_back(a);

        int ans1,ans2,ans3;

        for(int i=0;1;i++){

            for(int k=0;k<L;k++)x[k]=0;

            int p=v[v.size()-1],pos=1;

            while(p>0){
                x[L-pos]=p%10;
                pos++;
                p/=10;                
            }

            vector<int> y(L),z(L);
            y=x;
            z=x;

            sort(y.begin(),y.end());
            reverse(y.begin(),y.end());
            sort(z.begin(),z.end());

            int n=0,m=0;

            for(int j=L-1;j>=0;j--){
                n*=10;
                n+=y[j];
                m*=10;
                m+=z[j];
            }

            int d=m-n;

            bool f=false;

            for(int j=0;j<v.size();j++){
                if(v[j]==d){
                    ans1=j;
                    ans2=v[j];
                    ans3=i-j+1;
                    f=true;
                }
            }

            v.push_back(d);

            if(f)break;

        }

        cout<<ans1<<" "<<ans2<<" "<<ans3<<endl;
    }

}


Measured memory_bytes: 3120
#include <iostream>
#include <iomanip>
#include <algorithm>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

int main()
{
    ll n, m;
    cin >> n >> m;
    bool st[n + 1] = {false};
    int dp[n + 1] = {0};
    repi(i, m, 0)
    {
        int a;
        cin >> a;
        st[a] = true;
    }
    dp[0] = 1;
    repi(now, n, 0)
    {
        repi(next, min(n + 1, now + 3), now + 1)
        {
            if(!st[next]){
                dp[next] += dp[now];
                dp[next] %= MOD;
            }
        }
    }
    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 768
// 見せてやるぜ、奇跡ってやつをよぉ……
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m; cin >> n >> m;
    vvll edges(n);
    REP(i, m) {
        ll a, b; cin >> a >> b;
        edges[a - 1].push_back(b - 1);
        edges[b - 1].push_back(a - 1);
    }
    ll q; cin >> q;
    vll v(q), d(q), c(q);
    REP(i, q) {
        cin >> v[i] >> d[i] >> c[i];
        v[i]--;
    }

    vll col(n, 0), ddd(n, -1);
    for (ll i=q-1; i>=0; i--) {
        // v[i] から距離 d[i] まで塗られているなら上書きはない
        if (ddd[v[i]] >= d[i]) continue;

        ll tmpd = d[i];
        queue<ll> node;
        node.push(v[i]);
        while (tmpd >= 0 && !node.empty()) {
            queue<ll> nnode;
            while (!node.empty()) {
                q = node.front(); node.pop();
                if (ddd[q] >= tmpd) continue;
                ddd[q] = tmpd;
                if (col[q] == 0) col[q] = c[i];
                for (ll e: edges[q]) {
                    if (ddd[e] < tmpd - 1) nnode.push(e);
                }
            }
            node = nnode;
            tmpd--;
        }
    }

    REP(i, n) {
        cout << col[i] << '\n';
    }
    return 0;
}


Measured memory_bytes: 12080
import java.math.BigInteger;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static final MyScanner in = new MyScanner();

	public static void main(String[] args) {

		long all=0;
		Map<Integer,Integer> map = new HashMap<>();
		int N = in.nextInt();
		int[] A = new int[N];
		for(int i=0;i<N;i++) {
			A[i] = in.nextInt();
			int a = map.getOrDefault(A[i], -1) + 1;
			all+=a;
			map.put(A[i], a);
		}

		for(int a: A) {
			System.out.println(all - map.get(a));
		}
	}


	public static class MyScanner {
		Scanner sc = new Scanner(System.in);
		String next() { return sc.next();}
		int nextInt() { return Integer.valueOf(sc.next());}
		long nextLong() { return Long.valueOf(sc.next()); }
	}
}

Measured memory_bytes: 79724
n = int(input())
a = list(input().split())
l, r = [], []
for i, ai in enumerate(a):
    if i % 2 == 0:
        r.append(ai)
    else:
        l.append(ai)
if n % 2 == 0:
    print(" ".join(l[::-1]) + " " + " ".join(r))
else:
    print(" ".join(r[::-1]) + " " + " ".join(l))

Measured memory_bytes: 26616
import java.io.IOException;
import java.util.Scanner;
class Main{
	public static void main(String[] args)throws NumberFormatException, IOException{
//		System.out.println(" ");
		Scanner scan = new Scanner(System.in);
		int times = scan.nextInt();
		int num[] =new int[times];
		int temp = 0;
		int min = 0;
		int banchi = 0;
		int finir = 0;
		int irekae = 0;
		int i = 0;
		for(i=0;i<times;i++){
			num[i] = scan.nextInt();
		}
		i = 0;
		int bot = num.length-1;
		int pre = bot-1;
		while (times != 1){
			min = num[finir];
			banchi = finir;
//			????°????????????°?????¢???
			for(int ii=finir;ii<times;ii++){
				if(min > num[ii]){
					min = num[ii];
					banchi = ii;
				}
			}
//				????????????????????°?????¨????°????????????°?????\????????????
			if(finir != banchi){
				temp = num[finir];
				num[finir] = num[banchi];
				num[banchi] = temp;
				irekae += 1;
			}
			
			finir +=1;
			
			if(finir == times-i){//???-1????????????????????\?????????????°??????????
				break;
			}
		}
		for(i=0;i<times;i++){
			System.out.print(num[i]);
			if(i == times-1){
				System.out.println("");
				System.out.println(irekae);
			}
			else{
				System.out.print(" ");
			}

		}
	}
}

Measured memory_bytes: 26332
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
using Graph = vector<vector<int>>;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
// 
void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}


//-------------------------------------------------
// メモ
/*






*/
//-------------------------------------------------


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  string  s ;
  cin >>  s ;
  if(s[0]=='7' || s[1]=='7' || s[2]=='7'){
    yes() ;
  }
  else{
    no() ;
  }
  
  
  
  return 0 ;
}




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

const int MAXN = 1005;


signed main(){
	int X; cin >> X;
	for(int i=1; i< MAXN; ++i){
		if(X - 100*i < 0 || X - 100*i > 5*i) continue;
		else{
			cout << 1;
			return 0;
		}
	}
	cout << 0;
}

Measured memory_bytes: 256
S = input()
N = len(S)
count1,count2,count3 = 0,0,0
flg1,flg2,flg3 = False,False,False
for i in range(N):
    #print(S[i],S[-1-i])
    if S[i] == S[-1-i]:
        count1 += 1
if count1 == N:
    flg1 = True
#print(count1,flg1)
a = int((N-1)/2)
for i in range(a):
    #print(S[i],S[a-1-i])
    if S[i] == S[a-1-i]:
        count2 += 1
if count2 == int((N-1)/2):
    flg2 = True
#print(count2,flg2,a)
b = int((N+3)/2)
#print(b)
for i in range(N-b+1):
    #print(S[b+i-1],S[N-1-i])
    if S[b+i-1] == S[N-i-1]:
        count3 += 1
if count3 == N-b+1 :
    flg3 = True
if flg1 == True and flg2 == True and flg3 == True:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 61956
# import sys
# input = sys.stdin.readline

n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = list(input())
ans = 0
D = {"r":p, "s":r, "p":s}
for i in range(n):
    if i-k < 0 or t[i] != t[i-k]:
        ans += D[t[i]]
    else:
        t[i] = "n"
        # print(t)
    # print(i,ans)
print(ans)

Measured memory_bytes: 49520
from collections import deque
N,*AB=map(int,open(0).read().split())
E=[[]for _ in range(N+1)]
for a,b in zip(*[iter(AB)]*2):
	E[a].append(b)
	E[b].append(a)
def g(s):
	Q=deque([s])
	d=[0]*(N+1)
	while Q:
		v=Q.popleft()
		for u in E[v]:
			if d[u]==0:
				Q.append(u)
				d[u]=d[v]+1
	return d[1:]
print("Fennec"if 0<sum(1 if f<=s else-1 for f,s in zip(g(1),g(N))) else"Snuke")


Measured memory_bytes: 33776
#include <iostream>

using namespace std;

int main() {
  int n, x;
  cin >> n >> x;
  if (x == 1 || x == 2*n-1) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
    if (n == 2) {
      cout << 1 << endl;
      cout << 2 << endl;
      cout << 3 << endl;
    } else {
      if (x == 2) {
        int cur = 5;
        for (int i=1; i<=2*n-1; i++) {
          if (i == n-1) cout << x+1 << endl;
          else if (i == n) cout << x << endl;
          else if (i == n+1) cout << x-1 << endl;
          else if (i == n+2) cout << x+2 << endl;
          else cout << cur++ << endl;
        }
      } else {
        int cur = 1;
        if (cur == x-2) cur = x+2;
        for (int i=1; i<=2*n-1; i++) {
          if (i == n-1) cout << x-1 << endl;
          else if (i == n) cout << x << endl;
          else if (i == n+1) cout << x+1 << endl;
          else if (i == n+2) cout << x-2 << endl;
          else { cout << cur++ << endl; if (cur == x-2) cur = x+2;}
        }
      }
    }
  }
  return 0;
}


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

int n,a[107],s;

inline bool cmp(int x,int y){
	return x>y;
}

int main(){
	cin>>n;
	for(int i=1;i<=n;++i) cin>>a[i];
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;++i){
		if(i&1) s+=a[i];
		else s-=a[i];
	}
	cout<<s;
}

Measured memory_bytes: 256
n,t = map(int,input().split())
tl = list(map(int,input().split()))
ans = t
for i in range(n-1):
	if tl[i+1]-tl[i] >= t:
		ans += t
	else:
		ans += t-(t-(tl[i+1]-tl[i]))
print(ans)

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

int main() {
  int n;
  string s;
  cin >> n >> s;
  string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  for(int i = 0; i < s.size(); i++){
    for(int j = 0; j < 26; j++){
      if(s[i] == alphabet[j]){
        if(j + n >= 26){
          s[i] = alphabet[(j + n) - 26];
          break;
        }
        else {
          s[i] = alphabet[j + n];
          break;
        }
      }
    }
  }

  cout << s;
}
  



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

using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define dump(x) cerr << #x " = " << (x) << '\n'
#define sz(x) ((int)(x).size())
#define endl '\n'

#ifdef _DEBUG27_
    //#define STRESS 1
#endif

typedef long long llong;

const int INF = 2e9;
const llong LINF = 2e18;

void inv(bool e);
template<typename T> T sign(T a);
template<typename T> void die(T &a);
template<typename T> void umax(T &a, T b);
template<typename T> void umin(T &a, T b);

bool brute, alter;
int cnt_tests = 1;

// Improoving ATC rating. I want to leave this green trash

// Code below

int n, m;

llong cost[10][10];

int wall[300][300];

void inp() {
    cin >> n >> m;
    for (int i = 0; i <= 9; ++i) {
        for (int j = 0; j <= 9; ++j) {
            cin >> cost[i][j];
        }
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            cin >> wall[i][j];
        }
    }
}

llong dist[10][10];

void solve() {
    for (int i = 0; i <= 9; ++i) {
        for (int j = 0; j <= 9; ++j) {
            dist[i][j] = cost[i][j];
        }
    }
    for (int k = 0; k <= 9; ++k) {
        for (int j = 0; j <= 9; ++j) {
            for (int i = 0; i <= 9; ++i) {
                umin(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
    llong ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (wall[i][j] != -1) {
                ans += dist[wall[i][j]][1];
            }
        }
    }
    cout << ans;
}

void stress() {

}

void naive() {

}
void run();
int main() {
    #ifdef _DEBUG27_
        if (1)
            freopen("input.txt", "r", stdin);
    #else
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        if (0) {
            freopen("palindrome.in", "r", stdin);
            freopen("palindrome.out", "w", stdout);
        }
    #endif
    srand(time(0));
    #ifdef STRESS
        brute = true;
    #else
        brute = false;
    #endif  
    
    for (int i = 0; (i < cnt_tests); i++) {
        run();
    }
    #ifdef _DEBUG27_
        cout << endl << "Time: " << clock() / 1000.0 << " ms";
    #endif
    return 0;
}

void run() {
    if (!brute) {
        inp();
    }
    else {
        stress();
    }
    solve();
    cout << endl;
}

template<typename T>
void die(T &a) {
    cout << a;
    exit(0);
}

template<typename T>
T sign(T a) {
    if (a == 0)
        return 0;
    if (a < 0)
        return -1;
    return 1;
}

template<typename T>
void umax(T &a, T b) {
    if (b > a)
        a = b;
}

template<typename T>
void umin(T &a, T b) {
    if (b < a)
        a = b;
}

void inv(bool e) {
    if (!e) {
        vector<int> a;
        a[-1] += 1;
    }
}

/** CLEARING BUFFER

    cout << VAL << flush;

    OR

    printf(VAL);
    fflush(stdout);
*/

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	int n, i, j, k, minn, id, s;
	cin >> n;
	vector<int> a(n); 
	s = 0;
	for (i = 0; i < n; i++) {
		cin >> a[i];
		s += a[i];
		a[i] *= n;
	}
	minn = s * 10;
	for (i = 0; i < n; i++) {
		if (abs(s - a[i]) < minn) {
			minn = abs(s - a[i]);
			id = i;
		}
	}

	cout << id << "\n";

	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> PL;
#define int ll

const ll MOD = 1000000007;
const ll INF_LL = (ll)1000000007 * 1000000007;
const int INF_INT = (int)1000000007;
const double PI = 3.14159265358979323846;

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define irep(itr, st) for (auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for (auto itr = (st).rbegin(); itr != (st).rend(); ++itr)

#define m0(x) memset((x), 0, sizeof((x)))
#define m1(x) memset((x), -1, sizeof((x)))

// xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end()  // sortなどの引数を省略したい
#define RALL(x) (x).rbegin(), (x).rend()  // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())     // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))  //最大値を求める
#define MIN(x) *min_element(ALL(x))  //最小値を求める
#define all(x) (x).begin(), (x).end()

//略記
#define pb emplace_back  // vectorヘの挿入
#define mp make_pair     // pairのコンストラクタ
#define F first          // pairの一つ目の要素
#define S second         // pairの二つ目の要素

#define BITCOUNT __builtin_popcount
#define BITCOUNT_LL(x) __builtin_popcountll(x)

#define perm(c)             \
  sort(all(c));             \
  for (bool c##p = 1; c##p; \
       c##p = next_permutation(all(c)))  //順列 123 132 213 231 312 321

#define BIT(n) (1LL << (n))

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ": " << (A) << std::endl;
#else
#define PRINT(A)
#endif

//入力高速化
struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

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

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

signed main() {
  int n,m,d; cin >> n >> m >> d;

  // 5 3 1  (m-1)*((n-d*2)*2  + d*2)/m^n
  double ans = ((n-2*d)*2 + (d*2))*(m-1);
  ans = ans / n / n;
  if(d == 0){
    ans = 1.0/n*(m-1);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int Maxn = 100010;

//vector<ll> prime_numbers;
vector<bool> prime_table(ll n){
    vector<bool> res(n + 1, true);
    res[0] = res[1] = false;
    for (ll i = 2LL; i <= n; i++){
        if (res[i]){
            //prime_numbers.push_back(i);
            for (ll j = 2LL * i; j <= n; j+= i) res[j] = false;
        }
    }
    return res;
}

template<typename T> class CumulativeSum{
    public:
        vector<T> sum;

        CumulativeSum(int n);
        void add(int i, T x);
        void build();
        T get(int i);
};

template<typename T> CumulativeSum<T>::CumulativeSum(int n){
    sum = vector<T>(n, 0);
}

template<typename T> void CumulativeSum<T>::add(int i, T x){
    sum[i] += x;
}

template<typename T> void CumulativeSum<T>::build(){
    for (int i = 1; i < sum.size(); i++) sum[i] += sum[i - 1];
}

template<typename T> T CumulativeSum<T>::get(int i){
    if (i < 0) return 0;
    return sum[min(i, (int)sum.size() - 1)];
}


int main(){
    vector<bool> is_prime = prime_table(Maxn);
    CumulativeSum<ll> cs(Maxn);
    for (int i = 3; i < Maxn; i++){
        if (is_prime[i] && is_prime[(i + 1) / 2]){
            cs.add(i, 1);
        }
    }

    cs.build();

    int q;
    cin >> q;
    while(q--){
        int l, r;
        cin >> l >> r;
        cout << cs.get(r) - cs.get(l - 1) << endl;
    }

    return 0;
}

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

int main(){
	int n,m;
	cin>>n>>m;
	int l,r,tl,tr;
	l=0;
	r=n-1;
	for (int i = 0; i < m; i++) {
		cin>>tl>>tr;
		l=max(l,tl-1);
		r=min(r,tr-1);
	}
	cout<<max(0,r-l+1);
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define LEN 100005

// プロセスを表す構造体
typedef struct pp {
	char name[100];
	int t;
} P;

P Q[LEN];
int head, tail, n;

void enqueue(P x) {
	Q[tail] = x;
	tail = (tail + 1) % LEN;
}

P dequeue() {
	P x = Q[head];
	head = (head + 1) % LEN;
	return x;
}

// 小さいほうの値を返す
int min(int a, int b) { return a < b ? a : b; }

int main() {
	int elaps = 0, c;
	int i, q;
	P u;
	scanf("%d %d", &n, &q);

	// 全プロセスを順番にキューに追加する	
	for (i = 1; i <= n; i++) {
		scanf("%s", Q[i].name);
		scanf("%d", &Q[i].t);
	}
	head = 1;
        tail = n + 1;

	// シミュレーション
	while (head != tail) {
		u = dequeue(); // 先頭プロセスを処理するためにデキューする
		c = min(q, u.t); // クォンタムか残り処理時間のどちらか小さい方をcに入れる
		u.t -= c; // 処理時間を引いて残り処理時間とする
		elaps += c; // 経過時間を加算
		if (u.t > 0) {
			enqueue(u); // 処理時間がまだ残っていればキュー末尾に追加する
		}
		else {
			printf("%s %d\n", u.name, elaps);
		}
	}

	return 0;
}


Measured memory_bytes: 12732
from collections import deque

n,x = map(int,input().split())

l = deque(list(map(int,input().split())))
count = 0

if sum(l) <= x:
    print(n+1)
else:
    while count <= x:
        count += l.popleft()
        if len(l) == 0:
            break

    print(n-len(l))

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

class DisSet{
	public :
		vector<int>rank,p;
		DisSet(){
		};
		
		DisSet(int size){
			rank.resize(size,0);
			p.resize(size,0);
			for(int i=0;i<size;i++){
				makeset(i);
			}
		}
		
		void makeset(int x){
			p[x] = x;
			rank[x] = 0;
		}
		
		bool same(int x,int y){
			return findset(x)==findset(y);
		}
		
		void link(int x,int y){
			if(rank[x]>rank[y]){
				p[y] = x;
			}else {
				p[x] = y;
				if(rank[x]==rank[y]){
					rank[y]++;
				}
			}
		}
		
		void unit(int x,int y){
			link(findset(x),findset(y));
		}
		
		int findset(int x){
		if(x!=p[x]){
			p[x] = findset(p[x]);
		}
		return p[x];
		}

};


int main(){
	int n,q,c,t,v;
	
	cin>>n>>q;
	
	DisSet ds = DisSet(n);
	
	for(int i=0;i<q;i++){
		cin>>c>>t>>v;
		if(c==0) ds.unit(t,v);
		else if(c==1){
			if(ds.same(t,v)) cout<<1<<endl;
			else cout<<0<<endl; 
		}
	}
	
	return 0;
}

Measured memory_bytes: 3204
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define LOWER(a,x) lower_bound(ALL(a), x) - a.begin() - 1;
#define COUNT(a,x)  upper_bound(ALL(a), x) - lower_bound(ALL(a), x);
#define MCOUNT(a,x,y) upper_bound(ALL(a), y) - lower_bound(ALL(a), x);
#define SCAN(x) scanf("%lld",&x);
#define INF 5555555555555555555
#define MOD 1000000007
#define pb push_back
#define F first
#define S second
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef map<ll, ll> MAP;
typedef set<ll> SET;
ll n = 0, m = 0, ans = 0, sum = 0, cnt = 0, tmp = 0, ma = 0, mi = 0;
string s;
bool flag, ok;
ll dx[4] = { 1,-1,0,0 }, dy[4] = { 0,0,1,-1 };
ll ddx[9] = { 1,-1,0,0,1,1,-1,-1,0 }, ddy[9] = { 0,0,1,-1,1,-1,1,-1,0 };
#pragma endregion
#define MAX 111111



int main(void) {
  ll a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  ll ans = llabs(a - b);
  ll dif = llabs(d - c);
  ok = false;
  for (ll i = 0;i < n;i += 2) {
	cnt = i >> 1;
	mi = c * (n - 1 - i) - dif * cnt;
	mi = max(mi, 0LL);
	ma = d * (n - 1 - i) + dif * cnt;
	if (ans >= mi && ans <= ma) {
	  ok = true;
	  break;
	}
  }

  if (ok) {
	cout << "YES" << endl;
  }
  else {
	cout << "NO" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		new Main().execute();
	}
	
	private void execute() {
		Scanner sc = new Scanner(System.in);
		final int N = sc.nextInt();
		
		
		if(N==1) {
			System.out.println("Hello World");
		}
		else if (N==2) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			System.out.println(a+b);
		}
		
	}
	
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
//void IO(){
//	#ifndef ONLINE_JUDGE
//	    freopen("input.txt", "r", stdin);
//	    freopen("output.txt", "w", stdout);
//	#endif
//}
// end of Template

int a,b,c,k;
priority_queue<int> q;
int main(){
	//IO();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>a>>b>>c;
    cin>>k;
    q.push(a);
    q.push(b);
    q.push(c);
    for(int i=1;i<=k;i++){
        int t = q.top();
        t*=2;
        q.pop();
        q.push(t);
    }
    int ans=0;
    while(!q.empty()){
        ans+=q.top();
        q.pop();
    }
    cout<<ans<<newl;

}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
    long long int n,i,j,k,ans;
    scanf("%lld", &n);
    k=sqrt(n);
    //printf("k=%lld\n", k);
    ans=n;
    for(i=1;i<=k;i++){
        if(n%i==0){
        j=n/i;
        ans=(ans<=i+j-2)?ans:i+j-2;
        //printf("%lld\n", i);
        //printf("%lld\n", j);
        //printf("%lld\n", ans);
        }
    }
    printf("%lld", ans);


}


Measured memory_bytes: 128
import sys
s = input()
def hitachi(s):
  n = len(s)
  if n % 2 != 0:
    return False
  for i in range(0, n, 2):
      if s[i] != 'h' or s[i + 1] != 'i':
          return False
  return True

if hitachi(s):
  print('Yes')
else:
  print('No')


Measured memory_bytes: 2940
/**
 *    author:  morato
 *    created: 06.09.2020 23:31:33
**/
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 5;

vector<int> adj[N];
map<pair<int, int>, int> cor;
int maior;

void dfs(int v, int p = -1, int cor_pai = -1) {
  cor[{p, v}] = cor_pai;
  int cur = 1;
  for (int u : adj[v]) if (u != p) { 
    if (cur == cor_pai) cur++;
    if (cur > maior) cur = 1;
    dfs(u, v, cur);
    cur++;
  }  
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> grau(n), a(n), b(n);
  for (int i = 0; i < n - 1; i++) {
    cin >> a[i] >> b[i];
    a[i]--, b[i]--;
    adj[a[i]].push_back(b[i]);
    adj[b[i]].push_back(a[i]);
    grau[a[i]]++;
    grau[b[i]]++;
  }
  maior = *max_element(grau.begin(), grau.end());
  cout << maior << '\n';
  dfs(0);
  for (int i = 0; i < n - 1; i++) {
    cout << cor[{a[i], b[i]}] << '\n';
  }
  return 0;
}

Measured memory_bytes: 18004
#include <bits/stdc++.h>
#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long

using namespace std;

const int MOD = 1000000007;

int main() {
  ll a, b, k;
  scanf("%lld %lld %lld", &a, &b, &k);

  if (a < k) {
    k = k - a;
    a = 0;

    if (b > k) {
      b = b - k;
    } else {
      b = 0;
    }
  } else {
    a = a - k;
  }

  cout << a << " " << b << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define cool ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) 
#define ll long long
#define MAX 1000001
int prime_no[MAX];
int g=0; 
void SieveOfEratosthenes(int n) 
{ 
    bool prime[MAX]; 
    memset(prime, true, sizeof(prime)); 
    for (int p=2; p*p<=n; p++){ 
        if (prime[p] == true){ 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
    for (int p=2; p<=n; p++){
        if (prime[p]) {
       		prime_no[g]=p;
       		g++;
	   }	
	} 
}
void solve(){
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
	cin>>a[i];
	int b[n];
	b[0]=a[0];
	b[1]=abs(a[1]-a[0]);
	b[2]=min((abs(a[2]-a[0])),(abs(a[2]-a[1])+b[1]));
	for(int i=3;i<n;i++){
		b[i]=min((abs(a[i]-a[i-2])+b[i-2]),(abs(a[i]-a[i-1])+b[i-1]));
	}
	cout<<b[n-1];	
} 
int main()
{ 
    cool;
    int t;
    //cin>>t;
    t=1;
    while(t--){
    	solve();
	}
    return 0;
}


Measured memory_bytes: 1024
n = int(input())
a = [int(input()) for _ in range(n)]

i = 0
count = 0
root = set()
while True:
    light = a[i]
    count += 1

    if i not in root:
        root.add(i)
    else:
        print(-1)
        break

    if light == 2:
        print(count)
        break

    i = light - 1

Measured memory_bytes: 15904
#include <bits/stdc++.h>
#define PI 3.1415926535897932
#define _GLIBCXX_DEBUG
using namespace std;
long long GCD(long long A,long long B){
  if(B==0){
    return A;
  }
  else{
    return GCD(B,A%B);
  }
}
int main() {
  
  string S,T;
  cin>>S>>T;
  
  int ans=10000;
  
  int count=0;
  
  
  for(int i=0;i<=S.size()-T.size();i++){
    string U=S.substr(i,T.size());
    for(int j=0;j<T.size();j++){
      if(U[j]!=T[j]){
        count++;
      }
    }
    
    ans=min(ans,count);
    count=0;
  }
  
  cout<<ans<<endl;
}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> P;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max()/2;
const int MOD = 1e9+7;

struct Edge{
    int from, to,cost;
    Edge(int from, int to,int cost): from(from), to(to), cost(cost){}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

bool operator < (const Edge &e, const Edge &f){
    return e.cost < f.cost;
}

struct UF {
	vector<int> data;
	UF(int size) : data(size, -1) { }
	bool unite(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool find(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
    void init(int size){
        for(int i=0;i<size;i++) data[i]=-1;
    }
};

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

    int n,m;cin>>n>>m;
    Edges es;
    for(int i=0;i<m;i++){
        int st,gt,cost;
        cin>>st>>gt>>cost;st--;gt--;
        es.push_back(Edge(st,gt,cost));
    }
    sort(es.begin(),es.end());
    UF uf(n);
    int mcost=0;
    Edges used;
    for(int i=0;i<m;i++){
        Edge e=es[i];
        if(!uf.find(e.from,e.to)){
            mcost+=e.cost;
            uf.unite(e.from,e.to);
            used.push_back(e);
        }
    }
    int res=0,sum=0;
    for(int i=0;i<n-1;i++){
        uf.init(n);
        int tmp=0;
        for(int j=0;j<m;j++){
            Edge e=es[j];
            if(e.from==used[i].from && e.to==used[i].to) continue;
            if(!uf.find(e.from,e.to)){
                tmp+=e.cost;
                uf.unite(e.from,e.to);
            }
        }
        if(mcost!=tmp){
            res++;
            sum+=used[i].cost;
        }
    }
    cout<<res<<" "<<sum<<endl;
}


Measured memory_bytes: 3832