akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int calc(char x, char y, char z)
{
  return (x-'0')*100 + (y-'0')*10 + z-'0';
}


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

  int min = INT_MAX;
  for (size_t i = 0; i < s.size()-2; i++)
  {
    int num = calc(s.at(i), s.at(i+1), s.at(i+2));
    int tmp = abs(753 - num);
    if (tmp < min) min = tmp;
  }
  
  cout << min << endl;
  return 0;
}


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


int main(){
	
	
	int x,y,z;
	int n;
	cin >> n;
	int count = 0;
	cin >> x;
	cin >> y;
	int large = 0;
	if(y>=x) large = 1;
	int large_ = 0;
	for(int i=2;i<n;i++){
	cin >> z;
	large_ = int(z>=y);
	if((large==1 && large_==1) || (large==0 && large_==0) ) count+=1;
	//cout <<large << large_ << endl;
	large = large_;
	
	x = y;
	y = z;
	}
	cout << count << endl;
	return 0;
}


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

main(){
  double a, s;
  while( cin >> a ){
    s = a;
    for ( int i = 2; i <= 10; i++ ){
      if ( i % 2 == 0 ) a *= 2;
      else a /= 3;
      s += a;
    } 
    printf("%.8f\n", s);
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(20);
    int n;
    cin >> n;
    vector<int> v(n+2);
    for (int i=1; i <= n; i++) cin >> v[i];
    v[n+1] = 0;
    int cost = 0;
    for (int i=1; i < n+2; i++){
        cost += abs(v[i-1] - v[i]);
    }
    for (int i=1; i < n+1; i++){
        int oc = abs(v[i-1] - v[i]) + abs(v[i] - v[i+1]);
        int nv = abs(v[i-1] - v[i+1]);
        int wn = oc - nv;
        cout << cost-wn << endl;
    }
    return 0;
}


Measured memory_bytes: 2048
//#define _GLIBCXX_DEBUG

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,-1,0,0,1,1,-1,-1};
vector<ll>dy={0,0,1,-1,1,-1,1,-1};
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...));
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll a;cin>>a;
  cout<<a+a*a+a*a*a<<endl;
  return 0;
}

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

#define lli long long int
#define endl "\n"
#define debug(n) cout<<n<<endl
#define debug2(a, b) cout<<a<<" "<<b<<endl;
#define forn(i, in, fin) for(int i = in; i<fin; i++)
#define all(v) v.begin(), v.end()
#define fastIO(); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;

const lli MOD = 1e9 + 7;

int main()
{
    fastIO();
    lli n, k;  cin>>n>>k;
    vector<lli> candies(n);
    vector<lli> prefix(100010);
    for(auto &x: candies)
    {
        cin>>x;
    }
    vector<vector<lli>> dp(n+1, vector<lli>(k+1, 0));

    
    for(int i = 0; i<=min(k, candies[0]); i++)
    {
        dp[0][i] = 1;
    }
    for(int i = 1; i<n; i++)
    {
        fill(all(prefix), 0);
        prefix[0] = dp[i-1][0];
        for(int l = 1; l<=k; l++ )
        {
            prefix[l] = prefix[l-1] + dp[i-1][l];
        }
        for(lli j = k ; j>=0; j--)
        {
            lli minimo = min(j, candies[i]);   
            dp[i][j] = (prefix[j] -  (j-minimo-1 >= 0? prefix[j-minimo-1]: 0))%MOD ;
        }
    }

    cout<<dp[n-1][k]<<endl;
    

    return 0;
}

Measured memory_bytes: 81024
#include<iostream>
#include<string>

using namespace std;

