akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>

using namespace std;
long long dp[1010][1010] = {},mod = 1000000007;
string s[1010];
int main(){
	int i,j,h,w;
	cin >> h >> w;
	for(i=0;i<h;i++){
		cin >> s[i];
	}
	dp[0][0] = 1;
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			if(s[i+1][j]!='#') (dp[i+1][j] += dp[i][j]) %= mod;
			if(s[i][j+1]!='#') (dp[i][j+1] += dp[i][j]) %= mod;
		}
	}
	cout << dp[h-1][w-1] << endl;
}

Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
int a[61];
int main()
{
	int n,k;
	cin>>n>>k;
	for(int i=1;i<=n;i++)cin>>a[i];
	sort(a+1,a+1+n);
	int sum=0;
	for(int i=n;i>n-k;i--)sum+=a[i];
	cout<<sum<<endl;
	return 0;
}

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

int main()
{
	int r, g, b, n, ans;
	cin >> r >> g >> b >> n;
	ans = 0;
	for (int a = 0; a * r <= n ; a++) {
		for (int d = 0; a * r + d * g <= n ; d++) {
			if ((n -r * a - g * d) % b == 0) {
				ans += 1;
				
			}
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	int n, m, k, start, goal, r;
	int[][] cost, time;
	
	final int INF = Integer.MAX_VALUE;
	
	void warshall(int[][] wf) {
		for (int i = 0; i < m; i++) {
			for (int j = 0; j < m; j++) {
				for (int k = 0; k < m; k++) {
//					if (wf[i][k] != INF && wf[k][j] != INF && wf[i][j] > wf[i][k] + wf[k][j]) {
//						wf[i][j] = wf[i][k] + wf[k][j];
					if (wf[j][i] != INF && wf[i][k] != INF && wf[j][k] > wf[j][i] + wf[i][k]) {
						wf[j][k] = wf[j][i] + wf[i][k];
					}
				}
			}
		}
	}
	
	int solve() {
		if (r == 0) {
			return cost[start][goal];
		} else {
			return time[start][goal];
		}
	}
	
	void run() {
		Scanner sc = new Scanner(System.in);
		String output = "";
		while (sc.hasNext()) {
			n = sc.nextInt();
			m = sc.nextInt();
			if (n == 0 && m == 0) {
				break;
			} else {
				cost = new int[m][m];
				time = new int[m][m];
				for (int i = 0; i < m; i++) {
					Arrays.fill(cost[i], INF);
					Arrays.fill(time[i], INF);
				}
				for (int i = 0; i < n; i++) {
					int a = sc.nextInt() - 1;
					int b = sc.nextInt() - 1;
					cost[a][b] = cost[b][a] = sc.nextInt();
					time[a][b] = time[b][a] = sc.nextInt();
				}
				for (int i = 0; i < m; i++) cost[i][i] = time[i][i] = 0;
				
				warshall(cost);
				warshall(time);
				
				k = sc.nextInt();
				for (int i = 0; i < k; i++) {
					start = sc.nextInt() - 1;
					goal = sc.nextInt() - 1;
 					r = sc.nextInt();
					output += solve() + "\n";
				}
			}
		}
		sc.close();
		System.out.print(output);
	}
	
	public static void main(String[] args) {
		new Main().run();
	}

}

Measured memory_bytes: 160064
#include <bits/stdc++.h>
 
using namespace std;
 
#define ss second
#define ff first
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(a) (a).begin(),(a).end()
#define rep(i,a,b) for(int (i) = (a); (i) < (b); (i)++)
#define debug(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<ll>;
using vii = vector<pair<int,int>>;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3fLL;
const int maxn = 1e2+10;

int main(int argc,const char** argv){

	fastio;

	int n;

	cin >> n;

	vi v(n),dp(n,INF);

	dp[0] = 0;

	for(int &x:v) cin >> x;

	rep(i,0,n){
		for(int j=i+1;j <= i+2 && j < n ;j++){
			if(j < n) dp[j] = min(dp[j],dp[i] + abs(v[i]-v[j]));
		}
	}

	cout << dp[n-1] << '\n';

	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <utility>
#include <queue>
#include <climits>
using namespace std;

#define endl '\n'
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
typedef pair<int, int> ii;
typedef long long LL;
typedef long double LD;

string s;
LL k;

void solve(){
	FOR(i, 0, s.length()-1) {
		int need = 'z' - s[i] + 1;
		if(s[i] > 'a' && need <= k) {
			k -= need;
			s[i] = 'a';
		}
	}
	s[s.length()-1] = (s[s.length()-1] - 'a' + k % 26LL) % 26 + 'a';
    cout << s << endl;
}

int main(int argc, char *argv[]){
    ios::sync_with_stdio(false);
    std::cin.tie(0);
    while(cin >> s >> k) {
	    solve();
	}
    return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
    ios::sync_with_stdio(0); cin.tie(0);
 
    int n;
    cin >> n;
    vector<long long> a(n);
    long long x = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        x ^= a[i];
    }
    for (int i = 0; i < n; i++) cout << (x ^ a[i]) << ' ';
    cout << '\n';
}

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


int main() {
   int n;
   cin>>n;
   int i=1;

   for(i=1;i*i<n;i++){
   }
   if(i*i==n){
      cout<<i*i<<endl;
   }
   else {
   cout<<i*i-2*i+1<<endl;
   }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pint pair<int,int>
#define mk(x,y) make_pair(x,y)
#define fir first
#define sec second
#define Rep(x,y,z) for(int x=y;x<=z;++x)
#define Red(x,y,z) for(int x=y;x>=z;--x)
using namespace std;
const int MAXN=2e5+5;
char buf[1<<12],*p1=buf,*p2=buf,nc;int ny;
inline char gc() {return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<12,stdin),p1==p2)?EOF:*p1++;}
//inline char gc(){return getchar();}
inline int read(){
	int x=0;ny=1;while(nc=gc(),(nc<48||nc>57)&&nc!=EOF)if(nc==45)ny=-1;if(nc<0)return nc;
	x=nc-48;while(nc=gc(),47<nc&&nc<58&&nc!=EOF)x=(x<<3)+(x<<1)+(nc^48);return x*ny;
}
int n,k,a[MAXN];
inline bool chk(int x){
	ll tmp=0;
	Rep(i,1,n){
		tmp+=(a[i]-1)/x;
	}
	return tmp<=k;
}
int main(){
//	freopen("std.in","r",stdin);
//	freopen("std.out","w",stdout);
	n=read(),k=read();
	Rep(i,1,n)a[i]=read();
	int l=1,r=1e9,ans;
	while(l<=r){
		int mid=l+r>>1;
		if(chk(mid))r=mid-1,ans=mid;else l=mid+1;
	}cout<<ans<<"\n";
	return 0;
}



Measured memory_bytes: 4308
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <assert.h>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

int main(){
  ll d[3];
  cin>>d[1]>>d[2]>>d[0];
  cout << d[0] << " " << d[1] << " " << d[2] << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
#include <numeric>
#include<vector>

#define LL long long
#define MOD 1000000007

using namespace std;

LL gcd(LL C, LL D) {
	if (C < D) gcd(D, C);

	if (C%D == 0)return D;
	else gcd(D, C%D);
}

///<summary>
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

int main() {

	int M1, M2, D;
	cin >> M1 >> D >> M2 >> D;

	if (M1 == M2 - 1) {
		cout << "1" << endl;
	}
	else {
		cout << "0" << endl;
	}

}





Measured memory_bytes: 256
#include<bits/stdc++.h>
#define two(a) (1<<(a))
#define LINF (1ll<<61)
#define EPS (1e-14)
#define Lshift(a,b) ((a)<<(b))
#define Rshift(a,b) ((a)>>(b))
#define rep(a,b) for(a=0 ; a<b ; a++)
#define xrep(a,b,c) for(a=b ; a<c ; a++)
#define INF (1<<29)
#define sz(a) int(a.size())
#define mset(x) memset(x, 0, sizeof(x))
#define swap(a,b) ( (a^=b) , (b^=a) , (a^=b) )
#define GET(x) (mark[x>>5]>>(x&31)&1)
#define SET(x) (mark[x>>5]|=1<<(x&31))
#define maxL (10000000>>5)+1
#define mod 1000000007
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define si set<int>
#define pb push_back
typedef long long ll;
using namespace std;


int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    ll n;
    cin >> n;
    vector<int> ans;
    while (n) {
        int x = n % 26;
        n /= 26;
        if (x == 0) {
            n--;
            x += 26;
        }
        ans.push_back(x + 'a' - 1);
    }
    reverse(ans.begin(), ans.end());
    for (auto c: ans) cout << char(c);
    cout << endl;
}


Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define me BOSS
#define bug() cout<<"AIkahne aise"<<endl
#define PI acos(-1)
ll A[5000001],bin[5000001];
vector<ll>v;
map<int,int>myMap;
set<int>mySet;
vector<pair<ll,ll> >vp;
/* Precode Start Here *\


power of 2 less than or equal to N

ll largest_power(ll N)
{
    //changing all right side bits to 1.
    N = N (N>>1);
    N = N| (N>>2);
    N = N| (N>>4);
    N = N| (N>>8);


//as now the number is 2 * x-1, where x is required answer, so adding 1 and dividing it by
 2.
            return (N+1)>>1;

}


     Sieve
void sieve()
{
    for(ll i=3; i<=2000; i+=2)
    {
        for(ll j=i*i; j<=4000000; j+=i)
            A[j]=1;
    }
    v.push_back(2);
    for(ll i=3; i<=4000000; i+=2)
        if(A[i]==0)
            v.push_back(i);
}

     Power Function Modulo P

ll modPow(ll a, ll x, ll p) {
    //calculates a^x mod p in logarithmic time.
    long res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}


   factorial

ll fact(ll n)
{
    ll ans=1;
    for(ll i=1;i<=n;i++)
    {
        ans=(ans*i)%mod;
    }
    return ans;
}
     Calculating nCr using Fermats law Theorem

ll modInverse(ll a, ll p) {
    //calculates the modular multiplicative of a mod m.
    //(assuming p is prime).
    return modPow(a, p-2, p);
}


ll modBinomial(ll n, ll k, ll p) {
// calculates C(n,k) mod p (assuming p is prime).

    ll numerator = 1; // n * (n-1) * ... * (n-k+1)
    for (ll i=0; i<k; i++) {
        numerator = (numerator * (n-i) ) % p;
    }

    ll denominator = 1; // k!
    for (ll i=1; i<=k; i++) {
        denominator = (denominator * i) % p;
    }

    // numerator / denominator mod p.
    return ( numerator* modInverse(denominator,p) ) % p;
}
     num of divisor and euler totient

ll phi[1000001],mark[1000001],divi[1000001];;
void divisorPhi(ll n)
{
    for(int i=1;i<=n;i++)
        phi[i]=i;
    for(int i=2;i<=n;i++)
    {
        if(!mark[i])
        {
            for(int j=i;j<=n;j+=i)
            {
                mark[j]=1;
                phi[j]*=(1-1/(double)i);
            }
        }
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=i;j<=n;j+=i)
            divi[j]++;
    }
}




/* Precode Ends */
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
 ll a,b,c;
 cin>>a>>b>>c;
 if(a+b+c>=22)
 {
     cout<<"bust"<<endl;
 }
 else
 {
     cout<<"win"<<endl;
 }
return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

int a[111111];
ll v[111111];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
	int n,k; cin>>n>>k;
	for(int i=0;i<n;i++)
	{
		cin>>a[i]>>v[i];
	}
	ll ans=0;
	int curbit = 0;
	for(int i=30;i>=0;i--)
	{
		if(k&(1<<i))
		{
			int bit = curbit;
			if(i>0) bit|=((1<<i)-1);
			ll val=0;
			for(int j=0;j<n;j++)
			{
				if((a[j]&bit)==a[j])
				{
					val+=v[j];
				}
			}
			ans=max(ans,val);
			curbit^=(1<<i);
		}
	}
	ll val=0;
	for(int j=0;j<n;j++)
	{
		if((a[j]&k)==a[j])
		{
			val+=v[j];
		}
	}
	ans=max(ans,val);
	cout<<ans<<'\n';
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define fs first
#define sc second
using namespace std;
typedef double D;
typedef pair<D,D> pdd;
typedef vector<D> vd;
const D EPS = 1e-8;
const D PI = acos(-1);

int n,k;
pdd p[2000];
vector<pdd> v;
int max_r[2000], max_l[2000];
D dp1[1501][1501],dp2[1501][1501];

inline void modify(D &seta){
  if(seta>PI)seta-=2*PI;
  if(seta<-PI)seta+=2*PI;
}

inline bool in_upper(const D &seta){
  return (EPS<seta && seta<PI-EPS);
}

inline bool comp(const pdd &a, const pdd &b){
  return abs(a.fs-b.fs)<EPS?a.sc+EPS<b.sc:a.fs<b.fs;
}

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

  cin >> n >> k;
  rep(i,n){
    D x,y,r;
    cin >> x >> y >> r;
    complex<D> c(x,y);
    D d = abs(c), s = arg(c), a = sqrt(d*d-r*r);
    D ds = acos( (d*d + a*a - r*r)/(2*d*a) );
    
    D start = s-ds, end = s+ds;
    modify(start); modify(end);
    pdd tmp = pdd(in_upper(start)?start:0, in_upper(end)?end:PI);
    if(tmp.fs<EPS && PI-EPS<tmp.sc)continue;
    v.push_back(tmp);
  }

  sort(v.begin(),v.end(),comp);

  rep(i,v.size())rep(j,v.size()){
    if(i==j)continue;
    if(v[j].fs-EPS<v[i].fs && v[i].sc<v[j].sc+EPS){
      v.erase(v.begin()+i);
      i--;
      break;
    }
  }

  int m = v.size();
  rep(i,m){
    pdd dummy(v[i].sc,0);
    max_l[i] = upper_bound(v.begin(),v.end(),dummy,comp) - v.begin();
    max_r[i] = max_l[i]-1;
  }
  
  rep(i,m)rep(j,k+1){
    dp1[i+1][j] = max(dp1[i+1][j], dp1[i][j]);
    if(j+1<=k){
      D use = max(dp1[i][j], dp2[i][j]);
      dp1[max_l[i]][j+1] = max(dp1[max_l[i]][j+1], use + v[i].sc-v[i].fs);
      if(max_r[i]!=i){
	dp2[max_r[i]][j+1] = max(dp2[max_r[i]][j+1], use + v[max_r[i]].fs-v[i].fs);
      }
    }
  }

  D ans = 0;
  rep(i,k+1)ans = max(ans, dp1[m][i]);
  cout << fixed << setprecision(10) << ans/PI << "\n";
}

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

