akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
struct edge{ll to,cost;};
vector<vector<edge>> graph;
ll n,m;
ll prim(){
    vector<bool> used(n,false);
    priority_queue<P,vector<P>,greater<P>> pq;
    ll res=0;
    pq.push(P(0,0));
    while(!pq.empty()){
         ll cst = pq.top().fi, v = pq.top().se;
        pq.pop();
        if(used[v]) continue;
        used[v]=true;
        res += cst;
        for(int i = 0; i < graph[v].size(); i++){
            edge e=graph[v][i];
            pq.push(P(e.cost, e.to));
        }
    }
    return res;
}
int main(){
    cin>>n;
   graph.resize(n);
   V<P> x(n),y(n);
   for(int i=0;i<n;i++){
       cin>>x[i].fi>>y[i].fi;
       x[i].se=i;y[i].se=i;
   }
   sort(all(x));sort(all(y));
   auto f=[](P a,P b){return abs(a.fi-b.fi);};
  for(int i = 0; i <n-1; ++i) {
    graph[x[i].se].emplace_back((edge){x[i+1].se,f(x[i],x[i+1])});
    graph[x[i+1].se].emplace_back((edge){x[i].se,f(x[i],x[i+1])});
    graph[y[i].se].emplace_back((edge){y[i+1].se,f(y[i],y[i+1])});
    graph[y[i+1].se].emplace_back((edge){y[i].se,f(y[i],y[i+1])});
  }
cout<<prim()<<endl;
}

Measured memory_bytes: 20592
N=int(input())
A=[int(_) for _ in input().split()]
X=[]
x=0
for j in range(N):
    if (j%N)%2==0:
        x+=A[j]
    else:
        x-=A[j]
X.append(x)
for i in range(1,N):
    x=2*A[i-1]-X[i-1]
    X.append(x)
print(' '.join(map(str, X)))

Measured memory_bytes: 19100
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <climits>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string.h>
#include <iomanip>
#include <ctype.h>

#define ll          long long int
#define ull         unsigned long long int
#define pb          push_back
#define pii         pair<int,int>
#define fp          first
#define sp          second
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define M_PI        3.14159265358979323846
#define mp          make_pair
#define sz(x)       (int)x.size()
#define hell        1000000007
#define forn(i,a,b)  for(int i=a;i<b;i++)
#define eps 1e9
#define all(a)      (a).begin(),(a).end()
const long long INF = (long long) 1e18+2;


using namespace std;
void solve();

void fastIO() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}

int main(){
   fastIO();
    solve();
}
//void sieve();
ll pw(ll k,ll x);
ll gcd(ll x,ll y);


void solve(){

  int n,k;
  cin>>n>>k;
  ll h[n];
  forn(i,0,n)
  cin>>h[i];

  ll dp[n];
  dp[0]=0;
  dp[1]=abs(h[0]-h[1]);
  
  forn(i,2,n){
    ll ans=INT_MAX;
    for(int j=i-1;j>=max(0,i-k);j--){
    ans=min(dp[j]+abs(h[i]-h[j]),ans);
  }
  dp[i]=ans;
  }
  cout<<dp[n-1];
}


///Before submit=>
///    *check for integer overflow,array bounds
///    *check for n=1

ll gcd(ll x,ll y){
  if(x==0)
  return y;
  else
  return gcd(y%x,x);
}


ll pw(ll k,ll x){
  if(x==0)
  return 1;
  if(x&1)
  return ((pw(k,x-1)%hell)*k%hell)%hell;
  else
  return ((pw(k,x/2)%hell)*(pw(k,x/2)%hell))%hell;
}

/*void sieve(){

  for(int i=2;i<=1000000;i++){
    if(prime[i]==true){
      for(int j=i*i;j<=1000000;j+=i)
      prime[j]=false;
    }
  }

}*/


Measured memory_bytes: 1792
#include <string>
#include <queue>
#include <iostream>
using namespace std;
int main() {
    char x;
    string a, b, c;
    queue<char> A, B, C;
    cin >> a >> b >> c;
    for(int i = 0; i < a.size(); i++) 
        A.push(a[i]);
    for(int i = 0; i < b.size(); i++) 
        B.push(b[i]);
    for(int i = 0; i < c.size(); i++) 
        C.push(c[i]);
    
    x = A.front();   A.pop();  
    while(true) {
        if(x == 'a') {
            if(A.empty())  {//若为空，输出，结束
                printf("A\n");
                break;
            }
            else { //若不为空，更新x，并删除一个
                x = A.front();  A.pop();
            }
        }
        else if( x == 'b') {
            if(B.empty()) {
                printf("B\n");
                break;
            }
            else {
                x = B.front();  B.pop();
            }
        }
        else if (x == 'c') {
            if(C.empty()) {
                printf("C\n");
                break;
            }
            else {
                x = C.front();  C.pop();
            }
        }
    }
}


