akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
typedef long long LL;
using namespace std;
const int N = 3e3 + 5;

char seq[N * 2];
int locAll[N * 2];
int locA[N];
int locB[N];
int dp[N][N];
int n;
string toString(int num[]) {
    string tmp;
    for(int i = 1; i <= 2*n; ++i) {
        if(num[locAll[i]]) 
            tmp += seq[i];
    }
    return tmp;
}

int main() {
    while(~scanf("%d", &n)) {
        memset(dp, 0, sizeof(dp));
        scanf("%s", seq + 1);
        for(int i = 1, cntA = 0, cntB = 0; i <= 2*n; ++i) {
            if(seq[i] == 'a') {
                locA[++cntA] = i;
                locAll[i] = cntA;
            } else {
                locB[++cntB] = i;
                locAll[i] = cntB;
            }
        }
        dp[n][n] = 1;

        for(int i = n-1; i >= 1; --i) {
            dp[i][i] = 1;
            if(locA[i] < locB[i]) {
                int Max = 0;
                for(int j = locA[i]; j <= locB[i]; ++j) {
                    if(locAll[j] < i)
                        continue;
                    Max = max(Max, locAll[j]);
                }
                for(int j = locB[i]+1; j <= 2*n; ++j) {
                    if(locAll[j] > Max)
                        dp[i][locAll[j]] = dp[Max + 1][locAll[j]];
                }
            } else {
                int tot = 0, Max = 0;
                for(int j = locB[i]; j <= locA[i]; ++j) {
                    if(locAll[j] < i)
                        continue;
                    if(locAll[j] != i) tot ++;
                    Max = max(Max, locAll[j]);
                    dp[i][locAll[j]] = 1;
                }    

                for(int j = locA[i]+1; j <= 2*n; ++j) {
                    if(seq[j] == 'b') {
                        if(tot == 0) {
                            dp[i][locAll[j]] = dp[Max+1][locAll[j]];
                        } else {
                            dp[i][locAll[j]] = 1;
                            tot ++;
                        }
                    } else {
                        if(tot == 0) {
                            dp[i][locAll[j]] = dp[Max+1][locAll[j]];
                        } else {
                            dp[i][locAll[j]] = 1;
                            Max = max(Max, locAll[j]);
                            tot --;
                        }
                    }
                }
                
            }
            if(toString(dp[i]) < toString(dp[i + 1])) {
                memcpy(dp[i], dp[i + 1], sizeof(dp[i + 1]));
            }
        }

        printf("%s\n", toString(dp[1]).c_str());

    }
    return 0;
}

