akhauriyash/Code-Regression huggingface dataset:
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <cassert>
#include <bitset>
#include <cmath>
#include <iomanip>

using namespace std;

using int64 = long long;

/////////////////////
// Code starts here//
/////////////////////
// Fenwick tree
template <typename T>
class Fenwick {
 public:
  vector<T> fenw;
  int n;

  Fenwick(int _n) : n(_n) {
    fenw.resize(n);
  }

  void modify(int x, T v) {
    while (x < n) {
      fenw[x] = max(fenw[x], v);
      x |= (x + 1);
    }
  }

  T get(int x) {
    T v{};
    while (x >= 0) {
      v = max(v, fenw[x]);  
      //v += fenw[x];
      x = (x & (x + 1)) - 1;
    }
    return v;
  }
};

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

    int N;
    cin >> N;

    Fenwick<int64> tree(N + 1);

    int64 res = 0;

    vector<int> H(N), A(N);
    for (auto & v : H)
        cin >> v;
    for (auto & v : A)
        cin >> v;

    for (int i = 0; i < N; i++) {
        int h = H[i], a = A[i];
        auto bst = tree.get(h - 1) + a;
        res = max(res, bst);
        tree.modify(h, bst);
    }

    cout << res << "\n";

    return 0;
}


Measured memory_bytes: 3456
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

typedef struct
{
  ll b;
  ll c;
} hoge;

int downll_hoge(const void *aa, const void *bb) { return ((hoge *)aa)->c < ((hoge *)bb)->c ? 1 : ((hoge *)aa)->c > ((hoge *)bb)->c ? -1 : 0; }

ll a[100005];
int main()
{
  ll n, m, ans = 0;
  scanf("%lld%lld", &n, &m);
  hoge fuga[m];
  for (ll i = 0; i < n; i++)
  {
    ll aaa;
    scanf("%lld", &aaa);
    a[i] = aaa;
    ans += aaa;
  }
  sortup(a, n);
  for (ll i = 0; i < m; i++)
  {
    ll b, c;
    scanf("%lld%lld", &b, &c);
    fuga[i].b = b, fuga[i].c = c;
  }
  qsort(fuga, m, sizeof(hoge), downll_hoge);
  ll j = 0;
  for (ll i = 0; i < n; i++)
  {
    if (!fuga[j].b)
    {
      i--;
      j++;
      continue;
    }
    if (j >= m)
      break;
    if (a[i] < fuga[j].c)
    {
      ans += (fuga[j].c - a[i]);
      fuga[j].b--;
      // printf("yayay: %lld\n", fuga[j].c - a[i]);
      // printf("yayay: %lld\n", fuga[j].c);
      // printf("yayay: %lld\n", a[i]);
      // printf("j: %lld\n", j);
      // puts("");
    }
    else
      break;
  }
  printf("%lld\n", ans);
  return 0;
}


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

vector<ll> a,f;
ll n;


ll binarySearch_latest(bool (*callback)(ll, ll), ll userQuery = 0) {
    ll ng = -1;
    ll ok = 10e12;
    while(abs(ok - ng) > 1){
        ll mid = (ok + ng) / 2;
        if (callback(mid, userQuery)){ ok = mid; } else { ng = mid; }
    }
    return ok;
}
bool judge1(ll arrValue, ll user){
    
    ll ans = 0;
    for (int i = 0; i < n; i++)
    {
        ll sa = a[i]*f[i] - arrValue;
        if (sa <= 0) continue;
        ll tmp = sa / f[i];
        if (sa % f[i] != 0) tmp++;
        ans += tmp;
    }
    
    return ans <= user;
}


int main()
{
    ll k;
    cin >> n >> k;
    rep(i, n){ int tmp; cin >> tmp; a.push_back(tmp);}
    rep(i, n){ int tmp; cin >> tmp; f.push_back(tmp);}

    sort(a.begin(), a.end(), greater<ll>());
    sort(f.begin(), f.end());
    
    cout << binarySearch_latest(judge1, k) << endl;

}


Measured memory_bytes: 4976
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>

using namespace std;

int main()
{
  int N;
  cin >> N;
  int M = 0, m = 1e9;
  
  int a;
  for(int i = 0; i < N; i++) {
    cin >> a;
    M = max(M, a);
    m = min(m, a);
  }
  
  cout << abs(M - m) << endl;
  
  return 0;
}


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

using namespace std;
typedef long long ll;