int main() {
	int n, w[300000], e[300000], ans = 999999;
	string s;

	cin >> n >> s;

	for (int i = 0; i < n - 1; i++) {
		if (s[i] == 'W') {
			w[i + 1] = w[i] + 1;
		}
		else {
			w[i + 1] = w[i];
		}
	}
	for (int i = n - 1; i > 0; i--) {
		if (s[i] == 'E') {
			e[i - 1] = e[i] + 1;
		}
		else {
			e[i - 1] = e[i];
		}
	}
	for (int i = 0; i < n; i++) {
		if (ans > w[i] + e[i]) {
			ans = w[i] + e[i];
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3076
D, G = map(int, input().split())
p = []
c = []
cscore = []
ans = []

#各得点帯の問題を完答したときの点数をcscoreに入れる
for i in range(D):
    pi, ci = map(int, input().split())
    p.append(pi)
    c.append(ci)
    score = pi * (i+1) * 100 + ci
    cscore.append(score)

#各得点帯を完答する組み合わせ全パターン試してその総得点をtotscoreに入れる
totscore = []
for i in range(1 << len(cscore)):
    output = []
    for j in range(len(cscore)):
        if ((i >> j) & 1) == 1:
            output.append(cscore[j])
    tot = 0
    for i in range(len(output)):
        tot += output[i]
    totscore.append(tot)
#totscoreの各場合においてそれぞれ解くべき問題数を計算
for i in range(len(totscore)):
    problems = 0
    b = format(i, "b").zfill(D)

    #完答のみで目標得点を超えている場合はその問題数を計算
    if totscore[i] >= G:
        for k in range(D):
            problems += p[k] * int(b[D-1-k])
        ans.append(problems)

    #完答のみで目標得点を超えていない場合は得点の高い方から問題を1問ずつ解いていく
    else:
        remainscore = G - totscore[i]
        for k in range(D):
            problems += p[k] * int(b[D-1-k])
        for l in range(D, 0, -1):
            if int(b[D-l]) == 0:
                for m in range(p[l-1]):
                    if remainscore > 0:
                        remainscore -= l * 100
                        problems += 1
        #点数がGに届いてない場合はカット
        if remainscore <= 0:
            ans.append(problems)

#条件を満たしたもののうち最小値を出力
print(min(ans))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
	int n,k;
	cin>>n>>k;
	ll h[n],dp[n];
	for(int i=0;i<n;i++)
	{
		cin>>h[i];
		dp[i]=0;
	}
	dp[0]=0;
	dp[1]=abs(h[1]-h[0]);
	for(int i=2;i<n;i++)
	{
		dp[i]=1001001001;
		for(int j=1;j<=min(i,k);j++)
		{
			dp[i]=min(dp[i],abs(h[i]-h[i-j])+dp[i-j]);
		}
	}
	/*for(int i=0;i<n;i++)
	cout<<dp[i]<<" ";
	cout<<endl;*/
	cout<<dp[n-1]<<"\n";
}

Measured memory_bytes: 1792
#include<iostream>
#include<cmath>
using namespace std;
int main(){
    int N;
    int a[100];
    int ave,ans = 0;
    double sum = 0.0;
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> a[i];
        sum += a[i];
    }
    ave = round(sum/N);
    for(int i=0;i<N;i++) ans += (a[i]-ave)*(a[i]-ave);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
 
int main() {
    int n;
    while (1) {
       cin >> n;
       if(n==0) return 0;
        unordered_map<string, int>mp;
        string s; int Max = 0;
        int d = 0;
        for (int i = 1; i <= n; i++) {
            string c; cin >> c;
            mp[c]++;
            if (mp[c] > Max) { s = c; Max = mp[c]; }
            int sec = 0;
            for (auto&& p : mp) {
                if (p.first != s&&sec < p.second) sec = p.second;
            }
            if (sec + n - i < Max && !d)d = i;
        }
        if (!d)puts("TIE");
        else cout << s << ' ' << d << endl;
    }
}

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

using namespace std;

const int INF = 1000000005;
const int MAX_N = 200005;

int a[MAX_N], ans[MAX_N];
vector<int> G[MAX_N];

void dfs(int u, int p, vector<int>& dp){
    int pos = lower_bound(dp.begin(), dp.end(), a[u]) - dp.begin();
    int pre_val = dp[pos];
    dp[pos] = a[u];
    ans[u] = lower_bound(dp.begin(), dp.end(), INF) - dp.begin();
    for(int v : G[u]){
        if(v != p){
            dfs(v, u, dp);
        }
    }
    dp[pos] = pre_val;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    int u, v;
    for(int i = 0; i < n - 1; ++i){
        cin >> u >> v;
        --u, --v;
        G[u].push_back(v), G[v].push_back(u);
    }
    vector<int> dp(n, INF);
    dfs(0, -1, dp);
    for(int i = 0; i < n; ++i){
        cout << ans[i] << "\n";
    }
}

Measured memory_bytes: 30904
#include <iostream>
using namespace std;
int main()
{
	int a[13] = {0,1,2,1,3,1,3,1,1,3,1,3,1};
	int c1,c2;
	cin >> c1 >> c2;
	if(a[c1] == a[c2])
		{
			cout << "Yes" << endl;
			return 0;
		}
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
//Robs Code
/***********HEADER***************/
#include <iostream>
#include <bitset>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <set>
#include <queue>
#include <map>
/***********MACROS***************/
#define int long long int
#define fri(l,k) for (i=l;i<=k;i++)
#define frj(l,k) for (j=l;j>=k;j--)
#define fij(a,b,l,k) for(i=a;i<=b;i++) for(j=l;j<=k;j++)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define endl "\n"
#define pb push_back
#define _1 first
#define _2 second
#define mxsz 1000000007
#define mxval 1e9 + 7
#define grt [](auto x,auto y){return x>y;}
#define pii pair<int,int>
/*********VARIABLE****************/
using namespace std;
int i,j,n,m,k,l,q,t,a,b,sum[3],tot[3],cnt[3];
/*********FUNCTIONS**************/
int powom(int a,int b) {
    int result = 1;
    while (b > 0) {
        if (b & 1)
            result = result * a;
        a = a * a;
        b >>= 1;
    }
    return result;
}
/***********MAIN**************/
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	cin>>n;
	vector<int> v(n);
	for(int i=0;i<n;i++){
		cin>>v[i];
	}
	sort(all(v));
	cout<<(v[n/2]-v[n/2-1]);
	return 0;
}
//.........

Measured memory_bytes: 1024
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
int n,a[1000005],ans;
char s[1000005];
int C(int n,int m){return (n&m)==m;}
int main()
{
	scanf("%d",&n);
	scanf("%s",s+1);
	if(n==1) printf("%c",s[1]);
	else
	{
		n--;
		for(int i=1;i<=n;i++) a[i]=abs(s[i]-s[i+1]);
		int flag1=0;
		for(int i=1;i<=n;i++) if(a[i]==1) flag1=1;
		if(!flag1) for(int i=1;i<=n;i++) a[i]/=2;
		flag1^=1;
		for(int i=1;i<=n;i++) ans^=C(n-1,i-1)*(a[i]&1);
		printf("%d\n",ans<<flag1);
	}
}

Measured memory_bytes: 8596
N = int(input())
p = list(map(float, input().split()))

dp = [[0.0] * (N + 1) for _ in range(N + 1)]
dp[1][0] = 1 - p[0]
dp[1][1] = p[0]
for i in range(2, N + 1):
    for j in range(N + 1):
        if j == 0:
            dp[i][j] = dp[i - 1][j] * (1 - p[i - 1])
        else:
            dp[i][j] = dp[i - 1][j] * (1 - p[i - 1]) + dp[i - 1][j - 1] * p[i - 1]
M = N // 2 + 1
ans = 0
for i in range(M, N + 1):
    ans += dp[-1][i]
print(ans)

Measured memory_bytes: 135036
n=int(input())

#xの約数を列挙する
def divisor(x):
    ans=set([])
    i=1
    while(i*i<=x):
        if(x%i==0):
            ans.add(i)
            ans.add(x//i)
        i+=1
    ans=sorted(list(ans))
    return ans

div_n=divisor(n)[1:]
#print(div_n)

prime_n=[]
isprime=[True for _ in range(len(div_n))]
for i in range(len(div_n)):
    if(isprime[i]):
        for j in range(i+1,len(div_n)):
            if(div_n[j]%div_n[i]==0):
                isprime[j]=False
        prime_n.append(div_n[i])
    else:
        pass
#print(prime_n)

soinsu={}
for di in prime_n:
    ans_di=0
    ni=n
    while(ni%di==0):
        ni//=di
        ans_di+=1
    soinsu[di]=ans_di
#print(soinsu)

ans=0
for k,v in soinsu.items():
    vi=v
    i=1
    while(vi>=i):
        vi-=i
        i+=1
        ans+=1
print(ans)


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

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            // 解答はココに書く
            int[] data = cin.ReadIntArray(2);
            int hp = data[0];
            int n = data[1];
            int[] damage = cin.ReadIntArray(n);
            Console.WriteLine(damage.Sum() >= hp ? "Yes" : "No");
            //Console.ReadLine();
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 19424
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  int n;
  while(cin>>n,n){
    int ans=0;
    int t=sqrt(n);
    for(int i=0;i<=t;i++)
      for(int j=i;j<=t;j++)
	for(int k=j;k<=t;k++)
	  for(int l=k;l<=t;l++)
	    if(i*i+j*j+k*k+l*l==n)ans++;
    cout<<ans<<endl;
  }
  return 0;
}



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

int main(void){
    int n;
    cin>>n;
    vector<int> a(n);
    bool ng = false;
    rep(i,n){
        cin>>a[i];
        if(i<a[i]) ng = true;
    }
    rep(i,n-1){
        if(a[i]+1 < a[i+1]){
            ng = true;
        }
    }
    if(ng){
        cout<<-1<<endl;
        return 0;
    }
    a.push_back(0);
    ll cost = 0;
    for(int i = n-1; i >= 0; i--){
        if(a[i]+1 != a[i+1]){
            cost += a[i];
        }
    }
    cout<<cost<<endl;
    return 0;
}


Measured memory_bytes: 1920
import java.util.Scanner;
public class Main {
	public static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int i, j, k;
		int n = sc.nextInt();
		int a[] = new int[n];
		
		for(i = 0; i < n; i++){
			a[i] = sc.nextInt();
		}
		
		bubblesort(n, a);
	}
	public static void bubblesort(int n, int a[]){
		int flag = 1;
		int i = 0;
		int temp;
		int count = 0;
		while(flag == 1){
			flag = 0;
			for(int j = n - 1; j >= i + 1; j--){
				if(a[j] < a[j - 1]){
					temp = a[j];
					a[j] = a[j-1];
					a[j - 1] = temp;
					count++;
					flag = 1;
				}
			}
			i++;
		}
		for(i = 0; i < n; i++){
			if(i == n - 1) System.out.println(a[i]);
			else System.out.print(a[i] + " ");
		}
		System.out.println(count);
	}

}


Measured memory_bytes: 26240
import java.util.*;

public class Main {

	public static Drink [] drinks;

	public static class Drink implements Comparable<Drink>{
		long cost;
		long drinks;
		double cperd;

		public Drink(){

		}

		public Drink(long cost_, long drinks_){
			cost = cost_;
			drinks = drinks_;
		}

		@Override
		public int compareTo(Drink o) {
			// TODO Auto-generated method stub
			return (int)(this.cost - o.cost);
		}

	}



	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner sc = new Scanner(System.in);
		long N = sc.nextInt();
		long M = sc.nextInt();
		long total = 0;
		PriorityQueue <Drink> q = new PriorityQueue<Drink>();
		for(long i = 0 ;i<N; i++) {
			q.add(new Drink(sc.nextInt(),sc.nextInt()));
		}

		while(M > 0) {
			Drink cur = q.poll();
			if(M>cur.drinks) {
				total += cur.drinks*cur.cost;
				M -= cur.drinks;
			}
			else{
				total += M*cur.cost;
				M = 0;
			}

		}
		System.out.println(total);

	}

}

