akhauriyash/Code-Regression huggingface dataset:
/*
  文字のカウント(与えられた英文に含まれる、各アル
  ファベットの数を数えるプログラム)
  2018/02/21
*/

#include <stdio.h>
int main(void) {
  int al[30] = {0};
  char b[1200]= {0};
  int i,j,n;
  i=0;
  while( scanf("%c",&b[i]) != EOF) {
    if (b[i] >= 'A' && 'Z' >= b[i] ) {
      n = b[i] - 'A';
      al[n] += 1;
     } else if(b[i] >=  'a' && b[i] <= 'z' ) {
      n = b[i] - 'a';
      al[n] += 1;
    }
    i=i+1;
  }
  for(j=97; j<=122; j++) {
    n = j - 'a';
    printf("%c : %d\n",j,al[n]);
  }
  return 0; 
}


Measured memory_bytes: 2100
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

typedef long long int li;

vector<int> v, dp;

int dpf(int N, int K)
{
    if (N < 0)
        return 1000000;
    else if (N == 0)
        return 0;
    else
    {
        if (dp[N] != -1)
            return dp[N];
        
        int minima = dpf(N-1, K) + abs(v[N-1] - v[N]);
        for (int k = 2; k <= K && N-k >= 0; ++k)
            minima = min(minima, dpf(N-k, K) + abs(v[N-k] - v[N]));
        
        dp[N] = minima;
        return dp[N];
    }

}


int main()
{
    int N, K;
    cin >> N >> K;
    v.resize(N);
    dp.resize(N);
    for (int i = 0; i < N; ++i)
    {
        cin >> v[i];
        dp[i] = -1;
    }

    dpf(N-1, K);

    cout << dp[N-1];
    return 0;
}

Measured memory_bytes: 8832
#include <iostream>
#include <set>

using namespace std;

int main()
{
	int N, K;
	cin >> N >> K;
	set<int> s = { 1 };

	for (int i = 0; i < N; ++i) {
		set<int> t;
		for (auto x : s) {
			t.insert(x * 2);
			t.insert(x + K);
		}
		swap(s, t);
	}
	cout << *s.begin() << endl;
}


Measured memory_bytes: 256
def resolve():
    n, m = map(int, input().split())
    A = list(map(int, input().split()))
    B=[]
    ans=0
    k=0
    j=0
    for _ in range(m):
        a, b = map(int, input().split())
        B.append([b,a])
    for i in A:
        B.append([i,1])
    B.sort(reverse=True)
    f=B[0][1]
    while f<n:
        k+=B[j][1]
        f+=B[j+1][1]
        ans+=B[j][0]*B[j][1]
        j+=1
    ans+=B[j][0]*(n-k)

    print(ans)
resolve()

Measured memory_bytes: 92440
#include<iostream>

using namespace std;
#define N 500001

int counter=0;

void Merge(int A[],int left,int mid,int right){
  
  int n1,n2,i,j;
  int L[N],R[N];

  n1=mid-left;
  n2=right-mid;

  for(i=0;i<n1;i++){
    L[i]=A[left+i];
  }

  for(i=0;i<n2;i++){
    R[i]=A[mid+i];
  }
  L[n1]=999999998;
  R[n2]=999999998;

  i=0;
  j=0;
  for(int k=left;k<right;k++){
    counter++;
    if(L[i]<=R[j]){
      A[k]=L[i];
      i++;
    }
    else{
      A[k]=R[j];
      j++;
    }
  }

}

void MergeSort(int A[],int left,int right){
  int mid;
  if(left+1<right){
    mid=(left+right)/2;
    MergeSort(A,left,mid);
    MergeSort(A,mid,right);
    Merge(A,left,mid,right);
  }

}


int main(){

  int num,i;
  int data[N];
 
  cin >>num;

  for(i=0;i<num;i++){
    cin >>data[i];
  }

  MergeSort(data,0,num);

  for(i=0;i<num;i++){
    cout <<data[i];
    if(i!=num-1)cout <<" ";
  }
  cout <<endl;
  cout <<counter<<endl;
  return 0;

}

Measured memory_bytes: 4780
#include<iostream>
#include<cstdio>
#include<queue>
#include<cmath>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
#define maxn 1005
int cgy;
struct node{
	int to;
	int id;
	node(int a,int b){
		to=a;
		id=b;
	}
	node(){}
};
int n,m;
int tot;
int vis[maxn];
int bh[maxn][maxn][3];
vector<node> e[maxn];
int u[maxn*maxn*2];
int v[maxn*maxn*2];
void dfs(int root,int fa,int b,int f){
	vis[root]=tot;
	bh[fa][root][f]=b;
	int len=e[root].size();
	for(int i=0;i<len;i++){
		if(vis[e[root][i].to]!=tot)
		dfs(e[root][i].to,fa,b,f);
	}
}
void s(int now){
	tot++;
	vis[now]=tot;
	int len=e[now].size();
//	cout<<now<<" "<<len<<endl; 
	for(int i=0;i<len;i++){
		if(vis[e[now][i].to]!=tot)
		dfs(e[now][i].to,now,e[now][i].id,0);
	}
	reverse(e[now].begin(),e[now].end());
	tot++;
	vis[now]=tot;
//	int len=e[now].size();
	for(int i=0;i<len;i++){
		if(vis[e[now][i].to]!=tot)
		dfs(e[now][i].to,now,e[now][i].id,1);
	}	
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		scanf("%d%d",&u[i],&v[i]);
		e[u[i]].push_back(node(v[i],i));
	}
	for(int i=1;i<=n;i++){
		s(i);
	}
	for(int i=1;i<=m;i++){
		if((bh[u[i]][v[i]][0]!=i||bh[u[i]][v[i]][1]!=i) ^ 0 ^ (bh[v[i]][u[i]][0]!=0)){
			puts("diff");
		}
		else{
			puts("same");
		}
	}
}

