akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
/*#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2")  //Enable AVX*/

using namespace std;

using ll = long long;

#define mp make_pair

const int p = 998244353;


int mul(int a, int b) {
    return (1LL * a * b) % p;
}

int add(int a, int b) {
    int s = (a+b);
    if (s>=p) s-=p;
    return s;
}

int sub(int a, int b) {
    int s = (a+p-b);
    if (s>=p) s-=p;
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int inv(int n)
{
    return po(n, p-2);
}

/*struct DSU {
    vector<int> sz;
    vector<int> parent;

    void make_set(int v) {
        parent[v] = v;
        sz[v] = 1;
    }

    int find_set(int v) {
        if (v == parent[v])
            return v;
        return parent[v] = find_set(parent[v]);
    }

    void union_sets(int a, int b) {
        a = find_set(a);
        b = find_set(b);
        if (a != b) {
            if (sz[a] < sz[b])
                swap(a, b);
            parent[b] = a;
            sz[a] += sz[b];
        }
    }

    DSU(int n) {
        sz.resize(n);
        parent.resize(n);
        for (int i = 0; i < n; i++) make_set(i);
    }
};*/

/*const int N = 1000000;

vector<int> facs(N), invfacs(N);

void init()
{
    facs[0] = 1;
    for (int i = 1; i<N; i++) facs[i] = mul(facs[i-1], i);
    invfacs[N-1] = inv(facs[N-1]);
    for (int i = N-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1);
}

int C(int n, int k)
{
    return mul(facs[n], mul(invfacs[k], invfacs[n-k]));
}*/


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);

    int n;
    cin>>n;
    vector<pair<int, int>> x(n);
    for (int i = 0; i<n; i++)
    {
        cin>>x[i].first; x[i].first--; x[i].second = i+1;
    }
    sort(x.begin(), x.end());
    vector<int> a;
    for (int i = 0; i<n; i++)
    {
        for (int j = 0; j<x[i].second-1; j++) a.push_back(x[i].second);
    }
    for (int i = 0; i<n; i++)
    {
        for (int j = 0; j<n-x[i].second; j++) a.push_back(x[i].second);
    }

    /*for (auto it: a) cout<<it<<' ';
    cout<<endl;*/

    vector<int> A;
    int cur = 0;
    int pos = 0;

    vector<int> cnt(n+1);
    for (int i = 0; i<n; i++)
    {
        /*cout<<i<<":\n";
        cout<<x[i].first<<' '<<x[i].second<<endl;
        for (auto it: A) cout<<it<<' ';
        cout<<endl;*/
        while (pos<x[i].first)
         {
             A.push_back(a[cur]);
             cnt[a[cur]]++;
             cur++;
             pos++;
         }
         A.push_back(x[i].second);
         cnt[x[i].second]++;
         pos++;
         if (cnt[x[i].second]!=x[i].second)
         {

             cout<<"No"; return 0;
         }
    }
    while (cur<a.size())
    {
        A.push_back(a[cur]);
        cur++;
    }
    cout<<"Yes"<<endl;
    for (auto it: A) cout<<it<<' ';



}




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

using namespace std;

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

#define int ll

const ll mod = 1e9 + 7;


main(){
	int n,m;
	int a[1000];

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

	sort(a,a+n);
	reverse(a,a+n);

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

	int r = 0;
	for(int i=0;i<n;i++) if(a[i]*4*m>=sum) r++;

	if(r<m){
		cout << "No" << endl;
	}else{
		cout << "Yes" << endl;
	}

	return 0;
}


Measured memory_bytes: 3600
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

debug = True
#debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)

def solve():
    s = SI()
    t = SI()

    cnt = 0
    if s[0] == t[0]:
        cnt += 1
    if s[1] == t[1]:
        cnt += 1
    if s[2] == t[2]:
        cnt += 1
    print(cnt)

solve()

Measured memory_bytes: 3064
#include <iostream>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>

using namespace std;
using namespace __gnu_pbds;

typedef tree<pair<long long int,long long int>,null_type,less<pair<long long int,long long int> >,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

int main()
{
    int n,k;
    cin>>n>>k;
    map<int,int> h;
    for(int i=0;i<k;i++)
    {
        int d;
        cin>>d;
        for(int i=0;i<d;i++)
        {
            int x;
            cin>>x;
            h[x]++;
        }
    }
    int ans=0;
    for(int i=0;i<n;i++)
        if(h[i+1]==0)ans++;
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000000000000009
//#define INF 9223372036854775807
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl
//#define P pair<int,int>

signed main(){
    int N,K;
    cin >> N >> K;
    out(N%K==0,"0","1");
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
    string s;
    int w;

    cin >> s >> w;

    for (int n = 0; n < s.length(); n++)
        if (n % w == 0) cout << s[n];

    cout << endl;

    return 0;
}


Measured memory_bytes: 256
use std::io::Read;
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let a: i32 = iter.next().unwrap().parse().unwrap();
    let b: i32 = iter.next().unwrap().parse().unwrap();

    println!("{}", if b % a == 0 { a + b } else { b - a });
}


