akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
using namespace std;
const int nmax=100005;
long long n,a[nmax],st,dr,i,j;
int main()
{
    //freopen("data.in","r",stdin);
    cin>>n;
    for(i=1;i<=n;i++)
        cin>>a[i];
    st=2;dr=2;
    for(i=n;i>=1;i--)
    {
        st=1LL*(st/a[i]+(st%a[i]!=0))*a[i];
        dr=1LL*(dr/a[i])*a[i]+a[i]-1;
    }
    if(st<=dr) cout<<st<<' '<<dr<<'\n';
    else cout<<"-1";
    return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	int a,b;
	scanf("%d %d",&a,&b);
	b=b*2;
	if(a-b<0){
		printf("0\n");
	}
	else{
		printf("%d\n",a-b);
	}
	return 0;
}

Measured memory_bytes: 128
from collections import Counter

N, P = map(int, input().split())
S = input()

sum = 0
if P == 2 or P == 5:
    for i in range(N):
        if int(S[i]) % P == 0:
            sum += i+1
    print(sum)
    exit()

m = []
t = 1
q = 0
for i in range(N,0,-1):
    q = ((int(S[i-1]) % P) * t + q) % P
    m.append(q)
    t = (10 * t) % P
    
mc = Counter(m)

for v in mc.values():
    if v > 1:
        sum += v*(v-1)//2

sum += mc[0]

print(sum)

Measured memory_bytes: 11996
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
    ll ar[4]={0};
    ll a,b; cin>>a>>b;
    ar[a]=1;
    ar[b]=1;
    if(ar[1]==0) cout<<1<<endl;
    else if(ar[2]==0) cout<<2<<endl;
    else cout<<3<<endl;
}

Measured memory_bytes: 256
n = int(input())
happiness = []
for _ in range(n):
    a,b,c = map(int,input().split())
    happiness.append((a,b,c,a,b,c))
#最後に選ぶのがa,b,c各々の時の幸福度の最大値
dp = [[0]*3 for _ in  range(n+1)]

for i in range(1,n+1):
    for j in range(3):
        for k in range(3):
            if k != j:
                dp[i][j] = max(dp[i][j],dp[i-1][k] + happiness[i-1][j])
print(max(dp[n]))

Measured memory_bytes: 42536
#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair

/*int P[10010];
void init(int n){//Union-find
    for(int i=0;i<n;++i)P[i]=i;
}
int root(int a) {
    if(P[a]==a)return a;
    return (P[a]=root(P[a]));
}
bool is_same_set(int a,int b){
    return root(a) == root(b);//代表元を求める
}
void unite(int a,int b){
    P[root(a)]=root(b);
}//対set,グラフ？
//セグメント木？？
*/

double dot_product(xy_t a, xy_t b) { return (conj(a)*b).real(); }//内積
double cross_product(xy_t a, xy_t b) { return (conj(a)*b).imag(); }//外積
xy_t projection(xy_t p, xy_t b) { return b*dot_product(p,b)/norm(b); }//投影
//対図形

#define mod 1000000007
/*ll f[2001];
//int n,k とかしておく

ll pw(ll x, ll y){//euclidの互除法より
    ll a= 1;
    while(y){
        if(y&1){//奇数なら
            a = a*x%mod;
        }
        x = x*x%mod;
        y /= 2;
    }
    return a;
}

ll modinv(ll x){//逆元を求める
    return pw(x, mod - 2 );
}

ll comb(int n,int r){
    if(n<r){
        return 0;
    }
    return f[n] * modinv(f[r])%mod*modinv(f[n-r])%mod;
}//対combination//ただしfは用意してね
*/

//cerrはコメントアウトしなくても通る

vector<pair<int,int>> B,R;
int makedb[100],makedr[100];