Measured memory_bytes: 35584
#include <iostream>
#include <vector>
#include <algorithm>
long long N, Q;
std::vector<std::vector<long long>> G;
std::vector<long long> count;
std::vector<long long> ans;
std::vector<int> used;
void dfs(int n, long long sum){
    if(G[n].size() == 0) return;
    used[n] = 1;
    for(int i: G[n]){
        if(used[i] == 0){
            ans[i] = sum + count[i];
            dfs(i, sum + count[i]);
        }
    }
}
int main(){
    std::cin >> N >> Q;
    count.resize(N, 0);
    G.resize(N);
    used.resize(N, 0);
    ans.resize(N, 0);
    for(int i = 0; i < N - 1; i++){
        int a, b;
        std::cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    for(int i = 0; i < Q; i++){
        long long p, x;
        std::cin >> p >> x;
        p--;
        count[p] += x;
    }
    ans[0] = count[0];
    dfs(0, count[0]);
    for(int i = 0; i < N; i++){
        std::cout << ans[i] << ' ';
        if(i == N - 1) std::cout << std::endl;
    }
}

Measured memory_bytes: 23552
#define lp(i,n) for(int i=0;i<n;i++)
#define pau system("pause")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;

int main(){
    int n,m,ans;
    cin>>n;
    vector<int>t(n);
    lp(i,n)
        cin>>t[i];
    cin>>m;
    vector<vector<int>>p(m,vector<int>(2));
    lp(i,m)
        cin>>p[i][0]>>p[i][1];
    lp(i,m){
        ans=0;
        lp(j,n){
            if(p[i][0]==(j+1))
                ans+=p[i][1];
            else
                ans+=t[j];
        }
        cout<<ans<<endl;
    }
}


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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define ALL(x) x.begin(), x.end()
#define LL long long
#define ULL unsigned long long
#define TIME cout << "Time elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms" << endl;

const int MOD = (int)1e9 + 7, MAXN = (int)1e5 + 10;
int n;
VI A;

int mul(int a, int b) {
	return (1ll * a * b) % MOD;
}

int sub(int a, int b) {
	a -= b;
	return a < 0 ? a + MOD : a;
}


int fact[MAXN], finv[MAXN], inv[MAXN];
void precalc()
{
	fact[0] = fact[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for(LL i = 2; i < MAXN; ++i) {
		inv[i] = sub(MOD, mul(inv[MOD % i], MOD / i));
		fact[i] = mul(fact[i - 1], i);
		finv[i] = mul(finv[i - 1], inv[i]);
	}
}

int comb(int n, int r)
{
	if(n < r) return 0;
	return mul(fact[n], mul(finv[r], finv[n - r]));
}

void solve()
{
	precalc();

	int dist;
	VI pos(MAXN + 1, -1);
	for(int i = 0; i < n + 1; ++i) {
		if(pos[A[i]] != -1) {
			dist = i - pos[A[i]];
			break;
		}
		pos[A[i]] = i;
	}
	
	for(int len = 1; len <= n + 1; ++len) {
		int whole = comb(n + 1, len), remain = comb(n - dist, len - 1);
		cout << sub(whole, remain) << '\n';
	}
	cout << flush;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cout.tie(0);
	cin.tie(0);
#ifndef ONLINE_JUDGE
//	freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
    cin >> n;

	A = VI(n + 1, 0);
	REP(i, 0, n + 1) cin >> A[i];

	solve(); 

	return 0;
}

Measured memory_bytes: 3200
import math

n=int(input())
p=list(map(int,input().split()))
q=list(map(int,input().split()))


def fun(x):
    
    count=0
    
    for k in range(len(x)-1):
        count+=math.factorial(len(x)-1)*sum(i<x[0] for i in x)
        del x[0]
        
    return count+1

a=fun(p)
b=fun(q)

print(abs(a-b))

Measured memory_bytes: 3064
import java.io.*

val pw = PrintWriter(System.out)
const val MOD = 1000000007L
const val INF = 2147483647
const val LINF = 9223372036854775807L

fun main(args: Array<String>) {
    solve()
    pw.flush()
}

fun solve() {
    val (n, m) = nextIntList()
    val a = nextIntList()
    val sum = a.sum()
    var count = 0
    val tmp = 4 * m
    for (b in a){
        if(b >= (sum + tmp - 1) / tmp) count++
    }

    println(if(count >= m) "Yes" else "No" )

}


fun println(v: String) {
    pw.println(v)
}

fun print(v: String) {
    pw.print(v)
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ").toMutableList()
fun nextIntList(index: Int = 0) = next().split(" ").map { it.toInt() + index }.toMutableList()
fun nextLongList(index: Long = 0L) = next().split(" ").map { it.toLong() + index }.toMutableList()
fun nextDoubleList() = next().split(" ").map { it.toDouble() }.toMutableList()

fun ary(n: Int, init: String = "") = Array(n) { init }
fun intAry(n: Int, init: Int = 0) = IntArray(n) { init }
fun longAry(n: Int, init: Long = 0L) = LongArray(n) { init }
fun doubleAry(n: Int, init: Double = 0.0) = DoubleArray(n) { init }
fun ary2(n: Int, m: Int, init: String = "") = Array(n) { Array(m) { init } }
fun intAry2(n: Int, m: Int, init: Int = 0) = Array(n) { IntArray(m) { init } }
fun longAry2(n: Int, m: Int, init: Long = 0) = Array(n) { LongArray(m) { init } }
fun doubleAry2(n: Int, m: Int, init: Double = 0.0) = Array(n) { DoubleArray(m) { init } }
fun ary3(n: Int, m: Int, k: Int, init: String = "") = Array(n) { Array(m) { Array(k) { init } } }
fun intAry3(n: Int, m: Int, k: Int, init: Int = 0) = Array(n) { Array(m) { IntArray(k) { init } } }
fun longAry3(n: Int, m: Int, k: Int, init: Long = 0L) = Array(n) { Array(m) { LongArray(k) { init } } }
fun doubleAry3(n: Int, m: Int, k: Int, init: Double = 0.0) = Array(n) { Array(m) { DoubleArray(k) { init } } }

fun abs(n: Int): Int = Math.abs(n)
fun abs(n: Long): Long = Math.abs(n)
fun abs(n: Double): Double = Math.abs(n)
fun max(vararg values: Int) = if (values.isEmpty()) -INF else values.max()!!
fun max(vararg values: Long) = if (values.isEmpty()) -LINF else values.max()!!
fun min(vararg values: Int) = if (values.isEmpty()) INF else values.min()!!
fun min(vararg values: Long) = if (values.isEmpty()) LINF else values.min()!!

Measured memory_bytes: 37728
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
//#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
        

fast();
//ll t;cin>>t;while(t--)
{
    ll n;
    cin>>n;
    ll a[n],pre[n];
    for(int i=0;i<n;i++)
    {
      cin>>a[i];
      if(i==0)
        pre[i]=a[i]%mod;    // here
      else
        pre[i]=(a[i]+pre[i-1])%mod;   //here
    }
    //for(auto t:)cerr<<t<<" ";cerr<<endl;
    ll ans=0;
    for(int i=0;i<n;i++)
    {
      ll temp=pre[n-1]-pre[i];
      if(temp<0)
        temp+=mod;
      //ans+=((pre[n-1]-pre[i]+mod)%mod*a[i]%mod)%mod;
      ans+=(temp*a[i])%mod;
      ans=ans%mod;
    }
    cout<<ans<<endl;

}
return 0;
}

Measured memory_bytes: 6716
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
#include <map>
#include <set>
#include <bitset>
#include <fstream>
#include <iomanip>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    long long int  n;
    cin >> n;
    vector<vector<long long int>> grid(3,vector<long long int>(n));
    REP(i,3){
        REP(j,n){
            cin >> grid[i][j];
            if(i==0){
                grid[i][j] *= -1;
            }
        }
        sort(grid[i].begin(), grid[i].end());
    }
    long long int result = 0,tmp;

    REP(i,n){

        result += abs(distance(grid[0].end(), upper_bound(grid[0].begin(), grid[0].end(), -grid[1][i])) *
                      distance(grid[2].end(), upper_bound(grid[2].begin(), grid[2].end(), grid[1][i])));
    }
    cout << result << endl;
}


Measured memory_bytes: 3328
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<deque>
#include<queue>
using namespace std;

using ll = long long;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001;
const int MOD = 1000000007;

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

int light[1000005];
vector<vector<int>> miti(1000005);

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

  rep(i, m) {
    int a, b;
    cin >> a >> b;
    miti[a].push_back(b);
    miti[b].push_back(a);
  }

  deque<pair<int, int>> next;
  for (int x : miti[1]) {
    next.push_back(make_pair(x, 1));
  }
  do {
    deque<pair<int, int>> nn;
    for(pair<int, int> x : next) {
      if (light[x.first] == 0) {
        light[x.first] = x.second;
        for (int y : miti[x.first]) {
          if (light[y] == 0) {
            nn.push_back(make_pair(y, x.first));
          }
        }
      }
    }
    next = nn;
  } while (!next.empty());

  bool ok = true;
  for (int i = 2; i <= n; i++) {
    if (light[i] == 0) ok = false;
  }
  if (!ok) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
    for (int i = 2; i <= n; i++) {
      cout << light[i] << endl;
    }
  }
}