Measured memory_bytes: 4352
#include<iostream>
#include<string>
using namespace std;
int main(){
  int n,k;
  string str;
  cin>>n>>str>>k;

  char target=str[k-1];
  for(int i=0;i<(int)str.size();i++){
    if(str[i]!=target){
      str[i]='*';
    }
  }

  cout<<str<<endl;
  return(0);
}



Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int i = 0; i < n; i++) {
			if (sc.nextInt() % 2 == 1) {
				System.out.println("first");
				return;
			}
			
		}
		System.out.println("second");
	}
}

Measured memory_bytes: 48180
W,H,x,y,r = list(map(int, input().split()))

if W>x:
    if H>y:
        if x-r>=0:
            if y-r>=0:
                print('Yes')
            else:
                print('No')
        else:
            print('No')
    else:
        print('No')
else:
    print('No')



Measured memory_bytes: 5596
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static final long MOD = 1000000007;

	public static void main(String[] args) {
		int N = sc.nextInt();
		int M = sc.nextInt();
		char[] S = sc.next().toCharArray();
		for (int i = 0; i < N; ++i) {
			S[i] -= 'a';
		}
		final long A = 37;
		final long revA = pow(A, (int) MOD - 2);
		long hash = S[0];
		int r = 0;
		int l = 0;
		ArrayList<HashSet<Long>> sets = new ArrayList<HashSet<Long>>();
		for (int i = 0; i < N; ++i) {
			sets.add(null);
		}
		for (int i = 0; i < M; ++i) {
			String q = sc.next();
			if (q.charAt(0) == 'R') {
				if (q.charAt(1) == '+') {
					++r;
					hash *= A;
					hash += S[r];
					hash %= MOD;
				} else {
					hash += MOD - S[r];
					--r;
					hash *= revA;
					hash %= MOD;
				}
			} else {
				if (q.charAt(1) == '+') {
					hash += MOD - S[l] * pow(A, r - l) % MOD;
					++l;
					hash %= MOD;
				} else {
					--l;
					hash += S[l] * pow(A, r - l);
					hash %= MOD;
				}
			}
			if (sets.get(r - l) == null) {
				sets.set(r - l, new HashSet<Long>());
			}
			sets.get(r - l).add(hash);
		}
		int ret = 0;
		for (HashSet<Long> set : sets) {
			if (set != null) {
				ret += set.size();
			}
		}
		System.out.println(ret);
	}

	static long pow(long base, int p) {
		if (p == 0) return 1;
		if (p == 1) return base;
		long ret = pow(base, p / 2);
		ret *= ret;
		ret %= MOD;
		if (p % 2 != 0) {
			ret *= base;
			ret %= MOD;
		}
		return ret;
	}

}

Measured memory_bytes: 157528
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        char[] c1 = str.toCharArray();
        str = sc.next();
        char[] c2 = str.toCharArray();
        
        int min = 100000;
        for (int i = 0; i < c1.length - c2.length+1; i++) {
            int now = 0;
            for (int j = 0; j < c2.length; j++) {
                if (c1[j+i] != c2[j]) now++;
            }
            
            min = Math.min(min, now);
        }
        System.out.println(min);
    }
}


Measured memory_bytes: 35556
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

#define rep(i,a,b) for(auto (i)=a;i<b;i++)
#define list(i,N) for(auto (i)=0;i<N;i++)

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
#define mp make_pair
#define pb push_back

#define int ll
#define INF 1e18+5
#define mod 1000000007

int32_t main(){

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

	int N; cin >> N;
	int arr[N]; list(i,N) cin >> arr[i];
	
	int minSoFar = INF; int counter = 0;
	list(i,N){
		if(arr[i] < minSoFar){
			counter++;
			minSoFar = arr[i];
		}
	}
	
	cout << counter << "\n";
	return 0;
}


Measured memory_bytes: 1792
#define _USE_MAT_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <stack>
#include <deque>
#include <numeric>
#include <functional>
using namespace std;

#define INF 1e9
#define MOD 1000000007;//1e9+7

void solve() {
    string S, T, U;
    int A, B;
    cin >> S >> T >> A >> B >> U;
    cout << A - (S == U) << " " << B - (T == U);
}

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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <cmath>
#include <algorithm>
#include <set>
#define ll long long
#define INF 1000000000
#define MOD 1
#define SIZE 100001
using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  vector<bool>v(4);int a;
  for (int i=0; i<2; i++){
	  cin>>a;
	  v[a]=1;
  }
  for (int i=1; i<=3; i++){
	  if(!v[i]){cout<<i;break;}
  }
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;



const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;



int main() {
	int p, q, r;
	cin >> p >> q >> r;
	int sum = p + q + r;
	cout << sum - max(p, max(q, r)) << endl;

}


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

using namespace std;


int main() {
      
      int n;
  scanf("%d",&n);
  string s;
  cin>>s;
  
  int i,cnt=0;
  for(i=0;i<n-2;++i)
  {   if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')
          cnt++;
  }
  
  printf("%d",cnt);

       
     
	return 0;
}

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

typedef long long ll;

using namespace std;

#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORd(i,a,b) for(int i=a;i>=b;i--)
#define II pair <int,int>
#define fi first
#define se second

const int maxn=1e5+10;
const ll maxN=1e18+10;
const int MOD=1e9;