int main() {
    int a, b;
    cin >> a >> b;

    bool found = false;
    for (int i = 0; i <= 100000; i++) {
        if (i * 8 / 100 == a && i * 10 / 100 == b) {
            cout << i << endl;
            found = true;
            break;
        }
    }

    if (!found)cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;

int main(){
    int n;
    double v[50];
    cin >> n;
    rep(i,n) cin >> v[i];
    sort(v,v+n);
    for(int i=0;i<n-1;i++){
        v[i+1] = (v[i] + v[i+1])/2.0;
    }
    printf("%.10lf",v[n-1]);
    return 0;
}

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

const int maxl=1<<18;

int n,up;
int mx[maxl],sec[maxl];
int f[maxl];

inline void upd(int i,int x)
{
	if(x>mx[i])
		sec[i]=mx[i],mx[i]=x;
	else if(x>sec[i])
		sec[i]=x;
}

inline void prework()
{
	scanf("%d",&n);up=1<<n;
	for(int i=0;i<up;i++)
		scanf("%d",&mx[i]);
	for(int j=0;j<n;j++)
		for(int i=0;i<up;i++)
		if((i>>j)&1)
		{
			if(mx[i^(1<<j)])
				upd(i,mx[i^(1<<j)]);
			if(sec[i^(1<<j)])
				upd(i,sec[i^(1<<j)]);
		}
}

inline void mainwork()
{
	for(int i=1;i<up;i++)
	{	
		f[i]=max(f[i-1],mx[i]+sec[i]);
		printf("%d\n",f[i]);
	}
}

int main()
{
	prework();
	mainwork();
	return 0;
}

Measured memory_bytes: 6888
#include <iostream>
#include <math.h>
#include <set>
using namespace std;

bool isPrime(long long x){
	if(x == 2)
		return true;
	else if((x < 2) || (x % 2 == 0))
		return false;

	long long i = 3;
	while(i <= sqrt((double)x)){
		if(x % i == 0)
			return false;
		i += 2;
	}

	return true;
}

int main(){
	long long n, ans;
	set<long long> a;

	cin>>n;
	ans = n;

	while(n%2 == 0){
		n /= 2;
		a.insert(2);
	}

	for(long long i=3;i*i<=n;i+=2){
		if(isPrime(i)){
			while(n%i==0){
				n /= i;
				a.insert(i);
			}
		}
	}

	if(n!=1) a.insert(n);

	for(set<long long>::iterator it = a.begin();it != a.end();it++)
		ans = ans * (*it - 1) / *it;

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

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

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader inp = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Solver solver = new Solver();
        solver.solve(inp, out);
        out.close();
    }

    private static class Solver {

        int[] a;
        int min = Integer.MAX_VALUE;
        boolean[] dp;
        boolean[] set;

        private boolean win(int k) {
            Stack<Integer> solve = new Stack<>();
            solve.add(k);

            while (!solve.isEmpty()) {
                int k2 = solve.peek();
                if (set[k2]) {
                    solve.pop();
                    continue;
                }

                boolean win = true;
                boolean skip = false;
                for (int i: a) {
                    if (k2 - i >= 0 && !set[k2 - i]) {
                        skip = true;
                        solve.add(k2 - i);
                    } else if (k2 - i >= 0) {
                        win &= dp[k2 - i];
                    }
                }
                if (!skip) {
                    solve.pop();
                    set[k2] = true;
                    dp[k2] = !win;
                }
            }
            return dp[k];
        }

        private void solve(InputReader inp, PrintWriter out) {
            int n = inp.nextInt(), k = inp.nextInt();
            a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = inp.nextInt();
                min = Math.min(min, a[i]);
            }
            dp = new boolean[k+1];
            set = new boolean[k+1];
            out.print(win(k) ? "First" : "Second");
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}



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

int main() {
	int Q;
	cin >> Q;
	for (; Q > 0; Q--) {
		int c, a, n, ans = 0;
		cin >> c >> a >> n;

		for (; c >= 1 && a >= 1 && n >= 1; ans++) {
			c--; a--; n--;
		}

		for (; c >= 2 && a >= 1; ans++) {
			c -= 2; a--;
		}

		for (; c >= 3; ans++) {
			c -= 3;
		}
		cout << ans << endl;
	}
	return 0;
}

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

const int maxn=505;
const long long inf=1000000000000000;
long long n;
long long w[maxn][maxn]={0},p[maxn][maxn]={0},tot[maxn][maxn]={0},dp[maxn][maxn]={0};
long long ans=inf;

long long getsum(int a,int b,int c,int d){
	return p[b][d]-(c==0?0:p[b][c-1])-(a==0?0:p[a-1][d])+(a==0||c==0?0:p[a-1][c-1]);
}

signed main(){
	cin>>n;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			if(i!=j)  cin>>w[i][j];
			
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			p[i][j]=p[i][j-1]+p[i-1][j]-p[i-1][j-1]+w[i][j];
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			tot[i][j]=tot[i][j-1]+tot[i-1][j]-tot[i-1][j-1]+(i<j?w[i][j]:0);
			
	for(int i=1;i<=n;i++){
		dp[i][1]=tot[i][i]-tot[0][i]-tot[i][0]+tot[0][0];
		for(int j=2;j<=i;j++){
			dp[i][j]=inf;
			for(int k=1;k<=j-1;k++)
				dp[i][j]=min(dp[i][j],dp[j-1][k]+(tot[i][i]-tot[i][j-1]-tot[j-1][i]+tot[j-1][j-1])+getsum(j,i,0,k-1));
		}
	}
	
	for(int i=1;i<=n;i++)  ans=min(ans,dp[n][i]);
	cout<<ans;
	
	return 0;
}

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

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

    int n, m;
    cin >> n >> m;
    vector<vector<P>> input(n + 1);
    for(int i = 0; i < m; ++i){
        int p, y;
        cin >> p >> y;
        input[p].push_back(P(y, i));
    }
    for(int i = 1; i <= n; ++i) sort(input[i].begin(), input[i].end());
    vector<ll> ans(m, 0);
    for(int i = 1; i <= n; ++i){
        int sz = input[i].size();
        for(int j = 0; j < sz; ++j){
            int y = input[i][j].first, id = input[i][j].second;
            ans[id] += (ll)i * 1000000;
            ans[id] += j + 1;
        }
    }
    for(int i = 0; i < m; ++i){
        cout << setfill('0') << right << setw(12);
        cout << ans[i] << "\n";
    }
}

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

