akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<queue>
using namespace std;

int n,m;
bool g[50][50];
bool visited[50];


void dfs(int i){
    visited[i] = true;
    for(int j = 0;j<n;j++){
        if(!g[i][j]){
            continue;
        }
        if(visited[j]){
            continue;
        }
        dfs(j);
    }
}

int main(){
    cin >> n >> m;
    int  a[m],b[m];
    for(int i=0;i<m;i++){
        cin >> a[i] >> b[i];
        a[i]--;b[i]--;
        g[a[i]][b[i]] = true;
        g[b[i]][a[i]] =true;
    }
    int ans = 0;
    for(int i=0;i<m;i++){
        g[a[i]][b[i]] = g[b[i]][a[i]] = false;
        for(int j=0;j<n;j++){
            visited[j] = false;
        }
        dfs(0);

        bool bridge = false;
        for(int j=0;j<n;j++){
            if(!visited[j]){
                bridge = true;
            }
        }
        if(bridge){
            ans ++;
        }
        g[a[i]][b[i]] = g[b[i]][a[i]] = true;
    }
    cout << ans << endl;
    return 0;
}

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

int main(int argc,char const* argv[])
{
  int n;
  string s;
  cin >> n >> s;
  int cnt=0,cnt2=0;
  for(int i=0;i<n;i++)
    {
      if(s[i]=='(') cnt++;
      else 
	{
	  if(cnt==0)cnt2++;
	  else cnt--;
	}
    }
  for(int i=0;i<cnt2;i++)
    {
      s="("+s;
    }
  for(int i=0;i<cnt;i++)
    {
      s+=")";
    }
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 256
/*     Abhinav Vaishya (abhinav_2812)          */
/*     DA-IICT                    */


#include<cstdio>
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<iomanip>

using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector<int> vi;
typedef vector<long long> vl;


#define MOD 1000000007
#define si(n) scanf("%d",&n)
#define sd(n) scanf("%lf",&n)
#define sl(n) scanf("%lld",&n)
#define sld(n) scanf("%Lf",&n)
#define ss(s) scanf("%s",s)
#define pi(n) printf("%d",n)
#define pd(n) printf("%lf",n)
#define pl(n) printf("%lld",n)
#define pld(n) printf("%Lf",n)
#define ps(s) printf("%s",s)
#define pline printf("\n")
#define _for(i,a,n) for(int i=a; i<n; i++)
#define __for(i,a,n) for(int i=a; i<=n; i++)
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define ALL(x) x.begin(),x.end()

int max_ar(vi &a);
int min_ar(vi &a);
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b);

//----Code starts here----//
int main() {
        LL n;
        sl(n);
        LL p=1;
        __for(i,1,n) {
                p=(p*i)%MOD;
        }
        pl(p); pline;
        return 0;
}
//----Code ends here----//



//maximum element in a vector
int max_ar(vi &a) {
        int mx=-1;
        _for(i,0,a.size()) mx=max(mx,a[i]);
        return mx;
}

//minimum element in a vector
int min_ar(vi &a) {
        int mn=1000000000;
        _for(i,0,a.size()) mn=min(mn,a[i]);
        return mn;
}