Measured memory_bytes: 34188
N, K = list(map(int, input().split()))
H = list(map(int, input().split()))

INF = 10**6

# DP = [INF] * N
# DP = [INF] * ((10**5)+10)
DP = [float('inf')] * N
DP[0] = 0

# for i in range(1, N):
#     for j in range(1, K+1):
#         if 0 <= i - j < N:
#             DP[i] = min(DP[i], DP[i-j] + abs(H[i-j] - H[i]))

for i in range(1, N):
    for j in range(1, K + 1):
        # if 0 <= i - j < N:
        if i - j < 0:
            break
        DP[i] = min(DP[i], DP[i - j] + abs(H[i] - H[i - j]))

print(DP[N-1])
# print(DP)

Measured memory_bytes: 54880
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
  int y,m,d;
  while(cin>>y>>m>>d) {
    int a;
    if (y<1868||y==1868&&m<9||y==1868&&m==9&&d<8) {
      cout << "pre-meiji";
      a = -1;
    } else if (y<1912||y==1912&&m<7||y==1912&&m==7&&d<=29) {
      cout << "meiji";
      a = y-1868;
    } else if (y<1926||y==1926&&m<12||y==1926&&m==12&&d<=24) {
      cout << "taisho";
      a = y-1912;
    } else if (y<1989||y==1989&&m<1||y==1989&&m==1&&d<=7) {
      cout << "showa";
      a = y-1926;
    } else {
      cout << "heisei";
      a = y-1989;
    }
    if (a>=0) {
      printf(" %d %d %d",a+1, m, d);
    }
    cout << endl;
  }
}

Measured memory_bytes: 0
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

