akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define ENDL cout << endl;
using namespace std;
using LL = long long;
using LD = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using PLL = pair<LL, LL>;
using VPLL = vector<PLL>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
const LL INF = 1e14;
const LL MOD = 1e9 + 7;

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()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  VPII a(n);
  REP(i, n)
  {
    int in;
    cin >> in;
    a[i] = {in, i+1};
  }
  SORT(a);
  REPx(x, a) cout << x.second << " ";
  ENDL

  return 0;
}

Measured memory_bytes: 1664
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
    string pst;
    cin >> pst;
    int n;
    cin >> n;
    int res = 0;
    for (int i = 0; i<n; ++i) {
        string str, str2;
        cin >> str;
        str2 = str + str;
        if (str2.find(pst) != -1)res++;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3176
#include<stdio.h>
int main()
{
	int S, h, a, m, s;
	    scanf("%d",&S);
		h = S / 3600;
		a = S % 3600;
		m = a / 60;
		s = a % 60;

		printf("%d:%d:%d\n", h, m, s);

		return 0;

}


Measured memory_bytes: 2724
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;
#define N 26

int main(){
 ll d;
 cin>>d;
 ll c[N];
 for(ll i=0;i<N;i++)cin>>c[i];
 ll s[d][N];
 for(ll i=0;i<d;i++)for(ll j=0;j<N;j++)cin>>s[i][j];

 vector<ll> t(d);
 vector<ll> last(N,0);
 for(ll i=0;i<d;i++){
  cin>>t[i];
 }
 ll sum = 0;
 for(ll i=0;i<d;i++){
  sum += s[i][t[i]-1];
  last[t[i]-1] = i+1;
 // ll sum2 = sum;
  //if( i == d-1){
   for(ll j=0;j<N;j++) sum -= (i+1-last[j])*c[j];
  //}
  cout<<sum<<endl;
 }


    return 0;
}


Measured memory_bytes: 3672
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int A=sc.nextInt(),B=sc.nextInt();
int wa=A+B;
int sa=A-B;
int seki=A*B;
int max=0;
if(wa>=seki&&wa>=sa){max=wa;}
if(sa>=wa&&sa>=seki){max=sa;}
if(seki>=wa&&seki>=sa){max=seki;}
System.out.println(max);
}
}

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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

signed main()
{
  int A, P;
  cin >> A >> P;
  cout << (3*A + P)/2 << endl;
  return 0;
}

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

int main() {
  long long int T[2];
  long long int A[2];
  long long int B[2];
  
  cin >> T[0] >> T[1];
  cin >> A[0] >> A[1];
  cin >> B[0] >> B[1];
  
  long long int count = 0;
  if (A[0]*T[0] + A[1]*T[1] == B[0]*T[0] + B[1]*T[1])
    cout << "infinity" << endl;
  else if ((A[0]*T[0] >= B[0]*T[0] && A[0]*T[0] + A[1]*T[1] >= B[0]*T[0] + B[1]*T[1]) || (A[0]*T[0] <= B[0]*T[0] && A[0]*T[0] + A[1]*T[1] <= B[0]*T[0] + B[1]*T[1]))
    cout << 0 << endl;
  else {
  	long long int zentai_sabun = abs(A[0]*T[0] + A[1]*T[1] - (B[0]*T[0] + B[1]*T[1]));
    long long int sabun0 = abs(B[0]*T[0] - A[0]*T[0]);
    count += floor(sabun0 / (double)zentai_sabun) * 2;
    if (sabun0 % zentai_sabun != 0)
      count++;
    cout << count << endl;
  }
}

Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;

#[fastout]
fn main() {
    input!{
        S: Chars,
    }
    
    if S[0] != 'A' {
        println!("WA")
    } else {
        let mut c_num = 0;
        let mut not_small = 0;
        for i in 1..S.len() {
            if i == 1 || i == S.len() - 1 {
                if !S[i].is_lowercase() {
                    not_small += 1;
                }
            } else {
                if S[i] == 'C' {
                    c_num += 1;
                } else {
                    if !S[i].is_lowercase() {
                        not_small += 1
                    }
                }
            }
        }

        if c_num == 1 && not_small == 0 {
            println!("AC")
        } else {
            println!("WA")
        }
    }

    println!("", );
}


Measured memory_bytes: 2180
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;