//sort a pair vector by second element
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b) {
        return (a.second < b.second);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
const int maxn = 1e5 + 5;
int aodd[maxn];
int aeven[maxn];
 
int main(){
  int n; cin >> n;
  int x;
  memset(aodd,0,sizeof(aodd));
  memset(aeven,0,sizeof(aeven));
  int a1 = 0, b1 = 0, a2 = 0, b2 = 0,c1 = 0, c2 = 0;
  //int z = 0, y = 0;
  for(int i = 0; i < n; ++i){
     cin >> x;
     if(i%2){aeven[x]++; 
     
         if(aeven[x] > a1)c1 = x;
         if(c1 != x)b1 = max(b1,aeven[x]);
         a1 = max(a1,aeven[x]);
     }
     else{ 
         aodd[x]++;
         if(aodd[x] > a2)c2 = x;
         if(c2 != x)b2 = max(b2,aodd[x]);
         a2 = max(a2,aodd[x]);
     }
  }
  //cout << a1 << ' ' << a2 << '\n';
  if(c1 != c2) cout << n - a1 - a2 << '\n';
  else cout << min(n - (a1 + b2),n - (b1 + a2)) << '\n';
}

Measured memory_bytes: 4376
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<ll, ll>
#define ull unsigned ll
#define f first
#define s second
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
#define SQ(x) (x)*(x)
#define MN(a,b) a = min(a,(__typeof__(a))(b))
#define MX(a,b) a = max(a,(__typeof__(a))(b))
#define pb push_back
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#ifdef BALBIT
#define IOS()
#define bug(...) fprintf(stderr,"#%d (%s) = ",__LINE__,#__VA_ARGS__),_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define bug(...)
#endif

const int iinf = 1e9+10;
const ll inf = 1ll<<60;
const ll mod = 1e9+7 ;


void GG(){cout<<"0\n"; exit(0);}

ll mpow(ll a, ll n, ll mo = mod){ // a^n % mod
    ll re=1;
    while (n>0){
        if (n&1) re = re*a %mo;
        a = a*a %mo;
        n>>=1;
    }
    return re;
}

ll inv (ll b, ll mo = mod){
    if (b==1) return b;
    return (mo-mo/b) * inv(mo%b,mo) % mo;
}

const int maxn = 1e2+5;

vector<int> g[maxn];
int mx[maxn];
int mxd = 0;
void dfs(int v, int p=-1, int dep = 1) {
    mxd = max(mxd, dep);
    int nch = 0;
    for (int u : g[v] ) {
        if (u != p) {
            dfs(u,v,dep+1);
            nch++;
        }
    }
    mx[dep] = max(mx[dep], nch);
}

signed main(){
    IOS();
    int n; cin>>n;
    vector<pii> tmp;
    for (int i = 0; i<n-1; ++i) {
        int a,b; cin>>a>>b;
        --a; --b;
        tmp.pb({a,b});
        g[a].pb(b); g[b].pb(a);
    }
    pii Re = {1000 , 1};
    for (int i = 0; i<n; ++i) {
        memset(mx, 0, sizeof mx);
        mxd = 0;
        dfs(i);
        if (mxd > n/2+1) continue;
        ll re = 1;
        for (int j = 1; mx[j] != 0; ++j) {
            re *= mx[j];
        }
        Re = min (Re, {mxd, re});
    }
    for (pii p : tmp) {
        memset(mx, 0, sizeof mx);
        mxd = 0;
        dfs(p.f, p.s);
        dfs(p.s, p.f);
        if (mxd > n/2+1) continue;
        ll re = 2;
        for (int j = 1; mx[j] != 0; ++j) {
            re *= mx[j];
        }
        Re = min (Re, {mxd, re});
    }
    cout<<Re.f<<' '<<Re.s<<endl;


}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

typedef long long ll;

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; }
const int INF = 1e9;
const long long INFL = 1LL<<60;

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  set<string> ss;
  rep(i, n) {
    string str;
    cin >> str;
    s[i] = str;
    ss.insert(str);
  }
  int m;
  cin >> m;
  vector<string> t(m);
  rep(i, m) {
    cin >> t[i];
  }
  int ans = 0;
  for (auto itr = ss.begin(); itr != ss.end(); itr++) {
    int sc = count(ALL(s), *itr);
    int tc = count(ALL(t), *itr);
    chmax(ans, sc - tc);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<fstream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<climits>
#include<set>
#include<map>
#include<cmath>
#include<iomanip>
#include<iterator>
#include<queue>
#include<stack>
#include<cctype>
#include<deque>
#include<time.h>
#include<bitset>
#include<random>
#include<unordered_set>
#include<unordered_map>

//by Skeef79

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:16777216")
#define pb push_back
#define en '\n'
#define for0(i,n) for(int i = 0;i<n;i++)
#define for1(i,n) for(int i = 1;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define vec vector
#define pii pair<int,int>
#define pll pair<ll,ll>
#define REP(a,i,b) for (int i = a;i<b;i++);

using namespace std;

const int INF = 2000000000;
const ll LINF = 2000000000000000000;

template<typename T> void print(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}

template<typename T> void print(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}

template<typename T> void print(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
	{
		for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << ' ';
		cout << en;
	}
}

template <typename T> void input(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cin >> a[i];
}

template<typename T> void input(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cin >> a[i];
}

template<typename T> void input(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
		for (int j = 0; j < a[i].size(); j++)
			cin >> a[i][j];
}

void solve()
{
	int n;
	cin >> n;
	vector<int> a(n);
	input(a);
	vector<bool> f(n + 1,false);

	for (auto to : a)
		if (to == 1)
			f[to] = 1;
		else
			if (f[to - 1])
				f[to] = 1;
	
	if (!f[1])
		cout << -1;

	else
	{
		int idx = 1;
		while (idx <= n && f[idx])
			idx++;
		//if (idx <= n && !f[idx])
			//idx--;
		idx--;
		//idx--;
		cout << n - idx;
	}
}


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


#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif

	//freopen("journey.in", "r", stdin);
	//freopen("journey.out", "w", stdout);


	int tst = 1;
	//cin >> tst;
	while (tst--)
		solve();


}

Measured memory_bytes: 1024
// failed to generate code

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

int N;
double dp[301][301][301];

double rec(int i, int j, int k) {
	if (i == 0 && j == 0 && k == 0) return 0.0;
	if (i == -1 || j == -1 || k == -1) return 0.0;
	if (dp[i][j][k] > 0.0) return dp[i][j][k];
	// printf("%d,%d,%d\n",i,j,k);
	return dp[i][j][k] = 1.0/(i+j+k)*(rec(i-1,j,k)*i+rec(i+1,j-1,k)*j+rec(i,j+1,k-1)*k+N);
}

int main(){
	int i = 0, j = 0, k = 0;
	scanf("%d", &N);
	int n;
	for (int l = 0; l < N; l++) {
		scanf("%d", &n);
		if (n == 1) i++;
		if (n == 2) j++;
		if (n == 3) k++;
	}
	printf("%.16f\n", rec(i,j,k));
	return 0;
}


Measured memory_bytes: 213248
#include <cstdio>

const int MOD=1e9+7;

struct Matrix{
  int mat[50][50];
  Matrix(){
    for(int i=0;i<50;i++){
      for(int j=0;j<50;j++){
	mat[i][j]=0;
      }
    }
  }
  Matrix operator*(Matrix m)const{
    Matrix res;
    for(int i=0;i<50;i++){
      for(int j=0;j<50;j++){
	for(int k=0;k<50;k++){
	  res.mat[i][j]=(res.mat[i][j]+1LL*mat[i][k]*m.mat[k][j])%MOD;
	}
      }
    }
    return res;
  }
};

int main(){
  int N;
  long long K;
  scanf("%d %lld",&N,&K);
  struct Matrix base;
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      scanf("%d",&base.mat[i][j]);
    }
  }
  struct Matrix ac;
  for(int i=0;i<N;i++){
    ac.mat[i][i]=1;
  }
  for(;K;K>>=1){
    if(K&1) ac=ac*base;
    base=base*base;
  }
  int ans=0;
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      ans=(ans+ac.mat[i][j])%MOD;
    }
  }
  printf("%d\n",ans);
  return 0;
}


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

using namespace std;

