akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i))
using ll = long long;
using namespace std;

ll D;
string N;
ll dp[101010][101][2];
ll mod = 1e9 + 7;

ll solve(int i, int md, bool b) {
    if (i >= N.size()) {
        return md == 0;
    }
    ll& ret = dp[i][md][b];

    if (~ret) return ret;
    ret = 0;

    int x = N[i] - '0';
    for (int d=0; d<=(b ? 9 : x); ++d) {
        ret += solve(i+1, (md + (d % D)) % D, (b or d < x));
        ret %= mod;
    }

    return ret;
}

int main() {
    cin >> N >> D;
    //rep(i, 101010) rep(j, 101) rep(k, 2) dp[i][j][k] = -1;
    dp[0][0][0] = 1;
    rep(i, N.size()) rep(j, 101) rep(k, 2) {
        int x = N[i] - '0';
        for (int d=0; d<=(k ? 9 : x); ++d) {
            dp[i+1][(j + (d % D))%D][k or d < x] += dp[i][j][k];
            dp[i+1][(j + (d % D))%D][k or d < x] %= mod;
        }
    }

    cout << ( (dp[N.size()][0][1] % mod) + (dp[N.size()][0][0] % mod) - 1 + mod) % mod << endl;
}


Measured memory_bytes: 16640
#include<bits/stdc++.h>
using namespace std;int N,C,D[2][5001],i,j,*A,*B;main(){A=*D;B=D[1];cin>>N;fill_n(*D,1e4+2,1e9);A[1]=*B=0;for(;++i<N&&cin>>C;)for(j=N/2;~j;)A[j+1]=min(A[j],B[j]+C),B[j--]=min(A[j]+C,B[j]);cout<<min(A[N/2],B[N/2])<<endl;}