Measured memory_bytes: 256
from collections import deque
K = int(input())
d = deque()
for i in range(1,10):
    d.append(i)

count=0
while True:
    count += 1
    check = d.popleft()
    mod = check % 10
    if check % 10 == 0:
        d.append(check*10)
        d.append(check*10+1)
    elif check % 10 == 9:
        d.append(check*10+8)
        d.append(check*10+9)
    else:
        d.append(check*10+mod-1)
        d.append(check*10+mod)
        d.append(check*10+mod+1)
    if count == K:
        break
print(check)
        

Measured memory_bytes: 11980
function main(input){
  var str = input.split('\n');
  var times = parseInt(str[0]);
  var riceCakes = [];
  for(let i=1;i<str.length;i++){
    riceCakes.push(parseInt(str[i]));
  }
  riceCakes.sort(function(x,y){return x-y;})
  for(let j=0;j<times-1;j++){
    if(riceCakes[j+1]-riceCakes[j] === 0){
      riceCakes.splice(j,1,0);
    }
  }
  var result = riceCakes.filter(function(value,index,array){
    return value > 0;
  })
  console.log(result.length)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29588
import math
n = int(input())
l = [list(map(int,input().split())) for i in range(n)]
s=0
for j in range(n-1):
  for k in range(j+1,n):
    s += math.sqrt( (l[j][0]-l[k][0])**2 + (l[j][1]-l[k][1])**2 )

print(2*s/n)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        String jo[] = {"pon", "pon", "hon", "bon", "hon", "hon", "pon", "hon", "pon", "hon"};

        System.out.println(jo[n % 10]);
    }
}

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

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

  ll ans = 0, last = 0;
  rep(i,0,S.size()-1) {
    ll cnt = 0;
    while (S[i] == S[i+cnt]) {
      cnt++;
      ans += cnt;
    }
    if (S[i] == '>') ans -= min(cnt, last);
    i += cnt - 1;
    last = cnt;
  }

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


Measured memory_bytes: 900
/**   Created by: Marcos Portales
          Codeforces User: marcosportales
          Country: Cuba
          Copyright                    */
#include<bits/stdc++.h>
using namespace std;
/// Pragmas:
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2") //Enable AVX
/// Macros:
#define int long long
#define f first
#define s second
#define db(x) cerr << #x << ": " << (x) << '\n';
#define pb push_back
#define lb lower_bound
#define up upper_bound
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define enl '\n'
#define vi vector<int>
#define sz(a) int((a).size())
#define rep(i,x,y) for(int i=x;i<y;i++)
typedef pair<int,int> ii;
typedef long double ld;
typedef unsigned long long ull;
/// Constraints:
const int maxn = 400010;
const int mod = 1000000007;
const ld eps = 1e-9;
const int inf = ((1ll<<31ll)-1ll);
const int INF = 2000000000000000000ll;
const ld pi = acos(-1);
/// Prime Numbers:
// 2, 173, 179, 181, 197, 311, 331, 737, 1009, 2011, 2027, 3079, 4001, 10037, 10079, 20011, 20089;
// 100003, 100019, 100043, 200003, 200017, 1000003, 1000033, 1000037, 1000081;
// 2000003, 2000029, 2000039, 1000000007, 1000000021, 2000000099;
/// Functions:
#define lg2(x) 31 - __builtin_clz(x)
#define lgx(x,b) ( log(x) / log(b) )
/// Red-Black Tree Template ---------------------------------
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree < long long ,  null_type ,  less<long long> ,  rb_tree_tag ,  tree_order_statistics_node_update > ordered_set;
/// Quick Pow------------------------------------------------
int qpow(int b,int e){
    if( !e ) return 1;
    if( e & 1 ) return qpow(b,e-1) * b % mod;
    int pwur = qpow(b,e>>1);
    return (pwur * pwur) % mod;
}
int modinv(int x){
    return qpow(x,mod-2);
}
/// My Code -------------------------------------------------

int a[101][101];

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout.setf(ios::fixed); cout.precision(0);
    srand(time(NULL));

    //freopen("a.in","r",stdin);
    //freopen("a.in","w",stdout);
    int a,b,x;
    cin>>a>>b>>x;
    if(b==0)cout<<1;
    else if(a==0)cout<<b/x+1;
    else {
        cout<<b/x-(a-1)/x;
    }
    return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

template<class T>
struct CumulativeSum {
  vector<T> v;

