akhauriyash/Code-Regression huggingface dataset:
s = input()

li = []
mod = 2019
tmp = 0

for i in range(len(s)):
    li.append(tmp)
    tmp += int(s[i])*pow(10,len(s)-i-1,mod)
    #tmp += int(s[i]) * 10 ** (len(s)-i-1)
    tmp %= mod
    #print(len(s)-i-1,s[i])

li.append(tmp)
li.sort()

tmp = li[0]
t_num = 1
ans = 0

for i in range(1,len(li)):
    if tmp == li[i]:
        t_num += 1
    else:
        ans += t_num*(t_num-1)//2
        t_num = 1
        tmp = li[i]

ans += t_num*(t_num-1)//2

print(ans)

Measured memory_bytes: 75460
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 文字列の入力
        String s = sc.next();
        sc.close();
        String replaced = s.replace("2017", "2018");
		// 出力
		System.out.println(replaced);
	}
}


Measured memory_bytes: 21588
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
void solve(){
  ll n,m,k,tmp,max_v=0,max_i=0,sum=0,min_v=1000000000000;
  cin >> n >>m;
  if(n==0&&m==0) return;
  set<ll> st[m];
  vector<ll> s(m),min_t(n);
  for(int i=0;i<m;i++){
    cin >> s[i] >> k;
    for(int j=0;j<k;j++){
      cin >> tmp;
      tmp--;
      st[i].insert(tmp);
    }
    if(k==1){
      min_t[*st[i].begin()] += s[i];
    }
  }
  for(ll i=0;i<n;i++){
    tmp = 0;
    for(ll j=0;j<m;j++){
      if(st[j].find(i)!=st[j].end()){
        tmp += s[j];
      }
    }
    if(tmp>max_v){
      max_v = tmp; 
      max_i = i;
    }
  }
  for(int i=0;i<n;i++){
    if(i==max_i) continue;
    min_v = min(min_v,min_t[i]);
  }
  cout << max_v-min_v+1<<endl;
  solve();
}
signed main(){
  init_io();
  solve();
}



Measured memory_bytes: 39232
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
using namespace std;

const int N=2e5+5;
int dp[N];

void solve()
{
    string s;
    cin>>s;
    /*int n=s.size();
    s="."+s;
    for(int i=1;i<=n;i++)
    {
        if(s[i]=='?')
        {
            dp[i]=max(dp[i],dp[i-1]+1);
            if(i>1&&s[i-1]!='D') dp[i]=max(dp[i],dp[i-2]+2);
        }
        else if(s[i]=='P') dp[i]=dp[i-1];
        else if(s[i]=='D')
        {
            dp[i]=max(dp[i],dp[i-1]+1);
            if(i>=1&&s[i-1]!='D') dp[i]=max(dp[i],dp[i-2]+2);
        }
    }
    cout<<dp[n];*/
    for(int i=0;i<s.size();i++) if(s[i]=='?') s[i]='D';
    cout<<s;
}

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //int t;
    //cin>>t;
    //while(t--)
        solve();
}


Measured memory_bytes: 3736
#include <iostream>
#include <vector>
#include <numeric>
#include <utility>
#include <cmath>
#include <algorithm>
#include <queue>

using ll = long long;

template <class T>
using vec = std::vector<T>;

template <class T>
constexpr T nil = static_cast<T>(-1);

template <class T>
constexpr T inf = std::numeric_limits<T>::max() / 2;


struct Edge
{
    int from, to;
    ll d;
};

auto Dijkstra(const vec<vec<Edge>>& edges,int begin)
{
    using namespace std;

    auto c = [](Edge e1, Edge e2) { return e1.d > e2.d; };
    priority_queue<Edge, vector<Edge>, decltype(c)> q(c);

    vec<ll> dist(edges.size() ,inf<ll>);
    vec<bool> reached(edges.size(), false);
    
    auto markAndPush = [&reached, &q, &edges, &dist](int v)
    {
        reached[v] = true;
        for (const auto& e : edges[v])
        {
            q.push({e.from, e.to, dist[e.from] + e.d});
        }
    };

    dist[begin] = 0;
    markAndPush(begin);

    while (!q.empty())
    {
        auto e = q.top(); q.pop();
        if (reached[e.to]) continue;

        dist[e.to] = e.d;
        markAndPush(e.to);
    }

    return dist;
}

void solve()
{
    using namespace std;

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

    vec<vec<Edge>> edges(n);

    for (int i = 0, from, to, d; i < m; ++i)
    {
        cin >> from >> to >> d;
        edges[from].push_back({from, to, d});
    }

    auto dist = Dijkstra(edges, r);

    for (auto d : dist)
        if (d == inf<ll>)
            cout << "INF" << endl;
        else
            cout << d << endl;
}

int main()
{
    solve();
    return 0;
}


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

#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define tr(ds, it) for(auto it=ds.begin(); it!=ds.end(); it++)
#define rtr(ds, it) for(auto it=ds.rbegin(); it!=ds.rend(); it--)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef priority_queue <int> pq;
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
#define o_set tree<ii, null_type,less<ii>, rb_tree_tag,tree_order_statistics_node_update>
#define graph vector<vi>
#define Mod 1000000007
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define T int t;cin>>t;rep(i,t)

