akhauriyash/Code-Regression huggingface dataset:
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        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<_>>()
    };

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

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

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        n: usize,
        h: [usize1; n],
    }
    let mut time = 0;
    let mut max = 0;
    for i in 0..h.len() {
        if max <= h[i] {
            time+=1;
            max = h[i];
        }
    }
    println!("{}", time);
}

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

using namespace std;

int main(){
	int n;
	string s;
	cin>>n;
	cin>>s;
	for(int i=0;i<s.size();i++){
		int val=(((int)s[i]-'A')+n)%26;
		cout<<(char)(val+(int)'A');
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		sc.close();
		long money = 100;
		long count = 0;
		while (true) {
			count++;
			money = (long) (money * 1.01d);
			if (money >= x) {
				System.out.println(count);
				return;
			}
		}
	}
}


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

unsigned long long sum1(unsigned long long a){
  return (a * (a + 1) / 2);
}

//Sample
int main()
{
  unsigned long long K;
  unsigned long long buf1 = 0;//aaa
  unsigned long long buf2 = 0;//aab & abc
  cin >> K;

  buf1 = sum1(K);

  for(int i = 1; i < K; i++){
    for(int j = i + 1; j <= K; j++){
      unsigned long long bufbuf = __gcd(i, j);
      buf2 += bufbuf;
      for(unsigned long long  ii = j + 1; ii <= K; ii++){
        buf2 += __gcd(bufbuf, ii);
      }
    }
  }

  cout << (buf1 + buf2 * 6) << endl;
  return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define int long long

using namespace std;
using LL = long long;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e19;
const int MOD = (int)1e9 + 7;

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

    LL n, p;
    cin >> n >> p;
    map<int, int> mp;
    LL ori = p;
    for(int i = 2; i*i <= p; i++){
        while(p % i == 0){
            mp[i]++;
            p /= i;
        }
    }
    if(p != 0) mp[p]++;

    LL ans = 1;
    for(auto x : mp){
        while(x.second >= n){
            ans *= x.first;
            x.second -= n;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll n,k,a[200005];
int main(void){
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    ll l=0,r=10000000000,m=(l+r)/2;
    while(r-l>1){
        ll cnt=0;
        for(int i=0;i<n;i++){
            cnt+=(a[i]-1)/m;
        }
        if(cnt<=k){
            r=m;
            m=(l+r)/2;
        }else{
            l=m;
            m=(l+r)/2;
        }
    }
    cout<<r<<endl;
    
    
}



Measured memory_bytes: 5128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 31) - 1;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

//rev?????????????????°??????
struct edge { int to, cap, rev; };

vector<edge> G[100];
bool used[100];

void add_edge(int from, int to, int cap) {
	G[from].push_back({ to,cap,(int)G[to].size() });
	G[to].push_back({ from,0,(int)G[from].size() - 1 });
}

//f???????????????????????´???????????§?????????????????§???????°?????????????
int dfs(int v, int t, int f) {
	if (v == t)return f;
	used[v] = true;
	for (int i = 0; i < G[v].size(); i++) {
		edge &e = G[v][i];
		if (!used[e.to] && e.cap > 0) {
			int d = dfs(e.to, t, min(f, e.cap));
			if (d > 0) {
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(int s, int t) {
	int flow = 0;
	for (;;) {
		fill(used, used + sizeof(used), 0);
		int f = dfs(s, t, INF);
		if (f == 0)return flow;
		flow += f;
		//cout << "flow:" << flow << endl;
	}
}

int main() {
	int n, e;
	int s, t, c;
	cin >> n >> e;
	REP(i,e){
		cin >> s >> t >> c;
		add_edge(s, t, c);
	}
	cout << max_flow(0, n - 1) << endl;
}

Measured memory_bytes: 3184
#include <bits/stdc++.h>
#define dum(x) cout<<#x<<'='<<x<<endl
#define ll long long
using namespace std;

int main() {
  int n; cin >> n;
  for (int i = 0; i <= 100; ++i) {
    for (int j = 0; j <= 100; ++j) {
      if (n == i * 4 + j * 7) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
/*

    author : s@if

*/

#include<bits/stdc++.h>
using namespace std;
#define NIL -1
#define fi first
#define sec second
#define MAX INT_MAX
#define INF 99999999
#define ll long long
#define PI acos(-1.0)
#define MOD 1000000007
#define PLL pair<ll,ll>
#define PII pair<int,int>
#define ull unsigned long long
#define triplell pair<pair<ll,ll> , ll>
#define triple pair<pair<int,int> , int>
#define For(i,n) for(int i=0;i<(int)n;i++)
#define Forn(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define forba(i,a,b) for(int i=(int)b;i>=(int)a;i--)

int dx[]={+1,-1,+0,+0};
int dy[]={+0,+0,+1,-1};
int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};
int hr[]={-2,-2,-1,+1,+2,+2,-1,+1};
int hc[]={+1,-1,+2,+2,-1,+1,-2,-2};

const int MAXN = (int)1e5+9;
int L[MAXN],R[MAXN],Z[MAXN];

struct node
{
	int l, r;
	
	node(int _l, int rr)
	{
		l=_l;
		r=rr;
	}
};

int main()
{
/*	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);  */
    
    int i,j,k,l,m,n,p,q,x,y,u,v,r,tc,t;
    
    cin>>n>>k;
    string s ;
    
    cin>>s;
    
    l=s.size();
    
    memset(L,0,sizeof(L));
    memset(R,0,sizeof(R));
    memset(Z,0,sizeof(Z));
    
    int cnt = 0;
    for(i=0;i<l;)
    {
    	if(s[i]=='0')
    	{
    		L[i]=cnt;
    		cnt = 0;
    		
    		j=i;
    		while(i<l && s[i]=='0')
    		{
    			Z[j]++;
    			i++;
			}
		}
		else
		{
			i++;
			cnt++;
		}
	}
	
	cnt = 0;
	for(i=l-1;i>=0;)
	{
		if(s[i]=='1')
		{
			cnt++;
			i--;
		}
		else
		{
			while(i>=0 && s[i]=='0')
			{
				i--;
			}
			
			R[i+1]=cnt;
			cnt=0;
		}
	}
	
	int ans = 0;
	vector<node>vec;
	
	for(i=0;i<l;)
	{
		if(s[i]=='0')
		{
		//	cout<<i<<" "<<L[i]<<" "<<R[i]<<" "<<Z[i]<<endl;
			vec.push_back(node(i-L[i],i+R[i]+Z[i]-1));
			
			while(i<l && s[i]=='0')
			{
				i++;
			}
		}
		else
			i++;
	}
	
	ans = 0;
	
	for(i=0;i<vec.size();i++)
	{
		j=i+k-1;
		if(j>=vec.size())
			j=vec.size()-1;
			
		int mx = vec[j].r-vec[i].l+1;
		ans=max(ans,mx);
	}
	
	if(ans==0)
		ans = n;
		
	cout<<ans<<endl;
	
//	main();

    return 0;
}

Measured memory_bytes: 2172
#include <bits/stdc++.h>
using namespace std;
#define fori(i,n) for(int i =0;i<n;i++)
#define pb push_back
#define ll long long
#define int long long
#define F first
#define S second
#define mp make_pair
#define rev(a) reverse(a.begin(),a.end())
#define srt(a) sort(a.begin(),a.end())
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cout.precision(15);
 
 
int mod = 1e9+7;
 
int pow(int a, int b) {
    int ans = 1;
    a %= mod;
    while(b) {
        if(b%2) {
            ans *= a;
            ans %= mod;
        }
        b /= 2;
        a *= a;
        a %= mod;
    }
    return ans;
}

int inv(int a) {
    return pow(a,mod-2);
}

int mul (int a,int b) {
    return ((a%mod)*(b%mod))% mod;
}

struct cmp {
    bool operator() (pair<int,int> a, pair<int,int> b) const {
        int x = a.F;
        int y = b.F;
        return x>=y;
    }
};


int32_t main() {
    FAST;
    int t;
    // cin>>t;
    t = 1;
    while(t--) {
        int n;
        cin>>n;
        int out = -1;
        n++;
        int a[n];
        int mx = 1e16;
        fori(i,n) {
            cin>>a[i];
        }
        int ans[n];
        ans[0] = 1;
        if(a[0] > 1) goto done;
        for(int i = 1;i<n;i++) {
            ans[i] = min(mx, 2ll*(ans[i-1] - a[i-1]));
            if(ans[i] < a[i]) goto done;
        } 
        ans[n-1] = a[n-1];
        for(int i =n-2;i>=1;i--) {
            ans[i] = min(ans[i], ans[i+1]+a[i]);
            if(ans[i] < a[i]) goto done;
        }
        out = 0;
        fori(i,n) {
            out += ans[i];
        }
        done :
        ;
        cout<<out;
    }
    
    return 0;
}

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

int main(){
    int n;
    long long k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    vector<int> order(n+1, -1);
    vector<int> recode;

    int v = 1, freq = 1, nonloop = 0;
    while (order[v] == -1){
        order[v] = recode.size();
        recode.push_back(v);
        v = a[v-1];
    }
    nonloop = order[v];
    freq = recode.size() - nonloop;

    if (k < nonloop) cout << recode[k] << endl;
    else{
        k -= nonloop;
        k %= freq;
        cout << recode[k + nonloop] << endl;
    }
    return 0;
}

Measured memory_bytes: 5880
#include <stdio.h>

int main(){
  int x, l, r;
  scanf("%d", &x);
  l = 1;
  r = x+1;
  while(l < r){
    int y = (l & r) + (l ^ r) / 2;
    if((long long) y*(y+1)/2 < x) l = y+1;
    else r = y;
  }
  printf("%d\n", l);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
    int n; cin >> n;
    
    multiset<int> s;
    REP(i, n) {
        int a; cin >> a;
        auto it = s.lower_bound(a);
        
        if(it != s.begin() && *(--it) < a) {
            s.erase(it);
            s.insert(a);
        } else {
            s.insert(a);
        }
    }

    cout << s.size() << endl;

    return 0;
}


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

using namespace std;

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

  int sz = s.size(), ans = 1 << 30;
  for (int i = 0; i < sz - 1; i++) {
    if (s[i] == s[i + 1]) continue;
    ans = min(ans, max(i + 1, sz - i - 1));
  }
  cout << (ans == 1 << 30 ? sz : ans) << endl;

  return 0;
}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Globalization;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;

class Program
{
    static void Main()
    {
        var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
        SetOut(sw);
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";


    void solve()
    {
        int sx, sy, tx, ty;
        sx = cin.nextint;
        sy = cin.nextint;
        tx = cin.nextint;
        ty = cin.nextint;

        for (int i = 0; i < tx - sx; i++)
        {
            Write("R");
        }
        for (int i = 0; i < ty - sy; i++)
        {
            Write("U");
        }
        for (int i = 0; i < tx - sx; i++)
        {
            Write("L");
        }
        for (int i = 0; i < ty - sy; i++)
        {
            Write("D");
        }

        Write("D");
        for (int i = 0; i < tx - sx + 1; i++)
        {
            Write("R");
        }
        for (int i = 0; i < ty - sy + 1; i++)
        {
            Write("U");
        }
        Write("L");

        Write("U");
        for (int i = 0; i < tx - sx + 1 ; i++)
        {
            Write("L");
        }
        for (int i = 0; i < ty - sy + 1; i++)
        {
            Write("D");
        }
        Write("R");

        WriteLine();
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 2776
#include<bits/stdc++.h>
#define For(i,j,k) for(int i=j;i<=k;++i)
#define Forr(i,j,k) for(int i=j;i>=k;--i)
#define getchar getchar_unlocked
#define ll long long 
using namespace std;
const int N=10010,INF=0x3f3f3f3f;
template<class T>void read(T &x){
	x=0;register char c=getchar();
	while(!isdigit(c))c=getchar();
	while( isdigit(c))x=x*10+c-48,c=getchar();
}
int n,X[N<<1],K,Lim,id[N<<1],sz[N<<2],m,Low;
vector<int>G[N<<2];
inline void add(int x,int y){G[y].push_back(x);}
inline void Add(int x,int y){add(x,y),add(y,x);}
inline void link(int x,int y){
	Add(x*2+1,y*2),Add(y*2+1,x*2);
}
inline void Link(int x,int y){
	add(x*2+1,y*2),add(y*2+1,x*2);
}
inline bool cmp(int a,int b){return X[a]<X[b];}
int pre[N<<2],sccno[N<<2],scc[N<<2],scc_cnt,low[N<<2],dfs_cnt;
stack<int>s;
void dfs(int u){
	low[u]=pre[u]=++dfs_cnt;
	sccno[u]=1;s.push(u);
	int S=G[u].size();
	For(i,0,S-1){
		int v=G[u][i];
		if(!pre[v])dfs(v),low[u]=min(low[u],low[v]);
		else if(sccno[v])low[u]=min(low[u],pre[v]);
	}
	if(pre[u]==low[u]){
		++scc_cnt;
		int w;
		do{
			w=s.top();s.pop();
			scc[w]=scc_cnt;sccno[w]=0;
		}while(w!=u);
	}
}
bool check(int dis){
	For(i,0,m)G[i].resize(sz[i]);
	For(i,0,2*n-1){
		For(j,max(i-9,0),min(i+9,2*n-1)){
			if(j==i)continue;
			if(abs(X[id[j]]-X[id[i]])>=dis)continue;
			if(abs(id[i]-id[j])==n)continue;
			Link(id[i],id[j]);
		}
	}
	dfs_cnt=0;scc_cnt=0;
	For(i,0,m)pre[i]=0,scc[i]=0;
	For(i,0,m)if(!pre[i])dfs(i);
	For(i,0,2*n-1)if(scc[i*2]==scc[i*2+1])return 0;
	return 1;
}
inline bool Check(int dis){
	int cnt=0,last=-INF;
	For(i,0,2*n-1){
		if(X[id[i]]-last>=dis)cnt++,last=X[id[i]];
		if(cnt==n)break;
	}
	return cnt==n;
}
void solveLim(){
	int L=0,R=Lim,ans=0;
	while(L<=R){
		int Mid=(L+R)>>1;
		if(Check(Mid))ans=Mid,L=Mid+1;
		else R=Mid-1;
	}
	Lim=ans;
}
int main(){
	read(n);Low=INF;
	For(i,0,n-1){
		read(X[i]),read(X[i+n]);
		link(i,i+n);
		Lim=max(Lim,max(X[i],X[i+n]));
		if(i)Low=min(Low,X[i]-X[i-1]);
	}
	m=4*n-1;
	For(i,0,2*n-1)id[i]=i;
	For(i,0,m)sz[i]=G[i].size();
	sort(id,id+2*n,cmp);
	solveLim();
	int L=Low,R=Lim,ans=0;
	while(L<=R){
		int Mid=(L+R)>>1;
		if(check(Mid))L=Mid+1,ans=Mid;
		else R=Mid-1;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 6016
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
int dp[100005][30];
int x[1000005];
int main(){
    int n;
    cin >> n;
    rep(i,n)cin >> x[i];
    int L;
    cin >> L;
    rep(i,n){
        dp[i][0] = (int)(upper_bound(x,x+n,x[i]+L)-x)-1;
    }
    for(int j = 1; j <= 29; j++){
        rep(i,n){
            dp[i][j] = dp[dp[i][j-1]][j-1];
        }
    }
    int q;
    cin >> q;
    while(q--){
        int a,b;
        cin >> a >> b;
        a--,b--;
        if(a>b)swap(a,b);
        int ans = 0;
        for(int i = 29; i >= 0; i--){
            if(dp[a][i] < b){
                ans += 1<<i;
                a = dp[a][i];
            }
        }
        cout << ans + 1 << endl;
    }
}

Measured memory_bytes: 14848
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int[][] member_pos,check_point;
		int[]member_check_point_id;

		int member_count = sc.nextInt();
		int check_point_count = sc.nextInt();

		member_pos = new int[member_count][2];
		check_point = new int[check_point_count][2];
		member_check_point_id = new int[member_count];

		for(int i = 0;i < member_count;i++){
			member_pos[i][0] = sc.nextInt();
			member_pos[i][1] = sc.nextInt();
		}

		for(int i = 0;i < check_point_count;i++){
			check_point[i][0] = sc.nextInt();
			check_point[i][1] = sc.nextInt();
		}

		for(int i = 0;i < member_count;i++){
			int min = Integer.MAX_VALUE;
			int x = member_pos[i][0];
			int y = member_pos[i][1];
			for(int j = 0;j < check_point_count;j++){
				int len = Math.abs(x - check_point[j][0]) + Math.abs(y - check_point[j][1]);
				if(len < min){
					min = len;
					member_check_point_id[i] = j + 1;
				}
			}
		}

		for(int i = 0;i < member_check_point_id.length;i++){
			System.out.println(member_check_point_id[i]);
		}

		sc.close();
	}

}


Measured memory_bytes: 22740
#include <iostream>
#include<math.h>
#include <limits>
#include <iomanip>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i =1; i <= (int)(n); i++)

int main() {
    int N;
    cin >> N;
    int ans = 0;
    rep(i, N) {
        int eight = 0;
        rep(j, N) {
            if (j%2!=0 && i % j == 0)eight++;
        }
        if (eight == 8)ans++;
   }

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

Measured memory_bytes: 256
void main() {
  problem();
}

void problem() {
  const N = scan!int;
  const K = scan!long;
  const A = scan!int(N);

  void solve() {
    int[int] alreadyVisited;

    int count;
    int last;
    for(int next = 1; !(next in alreadyVisited); next = A[next-1]) {
      if (count == K) {
        writeln(next);
        return;
      }

      last = next;
      alreadyVisited[next] = count++;
    }

    const loopback = A[last-1];
    const stepBeforeLoop = alreadyVisited[loopback];
    const loopSize = count - stepBeforeLoop;
    [last, loopback, count, stepBeforeLoop, loopSize].deb;

    const amari = (K - stepBeforeLoop) % loopSize;
    int point = loopback;
    foreach(i; 0..amari) {
      point = A[point - 1];
    }
    writeln(point);
  }

  solve();
}

// ----------------------------------------------

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");
import std.bigint, std.functional;

// -----------------------------------------------


Measured memory_bytes: 23604
import java.util.Scanner;

public class Main {

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

		if (a + b < c * 2) {
			System.out.println(a * x + b * y);
		} else {
			int ab = Math.min(x, y);
			System.out.println(Math.min((x - ab) * a + (y - ab) * b + c * ab * 2, c * Math.max(x, y) * 2));
		}

		sc.close();
	}
}

Measured memory_bytes: 21716
#include <iostream>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    string s;
    cin >> s;
    int count = 0;
    for(int i = 0; i < s.size() / 2; i++){
        if(s[i] != s[s.size()-1-i]) count++;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
x = int(input())
pro = 1
n = input().split(' ')
li = 10 ** 18
flag = 1
for i in range(x):
    pro = pro * int(n[i])
    if pro > li:
        flag = 0
        break;
if '0' in n:
    flag = 1
    pro = 0
if flag:
    print(pro)
else:
    print(-1)


Measured memory_bytes: 19320
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int faceNum = sc.nextInt();
        int limitScore = sc.nextInt();
        
        int face, score, cnt;
        double pr = 0;
        for(face = 1; face <= faceNum; face++){
            score = face;
            cnt = 0;
            while(score < limitScore){
                score *= 2;
                cnt++;
            }
            pr += 1 / Math.pow(2, cnt);
        }

        System.out.println(pr / faceNum);
    }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD=1e9+7;
const int INF32=1<<30;
const ll INF64=1LL<<60;

void solve(){
  int w,h,x,y; cin >>w >>h >>x >>y;
  cout <<1.0*w*h/2<<' ';
  if(x+x==w&&y+y==h) cout <<1;
  else cout <<0;
}

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);
  solve();
return 0;}

Measured memory_bytes: 3728
def main():
    N = int(input())
    z = 0
    for i in range(N):
        d1, d2 = map(int, input().split())
        if d1 == d2:
            z += 1
        else:
            z = 0
        if z >= 3:
            return True

    return False

print("Yes" if main() else "No")


Measured memory_bytes: 9160
from math import sin, cos, radians, sqrt

a, b, c = list(map(int, input().split()))
print(a * b * sin(radians(c)) / 2)
print(a + b + sqrt((a ** 2) + (b ** 2) - (2 * b * a * cos(radians(c)))))
print(b * sin(radians(c)))



Measured memory_bytes: 5704
import heapq

N, M = map(int, input().split())

AB = [[] for _ in range(M)]
for _ in range(N):
    a, b = map(int, input().split())
    if a > M: continue
    AB[M-a].append(b)

q = []
heapq.heapify(q)
ans = 0
for i in range(M-1, -1, -1):
    if len(AB[i]) != 0:
        for b in AB[i]:
            heapq.heappush(q, -b)
    if len(q) != 0:
        ans += heapq.heappop(q)
print(-ans)

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

struct UnionFind
{
	int N;
	vector<int> parent;
	vector<int> size_r;
	int num_of_sets;

	UnionFind(int N) : N(N), parent(N), size_r(N, 1), num_of_sets(N) {
		for (int i = 0; i < N; ++i) parent[i] = i;
	}

	int root(int x) {
		if (parent[x] == x) return x;
		return parent[x] = root(parent[x]);
	}

	bool merge(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return false;
		if (size_r[x] < size_r[y]) swap(x, y);
		parent[y] = x;
		size_r[x] += size_r[y];
		size_r[y] = 0;
		num_of_sets--;
		return true;
	}

	bool same(int x, int y) {
		return root(x) == root(y);
	}

	int size(int x) {
		return size_r[root(x)];
	}
};

int main() {
	int n, Q;
	cin >> n >> Q;
	UnionFind uf(n);
	for (int q = 0; q < Q; q++) {
		int t, u, v;
		scanf("%d%d%d", &t, &u, &v);
		if (t == 0) {
			uf.merge(u, v);
		} else {
			if (uf.same(u, v)) printf("1\n");
			else printf("0\n");
		}
	}
	return 0;
}

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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

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

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return (*this) *= a.inv(); }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

struct combination {
    vector<mint> fact, ifact;
    combination(int n) : fact(n + 1), ifact(n + 1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i)
            fact[i] = fact[i - 1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i)
            ifact[i - 1] = ifact[i] * i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }
    mint operator()(int n) { return fact[n]; }
};

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n, 1);
    rep(i, n) { cin >> a[i]; }
    sort(all(a));
    vector<mint> A(n, mint(0));
    rep(i, n) { A[i] = mint(a[i]); }

    combination comb(n + 10);
    mint ans = 0;
    for (int i = 0; i < A.size(); i++) {
        ans += A[i] * comb(i, k - 1);
        ans -= A[i] * comb(n - (i + 1), k - 1);
    }
    cout << ans.x << endl;
    return 0;
}

Measured memory_bytes: 2944
import java.util.Scanner;
public class Main {
     
    static char[] k = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
     
 
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        String str = stdIn.next();
        int q = stdIn.nextInt();
        for(int i = 0; i < q; i++) {
            String stt = stdIn.next();
            if(stt.equals("print")) {
                int a = stdIn.nextInt();
                int b = stdIn.nextInt();
                String tmp = str.substring(a, b+1);
                System.out.println(tmp);
            }
            else if(stt.equals("reverse")) {
                int a = stdIn.nextInt();
                int b = stdIn.nextInt();
                String tmp = str.substring(a,b+1);
                String tmp2 = "";
                for(int j = tmp.length()-1; j >= 0; j--) {
                    tmp2 += String.valueOf(tmp.charAt(j));
                }
                String ck1 = str.substring(0, a);
                String ck2 = str.substring(b+1,str.length());
                str = ck1 + tmp2 + ck2;
            }
            else if(stt.equals("replace")) {
                int a = stdIn.nextInt();
                int b = stdIn.nextInt();
                String p = stdIn.next();
                String ck1 = str.substring(0, a);
                String ck2 = str.substring(b+1,str.length());
                str = ck1 + p + ck2;
                 
            }
        }
    }
}


Measured memory_bytes: 47424
def main ():
    N = int(input())
    A = list(map(int,input(). split ()))
    if 0 in A:
        print(0)
        return
    prod = 1
    for a in A:
        prod *= a
        if prod > 1000000000000000000:
            print(-1)
            return
    print(prod)
main ()

Measured memory_bytes: 21716
#include <iostream>
#include <complex>
#include <cmath>

using namespace std;

typedef complex<double> Point;

bool parallel(const Point &v1, const Point &v2) {
    return abs(v1.real()*v2.imag() - v1.imag()*v2.real()) < 1e-10;
}

int main() {
    int N;
    cin >> N;
    while(N--) {
        Point ps[4];
        for(int i = 0; i < 4; ++i) cin >> ps[i].real() >> ps[i].imag();
        Point v1 = ps[1]-ps[0], v2 = ps[3]-ps[2];

        if(parallel(v1, v2)) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 0
N, X, Y = map(int, input().split())
ans = [0]*N
for i in range(1, N+1):
    for j in range(i+1, N+1):
        if i<X:
            if j<X:
                ans[j-i]+=1
            elif j<=Y:
                ans[X-i+min(j-X, Y-j+1)]+=1
            else:
                ans[X-i+j-Y+1]+=1
        elif i<=Y:
            if j<=Y:
                ans[min(j-i, i-X+Y-j+1)]+=1
            else:
                ans[min(i-X+1, Y-i)+j-Y]+=1
        else:
            ans[j-i]+=1

for a in ans[1:]:
    print(a)

Measured memory_bytes: 3444
//テンプレ
#include <bits/stdc++.h>
#define int long long
#define REP(i,n) for(int i = 0; i < (n); ++i)
#define FOR(i,a,b)  for(int i = (a); i <= (b); ++i)
#define ALL(v) (v).begin(),(v).end()

using namespace std;
//constexpr int MOD = 10e9+7;
//constexpr int INF = 1LL << 60;
template <class T> inline bool chmin(T& a, T b){if(a > b){ a = b; return 1;} return 0;}  
template <class T> inline bool chmax(T& a, T b){if(a < b){ a = b; return 1;} return 0;}  
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
//
signed main (){
   ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
   int a,b;
   cin >> a >> b; 
   cout << ceil(static_cast<double>(a+b)/2)<< endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
          
using namespace std;
          
#define ll long long
#define vi vector<int> 
#define pb push_back
#define sz(s) (int)s.size() 
#define all(v) v.begin(), v.end()
#define show(a) cerr << #a <<" -> "<< a <<"\n"
 
ll mn = 1000000, mx = -1000000000; 
ll cnt, cnt2, sum, x, y;
ll n, k, a[1001], b[1001];
vi v;
			             
int main (){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> k;
    if (n <= k) {
    	cout << "unsafe";
	}
	else {
		cout << "safe";
	}
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
 
int main(){
 
  string S;
  string T;
  int ans=0;
  
  cin >> S;
  cin >> T;
  
  for(int i=0;i<S.size();i++){
 
    if(S[i]!=T[i]) ans++;
    
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 3820
function main(arg) {
	arg = arg.trim();
  	var long = arg.length,
        c = Math.round(long/2),
  		out = 0;
	for (var i = 0; i < c; i ++) {
    	var stword = arg[i],
           	lsword = arg[long - i -1];
      	if (stword != lsword) {
        	out++;
        }
    }
  console.log(out)
  	
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 9420
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    int n;
    cin >> n;
    cout.precision(20);
    if(n % 2 == 0) cout << 0.5 << endl;
    else cout << (float)(n+1)/(float)(2*n) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;;
#define f(i,a,b) for(int i=a;i<=b;i++)
const int M=1e6;

int main(){
    char x;
    int r=0;
    while(cin>>x){
        r+=(x-'0');
        r%=9;
    }
    if(r%9) cout<<"No";
    else cout<<"Yes";
}


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


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

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


int main(){
  ll n; cin >> n;
  mint a = 10, b = 9, c = 9, d = 8;
  mint ans = a.pow(n) - b.pow(n) - c.pow(n) + d.pow(n);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3604
MOD = 2019
L, R = gets.split(' ').map(&:to_i)
  l = L%MOD
  r = R%MOD
if (l==0) || (r==0) || (L/MOD != R/MOD)
  puts 0
else
  min = 2018
  (l..r).each do |i|
    (i+1..r).each do |j|
      num = (i * j) % MOD
      min = num if num < min
      break if min == 0
    end
    break if min == 0
  end
  puts min
end

Measured memory_bytes: 1788
/*** akshaykumar99 ***/
 
#include<bits/stdc++.h> 
using namespace std;
 
const long long MOD = 1e9+7;
const long double PI = acos(-1);
const long long N = 1e6+1;
 
typedef long long ll;
typedef long double ld;

ll spf[N]; 
void sieve() 
{ 
    spf[1] = 1; 
    for (ll i=2; i<N; i++) 
        spf[i] = i; 
  
    for (ll i=4; i<N; i+=2) 
        spf[i] = 2; 
  
    for (ll i=3; i*i<N; i++) 
    { 
        if (spf[i] == i) 
        { 
            for (ll j=i*i; j<N; j+=i)             
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
} 
vector<ll> getFactorization(ll x) 
{ 
    vector<ll> ret; 
    while (x != 1) 
    { 
        ret.push_back(spf[x]); 
        x = x / spf[x]; 
    } 
    return ret; 
} 
void test_case()
{
    ll n;
    cin >> n;
    vector<ll> v(n);
    sieve();
    for(ll i = 0; i < n; i++)
    {
    	cin >> v[i];
    }
    vector<bool> done(N, 0);
    bool flag = 0;
    for(ll i = 0; i < n; i++)
    {
    	vector<ll> p = getFactorization(v[i]);
    	for(ll j = 0; j < p.size(); j++)
    	{
    		if(done[p[j]])
    		{
    			flag = 1;
    			break;
    		}
    	}
    	for(ll j = 0; j < p.size(); j++)
    	{
    		done[p[j]] = 1;
    	}
    	if(flag)
    		break;
    }
    if(!flag)
    {
    	cout << "pairwise coprime\n";
    	return;
    }
    ll gg = v[0];
    for(int i = 1; i < n; i++)
    {
    	gg = __gcd(gg, v[i]);
    }
    if(gg == 1)
    {
    	cout << "setwise coprime\n";
    	return;	
    }
    cout << "not coprime\n";


}
 
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL); 
    ll tc=1;
    // cin>>tc;
    while(tc--)
        test_case();
    return 0;
}


Measured memory_bytes: 19164
N,M = map(int,input().split())
AC = {}
WA = {}
for i in range(M):
    prb ,ans = input().split()
    if ans == "AC":
        AC[prb] = 1
    else:
        if (prb in WA) == False and (prb in AC) ==  False:
            WA[prb] = 1
        else:
            if (prb in AC) ==  False:
                WA[prb] +=1
wa = 0
for i,v in WA.items():
    if (i in AC):
        wa += v
print("{} {}".format(len(AC),wa))

Measured memory_bytes: 58072
#include <cstdlib>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <numeric>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>

using namespace std;

#define sz(X) ((int)(X).size())
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define all(X) (X).begin(),(X).end()
#define FOR(i, a, n) for(int i=(a), __ ## i=(n); i<__ ## i; i++)
#define REP(I,N) FOR(I,0,N)
#define PR(X) cout<<#X<<" = "<<(X)<<" "
#define PRL cout<<endl
#define PRV(X) {cout<<#X<<" = {";REP(__prv,sz(X)-1)cout<<(X)[__prv]<<",";if(sz(X))cout<<*(X).end();cout<<"}"<<endl;}

template<class T> ostream &operator<<(ostream &os, const vector<T> &vec)
{
	os << '{';
	REP(i, sz(vec))
	{
		os << vec[i];
		if (i + 1 != sz(vec))
			os << ',';
	}
	os << '}';
	return os;
}

template<class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &par)
{
	os << '(' << par.X << ',' << par.Y << ')';
	return os;
}

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<bool> VB;
typedef vector<unsigned long long> VULL;
typedef vector<vector<int>> VVI;
typedef queue<int> QI;

int gcd(int x, int y)
{
	return y ? gcd(y, x % y) : abs(x);
}

template<class T> T sqr(T x)
{
	return x * x;
}

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

	int n, m;
	cin >> m >> n;
	vector<LL> horz(m), vert(n);
	LL hrz = 0, vrt = 0;
	LL hrz2 = 0, vrt2 = 0;
	REP(i, m)
		cin >> horz[i];
	REP(i, n)
		cin >> vert[i];

	LL sum = 0;
	FOR(i, 1, m)
	{
		hrz = (hrz + sum + (horz[i] - horz[i - 1]) * i) % 1000000007;
		sum += ((horz[i] - horz[i - 1]) * i) % 1000000007;
	}

	sum = 0;
	FOR(i, 1, n)
	{
		vrt = (vrt + sum + (vert[i] - vert[i - 1]) * i) % 1000000007;
		sum += ((vert[i] - vert[i - 1]) * i) % 1000000007;
	}

	cout << (vrt*hrz) % 1000000007 <<endl;

	return 0;
}

Measured memory_bytes: 1920
#include <iostream>
#include <fstream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <utility>
#include <map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <sstream>
#include <cstring>
#include <bitset>
#include <stack>
using namespace std;
#define MP make_pair
#define PB push_back
const int INF=1e9;

int n,m,k,sx,sy,ans;
char c[805][805];
int dist[805][805];
int mx[]={0,0,1,0,-1};
int my[]={0,1,0,-1,0};

inline void bfs(int X,int Y)
{
	queue <int> q;
	q.push(X);q.push(Y);
	memset(dist,-1,sizeof(dist));
	dist[X][Y]=0;
	while (!q.empty())
	{
		int x=q.front();q.pop();
		int y=q.front();q.pop();
		for (int i=1;i<=4;i++)
		{
			int tx=x+mx[i];
			int ty=y+my[i];
			if (tx<1 || tx>n || ty<1 || ty>m || dist[tx][ty]!=-1 || c[tx][ty]!='.') continue;
			dist[tx][ty]=dist[x][y]+1;
			q.push(tx);
			q.push(ty);
		}
	} 
}

int main()
{
	cin>>n>>m>>k;
	for (int i=1;i<=n;i++) scanf("%s",c[i]+1);
	for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) if (c[i][j]=='S') {sx=i;sy=j;break;}
	bfs(sx,sy);
	ans=INF;
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
			if (dist[i][j]<=k && dist[i][j]!=-1)
			{
		//		cout<<i<<" "<<j<<endl;
				int res=min(i-1,n-i);
				res=min(res,min(j-1,m-j));
				ans=min(ans,res);
			}
	cout<<1+(ans+k-1)/k;
	return 0;
}

Measured memory_bytes: 3456
import sys, heapq, bisect, math, fractions
from collections import deque

N = int(input())
d = {}

res = 0
for i in range(N):
    s = "".join(sorted(sys.stdin.readline().strip()))
    if s in d:
        d[s] += 1
    else:
        d[s] = 1

for dd in d.values():
    res += dd * (dd - 1) // 2

print(res)

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

using namespace std;

#define INF 1e9

int len(int i,int j){
    int res=i*i+j*j;
    return res;
}

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

    while(1){
        int h,w;
        cin>>h>>w;
        
        if(h==0)break;

        int L=len(h,w);

        pair<int,int> ans={10000,10000};

        for(int i=1;i<1000;i++){
            for(int j=i+1;j<1000;j++){
                if(i==h && j==w)continue;
                int LL=len(i,j);
                if(LL==L && i<h)continue;
                if(LL>=L && LL<len(ans.first,ans.second)){
                    ans={i,j};
                }
            }
        }
        cout<<ans.first<<" "<<ans.second<<endl;
    }
}


Measured memory_bytes: 3068
n,m=map(int,input().split())
heights=list(map(int,input().split()))
heights_w=sorted([(h,i+1) for i,h in enumerate(heights)])[::-1]
cons={i+1:set() for i in range(n)}
for _ in range(m):
  a,b=map(int,input().split())
  cons[a].add(b)
  cons[b].add(a)

debug=False
watched=set()
res=0
if debug: res_m=set()
for h,i in heights_w:
  if i in watched:
    continue
  watched.add(i)
  flg=True
  for con in cons[i]:
    if debug: print(h,heights[con-1],i,con)
    flg=(flg and h>heights[con-1])
    watched.add(con)
  if debug: print(i,h,flg)
  if flg:
    if debug: res_m.add(i)
    res+=1
if debug: print(heights_w,cons,res_m)
print(res)



Measured memory_bytes: 130336
using System;

public class ABC168A {
	private static void Main(string[] args) {
		var n = ReadInt();
		var reading = new string[] {
			"pon", "pon", "hon", "bon", "hon",
			"hon", "pon", "hon", "pon", "hon",
		};

		var answer = reading[n % 10];
		Console.WriteLine(answer);
	}

	private static int ReadInt() => int.Parse(Console.ReadLine().Trim());
}

Measured memory_bytes: 27244
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll=long long;
using P=pair<int,int>;
int main() {
    string s,t;cin>>s>>t;
    sort(s.begin(),s.end());
    sort(t.begin(),t.end());
    reverse(t.begin(),t.end());
    if(s<t) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

int main(){

  int N,X,ans=0,mn=100001;
  cin >> N >> X;
  int m[X];
  for(int i=0; i<N; i++){
    cin >> m[i];
    X -= m[i];
    mn = min(mn, m[i]);
  }

  ans = N + X/mn;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))

ri = 0
for i in range(N):
    ri += (-1)**i*A[i]
R = [ri]
for i in range(1,N):
    ri = -(ri-A[i-1])+A[i-1]
    R.append(ri)
print(*R)

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

int main(){
string s;
cin>>s;
for(int i=0;s[i+4]!='\0';i++){
for(int j=0;j<1;j++){
if(s[i]=='a'&&s[i+1]=='p'&&s[i+2]=='p'&&s[i+3]=='l'&&s[i+4]=='e'){s[i]='p'; s[i+1]='e'; s[i+2]='a'; s[i+3]='c'; s[i+4]='h'; 

break;}
if(s[i]=='p'&&s[i+1]=='e'&&s[i+2]=='a'&&s[i+3]=='c'&&s[i+4]=='h'){s[i]='a'; s[i+1]='p'; s[i+2]='p'; s[i+3]='l'; s[i+4]='e'; 

break;}}}
cout<<s;
while(cin>>s){
for(int i=0;s[i+4]!='\0';i++){
for(int j=0;j<1;j++){
if(s[i]=='a'&&s[i+1]=='p'&&s[i+2]=='p'&&s[i+3]=='l'&&s[i+4]=='e'){s[i]='p'; s[i+1]='e'; s[i+2]='a'; s[i+3]='c'; s[i+4]='h'; 

break;}
if(s[i]=='p'&&s[i+1]=='e'&&s[i+2]=='a'&&s[i+3]=='c'&&s[i+4]=='h'){s[i]='a'; s[i+1]='p'; s[i+2]='p'; s[i+3]='l'; s[i+4]='e'; 

break;}}}
cout<<" "<<s;}
cout<<endl;
}

Measured memory_bytes: 1176
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	int N, Q; cin >> N >> Q;
	if (N < 1000) {
		vector<int>nums(N);
		for (int i = 0; i < N; ++i) {
			cin >> nums[i];
		}
		while (Q--) {
			int q; cin >> q;
			int ans = 0;
			for (int i = 0; i < N; ++i) {
				ans= max(ans, nums[i] % q);
			}
			cout << ans << endl;
		}
	}
	else {
		vector<int>nums(300001);
		for (int i = 0; i < N; ++i) {
			int a; cin >> a;
			nums[a] = true;
		}
		while (Q--) {
			int q; cin >> q;
			int ans = -1;
			for (int i = q - 1; i >= 0; --i) {
				for (int j = 0; true; ++j) {
					int num = j*q + i;
					if (num > 300000)break;
					if (nums[num]) {
						ans = i;
						break;
					}
				}
				if (ans != -1)break;
			}
			cout << ans << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3860
N, M, Q = [int(_) for _ in input().split()]

l = [[0 for i in range(N+1)] for j in range(N+2)]
for t in [input().split() for _ in range(M)]:
    i = int(t[0])
    j = int(t[1])
    l[i][j] += 1

for k in range(N):
    for i in range(1, N-k+1):
        j = i + k
        l[i][j] += l[i][j-1] + l[i+1][j] - l[i+1][j-1]

for k in [input().split() for _ in range(Q)]:
    p = int(k[0])
    q = int(k[1])
    print(l[p][q])


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

#define ll long long
#define pb push_back
#define mp make_pair
#define ld long double
#define F first
#define S second
#define pii pair<ll,ll> 

using namespace :: std;

const ll mod=1e9+7;
const ll maxn=2e5+500;
const ll inf=1e9+900;

void put(ll a){
    if(a==1){
	cout<<"First";
    }else{
	cout<<"Second";
    }
    exit(0);
}

vector<ll> ger[maxn];
pii find_far(ll a,ll p=-1){
    pii best=mp(0,a);
    for(auto v:ger[a]){
	if(v!=p){
	    pii e=find_far(v,a);
	    e.F++;
	    best=max(best,e);
	}
    }
    return best;
}


int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n;
    cin>>n;
    for(ll i=0;i+1<n;i++){
	ll v,u;
	cin>>v>>u;
	ger[v].pb(u);
	ger[u].pb(v);
    }
    ll a=find_far(1).S;
    ll e=find_far(a).F+1;
    if(e==1)put(1);
    if(e==2)put(2);
    e-=3;
    if(e%3==2)put(2);
    else put(1);


}


Measured memory_bytes: 26880
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main() {
    string n;
    cin >> n;
    int len = n.length();
    for (int i = 0; i < len; i++) {
        if (n[i] == '9') {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256