akhauriyash/Code-Regression huggingface dataset:
// Problem : B - Golden Coins
// Contest : AtCoder Beginner Contest 160
// URL : https://atcoder.jp/contests/abc160/tasks/abc160_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//Zory-2020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
// typedef __int128 ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define FR first
#define SE second
#define MP make_pair
#define PB push_back
#define vc vector
#define db double
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bin(x) (1ll<<(x))
#define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
#define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
#define mem(x,val) memset(x,val,sizeof x)
#define Swap(a,b,n) for(int I=0;I<=n;I++) swap(a[I],b[I])
#define PC __builtin_popcountll
#ifdef DEBUG
	#define debug(A,args...) fprintf(stderr,A,##args)
#else
	#define debug(A,args...) printf("")
#endif
#define deb debug("line %d\n",__LINE__)
namespace mine
{
	ll qread()
	{
		ll ans=0,f=1;char c=getchar();
		while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
		while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}
	void write(ll num){if(num<0) putchar('-'),num=-num;if(num>=10) write(num/10);putchar('0'+num%10);}
	void write1(ll num){write(num);putchar(' ');}
	void write2(ll num){write(num);putchar('\n');}
	template<typename T>inline bool chmax(T&a,const T&b){return a<b?a=b,1:0;}
	template<typename T>inline bool chmin(T&a,const T&b){return a>b?a=b,1:0;}
	ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
	bool IN(ll x,ll l,ll r){return l<=x and x<=r;}
	void GG(){puts("-1");exit(0);}

