akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdlib.h> 
#include <queue>
#include <utility>

using namespace std;

typedef struct pair{
    int x;
    int y;
}pair_t;

const int INF = 10000000;

int bfs();

int H,W,N;
char** field;
int** d;


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

int sx, sy;

int main() {
      cin >> H >> W >> N;
      field =(char**) malloc(sizeof(char*)*H);
      d =(int**) malloc(sizeof(int*)*H);
    
      for(int i=0; i<H;i++){
          char* row = (char*)malloc(sizeof(char)*W);
          int* dr = (int*)malloc(sizeof(int)*W);
          cin >> row;
          field[i] = row;
          d[i] = dr;
      }
    
      for(int i=0; i < H; i++){
          for(int j=0; j < W; j++){
    
              if(field[i][j]=='S'){
                  sx = j;
                  sy = i;
                  field[i][j] = '.';
              }
          }
      }

      int result = bfs();
    
      cout << result << endl;

     // for(int i=0; i<H; i++){
     //     free(field[i]);
     // }

     // free(field);
  

  return 0;
}

void init_d(int x, int y, int n){

    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            d[i][j] = INF;
        }
    }

    d[y][x] = n;
}

void clear(queue<pair_t> &q){
    queue<pair_t> empty;
    swap(q, empty);
}

int bfs(){
    int cheeze = 1;

    queue<pair_t> que;

    pair_t first = {sx, sy};
    que.push(first);
    d[sy][sx] = 0;

    init_d(sx, sy, 0);

    while(que.size()){
NEXT:
        pair_t p = que.front();
        que.pop();

        for(int i = 0; i<4; i++){
            int nx = p.x + dx[i];
            int ny = p.y + dy[i];

            if(0<= nx && nx < W && 0 <= ny && ny < H && field[ny][nx] != 'X' && d[ny][nx] == INF){
                if(field[ny][nx] != '.'){
                    if((int)(field[ny][nx] - '0') == cheeze ){

                        if(cheeze == N){
                            return d[p.y][p.x] + 1;
                        }


                        init_d(nx, ny, d[p.y][p.x] + 1);
                        clear(que);

                        pair_t n = {nx, ny};
                        que.push(n);
                        
                        cheeze++;
                        goto NEXT;
                    }
                }

                pair_t n = {nx, ny};
                d[ny][nx] = d[p.y][p.x] + 1;
                que.push(n);

            }
        }
    }
    return -1;
}

Measured memory_bytes: 6136
import java.util.Scanner;

public class Main {

	public static String Y = "Yes";
	public static String N = "No";
	public static long MOD = (long) (Math.pow(10, 9) + 7);
	public static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		char[] a = nc();
		char[] b = nc();
		char[] c = nc();

		int ac = a.length;
		int bc = b.length;
		int cc = c.length;

		int an = 0;
		int bn = 0;
		int cn = 0;

		char now = 'a';

