akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            // 時間無いから写しといて後でもう1回解く
            int n = int.Parse(Console.ReadLine());
            int[,] conf = new int[n, n];

            for (int i = 0; i < n; i++)
            {
                int a = int.Parse(Console.ReadLine());
                for (int j = 0; j < a; j++)
                {
                    var xy = Console.ReadLine().Split().Select(int.Parse).ToArray();
                    conf[i, xy[0] - 1] = xy[1] == 1 ? 1 : -1;
                }
            }

            int max = 0;
            for (int state = 0; state < (1 << n); state++)
            {
                bool[] isGood = Enumerable.Range(0, n).Select(x => (state & (1 << x)) != 0).ToArray();
                for (int i = 0; i < n; i++)
                {
                    if (!isGood[i]) continue; 
                    for (int j = 0; j < n; j++)
                    {
                        if (conf[i, j] == 0) continue;
                        if ((conf[i, j] == 1) == isGood[j]) continue;
                        goto end;
                    }
                }
                max = Math.Max(max, isGood.Count(x => x));
            end:;
            }

            Console.WriteLine(max);
        }
    }
}


Measured memory_bytes: 17480
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for (int i = 0; i < (a); i++)
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
typedef long long ll;
template<typename T>istream& operator>>(istream&i,vector<T>&v){rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const vector<T>&v){stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const vector<T>&v){if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.first>>v.second;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v){return o<<v.first<<","<<v.second;}
template<typename T>bool mins(T& x,const T&y){if(x>y){x=y;return true;}else return false;}
template<typename T>bool maxs(T& x,const T&y){if(x<y){x=y;return true;}else return false;}
template<typename T>ll suma(const vector<T>&a){ll res(0);for(auto&&x:a)res+=x;return res;}

#ifdef _DEBUG
inline void dump() { cerr << endl; }
template <typename Head> void dump(Head &&head) {
  cerr << head;
  dump();
}
template <typename Head, typename... Tail>
void dump(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  dump(forward<Tail>(tail)...);
}
#define dbg(...)                                                               \
  do {                                                                         \
    cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = ";                        \
    dump(__VA_ARGS__);                                                         \
  } while (false)
#else
#define dump(...)
#define dbg(...)
#endif

template <typename T> struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template <typename T> using Edges = vector<edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template <typename T> using Matrix = vector<vector<T>>;

const ll LINF = 1LL << 60;
const int INF = 1001001001;

/////////////////////////////////////////////////////////////////////

const ll MUL = 1000000000;

int main() {
  ll n; cin>>n;
  vector<ll> a(n);
  rep(i, n) {
    long double t; cin>>t;
    a[i] = t * MUL + 0.1;
  }

  vector<vector<ll>> g(21, vector<ll>(21));
  vector<ll> t(n);
  vector<ll> f(n);
  rep(i, n) {
    ll tmp = a[i];
    while (tmp%2==0) { t[i]=min(18LL, t[i]+1); tmp/=2; }
    while (tmp%5==0) { f[i]=min(18LL, f[i]+1); tmp/=5; }
    g[t[i]+1][f[i]+1]++;
  }

  rep(i, 19) g[i+1][0] += g[i][0];
  rep(i, 19) g[0][i+1] += g[0][i];
  rep(i, 19) rep(j, 19) g[i+1][j+1] += g[i+1][j] + g[i][j+1] - g[i][j];

  ll ans = 0;
  rep(i, n) {
    ll two = 18 - t[i];
    ll five = 18 - f[i];
    ll tmp = g[19][19] - g[two][19] - g[19][five] + g[two][five];
    if (t[i]*2 >= 18 && f[i]*2 >= 18) tmp--;
    ans += tmp;
  }
  cout << ans/2 << endl;

  return 0;
}


Measured memory_bytes: 8012
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<cstdio>
using namespace std;

static const int INF=100000;
static const int MOD=1000000007;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    ll N,Q;
    cin >> N >> Q;
    ll a[N-1],b[N-1];
    ll p[Q],x[Q];
    vector<pair<ll,ll> > v(N-1);
    for(int i=0;i<N-1;i++){
        cin >> a[i] >> b[i];
        a[i]--,b[i]--;
        v[i]=make_pair(a[i],b[i]);
    }
    sort(v.begin(),v.end());
    //for(int i=0;i<N-1;i++){
        //cout << v[i].first << v[i].second << endl;
    //}
    for(int i=0;i<Q;i++){
        cin >> p[i] >> x[i];
        p[i]--;
    }
    vector<ll> tmp(N+1,0);
    for(int i=0;i<Q;i++){
        tmp[p[i]]+=x[i];
    }
    //for(int i=0;i<N;i++){
        //cout << tmp[i] << endl;
    //}
    for(int i=0;i<N-1;i++){
        tmp[v[i].second]+=tmp[v[i].first];
    }
    for(int i=0;i<N;i++){
        cout << tmp[i] << " ";
    }

}


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

const ll mod = 1e9+7;
const ll nax = 1e4+7;

ll dp[nax][102][2];
string num;
ll d;

ll di(ll pos,ll sum,int f){
	if (pos==num.size()) {
		if (sum==0) return 1;
		return 0;
	}
	
	if (dp[pos][sum][f]!=-1) return dp[pos][sum][f];
	
	ll res=0,nf,lim;
	
	if (f==0) lim=(num[pos]-'0');
	else lim=9;
	
	for (ll i=0;i<=lim;++i){
		
		nf=f;
		
		if (i<lim) nf=1;
		
		res=(res+di(pos+1,(sum+i)%d,nf))%mod;
	}
	
	return dp[pos][sum][f]=res;
	
}

int main(){
//	freopen("input.inp","r",stdin);
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	memset(dp,-1,sizeof(dp));
	cin>>num>>d;
	
//	cout<<num<<" "<<d<<"\n";
	
	ll res=(di(0,0,0)-1+mod)%mod;
	
/*	for (ll i=0;i<=num.size();++i){
		for (ll j=0;j<d;++j){
			for (ll f=0;f<2;++f) cout<<dp[i][j][f]<<" ";
		}
		cout<<"\n";
	}
	cout<<"\n";*/
	
	cout<<res<<"\n";
}