	const db eps=1e-8;
	const int INF=0x3f3f3f3f;
	const int MOD=1e9+7;
	int mm(const int x){return x>=MOD?x-MOD:x;}
	template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
	ll qpower(ll x,ll e,int mod=MOD){ll ans=1;while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
	ll invm(ll x){return qpower(x,MOD-2);}
	const int MM=5e6+10;
	ll fac[MM],facinv[MM],Inv[MM];ll Comb(int n,int m){return n<0 or n<m?0:fac[n]*facinv[m]%MOD*facinv[n-m]%MOD;}
	void PRE()
	{
		fac[0]=1;fo(i,1,MM-1) fac[i]=fac[i-1]*i%MOD;
		facinv[MM-1]=invm(fac[MM-1]);fd(i,MM-1,1) facinv[i-1]=facinv[i]*i%MOD;
		Inv[1]=1;fo(i,2,MM-1) Inv[i]=(MOD-MOD/i)*Inv[MOD%i]%MOD;
	}

	const int N=1e6+10;
	//------------------FIXED------------------
	
	void main()
	{
		int X=qread();write( X/500*1000+X%500/5*5 );
	}
};//变量重名！
signed main()
{
	#ifdef DEBUG
	//freopen("a.in","r",stdin);
	// freopen("z.txt","r",stdin);
	//freopen("a.out","w",stdout);
	#endif
	srand(time(0));
	mine::main();
	//debug("\n------------------------------------------\nTime: %.2lf s\n",1.0*clock()/CLOCKS_PER_SEC);
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
using namespace std;
#define ll long long
ll par[100001];
ll dist[100001];
ll root(ll x){
    ll y=par[x];
    if(y!=x){
       par[x]=root(y);
       dist[x]+=dist[y];
    }
    return par[x];
}
bool unite(ll L,ll R,ll D){
    ll x=root(L);
    ll y=root(R);
    if(x==y){
        if(dist[L]-dist[R]==D)return true;else return false;
    }else{
        par[x]=y;
        dist[x]=dist[R]+D-dist[L];
        return true;
    }
}
int main(){
    ll N,M;
    cin >> N >> M;
    ll i;
    for(i=0;i<N;i++){
        par[i]=i;
        dist[i]=0;
    }
    ll L,R,D;
    for(i=0;i<M;i++){
        cin >> L >> R >> D;
        if(!unite(L-1,R-1,D)){
            cout << "No"<<endl;
            return 0;
        }
    }
    cout << "Yes" <<endl;
    return 0;
}


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

int main() {
    while (true) {
        int n, m;
        cin >> n >> m;
        if ((n | m) == 0) {
            break;
        }
        int* passTimes = new int [n + m + 1];
        for (int i = 1; i <= n; i++) {
            cin >> passTimes[i];
        }
        for (int i = n + 1; i <= n + m; i++) {
            cin >> passTimes[i];
        }
        passTimes[0] = 0;
        for (int i = 1; i < n + m; i++) {
            for (int j = 1; j < n + m - i; j++) {
                if (passTimes[j] > passTimes[j + 1]) {
                    int temp = passTimes[j];
                    passTimes[j] = passTimes[j + 1];
                    passTimes[j + 1] = temp;
                }
            }
        }
        int maxGap = 0;
        for (int i = 0; i < n + m; i++) {
            int gap = passTimes[i + 1] - passTimes[i];
            if (maxGap < gap) {
                maxGap = gap;
            }
        }
        cout << maxGap << endl;
        delete[] passTimes;
    }
}

Measured memory_bytes: 980
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

typedef unsigned long long ULLONG;
typedef long long LLONG;

template <class _T> static _T tp_abs(const _T& a) {
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void get1int(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void get2int(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void get3int(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}
static void getstring(char* buff) {
	if (scanf(" %s", buff) < 0) {
		printf("getstr error!\n");
	}
}

static const long long MOD_NUM = 1000000007LL;

static void A_task();

int main()
{
	A_task();
	fflush(stdout);
	return 0;
}

static void A_task()
{
	const char* day[] = { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };

	char sz[10] = { 0 };
	getstring(sz);

	int ans = 0;
	for (int i = 0; i < 7; i++) {
		if (strcmp(sz, day[i]) == 0) {
			ans = 7 - i;
			break;
		}
	}
	printf("%d\n", ans);
}


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

using namespace std;

int main()
{
    int i,sum=0;
    string s;
    cin>>s;
    for(i=0;i<s.length()/2;i++)
        if(s[i]!=s[s.length()-i-1])
            sum++;
    cout<<sum<<endl;
    return 0;
}


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


#define NIL -1
#define WHITE 0
#define BLACK 1
#define MAXVRT 100   /* 頂点の最大個数 */


int d[MAXVRT];
int pi[MAXVRT];
int color[MAXVRT];
int G[MAXVRT][MAXVRT];


int prim(int, int);

int main()
{
  int i, j, n, sumOfW;

  scanf("%d", &n);
  for( i = 0; i<n; i++ )
    {
      for( j = 0; j<n; j++ )
        scanf("%d", &G[i][j] );
    }
  
  /*　最小全域木の各辺の重みを求める　*/
  sumOfW = prim(0, n);
  printf("%d\n", sumOfW);
  
  return 0;
}


/* プリムのアルゴリズムを用いて、重み付きグラフGの最小全域木の各辺の重みを計算する関数
   引数　r　始点　n 頂点数 　戻り値　各辺の重みの和 */
int prim(int r, int n)
{
  int i, j, u, res = 0, mincost;

  /* ノードiの色、コスト等を記録する配列を初期化　*/
  for( i = 0; i<n; i++ )
    {
      color[i] = WHITE;
      pi[i]    = NIL;
      d[i]     = INT_MAX;
    }
  d[r] = 0;

  while( 1 )
    {
      mincost = INT_MAX;
      for( i = 0; i<n; i++ )
	{
	  if( color[i] != BLACK && d[i] < mincost )
	    {
	      mincost = d[i];
	      u = i;
	    }
	}

      /*　最小全域木を構築し終わったらループを抜ける　*/
      if( mincost == INT_MAX )
	break;

      color[u] = BLACK;      /* ノードuをその時点での最小全域木に含める　*/

      /*　ノードuに隣接し、その時点での最小全域木に含まれないノードの内、コストが最小のものを求める　*/
      for( i = 0; i<n; i++ )
	{
	  if( color[i] != BLACK && G[i][u] != NIL )
	    {
	      if( d[i] > G[i][u] )
		{
		  pi[i] = u;
		  d[i]  = G[i][u];
		}
	    }
	}
    }

  for( i = 0; i<n; i++ )
    res += d[i];

  return res;
}



Measured memory_bytes: 2052
#include<bits/stdc++.h>
using namespace std;
int a,b,c,ans,tmp;
int main()
{
	cin>>a>>b>>c;
	while(a--)
	{
		cin>>tmp;
		if(tmp<b||tmp>=c)
			ans++;
	}
	cout<<ans<<endl;
    return 0;
}

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

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> M;
typedef vector<int> V;
typedef queue<int> Q;
typedef pair<long,long> PLL;
typedef map<long,long> MLL;
typedef vector<long long> VLL;
typedef vector<pair<int,int>> VP;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
/*--------------------------------------------*/
int main(){
    int n;cin>>n;
    int half=n/2;
    int cnt=0;
    int cnt2=0;
    rep(i,n){
        int tmp;
        cin>>tmp;
        if(tmp%4==0)cnt++;
        else if(tmp%2==0)cnt2++;
    }
    bool flag=false;
    if(cnt>=half||cnt*2+cnt2>=n)flag=true;
    cout<<(flag?"Yes":"No")<<endl;
}


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

using namespace std;

int main(){
    int k, n;
    cin>>k>>n;
    vector <int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a.begin(), a.end());
    int maxx=0;
    for(int i=0;i<n-1;i++){
        maxx=max(a[i+1]-a[i], maxx);
    }
    maxx=max(maxx, a[0]+(k-a[n-1]));
    cout<<k-maxx<<endl;
    return 0;
}

Measured memory_bytes: 1024
n = int(input())
P = list(map(int,input().split()))
cnt = 0
for i in range(1,n-1):
    if (P[i]>P[i-1] and P[i]<P[i+1]) or (P[i]>P[i+1] and P[i]<P[i-1]):
        cnt += 1
print(cnt)

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



int main()
{
    //cout << "Hello World!" << endl;
    int n;
    cin>>n;
    
    int j=1;
    
    int k=0;
    
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        
        if(x==j)
        {
        
        j+=1;
        k+=1;
        }
    
    }
    if(k==0)
    cout<<"-1";
    else
    cout<<n-k;
    
    return 0;
}


Measured memory_bytes: 256
#include <numeric>
#include<iostream>
#include<set>
#include <bitset>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
using namespace std;
#define int long long
#define ll long long
#define mod  1000000007
#define inf 1e17
#define rep(i,j,n) for(int i=j;i<n;i++)
double pi = 3.141592653589793;
//使うやつはここから下に置こうな
//就職させてください!!!!
struct edge{long long to,cost;};
typedef pair<int,int>P;
vector<edge> G[100005];
vector<edge> Gs[100005];
long long d[100005];
int ds[114514];
int n,m,s,t;

void dijkstra_yen(long long k){
    priority_queue<P,vector<P>,greater<P> >que;
    fill(d,d+n,inf);
    d[k]=0;
    que.push(P(0,k));
    while(!que.empty()){
        P p=que.top();que.pop();
        int v=p.second;
        if(d[v]<p.first)continue;
        for(int i=0;i<G[v].size(); i++){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
}

void dijkstra_sunu(long long k){
    priority_queue<P,vector<P>,greater<P> >que;
    fill(ds,ds+n,inf);
    ds[k]=0;
    que.push(P(0,k));
    while(!que.empty()){
        P p=que.top();que.pop();
        int v=p.second;
        if(ds[v]<p.first)continue;
        for(int i=0;i<Gs[v].size(); i++){
            edge e=Gs[v][i];
            if(ds[e.to]>ds[v]+e.cost){
                ds[e.to]=ds[v]+e.cost;
                que.push(P(ds[e.to],e.to));
            }
        }
    }
}

signed main(){
cin>>n>>m>>s>>t;
    long long  a,b,c,f;
    for(int i=0; i<m; i++){
        cin>>a>>b>>c>>f;
        a--;b--;
        G[a].push_back(edge{b,c});
        G[b].push_back(edge{a,c});
        Gs[a].push_back(edge{b,f});
        Gs[b].push_back(edge{a,f});
    }
    int cost[114514];
    dijkstra_yen(s-1);
    dijkstra_sunu(t-1);
    cost[n]=inf;
    int total=1000000000000000;
    for(int i=n-1;i>=0;i--){
        cost[i]=min(d[i]+ds[i],cost[i+1]);
    }
    rep(i,0,n)cout<<total-cost[i]<<endl;
    return 0;
}

Measured memory_bytes: 19140
#include<bits/stdc++.h>
    using namespace std;
    #define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    #include <ext/pb_ds/assoc_container.hpp> 
    #include <ext/pb_ds/tree_policy.hpp> 
    using namespace __gnu_pbds; 
    #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
     
    #define ff first
    #define ss second
    #define mp make_pair
     
    #define pb push_back
    #define endl "\n"
     
    #define int long long int
    #define double long double
     
    #define bp __builtin_popcountll
    #define inf 1e18
    const int N=1e6+6;
    const int MOD=1e9+7;
     int nextPowerOf2( int n)  
	{  
	    int count = 0;  
	    if (n && !(n & (n - 1)))  
	        return n;  
	      
	    while( n != 0)  
	    {  
	        n >>= 1;  
	        count += 1;  
	    }  
	      
	    return 1 << count;  
	}
    void solve()
    {
    	int n,k;
    	cin>>n>>k;
    	double ans=0;
    	for(int i=1;i<=n;i++)
    	{
    		int pp=nextPowerOf2((k+i-1)/i);
    		ans+=1.0/pp;
    	}
    	ans=ans/(double)n;
    	cout<<fixed<<setprecision(10)<<ans<<endl;
    }
	signed main()  
    {
        FAST
        int t=1;
        // cin>>t;
        while(t--)
        {
        	solve();
        }
    }

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

int main(){
  string s; cin >> s;
  sort(s.begin(), s.end());
  if(s[0] == s[1] && s[1] != s[2] && s[2] == s[3]){
    cout << "Yes";
  }
  else cout << "No";
  
  return 0;
}

Measured memory_bytes: 256
package main

import (
    "bufio"
    "os"
    "strconv"
    "fmt"
    "container/heap"

)

/*********** PriorityQueue ***********/
type PriorityQueue struct {
    arr []interface{}
    comps []CompFunc
}

/*
p < q ... -1
p == q ... 0
p > q ... 1
*/
type CompFunc func(p, q interface{}) int

func NewPriorityQueue() *PriorityQueue {
    return new(PriorityQueue)
}

func (pq PriorityQueue) Len() int {
    return len(pq.arr)
}

func (pq PriorityQueue) Swap(i, j int) {
    pq.arr[i], pq.arr[j] = pq.arr[j], pq.arr[i]
}

func (pq PriorityQueue) Less(i, j int) bool{
    for _, comp := range pq.comps {
        result := comp(pq.arr[i], pq.arr[j])
        switch result {
            case -1: return true
            case 1:  return false
            case 0:  continue
        }
    }
    return true
}

func (pq *PriorityQueue) Push(x interface{}) {
    pq.arr = append(pq.arr, x)
}

func (pq *PriorityQueue) Pop() interface{} {
    n := pq.Len()
    item := pq.arr[n - 1]
    pq.arr = pq.arr[:n - 1]
    return item
}

func (pq *PriorityQueue) IsEmpty() bool {
    return pq.Len() == 0
}

/* input */
var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
    sc.Scan()
    n, _ := strconv.Atoi(sc.Text())
    return n
}

func main() {
    sc.Split(bufio.ScanWords)
    comp := func(p, q interface{}) int {
        if p.(int) < q.(int) {
            return -1
        } else if p.(int) == q.(int) {
            return 0
        } else {
            return 1
        }
    }
    n := readInt()
    preQue := new(PriorityQueue)
    preQue.comps = append(preQue.comps, comp)
    sufQue := new(PriorityQueue)
    sufQue.comps = append(sufQue.comps, comp)
    var mid []int
    var preScore, sufScore int
    var preScores []int
    var sufScores []int
    for i := 0; i < n; i++ {
        v := readInt()
        preScore += v
        heap.Push(preQue, v)
    }
    for i := 0; i < n; i++ {
        mid = append(mid, readInt())
    }
    for i := 0; i < n; i++ {
        v := -readInt()
        sufScore += v
        heap.Push(sufQue, v)
    }
    
    preScores = append(preScores, preScore)
    for _, m := range mid {
        v := heap.Pop(preQue).(int)
        if v < m {
            preScore += (m - v)
            heap.Push(preQue, m)
        } else {
            heap.Push(preQue, v)
        }
        preScores = append(preScores, preScore)
    }

    sufScores = append(sufScores, sufScore)
    for i := n - 1; i >= 0; i-- {
        m := mid[i]
        v := heap.Pop(sufQue).(int)
        if -v > m {
            sufScore += -v - m
            heap.Push(sufQue, -m)
        } else {
            heap.Push(sufQue, v)
        }
        sufScores = append(sufScores, sufScore)
    }
    ans := -10000000000000000
    for i := 0; i <= n; i++ {
        score := preScores[i] + sufScores[n - i]
        if ans < score {
            ans = score
        }
    }
    fmt.Println(ans)
}

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

int main()
{
	int n;
	cin >> n;
	auto t = vector<vector<int>>(n + 1);
	for(int i = 2; i <= n; ++i){
		int a;
		cin >> a;
		t[a].push_back(i);
	}
	for(int i = 1; i <= n; ++i){
		cout << t[i].size() << endl;
	}
	return 0;
}

Measured memory_bytes: 13984
#include<stdio.h>
int main()
{
	long long int sum=0;
	int n,a;
	int max=-1000000,min=1000000;
	scanf("%d",&n);
    for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a);
		if(a>max)  max=a;
		if(a<min)  min=a;
		sum+=a;
	}	
	printf("%d %d %lld\n",min,max,sum);
	return 0;
}

Measured memory_bytes: 1028
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <math.h>
#include <sstream>

using namespace std;

// implemented after reading the editorial

int main()
{
  string S, T;
  cin >> S >> T;
  int n = S.size();
  bool success = false;
  for (int i = 0; i < n; ++i) {
    if (S == T) {
      success = true;
      break;
    }
    S = S.back() + S.substr(0, n - 1);
  }
  if (success) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>

int main(){
	int N,i,x,sum=0,spr=0,ans;
	scanf("%d",&N);
	for(i = 0;i<N;i++){
		scanf("%d",&x);
		sum += x;
		spr += x*x;
	}
	x = int(1.0*sum/N);
	ans = spr+x*(x*N-sum-sum);
	++x;
	spr = spr+x*(x*N-sum-sum);
	if(ans >spr) ans=spr;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#define INFI 1e9

using namespace std;

int main() {
	int v, e;
	cin >> v >> e;
	int t1, t2, t3;
	int** dist = new int* [v];
	for (int i = 0;i < v;i++) {
		dist[i] = new int[v];
		for (int j = 0;j < v;j++) {
			dist[i][j] = -1;
		}
	}
	for (int i = 0;i < e;i++) {
		cin >> t1 >> t2 >> t3;
		dist[t1][t2] = t3;
	}



	vector<pair<int,int> >* dp = new vector<pair<int,int> >[1 << (v-1)];
	dp[0];
	for (int i = 0;i < 1<<(v-1);i++) {
		for (int j = 1;j <= v - 1;j++) {
			if (i & 1 << (j - 1)) {
				int index = i - (1 << (j - 1));
				if (index == 0) {
					if (dist[0][j] >= 0) {
						dp[i].push_back(make_pair(j, dist[0][j]));
					}
				}
				else {
					int m = INFI;
					for (int k = 0;k < dp[index].size();k++) {
						if (dist[dp[index][k].first][j] >= 0) {
							m = min(dp[index][k].second + dist[dp[index][k].first][j],m);
						}
					}
					if (m != INFI) {
						dp[i].push_back(make_pair(j, m));
					}
				}	
			}
		}
	}
	
	int m = -1;
	for (int i = 0;i < dp[(1 << (v - 1)) - 1].size() ;i++) {
		if (dist[dp[(1 << (v - 1)) - 1][i].first][0] >= 0) {
			if (m == -1) {
				m = dp[(1 << (v - 1)) - 1][i].second + dist[dp[(1 << (v - 1)) - 1][i].first][0];
			}
			else {
				m = min(m, dp[(1 << (v - 1)) - 1][i].second + dist[dp[(1 << (v - 1)) - 1][i].first][0]);
			}
			
		}
		
	}
	cout << m << endl;
}


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

int main() {
  int a; 
  cin >> a;
  vector<int> vec(a);
  for (int i = 0; i < a; i++) {
  cin >> vec.at(i);
	}
  sort(vec.begin(), vec.end() );
 	
  if(vec.at(a/2) != vec.at(a/2 -1))
    cout << vec.at(a/2) - vec.at(a/2-1) << endl;
  else
    cout << 0 << endl;
  
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
 
int main() {
 
  int64_t x,k,d;
  cin>>x>>k>>d;

  // |x|-k*d = 0
  // |x| = k*d
  // |x|/d = k
  // 0を超えてしまったら戻ってを繰り返せばよい。


  if(abs(x)/d >= k)
    cout<<abs(x)-k*d<<endl;
  else if((k-abs(x)/d)%2==0)
    cout<<abs(abs(x)-(abs(x)/d)*d)<<endl;
  else
    cout<<abs(abs(x)-(abs(x)/d+1)*d)<<endl;

	return 0;
}



Measured memory_bytes: 3632
import java.util.*;
import java.util.Map.Entry;
import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.rmi.server.UnicastRemoteObject;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static long mod=1000000007;
//    static int dx[]={-1,0,1,0};
//    static int dy[]={0,-1,0,1};

    public static void main(String[] args)   throws Exception, IOException{        
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        
        int n=sc.nextInt();
        int d[]=sc.nextIntArray(n);
        String ans="Yes";
        for (int i = n-1; 1 <= i; i--) {
			if(d[i-1]>d[i]) {d[i-1]--;}
			if(d[i-1]>d[i]) {ans="No";break;}
		}
      
        out.println(ans);
        out.flush();
    }



    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
}

class P {
	int x, y;
	P(int  x, int y) {
	  this.x=x;
	  this.y=y;
	}
}


//class P {
//    int id, d;
//    P(int  id, int d) {
//        this.id=id;
//        this.d=d;
//    }
//}

//class P implements Comparable<P>{
//    int a,b;
//    P(int a, int b) {
//    	this.b=b;
//    	this.a=a;
//    }
//
//    public int compareTo(P p){
//        return b-p.b;
//    }
//}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) throws IOException{
        int r[] = new int[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextInt(); 
        }
        return r;
    }
    public long[] nextLongArray(int size) throws IOException{
        long r[] = new long[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextLong(); 
        }
        return r;
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 40508
bingo = []
for _ in range(3):
	bingo.append(list(map(int,input().split())))
n = int(input())
b = []
for _ in range(n):
	b.append(int(input()))

def judge(bingo):
	#たて
	for i in range(3):
		if bingo[i][0] == True and bingo[i][1] == True and bingo[i][2] == True:
			return True
	##横
	for i in range(3):
		if bingo[0][i] == True and bingo[1][i] == True and bingo[2][i] == True:
			return True
	#斜め
	if bingo[1][1] == True:
		if bingo[0][0] ==True:
			if bingo[2][2] ==True:
				return True

		elif bingo[0][2] ==True:
			if bingo[2][0] == True:
				return True

for i in range(len(b)):
	for j in range(3):
		for k in range(3):
			if bingo[j][k] == b[i]:
				bingo[j][k] = True
if judge(bingo):
	print('Yes')
else:
	print('No')


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 1e6;

typedef long long ll;

ll a[N],b[N];

int main()
{
    int n;
    cin >> n;
    ll sum = 0;
    for (int i = 1; i <= n ; i ++ )
        {
            cin >> a[i];
            sum += a[i];
            b[i] = b[i-1] + a[i];
        }

    ll minn = 1e10;

    for (int i = 1; i < n ; i ++ )
    {
        if(minn >= abs(2*b[i]-sum)) minn = abs(2*b[i]-sum);
    }
    cout << minn << endl;

    return 0;
}


Measured memory_bytes: 5888
// O O O O O O O O O O O O O O O OO O OO O OO O O O TTCH O TTTCH O TTTCH O O O O
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx")
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <cstdio>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
// #include <random>
#include <iomanip>
#include <bitset>
#include <cassert>
 
using namespace std;

#define int long long
#define y1 y11
#define double long double
#define less less228
#define left left228
#define right right228
#define list list228
#define all(v) v.begin(), v.end()
 
 
 
template<typename T> void uin(T &a, T b) {
    if (b < a) a = b;
}
template<typename T> void uax(T &a, T b) {
    if (b > a) a = b;
}
 
const int N = 100 * 1000 + 228;
const int MOD = 998244353;

int mod(int x) {
    x %= MOD;
    if (x < 0) x += MOD;
    return x;
}
int fp(int a, int b) {
    int res = 1;
    for (; b; b >>= 1, a = mod(a * a)) {
        if (b & 1) res = mod(res * a);
    }
    return res;
}

bool used[N];

int mex(vector<int> v) {
    for (int i : v) {
        used[i] = 1;
    }
    int mx = 0;
    while (used[mx])++mx;
    for (int i : v) {
        used[i] = 0;
    }
    return mx;
}

int n;
int m1, m2, m3;
vector<int> g[3][N];
int gr[3][N];
int val[3][N];

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    cin >> m1;
    for (int i = 0; i < m1; ++i) {
        int u, v;
        cin >> u >> v;
        g[0][min(u, v)].emplace_back(max(u, v));
    }
    cin >> m2;
    for (int i = 0; i < m2; ++i) {
        int u, v;
        cin >> u >> v;
        g[1][min(u, v)].emplace_back(max(u, v));
    }
    cin >> m3;
    for (int i = 0; i < m3; ++i) {
        int u, v;
        cin >> u >> v;
        g[2][min(u, v)].emplace_back(max(u, v));
    }
    for (int t = 0; t < 3; ++t) {
        for (int v = n; v; --v) {

            vector<int> go;
            for (int to : g[t][v]) {
                go.emplace_back(gr[t][to]);
            }
            gr[t][v] = mex(go);
            val[t][gr[t][v]] = mod(val[t][gr[t][v]] + fp(10, 18 * v));
        }
    }
    int ans = 0;
    for (int a = 0; a < 500; ++a) {
        if (val[0][a] == 0) continue;
        for (int b = 0; b < 500; ++b) {
            if (val[1][b] == 0) continue;
            int c = a ^ b;
            ans = mod(ans + mod(val[0][a] * val[1][b]) * val[2][c]);
        }
    }
    cout << ans << '\n';
    return 0;
}
// RU_023
 
/*
5
1 3 4 2 3 
3
1 5 3
4 3 2
2 4 2
-------
2


7
5 6 2 3 6 7 6
5
7 7 5
3 3 7
3 7 10
1 7 6
4 7 8
-------
16

*/

Measured memory_bytes: 15872
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

const int mod = 1e9 + 7;
ll modpow(ll A, ll B) {
	ll kotae = 1;
	while (B > 0) {
		if (B & 1) kotae = kotae * A % mod;
		A = A * A % mod;
		B >>= 1;
	}
	return kotae;
}

int P[200001];
ll kotae = 0;
int N;
int to[400001], ne[400001], he[200001];
int dfs(int v, int prev) {
	int kazu = 1;
	for (int u = he[v]; u; u = ne[u]) {
		if (to[u] != prev) {
			int k = dfs(to[u], v);
			kazu += k;
			kotae += P[k] - 1;
		}
	}
	kotae += P[N - kazu];
	return kazu;
}

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


	N = getint();
	int k = 1;
	rep(i, N - 1) {
		int a = getint(), b = getint();
		to[k] = b;
		ne[k] = he[a];
		he[a] = k++;
		to[k] = a;
		ne[k] = he[b];
		he[b] = k++;
	}
	P[0] = 1;
	rep1(i, N) {
		P[i] = P[i - 1] * 2;
		if (P[i] >= mod) P[i] -= mod;
	}

	dfs(1, 0);
	kotae %= mod;
	ll igai = ll(P[N - 1]) * N % mod;
	kotae = (igai - kotae + mod) % mod;
	kotae = kotae * modpow(P[N], mod - 2) % mod;

	printf("%lld", kotae);

	Would you please return 0;
}

Measured memory_bytes: 7936
#include <bits/stdc++.h>
#define read(arr,n)	for(int i=0;i<n;i++) cin>>arr[i];
#define print(arr,n) for(int i=0;i<n;i++) cout << arr[i]<<' ';cout << endl;

using namespace std;

typedef long long ll;

void solve() {
	ll n;
	cin >> n;
	string s;
	cin >> s;
	
	int i = 0, ans = 0;
	while (i+2 <  n) {
		if (s[i] == 'A' && s[i+1]=='B' && 	
			s[i+2] == 'C') {
			ans++;
		}
		i++;
	}

	cout << ans << endl;
}

int main() {
	int t = 1;
	//cin >> t;
	while (t--) {
		solve();	
	}
	return 0;
}


Measured memory_bytes: 256
import Control.Monad
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)

main :: IO ()
main = do
    _ <- B.getLine
    ts <- map (fst . fromJust . B.readInt) . B.words <$> B.getLine :: IO [Int]
    m <- fst . fromJust . B.readInt <$> B.getLine :: IO Int
    let s = sum ts
    replicateM_ m $ do
        [p, x] <- map (fst . fromJust . B.readInt) . B.words <$> B.getLine
        print $ s - ts !! (p - 1) + x


Measured memory_bytes: 636
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

using ll = long long;
using ld = long double;
const int INF = 1e9;
const double EPS = 1e-9;
const ll MOD = 1000000007;

struct mint
{
  ll x;
  mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= MOD)
      x -= MOD;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += MOD - a.x) >= MOD)
      x -= MOD;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const { return pow(MOD - 2); }
  mint &operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