ll counts[10000001];

void solve() {

    ll n;
    cin >> n;

    ll ans = 1;

    if (n == 1) {
        cout << 1 << "\n";
        return;
    }
    
    memset(counts, 0, n + 1) ; 
    for (ll i = 2; i*i <= n; i++) {
        for (ll j = 2 * i; j <= n; j += i) {
            if ((j / i) == i)
                counts[j] += 1;
            else if (j / i > i)
                counts[j] += 2;
        }
    }

    for (ll i = 2; i <= n; i++) {
        // cout << counts[i] << " ";
        ans += (i * (counts[i] + 2LL));
    }
    cout << ans << "\n";

}

int main()
{
    fastio;
    // T
    solve();
    //code
    return 0;
}


Measured memory_bytes: 81712
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <string.h>
#include <ctype.h>
#include <algorithm>
#include <math.h>

using namespace std;

int main() {
  int x;
  cin >> x;
  
  int ma = 0;
  if(x == 1) {
    cout << "1" << endl;
    return 0;
  }
  for(int i = 2; i < x; i++) {
    int num = i*i;
    for(int j = 0; ; j++) {
      if(num <= x)
        num *= i;
      else if(j == 0)
        goto Exit;
      else
        break;
    }
    ma = max(ma, num/i);
    Exit:;
  }
  cout << ma << endl; 
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <stack>
#include <set>
#include <algorithm>
using namespace std;
#define ll long long int

ll HowMuchMeet ( ll a, ll b, ll k ) {
  ll x = b - k;
  ll y = ( a - k ) / b;
  return x * y + min(x, a - ( y * b + k ) + 1);  
}
int main( ) {
  ll n,k,ans = 0;
  cin >> n >> k;
  if ( k == 0 )
  {
    cout << n * n << endl;
    return 0;
  }
  for ( int b = k + 1; b <= n; b++ ) 
  {
    ans += HowMuchMeet(n,b,k);
  }
  cout << ans << endl;
  return 0;
}



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


int main(){
    int a, b;
    cin >> a >> b;
    int m = min(a,b);
    int M = max(a,b);
    rep(i,M){
        cout << m;
    }
    cout << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

N = int(input())
S = input()

ans = 0
for i in range(N):
    ans = max(ans, len(set(S[:i]) & set(S[i:])))
print(ans)




Measured memory_bytes: 5840
import heapq

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

L=[]
for i in range(N):
    a,b=map(int,input().split())
    L.append([a,-b])
L.sort()
#print(L)
Q=[]
heapq.heapify(Q)
l=0
ans=0
for i in range(1,M+1):
    for j in range(l,N):
        if L[j][0]==i:
            heapq.heappush(Q,[L[j][1],L[j][0]])
            #print(i,L[j])
            l+=1
        else:
            break
    
    if len(Q)==0:
        pass
    else:
        ans-=Q[0][0]
        #print(i,ans)
        heapq.heappop(Q)
print(ans)

Measured memory_bytes: 29864
while True:
    m,f,r=map(int,input().split())
    if m==-1 and f==-1 and r==-1 : break
    x = m + f
    if m==-1 or f==-1 : print('F')
    elif x >= 80 : print('A')
    elif x >= 65 : print('B')
    elif x >= 50 : print('C')
    elif x >= 30 :
        if r >= 50 : print('C')
        else : print('D')
    else : print('F')


Measured memory_bytes: 5592
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = min(a) + min(b)
for i in range(M):
    x, y, c = map(int, input().split())
    p = a[x-1] + b[y-1] - c
    if p < ans:
        ans = p
print(ans)

Measured memory_bytes: 24696
#include<stdio.h>
#include<ctype.h>
int main(){

  char s1[10],s2[10],s3[10],x,y,z;

  scanf("%s %s %s",s1,s2,s3);

  x = toupper(s1[0]);
  y = toupper(s2[0]);
  z = toupper(s3[0]);

  printf("%c%c%c\n",x,y,z);

  return 0;
}

Measured memory_bytes: 128
def fact(n):
    if n <= 0:
        return 0
    ans = 1
    for i in range(n):
        ans *= i + 1
    return ans


def getNum(N, a):
    num = 1
    for i in range(N):
        dig = a[i]
        cnt = 0
        for j in range(i):
            if dig > a[j]:
                cnt += 1
        num += (dig - cnt - 1) * fact(N - i - 1)
    return num


N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
print(abs(getNum(N, P) - getNum(N, Q)))


Measured memory_bytes: 3064
#include <stdio.h>

void wareki_convert(int year, int month, int day);

int main(void)
{
	int year, month, day;
	while (scanf("%d %d %d", &year, &month, &day) != EOF) {
		wareki_convert(year, month, day);
	}
	return 0;
}

void wareki_convert(int year, int month, int day)
{
	if (year <= 1867 || (year == 1868 && month <=8) || (year == 1868 && month == 9 && day <=7)) {
		printf("pre-meiji\n");
	} else if (year <= 1911 || (year == 1912 && month <=6) || (year == 1912 && month == 7 && day <=29)) {
		int year_wareki =  (year - 1867);
		printf("meiji %d %d %d\n", year_wareki, month, day);
	} else if (year <= 1925 || (year == 1926 && month <=11) || (year == 1926 && month == 12 && day <=24)) {
		int year_wareki =  (year - 1911);
		printf("taisho %d %d %d\n", year_wareki, month, day);
	} else if (year <= 1988 || (year == 1989 && month == 1 && day <=7)) {
		int year_wareki =  (year - 1925);
		printf("showa %d %d %d\n", year_wareki, month, day);
	} else {
		int year_wareki =  (year - 1988);
		printf("heisei %d %d %d\n", year_wareki, month, day);
	}
}

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

#define rep(i,n) for(ll i=0;i<n;i++)
#define repm(i,m,n) for(ll i=m;i<n;i++)
#define max(a,b) (((a)>(b))?(a):(b))
#define min(a,b) (((a)<(b))?(a):(b))
#define YesNo(a) (a)?cout<<"Yes"<<endl:cout<<"No"<<endl
#define YESNO(a) (a)?cout<<"YES"<<endl:cout<<"NO"<<endl
#define INF (2e9)
#define PI (acos(-1))
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007

typedef long long ll;

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

  cout << R + max(0, 100*(10-N)) << endl;
}

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

int main(){
    string S;
    cin >> S;
    int N = S.length();
    int ans = N;
    S += '1';
    for (int i = 0; i < N; ++i) {
        if (S[i] != S[i + 1]) {
            ans = min(ans, max(i + 1, N - (i + 1)));
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    
    int i, j, N, flag_r, flag_w, count;
    cin >> N;
    int L[N];
    flag_r = 0;
    flag_w = 0;
    count = 0;

    string S;
    cin >> S;
    
    for (i = 0; i < N; i++){
        if (S.at(i) == 'R'){
            L[i] = 1;
            flag_r = 1;
            
        } else {
            L[i] = 0;
            flag_w = 1;
        }
    }
        
    if (flag_r == 0 || flag_w == 0){
        cout << "0" << "\n";
        return 0;
    }
    
    i = 0;
    j = N - 1;
    
    while(1){
        
        while(L[i] == 1){
            i++;
        }

        while(L[j] == 0){
            j--;
        }
        
        if (i > j) break;
        
        L[i] = 1;
        L[j] = 0;
        count++;
    }
    
    cout << count << "\n";

    return 0;
}



Measured memory_bytes: 4480
#include<iostream>
#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;
int main()
{
#ifdef LOCAL
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    int N, K;
    cin >> N >> K;

    long long count = 0;
    for(int b=1;b<=N;b++){
        int p = N/b;
        int r = N%b;

        count += p*max(0,b-K) + max(0, r-K+1);
    }
    if(K == 0) count -= N;
    cout << count << endl;

    return 0;
}

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

using namespace std;

#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n);i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(a);i>=(int)(b);--i)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;

const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}

template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {a = b; return true;}
  return false;
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, SZ(v)) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}

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

  int n; cin >> n;
  vector<P> p(n);
  REP(i, n) {
    cin >> p[i].first;
    p[i].second = i+1;
  }
  sort(ALL(p));

  vi a(n), b(n);
  FOR(i, 1, n+1) {
    a[i-1] = 30000 * i;
    b[i-1] = 30000 * (n - i) + p[i-1].second;
  }

  cout << a << endl;
  cout << b << endl;




}