using ll = long long;


#define MOD 1000000007

int main(void) {
    string L;
    vector<pair<ll, ll>> dp;
    cin >> L;
    dp.resize(L.size() + 1);
    dp[0].second = 1;
    for(ll i = 0;i < L.size();i++) {
        if(L[i] == '1') {
            dp[i + 1].first += (dp[i].first + dp[i].second) % MOD;
            dp[i + 1].first += 2 * dp[i].first % MOD;
            dp[i + 1].second += 2 * dp[i].second % MOD;
        } else {
            dp[i + 1].first += 3 * dp[i].first % MOD;
            dp[i + 1].second += dp[i].second;
        }
        dp[i + 1].first %= MOD;
        dp[i + 1].second %= MOD;
    }
    cout << (dp[L.size()].first + dp[L.size()].second) % MOD << endl;
    return 0;
}


Measured memory_bytes: 2048
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <numeric>
#include <complex>
#define ll long long
using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	cout << n - k + 1 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define eb emplace_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"LINE %d: (%s) = ",__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

int d[MAXn];
int main(){
    IOS();
    int n,L;
    cin >> n >> L;
    int ans = -1;
    for (int i=0;i<n;++i) {
        cin >> d[i];
    }
    for (int i=0;i<n-1;++i) {
        if (d[i] + d[i+1] >= L) ans = i+1;
    }
    if (ans == -1) return cout << "Impossible" << endl,0;
    cout << "Possible" << endl;
    for (int i=1;i<ans;++i) cout << i << endl;
    for (int i=n-1;i>ans;--i) cout << i << endl;
    cout << ans << endl;
}


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

using namespace std;

int main() {
    int sx, sy, tx, ty;
    scanf("%d %d %d %d", &sx, &sy, &tx, &ty);

    for (int i=sx; i<tx; ++i)
        printf("R");

    for (int i=sy; i<ty; ++i)
        printf("U");

    for (int i=tx; i>sx; --i)
        printf("L");

    for (int i=ty; i>sy; --i)
        printf("D");

    printf("D");
    for (int i=sx; i<tx; ++i)
        printf("R");

    printf("RU");
    for (int i=sy; i<ty; ++i)
        printf("U");

    printf("LU");
    for (int i=tx; i>sx; --i)
        printf("L");

    printf("LD");
    for (int i=ty; i>sy; --i)
        printf("D");

    printf("R\n");
    return 0;
}


Measured memory_bytes: 128
#d  tree
#code自体はあっている。ただ、そもそもアルゴリズムが違う。
#下から調べていかないと最適でない。
#Right Answer. 
import sys
sys.setrecursionlimit(2 * 10 ** 5 + 10)

n,k =  [int(i) for i in input().split()]
a   =  [int(i)-1 for i in input().split()]

#this is directed tree so every node is not reached yet
#return the depth from its lowest bottom
def dfs(u):
    global cnt
    depth = 0 #default, this value is used when bottom
    
    for v in edges[u]:
        depth = max(depth, (dfs(v)+1)%k) #apply the maximum depth
        #because the edge was alerady cut, by the following procedure
    
    if depth==k-1 and u!=0 and a[u] != 0:
        cnt += 1
        
    return depth


cnt = 0
if a[0]!=0:
    cnt += 1

edges = [[] for _ in range(n)]
for i in range(1,n):
    pa = a[i]
    edges[a[i]].append(i)   

dfs(0)    
print(cnt)

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

int n, buf, emp = 0, p = 0;
int color[9] = {0,0,0,0,0,0,0,0,0};

int main(){
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> buf;
        if(buf < 400){
            color[0]++;
        }else if(buf < 800){
            color[1]++;
        }else if(buf < 1200){
            color[2]++;
        }else if(buf < 1600){
            color[3]++;
        }else if(buf < 2000){
            color[4]++;
        }else if(buf < 2400){
            color[5]++;
        }else if(buf < 2800){
            color[6]++;
        }else if(buf < 3200){
            color[7]++;
        }else{
            color[8]++;
        }
    }
    for(int j = 0; j < 8; j++){
        if(color[j] == 0){
            emp++;
        }
    }
    if(emp == 8) p = 1;
    if(color[8] == 0){
        cout << 8 - emp << " " << 8 - emp << endl;
    }else{
        cout << 8 - emp + p << " " << 8 - emp + color[8] << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
#include<map>
#include<vector>
#include<iomanip>
using namespace std;
typedef long long ll;
ll inf = 100000000;
ll v[205];
ll x[20000005];
ll a[10000005];
ll dp[10005][10005];
int dx[4] = { 1,-1,0,0 };
int dy[4] = { 0,0,1,-1 };
typedef pair<ll, ll> P;
double q[200005];
ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

int main() {
	ll n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a, a + m);
	for (int i = 0; i < m-1; i++) {
		x[i] = a[i + 1] - a[i];
	}
	sort(x, x + m-1);
	ll sum = 0;
	for (int i = 0; i <m-1-( n-1); i++) {
		sum += x[i];
	}
	cout << sum << endl;
	return 0;

}

