akhauriyash/Code-Regression huggingface dataset:
///
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fr(i,a,b) for(int i=a;i<=b;i++)
#define re_fr(i,a,b) for(int i=a;i>=b;i--)
#define frl(i,a,b) for(ll i=a;i<=b;i++)
#define re_frl(i,a,b) for(ll i=a;i>=b;i--)
#define mp make_pair
#define MX 1e18
#define eps 1e-9
#define mod 1000000007
#define mod2 100000000
#define fast() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
ll gcd(ll a,ll b) {return b==0?a:gcd(b,a%b);}
void fil()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
}
int main()
{
    fast();
    ll p; cin>>p;
    ll x=log2(p);
    cout<<(ll) (1<<x) <<endl;









    return 0;
}


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

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

  vector<vector<long long int> > A(n, vector<long long int>(m));
  vector<vector<long long int> > B(m, vector<long long int>(l));
  vector<vector<long long int> > C(n, vector<long long int>(l));

  for(int i=0; i<n; i++)
    for(int j=0; j<m; j++)
      cin >> A[i][j];

  for(int i=0; i<m; i++)
    for(int j=0; j<l; j++)
      cin >> B[i][j];

  for(int i=0; i<n; i++){
    for(int j=0; j<l; j++){
      C[i][j] = 0;
      for(int k=0; k<m; k++)
	C[i][j]+=A[i][k]*B[k][j];
      cout << C[i][j];
      if(j!=l-1)
	cout << " ";
    }
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 1424
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    std::ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    vector<int>a(n+1), b(n);
    for(int i=0;i<n+1;++i){
        cin >> a[i];
    }
    for(int i=0;i<n;++i){
        cin >> b[i];
    }

    ll ans = 0;
    for(int i=0;i<n;++i) {
        if(a[i] < b[i]) {
            ans += a[i];
            ans += min(a[i+1], b[i]-a[i]);
            a[i+1] -= min(a[i+1], b[i]-a[i]);
        } else {
            ans += b[i];
        }
    }

    cout << ans << endl;
}


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

typedef priority_queue<int> maxHeap;
typedef priority_queue<int, vector<int>, greater<int>> minHeap;
#define endl "\n"
#define int long long
#define MOD 1000000007
#define PI 3.1415926535897932384626433832795
#define max(x, y) ((x > y) ? x : y)
#define min(x, y) ((x < y) ? x : y)
#define mid(s, e) ((s + (e - s) / 2))

bool test_cases;

void init(bool k) {
    test_cases = k;
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

struct precompute {
    void compute() {
    }
};

int dp[101][100001];

struct test_cases {
    void test_case() {
        int n, w;
        cin >> n >> w;
        memset(dp, -1, sizeof(dp));
        int val[n], wt[n];
        for (int i = 0; i < n; i++) {
            cin >> wt[i] >> val[i];
        }

        int dp[n + 1][w + 1];
        memset(dp, 0, sizeof(dp));

        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= w; j++) {
                if (i == 0 || j == 0) {
                    dp[i][j] = 0;
                } else if (j < wt[i - 1]) {
                    dp[i][j] = dp[i - 1][j];
                } else {
                    dp[i][j] = max(val[i - 1] + dp[i - 1][j - wt[i - 1]], dp[i - 1][j]);
                }
            }
        }
        cout << dp[n][w] << endl;
    }
};

int32_t main() {
    init(false);
    int tc;
    if (test_cases) {
        cin >> tc;
    } else {
        tc = 1;
    }
    struct precompute l;
    l.compute();
    for (int i = 0; i < tc; i++) {
        struct test_cases o;
        o.test_case();
    }
    return 0;
};

Measured memory_bytes: 161404
#include <iostream>
#include <algorithm>
#include <math.h> 
#include <string>
#include <iomanip>
#include <vector>
using namespace std;
int main(){
    int n, a, b;
    cin >> n >> a >> b;
    int p[110];
    int x = 0;
    int y = 0;
    int z = 0;
    for(int i = 0; i < n; i++) cin >> p[i];
    for(int i = 0; i < n; i++){
        if(p[i] <= a) x++;
        else if(a + 1 <= p[i] && p[i] <= b) y++;
        else if(b + 1 <= p[i]) z++;
    }

    cout << min({x,y,z}) << endl;
}


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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

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

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

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

template <class T> T Sq(const T &t) { return t * t; }

const int mod = 1e9 + 7;

signed main() {
  int n = read();
  n--;
  int sum = (n + 1) * n / 2;
  print(sum);
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>

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

#define in(v) v; cin >> v;
void ins() {}
template<class T,class... Rest>void ins(T& v,Rest&... rest){cin>>v;ins(rest...);}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rrep(i,n) for(long long i=(n);i>=0;--i)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))