Measured memory_bytes: 20420
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string s;
  cin>>s;
  int sum=0;
  int min=50000;
  for(int i=0;i<=s.length()-3;i++){
    sum+=(s[i]-'0')*pow(10,2);
    sum+=(s[i+1]-'0')*pow(10,1);
    sum+=(s[i+2]-'0')*pow(10,0);
    if(min>abs(753-sum)){
      min=abs(753-sum);
    }
    sum=0;
  }
  cout<<min<<endl;

     
}

Measured memory_bytes: 256
#include<bits/stdc++.h>  
using namespace std;
 
#define mod 1e9+7
 
typedef long long ll;
 
int main()
{
    vector<int> ref,miw;
    int ans=INT_MAX,refLen,miwLen,cpnLen,temp;
    int x,y,c;

    ref.push_back(INT_MAX);
    miw.push_back(INT_MAX);

    cin>>refLen>>miwLen>>cpnLen;

    for(int i=0;i<refLen;i++){
    	cin>>temp;
    	ref.push_back(temp);
    }

    for(int i=0;i<miwLen;i++){
    	cin>>temp;
    	miw.push_back(temp);
    }

    ans= *min_element(ref.begin(),ref.end())+ *min_element(miw.begin(),miw.end());

    for(int i=0;i<cpnLen;i++){
    	cin>>x>>y>>c;
    	temp=ref[x]+miw[y]-c;
    	ans=min(ans,temp);
    }

    cout<<ans;

    return 0;
}
     

Measured memory_bytes: 1400
n = gets.chomp.to_i
list = gets.chomp.split(' ').map(&:to_i)

h = {}
list.each do |len|

  if h.key?(len)
    h[len] += 1
  else
    h[len] = 1
  end
end

e = []
keys = h.keys.sort.uniq.reverse
keys.each do |key|
  if h[key] >= 4
    e << key
    e << key
  elsif h[key] >= 2
    e << key
  end
  break if e.size >= 2
end

puts e.size >= 2 ? e[0] * e[1] : 0


Measured memory_bytes: 24816
#define _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <iostream>
#include <string.h>
#include <set>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;

typedef double LD;
typedef long long LL;
typedef pair<int, int> PII;
#define MP make_pair
#define PB push_back
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i,0,t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())

const LL MOD = 1000000007;
const int INF = 1e9;
const LL LINF = 1LL * INF * INF;
const int MAXN = 200007;
const LD EPS = 1e-7;

deque <char> D;

int main()
{
	ios_base::sync_with_stdio(0);
	//freopen("In.txt", "r", stdin);
	int n, k, neg = 0;
	cin >> n >> k;
	REP(i, n)
	{
		char c;
		cin >> c;
		D.push_back(c);
	}
	bool o = k & 1;
	k = min(k, 2 * n);
	if ((k ^ o) & 1)
		k ^= 1;
	REP(i, k)
	{
		if ((D.front() == 'A') ^ (neg & 1))
		{
			D.pop_front();
			if (neg & 1)
				D.push_front('A');
			else
				D.push_front('B');
			continue;
		}
		++neg;
		D.pop_front();
		if (neg & 1)
			D.push_back('B');
		else
			D.push_back('A');
	}
	if (neg & 1)
	{
		REP(i, n)
		{
			if (D.front() == 'A')
				cout << 'B';
			else cout << 'A';
			D.pop_front();
		}
	}
	else
		REP(i, n)
	{
		cout << D.front();
		D.pop_front();
	}
	//cout << endl; system("pause");
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <string>
using namespace std;

typedef long long ll;
typedef long double ld;

int main(){
  ll n;
  cin >> n;
  for(ll a=-1000;a<=1000;a++){
    for(ll b=-1000;b<=1000;b++){

      if(pow(a,5)-pow(b,5)==n){
        cout << a << " "<< b;
        return 0;
      }
   }
  }

}

Measured memory_bytes: 4100
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int n;
	cin >> n;
	while(1){
		int m = n;
		int a = m%10;
		m/=10;
		int b = m%10;
		m/=10;
		int c = m%10;
		if( a == b && b == c ){
			cout << n << endl;
			break;
		}
		++n;
	}
	return 0;
}

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

typedef long long ll;

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

const int maxn = 1e6 + 5;

int n,k;
string s;

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

  cin>>n>>k;
  cin>>s;
  k--;
  s[k] = s[k]-'A'+'a';
  cout<<s<<endl;
  

  return 0;
}


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

int main() {
  string x;
  cin >> x;

  int count = 0;
  int i = 0;
  while (i < 3) {
    if (x.at(i) == '1') {
      count ++;
    }
    i ++;
  }

  cout << count << endl;
}


Measured memory_bytes: 256
S = input()
ans = 0
for num in range(2**((len(S)-1))):
  before = 0
  nums = []
  for i in range(len(S)-1):
    if num>>i&1:
      nums.append(int(S[before:i+1]))
      before = i+1
  nums.append(int(S[before:]))
  ans += sum(nums)
print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<cstring>
using namespace std;
typedef long long ll;
char a[110];
ll k;
int main()
{
    cin>>a>>k;
    ll len=strlen(a);
    ll sum1=0;
    for(int i=0;i<=len;i++)
        if(a[i]=='1')   sum1++;
    else break;

    if(sum1>=k) cout<<1<<endl;
    else
    {
        for(int i=0;i<len;i++)
      {
           if(a[i]!='1') { cout<<a[i]<<endl; break;}
        if(i==len)    cout<<1<<endl;
      }
    }


    return 0;
}


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