bool cmp(II a, II b)
{
    return a.se<b.se;
}

int main()
{
    //freopen("IN.INP","r",stdin);
    //freopen("OUT.OUT","w",stdout);
    int n;
    cin >> n;
    FOR(i,1,n) {
        int h;
        cin >> h;
        if (h%2==0){
            if (h%3!=0&&h%5!=0) {
                cout << "DENIED";
                exit(0);
            }
        }
    }
    cout << "APPROVED";
}


Measured memory_bytes: 256
def main():
    n = int(input())
    mod = 10 ** 9 + 7 #素数
    
    def modpow(x, n, mod):
        res = 1
        while n:
            if n % 2:
                res *= x % mod
                res %= mod
            x *= x % mod
            n >>= 1
        return res
 
    # 全パターン:10 ** n
    all_p = modpow(10, n, mod)
    # 0を含まないパタンーン:9 ** n
    not_0 = modpow(9, n, mod)
    # 9を含まないパターン:9 ** n
    not_9 = modpow(9, n, mod)
    # 0と９を含まないパターン:8 ** n
    not_0_9 = modpow(8, n, mod)
    # 条件のパターン
    ans = (all_p - not_0 - not_9 + not_0_9) % mod
    print(ans)
 
if __name__ == '__main__':
    main()


Measured memory_bytes: 9140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
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; }
int main(){
    string s; cin>>s;
    while(true){
        ll n=s.size();
        if(n>=5 && s.substr(n-5, 5)=="dream"){
            s=s.substr(0,n-5);
        }else if(n>=7 && s.substr(n-7, 7)=="dreamer"){
            s=s.substr(0,n-7);
        }else if(n>=5 && s.substr(n-5, 5)=="erase"){
            s=s.substr(0,n-5);
        }else if(n>=6 && s.substr(n-6, 6)=="eraser"){
            s=s.substr(0,n-6);
        }else{
            break;
        }
    }
    if(s.size()==0) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
     
    using namespace std;
     
    int main()
    {
    	
        int n;
        cin>>n;
        vector<long> a(n);
        vector<long> b(n);
        vector<long> c(n);
        for(int i=0;i<n;i++){
        	cin>>a[i]>>b[i]>>c[i];
		}
        long dp[n][3];
        dp[0][0]=a[0];
        dp[0][1]=b[0];
        dp[0][2]=c[0];
        for(int i=1;i<n;i++){	
		  dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
		  dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];
		  dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c[i];
		}
		long val=max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
		cout<<val<<endl;
		return 0;
    }

Measured memory_bytes: 8004
from fractions import gcd

def my_count(a, b, num): #区間[a, b]におけるnumの倍数の個数
  return b//num - (a-1)//num

a, b, c, d = map(int, input().split())
lcm = c * d // gcd(c, d)
print(b - a + 1 - (my_count(a, b, c)+my_count(a, b, d)-my_count(a, b, lcm)))

Measured memory_bytes: 5048
// #include {{{
#include <array>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <tuple>
#include <utility>
#include <random>
#include <limits>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cstdint>
#include <cassert>
// }}}

using namespace std;

// macros {{{
template<typename T, size_t N>
constexpr size_t NELEMS(T (&)[N]) { return N; }

template<typename InputIt>
void PRINT_RANGE(InputIt first, InputIt last)
{
    for(; first != last; ++first)
        cout << *first << (first==last ? "" : " ");
    cout << "\n";
}

template<typename T>
void PRINT_MATRIX(T mat, size_t nr, size_t nc)
{
    for(size_t r = 0; r < nr; ++r) {
        for(size_t c = 0; c < nc; ++c) {
            cout << mat[r][c] << (c==nc-1 ? "" : " ");
        }
        cout << "\n";
    }
}

#define FOR(i, start, end) for(int i = (start); i < (end); ++i)
#define REP(i, n) FOR(i, 0, n)
// }}}

// types {{{
using ll  = long long;
using ull = unsigned long long;
// }}}

ll N, A, B;

void solve()
{
    if(A > B) {
        cout << 0 << "\n";
        return;
    }

    if(N == 1) {
        ll ans = (A == B ? 1 : 0);
        cout << ans << "\n";
        return;
    }

    if(N == 2) {
        cout << 1 << "\n";
        return;
    }

    ll ans = (N-2)*B - (N-2)*A + 1;
    cout << ans << "\n";
}

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

    solve();

    return 0;
}


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

ll X, Y;

ll grundy(ll a, ll b){
  return abs(a - b) <= 1 ? 0 : 1;
  set<ll> V;
  if(a == 0 && b <= 1) return 0;
  if(a <= 1 && b <= 0) return 0;

  for(ll i = 2; i <= a; i+=2){
    V.insert(grundy(a-i, b+i/2));
  }
  for(ll i = 2; i <= b; i+=2){
    V.insert(grundy(a+i/2, b-i));
  }

  ll g = 0;
  while(V.count(g)) g++;
  return g;
}

int main(void){
  cin >> X >> Y;


  /*
  cout << "\\ | 0 1 2 3 4 5 6 7 8 9" << endl;
  cout << "------------------------" << endl;
  for(int a = 0; a < 10; a++){
    cout << a << " | ";
    for(int b = 0; b < 10; b++){
      cout << grundy(a, b) << " ";
    }
    cout << endl;
  }
  return 0;
  */

  ll g = grundy(X, Y);
  
  if(g == 0){
    cout << "Brown" << endl;
  }else{
    cout << "Alice" << endl;
  }
}


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


