akhauriyash/Code-Regression huggingface dataset:
n = int(input())
A = list(map(int, input().split(' ')))
q = int(input())
M = list(map(int, input().split(' ')))

# 上限と下限でフィルター
max_A = 0
min_A = float('inf')
for num in A:
    max_A += num
    if num < min_A:
        min_A = num

def rec(i, m):
    if m < 0:
        return False
    elif m == 0:
        return True
    if i >= n:
        return False

    rst = rec(i+1, m - A[i]) or rec(i+1, m)
    return rst

for m in M:
    if m < min_A or max_A < m:
        print('no')
    elif rec(0, m):
        print('yes')
    else:
        print('no')



Measured memory_bytes: 5632
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 2000000001; 
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int N; ll M; cin >> N >> M;
    ll lm = 1;
    ll data[N];
    F0R(i, N) {
        ll cur; cin >> cur; data[i] = cur;
        ll g = __gcd(lm, cur);
        lm = lm * cur / g;
        if (lm >= MX) {
            cout << 0 << endl; return 0;
        }
    }

    ll res = lm / 2;
    F0R(i, N) {
        if (res % data[i] != data[i] / 2) {
            cout << 0 << endl; return 0;
        }
    }

    ll ans = M / lm;
    ll val = M % lm;
    if (val >= lm / 2) ans++;
    cout << ans << endl;
	
	return 0;
}
 



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
#define INF (1LL << 60)
#define mod 1000000007
#define dbg(x) cout<<#x"="<<x<<endl
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef pair<vll, vll> pvll;

struct state {
  ll d, v, p;

public:
  bool operator<(const state s) const { return d > s.d; }
};

const ll S = 0, G = 1;
ll N, M, A[100000], B[100000], C[100000];
vector< vector<pll> > E1(100000), E2(100000);

pvll dijkstra(vector< vector<pll> > &E, ll s) {
  vll dist(N, INF), cnt(N, 0);
  priority_queue<state> q;
  q.push((state) { 0, s, -1});
  cnt[s]=1;
  dist[s]=0;

  while(q.size()) {
    ll d = q.top().d, v = q.top().v, p = q.top().p;
    q.pop();

    if(dist[v] < d) continue;  

    REP(i, 0, E[v].size()) {
      ll u = E[v][i].first, c = E[v][i].second;
      if(dist[u] == d + c){
        (cnt[u] += cnt[v])%=mod;
      }else if(dist[u] > d + c){
        dist[u] = d + c;
        cnt[u]=cnt[v];
        q.push((state) { d + c, u, v });
      }
    }
  }

  return pvll(dist, cnt);
}

int main(void) {
  cin >> N >> M;
  REP(i, 0, M) {
    cin >> A[i] >> B[i] >> C[i]; A[i]--; B[i]--;
    E1[A[i]].push_back(pll(B[i], C[i]));
    E2[B[i]].push_back(pll(A[i], C[i]));
  }

  pvll d1 = dijkstra(E1, S), d2 = dijkstra(E2, G);
  vll dist1 = d1.first, dist2 = d2.first, cnt1 = d1.second, cnt2 = d2.second;

  ll orgd = dist1[G];
  ll orgc = cnt1[G];

  REP(i, 0, M) {
    ll u = A[i], v = B[i], cost = C[i];
    if(dist1[v] + cost + dist2[u] < orgd) cout << "HAPPY" << endl;
    else if(dist1[u] + cost + dist2[v] == orgd && (cnt1[u] * cnt2[v])%mod == orgc) cout << "SAD" << endl;
    else cout << "SOSO" << endl;
  }
}

Measured memory_bytes: 22276
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
const ll mod = 998244353;
vector<int> a(4000);
int n,s;
ll dp[4000][4000][3];
int ways(int l,int r,int S){
    if(S == 0){
        return 1;
    }
    if(r == l){
        return 0;
    }
    return ways(l,r-1,S) + (S>=a[r-1]?ways(l,r-1,S-a[r-1]):0);
}



int main(){
    cin >> n >> s;
    for(int i = 0;i<n;++i){
        cin >> a[i];
    }
   
    /*
     int ans  = 0;
    for(int i = 0;i<n;++i){
        for(int j = i;j < n;++j){
            ans += ways(i,j+1,s);
            if(ans >= mod){
                ans-=mod;
            }
        }
    }
    
    cout << ans <<"\n";
    */
   auto add =[&](ll &x,ll y){
       x += y;
       if(x >= mod){
           x-=mod;
       }
   };
   
   memset(dp,0LL,sizeof dp);
   dp[0][0][0] = 1;
   for(int i = 0;i<n;++i){
       for(int j = 0;j<=s;++j){
            (dp[i+1][j][0] += dp[i][j][0]) %= mod;
            (dp[i+1][j][1] += dp[i][j][0] + dp[i][j][1]) %= mod;
            (dp[i+1][j][2] += dp[i][j][0] + dp[i][j][1] + dp[i][j][2]) %= mod;
            if(j + a[i] <= s){
                (dp[i+1][j+a[i]][1] += dp[i][j][0] + dp[i][j][1]) %= mod;
                (dp[i+1][j+a[i]][2] += dp[i][j][0] + dp[i][j][1]) %= mod;
            }
       }
   }
   cout << dp[n][s][2] <<"\n";
    return 0;    
}