  CumulativeSum(size_t n) : v(n+1) {};
  CumulativeSum(vector<T> v_) : v(v_) {
    v.push_back(T());
  };

  void add(size_t i, T x) {
    v[i] += x;
  }

  // O(N)
  void build() {
    for (size_t i = v.size()-1; i > 0; i--)
      v[i-1] += v[i];
  }

  // O(1) sum [l, r]
  T sum(size_t l, size_t r) const {
    return v[l]-v[r+1];
  }

  // O(1) sum [0, r]
  T sum(size_t r) const {
    return sum(0, r);
  }
};

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

  ll n;
  cin >> n;
  vl a(n);
  rep(i, n) {
    cin >> a[i];
  }

  using cumsum = CumulativeSum<ll>;
  vector<cumsum> cs(20, cumsum(n));

  rep(i, n) {
    rep(j, 20) {
      if (a[i] >> j & 1LL) {
        cs[j].add(i, 1);
      }
    }
  }

  rep(i, 20) {
    cs[i].build();
  }

  auto f = [&](ll l, ll r) {
    rep(i, 20) {
      if (cs[i].sum(l, r) > 1) {
        return false;
      }
    }
    return true;
  };

  ll ans = 0;
  ll right = 0;
  rep(left, n) {
    while (right < n && f(left, right)) {
      right++;
    }

    ans += right-left;

    if (right == left) right++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 34688
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N;
string S;

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

  if (S[0] == 'W' || S[2*N-1] == 'W'){
    cout << 0 << endl;
    return 0;
  }

  ll ans = 1, now = 1;
  for (int i = 1; i < 2 * N; i++){
    if (S[i] == 'B'){
      if (now % 2 != 0){
        ans *= now; now--;
      }else{
        now++;
      }
    }else{
      if (now % 2 == 0){
        ans *= now; now--;
      }else{
        now++;
      }
    }
    if (now < 0){
      cout << 0 << endl;
      return 0;
    }
    ans %= MOD;
  }

  if (now != 0){
    cout << 0 << endl;
    return 0;
  }

  for (ll i = 1; i <= N; i++){
    ans *= i; ans %= MOD;
  }
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 3748
import math

def isPrime(n):
  x = int(math.sqrt(n))
  for i in range(2, x+1):
    if n % i == 0:
      return False
      break
  #print(n)
  return True
  

n = int(input())
cnt = 0
for i in range(n):
  a = int(input())
  if isPrime(a):
    cnt += 1
print(cnt)


Measured memory_bytes: 5676
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod  1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int digit_sum(int n){
  int ret = 0;
  while(n){
    ret += n % 10;
    n /= 10;
  }
  return ret;
}

int main(){
  int N;
  cin >> N;
  int ans = INT_MAX;
  for(int i = 1; i < N; i++){
    ans = min(ans, digit_sum(i) + digit_sum(N - i));
  }
  cout << ans << endl;
}

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

int main()
{
	int L, R, D;
	cin >> L >> R >> D;

	ce(R/D-(L-1)/D)
    return 0;
}



Measured memory_bytes: 3544
/*
* @Author: _dp95
* @Date:   2020-04-13 06:47:27
*/
#include "bits/stdc++.h"
using namespace std ;

#define timesaver ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll ;
typedef long double ldb ;

#define mp make_pair
#define pb push_back
#define F first
#define S second
#define nl '\n'

#define all( x ) x.begin(),x.end() 
#define sz( x ) ( int )( x ).size( )
#define mem( a, val ) memset(a, val, sizeof( a ) )
#define deci( x ) cout<<fixed<<setprecision( x );
#define bitcount( x ) __builtin_popcountll( x )

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

const int MAX = 2*1000*1000 + 10 ;
const ll INF = 1e18 ;
const int MOD = 1e9 + 7 ;

signed main( ){
  timesaver ;
  int n, k, ans(0) ;
  cin >> n >> k ;
  for( int i = 0; i <= n ; i++ )
    for( int j = 0 ; j <= n ; j++ )
      ans += ( (k-i-j) >= 0 and (k-i-j)<=n) ;
  cout << ans << nl ;
  
}

Measured memory_bytes: 256
s=input()
t=input()
s=list(s)
t=list(t)
c=0
for i in range(0,len(s)-len(t)+1):
    aa=0
    pp=0
    #print()
    for j in range(i,i+len(t)):
        #print(s[j],t[pp],"compare")
        if(s[j]==t[pp]):
            aa+=1
        pp+=1
    c=max(c,aa)
print(len(t)-c)

Measured memory_bytes: 9072
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>


#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long
//#define lint long long

const int INF = 1e18;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

//typedef pair<int, int> P;
//priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順

signed main(){
  int n ,a,b;
  cin >> n >> a >> b;
  cout << min(n*a,b) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int top,s[1000];
void push(int x)
{
    s[++top]=x;
}
int pop(){
top--;
return s[top+1];
}
int main()
{
    int a,b;
    top=0;
    char h[100];
    while(scanf("%s",h)!=EOF){
        if(h[0]=='+'){
            a=pop();
            b=pop();
            push(a+b);
        }
        else if(h[0]=='-'){
             b=pop();
           a=pop();
            push(a-b);
        }
        else if(h[0]=='*'){
            a=pop();
            b=pop();
            push(a*b);
        }else push(atoi(h));

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

Measured memory_bytes: 2756
N = int(input())
A = list(map(int, input().split()))
count = 0
A.sort()
c=0
"""
for k in range(len(A)-1):
    if A[k] == A[k+1]:
        del A[k]
        A.insert(0,0)
        c+=1
        if k <len(A)-2:
            if A[k+1] != A[k+2]:
                del A[k+1]
                A.insert(0,0)
                c+=1
        else:
            del A[k+1]
            A.insert(0,0)
            c+=1
del A[:c]
if len(A)>0:
    saidai = A[-1]
else:
    saidai=0
#print(A)
"""
saidai = A[-1]
foo = [0 for k in range(saidai+1)]
for k in range(len(A)):
    if foo[A[k]] == 1:
        continue
    else:
        for j in range(A[k], saidai+1, A[k]):
            foo[j] = 1
        if k < len(A)-1:
            if A[k] == A[k+1]:
                continue
        if 0 < k < len(A):
            if A[k] == A[k-1]:
                continue
        count+=1
print(count) 

Measured memory_bytes: 32284
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r#"3 4
2 1 3
3 1 2 3
2 3 2"# => r#"1"#,
r#"5 5
4 2 3 4 5
4 1 3 4 5
4 1 2 4 5
4 1 2 3 5
4 1 2 3 4"# => r#"0"#,
r#"1 30
3 5 10 30"# => r#"3"#,
}

fn solve(src: &str) -> String {
    let mut disp:String = "".to_string();
    input! {
        source = src,
        n: usize,
        m: usize,
        ka: [[usize]; n],
    }
    let mut a = vec![vec![false; m]; n];

    let mut ans = 0;

    for i in 0..n {
        for j in 1..ka[i].len()+1 {
            a[i][ka[i][j - 1] - 1] = true;
        }
    }

    for i in 0..m {
        let mut sum = true;
        for j in 0..n {
            sum &= a[j][i];
        }
        if sum {
            ans += 1;
        }
    }

    disp.push_str(&ans.to_string());
    disp.to_string()
}

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> P(N);
  for (int i = 0; i < N; i++) cin >> P.at(i);
  sort(P.begin(), P.end());
  int ans = 0;
  for (int i = 0; i < K; i++) {
    ans += P.at(i);
  }
  cout << ans << "\n";
}

Measured memory_bytes: 3624
#include<stdio.h>

int main(void)
{
  char s[4];
  
  scanf("%s",s);
  
  if(s[0]!=s[1]&&s[0]!=s[2]&&s[1]!=s[2])
  printf("Yes\n");
  
  else printf("No\n");
  
  
  
 return 0; 
}

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

int dp[101010];

bool rec(int n) {
  if (dp[n] != -1) {
    return dp[n];
  }

  if (n == 0) {
    return true;
  }

  bool res = false;
  if (n - 100 >= 0) {
    res |= rec(n - 100);
  }
  if (n - 101 >= 0) {
    res |= rec(n - 101);
  }
  if (n - 102 >= 0) {
    res |= rec(n - 102);
  }
  if (n - 103 >= 0) {
    res |= rec(n - 103);
  }
  if (n - 104 >= 0) {
    res |= rec(n - 104);
  }
  if (n - 105 >= 0) {
    res |= rec(n - 105);
  }

  return dp[n] = res;
}

signed main() {
  int X;
  cin >> X;

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

  if (rec(X)) {
    cout << 1 << endl;
  } else {
    cout << 0 << endl;
  }

  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
map<int,int> tp;
struct qq
{
    ll l, r;
    ll id;
}D[100005];
ll ans[1000005];
ll a[10000000];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n, m;
    cin >> n >> m;
    ll p = n % m;
    cout << min(p, m - p) << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
long long gcd(int a,int b){
  if(a%b==0)return b;
  else return gcd(b,a%b);
}
int main(){
  long long a,b,c,d;cin>>a>>b>>c>>d;
  long long cwr =  ((b-b%c+c)-(a-a%c+c))/c;
  if(a%c==0)cwr++;
  long long dwr = ((b-b%d+d)-(a-a%d+d))/d;
  if(a%d==0)dwr++;
  long long g = d*c/gcd(c,d);
  long long ewr = ((b-b%g+g)-(a-a%g+g))/g;
  if(a%g==0)ewr++;
  //cout << (b-a+1) << " " << cwr << " " << dwr << " " << ewr << endl;
  cout << (b-a+1)-cwr-dwr+ewr << endl;
  
}

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

int main() {
  int a,b;
  int count =0;
  cin >> a >> b;
  for(;a<=b;a++){
    if( (a/10000)==(a%10)){
      if( (a/1000)%10 == (a/10)%10 )
        count +=1;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P>IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P> > G;
void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));}
void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);}
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
const ll INF = 1145141919;
const ll MOD = 1000000007;
const ll NUM = 101010;


int main(){

    ll N, ans = 0;
    cin >> N;
    V v(N), t(N + 1, 0);
    rep(i, N)cin >> v[i];
    for(;;){
        ll tmp = 1;
        rep(i, N)tmp *= v[i] + t[i] - 1;
        if(tmp % 2 == 0)ans++;
        t[0]++;
        rep(i, N)if(t[i] == 3){
            t[i + 1]++;
            t[i] = 0;
        }
        if(t[N])break;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define YES {cout<<"YES"<<'\n';}
#define NO {cout<<"NO"<<'\n';}
#define Yes {cout<<"Yes"<<'\n';}
#define No {cout<<"No"<<'\n';}
#define yes {cout<<"yes"<<'\n';}
#define no {cout<<"no"<<'\n';}
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) {cout << n << '\n';}
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    int n,m; cin >> n >> m;
    VI a(m,0);
    REP(i,n){
        int k; cin >> k;
        REP(j,k){int x; cin >> x; a[x-1]++;}
    }
    out(COUNT(a,n));

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

void solve()
{
	int a, b;
	while(cin >> a >> b)
	{
		if(a < b)
		{
			int temp = a;
			a = b;
			b = temp;
		}
		cout << gcd(a, b) << endl;
	}
}

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

Measured memory_bytes: 1160
a, b, c, x = eval("int(input())," * 4)  #文字の定義
count = 0  #カウントの定義
#繰り返し処理を利用して虱潰しにカウント
for i in range(a + 1):
	for j in range(b + 1):
		for k in range(c + 1):
			if i * 500 + j * 100 + k * 50 == x:
				count += 1
print(count)


Measured memory_bytes: 2940
using System;
using System.Linq;

namespace abc115_c
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] a = new int[x[0]];
            for (int i = 0; i < x[0]; i++) a[i] = int.Parse(Console.ReadLine());
            Array.Sort(a);
            int ret = 1145141919;
            for (int i = 0; i + x[1] - 1 < x[0]; i++) ret = Math.Min(ret, a[i + x[1] - 1] - a[i]);
            Console.WriteLine(ret);
        }
    }
}

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