int main(){
    int n;
    cin >> n;
    rep(i,n){
        int a,b;
        cin >> a>> b;
        R.push_back(mp(a,b));
    }
    rep(i,n){
        int c,d;
        cin >> c>>d;
        B.push_back(mp(c,d));
    }
    sort(R.begin(),R.end());
    sort(B.begin(),B.end());
    cerr<<"sortok"<<endl;
    rep(i,n){
        int x,y;
        tie(x,y)=B[i];
        cerr<<"tieok"<<endl;
        int temp=-1;
        int tempr=-1;
        for(int j=0;j<n&&R[j].first<x;j++){
            if(temp<R[j].second&&R[j].second<y&&makedr[j]!=1){
                temp=R[j].second;
                tempr=j;
            }
        }
        cerr<<"tempr"<<tempr<<endl;
        if(tempr>=0){
            makedr[tempr]=1;
            cerr<<R[tempr].first<<' '<<R[tempr].second<<' '<<B[i].first<<' '<<B[i].second<<endl;

        }
        makedb[i]=1;
    }
    int ans=0;
    rep(i,n){
        if(makedr[i]==1){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}//もう一度


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    string s, t;
    cin >> s >> t;
    if(s.size() + 1 == t.size() && s == t.substr(0, s.size())){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int a, b;
    cin >> a >> b;
    
    if(a % 2 == 0 || b % 2 == 0){
        cout << "Even\n";
    }
    else{
        cout << "Odd\n";
    }
}

Measured memory_bytes: 256
x, y = map(int, input().split())
G1 = [1, 3, 5, 7, 8, 10, 12]
G2 = [4, 6, 9, 11]
G3 = [2]
if (x in G1 and y in G1) or (x in G2 and y in G2) or (x in G3 and y in G3):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <iostream>
#include <vector>

using namespace std;

vector<int> adjacent[100'000];
bool visited[100'000];
bool onPath[100'000];
int dist[100'000];

void fill(const int node, const int end, const int d)
{
    visited[node] = true;
    dist[node] = d;
    if (node == end)
    {
        onPath[node] = true;
    }
    for (const int &adj : adjacent[node])
    {
        if (!visited[adj])
        {
            fill(adj, end, d + 1);
            onPath[node] = onPath[node] || onPath[adj];
        }
    }
}

bool visited2[100'000];

void countNodes(const int node, const int stop, int &count)
{
    visited2[node] = true;
    count++;

    for (const int &adj : adjacent[node])
    {
        if (!visited2[adj] && adj != stop)
        {
            countNodes(adj, stop, count);
        }
    }
}

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

    for (int i = 0; i < N - 1; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        adjacent[a].push_back(b);
        adjacent[b].push_back(a);
    }

    for (int i = 0; i < N; i++)
        onPath[i] = visited[i] = false;
    fill(0, N - 1, 0);

    int stop;
    for (int i = 0; i < N; i++)
    {
        if (onPath[i] && dist[i] - 1 + 1 == dist[N - 1] + 1 - (dist[N - 1] + 1) / 2)
        {
            stop = i;
        }
    }

    for (int i = 0; i < N; i++)
        visited2[i] = false;
    int cnt = 0;
    countNodes(0, stop, cnt);

    cout << (cnt > N - cnt ? "Fennec" : "Snuke") << endl;

    return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<3; i++)

using namespace std;
int main(void){
    vector<int>L(3,0);
    rep(i, 3) cin >> L[i];
    if(count(L.begin(), L.end(), 5)==2 and count(L.begin(), L.end(), 7)==1){
        cout << "YES";
    }else{
        cout << "NO";
    }
}

Measured memory_bytes: 256
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<iomanip>
#include<sstream>
#include<cmath>
#include<bitset>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(int i = 1;i <=  n; i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj),rend(obj)
typedef long long int ll;
typedef long double ld;
const ll INF = (1LL << 60);
const int INf = 1e9;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T& val) {
    fill((T*)array, (T*)(array + N), val);
}bool isPrime(int x) {
    int i;
    if (x < 2)return 0;
    else if (x == 2) return 1;
    if (x % 2 == 0) return 0;
    for (i = 3; i * i <= x; i += 2) if (x % i == 0) return 0;
    return 1;
}

int main() {   
    int n,k=0; cin >> n; vector<int> b;
    for (int i = 3; i < 55555; i += 5) {
        if (isPrime(i)) {
            b.push_back(i);
        }
    }
    rep(i, n - 1) cout << b[i] << " ";
    cout << b[n - 1] << endl;
}

Measured memory_bytes: 256
//C
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

//C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Others
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 int dx[8] = { -1,0,1,-1,1,-1,0,1 };
const int dy[8] = { 1,1,1,0,0,-1,-1,-1 };


//LOVE NyantakoGG	https://www.youtube.com/channel/UC6XdFs8T6Ei54O0FYl3PVVA


using namespace std;



int main() {
	int A, B, K;
	cin >> A >> B >> K;
	for (int i = min(A, B); i >= 0; i--) {
		if (A % i == 0 && B % i == 0) {
			K--;
			if (K) {

			}
			else {
				cout << i << endl;
				return 0;
			}
		}
	}
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define x first
#define y second

typedef long double ld;

const int N=201000;
const ld pi=acos(-1.0);

namespace Worker
{
	int stk[N],tot;
	int solve(int *s,int n)
	{
		tot=0;
		for(int i=1;i<=n;i++)
		{
			if(!tot || s[i]>=stk[tot])stk[++tot]=s[i];//fuck
			else (*std::upper_bound(stk+1,stk+tot+1,s[i]))=s[i];
		}

		return tot;
	}
}

namespace NanTi
{
	typedef std::pair<int,int> pii;

	pii s[N];
	int t[N];
	int x0,x1,y0,y1,n;

	void initialize()
	{
		scanf("%d%d%d%d",&x0,&y0,&x1,&y1);
		if(x0>x1)std::swap(x0,x1),std::swap(y0,y1);

		scanf("%d",&n);
		int tmp=0,miny=std::min(y0,y1),maxy=std::max(y0,y1);
		for(int i=1;i<=n;i++)
		{
			scanf("%d%d",&s[i].x,&s[i].y);
			if(s[i].x<x0 || s[i].x>x1 || s[i].y<miny || s[i].y>maxy)continue;
			s[++tmp]=s[i];
		}
		n=tmp;
		std::sort(s+1,s+n+1);
		for(int i=1;i<=n;i++)
			t[i]=s[i].y;
	}

	void solve()
	{
		initialize();
		if(y0>y1)for(int i=1;i<=n;i++)t[i]*=-1;

		int m=Worker::solve(t,n);

		int dx=std::abs(x0-x1)+1,dy=std::abs(y0-y1)+1;

		ld delta=pi*5-20,ans=(dx+dy-2)*100.0;
		ans+=delta*m;
		
		if(m==dx || m==dy)ans+=pi*5;
		
		printf("%.20Lf\n",ans);
	}
}

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


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

#define REP(i,n) for(long long i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(long long i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

ll dp[102][200000];

int main(){
  int N, W;
  cin >> N >> W;
  vector<int> w(N), v(N);
  ll sum = 0;
  REP(i, N){
    cin >> w[i] >> v[i];
    sum+= v[i];
  }
  REP(i, N+1){
    REP(j, sum+1){
      dp[i][j] = INF*INF;
    }
    REP(i, N){
      dp[i][0] = 0;
    }
  }
  REP(i, N){
    REP(j, sum+1){
      dp[i+1][j] = dp[i][j];
    }
    REP(j, sum+1){
      dp[i+1][j+v[i]] = min(dp[i+1][j+v[i]], dp[i][j]+w[i]);
    }
  }
  REPR(i, sum){
    if(dp[N][i] <= W){
      cout << i << endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 157184
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
	string s; cin >> s;
	ll po[4] = {};
	map<char, ll> m = {
		{'N', 0},
		{'W', 1},
		{'S', 2},
		{'E', 3}
	};
	for(ll i = 0; i < s.size(); ++i) po[m.find(s[i])->second]++;
	for(ll i = 0; i < 4; ++i) po[i] = min<ll>(po[i], 1);
	cout << ((po[0] ^ po[2]) || (po[1] ^ po[3]) ? "No\n" : "Yes\n");
	return 0;
}

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

int main() {
    int N, M;
    cin >> N >> M;
    int cnt = 0;
    map<int, int> ma;
    for (int i = 0; i < N; i++) {
        int K;
        cin >> K;
        for (int j = 0; j < K; j++) {
            int A;
            cin >> A;
            ma[A]++;
        }
    }
    for (auto o : ma) {
        if (o.second == N) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N, K, a[100010], acc[100010], accb[100010];

signed main() {
    cin >> N >> K;
    rep(i,0,N) {
        cin >> a[i+1];
        acc[i+1] = acc[i] + a[i+1];
        accb[i+1] = accb[i] + (a[i+1] > 0 ? a[i+1] : 0);
    }

    int ans = -INF, whsum = accb[N];
    repq(i,1,N-K+1) {
        int ub = i + K - 1;
        chmax(ans, acc[ub] - acc[i-1] + whsum - accb[ub] + accb[i-1]);
        chmax(ans, whsum - accb[ub] + accb[i-1]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
#include <cstdio>
#include <algorithm>

using namespace std;

const int mod = 1000000007;
int a[1001];
int b[1001];

int main() {
    int n, m, c = 0, i, j, k;
    long long ans = 1;
    
    scanf("%d %d", &n, &m);
    
    for (i = 0; i < n; i++) scanf("%d", &a[i]);
    for (i = 0; i < m; i++) scanf("%d", &b[i]);
    
    sort(a, a + n);
    reverse(a, a + n);
    sort(b, b + m);
    reverse(b, b + m);
    
    for (i = n * m, j = 0, k = 0; i > 0; i--) {
        if (a[j] == i && b[k] == i) {
            c += j + k;
            j++;
            k++;
        } else if (a[j] == i) {
            ans = ans * k % mod;
            c += k - 1;
            j++;
        } else if (b[k] == i) {
            ans = ans * j % mod;
            c += j - 1;
            k++;
        } else {
            ans = ans * c % mod;
            c--;
        }
    }
    
    printf("%lld\n", ans);
    
    return 0;
}


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

#define pb insert
#define eb emplace_back
#define ff first
#define ss second
typedef long long int ll;
typedef long double ld;
#define all(a) a.begin(),a.end()
typedef vector<ll> vl;
typedef pair<ll,ll> pp;
typedef vector<pp> vp;
typedef map<pp,ll> ip;
typedef map<pp,char> ic;
typedef map<ll,ll> ii;
typedef set<ll> sl;
typedef set< pair<ll,ll> > sp;
const ll mod = 998244353;


//main code
int main() {
    ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
    
    ll x,y,z;cin>>x>>y>>z;
    string s;cin>>s;
    ll i=0;
    vl a,b;
    while(i<s.size()){
        while(s[i]=='x'){
            i++;
        }
        a.eb(i+1);
        
        i+=z+1;
        
        if(a.size()==y) break;
    }
    reverse(all(s));
    i=0;
    
    while(i<s.size()){
        while(s[i]=='x'){
            i++;
        }
        
            
        b.eb(x-i);

        i+=z+1;
        
        if(b.size()==y) break;
    }
    
    reverse(all(b));
    for(int i=0;i<y;i++){
        if(a[i]==b[i]) cout<<a[i]<<"\n";
    }
    return 0;
    
    
}
    

Measured memory_bytes: 5128
//AtCoder ABC116 A - Right Triangle
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
int main() {
    vector<ll> e(3);
    cin>>e[0]>>e[1]>>e[2];
    sort(e.begin(),e.end());
    ll ans=e[0]*e[1]/2;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#define REP(i, a, n) for(int i = a; i < n; i++)
using namespace std;


int n, c, a[100001], cnt;

int main(void) {
  while(cin >> n, n != 0) {
    REP(i, 1, n + 1) {
      cin >> c;

      if(i % 2 == 1) {
        a[i] = c;
      } else {
        a[i] = c;
        for(int j = i - 1; j >= 1 && a[j] != c; j--) {
          a[j] = c;
        }
      }
    }

    cnt = 0;
    REP(i, 1, n + 1) {
      if(a[i] == 0) cnt++;
    }

    cout << cnt << endl;
  }
  return 0;
}

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

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

#define INF 100000000
#define MOD 1000000007
#define writeln(n) cout<<n<<endl
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//vector<tuple<long long, long long, long long>>vec;

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;
}

llong pownew(llong m, llong n) {
    if (n == 0) { return 1; }
    if (n % 2 == 0) { return pow(m*m, n/2); }
    return pow(m, n-1) * m;
}

bool isprime(int p) {
    if (p == 1) return false;
    for (int i = 2; i < p; i++) {
        if (p%i == 0) return false;
    }
    return true;
}

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

const int inf=100000000;

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    llong Q,H,S,D;
    cin>>Q>>H>>S>>D;
    llong N; cin>>N;
    Q*=4;
    H*=2;
    llong ans=0;
    if(N%2!=0)
    {
        ans=min(N/2*D+min({Q,H,S}),N*min({Q,H,S}));
    }
    else
        {
        ans=min(N/2*D,N*min({Q,H,S}));
        }
    cout<<ans<<endl;
    return  0;
}


Measured memory_bytes: 256
<?php
$N = (int)trim(fgets(STDIN));
$A = explode(' ', fgets(STDIN));
$A = array_map(function ($a) {
    return (int)$a;
}, $A);
$ans = 0;
$dp = [];
$dp[0][0] = 0;

for ($i = 0; $i < $N; $i++) {
    $max_A = max($A);
    $index = array_keys($A, $max_A)[0];
    $A[$index] = 0;
    $dp[$i + 1][0] = $dp[$i][0] + $max_A * abs($N - ($i + 1) - $index);
    for ($l = 0; $l < $i; $l++) {
        $dp[$i + 1][$l + 1] = max($dp[$i][$l + 1] + $max_A * abs(($N - ($i - $l)) - $index), $dp[$i][$l] + $max_A * abs($index - $l));
    }
    $dp[$i + 1][$i + 1] = $dp[$i][$i] + $max_A * abs($index - $i);
}

for ($i = 0; $i <= $N; $i++) {
    $ans = max($dp[$N][$i], $ans);
}

echo $ans;

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

int gcd(int a, int b) {
	return b ? gcd(b, a % b) : a;
}

int main()
{
	int A, B, C;
	cin >> A >> B >> C;
	cout << (C % gcd(A, B) == 0 ? "YES" : "NO") << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long unsigned int ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://beta.atcoder.jp/contests/abc054/tasks/abc054_c

int p[10][10] = {};

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

    int a, b;
    REP(i, M) {
        cin >> a >> b;
        p[a][b] = 1;
        p[b][a] = 1;
    }

    vector<int> perm(N-1);
    REP(i, N-1) perm[i] = i + 2;
    sort(perm.begin(), perm.end());

    int ans = 0;
    do {
        int now = 1;
        for (int i = 0; i < perm.size(); i++) {
            if (!p[now][perm[i]]) break;
            now = perm[i];
            if (i == perm.size()-1) ans++;
        }
    } while(next_permutation(perm.begin(), perm.end()));

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

import sys


INF = sys.maxsize // 10


def minimize(s, t):
    ns = len(s)
    nt = len(t)
    res = INF
    for start_idx in range(ns - nt + 1):
        cand = sum(c != d for c, d in zip(s[start_idx: start_idx + nt], t))
        res = min(res, cand)
    return res


def main():
    s = input()
    t = input()
    print(minimize(s, t))


if __name__ == '__main__':
    main()

Measured memory_bytes: 9080
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <string>
using namespace std;

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b) cout<<c;
    if(a==c) cout<<b;
    if(b==c) cout<<a;

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

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

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n, T; cin >> n >> T;
  int ans = 0, now = 0;
  while (n--) {
    int t; cin >> t;
    if (now < t) {
      now = t;
    }
    ans += t + T - now;
    now = t + T;
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
/*
    Author - Param Kothari
    Ah shit, here we go again
*/

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

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mk make_pair 
 
typedef long long ll;
typedef long double ld;

void solve(){
    ll res = 0;
    int k;
    cin >> k;
    for(int i = 1; i <= k; i++){
        for(int j = 1; j <= k; j++){
            for(int l = 1; l <= k; l++){
                res += __gcd(__gcd(i, j), l);
            }
        }
    }
    cout << res << "\n";
    return;
}
 
int main(){
    IOS;
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}



Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

int main() {
    string a,b,c;
    cin>>a>>b>>c;
    string s = {a[0],b[0],c[0]};
    transform(s.begin(), s.end(), s.begin(), ::toupper);
    cout<<s<<endl;
    
}



Measured memory_bytes: 256
from collections import defaultdict, deque


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N, M = read_ints()
    out_degree = [0]*N
    max_path = [0]*N
    G = defaultdict(list)
    for _ in range(M):
        x, y = read_ints()
        x -= 1
        y -= 1
        out_degree[x] += 1
        G[y].append(x)
    Q = [i for i, degree in enumerate(out_degree) if degree == 0]
    while len(Q):
        node = Q.pop()
        while len(G[node]):
            parent = G[node].pop()
            out_degree[parent] -= 1
            max_path[parent] = max(max_path[parent], max_path[node]+1)
            if out_degree[parent] == 0:
                Q.append(parent)
    return max(max_path)


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 71000
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };

    let n: usize = sc.read();
    let m: usize = sc.read();
    let q: usize = sc.read();

    let mut e = vec![];
    let mut uf = UnionFind::new(n);
    for _ in 0..q {
        let a: usize = sc.read();
        let b: usize = sc.read();
        let c: usize = sc.read();
        if c == 0 {
            uf.unite(a, b);
        } else {
            e.push((a, b));
        }
    }

    for &(a, b) in e.iter() {
        if uf.find(a) == uf.find(b) {
            println!("No");
            return;
        }
    }

    let used = uf
        .sizes
        .into_iter()
        .filter(|&s| s > 0)
        .map(|s| s - 1)
        .sum::<usize>();

    if m == n - 1 {
        if e.is_empty() {
            println!("Yes");
        } else {
            println!("No");
        }
    } else {
        let min = used + uf.size;
        let max = used + uf.size * (uf.size - 1) / 2;
        if min <= m && m <= max {
            println!("Yes");
        } else {
            println!("No");
        }
    }
}

pub struct UnionFind {
    parent: Vec<usize>,
    sizes: Vec<usize>,
    size: usize,
}

impl UnionFind {
    pub fn new(n: usize) -> UnionFind {
        UnionFind {
            parent: (0..n).map(|i| i).collect::<Vec<usize>>(),
            sizes: vec![1; n],
            size: n,
        }
    }

    pub fn find(&mut self, x: usize) -> usize {
        if x == self.parent[x] {
            x
        } else {
            let px = self.parent[x];
            self.parent[x] = self.find(px);
            self.parent[x]
        }
    }

    pub fn unite(&mut self, x: usize, y: usize) -> bool {
        let parent_x = self.find(x);
        let parent_y = self.find(y);
        if parent_x == parent_y {
            return false;
        }

        let (large, small) = if self.sizes[parent_x] < self.sizes[parent_y] {
            (parent_y, parent_x)
        } else {
            (parent_x, parent_y)
        };

        self.parent[small] = large;
        self.sizes[large] += self.sizes[small];
        self.sizes[small] = 0;
        self.size -= 1;
        return true;
    }
}
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .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: 10492
#include <bits/stdc++.h>
#include <stdio.h>

using namespace std;
#define ll long long
#define all(x) x.begin(), x.end()
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
const int N = 1e5 + 10;
const double eps = 1e-9;

int main() {
    int n, k, one;
    cin >> n >> k;
    vi v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    cout << (n - 1 + k - 2) / (k - 1) << endl;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H,W;
  cin >> H >> W;
  
  for(int i = 0; i < W+2; i++){
    cout << "#";
  }
  cout << endl;
  
  for(int i = 0; i < H; i++){
    string s;
    cin >> s;
    s = "#" + s + "#";
    cout << s << endl;
  }
  
  for(int i = 0; i < W+2; i++){
    cout << "#";
  }
  cout << endl;
  
}
    

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

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/2;
    public static final int inf = Integer.MAX_VALUE/2;

    static void solve(InputReader in, PrintWriter out){
        int n = in.ni();
        int sqrt = (int)Math.round(Math.sqrt(1+8*n));
        if(sqrt*sqrt==(1+8*n)&&(1+sqrt)%2==0){
            out.println("Yes");
            int k = (1+sqrt)/2;
            out.println(k);
            ArrayList<Integer>[] ans = new ArrayList[k];
            for (int i = 0; i < k; i++) {
                ans[i] = new ArrayList<>();
            }
            int a = 1;
            for (int i = 1; i < k; i++) {
                for (int j = 0; j < i; j++) {
                    ans[i].add(a);
                    ans[j].add(a);
                    a++;
                }
            }
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < k; i++) {
                sb.append(ans[i].size()+" ");
                for(Integer j: ans[i]) sb.append(j+" ");
                sb.append("\n");
            }
            out.println(sb);
        }else{
            out.println("No");
        }
    }

    public static void main(String[] args){
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public double nd(){
            return Double.parseDouble(ns());
        }
        public char nc(){
            return ns().toCharArray()[0];
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 51824
// Copyright 2020 yaito3014
#include <bits/stdc++.h>

int main() {
  using namespace std;
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  using namespace chrono_literals;
  chrono::high_resolution_clock clock;
  auto be = clock.now();
  int D;
  cin >> D;
  array<int, 26> c;
  for (auto& e : c) cin >> e;
  vector<array<int, 26>> d(D);
  for (auto& r : d)
    for (auto& e : r) cin >> e;
  auto eval = [&](vector<int> t) {
    int S = 0;
    array<int, 26> last = {};
    for (int i = 0; i < D; ++i) {
      S += d[i][t[i]];
      last[t[i]] = i + 1;
      for (int j = 0; j < 26; ++j) S -= c[j] * (i + 1 - last[j]);
    }
    return S;
  };

  mt19937 mt(random_device{}());
  uniform_int_distribution<int> dist_type(0, 25), dist_day(0, D - 1);
  vector<int> t(D);
  generate(begin(t), end(t), [&]() { return dist_type(mt); });
  int S = eval(t);
  int cnt = 0;
  while (clock.now() - be < 1900ms) {
    int day = dist_day(mt);
    int prv = t[day];
    t[day] = dist_type(mt);
    int score = eval(t);
    if (cnt < 1000 && score > S && ++cnt) continue;
    cnt = 0;
    t[day] = prv;
  }
  for (const auto& e : t) cout << (e + 1) << '\n';
}


Measured memory_bytes: 3716
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
    int n;
    while(scanf("%d",&n)==1)
    {
            int i,max,k;
            for(i=1;i*i<=n;i++)
            {
                    for(k=i;k*i<=n;)
                    {
                            k=k*i;
                            if(k==i)
                                break;
                    }
                    max=k>max?k:max;

            }
            printf("%d\n",max);
    }
    return 0;
}


Measured memory_bytes: 128
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        int[] c = new int[n];
        for(int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        for(int i = 0; i < n; i++) {
            b[i] = sc.nextInt();
        }
        for(int i = 0; i < n; i++) {
            c[i] = sc.nextInt();
        }
        Arrays.sort(a);
        Arrays.sort(c);
        long count = 0;
        for(int i = 0; i < n; i++) {
            int num = b[i];
            long aIndex = lowerBound(a, num);
            long cIndex = upperBound(c, num);
            count += (aIndex * (n - cIndex));
        }
        System.out.println(count);
    }

    public static int lowerBound(int[] array, int value) {
        int left = -1;
        int right = array.length;
        while (right - left > 1) {
            int middle = (right + left) / 2;
            if (array[middle] >= value) {
                right = middle;
            } else {
                left = middle;
            }
        }
        return right;
    }

    public static int upperBound(int[] array, int value) {
        int left = -1;
        int right = array.length;
        while (right - left > 1) {
            int middle = (right + left) / 2;
            if (array[middle] > value) {
                right = middle;
            } else {
                left = middle;
            }
        }
        return right;
    }

}


Measured memory_bytes: 95572
exp = input().split()
op = '+ - *'.split()
stack = []

for e in exp:
    if e == '+':
        ope1 = stack.pop()
        ope2 = stack.pop()
        stack.append(ope2 + ope1)
    elif e == '-':
        ope1 = stack.pop()
        ope2 = stack.pop()
        stack.append(ope2 - ope1)
    elif e == '*':
        ope1 = stack.pop()
        ope2 = stack.pop()
        stack.append(ope2 * ope1)
    else:
        stack.append(int(e))

print(stack[0])



Measured memory_bytes: 5600
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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;
}

using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1e17;
#define int long long
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, m; cin >> n >> m;
	int ans = 0;
	if (n * 2 > m) {
		ans += m / 2;
		m = 0;
	}
	else {
		ans += n;
		m -= n * 2;
	}
	ans += m / 4;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize(2,3,"Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define in inline
namespace fast_io
{
	char buf[1<<12],*p1=buf,*p2=buf,sr[1<<23],z[23],nc;int C=-1,Z=0,Bi=0,ny;
	in char gc() {return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<12,stdin),p1==p2)?EOF:*p1++;}
	in int read()
	{
		int x=0;ny=1;while(nc=gc(),(nc<48||nc>57)&&nc!=EOF)if(nc==45)ny=-1;Bi=1;if(nc<0)return nc;
		x=nc-48;while(nc=gc(),47<nc&&nc<58&&nc!=EOF)x=(x<<3)+(x<<1)+(nc^48),Bi++;return x*ny;
	}
	in db gf() {int a=read(),y=ny,b=(nc!='.')?0:read();return (b?a+(db)b/pow(10,Bi)*y:a);}
	in int gs(char *s) {char c,*t=s;while(c=gc(),c<32);*s++=c;while(c=gc(),c>32)*s++=c;return s-t;}
	in void ot() {fwrite(sr,1,C+1,stdout);C=-1;}
	in void flush() {if(C>1<<22) ot();}
	template <typename T>
	in void write(T x,char t)
	{
		int y=0;if(x<0)y=1,x=-x;while(z[++Z]=x%10+48,x/=10);
		if(y)z[++Z]='-';while(sr[++C]=z[Z],--Z);sr[++C]=t;flush();
	}
	in void write(char *s) {int l=strlen(s);for(int i=0;i<l;i++)sr[++C]=*s++;sr[++C]='\n';flush();}
};
using namespace fast_io;
const int N=1e2+5;
int q,n,m,k,p,c[N][N],pw[N][N],f[2][N][N];
in void M(int &x) {x-=p;x+=x>>31&p;}
in void cl(int x) {for(int i=0;i<=n;i++)for(int j=0;j<=m;j++)f[x][i][j]=0;}
int main()
{
	n=read(),m=read(),k=read(),p=read();for(int i=0;i<=max(n,m);i++) c[i][0]=1;
	for(int i=1;i<=max(n,m);i++) for(int j=1;j<=i;j++) M(c[i][j]=c[i-1][j-1]+c[i-1][j]);
	for(int i=0;i<=k;i++) pw[i][0]=1;
	for(int i=0;i<=k;i++) for(int j=1;j<=max(n,m);j++) pw[i][j]=1ll*pw[i][j-1]*i%p;
	f[0][0][0]=1;
	for(int t=1;t<=k;t++)
	{
		cl(q^1);
		for(int i=0;i<=n;i++) for(int j=0;j<=m;j++) if(f[q][i][j])
		{
			int x=f[q][i][j],y=1ll*pw[k-t+1][j]*pw[t][m-j]%p;
			for(int a=0;a<=n-i;a++,x=1ll*x*y%p) M(f[q^1][i+a][j]+=1ll*c[n-i][a]*x%p);
		}q^=1;cl(q^1);
		for(int i=0;i<=n;i++) for(int j=0;j<=m;j++) if(f[q][i][j])
		{
			int x=f[q][i][j],y=1ll*pw[k-t+1][i]*pw[t][n-i]%p;
			for(int b=0;b<=m-j;b++,x=1ll*x*y%p) M(f[q^1][i][j+b]+=1ll*c[m-j][b]*x%p);
		}q^=1;cl(q^1);
		for(int i=0;i<=n;i++) for(int j=0;j<=m;j++) if(f[q][i][j])
		{
			int x=f[q][i][j],y=1ll*(p-pw[k-t][j])*pw[t][m-j]%p;
			for(int a=0;a<=n-i;a++,x=1ll*x*y%p) M(f[q^1][i+a][j]+=1ll*c[n-i][a]*x%p);
		}q^=1;cl(q^1);
		for(int i=0;i<=n;i++) for(int j=0;j<=m;j++) if(f[q][i][j])
		{
			int x=f[q][i][j],y=1ll*(p-pw[k-t][i])*pw[t][n-i]%p;
			for(int b=0;b<=m-j;b++,x=1ll*x*y%p) M(f[q^1][i][j+b]+=1ll*c[m-j][b]*x%p);
		}q^=1;
	}
	write(f[q][n][m],'\n');
	return ot(),0;
}
//Author: disangan233

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

signed main(){
int sum=0,MAX=0;
  for(int i=0;i<5;i++){
  int a;cin>>a;
    for(int j=0;j<10;j++){
    if((a+j)%10==0){sum+=a+j;MAX=max(MAX,j);}
    }
  }
                                     cout<<sum-MAX<<endl;
}


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++)
typedef long long ll;

int main() {
  int H, W; cin >> H >> W;
  int i = 0; int j = 0;
  string s;
  while (i < H){
    while(j < W){
      cin >> s;
      if (s == "snuke"){
   
        printf("%c%d", 'A' + j, i+1);
        return 0;
      }
      j++;
      }
    j = 0;
    i++;
    }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vvi= vector<vi>;
using vs = vector<string>;
#define  rep(i,n) for(ll i = 0; i < (n); ++i)
#define  red(i,n) for(ll i = (n)-1; i >= 0; --i)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a)
#define  mp(a,b)  make_pair(a,b)
#define  yn(a)    cout << ( (a)?"Yes\n":"No\n" )
inline ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
const ll INF = 1e9+9, LINF = 1e18;


int main()
{
    ll n,x=1,y=1,a;
    cin>>n;
    rep(i,n){
        cin>>a;
        x*=2-a%2;
        y*=3;
    }
    cout<<y-x<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using CompLib.Util;

public class Program
{
    private long N, X;

    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextLong();
        X = sc.NextLong();

        long ans = N;
        N -= X;
        if (N < X)
        {
            long t = N;
            N = X;
            X = t;
        }

        while (X > 0)
        {
            long d = N / X;
            long m = N % X;
            ans += X * d * 2;
            N = X;
            X = m;
        }

        Console.WriteLine(ans - N);
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            if (_index >= _line.Length)
            {
                string s;
                do
                {
                    s = Console.ReadLine();
                } while (s.Length == 0);

                _line = s.Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public string ReadLine()
        {
            _index = _line.Length;
            return Console.ReadLine();
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            string s = Console.ReadLine();
            _line = s.Length == 0 ? new string[0] : s.Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 27488
n = int(input())
s = [int(x) for x in input().split()]

cnt = 0
for i in range(len(s)):
    mini = i
    for j in range(i,len(s)):
        if(s[j] < s[mini]):
            mini = j
    
    if(i != mini):

        v = s[i]
        s[i] = s[mini]
        s[mini] = v
        cnt += 1


    
print(" ".join(map(str,s)))
print(cnt)


Measured memory_bytes: 5604
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
typedef long long int lint;
using namespace std;

int main() {
    string s;
    cin >> s;
    int g = 0, p = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'g') {
            g++;
        } else {
            p++;
        }
    }
    cout << (g - p) / 2 << endl;
}

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

int main(){
  int k,s,cnt=0;
  cin>>k>>s;
  for(int i=0;i<=k;i++){
    for(int j=0;j<=k;j++){
      int z=max(0,s-i-j);
      if(i+j+z==s && z<=k) cnt++;
    }
  }
  cout<<cnt;
}


Measured memory_bytes: 256
class edge:
    def __init__(self,to,cap,rev):
        self.to,self.cap,self.rev=to,cap,rev

def makeG(n):
    return [[] for _ in xrange(n)]

def add(G,fr,to,cap):
    G[fr].append(edge(to,cap,len(G[to])))
    G[to].append(edge(fr,0,len(G[fr])-1))

def dfs(G,v,t,f,used):
    if v==t: return f
    used[v]=True
    for i in xrange(len(G[v])):
        e=G[v][i]
        if not used[e.to] and e.cap>0:
            d=dfs(G,e.to,t,min(f,e.cap),used)
            if d>0:
                e.cap-=d
                G[e.to][e.rev].cap+=d
                return d
    return 0
    
def max_flow(G,n,s,t):
    flow=0
    while True:
        used=[False]*n
        f=dfs(G,s,t,float("inf"),used)
        if f==0: return flow
        flow+=f

V,E=map(int,raw_input().split())
G=makeG(V)
for i in xrange(E):
    u,v,c=map(int,raw_input().split())
    add(G,u,v,c)
s=0
t=V-1
print(max_flow(G,V,s,t))

Measured memory_bytes: 7080
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,0,n+1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int MOD=1e9+7;
const int INF=1e18;
const int MAX=3000;

int lcm(int x,int y){
    return x/__gcd(x,y)*y;
}

signed main(){
    int N;cin>>N;
    int ans=1;
    REP(i,N){
        int t;cin>>t;
        ans=lcm(ans,t);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
use std::io;
use std::str::FromStr;

fn main() {
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).ok();
    let mut it = buf.split_whitespace().map(|n| String::from_str(n).unwrap());
    let a = it.next().unwrap();

    let mut buf = String::new();
    stdin.read_line(&mut buf).ok();
    let mut it = buf.split_whitespace().map(|n| String::from_str(n).unwrap());
    let b = it.next().unwrap();


    let rev = a.chars().rev().collect::<String>();
    if b == rev {
        println!("YES");
    } else {
        println!("NO");
    }
}


Measured memory_bytes: 4352
unittest
{
	assert( [ "4", "2 4 4 3" ].parse.expand.solve == "4\n3\n3\n4" );
	assert( [ "2", "1 2" ].parse.expand.solve == "2\n1" );
	assert( [ "6", "5 5 4 4 3 3" ].parse.expand.solve == "4\n4\n4\n4\n4\n4" );
}



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

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

auto parse( T )( T input )
if( isInputRange!T && is( ElementType!T == string ) )
{
	auto n = input.front.strip.to!( long );
	input.popFront;
	auto xs = input.front.split.to!( long[] );
	
	return tuple( xs );
}

auto solve( long[] xs )
{
	auto rs = new long[ xs.length ];
	
	auto xs_s = xs.dup.sort();
	auto cl = xs_s[ ( xs_s.length - 1 ) / 2 ];
	auto cr = xs_s[ ( xs_s.length + 1 ) / 2 ];
	
	foreach( i, x; xs )
	{
		if( x <= cl ) rs[ i ] = cr;
		else          rs[ i ] = cl;
	}
	
	return rs.to!( string[] ).join( "\n" );
}


Measured memory_bytes: 25904