Measured memory_bytes: 95724
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
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; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main(){
  ll N,ans=0;
  cin >> N;
  auto T = divisor(N);
  rep(i,T.size()){
    ll X=T[i];
    if(N/X-1>X){
      ans+=N/X-1;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#include<math.h>
#include<string>
#include <cctype>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1ll<<60;

using namespace std;
using ll = long long;
typedef pair<int, int> P;

int main(){
    int n; cin >> n;
    string s; cin >> s;
    rep(i, s.size()){
        if(s[i]+(n-1)*('B'-'A')>='Z'){
            int d = 'Z' - s[i]/('B'-'A');
            s[i]='A'+(n-d-1)*('B'-'A');
        }
        else s[i] = s[i]+n*('B'-'A');
    }
    out(s);
}

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

int main()
{
  string s;
  cin >> s;
  int N = s.size();
  
  int counta = 0;
  for(int i = 0; i < N; i++){
    if(s.at(i) == 'A'){
      counta = i;
      break;
    }
  }
  
  int countz = 0;
  for(int i = N-1; i >= 0; i--){
    if(s.at(i) == 'Z'){
      countz = i;
      break;
    }
  }
  
  cout << countz - counta + 1 << endl;
  
}

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

int main(void)
{
  int n;
  cin >> n;
  map<int, int> mp;
  for(int i = 0; i < n -1; i++)
  {
    int a;
    cin >> a;
    mp[a]++;
  }
  for(int i = 1; i <= n; i++)
  {
    cout << mp[i] << endl;
  }
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<string> vs;
const ll mod = 1e9+7;
const ll inf = 1e17;
const int INF = 1e9;
const double PI = acos(-1);
#define fo(i, a, b) for (int i = a; i < b; i++)
#define re(i, n) fo(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(s) s.begin(), s.end()
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
int main()
{
  int n, m, x;
  cin >> n >> m >> x;
  vi c(n);
  vvi a(n, vi(m));
  re(i, n) {
    cin >> c[i];
    re(j, m) {
      cin >> a[i][j];
    }
  }

  int ans = INF;
  re(bit, (1<<n)) {
    int sum = 0;
    vi s(m);
    re(i, n) {
      if(bit>>i & 1) {
        sum += c[i];
        re(j, m) {
          s[j] += a[i][j];
        }
      }
    }

    bool achi = true;
    re(i, m) {
      if(s[i] < x) {
        achi = false;
        break;
      }
    }
    if(achi) {
      ans = min(ans, sum);
    }
  }

  if(ans == INF) cout << -1 << endl;
  else cout << ans << endl;

  return 0;
}


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


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

    int R;
    cin >> R;


    cout << 2*R*3.1415926535<<endl;


}

Measured memory_bytes: 3804
#include<stdio.h>

int main()
{
    long long int i,n, x, remind, num[100000],sum=0, save, max;

    scanf("%lld%lld", &n, &x);
    for(i = 0; i < n; i++)
    {
        scanf("%lld", &num[i]);
        sum+=num[i];

    }
    if(sum == x)
        printf("%lld\n",n);
    else
    {
       remind = x - sum;
      
       max = num[0];
        for(i =0; i < n; i++)
        {


            if(max > num[i])
                max = num[i];
        }
        save = remind / max;

        printf("%lld\n", n+save);
    }
    return 0;

   // }



}

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

long long maxA = 1001001001;

int main(){
  long long N,K;
  cin >> N >> K;
  vector<vector<long long>> A(N,vector<long long>(N));
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      cin >> A[i][j];
    }
  }
  
  mcf_graph<long long,long long> G(N*2+2);
  G.add_edge(N*2,N*2+1,N*K,maxA);
  for(int i=0;i<N;i++) G.add_edge(N*2,i,K,0);
  for(int j=0;j<N;j++) G.add_edge(j+N,N*2+1,K,0);
  
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      G.add_edge(i,j+N,1,maxA-A[i][j]);
    }
  }
  
  pair<long long,long long> cost = G.flow(N*2,N*2+1,N*K);
  cout << maxA*N*K - cost.second << endl;
  
  vector<vector<char>> V(N,vector<char>(N,'.'));
  auto E = G.edges();
  for(auto e : E){
    long long from = e.from, to = e.to;
    if(from==N*2 || to==N*2+1) continue;
    
    if(e.flow==1){
      V[from][to-N] = 'X';
    }
  }
  
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      cout << V[i][j];
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 4000
#pragma GCC optimize("-Ofast","-funroll-all-loops")
#include<bits/stdc++.h>
#define int long long
#define lowbit(x) (x &(-x))
#define endl '\n'
using namespace std;
const int INF=0x3f3f3f3f;
const int dir[4][2]={-1,0,1,0,0,-1,0,1};
const double PI=acos(-1.0);
const double e=exp(1.0);
const double eps=1e-10;
const int M=1e9+7;
const int N=2e5+10;
typedef long long ll;
typedef pair<int,int> PII;
typedef unsigned long long ull;
int mp[110][110],dp[110][110];
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);

	int h,w;
	cin>>h>>w;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			char c;
			cin>>c;
			c=='#'?mp[i][j]=1:mp[i][j]=0;
		}
	}
	dp[0][0]=mp[0][0];
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(i+j==0) continue;
			dp[i][j]=INF;
			if(i>0) dp[i][j]=min(dp[i][j],dp[i-1][j]+(mp[i][j]&&!mp[i-1][j]));
			if(j>0) dp[i][j]=min(dp[i][j],dp[i][j-1]+(mp[i][j]&&!mp[i][j-1]));
		}
	}
	cout<<dp[h-1][w-1]<<endl;
	return 0;
}


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

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int a, b; cin >> a >> b;
    if((a>=1 && a<=9) && (b>=1 && b <=9)) cout << a*b << endl;
    else cout << "-1" << endl;

    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    int N; cin >> N;
    vector<int> h(N+1, 0);
    rep (i, 0, N) cin >> h[i];

    int ans = 0;
    while (true) {
        rep (i, 0, h.size()-1) {
            if (h[i] == 0) continue;
            if (h[i+1] == 0) ++ans;
            --h[i];
        }
        if (count(h.begin(), h.end(), 0) == h.size()) {
            cout << ans << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
N,K=map(int, input().split())
A = list(map(int, input().split()))
 
INF = 10**9
dp = [INF]*N
 
for i in range(len(A)):
    if i == 0:
        dp[0] = 0
    elif i == 1:
        dp[1] = abs(A[1]-A[0])
    else:
        jmp = min(i,K)
        for j in range(1,jmp+1):
            dp[i] = min(dp[i], dp[i-j]+abs(A[i]-A[i-j]))
            
print(dp[N-1])

Measured memory_bytes: 84748
#include <iostream>
#include <string>
#include <map>
#include <set>

using namespace std;

int main(){
  int page;
  string word;
  map<string, set<int> > index;

  while(cin >> word >> page){
    index[word].insert(page);
  }

  for(map<string, set<int> >::iterator i = index.begin(); i != index.end(); i++){
    cout << i -> first << endl;
    for(set<int>::iterator j = i -> second.begin(); j != i -> second.end(); j++){
      if(j != i -> second.begin() ){
        cout << " ";
      }
    cout << *j;
    }
    cout << endl;
  }
}

Measured memory_bytes: 1228
def make_fibonacchi(n: int):
    
    res = {}
    
    res[0] = 1
    res[1] = 1
    
    if n == 0 or n == 1:
        return 1
    
    for i in range(2, n + 1):
        res[i] = res[i-1] + res[i-2]
    
    return res[n]


n = int(input())
print(make_fibonacchi(n))


Measured memory_bytes: 5600
using System;
using System.Linq;
using static System.Console;

class Program
{
    static void Main()
    {
        var s = ReadLine().Split();
        var n = int.Parse(s[0]);
        var k = int.Parse(s[1]);
        var p = ReadLine().Split().Select(x => int.Parse(x));
        var ans = p.OrderBy(x => x).Take(k).Sum();
        WriteLine(ans);
    }
}

Measured memory_bytes: 28624
S = str(input())
T = str(input())

if S[0]==T[0] and S[1]==T[1] and S[2]==T[2]:
    print("3")
elif S[0]==T[0] and S[1]==T[1] and S[2]!=T[2]:
    print("2")
elif S[0]==T[0] and S[1]!=T[1] and S[2]==T[2]:
    print("2")
elif S[0]!=T[0] and S[1]==T[1] and S[2]==T[2]:
    print("2")
elif S[0]==T[0] and S[1]!=T[1] and S[2]!=T[2]:
    print("1")
elif S[0]!=T[0] and S[1]==T[1] and S[2]!=T[2]:
    print("1")
elif S[0]!=T[0] and S[1]!=T[1] and S[2]==T[2]:
    print("1")
else:
    print("0")

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
    Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Main();
    }

    public Main() {
        new aoj().doIt();
    }
    class aoj {
        void doIt(){
        	int sum = 0;
        	for(int i = 0;i < 5;i++){
        		sum = sum + Math.max(40, sc.nextInt());
        	}
        	System.out.println(sum/5);
        }
    }
}

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