int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    for(int i = 0;i < n; i++){
        cin >> v[i];
    }
    bool f = false;
    int memo = v[0];
    for(int i = 1; i < n; i++){
        if(v[i] < memo-1){f = true; break;}
        if(v[i] > memo){memo = v[i];}
    }
    if(f){cout << "No" << endl;}
    else{cout << "Yes" << endl;}
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <iomanip>
#include <string>
using namespace std;

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

	vector<string> s(N);

	for (int i = 0; i < N; ++i) {
		cin >> s.at(i);
	}

	int k = 0;

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

	for (int i = 0; i < N-1; ++i) {
		if (s.at(i) == s.at(i + 1)) { ++k; }

	}

	cout << N-k << endl;

}

Measured memory_bytes: 9600
import sys
input = sys.stdin.readline

H,W = (int(x) for x in input().split())
S = [list(input()) for _ in range(H)]
memh = [[0] * W for _ in range(H)]
memv = [[0] * W for _ in range(H)]
ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == '.':
            h = memh[i][j]
            if h == 0:
                stopped = False
                for k in range(W-j-1):
                    if S[i][j+k+1] == '#':
                        for l in range(k+1):
                            memh[i][j+l] = k+1
                        stopped = True
                        break
                if stopped == False:
                    for l in range(W-j):
                        memh[i][j+l] = W-j
                h = memh[i][j]
            v = memv[i][j]
            if v == 0:
                stopped = False
                for k in range(H-i-1):
                    if S[i+k+1][j] == '#':
                        for l in range(k+1):
                            memv[i+l][j] = k+1
                        stopped = True
                        break
                if stopped == False:
                    for l in range(H-i):
                        memv[i+l][j] = H-i
                v = memv[i][j]
            ans = max(ans,h+v-1)
print(ans)

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

void BubbleSort(void);
void SelectionSort(void);

int n;

typedef struct{
  char kind;
  int value;
}array;

array C[36],B[36],S[36],temp;

int main(){
  int i;

  scanf("%d",&n);

  if(n>=1 && n<=36){
    for (i=0; i<n; i++){
      scanf(" %c",&C[i].kind);
      scanf("%d",&C[i].value);
      B[i] = S[i] = C[i];
    }
    BubbleSort();
    SelectionSort();
  }

  return 0;
}

void BubbleSort(void)
{
  int i,j,a,b;
  int jud=1;

  for (i=0; i<n; i++){
    for (j=n-1; j>0; j--){
      if (B[j].value < B[j-1].value){
        temp = B[j-1];
        B[j-1] = B[j];
        B[j] = temp;
      }
    }
  }

  for (i=0; i<n-1; i++) printf("%c%d ",B[i].kind,B[i].value);
  printf("%c%d\n",B[i].kind,B[i].value);

  for(i=0; i<n; i++){
    for(j=i+1; j<n; j++){
      for(a=0; a<n; a++){
        for(b=a+1; b<n; b++){
          if (C[i].value == C[j].value){
            if ((C[i].value == B[b].value) && (C[i].kind == B[b].kind)){
              if ((C[j].value == B[a].value) && (C[j].kind == B[a].kind))
                jud = 0;
            }
          }
        }
      }
    }
  }

  if (jud == 0) printf("Not stable\n");
  if (jud == 1) printf("Stable\n");
}

void SelectionSort(void)
{
  int i,j,minj,a,b,jud=1;

  for (i=0; i<n; i++){
    minj = i;
    for (j=i; j<n; j++){
      if (S[j].value < S[minj].value){
        minj = j;
      }
    }
    if (minj != i){
      temp = S[i];
      S[i] = S[minj];
      S[minj] = temp;
    }
  }
  for (i=0; i<n-1; i++) printf("%c%d ",S[i].kind,S[i].value);
  printf("%c%d\n",S[i].kind,S[i].value);

  for(i=0; i<n; i++){
    for(j=i+1; j<n; j++){
      for(a=0; a<n; a++){
        for(b=a+1; b<n; b++){
          if (C[i].value == C[j].value){
            if ((C[i].value == S[b].value) && (C[i].kind == S[b].kind)){
              if ((C[j].value == S[a].value) && (C[j].kind == S[a].kind))
                jud = 0;
            }
          }
        }
      }
    }
  }

  if (jud == 0) printf("Not stable\n");
  if (jud == 1) printf("Stable\n");
}


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