Measured memory_bytes: 375296
s = input()
if s == "SUN":
    print(7)
elif s == "MON":
    print(6)
elif s == "TUE":
    print(5)
elif s == "WED":
    print(4)
elif s == "THU":
    print(3)
elif s == "FRI":
    print(2)
elif s == "SAT":
    print(1)

Measured memory_bytes: 3060
#include <stdio.h>

int main(void)
{
	int H,W,a,b;
	while(1){
		scanf("%d %d",&H,&W);
		if(H==0&&W==0){
			break;
		}
		for(a=1;a<H;a++){
			for(b=1;b<W;b++){
				printf("#");
			}
			printf("#\n");
		}
		for(b=1;b<W;b++){
			printf("#");
		}
		printf("#\n\n");
	}
	return 0;
}

Measured memory_bytes: 588
import java.util.*;

public class Main {

    public static void main(String[] args) {
	    // write your code here
        Scanner sc = new Scanner(System.in);

        // 整数の入力
        int n = sc.nextInt();
        int m = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();

        int maxX = x;
        int minY = y;
        for(int i = 0; i < n; i++) {
            int value = sc.nextInt();
            if (value > maxX) {
                maxX = value;
            }
        }
        for(int i = 0; i < m; i++) {
            int value = sc.nextInt();
            if (value < minY) {
                minY = value;
            }
        }

        // 出力
        System.out.println(minY > maxX ? "No War" : "War");
    }
}


Measured memory_bytes: 21844
import java.util.*; 
class Main {
   public static void main(String[] args) {
      
        Scanner sc = new Scanner(System.in);
       int sam = sc.nextInt();
       int tako[] = new int [sam];
       
       int cnt = 0;
       for(int i = 0; i < sam; i++){
           tako[i] = sc.nextInt();
       }
       
       int now = 0;
       for(int i = sam-1; i >= 0; i--){
           now = tako[i];
           for(int j = i-1; j >= 0;j--){
               cnt += tako[j] * now;
           }
       }
     System.out.print(cnt);
   }
}


Measured memory_bytes: 21972
import math

N=int(input())

L=[]
T=[]
for i in range(N):
    L.append(tuple(int(x) for x in input().split()))

for i in range(N):
    for j in range(i+1,N):
        T.append(math.sqrt((L[i][0]-L[j][0])**2+(L[i][1]-L[j][1])**2))

print(sum(T)*(N-1)/len(T))


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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int MOD, n;
vi S;

void maltiple(vvi& mat){
    vi nextS(n);

    rep(i, n){
        rep(j, n){
             (nextS[i] += mat[i][j] * S[j]) %= MOD;
        }
    }

    S = nextS;
        //pow(mat);
}

void mul(vvi& a, vvi& b){
    vvi res(n, vi(n));

    rep(i, n){
        rep(j, n){
            rep(k, n){
                (res[i][j] += a[i][k] * b[k][j]) %= MOD;
            }
        }
    }

    a = res;
}

int main(void){
    for(int a, b, c, t; cin >> n >> MOD >> a >> b >> c >> t, n;){
        S = vi(n, 0);

        rep(i, n){
            cin >> S[i];
        }

        vvi mat(n, vi(n, 0));
        rep(i, n){
            mat[i][i] = b;
            if(i != n - 1){
                mat[i + 1][i] = a;
                mat[i][i + 1] = c;
            }
        }
        vvi D;

        bool ok = t != 0;
        rep(i, 30){
            bool run = t & 1;
            t >>= 1;

            if(run){
                if(D.size() == 0) D = mat;
                else mul(D, mat);
            }

            mul(mat, mat);
            if(t == 0) break;
        }
        if(ok) maltiple(D);

        rep(i, n) cout << (i ? " ":"") << S[i];
        cout << endl;
    }

	return 0;
}

Measured memory_bytes: 1268
import sys
N, M = map(int, input().split())
 
dp_f = [None] * (10**5 + 2)
dp_f[1] = 1
dp_f[2] = 1
for i in range(3, 10**5 + 1):
    dp_f[i] = dp_f[i-1] + dp_f[i-2]
def f(n):
    if n == 1:
        return 1
    elif n == 2:
        return 1
    elif dp_f[n] is not None:
        return dp_f[n]
    v = f(n-1) + f(n-2)
    dp_f[n] = v
    return dp_f[n]
 
if M == 0:
    m = f(N+1)
    m %= 1000000007
    print(m)
    sys.exit(0)
 
