akhauriyash/Code-Regression huggingface dataset:
while True:
  a,b = map(int,input().split())
  if a == 0 and b ==0 :
    break
  else:
    for i in range(a):
      if i == 0 or i == a -1:
        print('#' * b)
      else:
        print('#%s#' %('.' * (b-2)))
    print()    





Measured memory_bytes: 5616
import heapq

def main():
    q = []
    heapq.heapify(q)
    while True:
        s = input().split()
        if s[0] == 'end':
            break
        elif s[0] == 'insert':
            heapq.heappush(q, -int(s[1]))
        else:
            p = heapq.heappop(q)
            print(-p)

if __name__ == '__main__':
    main()


Measured memory_bytes: 45304
#include <iostream>
#include <vector>
#include <algorithm>    // std::min_element, std::max_element
using namespace std;


int main(){
    
    int c = 0; //count how many input sets
    int l; //entire length
    int n; // number of branches
    int m; //number of orders
    vector<int> v;
    int sum;
    
    
    for(;; c++){
        
        sum = 0;
        cin >> l;
        if(l == 0)
            break;
        cin >> n;
        cin >> m;
        
        vector<int> d; //from 4th to n-1 line on txt
        d.push_back(0);
        int k[m]; //coustomer k1' house at k[0] meater     n+3 to m line
        
        for(int i = 1; i < n; i++){
            int in;
            cin >> in;
            d.push_back(in);
        }
        
        for(int i = 0; i < m; i++)
            cin >> k[i];
        
        std::sort(d.begin(), d.end());
      
        for (int j = 0; j < m; j++){
            
            int right = n-1;
            int left = 0;
            int middle = (right + left)/2;
            
            if ( d[right] <= k[j] )
                sum  += min(k[j] - d[right], l - k[j]);
            else{
                while(true){//Binary Search
                    if (left + 1 == right)
                    {
                        sum  += min(abs(d[right] - k[j]), abs(k[j] - d[left]));
                        break;
                    }
                    else if ( k [j] == d[middle] )
                        break;
                    else if(k [j] < d[middle])
                    {
                        right = middle;
                        middle = (right + left)/2;
                    }
                    else if(k [j] > d[middle]){
                        left = middle;
                        middle = (right + left)/2;
                    }
                }
            }
        }
        
        v.push_back(sum);
        
    }
    for (int i = 0; i < c; i++)
        cout << v[i] << endl;
    return 0;
}
     
       

Measured memory_bytes: 3376
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <queue>
#include <stack>
#include <bitset>
#define y1 y11
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define NAME ""

using namespace std;
	
typedef long long ll;
typedef long double ld;

const ld PI = acos(-1.0);

const int MAXN = 1000001;
string s;
string t;
ll x[MAXN];
ll f1[MAXN];
ll f2[MAXN];
ll f[MAXN];
const ll INF = 1ll << 40;
int main()
{
	ios_base::sync_with_stdio(0);
	int n;
	ll t, e;
	cin >> n >> e >> t;
	x[0] = 0;
	for (int i = 1; i <= n; i++)
	{
		cin >> x[i];
	}
	for (int i = 0; i <= n; i++) f[i] = f2[i]  = INF;
	f[0] = 0;
	for (int i = 1; i <= n; i++)
	{
		ll d = f[i - 1] + x[i] - x[i  - 1];
		int g = upper_bound(x + i, x + n + 1, x[i] + t / 2) - x;	
		f[g - 1] = min(f[g - 1], d + t + x[g - 1] - x[i]);
		f2[g] = min(f2[g], d - 3 * x[i]);
		f2[i] = min(f2[i], f2[i - 1]);
		f[i] = min(f[i], f2[i] + 3 * x[i]);
	}
	cout << f[n] + e - x[n] << endl;
	return 0;
}






Measured memory_bytes: 2688
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>

#define rep(i, n) REP(i, 0, n)
#define REP(i, a, n) for(int i = a ; i < (int)n ; i++)
#define ALL(v) v.begin(), v.end()
#define pb push_back
#define mp make_pair
#define eps 1e-14
#define m0(x) memset(x, 0, sizeof(x))

using namespace std;

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

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

signed main(){
  string a, b, c;
  
  cin >> a >> b >> c;
  if(a[a.size()-1] == b[0] && b[b.size()-1] == c[0]) cout << "YES" << endl;
  else cout << "NO" << endl;
}


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

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

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

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N, K;

void MAIN() {
    scanf("%d%d", &N, &K);
    printf("%d\n", N-K+1);

}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

void solve(vector<vector<int>> &A, vector<bool> check, int &ans, int now){
    check.at(now) = true;
    bool T = false;
    for (int i = 0; i < A.at(now).size(); i++){
        if (check.at(A.at(now).at(i))) {
            continue;
        }
        solve(A, check, ans, A.at(now).at(i));
        T = true;
    }
    if (!T) {
        for (int i = 0; i < check.size(); i++) {
            if (!check.at(i)){
                break;
            }
            if (i == check.size() - 1) {
                ans++;
            }
        }
    }
    return;

}

int main() {
    int N, M, ans = 0;
    cin >> N >> M;
    vector<vector<int>> A(N);
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        A.at(a - 1).emplace_back(b - 1);
        A.at(b - 1).emplace_back(a - 1);
    }
    vector<bool> check(N, false);
    solve(A, check, ans, 0);
    cout << ans << endl;
}

