akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x,a) fill(x.begin(),x.end(),a)
#define FILA(ar,N,a) fill(ar,ar+N,a)
#define NEXTP(x) next_permutation(x.begin(),x.end())
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define pb push_back
#define pri(aa) cout<<(aa)<<endl
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
const ll INF=1e9+7;
const ll N = 300003;
const ll so = 998244353;
//a^(p-1) = 1 (mod p)(p->Prime numbers)
//a^(p-2) = a^(-1)
ll calc(ll a,ll b,ll p){//a^(b) mod p   
	if(b==0)return 1;
	ll y = calc(a,b/2,p);y=(y*y)%p;
	if(b & 1) y = (y * a) % so;
	return y;
}

ll n,a,b,k,ans=0;
ll f[N],fr[N];

ll C(ll n,ll k){
	return f[n] * fr[k] % so * fr[n-k] % so;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>a>>b>>k;
	if(k==0){
		cout<<1<<endl;
		return 0;
	}
	f[0]=fr[0]=1;
	FOR(i,1,n+1){
		f[i] = (f[i-1] * i) % so;
		fr[i] = calc(f[i],so-2,so);
	}

	FOR(i,0,n+1){//A i ko
		ll j = (k-i*a);
		if(j%b!=0)continue;
		if(j<0||j>n*b)continue;
		j = j / b;
		ans += C(n,i) * C(n,j) % so;
		ans = ans % so;
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a7=1000000007;
ll inf=100000000000000000;

ll min(ll a,ll b){
    if(a<b)return a;
    return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    return b;
}

int main(){
    ll n;cin>>n;
    ll a[n+2];
    a[0]=0;
    a[n+1]=0;
    ll sum=0;
    for(ll i=1;i<=n;i++){
        cin>>a[i];
    }
    ll b[n+1],c[n];
    for(ll i=0;i<=n;i++){
        b[i]=abs(a[i+1]-a[i]);
        sum+=b[i];
    }
    for(ll i=0;i<=n-1;i++){
        c[i]=abs(a[i+2]-a[i]);
    }
    for(ll i=1;i<=n;i++){
        cout<<sum-b[i-1]-b[i]+c[i-1]<<endl;;
    }
    
    return 0;
}



Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=400005;

ll S[maxn];
int n,q;

void update(int id,int i,int v,int l,int r) {
	if (l==r) S[id]+=v;
	else {
		int m=l+r>>1;
		if (i<=m) update(id<<1,i,v,l,m);
		else update(id<<1|1,i,v,m+1,r);
		S[id]=S[id<<1]+S[id<<1|1];
	}
}

ll query(int id,int ql,int qr,int l,int r) {
	if (ql==l && qr==r) return S[id];
	int m=l+r>>1;
	if (qr<=m) return query(id<<1,ql,qr,l,m);
	else if (ql>m) return query(id<<1|1,ql,qr,m+1,r);
	else return query(id<<1,ql,m,l,m)+query(id<<1|1,m+1,qr,m+1,r);
}

int main() {
	cin>>n>>q;
	for (int i=0;i<q;i++) {
		bool op; cin>>op;
		if (op) {
			int s,t; cin>>s>>t;
			cout<<query(1,s,t,1,n)<<'\n';
		}
		else {
			int i,x; cin>>i>>x;
			update(1,i,x,1,n);
		}
	}
}


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

using std::cerr;
using std::endl;

const int N = 21;

int n, K, ans = 1, h[(1 << N) + 5], ch[(1 << N) + 5][2], f[N][(1 << N) + 5];

int main() {
  scanf("%d %d", &n, &K);
  for (int i = 0; i <= n; ++i)
    for (int j = 0; j < 1 << i; ++j)
      scanf("%1d", &f[i][(1 << i) | j]);
  h[0] = -1;
  for (int s = 1; s < 2 << n; ++s)
    h[s] = h[s >> 1] + 1;
  for (int s = 2; s < 2 << n; ++s) {
    if (s & (1 << (h[s] - 1))) {
      ch[s][1] = s ^ (1 << h[s]);
      ch[s][0] = ch[ch[s][1]][0];
    } else {
      ch[s][0] = s ^ (3 << (h[s] - 1));
      ch[s][1] = ch[ch[s][0]][1];
    }
  }
  for (int i = n; i; --i) {
    for (int v = 1 << i; v < 2 << n; ++v) {
      int s = v >> i, t = (v & ((1 << i) - 1)) | (1 << i);
      if (ch[t][0])
        f[h[ch[t][0]]][((s << 1 ^ 1) << h[ch[t][0]]) ^ ch[t][0]] += f[i][v];
      if (ch[t][1])
        f[h[ch[t][1]]][((s << 1 ^ 0) << h[ch[t][1]]) ^ ch[t][1]] += f[i][v];
      f[0][s] += f[i][v];
    }
  }
  for (int s = 2; s < 2 << n; ++s)
    if (f[0][s] >= K && h[s] > h[ans])
      ans = s;
  int p = n;
  while (!(ans >> p) & 1)
    --p;
  while (p--)
    printf("%d", (ans >> p) & 1);
  putchar('\n');
  return 0;
}



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

int n, k, ar[100001];

int main(){
        cin >> n>> k;
        for (int i = 0; i < n; i++) {
                cin >> ar[i];
        }
        sort(ar, ar + n);
        int mn = 2e9;
        for (int i = 0; i < n-k+1; i++) {
                mn = min(mn, ar[i+k-1]-ar[i]);
        }
        cout << mn;
return 0;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    int n;
    cin >> n;
    ll mi, res = -1e15;
    cin >> mi;
    for (int i = 1; i < n; i++)
    {
        ll r;
        cin >> r;
        res = max(res, r - mi);
        mi = min(mi, r);
    }
    cout << res << endl;
}



Measured memory_bytes: 3216
#include<bits/stdc++.h>
#define clr(x) memset(x, 0, sizeof(x))
#define sz(x) (int)x.size()

using namespace std;

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

const ll mx = 105;
const ll maxn = 1000001;
const ll mod = 1000000007;

vector<vector<int>> adj;
vector<ll> lis;
bool vis[maxn];
bool pos;

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

  ll t = 1;

  //cin>>t;

  while(t--){
    
     ll n, i, j, k;

     float r, pi = float(22)/float(7);
     cin>>r;
     cout<<setprecision(20)<<2*M_PI*r;     
  }     
        
}


Measured memory_bytes: 3804
const main = (input) => {
  input = input.trim();
  input = input.split(' ');
  const a = parseInt(input[0], 10);
  const b = parseInt(input[1], 10);
  const c = a+b;
  const d = a-b;
  const e = a*b;
  console.log(Math.max(c,d,e)+0);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        FDivisionOrSubstraction solver = new FDivisionOrSubstraction();
        solver.solve(1, in, out);
        out.close();
    }

    static class FDivisionOrSubstraction {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long n = in.nextLong();
            long cnt = 0;

            long m = n - 1;

            //case1
            for (int i = 1; i <= Math.sqrt(m); i++) {
                if (m % i == 0) {
                    if (i >= 2) {
                        cnt++;
                    }
                    if (i < m / i) {
                        cnt++;
                    }
                }
            }

            // case2
            ArrayList<Long> divisor = new ArrayList<>();
            for (int i = 2; i <= Math.sqrt(n); i++) {
                if (n % i == 0) {
                    divisor.add((long) i);
                    if (i < n / i) {
                        divisor.add(n / (long) i);
                    }
                }

            }
            divisor.add(n);

            //out.println(cnt);
            //out.println(divisor);

            for (Long l : divisor) {
                long cmp = n;
                while (cmp % l == 0) {
                    cmp /= l;
                }
                if (cmp % l == 1) {
                    //out.println(l);
                    cnt++;
                }
            }

            out.println(cnt);
        }

    }
}