// === debug ===
template<class T>ostream& operator<<(ostream& os,const vector<T>& vec){os<<"{";for(size_t i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
ostream& operator<<(ostream& os,const vector<char>&v){for(size_t i=0;i<v.size();++i)os<<v[i];return os;}
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>& rhs){os<<"("<<rhs.first<<", "<<rhs.second<<")";return os;}

#ifdef LOCAL
void debug() {cerr << "\n";}
template<class First> void debug(const First& first) {cerr<<first<<"\n";}
template<class First, class... Rest> void debug(const First& first, const Rest&... rest) {cerr<<first<<",";debug(rest...);}
void debug2() {cerr << "\n";}
template<class First> void debug2(const First& first) {cerr<<first<<" ";}
template<class First, class... Rest> void debug2(const First& first, const Rest&... rest) {cerr<<first<<" ";debug2(rest...);}
#else
#define debug(...) 42
#define debug2(...) 42
#endif
// === end ===

int main() {
  ll X, K, D;
  cin >> X >> K >> D;
  X = abs(X);
  if (X / D > K) {
    cout << X - K * D << endl;
    return 0;
  }
  int count = X / D;
  K -= count;
  X -= D * count;
  if (K == 0) {
    cout << X << endl;
    return 0;
  }
  if (abs(X - D) < X) {
    X = abs(X - D);
    --K;
  }
  if (K % 2 == 0) {
    cout << X << endl;
    return 0;
  }
  cout << abs(X-D) << endl;

  return 0;
}


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

int visit[100],end[100],a[100][100];
int t,N,u,k,col;

void rist_to_mat(int N) {
	for(int l=0; l<N; ++l) {
		cin >> u >> k;
		for (int i=0; i<k; ++i) {
			cin >> col;
			a[u-1][col-1] = 1;
		}
	}
}

void dfs(int cur,int N) {
	t += 1;
	visit[cur] = t;
	for(int dst=0; dst<N; ++dst) {
		if(a[cur][dst] == 1 && visit[dst] == 0) {
			dfs(dst,N);
		}
	}
	t += 1;
	end[cur] = t;
}

int main() {
	cin >> N;
	rist_to_mat(N);
	for(int i=0; i<N; ++i) {
		if(visit[i] == 0) dfs(i,N);
	}
	for(int i=0; i<N; ++i) {
		cout << i+1 << ' ' << visit[i] << ' ' << end[i] << endl;
	}
}

Measured memory_bytes: 1200
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>

const int kN = 400000 + 5;
int n, q;
int b[kN];
int s[2][kN];
std::vector<int> queries[kN];

struct SegmentTree {
    int lazy[kN << 2], t[kN << 2];

    void init()
    {
        std::fill(t, t+ (kN << 2), kN);
        std::fill(lazy, lazy + (kN << 2), kN);
    }

    void update(int rt, int dt)
    {
        t[rt] = std::min(t[rt], dt);
        lazy[rt] = std::min(lazy[rt], dt);
    }

    void down(int rt)
    {
        if (lazy[rt] != kN) {
            update(rt << 1, lazy[rt]);
            update(rt << 1 | 1, lazy[rt]);
            lazy[rt] = kN;
        }
    }

    void up(int rt)
    {
        t[rt] = std::min(t[rt << 1], t[rt << 1 | 1]);
    }

    void modify(int L, int R, int dt, int l, int r, int rt)
    {
        if (L <= l && r <= R) {
            update(rt, dt);
            return ;
        }
        int mid = l + r >> 1;
        down(rt);
        if (L <= mid) modify(L, R, dt, l, mid, rt << 1);
        if (mid < R)  modify(L, R, dt, mid + 1, r, rt << 1 | 1);
        up(rt);
    }

    int query(int L,int R, int l, int r, int rt)
    {
        if (L > R)
            return kN;
        if (L <= l && r <= R)
            return t[rt];
        int mid = l + r >> 1;
        down(rt);
        if (L <= mid && mid < R)
            return std::min(query(L, R, l, mid, rt << 1), query(L, R, mid + 1, r, rt << 1 | 1));
        else if (L <= mid)
            return query(L, R, l, mid, rt << 1);
        else
            return query(L, R, mid + 1, r, rt << 1 | 1);
    }
}sgt0, sgt1;

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; ++ i) {
        scanf("%d", b + i);
    }
    for (int i = n; i >= 1; -- i) {
        s[0][i] = s[0][i + 1] + (b[i] == 0);
        s[1][i] = s[1][i + 1] + (b[i] == 1);
    }
    sgt0.init();
    sgt1.init();
    int result = s[1][1];
    scanf("%d", &q);
    for (int i = 0; i < q; ++ i) {
        int l, r;
        scanf("%d%d", &l, &r);
        queries[r].emplace_back(l);
    }
    for (int r = 1; r <= n; ++ r) {
        for (int l : queries[r]) {
            int val = s[1][1] - s[1][l] + s[0][l] - s[0][r + 1];
            val = std::min(val, sgt0.query(l, l, 1, n , 1) - s[0][r + 1]);
            val = std::min(val, sgt1.query(1, l - 1, 1, n, 1) - s[1][l] + s[0][l] - s[0][r + 1]);
            result = std::min(result, val + s[1][r + 1]);
            sgt0.modify(l, r, val + s[0][r + 1], 1, n, 1);
            sgt1.modify(r, r, val + s[1][r + 1], 1, n, 1);
        }
    }
    printf("%d\n", result);
}


Measured memory_bytes: 43904
import math


def divisor(num):
    if num < 0:
        return [0,]
    elif num == 1:
        return [1,]
    else:
        divisor_list =[1,]
        for i in range(2, int(math.sqrt(num) + 1)):
            if num % i== 0:
                divisor_list.append(i)
        return divisor_list


N,M = map(int,input().split(' '))
P = M // N
divisor_list = divisor(M)

for i in reversed(range(len(divisor_list))):
    num = M // divisor_list[i]
    divisor_list.append(num)

for i in reversed(range(len(divisor_list))):
    if divisor_list[i] <= P:
        print(divisor_list[i])
        break