Measured memory_bytes: 6400
#include<iostream>
using namespace std;
int main(){
  int n,x; cin >> n >> x;
  int min_m = 99999;
  for(int i = 0; i < n; i++){
    int m; cin >> m;
    x -= m;
    min_m = min(min_m,m);
  }
  int ans = n;
  if(x >=0)
    ans += x/ min_m;
  
  cout << ans ;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  double sum=0;
  vector<double> A(N);
  for(int i=0; i<N; i++){
    cin>>A.at(i);
    sum+=1/A.at(i);
  }
  printf("%.10f\n",1/sum);
  return 0;
}
  

Measured memory_bytes: 3820
//code by lynmisakura.wish to be accepted!
/****************************/
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
#include<set>
#include<bitset>
using namespace std;
/***************************/
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int, int> pi;
typedef vector<pair<int, int>> vpi;

const long long INF = 1LL << 55;

#define itn int
#define endl '\n'
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define dup(x,y) ((x) + (y) - 1)/(y)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(int i = 0;i < n;i++)
#define rep(i,n) for(int i = 0;i < n;i++)
#define rrep(i,n) for(int i = n - 1;i >= 0;i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }

#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

ll N,C;
ll d[31][31];
ll c[510][510];

int main(void) {
	cin >> N >> C;
	rep(i, C)rep(j, C)cin >> d[i][j];
	rep(i, N)rep(j, N)cin >> c[i][j];
	rep(i, N)rep(j, N)c[i][j]--;
	vector<vector<ll>> sumd(3, vector<ll>(C));
	for (ll modulo = 0; modulo < 3; modulo++)
	{
		for (ll color = 0; color < C; color++)
		{
			sumd[modulo][color] = 0;
		}
	}
	for (ll modulo = 0; modulo < 3; modulo++)
	{
		for (ll color = 0; color < C; color++)
		{
			for (ll i = 0; i < N; i++)
			{
				for (ll j = 0; j < N; j++)
				{
					if ((i + j) % 3 == modulo) {
						sumd[modulo][color] += d[c[i][j]][color];
					}
				}
			}
		}
	}
	
	ll ans = 100000000000;
	for (ll i = 0; i < C; i++)
	{
		for (ll j = 0; j < C; j++)
		{
			for (ll k = 0; k < C; k++)
			{ 
				//cout << i << " " << j << " " << k << " " << sumd[0][i] + sumd[1][j] + sumd[2][k] << endl;
				if (i != j and j != k and k != i) {
					mins(ans, sumd[0][i] + sumd[1][j] + sumd[2][k]);
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  int s;
  cin >> s;
  int a[1000005];
  a[0]=s;
  int i=0;
  while(1) {
    if(a[i]%2==0) {
      i++;
      a[i]=a[i-1]/2;
    }else {
      i++;
      a[i]=3*a[i-1]+1;
    }
    for (int k=0;k<i;k++) {
      if(a[i] == a[k]) {
        cout << i+1 << endl;
        return 0;
      }
    }
  }
}

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

// int main(int argc, char *argv[])
// {
//     string N;
//     cin >> N;
//     const int n = N.size();
//     vector<bool> dp(3000);
//     int res = 0;
//     for (int i = 0; i < n; i++) {
//         int d = N[i] - '0';
//         vector<bool> dp1(3000);
//         for (int j = 0; j < 2019; j++) {
//             dp1[(j * 10 + d) % 2019] = dp1[(j * 10 + d) % 2019] || dp[j];
//         }
//         dp1[d] = true;
//         if (dp1[0]) res++;
//         dp = dp1;
//     }
//     cout << res << endl;
//     return 0;
// }
#include <bits/stdc++.h>
using namespace std;

const int M = 2019;

int main(int argc, char *argv[])
{
    string N;
    cin >> N;
    const int n = N.size();
    vector<int> cnt(M);
    cnt[0]++;
    int suffix = 0;
    int p = 1;
    long long res = 0;
    for (int i = n - 1; i >= 0; i--) {
        int d = N[i] - '0';
        suffix = (suffix + d * p) % M;
        p = (p * 10) % M;
        res += cnt[suffix];
        cnt[suffix]++;
    }
    cout << res << endl;
    return 0;
}


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

ans = 0
for d in range(1, 11):
    for i in range(3 ** d):
        x = 0
        for j in range(d):
            x += [3, 5, 7][i%3] * 10 ** j
            i = i // 3
        if x > N:
            break
        if len(set(str(x))) == 3:
            ans += 1
print(ans)



Measured memory_bytes: 3060
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), k = scanner.nextInt();
			double sum = IntStream.rangeClosed(1, n).mapToDouble(i -> {
				double result = 1.0d;
				// iがkを超えるまでコインを振り続ける
				while (i < k) {
					i <<= 1;
					result /= 2.0d;
				}
				return result;
			}).sum();
			System.out.println(sum / n);
		}
	}
}