int main(){
  int N, K;
  cin >> N >> K;
  
  vector<int> vals(N+1);
  vector<int> sum(N+2);

  vals[0] = 0;
  sum[0] = 0;
  for(int i = 1; i <= N; i++){
    cin >> vals[i];
    sum[i] = sum[i-1] + vals[i];
  }
  sum[N+1] = sum[N];
  
  int maxVal = -1;
  for(int i = 1; i <= N-K+1; i++){
    int temp = sum[i+K-1] - sum[i-1];
    maxVal = max(temp, maxVal);
  }
  
  cout << setprecision(10) << (double)(maxVal + K) * 0.5;
  
  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long int
#define Endl endl
#define mod  1000000007
#define mkp make_pair
#define pb push_back
#define cin(n) scanf("%d",&n)
#define cout(n) printf("%d ",n)
#define sf(n) scanf("%d",&n)
#define pf(n) printf("%d ",n)
#define bitget(n) __builtin_popcountll(n)

ll dx[] = {1,1,0,-1,-1,-1,0,1};
ll dy[] = {0,-1,-1,-1,0,1,1,1};
ll dxx[] = {1,-1,0,0};
ll dyy[] = {0,0,-1,1};
ll modexpo(ll x,ll y){if(y==0)return 1;if(y%2){ll viky=modexpo(x,y/2);
return (((x*viky)%mod)*viky)%mod;}else{ll viky=modexpo(x,y/2);return (viky*viky)%mod;
}}
ll intpoint(ll x1, ll y1, ll x2, ll y2) { return ( __gcd(abs(x1-x2),abs(y1-y2))+1); }
bool isvalid(ll x,ll y,ll n,ll m) { return (x>=0&&x<n&&y>=0&&y<m); }
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// int pp = uniform_int_distribution<int>(0, kk-1)(rng);
// ---------------------///////////////---------------------------------
// ---------------------///////////////----------------------------------
// -------------/////////////////---------------------------------///////
ll dp[100011][3];



int main()
{
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll t,i,j,l,r,q,k,kk,x,p,m,n;
    cin>>n;
    for(i=0;i<n;i++){
      cin>>dp[i][0]>>dp[i][1]>>dp[i][2];
    }

    for(i=1;i<n;i++){
      dp[i][0] = dp[i][0] + max(dp[i-1][1],dp[i-1][2]);
      dp[i][1] = dp[i][1] + max(dp[i-1][0],dp[i-1][2]);
      dp[i][2] = dp[i][2] + max(dp[i-1][1],dp[i-1][0]);
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const ll N = 100011;
int n, a[N], a4, m, a6, x;
vector<int> g[N];
bool mark[N] ; 
void dfs(int v, int par){
	mark[v] = 1 ;
	for(int i = 0 ; i < g[v].size() ; i ++){
		if(g[v][i] == par)
			continue ;
		if(g[v][i] == x){
			cout << "Yes" ;
			exit(0) ;
		}
		if(!mark[g[v][i]])
			dfs(g[v][i], v) ;
	}
}
int main()
{
	scanf("%d%d", &n, &m) ;
	for(int i = 1 ; i <= m ; i ++){
		int u, v ;
		scanf("%d%d", &v, &u) ;
		g[v].push_back(u) ;
		g[u].push_back(v) ;
	}
	for(int i = 1 ; i <= n ; i ++){
		if(g[i].size() % 2 == 1)
			return cout << "No", 0 ;
		if(g[i].size() >= 6)
			a6 ++ ;
		if(g[i].size() == 4)
			a4 ++ ;
	}	
	if(a6 or a4 >= 3)
		return cout << "Yes", 0 ; 
	if(a4 < 2)
		return cout << "No", 0 ;
	for(int i = 1 ; i <= n ; i ++){
		if(g[i].size() != 4)
			continue ;
		if(x == 0)
			x = i ;
		else{
			mark[x] = 1 ;
			x = i ; 
			dfs(i, 0) ; 
		}
	}
	cout << "No" ; 
}

Measured memory_bytes: 7040
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

template <class F>
int upper_bound(int i0, int i1, F f) {
    while (i0 < i1) {
        int i = (i0 + i1) / 2;
        if (f(i)) i0 = i + 1; else i1 = i;
    }
    return i0;
}

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

    int n, x;
    cin >> n >> x;

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

    auto f = [&](int k) {
        ll s = 0;
        for (int i = 0; i < n; i++) {
            int j = i / k;
            if (j == 0) {
                s += 2 * x + 5 * (ll)a[i];
            } else {
                s += x + (j * 2 + 3) * (ll)a[i];
            }
        }
        return s;
    };

    int k = upper_bound(1, n, [&](int k) {
        return f(k + 1) - f(k) < 0; // kが大きくなるほど満たされなくなる条件
    });
    cout << f(k) << endl;
    
    //ll r = 1LL << 60;
    //for (int k = 1; k <= n; k++) {
    //    r = min(r, f(k));
    //}

    //cout << r << endl;

    //まとめたほうが移動距離が短くなる
    //まとめたほうが捨てるコストが減る ここがXに依存
    //まとめたほうが移動コストが高くなる
    //ゴミには距離の違いしかない
    //持ってるゴミが少ないほうが、新たにゴミを追加する移動コストは小さい
    //まばらに拾うことはあるか？
    //まず、一番遠いゴミを拾いに行く
    //理想手順でk個目のゴミとなることで番号を付ける その番号さえわかれば答えがわかる！
    //番号が大きくなるとその番号を持つゴミの個数は広義単調減少
    //2番になりたくない人は1番で確定、2番になりたい人が多いと3番とかに回ってもらうか1番になってもらうことになる
    //1番の数を決めればあとは自動やんけ 遠い順に小さい番号を割り当てるだけ これで部分点は取れそう
    //全部1番にするところから、1つだけ1番にするところまで


    return 0;
}

Measured memory_bytes: 1024
num = int(input(""))
val = list(map(int,input().split()))
val_sum = sum(val)
ans = 0
mod = 10**9 + 7

for i in range(num):
    val_sum = val_sum - val[i]
    ans     = val[i] * val_sum + ans
        
print(ans%mod)

Measured memory_bytes: 31552
import java.util.*;

import java.lang.*;

import java.math.*;



public class Main {

	Scanner sc = new Scanner(System.in);



	void run() {

		char[][][] affine = new char[26][26][26];

		char[][][] invaffine = new char[26][26][26];

		for (int i = 0; i < 26; i++) {

			for (int j = 0; j < 26; j++) {

				for (int k = 0; k < 26; k++) {

					affine[i][j][k] = (char) (((i * j + k) % 26) + 'a');

					invaffine[(((i * j + k) % 26) )][j][k] = (char)(i+'a');

				}

			}

		}

		String[][][] thisThat = new String[2][26][26];

		for (int i = 0; i < 26; i++) {

			for (int j = 0; j < 26; j++) {

				if ( i % 2 != 0 && i % 13 != 0) {

					thisThat[0][i][j] = "";

					thisThat[1][i][j] = "";

					thisThat[0][i][j] += affine['t' - 'a'][i][j];

					thisThat[0][i][j] += affine['h' - 'a'][i][j];

					thisThat[0][i][j] += affine['i' - 'a'][i][j];

					thisThat[0][i][j] += affine['s' - 'a'][i][j];

					thisThat[1][i][j] += affine['t' - 'a'][i][j];

					thisThat[1][i][j] += affine['h' - 'a'][i][j];

					thisThat[1][i][j] += affine['a' - 'a'][i][j];

					thisThat[1][i][j] += affine['t' - 'a'][i][j];

					// System.out.println(thisThat[0][i][j] + " "+

					// thisThat[1][i][j]);

				}

			}

		}

		int n = sc.nextInt();

		sc.nextLine();

		for (int q = 0; q < n; q++) {

			String target = sc.nextLine();

			int afi = 0;

			int afb = 0;

			for (int i = 0; i < 26; i++) {

				for (int j = 0; j < 26; j++) {

					if (i % 2 != 0 && i % 13 != 0) {

						for (String parts : target.split(" ")) {

							if (parts.equals(thisThat[0][i][j])

									|| parts.equals(thisThat[1][i][j])) {

								afi = i;

								afb = j;

							}

						}

					}

				}

			}

			String ans = "";

			for (Character c : target.toCharArray()) {

				if (Character.isLetter(c)) {

					ans += invaffine[c - 'a'][afi][afb];

				} else {

					ans += c;

				}

			}

			System.out.println(ans);

		}

	}



	public static void main(String[] args) {

		Main m = new Main();

		m.run();



	}

}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long ll;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++)

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}