int main() {
    int K, N;
    cin >> K >> N;
    vector<int> A(N);
    int max_dist = 0;
    vector<int> p(2, 0);
    rep(i, N) {
        cin >> A[i];
        if (i != 0) {
            if (abs(p[0] - p[1]) < abs(A[i] - A[i - 1])) {
                p[0] = A[i - 1];
                p[1] = A[i];
            }
        }
    }
    if (abs(p[0] - p[1]) < abs(A[N - 1] - A[0] - K)) {
        p[0] = A[0] + K;
        p[1] = A[N - 1];
    }
    cout << K - abs(p[1] - p[0]) << endl;
    return 0;
}

Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include<iostream>
#include<algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>

using namespace std;
typedef long long ll;

int main() {
	cin.sync_with_stdio(0); cin.tie(0); cout.tie(NULL);
	double a, b, h, m; cin >> a >> b >> h >> m;
	double Qm = m / (double)60 * (double)2 * M_PI;
	double Qh = ((double)60 * h + m) / (double)720 * (double)2 * M_PI;
	double x = Qh - Qm; x = abs(x);
	double t = sin(x) * a;
	double t2 = cos(x) * a;
	double ans = t * t + (b - t2) *(b - t2);
	ans = sqrt(ans);
	cout << fixed;
	cout.precision(14);
	cout << ans << '\n';

	

	

	




} 

