akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner scanner = new Scanner(System.in);

		int N = scanner.nextInt();
		int K = scanner.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = scanner.nextInt();
		}

		quick_sort(A, 0, N - 1);
		
		int kn = 1;
		int[] knc = new int[N];
		knc[0] = 1;
		for (int i = 1; i < N; i++) {
			if (A[i] == A[i - 1]) {
				knc[kn-1]++;
			} else {
				kn++;
				knc[kn-1] = 1;
			}
		}

		int tar = kn - K;
		if (tar <= 0) {
			System.out.println(0);
			return;
		}

		quick_sort(knc, 0, kn - 1);
		int sum = 0;
		int i = 0;
		while (tar > 0) {
			sum += knc[i];
			i++;
			tar--;
		}

		System.out.println(sum);

	}


	public static void quick_sort(int[] d, int left, int right) {
		if (left >= right) {
			return;
		}
		int p = d[(left + right) / 2];
		int l = left, r = right, tmp;
		while (l <= r) {
			while (d[l] < p) {
				l++;
			}
			while (d[r] > p) {
				r--;
			}
			if (l <= r) {
				tmp = d[l];
				d[l] = d[r];
				d[r] = tmp;
				l++;
				r--;
			}
		}
		quick_sort(d, left, r); // ピボットより左側をクイックソート
		quick_sort(d, l, right); // ピボットより右側をクイックソート
	}

}


Measured memory_bytes: 85436
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        String str = sc.next();
        char array[] = str.toCharArray();
        
        int[] ans = new int[100005];
        
        int idx = n;
        int k = 0;
        while (true) {
            boolean ok = false;
            for (int j = idx - m; j < idx; j++) {
                if (j < 0) continue;
                if (array[j] == '0') {
                    ans[k] = idx - j;
                    idx = j;
                    k++;
                    ok = true;
                    break;
                }
            }
            
            if (idx == 0) break;
            
            if (!ok) {
                System.out.println(-1);
                return;
            }
        }
        
        for (int i = k - 1; i >= 0; i--) {
            System.out.print(ans[i]);
            
            if (i != 0) {
                System.out.print(" ");
            } else {
                System.out.println();
            }
        }
    }
}


Measured memory_bytes: 38628
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define debug(x) cout << #x << " = " << x << endl;
#define debret(x) cout << #x << " = " << x << endl; return 0;

using namespace std;

int main(void){

    int N;
    int K;
    cin >> N >> K;

    int board[N];
    REP(i,N){
        cin >> board[i];
    }
    long long blackImos[N+1];
    long long idealScore[N+1];
    
    blackImos[0]     = 0;
    idealScore[0]    = 0;
    
    REP(i,N+1){
        blackImos[i+1]     = board[i] + blackImos[i];
        idealScore[i+1]    = max(0,board[i]) + idealScore[i];
    }
    
    // REP(i,N+1){
    //     debug(blackImos[i])
    // }
    // REP(i,N+1){
    //     debug(idealScore[i])
    // }

    long long ans = 0;
    
    REP(i,N-K+1){

        long long sum = idealScore[N];
        
        long long blackScore = blackImos[i+K]  - blackImos[i];
        long long score      = sum - (idealScore[i+K] - idealScore[i]);

        // white
        ans = max(ans,score + 0);
        // black
        ans = max(ans,score + blackScore);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2176
#include<stdio.h>

int main()
{
  int arr1[100][100];
  int h,w;
  int n;
  int count = 0;
  int arr2[100];
  int temp[100];
  scanf("%d %d", &h, &w);
  
  for(int i = 0; i < h; i++)
    {
      for(int k = 0; k < w; k++)
	{
	  scanf("%d", &arr1[i][k]);
	}
    }
  for(int i = 0; i < w; i++)
    {
      scanf("%d", &arr2[i]);
    }
  for(int i = 0; i<h; i++)
    {
      for(int j = 0; j<w; j++)
	{
	  temp[i] += arr1[i][j]*arr2[j];
	}
    }
  for(int i = 0; i < h; i++)
    {
      printf("%d\n", temp[i]);
    }
}



Measured memory_bytes: 2120
#define _GLIBCXX_DEBUG
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#include <bits/stdc++.h>
using namespace std;

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

  sort(d, d + SIZE_OF_ARRAY(d));

  cout << d[N/2]-d[N/2-1] << endl;

  return 0;
}


Measured memory_bytes: 4016
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <tuple>
#include <stack>
#include <bitset>

#define MAX_N 200010
#define MAX_Q 200010
#define INF   1000000000000
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

ll a[MAX_N];
ll b[MAX_N];
ll p[MAX_Q];
ll x[MAX_Q];
ll cnt[MAX_N];
vector<ll> G[MAX_N];
ll d[MAX_N];

bool bfs(){
  queue<ll> q;
  q.push(1);
  d[1] = 0;
  
  while (q.size() != 0) {
    ll v = q.front(); q.pop();
    for (ll i = 0; i < G[v].size(); i++){
      ll vn = G[v][i];
      if ( d[vn] == INF ) {
        q.push(vn);
        d[vn] = d[v] + 1;
      }
    }
  }
  return true;
}


bool dfs(ll v, ll cp) {
  cnt[v] += cp;
  for(ll i = 0; i < G[v].size(); i++) {
    ll vn = G[v][i];
    if (d[v] < d[vn]) dfs(vn, cnt[v]);
  }
  return true;
}

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

    ll N, Q;
    cin >> N >> Q;
    
    for(ll i = 0; i < N-1; i++) {
      cin >> a[i] >> b[i];
      G[ a[i] ].push_back(b[i]);
      G[ b[i] ].push_back(a[i]);
    }
    for(ll i = 0; i < Q; i++) cin >> p[i] >> x[i];
    
    fill(d, d + MAX_N, INF);
    bfs();
    
    fill(cnt, cnt + N, 0);
    for(ll i = 0; i < Q; i++) cnt[ p[i] ] += x[i];

    dfs(1, 0);

    for(ll i = 1; i <= N; i++) cout << cnt[i] << " ";
    cout << endl;
    
    return 0;
}
    