Measured memory_bytes: 3064
# 準備
num_list = [0] * 1000000
i = 2
cnt = 0
for num in range(2,len(num_list)):
    if num_list[i] == -1:
        num_list[i] = num_list[i-1]
        i += 1
        continue
    cnt+=1
    num_list[i] = cnt
    # num_list[i*2::i] = -1
    for j in range(i*2,len(num_list),i):
        num_list[j] = -1
    i += 1

while True:
    try:
        n = int(input())
    except Exception as e:
        break
    print(int(num_list[n]))


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

int main() {
	int n; cin >> n;
	vector<int> d1(n);
	vector<int> d2(n);
	bool flag = true;

	for (int i = 0; i < n; i++) {
		cin >> d1[i] >> d2[i];
	}

	for (int i = 0; i < n - 2; i++) {
		if (d1[i] == d2[i])
			if (d1[i + 1] == d2[i + 1])
				if (d1[i + 2] == d2[i + 2] && flag) {
					cout << "Yes" << endl;
					flag = false;
				}
	}

	if(flag)
		cout << "No" << endl;

}

Measured memory_bytes: 3632
import java.util.*;

class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        List<String> list = new ArrayList<String>();
        String[] str = new String[n];
        for (int i = 0; i < n; i++) {
            str[i] = sc.next();
            list.add(str[i]);
        }
        List<String> listB = new ArrayList<String>(new HashSet<>(list));

        System.out.println(listB.size());
        sc.close();
    }
}


Measured memory_bytes: 73412
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<iomanip>
#include<stdio.h>
using namespace std;