A = [int(input()) for i in range(M)]
 
S = []
S.append(A[0])
for i in range(1, M):
    if A[i] == A[i-1] + 1:
        print(0)
        sys.exit(0)
    S.append(A[i] - A[i-1] - 1)
S.append(N - A[-1])
 
m = 1
for s in S:
    m *= f(s)
    m %= 1000000007
 
print(m)

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

int main()
{
    int n;
    string s, t;
    cin >> n >> s >> t;
    string ans = "";

    rep(i, n)
    {
        ans += s.at(i);
        ans += t.at(i);
    }

    cout << ans << endl;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
const int N=205;
char s[N];
int a[N][N],flag[N],n;
void dfs(int x){
	for (int i=1;i<=n;i++)
		if (a[x][i]){
			if (!flag[i]){
				flag[i]=3-flag[x];
				dfs(i);
			}
			else if (flag[i]+flag[x]!=3){
				puts("-1");
				exit(0);
			}
		}
}
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++){
		scanf("%s",s+1);
		for (int j=1;j<=n;j++)a[i][j]=s[j]-'0';
	}
	flag[1]=1;dfs(1);
	for (int i=1;i<=n;i++)
		for (int j=1;j<=n;j++)
			if (i!=j&&!a[i][j])a[i][j]=1e9;	
	for (int k=1;k<=n;k++)
		for (int i=1;i<=n;i++)
			for (int j=1;j<=n;j++)a[i][j]=min(a[i][k]+a[k][j],a[i][j]);
	int ans=0;
	for (int i=1;i<=n;i++)
		for (int j=1;j<=n;j++)
			ans=max(ans,a[i][j]);
	printf("%d\n",ans+1);				
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int> 
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
ll x[11];
ll n,m;
int main(){
    cin>>n>>m>>x[0];
    for(int i=1;i<=10;i++){
        x[i]=x[i-1]*n-m;
        cout<<x[i]<<endl;
    }
    return 0;
}

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

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