Measured memory_bytes: 29704
#!/usr/bin/env python3
import sys
import fractions

def solve(A: int, B: int):
    print(A*B//fractions.gcd(A, B))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5048
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9+7;
constexpr lint mod2 = 998244353;

int main() {
  int n, m, s = 0; scanf("%d %d", &n, &m);
  s += n * 100 + m * 1800;
  rep(i, m) s *= 2;
  printf("%d", s);
  return 0;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    long long a, b, c, k;
    cin >> a >> b >> c >> k;
    if (k % 2 == 0) {
        cout << a - b << '\n';
    } else {
        cout << b - a << '\n';
    }
    return 0;
}


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

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

  vector<int> c(m);
  rep(i, m) cin >> c.at(i);

  vector<int> T(51000, 99999);
  T.at(0) = 0;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j + c.at(i) <= n; j++) {
      T.at(j + c.at(i)) = min(T.at(j + c.at(i)), T.at(j) + 1);
    }
  }

  cout << T.at(n) << endl;
  return 0;
}


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

void printPair(vector<pair<int, int> > pdata){
  for (auto p: pdata){
    cout << p.first << " " << p.second << endl;
  }
}

int main(){
  int n, T;
  cin >> n >> T;
  vector<pair<int, int> > keiro;
  vector<int> c;
  for (int i = 0; i < n; i++){
    int a , b;
    cin >> a >> b;
    c.push_back(a);
    keiro.push_back(make_pair(a, b));
  }

  sort(keiro.begin(), keiro.end());
  for (auto i: keiro){
    if (i.second <= T){
      cout << i.first << endl;
      return 0;
    }
  }
  cout << "TLE" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(ll i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[8]={0,1,0,-1,1,1,-1,-1},mdy[8]={-1,0,1,0,1,-1,1,-1};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
int r;
int main(){
	cin>>r;
	cout<<3*r*r<<endl;
	return 0;
}

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

using namespace std;

#define ll long long 

ll n,arr[100005], brr[100005], crr[100005];

ll dp[100005][4];

int main()
{
	ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);
	
	cin >> n;		
		
	for(int i = 1; i <= n; i++)
	{
		cin >> arr[i] >> brr[i] >> crr[i];
	}	
	
	dp[1][1] = arr[1];
	dp[1][2] = brr[1];
	dp[1][3] = crr[1];
	
	for(int i = 2; i <= n; i++)
	{
		dp[i][1] = max(dp[i-1][2]+arr[i], dp[i-1][3]+arr[i]);
		dp[i][2] = max(dp[i-1][1]+brr[i], dp[i-1][3]+brr[i]);
		dp[i][3] = max(dp[i-1][1]+crr[i], dp[i-1][2]+crr[i]);
	}
	
	ll ans = max(dp[n][1], max(dp[n][2], dp[n][3]));
	
	cout << ans << endl;
	
	return 0;
}


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

static const int NMAX = 100;
static const int INF = (1<<29);
int N,T;
int c[NMAX+1],t[NMAX+1];
int main(){
  cin >> N >> T;
  for(int i=0;i<N;i++){
    cin >> c[i] >> t[i];
  }

  int ans = INF;
  for(int i=0;i<N;i++){
    if(t[i]>T) continue;
    ans = min(ans,c[i]);
  }
  if(ans == INF) cout << "TLE" << endl;
  else cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<cstdio>
using ll = long long;
using namespace std;
int main(){
    ll n;
    cin >> n;
    if(n<1200)  cout << "ABC\n";
    else if(n<2800) cout << "ARC\n";
    else cout << "AGC\n";
    return 0;
}


Measured memory_bytes: 256
#include <queue>
#include <iostream>
using namespace std;
typedef unsigned long ul;
int main(){
queue<ul> q;
int n;
cin>>n; long t=0,u=0; ul l,c=0;
for(int i=0;i<n;i++){
cin>>l;
if(c&l){do{c^=q.front();q.pop();u--;}while(c&l);
}c|=l;q.push(l);u++;t+=u;}cout<<t;
}

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


int main() {
  string s;
  cin >> s;
  if(s == "RRR"){
    cout << 3;
  }
  if(s == "SRR"){
    cout << 2;
  }
  if(s == "RSR"){
    cout << 1;
  }
  if(s == "RRS"){
    cout << 2;
  }
  if(s == "SSR"){
    cout << 1;
  }
  if(s == "RSS"){
    cout << 1;
  }
  if(s == "SRS"){
    cout << 1;
  }
  if(s == "SSS"){
    cout << 0;
  }
  
  
  return 0;
}




Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(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;
typedef vector<pair<int,int>> vp;
const ll INF = 1e18;
const ll mod =1000000007;
#define foreach(ix,a) for(auto& (ix) : (a) 
struct UnionFind {
    vector<int> par;
 
    UnionFind(int N) : par(N,-1) {}
 
    int root(int x) { 
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }
    void unite(int x, int y) { 
        int rx = root(x); 
        int ry = root(y);
        if (rx == ry) return; 
        if(size(x)<size(y))swap(rx,ry);
        par[rx]+=par[ry];
        par[ry]=rx;
    }
    bool same(int x, int y) { 
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
    int size(int x){
        return -par[root(x)];
    }
};

int main(){
    ll n,m;
    cin>>n>>m;
    UnionFind f(n);
    vi a(m),b(m);
    rep(i,m){
        cin>>a[i]>>b[i];
        a[i]--;b[i]--;
    }
    vl ans(m+1,0);
    ans[m]=n*(n-1)/2;
    //f.unite(a[m-1],b[m-1]);
    rep(i,m){
        if(f.same(a[m-i-1],b[m-i-1])){
            ans[m-i-1]=ans[m-i];
        }
        else{
            ans[m-i-1]=ans[m-i]-(f.size(a[m-i-1])*f.size(b[m-i-1]));
            //cout<<(f.size(a[m-i-1])*f.size(b[m-i-1]))<<endl;
        }
        f.unite(a[m-i-1],b[m-i-1]);
    }
    rep(i,m)cout<<ans[i+1]<<endl;
}

Measured memory_bytes: 5096
#include<iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<stdlib.h>
#include<stack>
using namespace std;
#define PI 3.14159265358979
typedef  long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#include<set>
int r,s,p;

int judge(char player,char m)
{
    if(player=='r'&&m=='s') return r;
    else if(player=='s'&&m=='p') return s;
    else if(player=='p'&&m=='r') return p;
    else return 0;
    
}

int main(void)
{
    int ans =0;
    int n,k;
    cin>>n>>k;

    cin>>r>>s>>p;

    string s;
    cin>>s;

    for(int i=0;i<k;i++)    // sub DP i(0~K)
    {

        int rjp = 0;
        int sjp = 0;
        int pjp = 0;

        for(int j=i;j<n;j+=k)
        {
            //　j番目にr,s,pを出すときの最大値
            int rj=judge('r',s[j]) +max(sjp,pjp);
            int sj=judge('s',s[j]) +max(rjp,pjp);
            int pj=judge('p',s[j]) +max(sjp,rjp);

            rjp= rj;
            sjp=sj;
            pjp=pj;
        }


        ans += max(rjp,max(sjp,pjp));
    }
    cout<<ans<<endl;

}

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

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
template <typename T>
constexpr T INF = numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity() : numeric_limits<T>::max() / 2;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (int i = start, i##_len = stop; i < i##_len; ++i)
#define RREP(i, n) for (int i = n; i-- > 0;)
#define ALL(v) (v).begin(), (v).end()

template<typename T>
istream& operator>>(istream& in, vector<T>& a) { for (T& x : a) cin >> x; }

void LOG(const int& x) { cerr << x << "\n"; }
void LOG(const vector<int>& a) { for (int x : a) cerr << x << " "; cerr << "\n"; }

int ceil(int a, int b) { return (a - 1) / b + 1; }

class UnionFind {
private:
  vector<int> par;
  vector<int> rnk;
  int find(int x) {
    return par[x] == x ? x : par[x] = find(par[x]);
  }
public:
  UnionFind(int size) {
    par.resize(size);
    rnk.resize(size);
    REP(i, size) par[i] = i, rnk[i] = 0;
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (rnk[x] < rnk[y]) {
      par[x] = y;
    } else {
      par[y] = x;
      if (rnk[x] == rnk[y]) rnk[x]++;
    }
  }
  bool same(int x, int y) {
    return find(x) == find(y);
  }
};

struct InitCpp { InitCpp() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
} } initCpp;

signed main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n);
  cin >> a >> b >> c;
  sort(ALL(a));
  sort(ALL(b));
  sort(ALL(c));
  i64 res = 0;
  for (int x : b) {
    auto i = lower_bound(ALL(a), x);
    auto j = lower_bound(ALL(c), x + 1);
    res += (i - a.begin()) * (c.end() - j);
  }
  cout << res << endl;
}

Measured memory_bytes: 1408
x = list(map(int,input().split()))
n = int(x[0])
a = int(x[1])
b = int(x[2])

res = 0

for i in range(n+1):
  m = sum([int(r) for r in list(str(i))])
  if a <= m <= b:
    res += i

print(res)

Measured memory_bytes: 9136
#define _USE_MATH_DEFINES  

#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <vector>

int main(){
    int h, w;

    while(1){
        std::cin >> h >> w;
        if(0 == h + w){
            break;
        }else{
            std::string line(w, '#');
            for(int i = 0; i < h; ++i){
                std::cout << line << std::endl;
            }
            std::cout << std::endl;
        }
    }

    return 0;
}


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

public class Main {
	public static void main(String[] args) {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    
		int n = 0;
		int m = 0;
		
		int[][] md;
		int[] vd;
		
		String x = "";
		try {
			x = in.readLine();
			String[] nm = x.split(" ");
			n = Integer.parseInt(nm[0]);
			m = Integer.parseInt(nm[1]);
			
			md = new int[n][m];
			vd = new int[m];
			
			for (int i = 0; i < n; i++) {
				x = in.readLine();
				String[] row = x.split(" ");
				for (int j = 0; j < m; j++) {
					md[i][j] = Integer.parseInt(row[j]);
				}
			}
			
			for (int i = 0; i < m; i++) {
				x = in.readLine();
				
				vd[i] = Integer.parseInt(x);
			}
			
			for (int i = 0; i < n; i++) {
				int v = 0;
				for (int j = 0; j < m; j++) {
					v = v + md[i][j] * vd[j];
				}
				System.out.println(v);
			}
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

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

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  vector<ll> b(n);
  vector<ll> c(n);
  rep(i,n) cin >> a[i];
  rep(i, n) cin >> b[i];
  rep(i, n) cin >> c[i];
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());
  ll ans = 0;
  for (ll i = 0; i < n; i++){
    ll key = b[i];
    //aの中でkey未満を探す
    auto iter_lower = lower_bound(a.begin(), a.end(), key);
    ll idx_lower_a = distance(a.begin(), iter_lower);
    ll num_a = (iter_lower == a.end()) ? n :idx_lower_a;
    //cの中でkeyより大きいものを探す
    auto iter_upper = upper_bound(c.begin(), c.end(), key);
    ll idx_bound_c = distance(c.begin(), iter_upper);
    ll num_c = (iter_upper == c.end()) ? 0 : n - idx_bound_c;
    ans += num_a * num_c;
  }
  cout << ans << endl;
}

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

using namespace std;

int main(){
    int N; cin >> N;
    int a[N][3];
    for (int i = 0; i < N; i++) cin >> a[i][0] >> a[i][1] >> a[i][2];

    int dp[N+1][3] = {};

    for (int i = 0; i < N; i++){
        for (int j = 0; j < 3; j++){
            for (int k = 0; k < 3; k++){
                if ( j == k ) continue;
                dp[i+1][k] = max(dp[i+1][k], dp[i][j] + a[i][k]);
            }
        }
    }


    int res = 0;
    for (int i = 0; i < 3; i++) res = max(dp[N][i], res);
    cout << res << endl;
}
        


Measured memory_bytes: 2560
#include "bits/stdc++.h"

using namespace std;

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

bool era[10000001]={false};


void makeERA(){
    for(int i=2;i<10000001;i++){
        if(era[i]!=true)continue;
        for(int j=2;;j++){
            if(i*j<=10000000)
                era[i*j]=false;
            else break;
        }
    }
    era[2]=true;
}



int main(){
    for(int i=0;i<10000001;i++)era[i]=true;
    era[0]=false;era[1]=false;
    makeERA();
    
    int n;
    while(cin>>n){
        if(n==0)break;
        
        if(n%2==0)n--;
        for(int i=n;i>=8;i-=2){
            if(era[i-8]&&era[i-6]&&!era[i-4]&&era[i-2]&&era[i]){
                cout<<i<<endl;
                goto next;
            }
        }
    next:;
    }
    
    
    return 0;
}

Measured memory_bytes: 10924
using System;
using System.Collections.Generic;
using System.Linq;

class Program {
    static int Main(string[] args) {
        string[] v = Console.ReadLine().Split(' ');

        int r = int.Parse(v[0]);
        int c = int.Parse(v[1]);

        int[,] list = new int[r + 1, c + 1];

        for (int i = 0; i < r; i++) {
            string[] x = Console.ReadLine().Split(' ');

            for (int k = 0; k < x.Length; k++) {
                list[i, k] = int.Parse(x[k]);

                list[i, c] += int.Parse(x[k]);
                list[r, k] += int.Parse(x[k]);
                list[r, c] += int.Parse(x[k]);
            }
        }

        for (int i = 0; i < r + 1; i++) {
            for (int k = 0; k < c + 1; k++) {
                if (k > 0) { Console.Write(" "); }
                Console.Write(list[i, k]);
            }
            Console.WriteLine(string.Empty);
        }

        return 0;
    }
}


Measured memory_bytes: 15968
#include <iostream>
#include<math.h>
#include <algorithm>
#include<string>
using namespace std;

int main() {
        long long int n;
        long long int a[100010];
        int ans=0, chnum[2][100010],count=0;

        cin >> n;
        for(int i=0; i<n; i++) cin >> a[i];

        sort(a,a+n);

        chnum[0][0]=a[0];

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

                if(a[i]==chnum[0][count]) chnum[1][count]++;
                else{
                        count++;
                        chnum[0][count]=a[i];
                        chnum[1][count]=1;
                }
        }

        for(int i=0;i<=count;i++){
                if(chnum[0][i]<chnum[1][i]) ans+=chnum[1][i]-chnum[0][i];
                else if(chnum[0][i]>chnum[1][i]) ans+=chnum[1][i];
        }

        cout << ans << endl;

        return 0;
}

Measured memory_bytes: 1792
using System;
using System.Linq;
using System.Collections.Generic;

namespace AtCoder
{
	class Program
	{
		public static void Main()
		{
			var intArray = IO.ReadIntArray();
			var lakeDistance = intArray[0];
			var buildNum = intArray[1];
			var positions = IO.ReadIntArray().ToList();
			positions.Add(positions[0] + lakeDistance);
			var maxDistance = Enumerable.Range(0 , buildNum).Max(iIndex =>
			{
				return positions[iIndex + 1] - positions[iIndex];
			});
			IO.Write(lakeDistance - maxDistance);
		}
	}

	public static class IO
	{
		public static string   Read()							   { return Console.ReadLine(); }
		public static string[] ReadArray(char iSplitter = ' ')	   { return Read().Split(iSplitter); }
		public static int	   ReadInt()						   { return int.Parse(Read()); }
		public static int[]	   ReadIntArray(char iSplitter = ' ')  { return ReadArray().Select(iText => int.Parse(iText)).ToArray(); }
		public static long	   ReadLong()						   { return int.Parse(Read()); }
		public static long[]   ReadLongArray(char iSplitter = ' ') { return ReadArray().Select(iText => long.Parse(iText)).ToArray(); }
		public static char[]   ReadCharArray()					   { return Read().ToCharArray(); }

		public static void Write(string iValue)			  { Console.WriteLine(iValue); }
		public static void Write(int iValue)			  { Console.WriteLine(iValue); }
		public static void Write(IEnumerable<int> iValue) { Console.WriteLine(string.Join(" " , iValue)); }
		public static void Write(long iValue)			  { Console.WriteLine(iValue); }
		public static void Write(decimal iValue)		  { Console.WriteLine(iValue); }
		public static void Write(bool iValue)			  { Console.WriteLine(iValue ? "Yes" : "No"); }
	}

	public static class Util
	{
		public static long Gcd(long i0 , long i1) { return (i0 > i1) ? _Gcd(i0 , i1) : _Gcd(i1 , i0); }
		public static long Lcm(long i0 , long i1) { return (i0 * i1) / Gcd(i0 , i1); }
		public static long ModPow(long iBaseNumber , long iPow , long iModNumber)
		{
			var num = 1L;
			while(iPow != 0)
			{
				if((iPow & 0x1) != 0)
				{
					num = (num * iBaseNumber) % iModNumber;
				}
				iBaseNumber = (iBaseNumber * iBaseNumber) % iModNumber;
				iPow >>= 1;
			}
			return num;
		}

		private static long _Gcd(long i0 , long i1)	{ return (i1 == 0) ? i0 : _Gcd(i1 , i0 % i1); }
	}
}


Measured memory_bytes: 34780
//#include <bits/stdc++.h>
// utility
#include <bitset>
#include <tuple>
#include <typeinfo>
// error handling
#include <cassert>
// string
#include <cctype>
#include <cstring>
#include <string>
// container
#include <array>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// algorithm
#include <algorithm>
// iterator
#include <iterator>
// math
#include <cmath>
#include <complex>
#include <numeric>
#include <random>
// i/o
#include <cstdio>
#include <iomanip>
#include <iostream>

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
typedef __int128_t Int;
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T> void printvv(const vector<vector<T>> &v) {
  cerr << endl;
  rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
    if (typeid(v[i][j]) == typeid(INF) and v[i][j] == INF) {
      cerr << "INF";
    } else
      cerr << v[i][j];
    cerr << (j == v[i].size() - 1 ? '\n' : ' ');
  }
  cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  int N;
  cin >> N;
  if(N==0){
    cout<<0<<endl;
    return 0;
  }

  int x = 0, i = (N < 0);
  N = abs(N);
  while (x < N) {
    x |= (1ll << i);
    i += 2;
  }
  bitset<32> b(x ^ (x - N));
  stringstream ss;
  ss << b;
  cout << ss.str().substr(ss.str().find('1')) << endl;

  return 0;
}


Measured memory_bytes: 256
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    N = int(input())
    print((1 + N) * N // 2)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3944
#include<cstdio>
#include<algorithm>
#include<cctype>
#include<cstring>
#include<iostream>
#include<cmath>
#define LL long long
#define N (100005)
using namespace std;
int n,top;
char c[N];
int st[N];
template <typename T> void read(T&t) {
	t=0;
	bool fl=true;
	char p=getchar();
	while (!isdigit(p)) {
		if (p=='-') fl=false;
		p=getchar();
	}
	do {
		(t*=10)+=p-48;p=getchar();
	}while (isdigit(p));
	if (!fl) t=-t;
}
int main(){
	scanf("%s",c+1);
	n=strlen(c+1);
	for (int i=1;i<=n;i++){
		if (top&&((c[i]-'0')^st[top])) top--;
		else st[++top]=c[i]-'0';
	}
	printf("%d",n-top);
	return 0;
}


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

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

int main() {
    int A, B, C, K;
    cin>> A >> B >> C >> K;
    int k = 0;
    bool success = false;
    while(k < K){
        if(C <= B){
            C *= 2;
            k++;
        }else if(B <= A){
            B *= 2;
            k++;
        }
        if(A < B && B < C){
            success = true;
            break;
        }
    }
    if(success) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3628
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * 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);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long q = in.nextLong();
            long h = Math.min(q * 2, in.nextLong());
            long s = Math.min(h * 2, in.nextLong());
            long d = Math.min(s * 2, in.nextLong());
            long n = in.nextLong();

            out.println(d * (n / 2) + s * (n % 2));
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tok;

        public String nextString() {
            while (!tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return tok.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(nextString());
        }

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
            tok = new StringTokenizer("");
        }

    }
}