#define PRINT_VECTOR_MAX 100
template <class S> void print(vector<S> &v){for(ll i=0; i<(ll)min(v.size(),PRINT_VECTOR_MAX); i++){cerr << v[i] << ' ';}cerr << endl;}
template <class S> void print(vector<vector<S>> &v) {for (ll i = 0; i < (ll)min(v.size(),PRINT_VECTOR_MAX); i++) {for (ll j = 0; j < (ll)min(v[i].size(),PRINT_VECTOR_MAX); j++) {cerr << v[i][j] << ' ';}cerr << endl;}}

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

void Main(){
	int n,m; cin >> n >> m;
	vector<ll> a(n), b(m);
	rep(i,n) cin >> a[i];
	rep(i,m) cin >> b[i];
	auto c = convolution(a,b);
	for(auto k: c){
		cout << k << ' ';
	}
}


Measured memory_bytes: 27284
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
//void IO(){
//	#ifndef ONLINE_JUDGE
//	    freopen("input.txt", "r", stdin);
//	    freopen("output.txt", "w", stdout);
//	#endif
//}
// end of Template

int a[3];
int main(){
	//IO();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    for(int i=0;i<3;i++)cin>>a[i];
    sort(a,a+3);
    cout<<a[2]-a[0]<<newl;
}


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

#define rep(i,n) for(int i = 0;i < n;++i)
#define rep2(i,n,m) for(int i = n;i < m;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;

const int INF = 1001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    map<string,int> memo;
    rep(i,n) {
        string s;
        cin >> s;
        memo[s] = 1;
    }
    cout << memo.size() << endl;




    cout << endl;
    return 0;
}