Measured memory_bytes: 36460
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			var cin = new Scanner2();
			long x = cin.Long();
			var isPrime = Eratosthenes(x * 10);

			for (long i = x; i < x * 10; i++) {
				if (isPrime[i]) {
					Console.WriteLine(i);
					return;
				}
			}
		}

		public static bool[] Eratosthenes(long n)
		{
			bool[] isPrimes = new bool[n + 1];
			for (int i = 2; i <= n; i++) {
				isPrimes[i] = true;
			}

			for (long i = 2; i <= n; i++) {
				if (isPrimes[i]) {
					for (long j = i + i; j <= n; j += i) {
						isPrimes[j] = false;
					}
				}
			}

			return isPrimes;
		}
	}

	public class Scanner2
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private readonly string filePath_;
		private string[] buf_;
		private int index_;
		Func<string> reader_;

		public Scanner2(string file = "")
		{
			if (string.IsNullOrWhiteSpace(file)) {
				reader_ = Console.ReadLine;
			} else {
				filePath_ = file;
				var fs = new StreamReader(file);
				reader_ = fs.ReadLine;
			}
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = reader_();
			while (st == "") {
				st = reader_();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int() => int.Parse(Next());
		public long Long() => long.Parse(Next());
		public double Double() => double.Parse(Next());

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}

		public void Save(string text)
		{
			if (string.IsNullOrWhiteSpace(filePath_)) {
				return;
			}

			File.WriteAllText(filePath_ + "_output.txt", text);
		}
	}
}

Measured memory_bytes: 13244
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;

const int N = 220000;
const int P = 1000000007;

vector<int> g[N];
int sz[N], p2[N], n, res, inv2 = (P + 1) / 2;

int dfs(int u, int p){
    sz[u] = 1;
    for(int v : g[u]){
        if (v != p) sz[u] += dfs(v, u);
    }
    if(p != 0)
        res = (res + (ll)(1 + P - p2[sz[u]]) * (1 + P - p2[n - sz[u]]) % P) % P;
    return sz[u];
}

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

    p2[0] = 1;
    for (int i = 1; i < N; ++i) p2[i] = (ll) p2[i - 1] * inv2 % P;
    
    cin >> n;
    res = (P - (int64_t)n * inv2 % P) % P;
    for (int i = 1, v, u; i < n; ++i){
        cin >> v >> u;
        g[v].push_back(u);
        g[u].push_back(v);
    }
    
    dfs(1, 0);
    
    cout << (ll)(res + (ll)(1 + P - p2[n]) % P) % P << endl;

    return 0;
}

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

int main(){
  string a,b;
  cin >> a;
  if(a == "A"){
    b = "T";
  }else if(a == "T"){
    b = "A";
  }else if(a == "C"){
    b = "G";
  }else{
    b= "C";
  }
  cout << b << endl;
  
  
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

const int N = 700;
bool g[N][N];
int visit[N];

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      g[i][j] = true;
    }
    g[i][i] = false;
  }
  while (m--) {
    int x, y;
    scanf("%d%d", &x, &y);
    --x; --y;
    g[x][y] = g[y][x] = false;
  }
  fill(visit, visit + n, -1);
  vector<int> Q;
  vector<ii> a;
  for (int i = 0; i < n; ++i) {
    if (visit[i] >= 0) continue;
    Q.clear();
    Q.push_back(i);
    visit[i] = 0;
    for (int k = 0; k < Q.size(); ++k) {
      int u = Q[k];
      for (int v = 0; v < n; ++v) {
        if (g[u][v]) {
          if (visit[v] < 0) {
            visit[v] = 1 - visit[u];
            Q.push_back(v);
          } else if (visit[v] + visit[u] != 1) {
            // trace(u, v, visit[u], visit[v]);
            puts("-1");
            return 0;
          }
        }
      }
    }
    int sum = 0;
    for (int k = 0; k < Q.size(); ++k) {
      sum += (visit[Q[k]] == 0);
    }
    // trace(sum, Q.size());
    a.push_back({sum, Q.size() - sum});
  }
  vector<int> d(n + 1), e(n + 1);
  d[0] = true;
  for (auto& it : a) {
    int x = it.first, y = it.second;
    for (int i = 0; i <= n; ++i) e[i] = false;
    for (int i = n; i >= 0; --i) {
      if (i >= x && d[i - x]) e[i] = true;
      if (i >= y && d[i - y]) e[i] = true;
    }
    swap(d, e);
  }
  int ret = INF;
  for (int i = 0; i <= n; ++i) {
    if (d[i]) {
      int j = n - i;
      ret = min(ret, i * (i - 1) / 2 + j * (j - 1) / 2);
    }
  }
  if (ret == INF) ret = -1;
  printf("%d\n", ret);
  return 0;
}


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

int main(){

  int N;
  std::cin>>N;
  std::vector<int> al(N);
  int sum=0;

  for(auto i =al.begin(); i != al.end(); i++ ){
    std::cin>>*i;
    sum += *i;
  }
  int l_max = *(max_element(al.cbegin(),al.cend()));
  if(2*l_max<sum){
    std::cout<<"Yes"<<std::endl;
  }else{
    std::cout<<"No"<<std::endl;
  }

  return 0;
}


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

