akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <vector>
#include <list>
#define LL long long
#define INF 0x7fffffff
#define clr(x,y) memset(x,y,sizeof(x))
using namespace std;

struct Node
{
    LL cnt;
    char ch;
};

list<Node> l;

int main()
{
    //freopen("in.txt","r",stdin);
    int q;
    while(~scanf("%d",&q))
    {
        l.clear();
        for(int i=1;i<=q;i++)
        {
            LL p,n;
            char c[2];
            scanf("%lld%s%lld",&p,c,&n);
            list<Node>::iterator it,it2;
            Node node;
            node.cnt=n;
            node.ch=c[0];
            if(l.empty())
                l.push_back(node);
            else if(p==0)
            {
                if((l.begin())->ch==c[0])
                    (l.begin())->cnt+=n;
                else
                    l.insert(l.begin(),node);
            }
            else
            {
                LL sum=0;
                for(it=l.begin();it!=l.end();it++)
                {
                    sum+=it->cnt;
                    if(sum==p)
                    {
                        if(it->ch==c[0])
                            it->cnt+=n;
                        else
                        {
                            it2=it;
                            it2++;
                            if(it2==l.end())
                                l.push_back(node);
                            else
                                it2->cnt+=n;
                        }
                        break;
                    }
                    else if(sum>p)
                    {
                        if(it->ch==c[0])
                            it->cnt+=n;
                        else
                        {
                            Node n1,n2;
                            n1.ch=n2.ch=it->ch;
                            n2.cnt=sum-p;
                            n1.cnt=it->cnt-n2.cnt;
                            l.insert(it,n2);
                            l.insert(it,node);
                            l.insert(it,n1);
                            l.erase(it);
                        }
                        break;
                    }
                }
            }
            //for(it=l.begin();it!=l.end();it++)
            //    printf("%c %lld\n",it->ch,it->cnt);
            if(l.size()==1)
            {
                puts("No");
                continue;
            }
            LL sum=0;
            for(it=l.begin();it!=l.end();it++)
                sum+=it->cnt;
            if(sum%2!=0)
            {
                puts("No");
                continue;
            }
            it=l.begin();
            it2=l.end();
            it2--;
            bool ok=1;
            for(;it!=l.end();it++,it2--)
                if(it->ch==it2->ch||it->cnt!=it2->cnt)
                {
                    ok=0;
                    break;
                }
            if(ok)
                puts("Yes");
            else
                puts("No");
        }
    }
    return 0;
}

Measured memory_bytes: 1220
#include "bits/stdc++.h"
using namespace std;

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

	int ans;
	if (a + b == 3) {
		ans = 3;
	} else if (a + b == 4) {
		ans = 2;
	} else {
		ans = 1;
	}

	cout << ans << endl;
}


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

int ma(vector<int> a){
  int ma = 0;
  for(int x : a){
    ma = max(ma, x);
  }
  return ma;
}

int mi(vector<int> a){
  int mi = 100000;
  for(int x : a){
    mi = min(mi, x);
  }
  return mi;
} 

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> l(m), r(m);
  for(int i = 0; i < m; i++){
    cin >> l[i] >> r[i];
  }
  
  if(ma(l) <= mi(r)){
    cout << mi(r) - ma(l) + 1 << endl;
  }
  else{
    cout << 0 << endl;
  }
}

Measured memory_bytes: 1792
N = int(input())
lis = [0]*N
S = [0]*N
P = [0]*N
for k in range(N):
  S[k],P[k] = input().split()
  P[k] = int(P[k])
  lis[k] = [S[k],P[k],k+1]
from operator import itemgetter
lis = sorted(lis, key=itemgetter(1),reverse = True)
lis = sorted(lis, key=itemgetter(0))
for i in range(N):
  print(lis[i][2])



Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <iomanip>
#include <cmath>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
template<class T> inline void chmin(T& a, T b) {if (a>b) a=b; }
template<class T> inline void chmax(T& a, T b) {if (a<b) a=b; }
inline void print() { cout << endl; }
template <class Head, class... Tail> inline void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " "; print(forward<Tail>(tail)...);}
template <class T> inline void print(vector<T>& vec) { for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " "; } cout << endl;}
template <class T> inline void print(vector<vector<T>>& df) { for (auto& vec : df) { print(vec); }}
typedef long long ll;
const ll LINF = 1e18;
const int INF = 1e9;



typedef pair<int, int> pt;

int dist(pt tgt, pt cent) {
    return abs(cent.first - tgt.first) + abs(cent.second - tgt.second);
}