Measured memory_bytes: 22356
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define mem(x,v) memset(x,v,sizeof(x))
#define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
#define rep(i,a,b) for(register int i=(a);i<int(b);++i)
#define Dep(i,a,b) for(register int i=(a);i>=int(b);--i)
#define gc getchar
#define pc putchar
#define fi first
#define se second
inline ll read(){
    ll x=0,f=1;char c=gc();
    for(;!isdigit(c);c=gc())if(c=='-')f=-1;
    for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c^48);
    return x*f;
}
inline void write(ll x){if(x<0)x=-x,pc('-');if(x>=10)write(x/10);putchar(x%10+'0');}
inline void writeln(ll x){write(x);pc('\n');}
inline void wri(ll x){write(x);pc(' ');}
const int maxn=5005;
ll dp[maxn][maxn],a[maxn];
ll n,A,B,ans;
int main(){
	n = read(),A = read(),B = read();
	ans = 1ll << 60;
	Rep(i,1,n) a[i] = read();
	memset(dp,0x3f,sizeof(dp));
	dp[0][0] = 0;
	Rep(i,1,n)Rep(j,0,n){
		if(a[i] > j)
			dp[i][j]=min(dp[i][j],dp[i-1][j] + A),
			dp[i][a[i]]=min(dp[i][a[i]],dp[i-1][j]);
		else dp[i][j]=min(dp[i][j],dp[i-1][j]+B);
	}
	Rep(i,0,n) ans=min(ans,dp[n][i]);
	writeln(ans);
	return 0;
}

Measured memory_bytes: 195968
N = int(input())
T = list(map(int, input().split()))
A = list(map(int, input().split()))

exact = [False]*N

height = [0]*N
height[0] = T[0]
exact[0] = True

for i in range(1,N):
    height[i] = T[i]
    exact[i] = T[i]>T[i-1]

if (exact[-1] and A[-1]!=height[-1]) or A[-1]>height[-1]:
    print(0)
    exit()

height[-1] = A[-1]
exact[-1] = True

for i in range(N-1):
    if A[i]>A[i+1]:
        if (exact[i] and A[i]!=height[i]) or A[i]>height[i]:
            print(0)
            exit()
        height[i]=A[i]
        exact[i]=True
    else:
        if exact[i] and A[i]<height[i]:
            print(0)
            exit()
        else:
            height[i]=min(height[i], A[i])

ans=1
mod=10**9+7
for e,h in zip(exact, height):
    if not e:
        ans=(ans*h)%mod

print(ans)

Measured memory_bytes: 18752
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N_MAX 1000010

int min( int a, int b ){
    if ( a<b ) return a;
    else return b;
}

char s[N_MAX];
int d[N_MAX][2];

int main(){
    
    //整数を文字列として入力
    scanf("%1000000s",s);
    int len = strlen(s);
    
    int x = s[len-1] - '0';
    d[len-1][0] = x;
    d[len-1][1] = 11 - x;
    
    for ( int i=len-2; i>=0; i-- ){
        x = s[i] - '0';   //xにi桁目の数字を代入
        d[i][0] = min( d[i+1][0] + x, d[i+1][1] + x );
        d[i][1] = min( d[i+1][0] + 11 - x, d[i+1][1] + 9 - x );
    }
    
    int ans = min( d[0][0] , d[0][1] );
    printf("%d\n",ans);
    
    return 0;
    
}