using namespace std;

using ll = long long;

int solve(int N, int K, vector<int>& x, vector<int>& y, vector<char>& c, char tar) {
    vector< vector<int> > cnt(K + 1, vector<int>(K + 1, 0));
    for (int i = 0; i < N; i++) {
        int wx = x[i] / K, hy = y[i] / K;
        bool flag;
        if ((wx + hy) % 2 == 0) {
            flag = (c[i] == tar);
        } else {
            flag = (c[i] != tar);
        }
        int px = x[i] % K, py = y[i] % K;
        if (flag) {
            cnt[0][0]++;
            cnt[K - px][0]--;
            cnt[0][K - py]--;
            cnt[K - px][K - py]++;
            cnt[K - px][K - py]++;
            cnt[K][K - py]--;
            cnt[K - px][K]--;
            cnt[K][K]++;
        } else {
            cnt[0][0]--;
            cnt[K - px][0]++;
            cnt[0][K - py]++;
            cnt[K - px][K - py]--;
            cnt[K - px][K - py]--;
            cnt[K][K - py]++;
            cnt[K - px][K]++;
            cnt[K][K]--;
            cnt[0][0]++;
            cnt[0][K]--;
            cnt[K][0]--;
            cnt[K][K]++;          
        }
    }
    for (int i = 0; i <= K; i++) {
        for (int j = 0; j < K; j++) {
            cnt[i][j + 1] += cnt[i][j];
        }
    }

    for (int i = 0; i < K; i++) {
        for (int j = 0; j <= K; j++) {
            cnt[i + 1][j] += cnt[i][j];
        }
    }

    int res = 0;
    for (int i = 0; i < K; i++) {
        for (int j = 0; j < K; j++) {
            res = max(res, cnt[i][j]);
        }
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    vector<int> x(N), y(N);
    vector<char> c(N);
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> y[i] >> c[i];
    }
    cout << max(solve(N, K, x, y, c, 'B'), solve(N, K, x, y, c, 'W')) << endl;
    return 0;
}

Measured memory_bytes: 5136
l,r=map(int, input().split())
import sys
ans = 2018
for i in range(l,r):
    for j in range(i+1,r+1):
        a = (i*j) % 2019
        if a < ans:
            ans = a
        if ans == 0:
            print(ans)
            sys.exit()
print(ans)

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

using namespace std ;

int main()
{

    string a ;

    cin >> a ;

    int ans = 700 ;

    for(int i=0 ; i<3 ; i++)
    {
        if(a[i]=='o')ans = ans + 100 ;
    }

    cout << ans ;

}


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    int a[5];
    inc(i, 0, 5) cin >> a[i];
    int v[5] = {0, 1, 2, 3, 4};
    int mmin = 100000000;
    do{
        int ans = 0;
        inc(i, 0, 4){
            ans += (a[v[i]]+10-1)/10*10;
        }
        ans += a[v[4]];
        mmin = min(ans, mmin);
    }while(next_permutation(v, v+5));
    cout << mmin << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define put(x) cout << x << endl;
using namespace std;
int main()
{
    int k;
    string s;
    cin >> k >> s;
    if (s.size() <= k) {
        put(s);
    }
    else {
        cout << s.substr(0, k) << "..." << endl;
    }
    return 0;
}

Measured memory_bytes: 3608
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
ans = []

reg = 0
i = 1
while reg <= n:
    ans.append(i)
    reg += i
    i += 1
if reg - n > 0:
    ans.remove(reg-n)
for x in ans:
    print(x)

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

#define what_is(x) cout << #x << " is " << x << endl;
#define PI acos(-1)
#define hell 1000000007
#define HELL 998244353
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fix(n) cout << fixed << setprecision(n)
#define mset(a,n) memset(a,n,sizeof a)
#define rep(i,a,b) for (__typeof((b)) i=(a);i<(b);i++)
#define repp(i,a,b,p) for(__typeof((b)) i=(a);i<(b);i+=p)
#define ren(i,a,b) for(__typeof((a)) i=(a);i>=(b);i--)
#define renn(i,a,b,p) for(__typeof((a) i=(a);i>=(b);i-=p)
#define ADD(a,b,c) ((a)%c+(b)%c)%c
#define SUB(a,b,c) ((a)%c-(b)%c+c)%c
#define MUL(a,b,c) (((a)%c)*((b)%c))%c
#define lbd lower_bound
#define ubd upper_bound
#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define all(v) (v).begin(), (v).end()
#define sz(x) (ll)x.size()
// #define out(n) cout<<n<<" "
#define outl(n) cout<<n<<endl
#define bug(n) {outl(n);return;}
#define pii pair<int,int>
#define lim 9223372036854775805
#define ninf -9223372036854775802
#define M 1000000007
#define eps 1e-9
#define MAX 10
#define N 500001
#define db(a) for(auto it:a) {cout<<it<<" ";}cout<<endl;
ll prime[MAX];
ll fact[MAX];

const long long INF64 = 1e18;
ll vpow(ll a,ll b,ll p){
    if(b==0)
        return 1;
    if(b==1)
            return a;
    ll temp=vpow(a,b/2,p);
    temp*=temp;
    temp%=p;
    if(b%2==0)
        return temp;
    temp=temp*a;
    temp%=p;
    return temp;
}

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