int main() { 
    int N; cin >> N;
    vector<pt> P(N);
    vector<int> H;
    REP(i, N) {
        int x, y, h;
        cin >> x >> y >> h;
        P[i] = make_pair(x, y);
        H.push_back(h);
    }

    int cx, cy, ch;
    ch = 0;
    REP(x, 101) {
        REP(y, 101) {
            // print("x=", x, "y=", y, "-----------");
            pt cent = make_pair(x, y); // candidate
            int start = 0;
            ll h = 0;
            REP(i, N) {
                if(H[i] > 0) {
                    h = dist(cent, P[i]) + H[i];
                    // start = i+1;
                    break;
                }
            }

            bool valid_pt = true;
            for(int i=0; i<N; i++) {
                int elm_h = h - dist(cent, P[i]);
                // print("P[", i, "]=", P[i].first, P[i].second);
                // print("h=", h);
                // print("elm_h=", elm_h, "H[",i, "]=", H[i]);
                if (elm_h >= 0 && elm_h != H[i]) {
                    valid_pt = false;
                    break;
                } else if(elm_h<0 && H[i] != 0) {
                    valid_pt = false;
                    break;
                }
            }
            if (valid_pt) {
                if (h > ch) {
                    ch = h;
                    cx = x;
                    cy = y;
                }
            }
        }
    }
    print(cx, cy, ch);
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)

int main()
{
	int n, m;
	string str, nstr,sharp;
	
	cin >> n >> m;

	rep(i, m + 2) {
		sharp += '#';
	}

	rep(i, n) {
		cin >> nstr;
		str += nstr;
	}

	cout << sharp << endl;

	rep(i, n) {
		cout <<'#'+str.substr(i*m, m)+'#' << endl;
	}
	
	cout << sharp << endl;


	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,n) for(int i=1;i<(int)(n);i++)

typedef long long ll;
using namespace std;
int main()
{
  int n;
  cin>>n;
  int a[8]={1,2,4,8,16,32,64};
  int ans=0;
  rep(i,7){
    if(a[i]<=n&&a[i]>ans){
      ans=a[i];
    }
  }
  cout<<ans<<endl;
  return 0;
}


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

typedef long long ll;
#define pa pair<int, int> 
#define pal pair<long long, long long>
#define pali pair<long long, int>
#define pad pair<double, double>
#define pb push_back
#define mp make_pair 
#define COUT(v) for(int64_t i=0;i<(v).size();i++){ cout << v.at(i) << endl;}
#define REP(i, n) for(int64_t i=0;i<n;i++)
#define VIN(v) for(int64_t i=0;i<(v).size();i++){cin >> (v).at(i);}

typedef vector<bool> bvec;
typedef vector<int> ivec;
typedef vector<long long> lvec;
typedef vector<double> dvec;
typedef vector<pa> pavec;
typedef vector<pali> palivec;
typedef vector<pal>palvec;


typedef vector< vector<bool> > bmat;
typedef vector< vector<int> > imat;
typedef vector< vector<long long> > lmat;

typedef vector<string> svec;
typedef vector< vector<string> > smat;
const ll infll = (1LL << 60) - 1;
const int inf = (1 << 30) - 1;
const int MOD = 1000000007;


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

ll lcm(ll x, ll y){
    return x*y/gcd(x,y);
}

lvec mfactor(ll n){
    bvec ip(n, true);
    lvec mf(n, -1);
    ip[0]=false; ip[1]=false; mf[0]=0; mf[1]=1;
    REP(i, n){
        if(ip[i]){
            mf[i] = i;
            for(ll j=i*i; j<n; j+=i){
                ip[j] = false;
                if(mf[j] == -1) mf[j]=i;
            }
        }
    }
    return mf;
}

palivec get_prime(ll n, const lvec &mf){
    palivec plist;
    while(n != 1){
        int cnt=0;
        ll m=mf[n];
        while(mf[n] == m){
            cnt++;
            n/=m;
        }
        plist.pb(pali(m, cnt));
    }
    return plist;
}

void COMinit(int m, lvec &fac, lvec &finv){
    lvec inv(m);
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < m; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM(int n, int k, const lvec& fac, const lvec &finv){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll powmod(ll x, ll n){
    ll res=1;
    while(n>0){
        if(n&1) res = res*x%MOD;
        x = x*x%MOD;
        n>>=1;
    }
    return res;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    if(n%2==1) {
        cout << 0<< endl;
        return 0;
    }
    ll x=10;
    ll ans=0;
    while(n/x > 0 ){
        ans += n/x;
        x*=5;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass : Scanner
{
    static void Main()
    {
        var (x, y) = ReadTuple<long,long>();
        if (x <= 1 && y <= 1)
        {
            WriteLine("Brown");
        }
        else if (Abs(x - y) <= 1)
        {
            WriteLine("Brown");
        }
        else
        {
            WriteLine("Alice");
        }
    }
}



class Scanner
{
    public static string RString() => Console.ReadLine();
    public static int RInt() => ReadTuple<int>();
    public static long RLong() => ReadTuple<long>();
    public static double RDouble() => ReadTuple<double>();

    public static string[] RStrings() => Console.ReadLine().Split();
    public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
    public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
    public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse);
    public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray();
    //public static string[] RStrings(Func<string, string> func) => Console.ReadLine().Split().Select(func).ToArray();

    public static T1 ReadTuple<T1>()
    {
        var r = RString();
        var r1 = (T1)Convert.ChangeType(r, typeof(T1));
        return r1;
    }
    public static (T1, T2) ReadTuple<T1, T2>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        return (r1, r2);
    }
    public static (T1, T2, T3) ReadTuple<T1, T2, T3>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
        return (r1, r2, r3);
    }
    public static (T1, T2, T3, T4) ReadTuple<T1, T2, T3, T4>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
        var r4 = (T4)Convert.ChangeType(r[3], typeof(T4));
        return (r1, r2, r3, r4);
    }
}


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