Measured memory_bytes: 4048
#include <stack>
#include <cctype>
#include <string>
#include <cstring>
#include <iostream>
using namespace std;
string s; int n, p[300], v[300], w[300];
int main() {
	while (cin >> s >> n, s != "0") {
		string t = string({ s[0] });
		for (int i = 1; i < s.size(); i++) {
			if (isdigit(s[i - 1]) && isalpha(s[i])) t += "(" + string({ s[i] }) + ")";
			else t += s[i];
		}
		for (int i = 0; i < 300; i++) p[i] = 0, v[i] = 0, w[i] = 0;
		int pos1 = 0, w1 = 0; s = "";
		for (int i = 0; i < t.size(); i++) {
			if (isdigit(t[i])) w1 = 10 * w1 + t[i] - 48;
			else {
				if (t[i] == '(') v[pos1] = w[pos1] = w1, w1 = 0;
				s += t[i]; pos1++;
			}
		}
		stack<int> st;
		for (int i = 0; i < s.size(); i++) {
			if (s[i] == '(') st.push(i);
			if (s[i] == ')') p[i] = st.top(), p[st.top()] = i, st.pop();
		}
		int pos = 0;
		for (int i = 0; i <= n; i++) {
			while (pos < s.size()) {
				if (s[pos] == '(') {
					if (w[pos]) w[pos]--, pos++;
					else w[pos] = v[pos], pos = p[pos] + 1;
				}
				else if (s[pos] == ')') pos = p[pos];
				else {
					if(i != n) pos++; break;
				}
			}
		}
		cout << (pos < s.size() ? s[pos] : '0') << endl;
	}
	return 0;
}

Measured memory_bytes: 3032
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

func main() {
	x, y := ReadInt(), ReadInt()
	fmt.Println(
		Min(
			f(x, y),
			1+f(-x, y),
			1+f(x, -y),
			2+f(-x, -y),
		),
	)
}

func f(x, y int) int {
	if x == y {
		return 0
	}
	if y-x == 1 {
		return 1
	}
	if x == -y {
		return 1
	}
	if x >= 0 && x < y {
		return y - x
	}
	if y <= 0 && x < y {
		return y - x
	}
	return math.MaxInt32
}