Measured memory_bytes: 1200
// ctrl+shift+b
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll A, B; cin >> A >> B;
    if (A % 2 == 1 && B % 2 == 1){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3652
using System;
using System.Linq;
using System.IO;
using System.Collections.Generic;
using static System.Math;

class P
{
  static int[] Input(){
    return Console.ReadLine().Split().Select(int.Parse).ToArray();
  }
  static int[][] Input2(int n){
    int[][] X = new int[n][];
    for(int i = 0; i < n; i++){
      X[i] = Input();
    }
    return X;
  }
  static void Main()
  {
    int[] NK = Input();
    int N = NK[0];
    int[] X = Input();
    int tt = Abs(X[0]);
    for(int i=0;i<N;i++){
      if (i!=N-1){
        tt += Abs(X[i+1]-X[i]);
      }else{
        tt += Abs(X[i]);
      }
    }
    var sw = new StreamWriter(Console.OpenStandardOutput()){AutoFlush = false};
    Console.SetOut(sw);
    for(int i=0;i<N;i++){
      if (i!=N-1 && i!=0){
        Console.WriteLine(tt - Abs(X[i+1]-X[i])-Abs(X[i]-X[i-1])+Abs(X[i+1]-X[i-1]));
      }
      if (i==0){
        Console.WriteLine(tt - Abs(X[i+1]-X[i])-Abs(X[i])+Abs(X[i+1]));
      }
      if (i==N-1){
        Console.WriteLine(tt - Abs(X[i])-Abs(X[i]-X[i-1])+Abs(X[i-1]));
      }
    }
    Console.Out.Flush();
  }
}


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

using namespace std;
#define ll  long long
#define ld  long double
#define endl '\n'
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793238463;
const int MAXN = 1e5 + 5;

void debug_out() {
    cerr << endl;
}

template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

int main() {
    FAST
    int n, a, b, c;
    cin>>n>>a>>b>>c;
    bool flag=1;
    vector<char> v;
    string arr[n];
    for (int i = 0; i < n; i++) {
        cin>>arr[i];

    }
    for(int i=0;i<n;i++)
    {
        string h=arr[i];

        if (h[0] == 'A' && h[1] == 'B') {
            if(a == 1 && b == 1 && c == 0 && i < n -1 && arr[i + 1] == "BC"){
                a--;
                b++;
                v.push_back('B');
            }
            else if(a == 1 && b == 1 && c ==0 && i < n -1 && arr[i + 1] == "AC"){
                a++;
                b--;
                v.push_back('A');
            }
            else {
                if (a > b) {
                    a--;
                    b++;
                    v.push_back('B');
                } else {
                    a++;
                    b--;
                    v.push_back('A');
                }
            }
        } else if (h[0] == 'A' && h[1] == 'C') {

            if(a == 1 && b == 0 && c ==1 && i < n -1 && arr[i + 1] == "BC"){
                a--;
                c++;
                v.push_back('C');
            }
            else if(a == 1 && b == 0 && c == 1 && i < n -1 && arr[i + 1] == "AB"){
                a++;
                c--;
                v.push_back('A');
            }
            else {
                if (c > a) {
                    a++;
                    v.push_back('A');
                    c--;
                } else {
                    a--;
                    c++;
                    v.push_back('C');
                }
            }
        }
        else{
            if(a == 0 && b == 1 && c == 1 && i < n -1 && arr[i + 1] == "AC"){
                b--;
                c++;
                v.push_back('C');
            }
            else if(a == 0 && b == 1 && c == 1 && i < n -1 && arr[i + 1] == "AB"){
                c--;
                b++;
                v.push_back('B');
            }
            else {
                if (c > b) {
                    b++;
                    v.push_back('B');
                    c--;
                } else {
                    b--;
                    c++;
                    v.push_back('C');
                }
            }
        }
        if(a<0 || b<0 || c<0)
        {
            flag=0;
            break;
        }

    }

    if(flag)
    {
        cout<<"Yes"<<endl;
        for(int i=0;i<(int)v.size();i++)
            cout<<v[i]<<endl;
    } else{
        cout<<"No"<<endl;
    }

    return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> pa;

#define fst first
#define snd second
#define pb push_back

const int maxn=500005,maxm=512;
const double pi=acos(-1.0);
//const ll mod=1000000007;
const ll mod=1000000007;
const double eps=1e-8;

int n,k;

int a[maxn];

ll ans=0;
vector<ll> ve[2];
int nz=0,np,nn;


int sgn()
{
    int i,j,l;
    for(i=0;i<=k&&i<=nn;i+=2)
    {
        if(k-i<=np) return 1+i;
    }
    if(nz==0) return -1;
    return 0;
}

int cal()
{
    int i,j;
    if(k>np+nn) return 0;
    int sgnn=sgn();
    if(sgnn==0) return 0;
    if(sgnn==-1)
    {
        i=j=0;ll ans=1;
        while(i+j<k&&i<np&&j<nn)
        {
            if(ve[0][i]<ve[1][j]) ans=ans*ve[0][i]%mod,++i;
            else  ans=ans*ve[1][j]%mod,++j;
        }
        for(;i<np&&i+j<k;i++)
        {
            ans=ans*ve[0][i]%mod;
        }
        for(;j<nn&&i+j<k;j++)
        {
            ans=ans*ve[1][j]%mod;
        }
        return (mod-ans)%mod;
    }
    ll ans=1;--sgnn;
    i=k-sgnn;j=sgnn;
    for(;i-2>=0&&j+2<=nn;)
    {
        ll t1=ve[0][np-i]*ve[0][np-i+1];
        ll t2=ve[1][nn-j-1]*ve[1][nn-j-2];
        if(t1>=t2) break;
        else i-=2,j+=2;
    }
    for(int l=np-1;l>=np-i;l--) ans=ans*ve[0][l]%mod;
    for(int l=nn-1;l>=nn-j;l--) ans=ans*ve[1][l]%mod;
    return ans;
}

int main()
{
	int i,j;
	scanf("%d %d",&n,&k);
	for(i=0;i<n;i++)
    {
        int x;scanf("%d",&x);
        if(x==0) ++nz;
        else if(x>0) ve[0].pb(x);
        else ve[1].pb(-x);
    }
    sort(ve[0].begin(),ve[0].end());
    sort(ve[1].begin(),ve[1].end());
    np=ve[0].size();nn=ve[1].size();
    printf("%d\n",cal());
    return 0;
}


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

int gcd(long long a, long long b){
  long long M = max(a, b), m = min(a, b);
  while(m != 0){
  	long long r = M%m;
    M = m; m = r;
  }
  return M;
}

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

int main(){
  string s;
  cin >> s;
  int n = s.size();
  int a = 0, b = 0;
  for(int i = 0; i < n; i++){
  	if(i%2 == 0){
    	if(s.at(i) == '0'){
        	a++;
        }
    	else{
        	b++;
        }
    }
  
  	else{
    	if(s.at(i) == '1'){
        	a++;
        }
    	else{
        	b++;
        }
    }
  }
  cout << n - max(a, b) << endl;
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;



int n;
vector<int> g[maxn];
bool added[maxn];
int val[maxn];



ll ans = 0;

void dfs(int at, int p=-1) {
    for (int to: g[at]) {
	if (to == p) continue;
	ans += min(val[at],val[to]);
	dfs(to, at);
    }
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    cin>>n;
    for (int i=0; i<n-1; i++) {
	int u,v; cin>>u>>v;
	g[u].push_back(v);
	g[v].push_back(u);
    }

    int x=1;
    for (int i=1; i<=n; i++) {
	if (g[i].size()>g[x].size()) {
	    x=i;
	}
    }

    priority_queue<pair<int,int>> pq;
    pq.push({g[x].size(),x});
    added[x]=true;


    

    vector<int> c(n);
    for (int i=0; i<n; i++) {
	cin>>c[i];
    }
    sort(c.begin(), c.end());



    
   
    while (pq.size()) {
	auto at = pq.top().second;
	pq.pop();
	for (int to: g[at]) {
	    if (added[to]) continue;
	    pq.push({g[to].size(),to});
	    added[to]=true;
	}
	assert(c.size());
	val[at] = c.back();
	c.pop_back();
    }


    dfs(1);
    cout<<ans<<"\n";
    for (int i=1; i<=n; i++) {
	cout<<val[i]<<" ";
    }
    cout<<endl;
    
    return 0;
}


Measured memory_bytes: 27968
fun main(args:Array<String>) {
    val n = readLine()!!.toInt()
    val b = readLine()!!.split(" ").map { it.toInt() }
    var before = 0
    var result = b[0]
    for (i in 0..n - 2) {
        if (before > b[i]) {
            result += b[i]
        } else {
            result += before
        }
        before = b[i]
    }
    result += before
    println(result)
}

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repp(i, n, m) for(int (i) = (n); (i) < (m); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 5000*5000+5;

/* ...o(^-^)o... */

int n;
int id(int i){
    if(i < 0) return n+i;
    if(i >= n) return i-n;
    return i;
}

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

    queue<int> que;
    rep(i, n){
        if(b[i] > a[i] && b[i]>b[id(i-1)]+b[id(i+1)]){
            que.push(i);
        }
    }

    lint res = 0;
    while(!que.empty()){
        int i = que.front(); que.pop();

        lint sur = min(b[i]-a[i], b[i]-b[id(i+1)]-b[id(i-1)]) - 1;
        lint c = sur / (b[id(i+1)]+b[id(i-1)]) + 1;
        res += c;
        b[i] -= c * (b[id(i+1)]+b[id(i-1)]);

        if(b[id(i-1)] > a[id(i-1)] && b[id(i-1)]>b[i]+b[id(i-2)]) que.push(id(i-1));
        if(b[id(i+1)] > a[id(i+1)] && b[id(i+1)]>b[i]+b[id(i+2)]) que.push(id(i+1));
    }

    bool isok = true;
    rep(i, n){
        if(a[i] != b[i]) isok = false;
    }
    if(!isok){
        out(-1); return 0;
    }
    out(res);
}

Measured memory_bytes: 3840
#include <iostream>

using namespace std;

int main(void)
{
    int a, b, c, d;

    cin >> a >> b >> c >> d;

    if(a+b>c+d){
        cout << "Left" << endl;
    }
    
    else if(a+b<c+d){
        cout << "Right" << endl;
    }

    else{
        cout << "Balanced" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef vector <ll> vi;
int main()
{
  int n,q;
  cin>>n>>q;
  vi a(n);
  for(ll i=0;i<n;i++)
    cin>>a[i];
  sort(a.begin(),a.end());
  vector <pair <ll,ll> > b(q,make_pair(0,0));
  for(ll i=0;i<q;i++)
  {
    cin>>b[i].second>>b[i].first;
  }
  sort(b.rbegin(),b.rend());
  ll index=0;
  for(ll i=0;i<q && index<n ;i++)
  {
    ll num=b[i].second;
    ll ele=b[i].first;
    if(ele<=a[index])
    {
      break;
    }
    else
    {
      for(ll j=0;j<num && index<n;j++)
      {
        if(a[index]<ele)
        {
          a[index]=ele;
          index++;
        }
        else
        {
          	index=n;
         	 break;
        }
        
      }
    }
    //sort(a.begin(),a.end());
  }
  ll sum=0;
  for(ll i=0;i<n;i++)
  {
    	sum+=a[i];
  }
  cout<<sum<<endl;
}
  






Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
const int MOD = 1e9 + 7;

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

    string N;
    cin >> N;

    int nlen = N.length();
    vector<vector<int>> dp(nlen + 5, vector<int>(2, 1e9));
    dp[0][0] = 0;
    for (int i = 0; i < nlen; ++i) {
        int num = N[nlen - i - 1] - '0';
        dp[i + 1][0] = num + min(dp[i][0], (num < 9 ? dp[i][1] + 1 : (int)1e9));
        dp[i + 1][1] = 10 - num + min(dp[i][0], dp[i][1] - 1);
    }

    cout << min(dp[nlen][0], dp[nlen][1] + 1) << endl;

    return 0;
}


Measured memory_bytes: 55964
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")

#pragma GCC target("avx,avx2")
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ll=long long ;
#define Whats(x) //cout<<#x<<" is "<<(x)<<endl
string ans;
vector<ll>nums(100);
vector<ll>tos(100);

ll int_pow(ll x, int cnt) {
	ll sum=1;
	for(int i=0;i<cnt;++i)sum*=x;
	return sum;
}

void solve(string nst,int rest_keta,vector<int>used_num,ll need) {
	if (rest_keta == 0) {
		assert(need==0);
		ans=nst;
		return;
	}
	if (used_num.empty()) {
		for (int x = 1; x <= 9; ++x) {
			ll cnt=nums[rest_keta]/9;
			if (need >= cnt) {
				need-=cnt;
			}
			else {
				solve(string(1, '0' + x), rest_keta - 1, vector<int>{x},need);
				return;
			}
		}
	}
	else if (used_num.size() == 1) {
		for (int x = 0; x <= 9; ++x) {
			ll cnt;
			if (x != used_num[0]) {
				cnt=int_pow(2,rest_keta-1);
			}
			else {
				cnt=tos[rest_keta-1];
			}
			vector<int>av(used_num);
			av.push_back(x);
			sort(av.begin(),av.end());
			if(av[0]==av[1])av.pop_back();
			if (need >= cnt) {
				need -= cnt;
			}
			else {
				nst.push_back('0'+x);
				solve(nst, rest_keta - 1, av, need);
				return;
			}
		}
	}
	else {
		for (int i = 0; i < 2; ++i) {
			int x=used_num[i];
			ll cnt=int_pow(2,rest_keta-1);

			if (need >= cnt) {
				need-=cnt;
			}
			else {
				nst.push_back('0'+x);
				solve(nst,rest_keta-1,used_num,need);
				return;
			}
		}
	}
}

int main() {
	nums[2]=81;
	for (int x = 3; x < 100; ++x) {
		nums[x]=nums[x-1]*2+81;
		if(nums[x]>=1e18)break;
		Whats(nums[x]);
	}
	tos[1]=9;
	for (int x = 2; x < 100; ++x) {
		tos[x]=tos[x-1]+9*int_pow(2,x-1);
		if(tos[x]>=1e18)break;
		Whats(tos[x]);
	}
	while (true) {
		ll sum=0;
		ll N;cin>>N;
		if(!N)break;
		N--;
		int keta=2;
		while (true) {
			if(sum+nums[keta]>N)break;
			else sum+=nums[keta];

			keta++;
		}
		Whats(keta);
		ll need=N-sum;
		Whats(need);
		solve("",keta,vector<int>(),need);
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 3204
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
typedef long long ll;



int main(){

    while(true){
        int n;
        cin>>n;
        if(n==0)break;
        
        vector<int> ans;
        REP(i,n){
            int sum=0;
            REP(j,5){
                int t; cin>>t;
                sum+=t;
            }
            ans.push_back(sum);
        }
        
        sort(ans.begin(),ans.end());
        cout<<ans[ans.size()-1]<<" "<<ans[0]<<endl;
        
    }
    
    return 0;
}

Measured memory_bytes: 3080
/**
    BISMILLAH
    @Author : Arham
*/
#include <bits/stdc++.h>
#define endl "\n"
#define found true
#define infinity -1
#define not_found false
#define FOR(limit) for(int i = 0; i < limit; i++)
#define __FOR(limit) for(int j = 0; j < limit; j++)
#define __FOR__(limit) for(int k = 1; k <= limit; k++)
#define hello(a) a ? "Yes" : "No"
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define F first
#define S second
// getline (cin, string);
typedef long long lld;
using namespace std;
void solving_f();
int main() {
    ios_base::sync_with_stdio(not_found);
//    cin.tie(0);
//    cout.tie(0);

//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    solving_f();

    return not_found;
}
void solving_f() {
    lld n, d, d1, d2, temp;
    cin >> n >> d;
    vector < pair < lld, lld > > v;
    vector < pair < lld, lld > > :: iterator it;
    __FOR__ (n) {
        lld val, value;
        cin >> val >> value;
        v.pb(mp(val, value));
    }
    int count = not_found;
    for(it = v.begin(); it < v.end(); it++) {
        d1 = it -> F;
        d2 = it -> S;
        d1 *= d1;
        d2 *= d2;
        temp = d1 + d2;
        if(temp <= d*d)
            count++;
    }
    cout << count << endl;
}


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

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  
  
  if ((d >= abs(c - a))|| (d >=abs( b-a) && d>=abs( c-b)))  cout << "Yes" << endl;
  else cout <<"No" << endl;
  
  
  
  

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<string>
#include<set>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<functional>
using namespace std;
#define LL long long
#define MOD 100000
#define inf 1999999999

string s, bef = "";
int k = 0;

int main() {
	cin >> s;
	string tmp = "";
	for (int i = 0; i < s.size(); i++) {
		tmp += s[i];
		if (tmp != bef) {
			bef = tmp;
			tmp = "";
			k++;
		}
	}

	cout << k << endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    string ans ="";
    rep(i,n)ans+="x";
    cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
n, m = gets.split.map(&:to_i)

prob_pens = Array.new(n + 1, 0)
accepted = Array.new(n + 1, false)

m.times do
  prob, result = gets.chomp.split(' ')
  if result == 'AC' || accepted[prob.to_i] == true
    accepted[prob.to_i] = true
    next
  end
  prob_pens[prob.to_i] += 1
end

acs = accepted.find_all { |i| i == true }.size
accepted.each_with_index do |res, idx|
  prob_pens[idx] = 0 unless res
end
pens = prob_pens.inject(:+)

puts [acs, pens].join(' ')

Measured memory_bytes: 4220
def g;gets.split.map &:to_i;end
while(n,m=g)[0]>0
d=(0..n).map{[]}
m.times{s,t=g;d[s]<<t;d[t]<<s}
l=[0]+g
r=[0]+(1..n).map{g[1..-1].sort}
h={l<<1=>[]}
q=l[1]<1?[]:[l]
q.map{|w|*t,a=w
d[a].map{|i|t[i]>0&&h[v=t+[i]]||=(q<<v;["Move to room #{i}.",w])}
r[a].map{|i|u=w.dup;v=u[i]^=1;a!=i &&h[u]||=(q<<u;["Switch o#{v>0??n:"ff"} room #{i}.",w])}}
puts (h[c=[0]*n+[1,n]])?(s=[]
s=[l]+s while(l,c=h[c])[1]
["You can go home in #{s.size} steps."]+s):h.all?{|k,v|k[n+1]<n}?"Help me!":"You can not switch off all lights."
end

Measured memory_bytes: 36036
n = gets.to_i
a, b, c = 3.times.map { gets.split.map(&:to_i) }

b_sum = b.reduce(&:+)
c_sum = (1..n).reduce(0) { |s, i| a[i] == a[i - 1] + 1 ? s += c[a[i - 1] - 1] : s }

p b_sum + c_sum

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define ld long double
#define fi first
#define se second
#define all(uiet) uiet.begin(),uiet.end()
#define read(UIET) for(int i = 0; i < n; ++i) cin >> UIET[i]
#define out(UIET) for(int i = 0; i < n; ++i) cout << UIET[i] << " "
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vpp vector<pair< int, int > >
#define pll pair<int , int >
#define ppll pair < pll , pll >
#define debug(n1) cout << n1 << endl
#define len(a) ((int) (a).size())
#define endl "\n"
#define mod 1000000007
const int INF=(1LL<<60)-1;
bool isPerfectSquare(long double x) {   
    long double sr = sqrt(x); 
    return ((sr - floor(sr)) == 0); 
} 
bool isPrime(int x){
    for(int i = 2; i * i <= x; ++i){
        if(x % i == 0) return 0;
    }
    return 1;
}
int fun(int n){
    if(n & 1) return 3 * n + 1;
    else return n/2;
}
int32_t main(){
    SPEED;
    int h;
    cin >> h;
    if(h == 1) cout << 1;
    else{
        int ans = 0;
        for(int i = 1; i <= 1000000; ++i){
            h /= 2;
            if(h <= 0) break;
            ans += pow(2, i);
        }
        cout << ans + 1;
    }
}


Measured memory_bytes: 4068
#include <bits/stdc++.h>
 
using namespace std;
 
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
 
template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}
 
int gcd(int a, int b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}
 
long long lcm (int a, int b){
    return  (long long) a*b /gcd(a,b);
}
 
 
 
int main(){
    int N;
    cin >> N;

    vector<int>A(N);
    rep(i,N) cin >> A[i];

    sort(A.begin(),A.end());
    rep(i,N-1){
        if(A[i] == A[i+1]){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;


 
}

Measured memory_bytes: 3968
def sod(n):
    o=n//10000
    p=(n//1000)%10
    q=(n//100)%10
    r=(n//10)%10
    s=n%10
    return o+p+q+r+s

N,A,B=map(int,input().split())
ans=0
for i in range(1,N+1):
    if A<=sod(i)<=B:
        ans+=i
print(ans)

Measured memory_bytes: 39280
#include <stdio.h>
#define MAX_N (12)

int main(void) {
	int ary[MAX_N], tmp[MAX_N];
	size_t n, i, k, num;
	const char *fmt;

	while (1) {
		scanf("%d", &n);
		if (!n)
			break;

		for (i = 0; i < n; i++) {
			scanf("%d", ary+i);
		}

		for (num = 0;; num++) {
			for (i = 0; i < n; i++) {
				tmp[i] = 0;
				for (k = 0; k < n; k++) {
					tmp[i] += (ary[i] == ary[k]);
				}
			}

			k = 1;
			for (i = 0; i < n; i++) {
				if (ary[i] != tmp[i]) {
					k = 0;
					break;
				}
			}
			if (k)
				break;

			for (i = 0; i < n; i++) {
				ary[i] = tmp[i];
			}
		}

		printf("%d\n", num);
		fmt = "%d";
		for (i = 0; i < n; i++) {
			printf(fmt, ary[i]);
			fmt = " %d";
		}
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <vector>
#include<cmath>
#include <set>
#include <map>
#include<cstring>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
#define ll long long
#define N 200005
#define fori for(i=0;i<n;i++)
#define fori1 for(i=1;i<=n;i++)
const int mod = 1e9 + 7;
ll a[3*N];//开三倍
char s[N];
ll degree[N];
ll b[3*N];
ll vis[N];
int main()
{

	ll i, j, k;
	ll n, sum,m;
	ll flag = 1, maxn = 0, minn = mod;
	cin >> n >> m;
	cout << (n * n - m) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    Edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<Edge>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reprep(i,j,w,h) rep(j,h)rep(i,w)
#define rrep(i,m, n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> a(n);rep(i,n)std::cin >> a[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<int>(n,a)));
typedef long long ll;
const int INF = 2000000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
typedef unsigned int uint;
int main(){
  string s;
  int x,y;
  std::cin >> s;
  std::cin >> x>>y;
  std::vector<int> dum;
  int c=0;
  rep(i,s.size()){
    if(s[i]=='F')c++;
    else{
      dum.pb(c);
      c=0;
    }
  }
  if(c!=0)dum.pb(c);
  std::vector<int> tate,yoko;
  x-=dum[0];
  rrep(i,1,dum.size()){
    if(pow(-1,i)==1)yoko.pb(dum[i]);
    else tate.pb(dum[i]);
  }
  int ys=yoko.size(),ts=tate.size();
  vvector(ydp,bool,ys+1,20000,0);
  vvector(tdp,bool,ts+1,20000,0);
  ydp[0][10000]=1;
  tdp[0][10000]=1;
  rep(i,ts){
    rep(j,20000){
      if(tdp[i][j]){
        tdp[i+1][j+tate[i]]=1;
        tdp[i+1][j-tate[i]]=1;
      }
    }
  }
  rep(i,ys){
    rep(j,20000){
      if(ydp[i][j]){
        ydp[i+1][j+yoko[i]]=1;
        ydp[i+1][j-yoko[i]]=1;
      }
    }
  }
  if(x+10000>19999||x+10000<0){
    std::cout << "No" << std::endl;
    exit(0);
  }
  if(ydp[ys][10000+x]&&tdp[ts][y+10000])std::cout << "Yes" << std::endl;
  else std::cout << "No" << std::endl;
}

Measured memory_bytes: 20096
#include "bits/stdc++.h"
 
using namespace std;
 
using ld = double;
const ld eps = 1e-9, pi = acos(-1.0);
 
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    int n;
    cin >> n;
    vector<ld> rr(n);
    for (int i = 0; i < n; i++)
        cin >> rr[i];
    sort(rr.begin(), rr.end());
    ld ret = 0;
    for (int b = 1; b < (1 << n); b++)
    {
        vector<ld> r;
        for (int i = 0; i < n; i++)
        {
            if ((b >> i) & 1)
                r.push_back(rr[i]);
        }
        int sz = r.size();
        if (sz < 3)
            continue;
        do
        {
            //
            ld lb = 0, ub = pi, ar = 0, sum = 0;
            for (int i = 0; i < 100; i++)
            {
                auto mid = (lb + ub) / 2;
                sum = 0;
                ar = 0;
                for (int j = 0; j < sz; j++)
                {
                    auto tmp = acos(max((ld)-1.0, min((ld)1.0, r[0] * r[1] / r[j] / r[(j + 1) % sz] * cos(mid))));
                    ar += 0.5 * r[j] * r[(j + 1) % sz] * sin(tmp);
                    sum += tmp;
                }
                if (sum < 2 * pi)
                    lb = mid;
                else
                    ub = mid;
            }
            if (abs(sum - 2 * pi) < eps)
                ret = max(ret, ar);
        } while (next_permutation(r.begin() + 1, r.end()));
    }
    cout << fixed << setprecision(10) << ret << endl;
}


Measured memory_bytes: 3652
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <list>
#include <stack>

using namespace std;

int main()
{
	int h, w;
	cin >> h >> w;
	int c[10][10];
	for (int i = 0; i < 10; i++)
		for (int j = 0; j < 10; j++)
			cin >> c[i][j];
	int a[10];
	for (int i = 0; i < 10; i++)
		a[i] = 0;
	for (int i = 0; i < h * w; i++)
	{
		int b;
		cin >> b;
		if (b == -1)
			continue;
		a[b]++;
	}

	int cost[10];
	cost[1] = 0;
	//	iから1への最小コストを求める
	for (int i = 0; i < 10; i++)
	{
		if (i == 1)
			continue;
		int line[10];
		for (int j = 0; j < 10; j++)
			if (j == i)
				line[j] = INT_MAX;
			else
				line[j] = c[i][j];
		while (1)
		{
			int now = 0;
			for (int j = 0; j < 10; j++)
				if (line[j] < line[now])
					now = j;
			if (now == 1)
				break;
			for (int j = 0; j < 10; j++)
				if (now == j)
					continue;
				else if (line[j] > line[now] + c[now][j])
					line[j] = line[now] + c[now][j];
			line[now] = INT_MAX;
		}
		cost[i] = line[1];
	}

	int result = 0;
	for (int i = 0; i < 10; i++)
		result += a[i] * cost[i];
	printf("%d", result);

	return 0;
}


Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N,M = map(int, input().split())
uf = UnionFind(N)
for i in range(M):
    a,b = map(int,input().split())
    uf.union(a-1, b-1)
print(uf.group_count() - 1)

Measured memory_bytes: 12928
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef long long ll;
typedef char keytype;

void quicksort_des(keytype a[], int first, int last)
{
    int i, j;
    keytype x, t;

    x = a[(first + last) / 2];
    i = first;  j = last;
    for ( ; ; ) {
        while (a[i] > x) i++;
        while (x > a[j]) j--;
        if (i >= j) break;
        t = a[i];  a[i] = a[j];  a[j] = t;
        i++;  j--;
    }
    if (first  < i - 1) quicksort_des(a, first , i - 1);
    if (j + 1 < last) quicksort_des(a, j + 1, last);
}

int main(){
    char s[5];

    scanf("%s", s);

    quicksort_des(s, 0, 3);

    if(s[0] == s[1] && s[2] == s[3] && s[0] != s[2]) puts("Yes");
    else puts("No");

    return 0;
}


Measured memory_bytes: 1624
from functools import reduce

def main():
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10

    # 1文字のみを読み込み
    # s = input().rstrip()
    
    # スペース区切りで標準入力を配列として読み込み
    # s = input().rstrip().split(' ')

    # 1文字ずつ標準入力を文字列として読み込み
    # s = list(input().rstrip())
    
    # 位置文字ずつ標準入力を数値配列として読み込み
    X = [int(_) for _ in input().split()]
    N = X[0]
    K = X[1]
    print(K*(K-1)**(N-1))
if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
s = input()
key = "keyence"
j = 0
while j < len(key) and s[j] == key[j]:
    j += 1

j -= 1
for i in range(len(key) - j - 1):
    if s[len(s) - 1 - i] != key[len(key) - 1 - i]:
        print("NO")
        exit()
print("YES")

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
	long long int a,b;
	scanf("%lld %lld",&a,&b);
	int ans=0;
	if(a>b)
	{
		int t;
		t = a;
		a = b;
		b = t;
	}
	for (long long int i=a;i<=b;i++)
	{
		if(labs(a-i)==labs(b-i))
		{
			
			ans = i;
			cout << ans;
			return 0;
		}
	}	
	cout << "IMPOSSIBLE";

	return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <stdlib.h>
#include <functional>
#include <string>
#include <list>
#include <fstream>
#include <iomanip>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <chrono>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}

struct Edge {
	int from, to;
};

int main() {
	ll num;
	cin >> num;
	ll c = 0;
	ll base = 1;
	int ans = 0;
	while (c < num) {
		c *= 10;
		c += 9;
		base *= 10;
		ans += 9;
	}

	while (c > num)
		c -= base/10, ans--;



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

Measured memory_bytes: 256
import sys

def solve():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    A = [int(a) for a in input().split()]
    A.sort()
    totalSum = 0
    for a in A: totalSum += a

    if K >= totalSum - A[N-1]: print(totalSum)
    else:
        divisor = []
        k = 1
        while k ** 2 <= totalSum:
            if totalSum % k == 0:
                divisor.append(k)
                if k ** 2 < totalSum: divisor.append(totalSum//k)
            k += 1

        divisor.sort(reverse = True)
        for d in divisor:
            need = []
            lenneed = 0
            for a in A:
                if a % d > 0: 
                    need.append(a % d)
                    lenneed += 1

            #print(d, need)
            if lenneed == 0:
                print(d)
                break
            else:
                possible = False
                need.sort()
                needSum = [[0, 0] for _ in range(lenneed)]
                needSum[0][0] = need[0]
                needSum[lenneed -1][1] = d - need[lenneed - 1]
                for i in range(1, lenneed):
                    needSum[i][0] = needSum[i-1][0] + need[i]
                    needSum[lenneed - 1 - i][1] = needSum[lenneed - i][1] + d - need[lenneed - i - 1]
                #print(needSum)

                for i in range(lenneed - 1):
                    if needSum[i][0] == needSum[i+1][1] and needSum[i][0] <= K:
                        possible = True
                
                if possible: 
                    print(d)
                    break

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 3188
/******************** Beginning of Template **************************/
/************ ALL HEADER FILE ***********/
//#include<bits/stdc++.h>
#include <iostream>
using namespace std;

/************************************ ALL DEFINE ****************************************************/
#define FORS(i, j, k, step) for (int i=j; i<k; i+=step)
#define FOR(i, j, k) for (int i=j; i<k; i++)
#define RFORS(i, j, k, step) for (int i=j; i>=k; i-=step)
#define RFOR(i, j, k, step) for(int i=j; i>=k; i--)
#define REP(i, k) for(int i = (0); i < (k); i++ )
#define RREP(i, k) for(int i = j; i >= (k); i-- )

#define ALL(cont) cont.begin(), cont.end()
#define RALL(cont) cont.begin(), cont.end()
#define FOREACH(it, l) for(auto it=l.begin(); it != l.end(); it++)
#define mp make_pair
#define pb push_back
#define RESET(a, b) memset(a, b, sizeof(a))
#define INF (int)MAX_INT
#define EPS (int)1e-9
#define PI acos(-1)
#define MOD 1000000007
#define fango using
#define ganteng namespace
#define sekali std

/*********************************Debug DEFINE  ********************************/
#define TESTING
//#define FILE_INPUT
//#define FILE_OUTPUT
/*********************************END of Debug DEFINE  ********************************/

#ifdef TESTING
#define VALUE(x) cout << ">>>> The value of " << #x << " is " << x << "<<<<" << endl
#define NEWLINE cout << "---------------------------------------------" << endl
#define DUMP_STR cout << ">>>>FANGO IS THE MOST HANDSOME MANKIND IN THE ENTIRE WORLD<<<<" << endl;
#define DUMP_CHAR cout << " YO ";
#endif //TESTING_ON_CONSOLE



/************************************ END OF DEFINE ****************************************************/

/************************************ ALL TYPEDEF ****************************************************/
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<piii> viii;
typedef long long int32;
typedef unsigned long long uint32;
typedef long long int int64;
typedef unsigned long long int uint64;



/************************************ ALL DEFINE ****************************************************/

/************************************ END OF PREHEADER ***********************************************/



void solve() {

	int f = 0;
	string s;
	cin >> s;

	for (int i = 0; i < s.size() - 1; i++) {

		if (s[i] == s[i + 1]) {
			f = 1;
			break;
		}
	}
	if (f == 0) {
		cout << "Good";
	}
	else {
		cout << "Bad";
	}


}

int main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int TC = 1;
	//cin >> TC;

	while (TC--) {

		solve();
	}
}

Measured memory_bytes: 3000
import java.util.*

data class Item(var y:Int, var x:Int, var c:Int)

fun main() {
    val (h,w,k) = readLine()!!.split(" ").map { it.toInt() }
    var (y1,x1,y2,x2) = readLine()!!.split(" ").map { it.toInt() }
    x1--
    y1--
    x2--
    y2--
    val dirs = arrayOf(-1 to 0, 1 to 0, 0 to -1, 0 to 1)
    // 0 - 빔, 1 - 채움, 2 - 장애물
    val board = Array(h){IntArray(w)}
    val vv = Array(h){IntArray(w){10000000} }
    for(i in 0 until h) {
        val row = readLine()!!
        for(j in 0 until w) {
            if(row[j] == '.') continue
            board[i][j] = 2
        }
    }

    val q = LinkedList<Item>()
    var ans = -1
    q.add(Item(y1, x1, 0))

    while (q.isNotEmpty()) {
        val v = q.poll()
//        println("Y : ${v.y}, X : ${v.x} - ${v.c}")
        if(v.x == x2 && v.y == y2) {
            ans = v.c
            break
        }
        for((dy, dx) in dirs) {
            for(i in 1..k) {
                val cy = dy * i + v.y
                val cx = dx * i + v.x
                if(cy < 0 || cy >= h || cx < 0 || cx >= w)
                    break
                if(board[cy][cx] == 2)
                    break
                if(board[cy][cx] == 1 && vv[cy][cx] < v.c + 1)
                    break
                board[cy][cx] = 1
                if(vv[cy][cx] > v.c + 1)
                    q.add(Item(cy, cx, v.c + 1))
                vv[cy][cx] = v.c + 1
            }
        }
    }
    print(ans)

}

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

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

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



Measured memory_bytes: 3624
n, m = map(int, input().split())
r = [[0]*n for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    r[a][b] += 1
    r[b][a] += 1

for i in range(n):
    print(sum(r[i]))


Measured memory_bytes: 3060
#include<stdio.h>
int main(void){
  int A;
  int B;
  int C;
  1<=A,B,C;
  A,B,C<=100;
  scanf("%d",&A);
  scanf("%d",&B);
  scanf("%d",&C);
  if((B/A)>=C){
    printf("%d",C);
  }
  if((B/A)<C){
    printf("%d",B/A);
  }
}


Measured memory_bytes: 128
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tommy6073
 */

#include <iostream>
#include <string>
#include <map>

using namespace std;

class CMakeARectangle {
public:
    void solve(std::istream& in, std::ostream& out) {
        long long N;
        in >> N;
        map<long long, long long> sides;
        for (int i = 0; i < N; ++i) {
            long long side;
            in >> side;
            ++sides[side];
        }
        long long pairs = 0;
        map<long long, long long>::reverse_iterator it;
        long long max;
        long long max2;
        for (it = sides.rbegin(); it != sides.rend(); ++it) {
            if (it->second >= 4 && pairs == 0) {
                pairs = 2;
                max = it->first;
                max2 = it->first;
                break;
            } else if (it->second >= 2) {
                if (pairs == 0) {
                    max = it->first;
                    pairs = 1;
                } else {
                    max2 = it->first;
                    pairs = 2;
                    break;
                }
            }
        }
        long long ret = 0;
        if (pairs == 2) {
            ret = max * max2;
        }
        out << ret;
    }
};


int main() {
	CMakeARectangle solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

constexpr int MOD = 10000;

int dp[505][2][3][10][500]; // dp[桁][未満フラグ][谷:0/山:1/未定:2][直前の数字][余り]

int solve(string x, int m, int f=0){
    int n = x.size();
    memset(dp, 0, sizeof(dp));
    dp[0][0][2][0][0] = 1;
    for(int i=0;i<n;i++){
        int D = x[i]-'0';
        for(int j=0;j<2;j++){
            for(int k=0;k<3;k++){
                for(int l=0;l<10;l++){
                    for(int d=0;d<=(j?9:D);d++){
                        if((k==0 && l>=d) || (k==1 && l<=d) || (k==2 && l>0 && l==d)) continue;
                        for(int r=0;r<m;r++){
                            dp[i+1][j||(d<D)][((k==2&&l==0)?2:l<d)][d][(r*10+d)%m] += dp[i][j][k][l][r];
                            dp[i+1][j||(d<D)][((k==2&&l==0)?2:l<d)][d][(r*10+d)%m] %= MOD;
                        }
                    }
                }
            }
        }
    }
    int res = 0;
    for(int i=(f?1:0);i<2;i++)for(int j=0;j<3;j++)for(int k=0;k<=9;k++){
        res += dp[n][i][j][k][0];
        res %= MOD;
    }
    return res;
}

int main(){
    string a, b;
    int m;
    cin >> a >> b >> m;
    cout << (solve(b,m) - solve(a,m,1) + MOD)%MOD << endl;
    return 0;
}



Measured memory_bytes: 62348
#include<stdio.h>

int main()
{
	int a,b;
	int sum = 0;
	int amari;
	int h;
	int N;
	scanf("%d", &N);
	int s[N];
	
	for(a=0; a<N; a++) scanf("%d", &s[a]);
	
	for(a=0; a<N; a++) sum = sum + s[a];
	
	amari = sum % 10;
	
	if(amari == 0) 
	{
      for(b=0; b<N-1; b++){
		for(a=0; a<N-1; a++){
			if(s[a+1] < s[a]){
				h = s[a];
				s[a] = s[a+1];
				s[a+1] = h;
            }
			}
		}
	
		h = 0;
		
		for(a=0; a<N && h == 0; a++)
		{
			if((sum - s[a]) % 10 != 0){
				sum = sum - s[a];
				h++;
			}
		}
		
		if (h==0) printf ("0");
		else printf("%d", sum);
	}
	else printf("%d", sum);	

	return 0;
}
	

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

using namespace std;

int main() {
    int n;
    cin>>n;
    int k;
    cin>>k;
    vector<int> h(n), dp(n, INT_MAX);
    for(int i=0;i<n;i++) {
        cin>>h[i];
    }
    dp[0] = 0;
    dp[1] = abs(h[0]-h[1]);
    for(int i=0;i<n;i++) {
        for(int j=i-1;j>=0&&i-j<=k;j--){
            dp[i] = min(dp[i], dp[j] + abs(h[j]-h[i]));
        }
    }
    cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x;
  cin>>x;
  int sum;
  for(;x>=500;x=x-500){
    sum+=1000;
  }
  for(;x<500&&x>=5;x=x-5){
    sum+=5;
  }
  cout<<sum;
}

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

int main()
{
	int a, b;
	scanf("%d%d", &a, &b);
	if((a + b) % 2 == 0) printf("%d\n", (a + b) / 2);
	else printf("%d\n", (a + b) / 2 + 1); 
	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>

int main(){
  int n;
  scanf("%d", &n);
  
  // get array
  int *array = (int *)malloc(sizeof(int)*n);
  for(int i = 0; i < n;i++){
	scanf("%d", &array[i]);
  }
  
  int max,nextMax;
  int maxIndex;

  // init
  if(array[0] > array[1]) {
	max = array[0];
    maxIndex = 0;
    nextMax = array[1];
  } else {
	max = array[1];
    maxIndex = 1;
    nextMax = array[0];
  }
  
  for(int i = 2; i < n; i++){
	if(max < array[i]) {
      nextMax = max;
      max = array[i];
      maxIndex = i;
    } else if(nextMax < array[i]){
	  nextMax = array[i];
    }
  }
  
  // print
  for(int i = 0; i < n; i++){
	if(i == maxIndex)
      printf("%d\n", nextMax);
    else
      printf("%d\n", max);
  }
  
  return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << - 1 << endl;}
void unhap() {cout << ":(" << endl;}

int main() {
  ll n, k, r, s, p;
  string t;
  cin >> n >> k >> r >> s >> p >> t;
  ll pts = 0;
  for (ll i = 0; i < k; i++) {
    if (t.at(i) == 'r') pts += p;
    else if (t.at(i) == 's') pts += r;
    else pts += s;
  }
  vector<int> win(k, 1);
  for (ll i = k; i < n; i++) {
    if (t.at(i) != t.at(i - k)) {
      if (t.at(i) == 'r') pts += p;
      else if (t.at(i) == 's') pts += r;
      else pts += s;
      win.push_back(1);
    }
    else if (win.at(i - k) == 0) {
      if (t.at(i) == 'r') pts += p;
      else if (t.at(i) == 's') pts += r;
      else pts += s;
      win.push_back(1);
    }
    else win.push_back(0);
  }
  cout << pts << endl;
}

Measured memory_bytes: 1340