int main(){
    string s;cin >> s;
    bool ok = true;
    string t = s;
    reverse(all(t));
    ll n = s.size();
    rep(i,n)if(s[i] != t[i])ok = false;
    string front = s.substr(0,(n-1)/2);
    string front_r = front;
    reverse(all(front_r));
    rep(i,front.size())if(front[i] != front_r[i])ok = false;
    string back = s.substr(((n+3)/2) - 1, (n-1)/2);
    string back_r = back;
    reverse(all(back_r));
    rep(i,back.size())if(back[i] != back_r[i])ok = false;

    cout << (ok ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  char a[10001];
  scanf("%c",&a[0]);
  if(a[0]>=97&&a[0]<=122){
  	printf("a\n");
  }
  if(a[0]>=65&&a[0]<=90){
  	printf("A\n");
  }
  return 0;
}

Measured memory_bytes: 1588
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define dump(x)  cout << #x << " = " << (x) << endl;

#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
//             0123456789 - digits. check the limits, int vs long
const int MX = 100001;



int fak(int n) {
    if (n == 0) return 1;
    if (n == 1) return 1;
    ll x = 1;
    for (int i = 1; i < n + 1; i++) {
        x *= i;
        x %= MOD;
    }
    return x % MOD;
}

int powMod(int numb, int degree) {
    if (degree == 0) return 1;
    if (degree == 1) return numb;
    ll temp = powMod(numb, degree / 2);
    temp = (temp * temp)%MOD;
    if (degree & 1) {
        return ((temp * numb) % MOD);
    } else return (temp % MOD);
}

int revElement(int x) {
    return powMod(x, MOD - 2) % MOD;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(0);
    cout << std::fixed;
    //  freopen("ex.in","r",stdin);
    // freopen("ex.out","w",stdout);
    int x, y;
    cin >> x >> y;
    if (x < y) swap(x, y);
    if ((x + y) % 3 != 0 || 2*y < x) {
        cout << 0 << "\n";
        return 0;
    }
    int p = 2*y - x;
    p /= 3;
    int q = 2*x - y;
    q /= 3;

    // dump(p + q);
    ll fakpq = fak(p + q);

    ll revp = revElement(fak(p));
    ll revq = revElement(fak(q));
    // dump(revp);
    // dump(fak(p));
    

    ll ans = 1;
    ans = (ans * fakpq * revp) % MOD;
    ans = (ans * revq) % MOD;
    cout << ans % MOD << "\n";
    return 0;
}

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

using namespace std;

void test()
{
    long long int n;
    cin>>n;

    vector<char>vec;

    while(n)
    {
        n--;

        vec.push_back((char)(97+n%26));
        n/=26;
    }

    for(int i=vec.size()-1;i>=0;i--)
        cout<<vec[i];

}

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

    test();

    return 0;
}


Measured memory_bytes: 3660
#include <algorithm>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define REP(i, m, n) for (int i = int(m); i < int(n); i++)
#define RREP(i, m, n) for (int i = int(n) - 1; i >= int(m); --i)
#define EACH(i, c) for (auto &(i) : c)
#define all(c) begin(c), end(c)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(begin(c), end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x) cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s)                                                               \
    do {                                                                       \
    } while (0)
#define dump(x)                                                                \
    do {                                                                       \
    } while (0)
#define BR
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int, int>;
using VP = vector<PII>;

constexpr LL INF = 1LL << 60;

void solve() {
    int n;
    cin >> n;
    VVLL a(n, VLL(n)), b(n, VLL(n));
    REP(i, 0, n) REP(j, 0, n) cin >> a[i][j];
    REP(i, 0, n) REP(j, 0, n) b[i][j] = a[i][j];
    REP(k, 0, n) REP(i, 0, n) REP(j, 0, n) {
        if (i == j || i == k || j == k)
            continue;
        if (b[i][j] > b[i][k] + b[k][j]) {
            cout << -1 << endl;
            return;
        }
        if (b[i][j] == b[i][k] + b[k][j]) {
            a[i][j] = INF;
        }
    }
    LL ans = 0;
    REP(i, 0, n) REP(j, 0, n) if (a[i][j] == b[i][j]) ans += a[i][j];
    cout << ans / 2 << endl;
}

int main() {
    solve();

    return 0;
}

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

const int INF = 1e9 + 10;

int main() {
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> c(h);
    rep(i,h) cin >> c[i];
    ll count = 0;
    rep(mi, 1<<h) rep(mj, 1<<w) {
        int blck = 0;
        rep(i,h) rep(j,w) {
            if ( !((mi>>i)&1) && !((mj>>j)&1) && c[i][j] == '#') blck++;
        }
        if (blck == k) count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		int c = Integer.valueOf(a + b);
	    int d =(int) Math.floor(Math.sqrt(c));
        if(c == d * d){ 
        		System.out.println("Yes");
        	}else {
        		System.out.println("No");
        	}
	}

}

Measured memory_bytes: 20820
def main():
    a, b, c, k = map(int, input().split())

    ans = 0
    rest = k

    use = min(k, a)
    ans += use
    k -= use

    if k == 0:
        print(ans)
        return

    use = min(k, b)
    k -= use

    if k == 0:
        print(ans)
        return

    use = min(k, c)
    ans -= use

    print(ans)


if __name__ == '__main__':
    main()

# import sys
# input = sys.stdin.readline
# 
# sys.setrecursionlimit(10 ** 7)
# 
# (int(x)-1 for x in input().split())
# rstrip()
#
# def binary_search(*, ok, ng, func):
#     while abs(ok - ng) > 1:
#         mid = (ok + ng) // 2
#         if func(mid):
#             ok = mid
#         else:
#             ng = mid
#     return ok


Measured memory_bytes: 9192
#include <iostream>
#include <cstdio>
#include <cassert>
#include <ctime>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define all(x) (x).begin(), (x).end()

#ifdef LOCAL
#define dbg(x) cerr << #x " = " << x << endl;
#define idbg(x) #x " = " << x
#include "pretty_print.h"
#else
#define dbg(x)
#define idbg(x) ""
#endif

