akhauriyash/Code-Regression huggingface dataset:
h,w,k=map(int,input().split())
s=[list(input())for _ in range(h)]
g=1
for i in range(h):
    for j in range(w):
        if s[i][j]!='#':continue
        s[i][j]=g
        k=j-1
        while k>=0 and s[i][k]=='.':
            s[i][k]=g
            k-=1
        k=j+1
        while k<w and s[i][k]=='.':
            s[i][k]=g
            k+=1
        g+=1
for i in range(h-2,-1,-1):
    if s[i][0]=='.':
        for j in range(w):
            s[i][j]=s[i+1][j]
for i in range(h):
    if s[i][0]=='.':
        for j in range(w):
            s[i][j]=s[i-1][j]
for t in s:
    print(*t)


Measured memory_bytes: 50908
read a b
x=$[a+b]
y=$[a-b]
z=$[a*b]
if [ "$x" -ge "$y" -a "$x" -ge "$z" ]
then
	echo $x
elif [ "$y" -ge "$x" -a "$y" -ge "$z" ]
then
	echo $y
else
	echo $z
fi


Measured memory_bytes: 376
#include<stdio.h>

int abs(int a,int b);

int main(){
    int n,i,j,suma,sumb;
    unsigned int min = -1;
    int w[100]={0};
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&w[i]);
    }
    for(i=1;i<n;i++){
        suma = 0;
        sumb = 0;
        for(j=0;j<i;j++){
            suma += w[j];
        }
        for(;j<n;j++){
            sumb += w[j];
        }
        if(min > abs(suma,sumb)){
            min = abs(suma,sumb);
        }
    }
    printf("%d",min);

    return 0;
}

int abs(int a,int b){
    if(a > b){
        return a-b;
    }
    return b-a;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n, t;
    cin >> n >> t;
    int odp = 100000;
    for (int i = 0; i < n; ++i)
    {
        int cost, czas;
        cin >> cost >> czas;
        if (czas <= t)
            odp = min(odp, cost);
    }
    if (odp == 100000)
        cout << "TLE";
    else
        cout << odp;
    return 0;
}


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

#ifdef LOCAL
#define debug(var) cerr << #var << " = " << var << endl;
#else
#define debug(var)
#endif

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

