akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n, m;
        cin >> n >> m;
        if(n == 0)
            return 0;

        vector<vector<int> > hope(m, vector<int>(n));
        for(int i=0; i<n; ++i){
            for(int j=0; j<m; ++j)
                cin >> hope[j][i];
        }

        vector<pair<int, int> > num(m);
        for(int i=0; i<m; ++i){
            num[i].first = - count(hope[i].begin(), hope[i].end(), 1);
            num[i].second = i+1;
        }
        sort(num.begin(), num.end());

        cout << num[0].second;
        for(int i=1; i<m; ++i)
            cout << ' ' << num[i].second;
        cout << endl;
    }
}

Measured memory_bytes: 1308
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8


void mainmain(){
	int n, m, q;
	scanf("%d%d%d", &n, &m, &q);
	vint as(q);
	for(int i = 0; i < q; ++i){
		scanf("%d", &as[i]);
		--as[i];
	}

	vint vis(m);
	vector<int> seq;
	for(int i = q; i--; ){
		if(!vis[as[i]]){
			vis[as[i]] = 1;
			seq.push_back(as[i]);
		}
	}
	for(int i = 0; i < m; ++i){
		if(!vis[i]){ seq.push_back(i); }
	}
	vint rtbl(m);
	for(int i = 0; i < m; ++i){
		rtbl[seq[i]] = i;
	}

	vint cnt(m + 1);
	cnt[0] = n;
	for(int i = q; i--; ){
		int x = rtbl[as[i]];
		if(cnt[x] > 0){
			--cnt[x];
			++cnt[x + 1];
		}
	}

	int minidx;
	for(minidx = 0; !cnt[minidx]; ++minidx);
	vis.assign(m, 0);
	vint seq2;
	for(int i = 0; i < minidx; ++i){
		seq2.push_back(seq[i]);
		vis[seq[i]] = 1;
	}
	for(int i = 0; i < m; ++i){
		if(!vis[i]){
			seq2.push_back(i);
		}
	}

	puts(seq == seq2 ? "Yes" : "No");
}



}
int main() try{
//	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){}


Measured memory_bytes: 2936
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
	int n, h, m, s;
	scanf("%d",&n);
	h = n/3600;
	m = n%3600/60;
	s =  n%60; 
	printf("%d:%d:%d\n", h, m, s );	
	
	return 0;
}


Measured memory_bytes: 2728
import sys
from math import ceil, floor
from collections import deque, Counter, defaultdict
from fractions import gcd
input = lambda: sys.stdin.readline().rstrip()

def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return

def comb(n,r):
    p,q=1,1
    for i in range(r):
        p=p*(n-i) 
        q=q*(i+1) 
    return p//q

def main():
    n = int(input())
    As = list(map(int, input().split()))
    Ps = list()
    cnt = 0
    counter = Counter(As)
    for i in range(n):
        Ps.append(counter[As[i]]-1)
    
    for i in counter:
        cnt += comb(counter[i], 2)

    for i in range(n):
        print(cnt-Ps[i])

if __name__ == '__main__':
    main()

Measured memory_bytes: 27432
# python3
# -*- coding: utf-8 -*-
import sys
import math
#from math import gcd
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint

INF = float('inf')

ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
sys.setrecursionlimit(1000000000)


def lcm(a, b):
    return (a * b) // gcd(a, b)


# main
a,b,c = mis()

if len(set([a,b,c])) == 2:
    print("Yes")
else:
    print("No")


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


int main()
{
    bool vis[205]={false};
    int a[4][4];
    for(int i=1;i<=3;i++)
        for(int j=1;j<=3;j++) cin>>a[i][j];
    int n; cin>>n;
    int x;
    for(int i=1;i<=n;i++){
        cin>>x; vis[x]=true;
    }
    bool flag=false;
    for(int i=1;i<=3;i++){
        if(vis[a[i][1]] and vis[a[i][2]] and vis[a[i][3]])
            flag=true;
        else if(vis[a[1][i]] and vis[a[2][i]] and vis[a[3][i]])
            flag=true;
    }
    if(vis[a[1][1]] and vis[a[2][2]] and vis[a[3][3]])
        flag=true;
    if(vis[a[1][3]] and vis[a[2][2]] and vis[a[3][1]])
        flag=true;
    if(flag)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int k;
    string s;

    cin>>k;
    cin>>s;

    int l=s.size();
    if(l<=k)
        cout<<s<<endl;
    else
    {

        for(int i=0;i<k;i++)
            cout<<s[i];
        cout<<"..."<<endl;
    }
    return 0;

}


Measured memory_bytes: 3556
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct Edge{
    ll to, weight;
    Edge(ll t, ll w) : to(t), weight(w){}
};
using graph = vector<vector<ll>>;
using Graph = vector<vector<Edge>>;


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

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

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    ll n;
    cin>>n;
    ll ans = 0;
    vector<ll> a(n+2);
    a[0] = 0;
    a[n+1] = 0;
    for(ll i=1;i<=n;++i){
        cin>>a[i];
        ans += abs(a[i-1] - a[i]);
    }
    ans += abs(a[n] - a[n+1]);
    //cout<<ans<<endl;
    
    for(ll i=1;i<=n;++i){
        ll sum = abs(a[i-1] - a[i]) + abs(a[i] - a[i+1]) - abs(a[i+1] - a[i-1]);
        cout<<ans-sum<<endl;
    }

    return 0;
}

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