mint fac_d(ll n, ll k)
{
  mint res = 1;
  for (ll i = 0; i < k; ++i)
  {
    res *= (n - i);
  }
  return res;
}

mint fac_n(ll n)
{
  mint res = 1;
  for (ll i = 0; i < n; ++i)
  {
    res *= (i + 1);
  }
  return res;
}

mint nCk(ll n, ll k)
{
  if (n < k)
    return 0;
  return fac_d(n, k) * fac_n(k).pow(MOD - 2);
}

int main()
{
  long long n;
  scanf("%lld", &n);
  long long a;
  scanf("%lld", &a);
  long long b;
  scanf("%lld", &b);
  mint sum = 2;
  sum = sum.pow(n) - 1;
  sum -= nCk(n, a);
  sum -= nCk(n, b);
  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
using namespace std;

int main()
{
	int N, K;
	cin >> N >> K;
	for (auto i = 1; i <= N; ++i)
	{
		char s;
		cin >> s;
		if (i == K)
		{
			s = 'a' + (s - 'A');
		}
		cout << s;
	}
	cout << endl;

	return 0;
}


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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			final int n = sc.nextInt();
			
			if(n == 0){
				break;
			}
			
			int[] array = new int[n];
			for(int i = 0; i < n; i++){
				array[i] = sc.nextInt();
			}
			
			final int MAX = 1 << n;
			int min = Integer.MAX_VALUE;
			for(int bit = 0; bit < MAX; bit++){
				int sum1 = 0, sum2 = 0;
				
				for(int i = 0; i < n; i++){
					if((bit & (1 << i)) != 0){
						sum1 += array[i];
					}else{
						sum2 += array[i];
					}
				}
				
				min = Math.min(min, Math.abs(sum1 - sum2));
			}
			
			System.out.println(min);
		}
	}

}