void solve() {
	char a, b, c, d; scanf(" %c%c%c%c", &a, &b, &c, &d);
	a -= '0'; b -= '0'; c -= '0'; d -= '0';
	for (int i = -1; i < 2; i+=2) {
		for (int j = -1; j < 2; j+=2) {
			for (int k = -1; k < 2; k+=2) {
				if (a+i*b+j*c+k*d != 7) continue;
				printf("%d%+d%+d%+d=7", a, i*b, j*c, k*d);
				return;
			}
		}
	}
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


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

#define int long long
#define pii pair<int, int>
#define pb push_back
#define vi vector<int>

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    string s,t ;
    cin >> s >> t;
    t.pop_back();
    if(s == t) {
        cout << "Yes";
    }
    else cout << "No";

    return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define ll long long
int main(){
    string s;
    cin >> s;
    rep(i,s.size()){
        cout << 'x';
    }
    cout << endl;
    return 0;
}

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

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

        vector<int> v(N, 0);
        vector<int> c(N, 0);

        for(int i = 0; i < N; i++) cin >> v[i];
        for(int i = 0; i < N; i++) cin >> c[i];

        int sum = 0;
        for(int i = 0; i < N; i++)
        {
                int a = v[i] - c[i];
                if(a > 0) sum += a;
        }

        cout << sum << endl;

        return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define REP(i,n)   for (int i = 0; i < (n); ++i)
#define SORT(a)    sort((a).begin(), (a).end());
#define UNIQ(a)    SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end());
#define FIND(a,x)  find((a).begin(), (a).end(), (x)) != (a).end()
#define REVERSE(a) reverse((a).begin(), (a).end());

using namespace std;
using ll = long long;
using P = pair<int,int>;

const int MOD = 1000000007; // 10^9 + 7

int a[3][3] = {};

bool check() {
  bool f = true;
  for (int i = 0; i < 3; i++) {
    f = true;
    for (int j = 0; j < 3; j++)
      f &= a[i][j] == 0;
    if (f) return true;
  }

  for (int i = 0; i < 3; i++) {
    f = true;
    for (int j = 0; j < 3; j++)
      f &= a[j][i] == 0;
    if (f) return true;
  }

  f = true;
  for (int i = 0; i < 3; i++) {
    f &= a[i][i] == 0;
  }
  if (f) return true;

  f = true;
  for (int i = 2; i >= 0; i--) {
    f &= a[i][3 - i - 1] == 0;
  }
  if (f) return true;

  return false;
}

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

  REP(i, 3)REP(j, 3) cin >> a[i][j];
  int n; cin >> n;
  REP(i, n) {
    int b; cin >> b;
    REP(j, 3)REP(k, 3) {
      if (a[j][k] == b) {
        a[j][k] = 0;
      }
    }
  }

  cout << (check() ? "Yes" : "No") << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1 << 21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

// abc129d
int main(){
    int h, w;
    cin >> h >> w;
    char s[h][w];
    rep(i, h)rep(j, w) cin >> s[i][j];
    int ss[h][w], sh[h][w];
    int ans = 0;
    rep(i, h){
        rep(j, w){
            if (s[i][j]=='#') ss[i][j] = 0;
            else if (j==0) ss[i][j] = 1;
            else ss[i][j] = ss[i][j-1] + 1;
        }
        for(int j=w-1; j>=0; j--){
            if (s[i][j]=='#') continue;
            if (j==w-1) ss[i][j] = ss[i][j];
            else ss[i][j] = max(ss[i][j+1], ss[i][j]);
        }
    }

    rep(j, w){
        rep(i, h){
            if (s[i][j]=='#') sh[i][j] = 0;
            else if (i==0) sh[i][j] = 1;
            else sh[i][j] = sh[i-1][j] + 1;
        }
        for(int i=h-1; i>=0; i--){
            if (s[i][j]=='#') continue;
            if (i==h-1) sh[i][j] = sh[i][j];
            else sh[i][j] = max(sh[i][j], sh[i+1][j]);
        }
    }
    rep(i,h){
        rep(j,w){
            chmax(ans, ss[i][j]+sh[i][j]-1);
        }
    }

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


Measured memory_bytes: 35456
S = input()

MM = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12']

if S[0:2] in MM and S[2:4] in MM:
  print('AMBIGUOUS')
elif S[0:2] in MM:
  print('MMYY')
elif S[2:4] in MM:
  print('YYMM')
else:
  print('NA')


Measured memory_bytes: 2940
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<bitset>
#include<set>
#define N (410)
#define P ()
#define M ()
#define inf (0x7f7f7f7f)
#define rg register int
#define Label puts("NAIVE")
#define spa print(' ')
#define ent print('\n')
#define rand() (((rand())<<(15))^(rand()))
#define file(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
typedef long double ld;
typedef long long LL;
typedef unsigned long long ull;
using namespace std;
namespace fastIO1{
	inline char read(){
		static const int IN_LEN=1000000;
		static char buf[IN_LEN],*s,*t;
		return (s==t?t=(s=buf)+fread(buf,1,IN_LEN,stdin),(s==t?-1:*s++):*s++);
	}
	template<class T>
	inline void read(T &x){
		static bool iosig;
		static char c;
		for(iosig=false,c=read();!isdigit(c);c=read()){
			if(c=='-')iosig=true;
			if(c==-1)return;
		}
		for(x=0;isdigit(c);c=read())x=((x+(x<<2))<<1)+(c^'0');
		if(iosig)x=-x;
	}
	inline char readc(char &c){
		for(c=read();!isalpha(c)&&!isdigit(c);c=read())
		if(c==-1)return 0;
	}
	const int OUT_LEN = 10000000;
	char obuf[OUT_LEN],*ooh=obuf;
	inline void print(char c) {
		if(ooh==obuf+OUT_LEN)fwrite(obuf,1,OUT_LEN,stdout),ooh=obuf;
		*ooh++=c;
	}
	template<class T>
	inline void print(T x){
		static int buf[30],cnt;
		if(x==0)print('0');
		else{
			if(x<0)print('-'),x=-x;
			for(cnt=0;x;x/=10)buf[++cnt]=x%10+48;
			while(cnt)print((char)buf[cnt--]);
		}
	}
	inline void flush(){fwrite(obuf,1,ooh-obuf,stdout);}
}
namespace fastIO2{
	template<class T>
	inline void read(T &x){
		static bool iosig;
		static char c;
		for(iosig=false,c=getchar();!isdigit(c);c=getchar()){
			if(c=='-')iosig=true;
			if(c==-1)return;
		}
		for(x=0;isdigit(c);c=getchar())x=((x+(x<<2))<<1)+(c^'0');
		if(iosig)x=-x;
	}
}
using namespace fastIO1;
int n,m,a[N*N],b[N*N],ans;
bitset<410> s[N]; bool gg[N];
int main(){
	read(n),read(m);
	for(int i=1;i<=m;i++)read(a[i]),read(b[i]);
	for(int i=1;i<=n;i++){
		s[i][i]=1;
		for(int j=m;j;j--)
		if(s[i][a[j]]&&s[i][b[j]]){gg[i]=1;break;}
		else if(s[i][a[j]])s[i][b[j]]=1;
		else if(s[i][b[j]])s[i][a[j]]=1;
	}
	for(int i=1;i<=n;i++)
	for(int j=i+1;j<=n;j++)
	if(!gg[i]&&!gg[j]&&(s[i]&s[j]).none())ans++;
	cout<<ans;
}

Measured memory_bytes: 1792
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;
int n,a,b;
string s;
int main(){
  cin>>n>>a>>b>>s;

  int dom=0,abr=0;
  REP(i,n){
    if(s[i]=='a' && dom+abr<a+b){
      puts("Yes");
      ++dom;
    }else if(s[i]=='b' && dom+abr<a+b && abr<b){
      puts("Yes");
      ++abr;
    }else puts("No");
  }
  return 0;
}





Measured memory_bytes: 896
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>
#include <random>
#include <list>
#include <numeric>


#define rep(p,q) for(int i = p;i < q;i++)
#define ll long long

using namespace std;

//D
int main(void) {
	int n;
	cin >> n;
	vector<vector<int>> v = vector<vector<int>>(n);
	rep(0, n-1) {
		int a, b;
		cin >> a >> b;
		v[a - 1].push_back(b - 1);
		v[b - 1].push_back(a - 1);
	}
	vector<int> c = vector<int>(n);
	rep(0, n)cin >> c[i];
	sort(c.rbegin(), c.rend());
	queue<int> q = queue<int>();
	q.push(0);
	vector<int> ans = vector<int>(n);
	vector<int> visited = vector<int>(n);
	iota(visited.begin(), visited.end(), 0);
	for (auto value : c) {
		int pos = q.front();
		q.pop();
		for (auto newV : v[pos]) {
			if(visited[newV] == newV)
			q.push(newV);
		}
		ans[pos] = value;
		visited[pos] = -1;
	}
	ll sum = 0;
	rep(1, n)sum += c[i];
	cout << sum << endl;
	rep(0, n-1)cout << ans[i] << " ";
	cout << ans[n - 1] << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
struct unionfind{
  int par[200010]; // 親ノード  必要に応じて要素数を変えよう
  int rank[200010]; // ランク　必要に応じて要素数を変えよう
  unionfind(int n){
    init(n);
  }
  void init(int n){
    for(int i=0;i<=n;i++){
      par[i]=i;
      rank[i]=1;
    }
  }
  int root(int x) {
    if (par[x] == x) {
      return x;
    }
    else {
      return par[x] = root(par[x]);
    }
  }
  int size(int x){
    return rank[root(x)];
  }
  bool same(int x,int y) {
    return root(x) == root(y);
  }
  void unite(int x,int y) {
    x=root(x);
    y=root(y);
    if(x==y){
      return;
    }
    if(rank[x]<rank[y]){
      swap(x,y);
    }
    rank[x]=rank[x]+rank[y];
    par[y]=x;
  }
};
int main(){
  int n,m;
  cin >> n >> m;
  int i;
  unionfind tree(n);
  for(i=0;i<m;i++){
    int x,y;
    cin >> x >> y;
    x--,y--;
    tree.unite(x,y);
  }
  int ans=0;
  for(i=0;i<n;i++){
    ans=max(ans,tree.size(i));
  }
  cout << ans << endl;
}

Measured memory_bytes: 5156
#include <cstdio>
#define repu(i,x,y) for (int i=x; i<=y; ++i)
#define repd(i,x,y) for (int i=x; i>=y; --i)
using namespace std;

typedef long long LL;
int head,tail,q[210],m,a[110];
LL n;

int main()
{
    scanf("%lld",&n);
    head=100,tail=99;
    while (n)
        if (n&1)
            n>>=1,a[++m]=1;
        else
            --n,++m;
    repd(i,m,1)
        (a[i]?q[++tail]:q[--head])=m-i+1;
    printf("%d\n",m*2);
    repu(i,head,tail)
        printf("%d ",q[i]);
    repu(i,1,m)
        printf("%d ",i);
    return 0;
}

Measured memory_bytes: 128
N = int(input())

s_ps = {}
for n in range(N):
    s,p=input().split()
    p=int(p)

    if s_ps.get(s) is None:s_ps[s] = []

    s_ps[s].append((n,p))

for s, ps in sorted(s_ps.items(), key=lambda x:x[0]):
    for n, p in sorted(ps, key=lambda x:x[1]*-1):
        print(n+1)

Measured memory_bytes: 3060
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int N;
    cin >> N;

    vector<string> ans;
    ans.pb("a");


    REP(i, N - 1) {
        vector<string> tmp;
        for(const auto& s: ans) {
            string t = s;
            sort(t.begin(), t.end());
            int cnt = unique(t.begin(), t.end()) - t.begin();
            REP(j, cnt + 1) {
                char c = char('a' + j);
                tmp.pb(s + c);
            }
        }
        ans = tmp;
    }

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

    REP(i, ans.size()) {
        cout << ans[i] << endl;
    }
    
}


Measured memory_bytes: 9116
n,m = map(int, input().split())
hlist = list(map(int, input().split())) 
ab = [list(map(int, input().split())) for _ in range(m)]

ex =[]

for i in range(0,m):
    if hlist[ab[i][0]-1] > hlist[ab[i][1]-1]:
        ex.append(ab[i][1]-1)
    elif hlist[ab[i][1]-1] > hlist[ab[i][0]-1]:
        ex.append(ab[i][0]-1)
    else:
        ex.append(ab[i][0]-1)
        ex.append(ab[i][1]-1)

exlen = len(set(ex))

res = n-exlen
print(res)

Measured memory_bytes: 37740
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;
#define MOD 1000000007
#define MAX 1000000

int main(){
  int n;
  cin>>n;
  vector<string> S(n);
  vector<int> count(26,100);
  for(int i=0;i<n;i++){
    cin>>S.at(i);
  }

  for(int i=0;i<n;i++){
    vector<int> num(26,0);
    for(int j=0;j<S.at(i).size();j++){
      num.at(S.at(i).at(j)-'a')++;
    }
    for(int j=0;j<26;j++){
      count.at(j)=min(count.at(j),num.at(j));
    }
  }
  for(int i=0;i<26;i++){
    for(int j=0;j<count.at(i);j++){
      cout<<(char)(i+'a');
    }
  }
  cout<<endl;
}


Measured memory_bytes: 256
import sys
from collections import deque

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, p, q, *AB = map(int, read().split())
    p -= 1
    q -= 1

    G = [[] for _ in range(N)]
    for a, b in zip(*[iter(AB)] * 2):
        G[a - 1].append(b - 1)
        G[b - 1].append(a - 1)

    if len(G[p]) == 1 and G[p][0] == q:
        print(0)
        return

    dist1 = [-1] * N
    dist1[p] = 0
    queue = deque([p])
    while queue:
        v = queue.popleft()
        for nv in G[v]:
            if dist1[nv] == -1:
                dist1[nv] = dist1[v] + 1
                queue.append(nv)

    dist2 = [-1] * N
    dist2[q] = 0
    queue = deque([q])
    while queue:
        v = queue.popleft()
        for nv in G[v]:
            if dist2[nv] == -1:
                dist2[nv] = dist2[v] + 1
                queue.append(nv)

    max_d = 0
    for d1, d2 in zip(dist1, dist2):
        if d1 < d2 and max_d < d2:
            max_d = d2

    print(max_d - 1)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 41988
from numpy import zeros, maximum, array

def main():
    N, T, *AB = map(int, open(0).read().split())

    dp = zeros(T + max(AB[::2]), int)
    for w, v in sorted(zip(*[iter(AB)] * 2)):
        dp[w:T + w] = maximum(dp[w:T + w], dp[:T] + v)

    print(dp.max())

main()


Measured memory_bytes: 12832
def check(n,s):
    v=str(n)
    for i in v:
        if i in s:
            return False
    return True
def solve():
    n,k=map(int,input().split())
    s=input().split()
    s=set(s)
 
    while True:
        if check(n,s):
            print(n)
            break
        else:
            n+=1
for _ in range(1):
    solve()

Measured memory_bytes: 9068
#ifndef Local
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/STACK:1024000000,1024000000")
#endif

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define popCnt(x) (__builtin_popcountll(x))
typedef long long Long;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif

  int n , k;
  cin >> n >> k;

  if (k == 0) {
    cout << 1LL * n * n << endl;
    return 0;
  }

  Long res = 0;
  for (int b = 1; b <= n; ++b) {
    res += 1LL * n / b * max(0 , b - k);
    res += max(0 , n % b - k + 1);
  }

  cout << res << endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define maxn 5005
#define plus qaq
using namespace std;
typedef long long ll;
const ll mod=998244353;
int n;
char s[maxn];
int t[maxn],a[10][maxn],g[maxn],temp[maxn];
void trans(char *x,int *y)
{
	int len=strlen(x);
	for(int i=0;i<=len-1;i++)
		y[i]=x[len-1-i]-'0';
}
int deg(int *a)
{
	for(int i=4000;i>=0;i--)
		if(a[i])
			return i;
	return 0;
}
void plus(int *a,int *b,int m)
{
	for(int i=m;i<=4000;i++)
		a[i]=(a[i]^b[i-m]);
}
void getgcd(int *a,int *b,int *gg)
{
//	for(int i=0;i<=5;i++)
//		cerr<<a[i];
//	cerr<<endl;
//	for(int i=0;i<=5;i++)
//		cerr<<b[i];
//	cerr<<endl;
	int da=deg(a),db=deg(b);
	if(da<db) swap(a,b),swap(da,db);
//	cerr<<"this "<<da<<" "<<db<<endl;
	if(db==0 && b[0]==0)
	{
//		memcpy(gg,a,sizeof(a));
		for(int i=0;i<=4000;i++)
			gg[i]=a[i];
		return;
	}
	plus(a,b,da-db);
	getgcd(b,a,gg);
}
int main()
{
	scanf("%d%s",&n,s); trans(s,t);

	for(int i=1;i<=n;i++)
	{
		scanf("%s",s); trans(s,a[i]);
		getgcd(a[i],g,temp);
		memcpy(g,temp,sizeof(g));
//		cerr<<"its "<<i<<endl;
//		for(int j=0;j<=11;j++)
///			cerr<<g[j];
//		cerr<<endl;
	}

	int d=deg(g);

//	for(int i=0;i<=11;i++)
//		cerr<<g[i];
//	cerr<<endl;

	memset(temp,0,sizeof(temp));

	for(int i=4000;i>=d;i--)
	if(temp[i]^t[i])
	{
		plus(temp,g,i-d);
	}

	ll ans=0;
	int dd=deg(t);
	for(int i=dd;i>=d;i--)
		ans=((ans<<1)+t[i])%mod;
	for(int i=dd-1;i>=0;i--)
	{
		if(temp[i]<t[i])
			break;
		else if(temp[i]>t[i])
		{
			ans--;
			ans=(ans%mod+mod)%mod;
			break;
		}
	}
	printf("%lld\n",(ans+1)%mod);
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define all(t) t.begin(), t.end()
#define inrange(i, a, b) (((i)>= min((a), (b))) && ((i) <= max((a), (b))))
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
#define fi first
#define se second
#define upb upper_bound
#define lwb lower_bound
#define show(x) cout << #x << " is " << x << "\n";
const ll inf = 2e18;
const ll mod = 1e9 + 7;
const ld pi = 3.141592653589793238462643383279502884;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void print(ll a[], ll n){for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<"\n";}
ll power(ll x, ll y){
    if(y<=0) return 1;
    ll ans = 1;
    x %= mod;
    while(y){
        if(y&1)
            ans = (x * ans) % mod;
        x = (x * x) % mod;
        y >>= 1;
    }
    return ans;
}
ll modInverse(ll n) {return power(n, mod-2);}
inline ll mul(ll a, ll b){ return (a * b) % mod; }
inline ll sub(ll a, ll b){ ll c = (a - b); if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = (a + b); if(c >= mod) c -= mod; return c; }
inline ll divi(ll a, ll b){ return mul(a, modInverse(b)); }

//------------------------------------------------------------------------------------------

//const ll N = 2e5 + 1;
//vector<ll> adj[N];
//bool visited[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cout<<fixed<<setprecision(10);

	ll n;
	cin>>n;
	ll a[n];
	ll ans=0;
	ll ma=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]<ma){
			ans+=ma-a[i];
		}
		else ma = max(a[i], ma);
	}
	
	cout<<ans;
	


    return 0;
}