Measured memory_bytes: 19140
#include<bits/stdc++.h>
#define f(i,a,b) for(register int i=a;i<=b;++i)
#define ff(i,a,b) for(register int i=a;i>=b;--i)
#define debug(x) cerr << #x << " : " << x << " " << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
const ll mod = 1e9 + 7;
const double tiaohe = 0.57721566490153286060651209;
ll oula(ll x) { ll res = x;f(i, 2, x / i) { if (x % i == 0) { res = res / i * (i - 1);while (x % i == 0) x /= i; } }if (x > 1) res = res / x * (x - 1);return res; }
ll quickmod(ll a, ll n, ll m) { ll s = 1;while (n) { if (n & 1) { s = s * a % m; }a = (a*a) % m;n = n / 2; }return s; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
void ex_gcd(ll a, ll b, ll &x, ll &y, ll &d) { if (!b) { d = a, x = 1, y = 0; } else { ex_gcd(b, a % b, y, x, d);y -= x * (a / b); } }
ll inv(ll t, ll p) { ll d, x, y;ex_gcd(t, p, x, y, d);return d == 1 ? (x % p + p) % p : -1; }
bool isPrime(ll x) { if (x == 2)return true;if (x % 2 == 0)return false;for (ll i = 2;i*i <= x;i++) if (x % i == 0)return false; return true; }
//double a = log(n) +tiaohe + 1.0 / (2 * n);
double eqa = (1 + sqrt(5.0)) / 2.0;

const int N = 2e5 + 5;
int t;

int main()
{
//	freopen("in.txt", "r", stdin);
	int a, b, c, d, e;
	while (cin >> a >> b >> c >> d >> e)
	{
		if (a == 0)puts("1");
		else if (b == 0)puts("2");
		else if (c == 0)puts("3");
		else if (d == 0)puts("4");
		else puts("5");
	}
	return 0;
}

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

int main() {
    int d;
    cin>>d;
    if(d==22)cout<<"Christmas Eve Eve Eve"<<endl;
    else if(d==23)cout<<"Christmas Eve Eve"<<endl;
    else if(d==24)cout<<"Christmas Eve"<<endl;
    else cout<<"Christmas"<<endl;
	return 0;
}

Measured memory_bytes: 256
n,c,k=map(int,input().split())
t=[]
bus=0
for _ in range(n):
	x=int(input())
	t.append(x)
t.sort()
cnt=0
timelimit=t[0]+k
for i in range(n):
	cnt+=1
	if t[i]>timelimit:
		bus+=1
		cnt=1
		timelimit=t[i]+k
	elif cnt==c:
		bus+=1
		cnt=0
		if i!=n-1:
			timelimit=t[i+1]+k
if cnt!=0:
	bus+=1
print(bus)


Measured memory_bytes: 7440
#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
 
using namespace std;
#define PB push_back
#define MP make_pair
#define REP(i,n) for(int i=0;i<(n);i++)
#define ll long long
int main()
{
    int n,m;
    int p[100100];
    int cnt[100100];
    bool ac[100100];
    string s[100100];

    cin>>n>>m;
    REP(i,m)cin>>p[i]>>s[i];

    REP(i,100100)
    {
        ac[i]=false;
        cnt[i]=0;
    }

    REP(i,m)
    {
        if(s[i]=="AC")
        {
            if(!ac[p[i]])
            {
                ac[p[i]]=true;
            }
        }else
        {
            if(!ac[p[i]])
            {
                cnt[p[i]]++;
            }
        }
    }
    int ans1=0,ans2=0;
    REP(i,n)if(ac[i+1])
    {
        ans1++;
        ans2+=cnt[i+1];
    }
    cout<<ans1<<" "<<ans2<<endl;

}

Measured memory_bytes: 6656
/*
    NEVER GIVE UP!
    THE EXPERT IN ANYTHING WAS ONCE A BEGINNER
*/

#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define f(i,a,b) for(ll i=a; i<=b; i++)
#define fi(i,a,b) for(ll i=a; i>=b; i--)
#define fa(x,b) for(auto x:b)
#define TC ll test_case; cin>>test_case; for(ll number=1 ; number <= test_case ; number ++ )
#define vll vector<ll>
#define pb push_back
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second
#define sz(a) (ll)(a).size()
#define sp(x) cout << fixed << setprecision(x);
#define ReadFile freopen("input.txt","r",stdin)
#define WriteFile freopen("output.txt","w",stdout)
#define endl "\n"

const ld pi = acos(-1);
const ll M=1e9+7,N=1e7+5,INF=1e18;


void solve()
{
    ll a,b,k;
    cin >> a >> b >> k;

    // cout << a << " " << b << " " << k << endl;

    if(a>=k)
    {
        a-=k;
        k=0;
    }
    else
    {        
        k-=a;
        a=0;
    }
    
    // cout << a << " " << k << endl;

    if(b>=k)
    {
        b-=k;
        k=0;
    }
    else
    {        
        k-=b;
        b=0;
    }
    
    // cout << b << " " << k << endl;
    
    cout << a << " " << b;
    
}

int32_t main()
{
    FIO
    solve();
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

if n == 3:
    if a[0] == a[1]^a[2]:
        print("Yes")
    else:
        print("No")
elif sum(a) == 0:
    print("Yes")
else:
    vals = []
    cnts = []

    for i in range(n):
        if a[i] in vals:
            cnts[vals.index(a[i])] += 1
        else:
            if len(vals) == 3:
                print("No")
                exit()

            vals.append(a[i])
            cnts.append(1)

    if len(vals) == 3 and (vals[0] == vals[1]^vals[2]) and (cnts[0] == cnts[1] and cnts[1] == cnts[2]):
        print("Yes")
    elif len(vals) == 2 and (vals[0] == 0 or vals[1] == 0):
        if vals[0] == 0 and  2*cnts[0] == cnts[1]:
            print("Yes")
        elif vals[1] == 0 and cnts[0] == 2*cnts[1]:
            print("Yes")
        else:
            print("No")
    else:
        print("No")

Measured memory_bytes: 20644
s = list(input())

words = ['dream', 'dreamer', 'erase', 'eraser']
ans = 'YES'

pointer = len(s)
while pointer > 0:
    if s[pointer-5: pointer] == list(words[0]):
        pointer -= 5
    elif s[pointer-5: pointer] == list(words[2]):
        pointer -= 5
    elif s[pointer-7: pointer] == list(words[1]):
        pointer -= 7
    elif s[pointer-6: pointer] == list(words[3]):
        pointer -= 6
    else:
        ans = 'NO'
        break

print(ans)


Measured memory_bytes: 9904
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
	string s; cin >> s;
	int sz = s.size();
	vector<int> ans(sz);
	int rcnt = 0, lcnt = 0;
	for (int i = 0; i < sz; ++i) {
		if (s[i] == 'R') rcnt++;
		else {
			ans[i] += rcnt / 2;
			ans[i - 1] += (rcnt + 1) / 2;
			rcnt = 0;
		}
		if (s[sz - i - 1] == 'L') lcnt++;
		else {
			ans[sz - i - 1] += lcnt / 2;
			ans[sz - i] += (lcnt + 1) / 2;
			lcnt = 0;
		}
	}
	for (int i = 0; i < sz; ++i) cout << ans[i] << " ";
	cout << endl;

	return 0;
}

Measured memory_bytes: 1024
N = int(input())
D, X = map( int, input().split())
A = list()
chocoX = 0

for i in range(N):
  a = input()
  A.append(a)
    
for j in range(N):
  chocoX += (((D -1) // int(A[j])) + 1)
    
print(chocoX + X)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

// greatest common divisor and least common multiple
// gcd is calculated by Euclidean Algorithm
// lcm = m * n / gcd(m,n)
template <typename T = int>
T gcd(T a, T b) {
    if (a < b)
        return gcd(b, a);
    if (b == 0)
        return a;
    T r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

template <typename T = int>
T lcm(T m, T n) {
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n;
    cin >> n;
    vector<lint> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    lint ret = a[0];
    for (int i = 0; i < n; ++i) {
        ret = gcd(ret, a[i]);
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 1024
#include<cstdio>

int main(){
	long long answer = 0;
	int b = 0;
	while(true){
		char tmp;
		scanf("%c", &tmp);
		if(tmp != 'W' && tmp != 'B') break;
		if(tmp == 'W') answer += b;
		else b++;
	}
	printf("%lld\n", answer);
	return 0;
}

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

using namespace std;

struct Card
{
    char ch;
    int value;
};

void swap(Card &c1, Card &c2)
{
    Card temp = c1;
    c1 = c2;
    c2 = temp;
}

void SelectionSort(vector<Card> &cards)
{
    int minj;
    for (int i = 0; i < cards.size(); i++)
    {
        minj = i;
        for (int j = i; j < cards.size(); j++)
        {
            if (cards[j].value < cards[minj].value)
                minj = j;
        }
        if (minj != i)
            swap(cards[i], cards[minj]);
    }
}

void BubbleSort(vector<Card> &cards)
{
    bool flag;

    for (int i = 0; i < cards.size(); i++)
    {
        flag = true;
        for (int j = 1; j < cards.size() - i; j++)
        {
            if(cards[j - 1].value > cards[j].value){
                flag = false;
                swap(cards[j-1], cards[j]);
            }
        }
        if(flag) break;
    }
}

int main()
{
    int n;
    cin >> n;
    vector<Card> array1(n);
    for (int i = 0; i < n; i++)
    {
        cin >> array1[i].ch >> array1[i].value;
    }
    vector<Card> array2 = array1;

    BubbleSort(array1);
    SelectionSort(array2);

    bool stable = true;
    for(int i=0;i<n;i++){
        if(array1[i].ch != array2[i].ch) stable = false;
    }

    for(int i=0;i<n;i++){
        if(i) cout << " ";
        cout << array1[i].ch << array1[i].value;
    }
    cout << endl << "Stable" << endl;
    for(int i=0;i<n;i++){
        if(i) cout << " ";
        cout << array2[i].ch << array2[i].value;
    }
    cout << endl;
    if(stable) cout << "Stable";
    else cout << "Not stable";
    cout << endl;
}



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

const int MAX = 5e5 + 5;
int n, a[MAX], lft[MAX], rgt[MAX];

int main() {
	scanf("%d", &n);

	for(int i = 1; i <= n; i++)
		scanf("%d", &a[i]);

	stack <int> s;
	for(int i = 1; i <= n; i++) {
		while(!s.empty() && a[s.top()] > a[i])
			s.pop();

		lft[i] = s.empty() ? 0 : s.top();
		s.push(i);
	}

	while(!s.empty()) s.pop();

	for(int i = n; i > 0; i--) {
		while(!s.empty() && a[s.top()] > a[i])
			s.pop();

		rgt[i] = s.empty() ? n + 1 : s.top();
		s.push(i);
	}

	long long ans = 0;
	for(int i = 1; i <= n; i++)
		ans += 1LL * a[i] * (rgt[i] - i) * (i - lft[i]);

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

Measured memory_bytes: 4608
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
    ll c=0;
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]==s[i+1])
        {
            c++;
        }
    }
    if(c>=1)
        cout<<"Bad"<<endl;
    else
        cout<<"Good"<<endl;
    return 0;
}



Measured memory_bytes: 256
import fractions

N, M = map(int, input().split())
S = input()
T = input()
c = fractions.gcd(N, M)
d = N*M//c
ans = d
for i in range(c):
    if S[i*(N // c)] != T[i*(M // c)]:
        ans = -1
print(ans)


Measured memory_bytes: 65516
#include <cstdio>

const int MAXN = 3000;

int pow_mod(int b, int p, int m) {
	int ret = 1;
	while( p ) {
		if( p & 1 ) ret = 1LL*ret*b%m;
		b = 1LL*b*b%m;
		p >>= 1;
	}
	return ret;
}

int N, M;

int c[MAXN + 5][MAXN + 5], s[MAXN + 5][MAXN + 5], f[MAXN + 5][MAXN + 5];
void init() {
	for(int i=0;i<=MAXN;i++) {
		c[i][0] = 1;
		for(int j=1;j<=i;j++)
			c[i][j] = (c[i-1][j] + c[i-1][j-1]) % M;
	}
	s[0][0] = 1;
	for(int i=1;i<=MAXN;i++)
		for(int j=1;j<=i;j++)
			s[i][j] = (1LL*j*s[i-1][j]%M + s[i-1][j-1]) % M;
	for(int i=0;i<=MAXN;i++) {
		for(int j=1;j<=i;j++)
			f[i][j] = (1LL*(j + 1)*f[i-1][j]%M + f[i-1][j-1]) % M;
		f[i][0] = 1;
	}
}

int main() {
	scanf("%d%d", &N, &M); init();
	int ans = 0;
	
	for(int p=0;p<=N;p++) {
		int d = 1LL*pow_mod(M-1, p, M)*c[N][p]%M;
		d = 1LL*d*pow_mod(2, pow_mod(2, N-p, M-1), M)%M;
/*
		for(int j=0;j<=p;j++) {
			for(int k=0;k<=j;k++) {
				ans = (ans + 1LL*d*s[j][k]%M*c[p][j]%M*pow_mod(2, 1LL*k*(N-p)%(M-1), M)%M)%M;
			}
		}
*/
		int t = 1, q = pow_mod(2, N-p, M);
		for(int k=0;k<=p;k++,t=1LL*t*q%M)
			ans = (ans + 1LL*d*f[p][k]%M*t%M)%M;
	}
	
	printf("%d\n", ans);
}

Measured memory_bytes: 85948
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>

using namespace std;

template<typename T> 
void show(T a){
  for(auto i : a){ cout << i << " "; }
  cout << endl;
}


int main(int argc, char *argv[]){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  unordered_map<int, int> map;
  map[1] = 0;
  map[7] = 0;
  map[4] = 0;
  map[9] = 0;
  vector<int> a(4);
  for(int& i : a){
    cin >> i;
  }
  for(int& i : a){
    if(map.count(i) <= 0) {
      cout << "NO" << endl;
      return 0;
    }
    map[i] = map[i]+1;
  }
  
  for(int& i : a){
    if(map[i] != 1){
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
}


Measured memory_bytes: 256
N,A=map(int,input().split())

X=list(map(int,input().split()))
x=[]
for i in range(N):
    x.append(X[i]-A)

L=[0 for i in range(5001)]
L[2500]=1

for i in range(N):
    if x[i]>=0:
        for j in range(5001):
            if L[5000-j]>0:
                L[5000-j+x[i]]+=L[5000-j]
    elif x[i]<0:
        for j in range(5001):
            if L[j]>0:
                L[j+x[i]]+=L[j]
print(L[2500]-1)

Measured memory_bytes: 3064
import math

N = int(input())

if N % 2 != 0:
  print(0)
else:
  answer = 0
  i = 0
  j = 1
  while j > 0:
    a = math.floor(N // (10 * (5 ** i)))
    if a == 0:
      print(answer)
      break
    else:
      answer += a
      i += 1

Measured memory_bytes: 3060
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <math.h>
using namespace std;

#define int long long
#define endl "\n"
#define all(v)  v.begin(),v.end()
#define fir first
#define sec second
#define fro front
#define m_p make_pair
#define mod 1000000007
#define INF 2000000000
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];
using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}
int krag(double xx) {
	return INF - (int)(INF - xx);
}


int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res* a% mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}



signed main() {
	int t, x;
	cin >> t >> x;
	printf("%.10lf", (t+0.0) / x);
}



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

using namespace std;

int main(){
	while(true){
		int n;
		cin >> n;
		if(n == 0){ break; }
		vector< vector<int> > grid(n, vector<int>(n));
		vector< vector<int> > flags(n, vector<int>(n));
		for(int i = 0; i < n; ++i){
			for(int j = 0; j < n; ++j){ cin >> grid[i][j]; }
		}
		for(int i = 0; i < n; ++i){
			int rmin = INT_MAX, cmax = 0;
			for(int j = 0; j < n; ++j){
				if(rmin > grid[i][j]){ rmin = grid[i][j]; }
				if(cmax < grid[j][i]){ cmax = grid[j][i]; }
			}
			for(int j = 0; j < n; ++j){
				if(grid[i][j] == rmin){ flags[i][j] |= 0x02; }
				if(grid[j][i] == cmax){ flags[j][i] |= 0x01; }
			}
		}
		int answer = 0;
		for(int i = 0; i < n; ++i){
			for(int j = 0; j < n; ++j){
				if(flags[i][j] == 0x03){ answer = grid[i][j]; }
			}
		}
		cout << answer << endl;
	}
	return 0;
}

Measured memory_bytes: 0
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string { sc.Scan(); return sc.Text() }
func scanInt() int { a,_ := strconv.Atoi(scanString()); return a }
func scanInt64() int64 { a,_ := strconv.ParseInt(scanString(),10,64); return a }
func scanFloat64() float64 { a,_ := strconv.ParseFloat(scanString(),64); return a }

func scanInts(n int) []int {
	res := make([]int, n); for i := 0; i < n; i++ { res[i] = scanInt() }; return res
}

func abs(a int) int { if a<0 { return -a }; return a }
func min(a,b int) int { if a<b { return a }; return b }
func max(a,b int) int { if a>b { return a }; return b }

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1000002)

	s := scanString()
	s = string('0') + s
	n := len(s)
	dp := make([][2]int, n+1)
	for i := 0; i < n+1; i++ {
		dp[i][0] = 1 << 31-1
		dp[i][1] = 1 << 31-1
	}

	dp[0][0] = 0

	for i := 0; i < n; i++ {
		for j := 0; j < 2; j++ {
			num := int(s[n-1-i]-'0')
			num += j

			for k := 0; k < 10; k++ {
				x := k-num
				if x < 0 {
					x += 10
					dp[i+1][1] = min(dp[i+1][1], dp[i][j]+k+x)
				} else {
					dp[i+1][0] = min(dp[i+1][0], dp[i][j]+k+x)
				}
				// fmt.Println(k,k+x,dp[i+1])
			}
		}
	}

	fmt.Println(dp[n][0])

}


Measured memory_bytes: 21248
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
#include<functional>
#include<stack>
#include<tuple>
#include<cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using ll = long long;
using P = pair<int, int>;
using MATRIX = vector< vector<ll> >;

int N, M;
int par[200000] = {0};

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
  cin >> N >> M;
  UnionFind tree(N);
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    a--;b--;
    tree.unite(a, b);
  }

  rep(i, N) {
    par[tree.root(i)]++;
  }

  int ans = 0;

  rep(i, N) {
    ans = max(ans, par[i]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 10188
import java.util.*;

public class Main{ //クラス名はMain
    public static void main(String[] args) {
			
			Scanner sc = new Scanner(System.in);
			
			// 文字列の入力
			String s = sc.next();
			
			/*--------------------------------*/
			//入力
			//String s = "bus";

			int p = s.length();

			String ans = s.substring(p-1,p);

			if("s".equals(ans)){
				s +="es";
			}else{
				s += "s";
			}
			System.out.println(s);
    }
}



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

int main() {
    while (true) {
        int n, w;
        cin >> n >> w;
        if ((n | w) == 0) {
            break;
        }
        vector<int> values(n);
        int maxValue = 0;
        for (int i = 0; i < n; i++) {
            cin >> values[i];
            if (maxValue < values[i]) {
                maxValue = values[i];
            }
        }
        int interval = maxValue / w + 1;
        vector<int> histogram(interval);
        for (int i = 0; i < n; i++) {
            histogram[values[i] / w]++;
        }
        int maxHeight = 0;
        double result = 0;
        for (int i = 0; i < interval; i++) {
            result += histogram[i] * (interval  - 1 - i);
            if (maxHeight < histogram[i]) {
                maxHeight = histogram[i];
            }
        }
        result /= (double) maxHeight * (interval - 1);
        result += 0.01;
        cout << result << endl;
    }
}

Measured memory_bytes: 0
#include <iostream>
#include <math.h>
#include <cstdio>

using namespace std;

int a1, a2, a3, dmp;
int ans = 0;

int main(){
	cin >> a1 >> a2 >> a3;
	
	
	if (a2 < a3) {
		dmp = a2;
		a2 = a3;
		a3 = dmp;
		dmp = 0;
	}
	if (a1 < a2) {
		dmp = a1;
		a1 = a2;
		a2 = dmp;
		dmp = 0;
	}
	if (a2 < a3) {
		dmp = a2;
		a2 = a3;
		a3 = dmp;
		dmp = 0;
	}
	
	ans = a2 - a3 + a1 - a2;
	cout << ans;
	
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner stdIn = new Scanner(System.in)) {
			Main m = new Main();
			while (true) {
				int h = stdIn.nextInt();
				int w = stdIn.nextInt();
				if (h > 300 || w > 300) {
					throw new RuntimeException(
							"Error:???????????????0??????300??§??????");
				}
				if (h == 0 && w == 0) {
					break;
				}
				m.setChar('#');
				m.DrawSquare(h, w);
				System.out.println("");
			}
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
	}

	private Character displayChar;
	/**
	 * ???????????????????????§????§???¢?????????
	 * @param height	????§???¢?????????(int)
	 * @param width		????§???¢??????(int)
	 */
	protected void DrawSquare(int height, int width) {
		if (height < 0 || width < 0) {
			throw new RuntimeException("Error:????????????????????\?????????????????????");
		}
		for (int i = 1; i <= height; i++) {
			for (int j = 1; j <= width; j++) {
				System.out.print(this.displayChar);
			}
			System.out.println("");
		}
	}

	/**
	 * ????§???¢???????????????????¨????
	 * @param displayChar???????????????(char)
	 */
	protected void setChar(Character displayChar) {
		this.displayChar = displayChar;
	}
}

Measured memory_bytes: 36048
#include <iostream>

using namespace std;

int main() {
  int H, W, s[100][100], r[100][100];
  char c;
  cin >> H >> W;
  for (int i = 0; i != H; i++)
    for (int j = 0; j != W; j++) {
      cin >> c;
      s[i][j] = (c == '#');
      if (!i && !j) r[i][j] = s[i][j];
      else {
        int p = j ? r[i][j - 1] + (s[i][j] > s[i][j - 1]) : 200;
        int q = i ? r[i - 1][j] + (s[i][j] > s[i - 1][j]) : 200;
        r[i][j] = min(p, q);
      }
    }

  cout << r[H - 1][W - 1] << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, m;
  cin >> n >> m;
  vector<vector<char>> a(n+1, vector<char>(n+1,'z'));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) cin >> a[i][j];
  }
  vector<vector<char>> b(m+1, vector<char>(m+1,'z'));
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= m; j++) cin >> b[i][j];
  }
  
  for (int i = 0; i <= n-m; i++) {
    for (int j = 0; j <= n-m; j++) {
      for (int h = 1; h <= m; h++) {
        int judge = 0;
        for (int w = 1; w <= m; w++) {
          if (a[i+h][j+w] != b[h][w]) {
            judge = 1;
            break;
          }
          if (h == m && w == m) {
            cout << "Yes" << endl;
            return 0;
          }
        }
        if (judge == 1) break;
      }
    }
  }
  
  cout << "No" << endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