#ifdef _WIN32
#  define LLD "%I64d"
#else
#  define LLD "%lld"
#endif

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;

template <typename T> T sqr(T x) { return x * x; }
template <typename T> T abs(T x) { return x < 0? -x : x; }
template <typename T> T gcd(T a, T b) { return b? gcd(b, a % b) : a; }
template <typename T> bool chmin(T &x, const T& y) { if (x > y) { x = y; return true; } return false; }
template <typename T> bool chmax(T &x, const T& y) { if (x < y) { x = y; return true; } return false; }


int main(int /* argc */, char** /* argv */)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifdef LOCAL
    assert(freopen("inp", "r", stdin));
    assert(freopen("out", "w", stdout));
    #endif

    int n, k;
    while (cin >> n >> k) {
        vector<int> a(n + 1, 0);
        for (int i = 1; i <= n; ++i) {
            cin >> a[i];
            --a[i];
            a[i] += a[i - 1];
            a[i] %= k;
        }
        map<int, int> mp;
        ll ans = 0;
        for (int i = 0; i <= n; ++i) {
            if (i >= k) {
                --mp[a[i - k]];
            }
            ans += mp[a[i]];
            mp[a[i]] += 1;
        }
        cout << ans << endl;
    }


    cerr << "Time execute: " << clock() / (double)CLOCKS_PER_SEC << " sec" << endl;
    return 0;
}


Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