Measured memory_bytes: 21460
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>

int main() {
	int n; std::cin >> n;
	std::vector<int> set(1 << n); for (auto& s : set) std::cin >> s;
	std::multiset<int> map;
	std::sort(set.begin(), set.end(), std::greater<int>());
	std::vector<bool> is_generated(1 << n, false);
	map.insert(set.front());
	is_generated[0] = true;
	bool can_generate = true;
	for (auto i = 1; i <= n && can_generate; ++i){
		std::stack<int> generated;
		for (auto j = 0; j < set.size() && generated.size() < (1 << i); ++j) {
			if (!is_generated[j]) {
				auto pos = map.upper_bound(set[j]);
				if (pos != map.end()) {
					is_generated[j] = true;
					generated.push(set[j]);
					generated.push(*pos);
					map.erase(pos);
				}
			}
		}
		if (generated.size() != (1 << i)) can_generate = false;
		while (!generated.empty()) {
			map.insert(generated.top());
			generated.pop();
		}
	}
	if (can_generate) std::cout << "Yes\n";
	else std::cout << "No\n";
}


Measured memory_bytes: 13568
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    int odp = 0;
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j)
            for (int k = 1; k <= n; ++k)
                odp += __gcd(i, __gcd(j, k));
    cout << odp;
    return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int N=200009;