int main(void){

    unsigned long long int X;
    unsigned long long int deposit=100; 
    unsigned long long int k=0;

    cin >> X;

    while(deposit < X){
        deposit *= 1.01;
        k++;
    }

    cout << k << endl;

    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#define ll long long
using namespace std;
const int N=510,MX=1e7;
int p[250010];
int vis[MX];
ll rec[N][N];
int n,m,cnt;
void prework(int n){
	vis[1]=false;
	int cnt=0;
	for (int i=2;cnt<n;++i){
		if (!vis[i])
			p[++cnt]=i;
		for (int j=1;j<=cnt&&i*p[j]<MX;++j){
			vis[i*p[j]]=1;
			if (i%p[j]==0) break;
		}
	}
}
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
ll lcm(ll x,ll y){
	if (!x||!y) return x+y;
	return x/gcd(x,y)*y;
}
void solve(){
	for (int i=1;i<=n;++i)
		for (int j=1;j<=n;++j)
			if ((i+j)%2==0)
				rec[i][j]=1LL*p[(i+j)/2]*p[n+(i-j)/2+(n+1)/2];
	for (int i=1;i<=n;++i)
		for (int j=1;j<=n;++j)
			if (!rec[i][j])
				rec[i][j]=lcm(lcm(rec[i-1][j],rec[i][j+1]),lcm(rec[i+1][j],rec[i][j-1]))+1;
}
 
int main(){
#ifndef ONLINE_JUDGE
	//freopen("a.in","r",stdin);
#endif
	ll tmp;
	scanf("%d",&n);
	if (n==2){
		printf("%d %d\n%d %d\n",4,7,23,10);
		return 0;
	}
	prework(n*n);
	solve();
	for (int i=1;i<=n;++i){
		for (int j=1;j<=n;++j)
			printf("%lld ",rec[i][j]);
		printf("\n");
	}
}

Measured memory_bytes: 45184
days = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT', 'NEXT_SUN'] #末尾までどのくらい遠いか

today_day = input()
today_index = days.index(today_day)
nextsun_index = days.index('NEXT_SUN')
print(nextsun_index - today_index)

Measured memory_bytes: 2940
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    int a = n%10;
    int b = (n - a) / 10;

    if(a == 9 || b == 9) {
        cout << "Yes";
    }
    else {
        cout << "No";
    }
    
    cout << endl;
    return 0;
}

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