ll inverseMod(ll a,ll b,ll p){
    if(b==0)
        return 1;
    ll temp=vpow(b,p-2,p);
    ll ans=temp*a;
    ans%=p;
    return ans;
}
void sieve()
{
    prime[0] = prime[1] = 1;
    for (ll i = 2; i < MAX; i++) {
        if (prime[i] == 0) {
            for (int j = i * 2; j < MAX; j += i) {
                if (prime[j] == 0) {
                    prime[j] = i;
                }
            }
            prime[i] = i;
        }
    }
}
ll max(ll a, ll b)
{
    return a>b?a:b;
}

void factorial(){
    fact[0]=1;
    fact[1]=1;
    rep(i,2,MAX){
        fact[i]=(fact[i-1]*i);
        // fact[i]%=M;
    }
}
ll rand(ll a,ll b){
    return a+rand()%(b-a+1);
}

void solve(ll ttt)
{
    ll n;
    cin>>n;
    ll i,j,count=0;
    for(i=1;i<=n;i++)
    {
        j=n/i;
        if(i*j==n)
        {
            count+=(j-1);
        }
        else{
            count+=(j);
        }
    }
    cout<<count<<endl;
}

int main(){
    io;
    // sieve();
    // factorial();
#ifndef ONLINE_JUDGE
    //
    //freopen("input1.txt","r",stdin);
    // freopen("output1.txt","w",stdout);
#endif
    ll t=1;
     //cin>>t;
    fix(12);
    rep(q,1,t+1){
         //cout<<"Case #"<<q<<": ";
         //cout<<"Test Case : "<<q<<endl;
         solve(q);
    }
    return 0;

}




Measured memory_bytes: 3664
import math

N = 1000001
 
spf = [*range(N)]
i = 2
while i * i < N:
  if spf[i] == i:
    for j in range(i * i, N, i):
      if spf[j] == j:
        spf[j] = i
  i += 1
  
r = 'pairwise'

input()
d = None
u = set()
for x in map(int, input().split()):
  d = math.gcd(d or x, x)
  s = set()
  while x > 1:
    p = spf[x]
    if p in u:
      r = 'setwise'
    s.add(p)
    x //= p
  u |= s
print((r, 'not')[d > 1], 'coprime')


Measured memory_bytes: 179372
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
#define ll long long int
#define lim 100010
#define mod 1e9+7
#define INF 1e9
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define ABS(x) ((x)>0?(x):-(x))
#define num 2019
int main(void){
	ll l,r;
	scanf("%lld%lld",&l,&r);
	ll ans=l*r%num;
	if(r-l>=2019){
		ans=0;
	}else{
		for(ll i=l;i<=r;i++){
			for(ll j=i+1;j<=r;j++){
				ans = MIN(ans,i*j%num);
			}
		}
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 128
N, M = map(int, input().split())
sc = [tuple(map(int, input().split())) for _ in range(M)]

for i in range(1000):
    t = str(i)
    if len(t) != N:
        continue
    ok = True
    for s, c in sc:
        if int(t[s - 1]) != c:
            ok = False
            break
    if ok:
        print(i)
        exit()
print(-1)


Measured memory_bytes: 3060
#include<bits//stdc++.h>
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    int d=abs(a-b),e=abs(b-c),f=abs(c-a);
    cout<<min({d+e,e+f,f+d})<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long int ll;

#define INF (1e9)

int N;

int main() {
    cin >> N;
    vector<int> h(N), dp(N);

    for (int i = 0; i < N; i++) {
        cin >> h[i];
    }

    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for (int i = 2; i < N; i++) {
        dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]),
                    dp[i - 1] + abs(h[i] - h[i - 1]));
    }

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


Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue> //C++
#include <string> //C++
#include <iostream> //C++
#include <vector> //C++
#include <algorithm> //C++
#include <map> //C++
using namespace std; //C++
#define rep(i, a, n) for (i = (a); i < (n); i++)
 
 
//C++で提出
 
 
 
// string s="AAA";    s.size() =3    (sのサイズ) ...1
// vector <int> a;    配列a(サイズは0) ...2
// a.push_back(10);   配列のサイズが一つ増えて一番後ろに10を代入 ...2
// A.pop_back();   最後の要素が消去される
// sort(A.begin(),A.end());   配列Aの最初の要素から最後の要素(/.)より前までを小さい順に並び替えてa[0]から代入していく...3
// reverse(A.begin(),A.end());   配列Aの最初の要素から最後の要素(/.)までを逆の順にしてa[0]から代入していく
// s.substr(3,2)   配列s[3]から2個の文字を抜き出した文字列 (s[3]とs[4]) ...4
// strcmp(s1,s2)  文字列が等しければ0を出力　s1>s2なら1 s1<s2なら-1を出力　C言語用なので配列は、s1[100]にする...5
 
 
 
 
/*
const int MAX = 100;
int main() {
	int N, M;
	string s, t;
	map<string, int> m;
	m["apple"] = 10;
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> s;
		m[s]++;
	}
	cin >> M;
	for (int i = 0; i < M; ++i) {
		cin >> t;
		m[t]--;
	}
	
	int max=0;
 
	for (map<string, int>::iterator i = m.begin(); i != m.end(); ++i) {
		if (max < (i->second)) max = i->second;
	}
 
	if (max < 0) cout << "0";
	else cout << max;
 
	return 0;
}
 
*/
 
