akhauriyash/Code-Regression huggingface dataset:
//BISMILLAHIR RAHMANIR RAHIM
#include <bits/stdc++.h>
#define mem(a, b) (memset(a, b, sizeof(a)))
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
#define PI acos(-1)
#define INF 2147483647
#define MOD 1000000007
#define MAX 200005
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<int, ii> pii;
typedef vector<ii> vii;
typedef priority_queue<int,vector<int>,greater<int> > PQ;

int Set(int mask, int pos){return mask = mask | (1<<pos);}
bool check(int mask, int pos){return (bool)(mask & (1<<pos));}

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    ll a;
    string b;
    ll num = 0;
    cin>>a>>b;

    int p = 1;
    for(int i = b.size() - 1; i >= 0; i--) {
        if(b[i] == '.')
            continue;
        num += (b[i] - '0') * p;
        p *= 10;
    }

    ll ans = (a * num) / 100;

    cout<<ans<<endl;

    return 0;
}



Measured memory_bytes: 3648
s = gets.to_i
arr = []
arr << s
while true
  if s.odd? 
    new_s = 3 * s + 1
  else
    new_s = s / 2
  end
  if arr.find_index(new_s)
    puts arr.size + 1
    exit
  end
  arr << new_s
  s = new_s
end 

Measured memory_bytes: 14148
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const double pi = acos(-1);
const ll MAX_N = 2000010;

// aのn乗を求める。計算量はO(logn)
ll modpow(ll a, ll n) {
    if(n == 0) {
        return 1;
    }
    if(n%2 == 1) {
        return (a * modpow(a, n-1))%mod;
    }
    return (modpow(a, n/2) * modpow(a, n/2))%mod;
}

ll inverse(ll a) {
    return modpow(a, mod-2);
}

ll inv[MAX_N];  // inv[i] : iの逆数のmod
ll fact[MAX_N];  // fact[i] : iの階乗のmod
ll invfact[MAX_N];

void init() {
    inv[0] = fact[0] = invfact[0] = 1;
    inv[1] = 1;
    for(ll i = 1; i < MAX_N; i++) {
        if(i >= 2) {
            inv[i] = mod - inv[mod%i]*(mod/i)%mod;
        }
        fact[i] = (i*fact[i-1])%mod;
        invfact[i] = inverse(fact[i]);
    }
}
 
ll Comb(ll n, ll r) {
    if(r < 0 || n < 0 || n < r) {
        return 0;
    }
    ll res = fact[n];
    res = (res * invfact[r])%mod;
    res = (res * invfact[n-r])%mod;
    return res;
}

ll Perm(ll n, ll r) {
    return (Comb(n, r) * fact[r])%mod;
}

//--- main関数でinit()を呼び出すのを忘れるな ---//
int main() {
    ll n, m;
    cin >> n >> m;

    init();

    ll ans = 0;
    exrep(i, 0, n) {
        ll x = (((Perm(m-i, n-i) * Perm(m-i, n-i))%mod * Perm(m, i))%mod * Comb(n, i))%mod; 
        if(i%2 == 0) {
            ans = (ans + x)%mod;
        }
        else {
            ans = (ans + mod - x)%mod;
        }
    }

    out(ans);
    re0;
}

Measured memory_bytes: 50468
//
#include <bits/stdc++.h>
#define FOR(i, l, r) for(ll i = l; i < r; i++)
#define rep(i, N) FOR(i, 0, N)
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<ll> vl;
const ll MOD = round(1e9+7);

int gcd(int a,int b){
  if(a<b) swap(a,b);
  while(a%b){
    int r = a%b;
    a=b;
    b=r;
  }
 return b;
}

