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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int N, M, R; scanf("%d %d %d", &N, &M, &R);
  vector<int> C(R);
  for (int i = 0; i < R; ++i) {
    scanf("%d", &C[i]);
  }

  vector<vector<int>> dist(N + 5, vector<int>(N + 5, INF));
  int a, b, c;
  for (int i = 0; i < M; ++i) {
    scanf("%d %d %d", &a, &b, &c);
    dist[a][b] = dist[b][a] = c;
  }
  for (int i = 1; i <= N; ++i) { dist[i][i] = 0; }
  for (int k = 1; k <= N; ++k) {
    for (int i = 1; i <= N; ++i) {
      for (int j = 1; j <= N; ++j) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }

  sort(C.begin(), C.end());
  int ans = INF;
  do {
    int d = 0;
    for (int i = 1; i < R; ++i) {
      d += dist[C[i - 1]][C[i]];
    }
    ans = min(ans, d);
  } while (next_permutation(C.begin(), C.end()));

  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 384
//
//AtCoder Beginner Contest 161
//A - ABC Swap
//

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define zero(a) memset(a, 0, sizeof(a))

using ll = long long;

int main()
{
    int x, y, z;

    cin >> x >> y >> z;

    int tmp = x;
    x = y;
    y = tmp;

    tmp = x;
    x = z;
    z = tmp;

    cout << x << " " << y << " " << z << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

ll dp[100005][3];

int main(){
  int N;
  cin >> N;
  vector<vector<int>> v;
  rep(i,N){
    int a, b, c;
    cin >> a >> b >> c;
    v.push_back({a,b,c});
  }

  dp[0][0] = v[0][0];
  dp[0][1] = v[0][1];
  dp[0][2] = v[0][2];

  REP(i,1,N){
    dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + v[i][0];
    dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + v[i][1];
    dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + v[i][2];
  }

  cout << max(dp[N-1][0], max(dp[N-1][1], dp[N-1][2])) << endl;
  
  return 0;
}


Measured memory_bytes: 8368
#include <bits/stdc++.h>
#include <iostream>
#include <utility>
#include <algorithm>
#include <numeric>
#define load ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
#define ll long long
#define ull unsigned long long
#define fori(i,n) for (int i=0; i<int(n);i++)
#define srt(v) sort(v.begin(), v.end())
#define MOD 1000000007
const int INF = 1e9;
const double PI = 3.14159265358979323846;

ll gcd(ll a, ll b) {
    return b != 0 ? gcd(b, a % b) : a;
}
 
ll lcm(ll a, ll b) {
    return (a * b) / gcd(a, b);
}

void solve(){

}

int main(){
	load;
    int n;
    cin >> n;
    vector<int> v(n);
    int ans = 0;
    fori(i,n){
    	cin >> v[i];
    	ans ^= v[i];
    }
    fori(i,n){
    	cout << (ans^v[i]) << " ";
    }
    cout << "\n";
	return 0;
}



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

vector<P>E[100000];
int d[100000],b[100000],cnt[200001],u[200000],v[200000],r[200000];
int main(){
	int n,m,q;scanf("%d%d%d",&n,&m,&q);
	rep(i,m){
		scanf("%d%d",&u[i],&v[i]);u[i]--;v[i]--;r[i]=q;
	}
	rep(i,q){
		int a;scanf("%d",&a);r[a-1]=i;
	}
	rep(i,m){
		E[u[i]].push_back(P(v[i],r[i]));E[v[i]].push_back(P(u[i],r[i]));
	}
	d[0]=1;b[0]=q;
	queue<int>que;que.push(0);
	while(!que.empty()){
		int p=que.front();que.pop();
		rep(i,E[p].size()){
			P v=E[p][i];
			if(d[v.first]==0){
				d[v.first]=d[p]+1;que.push(v.first);
			}
			if(d[v.first]==d[p]+1)
				b[v.first]=max(b[v.first],min(b[p],v.second));
		}
	}
	rep(i,n)cnt[b[i]]++;
	int ans=0;
	rep(i,q){
		ans+=cnt[i];
		printf("%d\n",ans);
	}
}

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

#pragma GCC optimize("O3")

using namespace std;

#define MAXN 105

#define FOR(i, n) for (int i = 0; i < n; i++)
#define FORR(j, i, n) for (int i = j; i < n; i++)
#define FORD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOBIR(i, n) for (int i = 1; i <= n; i++)
#define pb push_back
#define mp make_pair
#define endl '\n'
#define DUEHOANG                  \
	ios_base::sync_with_stdio(0); \
	cin.tie(NULL);                \
	cout.tie(NULL)

#define JaydenXia(in, out) \
	freopen(in, "r", stdin); \
	freopen(out, "w", stdout);

#define ll long long

typedef set<int> si;
typedef vector<int> vi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef priority_queue<int> pqi;
typedef stack<int> sti;
typedef queue<int> qi;
typedef deque<int> di;
typedef map<int, int> mii;
#define f first
#define s second
#define EPS 1e-9

int n;
pii psum[MAXN];
pii a[MAXN];

bool ang(pii p, pii q)
{
    return atan2(p.f, p.s) < atan2(q.f, q.s);
}

int main()
{
    cin >> n;
    FOR(i, n)
    {
        cin >> a[i].f >> a[i].s;
    }
    sort(a, a+n, ang);
    // FOR(i, n) cout << a[i].f << " " << a[i].s << " a" << endl;
    
    
    ll ans = 0;
    FOR(i, n)
    {
        ll x = 0;
        ll y = 0;
        FOR(j, n)
        {
            x += a[(i+j)%n].f;
            y += a[(i+j)%n].s;
            // cout << x << " " << y << endl;
            ans = max(ans, x*x+y*y);
        }
    }
    cout << setprecision(25) << fixed << sqrt(ans) << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<ctime>
using namespace std;
int main(){
	int x, y;
	while(~scanf("%X %X", &x, &y)){
	if(x < y)
		printf("<\n");
	else if(x > y)
		printf(">\n");
	else
		printf("=\n");
	}
}

Measured memory_bytes: 128
import java.util.*;
import java.io.*;

public class Main 
{ 

	 static FastReader sc=new FastReader(); 
	  public static void main(String[] args) 
    {
        int d=i();
    	int t = i(); 
        int s=i();
        int res=t*s;
        if(res>=d){
            System.out.println("Yes");
        }
        else
        System.out.println("No");
        	
        	
			
	
	}    	
    	
   static void input(int A[]) {
	   for(int i=0;i<A.length;i++) {
		   A[i]=sc.nextInt();
	   }
   }
     static int i() {
    	 return sc.nextInt();
     }
     static String s() {
    	 return sc.next();
     }
     static long l() {
    	 return sc.nextLong();
     }
     public static String rev(String str){  
    	    char ch[]=str.toCharArray();  
    	    String rev="";  
    	    for(int i=ch.length-1;i>=0;i--){  
    	        rev+=ch[i];  
    	    }  
    	    return rev;  
    	}  
        static void shuffleArray(int[] arr){
        int n = arr.length;
        Random rnd = new Random();
        for(int i=0; i<n; ++i){
            int tmp = arr[i];
            int randomPos = i + rnd.nextInt(n-i);
            arr[i] = arr[randomPos];
            arr[randomPos] = tmp;
        }   
}
  
        
        
    static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
} 






Measured memory_bytes: 25344
#include<iostream>                                        
#include<cmath>                                           
#include<cstdio>                                          
using namespace std;                                      
                                                          
int main(){                                               
  int n;                                                  
  int x[100];                                             
  int y[100];                                             
  double p1 = 0;                                          
  double p2 = 0;                                          
  double p3 = 0;                                          
  double pInf = 0;                                        
  int absDiff = 0;                                        
                                                          
  cin >> n;                                               
  for(int i=0;i<n;i++) cin >> x[i];                       
  for(int i=0;i<n;i++) cin >> y[i];                       
                                                          
  for(int i=0;i<n;i++){                                   
    absDiff = abs(x[i]-y[i]);                             
    p1 += absDiff;                                        
    p2 += absDiff * absDiff;                              
    p3 += absDiff * absDiff * absDiff;                    
    if(pInf < absDiff) pInf = absDiff;                    
  }                                                       
                                                          
  printf("%lf\n",p1);                                     
  printf("%lf\n",sqrt(p2));                               
  printf("%lf\n",cbrt(p3));                               
  printf("%lf\n",pInf);                                   
                                                          
  return 0;                                               
}

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

int main(){
  char C[2][3];
  for(int i=0; i<2; i++){
    for(int j=0; j<3; j++) cin >> C[i][j];
  }
  int cnt=0;
  for(int i=0; i<2; i++){
    for(int j=0; j<3; j++){
      if(C[i][j]==C[1-i][2-j]) cnt++;
    }
  }
  if(cnt==6) cout <<"YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  for(int i=0;i<100;i++)
  {
    for(int j=0;j<100;j++)
    {
      if(4*i+7*j==N) 
      {
        cout << "Yes" << endl; 
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


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

int dp[100000];
int main(){
    int N;cin>>N;
    vector<int> a(N);
    for(int i=0;i<N;i++)cin>>a.at(i);
    dp[1]=abs(a.at(1)-a.at(0));
    for(int i=2;i<N;i++)
        dp[i]=min(dp[i-2]+abs(a.at(i)-a.at(i-2)),dp[i-1]+abs(a.at(i)-a.at(i-1)));

    cout<<dp[N-1]<<endl;

    return 0;
}

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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

/*
 */

using vi = vector<int>;
using vvi = vector<vi>;
using P = pair<int,int>;

const int inf = 1LL<<60;

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

  vi rr(r);
  rep(i, 0, r){
    cin >> rr[i];
    rr[i]--;
  }

  vvi dist(n, vi(n, inf));
  rep(i, 0, n) dist[i][i] = 0;

  rep(i, 0, m){
    int a, b, c;
    cin >> a >> b >> c;
    dist[a-1][b-1] = dist[b-1][a-1] = c;
  }

  rep(k, 0, n) rep(i, 0, n) rep(j, 0, n){
    chmin(dist[i][j], dist[i][k]+dist[k][j]);
  }

  vi p(r);
  iota(all(p), 0);

  int ans = inf;
  do{
    int tmp = 0;
    rep(i, 1, r) tmp += dist[rr[p[i-1]]][rr[p[i]]];
    chmin(ans, tmp);
  }while(next_permutation(all(p)));

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 512
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define mod 1000000007
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define ll long long int 
#define PI 3.1415926535897932384626

using namespace std;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	string s;
	cin>>s;
	string temp="";
	for(int i=0;i<s.length();i++)
	{
	     if((int)(s[i]+n)>=91)
	     {
	          int r=(int)s[i]-26+n;
	          char ch=r;
	          temp+=ch;
	     }
	     else
	     {
	          int r=(int)s[i]+n;
	          char ch=r;
	          temp+=ch;
	     }
	}
	cout<<temp;
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
#define max 100005
using ll =long long;
using namespace std;

int num[3]={7,5,3};
ll n,ans=0;

int degit(ll num){
    int s=1;
    while((num/10)!=0){
        num/=10;
        s++;
    }
    return s;
}

void dfs(vector<int> &A ){
    if(A.size()==degit(n)+1)return;
    int flg1=0,flg2=0,flg3=0;
    ll m=0;
    rep(i,A.size()){
        m+=A[i]*pow(10,i);
        if(A[i]==3)flg1=1;
        if(A[i]==5)flg2=1;
        if(A[i]==7)flg3=1;
    }
    if(flg1==1&&flg2==1&&flg3==1&&m<=n)ans++;

    for(int i=0;i<3;i++){
        A.push_back(num[i]);
        dfs(A);
        A.pop_back();
    }
}
int main(){
    cin>>n;
    vector<int> A;
    dfs(A);
    cout<<ans<<endl;
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  
  vector<int> a(N);
  for (int i = 0; i < N; i++)
    cin >> a.at(i);
  
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  
  int A = 0;
  for (int j = 0; j < N; j += 2)
    A += a.at(j);
  
  int B = 0;
  for (int k = 1; k < N; k += 2)
    B += a.at(k);
  
  cout << A - B << endl;
}

Measured memory_bytes: 3600
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
#define fst first
#define snd second
using ll = long long;
using I = pair<int, int>;
 
int main() {
  int a, b, c;
  while (cin >> a >> b >> c) {
    set<int> s = {a, b, c};
    cout << s.size() << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
	
ll mod = 1e9 + 7;
 
int main(){
    ll n; cin >> n;
    string ans = "";
    while(n > 0){
        n--;
        char tmp = (n % 26) + 'a';
        n /= 26;
        ans += tmp;
    }
    reverse(ans.begin(), ans.end());
    cout << ans;
    
    return 0;
}


Measured memory_bytes: 3648
N = input()
nums = ['3', '5', '7']
for i in range(len(N)):
  for num in nums:
    if(len(num) == i):
      nums.append(num + '3')
      nums.append(num + '5')
      nums.append(num + '7')
cnt = 0
for num in nums:
  if(int(num) <= int(N) and '3' in num and '5' in num and '7' in num):
    cnt += 1
print(cnt)

Measured memory_bytes: 5156
#define _DEBUG
#include "bits/stdc++.h"
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
pair<vll,vll > prime_factor_decomp(ll n) {
    vll p, e;
    ll m = n;
    for (ll i = 2; i * i <= n; i++) {
        if (m % i != 0) continue;
        int c = 0;
        while (m % i == 0) c++, m /= i;
        p.push_back(i);
        e.push_back(c);
    }
    if (m > 1) {
        p.push_back(m);
        e.push_back(1);
    }
    return mp(p, e);
}
int main(){
	ll N;
	scan(N);
	if(N==1){
		prin(0);
		return 0;
	}
	pair<vll,vll > pe=prime_factor_decomp(N);
	vll e=pe.second;
	int ans=0;
	rep(i,e.size()){
		ll num=e[i];
		rep1(i,INF){
			if(num<i) break;
			num-=i;
			ans++;
		}
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
 
typedef vector<int> vi;;
typedef vector<ll> vll;

#define l() length()
#define sz() size()
 
#define b() begin()
#define e() end()
#define all(x) x.begin(), x.end()
 
#define pb(i) push_back(i)
#define PB() pop_back()
 
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
#define mp make_pair
#define Fi first
#define Se second
 
const int maxx=1e6+9;
 
// Happy Coding!

// 1 way is to find compute all the sorted permutations and find the 
// positions of the current permutation.

bool _find(string &str,int a,int b){
    int l=str.l();
    if(l!=a+b+1){return false;}
    if(l<a+1){return false;}
    if(str[a]!='-'){return false;}
    for(int i=0;i<str.l();i++){
        if(i==a){continue;}
        if(!isdigit(str[i])){
            return false;
        }
    }
    return 1;
}
void solve(){
    int a,b;
    cin>>a>>b;
    string str;
    cin>>str;
    cout<<(_find(str,a,b)?"Yes":"No")<<endl;
}

int main() {
    faster;
    int t=1;
    // cin>>t;
    while(t-->0){
        solve();
    }
	return 0;
}

Measured memory_bytes: 3628
Module Module1

    Sub Main()

        Dim al(8) As Integer

        For i As Integer = 0 To 2
            Dim tmp As String() = Split(Console.ReadLine(), " ")
            For j As Integer = 0 To 2
                al((3 * i) + j) = CInt(tmp(j))
            Next
        Next

        Dim N As Integer = CInt(Console.ReadLine())
        For i As Integer = 0 To N - 1
            Dim b As Integer = CInt(Console.ReadLine())
            For c As Integer = 0 To 8
                If al(c) = b Then
                    al(c) = 0
                    Exit For
                End If
            Next
        Next

        If al(0) + al(1) + al(2) = 0 OrElse al(3) + al(4) + al(5) = 0 OrElse al(6) + al(7) + al(8) = 0 OrElse al(0) + al(3) + al(6) = 0 OrElse al(1) + al(4) + al(7) = 0 OrElse al(2) + al(5) + al(8) = 0 OrElse al(0) + al(4) + al(8) = 0 OrElse al(2) + al(4) + al(6) = 0 Then
            Console.WriteLine("Yes")
        Else
            Console.WriteLine("No")
        End If

    End Sub

End Module


Measured memory_bytes: 13532
n,k=map(int,input().split())
l=[int(i) for i in input().split()]
right=[i for i in l if i>0]
left=[i for i in l if i<=0]
if not left: 
    sm=0 
    sm+=l[0]
    for i in range(1,k):
        sm+=(l[i]-l[i-1])
    print(sm)
    exit()
if not right: 
    sm=0 
    l=[abs(i) for i in l]
    l.sort()
    sm=l[0]
    for i in range(1,k):
        sm+=(l[i]-l[i-1])
    print(sm)
    exit()
le=len(left)
ri=len(right)
rl=[0]*le 
rr=[0]*ri 
left=[abs(i) for i in left]
left=left[::-1]
rl[0]=left[0]
for i in range(1,le):
    rl[i]=rl[i-1]+(left[i]-left[i-1])
rr[0]=right[0]
mini=10**20 
for i in range(1,ri) :
    rr[i]=rr[i-1]+(right[i]-right[i-1])
if len(left)>=k:
    mini=min(mini,rl[k-1])
if len(right)>=k:
    mini=min(mini,rr[k-1])
#print(left,right,rl,rr)
for a in range(1,len(left)+1):
    b=k-a 
    #print(a,b)
    if b>len(rr):
        #print('hsef')
        continue 
    mini=min(mini,2*rl[a-1]+rr[b-1],rl[a-1]+2*rr[b-1])
print(mini)

Measured memory_bytes: 14360
N,T = map(int,input().split())
data = [0] * N

M = 0
for i in range(N):
    data[i] = list(map(int,input().split()))
    M = max(M,data[i][0])

dp1 = [[0]*T for i in range(N)]

for j in range(T):
    if j < data[0][0]:
        dp1[0][j] = 0
    else:
        dp1[0][j] = data[0][1]

for j in range(T):
    for i in range(1,N):
        if data[i][0] <= j:
            dp1[i][j] = max(dp1[i-1][j],dp1[i-1][j-data[i][0]]+data[i][1])
        else:
            dp1[i][j] = dp1[i-1][j]

dp2 = [[0]*T for i in range(N)]

for j in range(T):
    if j < data[N-1][0]:
        dp2[N-i][j] = 0
    else:
        dp2[N-1][j] = data[N-1][1]

for j in range(T):
    for i in range(N-2,-1,-1):
        if data[i][0] <= j:
            dp2[i][j] = max(dp2[i+1][j],dp2[i+1][j-data[i][0]]+data[i][1])
        else:
            dp2[i][j] = dp2[i+1][j]

m = 0

for j in range(T):
    for i in range(N):
        if i == 0:
            m = max(m,dp2[i+1][T-1-j] + data[i][1])
        elif i == N-1:
            m = max(m,dp1[i-1][j] + data[i][1])
        else:
            m = max(m,dp1[i-1][j] + dp2[i+1][T-1-j] + data[i][1])

print(m)

Measured memory_bytes: 179588
#include <iostream>
#include <vector>
#include <string>
#include <iomanip>
#include <math.h>
#include <cmath>
#include <map>
#include <algorithm>
#include <functional>


int main()
{
	std::vector<std::vector<int>>A(3, std::vector<int>(3, 0));
	std::string ans = "No";

	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			std::cin >> A[i][j];
		}
	}

	int N = 0;
	std::cin >> N;

	std::vector<int>B(N);
	for (int i = 0; i < N; i++)
	{
		std::cin >> B[i];
		for (int ik = 0; ik < 3; ik++)
		{
			for (int jk = 0; jk < 3; jk++)
			{
				if (A[ik][jk] == B[i])
				{
					A[ik][jk] = -1;
				}
			}
		}
	}

	for (int i = 0; i < 3; i++)
	{
		int a = 0;
		for (int j = 0; j < 3; j++)
		{
			a +=A[i][j];
		}
		if (a == -3){
			ans = "Yes";
			std::cout << ans << std::endl;
			return 0;
		}
	}


	for (int i = 0; i < 3; i++)
	{
		int a = 0;
		for (int j = 0; j < 3; j++)
		{
			a += A[j][i];
		}
		if (a == -3){
			ans = "Yes";
			std::cout << ans << std::endl;
			return 0;
		}
	}

	int a = 0;
	for (int i = 0; i < 3; i++)
	{
		int j = i;
		a += A[i][j];
		if (a == -3){
			ans = "Yes";
			std::cout << ans << std::endl;
			return 0;
		}
	}
	a = 0;
	for (int i = 0; i < 3; i++)
	{
		int j = 2 - i;
		a += A[i][j];
		if (a == -3){
			ans = "Yes";
			std::cout << ans << std::endl;
			return 0;
		}
	}

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


Measured memory_bytes: 256
#include<iostream>
#include<cstdint>

int64_t T1, T2, V1, V2;

int main() {
  int64_t A1, A2, B1, B2; std::cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2;
  V1 = A1-B1; V2 = A2-B2;
  if(V1 < 0) { V1 = -V1; V2 = -V2; }
  int64_t dm = V1*T1, d = dm + V2*T2;
  if(d > 0) { std::cout << "0" << std::endl; return 0; }
  if(d == 0) { std::cout << "infinity" << std::endl; return 0; }
  int64_t ans = 1;
  int64_t r = (dm-1)/(-d);
  ans += r*2;
  if(dm%(-d)==0) ++ans;
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 256
import sys
from io import StringIO
import unittest

def resolve():
    N,M = list(map(int, input().split(' ')))
    K = [-1] * N
    for i in range(M):
        s, c = list(map(int, input().split(' ')))
        if K[s-1] != -1 and K[s-1] != c:
            print('-1')
            return
        K[s-1] = c
    if N > 1 and K[0] == 0:
        print('-1')
        return
    ans = ""
    if N==1:
        X = max(0, K[0])
        print(max(0, K[0]))
        return

    for i in range(N):
        if i==0 and K[i]==-1:
            ans += '1'
        elif K[i] == -1:
            ans += '0'
        else:
            ans += str(K[i])
    print(ans)

resolve()

Measured memory_bytes: 51564
#include <bits/stdc++.h>
using namespace std;
int main() {
    
    int h[2],k[2],a,b,c,d,hsum,ksum;
    
    for(int i = 0; i < 2; i++){
        cin>>h[i];
    }
    for(int i = 0; i < 2; i++){
        cin>>k[i];
    }
    cin>>a>>b>>c>>d;
   
   hsum = a * h[0] + b * h[1];
   ksum = a * k[0] + b * k[1];
   
   if(h[0] >= 10){
       int n = h[0] / 10;
       hsum = hsum + n*c;
   }
     if(h[1] >= 20){
       int v = h[1] / 20;
       hsum = hsum + v*d;
   }
   
   if(k[0] >= 10){
       int x = k[0] / 10;
       ksum = ksum + x*c;
   }
  
   if(k[1] >= 20){
       int y = k[1] / 20;
       ksum = ksum + y*d;
   }
   
   if(ksum < hsum){
       cout << "hiroshi" << endl;
   }
   else if(ksum > hsum){
       cout << "kenjiro" << endl;
   }
   else 
   cout <<"even" <<endl;
}


Measured memory_bytes: 3096
//---------- begin union_find ----------
pub struct DSU {
    p: Vec<i32>,
}
impl DSU {
    pub fn new(n: usize) -> DSU {
        DSU { p: vec![-1; n] }
    }
    pub fn init(&mut self) {
        for p in self.p.iter_mut() {
            *p = -1;
        }
    }
    pub fn root(&self, mut x: usize) -> usize {
        assert!(x < self.p.len());
        while self.p[x] >= 0 {
            x = self.p[x] as usize;
        }
        x
    }
    pub fn same(&self, x: usize, y: usize) -> bool {
        assert!(x < self.p.len());
        assert!(y < self.p.len());
        self.root(x) == self.root(y)
    }
    pub fn unite(&mut self, x: usize, y: usize) -> Option<(usize, usize)> {
        assert!(x < self.p.len());
        assert!(y < self.p.len());
        let mut x = self.root(x);
        let mut y = self.root(y);
        if x == y {
            return None;
        }
        if self.p[x] > self.p[y] {
            std::mem::swap(&mut x, &mut y);
        }
        self.p[x] += self.p[y];
        self.p[y] = x as i32;
        Some((x, y))
    }
    pub fn parent(&self, x: usize) -> Option<usize> {
        assert!(x < self.p.len());
        let p = self.p[x];
        if p >= 0 {
            Some(p as usize)
        } else {
            None
        }
    }
    pub fn size(&self, x: usize) -> usize {
        assert!(x < self.p.len());
        let r = self.root(x);
        (-self.p[r]) as usize
    }
}
//---------- end union_find ----------

use proconio::*;

#[fastout]
fn run() {
    input! {
        n: usize,
        q: usize,
    }
    let mut u = DSU::new(n);
    for _ in 0..q {
        input! {
            op: u8,
            a: usize,
            b: usize,
        }
        if op == 0 {
            u.unite(a, b);
        } else {
            let ans = u.same(a, b) as u8;
            println!("{}", ans);
        }
    }
}

fn main() {
    run();
}


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

typedef long long  LL;
const int N=100010;
struct edge{int s,t,n;}e[2*N];
int n,m,len,h[N],s[N],col[N],fa[N],ufs[N],inC[N],a[N];
LL ans;

int find(int x){return ufs[x]==x?x:ufs[x]=find(ufs[x]);}

void dfs(int x,int f)
{
	col[x]=-col[f],s[x]=col[x],fa[x]=f;
	for (int i=h[x],y; y=e[i].t,i; i=e[i].n)
		if (y!=f)  dfs(y,x),s[x]+=s[y];
}

void work()
{
	scanf("%d %d",&n,&m);
	for (int i=1; i<=n; i++)  ufs[i]=i;
	int x=1,y;
	for (int i=1,u,v,tot=0; i<=m; i++)
		{
			scanf("%d %d",&u,&v);
			if (find(u)!=find(v))
				{
					e[++tot]=(edge){u,v,h[u]},h[u]=tot;
					e[++tot]=(edge){v,u,h[v]},h[v]=tot;
					ufs[find(u)]=find(v);
				}else  x=u,y=v;
		}
	col[0]=-1,dfs(x,0);
	if (m==n-1)
		{
			if (s[1])  puts("-1"),exit(0);
			for (int i=1; i<=n; i++)  ans+=fabs(s[i]);
		}else
		{
			for (int i=y; i; inC[i]=1,a[++len]=s[i],i=fa[i]);
			if (len&1)
				{
					if (s[x]&1)  puts("-1"),exit(0);
					for (int i=1; i<=n; i++)
						if (inC[i])  ans+=fabs(s[i]-s[x]/2);
						else  ans+=fabs(s[i]);
				}else
				{
					if (s[x])  puts("-1"),exit(0);
					sort(a+1,a+len+1);
					for (int i=1; i<=n; i++)
						if (inC[i])  ans+=fabs(s[i]-a[len/2]);
						else  ans+=fabs(s[i]);
				}
		}
	printf("%lld",ans);
}

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


Measured memory_bytes: 9984
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD;
	bool[long] set;
	foreach (i; 0..N)
	{
		auto d = RD;
		set[d] = true;
	}

	writeln(set.keys.length);
	stdout.flush();
	debug readln();
}

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

int main(){
  string s;
  int Q;
  cin >> s >> Q;
  int ssize = s.size();
  vector<char> S(ssize);
  for(int i=0; i<ssize; i++) S.at(i) = s.at(i);
  vector<int> T(Q), F(Q);
  vector<char> C(Q);
  int flag = 0;
  for(int i=0; i<Q; i++){
    cin >> T.at(i);
    if(T.at(i) == 2) cin >> F.at(i) >> C.at(i);
  }
  for(int i=0; i<Q; i++){
    if(T.at(i) == 1){
      if(flag == 0) flag = 1;
      else flag = 0;
    }
    else{
      if(F.at(i) == 1){
        if(flag == 0) S.insert(S.begin(), C.at(i));
        else S.push_back(C.at(i));
      }
      else{
        if(flag == 0) S.push_back(C.at(i));
        else S.insert(S.begin(), C.at(i));
      }
    }
  }
  
  if(flag == 1) reverse(S.begin(), S.end());
  
  int Ssize = S.size();
  for(int i=0; i<Ssize; i++) cout << S.at(i);
  cout << endl;
}

Measured memory_bytes: 2876
#include<bits/stdc++.h>
using namespace std;
const int N = 1e3+5;
typedef long long ll;
const int inf = 1e9;
int h,a;
int main(){
  cin>>h>>a;
  if(h%a == 0) cout<<h/a<<endl;
  else cout<<(h/a)+1<<endl;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <iostream> // cout, endl, cin
#include <iomanip>
#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
#include <math.h>
using namespace std;

int main() {
	vector<long long> num(3);
	long long K;
	for (int i = 0; i < 3; i++) {
		cin >> num.at(i);
	}
	sort(num.begin(), num.end());
	cin >> K;
	for (int i = 0; i < K; i++) {
		num.back() *= 2;
	}
	long long ans;
	ans = num.at(0) + num.at(1) + num.at(2);
	cout << ans << endl;
}

Measured memory_bytes: 3612
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

ll N, M;
vector<ll> A, D;
vector<pll> B;

int main() {
    cin >> N >> M;
    A.resize(N); for (auto& item : A) cin >> item;
    sort(A.begin(), A.end());
    for (auto i = 0; i < M; i++) {
        ll b, c; cin >> b >> c;
        B.emplace_back(make_pair(b, c));
    }
    sort(B.begin(), B.end(), [](pll a, pll b) { return a.second > b.second; });
    for (const auto& item : B) {
        if (D.size() >= N) {
            break;
        }
        for (ll i = 0; i < item.first; i++) {
            if (D.size() < N) {
                D.emplace_back(item.second);
            }
            else {
                break;
            }
        }
    }
    ll X = 0;
    for (auto i = 0; i < D.size(); i++) {
        if (D[i] > A[i]) X = i + 1;
    }
    for (auto i = 0; i < X; i++) {
        A[i] = D[i];
    }
    cout << accumulate(A.begin(), A.end(), 0ll) << endl;
    return 0;
}

Measured memory_bytes: 4464
#include <iostream>
#include <vector>
#include <deque>
#include <set>
#include <cmath>
#include <bits/stdc++.h>
#include <limits>

#define MOD 1000000007
//#define MOD 7

using namespace std;

int main(void){
    // Your code here!
    long long n, max_value = 0;
    long long cum_sum[2][101] = {{}};
    
    cin >> n;
    for(int i = 0; i < 2; i++){
        for(int j = 0; j < n; j++){
            long long temp;
            cin >> temp;
            cum_sum[i][j+1] = cum_sum[i][j] + temp;
        }
    }
    
    for(int i = 0; i < n; i++)
        max_value = max(max_value, cum_sum[0][i+1]+cum_sum[1][n]-cum_sum[1][i]);
        
    cout << max_value << endl;
    
    return 0;
}

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

using ll = long long;
using namespace std;
constexpr ll inf = 1e15;
constexpr ll mod = 1e9+7;

template<size_t N>
class ModTool {
    ll fac[N+1], finv[N+1], inv[N+1];

public:
    ModTool() {
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < N; i++) {
            fac[i] = fac[i-1] * i % mod;
            inv[i] = mod - inv[mod%i] * (mod / i) % mod;
            finv[i] = finv[i-1] * inv[i] % mod;
        }
    }

    ll com(int n, int k) {
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
    }

    ll perm(int n, int k) {
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
        return fac[n] * finv[k] % mod;
    }
};

ModTool<100010> mt;

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

    int N;
    cin>>N;
    vector<int> A(N+1);
    set<int> prev;
    int dup;
    for (int n = 0; n < N+1; n++) {
        cin>>A[n];
        if (prev.count(A[n]) > 0) dup = n;
        prev.insert(A[n]);
    }
    int first;
    for (int n = 0; n < dup; n++) {
        if (A[n] == A[dup]) {
            first = n;
            break;
        }
    }

    for (int k = 1; k <= N+1; k++) {
        ll ans = mt.com(N, k-1) - mt.com(N-dup+first, k-1);
        if (ans < 0) ans += mod;
        ans = (mt.com(N, k) + ans) % mod;
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 8704
import itertools
N = int(input())
P = int(''.join(input().split()))
Q = int(''.join(input().split()))
Ns = list(itertools.permutations([str(i) for i in range(1,N+1)], N))
NP = 0
NQ = 0
for ni in Ns:
  nii = int(''.join(ni))
  if nii < P:
    NP += 1
  if nii < Q:
    NQ += 1
print(abs(NP - NQ))

Measured memory_bytes: 8052
def main():
    n, m = map(int, input().split(" "))
    p = []
    ids = [0 for _ in range(m)]
    y = []
    rev_y = dict()
    p_order = [1 for _ in range(n + 1)]
    for i in range(m):
        pi, yi = map(int, input().split(" "))
        p.append(pi)
        y.append(yi)
        rev_y[yi] = i
    y.sort()
    for year in y:
        city_index = rev_y[year]
        prefecture_id = p[city_index]
        born_time = p_order[prefecture_id]
        ids[city_index] = born_time
        p_order[prefecture_id] += 1
    for i in range(m):
        print("%s%s" % (padding_str(p[i]), padding_str(ids[i])))


def padding_str(n):
    return str(n).zfill(6)


if __name__ == '__main__':
    main()


Measured memory_bytes: 27428
ini = lambda : int(input())
inm = lambda : map(int,input().split())
inl = lambda : list(map(int,input().split()))
gcd = lambda x,y : gcd(y,x%y) if x%y else y
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

#maincode-------------------------------------------------
s = input()
q = ini()
mae = ''
bac = s
for i in range(q):
    a = input()
    if a[0] == '1':
        temp = mae
        mae = bac
        bac = temp
    else:
        if a[2] == '1':
            mae = mae + a[4]
        else:
            bac = bac + a[4]
mae = mae[::-1]
print(mae + bac)

Measured memory_bytes: 10452
n,k=map(int,input().split())
l=[]
d={}
for i in range(k):
    x=int(input())
    a=input().split()
    for j in range(x):
        try:
            d[a[j]]+=1
        except:
            d[a[j]]=1
            l.append(a[j])
print(n-len(l))


Measured memory_bytes: 9180
#include <bits/stdc++.h>
#define cina(a, n) for (int i = 0; i < n; ++i){ cin >> a[i]; }
#define ll long long

using namespace std;

int main () {
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	cin >> n;
	map<string, int> mp;
	for (int i = 0; i < n; ++i) {
		string s;
		cin >> s;
		mp[s]++;
	}
	cout << mp.size();
	return 0;
}

Measured memory_bytes: 19244
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(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()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//const ll INF = 1LL << 60;
//const int INF = 1001001001;

int main(void){
    int a=0;
    REP(i,3){
        int x; 
        cin >> x;
        a+=x;
    }
    printf("%s\n",a>=22?"bust":"win");

    return 0;
}

Measured memory_bytes: 3604
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  string s;
  while(getline(cin,s),s.size()!=1||s[0]!='0'){
    vector<int>num;
    rep(i,s.size()){
      int tmp=0;
      while(s[i]!=' '){
	tmp*=10;
	tmp+=s[i]-'0';
	i++;
	if(i==s.size())break;
      }
      if(tmp)num.pb(tmp);
    }
    //cout<<num[0]<<endl;
    int sum=0;
    int one=0;
    rep(i,num.size()){
      if(num[i]>10)num[i]=10;
      if(num[i]==1)one++;
      sum+=num[i];
    }
    rep(i,one){
      if(sum+10<=21)sum+=10;
    }
    if(sum>21)sum=0;
    cout<<sum<<endl;
  }


}

Measured memory_bytes: 1200
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0; i < n; i++)

const ll num = pow(10, 9) + 7;

ll func(ll a){
    ll val = 1;
    for(ll i = a; i > 0; i--){
        if(i == 1) val *= 1;
        else{
            val = (val * i) % num;
        }
    }
    return val;
}

int main(){
    ll N, M;
    cin >> N >> M;
    ll sub = abs(N - M);
    if(sub >= 2){
        cout << 0 << endl;
        return 0;
    }else{
        ll N_ans = func(N);
        ll M_ans = func(M);
        ll ans = (M_ans * N_ans) % num;
        if(sub == 0){
            ans = (ans * 2) % num;
        }
        cout << ans << endl;
        return 0;
    }
}

Measured memory_bytes: 3608
#include <iostream>
using namespace std;
#define MAX 2000000


int H, i, A[MAX + 1];

int parent(int i) 
{
	return i / 2;
}

int left(int i)
{
	return i * 2;
}

int right(int i)
{
	return i * 2 + 1;
}

void maxHeapify(int i) {
	int l, r, largest;
	l = left(i);
	r = right(i);

	if (l <= H && A[l] > A[i]) {
		largest = l;
	}
	else {
		largest = i;
	}

	if (r <= H && A[r] > A[largest]) {
		largest = r;
	}

	if (largest != i) {
		swap(A[i], A[largest]);
		maxHeapify(largest);
	}

}

int main(void)
{
	int i;

	cin >> H;

	for (i = 1; i <= H; i++) {
		cin >> A[i];
	}


	for (i = H / 2;i>=1;i--) {
		maxHeapify(i);
	}

	for (i = 1; i <= H; i++) {
		cout << " " <<  A[i];
	}

	cout << endl;


	return 0;
}

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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,tm,tp,f=0,i=0;
	long long int k;
	cin>>n>>k;
	int arr[n+1];
	map<int,int> ma;
	for(int i=1;i<n+1;i++){
		cin>>arr[i];
	}
	tp=1;
	while(k!=0){
		if(ma.find(tp)==ma.end()){
			tm=arr[tp];
			ma[tp]=i;
			tp=tm;
			i+=1;
			k-=1;
		}
		else{
			f=1;
			break;
		}
	}
	if(f){
		int c=ma[tp]-i;
		k=k%c;
		while(k--){
			tm=arr[tp];
			tp=tm;
		}
		cout<<tp<<"\n";
	}
	else{
		cout<<tp<<"\n";
	}
	return 0;
}


Measured memory_bytes: 11872
#include<iostream>
#include<iomanip>
#include<vector>
#include<queue>
#include<list>
#include<stack>
#include<algorithm>
#include<cmath>
#include<memory>
#include<string>

using namespace std;

int main()
{
  string s;
  getline(cin, s);

  vector<int> ap;
  vector<int> pe;

  int i = 0;
  
  while( true )
    {
      i = s.find( "apple", i );
      if ( i == string::npos ) break;
      ap.push_back( i++ );
    }

  i = 0;
  
  while( true )
    {
      i = s.find( "peach", i );
      if ( i == string::npos ) break;
      pe.push_back( i++ );
    }

  for ( auto it = ap.begin(); it != ap.end(); ++it )
    {
      s.replace( *it, 5, "peach" );
    }
  
  for ( auto it = pe.begin(); it != pe.end(); ++it )
    {
      s.replace( *it, 5, "apple" );
    }

  cout << s << endl;
  
  return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair <int, int>;
const double PI = acos(-1);



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

  vector<P> vs(M);
  rep(i, M){
    int a, b;
    cin >> a >> b;
    vs.at(i) = make_pair(b, a);
  }

  sort(vs.begin(), vs.end());

  int cur = 0;
  int ans = 0;

  rep(i, M){
    if(cur <= vs.at(i).second){
      cur = vs.at(i).first;
      ans++;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  int n = 0;
  cin >> n;
  map<string,int> count;
  for(int i = 0;i < n;i++){
    string s;
    cin >> s;
    count[s]++;
  }
  int max = 0;
  for(auto& i:count){
    int memo = i.second;
    if(memo > max)max= i.second;
  }
  vector<string> res;
  for(auto i:count){
    int memo = i.second;
    if(memo == max)res.push_back(i.first);
  }
  sort(res.begin(),res.end());
  for(auto& i:res){
    cout << i << endl;
  }
  return 0;
}

Measured memory_bytes: 26868
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=505,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,K,T;
    double U,V,L;cin>>N>>K>>T>>U>>V>>L;
    
    vector<int> can(L+1);
    for(int i=0;i<N;i++){
        int a;cin>>a;
        can[a]++;
    }
    
    double ans=0;
    
    int have=0;
    double rem=0.0;
    
    for(int i=1;i<=L;i++){
        if(rem==0.0){
            if(have){
                have--;
                rem=T;
                
                ans+=1.0/V;
                rem-=1.0/V;
            }else{
                ans+=1.0/U;
            }
        }else if(rem*V>=1.0){
            ans+=1.0/V;
            rem-=1.0/V;
        }else{
            double d=1.0-rem*V;
            ans+=rem;
            rem=0.0;
            
            if(have){
                have--;
                rem=T;
                
                ans+=d/V;
                rem-=d/V;
            }else{
                ans+=d/U;
            }
        }
        
        if(can[i]){
            if(rem==0.0){
                rem=T;
            }else{
                have++;
                if(have==K+1){
                    have--;
                    rem=T;
                }
            }
        }
    }
    
    cout<<setprecision(25)<<ans<<endl;
    
    
}




Measured memory_bytes: 3356
// AOJ 0362: Trampoline
// 2017.9.29 bal4u@uu
// 2017.11.14

#include <stdio.h>

int d[300005];

char buf[10], *p;
int getint()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

int main()
{
	int n, n1, i, j, a, k;

	fgets(p=buf, 10, stdin), n = getint(), n1 = n-1;
	for (i = 0; i < n; i++) {
		fgets(p=buf, 10, stdin), d[i] = getint();
	}

	for (k = j = i = 0; i < n1; i++) {
		a = j + d[i];
		if (a > k) k = a;
		j += 10;
		if (k < j) { puts("no"); return 0; }
	}
	for (k = j = n1*10, i = n1; i > 0; i--) {
		a = j - d[i];
		if (a < k) k = a;
		j -= 10;
		if (j < k) { puts("no"); return 0; }
	}
	puts("yes");
	return 0;
}

Measured memory_bytes: 2828
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int A, B, Q;
    cin >> A >> B >> Q;
    vector<long long> s(A), t(B);
    for(int i = 0; i < A; i++) cin >> s[i];
    for(int i = 0; i < B; i++) cin >> t[i];
    for(int i = 0; i < Q; i++){
        long long x;
        cin >> x;
        auto ite = lower_bound(s.begin(), s.end(), x);
        long long ans = 1e18;
        if(ite != s.end()){
            long long res = 0;
            res += abs(*ite - x);
            auto ite2 = lower_bound(t.begin(), t.end(), *ite);
            long long temp = 1e18;
            if(ite2 != t.end()) temp = min(abs(*ite2 - *ite), temp);
            if(ite2 != t.begin()) temp = min(temp, abs(*(ite2 - 1) - *ite));
            ans = min(res + temp, ans);
        }
        if(ite != s.begin()){
            long long res = 0;
            res += abs(*(ite - 1) - x);
            long long y = *(ite - 1);
            auto ite2 = lower_bound(t.begin(), t.end(), y);
            long long temp = 1e18;
            if(ite2 != t.end()) temp = min(abs(*ite2 - y), temp);
            if(ite2 != t.begin()) temp = min(abs(*(ite2 - 1) - y), temp);
            ans = min(res + temp, ans);
        }
        auto ite3 = lower_bound(t.begin(), t.end(), x);
        if(ite3 != t.end()){
            long long res = 0;
            res += *ite3 - x;
            auto ite2 = lower_bound(s.begin(), s.end(), *ite3);
            long long temp = 1e18;
            if(ite2 != s.end()) temp = min(abs(*ite2 - *ite3), temp);
            if(ite2 != s.begin()) temp = min(temp, abs(*(ite2 - 1) - *ite3));
            ans = min(res + temp, ans);
        }
        if(ite3 != t.begin()){
            long long res = 0;
            res += abs(*(ite3 - 1) - x);
            long long y = *(ite3 - 1);
            auto ite2 = lower_bound(s.begin(), s.end(), y);
            long long temp = 1e18;
            if(ite2 != s.end()) temp = min(abs(*ite2 - y), temp);
            if(ite2 != s.begin()) temp = min(abs(*(ite2 - 1) - y), temp);
            ans = min(res + temp, ans);
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 4760