akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define rep(_i,init,N) for(int _i=init;_i<N;++_i)
#define REP(_i,N) for(int _i=0;_i<N;++_i)
#define REP2(_i,_len,N) for(int _i=0,_len=(N);_i<_len;++_i)
#define VREP(v,_itr,_end) for(auto _itr=(v).begin(),_end=(v).end();_itr!=_end;++_itr)
#define VCREP(v,_itr,_end) for(auto _itr=(v).cbegin(),_end=(v).cend();_itr!=_end;++_itr)

using namespace std;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<vb > vvb;
typedef vector<int> vi;
typedef vector<vi > vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll > vvll;

#define SIZE 1000
#define MOD 1'000'000'009

int main(int argc, const char * argv[]) {
    string s,t;
    cin>>s>>t;
    
    int lenS=(int)s.length(),lenT=(int)t.length();
    
    vvi dp(lenS+1);
    REP(i,lenS+1){
        dp[i].resize(lenT+1,0);
    }
    REP(i,lenS) REP(j,lenT){
        if(s[i]==t[j]){
            dp[i+1][j+1]=dp[i][j]+1;
        }else{
            dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);
        }
    }
    
    int len=dp[lenS][lenT];
//    vc ansV(len,0);
    string ans;
    ans.resize(len, 0);
    int i=lenS,j=lenT;
    
    while(len>0){
        if(s[i-1]==t[j-1]){
            ans[len-1]=s[i-1];
            --i;
            --j;
            --len;
        }else if(dp[i][j]==dp[i-1][j]){
            --i;
        }else{
            --j;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 38352
def prm(a):
  if a==1 or a == 4:
    return False
  for i in range(2,int(a**0.5+1)):
    if a%i==0:
      return False
  else:
    return True
x=int(input())
d=[1]*(x+1)
for i in range(1,x+1):
  if prm(i):
    d[i]+=1
  else:
    while not prm(i) and i != 1:
      for j in range(2,i):
        if i%j==0:
          d[j]+=1
          i=i//j
          break
    if i!= 1:
      d[i]+=1
ans=1

for i in range(x+1):
  ans = ans * d[i] % (10**9+7)
print(ans)

Measured memory_bytes: 3064
import heapq

n, m = map(int, input().split())
a = list(map(int, input().split()))
a = list(map(lambda x: x*(-1), a))


heapq.heapify(a)

for i in range(m):
    tmp = heapq.heappop(a)
    heapq.heappush(a, tmp/2)

ans = 0
for num in a:
    ans += int(-num)

print(ans)


Measured memory_bytes: 14180
def op(x,y):
    """
    Outer product
    """
    return(complex.conjugate(x)*y).imag

def isrm(q,i,x):   
    """
    is i right most to q's from view of x?
    """
    for j in q:
        if op(i-x, j-x) < 0:
            return(False)
    return(True)

def rightmost(p,x):
    """
    Find a point in p which is rightmost from x(other than x)
    """
    for i in [i for i in p if i!=x]:
        q = p.copy()
        q.remove(i)
        if isrm(q,i,x):
            return(i)
    raise ValueError('Do not come here')

def solve(p,pf,orig):
    nx = rightmost(p,orig)
    ni = p.index(nx)
    if pf[ni]:   # second visit
        return(pf)
    pf[ni] = True
    return(solve(p,pf,nx))

while True:
    p = []
    n = int(input().strip())
    if n==0:
        break
    for i in range(n):
        x,y = list(map(float, input().strip().split(',')))
        p.append(x+y*1j)
    print(solve(p,[False for _ in range(n)],2000.0 + 0.0*1j).count(False))

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

#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define fast ios::sync_with_stdio(false); cin.tie(NULL);
const double eps = 1e-6;

/////////////////////////////////////////////

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

////////////////////////////////

#define int long long

void solve(){
	
	long double x;
	cin>>x;

	long double ans = x*x*x/27;

	cout<<fixed<<setprecision(10)<<ans<<endl;
}

signed main(){

    //fast;
    int t = 1;
    //cin>>t;
    for(int i = 1 ; i <= t; ++i){

    	solve();
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  int n;
  cin>>n;
  using P = pair<int, int>;
  vector<P> vp;
  for(int i=0;i<n;i++){
    int s,t;
    cin>>s>>t;
    vp.emplace_back(t,s);
  }
  sort(vp.begin(),vp.end());
  int ans=0,lst=0;
  for(auto p:vp)
    if(lst<p.second) lst=p.first,ans++;
  cout<<ans<<endl;
  return 0;
}



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

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

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

    string s;
    cin >> s;
    int k;
    cin >> k;

    set<string> st;

    int sub = min(k, (int)s.size());
    for (int i = 1; i <= sub; i++) {
        for (int j = 0; j < s.size() - i + 1; j++) {
            st.insert(s.substr(j, i));
        }
    }

    auto itr = st.begin();
    rep(i, k - 1) itr++;
    cout << *itr << endl;
}

Measured memory_bytes: 1664
#include <iostream>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

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

int main(){
  int N,X,line;
  cin >> N >> X;
  vector<int> x;
  for (int i=0; i < N; i++){
    cin >> line;
    x.push_back(line);
  }
  x.push_back(X);
  vector<int> diff;
  for(int i=1; i < x.size(); i++){
    diff.push_back(abs(x[i-1] - x[i]));
  }
  int ans = diff[0];
  for(int i=1; i < diff.size(); i++){
    ans = gcd(diff[i], ans);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1400
#include <stdio.h>

int main(void)
{
  int a,b;
  scanf("%d %d\n",&a,&b);
  if(a < b){
    printf("a < b\n");
    }
  else if(a > b){
    printf("a > b\n");
    }
  else if(a ==b){
    printf("a == b\n");
    }
  return 0;
}

Measured memory_bytes: 1752
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
typedef long long ll;
using namespace std;

int main(int argc, char* argv[])
{
	string S;
	cin >> S;

	if(S[2] == S[3] && S[4] == S[5])
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    N = Scanner.int()
    A = Scanner.map_int()
    B = Scanner.map_int()
    C = Scanner.map_int()
    A.sort()
    B.sort()
    C.sort()
    ans = 0
    for i in range(N):
        ok = -1
        ng = N
        while abs(ok - ng) > 1:
            m = (ok + ng) // 2
            if A[m] < B[i]:
                ok = m
            else:
                ng = m
        n = ok + 1
        ok = N
        ng = -1
        while abs(ok - ng) > 1:
            m = (ok + ng) // 2
            if C[m] > B[i]:
                ok = m
            else:
                ng = m
        m = N - ok
        ans += n * m
    print(ans)


def main():
    # sys.stdin = open("sample.txt")
    solve()


if __name__ == "__main__":
    main()


Measured memory_bytes: 115236
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main(){
  int N;
  cin>>N;
  VI A(N);
  rep(i,N) cin>>A[i];
  vector<PII> P(N);
  rep(i,N) P[i]=mp(A[i],i);
  sort(all(P));
  int ans=0;
  rep(i,N) if(abs(i-P[i].second)%2) ans++;
  cout<<ans/2<<endl;
}

Measured memory_bytes: 1536
k = int(input())

checked = [False for _ in range(k)]
r = 0
ans = -1

for i in range(1, k + 1):
    r = (r * 10 + 7) % k
    if checked[r]:
        break
    elif r == 0:
        ans = i
        break
    else:
        checked[r] = True

print(ans)

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

int main()
{
    int n,m;
    cin >> n >>m;
    char inp[n][m];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        cin >> inp[i][j];
    }
    int dp[n][m];
    memset(dp,0,sizeof(dp));
    for(int i=0;i<n;i++)
    {
        if(inp[0][i]=='.')
        dp[0][i]=1;
        else
        break;
    }
    for(int i=0;i<n;i++)
    {
        if(inp[i][0]=='.')
        dp[i][0]=1;
        else
        break;
    }
    for(int i=1;i<n;i++)
    {
        for(int j=1;j<m;j++)
        {
            if(inp[i][j]=='#')
            continue;
            dp[i][j]=(dp[i-1][j]+dp[i][j-1])%1000000007;
        }
    }
    cout << dp[n-1][m-1] << endl;
    
    return 0;
}

Measured memory_bytes: 8444
n,m,l = gets.split(" ").map(&:to_i)
b = readlines.map{|i| i.chomp.split.map(&:to_i)}
a = b.slice!(0,n)
n.times do |i|
  l.times do |j|
    print ' ' if (j != 0)
    c = 0
    m.times do |k|
      c += a[i][k]*b[k][j]
    end
    print c
  end
  puts
end

Measured memory_bytes: 9136
#include "bits/stdc++.h"
#include <random>
#define REP(i, n) for (ll i = 0; i < ll(n); ++i)
#define RREP(i, n) for (ll i = ll(n) - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < ll(n); ++i)
#define RFOR(i, m, n) for (ll i = ll(n) - 1; i >= ll(m); --i)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmax(T &a, const 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;
  vi a(n), b(n);
  REP(i, n) cin >> a[i];
  REP(i, n) cin >> b[i];
  int ans = INF;
  REP(i, 1 << n) {
    vi flag(n);
    REP(j, n) {
      if (j & 1) {
        if (i & (1 << j)) {
          flag[j] = 0;
        } else {
          flag[j] = 1;
        }
      } else {
        if (i & (1 << j)) {
          flag[j] = 1;
        } else {
          flag[j] = 0;
        }
      }
    }
    map<int, vi> mp;
    REP(j, n) {
      int t;
      if (i & (1 << j)) {
        t = b[j];
      } else {
        t = a[j];
      }
      mp[t].push_back(j);
    }
    bool ok = true;
    int sum = 0;
    vi res;
    for (auto a : mp) {
      auto tmp = a.second;
      vvi v(2);
      for (auto t : tmp) {
        v[flag[t]].push_back(t);
      }
      vi cnt(2);
      REP(i, 2) cnt[i] = tmp.size() / 2;
      if (tmp.size() & 1) {

        cnt[sum & 1]++;
      }
      REP(i, 2)if (cnt[i] != v[i].size())ok = false;
      if (!ok)break;
      int f = sum & 1;
      REP(k, tmp.size()) {
        res.push_back(v[f][k / 2]);
        f = 1 - f;
      }
      sum += tmp.size();
    }
    if (!ok)continue;
    int cnt = 0;
    REP(l, n)FOR(r, l + 1, n) {
      if (res[l] > res[r])cnt++;
    }
    chmin(ans, cnt);
  }
  if (ans == INF)cout << -1 << endl;
  else cout << ans << endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int a[10];
int main()
{
    for(int i=0;i<3;i++)
    cin>>a[i];
    sort(a,a+3);
    int sum=0;
    for(int i=1;i<3;i++)
    sum+=a[i]-a[i-1];
    cout<<sum<<endl;
    return 0;
}


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

int main(){
	int n; cin >> n;
	string a,b,c;
	cin >> a >> b >> c;
	int ans = 0;
	rep(j,n){
		int count = 0;
		if(a[j] == b[j] && b[j] == c[j]){
			count = 0;
		}else if(a[j] == b[j] || b[j] == c[j] || a[j] == c[j]){
			count = 1;
		}else{
			count = 2;
		}
		ans += count;
	}
	cout << ans << endl;
	
    return 0;
}



Measured memory_bytes: 256
cards = Hash.new

mark = "SHCD"

4.times{|i|
	cards[mark[i]]=[]
	13.times{
		cards[mark[i]].push false
	}
}

gets.to_i.times{
	arg = gets.split(" ")
	cards[arg[0]][arg[1].to_i - 1] = true
}

4.times{|i|
	13.times{|j|
		puts mark[i]+" "+(j+1).to_s if !cards[mark[i]][j]
	}
}

Measured memory_bytes: 6104
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }
//V,P(大文字)使用不可
//乗算の際にオーバーフローに注意せよ！！（適切にmodをとれ）

const ll INF=1e18;

map<ll,ll> prime_factor(ll n){
    map<ll,ll> res;
    for(int i=2;i*i<=n;i++){
        while(n%i==0){
            ++res[i];
            n/=i;
        }
    }
    if(n!=1) res[n]=1;
    return res;
}

ll mod_pow(ll x,ll n,ll m){
    if(n==0) return 1;
    ll res=mod_pow(x*x%m,n/2,m);
    if(n&1) res=res*x%m;
    return res;
}

signed main(){
    ll n,m;
    cin>>n>>m;
    map<ll,ll> mp=prime_factor(m);
    ll ans=1;
    for(auto p:mp){
        if(p.sc==1){
            ans=(ans*n)%mod;
        }else{
            ll s=p.sc;
            ll cnt=1;
            for(ll i=0;i<s;i++) cnt=(cnt*(n+s-1-i))%mod;
            for(ll i=2;i<=s;i++) cnt=(cnt*mod_pow(i,mod-2,mod))%mod;
            ans=(ans*cnt)%mod;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
// Last modify : 2019年01月16日 星期三 11时24分29秒
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int N, M, X, Y, Z1, Z2, t; 
    int xmax = -1000, xmin = 1000, ymax = -1000, ymin = 1000;
    while ( cin >> N >> M >> X >> Y ) {
        for (int i = 1; i <= N; i++) 
        {
            cin >> t;
            xmax = xmax < t ? t : xmax;
            xmin = xmin > t ? t : xmin;
        }
        for (int i = 1; i <= M; i++)
        {
            cin >> t;
            ymax = ymax < t ? t : ymax;
            ymin = ymin > t ? t : ymin;
        }
        Z1 = X + 1; // Z > X + 1
        Z2 = Y; // Z <= Y
        bool war = true;
        for (int Z = Z1; Z <= Z2; Z++)
        {
            if (Z > xmax && Z <= ymin) {
                war = false;
                break;
            }
        }
        if (!war) cout << "No War\n";
        else cout << "War\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n;
    string s;
    cin >> n >> s;
    vector<vector<int>> sum(n + 1, vector<int>(10, 0));
    REP(i, n) {
        REP(j, 10) {
            if (s[i] == (char)('0' + j)) {
                sum[i + 1][j] = sum[i][j] + 1;
            } else {
                sum[i + 1][j] = sum[i][j];
            }
        }
    }

    set<string> ans;

    FOR(i, 1, n - 1) {
        REP(j, 10) {
            if (sum[i][j] == 0) continue;
            REP(k, 10) {
                if (sum[n][k] - sum[i + 1][k] == 0) continue;
                string str;
                str = str + (char)('0' + j) + s[i] + (char)('0' + k);
                ans.emplace(str);
            }
        }
    }
    cout << sz(ans) << endl;
}



Measured memory_bytes: 2560
#include<iostream>
using namespace std;
int main()
{
int N, count;
  cin >> N;
  count = 0;

  bool check = false;
  for(int i = 0; i < 25; i++){
   for(int j = 0; j < 25; j++){
     if(7*i + 4*j == N){
       check = true;
     }
     if(check == true){
      break; 
     }
   }
  }
  if(check == true){
    cout << "Yes" << endl;
  }
  else{
  cout << "No" << endl;
    }
  }


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import math

numList = []
result = []

user2 = list(map(int, input().split()))


numList.append(user2[0] * user2[2] )
numList.append(user2[0] * user2[3]) 
numList.append(user2[1] * user2[2]  )
numList.append (user2[1] * user2[3])

numList.sort()

print(numList[3])


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

int main()
{
    int N, C, K;
    cin >> N >> C >> K;
    vector<int> T(N);
    for (int i = 0; i < N; i++)
        cin >> T.at(i);

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

    
    
    int n=0;
    int count = 0;

    for (int i=0; i<N; i++) {
        if (T.at(i) > T.at(n) + K || i >= n+C)
            count++, n=i;
    }
    if (n < N) count++;
    
    cout << count << endl;
}

Measured memory_bytes: 640
#include<stdio.h>
    
int main()
{
 int max, goukei, Count=0, i, j, k;
     
 scanf("%d %d", &max, &goukei);
    
 while((max != 0)||(goukei != 0)){
   for(i = 1; i <= max ; i++){
     for(j = i + 1 ; j <= max ; j++){
       for(k = j + 1 ; k <= max ; k++){
         if(i + j + k == goukei){
           Count++;
         }
       }
     }
   }
   printf("%d\n", Count);
      
   Count=0;
   scanf("%d %d", &max, &goukei);
}
 return 0;
}

Measured memory_bytes: 1752
#include <bits/stdc++.h>
#define SEKAI_NO_OWARI return 0;
#define INIT cin.tie(0); ios::sync_with_stdio(false);
#define rep(i, n) for(int i=0; i<n; i++)

using namespace std;

void solve() {
	int n; cin >> n;
	vector<int> p(n);
	for (int i = 0; i < n; i++) {
		//scanf("%d", &p[i]);
		cin >> p[i];
    }

	int res = 0;
	for (int i = 1; i < n - 1; i++) {
		if ((p[i - 1] < p[i]) && (p[i] < p[i + 1])) {
			res++;
		}
		else if ((p[i - 1] > p[i]) && (p[i] > p[i + 1])) {
			res++;
		}
	}
	cout << res << endl;
}

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

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

int arr[107];
int dp[mx];
bool vis[mx];
int n,k;

/// dp[i]= TRUE if it's a wining state for the first player

int main()
{
    cin>>n>>k;

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

    for( int stones= 0;stones<=k;stones++ )
        for( int i=0;i<n;i++ )
            if( stones-arr[i]>=0 and !dp[stones-arr[i]] )
                dp[stones]= 1;

    if( dp[k] )
        cout<<"First\n";
    else
        cout<<"Second\n";
}


Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>

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

int main() {

	int N, K;

	scanf("%d%d", &N, &K);

	ll C = 0;

	rep(a, N + 1) {
		if (!a) continue;
		if (!(2 * a % K)) {
			ll t = (ll)(N - a) / K + 1 + (a - 1) / K;
			C += t * t;
		}
	}

	printf("%lld\n", C);

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;
using namespace std;
int n[4];
int main(){
    
    rep(i,3){
        
        int a,b;
        cin>>a>>b;
        n[a-1]++;
        n[b-1]++;
    }
    rep(i,4){
        if(n[i]>=3){
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;

return 0;
}


Measured memory_bytes: 256
lines = []
while line = gets
    lines << line.chomp.split(' ').map(&:to_i)
end

N = lines[0][0]
M = lines[0][1]

access = []
for i in 1..N do
  access[i-1] = []
end
for j in 1..M do
  access[lines[j][0]-1].push(lines[j][1])
  access[lines[j][1]-1].push(lines[j][0])
end

label = []
unlabeled = []
for i in 1..N do
  unlabeled.push(i)
end

label[0] = 0
for i in 1..N do
  label[i-1] = "none"
end

next_target = [1]
while unlabeled != [] do
  last_target = next_target
  next_target = []
  last_target.each do |go_to|
    access[go_to-1].each do |go_from|
      if label[go_from-1] == "none" then
        label[go_from-1] = go_to
        next_target.push(go_from)
        unlabeled.delete_at(0)
      end
    end
  end
end

puts "Yes"
for i in 2..N do
  puts label[i-1]
end

Measured memory_bytes: 58016
#include <stdio.h>
#include <stdlib.h>
 
#define swap(x, y) {ll tmp = (x); (x) = (y); (y) = tmp;}
 
typedef long long ll;
 
ll n, X;
ll x[100005];
 
ll gcd(ll a, ll b);
ll lcd(ll a, ll b);
 
int main()
{
    ll i, j;
    ll ans;
    
    scanf("%lld %lld", &n, &X);
 
    for (i = 0; i < n; i++) {
        scanf("%lld", &x[i]);
 
        x[i] = abs(x[i] - X);
    }
 
 
    ans = x[0];
    for (i = 1; i < n; i++) {
        ans = gcd(x[i], ans);
    }
 
    printf("%lld\n", ans);
 
    return 0;
}
 
ll gcd(ll a, ll b)
{
    if (a < b) {
        swap(a, b);
    }
 
    while (a != 0) {
        ll r = b % a;
        b = a;
        a = r;
    }
 
    return b;
}

Measured memory_bytes: 896
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#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 n;
    int t[105];
    cin >> n;
    REP(i, n){
        cin >> t[i];
    }

    int m;
    cin >> m;
    int ans = 0;

    REP(i, n){
        ans += t[i];
    }
    
    int p[105], x[105];
    REP(i, m){
        cin >> p[i] >> x[i];
    }

    REP(i, m){
        cout << ans - t[p[i]-1] + x[i] << endl;
    }
}


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

int main() {
  int N;
  cin >> N;
  
  int cnt_min = 1000000000;
  
  for (int i = 0; i < N; i++){
    int A;
    cin >> A;
    int cnt = 0;
    while (A%2 == 0){
      cnt++;
      A /= 2;
    }
    if (cnt < cnt_min)
      cnt_min = cnt;
  }
  
  cout << cnt_min << endl;
}


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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    int ans = 0;
    rep(i, n) {
        cin >> h[i];
        if(h[i] >= k) ans++;
    }
    cout << ans << endl;
}

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

const int N = 2e5 + 9;
string s[N];

struct node {
    node* nxt[26];
    int dp[26];
    node() { 
    	for (int i = 0; i < 26; i++) nxt[i] = NULL; 
    	memset(dp, 0, sizeof dp);
    }
}*root;

void add(string &s) {
    node* cur = root;
    int n = s.size();
    vector<node*> pref(n);
    for (int i = 0; i < n; i++) {
    	pref[i] = cur;
        int b = s[i] - 'a';
        if (cur -> nxt[b] == NULL) cur -> nxt[b] = new node();
        cur = cur -> nxt[b];
    }
    vector<int> cnt(26, 0);
    for (int i = n - 1; i >= 0; i--) {
    	cnt[s[i] - 'a']++;
    	for (int j = 0; j < 26; j++) {
	    	if (cnt[j]) {
	    		pref[i] -> dp[j]++;
	    	}
	    }
    }
}

int yo(string &s) {
    node* cur = root;
    int n = s.size();
    for (int i = 0; i < n - 1; i++) {
        int b = s[i] - 'a';
        cur = cur -> nxt[b];
    }
    return cur -> dp[s.back() - 'a'];
}

int32_t main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	root = new node();
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s[i];
		reverse(s[i].begin(), s[i].end());
		add(s[i]);
	}

	long long ans = 0;
	for (int i = 0; i < n; i++) {
		ans += yo(s[i]) - 1;
	}

	cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 323348
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int N;
int nums[100009];
ll sum=0;

ll calc(int i,int j){
    return abs(nums[i]-nums[j]);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N;
    rep1(i,N) cin>>nums[i];
    nums[0]=nums[N+1]=0;
    
    rep(i,N+1) sum+=calc(i,i+1);
    rep1(i,N){
        ll tmp=sum-calc(i-1,i)-calc(i,i+1)+calc(i-1,i+1);
        cout1(tmp)
    }
}

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

int main(){
  int n;cin>>n;
  double ans;
  if(n==1)ans=1;
  else if(n%2==0)ans=0.5;
  else ans=(n/2+1)/(double)n;
  cout<<setprecision(10)<<ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int h1, m1, h2, m2, k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  cout << h2*60+m2-(h1*60+m1)-k << endk;
  return 0;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define ll unsigned long long
#define mod 1000000007
#define vi vector<ll>
#define pb push_back
#define mp make_pair
#define sp(x,y) fixed<<setprecision(y)<<x
#define mk(arr,n,type) type *arr=new type[n];
#define w(x) ll x; cin>>x; while(x--)
#define endl '\n'
#define str string
#define all(v) v.begin(),v.end()
void kehsihba() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
int32_t main(){
	//kehsihba();
	ll k,a,b;cin>>k>>a>>b;
	bool x=false;
	for(int i=a;i<=b;i++){
		if(i%k==0){
			x=true;break;
		}
	}
	if(x){cout<<"OK";}
	else{cout<<"NG";}
}

Measured memory_bytes: 3584
S=input()
hasN = S.find('N') >= 0
hasS = S.find('S') >= 0
hasE = S.find('E') >= 0
hasW = S.find('W') >= 0
if (hasN and hasS or not hasN and not hasS) and (hasE and hasW or not hasE and not hasW):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 61772
// D - Road to Millionaire
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main(){
	int N; cin>>N;
	vector<int> A(N+1);
	rep(i, N) cin>>A[i];
	ll yen = 1000, kabu_yen, kabu_n = kabu_yen = 0;
	rep(i, N){
		if(A[i] < A[i+1]){ // buy
			ll m = yen / A[i];
			ll cost = (ll)m * A[i];
			yen -= cost;
			kabu_yen += cost;
			kabu_n += m;
		}
		else if(A[i] > A[i+1]){ // sell
			yen += kabu_n * A[i];
			kabu_n = kabu_yen = 0;
		}
	}
	cout<< yen <<endl;
}


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

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

    int n;
    std::cin >> n;
    std::vector<int> a(n);
    for(auto& i : a){
        std::cin >> i;
    }
    for(auto it=a.begin(); it!=a.end(); ++it){
        std::rotate(std::upper_bound(a.begin(), it, *it), it, it+1);
        for(int j=0; j<n; ++j){
            std::cout << a[j] << ((j!=n-1)?" ":"\n");
        }
    }
    return 0;
}

Measured memory_bytes: 3140
#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define iss istringstream
#define sst stringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sh(i) (1LL<<i)
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

int n,q,y[1010],w[1010],x;
string e[1010];

int main(){
	while(cin>>n>>q&&n){
		rep(i,n)cin>>e[i]>>y[i]>>w[i];
		rep(i,q){
			cin>>x;
			int f=0;
			rep(j,n)if(w[j]-y[j]+1<=x&&x<=w[j]){
				cout<<e[j]<<" "<<y[j]-(w[j]-x)<<endl;
				f=1;
				break;
			}
			if(!f)cout<<"Unknown"<<endl;
		}
	}
}

Measured memory_bytes: 984
#include<iostream>
#include<deque>
#include<queue>
#include<math.h>
#include<string>
#include<string.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<iomanip>
#include<map>
#include<bitset>
#include<algorithm>
#include<stack>
#include<unordered_map>
#include<cstdlib>
#include<unordered_set>
#include<algorithm>
#include<chrono>
 
#define inf 0x3f3f3f3f
#define sup_inf 2e18
#define pb push_back
		
#define ii pair	<long long ,long long >
#define i64ii pair< long long, pair<int,int> >
#define i64i pair<long long , int >
#define f first
#define s second
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define iii pair<int, ii >	
#define in freopen("entrada","r",stdin);
#define out freopen("myfile.txt", "w", stdout);
#define eps 1e-9
#define id pair<int ,double > 
#define di pair<double, int>
 
#define pi 3.14159265359
#define nl (no<<1)
#define nr ( (no<<1)|1)
#define mid l + ( (r-l)>>1)
 
using namespace std;

typedef long long ll;	
typedef vector< int> vi;
typedef long double ld;
		
typedef  pair <ii, ii > iiii;
typedef vector < ii > vii;

const int MAX = 1e2;
const int maxn = 1e6 + 100;
 


int n, k, a[maxn];

int main (){
	//~ in
	
	
	scanf("%d %d ",&n, &k);
	for(int i = 0 ;i < n;i++)
		scanf("%d",&a[i]);
		
	sort ( a, a + n,[&](int a, int b ){return a > b;});
	
	ll ans = 0;
	for(int i = n-1;i >= k;--i)
		ans += a[i];
	
	printf("%lld\n", ans );
		
}


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

using namespace std;

int main(void)
{
	int n;
	cin >> n;
	vector<vector<pair<int, int>>> G(n); // (v number, edge number)
	for (int i = 0; i < n-1; i++) {
		int a, b;
		cin >> a >> b;
		G[a-1].push_back(make_pair(b-1, i));
		G[b-1].push_back(make_pair(a-1, i));
	}
	int max = 0;
	for (auto e : G) {
		if (max < e.size())
			max = e.size();
	}
	cout << max << endl;


	vector<int> colors(n-1);
	fill(colors.begin(), colors.end(), -1);

	queue<int> q;
	int root = -1;
	for (int i = 0; i < n; i++) { // find root
		if (G[i].size() == 1) {
			root = i;
			break;
		}
	}
	q.push(root);
	vector<int> u(n, -1);
	while (!q.empty()) {
		int v = q.front();
		q.pop();
		int col = 1;
		for (auto e : G[v]) {
			if (colors[e.second] != -1) {
				continue;
			}
			if (col == u[v])
				col++;
			colors[e.second] = col;
			u[e.first] = col;
			q.push(e.first);
			col++;
		}
	}

	for (auto e : colors)
		cout << e << endl;
	return 0;
}

Measured memory_bytes: 9944
import java.util.*;
import java.io.*;
public class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                PrintWriter ou = new PrintWriter(System.out);
                long n = Long.parseLong(sc.next());
                long p = Long.parseLong(sc.next());
                sc.close();
                if(n == 1){
                        ou.print(p + "\n");
                }else{
                        boolean ebishu = true;
                        for(int i = (int)Math.ceil(Math.pow(p , 1.0 / n)) ; ebishu && i >= 1 ; i--){
                                if(p % (long)Math.pow(i , n) == 0){
                                        ou.print(i + "\n");
                                        ebishu = false;
                                }
                        }
                }
                ou.flush();
        }
}

Measured memory_bytes: 38456
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int a[3],d;
	cin >> a[0] >> a[1]>>a[2]>>d;
	if (abs(a[2] - a[0]) <= d){
		cout << "Yes";
		return 0;
	}
	sort(a, a + 3);
	if (a[2] - a[1] <= d&&a[1] - a[0] <= d){
		cout << "Yes";
	}
	else cout << "No";
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){

  int a,b,c,i;

  int count;

scanf("%d %d %d\n",&a,&b,&c);

  for(i = a,count = 0;i <= b;i++){

    if(c%i == 0)count ++;

  }

  printf("%d\n",count);

return 0;

}
 

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll INF=1e18+1;
int main(){
        ll n,w,sum_val=0;
        cin>>n>>w;
        vector<ll> weight(n),value(n);
        for(int i=0;i<n;i++){
            cin>>weight[i]>>value[i];
            sum_val+=value[i];
        }
        vector<ll> dp(sum_val+1,INF);
        dp[0]=0;
        for(int i=0;i<n;i++){
            for(int j=sum_val-value[i];j>=0;j--){
                dp[j+value[i]]=min(dp[j+value[i]],dp[j]+weight[i]);
            }
        }

        ll ans=0;
        for(int i=0;i<=sum_val;i++){
            if(dp[i]<=w){
                ans=max(ans,(ll)i);
            }
        }


        cout<<ans<<"\n";



}


Measured memory_bytes: 1024
n = int(input())
 
total = 0
three = 3 
five = 5
threefive = 15 
for i in range(1, n + 1):
    if i == threefive:
        three += 3 
        five += 5
        threefive += 15
        continue 
    if i == three:
        three += 3 
        continue 
    if i == five:
        five += 5
        continue 
    total += i 

# print(three)
# print(five)
# print(threefive)

print(total)

Measured memory_bytes: 9192
#include <iostream>

using namespace std;
long long MOD = 1e9+7;
int main()
{
     long long n,sum=0;
    cin>>n;
    long long Arr[n];
    long long pSa[n];
    for(long long i=0 ; i < n ; i++){
        
        cin>>Arr[i];
    }
    for (long long j=0 ;j<n;j++){
        if(j==0){
            pSa[0]=Arr[0];
        }
      else{
          pSa[j]=pSa[j-1]+Arr[j];
      }
    }
    for(long long k=0;k<n;k++){
        long long a = Arr[k]%MOD;
        long long b = (pSa[n-1] - pSa[k])%MOD;
        long long c = ((a%MOD)*(b%MOD))%MOD;
        sum += c%MOD;
    }
    cout<<sum%MOD<<endl;
   return 0;
}

Measured memory_bytes: 6676
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main()
{
    int N, L; cin >> N >> L;
    int sum = 0;
    int absmin = 1e9;
    for (int i = 1; i <= N; i++) {
        int taste = L + i - 1;
        sum += taste;
        if (abs(taste) < abs(absmin)) absmin = taste;
    }
    cout << sum - absmin << '\n';
    return 0;
}

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

using namespace std;

int main(){
  long long int N,K;
  vector<long long int> H;
  cin >> N >> K;
  for(int n=0;n<N;n++){
    long long int h; 
    cin >> h;
    H.push_back(h);
  }
  sort(H.begin(),H.end());
  long long int sum=0;
  for(int m=0;m<N-K;m++){
    sum+=H[m];
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 2676
import sys
from collections import Counter, deque, defaultdict
from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
from functools import reduce
from math import ceil, floor, log10, factorial
import math

sys.setrecursionlimit(1000000)

MOD = 10 ** 9 + 7

INF = float('inf')
# N = int(input())
# A = [int(x) for x in input().split()]
# A = [int(input()) for _ in range(N)]
# dp = [[0] * 100 for _ in range(100)]
# dp = defaultdict(lambda: float('inf'))
# print('hoge', file=sys.stderr)

N, M = [int(x) for x in input().split()]

# E = {set() for _ in range(N + 1)}
E = defaultdict(lambda: set())

for i in range(M):
    u, v = [int(x) for x in input().split()]
    u -= 1
    v -= 1
    E[3 * u].add(3 * v + 1)
    E[3 * u + 1].add(3 * v + 2)
    E[3 * u + 2].add(3 * v)

S, T = [int(x) for x in input().split()]
S = 3 * (S - 1)
T = 3 * (T - 1)


def bfs(e, start, end):
    open = deque([start])
    w = dict()
    w[start] = 0
    while len(open) != 0:
        target = open.popleft()
        for next in E[target]:
            if not next in w:
                open.append(next)
                w[next] = w[target] + 1

    return w[end] // 3 if end in w else -1


print(bfs(E, S, T))


Measured memory_bytes: 137208
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,M,C;
  cin>>N>>M>>C;
  vector<int> B(M);
  vector<vector<int>> A(N,vector<int>(M));
  for(int i=0;i<M;i++){
    cin>>B.at(i);
  }
  for(int i=0;i<N;i++){
    for(int j=0;j<M;j++){
      cin>>A.at(i).at(j);
    }
  }
  
  int count = 0;
  for(int i=0;i<N;i++){
    int sum=0;
    for(int j=0;j<M;j++){
      sum+=A.at(i).at(j)*B.at(j);
    }
    if(sum+C>0){
      count++;
    }
  }
  cout<<count<<endl;
  
  return 0;
}

Measured memory_bytes: 256
from itertools import permutations

N = int(input())
P = input().split()
Q = input().split()
  
L = list(permutations("".join(list(map(str,list(range(1,N+1))))), N))

idx = 0
for l in L:
  #print(P,Q,l)
  if P == list(l):
    a = idx
  if Q == list(l):
    b = idx
  idx += 1
  
print(abs(b-a))


Measured memory_bytes: 46448
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;

public class Main {
    static Input in = new Input(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int D = in.nextInt();
        int[] c = new int[26];
        for (int i = 0; i < 26; i++)
            c[i] = in.nextInt();
        int[][] s = new int[D][26];
        for (int d = 0; d < D; d++) for (int i = 0; i < 26; i++)
            s[d][i] = in.nextInt();

        int[] ans = new int[D];
        for (int d = 0; d < D; d++)
            ans[d] = in.nextInt();
        for (int d = 0; d < D; d++)
            out.println(score(d + 1, c, s, ans));

        out.flush();
    }

    static long score(int D, int[] c, int[][] s, int[] array) {
        long S = 0;
        int[] last = new int[26];
        for (int d = 0; d < D; d++) {
            last[array[d] - 1] = d + 1;
            S += s[d][array[d] - 1];
            for (int i = 0; i < 26; i++)
                S -= c[i] * (d + 1 - last[i]);
        }
        return S;
    }

    static class Input {
        private BufferedReader br;
        private String[] buff;
        private int index = 0;

        Input(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }
        String nextLine() {
            try {
                return br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
        String next() {
            while (buff == null || index >= buff.length) {
                buff = nextLine().split(" ");
                index = 0;
            }
            return buff[index++];
        }
        byte nextByte() {
            return Byte.parseByte(next());
        }
        short nextShort() {
            return Short.parseShort(next());
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        float nextFloat() {
            return Float.parseFloat(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        BigInteger nextBigInteger() {
            return new BigInteger(next());
        }
        BigDecimal nextBigDecimal() {
            return new BigDecimal(next());
        }
    }
}



Measured memory_bytes: 35556
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MOD=1e9+7;
const long double Pi=acos(-1);
using  P=pair<ll,ll>;
int main(){
  ll counte=0,countw=0;
  string str;
  cin>>str>>str;
  vector<ll> w((ll)str.size());
  vector<ll> e((ll)str.size());
  for(ll i=0;i<(ll)str.size();i++){
    if(i==0){
      if(str.at(i)=='E'){e.at(i)=1;w.at(i)=0;counte++;}
      else{e.at(i)=0;w.at(i)=1;countw++;}
    }
    else{
      if(str.at(i)=='E'){e.at(i)=e.at(i-1)+1;w.at(i)=w.at(i-1);counte++;}
      else{e.at(i)=e.at(i-1);w.at(i)=w.at(i-1)+1;countw++;}
    }
  }
  ll ans;
  for(ll i=0;i<(ll)str.size();i++){
    if(i==0){ans=counte-e.at(0);}
    else if(i==(ll)str.size()-1){ans=min(ans,w.at(i));}
    else{ans=min(ans,w.at(i-1)+counte-e.at(i));}
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 5380
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#include <random>
#include <cassert>
using namespace std;

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<int, ll> i_ll;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
typedef vector<int> vi;
struct edge { int v; ll w; };

const int MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;
ll INF = INT_MAX;

struct binary_heap {
	int N;
	vector<int> a;
	binary_heap() : N(0) {}
	void push(int x) {
		a.pb(x); N++;
		for (int i = N - 1; i;) {
			int _i = (i - 1) / 2;
			if (a[_i] >= a[i]) break;
			swap(a[i], a[_i]);
			i = _i;
		}
	}
	int pop() {
		int x = a[0];
		swap(a[0], a[N - 1]);
		a.pop_back(); N--;
		for (int i = 0; i * 2 + 1 < N;) {
			int _i = i * 2 + 1;
			if (_i + 1 < N && a[_i] < a[_i + 1]) _i++;
			if (a[_i] <= a[i]) break;
			swap(a[i], a[_i]);
			i = _i;
		}
		return x;
	}
};

int main() {
	// binary_heap q;
	priority_queue<int> pq;
	for (;;) {
		char s[10]; scanf("%s", s);
		if (s[2] == 's') {
			int x; scanf("%d", &x);
			pq.push(x);
		}
		if (s[2] == 't') {
			int x = pq.top(); pq.pop();
			printf("%d\n", x);
		}
		if (s[2] == 'd') break;
	}
}

Measured memory_bytes: 6972
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

int main(){
    int n;
    cin>>n;
    cout<<48-n<<endl;
}


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

int main()
{
	long long n, m; cin >> n >> m;
	
	long long tmp;

	if (m < n) {
		tmp = m;
		m = n;
		n = tmp;
	}

	long long ans;

	if (n == 1 && m == 1) {
		ans = 1;
	}
	else if (n == 1) {
		ans = m - 2;
	}
	else {
		ans = (n - 2) * (m - 2);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>

using namespace std;
typedef long long int ll;

#define C cout<<
#define E <<endl

ll n,m,a,b,c,x,y,z,aa[100010],ba[100010];
bool r,ra,rb,rc;
string s,sa,sb,sc;
char ca,cb,cc[1000][1000],cd[1000][1000];
vector<ll> va,vb,vc;

int main(){
    cin>>n>>a;
    z=0;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            if(i+j<=a and a-i-j<=n)z++;
        }
    }
    C z E;
    
}

Measured memory_bytes: 256