int main()
{
	int k, total=0;
	string a;
	
	cin >> k;
	getchar();
	getline(cin, a);
	
	for (int i=0; i<=a.size(); i++)
	    if (a[i]>='a' && a[i]<='z') total++;
	
	if (total <= k)
		cout << a << endl;
	else
	{
		for (int i=0; i<=k-1; i++)
		{
			cout << a[i];
		}
		cout << "..." << endl;
	}
	return 0;
}

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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll LCM(ll a, ll b) { return a / GCD(a, b)* b; }

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,a,b; cin>>n>>a>>b;
  vector<ll> h(n);
  rep(i,n) cin>>h[i];
  
  ll l=0, r=1e9;
  while((r-l)>1){
    ll m=(r+l)/2;
    
    bool ok=true;
    ll cnt=0;
    rep(i,n){
      ll rem=h[i]-b*m;
      if(rem<=0) continue;
      cnt+=(rem+(a-b)-1)/(a-b);
      if(cnt>m){
        ok=false;
        break;
      }
    }
    if(ok) r=m;
    else l=m;
  }
  cout<<r<<endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main(){
    FAST
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++) cin>>arr[i];
    ll ans=0,count=0;
    for(int i=n-1;i>=1;i--){
        if(arr[i-1]>=arr[i]) count++;
        else{
            ans=max(ans,count);
            count=0;
        }
    }
    ans=max(ans,count);
    cout<<ans;
}

Measured memory_bytes: 640
//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int main() {
	int N;
	cin >> N;

	vector<int> w6;
	for (int i=1; pow(6, i) <= N; i++) {
		w6.push_back(pow(6, i));
	}
	sort(w6.begin(), w6.end(), greater<int>());

	vector<int> w9;
	for (int i=1; pow(9, i) <= N; i++) {
		w9.push_back(pow(9, i));
	}
	sort(w9.begin(), w9.end(), greater<int>());


	int ans = INF;
	for (int i=0; i<=N; i+=9) {
		int cnt = 0;

		// i円を9で引き出す
		int Y = i;
		for (int w : w9) {
			if (Y != 0) {
				cnt += Y / w;
				Y %= w;
			}
		}

		// 残りを6で引き出せるだけ引き出す
		Y = N - i;
		for (int w : w6) {
			if (Y - w >= 0) {
				cnt += Y / w;
				Y %= w;
			}
		}

		// 残りを1円で引き出す
		cnt += Y;

		// 最小なら更新
		ans = min(ans, cnt);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4080
#include <bits/stdc++.h>
using namespace std;
int main() {
	long long n, a;
	cin >> n;
	vector<char> name;
	while (n > 0) {
		a = n % 26;
		n /= 26;
		if(a == 0){
			a = 26;
			n -= 1;
		}
		name.push_back(a + 'a' - 1);
	}
	for (long long i = name.size() - 1; i > -1; --i) {
		cout << name.at(i);
	}
	cout << endl;
}

Measured memory_bytes: 3624
// tested by Hightail: https://github.com/dj3500/hightail
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <stack>
#include <cstring>
#include <iomanip>
#include <ctime>
#include <cassert>
using namespace std;
#define pb push_back
#define INF 1001001001
#define FOR(i,n) for(int (i)=0;(i)<(n);++(i))
#define FORI(i,n) for(int (i)=1;(i)<=(n);++(i))
#define mp make_pair
#define pii pair<int,int>
#define ll long long
#define vi vector<int>
#define SZ(x) ((int)((x).size()))
#define fi first
#define se second
#define wez(n) int (n); scanf("%d",&(n));
#define wez2(n,m) int (n),(m); scanf("%d %d",&(n),&(m));
#define wez3(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k));
inline void pisz(int n) { printf("%d\n",n); }
template<typename T,typename TT> ostream& operator<<(ostream &s,pair<T,TT> t) {return s<<"("<<t.first<<","<<t.second<<")";}
template<typename T> ostream& operator<<(ostream &s,vector<T> t){FOR(i,SZ(t))s<<t[i]<<" ";return s; }
#define DBG(vari) cout<<"["<<__LINE__<<"] "<<#vari<<" = "<<(vari)<<endl;
#define ALL(t) t.begin(),t.end()
#define FOREACH(i,t) for (__typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define TESTS wez(testow)while(testow--)
#define REP(i,a,b) for(int (i)=(a);(i)<=(b);++i)
#define REPD(i,a,b) for(int (i)=(a); (i)>=(b);--i)
#define REMAX(a,b) (a)=max((a),(b));
#define REMIN(a,b) (a)=min((a),(b));
#define IOS ios_base::sync_with_stdio(0);

const int N = 200200;
ll add[N], res[N];

int main () {
   IOS
   ll n, _q;
   cin >> n >> _q;
   vector<ll> queries = {n};
   ll start = n;
   FOR(i,_q) {
      ll query;
      cin >> query;
      while (!queries.empty() && queries.back() >= query) queries.pop_back();
      queries.pb(query);
   }
   n = queries[0];
   map<ll,ll,greater<ll>> m;
   m[queries.back()] = 1;
   while (!m.empty() && m.begin()->fi > n) {
      ll x = m.begin()->fi;
      ll krot = m.begin()->se;
      m.erase(m.begin());
      assert(!queries.empty());
      while (queries.back() >= x) queries.pop_back();
      assert(!queries.empty());
      ll y = queries.back();
      assert(x > y);
      m[y] += krot * (x / y);
      ll r = x % y;
      if (r > 0) {
         m[r] += krot;
      }
   }
   for (auto it : m) {
      ll x = it.fi, krot = it.se;
      assert(x <= n);
      assert(x > 0);
      add[x] += krot;
   }
   REPD(x,n,1) {
      res[x] = res[x+1] + add[x];
   }
   REP(x,1,start) cout << res[x] << '\n';
}

Measured memory_bytes: 9844
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 100;
int main() {
	int n;
    int p[N + 1], a[N + 1][N + 1];
	cin >> n;
	for( int i = 0; i < n; ++i ) {
		cin >> p[i] >> p[i + 1];
	}
	for( int i = 1; i <= n; i++ ) a[i][i] = 0;

	for( int m = 2; m <= n; m++ ) { 
		for( int i = 1; i <= n - m + 1; i++ ) {
			int j = i + m - 1;
			a[i][j] = ( 1 << 21 );
			for( int k = i; k<=j - 1; k++) {
				a[i][j] = min(a[i][j], a[i][k] + a[k+1][j] + 
					p[i-1] * p[k] * p[j] );
			}
		}
	}
	cout << a[1][n] << endl;
}


Measured memory_bytes: 3140
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

int n;
map<string, int> cnt;
int main() {
    cin.tie(0); cin.sync_with_stdio(0);
    cin >> n;
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        ans += cnt[s];
        cnt[s]++;
    }
    cout << ans;
}