MOD = 10**9 + 7
MAX_N = 10**6 + 5
fact = [0]*(MAX_N)
fact_inv = [0]*(MAX_N)
fact[0] = 1
for i in range(MAX_N-1):
    fact[i+1] = fact[i]*(i+1) % MOD
fact_inv[-1] = pow(fact[-1], MOD-2, MOD)
for i in range(MAX_N-2, -1, -1):
    fact_inv[i] = fact_inv[i+1]*(i+1) % MOD


def comb(n, k):
    return fact[n]*fact_inv[k] % MOD * fact_inv[n-k] % MOD


if K >= N:
    print(comb(2*N-1, N-1))
    exit()

ans = 1
for i in range(1, K+1):
    ans += comb(N, i)*comb(N-1, i) % MOD
    ans %= MOD
print(ans)


Measured memory_bytes: 88012
#include <bits/stdc++.h>
#define ll long long
#define pq priority_queue
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};
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; }

int main(){
    ll N,res=0;
    cin>>N;
    vector<vector<ll>> v(N,vector<ll> (3));
    vector<vector<ll>> dp(N+1,vector<ll> (3,0));
    for(ll i=0;i<N;i++){
        for(ll j=0;j<3;j++){
            cin>>v[i][j];
        }
    }
    for(ll i=0;i<N;i++){
        for(ll j=0;j<3;j++){
            for(ll k=0;k<3;k++){
                if(j!=k) chmax(dp[i+1][k],dp[i][j]+v[i][k]);
            }
        }
    }
    for(ll i=0;i<3;i++) chmax(res,dp[N][i]);
    cout<<res<<endl;
}


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