		for (;;) {

			if (now == 'a') {
				if (an == ac) {
					out("A");
					return;
				}
				now = a[an];
				an++;
			}
			if (now == 'b') {

				if (bn == bc) {
					out("B");
					return;
				}
				now = b[bn];
				bn++;
			}
			if (now == 'c') {

				if (cn == cc) {
					out("C");
					return;
				}
				now = c[cn];
				cn++;
			}

		}
	}

	/*
	 * 以下メソッド集
	 */
	static int ni() {
		return sc.nextInt();
	}

	static long nl() {
		return sc.nextLong();
	}

	static double nd() {
		return sc.nextDouble();
	}

	static String n() {
		return sc.next();
	}

	static char[] nc() {
		return sc.next().toCharArray();
	}

	static int kaijo(int n) {
		if (n == 0 || n == 1) {
			return 1;
		} else {
			return n * kaijo(n - 1);
		}
	}

	static int fib(int n) {
		return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
	}

	static long lcm(long m, long n) {

		return m * n / gcd(m, n);
	}

	static int lcm(int m, int n) {

		return m * n / gcd(m, n);
	}

	static long gcd(long a, long b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	static int gcd(int a, int b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	static void out(String info) {
		System.out.println(info);
	}

	static void out(int info) {
		System.out.println(info);
	}

	static void out(double info) {
		System.out.println(info);
	}

	static void out(long info) {
		System.out.println(info);
	}

	static void out(char info) {
		System.out.println(info);
	}

	static void out(Object obj) {
		System.out.println(obj.toString());
	}

	static void outn(String info) {
		System.out.print(info);
	}

	static void outn(int info) {
		System.out.print(info);
	}

	static void outn(double info) {
		System.out.print(info);
	}

	static void outn(long info) {
		System.out.print(info);
	}

	static void outn(char info) {
		System.out.print(info);
	}

	static double max(double d, double e) {
		return Math.max(d, e);
	}

	static long max(long a, long b) {
		return Math.max(a, b);
	}

	static double min(double d, double e) {
		return Math.min(d, e);
	}

	static long min(long a, long b) {
		return Math.min(a, b);
	}
}

class XY {
	int h;
	int c;

	XY(int h, int c) {
		this.h = h;
		this.c = c;
	}
}


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

#define PI acos(-1)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define endl '\n'
#define io  ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define file freopen ("team.in", "r", stdin),freopen ("team.out", "w", stdout);
#define fileIn freopen ("in.txt", "r", stdin);
#define all(v) ((v).begin()), ((v).end())


using namespace std;

typedef pair<int, int> pii;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, int> pli;

const int N = 1e5 + 10;
const int mod = 1e9 + 7;

ll fact[N];

void popFact (int n) {
  fact[0] = 1;
  for (int i = 1 ; i <= n ; i++)
    fact[i] = fact[i - 1] * i % mod;
}


ll Pow (ll b, ll e) {
  if (e == 0)
    return 1;
  ll ret = Pow(b, e/2);
  ret = ret * ret % mod;
  if ( e & 1 )
    ret = ret * b % mod;
  return ret;
}


ll getInverse (ll n) {
  return Pow (n, mod - 2);
}

ll divide (ll a, ll b) {
  return a * getInverse(b) % mod;
}

ll nCr (ll n , ll r) {
  if(r > n) {
    return 0;
  }
  return divide(divide(fact[n],fact[r]), fact[n - r]);
}


map<int, int> pos;
int a[N];
int n;

int main () {
#ifndef ONLINE_JUDGE
  //fileIn;
#endif
  io;
  cin >> n;
  n++;
  for(int i = 0; i < n; i++) {
    cin >> a[i];
  }
  popFact(n + 1);
  int lft = -1, rgt = -1;
  for(int i = 0; i < n; i++) {
    if(pos.count(a[i])) {
      lft = pos[a[i]];
      rgt = n - i - 1;
      break;
    }
    pos[a[i]] = i;
  }
  cout << n - 1 << endl;
  for(int i = 2; i <= n; i++) {
    cout << (nCr(n, i) - nCr(lft + rgt, i - 1) + mod) % mod << endl;
  }
  return 0;
}


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

using namespace std;

typedef long long ll;
#define fori(i,n) for(int i=0; i<n; i++)
#define itn int 
#define pb push_back
#define mp make_pair
#define vi vector <int>
#define vll vector <ll>
#define be(a) (a).begin(), (a).end()
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin >> s;
	cout << "2018"; 
	for (int i=4; i<(int)s.size(); i++) {
		cout << s[i];
	} 
	return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5+9, INF = 0x3f3f3f3f;
int dt[N], n, k;

int check( int p ) {
    int cnt = 0, i = 0, sum = 0;
    while( i < n ) {
        if( sum + dt[i] <= p ) {
            sum += dt[i]; ++i;
        }
        else {
            ++cnt; sum = 0;
        }
        if( cnt >= k ) break;
    }
    if( sum ) ++cnt;
    return cnt <= k && i == n;
}

int cxk() {
    int l = 0, r = 1e9, mid;
    while( l < r ) {
        mid = l + r >> 1;
        if( check( mid ) ) r = mid;
        else l = mid + 1;
    }
    return r;
}

int main( void ) {
    ios::sync_with_stdio( false );
    cin >> n >> k;
    for( int i = 0; i < n; ++i ) cin >> dt[i];
    cout << cxk() << '\n';
    return 0;
}


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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

ll N;

ll check(ll i) {
  string s = to_string(i);
  return s.size();
}

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

  cin >> N;

  ll ans = INF;
  RFOR(i, 1, sqrt(N) + 1) {
    if (N % i == 0)
      ans = min(ans, check(max((ll)i, N / (ll)i)));
  }
  cout << ans << endl;
  
  return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
    ll A, B;
    cin >> A >> B;
    if (A >= 1 && A <= 9 && B >= 1 && B <= 9) {
        cout << A * B << endl;
    } else {
        cout << -1 << endl;
    }
    return 0;
}



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

int main() {
	string s, t; cin >> s >> t; int f = 0;
	for (int i = 0; i < s.size(); ++i) {
		if (s[i] != t[i]) {
			f = 1; break;
		}
	}
	if (f)cout << "No";
	else cout << "Yes";
	return 0;
}

Measured memory_bytes: 3600
#include <stdio.h>

