akhauriyash/Code-Regression huggingface dataset:
#define M'   '
char*s,T[M],*r=T;U[M*35];n;k;main(i){for(;gets(r+1);k=!--n)for(;*++r&=31;)U[r-T]=k|=!!n<<*r;for(;~i--;)for(s=r;s-->T;k=U[k]=U[k-=~-~*s*M]?:*s?s-T:0)n+=__builtin_popcount(U[s-T]&(U[k+M]^=!s[-1]<<*s));printf("%d\n",n+1);}

Measured memory_bytes: 135140
#include <stdio.h>
#include <string.h>
const int MOD=1000000007;
struct mat
{
    long long val[4][4];
};
mat mul(const mat &a,const mat &b)
{
    mat ret;
    memset(ret.val,0,sizeof(ret.val));
    for (int i=0;i<4;++i)
        for (int j=0;j<4;++j)
            for (int k=0;k<4;++k)
                ret.val[i][k]+=a.val[i][j]*b.val[j][k];
    for (int i=0;i<4;++i)
        for (int j=0;j<4;++j)
            ret.val[i][j]%=MOD;
    return ret;
}
mat notbad[30],bad;
int main()
{
    notbad[0]=(mat){{{1,0,0,1},{1,1,0,1},{1,0,1,1},{1,1,1,2}}};
    bad=(mat){{{1,0,0,0},{1,1,0,0},{1,0,1,0},{1,1,1,1}}};
    for (int i=1;i<30;++i)
        notbad[i]=mul(notbad[i-1],notbad[i-1]);
    mat init=(mat){{{1,0,0,0},{0,1,0,0},{0,0,1,0},{0,0,0,1}}};
    int n,m;
    scanf("%d%d",&n,&m);
    int last=-1;
    for (int i=0;i<m;++i)
    {
        int cur;
        scanf("%d",&cur);
        int pw=cur-last-1,bits=0;
        while (pw)
        {
            if (pw&1)
                init=mul(notbad[bits],init);
            ++bits;
            pw>>=1;
        }
        init=mul(bad,init);
        last=cur;
    }
    int pw=n-last-1,bits=0;
    while (pw)
    {
        if (pw&1)
            init=mul(notbad[bits],init);
        ++bits;
        pw>>=1;
    }
    printf("%lld\n",init.val[3][0]);
    return 0;
}


Measured memory_bytes: 128
n,k=map(int,input().split())
a=list(map(int,input().split()))
def gcd(x,y):
    if x==y:
        return x
    elif x>y:
        r=-1
        while r!=0:
            r=x%y
            x=y
            y=r
        return x
    else:
        r=-1
        while r!=0:
            r=y%x
            y=x
            x=r
        return y

if n==1:
    if k==a[0]:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")
    exit()
g=gcd(a[0],a[1])
for i in range(2,n):
    g=gcd(g,a[i])
if k%g==0 and k<=max(a):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")


Measured memory_bytes: 62576
using System;
using System.Linq;

namespace ALDS1_5_D {
    class Problem {
        private int[] _nums, _workL, _workR;
        private long _count;

        public Problem(int[] nums,int n) {
            _nums = nums;

            int capacity = n / 2 + 2;
            _workL = new int[capacity];
            _workR = new int[capacity];

            // Run
            _count = 0;
            MergeSort(0, n);
        }

        public long Count {
            get { return _count; }
        }
        
        private void MergeSort(int left,int right) {
            if (left + 1 < right) {
                int mid = (left + right) / 2;
                MergeSort(left, mid);
                MergeSort(mid, right);
                Merge(left, mid, right);
            }
        }

        private void Merge(int left,int mid,int right) {
            int lenL = mid - left;
            for(int i = 0; i < lenL; i++)
                _workL[i] = _nums[left + i];
            _workL[lenL] = int.MaxValue;

            int lenR = right - mid;
            for(int i = 0; i < lenR; i++)
                _workR[i] = _nums[mid + i];
            _workR[lenR] = int.MaxValue;

            int indexL = 0;
            int indexR = 0;
            for(int i = left; i < right; i++) {
                if (_workL[indexL] <= _workR[indexR]) {
                    _nums[i] = _workL[indexL];
                    indexL++;
                    _count += indexR;
                }
                else {
                    _nums[i] = _workR[indexR];
                    indexR++;
                }
            }
        }
    }

    class Program {
        static void Main(string[] args) {
            int n = int.Parse(Console.ReadLine());
            int[] arr = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            Problem p = new Problem(arr, n);
            Console.WriteLine(p.Count);
        }
    }
}

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

int main(void){
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  for(int i=0;i<tx-sx;++i){
    cout << "R";
  }
  for(int i=0;i<ty-sy;++i){
    cout << "U";
  }
  for(int i=0;i<tx-sx;++i){
    cout << "L";
  }
  for(int i=0;i<=ty-sy;++i){
    cout << "D";
  }
  for(int i=0;i<=tx-sx;++i){
    cout << "R";
  }
  for(int i=0;i<=ty-sy;++i){
    cout << "U";
  }
  cout << "LU";
  for(int i=0;i<=tx-sx;++i){
    cout << "L";
  }
  for(int i=0;i<=ty-sy;++i){
    cout << "D";
  }
  cout << "R" << endl;
}