Measured memory_bytes: 5180
length = list(map(int, input().split()))
judge = {0:5,1:7,2:5}

for i in range(len(judge)):
    for j in range(len(length)):
        if length[j] == judge[i]:
            length.pop(j)
            break
        else:
            if j == len(length)-1:
                print('NO')
                exit()
print('YES')

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main()
{
    string x,y;
    int c=0;
    cin>>x>>y;
    for(int i=0;i<x.size();i++){
        if(x[i]!=y[i]){
            c++;
        }
    }
    cout<<c;

    return 0;
}


Measured memory_bytes: 3484
def wczytaj_liste(): 
    wczytana_lista = input()
    lista_znakow = wczytana_lista.split()
    ostateczna_lista = []
    for element in lista_znakow:
        ostateczna_lista.append(int(element))
    return ostateczna_lista 


class N_po_K:
    def __init__(self, maxN, modulo = 10**9+7): 
        self.modulo = modulo
        self.silnie = [1]
        for i in range(1, maxN + 1):
            self.silnie.append(self.silnie[i - 1] * i % self.modulo)
        
    def dwumian(self, N, K):
        if N < K: 
            return 0
        return self.silnie[N] * pow(self.silnie[K], self.modulo - 2, self.modulo)\
                              * pow(self.silnie[N-K], self.modulo - 2, self.modulo) % self.modulo