int main() {
    int n, m;
    double sum = 0;
    cin >> n >> m;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        sum += a[i];
    }
    sort(a.rbegin(), a.rend());

    for (int i = 0; i < m; i++)
    {
        if (a[i] < sum / (4.0 * m)) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll ZERO = 0;
const int Inf = 1e9;
const ll INF= 1e18;
const ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

int main() {
    int N;
    cin >> N;
    map<int,int> A;
    map<int,int> B;
    for(int i = 0;i < N;i++) {
        if(i % 2 == 0) {
            int C;
            cin >> C;
            A[C]++;
        }
        else {
            int C;
            cin >> C;
            B[C]++;
        }
    }
    vector<pair<int,int>> a;
    vector<pair<int,int>> b;
    a.push_back(make_pair(N / 2,Inf));
    b.push_back(make_pair(N / 2,Inf));
    for(auto x:A) {
        a.push_back(make_pair(N / 2 - x.second,x.first));
    }
    for(auto x:B) {
        b.push_back(make_pair(N / 2 - x.second,x.first));
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    if(a.at(0).second != b.at(0).second) {
        cout << a.at(0).first + b.at(0).first << endl;
    }
    else {
        cout << min(a.at(1).first + b.at(0).first,a.at(0).first + b.at(1).first) << endl;
    }
}

Measured memory_bytes: 6136