func Min(xs ...int) int {
	min := xs[0]
	for _, x := range xs[1:] {
		if min > x {
			min = x
		}
	}
	return min
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }


Measured memory_bytes: 1840
#include<stdio.h>
#include<algorithm>

using namespace std;

long long inp_c, inp_n, i1, cursum;

long long inp_a[10004];

long long readNumber() {
	long long temp_func;
	scanf("%lld", &temp_func);
	return temp_func;
};
long long printNumber(long long temp_func) {
	printf("%lld", temp_func);
	return 0;
};

int main() {
	
	inp_n = readNumber();
	
	inp_c = readNumber();
	
	for (i1 = 1; i1 <= inp_c; i1++) {
		
		inp_a[i1] = readNumber();
		
		cursum += inp_a[i1];
		
	};
	
	printNumber(max((long long)-1, inp_n - cursum));
	
	return 0;
	
}

Measured memory_bytes: 1808
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <bits/stdc++.h> 
 
using namespace std;
#define ll long long
#define ld long double


int main() {
    int n;

    cin >> n;

    int a = n / 500;

    int h = a * 1000;


    n -= 500 * a;


    h += (n / 5) * 5;

    cout << h;
}

Measured memory_bytes: 256
<?php
$n = fgets(STDIN);
$t = explode(" ",fgets(STDIN));
$tt = $t;
$m = fgets(STDIN);
$p = [];
$x = [];
$ans = 0;

for($i=0;$i<=$m-1;$i++){
$pm = explode(" ",fgets(STDIN));
$p[$i] = $pm[0];
$x[$i] = $pm[1];
}

for($i=0;$i<=$m-1;$i++){
$t[$p[$i]-1] = $x[$i];
for($j=0;$j<=$n-1;$j++){
$ans +=$t[$j];
}
echo $ans."\n";
$ans = 0;
$t = $tt;
}



Measured memory_bytes: 3832
#include<stdio.h>
#define MAX 100000

typedef struct{
  char card;
  int value;
  int key;
}Roll;

int partition(Roll *A,int p,int r){
  int x = A[r].value;
  int i=p-1,j;
  Roll tmp;
  for(j=p;j<r;j++){
    
    if(A[j].value<=x){
      i+=1;
      tmp=A[i];
      A[i]=A[j];
      A[j]=tmp;
    }
  }
      tmp = A[i+1];
      A[i+1]=A[r];
      A[r]=tmp;
  

    return i+1;
}
void quickSort(Roll *A,int p,int r){
  int q;
  if(p < r){
    q = partition(A,p,r);
    quickSort(A,p,q-1);
    quickSort(A,q+1,r);
  }
}

int main(){

  Roll A[MAX];
  int i,j,n,flag=0;

  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf(" %c%d",&A[i].card,&A[i].value);
    A[i].key = i;
  }

  quickSort(A,0,n-1);

  for(i=0;i<n;i++){
    if(A[i].value==A[i+1].value&&A[i].key>A[i+1].key){
      flag=5;
      break;
    }
  }
    if(flag==5)printf("Not stable\n");
    else printf("Stable\n");
  
  for(i=0;i<n;i++) printf("%c %d\n",A[i].card,A[i].value);

  return 0;
}

Measured memory_bytes: 1780
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second