Measured memory_bytes: 11264
#include "bits/stdc++.h"
#ifndef err
#define err(...)(void)0
#endif
using namespace std;
using ll = long long;
using ull = decltype(1ull);
template<class T>int size(T&&a) { return a.size(); }
#define REP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.first,_l##t=a.second;t<_l##t;t++)
#define RREP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.second-1,_l##t=a.first;t>=_l##t;t--)
template<class B>pair<int, B>make_pair(B b) { return{ 0,b }; }
#define rep(t,...)REP(t,make_pair(__VA_ARGS__))
#define rrep(t,...)RREP(t,make_pair(__VA_ARGS__))
#define all(a)begin(a),end(a)
#define rall(a)a.rbegin(),a.rend()
#define var(t, ...) t __VA_ARGS__;in,__VA_ARGS__;

void Calc();
int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);
  cin.exceptions(istream::failbit | istream::badbit);
  cout << fixed << setprecision(15); Calc(); cout.flush(); return 0;
}
template<class A>void amax(A&a, A b) { a = max(a, b); }
template<class A>void amin(A&a, A b) { a = min(a, b); }
template<class A>int comp(A a, A b) { return a < b ? 1 : b < a ? -1 : 0; }
struct Scanner {
  template<class A = string>A Next() { A a; cin >> a; return a; }
  template<class A = int>vector<A>Array(int n) { vector<A>a(n); for (A&i : a) cin >> i; return a; }
  string Line() const { string s; getline(cin, s); return s; }
  template<class A>Scanner&operator,(A&a) { a = Next<A>(); return *this; }
  template<class A>operator A() { return Next<A>(); }
}in;

/*---------------------------------------------------------------------*/


void Calc() {

  var(int, n, x);
  auto a = in.Array(n);
  int sum = accumulate(all(a), 0);
  x -= sum;
  int cnt = n;
  int mini = *min_element(all(a));
  cnt += x / mini;
  cout << (cnt) << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b) { return *(int *)a - *(int *)b; }                            /* 1,2,3,4.. */
int des(const void *a, const void *b) { return *(int *)b - *(int *)a; }                            /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { return *(char *)a - *(char *)b; }                     /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) { return strcmp(*(const char **)a, *(const char **)b); } /* aaa,aab.. */
#define min(a, b) (a < b ? a : b)
#define max(a, b) (a > b ? a : b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 1000001
#define MOD 1000000007

typedef long long int lli;