Measured memory_bytes: 20792
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <string>
#include <cmath>

using namespace std;

const long long maxi = 1e18;
const double maxi2 = log10(2e18);

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

	vector<long long> a(n);

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

	if (a[0] == 0) {
		cout << 0 << endl;
		return 0;
	}

	long long ans = 1;
	for (long long x: a) {

		if (log10(ans) + log10(x) > maxi2) {
			ans = -1;
			break;
		}

		ans *= x;
		if (ans > maxi) {
			ans = -1;
			break;
		}
	}

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


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

int main()
{
    string s;
    cin>>s;
    if(s=="Sunny")
    {
        cout<<"Cloudy"<<endl;
    }
    else if(s=="Cloudy")
    {
        cout<<"Rainy"<<endl;
    }
    else if(s=="Rainy")
    {
        cout<<"Sunny"<<endl;
    }
    return 0;
}

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

using namespace std;

vector<int>v;
int cunt[1000000];

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


    for(int i=0; i<tc-1; i++)
    {
        int n;
        cin>>n;
        cunt[n]++;

    }

    for(int i=1; i<=tc; i++)
    {
        cout<<cunt[i]<<endl;

    }

    return 0;

}




Measured memory_bytes: 4404
import java.util.*;

 class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long[] a = new long[(int)N];
        long[] b = new long[105];
        
        for(int i=0;i<N;i++) {
        	a[i] = sc.nextLong();
        	String bin = Long.toBinaryString(a[i]);
//        	System.out.println(bin);
        	for(int j=0;j<bin.length();j++) {
//        		String tmp = bin.substring(j,j+1);
        		if("1".equals(bin.substring(bin.length()-j-1,bin.length()-j))) {
        			b[j]++;
        		}
        	}
        }
        long ans=0;
        for(int i=0;i<100;i++) {
//        	System.out.println(b[i]);
//        	System.out.println(Math.pow(2, i)*b[i]*(N-b[i]));
        	long tmp=b[i]*(N-b[i]);
        	for(int j=0;j<i;j++) {
        		tmp=(tmp*2)%1000000007;
        	}
        	ans = (long) ((ans + tmp)%1000000007);
        }
        System.out.println(ans);	
        
        
    }

}