using namespace std;

long long INF=1e15;

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

    while(1){
        int n,m,p;
        cin>>n>>m>>p;

        if(n==0)break;

        int sum=0;
        vector<int> a(n);
        for(int i=0;i<n;i++){
            cin>>a[i];
            sum+=a[i];
        }

        sum*=(100-p);

        if(a[m-1]==0)sum=0;
        else sum/=a[m-1];

        cout<<sum<<endl;
    }
}


Measured memory_bytes: 3080
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		// 計算
		int h = 100;
		int w = 100;
		char[][] grid = new char[h][w];
		for(int i = 0; i < h; i++){
		    for(int j = 0; j < w; j++){
		        if(i > 49){
		            grid[i][j] = '.';
		        }else{
		            grid[i][j] = '#';
		        }
		    }
		}
		for(int i = 0; i < 49; i++){
		    for(int j = 0; j < w; j++){
		        if(a < 2) break;
		        if(i%2 == 0 && j%2 == 0){
		            grid[i][j] = '.';
		            a--;
		        }
		    }
		    if(a < 1) break;
		}
		for(int i = 51; i < h; i++){
		    for(int j = 0; j < w; j++){
		        if(b < 2) break;
		        if(i%2 == 0 && j%2 == 0){
		            grid[i][j] = '#';
		            b--;
		        }
		    }
		    if(b < 1) break;
		}
		
		// 出力
		System.out.println(h + " " + w);
		for(int i = 0; i < h; i++){
		    for(int j = 0; j < w; j++){
		        System.out.print(grid[i][j]);
		    }
		    System.out.println("");
		}
		
	}
}




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

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  long long sum = 0;
  long long r_num = 0;
  long long g_num = 0;
  long long b_num = 0;
  for (int i = 0; i < N; i++) {
    if (S[i] == 'R') {
      r_num++;
    } else if (S[i] == 'G') {
      g_num++;
    } else {
      b_num++;
    }
  }
  sum = r_num * g_num * b_num;

  for (int i = 0; i < N - 2; i++) {
    for (int j = i + 1; j < N - 1; j++) {
      if (2 * j - i < N) {
        if (S.at(i) != S.at(j) && S.at(i) != S.at(2 * j - i) &&
            S.at(j) != S.at(2 * j - i)) {
          sum--;
        }
      }
    }
  }

  cout << sum << endl;
}