#pragma ide diagnostic ignored "OCUnusedGlobalDeclarationInspection"
#pragma ide diagnostic ignored "OCUnusedMacroInspection"
using namespace std;

#define sqr(a) ((a)*(a))
#define forn(i, n) for(int i = 0; i < (int)n; ++i)
#define rep(i, k, n) for(int i = (int)k; i <= (int)n; ++i)
#define nrof(i, n) for(int i = (int)n - 1; i >= 0; --i)
#define x first
#define y second
#define mp make_pair
#define sz(a) (int)(a.size())
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double dd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int N = 1e6 + 9;
const int M = 2e3 + 9;
const int INFINT = 1e9 + 9;
const ll INFLL = 1e18 + 9;
const ll MOD = (ll) (1000000007);

void solve() {
    int n, x, t;
    cin >> n >> x >> t;
    cout << (n / x + ((n % x) > 0)) * t << endl;
}

int main() {
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;

int main(void){
	int A, B, K;
	cin >> A >> B >> K;
	int count = A > B ? A : B;
	while(K > 0){
		if(A % count == 0 && B % count == 0){
			--K;
		}
		--count;
	}
	cout << count + 1 << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;
ll n;
double vs[100];
bool comp2(const double& left, const double& right) {
    return left < right;
}

int main(){
    double sum=0;
    cin >> n;
    for(int i=0; i<n; i++) cin >> vs[i];

    sort(vs, vs+n, comp2);
    sum = vs[0];
    for(int i=1; i<n; i++){
        sum = (sum+vs[i])/2;
    }
    cout << setprecision(12) << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap};

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;

fn main() {
    input! {
        n: usize,
        c: usize,
        mut s: [(usize, usize, usize); n],
    }

    let mut ans = 0;
    s.sort();
    let mut working = vec![];
    for &(s, t, c) in &s {
        let mut nw = vec![];
        let mut added = false;
        for &(sw, tw, cw) in &working {
            if tw == s && cw == c {
                nw.push((s, t, c));
                added = true;
            } else if tw >= s {
                nw.push((sw, tw, cw));
            }
        }
        if !added {
            nw.push((s, t, c));
        }
        working = nw;
        ans = max(ans, working.len());
    }
    println!("{}", ans);
}


Measured memory_bytes: 8444
#include<stdio.h>
#include<algorithm>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#include <iostream>
#include <functional>
#include <time.h>
using namespace std;
clock_t fi, endtime;

const int r_c = 0;
const int r_t = 1;
const int MAX_V = 20;
const int MAX_E = 100;
const int MAX_D = 1000;

const int INF = MAX_V * MAX_E * MAX_D;

int main()
{
	int wf[MAX_V][MAX_V];
	int n, m, a, b, c, d, s, g, V, P;
	int sum = 0;
	scanf("%d", &n);
	scanf("%d", &m);
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			wf[i][j] = INF;
		}
	}
	for (int i = 0; i < m; ++i) {
		scanf("%d,%d,%d,%d", &a, &b, &c, &d);
		wf[a - 1][b - 1] = c; wf[b - 1][a - 1] = d;
	}
	for (int k = 0; k < n; ++k) {
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n; ++j) {
				if (wf[i][j] > wf[i][k] + wf[k][j])
					wf[i][j] = wf[i][k] + wf[k][j];
			}
		}
	}
	scanf("%d,%d,%d,%d", &s, &g, &V, &P);

	sum = wf[s - 1][g - 1] + wf[g - 1][s - 1] + P;
	printf("%d\n", V - sum);

}