inline double inp(pair<double, double> a, pair<double, double> b) {
    return a.first * b.first + a.second * b.second;
}
bool cmp(pair<double, double> a, pair<double, double> b) {
    return atan2(a.second, a.first) > atan2(b.second, b.first);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    int n;
    cin >> n;
    vector<pair<double, double>> z(n);
    rep(i, 0, n) cin >> z[i].first >> z[i].second;
    sort(z.begin(), z.end(), cmp);

    double ans = 0;
    rep(i, 0, n) {
        double s = 0, t = 0;
        rep(j, 0, n) {
            int k = (i + j) % n;
            s += z[k].first;
            t += z[k].second;
            ans = max(ans, sqrt(s * s + t * t));
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <stack>
#include <climits>
#include <deque>
#include <bitset>
#include <cassert>
#include <ctime>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
const int dy[]={-1,0,1,0},dx[]={0,1,0,-1};
// adjust problem by problem
const double EPS=1e-8;
const double PI=acos(-1.0);
#ifdef __GNUC__
int popcount(int n){return __builtin_popcount(n);}
int popcount(ll n){return __builtin_popcountll(n);}
#endif
#ifndef __GNUC__
template<class T> int popcount(T n){int cnt=0;while(n){if(n%2)cnt++;n/=2;}return cnt;}
#endif
template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T> void PrintSeq(T &a,int sz){for(int i=0;i<sz;i++){cout<<a[i];if(sz==i+1)cout<<endl;else cout<<' ';}}
bool EQ(double a,double b){return abs(a-b)<EPS;}
void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}
vector<string> split(string str,char del){
  vector<string> res;
  for(int i=0,s=0;i<SIZE(str);i++){
    if(str[i]==del){if(i-s!=0)res.push_back(str.substr(s,i-s));s=i+1;}
    else if(i==SIZE(str)-1){res.push_back(str.substr(s));}
  }
  return res;
}

/*
  A->0
  X->1
  Y->2
  Z->3
  W->4
  B->5
 */
vector<int> G[10];
int main(){

  G[0].push_back(1);
  G[0].push_back(2);
  G[1].push_back(-1);
  G[1].push_back(3);
  G[2].push_back(1);
  G[2].push_back(-1);
  G[3].push_back(4);
  G[3].push_back(5);
  G[4].push_back(5);
  G[4].push_back(2);
  G[5].push_back(2);
  G[5].push_back(1);
  string s;
  while(cin>>s&&s!="#"){
    int now=0;
    for(int i=0;i<(int)s.size();i++){
      now=G[now][s[i]-'0'];
      if(now==-1)break;
    }
    if(now!=5)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<class F>auto recursive(F f){return[f](auto...a){return f(f,a...);};}
template<class T>using rev_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<class T>using vector2d=vector<vector<T>>;
struct fixprec{int p;fixprec(int p):p(p){}}; ostream&operator<<(ostream&o,fixprec f){return o<<fixed<<setprecision(f.p);}
/*!* [union_find] *!*/
/*+* UnionFind 木 *+*/
// T (typename) : グラフの頂点を表す型, (int)parent を持つ必要あり
template <typename T>
struct UnionFind {
    vector<T> &u;
    UnionFind(vector<T> &u) : u(u) {
        for (int i = 0; i < u.size(); i++) {
            u[i].parent = i;
            u[i].sz = 1;
        }
    }
    int root(int x) {
        if (x < 0 || u.size() <= x) return -1;
        else if (x == u[x].parent) return x;
        else return u[x].parent = root(u[x].parent);
    }
    bool connect(int a, int b) {
        a = root(a), b = root(b);
        bool retval = a != b;
        if (retval) {
            u[a].sz += u[b].sz;
        }
        u[b].parent = a;
        return retval;
    }
};

struct Node {
    int parent;
    int sz;
};

int main() {
    int N, M;
    cin >> N >> M;
    vector<Node> v(N);
    UnionFind<Node> uf(v);
    for(int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        uf.connect(a, b);
    }
    int ans = 1;
    for(int i = 0; i < N; i++) {
        ans = max(ans, v[uf.root(i)].sz);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5092
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    int N;
    cin >> N;
    ll A[3*N];
    REP(i,3*N) cin >> A[i];

    vector<ll> sumL(N+1,0);
    priority_queue<ll, vector<ll>, greater<ll>> qL;
    REP(i,N){qL.push(A[i]); sumL[0]+=A[i];}
    REP(i,N){
        ll push = A[N+i];
        qL.push(push);
        ll pop = qL.top();
        qL.pop();
        sumL[i+1] = sumL[i] + push - pop;
    }

    vector<ll> sumR(N+1,0);
    priority_queue<ll> qR;
    REP(i,N){qR.push(A[3*N-1-i]); sumR[N]+=A[3*N-1-i];}
    REP(i,N){
        ll push = A[2*N-1-i];
        qR.push(push);
        ll pop = qR.top();
        qR.pop();
        sumR[N-1-i] = sumR[N-i] + push - pop;
    }
    ll ans = -1000000000000000000;
    REP(i,N+1) chmax(ans, sumL[i] - sumR[i]);
    cout << ans << endl;
    return 0;
}

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

int main(){
  double n,t,a;
  cin >> n >> t >> a;
  double h,min;
  int number = 1;
  cin >> h;
  min = abs(a-(t-h*0.006));
  for(int i=1;i<n;i++){
    cin >> h;
    if(min > abs(a-(t-h*0.006))) {
      min = abs(a-(t-h*0.006));
      number = i+1;
    }
  }
  cout << number << endl;
  return 0;
}


Measured memory_bytes: 256
#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>;
const int Max_N=1e4;

int main(){
	int N;
	cin >> N;
	vector<int> ans(N+1);
	for(int x=1; x<100; x++){
		for(int y=1; y<100; y++){
			for(int z=1; z<100; z++){
				int s=x*x+y*y+z*z+x*y+y*z+z*x;
				if(s>N) continue;
				ans[s]++;
			}
		}
	}
	rep(i,N) cout << ans[i+1] << endl;

	return 0;
}

Measured memory_bytes: 3636
s = input()
abc = {"a":0,"b":0,"c":0,"d":0,"e":0,"f":0,"g":0,"h":0,"i":0,"j":0,"k":0,"l":0,"m":0,"n":0,"o":0,"p":0,"q":0,"r":0,"s":0,"t":0,"u":0,"v":0,"w":0,"x":0,"y":0,"z":0}
for i in range(len(s)):
    abc[s[i]]+=1
alle = True
for i in abc:
    if abc[i] == 0:
        print(i)
        alle = False
        break
if alle:
    print("None")

Measured memory_bytes: 39280
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef queue<ll> qi;
int main()
{
	int s,w;
	cin>>s>>w;
	if(w>=s)
		cout<<"unsafe\n";
	else
		cout<<"safe\n";
	return 0;
}

Measured memory_bytes: 3596
N,M=map(int,input().split())
from heapq import heappop,heappush 

graph=[[] for _ in range(N)]
for _ in range(M):
    A,B=map(int,input().split())
    A,B=A-1,B-1
    graph[A].append(B)
    graph[B].append(A)

mark=[-1]*(N-1)

inf=float("inf")

di=[inf]*N
di[0]=0
hq=[(0,0)]

while hq:
    t,r=heappop(hq) #time room
    if t>di[r]:
        continue
    for x in graph[r]:
        t_new=t+1
        r_new=x
        if t_new<di[r_new]:
            di[r_new]=t_new
            heappush(hq,(t_new,r_new))
            if mark[r_new-1]==-1:
                mark[r_new-1]=r
    
print("Yes")
for i in mark:
    print(i+1)


Measured memory_bytes: 38724
from collections import deque

n,k=map(int,input().split())
p=list(map(int,input().split()))+[1000000]

p1=[0]*(n)
pmin=[0]*(n+1)
pmax=[0]*(n+1)

cnt=0

for i in range(n-1):
  if p[i]<p[i+1]:
    cnt+=1
  else:
    cnt=0
  p1[i+1]=cnt

d=deque()
d.append(0)

for i in range(1,k+1):
  if p[d[-1]]<p[i]:
    d.append(i)
  else:
    try:
      while p[d[-1]]>p[i]:
        d.pop()
    except:
      pass
    d.append(i)
pmin[k]=p[d[0]]

for i in range(k+1,n):
  if d[0]==i-(k+1):
    d.popleft()
  if p[d[-1]]<p[i]:
    d.append(i)
  else:
    try:
      while p[d[-1]]>p[i]:
        d.pop()
    except:
      pass
    d.append(i)
  pmin[i]=p[d[0]]


dd=deque()
dd.append(0)

for i in range(1,k+1):
  if p[dd[-1]]>p[i]:
    dd.append(i)
  else:
    try:
      while p[dd[-1]]<p[i]:
        dd.pop()
    except:
      pass
    dd.append(i)
pmax[k]=p[dd[0]]

for i in range(k+1,n):
  if dd[0]==i-(k+1):
    dd.popleft()
  if p[dd[-1]]>p[i]:
    dd.append(i)
  else:
    try:
      while p[dd[-1]]<p[i]:
        dd.pop()
    except:
      pass
    dd.append(i)
  pmax[i]=p[dd[0]]

ans=n-k+1
f=1
ff=[0]*n
for i in range(n):
  if p1[i]>=k-1:
    ff[i]=1
    if f==0:
      ans-=1
    else:
      f=0

for i in range(n-k):
  if p[i]==pmin[i+k] and p[i+k]==pmax[i+k] and ff[i+k]==0:
    ans-=1

print(ans)




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

int main()
{
  int r,c,e[100][100];
  int i,j;
  int sum1,sum2[100],sum3;
  cin >> r >> c;
  sum3=0;
  
  for(i=0;i<r;i++){
    sum1=0;
    for(j=0;j<c;j++){
      if(i==0){
	sum2[j]=0;
      }
      cin >> e[i][j];
      sum1=sum1+e[i][j];
      sum2[j]=sum2[j]+e[i][j];
      cout << e[i][j] << " ";
    }
    cout << sum1 <<endl;
  }
  
  for(int k=0;k<c;k++){
    cout << sum2[k] << " ";
    sum3=sum3+sum2[k];
  }
  cout << sum3 << endl;
  
  return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <list>
#include <map>
using namespace std;

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

int main(void){
  int a,b,c;
  cin >> a >> b >> c;
  int K;
  cin >> K;
  int ans = max(a,max(b,c));
  int _ans = ans;
  for(int i = 0; i < K; i++){
    ans *= 2;
  }
  cout << a+b+c+ans-_ans << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;


    void solve()
    {
        int N = cin.nextint;
        var A = cin.scanint;
        var B = cin.scanint;
        var C = cin.scanint;
        Array.Sort(A);
        Array.Sort(B);
        Array.Sort(C);

        var BB = new long[N];
        for (int i = 0; i < N; i++)
        {
            BB[i] =  N - upper_bound(C, B[i]);
        }
        for (int i = 1; i < N; i++)
        {
            int k = N - i - 1;
            BB[k] += BB[k + 1];
        }
        long ans = 0;
        for (int i = 0; i < N; i++)
        {
            int b = upper_bound(B, A[i]);
            if (b == N) break;
            ans += BB[b];
        }
        WriteLine(ans);

    }

    int upper_bound(int[] arr, int val)
    {
        int low = 0, high = arr.Length;
        int mid;

        while (low < high)
        {
            mid = ((high - low) >> 1) + low;
            if (arr[mid] <= val) low = mid + 1;
            else high = mid;
        }
        return low;
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 34280
IDENTIFICATION DIVISION.
PROGRAM-ID. PROGRAM_ID.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 ln         PIC X(30).
01 A          PIC 9(10).
01 B          PIC 9(10).
01 ans        PIC 9(10).
01 zs         PIC Z(9)9.

PROCEDURE DIVISION.
  ACCEPT ln.
  UNSTRING ln DELIMITED BY SPACE INTO A B.
  IF 2 * B < A THEN
    COMPUTE ans = A - 2 * B
    MOVE ans TO zs
    DISPLAY FUNCTION TRIM(zs)
  ELSE
    DISPLAY 0
  END-IF.
  STOP RUN.


Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<pair<ll, ll>> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i].first >> a[i].second;
    }
    sort(a.begin(), a.end(), [&](pair<ll, ll> i, pair<ll, ll> j) {
        if (i.first + i.second == j.first + j.second) {
            return i.first < j.first;
        }
        return i.first + i.second < j.first + j.second;
    });
    ll inf = 1e18;
    vector<ll> dp(n + 1, inf);
    dp[0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i; j >= 0; j--) {
            if (dp[j] <= a[i].first) {
                dp[j + 1] = min(dp[j + 1], dp[j] + a[i].second);
            }
        }
    }
    for (int i = n; i >= 0; i--) {
        if (dp[i] != inf) {
            cout << i << '\n';
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3736
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
static const int INF = 1ll<<60;
typedef pair<int,int> PII;
typedef pair<int,pair<int,int> > PPII;

struct edge{
    int cost;
    int to;
    edge(){}
    edge(int p1,int p2){
        to=p1;
        cost=p2;
    }
};

int N,M;
int H[100005];
int T[100005];
int X;
int dist[100005];
int dh[100005];
vector<edge> V[100005];

void dijkstra(){
    fill(dist,dist+100005,INF);
    priority_queue<PPII,vector<PPII>,greater<PPII> > que;
    que.push(PPII(0,PII(0,X)));
    dist[0]=0;
    while(!que.empty()){
        PPII p = que.top();
        que.pop();
        int v=p.SE.FI;
        if(dist[v]<p.FI)continue;
        for(int i=0;i<V[v].size();++i){
            if(H[v]-V[v][i].cost<0)continue;
            int to = V[v][i].to;
            int h=p.SE.SE;
            int d=V[v][i].cost;
            if(h-d>H[to]){
                int t=h-d-H[to];
                d+=t;
                h-=t;
            }
            else if(h-d<0){
                d+=abs(p.SE.SE-V[v][i].cost);
                h+=abs(p.SE.SE-V[v][i].cost);
            }
            if(h<0||h>H[v])continue;
            if(h<V[v][i].cost||h-V[v][i].cost>H[to])continue;
            if(dist[to]>dist[v]+d){
                dist[to]=dist[v]+d;
                dh[to]=h-V[v][i].cost;
                que.push(PPII(dist[to],PII(to,h-V[v][i].cost)));
            }
        }
    }
}


signed main(){
    cin>>N>>M>>X;
    for(int i=0;i<N;++i)cin>>H[i];
    for(int i=0;i<M;++i){
        int a,b,c;
        cin>>a>>b>>c;
        a--;
        b--;
        V[a].PB(edge(b,c));
        V[b].PB(edge(a,c));
    }
    dijkstra();
    if(dist[N-1]>=INF)cout<<-1<<endl;
    else cout<<dist[N-1]+H[N-1]-dh[N-1]<<endl;
}

Measured memory_bytes: 24640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, p[200005] = {}, d[200005] = {}, c[200005] = {};
    bool b[200005] = {};
    vector<int> g[200005] = {}, a;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> p[i], g[p[i]].push_back(i), d[p[i]]++;
    queue<int> q;
    for (int i = 1; i <= n; i++) if (!d[i]) q.push(i);
    while (!q.empty()) {
        int x = q.front();
        q.pop();
        vector<int> e = {-1};
        for (int i : g[x]) e.push_back(c[i]);
        sort(e.begin(), e.end());
        for (int i = 1; i <= e.size(); i++) {
            if (i == e.size()) c[x] = e.back() + 1;
            else if (e[i] - e[i - 1] >= 2) {
                c[x] = e[i - 1] + 1;
                break;
            }
        }
        b[x] = 1;
        d[p[x]]--;
        if (!d[p[x]]) q.push(p[x]);
    }
    for (int i = 1; i <= n; i++) if (!b[i]) {
        a.push_back(i);
        int x = p[i];
        while (x != i) a.push_back(x), x = p[x];
        break;
    }
    if (a.empty()) {cout << "POSSIBLE"; return 0;}
    vector<int> m;
    for (int i : a) {
        vector<int> e = {-1};
        for (int j : g[i]) if (b[j]) e.push_back(c[j]);
        sort(e.begin(), e.end());
        for (int j = 1; j <= e.size(); j++) {
            if (j == e.size()) m.push_back(e.back() + 1);
            else if (e[j] - e[j - 1] >= 2) {
                m.push_back(e[j - 1] + 1);
                break;
            }
        }
    }
    int w = m[0];
    for (int i = 1; i < a.size(); i++) {
        if (w == m[i]) w = m[i] + 1;
        else w = m[i];
    }
    if (w != m[0]) {
        cout << "POSSIBLE";
        return 0;
    }
    w = m[0] + 1;
    for (int i = 1; i < a.size(); i++) {
        if (w == m[i]) w = m[i] + 1;
        else w = m[i];
    }
    if (w == m[0]) cout << "POSSIBLE";
    else cout << "IMPOSSIBLE";
}


Measured memory_bytes: 15032
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#include<bits/stdc++.h>
using namespace std;

#if defined(DAIJOBU)
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif

#define fi first
#define se second
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef long double ld;

int main(){
	FIO
	
	string s;cin >> s;
	int c1 = 0, c2 = 0;
	forn(i, s.size())if(s[i] == 'A')c1++;else c2++;
	if((c1 == 2 && c2 == 1) || (c2 == 2 && c1 == 1))puts("Yes");
	else puts("No");
	return 0;
}



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

// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
#define PI (2*acos(0.0))
#define EPS (1e-9)
#define MOD (int)(1e9+7)
#define INF numeric_limits<int>::infinity()
#pragma endregion


int main()
{
    string s;
    while(cin>>s) {
        int flag = 0;
        string ans = "";
        int repeat = 0;
        for (char c : s) {
            if (flag==0) {
                if (c!='@') ans += c;
                else flag = 1;
            } else {
                if (flag==1) {
                    repeat = c - '0';
                    flag = 2;
                } else {
                    rep(i,repeat) ans += c;
                    flag = 0;
                }
            }
        }
        P(ans);
    }
    return 0;
}

Measured memory_bytes: 3136
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;

int h[100010];

int main(){
    int n, k;
    cin >> n >> k;
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
    sort(h, h+n);

    int min = 1 << 30;
//    for(int i = 0; i < n;i++){
//        cout << h[i] << " ";
//    }

    for(int i = 0; i <= n-k; i++){
        if(min > h[i+k-1]-h[i]){
            min = h[i+k-1]-h[i];
        }
    }

    cout << min << endl;

    return 0;
}


Measured memory_bytes: 640