int main() {
 
	int n,i;
	cin >> n;
	int x;
	int count=0;
	
	for (i = 0; i < n; i++) {
		cin >> x;
 
		if (x % 2 == 0) {
 
			if(x%3!=0 && x%5!=0) count++;
		}
		
	}
 
	if (count == 0) cout << "APPROVED";
	else cout << "DENIED";
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int dfs(vector<vector<int>> &F, vector<int> &seen, int n, int id) {
    seen[n] = id;
    int count = 1;
    for (auto f : F[n]) {
        if (seen[f]) continue;
        count += dfs(F, seen, f, id);
    }
    return count;
}

int main() {
    int N, M, K; cin >> N >> M >> K;
    vector<vector<int>> F(N), B(N);
    REP(i, 0, M) {
        int a, b; cin >> a >> b; a--; b--;
        F[a].push_back(b);
        F[b].push_back(a);
    }
    REP(i, 0, K) {
        int a, b; cin >> a >> b; a--; b--;
        B[a].push_back(b);
        B[b].push_back(a);
    }

    vector<int> seen(N); vector<int> groups; int id = 1;
    REP(i, 0, N) {
        if (seen[i]) continue;
        groups.push_back(dfs(F, seen, i, id++));
    }

    REP(i, 0, N) {
        int ans = groups[seen[i] - 1] - 1 - F[i].size();
        for (auto b : B[i]) if (seen[i] == seen[b]) ans--;
        cout << ans;
        if (i != N - 1) cout << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 13184
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n, m;
    while(cin >> n >> m, n){
        vector<int> t(m);
        vector<int> ans;
        vector<pair<int, int>> A(n*2, {-1, -1});
        for (auto &&i : t) scanf("%d", &i);
        int cur = 0;
        for (int _ = 0; _ < 30000; ++_) {
            for (int i = 0; i < n; ++i) {
                if(~A[i].first && A[i].second <= _){
                    ans.emplace_back(A[i].first);
                    A[i] = A[i+n];
                    A[i+n] = {-1, -1};
                }
                if(~A[i].first && A[i].second <= _){
                    ans.emplace_back(A[i].first);
                    A[i] = A[i+n];
                    A[i+n] = {-1, -1};
                }
            }
            while(cur < m && cur*10 <= _){
                int ok = 0;
                for (int i = 0; i < n; ++i) {
                    if(!~A[i].first){
                        ok = 1;
                        A[i] = {cur+1, _+t[cur]};
                        cur++;
                        break;
                    }
                }
                if(ok) continue;
                int to = -1, too = -1;
                for (int i = 0; i < n; ++i) {
                    if(!~A[i+n].first){
                        if(A[i].second >= _+t[cur]){
                            if(!~to || A[i].second < A[to].second) to = i;
                        }
                        else {
                            if(!~too || A[i].second > A[too].second) too = i;
                        }
                    }
                }
                if(~to){
                    A[to+n] = A[to];
                    A[to] = {cur+1, _+t[cur]};
                    cur++;
                }else if(~too){
                    A[too+n] = A[too];
                    A[too] = {cur+1, _+t[cur]};
                    cur++;
                } else break;
            }
        }
        for (int i = 0; i < ans.size(); ++i) {
            if(i) printf(" ");
            printf("%d", ans[i]);
        }
        puts("");
    }
    return 0;
}


Measured memory_bytes: 3144
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

#define INIT_DIR 90
#define PI 3.141592

using namespace std;


int main(){
	double dir = INIT_DIR * PI / 180;
	double moveX = 0,moveY = 0;
	int mx = 0,my = 0;
	string tmp;
	int tp = 0,tp2 = 0;

	char copy[8];

	while(cin >> tmp){
		strcpy(copy,tmp.c_str());
		tp = atoi(strtok(copy,","));
		tp2 = atoi(strtok(NULL,","));

		if(tp == 0 && tp2 == 0){
			break;
		}

		moveX += tp * cos(dir);
		moveY += tp * sin(dir);
		dir += tp2 * PI /180;
	}

	mx = (int)moveX * -1;
	my = (int)moveY;

	cout << mx << endl << my << endl;

	return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

typedef long long LL; 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

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

    LL N,A,B,C,D,E; cin >> N>>A >>B>>C>>D>>E;
    LL FA,FB,FC,FD,FE;
    LL minryu = A;

    FA = (N+A-1)/A;
    if(minryu<=B) FB = FA+1;
    else 
    {
        FB = 1+(N+B-1)/B;
        minryu = B;
    }

    if(minryu<=C) FC = FB+1;
    else 
    {
        minryu = C;
        FC = 2+(N+C-1)/C;
    }


    if(minryu<=D) FD = FC+1;
    else
    {
     FD = 3+(N+D-1)/D;
     minryu = D;
    }
    if(minryu<=E) FE = FD+1;
    else 
    {
        FE = 4+(N+E-1)/E;
        minryu = E;
    }
    cout << FE << endl;
}


Measured memory_bytes: 256