int main(void)
{
  int s;
  scanf("%d", &s);
  int nums[MAX] = {0};
  int fx = s;
  nums[fx] = 1;
  int ans;
  for (ans = 2; ans < MAX; ans++)
  {
    if (fx % 2 == 0)
      fx = fx / 2;
    else
      fx = 3 * fx + 1;
    if (nums[fx] == 1)
      break;
    nums[fx]++;
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    int cha=a-b;
    if(cha==0)
        printf("%d\n",c);
    else
    {
        if(c-cha<0)
            printf("0\n");
        else
            printf("%d\n",c-cha);
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 998244353
#define MOD(x) ((x)%mod)
#define pii pair<int,int>
#define mp(a,b) make_pair(a,b)
using namespace std;
int n;
int a[305];
int s;
long long dp[2][90005];
long long dp2[2][45005];
int now,last;
long long m;
long long ans;
int main()
{
	scanf("%d",&n);
	m=1;
	dp[1][0]=1;
	dp2[1][0]=1;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		s+=a[i];
		m=MOD(m*3);
		now=last;
		last=!now;
		for(int j=0;j<=90000;j++)
		{
			if(j<=45000)
			{
				dp2[now][j]=MOD(dp2[last][j]);
				if(j>=a[i]) dp2[now][j]=MOD(dp2[now][j]+dp2[last][j-a[i]]);
			}
			dp[now][j]=MOD(dp[last][j]*2);
			if(j>=a[i]) dp[now][j]=MOD(dp[now][j]+dp[last][j-a[i]]);
			if(i==n&&j>=(s+1)/2) ans=MOD(ans+dp[now][j]);
		}
	}
	if(s%2==0) ans=MOD(ans-dp2[now][s/2]+mod);
	printf("%lld",MOD(m-ans*3+mod+mod+mod));
	return 0;
}



Measured memory_bytes: 2304
from functools import lru_cache

input_lst = list(map(int, input().split()))
h, w, k = input_lst[0], input_lst[1], input_lst[2]

def row_comb(w):
    if w < 0:
        return 0
    elif w <= 1:
        return 1
    elif w == 2:
        return 2
    else:
        return row_comb(w-2)+row_comb(w-1)

@lru_cache(maxsize=1000)
def trio(h,w):
    if h == 0:
        return [1] + [0 for i in range(10)]
    else:
        lst = []
        for i in range(1, w+1):
            if i == 1:
                lst.append(trio(h-1,w)[0] * row_comb(w-1) + trio(h-1,w)[1] * row_comb(w-2))
            elif i == w:
                lst.append(trio(h-1,w)[w-1] * row_comb(w-1) + trio(h-1,w)[w-2] * row_comb(w-2))
            elif i == 2:
                lst.append(trio(h-1,w)[0] * row_comb(w-2) + trio(h-1,w)[2] * row_comb(w-3) + trio(h-1,w)[1] * row_comb(w-2))
            elif i == w-1:
                lst.append(trio(h-1,w)[w-1] * row_comb(w-2) + trio(h-1,w)[w-3] * row_comb(w-3) + trio(h-1,w)[w-2] * row_comb(w-2))
            elif i > 2 and i < w-1:
                a = row_comb(i-2) * row_comb(w-i)
                b = row_comb(i-1) * row_comb(w-i-1)
                c = row_comb(i-1) * row_comb(w-i)
                lst.append(trio(h-1,w)[i-2] * a + trio(h-1,w)[i] * b + trio(h-1,w)[i-1] * c)
        lst = lst + [0 for i in range(10)]
        return lst
    
print(trio(h, w)[k-1] % 1000000007)

Measured memory_bytes: 3812
n=int(input())
edges=[[] for i in range(n)]
for i in range(n-1):
    a,s,d=map(int,input().split())
    edges[a-1].append((s-1,d));edges[s-1].append((a-1,d))
q,k=map(int,input().split())
cost=[0]*n
from collections import deque
dq=deque([])
#pop/append/(append,pop)_left/in/len/count/[]/index/rotate()(右へnずらす)
for to,cos in edges[k-1]:
    dq.append((k-1,to))
    cost[to]=cos
while dq:
    par,now=dq.popleft()
    
    for to,c in edges[now]:
        if to!=par:
            cost[to]=cost[now]+c
            dq.append((now,to))

for i in range(q):
    x,y=map(int,input().split())
    print(cost[x-1]+cost[y-1])

Measured memory_bytes: 47184
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>
#include <cmath>
#include <stack>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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

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

constexpr ll mod = 1e9 + 7;
const double PI = acos(-1.0);

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

  ll k, a, b; cin >> k >> a >> b;

  if (a+2>=b) {
    cout << k+1 << endl;
    return 0;
  }

  if (k <= a) {
    cout << k+1 << endl;
    return 0;
  }

  ll d = b-a;
  k -= (a+1);
  ll ret = b;

  ret += d*(k/2);
  if (k%2 != 0) {
    ret++;
  }

  cout << ret << endl;

}


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

typedef long long ll;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    ll arr[n+1];
    unordered_map<ll,ll> count;
    for(int i=1; i<=n; i++){
        cin >> arr[i];
        count[arr[i]+i]++;
    }

    ll ans=0;
    for(ll i=1; i<=n; i++){
        if(count.find(i-arr[i])!=count.end()){
            ans+=count[i-arr[i]];
        }
    }
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 12844
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>
#include<math.h>

typedef int32_t i32;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ALLOC(size,type) ((type*)calloc((size),sizeof(type)))
#define SORT(a,num,cmp) qsort((a),(num),sizeof(*(a)),cmp)

typedef struct union_find {
  int32_t *parent;
  int32_t size;
} union_find;

void init_union_find (union_find * const u) {
  for (int32_t i = 0; i < u->size; ++i){
    u->parent[i] = -1;
  }
}

union_find* new_union_find (const int32_t size) {
  union_find * const u = (union_find *) calloc (1, sizeof (union_find));
  u->parent = (int32_t *) calloc (size, sizeof (int32_t));
  u->size = size;
  init_union_find (u);
  return u;
}

int32_t root (union_find * const u, int32_t x) {
  if (u->parent[x] < 0) return x;
  return u->parent[x] = root (u, u->parent[x]);
}

int same (union_find * const u, const int32_t x, const int32_t y) {
  return root (u, x) == root (u, y);
}

void unite (union_find * const u, int32_t x, int32_t y) {
  x = root (u, x);
  y = root (u, y);
  if (x == y) return;
  if (u->parent[x] > u->parent[y]) {
    const int32_t swap = x;
    x = y;
    y = swap;
  }
  u->parent[x] += u->parent[y];
  u->parent[y] = x;
}

typedef struct edge {
  i32 a, b;
  double c;
} edge;

int cmp_edge (const void *a, const void *b) {
  return ((edge *)a)->c <= ((edge *)b)->c ? -1 : 1;
}

void run (void) {
  i32 n;
  scanf ("%" SCNi32, &n);
  i32 *x = ALLOC (3 * n, i32);
  i32 *y = x + n;
  i32 *a = y + n;
  for (i32 i = 0; i < n; ++i) {
    scanf ("%" SCNi32 "%" SCNi32 "%" SCNi32, x + i, y + i, a + i);
  }
  double *dp = ALLOC (1 << n, double);
  union_find *u = new_union_find (n);
  edge *e = ALLOC (n * n, edge);
  for (i32 i = 1; i < (1 << n); ++i) {
    init_union_find (u);
    i32 len = 0;
    double sum = 0;
    i32 cnt = 0;
    for (i32 j = 0; j < n; ++j) {
      if (((i >> j) & 1) == 0) continue;
      sum += a[j];
      cnt++;
      for (i32 k = j + 1; k < n; ++k) {
        if (((i >> k) & 1) == 0) continue;
        double dx = x[j] - x[k];
        double dy = y[j] - y[k];
        e[len++] = (edge) {j, k, sqrt (dx * dx + dy * dy)};
      }
    }
    SORT (e, len, cmp_edge);
    for (i32 j = 0; j < len; ++j) {
      if (same (u, e[j].a, e[j].b)) continue;
      unite (u, e[j].a, e[j].b);
      sum -= e[j].c;
    }
    double max = sum / cnt;
    for (i32 j = (i - 1) & i; j > (i ^ j); j = (j - 1) & i) {
      double v = MIN (dp[j], dp[i ^ j]);
      max = MAX (max, v);
    }
    dp[i] = max;
  }
  printf ("%.10f\n", dp[(1 << n) - 1]);
}

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


Measured memory_bytes: 508
A,B,C,X=[int(input()) for i in range(4)]
cnt = 0
for a in range(0, A + 1):
  for b in range(0, B + 1):
    for c in range(0, C + 1):
      if a *500 + b * 100 + c * 50 == X:
        cnt += 1
print(cnt)

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

long long dp[100005][4];
long long MOD = 1000000007;

int main() {
    string T;
    cin >> T;
    dp[0][0] = 1;
    for (int i = 0; i < T.size(); i++) {
        for (int j = 0; j < 4; j++) dp[i+1][j] = dp[i][j];
        if (T[i] == 'A' || T[i] == '?') dp[i+1][1] = (dp[i][1] + dp[i][0]) % MOD;
        if (T[i] == 'B' || T[i] == '?') dp[i+1][2] = (dp[i][2] + dp[i][1]) % MOD;
        if (T[i] == 'C' || T[i] == '?') dp[i+1][3] = (dp[i][3] + dp[i][2]) % MOD;
        if (T[i] == '?') for (int j = 0; j < 4; j++) dp[i+1][j] += dp[i][j] * 2 % MOD;
    }
    printf("%lld\n", dp[T.size()][3] % MOD);
    return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#define REP(i, a, n) for(int i = ((int) a); i < ((int) n); i++)
using namespace std;

int H, N;
char T[100][2][2], B[3][2][2][2];
char block[2][2][2];

bool colide(int h) {
  REP(i, 0, 2) REP(j, 0, 2) REP(k, 0, 2) {
    if(T[h + i][j][k] == '#' && block[i][j][k] == '#') return true;
  }
  return false;
}

int vanish() {
  int ret = 0;
  for(int i = 99; i >= 0; i--) {
    int f = true;
    REP(j, 0, 2) REP(k, 0, 2) if(T[i][j][k] == '.') f = false;
    if(f) {
      REP(j, i + 1, 100) REP(k, 0, 2) REP(l, 0, 2) T[j - 1][k][l] = T[j][k][l];
      REP(j, 0, 2) REP(k, 0, 2) T[99][j][k] = '.';
      ret++;
    }
  }
  return ret;
}

int dfs(int n) {
  int ret = 0;
  char s[100][2][2];
  int h;

  if(n == N) return 0;

  REP(i, 0, 100) REP(j, 0, 2) REP(k, 0, 2) s[i][j][k] = T[i][j][k];

  REP(i, -1, 2) REP(j, -1, 2) REP(k, -1, 2) {
    REP(ii, 0, 2) REP(jj, 0, 2) REP(kk, 0, 2) block[ii][jj][kk] = '.';
    REP(ii, 0, 2) REP(jj, 0, 2) REP(kk, 0, 2) {
      if(B[n][ii][jj][kk] == '#') {
        if(!(0 <= ii + i && ii + i < 2 && 0 <= jj + j && jj + j < 2 && 0 <= kk + k && kk + k < 2)) goto CONT;
        block[ii + i][jj + j][kk + k] = '#';
      }
    }
    h = 98;
    while(h >= 0 && !colide(h)) h--;
    h++;
    REP(ii, 0, 2) REP(jj, 0, 2) REP(kk, 0, 2) if(block[ii][jj][kk] == '#') T[h + ii][jj][kk] = block[ii][jj][kk];
    ret = max(ret, vanish() + dfs(n + 1));
CONT:
    REP(ii, 0, 100) REP(jj, 0, 2) REP(kk, 0, 2) T[ii][jj][kk] = s[ii][jj][kk];
  }

  return ret;
}

int main(void) {
  while(cin >> H >> N, H || N) {
    REP(i, 0, 100) REP(j, 0, 2) REP(k, 0, 2) T[i][j][k] = '.';
    REP(i, 0, H) REP(j, 0, 2) REP(k, 0, 2) cin >> T[i][j][k];
    REP(i, 0, N) REP(j, 0, 2) REP(k, 0, 2) REP(l, 0, 2) cin >> B[i][j][k][l];
    cout << dfs(0) << endl;
  }
  return 0;
}

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

int main() {
    int a, b;
    cin >> a >> b;
    if (a == 1 && b == 2) cout << 3 << endl;
    else if (a == 1 && b == 3) cout << 2 << endl;
    else if (a == 2 && b == 1) cout << 3 << endl;
    else if (a == 2 && b == 3) cout << 1 << endl;
    else if (a == 3 && b == 1) cout << 2 << endl;
    else if (a == 3 && b == 2) cout << 1 << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
    int H, W, i, k, n, m;
	char a, b;
    while(scanf("%d%d", &H,&W), H!=0||W!=0){
        for(i=0;i<H;i++){
			switch(i%2){
				case 0:
					a='#'; b='.'; break;
				case 1:
					a='.'; b='#'; break;
			}
            for(k=0;k<W;k++){
				m=k%2;
				if(m==0) printf("%c", a);
				if(m!=0) printf("%c", b);
			}
            puts("");
        }
        puts("");
    }
    return 0;
}

Measured memory_bytes: 588
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
using namespace std;

int main()
{
    int N, K;
    cin >> N >> K;

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

    int ans = INT_MAX;
    for (int i = 0; i < N - K + 1; i++)
    {
        ans = min(ans, h[i + K - 1] - h[i]);
    }
    
    cout << ans << endl;
    return 0;
}

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

int main(){
    int N;
    cin>>N;
    vector<int> v(N, 0);
    for(int i=0;i<N;i++)cin>>v[i];
    int ans = 0;
    int minnum = v[0];
    for(int i=0;i<N;i++){
        if(minnum >= v[i]){
            ans++;
            minnum = v[i];
        }
    }cout<<ans<<endl;
}

Measured memory_bytes: 1024
//#include <algorithm>
//#include <cstdio>
//#include <functional>
#include <iostream>
//#include <cfloat>
//#include <climits>
//#include <cstdlib>
//#include <cstring>
//#include <cmath>
//#include <map>
//#include <queue>
//#include <set>
//#include <sstream>
//#include <stack>
//#include <string>
//#include <time.h>
//#include <vector>
//#include <random>
//#include <unordered_set>
//#include <complex>
#define WAIT system ("pause")
#define rt0 return 0
using namespace std;
int main()
{
	int N, A[100],B[100],C[100],D[100];
	int big[100],small[100];
	
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>A[i]>>B[i];
		big[i]=0;
	} 
	for(int i=0;i<N;i++){
		cin>>C[i]>>D[i];
		small[i]=0;
		for(int j=0;j<N;j++){
			if(A[j]<C[i] and B[j]<D[i]){
				small[i]++;
				big[j]++;
			}
		}
	} 
	
	int ans=0;
	while(1){
		int k=-1;
		int count=101;
		for(int i=0;i<N;i++){
			if(small[i]<=0) continue;
			if(small[i]<count){
				k=i;
				count=small[i];
			}
		}
		if(count>100) break;
		
		small[k]=0;
		count=0;
		int x=-1;
		int count1=101;
		for(int j=0;j<N;j++){
			if(big[j]<=0) continue;
			if(A[j]<C[k] and B[j]<D[k]){
				big[j]--;
				if(big[j]<count1) {
					count1=big[j];
					x=j;
				}
				count++;
			}
		}
		if(count>0) ans++;
		if(x>=0) {
			big[x]=0;
			for(int i=0;i<N;i++){
				if(A[x]<C[i] and B[x]<D[i]) small[i]--;
			}
		}
	}
	cout<<ans;
	
    rt0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

const int MAX_N = 112345;
int A[MAX_N];

int main2() {
  CLR(A, 0);
  int N = nextInt();
  REP(i, N) {
    int x = nextInt();
    A[x-1]++;
    A[x]++;
    A[x+1]++;
  }
  int ans = *max_element(A, A+MAX_N);
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 640
/*
  AOJ 2708
  Title:ABC gene
  @kankichi573
*/
#include <stdio.h>
#include <string.h>


// replace all ABC to *
void findABC(char *in,char *out,int moji[3])
{
  char *p,*q;


  for(p=in,q=out;*p;)
    if(0==strncmp("ABC",p,3))
      {
	*q='*';q++;
	p+=3;
      }
    else
      {
	moji[*p-'A']++;
	*q++=*p++;
      }
    *q='\0';
}
void char_replace(char *s,char from,char to)
{
  char *p;
  for(p=s;*p;p++)
    if(*p == from)
      *p = to;

}

int main()
{
  char buf[5001],output[5001];
  int ret,i,no_use,moji[3];

  scanf("%s",buf);

  while(1)
    {
      if(0==strcmp("ABC",buf))
	{
	  ret=1;
	  //printf("SUCCES\n");
	  break;
	}
      if(strlen(buf) <= 4)
	{
	  ret=0;
	  //printf("FAIL 1\n");
	  break;
	}
      memset(moji,0,sizeof(moji));
      findABC(buf,output,moji);

      //printf("%s\n",output);

      if(2 != (moji[0]?1:0)+(moji[1]?1:0)+(moji[2]?1:0))
	{
	  ret=0;
	  //printf("FAIL 1\n");
	  break;
	}

      for(i=0,no_use=-1;i<3;i++)
	if(moji[i]==0)
	  {
	    no_use = i;
	    break;
	  }

      char_replace(output,'*','A'+no_use);

      //printf("%c",'A'+no_use);
      //printf("%s\n",output);
      strcpy(buf,output);
     
  //printf("%d",ret);
  }
  printf("%s\n",ret?"Yes":"No");


  return(0);
}

Measured memory_bytes: 536
#include<bits/stdc++.h>
using namespace std;
const int N=200010;
int a[N];
int main(){
	int k,n;
	scanf("%d%d",&k,&n);
	for(int i=0;i<n;++i) scanf("%d",&a[i]);
	int mx=k+a[0]-a[n-1];
	for(int i=1;i<n;++i){
		if(mx<a[i]-a[i-1]) mx=a[i]-a[i-1];
	}
	printf("%d",k-mx);
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

int p[100005];
int dist[100005];

int main() {
  int n;
  while(cin >> n) {
    REP(i, n) cin >> p[i];
    REP(i, n) dist[i] = INF;
    priority_queue<pii, vector<pii>, greater<pii> > Q;
    Q.push(pii(0, 0));
    int ans;
    while(!Q.empty()) {
      pii now = Q.top(); Q.pop();
      if (now.second == n-1) {
        ans = now.first;
        break;
      }
      if (dist[now.second] < now.first) continue;
      if (p[now.second] == 0) {
        REP(i, 6) {
          int next = now.second + i + 1;
          if (next >= n) continue;
          if (dist[next] > now.first + 1) {
            dist[next] = now.first + 1;
            Q.push(pii(now.first + 1, next));
          }
        }
      } else {
        int next =  now.second + p[now.second];
        if (dist[next] > now.first) {
          dist[next] = now.first;
          Q.push(pii(now.first, next));
        }
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 0
#include<stdio.h>
#include<stdlib.h>
#define n_max 100001
typedef struct CC{
  char mark;
  int num,f;
}card;

card T[n_max];
int N,i,jud=0;

void swap(card *,card *);
int pt(int ,int );
void quicksort(int ,int );


int main(){
  scanf("%d\n",&N);
  for(i=1;i<=N;i++)
    {
      scanf("%c %d\n",&T[i].mark,&T[i].num);
      T[i].f=i;
    }
		
  quicksort(1,N);
  for(i=2;i<=N;i++)
    if(T[i-1].num==T[i].num && T[i-1].f>T[i].f)
      jud=1;
  puts(jud?"Not stable":"Stable");
  for(i=1;i<=N;i++)
    printf("%c %d\n",T[i].mark,T[i].num);
  return 0;
}


void swap(card *a,card *b)
{
  card temp;
  temp=*a;
  *a=*b;
  *b=temp;
}

int pt(int p,int r)
{
  int i,j;
  card c;
  c=T[r];
  i=p-1;
  for(j=p;j<r;j++)
    {
      if(T[j].num <= c.num)
	swap(&T[++i],&T[j]);	
    }
  swap(&T[i+1],&T[r]);
  return i+1;
}

void quicksort(int x,int y)
{
  int z;
  if(x<y){
    z=pt(x,y);
    quicksort(x,z-1);
    quicksort(z+1,y);
  }
}





Measured memory_bytes: 2948
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define FI first
#define SE second
#define PB push_back
#define EB emplace_back
#define SZ(x) (int)(x).size()
#define BN(x) ((1<<x)-1)
#define DUP(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

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

int main () {
  int n;
  cin >> n;
  vi a(n);
  rep(i,n) cin >> a[i];

  vi b(n);
  rep(i,n) {
    int sng;
    if (n%2 == 0) {
      sng = (i%2 == 0 ? 1 : -1);
    }
    else {
      sng = (i%2 == 0 ? -1 : 1);
    }
    b[n/2+sng*((i+1)/2)] = a[i];
  }

  rep(i,n) {
    printf("%d%s",b[i],i!=n-1?" ":"\n");
  }
}

Measured memory_bytes: 3712
def ceil(src, range):
    if src % 10:
        return ((int)(src / range) + 1 ) * range
    else:
        return src

def main():
    input_list = []
    rand_up_list = []
    sa = {}
    for i in range(5):
        num = int(input())
        input_list.append(num)
        rand_up_list.append(ceil(num,10))
        sa[i] = rand_up_list[i] - input_list[i]
    test = sorted(sa.items(), key=lambda x: x[1])
    sum = 0
    for i in range(5):
        if i < 4:
            sum += rand_up_list[test[i][0]]
        else:
            sum += input_list[test[i][0]]
    print(sum)
    
main()

Measured memory_bytes: 3064
/*
     _              ,_,                 
    / \   _ __, ___,| |__   __ _,_ __  
   / ^ \ | '_ \/ _ \| '_ \ / _` | /_/  
  /-/-\-\|-| |--| |-|-|_)-|-(_|-|-|    
 /_/   \_\_| |__| |_|_.__/ \__,_|_|    
 
*/
#include <bits/stdc++.h>
using namespace std;
 
#define int long long int
#define ld long double
#define ll long long
#define pb push_back
#define F first
#define S second
#define all(a)       (a).begin(),(a).end()
#define rep(i,a,n)   for(int i=a ; i<n ; i++)
 
typedef vector<ll> vi;
typedef pair<ll,ll> pii;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef map<ll,ll> mii;
typedef map<char,ll> mci;
 
ll gcd(ll a, ll b){
	if(b==0)return a;
	else return gcd(b, a%b);
}

signed main(){
    ll test=1;
    // cin>>test;
    while(test--){
        ll n; cin>>n;
        vi a(n), b(n), c(n);
        rep(i,0,n)cin>>a[i]>>b[i]>>c[i];

        int prev=-1;
        int dp[n][3];
        memset(dp, 0, sizeof(dp));
        dp[0][0]=a[0];
        dp[0][1]=b[0];
        dp[0][2]=c[0];
        for(int i=1; i<n; i++){
        	dp[i][0]=a[i]+max(dp[i-1][1], dp[i-1][2]);
        	dp[i][1]=b[i]+max(dp[i-1][0], dp[i-1][2]);
        	dp[i][2]=c[i]+max(dp[i-1][1], dp[i-1][0]);
        }
        cout<<max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]))<<endl;
    }
        
}

Measured memory_bytes: 7968
#include <cstdio>
#include <iostream> 
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>

using namespace std;
using ll = long long;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

int main()
{
	int n, d[105], i, ans = 1;

	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> d[i];
	}

	sort(d, d + n, greater<int>());

	for (i = 1; i < n; i++) {
		if (d[i] < d[i - 1]) {
			ans++;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
s = gets.chomp!.split("").map(&:to_i)
ans1 = 0
ans2 = 0

if s.length == 1 then
  puts 0
elsif s.length == 2 then
  if s[0] == s[1] then
    puts 1
  else
    puts 0
  end
else
  c = s.length % 2
  if c == 1 then
    if s.pop == 0 then
      ans1 += 1
    else
      ans2 += 1
    end
  end
  s.each_slice(2) do |l,m|
    if l == 0 then
      ans1 += 1
    else
      ans2 += 1
    end
    if m == 1 then
      ans1 += 1
    else
      ans2 += 1
    end
  end

  if ans1 >= ans2 then
    puts ans2
  else
    puts ans1
  end
end


Measured memory_bytes: 7676
#include <bits/stdc++.h>
using namespace std;
int main(){
  string A,B;
  cin>>A>>B;
  if(A.length()>B.length()){
    cout<<"GREATER";
    return 0;
  }
  else if(A.length()<B.length()){
    cout<<"LESS";
    return 0;
  }
  else{
    for(int i=0;i<A.length();++i){
      if(A.compare(B)>0){
        cout<<"GREATER";
        return 0;
      }
      else if(A.compare(B)<0){
        cout<<"LESS";
        return 0;
      }
    }
    cout<<"EQUAL";
    return 0;
  }
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 1
#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR
#endif


//改造
typedef long long int ll;
using namespace std;


//ここから編集する


int main() {
    ll A,B;
    cin >> A >> B;
    ll ans = (1 << 30);
    if(A * B <= 0){
        if(A != B){
            ans = abs(A + B)+1;
        }else{
            ans = 0;
        }
    }
    if(A < B){
        ans = min(ans,B-A);
    }else if(A > B){
        ans = min(ans,A-B+2);
    }else{
        ans = 0;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll n;
  cin >> n;
  ll res = 0;
  for(int i = 0;i < n;i++){
    ll num = 0;
    cin >> num;
    res += num;
  }
  res -= n;
  cout << res << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  char a[100],b[100],T,c[100];
  int i,j,k,I=0,J=0,count=0,t=0;
   
 
 
    while(1){
      scanf("%c",&a[I]);
      if(a[I]=='\n') break;
      I++;
    }
 
   while(1){
      scanf("%c",&b[J]);
      if(b[J]=='\n') break;
      J++;
    }
 
   while(count!=J){
      
     count=0;
   for(i=0;i<J;i++){
     if(a[i]==b[i]) count++;
     else count--;
   }
   
   if(count!=J){
     for(i=0;i<I;i++){
       if(i==0) T=a[0];
         a[i]=a[i+1];
     if(i==I-1)  a[I-1]=T;
     }
      
     t++;
     if(t==100) break;
      
   }
   }
   if(count==J) printf("Yes\n");
   else printf("No\n");
    
 
   return 0;
}

Measured memory_bytes: 524