def min_max_sums(): 
    N, K = wczytaj_liste()
    A = wczytaj_liste()
    A.sort()
    suma_min = 0 
    suma_max = 0
    dwumianator = N_po_K(N)
    for i in range(N):
        suma_min += dwumianator.dwumian(N-i-1, K-1)*A[i]
        suma_max += dwumianator.dwumian(N-i-1, K-1)*A[-i-1]
    print((suma_max - suma_min)%(10**9+7))

min_max_sums()

Measured memory_bytes: 68768
#include <iostream>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

int main() {
	int A, B, C, K;
	cin >> A >> B >> C >> K;


	int ans = 0;
	if (A < K)
	{
		ans += A;

		if (A + B <= K);
		if (A + B + C <= K)
			ans -= C;
		else {
			ans -= K - A - B;
		}
	}
	else {
		ans += K;
	}

	cout << ans;
	cin >> A;

	return 0;
}

Measured memory_bytes: 3636
import java.io.*;

public class Main{
 public static void main(String[] args){
	try{  
	 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  	 int x  = Integer.parseInt(br.readLine());
  	 String[] str = br.readLine().split(" ");

		for(int i = str.length-1;  i >= 0; i--){
			if(i != 0){
		 	 System.out.print(str[i] + " ");
			}else{
		 	 System.out.println(str[i]);
			}
		}
	}catch(IOException e){
	 System.out.println(e);
	}
}
}

