akhauriyash/Code-Regression huggingface dataset:
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.io.OutputStream;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.math.BigDecimal;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int N = in.nextInt();
            int[] A = new int[N];
            for(int i=0; i<N; i++){
                A[i] = in.nextInt();
            }
            int tmp = 0;
            int res = 0;
            for(int i=0; i<N; i++){
                tmp = A[tmp]-1;
                res ++;
                if(tmp==1){
                    out.println(res);
                    return;
                }
            }
            out.println(-1);
        }
    }


    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

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

        public 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());
        }

    }
}

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

#define int long long
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define vcopy(v1,v2) copy((v1).begin(), (v1).end(), back_inserter((v2)));
#define pb(n) push_back(n);

int x,t;

main() {
    cin >> x >> t;
    ct(max((long long)0,x-t))
}

Measured memory_bytes: 256
#include <stdio.h>
int main(int argc, char *argv[])
{
	int d;
	scanf("%d",&d);
	for(int i=d;i<1000;i++)
	{
		int a=i%10,b=(i%100)/10,c=i/100;
		if(a==b&&b==c)
		{
			printf("%d",i);
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>

using namespace std;
#define int long  long int
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

signed main()
{
	int N, A, B;
	cin >> N >> A >> B;
	if (A * N > B)cout << B;
	else cout << A * N;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
sunukes = set()
for i in range(1, n + 1):
    sunukes.add(i)

for _ in range(k):
    d = int(input())
    for i in list(map(int, input().split())):
        sunukes.discard(i)

print(len(sunukes))


Measured memory_bytes: 9176
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1
 
N,M=map(int,input().split())
 
class UnionFind:
    def __init__(self,n):
        self.par=[i for i in range(n)]
        self.siz=[1]*n
        
    def root(self,x):
        while self.par[x]!=x:
            self.par[x]=self.par[self.par[x]]
            x=self.par[x]
        return x
    
    def unite(self,x,y):
        x=self.root(x)
        y=self.root(y)
        if x==y:
            return False
        if self.siz[x]<self.siz[y]:
            x,y=y,x
        self.siz[x]+=self.siz[y]
        self.par[y]=x
        return True
    
    def is_same(self,x,y):
        return self.root(x)==self.root(y)
    
    def size(self,x):
        return self.siz[self.root(x)]
    
u=UnionFind(N)
 
for _ in range(M):
    a,b=map(int1,input().split())
    #print(a)
    u.unite(a,b)
    
#print(u.par)
#print(u.siz)

ans = 0
for aa in u.siz:
    ans=max(ans,aa)
print(ans)

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

int main(){
    int n;
    cin>>n;
    map<string,int> map1;
    string s;
    for (int i=0;i<n;i++){
        cin>>s;
        if (map1.find(s)!=map1.end()){
            map1[s]+=1;
        }
        else{
            map1[s]=1;
        }
    }
    vector<string> v;
    int max_c = 0;
    map<string,int>::iterator itr;
    for (itr=map1.begin();itr!=map1.end();itr++){
        if (itr->second > max_c) max_c=itr->second;
    }
    for (itr=map1.begin();itr!=map1.end();itr++){
        if (itr->second == max_c) v.push_back(itr->first);
    }
    sort (v.begin(),v.end());
    for (auto e:v){
        cout<<e<<endl;
    }
}

Measured memory_bytes: 26868
import Foundation
 
let nk = readLine()!.split(separator:" ").map{Int($0)!}
var sets: Set<Int> = []
for _ in 1...nk[1]{
  let c = readLine()!
  let A = readLine()!.split(separator:" ").map{Int($0)!}
  for i in A{
  sets.insert(i)
  }
}
print(nk[0] - sets.count)

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

#ifndef INT_MAX
#define INT_MAX 2147483647
#endif

#define rep(i,i0,n) for (int (i) = (i0); (i) < (n); ++(i))

using namespace std;

const int MAX_N = 262144;

class SegTree {
public:
    SegTree();
    void update(int i, int x);
    int query(int a, int b, int k, int l, int r);
private:
    int dat[MAX_N * 2];
    int n;
};

SegTree::SegTree() {
    n = MAX_N;
    rep(i, 0, 2 * n) {
        dat[i] = INT_MAX;
    }
}

void SegTree::update(int i, int x) {
    i += n - 1;
    dat[i] = x;
    while (0 < i) {
        i = (i - 1) / 2;
        dat[i] = min(dat[i * 2 + 1], dat[i * 2 + 2]);
    }
}

int SegTree::query(int a, int b, int k = 0, int l = 0, int r = MAX_N) {
    if (r <= a || b <= l) return INT_MAX;
    if (a <= l && r <= b) return dat[k];
    else {
        int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
        int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
        return min(vl, vr);
    }
}

int N = 0;
int Q = 0;
vector<int> L[202020];
int B[202020];
int cnt = 0;

int solve() {
    SegTree seg;
    int d = 0;

    rep(i, 0, N) {
        for(int r : L[i]) {
            seg.update(r, min(d, seg.query(i, r + 1)));
        }
        d = min(d + (B[i] ? 1 : -1), seg.query(i, i + 1));
    }

    return d + cnt;
}

int main(int argc, const char * argv[]) {
    int b, l, r;

    cin >> N;
    rep(i, 0, N) {
        cin >> b;
        B[i] = b;
        if (!b) ++cnt;
    }

    cin >> Q;
    rep(i, 0, Q) {
        cin >> l >> r;
        --l;
        --r;
        L[l].push_back(r);
    }

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 11776
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#define MOD 1000000007
#define mkp make_pair
typedef long long ll;
using namespace std;

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

  cout<<(a*3+p)/2<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<60;

const ll Mod=998244353;

int main(){
  int i,j;
  string s;
  cin>>s;
  int n=s.size();
  int r=0,b=0;
  int rban=0,bban=0;
  vector<int> rr(4020,inf),bb(4020,inf);
  for(i=0;i<n;i++){
    rr[i]=b;
    bb[i]=r;
    if(s[i]=='1') {
      r++;
      b++;
    }
    else if(s[i]=='0'){
      r+=2;
    }
    else {
      b+=2;
    }
  }

  VVI dp(r+1,VI(b+1,0));
  dp[0][0]=1;
  for(i=0;i<=r;i++){
    for(j=0;j<=b;j++){
      if(i==0&&j==0) continue;
      if(i-1>=0&&rr[i+j]>=j&&bb[i+j]>=i) dp[i][j]+=dp[i-1][j];
      if(j-1>=0&&bb[i+j]>=i&&rr[i+j]>=j) dp[i][j]+=dp[i][j-1];
      dp[i][j]%=Mod;
      //cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
    }
  }
  cout<<dp[r][b]<<endl;
  
}

Measured memory_bytes: 31616
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll INF = (ll)1e15;

// graph template
template<typename T>
class edge{
    public:
        int src, to; T cost;

        edge(int to, T cost): src(-1), to(to), cost(cost){}
        edge(int src, int to, T cost): src(src), to(to), cost(cost){}
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using AdjacencyList = vector<Edges<T>>;
template<typename T>
using Matrix = vector<vector<T>>;

template<typename T>
void warshall_floyd(Matrix<T> &g, T INF){
    for(int k = 0; k < (int)g.size(); k++){
        for(int i = 0; i < (int)g.size(); i++){
            for(int j = 0; j < (int)g.size(); j++){
                if(g[i][k] == INF or g[k][j] == INF) continue;
                g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
            }
        }
    }
}

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

    int r[8];
    for(int i = 0; i < R; i++){
        cin >> r[i];
        r[i]--;
    }

    Matrix<ll> mat(N, vector<ll>(N, INF));
    for(int i = 0; i < M; i++){
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        mat[a][b] = mat[b][a] = c;
    }

    warshall_floyd(mat, INF);  
    // for(int k = 0; k < N; k++){
    //     for(int i = 0; i < N; i++){
    //         for(int j = 0; j < N; j++){
    //             mat[i][j] = min(mat[i][j], mat[i][k] + mat[k][j]);
    //         }
    //     }
    // }

    sort(r, r + R);
    ll res = INF;
    do{
        ll dist = 0;
        for(int i = 0; i < R - 1; i++){
            dist += mat[r[i]][r[i+1]];
        }
        res = min(res, dist);
    }while(next_permutation(r, r + R));

    cout << res << '\n';

    return 0;
}

Measured memory_bytes: 512
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

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

	vector<int>v(2001);
	for (int i = 2; i*(i - 1) <= 2000; i++) {
		if (i*(i - 1)+1 < 1000)continue;
		bool flag = true;
		for (int j = 2; j < (i-1); j++) {
			if ((i-1)%j == 0)flag = false;
		}
		if (flag) {
			N = i * (i - 1) + 1;
			vector<vector<int>>ans(N);
			for (int j = 0; j < i; j++)ans[j].push_back(1);
			int cnt = i;
			for (int j = 2; j <= i; j++) {
				for (int k = 0; k < i - 1; k++) {
					ans[cnt + k].push_back(j);
				}
				cnt += i - 1;
			}
			for (int j = 2; j <= N; j++) {
				for (int k = 0; k < N; k++) {
					if (ans[k].size() < i) {
						ans[k].push_back(j);
						break;
					}
				}
			}
			cout << N << " " << i << endl;
			int dif = 0;
			int st = i;
			int dif_st = 0;
			for (int j = i+1; j <= N; j++) {
				int index = st;
				int dif_sum = dif_st;
				for (int k = 0; k < i - 1; k++) {
				//	cout << index + dif_sum << endl;
					ans[index+dif_sum].push_back(j);
					index += i - 1;
					dif_sum += dif;
					dif_sum %= i - 1;
				}
				dif_st++;
				if (dif_st == i - 1) {
					dif_st = 0;
					dif++;
				}
			}
			for (auto j : ans) {
				for (int k = 0; k < j.size(); k++) {
					if (k)cout << " ";
					cout << j[k];
				}
				cout << endl;
			}
			return 0;
		}
	}
	return 0;

}

Measured memory_bytes: 896
h,w,k=map(int,input().split())
Cho=[list(map(int,list(input()))) for _ in range(h)]
ans=10000000
for i in range(2**(h-1)):
	need=0
	seq=[]
	t=[]
	for j in range(h-1):
		t.append(j)
		if i&(1<<j):
			need+=1
			seq.append(t)
			t=[]
	seq.append(t+[h-1])
	f=1
	q=need+1
	cnt=[0]*q
	for x in range(w):
		cntp=[0]*q
		for i,g in enumerate(seq):
			cntg=0
			for y in g:
				cntg+=Cho[y][x]
				if cntg>k:
					f=0
					break
				cntp[i]+=Cho[y][x]
			if not f:
				break
		if not f:
			break
		for xx in range(q):
			cnt[xx]+=cntp[xx]
		if any(xxx>k for xxx in cnt):
			need+=1
			if need>ans:
				f=0
				break
			cnt=cntp
	if f:
		ans=min(ans,need)
print(ans)


Measured memory_bytes: 53208
#include <iostream>

using namespace std;

 
int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if (a <= b && b <= c)
        cout << a << " " << b << " " << c << endl;
    else if (a <= c && c <= b)
        cout << a << " " << c << " " << b << endl;
    else if (b <= a && a <= c)
        cout << b << " " << a << " " << c << endl;
    else if (c <= a && b <= c)
        cout << b << " " << c << " " << a << endl;
    else if (a <= b && c <= a)
        cout << c << " " << a << " " << b << endl;
     else 
        cout << c << " " << b << " " << a << endl;
    
        
}


Measured memory_bytes: 3116
// Date: 2020-03-27

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

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define IO freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout)
#define FIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for(int i = int(b); i >= int(a); --i)
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define D(x) cout << #x << " = " << x << endl;
#define SZ(x) ((int)x.size())
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 10;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {LL a=1; while(y){ if(y&1) a=a*x%MOD; x=x*x%MOD; y>>=1; } return a;}

int main() {
    FIO;
    int n; 
    cin >> n;
    LL x, y;
    cin >> x >> y;
    rep(i, 2, n) {
        LL nx, ny;
        cin >> nx >> ny;
        LL z = max((x+nx-1)/nx, (y+ny-1)/ny);
        x = nx * z, y = ny * z;
    }
    cout << x+y;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;

void Eratos(vector<bool> &IsPrime,ll n){
    rep(i,n) IsPrime[i]=1;
    IsPrime[0]=IsPrime[1]=0;
    for(ll i=2;i*i<n;i++){
        if(IsPrime[i]){
            for(ll j=i;i*j<n;j++){
                IsPrime[i*j]=0;
            }
        }
    }
}

int main(){
    ll n,rn=0;
    cin>>n;
    for(ll i=1;i*i<=n;i++) rn=i;
    rn++; 
    vector<bool> isp(rn);
    Eratos(isp,rn);
    ll ans=0,cpn=n;
    for(ll i=1;i<rn;i++){
        if(isp[i]){
            for(ll j=1;;j++){
                if(cpn%(ll)pow(i,j)==0){
                    cpn/=(ll)pow(i,j);
                    ans++;
                }
                else break;
            }
        }
    }
    if(cpn>=rn) ans++;
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

using ll = long long;

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

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a < b) {
      cout << "No" << endl;
      continue;
    }
    ll s = a % b;
    if (d < b) {
      cout << "No" << endl;
      continue;
    }
    if (d % b == 0) {
      if (s > c) {
        cout << "No" << endl;
      } else {
        cout << "Yes" << endl;
      }
      continue;
    }
    ll pl = d % b;
    ll g = gcd(pl, b);
    ll m = s + ((b - 1 - s) / g) * g;
    if (m > c)
      cout << "No" << endl;
    else {
      cout << "Yes" << endl;
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
#define ll long long
#define ld long double
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> A(N), C(N-1);
	int ans=0;
	for(int i=0; i<N; ++i) cin >> A[i];
	for(int i=0; i<N; ++i){
	    int B;
	    cin >> B;
	    ans += B;
	}
	for(int i=0; i<N-1; ++i) cin >> C[i];
	for(int i=0; i<N-1; ++i){
	    if(A[i]+1==A[i+1]) ans += C[A[i]-1];
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

typedef long long ll;

int main()
{
	std::ios::sync_with_stdio(false);
    cin.tie(0);
	ll n,m,ans = 0;
	cin >> n >> m;
	if(n*2<=m){
		ans += n;
		m -= n*2;
		n = 0;
		ans += m/4;
	}else{
		ans += m/2;
	}
	cout << ans << "\n"; 
    
	return 0;
}

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

using ll = long long;

//constant
const double EPS = 1e-10;
ll MOD = 1000000007;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

// vector
//template<typename T> vector<vector<T>> vv(ll H, ll W, T v) { return vector<vector<T>> vec(H, vector<T>(W, v)); }

// view vector
template<typename T> void view(T e) { std::cout << e << std::endl; }
template<typename T> void view(const std::vector<T>& v) { for (const auto& e : v) { std::cout << e << " "; } std::cout << std::endl; }
template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v : vv) { view(v); } }

// DP
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

// ***************************************

int main(void) {

	int N, W;
	cin >> N >> W;
	vector<pair<ll, ll>> vec(N);
	for (auto& v : vec) {
		cin >> v.first >> v.second;
	}

	vector<vector<ll>> dp(N + 1, vector<ll>(W + 1, 0));

	REP(i, N) {
		ll w = vec[i].first;
		ll v = vec[i].second;
		
		REP(j, W + 1) {
			chmax(dp[i + 1][j], dp[i][j]);
			if (j - w >= 0) {
				chmax(dp[i + 1][j], dp[i][j - w] + v);
			}
		}
	}

	cout << dp[N][W] << endl;

	return 0;
}

Measured memory_bytes: 80256
function main(input) {
  var N = input[0].split(" ")[0]-0;
  var K = input[0].split(" ")[1]-0;
  var list = input[1].split(" ").map(v=>v-0);
  var left = [];
  var right = [0];
  for(var i=0;i<N;i++){
    var v = list[i];
    if(v<0){
      left.push(v);
    }else if(v>0){
      right.push(v);
    }else{
      K--;
    }
  }
  left.push(0);
  left.reverse();
  var ans = null;
  for(var i=0;i<=K;i++){
    if(left[i] && right[K-i]){
      var a = 0;
      a+= Math.abs(left[i]*2) + Math.abs(right[K-i]);
      if(ans===null) ans = a;
      else ans = Math.min(a, ans);
    }
    if(left[K-i] && right[i]){
      var a = 0;
      a+= Math.abs(right[i]*2) + Math.abs(left[K-i]);
      if(ans===null) ans = a;
      else ans = Math.min(a, ans);
    }
  }

  if(K==0) console.log(0);
  else{
    if(right[K]){
      var a = 0;
      a+= Math.abs(right[K]);
      if(ans===null) ans = a;
      else ans = Math.min(a, ans);
    }
    if(left[K]){
      var a = 0;
      a+= Math.abs(left[K]);
      if(ans===null) ans = a;
      else ans = Math.min(a, ans);
    }
    console.log(ans);
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))


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

using namespace std;

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

	vector<int> math(N); // N個の数学の点数データ


	// 数学の点数データを受け取る
	for (int i = 0; i < N; i++) {
		cin >> math.at(i);
	}

	int ans = 0;

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

		G = math.at(i);
		if (G % 2 == 0) {
			if (G % 3 != 0 && G % 5 != 0) {
				ans++;
				break;
			}
			else
				continue;
		}
		else {
			continue;
		}
	}
	if (ans == 1) {
		cout << "DENIED" << endl;
	}
	else { cout << "APPROVED" << endl; }

}

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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
ll INF = LLONG_MAX;
ll MOD = 1e9 + 7;

using vc = vector<char>;
using vi = vector<int>;
using vll = vector<ll>;

vector<vll> dp;

vi NS;
vi MS;

ll recurse(int n, int m) {
    if (n == -1 || m == -1) return 1;

    if (dp[n][m] != -1) return dp[n][m];

    ll total = 0;
    if (NS[n] == MS[m]) 
        total += 2 * recurse(n-1, m-1);
    else 
        total += recurse(n-1, m-1);
    total %= MOD;
    total += recurse(n-1, m) - recurse(n-1, m-1);   total %= MOD;
    total += recurse(n, m-1) - recurse(n-1, m-1);   total %= MOD;
    dp[n][m] = total;
    return total;
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int N, M; cin >> N >> M;

    NS = vi (N);
    F0R(i, N) cin >> NS[i];

    MS = vi (M);
    F0R(i, M) cin >> MS[i];

    dp = vector<vll> (N, vll (M, -1));

    cout << (MOD + recurse(N-1, M-1)) % MOD << endl;
}

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

int main() {
    int n;
    cin>>n;
    vector<int> arr(n);
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    vector<int> dp(n,INT_MAX);
    dp[0]=0;
    for(int i=0;i<n;i++)
    {
        if(i+1<n && dp[i+1]> (dp[i]+abs(arr[i]-arr[i+1])))
            dp[i+1] = dp[i]+abs(arr[i]-arr[i+1]);
        
        if(i+2<n && dp[i+2]> (dp[i]+abs(arr[i]-arr[i+2])))
            dp[i+2] = dp[i]+abs(arr[i]-arr[i+2]);
    }
    // for(int i=0;i<n;i++)
    //     cout<<dp[i]<<endl;
    cout<<dp[n-1];
    
	return 0;
}


Measured memory_bytes: 1024
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }
void uniq(VI& es) { sort(ALL(es)); es.erase(unique(ALL(es)), es.end()); }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,Q,B,C,A;
	string s;
	while(cin>>N) {
		ll mx = 100001;
		VI h(mx);
		ll sum=0;
		REP(i, N) {
			cin>>A;
			sum+=A;
			h[A]++;
		}
		cin>>Q;
		REP(i, Q) {
			cin>>B>>C;
			sum += h[B]*(C-B);
			h[C]+=h[B];
			h[B]=0;
			cout<<sum<<endl;
		}
	}
	
	return 0;
}