Measured memory_bytes: 256
from sys import maxsize

def calc(m, f, r):
    border = [80, 65, 50, 30]
    grade = ["A", "B", "C", "D", "F"]

    if min(m, f) == -1:
        return grade[-1]
    if r >= 50:
        border[grade.index("C")] = -1 * maxsize

    i = 0
    while i < len(border) and m + f < border[i]:
        i += 1

    return grade[i]

ans = []
while True:
    m, f, r = map(int, input().split())
    if max(m, f, r) == -1:
        break
    ans.append(calc(m, f, r))

print("\n".join(ans))


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


typedef struct{

  int parent;
  int depth;
  int type;    //0:root , 1:node , 2:leaf
  vector<int> child;

}node_t;

vector <node_t> tree; 


void Depth(int num, int d){

  tree[num].depth = d;

  if(tree[num].child.size()==0)return ;

  for(int i=0; i<(int)tree[num].child.size(); i++)
    Depth(tree[num].child[i] , d+1);

}


int main(){

  int n;
  int num , child , k;


  cin >> n;
  tree.resize(n);


  for(int i=0; i<n; i++){
    tree[i].child.resize(0);
    tree[i].type = 2;
    tree[i].parent = -1;
  }



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

    cin >> num >> k;
    if(k!=0)tree[num].type = 1;

    for(int j=0; j<k; j++){
      cin >> child;
      tree[num].child.push_back(child);
      tree[child].parent = num;
    }

  }


  for(int i=0; i<n; i++){
    if(tree[i].parent == -1){
      tree[i].type = tree[i].depth = 0; 
      Depth(i,0);
      break;
    }
  }



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

    cout << "node " << i << ": parent = " << tree[i].parent
	 << ", depth = " << tree[i].depth << ", ";

    if(tree[i].type == 0)cout << "root, ";
    else if(tree[i].type == 1)cout << "internal node, ";
    else cout << "leaf, ";

    cout << '[';
    if(tree[i].child.size()>0){
      cout << tree[i].child[0] ;
      for(int j=1; j<(int)tree[i].child.size(); j++)
	cout << ", " << tree[i].child[j];
    }
    cout << ']' << endl;


  }
  

  return 0;
}

Measured memory_bytes: 5688
#include <iostream>

int abss(int x)
{
    if (x < 0)
        return -x;
    else
        return x;
}

int main()
{
    int n, a[100010];
    std::cin >> n;

    for (int i = 1; i <= n; ++i)
        std::cin >> a[i];

    int dp[100010] = { 0 };
    dp[2] = abss(a[1] - a[2]);
    for (int i = 3; i <= n; ++i)
        dp[i] = std::min(dp[i - 2] + abss(a[i - 2] - a[i]), dp[i - 1] + abss(a[i - 1] - a[i]));

    std::cout << dp[n];
}


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

using namespace std;

const int N = 3005;
int dp[N][N];
bool vis[N][N];

string ans="";
string s,t;

void search_ans(int row, int col) {
	
	if ( row == 0 or col == 0 ) return ;
	if (vis[row][col] ) return;
	vis[row][col] = 1;
	if (dp[row][col] == dp[row][col-1]) search_ans(row,col-1);
	else if (dp[row][col] == dp[row-1][col]) search_ans(row-1,col);
	else {
		ans+=t[col];
		search_ans(row-1,col-1);
	}
}

int main (){
	
	cin>>s>>t;
	s='#' + s;
	t='#' + t;
	//cout<<s<<'\n'<<t<<'\n';
	
	int len1= s.size();
	int len2= t.size();
	
	//~ cout<<"len 1-- " << len1 << " len 2-- " << len2<<'\n';
	//~ cout<<s[0]<<'\n';
	int mx=0;
	pair<int,int> loc;
	for (int i=1; i<len1;i++) {
		for (int j=1;j<len2;j++) {
			if (s[i]==t[j]) {
				dp[i][j]= dp[i-1][j-1]+1;
			}
			else {
				dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
			}
			
			if (dp[i][j] > mx ) {
				mx=dp[i][j];
				loc={i,j};
			}
			
			
		}
	}
	//~ cout<<"    ";
	//~ for (int i=1;i<len2;i++) cout<<t[i]<<" ";
	//~ cout<<'\n';
	
	//~ for (int i=0;i<len1;i++) {
		//~ cout<<s[i]<<" ";
		//~ for (int j=0;j<len2;j++) {
			//~ cout<<dp[i][j]<<' ';
		//~ }
		//~ cout<<'\n';
	//~ }
	
	search_ans(loc.first,loc.second);
	reverse(ans.begin(),ans.end());
	
	cout<<ans<<'\n';
}


Measured memory_bytes: 47636
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

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

int H, W;
string S[22];
int vis[22][22];

bool inside(int h, int w) {
    return 0 <= h && h < H && 0 <= w && w < W;
}