Measured memory_bytes: 22272
// g++ -std=gnu++1y -O2 -I/opt/boost/gcc/include -L/opt/boost/gcc/lib -o ./a.out ./X.cpp & a.out //
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define ull unsigned long long


using namespace std;

const int INF = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);	
    cin.tie(NULL); cout.tie(NULL);
    
    int N, W; cin >> N >> W;
    
    vector<ll> dp(W + 1, -INF);
    
    // max value of items with weight w
    
    dp[0] = 0;
    
    for(int i = 0; i < N; i++)
    {
		int w, v; cin >> w >> v;
		
		for(int wa = W - w; wa >= 0; --wa)
		{
			dp[wa+w] = max(dp[wa+w], dp[wa] + v);
		}
	}
	
	ll ans = 0;
	
	for(int i = 0; i <= W; i++)
	{
		ans = max(ans, dp[i]);
	}
	
	cout << ans << endl;
    
	
    
    return 0;
}



Measured memory_bytes: 1024
// B - Exponential

#include <bits/stdc++.h>
using namespace std;

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

  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= N; j++) {
      int k = N - i - j;
      if (Y == 10000 * i + 5000 * j && k ==0) {
        cout << i << " " << j << " 0" << endl;
        return 0;
      } else if (k < 0) {
        break;
      } else if (Y == 10000 * i + 5000 * j + 1000 * k) {
        cout << i << " " << j << " " << k << endl;
        return 0;
      }
    }
  }
  cout << "-1 -1 -1" << endl;
}


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

using namespace std;

#define eb emplace_back
#define ii pair<int, int>
#define OK (cerr << "OK" << endl)
#define debug(x) cerr << #x " = " << (x) << endl
#define ff first
#define ss second
#define int long long
#define tt tuple<int, int, int>
#define all(x) x.begin(), x.end()
#define vvi vector<vector<int>>
#define vvii vector<vector<pair<int, int>>>
#define Mat(n, m, v) vector<vector<int>>(n, vector<int>(m, v))
#define endl '\n'

constexpr int INF = 2e18;
constexpr int MOD = 1e9 + 7;
constexpr int MAXN = 2e5 + 3;

// #define MULTIPLE_TEST_CASES
void solve() {
  string s;
  cin >> s;

  int cur = 0;

  int ans = 0;
  for (char c : s) {
    if (c == 'R') {
      ++cur;
    } else {
      ans = max(ans, cur);
      cur = 0;
    }
  }
  ans = max(ans, cur);
  cout << ans << endl;
}

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

  int t = 1;
#ifdef MULTIPLE_TEST_CASES
  cin >> t;
#endif
  while (t--)
    solve();
}

Measured memory_bytes: 3652
import sys
from math import gcd

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


def main():
    A, B, C, D = map(int, readline().split())

    L = C // gcd(C, D) * D
    c1, c2 = (A + C - 1) // C, B // C
    d1, d2 = (A + D - 1) // D, B // D
    l1, l2 = (A + L - 1) // L, B // L

    ans = (B - A + 1) - ((c2 - c1 + 1) + (d2 - d1 + 1) - (l2 - l1 + 1))
    print(ans)
    return


if __name__ == '__main__':
    main()


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

#define all(x) begin(x), end(x)

using i64 = int_fast64_t;
using f64 = double;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

template<i64 M>
struct modint {
    i64 x;

    constexpr modint(const i64 y = 0) noexcept : x(y >= 0 ? y % M : (M - (-y) % M) % M) {}

    constexpr modint operator-() const noexcept { return modint(-x); }
    constexpr modint operator+(const modint &rhs) const noexcept { return modint(*this) += rhs; }
    constexpr modint operator-(const modint &rhs) const noexcept { return modint(*this) -= rhs; }
    constexpr modint operator*(const modint &rhs) const noexcept { return modint(*this) *= rhs; }
    constexpr modint operator/(const modint &rhs) const noexcept { return modint(*this) /= rhs; }

    constexpr modint &operator+=(const modint &rhs) noexcept {
        x += rhs.x;
        if (x >= M) x -= M;
        return *this;
    }

    constexpr modint &operator-=(const modint &rhs) noexcept {
        if (x < rhs.x) x += M;
        x -= rhs.x;
        return *this;
    }

    constexpr modint &operator*=(const modint &rhs) noexcept {
        x = x * rhs.x % M;
        return *this;
    }

    constexpr modint &operator/=(const modint &rhs) noexcept {
        i64 a = rhs.x, b = M, u = 1, v = 0;
        while (b > 0) {
            i64 t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        *this *= u;
        return *this;
    }

    friend ostream &operator<<(ostream &os, const modint &p) {
        return os << p.x;
    }

    friend istream &operator>>(istream &is, modint &a) {
        i64 t;
        is >> t;
        a = modint(t);
        return is;
    }
};

constexpr i64 MOD = 998244353;
using m64 = modint<MOD>;

m64 modpow(m64 x, i64 n) {
    m64 res = 1;
    while (n > 0) {
        if (n & 1) res *= x;
        x *= x;
        n >>= 1;
    }
    return res;
}

template<typename T = m64>
struct combinatorics {
    vector<T> fac;

    combinatorics(i64 n): fac(2*n+1) {
        fac[0] = 1;
        for (i64 i = 1; i <= 2*n; i++) fac[i] = fac[i-1] * i;
    }

    T p(i64 n, i64 k) const {
        if (k < 0 || n < k) return 0;
        return fac[n] / fac[n-k];
    }

    T c(i64 n, i64 k) const {
        if (k < 0 || n < k) return 0;
        return fac[n] / (fac[k] * fac[n-k]);
    }