int main(){

  string n;

  bool flag = false;
  cin >> n;

  int s = n.size();

  for(int i=0; i<s; i++){
    if(n[i]=='A' && n[i+1]=='C'){
      cout << "Yes" << endl;
      flag = true;
      break;
    }
  }

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

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000


int main() {
	int a[N];
	f(i, N)a[i] = 0;
	int n, k;
	int x, y, z;
	long long s, ans;
	bool v = true;
	ans = 0;
	scanf("%d", &n);
	f(i, n) {
		scanf("%d", &a[i]);
		if ((i % 2 == 0) && (a[i] % 2 == 1))ans++;
	}

	f(i, n) {

	}

	printf("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 2512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000000
using namespace std;
int main(void){
    ll n,a,b;cin>>n>>a>>b;
    ll now;cin>>now;
    ll next;
    ll ans=0;
    rep(i,n-1){
        cin>>next;
        ans+=min((next-now)*a,b);
        now=next;
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount
           
#define rep(i, n) for (int i = 0; i < n; ++i)

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;


int main()
{
    int n;
    while (scanf("%d", &n), n)
    {
	int t[3][2] = { 0 };
	static const int begin[] = { 11*60, 18*60, 21*60 };
	static const int end[] = { 14*60+59, 20*60+59, 25*60+59 };
	while (n--)
	{
	    int h, m, mm;
	    scanf("%d:%d %d", &h, &m, &mm);
	    if (h < 2)
		h += 24;
	    int time = h*60 + m;
	    int take = (mm+60 - m) % 60;
	    for (int i = 0; i < 3; ++i)
	    {
		if (begin[i] <= time && time <= end[i])
		{
		    ++t[i][0];
		    if (take <= 8)
			++t[i][1];
		}
	    }
	}
	const char* hoge[] = { "lunch", "dinner", "midnight" };
	for (int i = 0; i < 3; ++i)
	{
	    printf("%s ", hoge[i]);
	    if (t[i][0])
		printf("%d\n", 100 * t[i][1] / t[i][0]);
	    else
		puts("no guest");
	}
    }
}

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

typedef long long LL;
typedef unsigned long long ULL;

const int PI = 3.141592653589793238;
const LL inf64 = 1000000111111222222;
const int inf = 1000111222;
const int mod = 1000000007;
const int N = 100007;


int main() {
	
	ios_base :: sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	
	int a, b, c; cin >> a >> b >> c;
	int k; cin >> k;
	while (k--) {
		if (b <= a) {
			b *= 2;
		}
		else {
			c *= 2;
		}
	}
	if (b > a && c > b) {
		cout << "Yes\n";
	}
	else cout << "No\n";
	return 0;
}


Measured memory_bytes: 3692
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
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; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
vector<int> Zalgo(string s){
  int m=s.size();
  vector<int> res(m);
  res[0]=m;
  int i=1,j=0;
  while(i<m){
    while(i+j<m&&s[j]==s[j+i]){
      j++;
    }
    res[i]=j;
    if(j==0){
      i++;
      continue;
    }
    int k=1;
    while(i+k<m&&k+res[k]<j){
      res[i+k]=res[k];
      k++;
    }
    i+=k,j-=k;
  }
  return res;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin >> n;
    string s;cin >> s;
    int ans=0;
    for(int i=0;i<n;i++){
        vector<int> lcp=Zalgo(s.substr(i,n-i));
        for(int j=0;j<n-i;j++){
            chmax(ans,min(lcp[j],j));
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
table = [[[0]*10 for i in range(3)] for i in range(4)]

n = int(input())

for _ in range(n):
    b, f, r, v = map(int, input().split())
    table[b-1][f-1][r-1] += v
    
i = 0
for building in table:
    for floor in building:
        print(' ' + ' '.join(list(map(str, floor))))
    if i != 3:
        print('####################')
    i += 1


Measured memory_bytes: 5608
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define piii pair<int,pii>
#define pll pair<ll,ll>
#define plii pair<ll,pii>
#define vi vector<int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mx 100001
#define eps 0.00000000001
#define mod 1000000007
#define pi acos(-1)
#define inf 100000000
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    fio;
    ll N;
    cin >> N;

    vector<ll> A(N);

    for(ll i = 0;i < N;i++)
        cin >> A.at(i);

    ll k1=0,k2=0;

    SORT(A);

    for(ll i = 0;i < N -1;i++){
        if(A.at(i) == A.at(i+1)){
            if(k1 <= k2)
                k1 = A.at(i);
            else
            {
                k2 = A.at(i);
            }
            i++;
        }
    }


    cout << k1 * k2 << endl;
    return 0;
}


Measured memory_bytes: 3900
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional> // std::function<void(int)>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int Dy[8] = {-1,-1,0,1,1,1,0,-1};
int Dx[8] = {0,1,1,1,0,-1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector<int> a(n),b(n),c(n);
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++)cin>>b[i];
    for(int i=0;i<n-1;i++)cin>>c[i];
    a.push_back(inf);
    int res=0;
    for(int i=0;i<n;i++){
        res+=b[a[i]-1];
        if(a[i]+1==a[i+1]){
            res+=c[a[i]-1];
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 256
n = int(input())
arr = [ int(i) for i in input().split(" ")]

cnt = 0
for i in range(len(arr)-1):
  
  minj = i+1
  for j in range(i, len(arr)):
    if arr[j] < arr[minj]:
      minj = j
  
  tmpCur = arr[i]
  tmpMin = arr[minj]
  if tmpCur > tmpMin:
    cnt += 1
    arr[i], arr[minj] = tmpMin, tmpCur

print(" ".join([str(i) for i in arr]))
print(cnt)


Measured memory_bytes: 5604
#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
const int M=100010;
const int MOD=1000000007;
const int INF=1000000007;
using ll=long long;

int main() {
	ll ans=0;
	int n,a,num[M]={};
	cin>>n;
	rep(i,0,n){
		cin>>a;
		if(a>100000){
			ans++;
			continue;
		}
		num[a]++;
		ans++;
		if(num[a]==a)ans-=a;
	}
	cout<<ans<<endl;
}


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

int main(){
    long long n,a,b;
    cin>>n>>a>>b;
    long long c=a+b;
    long long s1=n/c*a;
    long long rem=n%c;
    long long s2=rem>a?a:rem;
    cout<<s1+s2<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main(void){
	ll a,b,c; cin>>a>>b>>c;
	if(c-a-b<0){
		cout<<"No"<<endl;
		return 0;
	}
	if(4*a*b<(c-a-b)*(c-a-b)){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	
}


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

using namespace std;

template<typename T>
ostream& operator<<(ostream& os, vector<T> v) {
  os << "[";
  for (T &i: v) os << i << ",";
  os << "]";
  return os;
}

template<class TH> void _dbg(const char *sdbg, TH h){ cout<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cout<<*sdbg++;
  cout<<'='<<h<<','; _dbg(sdbg+1, a...);
}

#ifdef __DJKIM613
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#endif

const int MAXN = 1e5 + 10;
int N;
long long A[MAXN];
long long C[MAXN];
long long ans[MAXN];
vector<int> adj[MAXN];
int main(void){
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);

  cin >> N;
  for(int x, y, i = 1; i < N ; i++){
    cin >> x >> y;
    adj[x].push_back(y);  adj[y].push_back(x);
    C[x]++; C[y]++;
  }

  for(int i = 1 ; i <= N ; i++) cin >> A[i];
  sort(A + 1, A + 1 + N);

  queue<int> Q;
  for(int i = 1 ; i <= N ; i++) {
    if(C[i] == 1) Q.push(i); 
  }

  long long val = 0;
  for(int i = 1 ; i <= N ; i++){
    val += A[i];
    int here = Q.front(); Q.pop();
    ans[here] = A[i];
    for(int there : adj[here]){
      C[there]--;
      if(C[there] == 1) Q.push(there);
    }
  }
  val -= A[N];

  cout << val << '\n';
  for(int i = 1 ; i <= N ; i++) cout << ans[i] << ' ';
  return 0;
}

Measured memory_bytes: 4864
s=input()
s1=int(s[0:2])
s2=int(s[2:4])

if 0<s1<13 and 0<s2<13:
    print("AMBIGUOUS")
elif 0<s1<13:
    print("MMYY")
elif 0<s2<13:
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(void){

    int a, b, c;
    cin >> a >> b >> c ;
    
    //*
    if(a <= c && b >= c){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    //*/
    
    //cout << a.at(0) - 'a' + 'A' << b.at(0) - 'a' + 'A' << c.at(0) - 'a' + 'A' << endl;

    return 0; 
}


Measured memory_bytes: 3636
#include <stdarg.h>
#include <stdio.h>

long long min(int len, ...) {
    long long i, _min, num;
    va_list ap;
    va_start(ap, len);

    _min = va_arg(ap, long long);
    for (i = 1; i < len; i++) {
        num = va_arg(ap, long long);
        if (num < _min)
            _min = num;
    }
    va_end(ap);
    return _min;
}

int main(void) {
    int i, j, k, l, N;
    long long a[410], dp[410][410], cum;
    scanf("%d", &N);
    for (i=1;i<=N;i++) scanf("%lld", &a[i]);

    for (i=1;i<=N;i++) {
        dp[i][i+1] = 0LL;
    }
    for (j=2;j<=N;j++) {
        for (i=1;i+j<=N+1;i++) {
            cum = 0LL;
            for (k=i;k<i+j;k++) cum += a[k];
            dp[i][i+j] = dp[i][i+j-1] + dp[i+j-1][i+j];
            for (l=2;l<j;l++) dp[i][i+j] = min(2, dp[i][i+j], dp[i][i+j-l] + dp[i+j-l][i+j] );
            dp[i][i+j] += cum;
        }
    }

    printf("%lld\n", dp[1][N+1]);
    return 0;
}

Measured memory_bytes: 1408
D = int(input())
c = list(map(int,input().rstrip().split(" ")))
s = []
kankaku = [0 for i in range(27)]
for i in range(D):
    s.append(list(map(int,input().rstrip().split(" "))))

for i in range(D):
    p = 0
    t = 0
    for i2 in range(26):
        if p < s[i][i2] + c[i2] * kankaku[i2] * (kankaku[i2] * 2) // 2:
            p = s[i][i2] + c[i2] * kankaku[i2] * (kankaku[i2] * 2) // 2
            t = i2 + 1
    kankaku[t - 1] = -1
    print(t)
    for i in range(26):
        kankaku[i] += 1


Measured memory_bytes: 9400
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
#ifndef ONLINE_JUDGE
#define dbg(x...) do{cout << "\033[32;1m" << #x << "->" ; err(x);} while(0)
void err(){cout << "\033[39;0m" << endl;}
template<template<typename...> class T,typename t,typename... A>
void err(T<t> a,A... x){for (auto v:a) cout << v << ' '; err(x...);}
template<typename T,typename... A>
void err(T a,A... x){cout << a << ' '; err(x...);}
#else
#define dbg(...)
#endif
const int mod=998244353;
const int INF=0x3f3f3f3f;
ll quick(ll a,ll b)
{
	ll ret=1;
	while(b)
	{
		if(b&1)
			ret=ret*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ret;
}
ll inv(ll a){return quick(a,mod-2);}
bool can[11];
bool check(int u)
{
	while(u)
	{
		if(!can[u%10]) return false;
		u/=10;
	}
	return true;
}
int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	for(int i=0;i<=9;i++) can[i]=1;
	for(int i=0,t;i<k;i++)
	{
		scanf("%d",&t);
		can[t]=0;
	}
	do{
		if(check(n)) break;
	}while(n++);
	printf("%d\n",n);
}


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

int main(){
  int h,w;
  cin >> h >> w;
  while(h!=0){
    int i,j;
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	if((i%2==0&&j%2==0)||(i%2==1&&j%2==1))
	  cout << "#";
	else cout << ".";
      }
      cout << endl;
    }
    cout << endl;
    cin >> h >> w;
  }
  return 0;
}



Measured memory_bytes: 3128
#include<stdio.h>
int main(void){
  char haiku[100];
  scanf("%s",haiku);
  int i;
  for(i=0;i<19;i++){
    if(i==5||i==13){
      printf(" ");
    }
    else{
      printf("%c",haiku[i]);
    }
  }
  return 0;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl "\n"
#define eb emplace_back
#define pb push_back
#define mk make_pair
#define mt make_tuple

#define Umap unordered_map
#define graph vector<vector<int>>

#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl

#define INF 1e9+5
#define N 40001
#define MAXN   100001


bool sortbysec(const tuple<int, int, int>& a,  
               const tuple<int, int, int>& b) 
{ 
    return (get<1>(a) < get<1>(b)); 
}
void dfs(int s, graph &g, bool vis[]){
	vis[s] = true;
	for(int i=0;i<g[s].size();i++){
		if(!vis[g[s][i]]) dfs(g[s][i],g,vis);
	}
}

string common_prefix(vector<string>& strings){
	string prefix;
	for(string s : strings){
		for(int i=0;i<s.size() && s[i]!='*';++i){
			if(i<prefix.size()){
				if(s[i]!=prefix[i]) return "*";
			}
			else prefix+=s[i];
		}
	}
	return prefix;
}

void reverse(vector<string>& strings){
	for(string& s : strings){
		reverse(s.begin(),s.end());
	}
}

int spf[0];
void sieve(){
	spf[1] = 1;
	for(int i=2;i<MAXN;i++) spf[i] = i;

	for(int i=4;i<MAXN;i+=2) spf[i] = 2;

	for(int i=3; i*i<MAXN;i++){
		if(spf[i]==i){
			for(int j=i*i;j<MAXN;j+=i){
				if(spf[j]==j) spf[j] = i;
			}
		}
	}
}
vector<int> getFactorization(int x){

	vector<int> primeFactors;
	while(x>1){
		primeFactors.pb(spf[x]);
		x /= spf[x];
	}
	return primeFactors;
}



void solve(){
	// sieve(); 
	int n; cin>>n;
	Umap<string,int>items;
	for(int i=0;i<n;i++) {
		string s; cin>>s;
		items[s]++;
	}

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

	





}

int main() {
IOS;
	int t=1; 
	// cin>>t;
	for(int i=1;i<=t;i++){
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	return 0;
}

Measured memory_bytes: 17688
"""
 SpeedForces
 Ah shit here we go again

"""

from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip
import heapq

def solve():
    n,m = vv()
    a = ll()
    a = [-i for i in a]
    heapq.heapify(a)
    for i in range(m):
        x = -heapq.heappop(a)
        # pr(x,x//2)
        x//=2
        heapq.heappush(a,-x)
    ans = 0
    # pr(a)
    for i in a:
        ans+=(-i)
    pr(ans)


    return
















def main():
    # for _ in range(int(input())):
        solve()

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()
pr = print
if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")
ll = lambda : list(map(int,input().split()))
vv = lambda :map(int,input().split())
# endregion

if __name__ == "__main__":
    main()

Measured memory_bytes: 50756
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N,M;
    cin >> N >> M;
    ll maxi = 1;
    for(ll i = 1;i * i <= M;i++){
        if(M % i == 0){
            if(M / i >= N)maxi = max(maxi, i);
            if(i >= N)maxi = max(maxi, M / i);
        }
    }
    cout << maxi << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<map>
using namespace std;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
class state {
public:
	int tx;
	int ty;
	int kx;
	int ky;
	bool operator < (const state &s)const {
		if (ty != s.ty)return ty < s.ty;
		if (tx != s.tx)return tx < s.tx;
		if (ky != s.ky)return ky < s.ky;
		if (kx != s.kx)return kx < s.kx;
		return false;
	}
};
int main() {
	while (true) {
		int W, H;
		cin >> W >> H;
		if (W == 0 && H == 0)
			break;
		int d[52][52];
		for (int i = 0; i < H + 2; i++) {
			for (int j = 0; j < W + 2; j++) {
				d[i][j] = 1;
			}
		}
		state num;
		cin >> num.tx >> num.ty >> num.kx >> num.ky;
		for (int i = 1; i < H + 1; i++) {
			for (int j = 1; j < W + 1; j++) {
				cin >> d[i][j];
			}
		}
		queue<state> q;
		q.push(num);
		map<state, int> m;
		m[num] = 0;
		while (true) {
			num = q.front();
			q.pop();
			if (m[num] >= 100) {
				cout << "NA" << endl;
				break;
			}
			if (num.tx == num.kx && num.ty == num.ky) {
				cout << m[num] << endl;
				break;
			}
			for (int i = 0; i < 4; i++) {
				state copy = num;
				if (d[copy.ty + dy[i]][copy.tx + dx[i]] == 0) {
					copy.ty += dy[i];
					copy.tx += dx[i];
				}
				if (d[copy.ky - dy[i]][copy.kx - dx[i]] == 0) {
					copy.ky -= dy[i];
					copy.kx -= dx[i];
				}
				if (m.find(copy)==m.end()) {
					q.push(copy);
					m[copy] = m[num]+1;
				}
			}
			if (q.empty()) {
				cout << "NA" << endl;
				break;
			}
		}
		m.clear();
		while (!q.empty()) {
			q.pop();
		}
	}
	return 0;
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

bool check(int n) {
  int i = n % 10;
  n /= 10;
  while(n > 0) {
    if(i == n%10 + 1) {
      i = n % 10;
      n /= 10;
    } else {
      return false;
    }
  }
  return true;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  int n; cin >> n;
  vi a(n);
  REP(i, n) cin >> a[i];

  int ma = -1;
  REP(i, n) {
    FOR(j, i+1, n) {
      int tmp = a[i] * a[j];
      if(check(tmp)) {
        ma = max(ma, tmp);
      }
    }
  }
  cout << ma << endl;
}



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

void NaiveSearch(string T, string P){
	int t=T.size();
	int p=P.size();
	int i,j;
	
	for (i=0;i<t-p+1;i++){
		bool flag=true;
		for (j=0;j<p;j++){
			if(T[i+j]!=P[j]){
				flag=false;
			}
		}
		
		if(flag==true){
			cout << i << endl;
		}
	}
}

int main(){
	string T,P;
	cin >> T >> P;
	NaiveSearch(T,P);
	return 0;
}

Measured memory_bytes: 1192
mod = 1000000007
eps = 10**-9


def main():
    import sys
    from collections import deque
    input = sys.stdin.readline

    N = int(input())
    que = deque(["3", "5", "7"])
    ans = 0
    while True:
        i = que.popleft()
        if int(i) > N:
            break
        if "3" in i and "5" in i and "7" in i:
            ans += 1
        que.append(i + "3")
        que.append(i + "5")
        que.append(i + "7")
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 76296
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define upperlimit 1000100
#define INF 1000000100
#define INFL 1000000000000000100
#define eps 1e-8
#define endl '\n'
#define sd(n) scanf("%d",&n)
#define slld(n) scanf("%lld",&n)
#define pd(n) printf("%d",n)
#define plld(n) printf("%lld",n)
#define pds(n) printf("%d ",n)
#define pllds(n) printf("%lld ",n)
#define pdn(n) printf("%d\n",n)
#define plldn(n) printf("%lld\n",n)
#define REP(i,a,b) for(i=a;i<=b;i++)
#define mp make_pair
#define pb push_back
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define F first
#define S second
#define clr(a) memset(a,0,sizeof(a))
using namespace std;
 
ll gcd(ll n1,ll n2){
    if(!n1)return n2;
    if(!n2)return n1;
    if(n1%n2==0)return n2;
    return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent){
    base%=mod;
    ll ans=1;
    while(exponent){
        if(exponent&1)ans=(ans*base)%mod;
        base=(base*base)%mod;
        exponent/=2;
    }
    ans%=mod;
    return ans;
}
int main()
{
    string s;
    
    cin>>s;
    int r=0;
    for(int i=0;i<6;i++){
          if(s[i]=='1')r++;

    }
   
    cout<<r; 
    return 0;
}

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

/* snippet: useful macros and functions */
#define ARC(i, a, b) for(Int i = (a); i < (b); ++i)
#define RC(i, n) ARC(i, 0, n)
#define ARCH(i, a, b) for(Int i = (a) - 1; i >= (b); --i)
#define RCH(i, n) ARCH(i, n, 0)
template<class T> T ant(const T &a, const T &b){ return a > b ? a : b; }
template<class T> T ont(const T &a, const T &b){ return a < b ? a : b; }
template<class T> T rng(const T &a, const T &b){ return a < b ? b - a : a - b; }
template<class T> void th(T &a, const T &b, T (*f)(const T &, const T &)){ a = f(a, b); }
#define anth(a, b) th(a, b, ant)
#define onth(a, b) th(a, b, ont)

/* snippet: modint library */
template<class T, int MOD>
class Modint{
	T val;
public:
	Modint(T val = 0) : val(val) {}
	operator T(){ return val; }
	Modint &operator+=(const Modint &a){ val += a.val; if(val >= MOD) val -= MOD; return *this; }
	Modint &operator-=(const Modint &a){ val -= a.val; if(val < 0) val += MOD; return *this; }
	Modint &operator*=(const Modint &a){ val = val * a.val % MOD; return *this; }
	void inverse(){T x[2]={MOD,val},a[2]={0,1};int i;for(i=0;x[!i];i^=1){a[i]-=x[i]/x[!i]*a[!i];x[i]=x[i]%x[!i];}if(!i)a[i]+= MOD;val=a[i];}
	Modint &operator/=(Modint a){ a.inverse(); return *this *= a; }
	friend Modint modpow(Modint a, int n){ Modint ret(1); while(n){ if(n & 1) ret *= a; a *= a; n >>= 1; } return ret; }
	friend Modint operator+(Modint a, const Modint &b){ return a += b; }
	friend Modint operator-(Modint a, const Modint &b){ return a -= b; }
	friend Modint operator*(Modint a, const Modint &b){ return a *= b; }
	friend Modint operator/(Modint a, const Modint &b){ return a /= b; }
	friend std::ostream &operator<<(std::ostream &os, const Modint &a){ return os << a.val; }
};

/* snippet: using declarations */
using Int = long long;
using std::cout;
using std::cin;
using std::endl;
using Mint = Modint<long long, 1000000007>;

bool palindrome(std::string str){
	std::string::iterator i;
	std::string::reverse_iterator j;
	for(i = str.begin(), j = str.rbegin(); i != str.end(); ++i, ++j) if(*i != *j) return false;
	return true;
}

int main(){
	std::string str;
	cin >> str;
	cout << (
		palindrome(str)
	&&	palindrome(str.substr(0, (str.size() - 1) / 2))
	&&	palindrome(str.substr((str.size() + 1) / 2, (str.size() - 1) / 2))
	? "Yes" : "No"
	) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<cmath>
using namespace std;

#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define absd(x) (x<0?-(x):x)
#define pow2(x) ((x)*(x))
#define rep(i,n) for(int i=0; i<n; ++i)
#define repr(i,n) for(int i=n-1; i>=0; --i)
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define replr(i,s,n) for(int i=n; i>=s; --i)
#define repf(i,s,n,j) for(int i=s; i<=n; i+=j)
#define repe(e,obj) for(auto e : obj)

#define SP << " " <<
#define COL << " : " <<
#define COM << ", " <<
#define ARR << " -> " <<
#define PNT(STR) cout << STR << endl
#define POS(X,Y) "(" << X << ", " << Y << ")"
#define DEB(A) " (" << #A << ") " << A
#define DEBREP(i,n,val) for(int i=0; i<n; ++i) cout << val << " "; cout << endl
#define ALL(V) (V).begin(), (V).end()
#define INF 1000000007
#define INFLL 10000000000000000007LL
#define EPS 1e-9

typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
//typedef pair<ll, ll> P;
typedef pair<P, int> PI;
typedef pair<int, P> IP;
typedef pair<P, P> PP;
typedef priority_queue<P, vector<P>, greater<P> > pvqueue;

int n, m, g, d;
int ma[30][10];

bool solve() {
  int pos = m;
  rep(i, d) {
    if(pos<n-1 && ma[i][pos]) ++pos;
    else if(pos && ma[i][pos-1]) --pos;
  }
  return pos==g;
}

int main() {
  while(cin >> n && n) {
    cin >> m >> g >> d; --m; --g;
    rep(i, d) {
      rep(j, n-1) {
        char c;
        cin >> c;
        ma[i][j] = c-'0';
      }
    }
    if(solve()) {
      cout << "0" << endl;
    }else {
      int f = 0;
      rep(i, d && !f) {
        rep(j, n-1) {
          if(!ma[i][j]) {
            if((j<n-2 && ma[i][j+1]) || (j && ma[i][j-1])) continue;
            ma[i][j] = 1;
            if(solve()) {
              cout << i+1 << " " << j+1 << endl;
              f = 1;
              break;
            }
            ma[i][j] = 0;
          }
        }
      }
      if(!f) cout << "1" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REPR(i,n) for (int i=(int)(n)-1;i>=0;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
#define tpl(...) make_tuple(__VA_ARGS__)
const int INF = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1);
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};
typedef long long ll;
typedef pair<int,int> pii;
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; }
template<typename Ch,typename Tr,typename C,typename=decltype(begin(C()))>basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>&os,
const C& c){os<<'[';for(auto i=begin(c);i!=end(c);++i)os<<(i==begin(c)?"":" ")<<*i;return os<<']';}
template<class S,class T>ostream&operator<<(ostream &o,const pair<S,T>&t){return o<<'('<<t.first<<','<<t.second<<')';}
template<int N,class Tp>void output(ostream&,const Tp&){}
template<int N,class Tp,class,class ...Ts>void output(ostream &o,const Tp&t){if(N)o<<',';o<<get<N>(t);output<N+1,Tp,Ts...>(o,t);}
template<class ...Ts>ostream&operator<<(ostream&o,const tuple<Ts...>&t){o<<'(';output<0,tuple<Ts...>,Ts...>(o,t);return o<<')';}
template<class T>void output(T t,char z=10){if(t<0)t=-t,putchar(45);int c[20];
int k=0;while(t)c[k++]=t%10,t/=10;for(k||(c[k++]=0);k;)putchar(c[--k]^48);putchar(z);}
template<class T>void outputs(T t){output(t);}
template<class S,class ...T>void outputs(S a,T...t){output(a,32);outputs(t...);}
template<class T>void output(T *a,int n){REP(i,n)cout<<a[i]<<(i!=n-1?',':'\n');}
template<class T>void output(T *a,int n,int m){REP(i,n)output(a[i],m);}
template<class T>bool input(T &t){int n=1,c;for(t=0;!isdigit(c=getchar())&&~c&&c-45;);
if(!~c)return 0;for(c-45&&(n=0,t=c^48);isdigit(c=getchar());)t=10*t+c-48;t=n?-t:t;return 1;}
template<class S,class ...T>bool input(S&a,T&...t){input(a);return input(t...);}
template<class T>bool inputs(T *a, int n) { REP(i,n) if(!input(a[i])) return 0; return 1;}

int x[10][10];
int main() {
  int n,d;
  while(input(n,d)) {
    REP(i,n) inputs(x[i], d);
    int ans = 0;
    REP(i,n) {
      REP(j,i) {
        int a = 0;
        REP(k,d) a += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
        int t = sqrt(a);
        if (t * t == a || (t-1)*(t-1) == a || (t+1)*(t+1) == a) ans++;
      }
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 256
n=int(input())
s=[]

for _ in range(n):
    s.append(int(input()))

s=sorted(s)
ans=sum(s)

for x in s:
    if ans%10!=0:
        break
    if x%10==0:
        continue
    ans-=x
if ans%10==0:
    ans=0
print(ans)



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

using namespace std;

const long long INF = LONG_LONG_MAX;
const int maxsum = (int) (1e5 + 1);

vector<vector<int>> g;
vector<long long> dp;

long long dfs(int v) {
    if (dp[v] != -1) return (dp[v]);
    if (g[v].empty()) return dp[v] = 0;
    for (int u : g[v]) {
        dp[v] = max(dp[v], dfs(u) + 1);
    }
    return dp[v];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s, t;
    int n, m;
    cin >> n >> m;
    g.resize(n);
    dp.resize(n, -1);
    int u, v;
    for (int i = 0; i < m; ++i) {
        cin >> u >> v;
        u--;
        v--;
        g[u].push_back(v);
    }
    long long ans = -1;
    for (int i = 0; i < n; ++i) {
        ans = max(ans, dfs(i));
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 8576
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <cassert>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;

typedef long long ll;

const int N = 200005;

struct node
{
        int a, b, c;
} v[N];
bool cmp1(node a, node b)
{
        return a.a < b.a;
}
bool cmp2(node a, node b)
{
        return a.b < b.b;
}

int main()
{
        ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int n; cin >> n;
        for(int i = 1; i <= n; ++i) cin >> v[i].a, v[i].b = i;
        sort(v+1,v+1+n,cmp1);
//        for(int i = 1; i <= n; ++i) cerr << v[i].a << ' ' << v[i].b << ' ' << v[i].c << endl;
        for(int i = 1; i <= n; ++i)
        {
                if(i <= n/2) v[i].c = v[(n+2)/2].a;
                else v[i].c = v[n/2].a;
        }
        sort(v+1,v+1+n,cmp2);
        for(int i = 1; i <= n; ++i) cout << v[i].c << '\n';
        return 0;
}


Measured memory_bytes: 4608
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    int arr[n+2];
    int dp[n+2]={0};
    
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    dp[0]=0;
    dp[1]=abs(arr[0]-arr[1]);
    
    for(int i=2;i<n;i++)
    {
        dp[i]=INT_MAX;
        for(int j=1;j<=k&&(i-j)>=0;j++)
        {
            //cout<<dp[i]<<" "<<dp[i-j]+abs(arr[i-j]-arr[i])<<endl;
            dp[i]=min(dp[i],dp[i-j]+abs(arr[i-j]-arr[i]));
        }
        //cout<<dp[i]<<endl;
    }
    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(void){
    int a,b,c,d,i,j,l,p,s;
    scanf("%d",&l);
    scanf("%d",&a);
    scanf("%d",&b);
    scanf("%d",&c);
    scanf("%d",&d);
    s=l;
    for(i=l;i>0;i--){
        a=a-c;
        if(a<=0){
                i=i-1;
            break;
        }
    }
    for(j=s;j>0;j--){
        b=b-d;
        if(b<=0){
            j=j-1;
            break;
        }
    }
    if(i<j){
    p=i;
    }else if(i>j){
    p=j;
    }else if(i==j){
    p=i;
    }
    printf("%d\n",p);
return 0;
}

Measured memory_bytes: 592