Measured memory_bytes: 3672
/*
*
* author: ian macleod
*
*/

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef vector<long long int> vll;

#define IO                 \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
 
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fo(i,a,b) for(ll i = a; i<=b;i+=1)
#define rf(i,a,b) for(ll i=a;i>=b;i--)

ll power(ll x, ll y) {
    ll res = 1;     // Initialize result
    x = x ;
    if (y==0)return 1;
    if(x==0)return 0;
    while (y > 0) {
        if (y & 1)
            res = (res*x);
        y = y>>1; // y = y/2
        x = (x*x);  // Change x to x^2
    }
    return res;
}


void solve() {
    
    ll n, a;
    cin >> n;
    a = n % 10;
    if (a == 3) {
        cout << "bon" << endl;
    }
    else if (a == 2 || a == 4 || a == 5 || a == 7 || a == 9) {
        cout << "hon" << endl;
    }
    else {
        cout << "pon" << endl;
    }
    
    return ;
}



int main() {
    solve();
}



Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
const double PI = acos(-1);

int main(){
	int n;cin>>n;
    vl t(n),a(n);
    rep(i,n)cin>>t[i];
    rep(i,n)cin>>a[i];
    reverse(been(a));
    if(t[n-1]!=a[n-1]){
        cout<<0<<endl;
        return 0;
    }
    rep(i,n-1){
        if(t[i]>t[i+1]){
            cout<<0<<endl;
            return 0;
        }
        if(a[i]>a[i+1]){
            cout<<0<<endl;
            return 0;
        }
    }
    vl sum(n,INF);
    vector<bool>bt(n,false),at(n,false);
    bt[0]=true;at[0]=true;
    rep(i,n){
        if(i==0)continue;
        if(t[i-1]!=t[i])bt[i]=true;
        if(a[i-1]!=a[i])at[i]=true;
    }
    reverse(been(a));reverse(been(at));
    rep(i,n){
        sum[i]=min(a[i],t[i]);
        if(bt[i]&&sum[i]!=t[i]){
            cout<<0<<endl;
            return 0;
        }
        if(at[i]&&sum[i]!=a[i]){
            cout<<0<<endl;
            return 0;
        }
    }
    
    ll ans =1;
    rep(i,n){
        if(!at[i]&&!bt[i])ans=ans*sum[i]%mod;
    }
    cout<<ans<<endl;;
}