    T h(i64 n, i64 k) const {
        return c(n+k-1, k);
    }
};

void solve() {
    i64 n, m, k;
    cin >> n >> m >> k;

    combinatorics c(n - 1);
    m64 ans = 0;
    for (i64 i = 0; i <= k; i++) {
        ans += c.c(n - 1, i) * modpow(m - 1, n - 1 - i) * m;
    }

    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


Measured memory_bytes: 6304
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using ull = uint64_t;
const ll INF = 9e18;

int main() {
    ll H, W;
    cin >> H >> W;
    ll sh, sw, gh, gw;
    cin >> sh >> sw;
    cin >> gh >> gw;
    sh--;
    sw--;
    gh--;
    gw--;

    // 道の一覧
    vector<vector<bool>> roads(H, vector<bool>(W, false));
    for (ll h = 0; h < H; h++) {
        for (ll w = 0; w < W; w++) {
            char c;
            cin >> c;
            while (c != '.' && c != '#') {
                cin >> c;
            }
            if (c == '.') {
                roads[h][w] = true;
            }
        }
    }

    vector<vector<bool>> done(H, vector<bool>(W, false));
    stack<pair<ll, ll>> dist_even;
    stack<pair<ll, ll>> dist_odd;
    stack<pair<ll, ll>> *dist_current = &dist_even;
    stack<pair<ll, ll>> *dist_next = &dist_odd;
    ll d = 0;
    dist_current->push(make_pair(sh, sw));
    while (d <= H * W + 1) {
        if (dist_current->empty()) {
            stack<pair<ll, ll>> *swp = dist_current;
            dist_current = dist_next;
            dist_next = swp;
            d++;
            continue;
        }
        auto src = dist_current->top();
        dist_current->pop();
        ll h = src.first;
        ll w = src.second;
        if (h == gh && w == gw) {
            cout << d << endl;
            return 0;
        }
        if (done[h][w]) {
            continue;
        }
        done[h][w] = true;
        for (ll y = h - 2; y <= h + 2; y++) {
            for (ll x = w - 2; x <= w + 2; x++) {
                if (y >= 0 && y < H && x >= 0 && x < W && roads[y][x] && !done[y][x]) {
                    if (abs(x - w) + abs(y - h) == 1) {
                        dist_current->push(make_pair(y, x));
                    } else {
                        dist_next->push(make_pair(y, x));
                    }
                }
            }
        }
    }
    cout << -1 << endl;
}


Measured memory_bytes: 4672
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,n) for(int i = 0;i < (int)(n);i++)
#define FOR(i,s,n) for(int i = s;i < (int)n;i++)
#define RREP(i,n) for(int i = (int)n-1;i >= 0;i--)
#define RFOR(i,s,n) for(int i = (int)n-1;i >= s;i--)
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a = b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a = b;return true;}return false;}
constexpr long long INF = 1e18;

struct UF{
	vector<int>par,sz;
	void init(int n){
		par.resize(n);
		sz.resize(n);
		for(int i=0;i<n;i++){
			par[i]=i;
			sz[i]=1;
		}
	}
	int find(int x){
		return x==par[x]?x:par[x]=find(par[x]);
	}
	void unite(int x,int y){
		x=find(x);y=find(y);
		if(x==y)return;
		sz[x]+=sz[y];
		par[y]=x;
	}
	bool same(int x,int y){
		return find(x)==find(y);
	}
	int size(int x){
		return sz[find(x)];
	}
};

signed main(){
	int N;
	cin >> N;
	vector<int>x(N),y(N);
	vector<vector<int>>tate(100010),yoko(100010);
	REP(i,N){
		cin >> x[i] >> y[i];
		x[i]--;y[i]--;
		tate[x[i]].emplace_back(y[i]);
		yoko[y[i]].emplace_back(x[i]);
	}
	UF var,col;
	var.init(100010);
	col.init(100010);
	REP(i,100010){
		REP(j,tate[i].size()-1){
			var.unite(tate[i][j],tate[i][j+1]);
		}
		REP(j,yoko[i].size()-1){
			col.unite(yoko[i][j],yoko[i][j+1]);
		}
	}
	map<int,int>mp;
	int ans = 0;
	REP(i,N){
		if(mp.count(col.find(x[i])))continue;
		ans += var.size(y[i])*col.size(x[i]);
		mp[col.find(x[i])]++; 
	}
	cout<<ans-N<<endl;
}

Measured memory_bytes: 13312
#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(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	int N, K; cin >> N >> K;
	vi H(N);
	REP(i,N) cin >> H[i];
	vl dp(N, numeric_limits<ll>::max());
	dp[0] = 0;
	FOR(i, 1, N) {
		FOR(j, 1, K + 1) {
			if (i - j >= 0) {
				dp[i] = min(dp[i], dp[i - j] + abs(H[i] - H[i - j]));
			}
		}
	}
	cout << dp[N - 1] << endl;
}