#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define FILL0(x) memset(x,0,sizeof(x))
#define FILL1(x) memset(x,-1,sizeof(x))

using namespace std;

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

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 (b<a) { a=b; return 1; } return 0; }

struct pnt
{
    int y;
    int x;
    int warp; //count
};

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int h, w;
    cin >> h >> w;
    pnt s, g;
    cin >> s.y >> s.x;
    cin >> g.y >> g.x;
    s.y--;s.x--;g.x--;g.y--;
    s.warp = 0;

    string maze[h];
    rep(i, h)
    {
        cin >> maze[i];
    }    

    deque<pnt> dq;
    dq.push_front(s);

    int visit[h][w];
    FILL0(visit);

    while(!dq.empty())
    {
        while(visit[dq.front().y][dq.front().x]!=0)
        {
            dq.pop_front();
        }
        pnt c = dq.front();
        dq.pop_front();

        visit[c.y][c.x]=1;
            
        if(c.y == g.y && c.x == g.x)
        {
            cout << c.warp << endl;                
            return 0;
        }

        for(int dy = -2; dy<=2; dy++)
        {
            for(int dx = -2; dx<=2; dx++)
            {
                if(dx==0 && dy==0)
                {
                    continue;
                }

                pnt next;
                next.y = c.y+dy;
                next.x = c.x+dx;
                next.warp = c.warp;

                if( next.y>-1 && next.x > -1 && next.y<h && next.x<w && visit[next.y][next.x]==0 && maze[next.y][next.x]=='.')
                {
                    if((( dy==0 && abs(dx)==1) || ( dx==0 && abs(dy)==1) ))
                    {
                        dq.push_front(next);
                    }
                    else
                    {
                        next.warp++;
                        dq.push_back(next);
                    }
                    
                }
            }
        }
    }

    cout <<  -1 << endl;

    return 0;

}


Measured memory_bytes: 9256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;


int main()
{
	ll n,m, cost=0;
	cin>>n>>m;
	vii q;

//	map<int, int> q;
	// map<int, int> q::iterator it;
	// for(int i = 0 ;i < n; i++){int a,b; cin>>a>>b; q.insert(make_pair(a,b));}
	for(ll i = 0 ; i < n ; i ++)
	{
		ll a,b;
		cin>>a>>b;
		q.push_back(make_pair(a,b));
	}
	sort(q.begin(), q.end());

	for(auto& x: q)
	{
		if(x.second<m)
		{
			cost+=(ll)x.second*x.first;
			m-=x.second;
		}
		else
		{
			cost+=x.first*m;
			break;
		}
	}
	cout<<cost<<endl;
	return 0;
}

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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    vector<int> ans;
    while(true){
        int res = 0;
        int N; cin >> N;
        if(N == 0) break;
        int W, H; cin >> W >> H;
        vector<vector<int>> A(W);
        rep(i, W) A[i].resize(H, 0);
        rep(i, N){
            int x, y; cin >> x >> y; x--; y--;
            A[x][y]++;
        }
        int S, T;  cin >> S >> T;
        for(int i = 0; i <= W-S; i++){
            for(int j = 0; j <= H-T; j++){
                int acc = 0;
                rep(k, S){
                    rep(l, T){
                        acc += A[i+k][j+l];
                    }
                }
                res = max(res, acc);
            }
        }
        ans.push_back(res);
    }
    rep(i, ans.size()) cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 3096
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <iostream>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <chrono>
#include <random>
#include <time.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define tii tuple<int,int,int>
#define pq priority_queue<ll>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
string stin(){string s;cin>>s;return s;}
int main(){
    string s=stin();
    int k=in();
    ll n=s.length();
    char c=s[0];
    bool bl=true;
    rep(i,n){
        if(s[i]!=c)bl=false;
    }
    ll ans=0;
    if(bl){
        ans=n*k/2;
    }else{
        ll X=0,Y=0,A=0,B=0;
        ll l=0,r=n-1;
        rep(i,n){
            if(s[i]==s[0])X++;
            else{
                l=i;
                break;
            }
        }
        rep3(i,n-1,0){
            if(s[i]==s[0])Y++;
            else{
                r=i;
                break;
            }
        }
        A=X+Y;
        int cnt=1;
        rep2(i,l,r){
            if(s[i]==s[i+1]){
                cnt++;
            }else{
                B+=cnt/2;
                cnt=1;
            }
        }
        ans=X/2+Y/2+A/2*(k-1)+B*k;
    }
    cout<<ans<<endl;
}




Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