Measured memory_bytes: 3800
while True:
    try:
        a, b, c, d, e, f = map(float, input().split())
        x = (c*e - b*f)/(a*e - b*d)
        y = (a*f - c*d)/(a*e - b*d)
        print("{:.3f} {:.3f}".format(x+0.0, y+0.0))
    except:
        break


Measured memory_bytes: 5584
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class CSlimes {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            String x = in.next();
            long ans = 0;
            for (int i = 1; i < n; i++) {
                if (x.charAt(i) != x.charAt(i - 1)) ans++;
            }
            ans++;
            out.println(ans);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

Measured memory_bytes: 1028
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
using namespace std;
#define INF 0x3f3f3f3f
//#define INF 1100000000000000000LL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=150;
//ここまでテンプレ
int main() {
	int N;
	cin>>N;
	bool F[SIZE][10]={};
	int P[SIZE][10]={};
	for(int i=0;i<N;i++){
		for(int j=0;j<10;j++){
			cin>>F[i][j];
		}
	}
	for(int i=0;i<N;i++){
		for(int j=0;j<11;j++){
			cin>>P[i][j];
		}
	}
	int maxi=-INF;
	for(int i=1;i<1024;i++){
		int sco=0;
		for(int j=0;j<N;j++){
			int mat=0;
			for(int k=0;k<11;k++){
				if(F[j][k] && (i>>k)&1)
					mat++;
			}
			sco+=P[j][mat];
		}
		maxi=max(maxi,sco);
	}
	cout<<maxi<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int n,temp,count=0;cin>>n;
  	for(int i=0;i<n;i++){
    	cin>>temp;
      	if(temp%2==1){
        	count++;
        }
    }
  cout<<((count%2==0)?"YES":"NO")<<endl;
}

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

int main() {
	int Arr[] = {111,222,333,444,555,666,777,888,999};
	int A; cin >> A;
	for(int pos = 0; ;pos++)
		if(A <= Arr[pos]){
			cout << Arr[pos]; 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 all(x) x.begin(), x.end()
#define mod 1000000007
typedef long long ll;

int main(){
  int n;
  cin >> n;
  vector<int> vec;
  int sum = 0;
  rep(i, n){
    int num;
    cin >> num;
    sum += num;
    vec.push_back(num);
  }
  if(sum % 10 != 0){
    cout << sum << endl;
    return 0;
  }
  sort(all(vec));
  rep(i, n){
    if(vec[i] % 10 != 0){
      cout << sum - vec[i] << endl;
      return 0;
    }
  }
  cout << 0 << endl;
  return 0;
}
    

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

int main()
{
  int n;
  cin >> n;
  
  int a[n];
  int col[9] = {0};
  rep(i,n) 
  {
    cin >> a[i];
    if(a[i] >= 3200)
    {
      col[8]++;
    }else
    {
      col[a[i]/400]++;
    }
  }
 
  int ansmin = 0, ansmax = 0;
  rep(i,8)
  {
    if(col[i] > 0)
    {
      ansmin++;
      ansmax++;
    }
  }
  if(col[8] > 0)
  {
    ansmax += col[8];
  }
  if(ansmin == 0) ansmin = 1;
  
  cout << ansmin << " " << ansmax << endl;
  
}

Measured memory_bytes: 3608
A, B, C, X, Y = map(int, input().split())

res = float("inf")

for i in range(0, max(X, Y) * 2 + 1, 2):
    Amai = max(0, X - i // 2)
    Bmai = max(0, Y - i // 2)
    res = min(res, A * Amai + B * Bmai + C * i)

print(res)


Measured memory_bytes: 65836
n, x, m = map(int, input().split())

mn = min(n, m)
S = set()
A = []
a = x
sum_9 = 0 # sum of pre + cycle

for _ in range(mn):
    if a in S: break
    S.add(a)
    A.append(a)
    sum_9 += a
    a = a*a % m

if len(A) >= mn:
    print(sum_9)
    exit()

pre_len = A.index(a)
cyc_len = len(A) - pre_len
btm_len = (n - pre_len) % cyc_len

cyc_num = (n - pre_len) // cyc_len

pre = sum(A[:pre_len])
cyc = sum_9 - pre
btm = sum(A[pre_len: pre_len + btm_len])

print(pre + cyc * cyc_num + btm)


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

typedef long long ll;

int n, q;
int A[21];

bool solve(int x, int m) {
    if (m == 0) {
        return true;
    }
    if (x >= n) {
        return false;
    }
    bool res;
    res = solve(x+1, m-A[x]) || solve(x+1, m);
    return res;
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> A[i];
    }
    
    cin >> q;
    vector<int>m(q);
    for (int i = 0; i < q; i++) {
        cin >> m[i];
        if (solve(0, m[i])) {
            cout << "yes" << endl;
        } else {
            cout << "no" << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3100
# -*- coding: utf-8 -*-
import math

N = int(input())

#1*N
A_list = [int(math.log10(N)+1)]

A = 2

while A * A <= N:
	if N % A == 0:
		A_list.append(int(math.log10(N/A)+1))
	A += 1

print(min(A_list))

Measured memory_bytes: 3060
import * as fs from 'fs';

namespace AtCoder {
    export interface Paramable {
        readonly args: string[][];
    }

    export interface Task {
        main(this: Task): void;
    }
}

namespace AtCoder.abc073 {
    export class TaskA implements AtCoder.Task, AtCoder.Paramable {
        public constructor(public readonly args: string[][]) {
        }

        public main(this: TaskA): void {
            const n: string = this.args[0][0];
            const ans: string = n.indexOf('9') > -1 ? 'Yes' : 'No';
            console.log(ans);
        }
    }

    const args: string[][] = fs.readFileSync('/dev/stdin', 'utf8').trim().split('\n').map(r => r.split(' '));
    const task: AtCoder.Task = new TaskA(args);
    task.main();
}



Measured memory_bytes: 7372
H, W = map(int, input().split())
table = []
for _ in range(H):
    table.append(input())
w = sum(v.count(".") for v in table)    
dist = [[-1 for _ in range(W)] for _ in range(H)]
dist[0][0] = 0
import queue
qu = queue.Queue()
qu.put((0,0))
while not qu.empty():
    x,y = qu.get()
    for dx,dy in ((1,0), (0,1), (-1,0), (0,-1)):
        nx,ny = dx + x , dy + y
        if nx >= 0 and nx < H and ny >= 0 and ny < W:            
            if table[nx][ny] == "." and dist[nx][ny] == -1:
                dist[nx][ny] = dist[x][y] + 1
                qu.put((nx,ny))
if dist[-1][-1] == -1:
    print(-1)
else :
    print(w - (dist[-1][-1] + 1))


Measured memory_bytes: 4080
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N;
    cin >> N;
    char S[N];
    cin >> S;
    
    /* a . b # */
    long long a[N];
    long long b[N];
    
    if(S[0] == '.'){
        a[0] = 1;
        b[0] = 0;
    } else{
        a[0] = 0;
        b[0] = 1;
    }
    
    for(int i = 1; i < N; i++){
        if(S[i]=='.'){
            a[i] = a[i-1] + 1;
            b[i] = b[i-1];
        } else{
            a[i] = a[i-1];
            b[i] = b[i-1] + 1;
        }
    }
    
    long long ans = 10000000;
    for(int i = 0; i < N; i++){
        ans = min(ans, b[i] + a[N-1] - a[i]);
    }
    
    ans = min(ans, a[N-1]);
    cout << ans << endl;
   
}


Measured memory_bytes: 3584
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;

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

		// 1行目、複数数字
		String[] ss0 = br.readLine().trim().split(" ", 0);

		String s = ""+(char)(ss0[0].charAt(0))+(char)(ss0[1].charAt(0))+(char)(ss0[2].charAt(0));  //=>"b"
		


        System.out.println(s.toUpperCase());
        return;
    }


}



Measured memory_bytes: 22484
#include<bits/stdc++.h>
#define ll long long
#define all(a) a.begin(),a.end()
#define sz(a) a.size()
#define re return 
#define MP make_pair
#define pb push_back
#define pii pair<int,int>
#define se second
#define fi first
using namespace std;
map<int,int> mp;
int n,ans;
signed main(){
	ios_base::sync_with_stdio(0);
	cin>>n;
	while(n--){
		int a;
		cin>>a;
		mp[a]++;
	}
	for(map<int,int>::iterator it=mp.begin();it!=mp.end();it++) if(it->se%2) ans++;
	cout<<ans;
	re 0;
}

Measured memory_bytes: 8208
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> u(N);
  for (int i = 0; i < N; i++) {cin >> u.at(i);}
  sort(u.begin(), u.end());
  double D = u.at(0);
  for (int i = 1; i < N; i++) {
    D += u.at(i);
    D /= 2.0;
  }
  cout << D << endl;
}

Measured memory_bytes: 3736
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int N;
vector<int>A;

ll ch(ll b)
{
	ll t=0;
	for(int i=0;i<N;i++)
	{
		t+=abs(A[i]-b);
	}
	return t;
}

int main()
{
	cin>>N;
	for(int i=0;i<N;i++)
	{
		int a;
		cin>>a;
		A.push_back(a-i-1);
	}
	sort(A.begin(),A.end());
	ll c;
	int mp=A.size();
	if(A.size()%2==0)
	{
		ll ms=A[mp/2-1]+A[mp/2];
		c=min(ch(ms/2),ch(ms/2+1));
	}
	else
	{
		c=ch(A[mp/2]);
	}
	cout<<c<<endl;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define X           first
#define Y           second
#define pb          push_back
#define mp          make_pair
#define SZ(X)       (X.size())
#define mst(a,b)    memset((a),(b),sizeof(a))
#define lowbit(a)   ((a)&(-a))
using namespace std;
typedef unsigned long long ull;
typedef long long LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int mod=1e9+7;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int maxn=5500;
inline int add(int x,int y){
    if((x+=y)>=mod)x-=mod;
    return x;
}
inline int mul(int x,int y){
    return (ll)x*y%mod;
}
inline int sub(int x,int y){
    if((x-=y)<0)x+=mod;
    return x;
}
int ci[maxn];
vector<int>to[maxn];
int dp[maxn][maxn];//dp[pos][i] 子树,有i个点未匹配
                //子树自匹配完是不合法的,所以dp[pos][0]表示以pos为根的子树匹配完,但pos的儿子们的子树未匹配完
int sz[maxn],uu[maxn];
void dfs(int pos,int fa){
    sz[pos]=1;
    dp[pos][1]=1;
    for(int d:to[pos])if(d!=fa){
        dfs(d,pos);
        for(int i=0;i<=sz[pos]+sz[d];++i)
            uu[i]=0;
        for(int i=0;i<=sz[pos];++i)
            for(int j=0;j<=sz[d];++j)
            uu[i+j]=add(uu[i+j],mul(dp[pos][i],dp[d][j]));
        sz[pos]+=sz[d];
        for(int i=0;i<=sz[pos];++i)
            dp[pos][i]=uu[i];
    }
    for(int i=2;i<=sz[pos];i+=2)
        dp[pos][0]=sub(dp[pos][0],mul(dp[pos][i],ci[i]));
}
int main() {
#ifdef local
    freopen("in.txt", "r", stdin);
#endif // local
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    ci[0]=1;
    for(int i=2;i<maxn;i+=2)
        ci[i]=mul(ci[i-2],i-1);
    int n;cin>>n;
    for(int i=1;i<n;++i){
        int a,b;cin>>a>>b;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    dfs(1,0);
    cout<<(mod-dp[1][0]);

    return 0;
}


Measured memory_bytes: 108672
using System;

namespace ALDS1
{
    class Program
    {
        private static int Prime(int a)
        {
            for(int i = 2; i <= Math.Sqrt(a); i++)
                if (a % i == 0) return 0;
            return 1;
        }

        static void Main()
        {
            int c = 0;
            int l = int.Parse(Console.ReadLine());
            while (l-- > 0)
                c += Prime(int.Parse(Console.ReadLine()));
            Console.WriteLine(c);
        }
    }
}

Measured memory_bytes: 9260
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int sum = 0;

		int ave = 0;

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

			int score = sc.nextInt();

			if(score<40) score = 40;

			sum += score;
		}

		ave = sum/5;

		System.out.println(ave);
	}

}



Measured memory_bytes: 26328
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n;
	cin>>n;

	int cnt = 0;
	for(int i=1; i<=n; i++)
	{
		if(to_string(i).length()%2==1)
		{
			cnt++;
		}
	}
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define endl '\n'
#define lcm( a, b ) ((a)/__gcd(a,b)*(b))
#define MP make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<int, P> i_P;
typedef pair< LL, LL > L_P;

const int INF = INT_MAX;
const int MIN = INT_MIN;
const LL LINF = LLONG_MAX;
const int MOD = 1000000000 + 7;
const int SIZE = 100005;

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

    int n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    a--; b--; c--; d--;
    string s;
    cin >> s;
    bool flg = true;
    for( int i = a + 1; i < max( c, d ); ++i ) {
        if( s[i - 1] == '#' && s[i] == '#' ) flg = false;

    }

    if( !flg ) {
        cout << "No" << endl;
        return 0;

    }
    if( c < d ) {
        cout << "Yes" << endl;
        return 0;

    }

    int cont = 0;
    int mx = 0;
    if( s[b - 1] == '.' ) ++cont;
    for( int i = b; i <= d; ++i ) {
        if( s[i] == '#' ) {
            mx = max( cont, mx );
            cont = 0;

        } else {
            ++cont;

        }
    }

    if( d + 1 != n && s[d + 1] == '.' ) {
        ++cont;

    }
    mx = max( cont, mx );
    if( mx >= 3 ) cout << "Yes";
    else cout << "No";
    cout << endl;
}


Measured memory_bytes: 592
#include <bits/stdc++.h>
#include <set>
#include <queue>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++) 
#define reps(i, s, n) for (int i = s; i < (int)(n); i++) 
#define ll long long
#define ld long double
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++) 
#define repsl(i, s, n) for (ll i = s; i < (ll)(n); i++)  
#define outdeb(fir, sec, thr) cout << fir << ":" << sec << ":" << thr << endl
#define readVarll(nam) ll nam; cin >> nam