int main(void)
{
	int a, b;
	scanf("%d %d", &a, &b);

	if (a == b)
	{
		printf("a == b\n");
	}

	else if (a > b)
	{
		printf("a > b\n");
	}
	else
	{
		printf("a < b\n");
	}
	return 0;
}


Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int arr[n];
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	int* dp=new int[n];
	dp[0]=0;
	dp[1]=abs(arr[1]-arr[0]);
	for(int i=2;i<n;i++)
	{
		dp[i]=min(dp[i-2]+abs(arr[i]-arr[i-2]),dp[i-1]+abs(arr[i-1]-arr[i]));
	}
	cout<<dp[n-1];
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#define MAX_N 100000
typedef long long ll;
using namespace std;
int main(){
  ll a[3][MAX_N];
  ll N, i1=0,i2=0,i3=0,ans=0;
  cin>>N;
  for(int c=0;c<3;c++){
    for(int i=0;i<N;i++){
      cin>>a[c][i];
    }
  }
  for(int c=0;c<3;c++){
    sort(a[c],a[c]+N);
  }
  for(i1=0;i2<N;i2++){
    i1=int(lower_bound(a[0],a[0]+N,a[1][i2])-a[0]);
    i3=int(upper_bound(a[2],a[2]+N,a[1][i2])-a[2]);
    ans+=i1*(N-i3);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int gcd(int a, int b) {  
  return b != 0 ? gcd(b, a % b) : a;
}//MAX
int lcm(int a, int b) { 
   return a * b / gcd(a, b);
   }
//MIN
 main() {
   ll l,r,ans = 2020;
   cin >> l >>r;
   if((r-l)+1>=2019)return cout << 0,0;
   for(ll i=l;i<=r;i++){
     for(ll j=i+1;j<=r;j++)
       ans = min(ans,(i*j)%2019);
     
   }
   cout << ans<<endl;
 }
 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using u32 = uint32_t;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define MAXC(c, x) (c = max(c, x))
#define MINC(c, x) (c = min(c, x))

#define REP(i,n) for(auto i = 0 * (n), i##_len = (n); i < i##_len; ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,n) for(ll i=s, i##_len=(ll)(n); i<i##_len; ++i)
#define TEN(x) ((ll)1e##x)
const ll mod = TEN(9) + 7;

const ll INF = 1e9;

template<int64_t mod> struct GF {
	typedef int64_t T;
	T v;
	GF() = default;
	GF(T v) : v((v % mod + mod) % mod) {}
	GF & operator+=(GF x) { v = (v + x.v) % mod; return *this; }
	GF & operator*=(GF x) { v = (v * x.v) % mod; return *this; }
	GF & operator-=(GF x) { v = (v - x.v + mod) % mod; return *this; }
	GF & operator/=(GF x) { return (*this) *= x.inverse(); }
	GF operator+(GF rhs) const { GF lhs = *this; return lhs += rhs; }
	GF operator*(GF rhs) const { GF lhs = *this; return lhs *= rhs; }
	GF operator-(GF rhs) const { GF lhs = *this; return lhs -= rhs; }
	GF operator/(GF rhs) const { GF lhs = *this; return lhs /= rhs; }
	GF inverse() const { // http://topcoder.g.hatena.ne.jp/iwiwi/20130105/1357363348
		T a = v, b = mod, x = 1, y = 0;
		while (b) {
			T t = a / b;
			swap(a -= t * b, b);
			swap(x -= t * y, y);
		}
		return x;
	}
	GF pow(T n) const {
		GF r; r.v = 1;
		for (T x = v; n > 0; n >>= 1) {
			if (n & 1) (r.v *= x) %= mod;
			(x *= x) %= mod;
		}
		return r;
	}
	typedef size_t U;
	static GF fact(U n) {
		static vector<GF> data;
		U m = data.size();
		if (m <= n) {
			data.resize(n + 1);
			if (m == 0) { data[0].v = 1; m++; }
			for (U i = m; i < n + 1; ++i) data[i] = data[i - 1] * i;
		}
		return data[n];
	}
	static GF nCr(U n, U r) { return fact(n) / fact(r) / fact(n - r); }
	static GF nPr(U n, U r) { return fact(n) / fact(r); }
};

int main() {
	#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
	#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);
	ll n; cin >> n;
	GF<mod> ans = 0;
	vector<GF<mod>> sum(n + 1, 0);
	vector<GF<mod>> dp(n + 1, 0);
	dp[0] = 1;
	REP(i, n) {
		dp[i + 1] = dp[i] + ((i - 2 < 0 ? 0 : sum[i - 2]) - (i - n - 1 < 0 ? 0 : sum[i - n - 1]));
		sum[i + 1] = sum[i] + dp[i + 1];
		if (i != n - 1) {
			ans = ans + dp[i + 1] * ((n - 1) * (n - 1) + min(n - 1, i + 2));
		}
	}
	ans = ans + dp[n] * n;
	cout << ans.v << endl;
}

Measured memory_bytes: 15872
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#define REP(i, n) for(LL i = 0;i < n;i++)
#define REPR(i, n) for(LL i = n;i >= 0;i--)
#define FOR(i, m, n) for(LL i = m;i < n;i++)
#define FORR(i, m, n) for(LL i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef long long LL;
//typedef LL int;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

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

    if(a == 5 || b == 5 || c == 5){
        if(a == 7 || b == 7 || c == 7){
            if(a+b+c == 17){
                cout << "YES" << endl;
                return 0;
            }
        }
    }
    cout << "NO" << endl; 
}


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

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <forward_list>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef bitset<16> BS;

const ll MOD = 1E+09 + 7;
const ll INF = 1E18;
const int MAX_N = 2000;

int N;
ll Z, W;

ll A[MAX_N + 1], dp[MAX_N + 1][2];

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

    cin >> N >> Z >> W;

    for (int i = 1; i <= N; i++) {
        cin >> A[i];
    }
    A[0] = W;

    for (int i = N - 1; i >= 0; i--) {
        dp[i][0] = abs(A[N] - A[i]);
        for (int j = i + 1; j < N; j++) {
            dp[i][0] = max(dp[i][0], dp[j][1]);
        }
        dp[i][1] = abs(A[N] - A[i]);
        for (int j = i + 1; j < N; j++) {
            dp[i][1] = min(dp[i][1], dp[j][0]);
        }
    }

    /*
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cout << "i = " << i << ", j = " << j << ", dp = " << dp[i][j] << "\n";
        }
    }
    */

    cout << dp[0][0] << "\n";

    return 0;
}

Measured memory_bytes: 3680
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 2019
#define INF 1000000000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 1000005;
const int MOD = 2019;

int main(){
    int n;
    cin>>n;
    map<string,int>m;
    REP(i,n){
        string s;
        cin>>s;
        m[s]++;
    }
    int ans=0;
    ans=SZ(m);
    OUT(ans);
    return 0;
}

Measured memory_bytes: 19204
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

import fractions
from functools import reduce

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