int main()
{
    FASTINOUT;
    string s,t;
    cin>>s>>t;
    int c=0;
    for (int i=0;i<s.size();i++){
        if (s[i]!=t[i])
            c++;
    }
    cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 3772
n = int(input())
a_list = list(map(int, input().split()))

ans = 0
tallest = a_list[0]
for i in range(1,n):
    if tallest > a_list[i]:
        ans += tallest - a_list[i]
    else:
        tallest = a_list[i]

print(ans)


Measured memory_bytes: 32180
M=998244353
*d=1,*[s=0]*7**6
*e=d
gets
$<.map{s+=a=_1.to_i
s.downto(0){|i|d[i+a]+=d[i]*2%M
e[i+a]+=e[i]%M}}
p (d.sum+~s%2*e[s/2]*3-d[0..s/2].sum*3)%M

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

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int64_t> x(n);
	for (auto &xi: x) {
		cin >> xi;
	}
	vector<int64_t> y(n);
	for (auto &yi: y) {
		cin >> yi;
	}
	int64_t sum1, sum2, sum3, best;
	sum1 = sum2 = sum3 = best = 0;
	for (auto i = 0; i < n; ++i) {
		auto diff = abs(x[i] - y[i]);
		sum1 += diff;
		sum2 += diff*diff;
		sum3 += diff*diff*diff;
		best = max(best, diff);
	}
	cout << fixed << setprecision(17);
	cout << sum1 << '\n' << sqrt(sum2) << '\n' << cbrt(sum3) << '\n' << best << '\n';
}