ll x[20],y[20];
ll n;

#define DEV_VAL 1000000007
ll mulbig(ll a, ll b)
{
  return (a * b) % DEV_VAL; 
}

ll addbig(ll a, ll b)
{
  return (a + b) % DEV_VAL;
}

ll powbig(ll a, ll b)
{
  ll ans = 1;
  repl(i, b)
  {
    ans = mulbig(ans, a);
  }
  return ans;
}

ll subbig(ll a, ll b)
{
  ll ans = a - b;
  while(ans < 0)
  {
    ans = addbig(ans, DEV_VAL);
  }
  return ans;
}

ll d[2001][2001];

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

  rep(i, n + 1)
  rep(j, n + 1)
  {
    d[i][j] = 1;
  }

  if(n < 3)
  {
    cout << fixed << 0 << endl;
    return 0;
  }

  ll ans = 1;
  repsl(i, 2, 2001)
  {
    repsl(j, 1, 2001)
    {
      d[i][j] = addbig(d[i-1][j], d[i][j-1]);  
    }
  }

  repsl(i, 2, n/3+1)
  {
    ans = addbig(ans, d[i][n - 3*i]);
  }
  
  cout << fixed << ans << endl;
  return 0;
}

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

using namespace std;

#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define whole(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;

const int N = (int)1e5 + 2;
const int LG = 20;
const ll mod = (int)1e9 + 7;
const int INF = (int)1e9 + 7;
const ll linf = 1e13;
const ld pi = acos(-1);
const int base = 10;
const ld EPS = 1e-9;