int calc(PII st) {
    if (S[st.first][st.second] == '#') return -1;
    queue<pair<PII, int>> que;
    memset(vis, -1, sizeof(vis));

    que.emplace(st, 0);
    while (!que.empty()) {
        const auto state = que.front();
        que.pop();

        const int ch = state.first.first;
        const int cw = state.first.second;
        if (vis[ch][cw] != -1) continue;
        vis[ch][cw] = state.second;

        REP(d, 4) {
            const int nh = ch + dx[d];
            const int nw = cw + dy[d];
            if (!inside(nh, nw) || vis[nh][nw] != -1 || S[nh][nw] == '#') continue;
            que.emplace(MP(nh, nw), state.second + 1);
        }
    }

    int res = 0;
    REP(i, H) REP(j, W) {
        chmax(res, vis[i][j]);
    }
    return res;
}

int main(void) {
    cin >> H >> W;
    REP(i, H) {
        cin >> S[i];
    }

    int ans = 0;
    REP(i, H) {
        REP(j, W) {
            chmax(ans, calc({i, j}));
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n, g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define dup(x, y) (((x) + (y)-1) / (y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int x, y;
  cin >> x >> y;
  cout << x + y / 2 << endl;
}

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

#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

	int a[1000];
	int ans = 0;
	for(int i = 0;i < n;i++){
		cin >> a[i];
		if((i+1) % 2 && a[i] % 2) ans++;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3640
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

void ABC081A (const unsigned int const * given_data)
{
	// local variables for this function
	int          retval_scanf;
	unsigned int iter;
	unsigned int num_marbles;

	// STEP.01
	// find the number of squares on which Sunuke will place a marble
	num_marbles = 0;
	iter        = *given_data;

	while (iter > 0)
	{
		num_marbles += iter % 10;
		iter        /=        10;
	}

	// STEP.03
	// print the answer of this task to the standard output
	printf( "%d\n", num_marbles );

	// STEP.END
	return;
}

int main (void)
{
	// variables for this function
	unsigned int given_data;
	int          retval_scanf;

	// STEP.01
	// read out the given string
	retval_scanf = scanf("%d", &given_data);

	// STEP.02
	// calculate & output the answer
	ABC081A(&given_data);

	// STEP.END
	return EXIT_SUCCESS;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
using namespace std;
vector <vector <long long> > adj, pre, post;
vector <long long> ans, f;
long long n, m, x, y;
 
void dfs(int cur = 1, int prev = 0)
{
	int size = adj[cur].size();
	pre[cur].resize(size, 1);
	post[cur].resize(size, 1);
	
	for (int i: adj[cur])
		if (i != prev)
		{
			dfs(i, cur);
			ans[cur] = ans[cur] * (ans[i] + 1) % m;
		}
	
	for (int i = 0, j = 0; i < size; i++, j++)
	{
		if (adj[cur][i] == prev) {j--; continue;}
		if (j == 0) pre[cur][j] = (ans[adj[cur][i]] + 1) % m;
		else pre[cur][j] = (ans[adj[cur][i]] + 1) * pre[cur][j - 1] % m;
	}
	
	for (int i = size - 1, j = size - 2; i >= 0; i--, j--)
	{
		if (adj[cur][i] == prev) {j++; continue;}
		post[cur][j] = (ans[adj[cur][i]] + 1) * post[cur][j + 1] % m;
	}
}
 
void dfsa(int cur = 1, int prev = 0)
{
	int size = adj[cur].size();
	for (int i = 0, j = 0; i < size; i++, j++)
	{
		if (adj[cur][i] == prev) {j--; continue;}
		
		if (j == 0) f[adj[cur][i]] = (post[cur][j + 1] * f[cur] + 1) % m;
		else f[adj[cur][i]] = ((pre[cur][j - 1] * post[cur][j + 1] % m) * f[cur] + 1) % m;
		dfsa(adj[cur][i], cur);
	}
}
 
int main()
{
	cin >> n >> m;
	adj.resize(n + 1);
	post.resize(n + 1);
	pre.resize(n + 1);
	ans.resize(n + 1, 1);
	f.resize(n + 1, 1);
	for (int i = 1; i < n; i++)
	{
		cin >> x >> y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	adj[1].push_back(0);
	
	dfs();
	dfsa();
	
	for (int i = 1; i <= n; i++)
		cout << ans[i] * f[i] % m << endl;
}

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

signed main() {
  int H, W; cin >> H >> W;
  // 上下左右4方向に対する方向ベクトル
  int dh[] = {-1, 0, 1, 0};
  int dw[] = {0, -1, 0, 1};
  string board[H];
  for(int i = 0; i < H; i++) cin >> board[i];

  bool ans = true;
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      if(board[i][j] == '#') {
        bool found = false;
        for(int k = 0; k < 4; k++) {
          int h = i + dh[k];
          int w = j + dw[k];
          // 周り4方向に1つでも'#'があれば良い(ただし、移動後に範囲内に入っていること)
          if(0<=h && h<H && 0<=w && w<W && board[h][w]=='#') found = true;
        }
        if(!found) ans = false;
      }
    }
  }

  cout << (ans ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
def e(x,y):
    z=1
    if x<y:
        z=x
        x=y
        y=z

    while x!=0 and y!=0 and z!=0 and x!=y:
        z=x%y
        x=y
        y=z
    return x

n=int(input(''))
a=input('')
a=a.split(' ')
for b in range(n):
    a[b]=int(a[b])

p=[]
for b in range(10**6+1):
    p.append(0)

for b in range(n):
    p[a[b]]+=1

for b in range(10**6+1):
    if p[b]>=1:
        c=b+b
        while c<=10**6:
            p[c]=0
            c=c+b

s=0
for b in range(10**6+1):
    if p[b]==1:
        s=s+1

print(s)

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

int main(void){
  int N;
  cin >> N;
  long long sum = 0;
  vector<int> a(N);
  for(int i = 0; i < N; i++){
    cin >> a[i];
    sum += a[i] - 1;
  }
  cout << sum;
 return 0; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

// https://atcoder.jp/contests/joi2008ho/submissions/7593812


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

int main() {
    int w, h;
    while (cin >> w >> h && w) {
        
        int n;
        cin >> n;
        vector<pair<pii, pii> > v(n);
        
        set<int> s[2];
        s[0].insert(h);
        s[1].insert(w);
        
        rep(i, 2) s[i].insert(0);
        
        rep(i, n) {
            cin >> v[i].F.F >> v[i].F.S >> v[i].S.F >> v[i].S.S;
            s[1].insert(v[i].F.F);
            s[0].insert(v[i].F.S);
            s[1].insert(v[i].S.F);
            s[0].insert(v[i].S.S);
        }
        
        map<int, int> mp[2];
        int cnt[2] = {0};
        rep(i, 2) for (auto e : s[i]) { mp[i][e] = cnt[i]; cnt[i] += 2; }
        
        int C[2];
        rep(i, 2) C[i] = cnt[i] + 2;
        
        int table[C[0]][C[1]];
        fill_n(*table, C[0] * C[1], 0);
        
        rep(i, n) {
            int x1 = mp[1][v[i].F.F], y1 = mp[0][v[i].F.S], x2 = mp[1][v[i].S.F], y2 = mp[0][v[i].S.S];
            
            rep3(j, x1, x2 + 1) {
                table[y1][j]++;
            }
            
            rep3(j, x1, x2 + 1) {
                table[y2 + 1][j]--;
            }
        }
        
        int H = mp[0][h] + 1, W = mp[1][w] + 1;
        
        rep(j, W) rep3(i, 1, H) table[i][j] += table[i - 1][j];
        
        // cout << endl; rep(i, H) { rep(j, W) cout << fixed << setw(3) << table[i][j] << " "; cout << '\n'; }
        
        int ans = 0;
        
        rep(i, H) rep(j, W) {
            if (table[i][j]) continue;
            ans++;
            
            queue<pii> q;
            q.push(pii(i, j));
            table[i][j] = 1;
            
            while (!q.empty()) {
                int y = q.front().F;
                int x = q.front().S;
                q.pop();
                
                rep(k, 4) {
                    int ny = y + dy[k];
                    int nx = x + dx[k];
                    
                    if (ny < 0 || ny >= H || nx < 0 || nx >= W) continue;
                    if (table[ny][nx]) continue;
                    table[ny][nx] = 1;
                    q.push(pii(ny, nx));
                }
            }
        }
        
        cout << ans << '\n';
    }
    
}




Measured memory_bytes: 8060
n, k, c = [int(i) for i in input().split()]
s = input()

work1 = [0] * k
work2 = [0] * k
cnt = 0
day = 0

while cnt < k:
	if s[day] == 'o':
		work1[cnt] = day
		cnt	+= 1
		day += (c+1)
	else:
		day += 1


cnt = k-1
day = n-1

while cnt >= 0:
	if s[day] == 'o':
		work2[cnt] = day
		cnt	-= 1 
		day -= (c + 1)
	else:
		day -= 1


for i in range(k):
	if work1[i] == work2[i]:
		print(work1[i]+1)



Measured memory_bytes: 20620
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	var a, b int
	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
		line := scanner.Text()
		strs := strings.Split(line, " ")
		a, _ = strconv.Atoi(strs[0])
		b, _ = strconv.Atoi(strs[1])
	}

	fmt.Printf("%v %v\n", a*b, 2*(a+b))
}



Measured memory_bytes: 1112
<?php
fscanf(STDIN,"%d %d %d %d %d",$h1,$m1,$h2,$m2,$k);

$sm = $h1 * 60 + $m1;
$em = $h2 * 60 + $m2;
$ans = $em - $sm - $k;
echo $ans.PHP_EOL;

Measured memory_bytes: 16108
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
using namespace std;
typedef long long int ll;
const int INF = 1 << 30;
#define rep(i,n) for(int i=(ll)0;i<(ll)n;++i)
#define ALL(x) x.begin(),x.end()
int main() {
	int n;
	int pos[510] = {};
	int dp[510] = {};
	int ans[251000] = {};
	cin >> n;
	rep(i, n) {
		cin >> pos[i];
		pos[i]--;
		dp[i] = i;
	}
	rep(i, n*n) {
		int mn=INF,mnp=INF;
		bool fl = 0;
		for (int j = 0; j < n; ++j) {
			if (dp[j] != 0&&i!=pos[j]) {
				int num;
				if (i < pos[j])num = pos[j] - i;
				else num = INF - j-1;
				if (mn > num) { mn = num; mnp = j; }
			}
			if (i == pos[j]) { dp[j] = n - j - 1; ans[i] = j + 1; fl = 1; }
		}
		if (fl)continue;
		if (mn == INF) { cout << "No" << endl; return 0; }
		dp[mnp] -= 1;
		ans[i] = mnp + 1;
	}
	cout << "Yes" << endl;
	rep(i, n*n) {
		cout << ans[i]<<" ";
	}
	cout<<""<<endl;
	return 0;
}

Measured memory_bytes: 2176
import sys

n = int(input())
nums = []
for _ in range(n):
    nums.append(int(input()))
s = sum(nums)
if s % 10 != 0:
    print(s)
else:
    nums.sort()
    for num in nums:
        t = s - num
        if t % 10 != 0:
            print(t)
            break
    else:
        print(0)

Measured memory_bytes: 62436
#include <iostream>
#include <cstdio>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());


int main(){
	int n,m,p;
	while(cin>>n>>m>>p,n||m||p){
		vint v(n);
		rep(i,n) cin>>v[i];
		int s=0;
		rep(i,n) s+=v[i];
		// s/=100;
		s*=(100-p);
		if(v[m-1]==0){
			cout<<0<<endl;
			continue;
		}
		s/=v[m-1];
		cout<<s<<endl;
	}
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
inline int getInt() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MX = 200005;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
//---------------------------------------------------------------
#define fastio std::ios::sync_with_stdio(false);
#define myio ifstream iofi; if(argc>1){iofi.open(argv[1]); std::cin.rdbuf(iofi.rdbuf());}
//--------------------------------------------------------------
struct c{
  int ic;
  int p;
  ll y;
  string id;
};


void Main(){
  int n,m;
  cin>>n>>m;
  v(c) ci(m);
  rep(i,m){
    ci[i].ic = i;
    cin>>ci[i].p;
    cin>>ci[i].y;
    char name[8];
    sprintf(name,"%06d",ci[i].p);
    ci[i].id += name;
  }
  sort(rng(ci),[](auto a,auto b){return a.y<b.y;});
  vi rank(n+1,1);
  rep(i,m){
    char name[8];
    sprintf(name,"%06d",rank[ci[i].p]);
    ci[i].id += name;
    rank[ci[i].p]++;
  }
  sort(rng(ci),[](auto a,auto b){return a.ic<b.ic;});
  rep(i,m){
    cout<<ci[i].id<<endl;
  }
} int main(int argc,char** argv)
{fastio; myio; Main();}


Measured memory_bytes: 8960
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		//行にダイスの番号、列にダイスの各面の数を代入する
		int[][] num = new int[n][6];
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < 6; j++) {
				num[i][j] = sc.nextInt();
			}
		}
		//n個のサイコロを扱うDicesインスタンス
		Dices d = new Dices(num);
		
		//すべてのサイコロが合同かどうかを判断
		if(d.allDicesNotCongruence()) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		sc.close();
	}
}

class Dices {
	//
	int[][] side;
	//コンストラクタ
	Dices(int[][] num){
		side = new int[num.length][6];
		for(int i = 0; i < num.length; i++) {
			for(int j = 0; j < 6; j++) {
				this.side[i][j] = num[i][j];
			}
		}
	}

	//tar番目のダイスとref番目のダイスが合同なら1を、異なるなら0を返す
	public int checkCon(int tar, int ref) {
		int isCon = 0;
		int cnt = 6;
		for (int i = 0; i < 6; i++) {
			if (this.side[tar][i] == this.side[ref][i])
				cnt--;
		}
		if (cnt == 0) {
			isCon = 1;
		}
		return (isCon);
	}

	//四方向から確かめ、合同な場合が存在すれば1,しなければ0を返す
	public int tryRotPosition(int tar, int ref) {
		int cnt = 0;
		cnt += checkCon(tar, ref);
		for (int i = 0; i < 3; i++) {
			this.rotR(tar);
			cnt += checkCon(tar, ref);
		}
		return (cnt >= 1 ? 1 : 0);
	}
	
	//tar番目のダイスとref番目のダイスが同一かを調べるメソッド
	//targetを転がし、それぞれの位置において四方向から判別
	//二つのダイスが同一なら1、異なれば0を返す
	public int checkDices(int tar, int ref) {
		int isCon = 0;
		int cnt = 0;
		cnt += this.tryRotPosition(tar, ref);
		this.rollN(tar);
		cnt += this.tryRotPosition(tar, ref);
		this.rollN(tar);
		cnt += this.tryRotPosition(tar, ref);
		this.rollW(tar);
		cnt += this.tryRotPosition(tar, ref);
		this.rollE(tar);
		cnt += this.tryRotPosition(tar, ref);
		this.rollE(tar);
		cnt += this.tryRotPosition(tar, ref);
		if (cnt >= 1) {
			isCon = 1;
		}
		return(isCon);
	}
	
	public boolean allDicesNotCongruence() {
		int isCon = 0;
		for(int i = 0; i < this.side.length -1; i++) {
			for(int j = i + 1; j < this.side.length; j++) {
				isCon += checkDices(i, j);
			}
		}
		return(isCon == 0 ? true : false);
	}

	
	//i番目のダイスを回転させるメソッド群
	
	public void rollE(int i) {
		int w = this.side[i][5];
		this.side[i][5] = this.side[i][2];
		this.side[i][2] = this.side[i][0];
		this.side[i][0] = this.side[i][3];
		this.side[i][3] = w;
	}

	public void rollW(int i) {
		int w = this.side[i][5];
		this.side[i][5] = this.side[i][3];
		this.side[i][3] = this.side[i][0];
		this.side[i][0] = this.side[i][2];
		this.side[i][2] = w;
	}

	public void rollN(int i) {
		int w = this.side[i][5];
		this.side[i][5] = this.side[i][4];
		this.side[i][4] = this.side[i][0];
		this.side[i][0] = this.side[i][1];
		this.side[i][1] = w;
	}

	public void rollS(int i) {
		int w = this.side[i][5];
		this.side[i][5] = this.side[i][1];
		this.side[i][1] = this.side[i][0];
		this.side[i][0] = this.side[i][4];
		this.side[i][4] = w;
	}

	public void rotR(int i) {
		int w = this.side[i][1];
		this.side[i][1] = this.side[i][2];
		this.side[i][2] = this.side[i][4];
		this.side[i][4] = this.side[i][3];
		this.side[i][3] = w;
	}
}



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

int main(){
  string S;
  cin>>S;
  int res=0;
  if(S == "SUN")res=7;
  else if(S == "MON")res=6;
  else if(S == "TUE")res=5;
  else if(S == "WED")res=4;
  else if(S == "THU")res=3;
  else if(S == "FRI")res=2;
  else res=1;

  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 256
#![allow(dead_code)]
#![allow(unused_imports)]
use ascii::{AsciiChar, AsciiStr, AsciiString};
use indexmap::IndexMap;
use itertools::*;
use libm::*;
use num::*;
use ordered_float::OrderedFloat;
use permutohedron::LexicalPermutation;
use proconio::marker::{Bytes, Chars};
use proconio::{fastout, input};
use std::cmp::{max, min, Ordering};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::mem::swap;

#[fastout]
fn main() {
    input!(n:usize, a:[i64; n]);
    let ans = a.iter().fold(1i64, |acc, &x| acc.saturating_mul(x));
    println!("{}", if ans > 10i64.pow(18) { -1 } else {ans});
}


Measured memory_bytes: 4592
import sys

def wantmin(n):

    ret = 0

    for i in range(N):
        if n > A[i] * F[i]:
            ret += A[i]

        else:
            ret += n // F[i]

    return ret

    

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

A = list(map(int,input().split()))
F = list(map(int,input().split()))

M = 0


S = 0
for i in range(N):
    M = max(M,A[i]*F[i])
    S += A[i]

A.sort()
F.sort()
F.reverse()

l = 0
r = M+1
lm = wantmin(l)
rm = wantmin(r)
mm = 0
amari = S - K
#print (amari)

if amari <= 0:
    print (0)
    sys.exit()

while True:

    mid = (l + r) // 2

    mm = wantmin(mid)
    #print (l,mid,r,mm)

    #if mm == amari:
     #   print (mid)
      #  sys.exit()

    if mm < amari:
        l = mid
        lm = mm

    else:
        r = mid
        rm = mm

    if r - l == 1:
        print (r)
        sys.exit()

        


Measured memory_bytes: 119500
#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define v first
#define ind second

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int main(void){
	const int N = (int)1e6;
	vector<bool> isP(N, true);
    isP[0] = isP[1] = false;
	for(int i = 2; i * i < N; i++) if(isP[i]) for(int j = i; i * j < N; j++) isP[i * j] = false;

    vi P;
    rep(i, N){
        if(isP[i]) P.pb(i);
    }

    for(int n, p, res; cin >> n >> p, n != -1; cout << res << endl){
        vector<pii> s(100);
        int pos = upper_bound(all(P), n) - P.begin();

        rep(i, s.size()){
            s[i].first = 2 * P[pos + i];
            s[i].second = pos + i;
        }

        rep(i, p){
            vector<pii>::iterator itr = min_element(all(s));
            res = itr->v;
            
            itr->v += P[itr->ind + 1] - P[itr->ind++];
        }
    }

	return 0;
}

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

ll divisor=1e9+7;
int main(){
	int a[3],k;
	cin>>a[0]>>a[1]>>a[2]>>k;
	if(a[0]>k){
		puts(k);
	}else if(a[0]+a[1]>k){
		puts(a[0]);
	}else{
		puts(a[0]-(k-a[0]-a[1]));
	}
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;
typedef long long int ll;

struct Edge{
	int to,rev; ll cap;
	Edge(int to,ll cap,int rev):to(to),cap(cap),rev(rev){}
};
// ここの値に注意！！
const int N=205;
const ll INF=1e9;
vector<Edge> g[N];
int level[N]; 
int iter[N];
void add_edge(int s,int t,ll c){
	g[s].push_back(Edge(t,c,g[t].size()));
	g[t].push_back(Edge(s,0,g[s].size()-1));
}
void bfs(int s){
	memset(level,-1,sizeof(level));
	queue<int> q;
	level[s]=0;
	q.push(s);
	while(q.size()){
		int v=q.front(); q.pop();
		for(auto &e:g[v]){
			if(e.cap>0&&level[e.to]<0){
				level[e.to]=level[v]+1;
				q.push(e.to);
			}
		}
	}
}
ll dfs(int v,int t,ll f){
	if(v==t)return f;
	for(int &i=iter[v];i<g[v].size();i++){
		Edge &e=g[v][i];
		if(e.cap>0&&level[v]<level[e.to]){
			int d=dfs(e.to,t,min(f,e.cap));
			if(d>0){
				e.cap-=d;
				g[e.to][e.rev].cap+=d;
				return d;
			}
		}
	}
	return 0;
}
ll max_flow(int s,int t){
	ll flow=0;
	while(1){
		bfs(s);
		if(level[t]<0)return flow;
		memset(iter,0,sizeof(iter));
		int f;
		while((f=dfs(s,t,INF))>0){
			flow+=f;
		}
	}
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int h,w; cin >> h >> w;
	char c;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin >> c;
			if(c=='.')continue;
			if(c=='S'){
				add_edge(w+h,j+h,INF);
				add_edge(w+h,i,INF);
			}else if(c=='T'){
				add_edge(i,w+h+1,INF);
				add_edge(j+h,w+h+1,INF);
			}else{
				add_edge(i,j+h,1);
				add_edge(j+h,i,1);
			}
		}
	}
	int res=max_flow(w+h,w+h+1);
	if(res>=INF){
		cout << -1 << endl;
	}else{
		cout << res << endl;
	}
}



Measured memory_bytes: 1152
import java.util.Scanner;

/**
 * Class Untitled
 */
public class Main {
	public static void main(String[] args) {
		//入力用インスタンスの作成
    	Scanner scan = new Scanner(System.in);
    	//入力する。
    	String str = scan.next();
    	//分割しれ配列に格納する。
    	String[] gengou = str.split("/", 0);
    	
    		
		int i = Integer.parseInt(gengou[0]);
    	if(i <= 2019){
    		i = Integer.parseInt(gengou[1]);
    		if(i <= 4){
    			System.out.println("Heisei");
    		}else{
    			System.out.println("TBD");
    		}
    		
    	}else{
    		System.out.println("Heisei");
    	}
	}
}

Measured memory_bytes: 23124
import qualified Data.IntMap as M              

main :: IO ()
main = do
    n  <- readLn
    as <- map read . words <$> getLine
    print $ solve n as

solve :: Int -> [Int] -> Int
solve n as = go mp0
  where
    mp0 = M.fromList $ zip [1 .. n] as

    go :: M.IntMap Int -> Int
    go mp = case M.minViewWithKey mp of
        Nothing -> 0
        Just ((k, a), mp') | M.lookup a mp' == Just k -> 1 + go mp'
                           | otherwise                -> go mp'

Measured memory_bytes: 48508
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

y = 0
for i in range(N):
  x = B[i] - A[i]
  if x < 0:
    y += B[i]
  else:
    xx = x - A[i+1]
    if xx < 0:
      y += A[i]+x
      A[i+1] = -xx
    else:
      y += A[i]+A[i+1]
      A[i+1] = 0
print(y)

Measured memory_bytes: 19156
K, N = map(int, input().split())
A = list(map(int, input().split()))

A_diff = list([0] for _ in range(N))

for i in range(N - 1):
    A_diff[i] = A[i + 1] - A[i]

A_diff[N - 1] = A[0] - A[N - 1] + K

ans = K - max(A_diff)

print(ans)


Measured memory_bytes: 32792
#include<bits/stdc++.h>
#define rep(i,n) for(int i;i<n;i++)
using namespace std;
using ll = long long;
using ld = long double;
int mod = 1000000007;
int main(){
    string s;
    cin >> s;
    if(s=="ARC")
    cout << "ABC"<<endl;
    else
    cout << "ARC" << endl;
    
    return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n; cin >> n;
	vi a(n); rep(i, n) cin >> a[i];
	int ans = 0;
	for(int i = n - 2, cur = 0; i >= 0; i--){
		if(a[i] >= a[i + 1]) cur++;
		else cur = 0;
		ans = max(ans, cur);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */

int N,K;
int V[51];

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

  cin >> N >> K;
  REP(i,N) cin >> V[i];
  int ans = 0;
  REP(i,N+1) REP(j,N+1) {
    vector<int> v;
    REP(k,i) v.push_back(V[k]);
    REP(k,j) v.push_back(V[N-1-k]);
    if (v.size() > N || v.size() > K) continue;
    SORT(v);
    int rem = K - v.size();
    int sub = accumulate(ALL(v),0);
    REP(k,rem) {
      if (k >= v.size() || v[k] >= 0) break;
      sub -= v[k];
    }
    CHMAX(ans,sub);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    int n, m;
    cin >>n >> m;
    int sum = 0;
    rep(i, m) {
        int x;
        cin >> x;
        sum += x;
    }
    if (n - sum >= 0) 
        cout << n - sum << endl;
    else
        cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;

int main()
 {
 	int p,q,r,a,b;
 	cin>>p>>q>>r;
	a=min(p+q,q+r);
	b=min(a,p+r);
	cout<<b<<endl;
	return 0;
}
 	
 					

Measured memory_bytes: 3564
#include <iostream>
#include <cstdlib>
#include <queue>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <map>
#include <cstdio>
using namespace std;
#define rep(i, a) for (int i = 0; i < a; i++)
#define irep(i, a) for (int i = 1; i <= a; i++)
#define mp make_pair
#define pb push_back
#define P pair<int, int>
#define ll long long

string t[111111];
int h, w;
int a,b,c,d;
P p[1111111];
P p2[1111111];
bool f[1111][1111];
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int main()
{
    cin >> h >> w;
    rep(i, h) cin >> t[i];
    queue<pair<int,P> >bfs;

    rep(i,h){
      rep(j,w){
        if(t[i][j]=='#'){
          bfs.push(mp(0,mp(i,j)));
          f[i][j]=1;
        }
      }
    }
    int ans=0;

    while(!bfs.empty()){
        P p=bfs.front().second;
        int cnt=bfs.front().first;
        bfs.pop();
        rep(k,4){
          int ny=p.first+dy[k];
          int nx=p.second+dx[k];
          if(ny<0||ny>=h||nx<0||nx>=w)continue;
          if(f[ny][nx])continue;
          f[ny][nx]=1;
          bfs.push(mp(cnt+1,mp(ny,nx)));
          ans=max(ans,cnt+1);
        }
    }

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


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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define INF (1<<29)
#define EPS (1e-8)

int main() {
	int n;
	while (cin >> n, n) {
		vector<pair<double, double> > buil(n);
		vector<int> num(n);
		
		REP(i, n) scanf("%d %lf %lf", &num[i], &buil[i].first, &buil[i].second);
		
		vector<double> graph[n];
		REP(i, n) {
			graph[i].resize(n);
			REP(j, n) {
				if (i == j) graph[i][j] = 0.0;
				else graph[i][j] = hypot(buil[i].first - buil[j].first, buil[i].second - buil[j].second);
			}
		}
		
		int m;
		cin >> m;
		while (m--) {
			int s, g;
			scanf("%d %d", &s, &g);
			
			int sn, gn;
			REP(i, n) {
				if (num[i] == s) sn = i;
				if (num[i] == g) gn = i;
			}
			
			vector<double> dis(n, INF);
			priority_queue<pair<double, int> > pq;
			pq.push(make_pair(0.0, sn));
			vector<int> prev(n, INF);
			
			while (!pq.empty()) {
				pair<double, int> now = pq.top();
				pq.pop();
				
				int from = now.second;
				
				REP(i, n) {
					if (graph[from][i] <= 50 + EPS ) {
						double d = now.first + graph[from][i];
						if (dis[i] > d) {
							dis[i] = d;
							prev[i] = from;
							pq.push(make_pair(d, i));
						}
					}
				}
			}
			
			if (dis[gn] == INF) puts("NA");
			else {
				vector<int> ans;
				int pos = gn;
				
				while (pos != sn) {
					ans.push_back(num[pos]);
					pos = prev[pos];
				}
				ans.push_back(num[sn]);
				reverse(ans.begin(), ans.end());
				REP(i, ans.size()) printf("%d%c", ans[i], i == ans.size() - 1 ? '\n' : ' ');
			}
		}
		
	}
	return 0;
}

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

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
  

N = int(input())
S = []
if N == 1:
  print(0)
  exit(0)
fac = factorization(N)
for i in range(len(fac)):
  S.append(fac[i][1])
ans = 0
for i in range(len(S)):
  for j in range(1,S[i] + 1):
    if S[i] - j < 0:
      break
    ans += 1
    S[i] -= j
print(ans)

Measured memory_bytes: 9504
n,m=map(int,input().split())
lr=[[int(i) for i in input().split()] for _ in range(m)]
l=[lr[i][0] for i in range(m)]
r=[lr[i][1] for i in range(m)]
print(min(r)-max(l)+1 if min(r)>=max(l) else 0)

Measured memory_bytes: 22808
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>

#include <map>
 
using namespace std;
typedef long long ll; 


ll ans,mx,sum,mn=1e18,flag;

string k,l;
int main(){
	string s;
	cin>>s;
	string t = s;
	reverse(t.begin(),t.end());
	for(ll i=0; i<(s.size()-1)/2; i++){
		k += s[i];
	}
	ll temp = ((s.size()+3)/2)-1;
	for(ll i=temp; i<s.size(); i++){
		l += s[i];
	}
	string k1 = k;
	string l1 = l;
	reverse(k1.begin(),k1.end());
	reverse(l1.begin(),l1.end());
	if(t==s && k==k1 && l==l1) cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 256