Measured memory_bytes: 16908
N = int(input())
l = [int(i) for i in input().split(' ')]

total =0
for n,i in enumerate(l):
    if n == 0:
        total+=1
    else:
        flag = True
        for ii in l[:n]:
            if ii>i:
                flag = False
                break
        if flag:
            total+=1
print(total)


Measured memory_bytes: 2940
from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
w = [input() for i in range(n)]

set_w = set(w)
if len(set_w) != n:
    print("No")
    exit()

end = w[0][-1]
for i in range(1,n):
    if w[i][0] != end:
        print("No")
        exit()
    else:
        end = w[i][-1]
print("Yes")

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

const int INF = 1001001001;
const int mod = 1000000007;

ll pow(ll base, ll order) {
	ll ans = 1;
	rep(i,order - 1) ans *= base;
	return ans;
}

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

ll sum(ll x) { // sum of subsequent numbers from 0 to x
	return x*(x + 1)/2;
}

int main() {
	int n;
	cin >> n;
	vector<int> a(n + 1), b(n);
	rep(i, n + 1) cin >> a.at(i);
	rep(i, n) cin >> b.at(i);

	ll ans = 0;
	vector<int> rest(n);
	rep(i, n) {
		int beat_prev = 0, beat;
		if (i >= 1) {
			beat_prev = min(rest.at(i - 1), a.at(i));
		}
		beat = min(a.at(i) - beat_prev, b.at(i));
		rest.at(i) = b.at(i) - beat;
		ans += beat + beat_prev;
		//cout << beat << endl;
	}
	ans += min(rest.at(n - 1), a.at(n));
	cout << ans << endl;
}


Measured memory_bytes: 1408
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
c = Counter(A)

cnt = 0
for v  in c.values():
    cnt += v - 1

ans = len(set(A)) if cnt % 2 == 0 else len(set(A)) - 1
if ans == 0: ans = 1
print(ans)

Measured memory_bytes: 21076
#include <stdio.h>
#include <stdlib.h>
#define int long long
#define inf (int)(1e18)

int min(int a, int b){
	return a <= b ? a : b;
}

signed main(){
	int N, i, d = 21, j;
	scanf("%lld", &N);
	int *A = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		scanf("%lld", &A[i]);
	}
	int **next_dig = (int **)malloc(sizeof(int *) * (N + 2));
	for(i = 0; i <= N + 1; i++){
		next_dig[i] = (int *)malloc(sizeof(int) * d);
		for(j = 0; j < d; j++){
//			printf("test\n");
			next_dig[i][j] = -1;
		}
	}
	for(j = 0; j < d; j++){
		next_dig[N][j] = N;
		next_dig[N + 1][j] = N;
		for(i = N - 1; i >= 0; i--){
//			printf("(i, j) = (%lld, %lld)\n", i, j);
			if(((1 << j) & A[i]) != 0){
				next_dig[i][j] = i;
			}
			else{
				next_dig[i][j] = next_dig[i + 1][j];
			}
		}
	}
/*	for(i = 0; i <= N; i++){
		for(j = 0; j < d; j++){
			printf("next_dig[%lld][%lld] = %lld\n", i, j, next_dig[i][j]);
		}
	}
*/	int ans = 0, now;
	for(i = 0; i < N; i++){
		now = inf;
		for(j = 0; j < d; j++){
//			printf("(i, j) = (%lld, %lld)\n", i, j);
			now = min(now, next_dig[next_dig[i][j] + 1][j]);
		}
		ans += now - i;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 37632
#include <iostream>
#include <string>
#include <set>
#include <algorithm>

using namespace std;
typedef long long ll;
#define all(x) begin(x), end(x)

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

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

    int d[n] = {};
    int cnt = 0;
    int temp = 0;

    while (d[temp] == 0) {
        if (cnt == k) {
            cout << temp + 1 << endl;
            return 0;
        }
        d[temp] = cnt;
        temp = a[temp] - 1;
        cnt++;
    }
    
    int p, q;
    p = cnt - d[temp];
    q = (k - cnt) % p;

    for (int i=0; i<q; i++) {
        temp = a[temp] - 1;
    }

    cout << temp + 1 << endl;

    return 0;
}

Measured memory_bytes: 5200
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n; cin>>n;
	vector<int>arr(n);
	int sum = 0;
	int dp[n+2];
	for(int i=0;i<n;i++){cin>>arr[i];}
	dp[0] = 0;
	dp[1] = abs(arr[1]-arr[0]);
	dp[2] = (dp[1]+abs(arr[2]-arr[1]));
	for(int i=0;i<n;i++){
		dp[i+1] = min(dp[i+1],dp[i]+abs(arr[i]-arr[i+1]));
		dp[i+2] = abs(dp[i] + abs(arr[i+2] - arr[i]));
	}
	cout<<dp[n-1];
  return 0;
}


Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate

def solve():
    N, M, Q = MI()
    E = [[] for _ in range(Q)]
    for i in range(Q):
        a, b, c, d = MI()
        a -= 1
        b -= 1
        E[i] = [a, b, c, d]

    ans = 0
    for A in comb_w(range(1, M+1), N):
        res = 0
        for (a, b, c, d) in E:
            if A[b] - A[a] == c:
                res += d
        ans = max(ans, res)
    print(ans)

if __name__ == '__main__':
    solve()


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

#define int long long
typedef pair<int, int> P;
typedef pair<P, int> Pp;

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

int n;
map<int, int> G[100000];
map<int, int> used[100000];
map<int, int> zipx, zipy;
bool f = false;

void dfs(int x, int y, int c) {
  // cout << x << " " << y << " " << c << endl;
  if ( f ) return;
  int zx = zipx[x], zy = zipy[y];  
  if ( !G[zx][zy] ) return;  
  if ( used[zx][zy] && used[zx][zy] != c ) {    
    f = true;
    return;    
  } else if ( used[zx][zy] ) {
    return;    
  }
  used[zx][zy] = c;
  int d = G[zx][zy]-1;  
  for ( int i = 0; i < 4; i++ ) {
    int nx = x+dx[i], ny = y+dy[i];    
    if ( d == i ) {
      dfs(nx, ny, 3-c);      
    } else {
      dfs(nx, ny, c);      
    }
  }
}

signed main() {
  while ( cin >> n, n ) {
    for ( int i = 0; i < 100000; i++ ) {
      G[i].clear();
      used[i].clear();
    }
    zipx.clear(); zipy.clear();
    f = false;    
    vector<Pp> dat(n);
    vector<int> X, Y;  
    for ( int i = 0; i < n; i++ ) {
      int x, y;
      char d;
      cin >> x >> y >> d;
      dat[i] = (Pp(P(x, y), d == 'y'));    
      X.emplace_back(x);
      X.emplace_back(x+1);
      X.emplace_back(x-1);
      Y.emplace_back(y);
      Y.emplace_back(y+1);
      Y.emplace_back(y-1);
    }

    {
      sort(X.begin(), X.end());
      X.erase(unique(X.begin(), X.end()), X.end());
      int cnt = 0;
      for ( int i = 0; i < X.size(); i++ ) {
	zipx[X[i]] = cnt++;
      }
    }

    {
      sort(Y.begin(), Y.end());
      Y.erase(unique(Y.begin(), Y.end()), Y.end());
      int cnt = 0;
      for ( int i = 0; i < Y.size(); i++ ) {
	zipy[Y[i]] = cnt++;      
      }
    }

    for ( int i = 0; i < n; i++ ) {
      int x = dat[i].first.first, y = dat[i].first.second, d = dat[i].second;
      int nx = zipx[x], ny = zipy[y];    
      if ( d == 0 ) { // x
	G[nx][ny] = 2;
	G[zipx[x+1]][ny] = 4;
      } else {
	G[nx][ny] = 1;
	G[nx][zipy[y+1]] = 3;      
      }
    }

    for ( int i = 0; i < n; i++ ) {
      int x = dat[i].first.first, y = dat[i].first.second, d = dat[i].second;
      int nx = zipx[x], ny = zipy[y];
      if ( used[nx][ny] ) continue;
      dfs(x, y, 1);
      if ( f ) break;    
    }

    if ( f ) cout << "No" << endl;
    else cout << "Yes" << endl;  
  }  
  return 0;
}



Measured memory_bytes: 40732
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
 


public class Main {
	static int a1[]= {0,-1,0,1};
	static int b1[]= {-1,0,1,0};
	private static         Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	static int K,N;
	static long mod =1000000007;

	public static void main(String[] args) {

		long N=sc.nextLong();
		long ans=1;
		for(long i=1;i<=N;i++) {
			ans=((ans%mod)*i)%mod;
		}p(ans);
	}
	//N==S
	//E==W
//83 S 
	//69E
	//78N
	//87W
	
	//static ArrayList<Integer> cc = new ArrayList<>(10001);
	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	public static int gcd(int a, int b) {
        return b == 0 ? a: gcd(b, a % b);
	}
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


Measured memory_bytes: 23892
#include <iostream>

using namespace std;

int main()
{
  int n, m;
  cin >> n >> m;
  int a[1000];
  for(int i=0; i<n; i++) {
    cin >> a[i];
  }

  for(int k=1; k<=m; k++){
    for(int i=0; i<n-1; i++){
      if(a[i]%k > a[i+1]%k){
	int tmp = a[i];
	a[i] = a[i+1];
	a[i+1] = tmp;
      }
    }
  }

  for(int i=0; i < n; i++){
    cout << a[i] << endl;
  }

  return 0;
}


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

int f(int n) {
	int res = 0;
	for (int i = 1; i * i <= n; i++) {
		for (int j = 1; j * j + i * i <= n; j++) {
			for (int k = 1;; k++) {
				int prod = i * i + j * j + k * k + i * j + j * k + k * i;
				if (prod > n) {
					break;
				} else if (prod == n) {
					res++;
				}
			}
		}
	}
	return res;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cout << f(i) << '\n';
	}
}



Measured memory_bytes: 3564
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int gcd(int x, int y) {
    if(y == 0) return x;
    return gcd(y, x % y);
}