int n, w;
ll dp[N], a[105], b[105];
int main ()
{
    scanf ("%d %d", &n, &w);
    for (int i = 1; i <= n; ++i)
    {
        scanf ("%lld %lld", a + i, b + i);
    }
    for (int i = 0; i < N; ++i) dp[i] = linf;
    dp[0] = 0;
    for (int i = 1; i <= n; ++i)
    {
        for (int j = N - 1; j >= b[i]; --j)
        {
            dp[j] = min(dp[j], dp[j - b[i]] + a[i]);
        }
    }
    ll ans = 0;
    for (int i = N - 1; i >= 0; --i)
    {
        if (dp[i] <= w) ans = max(ans, 1ll * i);
    }
    printf ("%lld\n", ans);
    return 0;
}


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

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 (b<a) { a=b; return 1; } return 0; }

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void vprint(vector<ll> A){
    ll L = A.size();
    FOR(i, 0, L){
        if(i) cout << ' ';
        cout << A[i];
    }
    cout << endl;
}

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

    // input
    ll n,a,b;
    cin >> n>>a>>b;

    ll cost0 = a*n;
    ll cost1 = b;

    ll ans = min(cost0, cost1);
    p(ans);    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;

/* --------------------------------------------------- */

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

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

int main() {
    int x;
    cin >> x;
    ll n = lcm(x, 360);
    cout << n / x << endl;

    return 0;
}