func main() {
	var s, t string
	count := 0
	fmt.Scan(&s)
	fmt.Scan(&t)

	splitS := strings.Split(s, "")
	splitT := strings.Split(t, "")

	for index, value := range splitS {
		if value == splitT[index] {
			count++
		}
	}

	fmt.Println(count)
}


Measured memory_bytes: 640
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Bismillahirrahmanirrahim

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long int lo;
typedef pair< lo,lo > PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(lo i=1;i<=n;i++)
#define mid (start+end)/2
#define ort (bas+son)/2

const lo MAX = -1000000000000000000; 
const lo MIN = 1000000000000000000; 
const lo inf = 1000000000; 
const lo KOK = 100000; 
const lo LOG = 30; 
const lo li = 100005; 
const lo mod = 1000000007; 

lo n,m,cev,b,a[li],k;
string s;
vector<lo> v;
PII p[10];

inline lo solve(){
	n=5;
	FOR{
		scanf("%lld",&p[i].se);
		if(p[i].se%10==0)
			p[i].fi=p[i].se%10;
		else p[i].fi=10-p[i].se%10;
	}
	sort(p+1,p+5+1);
	FOR{
		cev+=p[i].se;
		if(cev%10!=0 && i!=5){
			cev+=10-(cev%10);
		}
	}
	printf("%lld\n",cev);
	return 0;
}

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


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


int main(){
    int N;
    string S;

    cin >> N;
    cin >> S;

    bool answer = true;
    if(N%2 == 1){
        cout << "No";
        return 0;
    }

    for(int i=0; i<N/2; i++){
        if(S[i] != S[i+N/2]){
            answer = false;
            break;
        }
    }

    if(answer){
        cout << "Yes";
    }
    else{
        cout <<"No";
    }

    return 0;
}

Measured memory_bytes: 256
import numpy as np
import math

n, m = map(int, input().split())
probability = [0 for _ in range(n)]
ball = [1 for _ in range(n)]
probability[0] = 1
for i in range(m):
    x, y = map(int, input().split())
    prob = math.ceil(probability[x-1])
    probability[x-1] = prob * (ball[x-1] - 1) / ball[x-1]
    probability[y-1] += prob / ball[x-1]
    ball[x-1] -= 1
    ball[y-1] += 1
print(np.sum(np.array(probability) > 0))


Measured memory_bytes: 17060
#include<iostream>

using namespace std;

int main(){
		long long  n,a,b,c,d;
		cin>>n>>a>>b>>c>>d;
		for(int i=0;i<n;i++){
			if(a+i*d-(n-1-i)*c>=b && a+i*c-(n-1-i)*d<=b){cout<<"YES"<<endl;return 0;}
		}
		cout<<"NO"<<endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            int strLength = str.Length;

            int target;
            int favorite = 753;
            int min = int.MaxValue;
            int value;

            for(int i = 0; i < strLength - 2; i++)
            {
                target = 0;

                int target100 = int.Parse(str.Substring(i, 1));
                int target10 = int.Parse(str.Substring(i + 1, 1));
                int target1 = int.Parse(str.Substring(i + 2, 1));

                target = target100 * 100 + target10 * 10 + target1;

                value = Math.Abs(target - favorite);
                if (value < min)
                {
                    min = value;
                }
            }

            Console.Write(min);
        }
    }
}

Measured memory_bytes: 13268
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<sstream>
#include<vector>
#include<ctime>
#include<unordered_map>
using namespace std;
typedef long long ll;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
const int inf=0x3f3f3f3f;
int main()
{
	IOS;
	int a,b;
	cin>>a>>b;
	if(a/b==0) cout<<1<<endl;
	else if(a%b==0) cout<<a/b<<endl;
	else cout<<(a/b)+1<<endl;
	return 0;
}


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