int main() {
  int A, B;
  cin >> A >> B;
  int ans = -1;
  for(int i=0; i<1300; i++){
    if(i*8/100 == A && i/10 == B){
      ans = i;
      break;
    }
  }
  cout << ans << endl;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int a,b;
    cin>>a>>b;
    int ans = 0;
    if(b<a)
        ans = a-1;
    else
        ans = a;
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>	
int main(void)
{
	int n,x;
	scanf("%d",&n);
	x=n%10;
	if(x==2||x==4||x==5||x==7||x==9) printf("hon\n");
	else if(x==0||x==1||x==6||x==8) printf("pon\n");
	else printf("bon\n");
	return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

int main(){
    int s;
    cin >> s;
    
    vector<int> seq;
    seq.push_back(s);
    map<int, bool> temp;
    temp[s] = true;
    
    int now = 0;
    int cnt = 0;
    while(cnt < 100000000){
        if(seq[now] % 2 == 0){
            seq.push_back(seq[now++] / 2);
            if(temp[seq[now]]){
                cout << now + 1 << endl;
                return 0;
            }
            temp[seq[now]] = true;
        }
        else{
            seq.push_back(3 * seq[now++] + 1);
            if(temp[seq[now]]){
                cout << now + 1 << endl;
                return 0;
            }
            temp[seq[now]] = true;
        }
        
        cnt++;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <math.h>
#include <map>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;


int main(){
  long long N,M;
  cin>>N>>M;
  long long tmp;
  vector<long long> A;
  vector<long long> B;
  long long ans=1;
  long long lim;
  lim=M*N;
  for(long long i=0;i<N;++i){
    cin>>tmp;
    A.push_back(tmp);
  }
  for(long long j=0;j<M;++j){
    cin>>tmp;
    B.push_back(tmp);
  }
  sort(A.begin(),A.end(),greater<long long>());
  sort(B.begin(),B.end(),greater<long long>());
  A.push_back(0);
  B.push_back(0);
  int state_A=1;
  int state_B=1;
  if(A[0]!=M*N||B[0]!=M*N){
    cout<<0;
    return 0;
  }
  for(int a=1;a<A.size();++a){
    if(A[a-1]==A[a]){
      cout<<0;
      return 0;
    }
  }
  
  for(int b=1;b<B.size();++b){
    if(B[b-1]==B[b]){
      cout<<0;
      return 0;
    }
  }
  
for(int k=M*N;k>0;--k){
  if(A[state_A]==k && B[state_B]==k){
    state_A+=1;
    state_B+=1;
  }
  else if(A[state_A]==k){
    state_A+=1;
    ans*=(state_B);
    ans%=1000000007;
  }
  else if(B[state_B]==k){
    state_B+=1;
    ans*=(state_A);
    ans%=1000000007;
  }
  else{
    ans*=(state_A*state_B-(M*N-k));
    ans%=1000000007;
  }
}
cout<<ans;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
  int q,a,b,i,j=0,k=0;
  char str[1000],y[8],z[1000],x[1000];
  char *p="print",*rev="reverse",*rep="replace";
  scanf("%s",str);
  scanf("%d",&q);
  for(k=0;k<q;k++){
    scanf("%s",y);
    if (strcmp(y,p)==0) {
      scanf("%d %d",&a,&b);
      for(i=a;i<=b;i++){
	printf("%c",str[i]);
	if(i==b)printf("\n");
      }
    }else if (strcmp(y,rev)==0){
      scanf("%d %d",&a,&b);
      for(i=a;i<=b;i++){
        z[i]=str[i];
      }
      for(i=a,j=b;i<=b;i++,j--){
        str[i]=z[j];
      }
    }else if (strcmp(y,rep)==0) {
      scanf("%d %d %s",&a,&b,x);
      for(i=a,j=0;i<=b;i++,j++){
        str[i]=x[j];
      }
    }
  }
  return 0; 
}




Measured memory_bytes: 2108
using System;
using System.Linq;

namespace ABC075_D___Axis_Parallel_Rectangle改善
{
    class Program
    {
        static void Main(string[] args)
        {
            var NK = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var N = NK[0];
            var K = NK[1];

            var points = new Point[N];
            for (int i = 0; i < N; i++)
            {
                var xy = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
                points[i] = new Point(xy[0], xy[1]);
            }

            var projectionX = points.Select(p => p.x).OrderBy(x => x).ToArray();
            var projectionY = points.Select(p => p.y).OrderBy(y => y).ToArray();

            var cumlative = new int[N + 1, N + 1];
            foreach (Point p in points)
            {
                cumlative[Array.BinarySearch(projectionX, p.x) + 1, Array.BinarySearch(projectionY, p.y) + 1] += 1;
            }
            for (int x = 1; x < N + 1; x++)
            {
                for (int y = 1; y < N + 1; y++)
                {
                    cumlative[x, y] += cumlative[x, y - 1];
                }
            }
            for (int y = 1; y < N + 1; y++)
            {
                for (int x = 1; x < N + 1; x++)
                {
                    cumlative[x, y] += cumlative[x - 1, y];
                }
            }
            long minArea = long.MaxValue;
            for (int L = 1; L < N + 1; L++)
            {
                for (int B = 1; B < N + 1; B++)
                {
                    for (int T = B + 1; T < N + 1; T++)
                    {
                        for (int R = L + 1; R < N + 1; R++)
                        {
                            if ((cumlative[R, T] - cumlative[R, B - 1] - cumlative[L - 1, T] + cumlative[L - 1, B - 1]) >= K)
                            {
                                minArea = Math.Min(minArea, (projectionX[R - 1] - projectionX[L - 1]) * (projectionY[T - 1] - projectionY[B - 1]));
                            }
                        }
                    }
                }
            }
            Console.WriteLine(minArea);
        }
    }

    struct Point
    {
        public long x;
        public long y;

        public Point(long _x, long _y)
        {
            x = _x;
            y = _y;
        }

    }
}


Measured memory_bytes: 13524
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
    }

    vector<ll> num(N, 0);
    for (ll i = 0; i < N; i++) {
        num[A[i]]++;
    }

    if (N % 2 == 0) {
        //奇数が二人ずつじゃないとダメ
        for (ll i = 1; i < N; i += 2) {
            if (num[i] != 2) {
                cout << 0 << endl;
                return 0;
            }
        }
    } else {
        //0が一人、あとは偶数が二人ずつじゃないとダメ
        if (num[0] != 1) {
            cout << 0 << endl;
            return 0;
        }
        for (ll i = 2; i < N; i += 2) {
            if (num[i] != 2) {
                cout << 0 << endl;
                return 0;
            }
        }
    }

    constexpr ll MOD = (ll)1e9 + 7;
    ll ans = 1;
    for (ll i = 0; i < N / 2; i++) {
        (ans *= 2) %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sint(a) scanf("%d", &a)
#define sint2(a, b) scanf("%d %d", &a, &b)
#define sll(a) scanf("%lld", &a)
#define sll2(a, b) scanf("%lld %lld", &a, &b)
#define mem(a, i) memset(a, i, sizeof(a))
const double pi = acos(-1);
const int maxn = 1e6 + 10;
const int mod = 1e4;

int main()
{
    int a,b,c;
    sint(a);
    sint2(b,c);
    int sum=a+b+c;
    if(sum<22)
        cout<<"win"<<endl;
    else
        cout<<"bust"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>


int main(){
  long int a,b,c,k;
  long int ta,tb,tc;
  long int ans = 0;
  int flag = 0;

  scanf("%ld%ld%ld%ld", &a,&b,&c,&k);
  ta = b+c;
  tb = a+c;
  tc = a+b;
  if(k <= 0) {
    ta = a;
    tb = b;
    tc = c;
  }
  ans = ta - tb;
  ans = abs(ans);

  if(ans >= (long int)pow(10,18)){
    flag = 1;
    printf("Unfair");
  }

  if(a>b){
    if(k%2 == 1) ans = ans * -1;
  }else {
    if(k%2 == 0) ans = ans * -1;
  }

  if(flag == 0) printf("%ld", ans);
  return 0;
}

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

int main(){
  int a,b;
  cin >> a >> b;
  if(a > 8 || b > 8) cout << ":(" << endl;
  else cout << "Yay!" << endl;
}


Measured memory_bytes: 256
/*
大きなケースが全部WAになる　理由がわからん
・10万回も再帰できない？→dfsを非再帰に　それでもWAのまま
・なぞ

→たんに考察不足だった．

*/
#include<bits/stdc++.h>
using namespace std;


typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

#define pb push_back
#define mp make_pair
#define snd second
#define fst first
#define debug printf("--%d--\n",__LINE__)
#define ll long long int

ll N;
static ll a[114514], b[114514], s[114514];
static vvi l(114514);

static ll x[114514];

bool saiki(int v, int from){
	//cout << "saiki:" << v << " " << from << endl;
	ll cnt = 0;
	for(int i=0;i<l[v].size();i+=2){
		if (l[v][i] != from){
			if (!saiki(l[v][i+1], l[v][i])) return false;
			cnt += x[l[v][i]];
		}
	}
	ll y = s[v] * 2 - cnt;
	if (l[v].size()<=2) y = s[v] - cnt;
	if (from<0){
		return y==0;
	}else{
		if (y<0) return false;
		x[from] = y;
		//cout << "kakutei:" << from << " " << y << endl;
	}
	return true;
}

int main(void){
	
	cin >> N;
	for(int i=0;i<N;i++){
		cin >> s[i];
	}
	for(int i=0;i+1<N;i++){
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
	}
	
	/*
	N = 100000;
	for(int i=0;i<N;i++){
		s[i] = 1;
	}
	for(int i=0;i+1<N;i++){
		a[i] = N-1-i; b[i] = N-2-i;
	}
	*/
	
	for(int i=0;i+1<N;i++){
		l[a[i]].pb(i);l[a[i]].pb(b[i]);
		l[b[i]].pb(i);l[b[i]].pb(a[i]);
	}
	for(int i=0;i<N;i++) x[i] = -1;
	
	//cout << (saiki(rand()%N, -1) ? "YES" : "NO") << endl;
	
	vi st(400000);
	int sz = 3;
	st[0] = 0; st[1] = -1; st[2] = 0;
	while(sz > 0){
		int v = st[sz-3];
		int from = st[sz-2];
		bool flg = false;
		
		/*if (v>99990){
			cout << "saiki:" << v << " " << from << " " << st[sz-1] << endl;
			
			for(int i=sz-9;i<sz;i++){
				cout << st[i] << " ";
			}cout << endl;
		}*/
		
		for(int i=st[sz-1];i<l[v].size();i+=2){
			if (l[v][i] != from){
				st[sz-1]=i+2;
				sz += 3;
				st[sz-3] = l[v][i+1];
				st[sz-2] = l[v][i];
				st[sz-1] = 0;
				flg = true;
				break;
			}
		}
		if (flg) continue;
		
		ll cnt = 0;
		ll maxi = 0;
		for(int i=0;i<l[v].size();i+=2){
			if (l[v][i] != from){
				cnt += x[l[v][i]];
				maxi = max(maxi, x[l[v][i]]);
			}
		}
		ll sum = s[v] * 2;
		if (l[v].size()<=2) sum = s[v];
		
		ll y = sum - cnt;
		maxi = max(maxi, y);
		
		//ペアが作れないケースがある．★
		if (l[v].size()>2 && maxi*2>sum){
			cout << "NO" << endl; return 0;
		}
		
		if (from<0){
			if (y!=0){
				cout << "NO" << endl; return 0;
			}
		}else{
			if (y<0){
				cout << "NO" << endl; return 0;
			}
			x[from] = y;
			//cout << "kakutei:" << from << " " << y << endl;
		}
		sz -= 3;
	}
	cout << "YES" << endl;
	
	return 0;
}


Measured memory_bytes: 11392
#include <iostream>
#include <fstream>
#include <utility>
#include <vector>
#include <algorithm>

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define chmin(x, y) x = min(x, y)

using namespace std;

typedef long long ll;

const int INF = 1001001001;

int main()
{

    ll n, m, l;
    cin >> n;
    cin >> m;
    cin >> l;

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

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

    REP(k, n)
    REP(i, n)
    REP(j, n)
    chmin(dist[i][j], dist[i][k] + dist[k][j]);

    vector<vector<int>> dist2(n, vector<int>(n, INF));
    REP(i, n)
    REP(j, n)
    {
        if (dist[i][j] <= l)
            dist2[i][j] = 1;
    }
    REP(k, n)
    REP(i, n)
    REP(j, n)
    chmin(dist2[i][j], dist2[i][k] + dist2[k][j]);

    int q;
    cin >> q;
    REP(qi, q)
    {
        int s, t;
        cin >> s;
        cin >> t;
        --s, --t;
        int ans = dist2[s][t] - 1;
        if (dist2[s][t] == INF)
            ans = -1;
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int , int> P;
typedef pair<ll, ll> PL;
const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}
 

int n,i;

int main(){
    cin >> n >> i;
    cout << (n-i)+1 << endl;

}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if (a == b && a != c) {
        cout << "Yes" << endl;
    } else if (a == c && a != b) {
        cout << "Yes" << endl;
    } else if (b == c && b != a) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
mod = 10 ** 9 + 7
lcm = a[0]
for i in range(1,n):
  big,sml = lcm,a[i]
  while sml != 0:
    big,sml = sml,big%sml
  lcm *= a[i] // big
ans = 0
def inv(x):
  y = 1
  while x != 1:
    y *= mod // x + 1
    y %= mod
    x -= mod % x
  return y
#print(inv(5))
for i in range(n):
  ans += inv(a[i])
  ans %= mod
#print(ans)
ans *= lcm
ans %= mod
print(ans)
#print(lcm)
#print(1000000*999999*999998%mod)

Measured memory_bytes: 42716
def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    B = [int(x) for x in input().split()]
    ans = 0
    for i in range(N):
        k = B[i] - A[i]
        if k >= 0:
            if k <= A[i + 1]:
                ans += B[i]
                A[i + 1] -= k
            else:
                ans += A[i] + A[i + 1]
                A[i + 1] = 0
        else:
            ans += B[i]

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 19156
#include <iostream>
#include <set>
#include <string>
#include <vector>
#include <algorithm>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<=N;i++)
using namespace std;

int main(void)
{
	int A, B, C; cin >> A >> B >> C;
	int X; cin >> X;
	int ans = 0;

	rep(i, 0, A) {
		rep(j, 0, B) {
			rep(k, 0, C) {
				int sum = 500 * i + 100 * j + 50 * k;
				if (sum == X) {
					ans++;
					break;
				}
			}
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import { readFileSync } from 'fs'
import { reverse } from 'dns'
import { start } from 'repl'

function main(input: string[]) {
  let S = input[0]
  let T = input[1]

  let ans = 100000
  for (let i = 0; i <= S.length - T.length; i++) {
    let ansOne = 0
    for (let j = 0; j < T.length; j++) {
      if (S[i + j] != T[j]) ansOne++
    }
    ans = Math.min(ans, ansOne)
  }

  console.log(ans)
}

let lines: string[] = [];
const reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', function (line: string) {
  lines.push(line);
});
reader.on('close', function () {
  main(lines)
});


Measured memory_bytes: 33184
parseInt(x)=parse(Int, x)
parseMap(x::Array{SubString{String},1})=map(parseInt, x)

function main()
	n,k,c = readline() |> split |> parseMap
	s = readline() |> chomp
	a = Int[]
	b = Int[]
	f = 0
	fc  = 0
	g = n+1
	gc = 0
	for i in 1:n
		if s[i]=='o'
			if f<i&&fc<k
				push!(a,i)
				f=i+c
				fc+=1
			end
		end
		if s[n+1-i]=='o'
			if g>n+1-i&&gc<k
				push!(b,n+1-i)
				g = n+1-i-c
				gc+=1
			end
		end
	end
	for i in 1:length(a)
		if a[i]==b[length(a)+1-i]
			println(a[i])
		end
	end
end

main()

Measured memory_bytes: 166688
#include<bits/stdc++.h>
using namespace std;
const int N=1005;
const long long inf=6000000000000000000ll;
int Q,n,m,D,c[27],a[N][27],t[N],s[27],ans,i,j,x,y;
set<int> p[27];
void Change(int x,int y)
{
	ans-=a[x][t[x]];
	ans+=a[x][y];
	auto it=p[t[x]].find(x);
	auto e=it;
	--e;
	++it;
	ans+=c[t[x]]*(-(*it-*e)*(*it-*e-1)/2+(x-*e)*(x-*e-1)/2+(*it-x)*(*it-x-1)/2);
	p[t[x]].erase(x);
	t[x]=y;
	p[t[x]].insert(x);
	it=p[t[x]].find(x);
	e=it;
	--e;
	++it;
	ans-=c[t[x]]*(-(*it-*e)*(*it-*e-1)/2+(x-*e)*(x-*e-1)/2+(*it-x)*(*it-x-1)/2);
}
int main()
{
	scanf("%d",&D);
	for(i=1;i<=26;++i)
	{
		scanf("%d",&c[i]);
		p[i].insert(D+1);
		p[i].insert(0);
	}
	for(i=1;i<=D;++i)
		for(j=1;j<=26;++j)
			scanf("%d",&a[i][j]);
	for(i=1;i<=D;++i)
		scanf("%d",&t[i]);
	for(i=1;i<=D;++i)
	{
		for(j=1;j<=26;++j)
			++s[j];
		s[t[i]]=0;
		for(j=1;j<=26;++j)
			ans-=s[j]*c[j];
		ans+=a[i][t[i]];
		p[t[i]].insert(i);
	}
	scanf("%d",&Q);
	while(Q--)
	{
		scanf("%d %d",&x,&y);
		Change(x,y);
		cout<<ans<<endl;
	}
}

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

int main(){
    long long int n;
    cin >> n;
   
    int count = 1;
    
    while(n - pow(26, count) > 0){ 
        n = n - pow(26, count);
        count++;  
    }
    vector<int> s;
    n = n - 1;
    for(int i = 0; i < count; i++){
        s.push_back(n%26);
        n /= 26;
    }

    reverse(s.begin(), s.end());
    char tmp;
    for(int i = 0; i < count; i++){
        tmp = 'a' + s.at(i);
        cout << tmp;
    }
    cout << endl;
}

Measured memory_bytes: 4036
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<functional>
#include<cmath>
#include<queue>
#include<stack>
using namespace std;
int n, h, w, x[100009], y[100009], z[100009], t[100009]; vector<pair<int, int>>T; bool J[100009]; stack<int>S;
int solve(int p, int q) {
	if (p == 0)return q;
	if (q == w)return w + p;
	if (p == h)return w + h + (w - q);
	if (q == 0)return w + h + w + (h - p);
	return -1;
}
int main() {
	cin >> h >> w >> n; if (n == 1) { cout << "YES" << endl; return 0; }
	for (int i = 0; i < n; i++)cin >> x[i] >> y[i] >> z[i] >> t[i];
	bool OK = true;
	for (int i = 0; i < n; i++) {
		int v1 = solve(x[i], y[i]), v2 = solve(z[i], t[i]); if (v1 > v2)swap(v1, v2);
		if (v1 != -1 && v2 != -1 && J[i] == false) {
			T.push_back(make_pair(v1, i));
			T.push_back(make_pair(v2, i));
		}
	}
	sort(T.begin(), T.end());
	for (int i = 0; i < T.size(); i++) {
		if (J[T[i].second] == true) {
			if (S.top() != T[i].second) { OK = false; break; }
			S.pop();
		}
		else {
			S.push(T[i].second); J[T[i].second] = true;
		}
	}
	if (OK == true)cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 3956
#include<stdio.h>
int main(void)
{
	int n,l,a=0,r,min=10000,ans,i,j;
	scanf("%d %d", &n, &l);
	for(i=0; i<n; i++)
	a+=l+i;
	for(i=0; i<n; i++)
	{
		r=0;
		for(j=0; j<n; j++)
		{
			if(i!=j)
			r+=l+j;
		}
		if(min>abs(a-r))
		{
			min=abs(a-r);
			ans=r;
		}
	}
	printf("%d\n", ans);
	
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define N 200100
int a[5];
void solve(){
	int n,m;
	cin>>n>>m;
	memset(a,-1,sizeof a);
	while(m--){
		int s,c;
		cin>>s>>c;
		if(a[s]==-1 || a[s]==c){
			a[s]=c;
		} else{
			cout<<-1<<endl;
			return;
		}
	}
	for(int i=1;i<=n;i++){
		if(a[i]!=-1){
			if(i==1 && a[i]==0 && n!=1){
				cout<<-1<<endl;
				return;
			}
			cout<<a[i];
		} else{
			if(i==1 && n!=1){
				cout<<1;
			} else{
				cout<<0;
			}
		}
	}
}

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

Measured memory_bytes: 256
//ABC142C
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
using namespace std;
 
int main(){
  int N,K;
 
cin >> N >>K ;
   vector<int>h(N);
  for (int i=0 ; i<N ; i++){cin >>h.at(i);}
  
 // sort(h.begin(),h.end());
  int count=0;
  for(int i= 0;i<N;i++){
  if(h.at(i) >= K){count++;}
 
  }

cout<< count<<endl;
}


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

using namespace std;

int main()
{
    int n; cin >> n; bool ok = false;

    for(int i = 0; i <= n / 4 ; i++)
    {
        for(int j = 0; j <= n / 7; j++)
        {
            if(4 * i + 7 * j == n){
                ok = true;
            }
        }
    }

    if(ok == false){
        puts("No");
    }else{
        puts("Yes");
    }
    return 0;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


int main() {
    string s; cin >> s;
    int a=0;
    int z=0;
    REP(i,s.size()){
        if(s[i] == 'A'){
            a=i;
            break;
        }
    }
    REP(i,s.size()){
        if(s[i] == 'Z') z=i;
    }

    cout << z-a+1 << endl;
    return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define rep(i, n) REP(i, 0, n)
#define REP(i, l, r) for (long long i = l; i < r; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
map<pair<int, int>, int> gmemo;
int gcd(int a, int b) {
	if (gmemo[{a, b}] != 0) return gmemo[{a, b}];
	if (gmemo[{b, a}] != 0) return gmemo[{b, a}];
	if (a % b == 0)
		return gmemo[{a, b}] = b;
	else
		return gmemo[{a, b}] = gcd(b, a % b);
}
int lcm(int a, int b) {
	return a * b / gcd(a, b);
}
bool prime(int a) {
	if (a == 1) return false;
	for (int i = 2; i * i <= a; i++) {
		if (a % i == 0) return false;
	}
	return true;
}
signed main() {
	int x,y,z,K,a[1234],b[1234],c[1234];
	cin>>x>>y>>z>>K;
	rep(i,x)cin>>a[i];
	rep(i,y)cin>>b[i];
	rep(i,z)cin>>c[i];
	sort(a,a+x,greater<int>());
	sort(b,b+y,greater<int>());
	sort(c,c+z,greater<int>());
	int memo[131072],cnt=0;
	for(int i=0;i+1<=K&&i<x;i++){
		for(int j=0;(i+1)*(j+1)<=K&&j<y;j++){
			for(int k=0;((i+1)*(j+1)*(k+1))<=K&&k<z;k++){
				memo[cnt++]=a[i]+b[j]+c[k];
			}
		}
	}
	sort(memo,memo+cnt,greater<int>());
	rep(i,K){
		cout<<memo[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
int main(){
  string a, b;
  int x, y;
  cin >> x >> y;
  a = "."; 
  
  for (int i = 1; i < y + 2; i++) a += ".";
  for (int i = 0; i < x; i++){
    cin >> b;
	a += "." + b + "."; 
  }
  for (int i = 0; i < y + 2; i++) a += ".";
  
  for (int i = 2; i < x + 2; i++){
    for (int j = (i - 1) * (y + 2) + 1; j < i * (y + 2) - 1; j++){
      if (a.at(j) == '#') cout << "#";

      else {
        int count = 0;
        if (a.at(j - y - 3) == '#') count++;
        if (a.at(j - y - 2) == '#') count++;
        if (a.at(j - y - 1) == '#') count++;
        if (a.at(j - 1) == '#') count++;
        if (a.at(j + 1) == '#') count++;
        if (a.at(j + y + 1) == '#') count++;
        if (a.at(j + y + 2) == '#') count++;
        if (a.at(j + y + 3) == '#') count++;
        cout << count;
       }
    }
    cout << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <deque>
#include <bitset>
#include <climits>
#include <cstdio>
#include <list>
#include <iomanip>
using namespace std;

#define ll long long int
ll n;
ll arr[10000];
ll dp[10000][10000];
ll solve(int i, int j)
{
	if (i == j)
		return arr[i];

	if (j == i + 1)
		return max(arr[i], arr[j]);


	if (dp[i][j] != -1)
		return dp[i][j];

	ll ans1 = arr[i] + min(solve(i + 2, j), solve(i + 1, j - 1));
	ll ans2 = arr[j] + min(solve(i, j - 2), solve(i + 1, j - 1));

	return  dp[i][j] = max(ans1, ans2);

}
int main() {

	cin >> n;
	ll sum = 0;
	memset(dp, -1, sizeof dp);
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
		sum += arr[i];
	}
	//cout << sum << endl;

	ll X = solve(0, n - 1);
	ll Y = sum - X;
	//cout << X << " " << Y << endl;

	cout << X - Y;

	return 0;
}

Measured memory_bytes: 781696
S = gets.chomp.codepoints
N = S.size
R = 82
L = 76

result = Array.new(N, 1)

c = 0
0.upto(N-2) do |i|
  next if S[i] == L

  if S[i+1] == R
    c += 1
    result[i] = 0
  else
    div, mod = c.divmod(2)
    result[i] += div
    result[i+1] += div + mod
    c = 0
  end
end

c = 0
(N-1).downto(1) do |i|
  next if S[i] == R

  if S[i-1] == L
    c += 1
    result[i] = 0
  else
    div, mod = c.divmod(2)
    result[i] += div
    result[i-1] += div + mod
    c = 0
  end
end

puts result.join(' ')


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

int main() {
  int n,i;
  cin>>n;
  int h[n];
  for(i=0;i<n;i++)
    cin>>h[i];
  
  int ans=0;
  
  for(i=0;i<n;i++){
    if(i!=n-1 && h[i]>h[i+1])
      ans+=h[i]-h[i+1];
    if(i==n-1)
      ans+=h[i];
  }
  cout<<ans;
    
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
string S;
int L[301010],R[303030];
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>S;
	
	FOR(i,N) {
		L[i+1]=L[i]+(S[i]=='W');
		R[i+1]=R[i]+(S[i]=='E');
	}
	
	int mi=303030;
	FOR(i,N) {
		mi=min(mi,L[i]+(R[N]-R[i+1]));
	}
	cout<<mi<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int sz,x;
  cin>>sz;
  set<int>ar;
  set<int>::iterator it;
  for(int i=0;i<sz;i++){
    cin>>x;
    ar.insert(x);
  }
  for(it=ar.begin();it !=ar.end() ;it++){
    if(it==ar.begin())
    cout<<*it;
  else
    cout<<' '<<*it;}
    cout<<endl;
}



Measured memory_bytes: 7784
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
 
typedef long long ll;
const ll MOD = 1e9+7;
const ll INF = 1e18;


#define PB push_back
#define MP make_pair
#define F first
#define S second

template<typename T,typename U>
bool chmax(T& max, const U& x){
	if(max<x){
		max = x;
		return true;
	}
	return false;
}

template<typename T,typename U>
bool chmin(T& min, const U& x){
	if(min>x){
		min = x;
		return true;
	}
	return false;
}

struct vertex{
    vector<vertex*> edge;
    ll h;
};

int main(){
  	ll n,m;
    cin >> n >> m;
    vertex G[n+1];
    vector<bool> ans(n+1,true);
    for(ll i=1;i<=n;i++){
        ll tmp;
        cin >> tmp;
        G[i].h=tmp;
    }
    for(ll i=0;i<m;i++){
        ll a,b;
        cin >> a >> b;
        G[a].edge.PB(&G[b]);
        G[b].edge.PB(&G[a]);
    }
    
    for(ll i=1;i<=n;i++){
        for(vertex* e:G[i].edge){
            if(G[i].h<=e->h){
                ans[i]= false;
            }
        }
    }
    ll answer=0;
    for(ll i=1;i<=n;i++){
        if(ans[i]) answer++;
    }
    cout << answer << endl;
}


Measured memory_bytes: 10236
#include<cstdio>
#define MAX 10000
#define NIL -1

struct Node { int parent, left, right; };

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u, int d) {
    if (u == NIL) return;
    D[u] = d;
    setDepth(T[u].left, d + 1);
    setDepth(T[u].right, d + 1);
}

int setHeight(int u) {
    int h1 = 0, h2 = 0;
    if (T[u].left != NIL)
        h1 = setHeight(T[u].left) + 1;
    if (T[u].right != NIL)
        h2 = setHeight(T[u].right) + 1;
    return H[u] = (h1 > h2 ? h1 : h2);
}

int getSibling(int u) {
    if (T[u].parent == NIL) return NIL;
    if (T[T[u].parent].left != u && T[T[u].parent].left != NIL)
        return T[T[u].parent].left;
    if (T[T[u].parent].right != u && T[T[u].parent].right != NIL)
        return T[T[u].parent].right;
    return NIL;
}

void print(int u) {
    printf("node %d: ", u);
    printf("parent = %d, ", T[u].parent);
    printf("sibling = %d, ", getSibling(u));
    int deg = 0;
    if (T[u].left != NIL) deg++;
    if (T[u].right != NIL) deg++;
    printf("degree = %d, ", deg);
    printf("depth = %d, ", D[u]);
    printf("height = %d, ", H[u]);
    
    if (T[u].parent == NIL) {
        printf("root\n");
    } else if (T[u].left == NIL && T[u].right == NIL) {
        printf("leaf\n");
    } else {
        printf("internal node\n");
    }
}

int main() {
    int v, l, r, root = 0;
    scanf("%d", &n);
    
    for (int i = 0; i < n; i++) T[i].parent = NIL;
    
    for (int i = 0; i < n; i++) {
        scanf("%d %d %d", &v, &l, &r);
        T[v].left = l;
        T[v].right = r;
        if (l != NIL) T[l].parent = v;
        if (r != NIL) T[r].parent = v;
    }
    
    for (int i = 0; i < n; i++) if (T[i].parent == NIL) root = i;
    
    setDepth(root, 0);
    setHeight(root);
    
    for (int i = 0; i < n; i++) print(i);
    
    return 0;
}


Measured memory_bytes: 2776
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <tuple>
using namespace std;
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
typedef long long ll;
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
 
int main ()
{
    int N; cin >> N;

    vector<ll> L(N);
    REP(i,N) cin >> L[i];

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

    ll ans = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            for (int k = j + 1; k < N; k++) {
                if (L[i] == L[j] ||
                    L[j] == L[k] ||
                    L[k] == L[i]) {
                    continue;
                }
                if (L[i] + L[j] <= L[k]) continue;
                if (L[i] + L[k] <= L[j]) continue;
                if (L[j] + L[k] <= L[i]) continue;
                ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3600
fn read<T: std::str::FromStr>() -> Vec<T> {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf.split_whitespace()
        .map(|x| x.parse().ok().unwrap())
        .collect()
}

fn main() {
    let (n, k) = {
        let v: Vec<usize> = read();
        (v[0], v[1])
    };
    let x: Vec<i64> = read();

    let mut ans = 1_000_000_000;
    use std::cmp::{max, min};
    for i in 0..n - k + 1 {
        let tmp = if x[i] < 0 && x[i + k - 1] > 0 {
            x[i + k - 1] - x[i] + min(x[i + k - 1], -x[i])
        } else {
            max(x[i].abs(), x[i + k - 1].abs())
        };
        ans = min(ans, tmp);
    }
    println!("{}", ans);
}


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

typedef long long lli;

int main(){
  lli T,N,start,tmp=0,MAX=0,endnum=0,is,it,ir=0;
  vector<lli>s,t,rsw;

  cin>>T>>N;
  for(lli i=0;i<N;i++){
    cin>>is>>it;
    s.push_back(is);
    t.push_back(it);
    ir+=it-is;
    rsw.push_back(ir);
  }

  for(lli i=0;i<N;i++){
    start=s[i];
    for(lli j=endnum;j<N;j++){
      if(s[i+j]<start+T&&(i+j!=N-1 ? (s[i+j+1]>start+T):true)){
	endnum=j-1;
	if(start+T>=t[i+j])
	  tmp = rsw[i+j]-(i==0 ? 0:rsw[i-1]);
	else
	  tmp = (i+j==0 ? 0:rsw[i+j-1]) + (start+T-s[i+j]) -(i==0 ? 0:rsw[i-1]);

	break;
      }
    }
    
    MAX=max(MAX,tmp);
  }

  cout<<MAX<<endl;

  return 0;
}

Measured memory_bytes: 5604
#include <stdio.h>
int main(void){
	int n;
	scanf("%d",&n);
	int h[n];
	int i,j;
	for(i=0;i<n;i++){
		scanf("%d",&h[i]);
	}
	int ans = 1;
	int flag;
	for(i=1;i<n;i++){
		flag = 0;
		for(j=0;j<i;j++){
			if(h[i]<h[j]){
				flag = 1;
			}
		}
		if(flag==0){
			ans++;
		}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main(void)
{
	int n,m,a[1000],b[1000],c,i,j,s[1000],min,max;
	max=-1;
	scanf("%d %d",&n,&m);
	for(i=1;i<=n;i++){
		scanf("%d",&a[i]);	
		s[i]=0;
	}
	for(j=1;j<=m;j++){
		scanf("%d",&b[j]);
	}
	for(j=1;j<=m;j++){
		for(i=1;i<=n;i++){
			if(b[j]>=a[i]){
				s[i]++;
			//	printf("i= %d j= %d a=%d\n",i,j,s[i]);		
				break;
				
			}
		}
	}	
	for(i=1;i<=n;i++){
		if(max<s[i]){
			max=s[i];
			//printf("ma=%d\n",max);
			c=i;
		//	printf("a=%d\n",a[i]);
		}
	}
	printf("%d\n",c);
	return 0;
}
	

Measured memory_bytes: 1036
#include<bits/stdc++.h>
#define int long long
#define w(t) int t;cin>>t;while(t--)
#define fori(i,n) for(int i=0;i<n;i++)
#define pb push_back
#define mp make_pair
#define s second
#define f first
#define p pair<int,int>
#define vi vector<int>
#define space " "
#define endl "\n"
#define mod 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
void buildsegment(vi &arr, vi &tree, int node, int start, int end) {
	if (start == end) {
		tree[node] = arr[start];
		return;
	}
	int mid = (start + end) / 2;
	buildsegment(arr, tree, 2 * node + 1, start, mid);
	buildsegment(arr, tree, 2 * node + 2, mid + 1, end);
	tree[node] = min(tree[2 * node + 1] , tree[2 * node + 2]);
}
void updatesegment(vi &arr, vi &tree, int node, int start, int end, int idx, int val) {
	if (start == end) {
		arr[idx] = val;
		tree[node] = val;
	}
	else {
		int mid = (start + end) / 2;
		if (start <= idx && idx <= mid) {
			updatesegment(arr, tree, 2 * node + 1, start, mid, idx, val);
		}
		else {
			updatesegment(arr, tree, 2 * node + 2, mid + 1, end, idx, val);
		}
		tree[node] = min(tree[2 * node + 1] , tree[2 * node + 2]);
	}
}
int rmquery(vi &tree, int node, int start, int end, int l, int r) {
	if (l > end || start > r) {
		return INT_MAX;
	}
	if (l <= start && r >= end) {
		return tree[node];
	}
	int mid = (start + end) / 2;
	int p1 = rmquery(tree, 2 * node + 1, start, mid, l, r);
	int p2 = rmquery(tree, 2 * node + 2, mid + 1, end, l, r);
	// cout << min(p1, p2) << endl;
	return (min(p1, p2));
}
void solve() {
	int n;
	cin >> n;
	if (n % 1000 == 0) {
		cout << 0 << endl;
		return;
	}
	else {
		int ans = 1000 - (n % 1000);
		cout << ans << endl;

	}
}
int32_t main() {
#ifndef ONLINE_JUDGE
	//read input into input.txt
	freopen("input.txt", "r", stdin);
	//write output into output.txt
	freopen("output.txt", "w", stdout);
#endif
	fastio;
	// w(t) {
	// 	solve();
	// }
	solve();
	return 0;
}

Measured memory_bytes: 3620
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=1e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
const int INF=1e9+7;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}
#define trace1(x)			cerr<<#x<<": "<<x<<endl
#define trace2(x, y)			 cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)			 cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)		 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)		 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f)	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}

ll n;
ll h[100001];
ll cache[100001];

ll dp(ll x){
    if(x>n) return inf;
    if(x==n) return 0;
    ll &ans=cache[x];
    if(ans!=-1) return ans;
    ans=min(dp(x+1)+abs(h[x]-h[x+1]),dp(x+2)+abs(h[x]-h[x+2]));
    return ans;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	rep(i,1,n+1) cin >> h[i];
	mst(cache,-1);
	cout << dp(1);
	return 0;
}
/* The judge is never wrong! Your code is buggy
   Look for:
 * * Read the problem carefully.
 * * Don't forget to sort(), mod, ll!!!!
 * * Initial value = +/- infinity instead of zero!!!
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */

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

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

  ll cnt = 0;
  while (a >= b) {
    b *= 2;
    cnt++;
  }
  while (b >= c) {
    c *= 2;
    cnt++;
  }

  cout << (cnt <= k ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 3588
class SegmentTreeMax:
    def __init__(self, a):
        self.padding =  -float('inf')
        
        n = len(a)
        self.N = 2 ** (n-1).bit_length()
        self.data = [self.padding]*(self.N-1) + a + [self.padding]*(self.N-n)
        for i in range(2*self.N-2, 0, -2):
            self.data[(i-1)//2] = max(self.data[i], self.data[i-1])
    
    def update(self, idx, x):
        idx = self.N - 1 + idx
        self.data[idx] = x
        while idx:
            idx = (idx-1) // 2
            self.data[idx] = max(self.data[2*idx+1], self.data[2*idx+2])
    
    def search(self, i, j):
        if i == j:
            return self.data[self.N - 1 + i]
        else:
            idx1 = self.N-1+i
            idx2 = self.N-1+j-1
            result = self.padding
            while idx1 + 1 < idx2:
                if idx1&1 == 0: # idx1が偶数
                    result = max(result, self.data[idx1])
                if idx2&1 == 1: # idx2が奇数
                    result = max(result, self.data[idx2])
                    idx2 -= 1

                idx1 //= 2
                idx2 = (idx2 - 1)//2

            if idx1 == idx2:
                result = max(result, self.data[idx1])
            else: # idx1 + 1 == idx2
                result = max(result, self.data[idx1], self.data[idx2])

            return result


N = int(input())
H = list(map(int, input().split()))
A = list(map(int, input().split()))

dp = [0] * N
st = SegmentTreeMax(dp)

ans = 0
for h, a in zip(H, A):
  M = st.search(0, h-1)
  st.update(h-1, M + a)
  
print(st.search(0, N))

Measured memory_bytes: 121852
import math
[a,b,h,m] = [int(i) for i in input().split()]
#時:0.5　度 / 分
#分:6　度 / 分
ji = 0.5 * (h * 60 + m)
fu = 6 * m

ns = min(360 - abs(ji - fu),abs(ji - fu))
#print(ns)

print(math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(ns))))


Measured memory_bytes: 9504
#include <algorithm>
#include <cstring>
#include <iostream>
#include <limits.h>
#include <map>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
const int inf = 1 << 30;
const int INF = INT_MAX;

int n, m, x[100010], d[100010];

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for(int i = 0; i < m; ++i) {
    cin >> x[i];
  }
  sort(x, x + m);
  for(int i = 0; i < m - 1; ++i) {
    d[i] = x[i + 1] - x[i];
  }
  sort(d, d + m - 1);
  ll sum = 0;
  for(int i = 0; i < m - n; ++i) {
    sum += d[i];
  }
  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 1024