Measured memory_bytes: 3588
n = int(input())
a = list(map(int, input().split()))
ab = [abs(i) for i in a]
cnt = 0
for i in a:
    if i < 0:
        cnt += 1
if 0 in a or cnt % 2 == 0:
    print(sum(ab))
else:
    print(sum(ab) - min(ab) * 2)

Measured memory_bytes: 14284
using System;


namespace ConsoleApplication1
{

    // input W a b

    class NarrowRectanglesEasy
    {
        static void Main(string[] args)
        {
            // get a integer
            // int a = int.Parse(Console.ReadLine());
            // get two integers separated with half-width break
            string[] input = Console.ReadLine().Split(' ');
            int W = int.Parse(input[0]);
            int a = int.Parse(input[1]);
            int b = int.Parse(input[2]);


            if (a <= b)
            {

                if ((a + W) >= b) { Console.WriteLine(0); }
                if ((a + W) < b) { Console.WriteLine(Math.Abs(b - (a + W))); }

            }
            else {
                if ((b + W) >= a) { { Console.WriteLine(0); } }
                if ((b + W) < a) { { Console.WriteLine(Math.Abs(a-(b+W))); } }
            }

        }

    }
}


Measured memory_bytes: 13140
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
#include <functional>
#include <random>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vvvl> vvvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef long double LD;
typedef vector<LD> vld;
typedef vector<pair<LD, LD>> vpld;
typedef pair<ll, ll> PL;
typedef vector<PL> vpl;
typedef vector<vector<PL>> vvpl;
typedef vector<vvpl> vvvpl;
typedef pair<ll, PL> TL;
typedef vector<TL> vtl;
typedef vector<vtl> vvtl;
typedef long double ld;
typedef vector<ld> vld;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back
#define ALL(X) (X).begin(),(X).end()