int main(){
    string n;
    cin >> n;
    for(int i=0; i<3; i++){
        if(n.at(i)=='1') n.at(i)='9';
        else if(n.at(i)=='9') n.at(i)='1';
    }
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;

const int inf=2147483647;

int n,m,a,b;
long long c[111111],x[111111];
long long ans=1e18;

int main()
{
	scanf("%d%d",&n,&m);
	scanf("%d",&a);
	
	for (int i=2; i<=n; i++)
	{
		scanf("%d",&b);
		if (a<b)
		{
			c[1]+=b-a;
			c[a+1]-=b-a;
			c[b+1]+=b-a;
			c[a+1]+=b+1;
			c[b+1]-=b+1;
			x[a+1]--;
			x[b+1]++;
		}
		else
		{
			c[b+1]+=m-a+b;
			c[a+1]-=m-a+b;
			c[a+1]+=b+1+m;
			c[1]+=b+1;
			c[b+1]-=b+1;
			x[1]--;
			x[a+1]--;
			x[b+1]++;
		}
		a=b;
	}
	
	for (int i=1; i<=m; i++) 
	{
		c[i]+=c[i-1];
		x[i]+=x[i-1];
		
		ans=min(ans,c[i]+x[i]*i);
	}
	
	printf("%lld\n",ans);
	
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0, lim##__LINE__ = n; i < lim##__LINE__; ++i)
using C = std::complex<double>;
const double EPS = 1e-10;

// CGL_1_A
C projection(C p, C p1, C p2) {
    return C(((p-p1) / (p2-p1)).real(), 0.0) * (p2-p1) + p1;
}

void solve_CGL_1_A() {
    int x1, y1, x2, y2;
    std::cin >> x1 >> y1 >> x2 >> y2;
    C p1(x1,y1), p2(x2,y2);
    int q;
    std::cin >> q;
    rep(i,q) {
        int x, y;
        std::cin >> x >> y;
        C p = C(x,y);
        C res = projection(p, p1, p2);
        printf("%.20lf %.20lf\n", res.real(), res.imag());
    }
}

// CGL_1_B
C reflection(C p, C p1, C p2) {
    return std::conj(((p-p1) / (p2-p1))) * (p2-p1) + p1;
}

void solve_CGL_1_B() {
    int x1, y1, x2, y2;
    std::cin >> x1 >> y1 >> x2 >> y2;
    C p1(x1,y1), p2(x2,y2);
    int q;
    std::cin >> q;
    rep(i,q) {
        int x, y;
        std::cin >> x >> y;
        C p = C(x,y);
        C res = reflection(p, p1, p2);
        printf("%.20lf %.20lf\n", res.real(), res.imag());
    }
}

// CGL_1_C
// p0->p1 and p0->p2, query is p2
int counter_clockwise(C p0, C p1, C p2) {
    C a = std::conj(p1-p0) * (p2-p0);
    if (a.imag() >  EPS) { return +1; } // counter clockwise
    if (a.imag() < -EPS) { return -1; } // clockwise
    if (a.real() < -EPS) { return +2; } // p2-p0-p1
    if (std::norm(p1-p0) < std::norm(p2-p0)) { return -2; } // p0-p1-p2
    return 0; // p0-p2-p1
}

void solve_CGL_1_C() {
    int x1, y1, x2, y2;
    std::cin >> x1 >> y1 >> x2 >> y2;
    C p0(x1,y1), p1(x2,y2);
    int q;
    std::cin >> q;
    rep(i,q) {
        int x, y;
        std::cin >> x >> y;
        C p2 = C(x,y);
        int res = counter_clockwise(p0, p1, p2);
        if (res == 1) {
            printf("COUNTER_CLOCKWISE\n");
        }
        if (res == -1) {
            printf("CLOCKWISE\n");
        }
        if (res == 2) {
            printf("ONLINE_BACK\n");
        }
        if (res == -2) {
            printf("ONLINE_FRONT\n");
        }
        if (res == 0) {
            printf("ON_SEGMENT\n");
        }
    }
}

int main() {
    solve_CGL_1_C();
}



Measured memory_bytes: 3144
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <map>
#include <vector>
#include <cmath>
using namespace std;

string str;
int x, y, xx, yy;
vector<int> v[2];
int dp[4001][16001];

int func(int i, int idx, int val, int goal) {
	if (idx == v[i].size() && val == goal) return 1;
	else if (idx == v[i].size()) return 0;

	int& ret = dp[idx][val + 8000];
	if (ret != -1) return ret;
	ret = 0;
	ret += func(i, idx + 1, val + v[i][idx], goal);
	if (ret) return ret;
	ret += func(i, idx + 1, val - v[i][idx], goal);
	return ret;
}

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

	cin >> str;
	cin >> xx >> yy;
	bool start = 0;
	int dir = 0, cnt = 0;
	for (int i = 0; i < str.length(); ++i) {
		if (start == 1 && (str[i] == 'T' || i == str.length()-1)) {
			if (str[i] == 'F') cnt++;
			v[dir % 2].push_back(cnt);
			dir++; cnt = 0;
		}
		else if (start) cnt++;

		if (start == 0 && str[i] == 'F') x++;
		else if (start == 0 && str[i] == 'T') start = 1, cnt = 0;
	}

	xx = abs(x - xx);
	yy = abs(y - yy);

	memset(dp, -1, sizeof(dp));
	if (func(1, 0, 0, xx)) {
		memset(dp, -1, sizeof(dp));
		if (func(0, 0, 0, yy)) {
			cout << "Yes";
		}
		else cout << "No";
	}
	else {
		cout << "No";
	}
	return 0;
}

Measured memory_bytes: 250752
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int ans = 0;
    int n,m; cin >> n >> m;
    vector<pair <int , int>> ab;
    pair<int, int> tmp;

    for(int i=0;i<n;i++){
    	cin >> tmp.first >> tmp.second;
    	ab.push_back(tmp);
    }

    sort(ab.begin(),ab.end());
    int day = 0;
    priority_queue<int> q;
    for(int i=1; i<=m;i++){
    	while(day<n && ab[day].first == i){
    		q.push(ab[day].second);
    		day++;
    	}
    	if(q.size() > 0){
    		ans +=q.top();
    		q.pop();
    	}
    }

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

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

// 恒等置換
vector<int> identity(int n) {
  vector<int> result;
  for(int i = 0; i < n; ++i) result.push_back(i);
  return result;
}

// 合体: lhs の後に rhs を辿った結果を返す
vector<int> join(const vector<int>& lhs, const vector<int>& rhs) {
  const int N = lhs.size();
  vector<int> result(N);
  for(int i = 0; i < N; ++i) result[i] = lhs[rhs[i]];
  return result;
}

// 累乗
vector<int> power(const vector<int>& order, int n) {
  if(!n) return identity(order.size());
  if(n & 1) return join(order, power(order, n - 1));
  return power(join(order, order), n >> 1);
}

// 構文解析
vector<int> parse(const unordered_map<char, vector<int>>& part, const string& expression, int& i);
vector<int> term(const unordered_map<char, vector<int>>& part, const string& expression, int& i);
int number(const string& expression, int& i);

vector<int> parse(const unordered_map<char, vector<int>>& part, const string& expression, int& i) {
  vector<int> result = term(part, expression, i);
  while(expression[i] == '+') {
    ++i;
    result = join(result, term(part, expression, i));
  }
  return result;
}
vector<int> term(const unordered_map<char, vector<int>>& part, const string& expression, int& i) {
  vector<int> result;
  if(expression[i] == '(') {
    ++i;
    result = parse(part, expression, i);
    ++i;
  } else if(isdigit(expression[i])) {
    int left = number(expression, i);
    auto right = term(part, expression, i);
    result = power(right, left);
  } else {
    result = part.at(expression[i]);
    ++i;
  }
  return result;
}
int number(const string& expression, int& i) {
  int result = 0;
  while(isdigit(expression[i])) {
    result *= 10;
    result += expression[i] - '0';
    ++i;
  }
  return result;
}

// メイン
int main() {
  int N, K;
  cin >> N >> K;

  unordered_map<char, vector<int>> part;
  for(int k = 0; k < K; ++k) {
    char p; int h;
    cin >> p >> h;
    vector<int> order = identity(N);
    for(int i = 0; i < h - 1; ++i) for(int j = 0; j < N - 1; ++j) {
      int g;
      cin >> g;
      if(g) swap(order[j], order[j + 1]);
    }
    part[p] = order;
  }

  int E;
  cin >> E;
  for(int e = 0; e < E; ++e) {
    string expression;
    cin >> expression;
    int t = 0;
    auto answer = parse(part, expression, t);
    for(int i = 0; i < N; ++i) {
      if(i) cout << " ";
      cout << answer[i] + 1;
    }
    cout << endl;
  }
}

Measured memory_bytes: 1276
#include <bits/stdc++.h> 
using namespace std;
const long INF=1000000000000000;
const long MOD=1000000007;

long dis(long a,long b,long c){
    return max(a,max(b,c))-min(a,min(b,c));
}

int main() {
    long H,W;
    cin>>H>>W;
    
    if(H%3==0 || W%3==0){
        cout<<0<<endl;
        return 0;
    }
    
    
    long ans=INF;
    for(int h=0;h<H;h++){
        ans=min(ans,dis(h*W,(H-h)*(W/2),(H-h)*(W-W/2)));
    }
    for(int w=0;w<W;w++){
        ans=min(ans,dis(H*w,(H/2)*(W-w),(H-H/2)*(W-w)));
    }
    ans=min(ans,min(H,W));
    
    cout<<ans<<endl;
}


Measured memory_bytes: 256
while 1:
    n, m, p = map(int, input().split())
    if n == 0:
        break

    vote = []
    for _ in range(n):
        vote.append(int(input()))

    total = sum(vote) * 100 * (100 - p) // 100
    if vote[m-1] == 0:
        print(0)
    else:
        print(total // vote[m-1])


Measured memory_bytes: 5612
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int c = sc.nextInt();
    int[]b = new int[m];
    int[][]a = new int[n][m];
    
    int cou = 0;
    for(int i=0; i<m; i++) {
    	b[i] = sc.nextInt();
    }
    for(int i=0; i<n; i++) {
    for(int j=0; j<m; j++) {
    	a[i][j] = sc.nextInt();
    }
    }
    int ans = 0;
    for(int i=0; i<n; i++) {
    	int all = 0;
    	for(int j=0; j<m; j++) {
      			all += a[i][j]*b[j];
    	}
    	
    	if(all+c > 0) {
   			ans++;
   	    	}
    }
    	System.out.println(ans);
    }
}