N,X = II()
x = III()

for i in range(N):
    x[i] -= X

print(abs(gcd_list(x)))

Measured memory_bytes: 88172
#include<iostream>
#include<vector>

using namespace std;

int main(){
    long N,K,Q;
    cin>>N>>K>>Q;
    vector<int> hoge(N,K-Q);

    for (int  i = 0; i < Q; i++)
    {
        int tmp;
        cin>>tmp;
        hoge[tmp-1]++;
    }
    

    for (auto &&x : hoge)
    {
        if(x>0)cout<<"Yes"<<endl;
        else
        {
            cout<<"No"<<endl;
        }
        
    }
    

    
}

Measured memory_bytes: 1024
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int t1=0,x1=0,y1=0,t2,x2,y2;
	for(int i=1;i<=n;i++)
	{
		cin>>t2>>x2>>y2;
		int t=abs(t2-t1);
		int x=abs(x2+y2-x1-y1);
		if(x>t||(x-t)%2!=0)
		{
			cout<<"No"<<endl;
			return 0;
		}
		t1=t2;
		x1=x2;
		y1=y2;
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <math.h>
#include <regex>
#include "bits/stdc++.h"
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define INF (INT_MAX / 2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX / 2)
const int MGN = 10;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vd = vector<double>;
using vs = vector<string>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using psi = pair<string, int>;

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

  ll N,K; cin >> N>>K;
  vl A(N); REP(i,N) cin>>A[i];
  vl F(N); REP(i,N) cin>>F[i];

  sort(A.begin(), A.end());
  sort(F.begin(), F.end(), greater<ll>());

  ll l = -1, r = 1e12; // (l,r]
  while (l+1 < r) {
      ll m = (l + r) / 2;
      
      ll sum = 0;      
      REP(i,N) sum += max(A[i]-m/F[i], 0LL);
      
      if (sum <= K) r = m;
      else l = m;
  }
  
  ll ans = r;  
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3456
N = int(input())
P = list(map(int, input().split()))

ans = 0

i = 0

while i < len(P):
    if i+1 == P[i]:
        if i+1 != len(P):
            if i+2 == P[i+1]:
                ans += 1
                i += 1
            else:
                ans += 1
        else:
            ans += 1
    i += 1
    
print(ans)

Measured memory_bytes: 14008
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
    string A;
    cin >> A;
    string c;

    int mati = 0;

    for (int i = 0; i < A.size(); i++)
    {
        c = A[i];
        if (i%2==0)
        {
            if (c =="L")
            {
                mati = 1;
            }
            
        }
        else
        {
            if (c=="R")
            {
                mati = 1;
            }
            
        }
    }
    
    if (mati == 0)
    {
        cout << "Yes" <<endl;
    }
    else
    {
        cout <<"No" <<endl;
    }
    
    

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

void solve(long long N){
    for(int n=1;n<=3500;n++){
        for(int h=1;h<=3500;h++){
            long long a = 4LL*n*h - N*(n+h);
            long long b = N*n*h;
            if(a <= 0) continue;
            if(b%a) continue;
            cout << n << " " << h << " " << b/a << endl;
            return;
        }
    }
}

int main(){
    long long N;
    while(cin >> N){
        solve(N);
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC target ("sse4")
using namespace std;
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define MEM(x,a) memset((x),a,sizeof((x)))
#define F first
#define S second
#define imx INT_MAX
const long long MOD = (long long)(1e9+7);
const long long MMX = (long long)(1e18);
typedef long long LL;
typedef pair<int,int> pii;
int n,m,k[105][105],a,b,ii,jj,ni,nj,di[]={0,1},dj[]={1,0};
char c[105][105];
priority_queue<pair<pii,pii> >pq;
int main()
{
    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;i++)
    {
        scanf("%s",c[i]+1);
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)k[i][j]=imx;
    }
    pq.push({{0,'.'},{0,1}});
    while(!pq.empty())
    {
        a=-pq.top().F.F;
        b=pq.top().F.S;
        ii=pq.top().S.F;
        jj=pq.top().S.S;
        //printf("[%d %d]",ii,jj);
        pq.pop();
        for(int i=0;i<2;i++)
        {
            ni=ii+di[i];
            nj=jj+dj[i];
            if(ni<1||nj<1||ni>n||nj>m)continue;
            if(b=='.'&&c[ni][nj]=='#')
            {
                if(a+1<k[ni][nj])
                {
                    k[ni][nj]=a+1;
                    pq.push({{-k[ni][nj],c[ni][nj]},{ni,nj}});
                }
            }
            else
            {
                if(a<k[ni][nj])
                {
                    k[ni][nj]=a;
                    pq.push({{-k[ni][nj],c[ni][nj]},{ni,nj}});
                }
            }
        }
    }
    printf("%d",k[n][m]);
}


Measured memory_bytes: 3896
#include <iostream>

using namespace std;

int main() {
    long long int S;
    cin >> S;
    
    cout << 0 << " " << 0 << " " << (long long int)1e9 << " " << 1 << " ";
    if(S%(long long int)1e9!=0) {
        cout << (long long int)1e9-(S%(long long int)1e9) << " " << (long long int)((S+(long long int)1e9-(S%(long long int)1e9))/(long long int)1e9) << endl;
    } else {
               cout << 0 << " " << (long long int)(S/(long long int)1e9) << endl;
    }


    return 0;
    
}

Measured memory_bytes: 256
#include <stdio.h>

#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
const ll BIGMOD = 1e9 + 7;
using namespace std;

int main() {
  int gaiji;
  cin >> gaiji;
  cout << gaiji / 500 * 1000 + gaiji % 500 - gaiji % 500 % 5 << endl;

  return 0;
}

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

void doRoutine() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    srand(322179);
#ifdef LOCAL
    freopen("/root/alg/clion_main/input.txt", "rt", stdin);
    freopen("/root/alg/clion_main/output.txt", "wt", stdout);
#endif
}