Measured memory_bytes: 3400
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
#define int long long
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000000000000;

signed main(){
	int ans=0;
	string S;
	cin>>S;
	for(int i=0;i<S.size();i++){
		for(int j=1;i+j<=S.size();j++){
			string sub=S.substr(i,j);
			DEB(sub)END
			bool flag=true;
			REP(k,sub.size()){
				if(sub[k]!='A'&&sub[k]!='G'&&sub[k]!='C'&&sub[k]!='T'){
					flag=false;
					break;
				}
			}
			if(flag==false){
				break;
			}
			ans=max(ans,(int)sub.size());
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
#define NMAX 10
#define DMAX 10

int main(){
    ll l,r,kotae=2020;
    cin >> l >> r;
    if(r-l<2020){
        for(ll i=l;i<r;i++){
            for(ll j=i+1;j<=r;j++){
                ll total;
                ll a=i,b=j;
                a=a%2019,b=b%2019;
                total = a*b%2019;
                kotae=min(kotae,total);
            }
        }
    }
    if(r-l>2019) kotae=0;
    
    cout << kotae << endl;
    
    
    return 0;
}











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

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); }
template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); }
template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8


void mainmain(){
	string s;
	int w;
	cin >> s >> w;
	string ans;
	for(size_t i = 0; i < s.size(); i += w){
		ans += s[i];
	}
	cout << ans << endl;
}



}
int main() try{
//	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
int n,a;
int d[105];
int main(){
	cin>>n;
	int l=105,r=-1;
	for(int i=0;i<n;i++){
		cin>>a;
		d[a]++;
		l=min(a,l);
		r=max(a,r);
	}
	int ans=inf;
	for(int i=l;i<=r;i++){
		int tmp=0;
		for(int j=l;j<=r;j++){
			if(!d[j]) continue;
			tmp+=((j-i)*(j-i)*d[j]);
		}
		ans=min(ans,tmp);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
S = list(map(int,list(input())))

N = len(S)
A = [0]
base = 1
for i in range(N):
	A.append((A[-1] + S[N-1-i] * base) % 2019)
	base = base * 10 % 2019
A.sort()
ans = 0
cnt = 1
for i in range(N):
	if i == N-1:
		if cnt > 1:
			cnt += 1
			ans += (cnt * (cnt - 1)) // 2
	elif A[i] == A[i+1]:
		cnt += 1
	else:
		ans += (cnt * (cnt - 1)) // 2
		cnt = 1
print(ans)

Measured memory_bytes: 18468
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)

using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N, x;
    cin>> N>>x;
    ll a[N];
    rep(i,0,N) cin>>a[i];
    ll ans=0;
    if (a[0]>x) {
        ans=a[0]-x;
        a[0]=x;
    }
    rep(i,0,N-1){
        if (a[i]+a[i+1]>x){
            ans+=a[i]+a[i+1]-x;
            a[i+1]=x-a[i];
        }
    }
    cout << ans<<"\n";
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <ios>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
#define itn int
#define retrun return
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
using namespace std;
typedef long long llong;
typedef pair<int, int> pii;
llong gcd(llong a, llong b) {
	if (a < b) std::swap(a, b);
	if (a % b == 0)
		return b;
	else
		return gcd(b, a % b);
}
llong lcm(llong a, llong b) {
	llong g = gcd(a, b);
	return a * b / g;
}
//ここまで共通
string S, T;
int A, B;
string U;
int main() {
	cin >> S >> T;
	cin >> A >> B;
	cin >> U;
	
	if (S == U) {
		--A;
	}
	if (T == U) {
		--B;
	}
	cout << A << ' ' << B << endl;
	return 0;
}

Measured memory_bytes: 256
#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;

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

int c[100005];

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

    int n;
    cin >> n;
    for(int i = 0; i < n; ++i){
        int a;
        cin >> a;
        ++c[a];
    }
    int cnt = 0;
    int ans = 0;
    for(int i = 1; i <= 100000; ++i){
        if(c[i] <= 1)   continue;
        if(c[i] > 2){
            if(c[i] % 2){
                ans += c[i] - 1;
                c[i] = 1;
            }
            else{
                ans += c[i] - 2;
                c[i] = 2;
            }
        }
        if(c[i] == 2){
            if(cnt){
                ans += 2;
                cnt = 0;
            }
            else    ++cnt;
        }
    }
    if(cnt) ans += 2;
    ans = n - ans;
    cout << ans << endl;
}

Measured memory_bytes: 3872
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
int d[100100];
int V; // kanarazu dainyuu !
int E; // betuni iranai
struct edge
{
	int to,cost;
	edge(int to,int cost):to(to),cost(cost){}
};
vector<edge> g[100100];
void dijkstra(int s)
{
    fill(d,d+V+1,INF);
    priority_queue<P,vector<P>,greater<P> > q;
    d[s]=0;
    q.push(P(0,s));
    while(!q.empty())
    {
        P a=q.top();
        q.pop();
        if(d[a.sec]<a.fi)continue;
        for(int i=0;i<g[a.sec].size();i++)
        {
            edge e=g[a.sec][i];
            if(d[e.to]>d[a.sec]+e.cost)
            {
                d[e.to]=d[a.sec]+e.cost;
                q.push(P(d[e.to],e.to));
            }
        }
    }
    return;
}
int main()
{
	int r;
	scanf("%d %d %d",&V,&E,&r);
	for(int i=0;i<E;i++)
	{
		int s,t,d;
		scanf("%d %d %d",&s,&t,&d);
		g[s].pb(edge(t,d));
	}
	dijkstra(r);
	for(int i=0;i<V;i++)
	{
		if(d[i]==INF)printf("INF\n");
		else printf("%d\n",d[i]);
	}
	return 0;
}

Measured memory_bytes: 11304
/* while(!cin.eof()) */
 
#include<bits/stdc++.h>
using namespace std; 
#define int long long 
#define mod (int)(1e9+7)
#define MAXI (int)(1e15+100)
#define N 1000500


 
// Driver code to test above functions
int32_t main()
{
    
 
   
     
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int n, k, ans=0;
    cin >> n >> k;
   for(int i=0;i<n;i++)
    {
        int x;
        cin >> x;
        if(x>=k)
            ans++;
    }
    cout << ans;
    

    return 0;
} 

Measured memory_bytes: 256
#include<iostream>
#include<deque>

using namespace std;

deque<int> deq;

void f0()
{
    int op,a;

    cin>>op>>a;

    if(op)
    {
        deq.push_back(a);
    }else
    {
        deq.push_front(a);
    }
}

void f1()
{
    int idx;
    cin>>idx;

    cout<<deq[idx]<<endl;
}

void f2()
{
    int op;
    cin>>op;

    if(op)
    {
        deq.pop_back();
    }else
    {
        deq.pop_front();
    }
}

int main()
{
    int n;

    cin>>n;

    while(n--)
    {
        int op;
        cin>>op;

        switch(op)
        {
            case 0:f0();break;
            case 1:f1();break;
            case 2:f2();break;
        }
    }

    return 0;
}



Measured memory_bytes: 4544
#include<bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for(int i = 0;i < n;i++)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()

template<class T> bool chmax(T& a,T b){ if(a < b){ a = b; return true; }else return false; }
template<class T> bool chmin(T& a,T b){ if(a > b){ a = b; return true; }else return false; }
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;
using vpi = vector<Pi>;
using vpl = vector<Pl>;
 
#define debug(arr) cout << #arr << " = " << arr << '\n'
#define debug2(a,b) cout << "[" << #a << "," << #b << "] = " << "[" << a << "," << b << "]" << '\n'
template<class T> ostream &operator << (ostream& out, const vector<T>& arr) {
	cout << "{"; for (int i = 0; i < arr.size(); i++)cout << (!i ? "" : ", ") << arr[i]; cout << "}";
	return out;
}
template<class T> ostream &operator << (ostream& out, const vector<vector<T> >& arr) {
	cout << "{\n"; for (auto& vec : arr)cout << "  " << vec << ",\n"; cout << "}";
	return out;
}
template<class S,class T> ostream &operator << (ostream& out, const pair<S,T>& p){
  cout << "{" << p.first << "," << p.second << "}" << '\n';
  return out;
}
template<class T> istream &operator >> (istream& in, vector<T>& arr) {
	for (auto& i : arr)cin >> i; return in;
}

/////////////////////////////////////////////////////////////////////////
int main(void){
  cin.tie(0);
  ios::sync_with_stdio(false);
  //cout << fixed << setprecision(20);
  
  ll ans = 0;
  int n;cin >> n;
  for(int i = 1;i <= n;i++){
    for(int j = 1;i * j < n;j++){
      ans++;
    }
  }
  cout << ans << '\n';
  return 0;
}


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

int main() {
    int n;
    cin >> n;
    int d[n];
    for (int i = 0; i < n; i++) cin >> d[i];

    int cnt = 1;
    
    for (int i = 0; i < n; i++) {
        bool cnt_fl = false;
        for (int j = i + 1; j < n; j++){
            cnt_fl = true;
            if (d[i] == d[j]) {
                cnt_fl = false;
                break;
            }
        }
        if (cnt_fl == true) cnt++;
    }

    cout << cnt << endl;
}

Measured memory_bytes: 3472
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int h, w;
	cin>>h>>w;
	string s[22];
	for(int i=0; i<h; i++) cin>>s[i];
	int d[404][404];
	int n=h*w;
	const int INF=1e9;
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			if(i==j) d[i][j]=0;
			else d[i][j]=INF;
		}
	}
	int dx[4]={1, -1, 0, 0}, dy[4]={0, 0, 1, -1};
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			if(s[i][j]=='#') continue;
			int x=i*w+j;
			for(int k=0; k<4; k++){
				int i1=i+dx[k], j1=j+dy[k];
				if(i1<0 || j1<0 || i1>=h || j1>=w) continue;
				if(s[i1][j1]=='#') continue;
				int y=i1*w+j1;
				d[x][y]=d[y][x]=1;
			}
		}
	}
	for(int k=0; k<n; k++){
		for(int i=0; i<n; i++){
			for(int j=0; j<n; j++){
				d[i][j]=min(d[i][j], d[i][k]+d[k][j]);
			}
		}
	}
	int ans=0;
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			if(d[i][j]<INF/2) ans=max(ans, d[i][j]);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 896