Measured memory_bytes: 274976
N, Y = map(int, input().split());

# 10000x + 5000y + 1000z = Y
# z = N - x - y
# → 9000x + 4000y = Y - 1000N

# Y - 1000N
flag = False;
S = Y - N * 1000;
for i in range(N + 1):
  y_div, y_mod = divmod((S - 9000 * i), 4000);
  z = N - i - y_div;
  if (y_mod == 0 and z >= 0 and y_div >= 0):
    print(str(i) + " " + str(y_div) + " " + str(z));
    flag = True;
    break;

if (flag == False):
  print("-1 -1 -1");

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

int main() {
    int m,d;
    cin >> m >> d;
    int pday=0;
    for(int i=1;i<m+1;i++){
        for(int j=1;j<d+1;j++){
            int d1=j%10;
            int d10=(j-d1)/10;
            if(d1>=2 && d10>=2 && d1*d10==i){
                pday=pday+1;
            }
        }
    }
    cout << pday << endl;
}

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

int main() {
	long long n, move[5], people[6] = {};
	cin >> n;
	people[0] = n;
	for(int i = 0; i < 5; i++) cin >> move[i];
	long long min = move[0], result = 0;
	
	for(int i = 1; i < 5; i++){
		if(move[i] < min) min = move[i];
	}
	
	if(n % min > 0) n += min - (n % min);
	
	result = 4 + n / min;
	
	cout << result << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [int(input()) for i in range(N)]

if A[0]:
    print(-1)
    exit()

ans = 0
for a,b in zip(A,A[1:]):
    if a+1 < b:
        print(-1)
        exit()
    if a+1 == b:
        ans += 1
    else:
        ans += b
print(ans)

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

int main()
{
    cin.tie(0);

    int n;
    cin >> n;
    vector<int64_t> as(n);

    int64_t sum = 0;
    for (auto& a : as) {
        cin >> a;
        sum += a;
    }

    int64_t ans = 0x7ffffffffffffffL;
    int64_t pre = 0;

    for (int i = 0; i < n - 1; i++) {
        pre += as[i];
        ans = min(ans, abs(sum - pre - pre));
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int N, T;
  cin >> N >> T;
  vector<int> v;
  rep(i,N){
    int a;
    cin >> a;
    v.push_back(a);
  }

  ll mn = 10000000000000000LL;
  map<ll,int> memo;
  int ret = 0;
  rep(i,N){
    ll a = v[i];
    if(memo.begin() != memo.end()){
      auto itr = memo.begin();
      ll b = itr->first;

      if(b<=a){
        if(mn == b-a){
          ret++;
        }
        else if(mn > b-a){
          mn = b-a;
          ret = 1;
        }
      }
      
    }
    memo[a]++;
  }
  
  cout << ret << endl;
  
  return 0;
}



Measured memory_bytes: 6904
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>

using namespace std;

int main(){

    int n;
    cin >> n;

    int a[n-1];
    for(int i=0;i<n-1;i++)cin >> a[i];

    int b[n]={};

    for(int i=0;i<n-1;i++)b[a[i]-1]++;

    for(int i=0;i<n;i++)cout << b[i] << endl;

}

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

int main() {
	int n,m,a[100][100],b[100],c[100]={};cin>>n>>m;
	for(int i=0;i<n;i++)for(int j=0;j<m;j++)cin>>a[i][j];
	for(int i=0;i<m;i++)cin>>b[i];
	for(int i=0;i<n;i++)for(int j=0;j<m;j++)c[i]+=a[i][j]*b[j];
	for(int i=0;i<n;i++)cout<<c[i]<<endl;
	return 0;
}

Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

const int mod = 1000000007;
struct mint{
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a){
        if((x+=a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a){
        if((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a){
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        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 pow(ll t) const {
        if(!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if(t&1) a *= *this;
        return a;
    }

    mint inv() const {
        return pow(mod - 2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1){
        assert(n < mod);
        fact[0] = 1;
        for(int i = 1; i <= n; i++) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for(int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;  
    }
    mint operator()(int n, int k){
        if(k < 0 || n < k) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};


int main(){
    int n, m; cin >> n >> m;
    if(abs(n-m)>=2) {
        cout << 0 << endl;
        return 0;
    }
    mint ans = 1;
    for(int i = 1; i <= n; ++i) ans *= i;
    for(int i = 1; i <= m; ++i) ans *= i; 
    if(n == m) ans *= 2;
    cout << ans << endl;
}

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

int main(void){
  string s;
  cin >> s;
  s[0] = s[0] == '1' ? '9' : '1'; 
  s[1] = s[1] == '1' ? '9' : '1'; 
  s[2] = s[2] == '1' ? '9' : '1'; 
  cout << s << endl;
}

Measured memory_bytes: 256
# D
N, M = map(int, input().split())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))

LARGE = 10**9+7

A_dict = dict()
B_dict = dict()

for i in range(N):
    A_dict[A_list[i]] = 1
for i in range(M):
    B_dict[B_list[i]] = 1

res = 1

rows = 0
cols = 0

cross = 0

R = N*M

for _ in range(N*M):
    
    if R in A_dict.keys() and R in B_dict.keys():
        # A and B
        rows += 1
        cols += 1
        #print("1")
    elif R in A_dict.keys():
        # A
        rows += 1
        res = (res * cols) % LARGE
        #print("2")
    elif R in B_dict.keys():
        # B
        cols += 1
        res = (res * rows) % LARGE
        #print("3")
    else:
        # else
        res = (res * (rows * cols - cross)) % LARGE
        #print("4")
        if rows * cols - cross <= 0:
            res = 0
            break
    cross += 1
    R -= 1
    #print(rows, cols, cross)

print(res)

Measured memory_bytes: 3316
#include<stdio.h>
#include<stdbool.h>

bool check(int checks,int *D,int K);

int main(void){
  int N,K,D[10];
  int i,j,now;
  bool flg=true;

  scanf("%d%d",&N,&K);
  for(i=0;i<K;i++) scanf("%d",D+i);

  for(i=N;flg;i++){
    flg=false;
    for(now=1;now<=i;now*=10){
      if(check((i%(10*now))/now,D,K)){
	flg=true;
	break;
      }
    }
  }
  printf("%d\n",i-1);    
  return 0;
}

bool check(int checks,int *D,int K){
  int i;
  for(i=0;i<K;i++) if(checks==D[i]) return true;
  return false;
}


Measured memory_bytes: 128
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder {

    public class Program {
        public static void Main (string[] args) {
            new Program ().Solve (new ConsoleInput (Console.In, ' '));
        }

        public void Solve (ConsoleInput cin) {
            // WriteLine ("入力");
            var S = cin.ReadLine;
            int N = S.Length;
            List<int> s = new List<int> ();
            for (int i = 0; i < N; i++) {
                s.Add (int.Parse (S[i].ToString ()));
            }

            int index = 0;
            int count = 0;
            while (true) {
                if (index + 1 >= s.Count) break;
                if (s[index] != s[index + 1]) {
                    count++;
                    s.RemoveAt (index);
                    s.RemoveAt (index);
                    if (index != 0) index--;
                } else {
                    if (index + 1 == s.Count) break;
                    index++;

                }
            }

            WriteLine (count * 2);
        }

    }

    public class ConsoleInput {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput (System.IO.TextReader stream, char separator = ' ') {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string> ();
        }
        public string Read {
            get {
                if (inputStream.Count != 0) return inputStream.Dequeue ();
                string[] tmp = _stream.ReadLine ().Split (_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue (tmp[i]);
                return inputStream.Dequeue ();
            }
        }
        public string ReadLine { get { return _stream.ReadLine (); } }
        public int ReadInt { get { return int.Parse (Read); } }
        public long ReadLong { get { return long.Parse (Read); } }
        public double ReadDouble { get { return double.Parse (Read); } }
        public string[] ReadStrArray (long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray (long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray (long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

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

int main(int argc, char const *argv[])
{
	int a,b;
	cin>>a>>b;
	if (a<=b)
	{
		cout<<a<<endl;
	}
	else
	{
		cout<<a-1<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    string s;
    cin>>s;
    int f=1;
    for(int i=0;i<s.length()-1;i++){
        if(s[i]!=s[i+1])
            f=0;
    }
    if(f)
        cout<<(f^1)<<endl;
    else{
        int cnt=0;
        for(int i=0;i<s.length()-1;i++){
            if(s[i]!=s[i+1])
            cnt++;
        }
    cout<<cnt<<endl;
    }
    return 0;
}


Measured memory_bytes: 3716
#include <bits/stdc++.h>
     
    using namespace std;
     
    int main(){
        
        
        int N;
        cin>>N;
        
        vector<vector<int>> h(N,vector<int>(3));
        
        for(int i=0;i<N;i++){
            for(int j=0;j<3;j++){
                cin>>h[i][j];
            }
        }
        
        vector<vector<int>>dp (N,vector<int>(3));
        
        for(int j=0;j<3;j++){
            dp[0][j]=h[0][j];
        }
        for(int i=1;i<N;i++){
            dp[i][0]=h[i][0]+max(dp[i-1][1],dp[i-1][2]);
            dp[i][1]=h[i][1]+max(dp[i-1][0],dp[i-1][2]);
            dp[i][2]=h[i][2]+max(dp[i-1][0],dp[i-1][1]);
            
        }
      	cout<<max(dp[N-1][0],max(dp[N-1][1],dp[N-1][2]))<<endl;
        
    }

Measured memory_bytes: 11136
import java.util.*;
public class Main {
	
	public static void main(String... args) {
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		
		
		if (a + b > 2 * c) {
			int ans = 0;
			
			while(x >= 1 && y >= 1) {
				ans += 2*c;
				x-= 1;
				y-= 1;
			}
			
			if (x > 0 && a > 2*c) {
				while(x >= 1) {
					ans += 2*c;
					x -= 1;
				}
			}
			
			if (y > 0 && b > 2*c) {
				while(y >= 1) {
					ans += 2*c;
					y -= 1;
				}
			}
			
			ans += a*x + b*y;
			
			System.out.println(ans);
		} else {
			System.out.println(a*x + b*y);
		}
	}
}


Measured memory_bytes: 23252