Measured memory_bytes: 5628
import math
n=int(input())
x=[]
sum=0
for i in range(n):
    x.append(list(map(int,input().split())))
for i in range(n):
    for s in range(i+1,n):
        sum+=math.sqrt((x[i][0]-x[s][0])**2+(x[i][1]-x[s][1])**2)
sum=sum*2/n
print(sum)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll x,y,i,p,q,r,tmp,ans;
    cin>>x>>y;
    p=(2*x)-1;
    q=(2*y)-1;
    r=x+y;
    tmp=max(p,q);
    ans=max(tmp,r);
       cout<<ans<<endl;



    return 0;
}




Measured memory_bytes: 3608
#include <iostream>
using namespace std;
int main(void){
    int k, t, a, amax = 0;
    cin >> k >> t;
    for (int i = 0; i < t; i++) {
        cin >> a;
        amax = max(amax, a);
    }
    
    cout << max(0, amax - (k - amax) - 1) << endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
using LP=pair<ll,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353;



int main() {
    int A,B,C;
    cin>>A>>B>>C;
    int ans;
    if(A==B)ans=C;
    if(B==C)ans=A;
    if(C==A)ans=B;
    cout<<ans<<endl;
}

Measured memory_bytes: 3604
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

typedef long long ll;

const ll MOD = 1e9 + 7;

int main() {
    ll A, B, K;
    cin >> A >> B >> K;
    if (K <= A) {
        cout << A - K << " " << B << endl;
    } else if (K <= A + B) {
        cout << 0 << " " << A + B - K << endl;
    } else {
        cout << "0 0" << endl;
    }
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (x, y) = readLine()!!.split(" ").map { it.toInt() }
    (y until x+y).toList().let{ println(it.sum() + (it.map{Math.abs(it)}.min()!! * if(it.sum() >= 0) -1 else 1))}
}

Measured memory_bytes: 37980
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int n;
    cin >> n;

    vector<ll> a(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        a[i] += a[i - 1];
    }

    sort(a.begin(), a.end());

    map<ll, int> mp;
    for (int i = 0; i <= n; i++) {
        mp[a[i]]++;
    }

    ll r = 0;
    for (const auto& o : mp) {
        ll k = o.second;
        r += k * (k - 1) / 2;
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 14336
s = []
F = {
    '+': lambda: s.append(s.pop() + s.pop()),
    '-': lambda: s.append(-s.pop() + s.pop()),
    '*': lambda: s.append(s.pop() * s.pop())
}

for op in input().split():
    if op in F:
        F[op]()
    else:
        s.append(int(op))

print(s.pop())

Measured memory_bytes: 7732
S = input()
T = input()

num = 10**10

for i in range(len(S)-len(T)+1):
    U = S[i:(i+len(T))]
    tmp = 0
    for j in range(len(T)):
        if(T[j] != U[j]):
            tmp += 1
    num = min(num, tmp)
    
print(num)

Measured memory_bytes: 8952
N = int(input())
Ws = [input() for i in range(N)]

ret = "Yes"
if len(Ws) != len(list(set(Ws))):
    ret = "No"
    
for i in range(N-1):
    if Ws[i][-1] != Ws[i+1][0]:
        ret = "No"
    
    
print (ret)

Measured memory_bytes: 3060
#include <stdio.h>

int main(void){
int mp[105][105]={0};
int n=0;
scanf("%d",&n);
int i=0,j=0;;
for(i=0;i<n;i++){
int u=0;
int k=0;
scanf("%d%d",&u,&k);
int p=0;
int m=0;
for(p=0;p<k;p++){
scanf("%d",&m);
mp[u-1][m-1]=1;
}
}
for(i=0;i<n;i++){
printf("%d",mp[i][0]);
for(j=1;j<n;j++){
printf("\x0020%d",mp[i][j]);
}
printf("\n");
}
return 0;
}

Measured memory_bytes: 656
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=400005;
struct node
{
	int x,y;
	long long z;
}e[N*20];
int n,w[N],head[N],adj[N],nxt[N],len[N],size[N],root,cnt,i,j,k,mx[N],p[N],pt,h;
bool v[N];
long long ans,g,u[N];
int find(int x)
{
	return !p[x]?x:p[x]=find(p[x]);
}
bool cmp(node a,node b)
{
	return a.z<b.z;
}
void Dfs(int x,int dad,int sz)
{
	size[x]=1;
	mx[x]=0;
	for(int y=head[x];y;y=nxt[y])
		if(adj[y]!=dad&&!v[adj[y]])
		{
			Dfs(adj[y],x,sz);
			size[x]+=size[adj[y]];
			mx[x]=max(mx[x],size[adj[y]]);
		}
	mx[x]=max(mx[x],sz-size[x]);
	if(!root||mx[x]<mx[root])
		root=x;
}
void work(int x,int dad,long long d)
{
	u[x]=d+w[x];
	if(!pt||u[x]<u[pt])
		pt=x;
	for(int y=head[x];y;y=nxt[y])
		if(adj[y]!=dad&&!v[adj[y]])
			work(adj[y],x,d+len[y]);
}
void dzx(int x,int dad)
{
	e[++cnt]=(node){x,pt,u[x]+u[pt]};
	for(int y=head[x];y;y=nxt[y])
		if(adj[y]!=dad&&!v[adj[y]])
			dzx(adj[y],x);
}
void dfs(int x,int sz)
{
	root=0;
	Dfs(x,-1,sz);
	v[root]=true;
	pt=0;
	work(root,-1,0);
	dzx(root,-1);
	for(int y=head[root];y;y=nxt[y])
		if(!v[adj[y]])
			dfs(adj[y],size[adj[y]]);
}
int main()
{
	scanf("%d",&n);
	for(i=1;i<=n;++i)
		scanf("%d",w+i);
	for(i=1;i<n;++i)
	{
		scanf("%d%d%d",&j,&k,&len[i*2]);
		adj[i*2-1]=k;
		nxt[i*2-1]=head[j];
		head[j]=i*2-1;
		adj[i*2]=j;
		nxt[i*2]=head[k];
		head[k]=i*2;
		len[i*2-1]=len[i*2];
	}
	dfs(1,n);
	sort(e+1,e+1+cnt,cmp);
	//for(i=1;i<=cnt;++i)
		//printf("%d %d %lld\n",e[i].x,e[i].y,e[i].z);
	//return 0;
	for(i=1;i<=cnt;++i)
		if(find(e[i].x)!=find(e[i].y))
		{
			p[find(e[i].x)]=find(e[i].y);
			ans+=e[i].z;
		}
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 78720
l,r = map(int,input().split())
MOD = 2019

nl = l%MOD
diff = r-l
li1 = []
li2 = []

if diff>2018:
  print(0)
else:
  for i in range(diff+1):
    li1.append(nl+i)
  for j in range(len(li1)):
    for k in range(j+1,len(li1)):
      li2.append(li1[j]*li1[k]%MOD)
  print(min(li2))

Measured memory_bytes: 75440
#include <bits/stdc++.h>
using namespace std;
#define all(c) c.begin(),c.end()
#define init(c) memset(c,0,sizeof c)
#define S second
#define F first
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int N=20000005;
int n,k,x,t,a,b,m;
string s;
vi v;
 
void solve(){
	cin >> x >> n;
	map<int,bool>mp;
	for(int i =0;i<n;i++){
		cin >> m;
		mp[m]=1;
	}	
	int dif = 1e9;
	int low = x;
	int ans = 0;
	while(low>=-1){
		if(mp[low]){low--;continue;}
		if(dif>x-low){
			ans = low;
			dif = x-low;
			break;
		}
	}
	int hi = x;
	while(hi<=101){
		if(mp[hi]){hi++;continue;}
		if(dif>hi-x){
			ans = hi;
					
		}
		break;
	}	
	cout << ans;
 
}
 
int main(){

	t=1;
	while(t--){
		solve();
	}
	
	return 0;
}

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

#define REP(i,n) for(int i = 0; i < (n); ++i)
#define REP1(i,n) for(int i = 1; i <= (n); ++i)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; --i)
#define ALL(a) begin(a), end(a)
#define MP(a,b) make_pair((a), (b))
#define ROUNDUP(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))
#define X first
#define Y second
#define DEBUG(a) cout << #a << ": " << a << "\n"
// #define DEBUG(a) {}

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

constexpr int MOD = 1e9 + 7;
constexpr int INF = 1e9 + 1;
constexpr ll LLINF = 4 * 1e18 + 1;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

template<typename T>
T debug(T x) {
	DEBUG(x);
	return x;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int x;
        cin>>x;
        cout<<48-x<<"\n";
	return 0;
}


Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d %d", $K, $N);
$A = array_map('intval', explode(' ', trim(fgets(STDIN))));
$A[] = $A[0] + $K;
$d = [];
for ($i = 1; $i <= $N; $i++) {
    $d[] = $A[$i] - $A[$i - 1];
}
printf("%d", $K - max($d));


Measured memory_bytes: 27120
using System;

namespace ConsoleApp2
{
    public class Program
    {
        static void Main(string[] args)
        {
            int x, y, z;

            var buf = Console.ReadLine().Split(' ');
            x = int.Parse(buf[2]);
            y = int.Parse(buf[0]);
            z = int.Parse(buf[1]);

            Console.WriteLine($"{x} {y} {z}");
        }
    }
}


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

int main(){

    int n,k;
    cin >> n >> k;

    cout << setprecision(12);

    vector<double> p(n);

    rep(i,n){
        double t;
        cin >> t;
        p[i]=(double)t*(t+1)/2.*(1/t);
    }
    rep(i,n-1){
        p[i+1]+=p[i];
    }

    // rep(i,n){
    //     cout << p[i] <<" ";
    // }cout << endl;

    double ma=p[k-1];

    rep(i,n-k){
        ma=max(ma,p[i+k]-p[i]);
    }

    cout << ma << endl;

    return 0;
}

Measured memory_bytes: 1792
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

from itertools import permutations
from math import factorial, hypot

#############
# Main Code #
#############

N = getN()
A = getList()

cnt4 = 0
cnt2 = 0
for i in A:
    if i % 4 == 0:
        cnt4 += 1
    elif i % 2 == 0:
        cnt2 += 1

if cnt4 * 2 + 1 >= N:
    print('Yes')
else:
    left = N - cnt4 * 2
    if cnt2 >= left:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 16256
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
int a[100100],b[100100],c[100100];
lint lo[100100],hi[100100];
int main()
{
	int n,it=0;cin>>n;
	rep(i,n) cin>>a[i];rep(i,n) cin>>b[i];rep(i,n) cin>>c[i];
	sort(a,a+n);sort(b,b+n);sort(c,c+n);
	rep(i,n){
		while(it<n && a[it]<b[i]) it++;
		lo[i]=it;
	}
	it=n-1;
	for(int i=n-1;i>=0;i--){
		while(it>=0 && c[it]>b[i]) it--;
		hi[i]=n-it-1;
	}
	lint out=0;
	rep(i,n) out+=lo[i]*hi[i];
	cout<<out<<endl;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<ll, ll>
#define PP pair<P,P>
using namespace std;

int main(){
    ll n,m; cin >> n >> m;
    vector<P> is(m);
    rep(i,m) cin >> is[i].first >> is[i].second;
    vector<int> id(n);
    rep(i,n) id[i]=i;
    vector<ll> sz(n,1);
    vector<ll> ans(m);
    ans[m-1]=((n-1)*n)/2;

    for(int i=m-1; i>=1; i--){
        int f=is[i].first;
        int s=is[i].second;
        f--; s--;
        int fp=f;
        int sp=s;
        while(fp!=id[fp]){
            fp=id[fp];
            //cout << fp << ' ' << id[f] << ' ' << "fff" << endl;
        }
        while(sp!=id[sp]){
            sp=id[sp];
        }
        //cout << fp << ' ' << sp << endl;
        if(fp==sp){
            ans[i-1]=ans[i];
            continue;
        }
        ll tmp=sz[fp]*sz[sp];
        ans[i-1]=ans[i]-tmp;
        int mip=min(fp,sp);
        int map=max(fp,sp);
        sz[mip]=sz[fp]+sz[sp];
        id[map]=mip;
    }
    rep(i,m) cout << ans[i] << endl;
return 0;
}



Measured memory_bytes: 4864
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <bitset>
#include <cmath>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define FI first
#define SE second
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PB push_back
#define PQ priority_queue<int>
#define PGQ priority_queue<int,vector<int>,greater<int> >
#define VE vector<int>
#define VP vector<PA>
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define MOD 1000000007
#define INF 1000000007
#define PI 3.141592653589793238462643383279
using namespace std;
//
int main(){
  long long Q,H,S,D,N;
  cin>>Q>>H>>S>>D>>N;
  bool W=true,X=true,Y=true,Z=true;
  if(Q*2<=H){
    X=false;
  }
  if(Q*4<=S){
    Y=false;
  }
  if(Q*8<=D){
    Z=false;
  }
  if(H*2<=S){
    Y=false;
  }
  if(H*4<=D){
    Z=false;
  }
  if(S*2<=D){
    Z=false;
  }
  long long sum=0;
  N*=4;
  if(Z){
    sum+=N/8*D;
    N%=8;
  }
  if(Y){
    sum+=N/4*S;
    N%=4;
  }
  if(X){
    sum+=N/2*H;
    N%=2;
  }
  if(W){
    sum+=N*Q;
  }
  cout<<sum<<endl;
  return 0;
}


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

int main() {
  	int n;
  	cin >> n;
  	vector<int> d(n);
  	for (int i=0; i<n; i++) {
      	cin >> d[i];
    }
  
  	sort(d.begin(), d.end());
  	if (d[n/2]==d[n/2-1]) {
    	cout << 0 << endl;
      	return 0;
    }
  	cout << d[n/2]-d[n/2-1] << endl;
  	return 0;
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC155A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] ABC = Console.ReadLine().Split(' ');
            if (ABC[0] == ABC[1] & ABC[0] != ABC[2])
            {
                Console.WriteLine("Yes");
            }
            else if (ABC[0] == ABC[2] & ABC[0] != ABC[1])
            {
                Console.WriteLine("Yes");
            }
            else if (ABC[1] == ABC[2] & ABC[0] != ABC[1])
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 25880
// AtCoder template
// sabaより胡蝶しのぶさんの方が可愛いのではないか？
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n; ++i)

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

    string s,t; cin >> s >> t;
    int n = s.size();
    map<char,char> m1,m2;
    rep(i,n){
        if(!m1[s[i]]) m1[s[i]] = t[i];
        else if(m1[s[i]] != t[i]){
            cout << "No" << endl;
            return 0;
        }
        if(!m2[t[i]]) m2[t[i]] = s[i];
        else if(m2[t[i]] != s[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 916
def main():
    import sys
    input = sys.stdin.readline

    import numpy as np

    N, W = map(int, input().split())
    dp = np.zeros(W + 1, dtype = np.int64)

    for _ in range(N):
        w, v = map(int, input().split())
        dp[w:] = np.maximum(dp[w:], dp[:W - w + 1] + v)
        
        # for i in range(W, w - 1, -1):
            # dp[i] = max(dp[i], dp[i - w] + v)

    print (dp[W])

if __name__ == '__main__':
    main()

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

int main(){
    string S;
    cin >> S;
    rep(i,1<<3){
        int res = S[0] - '0';
        rep(bits,3){
            if(i&(1<<bits)){
                res+=S[bits+1] - '0';
            }else{
                res-=S[bits+1] - '0';
            }
        }
        if(res == 7){
            printf("%c",S[0]);
            rep(j,3){
                if(i&(1<<j))printf("+%c",S[j+1]);
                else printf("-%c",S[j+1]);
            }
            printf("=7\n");
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <functional>
#include <numeric>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void) {
	int A, B, C, K;
	cin >> A >> B >> C >> K;
	for (int i = 0; i < K; i++) {
		if (B <= A) B = B * 2;
		else C = C * 2;
	}
	int ans = 0;
	if (B <= A) ans++;
	if (C <= B) ans++;
	if (ans > 0) cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 3612
class SegTree
    def update(k); @d[k] = @op.call(@d[2 * k], @d[2 * k + 1]); end

    def initialize(v, e, &op)
        @n = v.size
        @log = (@n - 1).bit_length
        @size = 1 << @log
        @op = op

        @d = Array.new(2 * @size, e) # vector

        @n.times{|i| @d[@size + i] = v[i]}
        (@size - 1).downto(1) {|i| update(i)}
    end

    def set(pos, x)
        pos += @size
        @d[pos] = x
        1.upto(@log) {|i| update(pos >> i)}
    end

    def get(pos); @d[pos + @size]; end

    def prod(l, r)
        sml = smr = @d[0]
        l += @size
        r += @size

        while l < r
            (sml = @op.call(sml, @d[l]); l += 1) if l[0] == 1
            smr = @op.call(@d[r -= 1], smr) if r[0] == 1
            l >>= 1
            r >>= 1
        end
        @op.call(sml, smr)
    end

    def all_prod; @d[1]; end

    def max_right(l, &f)
        return @n if l == @n
        l += @size
        sm = @d[0]

        loop do
            l >>= 1 while l[0] == 0
            x = @op.call(sm, @d[l])
            if !f.call(x)
                while l < @size
                    l <<= 1
                    x = @op.call(sm, @d[l])
                    if f.call(x)
                        sm = x
                        l += 1
                    end
                end
                return l - @size
            end
            
            sm = x
            l += 1
            break if (l & -l) == l
        end

        @n
    end
    
    def min_left(r, &f)
        return 0 if r == 0
        r += @size
        sm = @d[0]

        loop do
            r -= 1
            r >>= 1 while r > 1 && r[0] == 1
            x = @op.call(@d[r], sm)
            if !f.call(x)
                while r < @size
                    r = 2 * r + 1
                    x = @op.call(@d[r], sm)
                    if f.call(x)
                        sm = x
                        r -= 1
                    end
                end
                return r + 1 - @size
            end
            sm = x
            break if (r & -r) == r
        end

        0
    end
end

n, q = gets.split.map(&:to_i)

a = Array.new(n, 0)
a[-1] = n - 1
row = SegTree.new(a, 0) {|s1, s2| s1 > s2 ? s1 : s2}
col = SegTree.new(a, 0) {|s1, s2| s1 > s2 ? s1 : s2}

ans = (n - 2) * (n - 2)

q.times do
    t, x = gets.split.map(&:to_i)
    x -= 1

    if t == 1
        r = row.max_right(0) {|s| s < x}
        ans -= r - 1
        col.set(x, r)
    else
        r = col.max_right(0) {|s| s < x}
        ans -= r - 1
        row.set(x, r)
    end
end

p ans


Measured memory_bytes: 24040