Measured memory_bytes: 8960
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define mod 1000000007
using namespace std;


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

int n;
cin>>n;

string A = "ABC";

A+= to_string(n);
cout<<A;
return 0;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
S=list(map(int,input().split()))
T=list(map(int,input().split()))
mod=1000000007

dp=[[0 for j in range(M+1)] for i in range(N+1)]
Sum=[[0 for j in range(M+1)] for i in range(N+1)]

for i in range(1,N+1):
	for j in range(1,M+1):
		if S[i-1]==T[j-1]:
			dp[i][j]=Sum[i-1][j-1]
#			for k in range(1,i):
#				for l in range(1,j):
#					dp[i][j]+=dp[k][l]
			dp[i][j]+=1
		Sum[i][j]=(Sum[i-1][j]+Sum[i][j-1]-Sum[i-1][j-1]+dp[i][j])%mod

print(Sum[N][M]+1)

Measured memory_bytes: 109276
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int n,a,b;
int main()
{
	scanf("%d%d%d",&n,&a,&b);
	if(abs(a-n)<abs(b-n))printf("A\n");
	else printf("B\n");
	return 0;
}

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


int main(){
    string n;
    cin >> n;
    vector<vector<int>> data(n.size()+1, vector<int>(2));
    data.at(0).at(1) = 1;

    for(int i=0; i<n.size(); i++){
        int x;
        x = n.at(i) - '0';
        data.at(i+1).at(0) = min(data.at(i).at(0)+x, data.at(i).at(1)+10-x);
        data.at(i+1).at(1) = min(data.at(i).at(0)+x+1, data.at(i).at(1)+9-x);
    }

    cout << data.at(n.size()).at(0) << endl;

    return 0;
}

Measured memory_bytes: 55940
# include <cmath>
# include <iostream>
# include <queue>
# include <set>
# include <stack>
# include <string>
# include <vector>


const int MAX = 2000000;
const int MOD = 1000000000 + 7;

long long fac[MAX], finv[MAX], inv[MAX];


void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}


long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


using namespace std;


int main() {
    COMinit();
    int n, k; cin >> n >> k;

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

    long long ans = 0;
    for (int i=n-1; i>=k-1; i--) {
        ans += (COM(i, k-1)*a[i]%MOD);
    }

    for (int i=0; i<n-k+1; i++) {
        ans -= (COM(n-i-1, k-1)*a[i]%MOD);
    }

    cout << (ans%MOD) << endl;
    return 0;
}



Measured memory_bytes: 47488
n=int(input())
s=[]
w=0
m=1000
for i in range(n):
    a=int(input())
    s.append(a)
    w+=a
    if a%10!=0:
        m=min(m,a)

if m==1000:
    print(0)
elif w%10!=0:
    print(w)
else:
    print(w-m)




Measured memory_bytes: 3060
#include <iostream>
int main(){
	int n,m,l,i,j,k;
	std::cin>>n>>m>>l;
	long long a[n][m],b[m][l],c[n][l];
	
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			std::cin>>a[i][j];
		}
	}
	for(i=0;i<m;i++){
		for(j=0;j<l;j++){
			std::cin>>b[i][j];
		}
	}
	for(i=0;i<n;i++){
		for(j=0;j<l;j++){
			c[i][j]=0;
			for(k=0;k<m;k++){
				c[i][j]+=a[i][k]*b[k][j];
			}
		}
	}
	for(i=0;i<n;i++){
		for(j=0;j<l;j++){
			std::cout<<c[i][j];
			if(j!=l-1)std::cout << " ";
		}
		std::cout<<std::endl;
	}	
	return 0;
}

Measured memory_bytes: 1396
H, W = map(int, input().split())
s = [input() for i in range(H)]
flag = True
for i in range(H):
    for j in range(W):
        if s[i][j] == '#':
            c = 0
            if j > 0:
                if s[i][j - 1] == '#':
                    c += 1
            if j < W - 1:
                if s[i][j + 1] == '#':
                    c += 1
            if i > 0:
                if s[i - 1][j] == '#':
                    c += 1
            if i < H - 1:
                if s[i + 1][j] == '#':
                    c += 1
            if c < 1:
                flag = False
                break
if flag:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
def main():
    N= int(input())
    A = [0]*10**5
    for x in range(1,101):
        for y in range(1,101):
            for z in range(1,101):
                n = x*x + y*y + z*z + x*y + y*z + z*x 
                A[n] += 1
    for i in range(1,N+1):
        print(A[i])
if __name__ == '__main__':
    main()

Measured memory_bytes: 9932
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

using namespace std;