Measured memory_bytes: 36968
#include <bits/stdc++.h>
using namespace std;
#define rep(a, b) for (a = 0; a < b; a++)


int main(){
  
  int N, M, i;
  cin >> N >> M;
  
  if (N <= M) {
    
    rep(i, M) cout << N;
    return 0;

  } else {
    
    rep(i, N) cout << M;
    return 0;
  }
  
}

Measured memory_bytes: 256
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;

int main(){
  int n,q;
  scanf("%d%d", &n,&q);
  
  ll c,x,y;
  fenwick_tree<ll> fw(n);
  
  rep(i,n){
    scanf("%ld", &x);
    fw.add(i,x);
  }
  
  rep(i,q){
    scanf("%ld%ld%ld", &c,&x,&y);
    if(c==0) fw.add(x,y);
    else printf("%ld\n",fw.sum(x,y));
  }
   
  return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define FOR(NAME, START, NUM) for (int NAME = START; NAME < (NUM); NAME++)
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); NAME++)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; NAME--)
#define ALL(NAME) (NAME).begin(), (NAME).end()
const ll INF =1000000000000000;

int main(){
  int n,q,num;
  cin >> n >> q;
  string s;
  cin >> s;
  vector<int> a(n);
  num = 0;
  
  REP(i,n-1){
    if(s.at(i) == 'A' && s.at(i+1) == 'C'){
      num++;
    }
    a.at(i+1) = num;
  }
  
  int l,r;
  REP(i,q){
    cin >> l >> r;
    cout << a.at(r-1)-a.at(l-1) << endl;
  }
}