void solve() {
	int x; cin >> x;
    int d = gcd(x, 360);
    cout << (x * 360 / d) / x << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 3652
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res

N=II()
LIS=LI()

MX=1000000000000000000
res = 1
if 0 in LIS:
    print(0)
else:
    for i in LIS:
        res *= i
        if res > MX:
            print(-1)
            exit(0)
    print(res)


Measured memory_bytes: 21708
#include<iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
long long a,b,c,d,sum=0;

long long lcm(long long  x,long long y){
	long long s=x,t=y,st;
	while(t!=0){
		st=s%t;
		s=t;
		t=st;
	}
	return x*y/s;
}
int main(){
 	scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
	long long t1=(a-1)/c,t2=(a-1)/d,t3=b/c,t4=b/d;
	t3=t3-t1;
	t4=t4-t2;
//	cout <<t3<<" "<<t4<<endl;
	long long lcms=b/lcm(c,d)-((a-1)/lcm(c,d));
//	cout<<lcms<<endl;
	lcms=(b-(a-1))-(t3+t4-lcms);
	cout<<lcms<<endl;
	

	return 0; 
} 

Measured memory_bytes: 256
# coding: utf-8
DATA = """
5
5 10
ssdss
""".split("\n")

def get_debug_line():
	for i in DATA:
		yield i

if 1:
	get_line = input
else:
	get_line = get_debug_line().__next__
	get_line()

X, Y, Z = [int(i) for i in get_line().strip().split(" ")]
print ("{0} {1} {2}".format(Z, X, Y))

Measured memory_bytes: 2940
N = int(input())
sum_min = 10000000
for a in range((N)//2+1):
    n_a = a+1
    n_b = N-a-1
    sum_a = 0
    sum_b = 0
    while(n_a>0):
        sum_a += n_a%10
        n_a //= 10
    while(n_b>0):
        sum_b += n_b%10
        n_b //= 10
    sum_all = sum_a + sum_b
    if(sum_all <= sum_min):
        sum_min = sum_all
print(sum_min)



Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
    static long mod=(long)1e9+7; 
    public static long kaijou(long n){
        long a=1;
        for(long i=1;i<=n;i++){
            a=a*i%mod;
        }
        return a;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N=sc.nextLong();
        long M=sc.nextLong();
        if(N==M){
            System.out.println(kaijou(N)*kaijou(M)*2%1000000007);
        }else if(N==M-1||M==N-1){
            System.out.println(kaijou(N)*kaijou(M)%1000000007);
        }else{
            System.out.println("0");
        }
        
    }
}


Measured memory_bytes: 21844
def solve():
    N, X = [int(s) for s in input().split() if s]
    L = [int(s) for s in input().split() if s]
    D = 0
    cnt = 0
    for l in L:
        # print(D)
        D += l
        cnt += 1
        if D > X:
            return cnt
    return cnt+1

print(solve())

Measured memory_bytes: 3060
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <queue>
#include <bitset>
#include <string>
using namespace std;

#define REP(i,n) for(int i=0; i<n; i++)
#define RPA(i,s,e) for(int i=s; i<=e; i++)
#define RPD(i,s,e) for(int i=s; i>=e; i--)
#define PB(a) push_back(a)
#define MP(i,s) make_pair(i,s)
#define SZ(a) (int)(a).size()
#define ALL(a) (a).begin(), (a).end()
#define PRT(a) cout << (a) << endl
#define PRT2(a,b) cout << (a) << " " << (b) << endl
#define PRT3(a,b,c) cout << (a) << " " << (b) << " " << (c) << endl

typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int> P;

int b,r,g,c,s,t;

void coding() {
	while(cin>>b>>r>>g>>c>>s>>t) {
		if(!(b|r|g|c|s|t)) break;
		int bon = 5 * b + 3 * r;
		int reg = t - s - bon;
		int ans = 100 - 3 * reg - 2 * bon;
		ans += 2 * c + 7 * g + 15 * bon + 15 * (b + r);
		cout << ans << endl;
	}
}

// #define _LOCAL_TEST

int main() {
#ifdef _LOCAL_TEST
	clock_t startTime = clock();
	freopen("a.in", "r", stdin);
#endif

	coding();

#ifdef _LOCAL_TEST
	clock_t elapsedTime = clock() - startTime;
	cout << endl;
	cout << (elapsedTime / 1000.0) << " sec elapsed." << endl;
	cout << "This is local test" << endl;
	cout << "Do not forget to comment out _LOCAL_TEST" << endl << endl;
#endif
}

Measured memory_bytes: 1160
s = int(input())
def f(x):
  if x % 2 == 0:
    return x/2
  else:
    return 3 * x + 1

X = [s]
cont = 1
next = s

while cont < 1000:
  cont += 1
  next = f(next)
  if next in X:
    break
  else:
    X.append(next)
    
print(cont)

Measured memory_bytes: 3060
import itertools

N,M,X=map(int,input().split())

Money=0

lst=range(N)
combs = []

for i in range(1, len(lst)+1):
    els = [list(x) for x in itertools.combinations(lst, i)]
    combs.extend(els)

inList=[]
for i in range(N):
    inList.append(list(map(int,input().split())))


Tmp=[0]*(len(combs))

for i in range(len(combs)):
    Skill=[0]*M
    for j in range(len(combs[i])):
        for k in range(M):
            Skill[k]+=inList[combs[i][j]][k+1]
        Tmp[i]+=inList[combs[i][j]][0]

    ok=True
    for k in range(M):
        if(Skill[k]<X):
            ok=False
    if(ok==False):
        Tmp[i]=10000000000

if(min(Tmp)==10000000000):
    print(-1)
else:
    print(min(Tmp))



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

int main(){
	char c;
 	cin >> c;
  
	if(c == 'a' || c == 'i' || c == 'u' || c ==  'e' || c == 'o') {
		cout << "vowel";
    } else {
      	cout << "consonant";
    }

}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
	int W=sc.nextInt();
	int H=sc.nextInt();
	int x=sc.nextInt();
	int y=sc.nextInt();
	int r=sc.nextInt();
	int top=r+y;
	int down=y-r;
	int right=x+r;
	int left=x-r;
	if(top>H||down<0||right>W||left<0)
	    System.out.println("No");
	else System.out.println("Yes");
	
    }
}