template <typename T> T gcd(T a, T b) {return (a == 0) ? b : gcd(b%a, a);}
template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b;}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec /* copy */){
    sort(ALL(vec)); vec.erase(unique(vec.begin(), vec.end()), vec.end()); return vec;
}

inline ll popcnt(ll x){return __builtin_popcountll((unsigned long long)x);};
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
//friend bool operator<(const tpl& lhs, const tpl& rhs){
//    return std::tie(lhs.l, lhs.r) < std::tie(rhs.l, rhs.r);
//}

bool bit(ll st, ll b){return ((st>>b)&1) == 1;}


int main(){
#ifdef __DEBUG_LOCAL__
    ifstream file("../../../../../in.txt"); if(file.is_open()) cin.rdbuf(file.rdbuf());
#endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    
    vl v = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    ll K; cin >> K; K--;
    cout << v[K] << endstr;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define nl "\n"
#define rep(i,n) for(ll i=0; i<(n); i++)
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007 //998244353
typedef vector<ll> vl;
typedef vector<vl> matrix;//A(n, vl(m)); //n*m行列
typedef vector<string> vs;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
typedef vector<bool> vb;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define Sortup(V) sort(V.begin(), V.end())
#define Sortdown(V) sort(V.rbegin(), V.rend())
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(b<a){a=b;return 1;}return 0;}
void CumuSum(vl &A){rep(i,A.size())if(i)A[i]+=A[i-1];}
ll llpow(ll e,ll x){ll res=1LL;while(x){if(x&1)res*=e;e*=e;x/=2;}return res;}
ll llpowMOD(ll e,ll x){ll res=1LL;while(x){if(x&1)res*=e;e*=e;x/=2;res%=MOD;e%=MOD;}return res;}

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

    // solution comes here

    ll N;
    cin >> N;
    vl a(N), b(N);
    rep(i, N) cin >> a[i];
    rep(i, N) cin >> b[i];

    ll sumA=0, sumB=0, lim;
    rep(i, N) {sumA+=a[i]; sumB+=b[i];}
    lim = sumB - sumA;

    ll cnt=0;
    rep(i, N) {
        if(a[i] <= b[i]) cnt += (b[i]-a[i]+1) / 2;
        //else cnt += a[i] - b[i];
    }

    if(cnt <= lim) cout << "Yes" << nl;
    else           cout << "No" << nl;
}

Measured memory_bytes: 384
n = int(input())
dic = {}
for _ in range(n):
  si = str(input())
  li = [si[i] for i in range(10)]
  li.sort()
  moji = "".join(li)
  if moji in dic.keys():
    dic[moji] += 1
  else:
    dic[moji] = 1
sm = 0
for j in dic.values():
  sm += j*(j-1)//2
print(sm)

Measured memory_bytes: 17888
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define loop(i, a, n) for(int i = (a); i < (n); i++)
#define sorn(i, n) char((i == n-1)?'\n':' ')
using namespace std;
using ll = int64_t;