signed main() {
	int a, b;
	cin >> a >> b;
	
	cout << max(a - b * 2, 0) << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    S = list(input())
    N = len(S)
    ans = N * (N - 1) // 2 + 1
    c = Counter(S)
    for k, v in c.items():
        if v > 1:
            ans -= v * (v - 1) // 2

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 5216
# https://atcoder.jp/contests/abc074/tasks/arc083_b

import sys
input = sys.stdin.buffer.readline

def floyd_warshall(V, dist):                                               # 動的計画法。頂点 k まで経由することが可能な場合の最短距離という部分問題を考えて、k = 0 から漸化式的に計算する
    res = 0
    for i in range(V):
        for j in range(i+1,V):
            flg = 0
            for k in range(V):
                if k==i or k==j:
                    continue
                if dist[i][j] > dist[i][k] + dist[k][j]:
                    return -1
                if dist[i][j] < dist[i][k] + dist[k][j]:
                    flg += 1
                if flg == V-2:
                    res += dist[i][j]
    return res

N = int(input())

dist = [list(map(int, input().split())) for _ in range(N)]

if N ==2:
    print(dist[0][1])
else:
    print(floyd_warshall(N, dist))

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

int main(){
     int A,B,C;
     cin >>A>>B>>C;
     if(A==B or A==C){
          if(B==C){
               cout <<"No"<<endl;
          }else{
               cout <<"Yes" <<endl;
          }
     }else{
          if(B==C){
               cout<<"Yes"<<endl;
          }else{
               cout <<"No" <<endl;
          }
     }
}


Measured memory_bytes: 3676
import math
import sys
import queue
from collections import Counter
from itertools import accumulate
from fractions import gcd
from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

mod = 1000000007

"""
# 標準入力取得
## 文字列
    = sys.stdin.readline().rstrip()
    = list(sys.stdin.readline().rstrip())

## 数値
    = int(sys.stdin.readline())
    = map(int, sys.stdin.readline().split())
    = list(map(int, sys.stdin.readline().split()))
    = [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

# Lの最小公倍数探索
# mの探索範囲をどのように絞ればいいかが分からない
if __name__ == "__main__":
    N = int(sys.stdin.readline())
    L = list(map(int, sys.stdin.readline().split()))

    print(sum((x - 1) for x in L))

Measured memory_bytes: 5328
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <tuple>
#include <utility>
#include <functional>
#include <set>
#include <map>
#include <bitset>
#include <list>

using namespace std;


#define INF pow(10, 9)
// typedef priority_queue<tuple<int,int,int>, vector< tuple<int, int, int> >, greater< tuple<int, int, int> > > PQ;



int main(void)
{


    string S;
    cin >> S; // x, y
    int Len = S.size();
    string k = S.substr(Len-1);
    if( k == "s")
    {
        S = S+"es";
    }
    else
    {
        S = S+"s";
    }

    cout << S << endl;




    return 0;
}


Measured memory_bytes: 3632
h, w = map(int, input().split())
s = [input() for _i in range(h)]
visit = [[-1 for _i in range(w)] for _j in range(h)]
r = 0
from collections import deque
for i in range(h):
    for j in range(w):
        if (s[i][j]=="#") and (visit[i][j]<0):
            q = deque([[i, j]])
            black = 1
            white = 0
            visit[i][j] = 1
            while q:
                x, y = q.popleft()
                for n, m in [[1,0], [0, 1], [-1,0], [0,-1]]:
                    if (0<=x+n) and (0<=y+m) and (x+n<h) and (y+m<w):
                        if (visit[x+n][y+m]<0) and (s[x][y]!=s[x+n][y+m]):
                            visit[x+n][y+m]=1
                            if s[x][y] == "#":
                                white += 1
                            else:
                                black += 1
                            q.append([x+n, y+m])
            r += black*white

print(r)

Measured memory_bytes: 4852
cond = [int(n) for n in input().split(" ")]
five,seven = 0,0
for c in cond:
    if c == 5:
        five += 1
    elif c == 7:
        seven += 1
else:
    if five == 2 and seven == 1:
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 7780
#include <stdio.h>

int main()
{
    int flag = 1, i, j;
    int A[100], N, k, count = 0;
    ;

    scanf("%d", &N);
    for (i = 0; i < N; i++)
        scanf("%d", &A[i]);

    while (flag)
    {
        flag = 0;
        i = 0;
        for (j = N - 1; j >= i + 1; j--)
        {
            if (A[j] < A[j - 1])
            {
                k = A[j];
                A[j] = A[j - 1];
                A[j - 1] = k;
                flag = 1;
                count++;
            }
        }
        i++;
    }
    for (i = 0; i < N; i++)
    {
        if (i)
            printf(" ");
        printf("%d", A[i]);
    }
    printf("\n%d\n", count);
    return 0;
}


Measured memory_bytes: 2108
#include<iostream>
#include<cstdio>
#include<algorithm>

using namespace std;

int main(){
	int l[10],sum;
	double x,y;
	double v1,v2;
	while(scanf("%d",&l[0])!=EOF){
		sum=l[0];
		for(int i=1;i<10;i++){
			scanf(",%d",&l[i]);
			sum+=l[i];
		}
		scanf(",%lf,%lf",&v1,&v2);
		x=(v1*sum)/(v1+v2);
		y=sum-x;
		int pass;
		double temp=0;
		for(int i=0;i<10;i++){
			temp+=l[i];
			if(temp>=x){
				pass=i;
				break;
			}
		}
		printf("%d\n",pass+1);
	}
}

Measured memory_bytes: 3152
#include<iostream>
using namespace std;
int main(){
  int a,b,c;
  while(cin >> a >> b >> c && a!=-1||b!=-1||c!=-1){
    if(a==-1||b==-1)cout<<"F"<<endl;
    else if(a+b>=80)cout<<"A"<<endl;
    else if(a+b>=65)cout<<"B"<<endl;
    else if((a+b>=50)||(a+b>=30&&c>=50))cout<<"C"<<endl;
    else if(a+b>=30)cout<<"D"<<endl;
    else cout << "F" << endl;
  }
}



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

int X;
bool *dp;

void Solve()
{
  dp[0] = true;
  for (int i = 0; i <= X; ++i)
    if (dp[i]) { for (int j = 100; j <= 105; ++j) dp[i + j] = true; }
  if (dp[X]) puts("1"); else puts("0");
}

void Init()
{
  cin >> X;
  dp = new bool[X + 120];
  for (int i = 1; i <= X; ++i)
    dp[i] = false;
}

void Clean()
{
  delete[] dp;
}

int main(){ Init(); Solve(); Clean(); return 0; }


Measured memory_bytes: 384
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

func main() {
	scanner.Split(bufio.ScanWords)
	sum := 0
	for i := 0; i < 5; i++ {
		score := nextInt()
		if score < 40 {
			sum += 40
		} else {
			sum += score
		}
	}
	// fmt.Println(sum)
	fmt.Println(sum / 5)
}



Measured memory_bytes: 1092
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <list>
#include <iomanip>
#include <queue>
#include <functional>
#include <cassert>
#include <cmath>
#include <set>
#include <map>
#include <numeric>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repe(i, n) for(int i = 0; i <= (n); i++)
#define fo(i, a, b) for(int i = (a); i < (b); i++)
#define foe(i, a, b) for(int i = (a); i <= (b); i++)
#define NL << endl

using namespace std;
using ll = long long;
const int INTMAX = numeric_limits<int>::max();
const int INTMIN = numeric_limits<int>::min();
const ll LLMAX = numeric_limits<long long>::max();
const ll LLMIN = numeric_limits<long long>::min();
const int MOD = 1000000007;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

using namespace std;

int main() {

	int n;

	cin >> n;

	for(int i = 111; i <= 999; i+=111) {
		if (n <= i) {
			cout << i NL;
			break;
		}
	}
	return 0;

}



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

#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

void solve()
{
  int N;
  cin >> N;
  int ans = 0;
  for (int i = 1; i <= N; i++) {
    if (1 <= i && i < 10)
      ans++;
    else if (100 <= i && i < 1000)
      ans++;
    else if (10000 <= i && i < 100000)
      ans++;
  }
  cout << ans << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

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

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int n;
  cin >> n;
  string possible;
  cin >> possible;
  if (possible[0] == '0') {
    cout << "Impossible" << endl;
    return 0;
  }
  for (int i = 0; i < 1<<n; i++) {
    for (int j = 0; j < n; j++) {
      if (i>>j&1) {
	if (possible[i] == '1' && possible[i^1<<j] == '0') {
	  cout << "Impossible" << endl;
	  return 0;
	}
      }
    }
  }
  cout << "Possible" << endl;
  vector<pair<int,int>> ans;
  function<void(int,int)> add = [&](int mask, int inv) {
    int lsb = mask&-mask;
    if (lsb == mask) {
      int x = 31-__builtin_clz(mask);
      for (int i = 0; i <= x; i++)
	ans.emplace_back(i,0);
      if (inv) {
	ans.emplace_back(x,1);
	ans.emplace_back(x+1,1);
	ans.emplace_back(x+1,0);
      } else {
	ans.emplace_back(x+1,0);
	ans.emplace_back(x+1,1);
	ans.emplace_back(x,1);
      }
      for (int i = x; i > 0; i--)
	ans.emplace_back(i,0);
    } else {
      if (inv == 0) {
	add(mask^lsb, 0);
	add(lsb, 0);
	add(mask^lsb, 1);
	add(lsb, 1);
      } else {
	add(lsb, 0);
	add(mask^lsb, 0);
	add(lsb, 1);
	add(mask^lsb, 1);
      }
    }
  };
  for (int i = 0; i < 1<<n; i++) {
    if (possible[i] == '0') {
      add(i, 0);
    }
  }
  ans.emplace_back(0,0);
  cout << (int)ans.size()-1 << endl;
  for (auto [x,y] : ans)
    cout << x << ' ' << y << '\n';
}


Measured memory_bytes: 4324
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define repR(i, n) for(ll i = n; i >= 0; i--)
#define For(i, m, n) for(ll i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()

using namespace std;

ll gcd(ll a, ll b){
    ll r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

ll lcm(ll x, ll y)
{
    if(x == 0 || y == 0) {
        return -1;
    }
    
    return (x * y / gcd(x, y));
}

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll nCr(ll n, ll r) {
    if ( r * 2 > n ) r = n - r;
    ll dividend = 1;
    ll divisor  = 1;
    for ( ll i = 1; i <= r; ++i ) {
        dividend *= (n-i+1);
        divisor  *= i;
    }
    return dividend / divisor;
}

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

ll mod = 1e9+7;

int main(){
    ll n, k, q;
    cin >> n >> k >> q;
    vector<ll> player(n);
    
    rep(i, q){
        ll x;
        cin >> x;
        player[x-1] ++;
    }
    
    rep(i, n){
        if(k + player[i] - q <= 0){
            cout << "No" << endl;
        }else {
            cout << "Yes" << endl;
        }
    }
    
    return 0;
}


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

int main(){
    int x,a,b;
    cin >> x >> a >> b;
    string ans;
    if(b - a <= 0){
        ans = "delicious";
    }else if(b - a <= x){
        ans = "safe";
    }else{
        ans = "dangerous";
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int lli;
const lli mod = 1e9+7;

struct UnionFindTree{
    vector<int> v;
    vector<int> rank;
    int numgroup;
     
    UnionFindTree(int n): v(n, -1), rank(n, 0), numgroup(n){}
    int Find(int x){
        if(v[x] < 0) return x;
        return v[x] = Find(v[x]);
    }
    void Union(int a, int b){
        a = Find(a);
        b = Find(b);
        if(a == b) return;
        if(rank[a] < rank[b]) swap(a, b);
        if(rank[a] == rank[b]) rank[a]++;
        v[b] = a;
        numgroup--;
    }
};

lli modpow(lli n, lli p, lli mod){
    lli res = 1;
    for(int i=63; i>=0; i--){
        res = res*res %mod;
        if((p & 1LL<<i) != 0) res = res*n %mod;
    }
    return res;
}

int main(){
    while(1){
        int n,m;
        cin >> n >> m;
        if(n==0) break;
        
        UnionFindTree uft(n);
        for(int i=0; i<m; i++){
            int a,b;
            cin >> a >> b;
            a--; b--;
            uft.Union(a, b);
        }
        if(m == 0){
            cout << modpow(2, n, mod) << endl;
        }else{
            cout << (modpow(2, uft.numgroup, mod) +1)%mod << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
  string s;
  cin >> s;
  ll n = s.size(), d = 1000000007, x[n + 1] = {}, a[n + 1] = {}, b[n + 1] = {}, c[n + 1] = {};
  x[0] = 1;
  for(ll i = 0; i < n; i++){
    if(s[i] == '?'){
      x[i + 1] = x[i] * 3;
      a[i + 1] = x[i] + a[i] * 3;
      b[i + 1] = a[i] + b[i] * 3;
      c[i + 1] = b[i] + c[i] * 3;
    }else{
      x[i + 1] = x[i];
      a[i + 1] = (s[i] == 'A' ? x[i] : 0) + a[i];
      b[i + 1] = (s[i] == 'B' ? a[i] : 0) + b[i];
      c[i + 1] = (s[i] == 'C' ? b[i] : 0) + c[i];
    }
    x[i + 1] %= d;
    a[i + 1] %= d;
    b[i + 1] %= d;
    c[i + 1] %= d;
  }
  cout << c[n] << endl;
  return 0;
}

Measured memory_bytes: 3584
import sys
input = lambda: sys.stdin.readline().rstrip() 
import collections
from operator import itemgetter

def resolve():
    N = int(input())
    S = [input() for _ in range(N)]

    counter = collections.Counter(S)

    max_freq = max(counter.values())
    most_freq = [k for k, v in counter.items() if v==max_freq]
    for i in sorted(most_freq):
        print(i)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 35564
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1e17;
const int inf = 1e5;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
struct SegmentTree{
  int N;
  vector<int> node;
  public :
    void intit(vector<int>v){
      int sz = v.size();
      N=1;
      while(N<sz) N*=2;
      node.resize(N);
      for(int i=0 ; i<sz ; i++) node[i+N-1] = v[i];
      for(int i=N-2 ; i>=0 ; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }
    void update(int x, int val){
      x += N-1;
      node[x+N-1] = val;
      while(x>0){
        x = (x-1)/2;
        node[x] = min(node[x*2+1], node[x*2+2]);
      }
    }
    int getmin(int a, int b, int k, int l, int r){
      if(b<=l || r<=a) return inf;
      else if(a<=l && r<=b) return node[k];
      else{
        int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
      }
    }
};
vector<ll> divisor(ll n){
  vector<ll> res;
  for(ll i=1; i*i<=n ; i++){
    while(n%i==0){
      ++res[i];
      n /= i;
    }
  }
  if(n!=1) res[n]=1;
  return res;
}
int main(){
  int N;  cin>>N;
  vector<string> v(N);
  rep(i,0,N) cin>>v[i];
  int a=0,b=0,c=0,d=0;
  rep(i,0,N){
    if(v[i]=="AC") a++;
    else if(v[i]=="WA") b++;
    else if(v[i]=="TLE") c++;
    else d++;
  }
  cout<<"AC x "<<a<<endl;;
  cout<<"WA x "<<b<<endl;;
  cout<<"TLE x "<<c<<endl;;
  cout<<"RE x "<<d<<endl;;
  return 0;
}


Measured memory_bytes: 6420
#include <stdio.h>
int main(void){
    int n, k, q, p[100000+5];
    scanf("%d %d %d", &n, &k, &q);
    for(int i=0; i<n; i++)p[i]=k;
    for(int i=0; i<q; i++){
        int a;
        scanf("%d", &a);
        p[a-1]++;
    }
    for(int i=0; i<n; i++){
        if(p[i]-q>0)printf("Yes\n");
        else printf("No\n");
    }
}


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

int main()
{
    long long int n,w,i,j,k;
    cin>>n>>w;

    long long int a[n][2];

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

    long long int dp[100005][n];

    for(i=0;i<100005;i++)
        for(j=0;j<n;j++)
            dp[i][j]=-1;

    dp[0][0]=w;
    dp[a[0][1]][0]=w-a[0][0];

    for(i=1;i<n;i++)
    {
        for(j=0;j<100005;j++)
            if(dp[j][i-1]!=-1)
                dp[j][i]=max(dp[j][i],dp[j][i-1]);

        for(j=0;j<100005;j++)
            if(dp[j][i-1]!=-1&&dp[j][i-1]>=a[i][0])
                dp[j+a[i][1]][i]=max(dp[j+a[i][1]][i],dp[j][i-1]-a[i][0]);
    }

    for(i=100004;i>=0;i--)
        if(dp[i][n-1]!=-1)
    {
        cout<<i;
        return 0;
    }
}


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

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define LB lower_bound
#define UB upper_bound

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL INF = 1e9;
const LL MOD = 1e9+7;

//other
//-------------------------------------------
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define FI first
#define SE second

//memo
// setprecision()


LL Gcd(LL a, LL b) {
  if (a < b) {
    return Gcd(b,a);
  }
  if (b == 0) {
    return a;
  }
  else {
    return Gcd(b,a%b);
  }
}

LL Lcm(LL a, LL b) {
  LL abd = Gcd(a,b);
  LL x = a / abd, y = b / abd;
  
  return x*y*abd;
}

int main() {
  int N;
  string S, T, U;
  cin >> N >> S >> T;
  
  REP(i,N){
    U += S.at(i);
    U += T.at(i);
  }
  
  cout << U << endl;
  
  return 0;
}

Measured memory_bytes: 256
sx , sy , tx , ty = map(int , input().split())

ans = ""
ans2 = ""

for u in range(ty - sy):
    ans += "U"
for r in range(tx - sx):
    ans += "R"

ans2 = "LU" + ans + "RD"

print(ans + ans.translate(str.maketrans('UR', 'DL')) + ans2 + ans2.translate(str.maketrans('URDL', 'DLUR')))

Measured memory_bytes: 3188
#include<iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<stdlib.h>
#include<set>
using namespace std;
#define PI 3.14159265358979
#define rep(i,n) for(int i=0;i<n;i++)


int main(void)
{
int n;
cin>>n;
int ans =1;
vector<int> b(n+1);
set<int> pushed;
for(int i=1;i<=n;i++)
{
    int a;
    cin>>b[i];
}
int now =1;
pushed.insert(1);
while(true)
{
    now = b[now];
    
    if(now==2){
        cout<<ans<<endl;
        return 0;
    }

    auto r = pushed.insert(now);
    if(r.second) ans++;

    if(!r.second) break;

}


cout<<-1<<endl;

}






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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};



string s, t;

ll str_check(){
  ll maxcur = -1;
  ll n = s.size();
  REP(cur, n-t.size()+1){
    bool checkflag = true;
    REP(i, t.size()){
      if(s[cur+i] != t[i] && s[cur+i] != '?'){
        checkflag = false;
        continue;
      }
    }
    if(checkflag)
      maxcur = cur;
  }
  
  return maxcur;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  cin >> s >> t;
  ll maxcur = str_check();
  if(maxcur == -1)
    cout << "UNRESTORABLE";
  else{
    REP(i, s.size()){
      if(maxcur == i){
        cout << t;
        i += t.size()-1;
      }
      else if(s[i] == '?')
        cout << 'a';
      else
        cout << s[i];
    }
  }
  
}

Measured memory_bytes: 256
def main():
    N = int(input())
    S = input()
    left = [0] * (N+1)
    right = [0] * (N+1)
    tmp = 0
    for i in range(N):
        if S[i] == "W":
            tmp += 1
        left[i+1] = tmp
    tmp = 0
    for i in range(N-1, -1, -1):
        if S[i] == "E":
            tmp += 1
        right[i] = tmp
    ans = int(1e10)
    for i in range(N):
        ans = min(ans, left[i]+right[i+1])
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 17628
package main

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

const mod = 1000000007

// 1MB
const ioBufferSize = 1 * 1024 * 1024

var sc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	sc.Split(bufio.ScanWords)
	return sc
}()

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	n := nextInt()

	f, d := 0, 0
	for m := n; m > 0; m /= 10 {
		f = m
		d++
	}

	md := f
	for i := 1; i < d; i++ {
		md *= 10
		md += 9
	}

	if n == md {
		fmt.Println(f + (d-1)*9)
	} else {
		fmt.Println(f - 1 + (d-1)*9)
	}
}


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

const int MaxN = 100005;

int n;
int f[MaxN][3], val[MaxN][3];

void upd(int &a, int b) {
	if (b > a) a = b;
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++ i) {
		scanf("%d%d%d", &val[i][0], &val[i][1], &val[i][2]);
	}
	for (int i = 1; i <= n; ++ i) {
		for (int j = 0; j < 3; ++ j) {
			for (int k = 0; k < 3; ++ k) {
				if (j == k) continue;
				upd(f[i][j], f[i - 1][k] + val[i][j]);
			}
		}
	}
	int Ans = 0;
	for (int j = 0; j < 3; ++ j)
			upd(Ans, f[n][j]);
	printf("%d\n", Ans);
	return 0;
}

Measured memory_bytes: 2560
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		try (BufferedReader br = new BufferedReader(
				new InputStreamReader(System.in))) {

			String in = br.readLine();
			String chr[] = in.split(" ");
			int a = Integer.parseInt(chr[0]);
			int b = Integer.parseInt(chr[1]);

			System.out.println(a==b?"Draw"
							  :(a==1||(b!=1&&a>b))?"Alice"
							  :"Bob");
		}
	}
}


Measured memory_bytes: 25428
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#define ll long long
using namespace std;

int main(void){
    char a[5] = {'a','i','u','e','o'};
    char tmp;
    cin >> tmp;
    for(int i=0;i<5;i++){
        if(tmp == a[i]){
            cout << "vowel" << endl;
            return 0;
        }
    }
    cout << "consonant" << endl;

    
    return 0;
}

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

int main() {
    char ch;
    int counter[26] = {};
    while ( scanf("%c", &ch) != EOF) {
        if (isalpha(ch)) {
            counter[tolower(ch) - 'a']++;
        }
    }

    for (int i = 0; i < 26; i++) {
        printf("%c : %d\n", 'a' + i, counter[i]);
    }
}

Measured memory_bytes: 1140
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
int n, a[3], fs, sc;
bool f;
char s[2][3], ans[100005];
int main(){
	scanf("%d%d%d%d\n%s", &n, a, a+1, a+2, s[1]);
	if(a[s[1][0]-'A'] == 0 && a[s[1][1]-'A'] == 0) return 0 * puts("No");
	rep(i,n){
		if(i < n-1) scanf("%s", s[i&1]);
		fs = s[~i&1][0]-'A';
		sc = s[~i&1][1]-'A';
		if(a[fs] + a[sc] == 0) return 0 * puts("No");
		f = a[fs] > a[sc] || (a[fs] == a[sc] && ('A'+sc == s[i&1][0] || 'A'+sc == s[i&1][1]));
		ans[i] = s[~i&1][f];
		a[f ? sc : fs]++;
		a[f ? fs : sc]--;
	}
	puts("Yes");
	rep(i,n) printf("%c\n", ans[i]);
}

Measured memory_bytes: 3908
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  int cnt=0;
  int ans =0;
  int ansp=0;
  for(int i=1;i<n;i++){
    if(a[i-1]>=a[i]){
      ansp++;
      
    }else{
      if(ansp>ans){
        ans=ansp;}
      ansp=0;
    }
    if(i==n-1)ans=max(ans,ansp);
  }
  cout<<ans<<endl;
  return 0;
}

    
      


Measured memory_bytes: 640
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<set>
#include<map>
#include<queue>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);++i)
#define rrep(i,n) for(int (i)=(n)-1;(i)>=0;--i)
#define rep1(i,n) for(int (i)=1;(i)<=(n);++i)
#define rrep1(i,n) for(int (i)=(n);(i)>=1;--i)
#define pb push_back
#define fr first
#define sc second
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> DP;
typedef pair<long long,long long> LP;
typedef double db;
using namespace std;

ll N;
ll C[200000];
ll T[200000];
ll pos[200000];
ll dp[200000];

ll mod =1e9+7;
int main()
{
  cin>>N;
  rep(i, 200000){
    pos[i]=-1;
  }
  rep(i,N){
    cin>>C[i];
    C[i]--;
    T[i]=-1;
  }
  rep(i,N){
    if(pos[C[i]] != -1){
      T[pos[C[i]]] = i;
    }
    pos[C[i]] = i;
  }
  dp[0] = 1;
  rep(i, N){
    if(i>0){
      dp[i] = (dp[i] + dp[i-1])%mod;
    }
    if(T[i] != -1 && T[i] != i+1){
      dp[T[i]] = (dp[T[i]] + dp[i]) % mod;
    }
  }
  // rep(i,N){
  //   cout<<T[i]<<"a"<<endl;
  //   cout<<dp[i]<<"b"<<i<<endl;
  // }
  cout<<dp[N-1]<<endl;
}


Measured memory_bytes: 6528
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

pub trait InputValue {
    fn parse(s: &str) -> Self;
}

pub fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

pub fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);


// ===

fn main() {
    let (a, b, c): (i32, i32, i32) = read();

    println!("{}", max(a, max(b, c)) - min(a, min(b, c)));
}


Measured memory_bytes: 4352
#include <iostream>
#include <string.h>

using namespace std;

int main() {
	int array[5];
	cin >> array[0];
	cin >> array[1];
	cin >> array[2];
	cin >> array[3];
	cin >> array[4];

	int time = 0;
	int min = 0;
	int wait = 0;
	int tmp = 0;
	for (int j = 0; j < 4; j++) {
		min = array[j];
		wait = 10 - array[j] % 10;
		for (int i = j + 1; i < 5; i++) {
			if (10 - array[i] % 10 < wait || array[i] % 10 == 0) {
				if (array[i] % 10 == 0) {
					wait = 0;
				}
				else {
					wait = 10 - array[i] % 10;
				}
				min = array[i];
				tmp = array[j];//交換
				array[j] = array[i];
				array[i] = tmp;
			}
		}
		time += (min + wait);
	}
	time += array[4];
	cout << time << endl;
	
}

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

int main()
{
  int n;
  int a;
  int max=-1000000;
  int min=1000000;
  long long sum=0;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a;
    if(a>max)
      max=a;
    if(a<min)
      min=a;
    sum+=a;
  }
  cout<<min<<" "<<max<<" "<<sum<<endl;
  return 0;
}


Measured memory_bytes: 3116
#include<stdio.h>
int count=0;
int t;

void xq(long long num,bool flag3,bool flag5,bool flag7){
	if(num>t) return;
	else{
		if(flag3&&flag5&&flag7) count++;
		xq(num*10+3,1,flag5,flag7);
		xq(num*10+5,flag3,1,flag7);
		xq(num*10+7,flag3,flag5,1);
	}
}

int main(){
	scanf("%d",&t);
	xq(0,0,0,0);
	printf("%d",count);
	
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main()

{

	int x, y, mini, maxi, consegue=1;	scanf("%d%d", &x, &y);

	mini = 2*x; maxi= 4*x;

	if(y<mini || y>maxi || y%2!=0)

		consegue = 0;

	if(consegue)

		printf("Yes\n");

	else

		printf("No\n");

	return 0;

}

Measured memory_bytes: 1648
# coding: utf-8
def main():
    n, m = map(int, input().split())
    N = ['a']*n
    for i in range(m):
        s, c = map(int, input().split())
        if N[s-1] == 'a':
            N[s-1] = c
        elif N[s-1] != c:
            print(-1)
            quit()
    if n != 1 and N[0] == 0:
        print(-1)
        quit()
    elif n != 1 and N[0] == 'a':
        print(1,end="")
        for i in range(1,n):
            if N[i] == 'a':
                print(0,end="")
            else:
                print(N[i],end= "")
    else:
        for c in N:
            if c == 'a':
                print(0,end="")
            else:
                print(c,end="")

if __name__ == '__main__':
    main()

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

int main() { 
  int a, b;
  cin >> a >> b;
  cout << a * b << endl;
  return 0;
}

Measured memory_bytes: 3592