#define DBG(VAR) cerr << #VAR << ": " << VAR << endl

#define all(x) x.begin(), x.end()
#define last(x) (--x.end())
#define vb vector<bool>
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
#define vc vector

#ifndef LOCAL
#define cerr if(0) cerr
#define DBG(...) (true)
#endif

#define D double
#define int long long

// ----------------------------- CODE NOW ------------------------


const int INF = 1000000000000000000;

int sum(int x) {
    int res = 0;
    while (x > 0) {
        res += x % 10;
        x /= 10;
    }
    return res;
}

signed main() {
    doRoutine();

    int n;
    cin >> n;
    int ans = INF;
    for (int a = 1; a < n; ++a) {
        ans = min(ans, sum(a) + sum(n - a));
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <numeric>
#include <type_traits>
#include <vector>
using namespace std;

template <class M, class N>
common_type_t<M, N> gcd(M a, N b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}

template <class M, class N>
common_type_t<M, N> lcm(M a, N b) {
  return a * b / gcd(a, b);
}

int main(int argc, const char *argv[]) {
  using ll = long long;
  int n, m;
  cin >> n >> m;
  m *= 2;

  vector<ll> va(n);
  for (auto &a : va) {
    cin >> a;
  }

  auto is_csm = [&](ll n) {
    return n <= m && all_of(va.begin(), va.end(), [&](auto a) {
             return n % a == 0 && n / a % 2 == 1;
           });
  };

  ll a_lcm = accumulate(va.begin(), va.end(), 1ll,
                        [](auto acc, auto cur) { return lcm(acc, cur); });
  ll min_csm = a_lcm;
  if (!is_csm(a_lcm)) {
    if (!is_csm(a_lcm * 2)) {
      cout << 0 << "\n";
      return 0;
    }

    min_csm *= 2;
  }

  ll ans = 1 + (m - min_csm) / (a_lcm * 2);
  cout << ans << "\n";
  return 0;
}

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

  int main () {
      int A, B;
      cin >> A >> B;
      
      int ans;
      
      if (A > B){
        
        ans = A + (A-1);
      }
      
      else if (A < B){
         
         ans = B + (B-1);
      }
      
      else {
          
          ans = A + B;
      }
      
        cout << ans << endl;
      
      }

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

int main()
{
char A[5]={'a','e','i','o','u'};
bool flag;
char s;
cin>>s;
for(int i=0;i<5;i++){
	if(A[i]==s){
		flag=true;
		break;}

	else{
		flag=false;}
	
}
if(flag==true)
	cout<<"vowel";
else if(flag==false)
	cout<<"consonant";
}

Measured memory_bytes: 256
function Main(s){
	s=s.split(/\n|\s/);
	s.forEach(function(e,i,a){a[i]=Number(a[i]);});
	
	var ans=":(";
	if(s[0]<9&&s[1]<9){ans="Yay!";}
	console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
#ifdef LOCAL
#define debug(x) cerr << #x << ": " << x << endl
#else
#define debug(x)
#endif
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

int N, X[100];
signed main(){
	cin >> N;
	rep(i, N) cin >> X[i];

	int ans = INT_MAX;
	for(int p=1; p<=100; p++){
		int tmp = 0;
		rep(i, N){
			tmp += (X[i]-p)*(X[i]-p);
		}
		ans = min(ans, tmp);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main
{
		public static int sum=0;
		public static int n,l;
		public static String str;
		public static char ch[]=new char[105];
		public static void dfs(int k,int nonzero,boolean beyond,int tot) {
			if(tot<=0)return ;
			if(nonzero==n) {
				sum+=tot;
				return ;
			}
			if(k<l-1)
			{
				if(ch[k]>'0')dfs(k+1,nonzero,false,tot);
				else dfs(k+1,nonzero,beyond,tot);
				if(ch[k]>'0')
				{
					dfs(k+1,nonzero+1,false,tot*(ch[k]-'0'-1));
					dfs(k+1,nonzero+1,beyond,tot);
				}
				dfs(k+1,nonzero+1,true,tot*(9-(ch[k]-'0')));
			}
			else {
				if(nonzero==n-1){
					if(beyond==false)sum+=tot*(ch[k]-'0');
					else sum+=tot*((ch[k]-'0')-1);
				}
			}
		}
        public static void main(String args[]) throws Exception
        {
                Scanner cin=new Scanner(System.in);
                str=cin.next();
                n=cin.nextInt();
                l=str.length();
                for(int i=0; i<l; ++i) {
                	ch[i]=str.charAt(l-i-1);
                }
                dfs(0,0,false,1);
                System.out.println(sum);
                cin.close();
        }
}

Measured memory_bytes: 24888
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define LL_MAX LLONG_MAX
#define ULL_MAX ULLONG_MAX
#define ull unsigned long long
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pb(x) push_back(x)
#define re() pop_back()
#define eb(x) emplace_back(x)
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define all(a) a.begin(),a.end()
#define msort(a) sort(a.begin(),a.end())
#define pii pair<int,int>
#define sz(x) int(x.size())
#define mk make_pair
#define endl '\n'

const int N= 5e5+ 4;
vector<int> dat(N),last(N),c(N),ans(N);
vector<vector<int>> qi(N),qs(N);
void update(int i,int val){
    while(i<N){
        dat[i]+=val;
        i+=i&-i;
    }
}

int sum(int i){
    int sum=0;
    while(i){
        sum+=dat[i];
        i-=i&-i;
    }
    return sum;
}

int rangesum(int l,int r) {
    return sum(r)-sum(l-1);
}


void sol()
{
    int n,q;
    cin>>n>>q;
    for (int i = 1; i < n+1; i++)
    {
        cin>>c[i];
    }

    for (int i = 0; i <q; i++)
    {
        int x,y;
        cin>>x>>y;
        qi[y].eb(i);
        qs[y].eb(x);
    }
    
    for (int i = 1; i < n+1; i++)
    {
        if(last[c[i]]>0) {
            update(last[c[i]],-1);
        }
        update(i,1);
        last[c[i]]=i;
        for (int j = 0; j< sz(qs[i]); j++)
        {
            ans[qi[i][j]]=rangesum(qs[i][j],i);
        }
        
    }
    
    for (int i = 0; i < q; i++)
    {
        cout<<ans[i]<<endl;
    }
}

int main()
{
    IOS;
    ll t=1;// cin>>t;
    while (t--)
    {
        sol();
    }
}


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

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<double, double> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<string> &o) {
    string a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {
    string s;
    cin >> s;
    int ans = count(s.begin(), s.end(), '1');
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();

        System.out.println(a * b + " " + 2 * (a + b));
        sc.close();
    }
}


Measured memory_bytes: 26104
import Text.Printf

inner_product (ax,ay) (bx,by) = ax * bx + ay * by
vabs (ax,ay) = sqrt (ax*ax+ay*ay)
vmul a (ax,ay) = (a*ax,a*ay)
vadd (ax,ay) (bx,by) = (ax+bx,ay+by)
vsub (ax,ay) (bx,by) = (ax-bx,ay-by)

ans ax ay bx by px py =
  let v1 = (bx-ax,by-ay)
      v2 = (px-ax,py-ay)
      ip = inner_product v1 v2
      q  = (ax,ay) `vadd` ( (ip / (vabs v1)**2) `vmul` v1 )
  in
    q `vadd` ( q `vsub` (px,py) )
    
main = do
  l0 <- getLine
  getLine
  q0 <- getContents
  let xy@(ax:ay:bx:by:_) = map read $ words l0 :: [Double]
      qs = map (map read) $ map words $ lines q0 :: [[Double]]
      o = map (\ (px:py:_) -> ans ax ay bx by px py) qs
  mapM_ (\(x,y) -> printf "%f %f\n" x y) o
  

Measured memory_bytes: 4780
Scanf.scanf "%d" (fun n ->
    let arr = Array.make n ' ' in
    let rec loop i c mx =
        if i = n then print_endline @@ String.init n (fun i -> arr.(i)) else
            if c > mx then () else (
                arr.(i) <- char_of_int c;
                loop (i + 1) 97 (max mx (c + 1));
                loop i (c + 1) mx
            )
    in
    loop 0 97 97
)

Measured memory_bytes: 5720
n, k = map(int,input().split())
A = list(map(int,input().split()))
A = [a-1 for a in A]

path = []
passed = set([])
p = 0
while 1:
  if k ==0:
    print(p+1)
    exit()
  if p not in passed:
    path.append(p)
    passed.add(p)
    p = A[p]
    k -= 1
  else:
    break
path = path[path.index(p):]
term = len(path)
k %= term
print(path[k]+1)



Measured memory_bytes: 32248
#include <iostream>
#include <string>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    string t, h;
    int tp = 0; int hp = 0;
    for (int i = 0; i < n; i++) {
        cin >> t >> h;
        if (t < h)
            hp += 3;
        else if (t > h)
            tp += 3;
        else {
            tp += 1; hp += 1;
        }
    }
    cout << tp << " " << hp << "\n";
}

Measured memory_bytes: 3160
#include<stdio.h>
int main()
{
	int a, b;
	scanf("%d%d", &a, &b);
		if (a % 2 == 0 && b % 2 == 0)
			printf("Even\n");
		else
			if (a % 2 == 1 && b%2 == 1)
				printf("Odd\n");
			else
				if (a % 2 == 0 || b % 2 == 0)
					printf("Even\n");
	return 0;
}

Measured memory_bytes: 128
def main():
    from collections import namedtuple
    from operator import attrgetter
    import sys
    readline = sys.stdin.readline

    mon = namedtuple('mon', 'x h')

    N, D, A = map(int, readline().split())
    mons = []
    for _ in range(N):
        x, h = map(int, readline().split())
        mons.append(mon(x=x, h=h))
    mons.sort(key=attrgetter('x'))

    imos = [0] * (N + 1)

    bomb = 0
    j = 0
    for i, mon in enumerate(mons):
        while (j + 1 < N) and (mons[j + 1].x - mon.x) <= D * 2:
            j += 1
        count = max(0, (mon.h - imos[i] * A + A - 1) // A)
        bomb += count

        imos[i] += count
        imos[j + 1] -= count

        imos[i + 1] += imos[i]

    print(bomb)


if __name__ == '__main__':
    main()


Measured memory_bytes: 84700
//https://atcoder.jp/contests/abc152/submissions/9612417
//勉強させていただいた提出

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;


const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

template<class T,class Y> inline bool chmin(T& a, Y& b) {if (a > b) {a = b;return true;}return false;}
template<class T,class Y> inline bool chmax(T& a, Y& b) {if (a < b) {a = b;return true;}return false;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()

template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(){
    ll N,b,o=1;
    cin>>N;
    vector<ll> A(N),fact(1000010,0);//factは素因数分解した素数のmax乗数を保存
    rep(i,N){
        cin>>A[i];
        b=A[i];
        for(int i=2;i*i<=b;i++){
            ll cnt=0;
            while(b%i==0){
                cnt++;
                b/=i;
            }
            chmax(fact[i],cnt);
        }
        if(b>1)chmax(fact[b],o);
    }

    modint<INF> lcm=1,ans=0;
    rep(i,1000001){
        if(fact[i]){
            lcm*=modpow(i,fact[i],INF);//乗数のあまり
        }
    }
    rep(i,N){
        ans+=lcm/A[i];
    }
    cout<<ans.a<<endl;

    return 0;
}

//a=97,z=122

Measured memory_bytes: 8192
#include<stdio.h> 
#include<stdlib.h>
#include<string.h>
#define min(a,b)((a)<(b)?(a):(b))

int n,k;
int fares[101][101];
void kouro(int f,int t,int m){
	int a,b;
	if(fares[f][t]==-1 | fares[f][t]>m){
		fares[f][t]=m;
		fares[t][f]=m;
		for(a=1;a<=n;a++){
			for(b=1;b<=n;b++){
				fares[a][b]=min(fares[a][b],fares[a][t]+fares[f][t]+fares[f][b]);
				fares[a][b]=min(fares[a][b],fares[a][t]+fares[f][t]+fares[f][b]);
                                fares[b][a]=fares[a][b];
			}
		}
	}
	
}
void kyaku(int f,int t){
	if(fares[f][t]>=10000000)printf("-1\n");
	else printf("%d\n",fares[f][t]);
}
int main(void){  
	int a,b; 
	int s,f,t,m; 
		while(1){          
		memset(fares,0,sizeof(fares));
		scanf("%d %d",&n,&k);
		if(n==0 && k==0)break;
		for(a=1;a<=n;a++){
			for(b=1;b<=n;b++){
				if(a==b)fares[a][b]=0;else fares[a][b]=100000000;
			}
		}
		for(a=0;a<k;a++){
			scanf("%d %d %d",&s,&f,&t);
			if(s==1){
				scanf("%d",&m);
				kouro(f,t,m);
			}
			if(s==0){
				kyaku(f,t);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 460
#include<cstdio>
int n;
char a[10];
void dfs(int x,int max){
	if(x==n){
		puts(a);
		return;
	}
	for(int i=0;i<=max;++i)
		a[x]=i+'a',dfs(x+1,max);
	a[x]=max+'a'+1,dfs(x+1,max+1);
	return;
}
int main(){
	scanf("%d",&n);
	dfs(0,-1);
}

Measured memory_bytes: 1408
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


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

    int N, K;  cin >> N >> K;
    vi A(N); REP(i, N) cin >> A[i];
    
    const int AMAX = N;
    vi h(AMAX+MGN, 0);
    REP(i, N) h[A[i]]++;

    sort(h.begin(), h.end(), greater<int>());

    int ans = 0;
    FOR(i, K, h.size()){
        ans += h[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine()); 
            List<int> button = new List<int>();
            for (int i = 0; i < N; i++) 
            {
                button.Add(int.Parse(Console.ReadLine()));
            }

            int p = 0;
            int count = 0;
            while (true) 
            {
                count++;
                if (button[p] == 2) 
                {
                    Console.WriteLine(count);
                    break;
                }
                if (count > N) {
                    Console.WriteLine(-1);
                    break;
                }
                p = button[p] - 1;
            }
        }
    }
}


Measured memory_bytes: 31760
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef unsigned long long ul;

int main() {
	int n; cin >> n;
	string a, b, c; cin >> a >> b >> c;
	int ans = 0;
	rep(i, n) {
		vector<char> v;
		v.push_back(a[i]);
		v.push_back(b[i]);
		v.push_back(c[i]);
		sort(v.begin(), v.end());
		int cnt = unique(v.begin(), v.end()) - v.begin();
		ans += cnt - 1;
	}
	cout << ans << endl;
	//stop
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define PQ priority_queue
#define UM unordered_map
#define ALL(a) (a).begin(),(a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
const ll INF = (1ll << 60);
typedef pair<ll,ll> pii;

int main() {
  ll N; cin>>N;
  vi A(N); REP(i,N) cin>>A[i];
  UM<ll,ll> um; REP(i,N) um[A[i]]+=1;
  vi a,b; for(auto i:um) if(i.second>=4) a.PB(i.first); else if(i.second>=2) b.PB(i.first);
  if(a.size()==0&&b.size()<=1) {cout<<0<<endl; return 0;}
  sort(ALL(a)); sort(ALL(b));
  ll ans=0;
  if(a.size()) ans=max(ans,a.back()*a.back());
  if(b.size()>=2) ans=max(ans,b[b.size()-1]*b[b.size()-2]);
  if(a.size()&&b.size()) ans=max(ans,b.back()*a.back());
  cout<<ans<<endl;
}


Measured memory_bytes: 5156
n = input().split()
m=int(n[1])
n=int(n[0])
x = list(map(int, input().split()))
x.sort()
gaplist=[]
for i in range(m-1):
    gaplist.append(x[i+1]-x[i])
gaplist.sort()
if n>1:
    del gaplist[(n-1)*-1:]
print(sum(gaplist))

Measured memory_bytes: 13968
n, k = map(int, input().split())

x = list(map(int, input().split()))
ans = []
for i in range(n-k+1):
    l = x[i]
    r = x[i+k-1]
    ans.append(min((abs(l)+abs(r-l)), abs(r)+abs(l-r)))
print(min(ans))



Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll>   vl;
#define f(i,n)  for(i=0;i<n;i++)
#define f1(i,n)  for(i=1;i<n;i++)
#define fr(i,n) for(i=n-1;i>=0;i--)
#define em emplace_back
#define mp make_pair
#define in insert
#define fi first
#define sc second
#define b begin
#define e end
#define er erase
#define l length
#define c clear
#define si size
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
const double pi=3.141592653;
const ll infi=1000000001;
const ll MOD=1000000007;
const ll mod=998244353;
const string no="NO\n",yes="YES\n";

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

// void dfs(vl v[],ll node,ll hai[]){
//     hai[node]=1;
//     for(auto i:v[node]){
//         if(hai[i]==0){
//             dfs(v,i,hai);
//         }
//     }
// }

// ll con(vl v[],ll hai[],ll sz){
//     ll count=0;
//     for(int i=1;i<sz;i++){
//         if(hai[i]==0){
//             count++;
//             dfs(v,i,hai);
//         }
//     }
    // return count;
// }

// void gcde(int a,int b,int *x,int *y){
//     if(a==0){
//         *x=0;
//         *y=1;
//         return;
//     }    
//     int x1,y1;
//     gcde(b%a,a,&x1,&y1);
    
//     *x=y1-(b/a)*x1;
//     *y=x1;
// }


// ll recur(vl v,ll in,ll m,ll n){
//     if(in==-1)  return 1000000000001;
//     ll d,e,c;
//     d=max(m/v[in],n*v[in]);
//     c=recur(v,in-1,m/v[in],n*v[in]);
//     e=recur(v,in-1,m,n);
//     return min(c,min(e,d));
// }

// ll bexpo(ll a,ll p){
//     ll x=1;
//     while(p){
//     if(p&1){
//         x=(x*a)%mod;
//     }
//     a=(a*a)%mod;
//     p>>=1;
//     }
//     return x;
// }
// int dx[8]{-1,0,0,1,-1,-1,1,1};
// int dy[8]{0,-1,1,0,-1,1,-1,1};


int main() {
    fastio
    int t=1;
    // cin>>t;
    ll n,m,i,l,a,b,c,d,bank,s,k,j,x,y,ans,q;

    while(t--){ans=0;
        cin>>a>>b>>c>>d;
        
       cout<<max({a*c,a*d,b*c,b*d});
       
    }
    
    
	return 0;
}

Measured memory_bytes: 3648
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

LL gcd(LL a, LL b)
{
	if (a < b) std::swap(a, b);
	LL r = a % b;
	while (r != 0)
	{
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}

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

std::vector<std::vector<bool>>field;
std::vector<std::vector<bool>>vis;
LL dx[] = { -1,0,0,1 }, dy[] = { 0,-1,1,0 };
void dfs(LL x, LL y)
{
	if (vis[x][y]) return;
	vis[x][y] = true;
	rep(k, 4)
	{
		LL kx = x + dx[k], ky = y + dy[k];
		if (0 <= kx && kx < field.size() && 0 <= ky && ky < field[0].size())
		{
			if (!field[kx][ky] && !vis[kx][ky]) dfs(kx, ky);
		}
	}
}

LL linking_num()
{
	vis.clear();
	vis.resize(field.size());
	rep(i, vis.size()) vis[i].resize(field[i].size(), false);

	LL res = 0;
	rep(i, field.size())
	{
		rep(j, field[i].size())
		{
			if (!field[i][j] && !vis[i][j])
			{
				dfs(i, j);
				++res;
			}
		}
	}

	return res;
}

LL n, m, q;

int main()
{
	in >> n >> m >> q;
	std::vector<LL>a(q);
	rep(i, q) in >> a[i];

	LL height = lcm(m, 7);
	field.resize(height / 7);
	rep(i, field.size()) field[i].resize(7, false);
	rep(x, field.size())
	{
		rep(y, field[x].size())
		{
			LL num = (x * 7 + y) % m;
			auto it = std::lower_bound(a.begin(), a.end(), num);
			if (it != a.end())
			{
				if (*it == num) field[x][y] = true;
			}
		}
	}

	LL first_num = linking_num();
	rep(i, height / 7) field.push_back(field[i]);
	LL diff_num = linking_num() - first_num;

	out << first_num + diff_num * (n / (height / 7) - 1) << std::endl;
	return 0;
}


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

using namespace std;

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

	int total = 0;
	for (int i = 0; i < N; i++) {
		int h;
		cin >> h;
		if (h >= K) {
			total++;
		}
	}
	cout << total << endl;
}

Measured memory_bytes: 3584