Measured memory_bytes: 3636
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(i, (q).size()) { cerr << (q)[i] << (i == i_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
#define CHOKUDAI_ const
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using cll = DANCE_ DANCE_ CHOKUDAI_;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    ll n; cin >> n;
    vector<ll> h(n);
    REP(i, n) cin >> h[i];

    vector<ll> cand(n, 0);
    REP(i, n-1) {
        if (h[i] >= h[i+1]) {
            cand[i+1] = cand[i] + 1;
        }
    }
    cout << *max_element(ALL_OF(cand)) << endl;
    
}

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

int main()
{
    int N;

    cin >> N;
    int dmin = 1000;
    for (int i = 0; i < N; ++i)
    {
        int A;
        cin >> A;
        int d = 0;
        while (A % 2 == 0)
        {
            A /= 2;
            ++d;
        }
        dmin = min(dmin, d);
    }

    cout << dmin << endl;
}


Measured memory_bytes: 256
n = int(input())
m = mi = 0
a = []
for i in range(n):
    x = int(input())
    a.append(x)
    if x == m:
        mi += 1
    if x > m:
        m = x
        mi = 1
if mi == 1:
    m2 = 0
    for i in range(n):
        if a[i] == m:
            continue
        if a[i] > m2:
            m2 = a[i]
    for i in range(n):
        if a[i] == m:
            print(m2)
        else:
            print(m)
else:
    for i in range(n):
        print(m)


Measured memory_bytes: 12520
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
using namespace std;
typedef long long ll;
ll d[51][51];
void MaximumAverageSets() {
	int n, a, b;
	cin >> n >> a >> b;
	ll t[51];
	map<ll, int> m;
	d[0][0] = 1;
	for (size_t i = 1; i < 51; i++)
	{
		d[i][0] = 1;
		for (size_t j = 1; j < 51; j++)
		{
			d[i][j] = d[i - 1][j] + d[i - 1][j - 1];
		}
	}

	for (size_t i = 0; i < n; i++)
	{
		cin >> t[i];
		m[t[i]]++;
	}
	sort(t, t + n, std::greater<ll>());
	ll res = 0;
	double avem = 0;
	ll bsum = 1;
	ll bnum = 1;
	for (size_t i = a; i <= b; i++)
	{
		ll sum = 0;
		int fl = 1;
		for (size_t j = 0; j < i; j++)
		{

			sum += t[j];
			if (j > 0) {
				if (t[j] != t[j - 1]) {
					fl = 1;
				}
				else {
					fl++;
				}
			}
		}

		if (bsum * i < sum * bnum) {
			bsum = sum;
			bnum = i;
			res = 0;
		}

		if (bsum * i == sum * bnum) {
			int c = m[t[a - 1]];
			
			res += d[c][fl];
		}
	}

	cout << to_string((double)bsum / (double)bnum) << endl;
	cout << res << endl;
}

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



Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
int n;
bool flg[60000];

int main() {
	memset(flg, 1, sizeof(flg));
	flg[1] = 0;
	for(int i = 2; i <= 55555; i++) {
		for(int j = 2; j <= sqrt(i); j++) {
			if(i % j == 0) {
				flg[i] = 0;
				break;
			}
		}
	}
	flg[2] = 0;
	//for(int i = 1; i <= 100; i++) if(flg[i]) printf("%d ", i);
	scanf("%d", &n);
	for(int i = 1; i <= 55555; i++) {
		if(n == 0) break;
		if(flg[i] && i % 10 == 9) {
			printf("%d ", i);
			n--;
		}
	}
	printf("\n");
}

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

int main() {
  
  int N,K;
  cin >> N >> K;
  
  int x=1;
  for (int i=0; i<N; i++) {
    if (x*2 < x+K) x*=2;
    else x+=K;
  }
  
  cout << x << endl;
}

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


int main() {
  int N;
  cin >> N;
  float v[1050];
  for (int i = 0; i < N; i++){
    cin >> v[i];
  }
for (int i=0; i<N; i++) {
    for (int j=i+1; j<N; j++) {
      if (v[i] > v[j]) {
        float tmp;
        tmp =  v[i];
        v[i] = v[j];
        v[j] = tmp;
      }
    }
  }


  float ans = v[0];

  for (int i=1; i <N ; i++){
    ans = (ans + v[i]) / ((float)2);
  }

  printf("%lf\n",ans);

  return 0;
}

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

int main(){

    int a,b,c;
    cin>>a;
    cin>>b;
    cin>>c;
    int remains=c-(a-b);
    if(remains<1){
        cout<<0;
    }
    else{
    cout<<remains;
    }
    return 0;
}


Measured memory_bytes: 256
//raja1999
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 <<endl;prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx


using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false);
int main(){
	std::ios::sync_with_stdio(false);
	long double q[5];
	ll n;
	 int i;
	rep(i,4){
		cin>>q[i];

	}
	long double val;
	q[0]*=4;
	q[1]*=2;
	q[3]/=2;
	val=q[3];
	sort(q,q+4);
	cin>>n;
	if(q[0]==q[1]||q[0]!=val)
	n*=q[0];
	else
	{

		n=((n-n%2))*q[0]+(n%2)*q[1];
	}
	cout<<n<<endl;

} 


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
typedef pair<int, int> P;
char field[824][824];
int dist[824][824];
int h, w, k;
int res = 1000;
int xs[] = {0, 1, 0, -1};
int ys[] = {1, 0, -1, 0};
P start;
int calc(int i, int j, int h, int w){
  h--,w--;
  int ans = abs(h - i);
  ans = min(ans, i);
  ans = min(ans, j);
  ans = min(ans, abs(w - j));
  return ans;
}