int main(){
	int n,ans=0;
	cin>>n;
	while(n>1){n=ceil(n/3.0),ans++;}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3088
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>



int main() {
  unsigned long long a, b, c, r, tmp, i, j = 0, k, num = 0,  ans = 0, K = 0;
  scanf("%llu", &K);
  for (i = 1; i <= K; i++) {
    for (j = 1; j <= K; j++) {
      a = i;
      b = j;
      /* 自然数 a > b を確認・入替 */
      if (a < b) {
        tmp = a;
        a = b;
        b = tmp;
      }

      /* ユークリッドの互除法 */
      r = a % b;
      while (r != 0) {
        a = b;
        b = r;
        r = a % b;
      }
      num = b;
      for (k = 1; k <= K; k++){ 
        b = num;
        c = k;
        /* 自然数 a > b を確認・入替 */
        if (b < c) {
          tmp = b;
          b = c;
          c = tmp;
        }

       /* ユークリッドの互除法 */
       r = b % c;
       while (r != 0) {
         b = c;
         c = r;
         r = b % c;
       }

       ans += c;
      }
    }
  }
  printf("%llu", ans);
  return 0;
}


Measured memory_bytes: 1736
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define pb push_back
#define mp make_pair
typedef long long ll;
using namespace std;
typedef pair<int, int> P;


//				x	,	y
map<int, pair<double, double> > m;
double nowx, nowy;

pair<double, double> calc_next_pos(double x, double y)
{
	pair<double, double> ret;

	double tmp_x = x, tmp_y = y;

	x *= -1.0;
	y *= -1.0;
	double rt = sqrt(x*x + y*y);
	x /= rt;
	y /= rt;

	ret.first = y + tmp_x;
	ret.second = -x + tmp_y;

	return ret;
}

int main()
{
	nowx = nowy = 1.0;

	m[2].first = 1.0;
	m[2].second = 1.0;

	pair<double, double> next;
	next = calc_next_pos(nowx, nowy);
	m[3] = next;

	int cnt = 4;

	while (cnt < 1001)
	{
		nowx = next.first;
		nowy = next.second;
		next = calc_next_pos(nowx, nowy);
		m[cnt] = next;
		cnt++;
	}

	int n;

	while (cin >> n, n != -1)
	{
		printf("%.2lf\n%.2lf\n", m[n].first, m[n].second);
	}

	return 0;
}

Measured memory_bytes: 1288
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,w) for (int i = 0;i < (w); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int INF = 1e9;

int main(){
  int n,w;cin >> n >> w;
  vector<vector<int>> item(4); 
  int wi;
  rep(i,n){
    int wt,vt;cin >> wt >> vt;
    if(i == 0) wi = wt;
    item[wt-wi].push_back(vt);
  }
  rep(i,4) {
    sort(item[i].rbegin(),item[i].rend());
    for(int j = 1;j < item[i].size();j++) item[i][j] += item[i][j-1];
  }
  //rep(i,item[1].size()) cout << item[1][i] << endl;
  ll sum = 0;
  ll ans = 0;
  rep(i,item[0].size()+1)rep(j,item[1].size()+1)rep(k,item[2].size()+1)rep(l,item[3].size()+1){
    if(ll(wi)*i+ll(wi+1)*j+ll(wi+2)*k+ll(wi+3)*l > ll(w)) continue;
    //printf("%d %d %d %d\n",i,j,k,l);
    sum = 0;
    sum += ((i > 0) ? item[0][i-1] : 0);
    sum += ((j > 0) ? item[1][j-1] : 0);
    sum += ((k > 0) ? item[2][k-1] : 0);
    sum += ((l > 0) ? item[3][l-1] : 0);
    ans = max(ans,sum);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3632
H, W = map(int, input().split())
S = [None] * H
for i in range(H):
  S[i] = input()

up = [[0 for w in range(W)] for h in range(H)]
down = [[0 for w in range(W)] for h in range(H)]
left = [[0 for w in range(W)] for h in range(H)]
right = [[0 for w in range(W)] for h in range(H)]

for h in range(H):
  for w in range(W):
    # up
    if h-1 >= 0:
      if S[h-1][w] == "#":
        up[h][w] = 0
      else:
        up[h][w] = up[h-1][w] + 1
    # left
    if w-1 >= 0:
      if S[h][w-1] == "#":
        left[h][w] = 0
      else:
        left[h][w] = left[h][w-1] + 1

    _h = H-1-h
    _w = W-1-w
    # down
    if _h+1 <= H-1:
      if S[_h+1][_w] == "#":
        down[_h][_w] = 0
      else:
        down[_h][_w] = down[_h+1][_w] + 1
    # right
    if _w+1 <= W-1:
      if S[_h][_w+1] == "#":
        right[_h][_w] = 0
      else:
        right[_h][_w] = right[_h][_w+1] + 1

ans = 0
for h in range(H):
  for w in range(W):
    if S[h][w] == "#":
      continue
    masu = 1
    masu += up[h][w]
    masu += down[h][w]
    masu += left[h][w]
    masu += right[h][w]
    if masu > ans:
      ans = masu

print(ans)


Measured memory_bytes: 187780
#include <bits/stdc++.h>
#define SIZE 10
using namespace std;
typedef unsigned long long ll;

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

	int i,j;
	int counter=0;
	ll N,A,B;
	ll tmp;
	ll answer;
	double ave;
	vector<int> given;

	cin >> N >> A >> B;

	if((B-A)%2){
		if((B-1)>(N-A)){
			answer=(N-A)-(((N-A)-(N-B))/2);
		}else{
			answer=(B-1)-(((B-1)-(A-1))/2);
		}
	}else{
		answer=(B-A)/2;
	}
	
	cout << answer << endl;

	return 0;
}


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

const int mxN = 1010, mxW = 2e4 + 5;
int N;

struct block {
	int weight, solid, value;
};

block a[mxN];
ll dp[mxN][mxW];

bool comp(const block& b1, const block& b2) {
	return (b1.weight + b1.solid < b2.weight + b2.solid);
}

ll rec(int b, int w) {
	if (b == N) {
		return 0;
	}
	ll& ret = dp[b][w];
	if (ret != -1) {
		return ret;
	}
	ret = rec(b + 1, w);
	if (a[b].solid >= w) {
		ret = max(ret, a[b].value + rec(b + 1, w + a[b].weight));
	}
	return ret;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a[i].weight >> a[i].solid >> a[i].value;
	}
	sort(a, a + N, comp);
	memset(dp, -1, sizeof(dp));
	ll ans = rec(0, 0);
	cout << ans;
	
	return 0;
}


Measured memory_bytes: 161452
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdio>
#define x first.first
#define y first.second
#define r second.first
#define color second.second

using namespace std;

typedef pair<double,double> P;
typedef pair<P,P> C;

bool check(C a,C b){
  return a.r+b.r>sqrt(pow(a.x-b.x,2)+pow(a.y-b.y,2));
}
 
int count(int bits){
  bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
  bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
  bits =(((bits >> 4) + bits) & 0x0f0f0f0f);
  bits += bits >> 8;
  return (bits + (bits >> 16)) & 0xff;
}
 
bool dp[(1<<25)];
 
int main(void){
 
	int n;
	while(cin >> n,n){
		C c[25];
		for(int i=0;i<n;i++){
			//cin >> c[i].x >> c[i].y >> c[i].r >> c[i].color;
			scanf("%lf %lf %lf %lf",&c[i].x,&c[i].y,&c[i].r,&c[i].color);
		}
		
		fill(dp,dp+(1<<n),false);
		dp[(1<<n)-1]=true;
		int ans=0;
		
		for(int S=(1<<n)-1;S>=0;S--){
			if(!dp[S])continue;
			for(int i=0;i<n;i++){
				for(int j=i+1;j<n;j++){
					
					int nx=S;
					nx&=~(1<<i);
					nx&=~(1<<j);
					if(dp[nx])continue;
					
					if(!(S>>i&1) || !(S>>j&1))continue;
					if(c[i].color!=c[j].color)continue;
					
					for(int k=0;k<n;k++){
						if(!(S>>k&1))continue;
						if((k<i && check(c[i],c[k]))||(k<j && check(c[j],c[k])))goto end;
					}
					
					dp[nx]|=dp[S];
					end:;
				}
			}
			if(dp[S])ans=max(ans,n-count(S));
		}
		cout << ans << endl;
	}
   
  return 0;
}

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

int main(){
	string s;
	cin >> s;
	vector<char> ans;
	for(int i=0;i<s.size();i++){
		if(s[i]=='0') ans.push_back('0');
		else if(s[i]=='1') ans.push_back('1');
		else if(ans.size()!=0) ans.pop_back();
	}
	for(int i=0;i<ans.size();i++){
		cout << ans[i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional> 
#include <iomanip>
#include <unordered_map>
#include <memory.h>
#include <cstring>
#include <fstream>

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	vector <int> v;
	int n, t;
	multiset <int, greater<int>> s;

	cin >> n;

	for (int i = 0; i < (1<<n); i++)
	{
		cin >> t;
		s.insert(t);
	}

	auto it = s.begin();
	v.push_back(*it);
	s.erase(it);

	while (1)
	{
		if (s.empty())
		{
			break;
		}
		int Size = v.size();
		for (int i = 0; i < Size; i++)
		{
			auto it = s.upper_bound(v[i]);
			if (it == s.end())
			{
				cout << "No" << '\n';
				return 0;
			}
			v.push_back(*it);
			s.erase(it);
		}
	}

	cout << "Yes" << '\n';

	return 0;
}

Measured memory_bytes: 13688
#include<string.h>
#include<stdio.h>

bool flag[100090];
int value[100090];

int main(){
	memset(flag,true,sizeof(flag));
	int N,M;
	scanf("%d%d",&N,&M);
	for(int i=1;i<=N;++i) scanf("%d",&value[i]);
	int ori,des;
	for(int i=1;i<=M;++i){
		scanf("%d%d",&ori,&des);
		if(value[ori]>value[des]) flag[des]=false;
		else if(value[ori]<value[des]) flag[ori]=false;
		else{
			flag[des]=false;
			flag[ori]=false;
		}
	}
	int cnt=0;
	for(int i=1;i<=N;++i)
		if(flag[i]) ++cnt;
	printf("%d ",cnt);
} 

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

int main() {
    int N;
    int a[110];
    cin >> N;
  for(int i = 0; i < N; i ++) cin >> a[i];
  
  sort(a, a + N, greater<int>());
 int A = 0;
 int B = 0;
  for(int i = 0; i<N ;i++){
      
      if (i % 2 == 0) A+=a[i];
      else B+=a[i];
  }
    
    cout << A - B << endl;
    
}
 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define ll long long
#define mp make_pair
#define pb push_back
#define fro(i,a,b)for(int i(a);i<(b);i++)
#define rep(i,n)fro(i,0,n)
const long long INF=1e9;
int w;
string s;
int main(){
	cin>>s>>w;
	int t=0;
	rep(i,s.size()){
		if(!t){cout<<s[i];t=w;}
		t--;
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

int main(void)
{
		int sum, ans=0,n,d;
		double m,p;

		scanf("%d",&n);
		scanf("%d", &d);

		int x[n][d];

		for (int i = 0;i < n;i++)
			for (int j = 0;j < d;j++)
				scanf("%d",&x[i][j]);

	for (int a = 0;a < n - 1;a++)
	{
		for (int b = a + 1;b < n;b++)
		{
			sum = 0;
			for (int i = 0;i < d;i++)
				sum += (x[a][i] - x[b][i]) * (x[a][i] - x[b][i]);
				m = sqrt((double)sum);
				
				sum = (int)m;
				p = (double)sum;
				if (m == p)
					ans++;
				

		}
	}
	printf("%d", ans);
	return 0;
}

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

int main() {
  int n,x;
  cin >> n >> x;
  vector<int> l(n);
  for(int i=0; i<n; i++) cin >> l[i];
  
  int d=0;
  int ans=1;
  for(int i=0; i<n; i++) {
    d+=l[i];
    if(d>x) break;
    ans+=1;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
<?php
$table = [];
$als = range('a', 'z');
$inf = 100;
for ($i=0; $i < count($als); $i++) { 
	$table[$als[$i]] = $inf;
}

$n = (int)trim(fgets(STDIN));

for ($i=0; $i < $n; $i++) { 
	$input = trim(fgets(STDIN));
	for ($j=0; $j < count($als); $j++) { 
		$cur_al = $als[$j];
		$cnt = substr_count($input, $cur_al);
		$table[$cur_al] = min($table[$cur_al], $cnt);
	}
}
for ($i=0; $i < count($als); $i++) { 
	$cur_al = $als[$i];
	$cur_cnt = $table[$cur_al];
	if ($cur_cnt !== $inf) {
		for ($j=0; $j < $cur_cnt; $j++) { 
			echo $cur_al;
		}
	}
}


Measured memory_bytes: 4604
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
using P = pair<int,int>;
using ll = long long;
static const int INF = 1000000000;
static const ll MOD = 1000000007;

ll gcd(ll a, ll b){return b!=0 ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}

int main(){
	int n, k;
	cin >> n >> k;
	vector<int> l(n);
	rep(i, n) cin >> l[i];
	
	sort(l.rbegin(), l.rend());
	int ans = 0;
	rep(i, k){
		ans += l[i];
	}
	
	cout << ans << endl;
	
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long 
#define ld long double
#define sz(v) int(v.size())
#define all(v) v.begin(), v.end()
 
#define y1 what

using namespace std;

const int N = (int) 2e5 + 10;
const int M = (int) 2e6 + 10;
const ll LINF = (ll) 1e18;
const int INF = (int) 1e9 + 7;
const double EPS = (double) 1e-9;
const double PI =  3.14159265359;

int n;
int a[N], b[N];   

int main() {
    #define fn "bst"
    #ifdef witch
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #else
        //freopen(fn".in", "r", stdin);
        //freopen(fn".out", "w", stdout);
    #endif
    srand(time(0));
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    int l = 1, r = n;
    for (int i = n; i >= 1; i--) {
        if ((n - i) % 2 == 0) {
            b[l] = a[i];
            l++;
        } else {
            b[r] = a[i];
            r--;
        }
    }
    for (int i = 1; i <= n; i++) {
        cout << b[i] << " ";
    }
    return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

const int mod = 998244353;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if(!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if(t & 1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
mint fact(int n) {
  if(n == 1 || n == 0) return 1;
  mint res = n;
  return res * fact(n - 1);
}

int main() {
  ll n, s;
  cin >> n >> s;
  vl a(n);
  rep(i, n) cin >> a[i];
  vector<mint> dp(s + 3010, 0);
  mint ans = 0;
  dp[0] = 1;
  rep(i, n) {
    for(int j = s; j >= 0; j--) dp[j + a[i]] += dp[j];
    dp[0] += 1;
    ans += dp[s];
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int f[100001]={0},a[100001],k,n,i,j;
int main()
{
	scanf("%d %d",&n,&k);
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(i=2;i<=n;i++)
	{
		f[i]=INT_MAX;	
		for(j=1;j<=min(k,i-1);j++)
			f[i]=min(f[i],abs(a[i]-a[i-j])+f[i-j]);
	}
	printf("%d",f[n]);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007

int main(){
  int n;
  string s;
  cin >> n >> s;
  if(n % 2 == 1){
    cout << "No" << endl;
    return 0;
  }
  int m = n/2;
  rep(i,m){
    if(s.at(i) != s.at(i+m)){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

typedef struct{
  int x,y,t;
}Point;

Point Q[10000];
int head,tail;
char map[1000][1000];
Point p,next;
int h,w,n;
int visited[1000][1000];
  

void enqueue(Point n){
  Q[tail] = n;
  tail = (tail+1)%10000;
}

Point  dequeue(){
  Point re;
  re = Q[head];
  head = (head+1)%10000;
  return re;
}


int bfs(Point start,char end){
  int i,j;
  for(i=0;i<h;i++)
    for(j=0;j<w;j++)
      visited[i][j]=0;

  head = 0;
  tail = 0;
  enqueue(start);
  while(head != tail){
    p = dequeue();

    if(map[p.x][p.y] == end) break;
    else  p.t++;

    if(p.x+1 < h &&  map[p.x+1][p.y] != 'X' && visited[p.x+1][p.y]==0){
      next=p;
      next.x++;
      enqueue(next);
      visited[next.x][next.y]=1;
    }
    if(p.x-1 >= 0 && map[p.x-1][p.y] != 'X' && visited[p.x-1][p.y]==0){
      next=p;
      next.x--;
      enqueue(next);
      visited[next.x][next.y]=1;
    }
    if(p.y+1 < w && map[p.x][p.y+1] != 'X' && visited[p.x][p.y+1]==0){
      next=p;
      next.y++;
      enqueue(next);
      visited[next.x][next.y]=1;
    }
    if(p.y-1 >= 0 && map[p.x][p.y-1] != 'X' && visited[p.x][p.y-1]==0){
      next=p;
      next.y--;
      enqueue(next);
      visited[next.x][next.y]=1;
    }
  }
  return p.t;
}
  

int main (){
  int i,j,k;
  int time;
  char hp,str[2000];
  Point start;

  scanf("%d %d %d",&h,&w,&n);
  for(i=0;i<h;i++){
    scanf("%s",str);
    for(j=0;j<w;j++){
      map[i][j] = str[j];
      if(map[i][j] == 'S'){
	start.x = i;
	start.y = j;
      }
    }
  }
  /*
  printf("\n");
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      printf("%c",map[i][j]);
    }
    printf("\n");
  }
  */
  hp=1;
  time = 0;

  while(hp<=n){
    start.t=0;
    time += bfs(start,'0'+hp);
    hp++;
    start = p;
  }
  printf("%d\n",time);

  return 0;
}

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

const int MAX = 3000003;
const int mod = 1000003;

long long fac[MAX]; //i!%mod=fac[i]
long long finv[MAX]; //pow(i!,-1)%mod=finv[i]
long long inv[MAX]; //pow(i,-1)%mod=inv[i]

// テーブルを作る前処理
void cominit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; 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;
    }
}

long long modpow(long long a,long long b)
{
	if (b==0LL)
	{
		return 1LL;
	}
	long long ans=modpow(a,b/2LL);
	ans*=ans;
	ans%=mod;
	if (b%2LL==1LL)
	{
		ans*=a;
		ans%=mod;
	}
	return ans;
}

int main(int argc, char const *argv[])
{
	cominit();
	int q;
	cin>>q;
	long long x[q],d[q],n[q];
	for (int i = 0; i < q; ++i)
	{
		cin>>x[i]>>d[i]>>n[i];
	}
	for (int i = 0; i < q; ++i)
	{
		if (d[i]==0)
		{
			cout<<modpow(x[i],n[i])<<endl;
			continue;
		}
		if (n[i]>=mod)
		{
			cout<<"0\n";
			continue;
		}
		long long nx=x[i]*inv[d[i]]%mod;
		long long ans=fac[nx+n[i]-1]*finv[nx-1]%mod;
		ans*=modpow(d[i],n[i]);
		ans%=mod;
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 73472
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int number = 3;
        int[]a = new int[3];
        for(int i = 0; i < number; i++){
            a[i] = sc.nextInt();
        }
        sc.close();
        //昇順に並び替え
        Arrays.sort(a);
        System.out.println(a[0] + a[1]);
    }
}

Measured memory_bytes: 21972
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int n;
string s;
int main() {
	cin >> n >> s;
	int out = 0;
	rep(i, n - 1) {
		bool u1[26], u2[26];
		fill(u1, u1 + 26, false);
		fill(u2, u2 + 26, false);
		rep(j, i + 1) {
			u1[s[j] - 'a'] = true;
		}
		Rep(j, i + 1, n) {
			u2[s[j] - 'a'] = true;
		}
		int c = 0;
		rep(j, 26) {
			if (u1[j] && u2[j])c++;
		}
		out = max(out, c);
	}
	cout << out << endl;
	return 0;
}

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

const int MAX_KETA = 8;

int main(){
	int n;
	cin >>n;
	for(int i = 0; i < n; i++){
		int min, max, str[MAX_KETA];
		string input;
		cin >>input;
		for(int j = MAX_KETA - 1, k = 0; j >= 0; j--, k++){
			str[k] = input[j] - '0';
		}
		sort(str, str + MAX_KETA);
		int sum = 0, keta = 1;
		for(int j = 0; j < MAX_KETA; j++){
			sum += str[j] * keta;
			keta *= 10;
		}
		max = sum;
		sum = 0;
		keta = 1;
		for(int j = MAX_KETA - 1; j >= 0; j--){
			sum += str[j] * keta;
			keta *= 10;
		}
		min = sum;
		
		cout <<max - min <<endl;
	}
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int>h(n);
  rep(i,n) cin >> h[i+1];
  int res = 1;
  int max_hight = h[1];
  for (int i = 2; i < (n+1); ++i){
    max_hight = max(max_hight, h[i]);
    if(max_hight <= h[i]) res++;
    else continue;
  }

  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
    	Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        long A[] = new long[N];
        long ans = 0;
        long ans2 = 0;
        Arrays.fill(A, 0);

        for(int cnt = 0; cnt < N; cnt++){
        	A[cnt] = in.nextLong();
        }

        Arrays.sort(A);

        for(int cnt = N - 1; cnt > 0; cnt--){
        	if(A[cnt] == A[cnt-1]){
        		if(A[cnt] > ans){
        			ans = A[cnt];
        			cnt--;
        		}
        		else if(A[cnt] > ans2){
        			ans2 = A[cnt];
        			cnt--;
        		}
        	}
        }
        System.out.println(ans * ans2);

    }
}

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

  const int MOD = 1000000007;

  //long long
  using ll = long long;

  //出力系
  #define print(x) cout << x << endl
  #define yes cout << "Yes" << endl
  #define YES cout << "YES" << endl
  #define no cout << "No" << endl
  #define NO cout << "NO" << endl
  
  // begin() end()
  #define all(x) (x).begin(),(x).end()

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

  //最大公約数（ll）
  ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x;}

  //素因数分解
  vector<pair<ll, int>>factorize(ll n){
    vector<pair<ll, int>> res;
    for(ll i = 2; i * i <= n; ++i){
      if(n % i) continue;
      res.emplace_back(i, 0);
      while(n % i == 0){
        n /= i;
        res.back().second++;
      }
    }
  if(n != 1) res.emplace_back(n, 1);
  return res;
  }



int main(){
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;

  int dx = tx - sx, dy = ty - sy;

  cout << string(dy, 'U') << string(dx, 'R');
  cout << string(dy, 'D') << string(dx, 'L');
  cout << 'L' << string(dy + 1, 'U') << string(dx + 1, 'R') << 'D';
  cout << 'R' << string(dy + 1, 'D') << string(dx + 1, 'L') << 'U';

}


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

int main(){
	string s;
	cin >> s;
	int len = s.size();
	int num=0;
	string s1 = "";
	string s2 = "";
	for(int i=0;i<len;i++){
		s1+=s[i];
		if(s1==s2){
			continue;
		}
		else{
			s2=s1;
			s1="";
			num++;
		}
	}
	cout << num << endl;
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  int n_1 = N / 1000;
  int n_2 = N / 100 - n_1 * 10;
  int n_3 = N / 10 - n_2 * 10 - n_1 * 100;
  int n_4 = N % 10;
  if (n_2 == n_3){
    if(n_1 == n_2 || n_3 == n_4){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
#%%code
def resolve():
    S=input()
    n=len(S)
    
    S2=[0]*n
    digit=0
    for i in range(n-1,-1,-1):
        s=int(S[i])
        S2[i]=(s*pow(10,digit,2019))%2019
        digit+=1
    #print(S2)

    S3=[0]*n;subsum=0
    for j,s2 in enumerate(S2):
        subsum+=s2;subsum%=2019;S3[j]=subsum
    S3.append(0)
    #print(S3)

    from collections import Counter
    c=Counter(S3).values()
    ans=0
    for k in c:
        if k>1:
            ans+=(k*(k-1))//2
    print(ans)
#%%submit!
resolve()

Measured memory_bytes: 23936
import sys
from decimal import *
import math
def input(): return sys.stdin.readline().rstrip()

def main():
    A, B = input().split()
    A = Decimal(A)
    B = Decimal(B)
    ans = A * B
    ans.quantize(Decimal('0'), rounding=ROUND_DOWN)
    print(int(ans))

if __name__ == '__main__':
    main()


Measured memory_bytes: 10008
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main{
	static IntStream REPS(int v){return IntStream.range(0,v);}
	static IntStream REPS(int l,int r){return IntStream.rangeClosed(l,r);}
	static IntStream INS(int n) {return REPS(n).map(i->getInt());}
	static Scanner s=new Scanner(System.in);
	static int getInt(){return Integer.parseInt(s.next());}
	public static void main(String[]$){
		int n=getInt(),cn=n;
		int rn=0;
		while(cn!=0) {
			rn*=10;
			rn+=cn%10;
			cn/=10;
		}
		System.out.println(rn==n?"Yes":"No");
	}
}

Measured memory_bytes: 23764
import java.util.*;

public class Main {
    public static void main(String[] args) {

      Scanner sc = new Scanner(System.in);
      
      int n = sc.nextInt();
      int m = sc.nextInt();
      int ans;
      
      ans = (n-1) * (m-1);
      System.out.println(ans);

      sc.close();
    }
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

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

    // start
    char a, b;
    cin >> a >> b;
    if(a==b)
        cout << "H" << endl;
    else
        cout << "D" << endl;
    // end

    return 0;
}


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

using namespace std;

int main(){
    int n,m;
    while(true){
        cin>>n>>m;
        if(n==0&&m==0)break;
        vector<pair<int,int>> e;
        for (int i = 0; i < n; ++i) {
            int a,b;
            cin>>a>>b;
            e.emplace_back(b,a);
        }
        sort(e.rbegin(),e.rend());
        long long ans=0;
        for (int i = 0; i < n; ++i) {
            if(m<=0)ans+=e[i].first*e[i].second;
            else {
                if(e[i].second<=m){
                    m-=e[i].second;
                    e[i].second=0;
                }
                else{
                    e[i].second-=m;
                    m=0;
                    ans+=e[i].first*e[i].second;
                }
            }
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 3132
#include <iostream>
using namespace std;
int main(){
	int c1,c5,c10,c50,c100,c500;
	int a[8]={1,5,10,50,100,500};
	cin>>c1>>c5>>c10>>c50>>c100>>c500;
	int n=c1*a[0]+c5*a[1]+c10*a[2]+c50*a[3]+c100*a[4]+c500*a[5];
	if(n>=1000){
		cout<<"1"<<endl;
	}else{
		cout<<"0"<<endl;
	}

}

Measured memory_bytes: 1160