Measured memory_bytes: 1408
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;

public class Main {

	static PrintWriter out;
	static InputReader ir;

	static void solve() {
		out.println((int)Math.pow(ir.nextInt(), 2)-ir.nextInt());
	}

	public static void main(String[] args) throws Exception {
		ir = new InputReader(System.in);
		out = new PrintWriter(System.out);
		solve();
		out.flush();
	}

	static class InputReader {

		private InputStream in;
		private byte[] buffer = new byte[1024];
		private int curbuf;
		private int lenbuf;

		public InputReader(InputStream in) {
			this.in = in;
			this.curbuf = this.lenbuf = 0;
		}

		public boolean hasNextByte() {
			if (curbuf >= lenbuf) {
				curbuf = 0;
				try {
					lenbuf = in.read(buffer);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return false;
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[curbuf++];
			else
				return -1;
		}

		private boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		private void skip() {
			while (hasNextByte() && isSpaceChar(buffer[curbuf]))
				curbuf++;
		}

		public boolean hasNext() {
			skip();
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (!isSpaceChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public int nextInt() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public char[][] nextCharMap(int n, int m) {
			char[][] map = new char[n][m];
			for (int i = 0; i < n; i++)
				map[i] = next().toCharArray();
			return map;
		}
	}
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    ll n,z,w;
    cin >> n >> z >> w;
    Vi a(n);
    rp(i,n) cin >> a.at(i);
    if(n==1){
        print(abs(w-a[n-1]));
        return;
    }
    if(abs(w-a[n-1])>abs(a[n-2]-a[n-1])){
        print(abs(w-a[n-1]));
    }else{
        print(abs(a[n-2]-a[n-1]));
    }
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
int main()
{
    char S[10];
    int ans(0);
    cin >> S;
    for (int i = 0; i < 4; i++)
    {
        if (S[i] == '+')
            ans++;
        else
        {
            ans--;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
a = list(str(input()) for _ in range(N))
b = list(str(input()) for _ in range(M))

import sys
c = N-M + 1

for a_j in range(c):
    for start_a in range(c):
        for a_i, b_i in zip(range(start_a, start_a+M), range(M)):
            if a[a_i][a_j:a_j+M] == b[b_i]:
                is_match = True
            else:
                is_match = False
                break
        if is_match:
            print("Yes")
            sys.exit()

print("No")

Measured memory_bytes: 3064
#include<stdio.h>
int min(int x,int y){
  if(x>=y)return y;
  else return x;
}
int main(void){
  int a,b,k;
  scanf("%d%d%d",&a,&b,&k);
  int c=0;
  for(int i=min(a,b);i>=1;i--){
	if(a%i==0&&b%i==0)c++;
    if(c==k){printf("%d",i);
             return 0;
            }
  }
  return 0;
}

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

int main() {
  int a,b,c,d;
  cin >> a >> b>>c>>d;
  if(a+b==c+d){
  cout << "Balanced" <<endl;
   
  }
  else if(a+b>c+d){
  cout << "Left" <<endl;
  }
  else{
  cout << "Right" <<endl;
  }
  
}

Measured memory_bytes: 256
import sys
from itertools import accumulate

def main():
    input = sys.stdin.readline
    N = int(input())
    T = list(map(int, input().split()))
    V_limit = list(map(int, input().split()))

    V = []
    for i in range(N):
        V += [V_limit[i] for _ in range(2 * T[i])]

    for i in range(len(V)-1):
        V[i] = min(V[i], V[i+1])

    V = [0] + V
    V[-1] = 0

    for i in range(len(V)-1):
        V[i+1] = min(V[i] + 0.5, V[i+1])

    for i in range(len(V)-1, 0, -1):
        V[i-1] = min(V[i] + 0.5, V[i-1])

    ans = 0
    for i in range(len(V)-1):
        ans += 0.25 * (V[i] + V[i+1])
    
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define PI 3.14159265359

int main() {
    ll n ,m, hoge, sum=0;
    cin >> n >> m;
    for(int i=0;i<m;i++){
        cin >> hoge;
        sum += hoge;
    }
    hoge = n - sum;
    if(hoge < 0) cout << -1 << endl;
    else cout << hoge << endl;
    return 0;
}

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

typedef long long ll;

int main(){
  ll n;
  cin >> n;
  ll ans = 0;
  for(ll i = 1; i <= n; i++){
    ans += n/i*(2*i+(n/i-1)*i)/2;
  }
  cout << ans << endl;
  return 0;
}

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

bool areRotations(string s1, string s2)
{
	int length1 = s1.length();
	int length2 = s2.length();
	string s3 = s1+s1;
	if (s3.find(s2) != std::string::npos){
		return true;
	}
	else{
		return false;
	}

}
int main()
{
    string s1, s2;
	cin>>s1>>s2;
	if (areRotations(s1,s2))
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
}



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

int countpow(int a){
  int c = 0;
  while (!(a & 1)){
    c++;
    a = a >> 1;
  }
  
  return c;
}

int main(int argc, char const* argv[])
{
  int n;
  cin >> n;
  
  int ne=0, t;
  for (int i=0; i<n; i++){
    cin >> t;
	if (t % 2 == 0){
      ne += countpow(t);
    }
  }
  
  cout << ne << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int num1 = scanner.nextInt();
		int num2 = num1/3600;
		int num3 = num1%3600/60;
		int num4 = num1%60;
		System.out.println(String.format("%s:%s:%s", num2,num3,num4));
	}
}

Measured memory_bytes: 17312
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

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

    int h, w, k;
    cin >> h >> w >> k;
    vector<string> s(h);
    for(int i = 0; i < h; ++i)  cin >> s[i];
    int sx = -1, sy = -1;
    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            if(s[i][j] == 'S'){
                sx = i, sy = j;
                break;
            }
        }
        if(sx != -1)    break;
    }

    vector<vector<int>> dist(h, vector<int>(w, INF));
    dist[sx][sy] = 0;
    queue<P> que;
    que.push(P(sx, sy));
    while(!que.empty()){
        P p = que.front();
        que.pop();
        int x = p.first, y = p.second;
        for(int i = 0; i < 4; ++i){
            int nx = x + dx[i], ny = y + dy[i];
            if(nx < 0 || nx >= h || ny < 0 || ny >= w)  continue;
            if(s[nx][ny] == '#')    continue;
            if(dist[nx][ny] > dist[x][y] + 1){
                dist[nx][ny] = dist[x][y] + 1;
                que.push(P(nx, ny));
            }
        }
    }

    int ans = INF;
    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            if(dist[i][j] > k)  continue;
            int cost = 1;
            int d = min({i, h - i - 1, j, w - j - 1});
            cost += d / k;
            if(d % k != 0)  ++cost;
            chmin(ans, cost);
        }
    }
    cout << ans << endl;
}

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

// 素数判定
// 計算量O(√n)
template<class T>
bool isPrime(T n){
    if(n < 2) return false;
    for(long long i = 2; i*i <= n; ++i) if(n % i == 0) return false;
    return true;
}

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