Measured memory_bytes: 3136
N = int(input())
H = list(map(int, input().split()))

M = [0] * (N+1)

SUM = 0
for i in range(0, N):
    M[i+1] = max(M[i], H[i])
    if M[i] <= H[i]:
        SUM += 1

print(SUM)


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

#define INF 0x7fffffff
#define ll	long long

int main() {
	ll	b,c,i,j,k,n,m,x,y,ans1 , ans = 0;
	string	str;

	cin >> k;

	if (k<=12) {
		cout << k << endl;
		return 0;
	}

	vector<int> a = {1,2};

	for(i=13;i<=k;i++) {
		int l = a.size()-1;
		int keta = l;
		bool f = true;
		while(l>=1) {
			if ((a[l-1] > a[l]-1)&&(a[l]!=9)) {
				f = false;
				a[l]++;
				for(j=l+1;j<=keta;j++) {
					if (a[j-1] != 0) a[j] = a[j-1] -1;
					else a[j] = 0;
				}
				break;
			}
			l--;
		}
		if (f) {
			bool f = false;
			for(j=0;j<=keta;j++) if (a[j]!=9) f = true;
			if (f) { // 最上位を+1
				a[0]++;
				for(j=1;j<=keta;j++) {
					if (a[j-1] != 0) a[j] = a[j-1] -1;
					else a[j] = 0;
				}
			} else { // 桁上げ
				a[0] = 1;
				for(j=1;j<=keta;j++) {
					a[j] = 0;
				}
				a.push_back(0);
			}

		}

	}

	for(i=0;i<a.size();i++) {
		cout << a[i];
	}
	cout << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};