int64 sqr(int64 x) {
  return x * x;
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int64 sum = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    sum += a[i];
  }
  sum /= n;
  int64 ret = 1LL << 60;
  for (int k = 0; k < 2; ++k) {
    int64 cur = 0;
    for (int i = 0; i < n; ++i) {
      cur += sqr(a[i] - sum - k);
    }
    ret = min(ret, cur);
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,s,f) for(i=s;i<f;i++)
#define print(v) for(auto &z:v) cout<<z<<' ';cout<<'\n'
#define hi cout<<'h'<<'i'<<'\n' 
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define B begin()
#define E end()
#define sz(v) (int)((v).size())
#define vi vector<int>
#define vii vector<pair<int,int>>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define clk1 clock_t start_time=clock()
#define clk2 cout<<(clock()-start_time)/(double)CLOCKS_PER_SEC
#define clean(arr) memset(arr,0,sizeof(arr))
#define mod 1000000007
#define mod2 998244353
#define space 100005
//<<fixed << setprecision(9)
vector<int> arr[space];
int main()
{
    int n,i,j,t;
    boost;
    int k,m;
    cin>>n>>m;
    rep(i,0,m)
    {
        string s;
        cin>>j>>s;

        arr[j].pb(s[0]=='A');
    }
    int c=0,p=0;
    rep(i,1,n+1)
    {
        bool ok=0;
        for(auto &z:arr[i])
        {
            if(z==1)ok=1;
        }
        if(ok)
        {
            c++;
            for(auto &z:arr[i])
            {
                if(z)break;
                p++;
            }
        }
    }
    cout<<c<<" "<<p;
}



Measured memory_bytes: 5760
n = int(input())

for _ in range(n):
    record = input()
    record = list(record)

    ans = [record.pop(0)]
    while record != []:

        arrow = record.pop(0)
        record.pop(0)
        train = record.pop(0)

        if train not in ans:
            if arrow == "-":
                ans.append(train)
            else:
                ans.insert(0, train)

    print(''.join(str(a) for a in ans))



Measured memory_bytes: 5628
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

vector<ll> divisor(ll n) {
  vector<ll> res;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      if (i * i != n)
        res.push_back(n / i);
    }
  }
  sort(res.begin(), res.end());
  return res;
}

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

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

  vector<ll> v = divisor(m);
  int vn = (int)v.size(), minv = m / n;
  ll ans = 0;
  rep(i, 0, vn) {
    if (v[i] <= minv)
      chmax(ans, v[i]);
  }

  cout << ans << endl;
}


Measured memory_bytes: 3652
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
    long  n=sc.nextLong();
        long a=sc.nextLong();
        long b=sc.nextLong();

        long so=n/(a+b);
        if(a==0){
            System.out.println('0');
            System.exit(0);
        }else if(n%(a+b)<=a){
            System.out.println(a*so + n%(a+b));
            System.exit(0);
        }else{
            System.out.print(a*so+a);
        }
    }
}

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


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

  int n = int(X/100);

  vector<int> data(n);
  data = {100, 101, 102, 103, 104, 105};

  vector<vector<int>> price(n, vector<int>(6));

  bool flag = false;

  for(int i = 0; i < n; i++){
    for(int j = 0; j < 6; j++){
      price.at(i).at(j) = data[j]*(i+1);
      if(price.at(i).at(j)%100==X%100){
        flag = true;
      }
    }
  }


/*  for(int i = 0; i < n; i++){
    for(int j = 0; j < 6; j++){
      cout << price.at(i).at(j) << " ";
    }
    cout << endl;
  }
*/


  if(flag){
    cout << 1 << endl;
  } else {
    cout << 0 << endl;
  }




}


Measured memory_bytes: 256
n, m = map(int, input().split())
a = [list(input()) for i in range(n)]
b = [list(input()) for i in range(m)]
for i in range(n-m+1):
    for j in range(n-m+1):
        flag = True
        if a[i][j] == b[0][0]:
            for k in range(m):
                for l in range(m):
                    if a[i+k][j+l] != b[k][l]:
                        flag = False
                        break
                if not flag:
                    break
        else:
            flag = False
        if flag:
            break
    if flag:
        break
if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define REPD(i,a,b) for (int i=(a);i<=(b);i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
typedef vector<si> vsi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<int> qi;
typedef queue<pi> qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
const int INF = 1001001001;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 円周率　M_PI
// 文字判定　isupper islower
// 文字変換　
// 順列　do {} while(next_permutation(ALL(X)));
// 最大値　LLONG_MAX
// a内でx以上　auto iter = lower_bound(ALL(a), x);
// a内でxより大きい　auto iter = upper_bound(ALL(a), x);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned Euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return Euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int digit_sum(int n) {
  int sum=n%10;
  while(n!=0) {
    n/=10;
    sum+=n%10;
  }
  return sum;
}

vpll PrimeFactorization(ll n) {
  vpll res;
  for (ll i=2; i*i<=n; i++) {
    if(n%i!=0) continue;
    ll ex=0;
    while(n%i==0) {
      ex++;
      n/=i;
    }
    res.push_back(pll(i,ex));
  }
  if(n!=1) res.push_back(pll(n,1));
  return res;
}