    int n; cin >> n;
    ll k = 5;
    vector<ll> ans;
    ans.push_back(2);
    rep(i,n-1){
        while(!isPrime(2*k+1)) k += 5;
        ans.push_back(2*k+1);
        k += 5;
    }
    rep(i,n){
        cout << ans[i];
        if(i != n-1) cout << " ";
    }
    cout << "\n";
}

Measured memory_bytes: 3652
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void){
	int n,x,y;
	int f;
	int min;
	scanf("%d %d %d",&n,&x,&y);
	int ans[n];
	for(int i=0; i<n; i++){
		ans[i]=0;
	}
	for(int i=1; i<n; i++){
		for(int j=i+1; j<=n; j++){
			min = fmin(abs(i-x)+abs(y-j)+1,j-i);
			ans[min]++;
		}
	}
	for(int i=1; i<n; i++){	
		printf("%d\n",ans[i]);
	}
	return 0;	
}


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

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

    int n;
    cin >> n;
    if (n % 2 == 0)
        cout << n << '\n';
    else
        cout << 2 * n << '\n';
    return 0;
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    int n, k;
    cin >> n >> k;
    if (k % 2 == 1)
        OP((ll)pow(int(n / k), 3));
    else
    {
        int cnt = 0;
        for (int i = 1; i <= n; i++)
        {
            if (i % k == k / 2)
                cnt++;
        }
        OP((ll)pow(cnt, 3) + (ll)pow(int(n / k), 3));
    }
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define swap(a, b, type) { type _tmp = a; a = b; b = _tmp; }
typedef long long ll;
typedef unsigned long long ull;

int a[100000];

int main()
{
	int N, b = 1, ans = -1, cnt = 0;

	cin >> N;
	rep(i, N) cin >> a[i];

	rep(i, N) {
		cnt++;

		if (a[b - 1] == 2) {
			ans = cnt;
			break;
		}

		b = a[b - 1];
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 640