signed main(){
    int x,y,z,k;
    cin >> x >> y >> z >> k;
    ll a[x], b[y], c[z];
    REP(i,x){
        cin >> a[i];
    }
    REP(i,y){
        cin >> b[i];
    }
    REP(i,z){
        cin >> c[i];
    }
    sort(a, a + x);
    reverse(a, a + x);
    sort(b, b + y);
    reverse(b, b + y);
    sort(c, c + z);
    reverse(c, c + z);
    vector<tuple<int, int, int>> vec;
    map<tuple<int, int, int>, bool> use;
    map<tuple<int, int, int>, bool> ok;
    cout << a[0] + b[0] + c[0] << endl;
    vec.emplace_back(tuple<int, int, int>(0, 0, 0));
    use[tuple<int, int, int>(0, 0, 0)] = true;
    REP(i,k - 1){
        ll mx = 0;
        int tx, ty, tz;
        REP(j,vec.size()){
            int cx = get<0>(vec[j]), cy = get<1>(vec[j]), cz = get<2>(vec[j]);
            if(ok[tuple<int, int, int>(cx, cy, cz)]) continue;
            if(cx + 1 < x){
                if(a[cx + 1] + b[cy] + c[cz] > mx && !use[tuple<int, int, int>(cx + 1, cy, cz)]){
                    mx = a[cx + 1] + b[cy] + c[cz];
                    tx = cx + 1;
                    ty = cy;
                    tz = cz;
                }
            }
            if(cy + 1 < y){
                if(a[cx] + b[cy + 1] + c[cz] > mx && !use[tuple<int, int, int>(cx, cy + 1, cz)]){
                    mx = a[cx] + b[cy + 1] + c[cz];
                    tx = cx;
                    ty = cy + 1;
                    tz = cz;
                }
            }
            if(cz + 1 < z){
                if(a[cx] + b[cy] + c[cz + 1] > mx && !use[tuple<int, int, int>(cx, cy, cz + 1)]){
                    mx = a[cx] + b[cy] + c[cz + 1];
                    tx = cx;
                    ty = cy;
                    tz = cz + 1;
                }
            }
            if(use[tuple<int, int, int>(cx + 1, cy, cz)] && use[tuple<int, int, int>(cx, cy + 1, cz)] && use[tuple<int, int, int>(cx, cy, cz + 1)]){
                ok[tuple<int, int, int>(cx, cy, cz)] = true;
            }
        }
        cout << mx << endl;
        vec.emplace_back(tuple<int, int, int>(tx, ty, tz));
        use[tuple<int, int, int>(tx, ty, tz)] = true;
    }
    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define r(i,n) for(int i = 0; i<n; i++)
#define R(i,n) for(int i = 1; i<=n; i++)
typedef long long ll;
using namespace std;

int main(){
  int n,d=0,m;
  cin >> n;
  m=n;
  while(n){
    d+=(n%10);
    n/=10;
  }
  
  if(m%d==0)cout << "Yes"<<endl;
  else cout << "No"<<endl;
}

Measured memory_bytes: 256
open Printf
open Scanf

module L =
  struct
    include List
  
    let rec unfold f x =
      match f x with
        None -> []
      | Some (a, b) -> a :: unfold f b
  end
    
let () =
  let n = scanf "%d " (fun x -> x) in
  let k = scanf "%d " (fun x -> x) in
  let xs = L.unfold (fun b -> if b = 0 then None else let v = scanf "%d " (fun x -> x) in Some (v,b-1)) n in
  L.fold_left (fun s x -> s + 2 * (min x (k-x))) 0 xs |> printf "%d\n"


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

int main() {
    string s[3];
    for (int i = 0; i < 3; i++)
    {
        cin >> s[i];
    }

    //どこまで進んだかチェック
    int index[3] = {};
    //aなのかbなのかcなのか
    int cnt = 0;

    while (1)
    {
        cnt = s[cnt][index[cnt]++] -  'a';
        if (index[cnt] >= s[cnt].size()) {
            cout << char('A' + cnt) << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct UnionFind{
  vector<int> r,p;
  UnionFind(){}
  UnionFind(int size){init(size);}
  void init(int size){
    r.resize(size,0);
    p.resize(size,0);
    for(int i=0;i<size;i++) r[i]=1,p[i]=i;
  }
  int find(int x){
    return (x==p[x]?x:p[x]=find(p[x]));
  }
  bool same(int x,int y){
    return find(x)==find(y);
  }
  void unite(int x,int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    p[y]=x;
  }
};
typedef pair<int,int> P;
#define MAX 114514
vector<int> vx[MAX],vy[MAX];
signed main(){
  int n,w,h;
  cin>>n>>w>>h;
  int x[n],y[n];
  for(int i=0;i<n;i++) cin>>x[i]>>y[i];
  bool f=0;
  map<P,int> m;
  for(int i=0;i<n;i++){
    m[P(x[i],y[i])]=i;
    vx[x[i]].push_back(y[i]);
    vy[y[i]].push_back(x[i]);
    f|=x[i]==1||x[i]==w;
    f|=y[i]==1||y[i]==h;
  }
  int ans=0;
  UnionFind uf(n);
  for(int i=0;i<MAX;i++){
    for(int j=0;j<(int)vx[i].size();j++)
      uf.unite(m[P(i,vx[i][0])],m[P(i,vx[i][j])]);
    for(int j=0;j<(int)vy[i].size();j++)
      uf.unite(m[P(vy[i][0],i)],m[P(vy[i][j],i)]);
  }
  if(uf.r[uf.find(0)]==n){
    cout<<n-1<<endl;
    return 0;
  }
  for(int i=0;i<n;i++){
    if(uf.find(i)!=i) continue;
    ans+=uf.r[i]+1;
  }
  cout<<ans-1-f<<endl;
  return 0;
}

Measured memory_bytes: 13848
#include <cstdio>

using namespace std;

int main()
{
  int N;
  scanf("%d", &N);
  while(N--){
    int K, P;
    scanf("%d%d", &K, &P);
    int mod = K % P;
    if(!mod)
      mod = P;

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

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

int main() {
    string s;
    cin >> s;

    int n = s.size()+1;
    vector<int> a(n, 0);
    for (int i = 0; i < n-1; i++) {
        if (s[i] == '<') a[i+1] = a[i] + 1;
    }
    for (int i = n-2; i >= 0; i--) {
        if (s[i] == '>') a[i] = max(a[i], a[i+1]+1);
    }
    long long ans = 0;
    for (int i = 0; i < n; i++) ans += a[i];
    cout << ans << endl;
}

Measured memory_bytes: 5868
N,A,B,K = map(int,input().split(" "))
mod = 998244353
ncr = [1]*(N+1)
v = 1
for i in range(N):
	v = (v * ((N-i)%mod) * pow((i+1),mod-2,mod)) % mod
	ncr[i+1] = v%mod

pat = 0
for a in range(N+1):
	if (K - (a * A) < 0):
		break
	if (K - (a * A)) % B == 0 and ((K - (a * A))//B) <= N:
		pat += ncr[a]*ncr[(K - (a * A))//B]
		pat %= mod

print(pat % mod)



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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  int H, W; scanf("%d %d", &H, &W);
  vector<string> A;
  cout << string(W + 2, '#') << endl;
  for (int i = 0; i < H; ++i) {
    string s; cin >> s;
    cout << "#" << s << "#" << endl;
  }
  cout << string(W + 2, '#') << endl;
  return 0;
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> v(n), c(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> c[i];
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (v[i] > c[i]) {
      ans += v[i] - c[i];
    }
  }
  cout << ans << '\n';
  return 0;
}


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

int main()
{
  int n;
  int a;
  int k;
  
  cin >> n >> a;
  
  k = n % 500;
  
  if (k <= a)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  return (0);
}

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

int main(){
    int N;
    cin >> N;
    vector<int> P(N);
    for(int i=0; i<N; i++) cin >> P[i];
    int mn = P[0], ans = 1;
    for(int i=1; i<N; i++){
        if(mn > P[i]){
            ans++;
            mn = P[i];
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
	int n;
	cin >> n;
	int a;
	int c[100000];
	for (size_t i = 0; i < n; i++)
	{
		cin >> a;
		c[a - 1] = i + 1;
	}
	for (size_t i = 0; i < n; i++)
	{
		cout << c[i] << endl;
	}
	cout << endl;
    return 0;
}

Measured memory_bytes: 1152
s = input().rstrip().split(' ')
A = int(s[0])
B = int(s[1])
 
sum = A
cnt = 1
flg = True
 
while flg:
  if B ==0 or B == 1:
    cnt = 0
    break
  if sum >= B:
    break
  sum += A -1
  cnt += 1
 
print(cnt)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <list>
#include <utility>
#include <tuple>
#include <cstdio>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <cmath>
#include <limits>
#include <iomanip>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
const long long INF = 1LL << 60;
typedef long long ll;
int main() {
    ll N;
    cin >> N;
    if(N>(ll)3){
        ll ans=1;
    for(ll i=1;i<=N;i++){
        ans*=(ll)10;
        if(ans >= (ll)(1e9+7)){
            ans = ans % (ll)(1e9+7);
        }
    }
    ll add=1;
    for(ll i=1;i<=N;i++){
        add*=(ll)8;
        if(add >= (ll)(1e9+7)){
            add = add % (ll)(1e9+7);
        }
    }
    ans = ans + add;
    ans = ans % (ll)(1e9+7);
    ll dec=1;
    for(ll i=1;i<=N;i++){
        dec*=(ll)9;
        if(dec >= (ll)(1e9+7)){
            dec = dec % (ll)(1e9+7);
        }
    }
    ans = ans - (ll)(((ll)2)*dec);
    if(ans < (ll)0){
        ans+= (ll)(1e9+7);
        if(ans < 0){
        ans+= (ll)(1e9+7);
        if(ans < 0){
        ans+= (ll)(1e9+7);
        }
        }
    }
    else{
        ans = ans % (ll)(1e9+7);
    }
    cout << ans << endl;
    }
    else{
        if(N==1){
            cout << 0 << endl;
        }
        else if(N==2){
            cout << 2 << endl;
        }
        else if(N==3){
            cout << 54 << endl;
        }
    }
}

Measured memory_bytes: 3620
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define next(a) ( ((a)+1)%SIZE )
#define ABS(x) ( (x)>0 ? x : -(x) )
#define MIN(x,y) ( (x) < (y) ? (x) : (y) )
#define MAX(x,y) ( (x) > (y) ? (x) : (y) )
#define INF 1000000000
#define SIZE 100000



typedef struct queue
{
	int front;
	int rear;
	int data[200];
}queue;

void init(queue* p)
{
	p->front = 0;
	p->rear = 0;
}

void enqueue(queue *p,int x)
{
	if (next(p->rear) == p->front)
		printf("OVERFLOW!\n");
	p->data[p->rear] = x;
	p->rear = next(p->rear);
}

int dequeue(queue *p)
{
	int x;

	if (p->front == p->rear)
		printf("NO DADA\n");

	x = p->data[p->front];
	p->front = next(p->front);

	return x;
}

int empty(queue *p)
{
	return p->front == p->rear;
}

void print(char* str, int a, int b)
{
	int i;

	for (i = a; i <= b; i++)
		printf("%c", str[i]);
	printf("\n");
}

void reverse(char* str, int a, int b)
{
	int i,j=0;
	char t;

	for (i = a; i <= (a + b) / 2; i++)
	{
		t = str[i];
		str[i] = str[b - j];
		str[b - j] = t;
		j++;
	}
}

void replace(char* str, int a, int b, char* temp)
{
	int i, j=0;

	for (i = a; i <= b; i++)
	{
		str[i] = temp[j];
		j++;
	}
}

int main()
{
	char str[1500];
	char temp[1500];
	char temp2[1500];
	int q;
	int a, b;
	int i, j;

	scanf("%s", str);
	scanf("%d", &q);

	for (i = 0; i < q; i++)
	{
		scanf("%s%d%d", temp,&a,&b);
		if (strcmp(temp, "print") == 0)
			print(str, a, b);
		else if (strcmp(temp, "reverse") == 0)
			reverse(str,a, b);
		else if (strcmp(temp, "replace") == 0)
		{
			scanf("%s", temp2);
			replace(str,a, b, temp2);
		}
	}

	return 0;
}



Measured memory_bytes: 2064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
int a[N];

int main(){
int n;cin>>n;
ll sum=0;
for(int i=0;i<n;i++){
    cin>>a[i];
}
for(int i=1;i<n;i++){
    if(a[i]<a[i-1])
        sum+=a[i-1]-a[i],a[i]=a[i-1];
}
cout<<sum<<endl;
return 0;
}

Measured memory_bytes: 4328
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    int n;cin>>n;
    map<string,int> c;
    rep(i,n){
        string s;
        cin >> s;
        c[s]++;
    }
    for(string s:{"AC","WA","TLE","RE"}){
        cout << s << " x " << c[s] << endl;
    }
    return 0;
}

Measured memory_bytes: 3676
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

struct bipartite_matching{
    int n, x, y;
    VVI e;
    VI match;
    vector<bool> used;

    void init(int a, int b){
        x = a;
        y = b;
        n = x + y;
        e.resize(n);
        match.resize(n);
        used.resize(n);
    }

    void add_edge(int u, int v){
        e[u].push_back(v + x);
        e[v + x].push_back(u);
    }

    bool dfs(int v){
        used[v] = true;
        for (int u : e[v]){
            int w = match[u];
            if (w < 0 || (!used[w] && dfs(w))){
                match[v] = u;
                match[u] = v;
                return true;
            }
        }
        return false;
    }

    int calc_matching(){
        int res = 0;
        fill(ALL(match), -1);
        REP(v,n){
            if (match[v] < 0){
                used.assign(n, 0);
                if (dfs(v)) res++;
            }
        }
        return res;
    }
};

int main() {
    int n, m, e;
    cin >> n >> m >> e;

    // cout << 3 << endl;
    // return 0;

    bipartite_matching bm;
    bm.init(n, m);

    REP(_,e){
        int u, v;
        scanf("%d %d", &u, &v);
        bm.add_edge(u, v);
    }

    cout << bm.calc_matching() << endl;

    return 0;
}

Measured memory_bytes: 3364
s =input()
A=0
Z=0

for i in range(len(s)):
  if s[i] =="A":
    A +=(i+1)
    break

    
for j in range(len(s)):
  if s[-(j+1)] =="Z":
    Z +=len(s)-j
    break
    
print(Z-A+1)

Measured memory_bytes: 3516
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define endl '\n'
#define pi pair<int, int>

int n;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n;
	
	int ret = 0;
	for(int i = 0, j = 1; i < n; i++){
		int x;
		cin >> x;
		if(x == j) j++;
		else ret++;
	}
	
	if(ret == n) ret = -1;
	cout << ret << endl;

	return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;

#define fill(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define sz(x) (int)x.size()
#define F first
#define S second
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
const ll INF = 1e18;
const ll mod = 1e9+7;
const int N = 2e6+10;

bool primes[N];
vector<ll> prim;
void primify(){
    for(int i=1;i<N;i++) {
        primes[i]=true;
    }
    prim.clear();

    prim.push_back(2);
    for(int i=4;i<N;i+=2) {
        primes[i]=false;
    }

    for(int i=3;i<N;i+=2) {
        if(primes[i]) {
            prim.push_back(i);
            for(int j=2;j*i<N;j++) {
                primes[j*i]=false;
            }
        }
    }
}

int main(){
fast;
ll  n;
cin>>n;
primify();

int ans =0;
int cnt =0;
for(int i=0;i<prim.size();i++) {
    if(n%prim[i]==0){  
        cnt =0;
        while(n%prim[i]==0) {
            cnt++;
            n/=prim[i];
        }
        int tans=0;
        for(int j=1;j<=100;j++) {
            if(j*(j+1)/2 <= cnt) {
                tans=j;
            }
        }
        ans+=tans;
    }
}

if(n>1) {
    ans++;
}

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

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

int main(void) {
  int H, N, cnt=0;
  cin >> H >> N;
  int A[N];
  
  for(int i=0; i<N; i++) cin >> A[i];
  
  for(int i=0; i<N; i++){
    H -= A[i];
  }
  
  if(H<=0) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++) //for文マクロ
using namespace std;

typedef unsigned long ul;
typedef long long ll;
typedef pair<ul, ul> P; //ペア　タイプでふ

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << ((a > b) ? b * c + (a - b) * d : a * c);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>

#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))

#define REPI(i, a, b) for (int(i) = int(a); (i) < int(b); ++(i))

using namespace std;

int main()
{
    int Z;           //入力待ち
    int j, k;        //for文用
    string to = ","; //デバッグ用
    int e_count = 0; //演算回数を数える
    int count = 0;   //よくあるカウント
    //----------

    int n;
    cin >> n; //最大で10000
    int a, b;
    cin >> a >> b;

    int wa = 0;
    REP(i, n + 1) //1から"Nまで"探す
    {
        //各桁を取り出して和をとる
        wa += i % 10;
        wa += i / 10 % 10;
        wa += i / 100 % 10;
        wa += i / 1000 % 10;
        wa += i / 10000 % 10;

        //和が条件を満たしていたらカウント
        if (wa >= a && b >= wa)
        {
            //cout << "満たしている" << i << endl;
            count += i;
        }
        wa = 0;
    }
    cout << count << endl;

    //-----------
    cin >> Z;
    return 0;
}

Measured memory_bytes: 256
S = input()
K = int(input())
n = len(S)

ans = []
st = set()

for i in range(n):
    for j in range(i + 1, min(n + 1, i + 1 + K)):
        sub = S[i:j]
        # print(sub)
        if sub in st:
            continue
        st.add(sub)
        ans.append(sub)
        ans.sort()
        # print(ans)
        if len(ans) > K:
            ans = ans[:K]

print(ans[-1])


Measured memory_bytes: 4336
import sys
from collections import defaultdict
from queue import deque
readline = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    N, M, L = geta(int)
    INF = 10**10

    d = [[INF] * (N + 1) for _ in range(N + 1)]

    for i in range(1, N + 1):
        d[i][i] = 0

    for _ in range(M):
        a, b, c = geta(int)
        d[a][b] = c
        d[b][a] = c

    def warshall_froyd(_d):
        for k in range(1, N + 1):
            for i in range(1, N + 1):
                for j in range(1, N + 1):
                    l = _d[i][k] + _d[k][j]
                    if _d[i][j] > l:
                        _d[i][j] = l

    warshall_froyd(d)

    f = [[INF] * (N + 1) for _ in range(N + 1)]
    for i in range(N + 1):
        f[i][i] = 0
        for j in range(N + 1):
            if d[i][j] <= L:
                f[i][j] = 1

    warshall_froyd(f)

    for _ in range(gete(int)):
        s, t = geta(int)
        ret = f[s][t]
        print(ret - 1 if ret != INF else -1)


if __name__ == "__main__":
    main()

Measured memory_bytes: 53080
N = int(input())
A = list(map(int, input().split()))
sums = sum(A)
sml = [abs(N*A[i]-sums) for i in range(N)]

tmp = 100
result = 0
for i, n in enumerate(sml):
    if tmp > n:
        result = i
        tmp = n

print(result)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

typedef long long ll;

int main(int argc, char *argv[])
{
	int N, d[55];
	ll ans = 0;

	cin >> N;

	for (int i = 0; i < N; i++) {
		cin >> d[i];
	}
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			ans += d[i] * d[j];
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n;
  while (cin >> n, n) {
    vi v(n);
    rep(i, n) {
      string s;
      cin >> s;
      v[i] = (s == "ru") + 2 * (s == "ld") + 3 * (s == "rd");
    }
    int c = 0;
    loop(i, 1, n) c += (v[i] >> 1) == (v[i - 1] >> 1);
    cout << c << endl;
  }
}

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

typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second　//pairの二つ目の要素


int main(){
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int ans=0;
    ans=min(a,k);
    k-=ans;
    if(b<k)ans-=k-b;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3628
// By Mohit Gupta
#include <bits/stdc++.h>
using namespace std;
#define printint(v) copy(begin(v), end(v), ostream_iterator<int>(cout," "))
#define printintv(s,e) copy(s,e, ostream_iterator<int>(cout," "))
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits (for ints only diff for ll)
//https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html for other in built
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef pair<int,int> p32; 
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef map<int,int> m32;
#pragma GCC optimize ("-O2")
const int LIM = 5e5+5, MOD = 998244353;
int t,n,m,k,x,y;
 
 
int32_t main()
{
	IOS;
	cin>>n;
	ll ans=0;
	for(int i=1;i<=n;i++){
		if(i%3==0 || i%5==0) ;
		else ans+=i;
	}
	cout<<ans<<ln;
}


Measured memory_bytes: 3604
#include <stdio.h>
#define LIMIT 100010

int min(int a,int b){
  if(a < b){
    return a;
  }
  return b;
}

int main(void) {
  int N, W;
  scanf("%d %d", &N, &W);

  int w[N], v[N];
  for (int i = 0; i < N; i++) {
    scanf("%d %d", &w[i], &v[i]);
  }

  int dp[LIMIT + 1];
  for (int i = 0; i < LIMIT; i++) {
    dp[i] = W + 1;
  }
  
  dp[0] = 0;

  for (int i = 0; i < N; i++) {
    for (int j = LIMIT; j >= v[i]; j--) {
      dp[j] = min(dp[j], dp[j - v[i]] + w[i]);
    }
  }

  for (int i = LIMIT - 1; i >= 0; i--) {
    if(dp[i] <= W){
      printf("%d\n", i);

      return 0;
    }
  }
}


Measured memory_bytes: 512
import math

def is_prime(k):
    for d in range(2, math.floor(math.sqrt(k))+1):
        if k % d == 0:
            return False
    
    return True

def main():
    N = int(input())
    ans = 0

    for i in range(N):
        k = int(input())

        if is_prime(k):
            ans += 1

    print(ans)

main()


Measured memory_bytes: 5680
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, e) for (ll (i) = (s); (i) < (e); ++(i))
#define per(i, s, e) for (ll (i) = (s); (i) >= (e); --(i))
#define all(x) x.begin(),x.end()
 

int main(void) {
    ll n, m; cin >> n >> m;
    priority_queue<ll> q;
    rep(i, 0, n) {
        ll a;
        cin >> a;
        q.push(a);
    }

    rep(i, 0, m) {
        ll a = q.top(); q.pop();
        q.push(a/2);
    }
    ll ans = 0;
    rep(i, 0, n) {
        ans += q.top(); q.pop();
    }
    cout << ans << endl;

}


Measured memory_bytes: 1400
#include "bits/stdc++.h"
using namespace std;

using ll = long long;
const int INF = 1e9 + 5;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n;
    scanf("%d",&n);
    vector<int> h(n);
    for(int i=0;i<n;i++){
		scanf("%d",&h[i]);
	}
    vector<int> dp(n,INF);
    dp[0] = 0;
    for(int i=0;i<n;i++){
		for(int j : {i+1,i+2}){
			if(j<n){
				dp[j] = min(dp[j],dp[i] + abs(h[i]-h[j]));
			}
		}
	}
    cout<<dp[n-1];
    return 0;
}









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

#define DIV 1000000007

long long N, K;
vector<long long> tree[100005];
long long pat[100005];

long long dfs(long long cur){
	long long num = K - 2;
	if(cur == 0){
		num = K - 1;
	}
	for(long long i = 0; i < tree[cur].size(); i++){
		if(pat[tree[cur][i]] >= 0){
			continue;
		}
		pat[tree[cur][i]] = num;
		num--;
		dfs(tree[cur][i]);
	}
}

int main(){
	cin >> N >> K;
	for(long long i = 0; i < N - 1; i++){
		long long a, b;
		cin >> a >> b;
		a--;b--;
		tree[a].push_back(b);
		tree[b].push_back(a);
	}
	for(long long i = 0; i < 100005; i++){
		pat[i] = -1;
	}

	pat[0] = K;
	dfs(0);
	long long ans = 1;
	for(long long i = 0; i < N; i++){
		ans *= pat[i];
		ans %= DIV;
	}
	cout << ans << endl;
}

Measured memory_bytes: 9984
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e3+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a,b) memset(a,b,sizeof a)
#define lx x<<1
#define rx x<<1|1
#define reg register
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
#define il inline
int n,m;
int h[N],cnt,vis[N],in[N],jg[N];
ll d[N];
struct edge{
	int to,nt,w;
}e[N<<1];
void add(int u,int v,int w){
	e[++cnt]={v,h[u],w},h[u]=cnt;
} 
ll spfa(int st){
	mst(vis,0),mst(in,0);
	for(int i=1;i<=n;i++) d[i]=-1e15;
	queue<int>q;
	q.push(st);vis[st]=1,d[st]=0;
	while(!q.empty()){
		int u=q.front();q.pop();vis[u]=0;
		for(int i=h[u];i;i=e[i].nt){
			int v=e[i].to,w=e[i].w;
			if(jg[v]) continue;
			if(d[v]<d[u]+w){
				d[v]=d[u]+w;
				if(!vis[v]){
					in[v]++;
					if(in[v]==n) jg[v]=1;
					q.push(v),vis[v]=1;
				}
			}
		}
		}
	return jg[n]==1?1e15:d[n];
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		int u,v,w;
		scanf("%d%d%d",&u,&v,&w);
		add(u,v,w);
	}
	ll ans=spfa(1);
	if(ans==1e15) puts("inf");
	else printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
#define ll long long
#define en "\n"
using namespace std;

int main()
{
    //ios::sync_with_stdio(false);
    int n,k,len,tm,ans=0;
    scanf("%d%d",&n,&k);
    k--;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&tm);
        if(tm==1)len=i;
    }
    ans+=(len/k+(n-len-1)/k);
    if(len%k+(n-len-1)%k<=k&&len%k+(n-len-1)%k)ans++;
    else if(len%k+(n-len-1)%k>k)ans+=2;

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


Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define fore(x, c) for(auto &&x : c)
#define rep(i, a, n) for(int i = a, i##len = (int)(n); i < i##len; ++i)
#define rrep(i, a, n) for(int i = (int)(n - 1); i >= a; --i)
#define sz(c) ((int)c.size())
#define contains(c, x) (c.find(x) != end(c))
#define inseg(l, x, r) ((l) <= (x) && (x) < (r))
#define dump(...)
#define pb push_back
#define eb emplace_back
#define _ 0
const signed INF_ = 1001001001; const long long INF = 1001001001001001001LL;
const int DX[9] = {0,1,0,-1,1,1,-1,-1,0}, DY[9] = {-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is, vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
  is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a, const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a, const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap = priority_queue<T, deque<T>, greater<T>>;
struct before_main_function {
  before_main_function() {
      cin.tie(nullptr); ios::sync_with_stdio(0);
      cout << setprecision(15) << fixed;
  }
} before_main_function;
// clang-format on
//------------------8<------------------------------------8<--------------------

signed main() {
  string s, t;
  int a, b;
  cin >> s >> t >> a >> b;
  string u;
  cin >> u;
  if (u == s) a--;
  if (u == t) b--;
  cout << a << " " << b << endl;
  return (0 ^ _ ^ 0);
}



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

using ll = long long;

const int mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
};

int main() {
  string s;cin >> s;
  int n=s.size();
  vector<vector<mint>> v(n+5,vector<mint>(13));
  v[0][0]=1;
  rep(i,n){
    if(s[i]!='?'){
      int x=s[i]-'0';
      rep(j,13){
        v[i+1][(j*10+x)%13]+=v[i][j].x;
      }
    }
    else{
      rep(x,10){
        rep(j,13){
          v[i+1][(j*10+x)%13]+=v[i][j].x;
        }
      }
    }
  }
  cout << v[n][5].x << endl;
      
    
  
}


Measured memory_bytes: 16660
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int N;
	int counter = 0;
	vector<int> p;
	vector<int> p_sort;
	
	cin >> N;

	for (int i = 0; i < N; i++) {
		int x;
		cin >> x;

		p.push_back(x);
		p_sort.push_back(x);
	}

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


	for (int i = 0; i < N; i++) {
		if (p[i] != p_sort[i])
			counter++;
	}

	if (counter <= 2) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
using ll = int64_t;

int main() {
  string S,T;
  cin >> S >> T;
  ll best = T.size();
  for(ll i=0; i+T.size()-1<S.size(); i++) {
    ll score = 0;
    for(ll j=0; j<T.size(); j++) {
      if(T[j] != S[i+j]) {
        score++;
      }
    }
    best = min(best, score);
  }
  cout << best << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int N;
    cin >> N;
    string ans = "Christmas";
    rep(i, 25-N){
        ans += " Eve";
    }
    cout << ans;
}


Measured memory_bytes: 256