int main() {
  ll n;
  cin >> n;
  ll ans=1;
  REP1(i,n) {
    ans=((ans%mod)*(i%mod))%mod;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3500
#include <iostream>
#include <vector>
#define N 201000
using namespace std;
vector <int> v[N], G[3], V[2];
int a[N], n, col[N], ch[N], res[N];
void dfs(int a, int b){
	col[a] = !col[b];
	V[col[a]].push_back(a);
	for(auto &x : v[a]){
		if(x == b) continue;
		dfs(x,a);
	}
}
int main() {
	int a, b;
	cin >> n;
	for(int i = 1; i<= n; i++) G[i%3].push_back(i);
	for(int i = 1; i< n; i++){
		cin >> a >> b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	dfs(1,0);
	int pv = 0;
	if(V[pv].size() > V[!pv].size()) pv = !pv;
	if(V[pv].size() <= G[0].size()){
		int pp = 0;
		for(auto &x: V[pv]){
			res[x] = G[0][pp];
			ch[G[0][pp]] = 1;
			pp++;
		}
	}
	else {
		int pp = 0, pp2 = 0;
		for(auto &x: V[pv]){
			if(pp < G[1].size()){
				res[x] = G[1][pp];
				ch[G[1][pp]] = 1;
				pp++;
			}
			else {
				res[x] = G[0][pp2];
				ch[G[0][pp2]] = 1;
				pp2++;
			}
		}
	}
	vector <int> p;
	for(int i=1; i<=n; i++) if(!ch[i]) p.push_back(i);
	for(int i=0; i<V[!pv].size(); i++) res[V[!pv][i]] = p[i];
	for (int i = 1; i <= n; i++)cout << res[i] << " ";
	return 0;
}

Measured memory_bytes: 22296
unittest
{
	assert( [ "3" ].parse.expand.solve == 6 );
	assert( [ "10" ].parse.expand.solve == 55 );
	assert( [ "1" ].parse.expand.solve == 1 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	return tuple( n );
}

auto solve( long n )
{
	return n * ( n + 1 ) / 2;
}


Measured memory_bytes: 256
#include<stdio.h>

	int main(){
	
	long long int n,k = 0;
	scanf("%lld",&n);
	
	for(int i=1;i<=n;i++){
		if(i % 3 == 0 && i % 5 == 0){
			continue;
		}
		else if(i % 3 == 0){
			continue;
		}
		else if(i % 5 == 0){
			continue;
		}
		else{
			k+=i;
		}
	}

printf("%lld",k);
		return 0;
	}

Measured memory_bytes: 1732
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <climits>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

struct Edge{
    int u,v,cost;
};
struct Node{
    int x,y,id;
};

bool compx(Node& x,Node& y){
    return x.x<y.x ;
}
bool compy(Node& x,Node& y){
    return x.y<y.y;
}
bool compc(Edge& x,Edge& y){
    return x.cost<y.cost;
}

int pare[100000];
int trank[100000];

int find(int u){
    if(u==pare[u]){
        return u;
    }else{
        return pare[u]=find(pare[u]);
    }
}

void unite(int u,int v){
    u=find(u);
    v=find(v);
    if(u==v){
        return;
    }
    if(trank[u]<trank[v]){
        pare[u]=v;
    }else{
        pare[v]=u;
        if(trank[u]==trank[v]){
            trank[u]++;
        }
    }
    return;
}

int main() {
    int N;
    cin>>N;
    vector<Edge> edge;
    vector<Node> node;
    REP(i,N){
        int x,y;
        cin>>x>>y;
        Node node_;
        node_.x=x;
        node_.y=y;
        node_.id=i;
        node.push_back(node_);

        pare[i]=i;
        trank[i]=0;
    }
    sort(node.begin(),node.end(),compx);
    REP(i,N-1){
        Edge edge_;
        edge_.u=node[i].id;
        edge_.v=node[i+1].id;
        edge_.cost=node[i+1].x-node[i].x;
        edge.push_back(edge_);
    }
    sort(node.begin(),node.end(),compy);
    REP(i,N-1){
        Edge edge_;
        edge_.u=node[i].id;
        edge_.v=node[i+1].id;
        edge_.cost=node[i+1].y-node[i].y;
        edge.push_back(edge_);
    }
    sort(ALL(edge),compc);
    long long ans =0;
    REP(i,edge.size()){
        Edge e =edge[i];
        if(find(e.u)!=find(e.v)){
            ans+=e.cost;
            unite(e.u,e.v);
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 6900
#include <algorithm>
#include <bitset>
#include <cmath>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(a) a.begin(),a.end()
using namespace std;
// using ll = long long;
// using P = pair<int,int>;
// using vi = vector<int>;
// using vvi = vector<vi>;




using Graph = vector<vector<int> >;



// 深さ優先探索
vector<int> dire;

void dfs(const Graph &G, int v, int pre) {
  if(dire[v] == 0) dire[v] = pre;
    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) { 
      if (dire[next_v]) continue; // next_v が探索済だったらスルー
      dfs(G, next_v,v); // 再帰的に探索
    }
}




int main() {
  int N,M; cin >> N >> M;
  dire.resize(N+1,0);
  Graph G(N+1);
  rep(i,M) {
    int a,b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  queue<int> q;
  q.push(1);
  while(!q.empty()) {
    int now = q.front(); q.pop();
    for(auto next_v : G[now]) {
      if(dire[next_v] == 0) {
	dire[next_v] = now;
	q.push(next_v);
      }
    }
  }
  cout << "Yes" << endl;

  for(int i=2; i<=N; i++) cout << dire[i] << endl;


  // for(int i=1; i <= N; i++) {
  //   for(auto next : G[i]) {
  //     cout << next;
  //   }
  //   cout << endl;
  // }
  
  
  return 0;
}





Measured memory_bytes: 9812
#include <bits/stdc++.h>  
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define forn(i,a,b)        for( i = a ; i < b  ; i++ )
#define debug(x)           cout << #x << " " << x << " -- "
#define I__O               ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll                 long long  
#define p(x)               cout << x << "\n" ; 
#define MOD                100000007
#define pi                 pair<int,int>
#define vi                 vector <int>
#define pb                 push_back
#define vp                 vector <pair<ll,ll>>
#define endl               cout << "\n"
#define mi                 map <int,int> 
#define f1                 first 
#define s1                 second    
#define in                 insert
#define all(x)             x.begin(),x.end() 
/*
    time : 6:26:43 PM
    date : 3/12/2020
*/    
using namespace std ; 
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set ; 
const int N = 2e5;  
const double pie = 3.14159265358979323846 ;
double dist(double Ax,double X,double Ay, double Y){
  double best = (Ax-Ay)*(Ax-Ay) + (X-Y)*(X-Y) ;
  best = sqrt(best) ;
  return best ;
} 
int tests(){ 
  unsigned long long a[3] ;
  for(int i = 0 ;i < 3; i++ )
  {
    cin >> a[i] ;  
  }
  long long  num  = a[2]-a[0]-a[1] ;
  if(num <= 0)
    return cout << "No",0 ; 

  num *= num;
  a[0] *= a[1];
  a[0] *= 4 ; 
  cout << ( a[0] < num ? "Yes": "No") << '\n';
}
int main(){
    I__O ;  
    int cases = 1 ; 
    // cin >> cases ; 
    while(cases--)
      tests(); 
    return 0 ; 
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define lb lower_bound
#define ub upper_bound

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

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

  	ll n, a , b;
  	cin >> n >> a >> b;
  	cout << (n / (a + b))*a + min(a, n % (a + b)) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>

using namespace std;

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

	int n;
	string s;
	cin >> n >> s;
	for (auto t : s) {
		int v = (t - 'A');
		cout << (char)((v + n) % 26 + 'A');
	}
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int n = sc.nextInt();
		int[] values = new int[w];
		for(int i = 0;i < values.length;i++){
			values[i] = i + 1;
		}
		for(int i = 0;i < n;i++){
			int c;
			String str = sc.next();
			String[] ab = str.split(",");
			int a = Integer.parseInt(ab[0])-1;
			int b = Integer.parseInt(ab[1])-1;
			c = values[a];
			values[a] = values[b];
			values[b] = c;
		}
		for(int i = 0;i < w;i++){
			System.out.println(values[i]);
		}
	}
}

Measured memory_bytes: 17196
#include<iostream>

using namespace std;

int main(){
    int N ,L;
    cin >> N >> L;
    int max = L + N - 1;
    int min = L;

    if(max < 0){
        cout << (min + max) * N / 2 - max << endl; 
    }
    else if (0 < min){
        cout << (min + max) * N / 2 - min << endl; 
    }
    else {
        cout << (min + max) * N / 2 << endl; 
    }

    return 0;
    
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define MAXV 100
#define MAXE 1000

int v_num,e_num,f=0;
int *visited;
int *s,*t;

void closedsearch(int);
int main(){
  int i; 
  scanf("%d %d",&v_num,&e_num);
  if(e_num < 0 || MAXE < e_num || v_num < 1 || MAXV < v_num ) return 0;
  s = (int*)malloc(e_num*sizeof(int));
  t = (int*)malloc(e_num*sizeof(int));
  visited = (int*)malloc(v_num*sizeof(int));
  for(i = 0;i<e_num;i++) scanf("%d %d",&s[i],&t[i]);
  for(i = 0;i<v_num;i++) visited[i] = 0;
  for(i = 0;i<v_num;i++){
    if(f == 1) break;
    if(visited[i] == 0 && f == 0) closedsearch(i);
  }
  printf("%d\n",f);
  free(s);
  free(t);
  free(visited);
  return 0;
}

void closedsearch(int v){
  int i;
  if(visited[v] == 1){
    f = 1;
  }else if(visited[v] == 0){
    visited[v] = 1;
    for(i = 0; i < e_num; i++)
      if(s[i]==v) closedsearch(t[i]);
    visited[v] = 2;
  }
}
      



Measured memory_bytes: 2148
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    *S,=ST()
    *S,=map(int,S)
    for i in range(2):
        for j in range(2):
            for k in range(2):
                res = S[0]
                ope = [i,j,k]
                for idx,s in enumerate(S[1:]):
                    if ope[idx]:
                        res += s
                    else:
                        res -= s
                if res == 7:
                    *S,=map(str,S)
                    for idx in range(3):
                        if ope[idx]:
                            ope[idx] = "+"
                        else:
                            ope[idx] = "-"
                    ans = S[0]+ope[0]+S[1]+ope[1]+S[2]+ope[2]+S[3]+"=7"
                    print(ans)
                    exit()


if __name__ == '__main__':
    main()

Measured memory_bytes: 38256
#include "bits/stdc++.h"
using namespace std;
#define INF 1e9
#define rep(i, n) for(int i=0;i<n;i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;  
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VII;   // VII a(n,vector<int>(m)) n * m 
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
template <class T, class U>  // chmax(max, a);
bool chmax(T &a, U b){
    if (a < b){ a = b;return 1;}
    return 0;
}
template <class T, class U> //chmin(min,a)
bool chmin(T &a, U b){
    if (a > b){ a = b; return 1;}
    return 0;
}
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}

// g++ -std=c++11 prac.cpp 
int main(){
    ll x,y,z,n,p,m=0,k,h,w,sum=0,ans=0,Max=-1e9,count=0,Min=1e9+1;
    string s,t,u,v;
    bool ok=false;
    cin >> n;
    VL a(n);
    rep(i,n){
        cin >> a[i];
        chmin(Min,abs(a[i]));
        if(a[i] < 0){
            sum++;
        }
        ans += abs(a[i]);
    }
    if(sum%2==0){
        cout << ans << endl;
        return 0;
    }
    else{
        ans -= Min*2;
        cout << ans << endl;
        return 0;
    }
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>

int main(){
    int a,b,c,k;
    scanf("%d %d %d %d",&a,&b,&c,&k);
    int sum=k;
    if(sum-a<=0){
        printf("%d\n",k);
        return 0;
    }
    sum=k-a;
    if(sum-b<=0){
        printf("%d\n",a);
        return 0;
    }
    sum=sum-b;
    printf("%d\n",a-sum);
    

    return 0;
}

Measured memory_bytes: 1732
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
n,k=MI()
lis=LI()
mx=[0 for i in range(n)]
mx[-1]=lis[-1]
for i in range(n-1):
    j=n-i-1
    mx[j-1]=max(mx[j],lis[j-1])
#print(mx)
difmx=0

for i in range(n):
    if mx[i]-lis[i]>difmx:
        difmx=mx[i]-lis[i]
#print(lis)
#print(difmx)
new_mx=[[0,0] for i in range(n)]
new_mx[-1]=[lis[-1],1]
count=0
for i in range(n-1):
    j=n-i-1
    #print(new_mx)
    #print(count)
    new_mx[j-1]=new_mx[j]
    if new_mx[j][0]-lis[j-1]==difmx:
        count+=new_mx[j][1]
    if new_mx[j][0]==lis[j-1]:
        new_mx[j][1]+=1
    if new_mx[j][0]<lis[j-1]:
        new_mx[j-1][0]=lis[j-1]
        new_mx[j-1][1]=1
print(count)
    
    
    




Measured memory_bytes: 98248
#include<iostream>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  int min = 0, max = N;
  for(int i=0; i<M; i++){
    int l, r;
    cin >> l >> r;
    if(l>min) min = l;
    if(r<max) max = r;
  }
  if(max < min) cout << 0 << endl;
  else cout << max-min+1 << endl;
  return 0;
}

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

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String s = br.readLine();
        int n = Integer.parseInt(s);
        double tot = 100000;
        for (int i=1; i < n+1; i++){
            tot = tot * 1.05;
            if (tot%1000 != 0){
                tot = tot - tot%1000 + 1000;
            }
        }
        System.out.println((int)tot);
    }
}

Measured memory_bytes: 16864
#include <bits/stdc++.h>
#define FOR(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define FORUL(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#define FORULE(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define FOREACH(it, X) for(__typeof((X).begin()) it = (X).begin(); it != (X).end(); it++)
#if defined(_MSC_VER) || __cplusplus > 199711L
#define AUTOVAR(newvar,v) auto newvar = (v)
#else
#define AUTOVAR(newvar,v) __typeof(newvar) r = (v)
#endif
#define PB(x) push_back(x)
#define MP(x,y) make_pair((x),(y))
#define MEMSET(m,v) memset(m,v,sizeof(m))

typedef long long				 ll;
typedef unsigned long long		ull;

#define DEBUG 1

#if DEBUG
#define DOUT cout<<"["<<__LINE__<<"]:"
#else
#define DOUT 0 && cout
#endif

using namespace std;

int M, D;

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false);
	cin >> M >> D;
	int ans = 0;
	for(int m=1;m<=M;m++) {
	for(int d=1;d<=D;d++) {
		int d1 = d%10;
		int d10 = d/10;
		if(d1<2) { continue; }
		if(d10<2) { continue; }
		if (m==d1*d10) {
			ans ++;
		}
	}
	}

	cout << ans << endl;

	return 0;
}




Measured memory_bytes: 256
// Problem : D - Chat in a Circle
// Contest : AtCoder - AtCoder Beginner Contest 173
// URL : https://atcoder.jp/contests/abc173/tasks/abc173_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 100005

//Solution

void solve(){
    int n;
    cin>>n;
    vi a(n);
    for(int &i : a) cin>>i;
    sort(all(a));
    int ans = a[n-1];
    int k = n-2;
    int p = 0, id = n-2;
    while(k--){
        ans += a[id];
        p++;
        if(p == 2) p = 0, id--;
    }
    cout<<ans<<endl;
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    while(tests--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 4776
#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
#include <cstdint>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, N) for(int i = 0; i < N; i++)
#define rep2(i, l, r) for (ll i = (ll)l; i < (ll)(r); i++)
#define INF 1000000000000000000
#define MAX 200001

const int MOD = 1000000007;

template <typename T > inline string toString(const T &a) {ostringstream oss; oss << a; return oss.str();};

template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) v += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr istream& operator >> (istream &is, Fp<MOD>& x) noexcept {
        return is >> x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};

using mint = Fp<MOD>;

int main(){
    string s;
    cin >> s;
    int n = s.size();
    char Begin = s[0];
    char End = s[n-1];
    if(Begin == End){
        if(n % 2 == 0) cout << "First" << endl;
        else cout << "Second" << endl;
    }
    else{
        if(n % 2 != 0) cout << "First" << endl;
        else cout << "Second" << endl; 
    }
}

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

int main() {
  long long a, b, c, k;
  cin >> a >> b >> c >> k;
  
  long long ans = a + b + c;
  a = max(a, max(b, c));
  ans -= a;
  for(int i = 0; i < k; i++) a *= 2;
  
  cout << ans + a << endl;
}

Measured memory_bytes: 3500
import sys
input = sys.stdin.readline


def read():
    s = input().strip()
    K = int(input().strip())
    return s, K


def solve(s, K):
    ans = []
    for a in s:
        c = (ord("z") - ord(a) + 1) % 26
        if c <= K:
            K -= c
            ans.append("a")
        else:
            ans.append(a)
    if K > 0:
        c = (ord(ans[-1]) - ord("a") + K) % 26
        ans[-1] = chr(c + ord("a"))
    return "".join(ans)


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


Measured memory_bytes: 10060
#include <iostream>

#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <iomanip>
#include <numeric>

using namespace std;

typedef long long LL;
typedef unsigned int UI;

#define rSort(a) sort(a.rbegin(),a.rend())
#define Sort(a) sort(a.begin(),a.end())
#define Sum(a)  accumulate(a.begin(), a.end(), 0)
#define REP(i, n) for(UI i = 0;i < n;i++)
#define REPR(i, n) for(UI i = n;i >= 0;i--)
#define FOR(i, m, n) for(UI i = m;i < n;i++)

int main(int argc, const char * argv[]) {

	cin.tie(0);
	ios::sync_with_stdio(false);

	LL N, M;
	LL calc = 0;
	LL sum = 0;
	LL ans = 0;

	cin >> N >> M;

	vector<LL>X((UI)M);

	REP(i, M) {
		cin >> X[i];
	}

	Sort(X);
	vector<LL>Y;

	REP(i,X.size() - 1) {
		Y.push_back(X[i + 1] - X[i]);
		sum += Y[i];
	}

	rSort(Y);

	if (N>=M) {
		ans = 0;
	}
	else {

		REP(i,N - 1) {
			calc += Y[i]; // 除去する分
		}
		ans = sum - calc;
	}

	cout << ans << endl;

	return 0;

}

Measured memory_bytes: 2168