Measured memory_bytes: 256
N, M, X = map(int, input().split())
array = list(map(int, input().split()))
index = [0] * (N+1)
tmp = 0
tmp2 = 0
for i in range(N):
    if i in array:
        index[i] = 1
for i in range(X,N+1):
    tmp += index[i]
for i in range(0,X+1):
    tmp2 += index[i]
if tmp <= tmp2:
    print(tmp)
else:
    print(tmp2)

Measured memory_bytes: 3064
from bisect import bisect_left


n = int(input())
nums = list(map(int, input().split()))


cumsum = []
ret = 0


for i in (nums):
    ret += i
    cumsum.append(ret)


s = cumsum[-1]


min_val = float('inf')


for i in range(len(cumsum)-1):
    min_val = min(min_val, abs(cumsum[i] * 2 - s))




print(min_val)

Measured memory_bytes: 86864
n = int(input())
xs = list(map(int, input().split()))

# +-+-...
t1 = 0
s1 = 0
for (i, x) in enumerate(xs):
    s1 += x
    if i % 2 == 0:
        if s1 < 1:
            t1 += (1 - s1)
            s1 = 1
    else:
        if s1 > -1:
            t1 += (s1 + 1)
            s1 = -1

# -+-+...
t2 = 0
s2 = 0
for (i, x) in enumerate(xs):
    s2 += x
    if i % 2 == 0:
        if s2 > -1:
            t2 += (s2 + 1)
            s2 = -1
    else:
        if s2 < 1:
            t2 += (1 - s2)
            s2 = 1

print(min(t1, t2))

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

typedef long long W;

const W INF = 1LL << 50;

struct edge {
	int to;
	W cost;
};
typedef pair<W, int> P;
typedef vector<vector <edge > > Graph;

void dijkstra(int s, const Graph& G, vector<W>& d) {
	priority_queue< P, vector<P>, greater<P> > que;
	fill(d.begin(), d.end(), INF);
	d[s] = 0;
	que.push(P(0, s));
	while(!que.empty()) {
		P p = que.top();
		que.pop();
		int v = p.second;
		if(d[v] < p.first) continue;
		for(int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			if(d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

int dist[100000];
int z[100000];

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

	int N, M, K, S;
	ll P, Q;
	cin >> N >> M >> K >> S >> P >> Q;

	fill((int*)begin(dist), (int*)end(dist), 1 << 25);
	queue<int> q;
	for(int i = 0; i < K; i++) {
		int a;
		cin >> a;
		a--;
		q.push(a);
		z[a] = 2;
		dist[a] = 0;
	}

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

	while(q.size()) {
		int v = q.front();
		int d = dist[v];
		q.pop();
		for(auto e : G[v]) {
			if(dist[e.to] > d + 1) {
				dist[e.to] = d + 1;
				q.push(e.to);
			}
		}
	}

	for(int i = 0; i < N; i++) {
		if(z[i] == 0 && dist[i] <= S) z[i] = 1;
	}

	for(int i = 0; i < N; i++) {
		for(auto& e : G[i]) {
			if(e.to == N - 1) e.cost = 0;
			else if(z[e.to] == 1) e.cost = Q;
			else if(z[e.to] == 2) e.cost = INF;
			else e.cost = P;
		}
	}

	vector<W> d(N);
	dijkstra(0, G, d);
	cout << d[N - 1] << endl;
}

Measured memory_bytes: 17556
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] va = new int[n];
        int[] ca = new int[n];
        for(int i=0; i<n; i++){
            va[i] = sc.nextInt();
        }
        for(int i=0; i<n; i++){
            ca[i] = sc.nextInt();
        }
        sc.close();

        int total = 0;
        for (int i=0; i<n; i++){
            total += va[i] > ca[i] ? va[i] - ca[i] : 0 ;
        }
        System.out.println(total);
    }
}


Measured memory_bytes: 21204
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<functional>

using namespace std;

int gcd(int a, int b, int &c){
  if(a>b) swap(a,b);
  if(a==0)return b;
  c++;
  return gcd(a, b%a, c);
}