int main(){
  cin >> h >> w >> k;
  for(int i = 0;i < h;i++){
    for(int j = 0;j < w;j++){
      cin >> field[i][j];
      if(field[i][j] == 'S'){
	start = P(i, j);
      }
      dist[i][j] = -1;
    }
  }

  queue<P> q;
  q.push(start);
  dist[start.first][start.second] = 0;
  while(!q.empty()){
    P tmp = q.front();q.pop();
    int x = tmp.first, y = tmp.second;
    //    cout << x << " " << y << " "<< dist[x][y] << endl;
    for(int i = 0;i < 4;i++){
      int nx = x + xs[i];
      int ny = y + ys[i];
      if(nx < 0 || nx >= h|| ny < 0 || ny >= w){
	continue;
      }
      if(field[nx][ny] == '#')continue;
      if(dist[nx][ny] != -1)continue;
      dist[nx][ny] = dist[x][y] + 1;
      q.push(P(nx, ny));
    }
  }
  for(int i = 0;i < h;i++){
    for(int j = 0;j < w;j++){
      if(dist[i][j] == -1)continue;
      if(dist[i][j] > k)continue;
      int score = calc(i, j, h, w); 
      int tmp = score / k + (score % k != 0) + 1;
      res = min(res, tmp);
    }
  }
  
  
 
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 4088
#include "bits/stdc++.h"
#define int long long

using namespace std;

signed main() {
    int N, sum = 0;
    vector<int> Xs;
    cin >> N;
    for(auto i = 0; i < N; i++){
        int t;
        cin >> t;
        Xs.push_back(t);
        sum += t;
    }
    int a = (2 * sum + N) / 2 / N;
    int ans = 0;
    for(auto i = Xs.begin(); i != Xs.end(); i++){
        ans += (*i - a) * (*i - a);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
L, R = map(int, input().split())
if (L//2019) < (R//2019) or L%2019==0 or R%2019==0:
    result = 0
else:
    result = 2018
    for i in range(L, R):
        for j in range(i+1, R+1):
            if result > (i*j)%2019:
                result = (i*j)%2019
print(result) 

Measured memory_bytes: 3060
#include<iostream>

using namespace std;

int main(){
   int time;
   cin >> time;
   int h, m, s;

   h = time /3600;
   m =(time%3600) / 60;
   s = (time%3600) % 60;

   printf("%d:%d:%d\n",h,m,s);
   return 0;
}


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

template<class S, S (*next)(S), int (*idx)(S)>
struct doubling {
    doubling(int _n, long long _max_k) : n(_n) {
        log = 1;
        while (1LL << log < _max_k) log++;
        t = std::vector<std::vector<int>>(log, std::vector<int>(_n));
        for (int i = 0; i < _n; ++i) t[0][i] = next(i);
    }

    void init() {
        for (int k = 0; k < log - 1; k++) {
            for (int i = 0; i < n; i++) t[k + 1][i] = t[k][idx(t[k][i])];
        }
    }

    S query(S s, long long k) {
        S now = s;
        for (int _k = 0; k > 0; _k++) {
            if (k & 1) now = t[_k][idx(now)];
            k >>= 1;
        }
        return now;
    }

    private:
        int n, log;
        std::vector<std::vector<S>> t;
};


std::vector<int> A;
int next (int n) { return A[n]; }
int idx(int n) { return n; }

int main(){
    int N;
    long long K;
    std::cin >> N >> K;

    A = std::vector<int>(N);
    for (auto &i : A) std::cin >> i, i--;

    doubling<int, next, idx> d(N, K);
    d.init();
    std::cout << d.query(0, K) + 1 << std::endl;
}


Measured memory_bytes: 51648
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

H, W = MAP()
if H == 1 or W == 1:
    print(1)
    exit()
if H % 2 == 0 and W % 2 == 0:
    a = H * W // 2
if H % 2 == 0 and W % 2 != 0:
    a = H * W // 2
if H % 2 != 0 and W % 2 == 0:
    a = (H - 1) * W // 2 + (W // 2)
if H % 2 != 0 and W % 2 != 0:
    a = (H - 1) * W // 2 + (W // 2 + 1)
print(a)

# exit()
# if H == 1 or W == 1:
#     print(1)
#     exit()

# if H % 2 == 0:
#     print(H * W // 2)
# else:
#     a = (H - 1) // 2 * W + (W - 1)
#     print(a)





# exit()
# if W % 2 == 0:
#     a = W // 2
#     b = W // 2
# else:
#     a = W // 2 + 1
#     b = W // 2
# # a = ceil(W / 2)
# # b = ceil((W-1) / 2)
# print(a)
# print(b)
# if H % 2 == 0:
#     ans = a * H // 2 + b * H // 2
#     print(H//2)
#     print(H//2)
# else:
#     ans = a * (H // 2+1) + b * H // 2
#     print(H//2+1)
#     print(H//2)
# print(ans)

Measured memory_bytes: 5372
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
#ifdef zerol
#define dbg(x...) do { cout << "\033[32;1m" << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
// -----------------------------------------------------------------------------

const int N = 2E5 + 100;
const int MOD = 1E9 + 7;
int n, a[N];
LL s[N], f[N];

int main() {
    cin >> n;
    FOR (i, 1, n + 1) scanf("%d", &a[i]);
    f[0] = 1;
    FOR (i, 1, n + 1) {
        if (a[i] != a[i - 1]) (s[a[i]] += f[i - 1]) %= MOD;
        // FOR (j, 1, i + 1) {
        //     if (a[j - 1] != a[j] && a[j] == a[i]) {
        //         f[i] += f[j - 1];
        //     }
        // }
        f[i] = s[a[i]];
        dbg(i, f[i]);
    }
    cout << f[n] << endl;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long int lli;
typedef long double ld;
const int oo = 1e9;
const int mod = 1e9+9;
 
//Juan Pablo Betancourt Maldonado

const int nax = 1e5+103;
int n, k;
int dp[nax];
int a[nax];
int f(int i){
	if (i==n-1) return 0;
	if(dp[i]!=-1) return dp[i];
	int ans = abs(a[i]-a[i+1])+f(i+1);
	for(int j=2; j<=k; j++){
		if(i+j<n) ans = min(ans, abs(a[i]-a[i+j])+f(i+j));
	}
	return dp[i]=ans;
}
int main(){
	cin>>n>>k;
	for(int i=0; i<n; i++) cin>>a[i];
	memset(dp, -1, sizeof dp);
	cout<<f(0)<<endl;
	return 0;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << (x) << endl
using namespace std;

const int N = 100005;

template <class T>
void read (T &x) {
	int sgn = 1;
	char ch;
	x = 0;
	for (ch = getchar(); (ch < '0' || ch > '9') && ch != '-'; ch = getchar()) ;
	if (ch == '-') ch = getchar(), sgn = -1;;
	for (; '0' <= ch && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
	x *= sgn;
}

template <class T>
void write (T x) {
	if (x < 0) putchar('-'), write(-x);
	else if (x < 10) putchar(x + '0');
	else write(x / 10), putchar(x % 10 + '0');
}

struct permutation {
	int n;
	vector<int> p;

	permutation () {
		n = 0;
	}
	permutation (int n) {
		this -> n = n;
		for (int i = 0; i < n; i++) p.push_back(i);
	}

	permutation& operator = (permutation rhs) {
		n = rhs.n;
		p = rhs.p;
		return *this;
	}

	permutation operator * (permutation rhs) const {
		permutation res(n);
		for (int i = 0; i < n; i++) res.p[i] = p[rhs.p[i]];
		return res;
	}

	permutation inv () const {
		permutation res(n);
		for (int i = 0; i < n; i++) res.p[p[i]] = i;
		return res;
	}

	void output () {
		for (int i = 0; i < n; i++) write(p[i] + 1), putchar(' ');
		putchar('\n');
	}

} id, p, q;

int n, k;

permutation qpow (permutation p, int k) {
	permutation res(p.n);
	while (k) {
		if (k & 1) res = res * p;
		p = p * p, k >>= 1;
	}
	return res;
}

vector<int> seq[N];
int main () {
	read(n), read(k);
	id = p = q = permutation(n);
	for (int i = 0; i < n; i++) {
		read(p.p[i]), p.p[i]--;
	}
	for (int i = 0; i < n; i++) {
		read(q.p[i]), q.p[i]--;
	}

	if (k == 1) p.output();
	else {
		permutation a = qpow(q * p.inv() * q.inv() * p, (k - 2) / 6), b;
		if (k % 6 == 1) a = a * q * p.inv() * q.inv(), b = p;
		if (k % 6 == 2) b = q;
		if (k % 6 == 3) b = q * p.inv();
		if (k % 6 == 4) a = a * q, b = p.inv();
		if (k % 6 == 5) a = a * q * p.inv(), b = q.inv();
		if (k % 6 == 0) a = a * q * p.inv(), b = q.inv() * p;
		(a * b * a.inv()).output();
	}
	return 0;
}

Measured memory_bytes: 8696
N,M=map(int,input().split())
number=[0]*N
ac,wa,=0,0
for m in range(M):
    p,s=input().split()
    p=int(p)-1
    if number[p]!=-1:
        if s == "WA":
            number[p]+=1
        elif s == "AC":
            ac+=1
            wa+=number[p]
            number[p] = -1
print(ac,wa)

Measured memory_bytes: 3828