akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
 
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
 
typedef long long ll;
typedef pair<int, int> ii;
 
int main(){

	int d;
	while(cin >> d){
		ll ans = 0;
		for(int i = 0; i < 600; i+= d){
			ans += (i * i * d);
		}
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3064
#include<bits/stdc++.h>							
typedef long long ll;
#define pb push_back
#define mod 1000000007ll
const ll maxn = 9e18;
using namespace std;
const ll maxsize = 100000009;



void solve() {
	int n, k;
	cin >> n >> k;
	ll sum = 0;
	for(int i = 0; i < k; ++i) {
		int x;
		cin >> x;  
		sum += x;
		}
		if(sum < n) cout << "No" << endl;
		else cout << 	"Yes" << endl;
}


int main() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cout.precision(35);
	solve();
	return 0;
}
 
 
 


Measured memory_bytes: 3652
import sys
from heapq import heappop, heappush
N, M = map(int, sys.stdin.readline().split())
A = [[] for _ in [0]*M]
for line in sys.stdin:
    a, b = map(int, line.split())
    if a > M:
        continue
    A[M-a].append(b)

ans = 0
q = []
for i, B in enumerate(A):
    for b in B:
        heappush(q, b)
        ans += b
    while len(q) > i+1:
        b = heappop(q)
        ans -= b
print(ans)


Measured memory_bytes: 22500
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>

#define rep(i,j,k) for(int i=j;i<k;i++)
#define drep(n,m) for(int i=0;i<n;i++)for(int j=0;j<m;j++)
#define Sort(x) sort((x).begin(),(x).end())
#define fi first
#define se second
#define vi vector<int>
#define INF 1000000000
#define MOD 1000000009
#define pb push_back
#define mp make_pair
typedef long long ll;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

ll gcd(ll a,ll b){
    if(a<b){
        int t=a;a=b;b=t;
    }
    int c=a%b;
    while(c!=0){
        a=b;
        b=c;
        c=a%b;
    }
    return b;
}

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

bool isPrime(int x){
    if(x==1)return false;
    if(x==2)return true;
    if(x%2==0)return false;
    for(int i=3;i<=sqrt(x);i+=2){
        if(x%i==0)return false;
    }
    return true;
}

int kaizyo(int x){
    if(x==1)return x;
    else return x*kaizyo(x-1);
}


int main() {
    int n;
    vi ans;
    vi v;
    rep(i,0,10)v.pb(pow(2,i));
    
    while(cin>>n){
        for(int i=9;i>=0;i--){
            if(n>=v[i]){
                n-=v[i];
                ans.pb(v[i]);
            }
        }
    
        for(int i=ans.size()-1;i>=0;i--){
            if(i==0)cout<<ans[i];
            else cout<<ans[i]<<" ";
        }
        cout<<endl;
        ans.clear();
    }
  
    return 0;
}



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

using namespace std;

int main() {
  string s;
  unordered_map<string, int> cnt;
  vector<string> v;

  while (cin >> s) {
    cnt[s] += 1;
    v.push_back(s);
  }

  int max_freq = 0;
  int max_len = 0;

  for (auto p: cnt) {
    max_freq = max(max_freq, p.second);
    max_len = max(max_len, (int)p.first.size());
  }

  for (auto p: cnt) {
    if (p.second == max_freq) {
      cout << p.first << ' ';
    }
  }

  for (auto p: cnt) {
    if (p.first.size() == max_len) {
      cout << p.first << endl;
    }
  }
}



Measured memory_bytes: 3168
#include <bits/stdc++.h>
#define pi (double)acos(-1)
using namespace std;
set<long long> s;
vector<int> v;

void solve()
{
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    for(int i=0;i<n;++i)
    {
        if(i+1==k)
            cout<<(char)(s[i]-'A'+'a');
        else
            cout<<s[i];
    }
    return;
}
int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int t=1;
	//cin>>t;
	while(t--) {solve();}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int, int>
#define mii map<pii, int>
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define sz(x) (int)x.size()
#define endl '\n'
#define M 1000000007
#define rep(i, a, b) for (int i = a; i < b; i++)
using namespace std;

void solve() {
     ll a,b,c;
     cin>>a>>b>>c;
     ll x=c/a;
     cout<<b*x<<endl;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t=1;
  while (t--) {
     solve();
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const int INF = 2000000000;

    int N,K,ans=1;
int main(){
    ios_base::sync_with_stdio(false);
    cin>>N>>K;
    REP(i,N){
        ans+=min(ans,K);
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define per(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define INF 2e9
#define LINF 1e18
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int n, x; cin >> n >> x;
    vector<int> l(n);
    rep(i, n) cin >> l[i];

    int d = 0;
    int ans = 0;
    rep(i, n+1) {
        if (d <= x) ans++;
        d += l[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#define ll long long
#define fr(i,k,N) for(ll i=k; i<N;i++)
#define rep(i,N) for(ll i=0; i<N;i++)
#define ALL(v) v.begin(),v.end()
#define mp make_pair
using namespace std;
template <class X> void pr(X test){cout<<test<<endl;}
template <class X> void prr(X test){for(auto it:test){cout<<it<<endl;}}
template <class X> void prrr(X test){int f=0;for(auto it:test){cout<<(f++!=0?" ":"")<<it;}cout<<endl;}
template<typename X>
istream&operator>>(istream&i,vector<X>&v){for(X&x:v)i>>x;return i;}

class UF { // union find from https://github.com/kartikkukreja/blog-codes (MIT)
    // [usage]
    // auto uf = new UF(n);
    // uf->merge(l, r); // 0 <= l, r <= n-1
    // ...
public:
    int *id; // inner id
    int cnt; // number of all vartices
    int *sz; // sz[i] means size of i's set
    UF(int N)   {
        cnt = N;
        id = new int[N];
        sz = new int[N];
        for(int i=0; i<N; i++) {
            id[i] = i;
            sz[i] = 1;
        }
    }
    ~UF() {
        delete [] id;
        delete [] sz;
    }
    int find(int p) {
        int root = p;
        while (root != id[root]) root = id[root];
        while (p != root) {
            int newp = id[p];
            id[p] = root;
            p = newp;
        }
        return root;
    }
    void merge(int x, int y) {
        int i = find(x);
        int j = find(y);
        if (i == j) return;
        
        if (sz[i] < sz[j]) {
            id[i] = j;
            sz[j] += sz[i];
        } else {
            id[j] = i;
            sz[i] += sz[j];
        }
        cnt--;
    }
    bool connected(int x, int y) {
        return find(x) == find(y);
    }
    int count() {
        return cnt;
    }
};

// return sorted 約数list 1 <= x <= n
vector<ll> divv(ll n) {
  vector<ll> v;
  for(ll i = 1; i*i <= n; i++) {
    if(n%i == 0) {
      v.push_back(i);
      if(i*i != n) v.push_back(n/i);
    }
  }
  sort(ALL(v));
  return v;
}

int main() {
    ll s,ans=0;

    cin>>s;
    rep(i, s){
        ans += i;
    }
    pr(ans);
    
}


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

int main()
{
    int a[5];
    cin>>a[0]>>a[1]>>a[2];
    int m=0,n=0;
    for(int i=0;i<3;++i)
    {
        if(a[i]==5)
            m++;
        if(a[i]==7)
            n++;
    }
    if(m==2&&n==1)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
 
using namespace std;
typedef long long ll;
 
 
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
vector<ll> G[100005];
vector<P> tree[100010];
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
 
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,a,b) for(i=a;i<=b;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
 
ll rui(ll abc,ll bed){
	//aのb乗を計算する
	if(bed==0){return 1;}
	else{
		ll ced = rui(abc,bed/2);
		ced *= ced;
		ced %= mod;
		if(bed%2==1){ced*=abc; ced%=mod;}
		return ced;
	}
}

ll i,j,k,ii,jj;
ll n,m,sum,num;
ll ans=0;
ll a,b,c,d,e,h,w;
 
ll x[500005],y[500005],z[500005];
ll u[500005],v[500005];
char s[500005],t[500005];
bool ok=false;
bool check[100005];
 
int main(){
    cin>>s;
	n=strlen(s);
	for(i=0;i<n;i++){
		a = s[i]-'a';
		x[a]++;
	}
	for(i=0;i<5;i++){
		num = max(num,x[i]);
	}
	if(num>(n+2)/3){
		p("NO");
	}else{
		p("YES");
	}
	return 0;
}

Measured memory_bytes: 7168
#include <stdio.h>
int main(){
    int a;
    long b;
    long c;
    scanf("%d%ld",&a,&b);
    c = b / a;
    for(;c >= 1; c--){
        if(b % c == 0){
            printf("%ld\n",c);
            break;
        }
    }
    return 0;
}

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

const int mod = 1e9 + 7, maxn = 2010;
long long fac[maxn];

long long exp(int n, int p) {
  long long base = n, ans = 1;
  while (p) {
    if (p & 1) ans *= base, ans %= mod;
    base *= base;
    base %= mod;
    p >>= 1;
  }
  return ans;
}

long long C(int r, int n) {
  return fac[n] * exp(fac[n - r], mod - 2) % mod * exp(fac[r], mod - 2) % mod;
}

int main() {
  #ifdef LOCAL
  freopen("input.txt", "r", stdin);
  #endif
  ios::sync_with_stdio(false);
  int r, b;
  cin >> r >> b;
  r -= b;
  fac[0] = 1;
  for (int i = 1; i <= r + b; ++i) fac[i] = fac[i - 1] * i, fac[i] %= mod;
  for (int k = 1; k <= b; ++k) {
    if (k > r + 1) {
      cout << 0 << endl;
      continue;
    }
    cout << C(k, r + 1) * C(k - 1, b - 1) % mod << endl;
  }
  return 0;
}

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

using namespace std;
using ull = unsigned long long;
using ll = long long;
using lli = long long int;
using ld = long double;
using pa = pair<int, int>;
using ppa = pair<pa, int>;
#define SORT(v, n) sort(v, v + n);
#define ALL(v) v.begin(), v.end()
#define VSORT(v) sort(ALL(v))
#define GRESORT(v) sort(ALL(v), greater<ll>())
#define REVERSE(v) reverse(ALL(v))
#define overlap(v) v.erase(unique(ALL(v)), v.end())
#define debug(x) cout << #x << ": " << x << endl
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for (int i = (b - 1); i >= a; i--)
#define rrep(i, n) RFOR(i, 0, n)
#define INF INT_MAX
#define SUP INT_MIN
#define mins(a, b) a = min(a, b)
#define maxs(a, b) a = max(a, b)

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

// 8近傍
// int dy[]={0,0,1,-1,1,1,-1,-1};
// int dx[]={1,-1,0,0,1,-1,1,-1};

// const ll MOD = 1000000007;

ll pow_mod(ll a, ll b, ll mod) {
    ll tmp = 1;
    a %= mod;
    if (b > 0) {
        tmp = pow_mod(a, b / 2, mod);
        if (b % 2)
            tmp = (((tmp * tmp) % mod) * a) % mod;
        else
            tmp = (tmp * tmp) % mod;
    }
    return tmp;
}

void solve() {
    string s; cin >> s;
    int cnt = 0;
    int n = s.size();
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'S'){
            cnt++;
        }else{
            if(cnt > 0){
                cnt--;
                n -= 2;
            }
        }
    }
    cout << n << endl;
}

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

    solve();

    return 0;
}


Measured memory_bytes: 720
s = input()
K = int(input())

c = [ord(s1)-ord('a') for s1 in s]
sl = list(s)

for i in range(len(s)):
    if c[i] and 26-c[i] <= K:
        sl[i] = 'a'
        K -= 26-c[i]
sl[len(s)-1] = chr((ord(sl[len(s)-1]) - ord('a') + K) % 26 + ord('a'))

print(''.join(sl))

Measured memory_bytes: 55408
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <climits>

using namespace std;

const int maxN=307;

long long dp[maxN][maxN],s[maxN][maxN],c[maxN][maxN];

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

	for (int i=0;i<=n;i++) {
		c[i][0]=c[i][i]=1;
		for (int j=1;j<i;j++) c[i][j]=(c[i-1][j]+c[i-1][j-1])%m;
	}

	for (int i=0;i<=k;i++) dp[1][i]=1,s[1][i]=(k-i+1)%m;
	for (int i=2;i<=n+1;i++) 
		for (int j=k;j>=0;j--){
			for (int t=1;t<i;t++) dp[i][j]=(dp[i][j]+dp[i-t][j]*c[i-2][t-1]%m*s[t][j+1]%m)%m;
			s[i][j]=(s[i][j+1]+dp[i][j])%m;
		}

	printf("%lld\n",dp[n+1][0]);
	return 0;
}


Measured memory_bytes: 2432
use proconio::{fastout, input};
struct Prob {
    a: Vec<usize>,
    g: Vec<Vec<usize>>,
    ans: Vec<usize>,
    dp: Vec<usize>,
}

impl Prob {
    fn dfs<'a>(&'a mut self, pos: usize, par: usize, len: usize) {
        let mut lb = 0;
        let mut ub = len;
        while ub - lb > 1 {
            let mid = (lb + ub) / 2;
            let ok = self.dp[mid] < self.a[pos];
            if ok {
                lb = mid;
            } else {
                ub = mid;
            }
        }
        let j = lb + 1;
        let prev_dp_j = self.dp[j];
        let prev_len = len;
        self.dp[j] = self.dp[j].min(self.a[pos]);
        let len = len.max(j + 1);
        self.ans[pos] = len - 1;
        for j in 0..self.g[pos].len() {
            let k = self.g[pos][j];
            if k == par {
                continue;
            }
            self.dfs(k, pos, len);
        }
        self.dp[j] = prev_dp_j;
    }
}

#[fastout]
fn main() {
    input! {
        n: usize,
        a: [usize; n],
        e: [(usize, usize); n-1],
    }

    let mut g: Vec<Vec<usize>> = vec![vec![]; n];
    for (u, v) in e {
        g[u - 1].push(v - 1);
        g[v - 1].push(u - 1);
    }

    let mut p = Prob {
        a,
        g,
        dp: vec![usize::max_value(); n + 1],
        ans: vec![usize::max_value(); n + 1],
    };
    p.dp[0] = 0;
    p.dfs(0, n, 1);
    for i in 0..n {
        println!("{}", p.ans[i]);
    }
}


Measured memory_bytes: 38120
#include <stdio.h>

int main(){
  int h,i,A[250],j,pk,lk,rk;
  scanf("%d",&h);
  for (i = 1; i <= h;i++){
    scanf("%d",&A[i]);  
  }


  for (i = 1; i <= h; i++){
    printf("node %d: ",i);
    printf("key = %d, ",A[i]);
    pk = A[i/2];
    lk = A[2*i];
    rk = A[2*i+1];
  
    if(i != 1){
      printf("parent key = %d, ",pk);
    }   
    if(2*i <=  h){ 
      printf("left key = %d, ",lk);
    }
    if(2*i+1 <= h){     
      printf("right key = %d, ",rk);
    }
    printf("\n");
  }




  return 0;

}

Measured memory_bytes: 600
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<list>
#include<stack>
//#include<unordered_map>
using namespace std;
#define ll long long
#define dd cout<<endl
const long long int inf = 1e18+7;
const int mod = 998244353;

using namespace std;

inline ll int max(ll int a,ll int b) { return a>b?a:b; }
inline ll int min(ll int a,ll int b) { return a<b?a:b; }
inline ll int abs1(ll int a) { return a>0?a:-a; }

//const int maxn=

int main()
{
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	
	ll int x,k,d;
	
	while(cin>>x>>k>>d)
	{
		if(x<0)
			x=-x;
		
		ll int minn=inf;
		
		ll int cnt=x/d;
		
		x=x-cnt*d;
		
		if(cnt<=k)
		{
			ll int yu=k-cnt;
			
			if(yu&1)
			{
				minn=min(minn,abs1(x-d));
				minn=min(minn,abs1(x+d));
			}
			else
				minn=min(minn,x);
		}
		else
		{
			minn=min(minn,x+(cnt-k)*d);
		}
		
		ll int cnt1=cnt+1;
		
		ll int x1=(x-d);
		
		if(cnt1<=k)
		{
			ll int yu=k-cnt1;
			
			if(yu&1)
			{
				minn=min(minn,abs1(x1-d));
				minn=min(minn,abs1(x1+d));
			}
			else
				minn=min(minn,abs1(x1));
		}
		else
		{
			minn=min(minn,x1+(cnt1-k)*d);
		}
		
		cout<<minn<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 3600
//
#include <vector>
#include <set>
#include <map>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
constexpr double BIGP = 1000000007L;
constexpr double INF_I = std::numeric_limits<double>::max();
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
//
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ll A, B, C;
    cin >> A >> B >> C;
    yes((A + B)  >= C);
    return 0;
}


Measured memory_bytes: 3124
#pragma GCC optimize ("Ofast","unroll-loops")
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define MP make_pair
#define F first
#define S second
#define setpre(a) cout.precision(a),cout<<fixed;
#define ALL(a) a.begin(),a.end()
#define MEM(a,b) memset(a,b,sizeof a)
#define Tie ios::sync_with_stdio(0),cin.tie(0);
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

ll n, a[200100], ans;
priority_queue<ll> q;

int main() {Tie
    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> a[i];
    sort(a, a + n), q.push(a[n - 1]);
    for(int i = n - 2; i > -1; i--) {
        ans += q.top();
        q.pop();
        q.push(a[i]);
        q.push(a[i]);
    }
    cout << ans << '\n';
}


Measured memory_bytes: 6880
#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t a = 2;
  int64_t b = 1;
  int64_t c;
  int N;
  
  cin >> N;
  
  if(N==0)
    cout << 0 << endl;
  if(N==1)
    cout << 1 << endl;
  if(N > 1){
  for(int i=2; i<N+1; i++){
    c=a+b;
    a=b;
    b=c;
  }
  cout << c << endl;
}
}

Measured memory_bytes: 3632
import sys
from collections import deque
input = sys.stdin.readline


def main():
    h, w = map(int, input().split())
    ch, cw = map(int, input().split())
    dh, dw = map(int, input().split())
    
    s = [input().replace("\n", "") for _ in range(h)]
    
    ans = [[-1]*w for _ in range(h)]
    ans[ch-1][cw-1] = 0
    not_yet = deque([(ch-1, cw-1)])
    one_time = deque([])
    while not_yet:
        x, y = not_yet.popleft()
        one_time.append((x, y))
        if x > 0 and ans[x-1][y] == -1 and s[x-1][y] == ".":
            not_yet.append((x-1, y))
            ans[x-1][y] = ans[x][y]
        if x < h-1 and ans[x+1][y] == -1 and s[x+1][y] == ".":
            not_yet.append((x+1, y))
            ans[x+1][y] = ans[x][y]
        if y > 0 and ans[x][y-1] == -1 and s[x][y-1] == ".":
            not_yet.append((x, y-1))
            ans[x][y-1] = ans[x][y]
        if y < w-1 and ans[x][y+1] == -1 and s[x][y+1] == ".":
            not_yet.append((x, y+1))
            ans[x][y+1] = ans[x][y]
        if not not_yet:
            while one_time:
                x2, y2 = one_time.popleft()
                for i in range(max(0, x2-2), min(h, x2+3)):
                    for j in range(max(0, y2-2), min(w, y2+3)):
                        if ans[i][j] == -1 and s[i][j] == ".":
                            ans[i][j] = ans[x][y]+1
                            not_yet.append((i, j))

    print(ans[dh-1][dw-1])
            
            
            
        
    
    
    
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 96800
using System;

namespace AGC037
{
    class A
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            string temp = S[0].ToString();
            int res = 1;
            for (int i = 1; i < S.Length; i++)
            {
                if (temp.Length == 2)
                {
                    res++;
                    temp = S[i].ToString();
                }
                else
                {
                    if (temp != S[i].ToString())
                    {
                        res++;
                        temp = S[i].ToString();
                    }
                    else
                    {
                        if (i < S.Length - 1) { res++; temp = S.Substring(i, 2); }
                        else break;
                        i++;
                    }
                }
            }
            Console.WriteLine(res);
        }
    }
}


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

K = sum(A) / sum(range(1, N+1))
D = []
for i in range(-1,N-1):
    D.append(A[i+1] - A[i] - K )

for d in D:
    if not (d <= 0 and d % N == 0):
        print("NO")
        break
else:
    print("YES")


Measured memory_bytes: 14228
#include <bits/stdc++.h>
#define watch(x) cerr << (#x) << " is " << (x) << endl;
using namespace std;
const int MAXN = 200001;
const int INF = 1234567890;
const int MOD = (int)(1e9 + 7);
using ll = long long;
using pll = pair<ll, ll>; //numerator is always negative
using pii = pair<int, int>;

int zero;
ll a, b;

map<pll, pii> ratings;

template <typename T> int sgn(T val){
	return (T(0) < val) - (val < T(0));
}

ll modpow(int a, int x){
	ll ans = 1, n = a;
	while(x){
		if (x & 1){
			ans *= n; ans %= MOD;
		}
		n *= n; n %= MOD; x /= 2;
	}
	return ans;
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n; cin >> n;
	zero = 0;
	for (int i = 0; i < n; ++i){
		cin >> a >> b;
		if (a == 0 and b == 0){
			zero++;
		}
		else if (a == 0){
			ratings[{0, 1}].first++;
		}
		else if (b == 0){
			ratings[{0, 1}].second++;
		}
		else{
			int neg = sgn(a) * sgn(b);
			ll num = sgn(a) * a, denom = sgn(b) * b;
			ll g = gcd(num, denom);
			num /= g; denom /= g;
			num *= neg;
			pll f{num, denom}, r{-1 * neg * denom, abs(num)};
			if (ratings.count(r) == 0){
				ratings[f].first++;
			}
			else{
				ratings[r].second++;
			}
		}
	}
	ll ans = 1;
	for (auto data : ratings){
		int s = data.second.first;
		int t = data.second.second;
		ll part = (modpow(2, s) - 1) + (modpow(2, t) - 1) + 1;
		part %= MOD;
		ans *= part; ans %= MOD;
	}
	ans = ans - 1 + zero;
	if (ans < 0) ans += MOD;
	cout << ans % MOD << endl;
	return 0;
}


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

int main(){
	int n, m;
	int f[256];
	f['N'] = 0;
	f['E'] = 1;
	f['S'] = 2;
	f['W'] = 3;
	int dx[4] = {0,1,0,-1};
	int dy[4] = {1,0,-1,0};
	
	while( cin >> n , n ){
		int px = 10, py = 10, cnt=0;
		int s[21][21] = {0};
		
		for(int i=0 ; i < n ; i++ ){
			int x, y;
			cin >> x >> y;
			s[y][x] = 1;
		}

		if( s[py][px] == 1 ){
			cnt++;
			s[py][px] = 0;
		}
		
		cin >> m ;
		for(int i=0 ; i < m ; i++ ){
			string d;
			int l;
			cin >> d >> l;
			for(int k=0 ; k < l ; k++ ){
				px = px + dx[ f[d[0]] ];
				py = py + dy[ f[d[0]] ];
				if( s[py][px] == 1 ){
					cnt++;
					s[py][px] = 0;
				}
			}
		}
		if( cnt == n ){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
		}
	}
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  map<int, int64_t> m, p;
  for (int i = 0; i < n; i++) {
    m[i - a.at(i)]++;
    p[i + a.at(i)]++;
  }
  int64_t ans = 0;
  for (auto x: m) {
    ans += x.second * p[x.first];
  }
  cout << ans << endl;
}


Measured memory_bytes: 38368
import java.util.Scanner;

/**
 * Created by wild on 2016/07/23.
 */
public class Main {
    public static void main(String[] args) {
        //入力
        Scanner scan = new Scanner(System.in);
        String money = scan.next();

        int num = scan.nextInt();
        String[] hate = new String[num];
        for (int i = 0; i < hate.length; i++) {
            hate[i] = scan.next();
        }

        while (check(money, hate)){
            Integer tmp = Integer.parseInt(money);
            tmp++;
            money = tmp.toString();
        }
        System.out.println(money);
    }

    private static boolean check(String str, String[] nums){
        for (int i = 0; i < nums.length; i++){
            if (str.indexOf(nums[i]) != -1) return true;
        }
        return false;
    }
}

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

int n;
char event[8];

int main(){
  scanf("%d",&n);
  int point,outcnt;
  for(int i=0;i<n;i++){
    int base[3]={0};
    point=0;
    outcnt=0;
    while(outcnt<3){
      scanf(" %s",event);
      if(strcmp(event,"HIT")==0){
	if(base[2]==1){base[2]=0;point++;}
	if(base[1]==1){base[1]=0;base[2]=1;}
	if(base[0]==1){base[1]=1;}
	base[0]=1;
      }
      if(strcmp(event,"HOMERUN")==0){
	for(int i=2;i>=0;i--)if(base[i]==1){base[i]=0;point++;}
	point++;
      }
      if(strcmp(event,"OUT")==0)outcnt++;
    }
    printf("%d\n",point);
  }
}

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

int main()
{
  int n;

  while (cin >> n, n){
    cout << (int)(n / pow(5, 1)) + (int)(n / pow(5, 2)) + (int)(n / pow(5, 3)) + (int)(n / pow(5, 4)) + (int)(n / pow(5, 5)) + (int)(n / pow(5, 6)) << endl;
  }
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
const unsigned long long int num = pow(5, 12);

bool A[num];

int change(char c)
{
    if (c == 'A')
    {
        return 1;
    }
    else if (c == 'C')
    {
        return 2;
    }
    else if (c == 'G')
    {
        return 3;
    }
    else if (c == 'T')
    {
        return 4;
    }

    return -1;
}

void insert(char *s)
{
    unsigned long long int key = 0;
    int p = 1;

    for (int i = 0; i < strlen(s); i++)
    {
        key += p * change(s[i]);
        p *= 5;
    }

    /*h1=key%num;

  if(A[h1][0]=='\0'){
    strcpy(A[h1],s);
    return;
  }
  
  h2=1+key%(num-1);
  while(1){
    h=(h1+h2*i)%num;

    if(A[h][0]=='\0'){
      strcpy(A[h],s);
      break;
    }
    else i++;
  }*/
    A[key] = true;
}

bool find(char *str)
{
    unsigned long long int key = 0;

    int len = strlen(str);
    int p = 1;

    for (int i = 0; i < len; i++)
    {
        key += p * change(str[i]);
        p *= 5;
    }

    if (A[key] == true)
    {
        return true;
    }
    else
        return false;
}

int main()
{
    //高速化
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);

    char tmp[12];
    char str[14];
    int num;

    for (int i = 0; i < num; i++)
    {
        A[i] = false;
    }

    cin >> num;
    for (long long int i = 0; i < num; i++)
    {
        cin >> tmp >> str;
        if (strcmp(tmp, "insert") == 0)
        {
            insert(str);
        }
        else
        {
            if (find(str))
            {
                cout << "yes" << endl;
            }
            else
                cout << "no" << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 8316
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<numeric>
#include<iomanip>
using namespace std;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r) { return l.second < r.second; }
bool greaterPair(const ipair& l, const ipair& r) { return l.second > r.second; }
int main()
{
	int n, x; cin >> n >> x;
	vector<int>m(n);
	int sum = 0;
	int ans = n;
	for (int i = 0; i < n; i++) {
		cin >> m[i];
		sum += m[i];
	}
	sum = x - sum;
	sort(m.begin(), m.end());
	while (1) {
		if (sum - m[0] >= 0) {
			ans++;
			sum = sum - m[0];
		}
		else {
			cout << ans << endl;
			break;
		}

	}

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint INF = 1e18;
typedef pair<lint, lint> P;

signed main(){
	lint N, M; cin >> N >> M;
	vector<vector<lint> > G(N);
	for(lint i = 0; i < M; i++){
		lint u, v; cin >> u >> v; --u; --v;
		G[u].push_back(v); 
	}
	lint s, t; cin >> s >> t; --s; --t;
	vector<vector<lint> > dist(N, vector<lint> (3, INF));
	queue<P> que;
	que.push(P(s, 0)); dist[s][0] = 0;

	while(que.size()){
		P p = que.front(); que.pop();
		lint now = p.first, num = p.second;
		for(auto next : G[now]){
			lint num_next = (num + 1) % 3;
			if(dist[next][num_next] == INF){
				dist[next][num_next] = dist[now][num] + 1;
				que.push(P(next, num_next));
			}
		}
	}

	lint ans = dist[t][0];
	if(ans == INF) cout << -1 << endl;
	else cout << ans/3 << endl;
}

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

using namespace std;
typedef long long ll;
const int N = 101 , W=1e5+1;
ll dp[N][W];
ll v[N] , w[N];
ll  n , cap;
ll rec( int i , ll rem)
{
    if(i>n)
    {
        return 0;
    }
    ll &ret=dp[i][rem];
    if(ret!=-1)
    {
        return ret;
    }
    ret=max(ret , rec(i+1 , rem));
    if(w[i]<=rem)
    {
        ret=max(ret , rec(i+1,rem-w[i])+v[i] );
    }
    return ret;
}
int main()
{
    cin>> n >> cap ;
    memset(dp , -1 , sizeof dp);
    for(int i = 1 ; i <=n ; i++)
    {
        cin >> w[i] >> v[i];
    }
    cout << rec(1, cap );
    return 0;
}


Measured memory_bytes: 82504
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
int mod = 998244353;
// int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b; if (a >= mod) a -= mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(11);
  int T;
  T = 1;
  while (T--) solve();
}

void solve() {
  int n;
  cin >> n;
  map<string, int> mp;
  rep(i, n) {
    string s;
    cin >> s;
    sort(all(s));
    mp[s]++;
  }
  ll ans = 0;
  for (auto e : mp) ans += 1LL * e.S * (e.S - 1) / 2;
  cout << ans << endl;
}


Measured memory_bytes: 11264
H, W, A, B = map(int, input().split())
M = 10 ** 5 + 5
M *= 2
fact = [0] * M
rfact = [0] * M
fact[0] = 1
MOD = 10 ** 9 + 7
for i in range(1, M):
    fact[i] = fact[i - 1] * i % MOD

rfact[M - 1] = pow(fact[M - 1], MOD - 2, MOD)
for i in range(M - 2, -1, -1):
    rfact[i] = rfact[i + 1] * (i + 1) % MOD


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


num = 0
for i in range(B + 1, W + 1):
    num += comb(H - (A + 1) + i - 1, i - 1) * comb(W - i + A - 1, A - 1)
    num %= MOD

print(num)

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

int main() {
    vector<bool> dp(A_MAX+1,true);
    int n;
    cin >> n;
    vector<int> a;
    int an;
    rep(i,n) {
        cin >> an;
        a.push_back(an);
    }
    sort(a.begin(), a.end());

    int S = a.size();
    int cnt = 0;
    rep(i,S) {
        int ai = a.at(i);
        if(dp.at(ai)) {
            int x = ai;
            while(x <= A_MAX) {
                dp.at(x) = false;
                x += ai;
            }
            if(i == 0 || (i > 0 && ai != a.at(i-1))) {
                if(i == S-1 || (i < S-1 && ai != a.at(i+1))) {
                    cnt++;
                }
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 4416
#include <stdio.h>
 
int main(){
    int g[12] = {1,3,1,2,1,2,1,1,2,1,2,1};
    int a, b;
    scanf("%d%d", &a, &b);
    printf(g[a-1] == g[b-1] ? "Yes\n" : "No");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <functional>
#include <queue>
#include <utility>
using namespace std;
typedef long long ll;
int main(){
  int A,B;
  cin >> A >> B;
  cout << max(A - 2 * B,0) << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
main(){
  int n,a[3],m,i,j,tmp;

  scanf("%d",&n);

  for(m=0;m<n;m++){

    for(i=0;i<3;i++){
      scanf("%d",&a[i]);
    }
    
    for(i=0;i<3;i++){
      for(j=3;j>i;j--){
	if(a[j]<a[j-1]){
	  tmp=a[j];
	  a[j]=a[j-1];
	  a[j-1]=tmp;
	}
      }
    }
    
    if((a[2]*a[2]) == (a[0]*a[0] + a[1]*a[1])){
      printf("YES\n");}
    
    else printf("NO\n");
    
  }
  return 0;
}

Measured memory_bytes: 580
import java.util.Scanner;
import java.util.Arrays;
class UnionFind{
    int n;
    int[] data;

    UnionFind(int _n){
        n = _n;
        data = new int[n];
        Arrays.fill(data,-1);
    }

    int parent(int u){
        return (data[u] < 0 ? u:(data[u] = parent(data[u])));
    }

    boolean unite(int u, int v){
        u = parent(u);
        v = parent(v);
        if(u==v)return false;
        if(-data[u] < -data[v]){
            int w = u;
            u = v;
            v = w;
        }
        data[u] += data[v];
        data[v] = u;
        return true;
    }

    boolean isSame(int u, int v){
        return parent(u) == parent(v);
    }

    int tsize(int u){
        return -data[parent(u)];
    }
}

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int M = scan.nextInt();

        UnionFind uf = new UnionFind(N);
        for(int i = 0;i<M;++i){
            int a = scan.nextInt() -1;
            int b = scan.nextInt() -1;
            uf.unite(a, b);
        }

        int m1 = Math.min(uf.tsize(0),uf.tsize(1));
        int m2 = N - m1;

        long ans = (long)m1*(m1-1)/2 +(long)m2*(m2-1)/2;
        System.out.println(ans - M);

    }
}

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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int a, b, c, d;
cin >> a >> b >> c >> d;
int left = max(a, c);
int right = min(b,d);
int ans = right-left;
ans = ans > 0 ? ans : 0;
cout << ans << endl;
return 0;
}

Measured memory_bytes: 256
MAP = {
  1 => 2,
  2 => 5,
  3 => 5,
  4 => 4,
  5 => 5,
  6 => 6,
  7 => 3,
  8 => 7,
  9 => 6,
}


def match_matching(n, nums)
  dp = Array.new(n + 10) { nil }
  dp[0] = 0
  n.times do |i|
    nums.each do |num|
      next unless dp[i]
      dp[i + MAP[num]] = [dp[i + MAP[num]].to_i, dp[i] * 10 + num].max
    end
  end
  dp[n]
end

n, m = gets.split.map(&:to_i)
nums = gets.split.map(&:to_i)

puts match_matching(n, nums.sort)

Measured memory_bytes: 29052
N,M,X=map(int,input().split())
L=[]
ans=[0]*(M+1)
A=float("inf")
for i in range(N):
	L.append(list(map(int,input().split())))
for i in range(N):
	for j in range(1,M+1):
		ans[j]+=L[i][j]
if min(ans[1:M+1])<X:
	print(-1)
	exit()
for i in range(1,2**N+1):
	ans=[0]*(M+1)
	i+=8192
	for j in range(N):
		if ((i>>j)&1):
			for k in range(M+1):
				ans[k]+=L[j][k]
	if min(ans[1:M+1])>=X:
		A=min(ans[0],A)
print(A)

Measured memory_bytes: 9240
X,Y=sorted(list(map(int,input().split())))
#移動方法を(i+1,j),(i,j+1)となるようにどうにかする
if (X-abs(Y-X))%3!=0 or X*2<Y:
  print(0)
  exit(0)
n=(X-abs(Y-X))//3
X=n+abs(Y-X)
Y=n

  
mod=10**9+7
a=1
for i in range(1,X+Y+1):
  a*=i
  a%=mod
b=1
for i in range(1,X+1):
  b*=i
  b%=mod
c=1
for i in range(1,Y+1):
  c*=i
  c%=mod

print(a*pow(b,-1,mod)*pow(c,-1,mod)%mod)


Measured memory_bytes: 9136
#include <cstdio>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <climits>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <deque>
#include <vector>
#include <string>
#include <bitset>
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define INF 1000000007
#define PI acos(-1.0)
#define endl "\n"
#define IOS cin.tie(0);ios::sync_with_stdio(false)
#define MP_ make_pair
#define PB_ push_back
#define FIR first
#define SEC second
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP_R(i,n) for(int i=((int)(n)-1);i>=0;--i)
#define FOR(i,m,n) for(int i=((int)(m));i<(int)(n);++i)
#define FOR_R(i,m,n) for(int i=((int)(m)-1);i>=(int)(n);--i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define SIZ(x) ((int)(x).size())
typedef long long int lli;
using namespace std;
int c2i(char c){switch(c){case '0' : return 0;case '1': return 1;case '2': return 2;case '3': return 3;case '4': return 4;case '5': return 5;case '6': return 6; case '7': return 7;case '8': return 8;case '9': return 9;default : return -1;}}



int digiS(int n)
{
  int cnt = 0;
  int m = n;
  string S = to_string(m);
  
  REP(i,SIZ(S))
    {
      cnt += c2i(S[i]);
      
    }
  return cnt;
  
  
}

int main()
{
  IOS; /* making cin faster */
  int N;
  cin >> N;

  int b;
  int mn = INF;
  
  FOR(a,1,N)
    {
      b = N - a;

      if( digiS(a) + digiS(b) < mn )
	{
	  mn = digiS(a) + digiS(b);
	  
	}
      
    }

  
  cout << mn << endl;
  

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
ll gcd(ll a , ll b)
{
    return b > 0 ? gcd(b , a % b) : a ;
}
int main()
{
	ll a , b , ans ;
	scanf("%lld%lld" , &a , &b) ;
	ans = a * b / gcd(a , b) ;
	printf("%lld\n" , ans) ;
	return 0 ;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <functional>
#include <utility>
#include <queue>
#include <vector>
#include <string>
#include <stack>
#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;
typedef long long int ll;
const ll  MOD = 1000000007;
typedef pair<ll,ll> P;
const ll INF = 100100100100100100;

ll N,M;
int main(){
  cin >> N >> M;
  if(abs(N-M) >= 2){
    cout << "0" << endl;
    return 0;
  }
  ll ans = 0;
  ll tmp = 1;
  rep(i,N){
    tmp = (tmp * (i+1)) % MOD;
  }
  ans = tmp;
  tmp = 1;
  rep(i,M){
    tmp = (tmp * (i+1)) % MOD;
  }
  ans = (ans * tmp) % MOD;
  if(N==M) ans = (ans *2) % MOD;
  cout << ans << endl;
}


Measured memory_bytes: 384
-- AtCoder My Practice
-- author: Leonardone @ NEETSDKASU

main = getLine
   >>= print
     . (\xs@(h:t) ->
           let len = length xs
           in if len < 2
               then read xs
               else 9 * (len - 1) + read [h]
                  - if all (== '9') t
                     then 0
                     else 1
       )

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

long long powermod(long long power,long long base) {
  long long n = 1;
  for (long long i = 0; i < power; i++) {
    n *= base;
    n %= 1000000007;
  }
  return n;
}

int main() {
  long long N;
  cin >> N;
  if (N > 1) {
    long long ans;
    ans = powermod(N, 10) - 2 * powermod(N, 9) + powermod(N, 8);
    ans %= 1000000007;
    ans = (ans + 1000000007) % 1000000007;
    cout << ans;
  }
  else cout << 0;
}


Measured memory_bytes: 3536
n=int(input())
s=list(map(int,input().split()))
count=0


for i in range(0,len(s)):
    index_1=i+1
    if(int(s[i])%2 != 0):
        if(int((index_1))% 2 != 0 ):
            count+=1
        else:
            count+=0
    else:
        count+=0

print(count)
    

Measured memory_bytes: 9180
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;
const long double EPS = 1e-10;

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

  vector<int> c(n);
  rep(i, n) c[--a[i]]++;

  vector<ll> d(n);
  rep(i, n) d[c[i]]++;

  vector<int> f(n + 1);
  f[0] = INF;
  ll sum = 0, psum = n;
  FOR(i, 1, n + 1) {
    psum -= d[i - 1];
    sum += psum;
    f[i] = sum / i;
  }

  vector<int> ans(n + 1);
  int idx = n;
  FOR(i, 1, n + 1) {
    while (i > f[idx]) {
      idx--;
    }
    ans[i] = idx;
  }
  FOR(i, 1, n + 1) cout << ans[i] << endl;






  
  return 0;
}

Measured memory_bytes: 7936
#include<iostream>

using namespace std;

int main() {

	int store[50];
	int pos;
	int move;

	int cnum;
	int snum;

	int stop = 0;
	for (;;) {
		cin >> cnum >> snum;

		if ( cnum == 0 ) break;

		pos = 0;
		move = snum;
		for ( int i=0; i<cnum; i++ ) {
			store[i] =0;
		}

		for ( int i=0;;i++) {
			if ( move > 0 ) {
				// More Fast
				/*
				for ( int j=0; j<move; j++ ) {
				store[(i+j)%cnum]++;
				}
				i+=move-1;
				move = 0;
				*/
				store[i%cnum]++;
				move--;
			}
			else {
				if ( store[i%cnum] == snum ) {
					pos = i % cnum;
					break;
				} else {
					move = store[i%cnum];
					store[i%cnum] = 0;
				}
			}
		}
		cout << pos << endl;
	}
}

Measured memory_bytes: 864
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)

int main(void){
	string s; cin >> s;
	string ans;
	int n = s.size();

	rep(i, n){
		if(s[i] == '0') ans += '0';
		else if(s[i] == '1') ans += '1';
		else if(s[i] == 'B'){
			ans.pop_back();
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <random>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
#include <cstdint>
using namespace std;
using LL = long long;

LL dp[234567][3];

int main() {
	int N;
	cin >> N;
	vector<LL>A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	memset(dp, 0x88, sizeof(dp));
	dp[1][0] = A[0];
	dp[2][1] = A[1];
	dp[3][2] = A[2];
	dp[3][0] = A[0] + A[2];
	for (int i = 4; i <= N; ++i) {
		for (int d = 0; d < 3; ++d) {
			for (int x = 0; x <= d; ++x) {
				dp[i][d] = max(dp[i][d], dp[i - 2 - (d - x)][x] + A[i - 1]);
			}
		}
	}
	if (N % 2) {
		LL ans = max(dp[N - 2][0], max(dp[N - 1][1], dp[N][2]));
		cout << ans << endl;
	}
	else {
		LL ans = max(dp[N - 1][0], dp[N][1]);
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 10336
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
	S = deque(SI())
	T = deque(SI())
	for i in range(len(S)):
		S.rotate(1)
		if T == S:
			print('Yes')
			exit()
	print('No')



if __name__ == "__main__":
	main()

Measured memory_bytes: 3316
#if 0
date

假设最终答案为 x ，那么其他的数其实可以分为三种：x ，小于 x 和大于 x 。
只需要关注与 x 的大小，把小于 x 的全设为 -INF ，大于 x 的全设为 INF ，得出的结果一定仍是 x 。

但这仍然难以处理，考虑枚举一个值 x ，把所有数分为两种：小于等于 x (0) 和大于 x (1) 。
如此将原数列转换为 01 串，若最后剩下的是 0 ，那么答案一定小于 x ，否则答案一定大于 x 。
那么 x 的值可以二分，接下来问题转换为 01 串上求最后剩下的数。

首先，如果两个相等的值相邻，那么在之后的操作中这两个位置的值始终不变。
那么如果中间的值 a[mid] 与 a[mid - 1] 或 a[mid + 1] 相等，即中间的值是 xx?  或 ?xx 形式，最后的结果一定是 a[mid] ，即 x。
否则 a[mid - 1] 到 a[mid + 1] 一定是 xyx 形式。
那么考虑 a[mid - 2] 到 a[mid + 2] ，若为 xxyx? 形式，一次操作后转换为 xx? 形式，最后结果一定是 x 。
?xyxx 形式同理，否则一定是 xyxyx 形式。

以此类推，从中间向两边找到第一个相邻且相等的 a[i] = a[i + 1] ，那么 a[i] 即最后的结果。
如果不存在此 a[i] ，那么就是 0101...01010 的形式，最终结果是 a[n] 。
#endif
#include <cstdio>
#include <algorithm>
#include <climits>
#define debug(...) fprintf(stderr, __VA_ARGS__)

inline int input() {
	int c = getchar(), x = 0;
	while(c < '0' or c > '9') c = getchar();
	while(c >= '0' and c <= '9') x = x * 10 + c - '0', c = getchar();
	return x;
}

const int maxn = 200005;
int a[maxn];
bool b[maxn];

bool check(int x, int n) {
	// debug("check %d\n", x);
	for(int i = 1; i <= n; i++)
		b[i] = a[i] > x;
	int mid = (1 + n) >> 1;
	for(int i = 0; i < mid; i ++) {
		if(b[mid + i] == b[mid + i + 1])
			return b[mid + i];
		if(b[mid - i] == b[mid - i - 1])
			return b[mid - i];
	}
	return b[n];
}

int main() {
	int n = input() * 2 - 1, min = INT_MAX, max = 0;
	for(int i = 1;  i <= n; i ++) {
		a[i] = input();
		min = std::min(a[i], min);
		max = std::max(a[i], max);
	}
	int l = min, r = max;
	while(l < r) {
		int mid = (l + r) >> 1;
		if(check(mid, n))
			l = mid + 1;
		else
			r = mid;
	}
	printf("%d\n", l);
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf=0x7fffffff;
#define mp(a,b) make_pair(a,b)
const int N=1111;
string s;
int main(){
	cin>>s;
	if(s[s.length()-1]=='s')s+="es";
	else s+="s";
	cout<<s;
	return 0;
}


Measured memory_bytes: 3616