int main() {
  string s, t;
  cin >> s >> t;
  unordered_map<char, char> mp, imp;
  bool flg = true;

  for (int i = 0; i < s.size(); ++i) {
    char cs = s[i], ct = t[i];
    if(mp.count(cs))
      if (mp[cs] != ct) flg = false;
    if(imp.count(ct))
      if (imp[ct] != cs) flg = false;
    mp[cs] = ct, imp[ct] = cs;
  }
  cout << (flg ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 776
#include<bits/stdc++.h>
using namespace std;
int main() {
	int k;
	string s;
	cin>>k>>s;
	if(s.length()<=k)cout<<s;
	else{
		string ss = s.substr(0,k);
		ss = ss+ "...";
		cout<<ss;
	}
	
 
 }

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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void c_p_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

int32_t main()
{
	c_p_c();
	int n, k; cin >> k >> n;

	mk(arr, n, int);

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

	vi v;

	for (int i = 0; i < n - 1; ++i)
		v.pb(arr[i + 1] - arr[i]);

	v.pb(k + arr[0] - arr[n - 1]);

	cout << (k - *max_element(v.begin(), v.end()));
	return 0;
}

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

int main(void){
    int X,A,B; cin >> X >> A >> B;
    if(A>=B) cout << "delicious" << endl;
    else if(A+X >= B) cout << "safe" << endl;
    else cout << "dangerous" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>

//#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long int
#define pb push_back

int main() {
  ll N;
  cin >> N;
  vector<ll> a(N);
  int cnt = 0;
  rep(i, N){
    cin >> a[i];
    if(a[i] < 0){
      cnt++;
      a[i] = -a[i]; // 絶対値をとった値にする
    }
  }
  sort(a.begin(), a.end());
  ll ans = 0;
  rep(i, N){
      ans += a[i];
  }
  if(cnt % 2 != 0){ // 奇数の場合は頑張っても1つはマイナスになるため、絶対値の小さいものを引く
    ans -= a[0]*2;
  } 
  

  
  cout << ans << endl;

}


Measured memory_bytes: 1024
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    ll x,ans=0; cin>>x;
    ans+=(x/11)*2;
    x%=11;
    if(x>6) ans+=2;
    else if(x>0) ans+=1;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

int main(){
    int n, k;
    string s;
    cin >> n >> k >> s;
    s[k-1] += 'a'-'A';
    cout << s << endl;
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    int a[n], b[n], c[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];
    for (int i = 0; i < n; i++) cin >> c[i];

    sort(a, a + n);
    sort(b, b + n);
    sort(c, c + n);

    int cnt[n];
    for (int i = 0; i < n; i++) {
        cnt[i] = c + n - upper_bound(c, c + n, b[i]);
    }
    
    ll cntsum[n + 1];
    for (int i = 0; i <= n; i++) {
        cntsum[i] = 0;
    }
    for (int i = n - 1; i >= 0; i--) {
        cntsum[i] = cntsum[i + 1] + cnt[i];
    }

    ll ans = 0;
    for (int i = 0; i < n; i++) {
        int j = upper_bound(b, b + n, a[i]) - b;
        ans += cntsum[j];
    }

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

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

int main(void) {
  int N;
  cin >> N;
  vector<long long> A(N);
  map<long long, long long> sum;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    sum[i + A[i]]++;
  }

  long long ans = 0;
  for (int i = 0; i < N; i++) {
    long long z = i - A[i];
    if (sum.count(z)) {
      ans += sum[z];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 17020
package main

import "fmt"

const inf = 1 << 60

func diff(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

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

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	xs := make([]int, n)
	for i := range xs {
		fmt.Scan(&xs[i])
	}

	ans := inf
	for l := 0; l <= n-k; l++ {
		r := l + k - 1
		route1 := diff(0, xs[l]) + diff(xs[l], xs[r])
		route2 := diff(0, xs[r]) + diff(xs[r], xs[l])
		tmp := min(route1, route2)
		if tmp < ans {
			ans = tmp
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 7296
#include<iostream>
#define ll long long
using namespace std;


int main(){
      ll l,r;cin >> l >> r;
      ll ans = 2018;

      if(r-l>=2019){
            cout << 0 << endl;
      }else{
            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 <cstdio>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <cmath>
#include <stack>

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

using namespace std;

int main(){
    string s;
    cin >> s;
    if((s[0] == s[1]) && (s[1] == s[2])) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
public class Main {

  private static void solve() {
    long n = nl();
    long k = nl();

    System.out.println(Math.min(n % k, k - n % k));

  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 36716
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int w, h, n;
    cin >> w >> h >> n;

    vector<int> x(n), y(n);
    for(int i=0; i<n; ++i)
        cin >> x[i] >> y[i];

    vector<int> x0 = x;
    vector<int> y0 = y;
    sort(x0.begin(), x0.end());
    sort(y0.begin(), y0.end());

    long long ret = LLONG_MAX;
    int tx, ty;
    for(int i=-15; i<=15; ++i){
        for(int j=-15; j<=15; ++j){
            if(n/2 + i < 0 || n/2 + i >= n || n/2 + j < 0 || n/2 + j >= n)
                continue;
            int sx = x0[n/2+i];
            int sy = y0[n/2+j];

            long long tmp = 0;
            long long maxDist = 0;
            for(int k=0; k<n; ++k){
                long long dist = abs(sx - x[k]) + abs(sy - y[k]);
                tmp += dist * 2;
                maxDist = max(maxDist, dist);
            }
            tmp -= maxDist;

            if(tmp < ret){
                ret = tmp;
                tx = sx;
                ty = sy;
            }
            ret = min(ret, tmp);
        }
    }

    cout << ret << endl;
    cout << tx << ' ' << ty << endl;

    return 0;
}

Measured memory_bytes: 2432
#include <stdio.h>
#include <limits.h>
 
using namespace std;
 
int main(){
    int n,tmp,min=INT_MAX,max=INT_MIN;
    scanf("%d",&n);
    for(int i = 0; i < n; i++){
        scanf("%d",&tmp);
        if(max < tmp-min) max = tmp - min;
        if(min > tmp) min = tmp;
    }
    printf("%d\n",max);
    return 0;
}


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

int main()
{
    int n, k, sum = 0;
    cin >> n >> k;
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    sort(p.begin(), p.end());
    rep(i, k) sum += p[i];
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3604
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

n = int(input())

a = n % 10

if a == 2 or a == 4 or a == 5 or a == 7 or a == 9:
    print("hon")
elif a == 0 or a == 1 or a == 6 or a == 8:
    print("pon")
else:
    print("bon")


Measured memory_bytes: 9116
#include <iostream>
bool isLeapYear(int year)
{
    return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;
}

bool printLeapYears(int from, int to)
{
    bool found = false;
    for (int i = from; i <= to; i++) {
        if (isLeapYear(i)) {
            std::cout << i << std::endl;
            found = true;
        }
    }
    return found;
}

int main()
{
    int from, to;
    bool found;
    bool isFirst = true;
    while (true) {
        std::cin >> from >> to;
        if (from == 0 && to == 0) {
            break;
        }
        if (!isFirst) {
            std::cout << std::endl;
        }
        isFirst = false;
        if (!printLeapYears(from, to)) {
            std::cout << "NA" << std::endl;
        }
    }
}

Measured memory_bytes: 3004
#include<map>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
map<string,int>T;
int n,l,ans;string c;
string o[205];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>c;
		if(!T[c])o[++l]=c;
		T[c]++;
	}
	cin>>n;
	for(int i=1;i<=n;i++)
	{cin>>c;T[c]--;}
	for(int i=1;i<=l;i++)
		ans=max(ans,T[o[i]]);
	cout<<ans<<endl;
}


Measured memory_bytes: 256
def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)
n=int(input())
mod=1000000007
s=[int(i) for i in input().split()]
ans=1
for i in s:
    ans*=i//gcd(ans,i)
print(sum(ans//i for i in s)%mod)

Measured memory_bytes: 4084
#include <iostream>

using namespace std;

int main()
{
    int h, w;
    cin >> h >> w;
    char pic[h][w];
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> pic[i][j];
        }   
    }   

    for (int i = 0; i < w + 2; i++) {
        cout << "#";
    }   
    cout << endl;
    for (int i = 0; i < h; i++) {
        cout << "#";
        for (int j = 0; j < w; j++) {
            cout << pic[i][j];
        }   
        cout << "#" << endl;;
    }   
    for (int i = 0; i < w + 2; i++) {
        cout << "#";
    }   
    cout << endl;
}




Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<numeric>
#include<stack>
#include<map>
#include<queue>
#include<unordered_map>
#include<cmath>
#include<utility>

using ULL = unsigned long long;
using LL = long long;
using String = std::string;
using Ints = std::vector<int>;
using Doubles = std::vector<double>;
using Bools = std::vector<bool>;
using Strings = std::vector<std::string>;
using ULLs = std::vector<ULL>;
using LLs = std::vector<LL>;

// pythonのdictionary相当
template <typename T1, typename T2>
using Dict = std::unordered_map<T1,T2>;



template <typename T>
int MegurubinarySearch(std::vector<T> &a, T key, bool mode) {
    T ng = -1;
    T ok = (int)a.size();

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1) {
        T mid = (ok + ng) / 2;

        bool okng;
        if (mode && a[mid] >= key) okng = true;
        else if (!mode && a[mid] > key) okng = true;
        else okng = false;

        if (okng) ok = mid;
        else ng = mid;
    }
    return ok;
}

int main(void) {
    int N;
    LLs a,b,c;
    std::cin >> N;

    for(int i=0;i<N;i++){
        LL _a;
        std::cin >> _a;
        a.emplace_back(_a);
    }
    for(int i=0;i<N;i++){
        LL _b;
        std::cin >> _b;
        b.emplace_back(_b);
    }
    for(int i=0;i<N;i++){
        LL _c;
        std::cin >> _c;
        c.emplace_back(_c);
    }

    std::sort(a.begin(),a.end());
    std::sort(b.begin(),b.end());
    std::sort(c.begin(),c.end());

    LL res = 0;

    for(auto _b:b){
        LL tmp = MegurubinarySearch<LL>(a, _b, true);
        tmp *= (N - MegurubinarySearch<LL>(c, _b, false));
        res += tmp;
    }

    std::cout << res << std::endl;

    return 0;
}

Measured memory_bytes: 6428
#include<stdio.h>
#include<string.h>
int valid(char a,char b)
{
    if(a=='0'&&b=='0')return 0;
    if(a=='1'&&b>'2')return 0;
    if(a>'1')return 0;
    return 1;
}
int main()
{
    char s[5];
    scanf("%s",s);
    if(valid(s[0],s[1]) && valid(s[2],s[3]))
    {
        puts("AMBIGUOUS");
    }else if(valid(s[0],s[1]))
    {
        puts("MMYY");
    }else if(valid(s[2],s[3]))
    {
        puts("YYMM");
    }else
    {
        puts("NA");
    }
    
}

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

int main() {
	int count = 0, number, a;

	//入力をもらう
	cin >> number;

	if (number / 100 == 1) count++;
	if (number % 100 == 10 || number % 100 == 11) count++;
	if (number % 10 == 1) count++;
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//ミョ(-ω- ?)
int main() {
    ll n,k;
    cin >> n >> k;
    ll res = 0;
    for (long long i = k; i <= n+1; ++i) {
        res = (res + ((n*2-i+1) * i / 2) -(i * (i-1) / 2)+ 1) % MOD;
    }
    cout << res%MOD << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int (i)=0;(i)<(n);++(i))
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);++(i))
#define EACH(e,v) for(auto& e:v)
#define ALL(v) (v).begin(),(v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort((v).rbegin(),(v).rend())
#define PERM(v) SORT(v);for(bool c##p=1;c##p;c##p=next_permutation(ALL(v)))
#define UNIQUE(v) SORT(v);(v).erase(unique(ALL(v)),(v).end())
template<typename A,typename B> inline bool chmax(A &a,const B &b){if(a<b){a=b;return 1;}return 0;}
template<typename A,typename B> inline bool chmin(A &a,const B &b){if(a>b){a=b;return 1;}return 0;}

const int MOD = (int)1e9 + 7;
const int INF = 1 << 30;
const ll INFF = 1LL << 62;

int N, M;
vector<vector<int>> A;

bool check(int mid) {
    set<int> ng;
    queue<int> q[N];
    REP(i, N) {
        REP(j, M) {
            q[i].emplace(A[i][j]);
        }
    }
    while (true) {
        vector<int> v(M + 1, 0);
        REP(i, N) {
            v[q[i].front()]++;
        }
        int mx = *max_element(v.begin(), v.end());
        if (mx <= mid) {
            break;
        } else {
            int piv = 0;
            while (v[piv] != mx) ++piv;
            ng.insert(piv);
            REP(i, N) {
                while (ng.count(q[i].front())) {
                    q[i].pop();
                    if (q[i].size() == 0) {
                        return false;
                    }
                }
            }
        }
    }
    return true;
}

signed main() {

    cin >> N >> M;

    A.resize(N);
    REP(i, N) {
        A[i].resize(M);
        REP(j, M) cin >> A[i][j];
    }

    ll ok = N, ng = 0;
    while (abs(ok - ng) > 1) {
      ll mid = (ok + ng) / 2;
      if (check(mid)) {
        ok = mid;
      } else {
        ng = mid;
      }
    }
    
    cout << ok << endl;

}

Measured memory_bytes: 1184
N = int(input())
List = []
for a in range(N):
    List.append(int(input()))

A = sorted(List)
Lmax = A[-1]
lmax = A[-2]
for i in range(N):
    if List[i] == Lmax:
        print(lmax)
    else:
        print(Lmax)

Measured memory_bytes: 70104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()
template <int MOD>
class ModInt {
  long long x;

 public:
  ModInt(long long v = 0) : x(v % MOD) {
    if (x < 0) x += MOD;
  }

  ModInt& operator+=(const ModInt& r) {
    x += r.x;
    if (x >= MOD) x -= MOD;
    return *this;
  }

  ModInt& operator-=(const ModInt& r) {
    x -= r.x;
    if (x < 0) x += MOD;
    return *this;
  }
  ModInt& operator*=(const ModInt& r) {
    x = (x * r.x) % MOD;
    return *this;
  }
  ModInt& operator/=(const ModInt& r) {
    *this *= r.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt& r) const { return ModInt(*this) += r; }
  ModInt operator-(const ModInt& r) const { return ModInt(*this) -= r; }
  ModInt operator*(const ModInt& r) const { return ModInt(*this) *= r; }
  ModInt operator/(const ModInt& r) const { return ModInt(*this) /= r; }
  bool operator==(const ModInt& r) const { return x == r.x; }
  bool operator!=(const ModInt& r) const { return x != r.x; }

  ModInt inverse() const {
    long long a = x, b = MOD, u = 1, v = 0, t;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt<MOD> pow(long long n) const {
    ModInt ret(1), mul(x);
    while (n > 0) {
      if (n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream& operator<<(ostream& os, const ModInt& x) { return os << x.x; }

  friend istream& operator>>(istream& is, ModInt& x) { return is >> x.x; }

  int getMod() { return MOD; }
};

using mint = ModInt<1000000007>;

int N;
ll K;
vector<vector<int>> a;

int main() {
  cin >> N >> K;
  a.resize(N, vector<int>(N));

  int R = 63;
  while (!((K >> R) & 1)) --R;
  vector<vector<vector<mint>>> n(
      N, vector<vector<mint>>(N, vector<mint>(R + 1, 0)));
  rep(i, N) rep(j, N) cin >> n[i][j][0];

  rep(k, R) {
    rep(i, N) rep(j, N) rep(l, N) { n[i][j][k + 1] += n[i][l][k] * n[l][j][k]; }
  }

  vector<vector<mint>> dp(N, vector<mint>(N, 0));
  rep(i, N) dp[i][i] = 1;

  rep(k, R + 1) {
    if (!((K >> k) & 1)) continue;

    vector<vector<mint>> next(N, vector<mint>(N, 0));
    rep(i, N) rep(j, N) rep(l, N) { next[i][j] += dp[i][l] * n[l][j][k]; }
    dp = next;
  }

  mint ans = 0;
  rep(i, N) rep(j, N) ans += dp[i][j];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1536
x = int(input())
p = []
for i in range(2, 1000):
    for j in range(2, int(i ** 0.5) + 1):
        if i / j % 1 == 0:
            break
    else:
        p.append(i)

for i in range(x):
    X = x - i
    L = []
    while X > 1:
        for j in p:
            if X / j % 1 == 0:
                L.append(j)
                X /= j
                break
            else:
                continue
    cnt = 0
    L_ = sorted(set(L))
    if len(L) > 1 and len(L_) == 1:
        print(x - i)
        exit()
    for k in range(len(L_)):
        if k == 0:
            cnt = L.count(L_[k])
            continue
        else:
            if L.count(L_[k]) == cnt:
                continue
            else:
                break
    else:
        if cnt != 1:
            print(x - i)
            break
        else:
            continue


Measured memory_bytes: 3064
<?php
  $input_line = fgets(STDIN);
  $array = explode(" ", $input_line);
  $a = $array[0] / $array[1];
  if ($array[0] % $array[1] != 0) {
  	$a = ceil($array[0] / $array[1]);
  }
  $sum = $a * $array[2];
  echo($sum);
?>

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

int n,s;
int dp[350][1024];

int rec(int k,int sum,int u){
  int res = 0;
  if(k==0 && sum==0)return 1;
  if(dp[sum][u] >= 0)return dp[sum][u];
  if(k==0)return 0; 

  for(int i=0;i<10;i++){
    if(u>>i &1){
      if(sum-k*i>=0)res += rec(k-1,sum - k*i,u - (1<<i));
    }
  }
  dp[sum][u] = res;
  return res;
}


int main(){
  for(int i=0;i<350;i++){
    for(int j=0;j<1024;j++)dp[i][j] = -1;
  }
  while(cin >> n >> s){
    if(s>330)cout << 0 << endl;
    else{
      for(int i=0;i<350;i++){
	for(int j=0;j<1024;j++)dp[i][j] = -1;
      }
      cout << rec(n,s,1023) << endl;
    }
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
 
using namespace std;
 
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
 
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;


int main(){
	int n, k;
	cin>>n>>k;
	n--;
	int x, y;
	while(k--){
		cin>>x>>y;
		x--; y--; 
		if(x>n/2) x = n-x;
		if(y>n/2) y = n-y;
		cout<<(x>y?y:x)%3+1<<endl;
 	}
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
#include <bitset>
#include <numeric>
#include <queue>
#include <map>
#include <cstdint>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long int ll;
typedef pair<ll, ll> P;
const vector<int> di = { -1, 0, 1, 0 };
const vector<int> dj = { 0, 1, 0, -1 };


int main() {

	long double a, b, c;
	cin >> a >> b >> c;

	long double ab = sqrtl(a * b);
	long double ans = c - (a + b) - 2 * ab;
	if (ans > 0) {
		cout << "Yes" << endl;
	}
	else {

		cout << "No" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e5)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

int main()
{
    ll N, L;
    cin >> N >> L;
    ll sum = 0;
    ll mi = MOD;
    ll ans = 0;
    rep(i, N) {
        sum += L + i;
        if (mi > abs(L+i)) {
            mi = abs(L+i);
            ans = L+i;
        }
    }
    print(sum - ans);
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

using namespace std;

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

	for (int i = 0; i < n; i++)
	{
		vector<int> a(3);
		for (int j = 0; j < a.size(); j++)
		{
			cin >> a.at(j);
		}
		sort(a.begin(), a.end());

		cout << (a.at(0)*a.at(0) + a.at(1)*a.at(1) == a.at(2)*a.at(2) ? "YES" : "NO") << endl;
	}
}


Measured memory_bytes: 3008
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <set>   

using namespace std;


int main() {

	string a;
	int cnt = 0;

	cin >> a;
	
	for (int i = 0; i < 4; i++) {
		if (a[i] == '+') {
			cnt++;
		}
		else {
			cnt--;

		}
	}
	
	cout << cnt << endl;

	

}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<string> vs;
#define fo(i, a, b) for (int i = a; i < b; i++)
#define re(i, n) fo(i, 0, n)
#define pb push_back
#define all(s) s.begin(), s.end()
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
int main()
{
  int n, m;
  cin >> n >> m;
  int k = 0, a = 0;
  vi v(m+1, 0);
  re(i, n) {
    cin >> k;
    re(j, k) {
      cin >> a;
      v[a]++;
    }
  }
  int cnt = 0;
  re(p, m+1) {
    if(v[p] == n) cnt++;
  }
  cout << cnt << endl;

  return 0;
}


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

#define ll long long
#define endl "\n"
#define deb(x) cerr << #x << ":" << x << "\n"

void solve()
{
	string s,t;
	cin>>s>>t;
	string d="";
	for(int i=0;i<t.size()-1;i++)d+=t[i];
	if(s==d)cout<<"Yes\n";
	else cout<<"No\n";
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	// cin >> t;
	while (t--)
		solve();
	return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define MOD 1000000007
int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 0;
    for(int i = 0; i < n; i++) {
        if(s.substr(i, 3) == "ABC") {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
#include<set>

using namespace std;
#define SAY_YES cout<<"YES"<<endl;
#define SAY_Yes cout<<"Yes"<<endl;
#define SAY_NO cout<<"NO"<<endl;
#define SAY_No cout<<"No"<<endl;
#define IFYES(TRUE_OR_FALSE) if(TRUE_OR_FALSE){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;} 
#define IFYes(TRUE_OR_FALSE) if(TRUE_OR_FALSE){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;} 
#define IFyes(TRUE_OR_FALSE) if(TRUE_OR_FALSE){cout<<"yes"<<endl;}else{cout<<"no"<<endl;} 
#define DEBUG_OUTPUT_ARRAY(XXX,ONE) for(int i=0;i<(ONE);i++){cout<<"DEBUG: i = "<<i<<" -> "<<XXX[i]<<endl;}
#define DEBUG_OUTPUT_ARRAY2(XXX,ONE,TWO) for(int i=0;i<(ONE);i++){cout<<"<<< i = "<<i<<" >>>"<<endl;for(int j=0;j<(TWO);j++){cout<<"DEBUG: j = "<<j<<" -> "<<XXX[i][j]<<endl; } }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX,ONE,TWO) for(int i=0;i<(ONE);i++){cout<<i<<"  ";for(int j=0;j<(TWO);j++){cout<<XXX[i][j]<<" "; } cout<<endl;}

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


const long long int mod=1000000007;
const long long int INF=99999999999999999;


long long int A,B,C,X,Y,N,res=0;
string str,resstr;
bool dp[11]={},dp2[11][11]={},dp3[11][11][11]={};

int main() {
	cout << fixed << setprecision(18);
    
    cin>>N>>str;
    for(int i=0;i<N;i++){
        for(int j=0;j<10;j++){
            for(int k=0;k<10;k++){
                dp3[j][k][str[i]-'0']|=dp2[j][k];
            }
            dp2[j][str[i]-'0']|=dp[j];
        }
        dp[str[i]-'0']=true;
    }
    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
            for(int k=0;k<10;k++){
                if(dp3[i][j][k]){res++;}
            }
        }
    }
    cout<<res<<endl;
} 


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

bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

int main() {
  long long X; cin >> X;
  for (; X < 1000050; X++) {
    if (is_prime(X)) {
      cout << X << endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> PI;
typedef pair<ll, ll> PL;
typedef pair<int, pair<int, int>> PII;
typedef pair<ll, pair<ll, ll>> PLL;
#define endl '\n'
#define INF 2e9
#define LINF 2e15
#define MOD 1000000007

int x;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	cin >> x;
	cout << !x << endl;
	return 0;
}

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

int main(){
	int r,n,a[1000],up,down;
	cin>>r;
	for(int j=0;j<r;j++){
	up=0; down=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];}
	for(int i=0;i<n-1;i++){
		if(a[i+1]-a[i] > up)
			up=a[i+1]-a[i];
		if(a[i]-a[i+1] > down)
			down=a[i]-a[i+1];
	}
	cout<<up<<" "<<down<<endl;
	}
	return 0;
}
		



Measured memory_bytes: 3012
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
signed main(){
  ll n,ans=1;
  string s;
  cin >> n >> s;
  for(int i=1;i<s.size();i++){
    if(s[i]!=s[i-1]){
      ans++;
    }
  }
  cout <<ans << endl;
}


Measured memory_bytes: 512
#include <algorithm>
#include <cstdio>
#include <cstring>

const int MaxN = 1000 + 5;
const int MaxW = 20000 + 5;

int N;
int W[MaxN], S[MaxN], V[MaxN];
long long Dp[MaxW];

template <typename Typ>
inline Typ max(Typ x, Typ y) { return x > y ? x : y; }

void init() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i)
    scanf("%d %d %d", &W[i], &S[i], &V[i]);
}

void solve() {
  static int lnk[MaxN];
  for (int i = 1; i <= N; ++i) lnk[i] = i;
  std::sort(lnk + 1, lnk + 1 + N, [](int x, int y){ return W[x] + S[x] < W[y] + S[y]; });
  for (int I = 1; I <= N; ++I) {
    int i = lnk[I];
    for (int j = S[i] + W[i]; j >= W[i]; --j)
      Dp[j] = max(Dp[j], Dp[j - W[i]] + V[i]);
  }
  long long ans = 0;
  for (int i = 1; i <= 20000; ++i) ans = max(ans, Dp[i]);
  printf("%lld\n", ans);
}

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

Measured memory_bytes: 384
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var nextString func() string

func init() {
	nextString = newReadString(os.Stdin)
}

func main() {
	s := nextString()
	ans := 0

	for i := 1; i <= len(s)/2-1; i++ {
		if s[:i] == s[i:2*i] {
			ans = i * 2
		}
	}
	fmt.Println(ans)
}

func nextInt() (result int) {
	result, _ = strconv.Atoi(nextString())
	return
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
		}
		return r.Text()
	}
}


Measured memory_bytes: 640
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush()

	for i := 0; i < 10000; i++ {
		n := nextInt()
		if n == 0 {
			break
		}
		fmt.Fprintf(out, "Case %d: %d\n", i+1, n)
	}
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}



Measured memory_bytes: 1440
from collections import Counter

n, k = map(int, input().split())
a = list(map(int, input().split()))
if len(set(a)) <= k:
    print(0)
else:
    b = Counter(a)
    t = len(set(a)) - k
    c = b.most_common()[:-t-1:-1]
    d = 0
    for e in c:
        d = d + e[1]
    print(d)

Measured memory_bytes: 52120