int main(void){
    lint H,N;
    cin >> H >> N;
    lint A[N],B[N];
    rep(i,N) cin >> A[i] >> B[i];
    lint dp[20010];
    fill(dp,dp+20010,LINF);
    dp[0]=0;
    rep(i,H) rep(j,N) dp[i+A[j]]=min(dp[i+A[j]],dp[i]+B[j]);
    lint ans=LINF;
    for(int i=H;i<20010;i++) ans=min(ans,dp[i]);
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;
const int INF = 1 << 28;

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

void get() {}

template <class Head, class... Tail>
void get(Head& head, Tail&... tail) {
  cin >> head;
  get(tail...);
}

template <class T>
void getv(vector<T>& vec) {
  for (int i = 0; i < vec.size(); ++i)
    cin >> vec[i];
}

int main() {
  int N;
  get(N);
  vector<int> A(N);
  getv(A);
  ll ans = 0;
  FOR(i, N) {
    ans += A[i] / 2;
    if (i < N - 1 && A[i] % 2 == 1 && A[i + 1] > 0) {
      A[i + 1]--;
      ans++;
    }
  }
  print(ans);

  return 0;
}

Measured memory_bytes: 640
//In The Name Of God
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define L(x) (2*(x))
#define R(x) ((2*(x))+1)
#define pii pair<int, int>
#define pb push_back
using namespace std;
const int N = 1e5 + 5, Mod = 1e9 + 7, P = 727, Lg = 17, TOF = 1900;

vector< int > A[N];
int Dp[N][2], Pd[N][2], mod;

void DfsDown(int u, int par){
      Dp[u][1] = 1;
      for(int i = 0; i < (int)A[u].size(); i++){
            int v = A[u][i];
            if(v == par) continue;
            DfsDown(v, u);
            Dp[u][1] = 1ll * Dp[u][1] * (1 + Dp[v][1]) % mod;
      }
}
void DfsUp(int u, int par){
      int zrb = 1;
      for(int i = 0; i < (int)A[u].size(); i++){
            int v = A[u][i];
            if(v == par) continue;
            Pd[v][1] = 1ll * Pd[u][1] * zrb % mod;
            zrb = 1ll * zrb * (Dp[v][1] + 1) % mod;
      }
      reverse(A[u].begin(), A[u].end());
      zrb = 1;
      for(int i = 0; i < (int)A[u].size(); i++){
            int v = A[u][i];
            if(v == par) continue;
            Pd[v][1] = 1ll * Pd[v][1] * zrb % mod;
            Pd[v][1] = (Pd[v][1] + 1) % mod;
            zrb = 1ll * zrb * (Dp[v][1] + 1) % mod;
            DfsUp(v, u);
      }
}
int main(){
      ios_base::sync_with_stdio(0); cin.tie(0);
      int n; cin >> n >> mod;
      for(int i = 1; i < n; i++){
            int x, y; cin >> x >> y;
            A[x].pb(y), A[y].pb(x);
      }
      Pd[1][1] = 1;
      DfsDown(1, 1);
      DfsUp(1, 1);
      for(int i = 1; i <= n; i++)
           cout << 1ll * Dp[i][1] * Pd[i][1] % mod << '\n';
      return 0;
}



Measured memory_bytes: 13824
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#define MAXN 1010
using namespace std;

int n,m,k,sx,sy;
int a[MAXN][MAXN];
bool visit[MAXN][MAXN];
int d[MAXN][MAXN];

void bfs(){
	static queue< pair<int,int> > Q;
	Q.push(make_pair(sx,sy));
	d[sx][sy]=0;
	visit[sx][sy]=1;
	while(!Q.empty()){
		int tx=Q.front().first,ty=Q.front().second;
		Q.pop();
		if(tx>1 && !visit[tx-1][ty] && !a[tx-1][ty]){
			Q.push(make_pair(tx-1,ty));
			visit[tx-1][ty]=1;
			d[tx-1][ty]=d[tx][ty]+1;
		}
		if(ty>1 && !visit[tx][ty-1] && !a[tx][ty-1]){
			Q.push(make_pair(tx,ty-1));
			visit[tx][ty-1]=1;
			d[tx][ty-1]=d[tx][ty]+1;
		}
		if(tx<n && !visit[tx+1][ty] && !a[tx+1][ty]){
			Q.push(make_pair(tx+1,ty));
			visit[tx+1][ty]=1;
			d[tx+1][ty]=d[tx][ty]+1;
		}
		if(ty<m && !visit[tx][ty+1] && !a[tx][ty+1]){
			Q.push(make_pair(tx,ty+1));
			visit[tx][ty+1]=1;
			d[tx][ty+1]=d[tx][ty]+1;
		}
	}
}

int dis(int x,int y){
	int res=min(min(x-1,n-x),min(y-1,m-y));
	if(!res) return 0;
	return (res-1)/k+1;
}

int main(){
#ifdef DEBUG
	freopen("C.in","r",stdin);
#endif
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1;i<=n;i++){
		static char str[MAXN];
		scanf("%s",str+1);
		for(int j=1;j<=m;j++){
			if(str[j]=='#') a[i][j]=1;
			if(str[j]=='S') sx=i,sy=j;
		}
	}
	bfs();
	int ans=0x7FFFFFFF;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			if(visit[i][j] && d[i][j]<=k)
				ans=min(ans,dis(i,j)+1);
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 8576
#pragma once
#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>

#define rep(name,begin,end,up) for(long long name = begin; name < end; name += up)
#define rev(name,begin,end,down) for(long long name = begin - 1; name >= end; name -= down)

using ll = long long;
using namespace std;

void abc154b(void) {

	string s;
	cin >> s;

	rep(i, 0, s.length(), 1) {
		cout << 'x';
	}

	cout << endl;
}

///*
int main(void) {

	abc154b();

	return 0;
}
//*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define deb(x) cout<<#x<<"="<<x<<endl;
#define endl '\n'
#define M 1000000007
#define int long long
#define INF 1e18
#define max_n 1000000

using namespace std;

void solve()
{
	ll n;
	cin >> n;
	if (n % 1000 == 0)cout << 0 << endl;
	else cout << ((n) / 1000) * 1000 + 1000- n << endl;
	// cout<<<<endl;
}

int32_t main()
{
	IOS
	ll T = 1;
	// cin>>T;
	for (ll i = 1; i <= T; ++i)
	{
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	return 0;
}

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

struct edge{
    int to,weight;
    edge(int to,int weight):to(to),weight(weight){}
};
using Graph = vector<vector<int>> ;
using GraphEdge = vector<vector<int>> ;

long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}
int main(){
    int N;cin >> N;
    double ans = 0;

    rep(i,N){
        double a;
        cin >> a;
        string s;cin >> s;
        if(s=="JPY"){
            int x = (int)a;
            ans += x;
        }else {
            ans += 380000*a;
        }
    }

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

Measured memory_bytes: 3728
#include <iostream>
#include <sstream>
#include <string>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <list>
#include <algorithm>
#include <ctime>
#include <limits>
#include <iomanip>
#include <functional>
#include <array>
#include <climits>
#include <cmath>

using namespace std;
using ll = long long;
const ll MOD = (ll)1e9 + 7;

int main()
{
    ll H, W, h, w;
    cin >> H >> W;
    cin >> h >> w;

    ll ans = (H - h) * (W - w);
    cout << ans;
    return 0;
}



Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<cmath>
#include<limits>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
using namespace std;

int ctoi(char c) {
	return c - 'a';
}


int main() {
	int H, W; cin >> H >> W;
	const int size = 26;
	vi Alphabet(size);

	rep(i, H * W) {
		char c; cin >> c;

		Alphabet[ctoi(c)]++;
	}

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

	const int max1 = (H % 2) and (W % 2);
	const int min4 = (H / 2) * (W / 2);
	bool flag1 =true, flag2 = true, flag3 = true, flag4 = true;
	int cnt = 0;

	if (max1) {
		int temp = 0;
		for (int i = 0; i < size; i++) {
			if (Alphabet[i] % 2 == 1) {
				Alphabet[i]--;
				flag1 = true;
				temp++;
				if (temp > 1) {
					flag1 = false;
					break;
				}
			}
		}
		
	}

	cnt = 0;
	for (int i = 0; i < size and cnt < min4; i++) {
		if (Alphabet[i] >= 4) {
			cnt += Alphabet[i] / 4;
			Alphabet[i] %= 4;

			if (cnt > min4) {
				Alphabet[i] += (min4 - cnt) * 4;
			}
		}
	}

	if (cnt < min4) {
		flag2 = false;
	}

	const int min2W = W / 2;
	cnt = 0;
	if (H % 2) {// W-wise count
		for (int i = 0; i < size and cnt < min2W; i++) {
			if (Alphabet[i] >= 2) {
				cnt += Alphabet[i] / 2;
				Alphabet[i] %= 2;

				if (cnt > min2W) {
					Alphabet[i] += (min2W - cnt) * 2;
				}
			}
		}
	}
	if (cnt < min2W and H % 2) {
		flag3 = false;
	}


	const int min2H = H / 2;
	cnt = 0;
	if (W % 2) {// H-wise count
		for (int i = 0; i < size and cnt < min2H; i++) {
			if (Alphabet[i] >= 2) {
				cnt += Alphabet[i] / 2;
				Alphabet[i] %= 2;

				if (cnt > min2H) {
					Alphabet[i] += (min2H - cnt) * 2;
				}
			}
		}
	}
	if (cnt < min2H and W % 2) {
		flag4 = false;
	}


	if (flag1 and flag2 and flag3 and flag4) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

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

#define fi first
#define se second
#define lch (o << 1)
#define rch (o << 1 | 1)

typedef double db;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> pint;

const int N = 2e5 + 5;
const int INF = 0x3f3f3f3f;
const ll INF_LL = 0x3f3f3f3f3f3f3f3f;

int a[N];

int main() {
	ios::sync_with_stdio(0);

	int n, k;
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		if (i > k)
			cout << (a[i] > a[i - k] ? "Yes" : "No") << endl;
	}

	return 0;
}


Measured memory_bytes: 4436
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;

/* --------------------------------------------------- */

int main() {
    int n;
    cin >> n;
    cout << (n - 1) / 2 << endl;
    
    return 0;
}

Measured memory_bytes: 3624