int main(){
  int a,b,c;
  while(scanf("%d%d",&a,&b), a+b){
    c = 0;
    int d = gcd(a,b,c);
    printf("%d %d\n",d,c);
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define sz 150
#define ll long long int 
using namespace std;


int main()
{
	ll n, i, j, k, count {1};
	vector<string> v;
	string s;
	
	cin>>n;
	
	for(i=0; i<n; i++)
	{
		cin>>s;
		v.push_back(s);
	}
	
	sort(v.begin(), v.end());
	
	for(i=1; i<n; i++)
	{
		if(v[i]==v[i-1])
			continue;
		count ++;
	}
	
	cout<<count<<endl;
	
}

Measured memory_bytes: 11624
#include <iostream>
#include <cstdlib>
#include <vector>
#include <string>

using namespace std;

int main()
{
    long long x, y, ans;
    ans = 0;
    cin >> x >> y;
    if(x <= y && x >= 0 && y >= 0){
        ans = y - x;
    }
    else if(x > y && x >= 0 && y >= 0){
        ans = ((y == 0) ? 1 : 2) + x - y;
    }
    else if(x >= 0 && y < 0){
        ans = 1 + abs(abs(y) - abs(x));
    }
    else if(abs(x) > abs(y) && x < 0 && y >= 0){
        ans = abs(abs(x) - abs(y)) + ((y == 0) ? 0 : 1);
    }
    else if(abs(x) <= abs(y) && x < 0 && y >= 0){
        ans = 1 + abs(abs(x) - abs(y));
    }
    else if(abs(x) >= abs(y) && x < 0 && y < 0){
        ans = abs(abs(y) - abs(x));
    }
    else if(abs(x) < abs(y) && x < 0 && y < 0){
        ans = 2 + abs(abs(y) - abs(x));
    }
    else {
        cout << "Not match" << endl;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double lld;
ll MOD = (1e9)+7;
const int dr[] = {+1, -1, +0, +0, +1, -1, +1, -1};
const int dc[] = {+0, +0, +1, -1, +1, -1, -1, +1};
const int kx[] = {+1, +2, -1, -2, +1, +2, -1, -2};
const int ky[] = {+2, +1, +2, +1, -2, -1, -2, -1};
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
inline void fastIO(){
  ios_base::sync_with_stdio(0);cin.tie(0);
}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void debug_out() { cerr << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }

#ifdef LOCAL
#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#else
#define debug(...) 47
#endif
const int MAXN=303030;
int main(){
  fastIO();
  int h,w,m;
  int maxX=0,maxY=0;
  int posX=0,posY;
  int tempMaxX=0,tempMaxY=0;
  cin>>h>>w>>m;
  map<int,int>cols;
  map<int,int>rows;
  map<pair<int,int>,int>coord;
  for(int i=0;i<m;i++){
    int x,y;
    cin>>x>>y;
    cols[x]++,rows[y]++;
    if(cols[x]>maxX)posX=x;
    if(rows[y]>maxY)posY=y;
    maxX=max(maxX,cols[x]);
    maxY=max(maxY,rows[y]);
    coord[make_pair(y,x)]++;
  }
  for(int i=0;i<=MAXN;i++){
    int num=cols[i]-coord[make_pair(posY,i)];
    tempMaxX=max(tempMaxX,num);
  }
  for(int i=0;i<=MAXN;i++){
    int num=rows[i]-coord[make_pair(i,posX)];
    tempMaxY=max(tempMaxY,num);
  }
  cout<<max(tempMaxY+maxX,tempMaxX+maxY)<<endl;
  return 0;
}


Measured memory_bytes: 88700
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m,num=1,index,ma,a0=0;
    cin>>n>>m;
    ll x[m],b[m];
    vector<pair<ll,ll > > v;
    for(int i=0;i<m;i++){
        cin>>x[i];
    }
    sort(x,x+m);
    for(int i=0;i<m-1;i++){
        b[i]=x[i+1]-x[i];
        if(b[i]!=1){
            num++;
        }
    }
    if(num<=n){
        ma=max(m-n,a0);
        cout << ma<<endl;
    }
    else{
        sort(b,b+m-1);
        for(int i=0;i<m-1;i++){
            b[i]--;
        }
        for(int i=0;i<m-1;i++){
            if(b[i]!=0){
                v.pb(make_pair(b[i],1));
                index=i+1;
                break;
            }
        }
        for(int i=index;i<m-1;i++){
            if(b[i]!=b[i-1]){
                v.pb(make_pair(b[i],1));
            }
            else{
                v[v.size()-1].second++;
            }
        }
        int si=v.size();
        for(int i=0;i<si;i++){
            if(num-v[i].second<=n){
                m+=v[i].first*(num-n);
                ma=max(m-n,a0);
                cout <<ma <<endl;
                break;
            }
            else{
                m+=v[i].first*v[i].second;
                num-=v[i].second;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 1792
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"

#define REP(i,a,b) for(int i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define all(a) begin(a),end(a)
#define ifnot(a) if(not (a))
#define dump(x)  cerr << #x << " = " << (x) << endl
using namespace std;

// #define int ll

int dx[] = { 0,1,0,-1 };
int dy[] = { 1,0,-1,0 };
#define LINF ((ll)1 << 60)
#define INF (1 << 28)
template<typename T>
void chmax(T& a, T b) {
        if (a < b) a = b;
}
template<typename T>
void chmin(T& a,T b) {
        if (a > b) a = b;
}
int T = 1;
//.....................
ull mod = (int)1e9 + 7;
const int MAX = (int)2e5 + 5;

int H, W;
static string field[1000];

void solve() {
        cin >> H >> W;
        rep(i, H) cin >> field[i];
        rep(i, H) {
                cout << field[i] << endl;
                cout << field[i] << endl;
        }
}

signed main() {
        cout << fixed << setprecision(20);
        rep(i, T) {
                solve();
        }
        return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

int main(){
    int W, H;
    cin >> W >> H;
    int x, y;
    cin >> x >> y;

    cout << setprecision(10) << (double)W*H/2 << ' ';
    if(x==W/2 && W%2==0 && H%2==0 && y==H/2){
        cout << 1 << endl;
    }else{
        cout << 0 << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
using namespace std;

const int N=100005;

int n,m,ans,x,y,p;
int a[N];

int main(){
	int i;
	scanf("%d%d",&n,&m);
	for (i=1;i<=n;i++) scanf("%d",&a[i]);
	p=0;
	for (i=1;i<n;i++)
		if (a[i]+a[i+1]>=m){
			p=i;
			break;
		}
	if (!p){
		printf("Impossible\n");
		return 0;
	}
	printf("Possible\n");
	for (i=1;i<p;i++) printf("%d\n",i);
	for (i=n-1;i>p;i--) printf("%d\n",i);
	printf("%d\n",p);
	return 0;
}

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

int main(){
  	string s;
  	cin >> s;
  	int ans = 0,aux = 0;
  	for(auto c : s){
      if(c == 'R') aux++;
      else aux = 0;
      ans = max(ans,aux);
    }
  	cout<< ans;
	return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

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

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

ll dp[110][5][5][5];

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

    // A -> 0
    // T -> 1
    // C -> 2
    // G -> 3
    dp[0][1][1][1] = 1;

    for(int i=0; i<n; i++){
        for(int j=0; j<4; j++){ // i-2
            for(int k=0; k<4; k++){ // i-1
                for(int l=0; l<4; l++){ // i
                    for(int m=0; m<4; m++){ // i+1
                        // *AGC 
                        if(k == 0 && l == 3 && m == 2) continue;

                        // *ACG
                        if(k == 0 && l == 2 && m == 3) continue;

                        // *GAC
                        if(k == 3 && l == 0 && m == 2) continue;

                        // A*GC
                        if(j == 0 && l == 3 && m == 2) continue;

                        // AG*C
                        if(j == 0 && k == 3 && m == 2) continue;

                        dp[i+1][m][l][k] += dp[i][l][k][j];
                        dp[i+1][m][l][k] %= MOD;
                    }
                }
            }
        }
    }

    ll ans=0;
    for(int i=0; i<4; i++){
        for(int j=0; j<4; j++){
            for(int k=0; k<4; k++){
                ans += dp[n][i][j][k];
                ans %= MOD;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (unsigned int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD =  1000000007 ;
const int INF = 2000000000;


    int A,B,C,D;
    string S,T;
int main(){
    cin>>S;
    T="abc";sort(ALL(S));
    cout<<(S==T?"Yes":"No")<<endl;
    return 0;

}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a[100],n,i,l=0,s=0,temp;
    scanf("%d",&n);
    i=0;
    temp=n;
    while(n>0)
    {
        a[i]=n%10;
        n=n/10;
        i++;
        l++;
    }
    for(i=0;i<l;i++)
    {
        s=s+a[i];
    }

    if(temp%s==0)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    return 0;
}


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

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;
double pi = 3.141592653589;
int main(void) 
{
    int a, b;
    double r;
    cin >> r;
    printf("%.10lf %.10f\n", pi * r * r, 2 * pi * r);

//    cout << (a/b) << " " << (a%b) << " " << ((double)a/(double)b) << endl;

}



Measured memory_bytes: 3284
//#pragma GCC optimize ("-O3","unroll-loops")
// #pragma GCC target("avx")
#include<bits/stdc++.h>
 
using namespace std;
 
#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), n)
#define ub(v,n) upper_bound(v.begin(), v.end(), n)
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
 
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; }
typedef pair<int, int>P;
const int MOD = 1e9+7; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 2e18;

int cnt[60];
int A[300030];
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll add(ll x, ll y) {
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
ll sub(ll x, ll y) {
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
ll mult(ll x, ll y) {
	return (x * y) % MOD;
}
ll bin_pow(ll x, ll p) {
	if (p == 0) return 1;
	if (p & 1) return mult(x, bin_pow(x, p - 1));
	return bin_pow(mult(x, x), p / 2);
}
void solve() {
	int N;cin>>N;
	REP(i,N){
		cin>>A[i];
		REP(j,60){
			if(A[i]&(1LL<<j))cnt[j]++;
		}
	}
	ll ans=0;
	REP(i,N){
		REP(j,60){
			if(A[i]&(1LL<<j)){
				ans+=((1LL<<j)%MOD)*(N-cnt[j]);
				ans%=MOD;
			}
			else{
				ans+=((1LL<<j)%MOD)*cnt[j];
				ans%=MOD;
			}
		}
	}
	ans=mult(ans,bin_pow(2,MOD-2));
	print(ans);
}
 
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
}


Measured memory_bytes: 3200
A, B = gets.split.map(&:to_i)

if (A..B).cover?(0)
  puts 'Zero'
elsif A > 0 && B > 0
  puts 'Positive'
elsif A < 0 && B < 0
  puts (B - A + 1).even? ? 'Positive' : 'Negative'
end


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

#define F first 
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 100010, M = 1010;

int n, t;
int a[N];
LL sum;

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i ++ ) scanf("%d", &a[i]);
	
	LL res = 0LL;
	for (int i = 1, t = 1; i <= n; i ++ , t *= -1)
	{
		sum += a[i];
		if (t * sum <= 0) res += abs(t - sum), sum = t;
	}
	
	sum = 0LL;
	LL ans = 0LL;
	for (int i = 1, t = -1; i <= n; i ++ , t *= -1)
	{
		sum += a[i];
		if (t * sum <= 0) ans += abs(t - sum), sum = t;
	}
	
	printf("%lld\n", min(res, ans));
    return 0;
}

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

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int A,B; char op;
	cin>>A>>op>>B;
	if(op=='+') A+=B;
	else A-=B;
	cout << A << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
 
#define ll long long
#define MOD 1000000007
#define pll             pair<ll,ll>
#define pii             pair<int,int> 
#define mp(a,b)         make_pair(a,b)
#define pb 				push_back
#define vi				vector<int>
#define vl 				vector<long long>
#define vb 				vector<bool>
#define printv(v)		for(auto x : v) cout<<x<<' ';br;
#define FOR(i,a,b) 		for(ll i = a; i <= b ; i++)
#define forn(i,n) 		for(ll i = 0 ; i < n; i++)
#define br 				cout<<endl;
#define testc()			ll t;cin>>t;while(t--)
 
#define fast 			ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define INF				INT_MAX
#define INFL			LLONG_MAX
#define max1(x,y) (x)>(y)?(x):(y)
#define ss second
#define ff first
#define MAXN 1000000001

int main(){
    fast
    ll n;
    cin>>n;
    ll arr[n];
    forn(i,n)
    cin>>arr[i];
    ll dp[n];
    dp[0]=0;dp[1]=abs(arr[0]-arr[1]);
    FOR(i,2,n-1){
        dp[i]=min(dp[i-2]+abs(arr[i]-arr[i-2]),dp[i-1]+abs(arr[i]-arr[i-1]));
    }
    cout<<dp[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 1792
from collections import deque
from bisect import insort_left

N,K = map(int,input().split())
V = [int(i) for i in input().split()]

answer = 0
A = 0
while A <= min(N,K):
    B = 0
    while A + B <= min(N,K):
        have = []
        for i in range(A):
            insort_left(have, V[i])
        for i in range(B):
            insort_left(have, V[-(i+1)])

        have = deque(have)

        throw = min(K - (A + B), len(have))
        for _ in range(throw):
            tmp = have.popleft()
            if tmp > 0:
                have.append(tmp)
                break

        answer = max(answer, sum(have))
        B += 1
    A += 1

print(answer)

Measured memory_bytes: 3444
import numpy as np

n, m = list(map(int, input().split()))
mat = np.zeros((m, 3))
for i in range(m):
	mat[i, 0], mat[i, 1] = list(map(int, input().split()))
	mat[i, 2] = i
mat = mat[mat[:, 1].argsort()]
cnt = np.zeros(n+1)
res = []
for i in mat[:, 0]:
	i = int(i)
	cnt[i-1] += 1
	res.append('{0:06d}{1:06d}'.format(i, int(cnt[i-1])))

for idx in np.argsort(mat[:, 2]):
	print(res[int(idx)])


Measured memory_bytes: 27832
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define INF 2147483647
#define LLINF 9223372036854775807
using namespace std;
int a[200010];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int mn=1000000000;
	int cnt=0;
	for(int i=0;i<n;i++){
		if(mn>a[i]){
			cnt++;
			mn=a[i];
		}
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int countA;

void cal(int K,int S){
  int z;
  REP(i,K+1){
    REP(j,K+1){
      z = S -i-j;
      if(0 <= z && z <= K) countA++;
    }
  }
}

int main(){
  int K,S;
  cin >>K>>S;
  countA =0;
  cal(K,S);
  std::cout << countA << '\n';
}


Measured memory_bytes: 256
MOD = 10 ** 9 + 7
def ncr(n, r):
    num = den = 1
    for i in range(r):
        num = (num * (n - i)) % MOD
        den  = (den * (i + 1)) % MOD
    return (num * pow(den, MOD - 2, MOD)) % MOD

n = int(input())
i = 1; ans = 0
while n - (3 * i) >= 0:
    total = n - 3 * i
    ans = (ans + ncr(total + i - 1, total)) % MOD
    i +=1

print(ans)


Measured memory_bytes: 65772
"""
N 個の宝石があり、i 番目の宝石の価値は Viです。
あなたはこれらの宝石の中からいくつかを選んで手に入れます。
このとき、1つも選ばなくとも、全て選んでも構いません。
ただし、i番目の宝石を手に入れる場合コスト Ciを支払わなければいけません。
手に入れた宝石の価値の合計を X、支払ったコストの合計を Yとします。
X−Yの最大値を求めてください。

制約
入力は全て整数である。
1≤N≤20
1≤Ci,Vi≤50

X - Y = Σ(Vi - Ci)
Vi - Ci > 0のものを全て取得する
"""
N = int(input())
v_list = input().split(" ")
c_list = input().split(" ")
v_list = [int(i) for i in v_list]
c_list = [int(i) for i in c_list]

sumValue = 0
for i in range(N) : 
    substantialValue = v_list[i] - c_list[i]
    if substantialValue > 0 : sumValue += substantialValue
print(sumValue)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
int n;
string s;
map<string,bool> mp;
int main(){
	ios::sync_with_stdio(0);
	cin>>n;
	int ans=0;
	rep(i,n){
		cin>>s;
		if(!mp[s]){
			mp[s]=true;
			ans++;
		}
	}
	cout<<ans;
	
	re 0;
}

Measured memory_bytes: 19292
N = int(input())

h = list(map(int,input().split()))

lis = [0,abs(h[1]-h[0])]


for i in range(N-2):

    i += 2

    lis.append( min ( lis[i-2] + abs(h[i] - h[i-2]) , lis[i-1] + abs(h[i] - h[i-1]) ) )

print (lis[-1])


Measured memory_bytes: 13980
#include <bits/stdc++.h>
/* S.size() s.substr(l,r=s.size()-l) -> l文字目からr文字分
__gcd()　lower_bound(a+l,a+r,x)-a でindex
配列  -> min/max({}) 
vector-> *min_element(a.begin()+l,a.begin()+r)  *忘れず lとrで[l,r) 
reverse(a+l,a+r)   配列aの[l,r)を逆順に strはreverse(all(s))
sort(a+l,a+r,greater <int>()) 配列aの[l,r)昇順sort,大きい順はgreater<type>()
clock()/CLOCKS_PER_SEC で秒数 int ti=clock() ok
vector v.push_back(x),v.pop_back()
q.push(x),front()で先頭を返す,pop()で削除, size(),empty()
<deque>(push/pop)_(front/back)/fornt/back/insert/
priority_queue 宣言は priority_queue< Type, vector<Type>, greater<Type>> Q1; 
pq.push(x),top()で参照 pop()で削除   greaterで最小 lessで最大がtopに*/
using namespace std;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define range(i, s, n) for (int i = (s); i < (n); i++)
#define lange(i, s, n) for (long long i = (s); i < long long (n); i++)
#define rrep(i,n) for(int (i)=(n)-1;(i)!=-1;(i)--)
#define vep(i,v) for(auto (i)=v.begin();(i)<(v.end());(i)++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline T GCD(T a, T b) { return b?GCD(b,a%b):a;}
template<class T> inline T LCM(T a, T b) { return a/GCD(a,b)*b;}
inline long long ceildiv(long long a, long long  b) { return (a+b-1)/b; }
template<class T> inline T modinv(T a, T M) { return (1-M*modinv(M%a,a))/a+M;}
typedef pair<long long,long long> P;
typedef pair<int,int> PI;
typedef std::vector<int> vi;
typedef std::vector<long long> vl;
typedef std::vector<std::vector<int>> vvi;
typedef std::vector<std::vector<long long>> vvl;
typedef std::vector<char> vc;
typedef std::vector<std::vector<char>> vvc;
typedef std::vector<long long> vl;
typedef std::vector<bool> vb;
typedef std::vector<std::vector<bool>> vvb;
using Graph = std::vector<std::vector<int> >;
const long long inf = 10e17;
const long long mod = 1000000007;
//int |x|<=2*10**9     long |x|<= 9*10**18
//printf(".(小数点以下の桁数)lf(double時、float ならf)")
#define ll long long
#define print(i) std::cout << (i) << '\n'
int f(string S){
    int n=S.size(),left=-1,right=-1;
    int ret=0;
    std::vector<int> res(n,0);
    for(int i=1;i<n;i++){
        int cnt= right<i?0:min(right-i,res[i-left]);
        while(i+cnt<n && S[cnt]==S[cnt+i])cnt++;
        res[i]=cnt;
        if(i>=cnt)ret=max(ret,cnt);
        if (right<i+cnt){right=i+cnt;left=i;}}
    res[0]=n;return ret;}
int main(){
int n,ans=0;string s;cin>>n>>s;
string now="";
rep(i,n){
    now=s[n-1-i]+now;
    ans=max(ans,f(now));
}
print(ans);
}


Measured memory_bytes: 3748
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int N=scan.nextInt();
		int[] a = new int[N];
		for(int i=0;i<N;i++){
			a[i]=scan.nextInt();
		}
		Arrays.sort(a);
		System.out.println(a[N-1]-a[0]);
	}

}


Measured memory_bytes: 21844
#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define FOR(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTL(d) printf("%lld\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9

typedef long long ll;
int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int Max(int a, int b) {
	return (a) > (b) ? (a) : (b);
}
void Swap(int *a, int *b) {
	int tmp = *a;
	*a = *b;
	*b = tmp;
}
void hSwap(char x[][51], int i, int j)
{
	char temp[51];

	strcpy(temp,x[i]);
	strcpy(x[i],x[j]);
	strcpy(x[j],temp);
}
void ShowData(char x[][51], int left, int right)
{
	int i;
	for (i = left; i <= right; i++)printf("%s\n", x[i]);
	printf("\n");
}
void QSort(char x[][51], int left, int right, int n) {
	int i, j;	//左端,右端
	char pivot[51];	//軸

	i = left;
	j = right;
	strcpy(pivot,x[(left + right) / 2]);

	while (1) {
		if (n > 0) {				//n>0なら昇順、n<=0なら降順
			while ((strcmp(x[i],pivot)<0) && (i <= right))i++;	//軸値より大きい要素
			while ((strcmp(pivot,x[j])<0) && (i <= right))j--;	//軸値より小さい要素
		}
		else {
			while ((x[i] > pivot) && (i <= right))i++;	//軸値より小さい要素
			while ((pivot > x[j]) && (i <= right))j--;	//軸値より大きい要素
		}
		if (i >= j)	break;
		hSwap(x, i, j);
		i++; j--;
	}
	//ShowData(x, left, right);

	if (left < i - 1)QSort(x, left, i - 1, n);
	if (j + 1 <  right)QSort(x, j + 1, right, n);
}



char str[250000][51] = { '\0' };
int main() {
	char s[5001];
	scanf("%s", s);
	int k;
	scanf("%d", &k);
	int len = strlen(s);
	int cnt = 1;
	REP(i, len) {
		REPS(j, k) {
			char t[51];
			strncpy(t, s + i, j);
			t[j] = '\0';
			if (i == 0 & j == 1) {
				strcpy(str[0], t);
				continue;
			}
			REP(k, cnt) {
				//printf("%s %s@\n", t, str[k]);
				if (strcmp(t, str[k]) == 0)break;
				if (k == cnt - 1)strcpy(str[cnt++], t);
			}
			//ShowData(str, 0, cnt-1);
		}
	}
	QSort(str, 0, cnt - 1, 1);
	//ShowData(str, 0, cnt-1);
	puts(str[k-1]);
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using Graph = vector<vector<pii>>;
const int MOD = 1e9 + 7;

int N, C;
vector<vector<int>> D;
vector<vector<int>> cnt;

int a[3];
int rec(int d = 0) {
    int res = INT_MAX;
    if (d >= 3) {
        if (a[0] == a[1] || a[1] == a[2] || a[2] == a[0])
            return res;
        res = 0;
        for (int i = 0; i < 3; ++i)
            for (int j = 0; j < C; ++j)
                res += D[j][a[i]] * cnt[i][j];
        return res;
    }

    for (int i = 0; i < C; ++i) {
        a[d] = i;
        res = min(res, rec(d + 1));
    }
    return res;
}

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

    cin >> N >> C;
    D.resize(C, vector<int>(C));
    cnt.resize(3, vector<int>(C));
    for (int i = 0; i < C; ++i)
        for (int j = 0; j < C; ++j)
            cin >> D[i][j];
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            int c;
            cin >> c;
            c--;
            cnt[(i + j) % 3][c]++;
        }
    }

    cout << rec() << endl;

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <cstring>

using namespace std;

const int dx[4] = {-1, 0, 0, 1};
const int dy[4] = {0, -1, 1, 0};
int w, h;
char v[51][51];
bool used[51][51];

inline bool valid(int y, int x) {
    return 0 <= y && y < h && 0 <= x && x < w;
}

int dfs(int y, int x, bool &adjb, bool &adjw, int &area) {
    used[y][x] = true;
    area ++;
    for (int i=0; i<4; ++i) {
        if (valid(y + dy[i], x + dx[i])) {
            adjb |= (v[y + dy[i]][x + dx[i]] == 'B');
            adjw |= (v[y + dy[i]][x + dx[i]] == 'W');
            if ( ! used[y + dy[i]][x + dx[i]] && v[y + dy[i]][x + dx[i]] == '.') {
                dfs(y + dy[i], x + dx[i], adjb, adjw, area);
            }
        }
    }
}

int main() {
    while (cin >> w >> h) {
        if (w == 0 && h == 0) break;
        for (int i=0; i<h; ++i) {
            for (int j=0; j<w; ++j) {
                cin >> v[i][j];
            }
        }
        memset(used, 0, sizeof used);
        int white = 0, black = 0;
        for (int i=0; i<h; ++i) {
            for (int j=0; j<w; ++j) {
                if ( ! used[i][j] && v[i][j] == '.') {
                    int area = 0;
                    bool adjb = false, adjw = false;
                    dfs(i, j, adjb, adjw, area);
                    if ( ! adjb && adjw) {
                        white += area;
                    } else if (adjb && ! adjw) {
                        black += area;
                    }
                }
            }
        }
        cout << black << " " << white << endl;
    }
    return 0;
}

Measured memory_bytes: 1316
#include<iostream>
#include<vector>
signed main(){
  int n;
  std::cin>>n;
  std::vector<int> a(n);
  for(auto& ai:a)std::cin>>ai;
  a.insert(std::begin(a),0);
  std::vector<int> b(n+1);
  int m = 0;
  for(int i=n;i>0;i--){
    int t = a[i];
    for(int j=i;j<=n;j+=i)t^=b[j];
    b[i] = t;
    m += b[i];
  }
  std::cout<< m <<std::endl;
  for(int i=1;i<=n;++i)if(b[i])std::cout<< i <<std::endl;
}

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

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String[] str = br.readLine().split(" ");
    int apple = Integer.parseInt(str[0]);
    int piece = Integer.parseInt(str[1]);
    System.out.println((apple * 3 + piece) / 2);
  }
}

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

int main(){
  ios::sync_with_stdio(0);
  priority_queue<int> pq;
  int n;
  cin >> n;
  while(n--){
        int x;
        cin >> x;
        pq.push(x);
    }
    int ans = 0;
    int k = 1;
    while(not pq.empty()){
        ans+= k*pq.top();
        pq.pop(); k*=-1;
    }
    cout << ans << endl;
} 


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.Ia;
		var a=(new string((char)(s[1]+'0'),s[0]));
		var b=(new string((char)(s[0]+'0'),s[1]));
		var h=new string[]{a,b};
		Array.Sort(h,(u,v)=>string.Compare(u,v));
		Console.WriteLine("{0}",h[0]);
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

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

string S[110];
int P[110];
int order[110];

void allSwap(int a) {
	swap(S[a], S[a + 1]);
	swap(P[a], P[a + 1]);
	swap(order[a], order[a + 1]);
}
int main(void) {
	int N;
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		cin >> S[i] >> P[i];
		order[i] = i + 1;
	}

	int j = N - 1;
	while(j > 0) {
		for (int i = 0; i < j; i++) {
			if (S[i] > S[i + 1]) {
				allSwap(i);
			} else if (S[i] == S[i + 1] && P[i] < P[i + 1]) {
				allSwap(i);
			}
		}
		j--;
	}

	for (int i = 0; i < N; i++) {
		printf("%d\n", order[i]);
	}

	return 0;
}


Measured memory_bytes: 3780
#include <bits/stdc++.h>
#define int long long
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;

vec gauss_jordan(const mat& A,const vec& b){
  int n=A.size();
  mat B(n,vec(n+1));
  vector<int> can(n,1);
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)B[i][j]=A[i][j]; //n*(n+1)の配列にする。

  for(int i=0;i<n;i++)B[i][n]=b[i]; //n番目に代入

  for(int i=0;i<n;i++){
    int pivot=i;//次の基準となる添え字。
    for(int j=0;j<n;j++)if(can[j] && B[j][i])pivot=j;//0以外の1つを探す
    swap(B[i],B[pivot]);//i行目に持ってくる。
    if(B[i][i]==1)can[i] = 0;

    
    for(int j=0;j<n;j++){ //
      if(i!=j && B[j][i])//i行目-i行目はスキップ
        for(int k=i;k<=n;k++)B[j][k]=B[j][k] ^ B[i][k];//i列の値をi列目以外を0にする。
    }
  }
  
  vec x(n);
  for(int i=0;i<n;i++)x[i]=B[i][n];
  
  int many = 0;
  for(int i=0;i<n;i++){
    if(B[i][i] == 0) many = 1;
    if(B[i][i] == 0 && B[i][n] == 1) return vec();
  }
  if(many) return vec(n+1);
  return x;
}

signed main(){
  
  while(1){
    
    int w, h, d;
    cin>>w>>h>>d;
    
    if( !w && !h && !d ) break;
    
    int a[25][25];
    
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++) cin>>a[i][j];
    
    mat A( h * w, vec( h * w ) );
    
    vec B( h * w );
    
    for(int i=0;i<h;i++){
      
      for(int j=0;j<w;j++){
	
	int idx = i * w + j;
	
	B[idx] = a[i][j];
	A[idx][idx] = 1;
	
	for(int ni=0;ni<h;ni++){
	  
	  for(int nj=0;nj<w;nj++){
	    
	    if( abs( ni - i ) + abs( nj - j ) != d ) continue;
	    
	    int nidx = ni * w + nj;
	    
	    A[idx][nidx] = 1;
	    
	  }
	  
	}
	
      }
      
    }
    
    vec ans = gauss_jordan( A, B );
    
    if( (int)ans.size() > 0 ) cout<<1<<endl;
    else cout<<0<<endl;
    
  }
  
  return 0;
}



Measured memory_bytes: 8928
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

//AtCoder Beginner Contest 154
//C	Distinct or Not
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int[] A = new int[N];
		Set<Integer> s = new HashSet<>();
		for (int i = 0; i < N; i++) {
			A[i] = Integer.parseInt(sc.next());
			s.add(A[i]);
		}
		sc.close();

		String ans = "NO";
		if (A.length == s.size()) {
			ans = "YES";
		}
		System.out.println(ans);
	}
}


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

struct edge { int to; ll dist; };

vector<edge> g[100005];
int n;
int q,k;

ll k_dist[100005];

void solve(int from){
  for(int i=0;i<g[from].size();i++){
    auto &e = g[from][i];
    if(!k_dist[e.to] && e.to != k){
      k_dist[e.to] = k_dist[from] + e.dist;
      solve(e.to);
    }
  }
}

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

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

  cin>>q>>k;
  k--;

  k_dist[k]=0;
  solve(k);

  // for(int i=0;i<n;i++){
  //   debug(k_dist[i]);
  // }

  while(q--){
    int x,y;cin>>x>>y;
    x--,y--;
    cout<<(k_dist[x] + k_dist[y])<<endl;
  }

  return 0;
}


Measured memory_bytes: 14336
n = int(input())
a = list()
for i in range(120):
	a.append(0)
for i in range(n):
	b, f, r, v = map(int, input().split())
	a[(b - 1) * 30 + (f - 1) * 10 + (r - 1)] += v
for i in range(4):
	if i >= 1:
		print("#" * 20)
	for j in range(3):
		for k in range(10):
			print(' ', end = '')
			print(a[i * 30 + j * 10 + k], end = '')
		print()


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

int main()
{

    string s;
    cin >> s;

    int cnt1 = 0;
    for (int i = 0; i < s.size(); i++)
    {
        if (i % 2 == 0 && s[i] != '0')
            cnt1++;
        if (i % 2 == 1 && s[i] != '1')
            cnt1++;
    }

    int cnt2 = 0;
    for (int i = 0; i < s.size(); i++)
    {
        if (i % 2 == 0 && s[i] != '1')
            cnt2++;
        if (i % 2 == 1 && s[i] != '0')
            cnt2++;
    }

    cout << min(cnt1, cnt2) << endl;
    return 0;
}


Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigDecimal;


public class Main {

	public static void main(String[] args) {
		try {
			BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
			String[] input = bf.readLine().split(" ");
			int a = Integer.parseInt(input[0]);
			int p = Integer.parseInt(input[1]);

			System.out.println(BigDecimal.valueOf((a * 3 + p) / 2, 0));
		} catch (Exception e) {
		}
	}
}


Measured memory_bytes: 22484