int main() {
    int N,M; cin >> N>>M;
    vi a(M);rep(i,M) cin>>a[i];
    sort(a.begin(),a.end());
    vi d(M-1);rep(i,M-1) d[i]=a[i+1]-a[i];
    sort(d.begin(),d.end());
  
    ll ans=0;
    rep(i,M-N) ans+=d[i];
  
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4032
//#pragma GCC optimize("trapv")
#include <iostream>
#include <vector>
#include <tuple>
#include <deque>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cassert>
#include <iomanip>
#include <algorithm>
#include <unordered_set>
#define int long long
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()

using namespace std;

const int MOD = 1e9 + 7;
const int INF = 1e9 * 1e9 + 10;

void fast()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

const int sz = 1e3 + 200;
char g[sz][sz];
bool used[sz][sz];
int dist[sz][sz];
vector <pair <int, int> > dir = { {-1, 0}, {1, 0}, {0, 1}, {0, -1} };

signed main()
{
	fast();
	int h, w;
	cin >> h >> w;

	pair <int, int> st = { 0, 0 }, nd = { 0, 0 };
	cin >> st.first >> st.second;
	cin >> nd.first >> nd.second;
	--st.first;
	--st.second;
	--nd.first;
	--nd.second;

	for (int i = 0; i < h; ++i)
	{
		for (int j = 0; j < w; ++j)
		{
			cin >> g[i][j];
			dist[i][j] = INF;
		}
	}

	dist[st.first][st.second] = 0;
	deque <pair <int, int> > q;
	q.push_back(st);

	while (q.size() > 0)
	{
		pair<int, int> v = q.front();
		q.pop_front();

		for (auto cur : dir)
		{
			if (v.first + cur.first < h && v.second + cur.second >= 0 && v.second + cur.second < w && dist[v.first + cur.first][v.second + cur.second] > dist[v.first][v.second] && v.first + cur.first >= 0 && g[v.first + cur.first][v.second + cur.second] == '.')
			{
				used[v.first + cur.first][v.second + cur.second] = 1;
				dist[v.first + cur.first][v.second + cur.second] = dist[v.first][v.second];
				q.push_front(make_pair(v.first + cur.first, v.second + cur.second));
			}
		}

		for (int j = -2; j < 3; ++j)
		{
			for (int i = -2; i < 3; ++i)
			{
				pair <int, int> cur = { j, i };
				if (v.first + cur.first < h && v.first + cur.first >= 0 && v.second + cur.second >= 0 && v.second + cur.second < w && dist[v.first + cur.first][v.second + cur.second] > dist[v.first][v.second] + 1 && g[v.first + cur.first][v.second + cur.second] == '.')
				{
					used[v.first + cur.first][v.second + cur.second] = 1;
					dist[v.first + cur.first][v.second + cur.second] = dist[v.first][v.second] + 1;
					q.push_back(make_pair(v.first + cur.first, v.second + cur.second));
				}
			}
		}
	}

	if (dist[nd.first][nd.second] == INF)
	{
		cout << "-1\n";
	}
	else
	{
		cout << dist[nd.first][nd.second] << '\n';
	}
	return 0;
}


Measured memory_bytes: 15024
def kipp(i,f):
    if i == 3:
        if eval(f) == 7:
            print(f+"=7")
            exit()
    else:
        kipp(i+1,f+"+"+a[i+1])
        kipp(i+1,f+"-"+a[i+1])

a = list(input())
kipp(0,a[0])

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
using namespace std;
int s[2005], t[2005];
long long f[2005][2005];
long long mod = 1e9 + 7;
int main()
{
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
		cin >> s[i];
	for (int i = 1; i <= m; i++)
		cin >> t[i];
	for (int i = 0; i <= n; i++)f[i][0] = 1;
	for (int i = 0; i <= m; i++)f[0][i] = 1;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
		{
			f[i][j] = (f[i - 1][j] + f[i][j - 1] - f[i - 1][j - 1] + mod) % mod;
			//f[i][j]记录的是1~i,1~j各项f[i][j]的和
			if (s[i] == t[j])
				f[i][j] = (f[i][j] + f[i - 1][j - 1]) % mod;	//相当于各项都了延长1
		}
	cout << f[n][m] << endl;
	return 0;
}

Measured memory_bytes: 31616
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <utility>
#include <map>
#include <unordered_map>
using namespace std;
typedef long long int ll;

int main() {
  string S,T;
  cin>>S>>T;
  
  int ans=0;
  if(S[0]==T[0])
    ++ans;
  if(S[1]==T[1])
    ++ans;
  if(S[2]==T[2])
    ++ans;
  
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
int a[1005][1005];
int in[1000005];
vector<int> g[1000005];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n - 1; j++) {
      cin >> a[i][j];
    }
    for (int j = 1; j <= n - 2; j++) {
      g[min(i, a[i][j]) * 1000 + max(i, a[i][j])].pb(
          min(i, a[i][j + 1]) * 1000 + max(i, a[i][j + 1]));
      in[min(i, a[i][j + 1]) * 1000 + max(i, a[i][j + 1])]++;
    }
  }
  queue<int> q[2];
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      if (!in[i * 1000 + j])
        q[0].push(i * 1000 + j);
    }
  }
  int cnt = 0;
  for (int i = 0;; i ^= 1) {
    while (!q[i].empty()) {
      int u = q[i].front();
      q[i].pop();
      for (int v : g[u]) {
        in[v]--;
        if (!in[v])
          q[i ^ 1].push(v);
      }
    }
    cnt++;
    if (q[i ^ 1].empty())
      break;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      if (in[i * 1000 + j]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 47104
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
using namespace std;
int dp[2005][11]={};
int num[11][2005]={};
vector<int>qp[11];
int n,k;
int main()
{
  scanf("%d %d",&n,&k);
  for(int i=0;i<n;i++)
    {
      int a,b;
      scanf("%d %d",&a,&b);
      qp[b].push_back(a);
    }
  for(int i=1;i<=10;i++)
    {
      sort(qp[i].begin(),qp[i].end(),greater<int>());
    }
  for(int i=1;i<=10;i++)
    {
      for(int j=1;j<=qp[i].size();j++)
	{
	  num[i][j]=num[i][j-1]+2*j-2+qp[i][j-1];
	}
    }
  for(int i=1;i<=10;i++)
    {
      for(int j=0;j<=qp[i].size();j++)
	{
	  for(int l=k;l>=j;l--)
	    {
	      dp[l][i]=max(dp[l][i],dp[l-j][i-1]+num[i][j]);
	    }
	}
    }
  printf("%d\n",dp[k][10]);
  return 0;
}

      

Measured memory_bytes: 1196
#include <stdio.h>
 
int main(void) {
    int i,j;
    int H, W;
    
    while(1){
        scanf("%d %d",&H,&W);
        //???????????其
        if(H==0&&W==0) break;
        for(i=0;i<H;i++){
            for(j=0;j<W;j++){
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
         
        return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

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

    ll N, K;
    cin >> N >> K;
    vector<ll> H(N);
    REP(i, N) cin >> H[i];

    sort(H.begin(), H.end());

    ll S = 0;
    REP(i, N-K){
    	S += H[i];
    }
    cout << S << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
int main(){
    int i,j,k,m,a,n,b[1000],f[1000],r[1000],v[1000],h[11][11][11]={0};
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d %d %d %d",&b[i],&f[i],&r[i],&v[i]);
	}
	for(m=1;m<=4;m++){
		for(i=1;i<=3;i++){
			for(j=1;j<=10;j++){
				for(a=1;a<=n;a++){
					if(b[a]==m&&f[a]==i&&r[a]==j){
						h[m][i][j]+=v[a];
					}
				}
			}
		}
	}
	for(m=1;m<=4;m++){
		for(i=1;i<=3;i++){
			for(j=1;j<=10;j++){
				printf(" %d",h[m][i][j]);
			}
			printf("\n");
			if(i==3&&m!=4){
				printf("####################\n");
			}
		}
	}
	return 0;
}

Measured memory_bytes: 632
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int main () {
  int N;
  cin >> N;
  ll T[1010];
  ll A[1010];
  for (auto i = 0; i < N; ++i) {
    cin >> T[i] >> A[i];
  }

  ll X = 1, Y = 1;
  for (auto i = 0; i < N; ++i) {
    ll k = max((X+T[i]-1)/T[i], (Y+A[i]-1)/A[i]);
    X = T[i] * k;
    Y = A[i] * k;
  }
  cout << X + Y << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  REP(i, n) cin >> a[i];
  reverse(ALL(a));
  vector<int> dp(n);
  int INF = MOD;
  REP(i, n) dp[i] = INF;
  REP(i, n) { *upper_bound(ALL(dp), a[i]) = a[i]; }
  cout << lower_bound(ALL(dp), INF) - dp.begin() << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	ll a,b;
	cin>>a>>b;
	if(b==1)cout<<0;
	else{
			ll cnt=1,num=a;
			while(1){
				if(num>=b){
					cout<<cnt;
					return 0;
				}
				cnt++;
				num+=a-1;
			}
	}
	return 0;
}

Measured memory_bytes: 256
# D - Teleporter

n, k = map(int, input().split())
a = list(map(int, input().split()))
assert len(a) == n

# なげなわ検出
p = [1]
hash = {1: 0}  # p[hash[1]] == 1
while True:
    x = a[p[-1] - 1]
    if x in hash:
        break
    hash[x] = len(p)  # p[hash[x]] == x
    p.append(x)

# 0, 1, 2, ..., (hash[x], ..., len(p)-1)*
looplen = len(p) - hash[x]
if k < len(p):
    print(p[k])
else:
    print(p[(k - len(p)) % looplen + hash[x]])


Measured memory_bytes: 39056
#include<bits/stdc++.h>
using namespace std;
int h,w,a,b;
int main()
{
    cin>>h>>w>>a>>b;
    int cnt1=a;
    int cnt2=w-a;
    int low1=b;
    int low2=h-b;
    for(int i=1;i<=low1;i++)
    {
        cout<<string(cnt2,'0');
        cout<<string(cnt1,'1');
        cout<<"\n";
    }
    for(int i=1;i<=low2;i++)
    {
        cout<<string(cnt2,'1');
        cout<<string(cnt1,'0');
        cout<<"\n";
    }
    return 0;
}

Measured memory_bytes: 1280
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int n) { return n & 1; }
constexpr bool even(const int n) { return ~n & 1; }
template<typename T = int> T in() { T x; cin >> x; return x; }
template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; }
template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; }
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
// clang-format on

void call(int n) {
  int i = 1;
CHECK_NUM:
  int x = i;
  if (x % 3 == 0) {
    cout << " " << i;
    goto END_CHECK_NUM;
  }
INCLUDE3:
  if (x % 10 == 3) {
    cout << " " << i;
    goto END_CHECK_NUM;
  }
  x /= 10;
  if (x) goto INCLUDE3;
END_CHECK_NUM:
  if (++i <= n) goto CHECK_NUM;

  cout << endl;
}

main {
  int n;
  cin >> n;
  call(n);
}



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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define foreach(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
constexpr int MOD = 1e9 + 7;
constexpr int INF = __INT_MAX__;               // 2^31 - 1
constexpr long long INFLL = __LONG_LONG_MAX__; // 2^61 - 1
constexpr int MAX_N = 1e5 + 5;
constexpr double PI = acos(-1);

struct mint {
    // Preparation: MOD is already defined.
    ll value;

    mint(ll value = 0) : value((value % MOD + MOD) % MOD) {}

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    mint pow(mint m) const {
        return pow(m.value);
    }

    mint inv() const {
        ll a = value, b = MOD, u = 1, v = 0;
        while (b) {
            ll t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        u %= MOD;
        return u;
    }

    mint &operator+=(const mint a) {
        if ((value += a.value) >= MOD) value -= MOD;
        return *this;
    }
    mint &operator-=(const mint a) {
        if ((value += MOD - a.value) >= MOD) value -= MOD;
        return *this;
    }
    mint &operator*=(const mint a) {
        (value *= a.value) %= MOD;
        return *this;
    }
    mint &operator/=(const mint a) {
        return (*this) *= a.inv();
    }

    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

int main() {
    string n;
    cin >> n;
    reverse(all(n));
    int m = 0;
    int cnt = 0;
    rep(i, n.size()) {
        int d = n[i] - '0';
        if (m > 0) {
            d -= m;
            m = 0;
        }

        if (i + 1 < (int)n.size() && d < 9) {
            cnt += 9;
            m = 1;
        } else {
            cnt += d;
        }
    }
    out(cnt);
}


Measured memory_bytes: 256
#include <inttypes.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
    char S[4];
    bool ans = true;

    gets(S);

    if ((S[0] == S[1]) && (S[1] == S[2]))
        ans = false;

    if (ans)
        puts("Yes");
    else
        puts("No");

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
long long dp[100005];
int n,w[105],W,v[105],sum;
int main(){
	scanf("%d%d",&n,&W);
	memset(dp,0x3f,sizeof(dp));
	dp[0]=0;
	for (int i=1;i<=n;i++) scanf("%d%d",&w[i],&v[i]);
	for (int i=1;i<=n;i++){
		sum+=v[i];
		for (int j=sum;j>=v[i];j--)
			dp[j]=std::min(dp[j],dp[j-v[i]]+w[i]);
	}
	for (int i=sum;i>=0;i--)
		if (dp[i]<=W) {
			printf("%d\n",i);
			return 0;
		}
} 

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x); i<=(y); i++)
#define ll long long
#define N 210
using namespace std;
int n,cnt,head[N],chk[N],match[N];
struct node{ int x,y; }a[N],b[N];
struct edge{ int to,nxt; }e[N*N];
void adde(int x,int y){
	e[++cnt].to=y; e[cnt].nxt=head[x]; head[x]=cnt;
}
void ins(int x,int y){
	adde(x,y); adde(y,x);
}
bool dfs(int u){
	for (int i=head[u],v; i; i=e[i].nxt){
		v=e[i].to;
		if (!chk[v]){
			chk[v]=1;
			if (!match[v] || dfs(match[v])){
				match[v]=u; return 1;
			}
		}
	}
	return 0;
}
int main(){
	scanf("%d",&n);
	rep (i,1,n) scanf("%d%d",&a[i].x,&a[i].y);
	rep (i,1,n) scanf("%d%d",&b[i].x,&b[i].y);
	rep (i,1,n) rep (j,1,n){
		if (a[i].x<b[j].x && a[i].y<b[j].y) ins(i,j+n);
	}
	memset(match,0,sizeof(match));
	int ret=0;
	rep (i,1,n){
		memset(chk,0,sizeof(chk));
		if (dfs(i)) ret++;
	}
	printf("%d\n",ret);
	return 0;
}

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

int main() {
	int A, B;
	cin >> A >> B;
	int ans = 0;
	for (int i = A;i <= B;++ i) if (i / 10000 % 10 == i % 10 && i / 1000 % 10 == i / 10 % 10) ++ ans;
	cout << ans;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

5桁の回文数⇔1桁目と5桁目、2桁目と4桁目が等しい
*/

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        int i;
        Scanner sc= new Scanner(System.in);

        while(true){
            String sarr=sc.next();

            if(sarr.equals("-")){
                break;
            }

            int m=sc.nextInt();
            int sum=0;
            for(i=0;i<m;i++){
                int h=sc.nextInt();
                sum+=h;
            }
            
            for(i=0;i<sarr.length();i++){
                int last = (i+sum) % sarr.length();
                System.out.printf("%c",sarr.charAt(last));
            }
            System.out.println();
        }
        sc.close();
    }    
}


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

#define REP(i,n) for(int i=0; i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VC vector<char>
#define FOREACH(x,a) for(auto& (x) : (a) )
using namespace std;

int main() {
	int n;
	cin >> n;
	REP(i, n) {
		REP(j, n) {
			if (i * 4 + j * 7 == n) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
s = input()

x = len(s) // 2

a = 'g' * (len(s) - x) + 'p' * x
ans = 0
for i in range(len(s)):
    if s[i] == 'g' and a[i] == 'p':
        ans += 1
    elif s[i] == 'p' and a[i] == 'g':
        ans -= 1
print(ans)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e4+5;

int n, p, cur;
ll cnt[N], ans;

int main()
{
	string s;
	cin >> n >> p >> s;
	if (p == 2 || p == 5)
	{
		for (int i = 0; i < n; i++)
			if ((s[i] - '0') % p == 0)
				ans += i+1;
	}
	else
	{
		int t;
		cnt[0] = t = 1;
		for (int i = n - 1; i >= 0; i--)
		{
			cur = (cur + (s[i] - '0') * t) % p;
			ans += cnt[cur]++;
			t = t * 10 % p;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100003,INF=1<<30;
const int MAX_N=4000001;

int main(){
    
    int N;cin>>N;
    vector<int> A(N);
    int sum=0,right;
    for(int i=0;i<N;i++){
        cin>>A[i];
        sum+=A[i];
    }
    right=sum/2;
    bitset<MAX_N> dp;
    dp[0]=1;
    
    for(int i=0;i<N;i++){
        dp |= (dp << A[i]);
    }
    
    for(int i=right;i>=0;i--){
        if(dp[i]){
            cout<<sum-i<<endl;
            break;
        }
    }
    
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const long long mod = 1e9+7;
long long power(long long a, long long b, long long m = mod) {
    if(b < 0) {
        return power(power(a, -b), mod-2);
    }
    long long x = 1;
    while(b) {
        if(b & 1) {
            x = 1ll * x * a % m;
        }
        a = 1ll * a * a % m;
        b /= 2;
    }
    return x;
}
const int N = 50;
vector<pair<int, ll>> g[(N+1)*(N+1)*N];
signed main() {  
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    
    int n, m; cin >> n >> m;
    int s; cin >> s;
    s = min(s, (n-1)*N);
    for(int i = 0; i < m; i++) {
        int u, v, a, b; cin >> u >> v >> a >> b;
        u--; v--;
        for(int j = a; j <= N*N; j++) {
            g[j * n + u].push_back({(j-a)*n + v, b});
            g[j * n + v].push_back({(j-a)*n + u, b});
        }
    }
    for(int i = 0; i < n; i++) {
        int c, d; cin >> c >> d;
        for(int j = 0; j+c <= N*N; j++) {
            g[j * n + i].push_back({(j+c)*n + i, d});
        }
    }
    set<pair<ll, int>> q;
    q.insert({0, s * n + 0});
    const ll inf = 2e18;
    vector<ll> dist((N+1)*(N+1)*N, inf);
    dist[s*n] = 0;
    while(!q.empty()) {
        int u = q.begin()->second;
        q.erase(q.begin());
        for(auto it: g[u]) {
            int v = it.first; ll w = it.second;
            if(dist[v] > dist[u] + w) {
                q.erase({dist[v], v});
                dist[v] = dist[u] + w;
                q.insert({dist[v], v});
            }
        }
    }
    // cout << g[3][0].first << endl;
    for(int i = 1; i < n; i++) {
        ll mn = 2e18;
        for(int j = 0; j <= N*N; j++) {
            mn = min(mn, dist[j * n + i]);
        }
        cout << mn << '\n';
    }
    return 0;
    
}


Measured memory_bytes: 24924
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,q;
  cin>>n>>m>>q;
  vector<vector<int>> t(n,vector<int>(n,0));
  for(int i=0;i<m;i++){
    int l,r;
    cin>>l>>r;
    l--;
    r--;
    t.at(l).at(r)++;
  }
  vector<vector<int>> a(n,vector<int>(n,0));
  for(int w=0;w<n;w++){
    for(int i=0;i+w<n;i++){
      if(w==0)
        a[i][i+w]=t.at(i).at(i+w);
      else
        a[i][i+w]=a[i][i+w-1]+a[i+1][i+w]-a[i+1][i+w-1]+t.at(i).at(i+w);
    }
  }
  for(int i=0;i<q;i++){
    int pi,qi;
    cin>>pi>>qi;
    pi--;
    qi--;
    cout<<a[pi][qi]<<endl;
  }
}

Measured memory_bytes: 5624
#include <iostream>
#include <vector>
#include <algorithm>

class UnionFind{ //連結判定
private:
    std::vector<int> parent; //parent[i] = parent of node i
    std::vector<int> rank;
    std::vector<int> size;
public:
    //constructor
    UnionFind(int N){
        for(int i=0; i<N; i++) parent.push_back(i); //parent = [0,1,..,N-1]
        for(int i=0; i<N; i++) rank.push_back(0); //rank = [0,0,..,0]
        for(int i=0; i<N; i++) size.push_back(1);
    }
    //initialize
    void init(int N){
        parent.clear();
        rank.clear();
        size.clear();
        for(int i=0; i<N; i++) parent.push_back(i); //parent = [0,1,..,N-1]
        for(int i=0; i<N; i++) rank.push_back(0); //rank = [0,0,..,0]
        for(int i=0; i<N; i++) size.push_back(1);
    }
    int root(int a){
        if(parent[a] == a) return a;
        return parent[a] = root(parent[a]); //親が自分自身になるまで再帰を呼び出す & 経路圧縮 
    }
    void unite(int a, int b){
        int rootA = root(a);
        int rootB = root(b);
        if(rootA == rootB) return; //ノードa, bがすでに連結しているとき
        //次数の大きい方を親として連結
        if(rank[rootA] < rank[rootB]){
            size[rootB] += size[rootA];
            parent[rootA] = rootB;
        }
        else{
            size[rootA] += size[rootB];
            parent[rootB] = rootA;
            if(rank[rootA] == rank[rootB]) rank[rootA]++;
        }
    }
    bool same(int a, int b){
        return root(a) == root(b); //ノードa, bが同じ木に属するかどうか
    }
    int get_size(int a){
        return size[root(a)];
    }
};

int main()
{
    using Pair = std::pair<int, int>;

    // input
    int N, M;
    std::cin >> N >> M;
    std::vector<int> p(N), x(M), y(M);
    for(int i=0; i<N; i++){scanf(" %d", &p[i]); p[i]--;}
    for(int i=0; i<M; i++){
        scanf(" %d %d", &x[i], &y[i]);
        x[i]--; y[i]--;
    }

    UnionFind uf(N);
    for(int i=0; i<M; i++) uf.unite(x[i], y[i]);

    int count = 0;
    for(int i=0; i<N; i++){
        if(uf.same(i, p[i])) count++;
    }

    std::cout << count << std::endl;
}

Measured memory_bytes: 2936
n,k = map(int, input().split())
p = list(map(int, input().split()))
a = 0
for i in range(k):
  a += p[i]

cand = [a]
for i in range(n-k):
  a -= p[i]
  a += p[i+k]
  cand.append(a)

ans = max(cand)
print((ans+k)/2)


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

using namespace std;

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

ll INF=1e18;

int X,Y,Z;
ll A[100005],B[100005],C[100005];
ll a[100005],b[100005];
ll sa[100005],sb[100005];
P a_b[100005];
ll MX[100005],MY[100005];

int main() {
  
  cin>>X>>Y>>Z;
  
  ll add=0LL;
  
  for(int i=0; i<X+Y+Z; i++){
  	scanf("%lld %lld %lld", &A[i], &B[i], &C[i]);
  	a[i]=A[i]-C[i];
  	b[i]=B[i]-C[i];
  	a_b[i].first=a[i]-b[i]; a_b[i].second=i;
  	add+=C[i];
  }
  
  sort(a_b,a_b+X+Y+Z);
  
  for(int i=0; i<X+Y+Z; i++){
  	int j=a_b[i].second;
  	sa[i]=a[j]; sb[i]=b[j]; 
  }
  
  priority_queue <ll, vector<ll>, greater<ll> > mx,my; 
  
  for(int i=0; i<Y; i++){
  	my.push(sb[i]); 
  	MY[Y]+=sb[i];
  }
  
  for(int k=Y; k<Y+Z; k++){
  	my.push(sb[k]); 
  	MY[k+1]=MY[k]+sb[k]; MY[k+1]-=my.top(); 
  	my.pop();
  }
  
  for(int i=X+Y+Z-1; i>=Y+Z; i--){
  	mx.push(sa[i]);
  	MX[X]+=sa[i];
  }
  
  for(int k=X+1; k<=X+Z; k++){
  	mx.push(sa[X+Y+Z-k]);
  	MX[k]=MX[k-1]+sa[X+Y+Z-k]; MX[k]-=mx.top();
  	mx.pop();
  }

  
  ll ans=-INF;
  
  for(int k=Y; k<=Y+Z; k++){
  	ans=max(ans,MY[k]+MX[X+Y+Z-k]);
  }
  
  cout<<ans+add<<endl;
  
}


Measured memory_bytes: 8700
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin >> s;
    set< char > st;
    for( int i = 0; i < s.size(); ++i ) {
        st.insert( s[i] );

    }

    int res = INF;
    for( auto it = st.begin(); it != st.end(); ++it ) {
        char ch = *it;
        int er = 0;
        int tmp_res = 0;
        int pos = 0;
        while( s[pos] != ch ) {
            ++pos; ++er;

        }
        tmp_res = er;

        ++pos;
        while( pos < s.size() ) {
            int tmp_er = 0;
            while( pos < s.size() && s[pos] != ch ) {
                ++pos; ++tmp_er;

            }
            tmp_res += max( 0, tmp_er - er );
            if( tmp_er > er ) er += tmp_er - er;
            ++pos;

        }
        res = min( tmp_res, res );

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



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

using namespace std;

const int N = 300004;
int cnth[N], cntw[N], x[N], y[N];
map <int, bool> mp[N];

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int h, w, m;
    cin >> h >> w >> m;
    for (int i = 0; i < m; i++) {
        cin >> x[i] >> y[i];
        mp[x[i]][y[i]] = true;
        cnth[x[i]]++, cntw[y[i]]++;
    }
    int mxh = 0, mxw = 0;
    for (int i = 0; i < N; i++) {
        mxh = max(mxh, cnth[i]);
        mxw = max(mxw, cntw[i]);
    }
    vector <int> hall, wall;
    for (int i = 0; i < N; i++) {
        if (cnth[i] == mxh) {
            hall.push_back(i);
        }
        if (cntw[i] == mxw) {
            wall.push_back(i);
        }
    }
    int cnt = 0, mx = 0;
    for (int i = 0; i < hall.size(); i++) {
        for (int j = 0; j < wall.size(); j++) {
            cnt++;
            if (cnt > N * 2)
                break;
            mx = max(mx, mxh + mxw - mp[hall[i]][wall[j]]);
        }
        if (cnt > N * 2)
            break;
    }
    cout << mx;
}

Measured memory_bytes: 66492
s = input()
lenn = len(s)
n_bef = -1
l = []
def add_l(m,n):
	global n_bef
	p = m - n_bef
	q = n-m
	l.extend([0] * (p-1))
	l.append(-~p//2+q//2)
	l.append(p//2+(-~q)//2)
	l.extend([0] * (q-1))
	n_bef = n

for i in range(lenn-1):
	if s[i] == 'R' and s[i+1] == 'L':
		m = i
	if s[i] == 'L' and s[i+1] == 'R':
		n = i
		add_l(m,n)
	if i == lenn - 2:
		n = i + 1
		add_l(m,n)
print(*l)


Measured memory_bytes: 6424
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <map>
#include <queue>

#define mp make_pair
#define pb push_back
#define ppb pop_back
#define fi first
#define se second

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> pl;
typedef vector<ll> vl;
typedef vector<pl> vpl;
typedef vector<vl> vvl;
typedef vector<bool> vb;
typedef vector<vb> vvb;

#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define fors(i, n, s) for (int i = 0; i < (int)(n); i += s)
#define forn1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define forn11(i, n) for (int i = 1; i < (int)(n); ++i)
#define forr(i, n) for (int i = (int)(n) - 1; i >= 0; --i)

#define prOk(ok) cout << ((ok) ? "Yes" : "No")
#define in insert
#define rem remove

#define linf ((ll) 1e9)
#define inf ((int) 1e5)
#define otherinf 555555


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

	ll numSta, numLine;
	cin >> numSta >> numLine;

	static vpl g[otherinf];				//graph as connectivity list
	map<pl, ll> ids;

	ll lastId = numSta;

	forn(i, numLine)
	{
		int a,b, com;
		cin >> a >> b >> com;
		a--; b--; com--;	//zero based

		ll ida, idb;

		if(ids.count(mp(a, com)) == 0)
		{
			ids[mp(a, com)] = ida = lastId++;
			g[a].pb(mp(ida, 1));
			g[ida].pb(mp(a, 0));
		}
		else
			ida = ids[mp(a, com)];

		if(ids.count(mp(b, com)) == 0)
		{
			ids[mp(b, com)] = idb = lastId++;
			g[b].pb(mp(idb, 1));
			g[idb].pb(mp(b, 0));
		}
		else
			idb = ids[mp(b, com)];

		g[ida].pb(mp(idb, 0));
		g[idb].pb(mp(ida, 0));
	}

	//SPFA for shortest path - https://en.wikipedia.org/wiki/Shortest_Path_Faster_Algorithm

	vl dist(otherinf, linf);
	dist[0] = 0;

	queue<ll> q;
	set<ll> inQ;

	q.push(0);
	inQ.insert(0);

	while(!q.empty())
	{
		ll u = q.front();
		q.pop();
		inQ.erase(u);

		for(auto e : g[u])
		{
			ll alt = dist[u] + e.second;
			if(alt < dist[e.first])
			{
				dist[e.first] = alt;
				if(inQ.count(e.first) == 0)
				{
					q.push(e.first);
					inQ.insert(e.first);
				}
			}
		}
	}

	if(dist[numSta-1] == linf)
		cout << -1;
	else
		cout << dist[numSta-1];

	return 0;
}

Measured memory_bytes: 77184
#include <bits/stdc++.h>
#define range(i, l, r) for(int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    lint H, W;
    cin >> H >> W;
    vec<string> grid(H);
    range(i, 0, H) cin >> grid.at(i);
    vec<string> res(H + 2, string(W + 2, '#'));
    range(i, 0, H) range(j, 0, W) {
        res.at(i + 1).at(j + 1) = grid.at(i).at(j);
    }
    range(i, 0, H + 2) cout << res.at(i) << "\n";
}

Measured memory_bytes: 256
//Coded by tzc_wk
/*
数据不清空，爆零两行泪。
多测不读完，爆零两行泪。
边界不特判，爆零两行泪。
贪心不证明，爆零两行泪。
D P 顺序错，爆零两行泪。
大小少等号，爆零两行泪。
变量不统一，爆零两行泪。
越界不判断，爆零两行泪。
调试不注释，爆零两行泪。
溢出不 l l，爆零两行泪。
忘文件操作，爆零两行泪。
*/
#include <bits/stdc++.h>
using namespace std;
#define fi			first
#define se			second
#define fz(i,a,b)	for(int i=a;i<=b;i++)
#define fd(i,a,b)	for(int i=a;i>=b;i--)
#define foreach(it,v) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define all(a)		a.begin(),a.end()
#define giveup(...) return printf(__VA_ARGS__),0;
#define fill0(a)	memset(a,0,sizeof(a))
#define fill1(a)	memset(a,-1,sizeof(a))
#define fillbig(a)	memset(a,0x3f,sizeof(a))
#define fillsmall(a) memset(a,0xcf,sizeof(a))
#define mask(a)		(1ll<<(a))
#define maskx(a,x)	((a)<<(x))
#define _bit(a,x)	(((a)>>(x))&1)
#define _sz(a)		((int)(a).size())
#define filei(a)	freopen(a,"r",stdin);
#define fileo(a)	freopen(a,"w",stdout);
#define fileio(a) 	freopen(a".in","r",stdin);freopen(a".out","w",stdout)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define put(x)		putchar(x)
#define eoln        put('\n')
#define space		put(' ')
#define y1			y_chenxiaoyan_1
#define y0			y_chenxiaoyan_0
#define int long long
typedef pair<int,int> pii;
inline int read(){
	int x=0,neg=1;char c=getchar();
	while(!isdigit(c)){
		if(c=='-')	neg=-1;
		c=getchar();
	}
	while(isdigit(c))	x=x*10+c-'0',c=getchar();
	return x*neg;
}
inline void print(int x){
	if(x<0){
		putchar('-');
		print(abs(x));
		return;
	}
	if(x<=9)	putchar(x+'0');
	else{
		print(x/10);
		putchar(x%10+'0');
	}
}
inline int qpow(int x,int e,int _MOD){
	int ans=1;
	while(e){
		if(e&1)	ans=ans*x%_MOD;
		x=x*x%_MOD;
		e>>=1;
	}
	return ans;
}
int n=read(),m=read(),s=read(),c[55],d[55];
struct edge{
	int u,v,w;
	edge(){/*ycxakioi*/}
	edge(int _u,int _v,int _w){
		u=_u;v=_v;w=_w;
	}
};
const int MAGIC=2456;
inline int id(int x,int y){
	return x*(MAGIC+1)+y;
}
vector<edge> g[55*2555];
int dist[55*2555],vis[25*2555];
priority_queue<pii,vector<pii>,greater<pii> > q;
signed main(){
	fz(i,1,m){
		int u,v,a,b;cin>>u>>v>>a>>b;
		fz(j,0,MAGIC){
			if(j>=a){
//				cout<<id(u,j)<<endl;
				g[id(u,j)].push_back(edge(id(u,j),id(v,j-a),b));
				g[id(v,j)].push_back(edge(id(v,j),id(u,j-a),b));
			}
		}
	}
	fz(i,1,n)	c[i]=read(),d[i]=read();
	fz(i,1,n){
		fz(j,0,MAGIC-1){
			int cur=j+c[i];
			if(cur>=MAGIC){
				g[id(i,j)].push_back(edge(id(i,j),id(i,MAGIC),d[i]));
			}
			else{
				g[id(i,j)].push_back(edge(id(i,j),id(i,cur),d[i]));
			}
		}
	}
//	cout<<"g[2458].size()="<<g[2458].size()<<endl;
	fillbig(dist);
	dist[id(1,min(s,MAGIC))]=0;
	q.push({0,id(1,min(s,MAGIC))});
	while(!q.empty()){
		pii p=q.top();q.pop();
		int sum=p.fi,x=p.se;
//		cout<<x<<" "<<dist[x]<<endl;
		if(sum>dist[x])	continue;
//		puts("-1");
		foreach(it,g[x]){
			int y=it->v,z=it->w;
//			cout<<"y="<<y<<" "<<z<<endl;
			if(dist[y]>dist[x]+z){
				dist[y]=dist[x]+z;
				q.push({dist[y],y});
			}
		}
	}
	fz(i,2,n){
		int mn=0x3f3f3f3f3f3f3f3fll;
		fz(j,0,MAGIC)	mn=min(mn,dist[id(i,j)]);
		cout<<mn<<endl;
	}
	return 0;
}

Measured memory_bytes: 30120
import java.util.*;

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

		// 入力
		Scanner sc = new Scanner(System.in);
		
		// 数値
		int x = sc.nextInt();
		int y = sc.nextInt();
		int z = sc.nextInt();
		
		
		int ans = (x-z)/(y+z);
		// 出力
		System.out.println(ans);

		sc.close();

	}
}

Measured memory_bytes: 22612
N, x = map(int, input().split())
a = list(map(int, input().split()))

count = 0

a.sort()

for idx, v in enumerate(a):
    if v <= x:
        x -= v
        if idx == N - 1:
            if x == 0:
                count += 1
        else:
            count +=1

print(count)


Measured memory_bytes: 9104
/*************************************************************************
    > File Name: C.cpp
    > Author: Roundgod
    > Mail: wcysai@foxmail.com 
    > Created Time: 2018-11-29 14:00:54
 ************************************************************************/

#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define MAXN 100005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll N,Q,k;
string str;
int main()
{
    scanf("%lld",&N);
    cin>>str;
    scanf("%lld",&Q);
    for(ll i=0;i<Q;i++)
    {
        scanf("%lld",&k);
        ll ans=0;
        ll d=0,m=0,cur=0;
        for(ll now=0;now<N;now++)
        {
            if(str[now]=='D') d++;
            else if(str[now]=='M') {cur+=d; m++;}
            else if(str[now]=='C')  ans+=cur;
            if(now+1>=k)
            {
                if(str[now+1-k]=='D') {cur-=m; d--;}
                else if(str[now+1-k]=='M') m--;
            }
        }
        printf("%lld\n",ans);
    }
    return 0;
}



Measured memory_bytes: 1412
#include<bits/stdc++.h>
#define int long long
using namespace std;
int dp[100001][3], N, inp[100001][3];

int thunder(int currDay, int lastAct){
    if(currDay > N){
        return 0;
    }
        //Doing A activity
    if(dp[currDay][0] == -1){
        dp[currDay][0] = inp[currDay-1][0] + thunder(currDay+1, 0);
    }   //Doing B activity
    if(dp[currDay][1] == -1){
        dp[currDay][1] = inp[currDay-1][1] + thunder(currDay+1, 1);
    }   //Doing C activity
    if(dp[currDay][2] == -1){
        dp[currDay][2] = inp[currDay-1][2] + thunder(currDay+1, 2);
    }
    if(lastAct == 0){ // Can do only 1 and 2
        return max(dp[currDay][1], dp[currDay][2]);
    }else if(lastAct == 1){
        return max(dp[currDay][0], dp[currDay][2]);
    }else if(lastAct == 2){
        return max(dp[currDay][0], dp[currDay][1]);
    }else{
        return max(dp[currDay][0], max( dp[currDay][1], dp[currDay][2] ));
    }
}

signed main(){
    memset(dp, -1, sizeof(dp));
    cin>>N;
    for(int i=0; i<N; i++){
        cin>>inp[i][0]>>inp[i][1]>>inp[i][2];
    }
    cout<<thunder(1, -1)<<endl;
    return 0;
}

Measured memory_bytes: 9600
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial, log, log10, log2
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
from datetime import datetime as dt

def main():
  n = int(readline())
  S = []
  for _ in range(n):
    S.append(''.join(sorted(input())))
  counter = Counter(S)
  ans = 0
  for i in counter.values():
    ans +=  i*(i-1)/2
  print(int(ans))
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 30256
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

const int MAX = 1e5 + 10;
int N, M;
LL H[MAX];
int A[MAX], B[MAX];

int main(void) {
    cin >> N >> M;
    REP(i, N) {
        cin >> H[i];
    }
    REP(i, M) {
        cin >> A[i] >> B[i];
        A[i]--; B[i]--;
    }

    VT<bool> nice(N, true);
    REP(i, M) {
        if (H[A[i]] == H[B[i]]) {
            nice[A[i]] = nice[B[i]] = false;
        } else if (H[A[i]] > H[B[i]]) {
            nice[B[i]] = false;
        } else {
            nice[A[i]] = false;
        }
    }

    int ans = 0;
    REP(i, N) ans += nice[i];

    cout << ans << endl;
}


Measured memory_bytes: 5200
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,K=MI()
    a=N%K
    b=K-N%K
    print(min(a,b))

main()


Measured memory_bytes: 38384
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int ans;
    char[] nums = sc.nextLine().toCharArray();
    int numLength = nums.length;
    int bw = 0;
    int wb = 0;
    for(int cnt = 0; cnt < numLength ; cnt++){
      if( nums[cnt] == ((cnt % 2 == 0)? '0': '1' )){
        bw++;
      }
      else {
        wb++; 
      }
    }
    ans = Math.min(bw,wb);
    System.out.println(ans);
    sc.close();
  }
}

Measured memory_bytes: 40484
#標準入力からの値取得(N)
N = int(input())
#標準入力からの値取得(List)
S = []
for i in range(N):
  S.append(input())
#ループで廻しつつ要素数をカウントする
ans = {}
for cnt in S:
  if cnt in ans:
    ans[cnt] += 1
  else:
  	ans[cnt] = 1
max_v = max(ans.values())
#ソートしながら出力。辞書をソートするとリストになるので注意。
for k, v in sorted(ans.items()):
  if v == max_v:
    print(k)

Measured memory_bytes: 45708