Measured memory_bytes: 17360
/*--ILRS-- sr4saurabh  */
#include <bits/stdc++.h>
using namespace std; 
typedef long long int ll;
#define pb push_back 
#define popb pop_back
#define mp make_pair
#define ve vector
#define vii vector < int >
#define vll vector < ll > 
#define pii pair < int , int >
#define pll pair < ll , ll >
#define vpl vector < pll >
#define fi first
#define sz size 
#define len length 
#define se second 
//const ll mod=998244353;
const ll mod = 1000000000+7;
const ll N=10000000+6;
#define M_PI           3.14159265358979323846
//--------------------------------------------
vii adj[200005];
vii vis(200005);
int cc = 0;

//--------------------------------------------
void dfs(int v)
{
	vis[v] = 1;
	cc++;
	for(int u : adj[v])
		if(!vis[u])
			dfs(u);
}




//============================================
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
       freopen ("INPUT.txt" , "r" , stdin);
       freopen ("OUTPUT.txt", "w" , stdout);
    #endif

	//THE WATER WAS DEEP, I DROWNED AND THEN CAME FLOATING UP,DEAD!!

       	int n,m;
       	cin>>n>>m;

       while(m--)
       {
       		int u,v;
       		cin>>u>>v;
       		adj[u].pb(v);
       		adj[v].pb(u);
       }

       int ma = 0;
       for(int i = 1; i <= n ;i++)
       {
       		cc = 0;
       		if(!vis[i])
       			dfs(i);

       		ma = max(cc, ma);

       }


       cout<<ma;







return 0;
}

Measured memory_bytes: 21064
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=1e5+10;
int c[maxn],a[maxn],to[maxn],ans[maxn],tmp[maxn],p[maxn],pos[maxn],K,now;
int n,m;
void solve(int y)
{
	for(;y;y>>=1)
	{
		if (y&1)
		{
			for (int i=1;i<=n;++i)p[i]=ans[to[i]];
			for (int i=1;i<=n;++i)ans[i]=p[i];
		}
		for (int i=1;i<=n;++i)p[i]=to[to[i]];
		for (int i=1;i<=n;++i)to[i]=p[i];
	}
	for(int i=1;i<=n;++i)p[i]=c[ans[i]];
	for(int i=1;i<=n;++i)c[i]=p[i];
}

signed main()
{
	cin>>n;
	for (int i=1;i<=n;++i)cin>>pos[i],c[i]=pos[i]-pos[i-1],to[i]=ans[i]=i;
	scanf("%d%lld",&m,&K);
	for(int i=1;i<=m;++i)cin>>a[i];
	for(int i=1;i<=m;++i)
		swap(to[a[i]],to[a[i]+1]);
	solve(K);
	for (int i=1;i<=n;++i)
		c[i]+=c[i-1],cout<<c[i]<<".0 "<<endl;;
}
/*
这个1e18 明示矩阵加速/倍增 
fi表示第i只兔子的期望位置。
扫操作，每次操作还要扫一下上一只和下一只，然后才能转移
这 
pos[i]=pos[i-1]+pos[i+1]-pos[i]

草啊谁tm想得到差分啊？？？？
 */

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

using namespace std;

#define MAX 5050
typedef long long ll;
const ll MOD = ((1e9) + 7);

int dp[MAX][MAX];

int main()
{
    int N, L;
    cin >> N >> L;
    vector<int> x(N), a(N);
    for (int i = 0; i < N; i++) {
        cin >> x[i]; 
    }
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }

    for (int i = 0; i < L; i++) {
        dp[0][i] = 1;
    }

    for (int i = 0; i < N; i++) {        
        for (int j = x[i]; j < L; j += a[i]) {
            if (j > 0) {
                dp[i+1][j] += dp[i][j-1];
            } else {
                dp[i+1][j] = dp[i][j];
            }
            dp[i+1][j] %= MOD;
            if (a[i] == 0) break;
        }
        
        for (int j = x[i]; j < L; j++) {
            dp[i+1][j+1] += dp[i+1][j];
            dp[i+1][j+1] %= MOD;
        }      
    }
    
    cout << dp[N][L-1] << endl;
    return 0;
}

Measured memory_bytes: 70108
# import itertools
import math
# import sys
# sys.setrecursionlimit(500*500)
# import numpy as np

# N = int(input())
# S = input()
# n, *a = map(int, open(0))
a, b, x = map(int, input().split())
# A = list(map(int, input().split()))
# B = list(map(int, input().split()))
# tree = [[] for _ in range(N + 1)]
# B_C = [list(map(int,input().split())) for _ in range(M)]

# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)

# A = np.array(A)
# cum_A = np.cumsum(A)
# cum_A = np.insert(cum_A, 0, 0)

# def dfs(tree, s):
#     for l in tree[s]:
#         if depth[l[0]] == -1:
#             depth[l[0]] = depth[s] + l[1]
#             dfs(tree, l[0])
# dfs(tree, 1)

# def factorization(n):
#     arr = []
#     temp = n
#     for i in range(2, int(-(-n**0.5//1))+1):
#         if temp%i==0:
#             cnt=0
#             while temp%i==0:
#                 cnt+=1
#                 temp //= i
#             arr.append([i, cnt])
#     if temp!=1:
#         arr.append([temp, 1])
#     if arr==[]:
#         arr.append([n, 1])
#     return arr

x_s = a * a * b - x
if x <= x_s:
    print(math.degrees(math.atan(a * b * b / (2 * x))))
else:
    print(math.degrees(math.atan(2 * x_s / (a * a * a))))

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

using namespace std;
typedef long long ll;

const int MM = 123456;
int n, w;
ll dp[MM];

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

    cin >> n >> w;
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        for (int j = w; j >= a; j--) {
            dp[j] = max(dp[j], dp[j - a] + b);
        }
    }
    cout << dp[w] << endl;
    return 0;
}

Measured memory_bytes: 1024