int main(){
    int h, w, k; cin >> h >> w >> k;
    char board[h][w];
    rep(i, h)rep(j, w) cin >> board[i][j];

    int ans = 0;
    rep(i, 1<<h){
        rep(j, 1<<w){
            int tmp = 0;
            rep(bi, h){
                rep(bj, w){
                    if(((i >> bi) & 1) && ((j >> bj) & 1) && board[bi][bj] == '#') tmp++;
                }
            }
            if(k == tmp) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define iss istringstream
#define sst stringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sh(i) (1LL<<i)
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

int dp[19][19];
string s;

int main(){
	cin>>s;
	int p=s.find('i');
	string t=s.substr(0,p),u=s.substr(p+3);
	reverse(u.begin(),u.end());
	rep(i,u.sz){
		if(u[i]=='(')u[i]=')';
		else if(u[i]==')')u[i]='(';
		if(u[i]=='[')u[i]=']';
		else if(u[i]==']')u[i]='[';
		if(u[i]=='{')u[i]='}';
		else if(u[i]=='}')u[i]='{';
	}
	rep(i,t.sz)rep(j,u.sz)dp[i+1][j+1]=max(dp[i][j]+(t[i]==u[j])*2,max(dp[i][j+1],dp[i+1][j]));
	cout<<dp[t.sz][u.sz]+3<<endl;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
    int n; cin >> n;
    auto v = make_v(3, n, 0);
    
    REP(i, 3) REP(j, n) {
        cin >> v[i][j];
    }
    
    REP(i, 3) {
        sort(v[i].begin(), v[i].end());
    }

    ll ans = 0;

    REP(i, n) {
        auto it1 = lower_bound(v[0].begin(), v[0].end(), v[1][i]);
        auto it2 = upper_bound(v[2].begin(), v[2].end(), v[1][i]);

        ans += (it1 - v[0].begin()) * (v[2].end() - it2);
    }

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


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

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

void chmax(int &l, int r){if(l<r)l=r;}

int main(){

  int n, d, x; cin>> n>> d>> x;
  int p[d][n];
  rep(i, d)rep(j, n) cin>> p[i][j];

  // dp[j][k]:=i日目、種類jまで見て、k円持ってるときの、翌日の所持金の最大
  const int M=100005;
  int dp[n+1][M];
  rep(i, n+1)rep(j, M) dp[i][j]=0;
  rep(i, d-1){
    rep(i, n+1)rep(j, M) dp[i][j]=0;    
    for(int k=0; k<=x; k++) dp[0][k]=k; // ?
    rep(j, n){
      for(int k=0; k<=x; k++){
        chmax(dp[j+1][k], dp[j][k]);
        if(k-p[i][j]>=0){
          chmax(dp[j+1][k], dp[j+1][k-p[i][j]]+p[i+1][j]);
        }
      }
    }
    int y=0;
    for(int k=0; k<=x; k++) chmax(y, dp[n][k]);
    x=y;
  }

  cout<< x<< endl;

  return 0;
}


Measured memory_bytes: 7392
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// to container
template <class C>
void input(C &c)
{
    for_each(c.begin(), c.end(), [](auto &i) { cin >> i; });
}

// to number, string
template <class T>
T input()
{
    T data;
    cin >> data;
    return data;
}

ull gcd(ull a, ull b)
{
    if (a < b)
    {
        return gcd(b, a);
    }
    ull r;
    while ((r = a % b))
    {
        a = b;
        b = r;
    }

    return b;
}

int main()
{
    ull A = input<ull>(), B = input<ull>();
    ull div = gcd(A, B);

    set<ull> primes;
    primes.insert(1);

    ull i = 2;
    for (ull i = 2; i <= (ull)sqrt(div) + 1; i++)
    {
        while (div % i == 0)
        {
            div /= i;
            primes.insert(i);
        }
    }

    if (div > 1)
        primes.insert(div);

    cout << primes.size() << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
int mpow(int base, int exp); 
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vi g[N];
long long int a[N];

void solve(){
	long long int i, j, k, p, q, r, x, y, u, v, n, m;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    u=a[0];
    v=0;
    for(i=0;i<n;i++){
        if(a[i]<u){
            v+=u-a[i];
        }
        u=max(u,a[i]);
       // deb(u);
      //  deb(v);
    }
cout<<v<<endl;

}

int main() {
	ios_base::sync_with_stdio(0);
	int i,t=1;
	//cin>>t;
	for(i=1;i<=t;i++){
		solve();
	}
	return 0;
}

int mpow(int base, int exp) {
	base %= mod;
	int result = 1;
	while (exp > 0) {
		if (exp & 1) result = ((ll)result * base) % mod;
		base = ((ll)base * base) % mod;
		exp >>= 1;
	}
	return result;
}

void ipgraph(int n, int m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
		g[u-1].pb(v-1);
		g[v-1].pb(u-1);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}




Measured memory_bytes: 12208
import java.util.*; 
import java.io.*;

public class Main {
    static StringTokenizer st;
    static BufferedReader br;  
    static PrintWriter out;
 
    public static void main(String[] args) throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));

        int D = nextInt();
        int T = nextInt();
        int S = nextInt();

        if( T * S >= D) {
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        };

        

    }
    
      
    public static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }
    public static long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    public static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    static String next() throws IOException {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine().trim());
        return st.nextToken();
    }
}

Measured memory_bytes: 32700
N = int(input())
A = list(map(lambda x: int(x)-1,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

def it():
    for x,y in zip(A,A[1:]):
        if x+1 == y:
            yield C[x]
    for x in A:
        yield B[x]
print(sum(it()))

Measured memory_bytes: 38516
#include<iostream>
#include<string>
using namespace std;
int main(){
  string julius;
  cin >> julius;
  for(int i=0;i<julius.size();i++){
    if(julius[i]>=68 && julius[i]<=90){
      julius[i]-=3;
    }else if(julius[i]>=88 && julius[i]<=90){
      julius[i]-=23;
    }else if(julius[i]>=65 && julius[i]<=67){
      julius[i]+=23;
    }
  }
  cout << julius << endl;
  return 0;
}

Measured memory_bytes: 1180