int main() {
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 1408
#include <iostream>
#include <array>

using namespace std;

int main() {
    auto a = array<int, 3>();

    for (int & _a : a) {
        cin >> _a;
    }

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

    auto c = array<int, 6>();

    for (int i = 0; i < 6; ++i) {
        c[i] = abs(a[0] - a[1]) + abs(a[1] - a[2]);
        next_permutation(a.begin(), a.end());
    }

    cout << *min_element(c.begin(), c.end()) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>

using namespace std;
int main(void){
  string s;
  cin >> s;
  int s_end = s.size(), s_begin = 0;
  for(int i = 0; i < s.size(); i++){
    if(s[i] == 'A'){
      s_begin = i;
      break;
    }
  }
  for(int i = s.size(); i >= 0; i--){
    if(s[i] == 'Z'){
      s_end = i;
      break;
    }
  }
  cout << s_end - s_begin + 1 << endl;
  return 0;
}

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

int main() {
  long long a, b, k;

  cin >> a >> b >> k;

  if (a == k) {
    cout << 0 << " " << b << endl;
  } else if (a > k) {
    a = a - k;
    cout << a << " " << b << endl;
  } else {
    long long diff = k - a;
    b = b - diff;
    if (b < 0) {
      b = 0;
    }
    cout << 0 << " " << b << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
const int INFTY =2147483647;
int main(){
    float pi =3.1415926535;
    int i;
    cin>>i;
    cout<<2*pi*(float)i<<endl;
}

Measured memory_bytes: 3740
N = int(input())
p = list(map(int,input().split()))
ans = 0
for i in range(N-2):
  ans += 1 if max(p[i],p[i+1],p[i+2])!=p[i+1] and min(p[i],p[i+1],p[i+2])!=p[i+1] else 0
print(ans)

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

int main(){
  int h, n;
  cin >> h >> n;
  vector<int> data(n);
  int i;
  for(i = 0; i < n; i++){
      cin >> data.at(i);
  }
  int sum = 0;
  for(int x : data){
      sum += x;
  }
  if(sum >= h){
      cout << "Yes" << endl;
      return 0;
  }
  else{
      cout << "No" << endl;
      return 0;
  }
}

Measured memory_bytes: 640
#define FNAME ""

#include <bits/stdc++.h>

#define hash padjf9srpi
#define y0 sdkfaslhagaklsldk
#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define forn(i, n) for (int i = 0; i < (n); i++)
#define fornr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define forab(i, a, b) for (int i = (a); i < (b); i++)
#define gcd __gcd
#define all(a) (a).begin(), (a).end()
 
#ifdef _WIN32
    #define I64 "%I64d"
#else
    #define I64 "%lld"
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int, int> pii;                                                                                                                                                                                      
typedef vector <int> vi;

template <class T> T sqr(const T &a) {return a * a;}

int n, a[100010];

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

#ifdef LOCAL
    freopen(FNAME".in", "r", stdin);
    freopen(FNAME".out", "w", stdout);
#endif

    scanf("%d", &n);
    LL s = 0;
    forn(i, n) {
        scanf("%d", &a[i]);
        s += a[i];
    }
    LL k = 1ll * n * (n + 1) / 2;
    if (s % k != 0) {
        puts("NO");
        return 0;
    }
//    cerr << s << " " << k << " "  << s / k << endl;
    a[n] = a[0];
    forn(i, n) {
        if ((a[i + 1] - a[i] - s / k) % n != 0 || (a[i + 1] - a[i] - s / k) / n > 0) {
            puts("NO");
            return 0;
        }
    }
    puts("YES");
}




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

using namespace std;

struct Acc
{
    int b, w;
    Acc(int b, int w): b(b), w(w) {}
    Acc& operator+=(const Acc& oth) {
        b += oth.b;
        w += oth.w;
        return *this;
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    vector<string> v(n);
    for (auto& r : v) {
        cin >> r;
    }
    vector<vector<int8_t> > used(n, vector<int8_t>(m));
    function<Acc(int, int, char)> cnt = [&](int i, int j, char lst) {
        if (i < 0 || i >= n || j < 0 || j >= m || used[i][j] || lst == v[i][j]) {
            return Acc{0, 0};
        }
        used[i][j] = 1;
        char c = v[i][j];
        Acc res{c == '#', c == '.'};
        res += cnt(i - 1, j, c);
        res += cnt(i + 1, j, c);
        res += cnt(i, j - 1, c);
        res += cnt(i, j + 1, c);
        return res;
    };
    int64_t ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            auto size = cnt(i, j, -1);
            ans += 1ll * size.b * size.w;
        }
    }
    cout << ans << endl;
    return 0;
}

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

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

typedef long long ll;
typedef pair<int, int> P;

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

int main(){
    vector<vector<int>> A(3, vector<int>(3));
    rep(i, 3)rep(j, 3) cin >> A[i][j];

    int N;
    cin >> N;

    vector<int> B(N);
    rep(i, N) cin >> B[i];

    bool ans = false;
    rep(i, 3){
        bool res = true;
        rep(j, 3) {
            res &= find(B.begin(), B.end(), A[i][j]) != B.end();
        }
        ans |= res;
    }

    rep(i, 3){
        bool res = true;
        rep(j, 3) {
            res &= find(B.begin(), B.end(), A[j][i]) != B.end();
        }
        ans |= res;
    }

    bool res = true;
    rep(i, 3) {
        res &= find(B.begin(), B.end(), A[i][i]) != B.end();
    }

    ans |= res;

    res = true;
    rep(i, 3) {
        res &= find(B.begin(), B.end(), A[i][2 - i]) != B.end();
    }

    ans |= res;

    if (ans) puts("Yes");
    else puts("No");
}

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

int main(int argc, const char* argv[]) {
    // cinを高速にするためのおまじない
    cin.tie(0);
    ios::sync_with_stdio(false);

    /////////////////////
    // Write code below /
    int x;
    cin >> x;
    if(x == 0){
        cout << "1" << endl;
        
    }
     else {
        cout << "0" << endl;
    }

    /////////////////////


    return 0;
}

Measured memory_bytes: 3632
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

a=one_int()

if a%1000>0:
    print(1000-a%1000)
else:
    print(0)

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

P make_p(int x)
{
  int tail = x % 10;
  int head = to_string(x)[0] - '0';
  return P(tail, head);
}

int main()
{
  int n;
  cin >> n;
  map<P, int> freq;
  for (int i = 1; i <= n; i++)
  {
    P p = make_p(i);
    freq[p]++;
  }
  int ans = 0;
  for (int i = 1; i <= n; i++)
  {
    P p = make_p(i);
    P q = P(p.second, p.first);
    ans += freq[q];
  }
  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 < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

int main() {
  int a,b,c;
  cin>>a>>b>>c; 
  if(a%2!=0||b%2!=0||c%2!=0){
    cout<<0<<endl;
  }
  else if(a==b&&b==c){
    cout<<-1<<endl;
  }
  else{
  int A=b+c;
  int B=a+c;
  int C=a+b;
  int d=__gcd(A,B);
  d=__gcd(d,C);
  int ans=0;
  while(d%2==0){
    d/=2;
    ans++;
  }
  cout<<ans<<endl;

  }
}



Measured memory_bytes: 256
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let n: usize = sc.read();
    let mut graph = vec![vec![]; n];
    for _ in 1..n {
        let a = sc.read::<usize>() - 1;
        let b = sc.read::<usize>() - 1;
        graph[a].push(b);
        graph[b].push(a);
    }
    let g = dfs(0, 0, &graph);
    if g == 0 {
        println!("Bob");
    } else {
        println!("Alice");
    }
}

fn dfs(v: usize, p: usize, graph: &Vec<Vec<usize>>) -> usize {
    let mut grundy = 0;
    for &next in graph[v].iter() {
        if next == p {
            continue;
        }
        grundy ^= dfs(next, v, graph) + 1;
    }
    grundy
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 16636
#include <stdio.h>

int main()
{
	int i, X, A, B;
	scanf("%d %d %d", &X, &A, &B);
	if (A >= B) printf("delicious\n");
	else if (A + X >= B) printf("safe\n");
	else printf("dangerous\n");
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1612
//なぜかAOJでWrong Answerになる！
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

int main(){
	char A_symbol[36+1];//列の文字のみを格納する配列
	char A_symboltmp[36+1];
	int A_num[36+1];//列の数字のみ格納する配列
	int A_numtmp[36+1];
	int num;//数列の長さ(カードの枚数)
	char tmpstr[3];

	/*配列を0で初期化modify
	for(int i=0;i<1001;i++){
		A[i] = 0;
	}
	*/

	cin >>num;
	
	for(int i=0;i<num;i++){
		scanf("%s",tmpstr);
		A_symbol[i]=tmpstr[0];
		A_symboltmp[i] = A_symbol[i];
		A_num[i] = atoi(&tmpstr[1]);
		A_numtmp[i] = A_num[i];
		//cout <<A_symbol[i] <<A_num[i] <<endl;
	}

	void bubbleSort(char A_symbol[],int A_num[],int N);
	void selectionSort(char A_symbol[],int A_num[],int N);
	
	bubbleSort(A_symboltmp,A_numtmp,num);//ほんとはポインタで定義してやるべき
	cout <<"Stable" <<endl;
	selectionSort(A_symbol,A_num,num);
	
	//バブルソートが常に安定なソートであることを利用して選択ソートが安定であるかどうかを判断
	for(int i=0;i<num;i++){
		if(A_numtmp[i] != A_num[i] || A_symbol[i] != A_symboltmp[i]){
			cout <<"Not stable" <<endl;
			return 0;
		}
	}
	cout <<"Stable" <<endl ;

	
	return 0;
}

void selectionSort(char A_symbol[], int A_num[],int N){
	int minj;//minjはA[i]?A[N-1]の最小値の添え字
	char tmpstr;
	int tmp;
	int cnt=0;//交換回数
	for(int i=0;i<N;i++){
		minj = i;
		for(int j=i;j<N;j++){
			if(A_num[j] < A_num[minj]){
				minj = j;
			}
		}
		
		if(minj != i){//iより後ろにiより小さいものがない場合
			cnt++;
			tmpstr = A_symbol[minj];
			A_symbol[minj] = A_symbol[i];
			A_symbol[i] = tmpstr;
			tmp = A_num[minj];
			A_num[minj] = A_num[i];
			A_num[i] = tmp;
		}


		//minj = iの場合，実際は交換になっていないのでこの場合はcnt++しない！
		
	}
	//ソート完了後の状態を出力
		for(int k=0;k<N-1;k++){
			cout <<A_symbol[k] <<A_num[k] <<" ";
		}
		cout <<A_symbol[N-1] <<A_num[N-1] ;
		cout <<endl;
		//cout <<cnt <<endl;

}

void bubbleSort(char A_symbol[],int A_num[],int N){
	bool flag = true;
	int tmp;
	int tmpstr;
	int cnt = 0;//交換回数のカウンタ

	/*まずソートを行う前の状態を出力
	for(int k=0;k<N-1;k++){
			cout <<A[k] <<" ";
		}
		cout <<A[N-1];
		cout <<endl;
		*/

	while(flag){
		flag = false;

		//交換が一回も行われなかった場合flag = trueでforループを抜ける
		for(int j=N-1;j>0;j--){
			if(A_num[j] < A_num[j-1]){
				tmp = A_num[j];
				A_num[j] = A_num[j-1];
				A_num[j-1] = tmp;
				tmpstr = A_symbol[j];
				A_symbol[j] = A_symbol[j-1];
				A_symbol[j-1] = tmpstr;
				cnt++;
				flag = true;
			}
		}
		/*この交換後の状態を出力
		for(int k=0;k<N-1;k++){
			cout <<A[k] <<" ";
		}
		cout <<A[N-1];
		cout <<endl;
		*/
	}
	/*ソート終了後の状態を出力*/
	for(int k=0;k<N-1;k++){
			cout <<A_symbol[k] << A_num[k] <<" ";
	}
	cout <<A_symbol[N-1] <<A_num[N-1] ;
	cout <<endl;
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(obj) (obj).begin(),(obj).end()
typedef long long ll;
ll mod=ll(1e9)+7;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int k;
  cin>>k;
  if(k<10){
      cout<<k<<endl;
      return 0;
  }
  queue<ll> q;
  for(int i=1;i<10;i++)q.push(i);
  k-=9;
  while(1){
      ll t=q.front();q.pop();
      for(int i=-1;i<2;i++){
            int d=t%10+i;
            if(d<0|| d>9) continue;
            ll nx=t*10+d;
            --k;
            if(!k){
                cout<<nx<<endl;
                return 0;
            }
            q.push(nx);  
      }
  }
  return 0;
}


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

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'
#define all(x) x.begin(), x.end()

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
using vvll = vector< vector<ll> >;
using vll = vector<ll> ;
using vb = vector<bool> ;
using pll = pair<ll, ll> ;

const ll maxs = 1e6+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;


void pre(){

    

}


void solve(){

    ll n;
    cin >> n;
    ll a[n+1];
    for(ll i=1;i<n+1;i++){
        cin >> a[i];
    }
    sort(a+1,a+n+1,greater<ll>());
    ll ans=0;
    vll b;
    b.pb(a[1]);
    for(ll i=2;i<=n;i++){
        b.pb(a[i]);
        b.pb(a[i]);
    }
    for(ll i=0;i<n-1;i++){
        ans += b[i];
    }
    cout << ans << endl;

}

int main(){
    // #ifndef ONLINE_JUDGE
    // freopen("input00.txt","r",stdin);
    // #endif
    IOS;
    pre();
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();   
    }
    return 0;
}

Measured memory_bytes: 8980
#include<bits/stdc++.h>
using namespace std;
long long int dfs(int l, int r, vector<long long int>& v, vector<vector<long long int>>& dp)
{
    if(l==r)
        return v[l];
    if(dp[l][r]!=INT_MAX)
        return dp[l][r];
    return dp[l][r] = max(v[l]-dfs(l+1, r, v, dp), v[r]-dfs(l, r-1, v, dp));
}
int main()
{
    int n;
    cin>>n;
    vector<long long int> v(n, 0);
    vector<vector<long long int>> dp(n, vector<long long int>(n, INT_MAX));
    for(int i=0; i<n; i++)
        cin>>v[i];
    cout<<dfs(0, n-1, v, dp);
    return 0;
}
 

Measured memory_bytes: 70912
#include<iostream>
#include<cmath>
#include<string>
#include<vector>
#include<numeric>

#include <algorithm>
#include <functional>
using namespace std;


int main(){
  string str;
  cin >> str;
  vector<char> vec;

  for(std::string::iterator it = str.begin(); it != str.end(); ++it){
   vec.push_back(*it);
  }

  std::sort(vec.begin(),vec.end());

  if(vec[0] == vec [1] && vec[2] == vec[3]  && vec[0] != vec[2]){
   cout << "Yes";
  }else{
   cout << "No";
  }
  return 0;
}


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

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

    int t = 0, tmpt, x = 0, tmpx, y = 0, tmpy;
    for(int i = 0; i < n; i++){
        cin >> tmpt >> tmpx >> tmpy;
        int dist = abs(tmpx-x) + abs(tmpy-y);
        if(dist > tmpt-t || dist%2 != (tmpt-t)%2){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

	static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;
 
        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }
 
        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        int nextInt()
        {
            return Integer.parseInt(next());
        }
 
        long nextLong()
        {
            return Long.parseLong(next());
        }
 
        double nextDouble()
        {
            return Double.parseDouble(next());
        }
 
        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		FastReader sc = new FastReader();
		int N = sc.nextInt(), K = sc.nextInt();
		int[] h = new int[N]; 
		for (int i=0; i<N; i++) {
			h[i] = sc.nextInt(); 
		}
		int[] dp = new int[N+10]; 
		Arrays.fill(dp, 1<<30);
		dp[0] = 0; 
		for (int i=0; i<N; i++) {
			for (int j=1; j<=K; j++) {
				if (i+j<N) {
					dp[i+j] = Math.min(dp[i+j], dp[i] + Math.abs(h[i]-h[i+j])); 
				}
				else {
					break; 
				}
 			}
		}
		System.out.println(dp[N-1]);
	}

}


Measured memory_bytes: 33304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
const int Nmax=200010;
int main() {
	ll N, M, ans=-1;
	cin >> N >> M;
	if(N <= 2 || M <= 2)
      if(N==1 && M==1) ans=1;
  	  else ans=0;
	if((N==1 && M>=3)||(M==1 && N>=3)) ans = N+M-3;
	if(ans==-1) ans = N * M - (N*2+M*2-4); 
	cout << ans << endl;
	return 0;
}

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

// 插入此處
namespace Number {
    typedef long long int LL;
    // 求取 a, b 的最大公因數
    LL gcd(LL a, LL b) {
        if (a % b == 0) {
            return b;
        }
        return gcd(b, a % b);
    }
    // 求取 a, b 的最大公因數 gcd
    // 以及 x, y 使得 a*x + b*y = gcd
    LL gcd_extend(LL a, LL b, LL *x, LL *y) { 
        if (a == 0) { 
            *x = 0, *y = 1; 
            return b; 
        } 
    
        LL x1, y1; // To store results of recursive call 
        LL gcd = gcd_extend(b%a, a, &x1, &y1); 
    
        *x = y1 - (b/a) * x1; 
        *y = x1; 
    
        return gcd; 
    }
    // 求 a_inv 使得 (a * a_inv) % m = gcd(a, m)
    // 若 a, m 互質，即求 a 在 mod m 群的反元素 a_inv 
    LL mod_inv(LL a, LL m) { 
        LL x, y; 
        LL g = gcd_extend(a, m, &x, &y); 
        // 處理 x 爲負的情形 
        LL a_inv = (x%m + m) % m; 
        return a_inv;
    }
    // 求 x^n % m
    LL mod_pow(LL x, LL n, LL m) {
        if (n == 0) {
            return 1;
        } else if (n & 1) {
            LL half = mod_pow(x, n/2, m);
            return (half * half % m) * x % m;
        } else {
            LL half = mod_pow(x, n/2, m);
            return half * half % m;
        }
    }
    // 連乘
    LL mul(LL from, LL to, LL m) {
        LL ret = 1;
        for (LL i = from; i <= to; i++) {
            ret *= i;
            ret %= m;
        }
        return ret;
    }
    // 求 (C n 取 k) % m
    LL mod_comb(LL n, LL k, LL m) {
        LL mi = k < n-k ? k : n-k;
        LL up = mul(n - mi + 1, n, m);
        LL down = mul(1, mi, m);
        return (up * mod_inv(down, m)) % m;
    }
    // 求 (P n 取 k) % m
    LL mod_perm(LL n, LL k, LL m) {
        LL up = mul(n - k + 1, n, m);
        return up;
    }
}

const LL MOD = 1e9 + 7;

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    LL N, M, K; cin >> N >> M >> K;
    LL ans = 0;
    LL res = 0;
    for (int i = 1; i < M; ++i) {
        res += i * (M - i);
        res %= MOD;
    }
    ans += Number::mod_pow(N, 2, MOD) * res % MOD;
    // cout << ans << endl;
    res = 0;
    for (int i = 1; i < N; ++i) {
        res += i * (N - i);
        res %= MOD;
    }
    ans += Number::mod_pow(M, 2, MOD) * res % MOD;
    // cout << ans << endl;
    ans = ans * Number::mod_comb(N * M - 2, K - 2, MOD) % MOD;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1000000007;

int main(){
  string s;
  cin>>s;
  ll ans=0;

  if (s.size()==1){
    cout<<s<<endl;
    return 0;
  }

  vector<int> num(s.size());
  for (int i=0;i<s.size();i++){
    num[i] = s[i]-'0';
  }

  for (ll i=0; i<1<<(s.size()-1); i++){
    vector<int> ope(s.size());
    ll bit=i;
    for (int j=0;j<(s.size()-1);j++){
      ope[j] = bit&1;
      bit>>=1;
    }
    vector<ll> sum(10,0);
    int pt=0;
    sum[0]=num[0];
    for (int j=0;j<ope.size()-1;j++){
      if (ope[j]==1) {
        pt++;
        sum[pt]+=num[j+1];
      }
      if (ope[j]==0) {
        sum[pt]*=10;
        sum[pt]+=num[j+1];
      }
    }
    for (int j=0;j<10;j++){
      ans+=sum[j];
    }

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


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>

#define ll long long

const ll INF = 1ll << 60;

using namespace std;

int n;
ll h[100010];
ll dp[100010];

void solve() {
    scanf("%d", &n);
    for (int i=0; i<n;i++) {
        scanf(" %lld", &h[i]);
        dp[i] = INF;
    }
    dp[0] = 0;
    for (int i = 1; i<n; i++) {
        if (dp[i]>(dp[i-1]+abs(h[i]-h[i-1]))) dp[i] = dp[i-1]+abs(h[i]-h[i-1]);
        if ((i>1) && (dp[i]>(dp[i-2]+abs(h[i]-h[i-2])))) dp[i] = dp[i-2]+abs(h[i]-h[i-2]);
    }
    printf("%lld\n", dp[n-1]);
}

int main() {
    solve();

    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define MP make_pair
#define PB push_back
#define SZ(a) ((int)a.size())
typedef long long ll;

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

int x;

int main () {
  scanf("%d", &x);
  printf("%d\n", 360 / gcd(x,360));
  return 0;
}


Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const ll INF = 1LL<<60;
const int ny[4] = {-1,1,0,0}, nx[4] = {0,0,-1,1};
int sy,sx,gy,gx;

int main(){
  int n; cin >> n;
  vector<int> l(n);
  rep(i,n){
    cin >> l[i];
  }
  int sum = 0;
  sort(l.begin(), l.end());
  rep(i,n-1){
    sum += l[i];
  }
  if(sum > l[n-1]) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
/**
*    author:  souzai32
*    created: 14.08.2020 12:05:39
**/

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {

    int n;
    cin >> n;
    vector<int> c(n-1),s(n-1),f(n-1);
    rep(i,n-1) cin >> c.at(i) >> s.at(i) >> f.at(i);

    vector<int> time(n);

    for(int i=0; i<n-1; i++){
        time.at(i)+=s.at(i)+c.at(i);
        for(int j=i+1; j<n-1; j++){
            if(time.at(i)<=s.at(j)) time.at(i)=s.at(j);
            else if((time.at(i)-s.at(j))%f.at(j)) time.at(i)+=f.at(j)-(time.at(i)-s.at(j))%f.at(j);
            time.at(i)+=c.at(j);
        }
    }
    
    rep(i,n) cout << time.at(i) << endl;

    return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1LL << 60;
constexpr int INF = 3000000007;
const double INFD = 1e100;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// ----------------------------------------------------------------------------
const string MINUSINF = "-";
ll match[10] = {2,5,5,4,5,6,3,7,6};
string dp[11000];


void chmax(string &a, string b){
  if(a == MINUSINF) a = b;
  if(a.size() < b.size()) a = b;
  else if(a.size() == b.size()){
    if(a < b) a = b;
  }
}

int main(){
  int N,M;
  cin >> N >> M;
  vector<int> A(M);
  for(int i=0; i<M; i++){
    cin >> A[i];
  }
  for(int i=0; i<11000; i++){
    dp[i] = MINUSINF;
  }
  dp[0] = "";
  for(int i=0; i<=N; i++){
    if(dp[i] == MINUSINF) continue;
    for(auto a : A){
      chmax(dp[i+match[a-1]],dp[i] + (char)('0' + a));
    }
  }
  cout << dp[N] << endl;
  return 0;
}


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

#define ll long long
#define sd(x) scanf("%d", &(x))
#define pii pair<int, int>
#define F first
#define S second
#define all(c) ((c).begin()), ((c).end())
#define sz(x) ((int)(x).size())
#define ld double

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<", "<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"{";
	for(int i = 0;i < (int)v.size(); i++){
		if(i)os<<", ";
		os<<v[i];
	}
	os<<"}";
	return os;
}

#ifdef LOCAL
#define cerr cout
#else
#endif

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::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...);
}
#else
#define trace(...)
#endif

int getp(ll x, int p){
    for(int i = 0; ; i++){
        if(x % p != 0) return i;
        x /= p;
    }
}
const int N = 70;
int freq[N][N];
char s[20];
int main(){
    int n; sd(n);
    ll ans = 0;
    for(int i = 0; i < n; i++){
        scanf("%s", s);
        int k = strlen(s);
        ll num = 0, den = 1;
        bool post = false;
        for(int j = 0; j < k; j++){
            if(s[j] == '.'){
                post = 1;
                continue;
            }
            num = num * 10 + s[j] - '0';
            if(post){
                den *= 10;
            }
        }
        num *= 1000000000 / den;
        int a = getp(num, 2), b = getp(num, 5);
        freq[a][b]++;
        if(a >= 9 && b >= 9) ans--;
    }

    for(int i = 0; i < N; i++) for(int j = 0; j < N; j++)
    for(int k = 0; k < N; k++) for(int l = 0; l < N; l++){
        if(i + k >= 18 && j + l >= 18) ans += freq[i][j] * (ll) freq[k][l];
    }
    printf("%lld\n", ans / 2);
}

Measured memory_bytes: 3736
#!usr/bim/python
#! -*- coding: utf-8 -*-

import numpy as np

hw = raw_input()
hw = hw.split()
h,w = map(int,hw)

c = np.zeros([10,10],int)
for i in range(10):
    line = raw_input()
    line = line.split()
    c[i] = map(int,line)

#a = np.zeros([h,w],dtype=int)
#for i in range(h):
#    line = raw_input()
#    line = line.split()
#    a[i] = map(int,line)

suji_num = np.zeros([10],int)
for i in range(h):
    line = raw_input()
    line = line.split()
    line = map(int,line)
    for j in range(10):
        num = line.count(j)
        suji_num[j] += num

maryoku = np.zeros([10],int)

for i in range(10):
    maryoku[i] = c[i,1]

i = 1
while i < max(maryoku):
    #print maryoku
    for j in range(10):
        if maryoku[j] == i:
            for k in range(10):
                keiyum = c[k,j]+i
                if keiyum < maryoku[k]:
                    maryoku[k] = keiyum
    i += 1

ans = 0
for i in range(10):
    ans += suji_num[i] * maryoku[i]

print ans


Measured memory_bytes: 19308
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i,a,b) for(ll i=(a);i<(b);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)
//#define INF (1LL<<59)

#define MAX_V 10000

struct edge{int to, cost;};
vector<edge> G[MAX_V];

int dfs(vector<int> &depth, int cur, int prev){
    depth[cur] = 0;
    
    for(auto e:G[cur]){
        if(e.to==prev)continue;
        depth[cur] = max(depth[cur], e.cost + dfs(depth, e.to, cur));
    }
    return depth[cur];
}


void dfs2(const vector<int> &depth, vector<int> &ans, int cur, int prev, int d_par){
    vector<pii> cand;
    cand.pb(0,-1);
    
    for(auto e:G[cur]){
        if(e.to==prev){
            ans[cur] = max(ans[cur], d_par+e.cost);
            cand.pb(d_par+e.cost, e.to);
            continue;
        }
        else{
            ans[cur] = max(ans[cur], e.cost+depth[e.to]);
//            cout<<cur<<" -> "<<e.to<<endl;
//            cout<<e.cost<<" "<<depth[e.to]<<endl;
            cand.pb(e.cost+depth[e.to], e.to);
        }
    }
    sort(all(cand),greater<pii>());
    
    for(auto e:G[cur]){
        if(e.to==prev)continue;
        if(e.to==cand[0].second)dfs2(depth, ans, e.to, cur, cand[1].first);
        else                    dfs2(depth, ans, e.to, cur, cand[0].first);
    }
}


int main(){
    int v;
    cin>>v;
    
    rep(i,v-1){
        int s,t,c;
        cin>>s>>t>>c;
        G[s].pb(edge{t,c});
        G[t].pb(edge{s,c});
    }
    
    vector<int> depth(v,0);
    depth[0] = dfs(depth,0,-1);
    
    vector<int> ans(v,0);
    dfs2(depth, ans, 0, -1, INF);
    
    
    for(auto e:ans)cout<<e<<endl;
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

const llong inf = 1100100100100100ll;
const llong mod = 1e9+7;

int main() {
	llong N;
	vector<llong> A, B;

	cin >> N;
	A.resize(N+1);
	B.resize(N+0);
	for (int i = 0; i < N+1; ++i)
		cin >> A[i];
	for (int i = 0; i < N; ++i)
		cin >> B[i];

	llong ans = 0;
	for (int i = 0; i < N; ++i) {
		llong kil = min(A[i], B[i]);
		ans += kil;
		A[i] -= kil;
		B[i] -= kil;
		if (B[i] > 0) {
			kil = min(A[i+1], B[i]);
			ans += kil;
			A[i+1] -= kil;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
#include <cstring>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

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

    int N;
    cin >> N;
    vector<vector<int>> G(N, vector<int>(N));
    for(int i = 0; i < N; ++i){
        string S;
        cin >> S;
        for(int j = 0; j < N; ++j){
            G[i][j] = S[j] - '0';
        }
    }
    vector<int> color(N, -1);
    auto is_bipartite = [&](auto&& self, int u = 0, int c = 0) -> bool {
        color[u] = c;
        for(int v = 0; v < N; ++v){
            if(!G[u][v])    continue;
            if(color[v] == -1 && !self(self, v, c ^ 1)) return false;
            else if(color[v] == c)  return false;
        }
        return true;
    };
    if(!is_bipartite(is_bipartite)){
        cout << -1 << endl;
        return 0;
    }
    int ans = -1;
    for(int u = 0; u < N; ++u){
        for(int v = 0; v < N; ++v)  color[v] = -1;
        bool ok = true;
        int max_number = 1;
        queue<P> que;
        que.emplace(u, 1);
        while(!que.empty()){
            int cur = que.front().first, c = que.front().second;
            que.pop();
            if(color[cur] != -1)    continue;
            color[cur] = c;
            chmax(max_number, c);
            for(int nxt = 0; nxt < N; ++nxt){
                if(!G[cur][nxt])    continue;
                if(color[nxt] == -1)    que.emplace(nxt, c + 1);
                else if(color[nxt] != c - 1 && color[nxt] != c + 1){
                    ok = false;
                    break;
                }
            }
            if(!ok) break;
        }
        if(ok)  chmax(ans, max_number);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3872