akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define rep(i, j, k)    for(int i = (j); i < (int)k; ++i)
#define rrep(i, k, j)   for(int i = (int)k - 1; i >= (j); --i)
#define pb              push_back
#define mp              make_pair
#define pii             pair<int, int>
#define endl            "\n"
#define vi              vector<int>
#define mii             map<int, int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int, vi, greater<int>>
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x, y)        fixed << setprecision(y) << x
#define mk(arr, n, type)type *arr = new type[n];
#define w(x)            int x; cin >> x; while(x--)
#define PI              3.14159265358979323846264338327950L
#define span(a)         begin(a), end(a)
#define parent(i)       (i >> 1)
#define left(i)         (i << 1)
#define right(i)        (left(i) | 1)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());




void c_p_c()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}


// int gcd (int a, int b) {
//   if (b == 0) return a;
//   else return gcd (b, a % b);
// }
// int gcd(int a, int b, int& x, int& y) {
//   if (b == 0) {
//     x = 1;
//     y = 0;
//     return a;
//   }
//   int x1, y1;

//   int d = gcd(b, a % b, x1, y1);
//   x = y1;
//   y = x1 - y1 * (a / b);
//   return d;
// }
// int lcm (int a, int b)  {
//   return a / gcd(a, b) * b;
// }
// int fact (int n){
//   if (n == 0) return 1 ;
//   else return n * fact(n - 1);
// }

// bool isPrime(int x) {
//   for (int d = 2; d * d <= x; d++) if (x % d == 0) return false;
//   return true;
// }

// int divisor(int number)
// {
//         int i;
//         for (i = 2; i <= sqrt(number); i++)
//         {
//                 if (number % i == 0)
//                 {
//                        return number/i;
//                 }
//         }
//         return 1;
// }


void solve()
{
      int n; cin >> n;
      int a[n]; for (int &i : a) cin >> i;
      sort(a, a + n);

      int ans = 0;
      rep(i, 0, n - 2)
      {
            rep (j, i + 1, n - 1)
            {
                  rep (k, j + 1, n)
                  {
                        if (a[k] != a[j] and a[j] != a[i] and a[k] != a[i])
                        {
                              if (a[i] + a[j] > a[k]) ans++;
                        }
                  }
            }
      }

      cout << ans << endl;
}
int32_t main()
{
     // c_p_c();
      //w(x)
      solve();
      return 0;
}


Measured memory_bytes: 3644
n = int(input())
nums = map(int, input().split())

start_num = 1
result_list = []
for num in nums:
    if num == start_num:
        result_list.append(num)
        start_num += 1

if len(result_list) == 0:
    print(-1)
else:
    print(n - len(result_list))

Measured memory_bytes: 25768
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        long n = Long.parseLong(sc.next());
        
        long x = n;
        for(int i = 1; i <= Math.sqrt(n); i++){
            if(n%i == 0){
                x = i;
            }
        }
        
        System.out.println(x + n/x -2);
    }
}

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

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

S = [0] * (N+1)

for i in range(N):
  S[i+1] = S[i] + A[i]
#print(S)
#S[1] > 0
ans1 = 0
work = 0
for i in range(1,N+1):
  if i%2 == 1:
    # pos is required
    if S[i] + work <= 0:
      temp = 1 - (S[i] + work)
      ans1 += temp
      work += temp
  else:
    # neg is required
    if S[i] + work >= 0:
      temp = (S[i] + work) + 1
      ans1 += temp
      work -= temp

#S[1] < 0
ans2 = 0
work = 0
for i in range(1,N+1):
  if i%2 == 1:
    # neg is required
    if S[i] + work >= 0:
      temp = (S[i] + work) + 1
      ans2 += temp
      work -= temp
  else:
    # neg is required
    if S[i] + work <= 0:
      temp = 1 - (S[i] + work)
      ans2 += temp
      work += temp

print(min(ans1, ans2))

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

struct Point
{
	int x;
	int y;
};

int main(){
	vector<Point> nums;
	vector<string> strs;
	string ope;
	Point p;
	int i;
	while(cin>>p.x>>ope>>p.y){
		nums.push_back(p);
		strs.push_back(ope);
		if(ope=="?"){
			break;
		}
	}
	for(i=0; i<nums.size()-1; i++){
		if(strs[i]=="+"){
			cout<<nums[i].x+nums[i].y<<"\n";
		}else if(strs[i]=="-"){
			cout<<nums[i].x-nums[i].y<<"\n";
		}else if(strs[i]=="*"){
			cout<<nums[i].x*nums[i].y<<"\n";
		}else{
			cout<<nums[i].x/nums[i].y<<"\n";
		}
	}
	return 0;
}


Measured memory_bytes: 3132
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	int a,b,c;
	cin>>a>>b>>c;
	cout<<min({a+b,a+c,b+c})<<endl;
	return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IOS std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define FRE freopen("in.txt", "r", stdin);
#define endl "\n"
#define PI acos(-1.0)
typedef long long LL;
typedef pair<int, int> PII;
const double eps = 1e-8;
const int inf = 0x3f3f3f3f;
const int N = 55, M = 1010;

int a[N], b[N], c[N], d[N];
bool vis[15];
int n, m, q;
int num[N];
int res;

void dfs(int x, int nm) {
	if(x > n) {
		int sum = 0;
		for(int i = 1; i <= q; i++) {
			if(num[b[i]] - num[a[i]] == c[i]) sum += d[i];
		}
		res = max(res, sum);
		return;
	}
	for(int i = nm; i <= m - 1; i++) {
		num[x] = i;
		dfs(x + 1, i);
	}
}

void solve() {
	scanf("%d%d%d", &n, &m, &q);
	for(int i = 1; i <= q; i++) {
		scanf("%d%d%d%d", &a[i], &b[i], &c[i], &d[i]);
	}
	dfs(1, 0);
	printf("%d\n", res);
}

int main() {
	//FRE;
	int t;
	solve();
	return 0;
}

Measured memory_bytes: 3812
//
// Created by kuroneko on 2019-07-06.
//

using namespace std;

#include <iostream>
#include <vector>

typedef long long ll;

int main() {
    long double W, H, x, y; cin >> W >> H >> x >> y;
    long double S;
    int ans;
    if (W/2.0 == x && H/2.0 == y) ans = 1;
    else ans = 0;
    S = W / 2.0 * H;

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

Measured memory_bytes: 512
import { readFileSync } from "fs";

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const range = (n: number | bigint) => [...Array(Number(n))].map((_, i) => i);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const tuple = <T extends unknown[]>(...ts: T) => ts;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [cin, nCin, biCin] = (() => {
  const inputs = readFileSync("/dev/stdin", "utf-8").split(/[\n|\s]+/);
  let count = 0;
  const cin = () => inputs[count++];
  return tuple(
    cin,
    () => Number(cin()),
    () => BigInt(cin())
  );
})();
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const isNumber = (x: unknown): x is number => typeof x === "number";
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const isBigint = (x: unknown): x is bigint => typeof x === "bigint";
type NumberOrBigintOrElse<T> = number | bigint extends T
  ? undefined
  : T extends number
  ? number
  : T extends bigint
  ? bigint
  : undefined;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const max = <T extends number | bigint>(...ts: T[]): NumberOrBigintOrElse<T> =>
  (ts.length === 0
    ? undefined
    : isNumber(ts[0])
    ? Math.max(...(ts as number[]))
    : (ts as bigint[]).reduce((acc, t) =>
        acc >= t ? acc : t
      )) as NumberOrBigintOrElse<T>;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const min = <T extends number | bigint>(...ts: T[]): NumberOrBigintOrElse<T> =>
  (ts.length === 0
    ? undefined
    : isNumber(ts[0])
    ? Math.min(...(ts as number[]))
    : (ts as bigint[]).reduce((acc, t) =>
        acc <= t ? acc : t
      )) as NumberOrBigintOrElse<T>;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const abs = <T extends number | bigint>(t: T): NumberOrBigintOrElse<T> =>
  (isNumber(t)
    ? Math.abs(t)
    : isBigint(t)
    ? t >= 0n
      ? t
      : -t
    : undefined) as NumberOrBigintOrElse<T>;

/**
 * Program
 */
type Color = "R" | "W";

const getAns = (N: number, cs: Color[]): number => {
  const rNum = cs.filter((c) => c === "R").length;
  return min(rNum, N - rNum, cs.slice(0, rNum).filter((c) => c === "W").length);
};

{
  const N = nCin();
  const cs = cin()
    .split("")
    .map((c) => c as Color);
  const ans = getAns(N, cs);
  console.log(ans);
}


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

int main(){

    int n;
    cin >> n;
    int a,temp,ans=0;
    for(int i=0;i<n;i++){
        cin >> a;
        if(i!=0){
            if(temp == a){
                ans++;
                temp = -1;
            }
            else{
                temp = a;
            }
        }     
        else temp = a;   
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a[9];
  for(int i=0;i<9;i++){
      
        cin>>a[i];
      
  }
  int n,flag = 0;
  cin>>n;
  int b[n];
  vector<int> v;
  for(int k=0;k<n;k++){
      cin>>b[k];
  }
  for(int p = 0;p<n;p++){
      for(int j = 0;j<9;j++){
          if(b[p]==a[j]){
              a[j]=0;
              v.push_back(j);
          }
      }
  }
  if(a[0]==0 && a[1]==0 && a[2]==0 ||a[0]==0 && a[3]==0 && a[6]==0 ||a[0]==0 && a[4]==0 && a[8]==0||a[1]==0 && a[4]==0 && a[7]==0||a[2]==0 && a[5]==0 && a[8]==0||a[3]==0 && a[4]==0 && a[5]==0||a[6]==0 && a[7]==0 && a[8]==0||a[4]==0 && a[6]==0 && a[2]==0)
    cout<<"Yes";
    else cout<<"No";
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    int a = 0;
    cin >> N;
    int Ntmp = N;
    while(N >= 1){
        a += N % 10;
        N /= 10;
    }
    if (Ntmp % a == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
long long MIN(long long a,long long b){return a<b?a:b;}
int main(){
  long long a,b;
  scanf("%lld %lld",&a,&b);
  printf("%lld\n",MIN(a%b,labs(b-a%b)));
  return 0;
}


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

int main () {
  string s, t;
  int a = 0;
  cin >> s >> t;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] != t[i]) {
      a++;
    }
  }
  cout << a << endl;
}

Measured memory_bytes: 3784
// 普通にわからなかった...
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int main(){
    int w, h;
    cin >> w >> h;
    vector<pii> v;
    for(int i = 0; i < w; i++){
        int p;  cin >> p;
        v.push_back({p, 0});
    }
    for(int i = 0; i < h; i++){
        int p;  cin >> p;
        v.push_back({p, 1});
    }
    sort(v.begin(), v.end());
    w++, h++;
    ll ans = 0;
    for(pii p : v){
        if(p.second == 0){
            ans += (ll)h*p.first;
            w--;
        }else{
            ans += (ll)w*p.first;
            h--;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  // greedy
  int N;
  cin >> N;
  vector<P> AB;
  rep(i, N) {
    int A, B;
    cin >> A >> B;
    AB.push_back(P(B, A));
  }
  sort(AB.begin(), AB.end());
  int cur = 0;
  rep(i, N) {
    cur += AB[i].second;
    if (cur > AB[i].first) {
      cout << "No" << '\n';
      return 0;
    }
  }
  cout << "Yes" << '\n';
  return 0;
}

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

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; }

using ll = long long;

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

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

int main() {
  ll N;
  cin>>N;
  vector<bitset<60>> vb(N);
  vector<ll> vl(N);
  for(ll i = 0LL; i < N; i++) {
    ll A;
    cin >> A;
    vl[i]=A;
    bitset<60> b(A);
    vb[i]=b;
  }
  ll ans = 0LL;
  ll j = 0LL;
  bitset<60> X;
  ll S = 0LL;
  for(ll i = 0LL; i < N; i++) {
    X=(X^vb[i]);
    S+=vl[i];
    ll x = X.to_ullong();
    while(x!=S){
      X=(X^vb[j]);
      S-=vl[j];
      x=X.to_ullong();
      j++;
    }
    ans+=i-j+1LL;
  }
  cout<<ans<<endl;
}

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

int main(){
    int N;
    string S;    
    int x=0;
    int max_x = 0;
    cin >> N >> S;
    for (int i=0; i<N; i++){
        if (S[i] == 'D'){
            x -= 1;}
        else{
            x += 1;}
         if (max_x < x){
            max_x = x;}
    }
    cout << max_x;

    return 0;
}

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

int main() {
  int N; cin >> N;
  string S; cin >> S;
  stack<char> st;
  rep(i, 0, N) {
    if(st.empty()) st.push(S[i]);
    else {
      if(S[i] == '(') {
        st.push(S[i]);
      } else {
        if(st.top() == ')') st.push(S[i]);
        else st.pop();
      }
    }
  }
  string ans = "";
  int l = 0, r = 0;
  while(!st.empty()) {
    if(st.top() == '(') l++;
    else r++;
    st.pop();
  }
  rep(i, 0, r) ans += '(';
  ans += S;
  rep(i, 0, l) ans += ')';
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
4 5 1
0 1 2
0 2 3
1 2 -5
1 3 1
2 3 2

output:
INF
0
-5
-3

OR
input:
4 6 0
0 1 2
0 2 3
1 2 -5
1 3 1
2 3 2
3 1 0

output:
NEGATIVE CYCLE
"""

import sys
from math import isinf


def generate_adj_table(_v_info):
    for each in _v_info:
        source, target, cost = map(int, each)
        init_adj_table[source][target] = cost
    return init_adj_table


def bellman_ford():
    distance[root] = 0

    for j in range(vertices - 1):
        for current, current_info in enumerate(adj_table):
            for adj, cost in current_info.items():
                if distance[current] + cost < distance[adj]:
                    distance[adj] = distance[current] + cost

    for current, current_info in enumerate(adj_table):
        for adj, cost in current_info.items():
            if distance[current] + cost < distance[adj]:
                print('NEGATIVE CYCLE')
                return list()

    return distance


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    vertices, edges, root = map(int, _input[0].split())
    v_info = map(lambda x: x.split(), _input[1:])

    distance = [float('inf')] * vertices
    init_adj_table = tuple(dict() for _ in range(vertices))

    adj_table = generate_adj_table(v_info)

    res = bellman_ford()
    for ele in res:
        if isinf(ele):
            print('INF')
        else:
            print(ele)

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

int main2() {
  int N = nextLong();
  vector<int> a(N);
  REP(i, N) a[i] = nextLong();

  int ans = 0;
  for (int i = 0; i < N; i+=2) {
    if (a[i] % 2) ans++;
  }
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 3660
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int a[5],b,c;
int main()
{
    cin>>a[1]>>a[2]>>a[3];
    sort(a+1,a+4);
    if(a[2]-a[1]==a[3]-a[2])
    {
        cout<<"YES"<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }
}

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

vector<int> vec;
int size=0;

void swap(int i, int j){
	int tmp = vec[i];
	vec[i] = vec[j];
	vec[j] = tmp;
}

void bottomUp(int cur){
	int p;
	if(cur%2==0){
		p = cur / 2;
	} else {
		p = (cur-1) / 2;
	}
	if(p>=1 && vec[p] < vec[cur]){
		swap(p, cur);
		bottomUp(p);
	}
}

void topDown(int cur){
	int l=cur*2;
	int r=l+1;
	int max=cur;
	if(l<=size&&vec[max]<vec[l]){
		max=l;
	}
	if(r<=size&&vec[max]<vec[r]){
		max=r;
	}
	if(max!=cur){
		swap(max,cur);
		topDown(max);
	}
}

void insert(int n){
	size++;
	if(vec.size()-1<size){
		vec.push_back(n);
	} else {
		vec[size]=n;
	}
	bottomUp(size);
}

int extract(){
	int max=vec[1];
	vec[1]=vec[size];
	size--;
	topDown(1);
	return max;
}

int main(){
	vec.push_back(-1);
	string cmd;
	while(true){
		cin >> cmd;
		if (cmd=="insert"){
			int n;
			cin >> n;
			insert(n);
		} else if(cmd=="extract"){
			cout << extract() << endl;
		} else {
			break;
		}
	}
    return 0;
}



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

using namespace std;

typedef long long ll;

ll n, m;
map <ll, char> ans;
string s, t, ss, tt;

int main () {
	cin >> n >> m;
	cin >> s >> t;
	
	ll l = n * m / __gcd(n, m);

    ans[1] = s[0];
	for (int i = 1; i <= n - 1; i++)
		ans[i * l / n + 1] = s[i];
		
	for (int i = 1; i <= m - 1; i++)
		ans[i * l / m + 1] = t[i];

   	ss = ans[1];
   	tt = ans[1];
	for (int i = 1; i <= n - 1; i++)
		ss += ans[i * l / n + 1];
		
	for (int i = 1; i <= m - 1; i++)
		tt += ans[i * l / m + 1];

	if (ss != s || tt != t) {
		cout << -1;
	} else {
		cout << l;
	}

}

Measured memory_bytes: 11136
import sys, collections
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [tuple(map(int, input().split())) for _ in range(Q)]

counter = collections.Counter(A)
S = sum(A)
for i, (b, c) in enumerate(BC):
    count = counter[b]
    S += (c-b)*count
    counter[b] -= count
    counter[c] += count
    print(S)


Measured memory_bytes: 35504
#!/usr/bin/env python3

N = int(input())
L = list(map(int, input().split()))

ans = 0

for i in range(N-2):
    for k in range(i+1,N-1):
        for j in range(k+1,N):
            #print(i,k,j)
            if L[i]+L[j] > L[k] and L[i]+L[k] > L[j] and L[k]+L[j] > L[i] and L[i] != L [k] and L[i] != L [j] and L[j] != L [k]:
                ans += 1
print(ans)


Measured memory_bytes: 68176
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n) { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x) { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};

int main() {
	int n;
	while (cin >> n, n) {
		vi num(n);
		REP(i, n)
			cin >> num[i];
		vector<vector<bool>> able(n, vb(n, false));
		for (int i = 2;i < n + 1;i += 2) {
			for (int j = 0;j + i - 1 < n;j++) {
				if (i == 2) {
					if (abs(num[j] - num[j + i - 1]) <= 1)
						able[j][j + i - 1] = true;
				}
				else {
					if (abs(num[j] - num[j + i - 1]) <= 1 && able[j + 1][j + i - 2])
						able[j][j + i - 1] = true;
					REP(k, i / 2 - 1)
						if (able[j][j + k * 2 + 1] && able[j + k * 2 + 2][j + i - 1])
							able[j][j + i - 1] = true;
				}
			}
		}
		vvi DP(n, vi(n, 0));
		REP(i, n)
			REP(j, n)
			if (able[i][j])
				DP[i][j] = j - i + 1;
		for (int i = 3;i < n + 1;i++) {
			for (int j = 0;j + i - 1 < n;j++)
				REP(k, i-1)
				DP[j][j + i - 1] = max(DP[j][j + i - 1], DP[j][j + k] + DP[j + k+1][j + i - 1]);
		}
		cout << DP[0][n - 1] << endl;
	}
}

Measured memory_bytes: 3132
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define seg_size 262144
#define REP(a,b) for(long long a = 0;a < b;++a)
vector<complex<double>>  DFT(vector<complex<double>> a) {
	int n = a.size();
	if (n == 1) return a;
	vector<complex<double>> a0(n / 2), a1(n / 2);
	REP(i, n) {
		if (i % 2 == 0) {
			a0[i / 2] = a[i];
		}
		else {
			a1[i / 2] = a[i];
		}
	}
	vector<complex<double>> inversed_a0 = DFT(a0), inversed_a1 = DFT(a1);
	vector<complex<double>> inversed_a(n);
	for (int i = 0; i < n; ++i) {
		complex<double> zeta = complex<double>(cos(2 * Ma_PI * i / n), sin(2 * Ma_PI * i / n));
		inversed_a[i] = inversed_a0[i % (n / 2)] + zeta * inversed_a1[i % (n / 2)];
	}
	return inversed_a;
}
vector<complex<double>> IDFT(vector<complex<double>> inversed_a) {
	int n = inversed_a.size();
	vector<complex<double>> now = DFT(inversed_a);
	reverse(now.begin(), now.end());
	for (int q = now.size() - 1; q >= 1; --q) {
		swap(now[q], now[q - 1]);
	}
	REP(i, n) {
		now[i] /= complex<double>(n, 0);
	}
	return now;
}
vector<complex<double>> conv(vector<complex<double>> a, vector<complex<double>> b) {
	int deg = a.size() + b.size() - 1;
	int n = 1;
	while (n < deg) n <<= 1;
	a.resize(n);
	b.resize(n);
	vector<complex<double>> inversed_a = DFT(a),inversed_b = DFT(b);
	vector<complex<double>> inversed_c(n);
	REP(i, n) {
		inversed_c[i] = inversed_a[i] * inversed_b[i];
	}
	return IDFT(inversed_c);
}

int main() {
	long long n;
	cin >> n;
	vector<pair<long long,long long>> A;
	REP(i, n) {
		long long b;
		cin >> b;
		A.push_back(make_pair(b, i));
	}
	sort(A.begin(), A.end());
	reverse(A.begin(), A.end());
	long long itr = A[0].second;
	REP(q, n) {
		if (q != itr) {
			cout << A[0].first << endl;
		}
		else {
			cout << A[1].first << endl;
		}
	}
}

Measured memory_bytes: 6512
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <cstdlib>
#include <cstdio>

#define INF_LL 1e18
#define INF 1e9+7

#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<double, int> PDI;

class Union_find{
private:
	vector<int> par;
	vector<int> rank;
	int n;

public:
	Union_find(int a){
		n = a;
		for(int i = 0;i < n;i++){
			par.push_back(i);
			rank.push_back(0);
		}
	}

	int find(int x){
		if(par[x] == x){
			return x;
		}else{
			return par[x] = find(par[x]);
		}
	}

	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;

		if(rank[x] < rank[y]){
			par[x] = y;
		}else{
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
		}
	}

	bool same(int x, int y){
		return find(x) == find(y);
	}
};

bool prime[1000];
ll prid[1000] = {};

void divide(int n){
	while(n > 1){
		REP(i, 1000){
			if(prime[i] && n%i==0){
				prid[i]++;
				n /= i;
				break;
			}
		}
	}
}

int main(void){
	int N;
	fill(prime, prime+1000, true);
	prime[0] = false;
	prime[1] = false;
	FOR(i, 2, 1000){
		if(prime[i]){
			int in = i+i;
			while(in < 1000){
				prime[in] = false;
				in += i;
			}
		}
	}
	cin >> N;
	FOR(i, 1, N+1){
		divide(i);
	}
	ll res = 1;
	REP(i, 1000){
		res *= prid[i]+1;
		res = res % 1000000007;
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(a) (int)a.size()
#define rep(i, a, b) for(int i = (a); i < (b); ++i)
using namespace std;
using ll = long long;
const ll MOD = (ll)1e9 + 7;
ll dp[10000][100][2];
int d;
string k;
ll f(int currPos, int currSum, int isSmaller) {
	if(currPos == k.size()) {
		return currSum == 0;
	}
	ll &ret = dp[currPos][currSum][isSmaller];
	if(ret != -1) return ret;
	int limit = 9;
	if(!isSmaller) limit = k[currPos] - '0';
	ll ans = 0;
	for(int digit = 0; digit <= limit; ++digit) {
		int newCurrSum = (currSum + digit) % d;
		int newIsSmaller = isSmaller;
		if(isSmaller == 0 && digit < limit) newIsSmaller = 1;
		ans += f(currPos + 1, newCurrSum, newIsSmaller);
		ans %= MOD;
	}
	return ret = ans;
}

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	memset(dp, -1, sizeof dp);
	cin >> k >> d;
	cout << (f(0, 0, 0) + MOD - 1) % MOD;
	return 0;
}

Measured memory_bytes: 16896
#include<stdio.h>
int main(){
	int n,b,f,r,v;
	scanf("%d",&n);
	int s[4][3][10]={};
	for(int a=0;a<n;a++){
		scanf("%d %d %d %d",&b,&f,&r,&v);
		s[b-1][f-1][r-1]=s[b-1][f-1][r-1]+v;
	}
	for(int c=0;c<4;c++){
		for(int d=0;d<3;d++){
			for(int e=0;e<10;e++){
				printf(" %d",s[c][d][e]);
			}
			printf("\n");
		}
		if(c==3)break;
		printf("####################");
		printf("\n");
	}
	
	return 0;
}

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

    int count=0;

    int a[n];

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

    for(int i=0;i<n;i++)
    {
        if(i%2==0)
        {
            if(a[i]%2==1)
            {
                count++;
            }
        }
    }

    cout<<count<<endl;

    return 0;
}


Measured memory_bytes: 3644
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int t = scan.nextInt();
		
		if (x>t) {
			System.out.println(x-t);
		} else {
			System.out.println(0);
		}
	}
}


Measured memory_bytes: 21716
/*****/

#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <iomanip>	//cout << fixed << setprecision(桁数);
#include <stdexcept>

//#define int long long

using namespace std;
using ll = long long;
using ld = long double;
using vecll = vector<ll>;

#define nextline() (std::cerr << "\n")
#define debug(x) (#x " : " + (x))
#define debug_cout(x) (std::cerr << #x << " : " <<  (x) << "\n")
#define debug_tabcout(n, x) (std::cerr << strMulti("\t",n) << #x << " : " <<  (x) << "\n")
#define debug_headcout(h, x) (std::cerr << h << " : " <<  (x) << "\n")
#define debug_tabheadcout(n, h, x) (std::cerr << strMulti("\t",n) << h << " : " <<  (x) << "\n")

#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; i++)
#define rep1(i, n) for(int i=1, i##_len=(n); i<=i##_len; i++)
#define rrep(i, n) for(int i=(n)-1; i >= 0; i--)
#define rrep1(i, n) for(int i=(n); i > 0; i--)
#define all(x) (x).begin(), (x).end()
#define pair(a, b) make_pair(a, b);
constexpr int INF = 2000000100;
constexpr ll DIV = 1000000007;	// 10e9+7
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> T divup(T a, T b) { if (a % b == 0) { return a / b; } return a / b + 1; }
#define diup(a, b) (a % b == 0 ? a / b : a / b + 1)
#define exist_in(list, value) (list.end() != std::find(all(list),value))
std::string strMulti(std::string t, int n) { std::string out = ""; for (int i = 0; i < n; i++) { out += t; } return out; }
//template<class T> T math_P(T m, T n) { T ret = 1; for (T i = m; i > m - n; i--) { ret *= i; } return ret; }
//template<class T> T math_C(T m, T n) { T ret = mathP(m, n); for (T i = 2; i <= n; i++) { ret /= i; } return ret; }
//template<class T> bool compare_by_b(pair<T, T> a, pair<T, T> b) { if (a.second != b.second) { return a.second < b.second; } return a.first < b.first; }
//template<class T> T math_gcd(T a, T b) { a = abs(a); b = abs(b); if (a < b) { std::swap(a, b); } T tmp; while (b != 0) { tmp = b; b = a % b; a = tmp; } return a; }
//template<class T> T math_lcm(T a, T b) { a = abs(a); b = abs(b); if (a > b) { std::swap(a, b); } if (a == 1) { return b; } T i = a; while (i % b != 0) { i += a; } return i; }
//template<class T1, class T2> bool exist_in(const T1& list, const T2& v) { return (list.end() != std::find(list.begin(), list.end(), v)); }
//template<class T> bool exist_in(const T& c, const typename T::value_type& v) {	return (c.end() != std::find(c.begin(), c.end(), v));}

/*****/

void Main()
{
	int n, m;
	cin >> n >> m;
	cout << (n - 1) * (m - 1);
}

/*****/

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

	std::cout << std::fixed << std::setprecision(10);


	/*
	while (true)
	{
		Main();
		cout << endl;
	}
	//*/


	Main();

	return 0;
}


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

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

inline ll dist(ll x, ll y, ll n) {

    ll c = abs(x - y);
    return min(c, n - c);

}

int main() {

    ll n, m, p;
    cin >> n >> m >> p;
    vector<ll> d(m);
    for (ll i = 0; i < m; i++) {
        cin >> d[i];
    }

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

    ll ans = 1145141919810893;
    for (ll gapd = 0; gapd < m; gapd++) {
        ll l = d[gapd];
        ll r = d[(gapd+1) % m];
        ll d1 = min(dist(p, l, n), dist(p, r, n));
        ll d2 = n - (r > l ? r - l : r - l + n);
        ll cand = d1 + d2;
        // cerr << gapd << " -> " << l << ", " << r << ", " << d1 << ", " << d2 << endl;
        if (ans > cand) {
            ans = cand;
        }
    }

    cout << ans * 100 << endl;

}


Measured memory_bytes: 3232
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <queue>
#include <utility>
#include <vector>
using namespace std;

int n;
double x[50], y[50];
double dis(double x1, double y1, double x2, double y2) {
  return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
}

double calc(double xx, double yy) {
  double res = 0.0;
  for (int i = 0; i < n; i++) {
    res = max(res, dis(xx, yy, x[i], y[i]));
  }
  return res;
}
int main() {
  vector<pair<double, double> > v;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%lf%lf", &x[i], &y[i]);
  }
  double r, left = 0.0, right;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      left = max(left, sqrt(dis(x[i], y[i], x[j], y[j])) / 2.0);
    }
  }
  left -= 1e-7;
  right = 20000.0;
  while (right - left >= 1e-10) {
    int flag = 0;
    r = (right + left) / 2;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        double h = sqrt(r * r - dis(x[i], y[i], x[j], y[j]) / 4.0);
        double dx, dy;
        dx = h * (y[i] - y[j]) / sqrt(dis(x[i], y[i], x[j], y[j]));
        dy = -h * (x[i] - x[j]) / sqrt(dis(x[i], y[i], x[j], y[j]));
        int flag2 = 1;
        for (int k = 0; k < n; k++) {
          if (k != i && k != j &&
              dis((x[i] + x[j]) / 2.0 + dx, (y[i] + y[j]) / 2.0 + dy, x[k],
                  y[k]) > r * r + 1e-7) {
            flag2 = 0;
          }
        }
        if (flag2) {
          flag = 1;
        }
        flag2 = 1;
        for (int k = 0; k < n; k++) {
          if (k != i && k != j &&
              dis((x[i] + x[j]) / 2.0 - dx, (y[i] + y[j]) / 2.0 - dy, x[k],
                  y[k]) > r * r + 1e-7) {
            flag2 = 0;
          }
        }
        if (flag2) {
          flag = 1;
        }
      }
    }
    if (flag) {
      right = r;
    } else {
      left = r;
    }
  }
  printf("%.10f\n", left);
}

Measured memory_bytes: 128
#include<stdio.h>
int main(){
    int a[5];
    for(int i=0;i<5;i++){
        scanf("%d",&a[i]);
    }
    for(int i=0;i<5;i++){
        if(a[i]==0){
            printf("%d\n",i+1);
            return 0;
        }
    }
}

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

#define DeltaCube23 ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define mp make_pair
#define minimum(a) *min_element(a.begin(), a.end())
#define maximum(a) *max_element(a.begin(), a.end())
#define MOD 1000000007
#define forf(i,a,b) for(int i = (a); i < (b); i++)
#define forr(i,a,b) for(int i = (a); i >= (b); i--)

typedef long long int lli;

using namespace std;

const int mx=1e5+5;

int main()
{
    DeltaCube23
    int n,q,t;
    cin>>n;
    int a[n];
    vector<int>val[mx];
    lli sum=0;
    forf(i,0,n)
    {
        cin>>a[i];
        t=a[i];
        sum+=t;
        val[t].pb(i);
    }
    cin>>q;
    while(q--)
    {
        lli b,c;
        cin>>b>>c;
        for(auto x:val[b])
        {
            val[c].pb(x);
        }
        lli s=val[b].size();
        sum=sum-(b*s)+(c*s);
        val[b].clear();
        cout<<sum<<"\n";
    }
    return 0;
}

Measured memory_bytes: 30092
#include <stdio.h>
#include <string.h>
int main(void){
    char s[100001],ans[30]="abcdefghijklmnopqrstuvwxyz" ;
    scanf("%s",s) ;
    int count2=0 ;
    for (int i=0; i<26; i++) {
        int count=0 ;
        for (int j=0; j<strlen(s); j++){
            if (s[j]==ans[i]) {
                break ;
            } else {
                count++ ;
            }
        }
        if (count==strlen(s)) {
            printf ("%c\n",ans[i]) ;
            break ;
        }
        count2++ ;
        if (count2==26) {
            printf ("None\n") ;
        }
    }
    return 0 ;    
}

Measured memory_bytes: 256
object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    import java.util.Comparator
    val W, H = ni()
    val P = na(W)
    val Q = na(H)

    case class Path(v: Int, x: Int)
//    val A = Array.ofDim[Path](W + H)
    val A = new java.util.PriorityQueue[Path](H + W, new Comparator[Path] {
      override def compare(o1: Path, o2: Path): Int = Integer.compare(o1.v, o2.v)
    })
    rep(W)(i => A.add(Path(P(i), 0)))//A(i) = Path(P(i), 0))
    rep(H)(i => A.add(Path(Q(i), 1)))//A(i + W) = Path(Q(i), 1))
//    Sorting.quickSort(A)(Ordering.by(_.v))

    var ans = 0L
    val c = Array[Long](H + 1, W + 1)
    while(!A.isEmpty) {
//    rep(A.length) { i =>
//      val p = A(i)
      val p = A.poll()
      ans += c(p.x) * p.v
      c(p.x ^ 1) -= 1
    }

    out.println(ans)
  }


  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int): Array[Int] = map(n)(_ => ni())
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    rep(as.length)(i => s += as(i))
    s
  }
}

Measured memory_bytes: 46296
n = int(input())
a = list(map(int, input().split()))
s = sorted(a)
A = 0
B = 0
for i in range(n-1, -1, -1):
    if n%2 == 0:
        if i%2 == 0:
            B += s[i]
        else:
            A += s[i]
    else:
        if i%2 == 0:
            A += s[i]
        else:
            B += s[i]
print(A - B)

Measured memory_bytes: 9176
#include <iostream>
#include <vector>
#include <cmath>
#include <limits.h>
#include <utility>
#include <map>
#include <algorithm>
#include <set>
using namespace std;
using P = pair<int,int>;
using ll = long long;
constexpr int MOD=1000000007;
constexpr int MAX=2000100;
long long fac[MAX], finv[MAX], inv[MAX];
bool COMinited = false;
long long COM(int n, int k) {
  if (COMinited == false) {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
      fac[i] = fac[i - 1] * i % MOD;
      inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
      finv[i] = finv[i - 1] * inv[i] % MOD;
    }
    COMinited = true;
  }
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long modpow(long long a, long long n, long long mod=MOD) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); }
int main(){
    int k;
    cin>>k;
    string s;
    cin>>s;
    int t=s.size();
    int ret=0;
    for(int i=t;i<=k+t;i++){
        ret+=modpow(25,k+t-i)*COM(k+t,i)%MOD;
        ret%=MOD;
    }
    cout<<ret<<endl;
}

Measured memory_bytes: 51112
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int main(){

	int ans = 0;
	int N,tmp,pre;

	scanf("%d",&N);
	scanf("%d",&pre);

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

		scanf("%d",&tmp);
		if(pre < tmp){

			ans++;
		}
		pre = tmp;
	}

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

	return 0;
}



Measured memory_bytes: 3216
#include <bits/stdc++.h> 
#include<cmath>
#include<string>
#define pb push_back
#define x first
#define y second
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define all(x) x.begin(),x.end()
#define int long long
using namespace std;
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
//void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
// look for  all edge cases
//search for a pattern


const int nax = 1e6+2;
int prime[nax];

void sieve(){
	
	for(int i = 1 ;i < nax ; i++){
		prime[i] = i;
	}
	
	
	for(int i = 2; i < nax; i++){
		if(prime[i] == i){
			for(int j = 2*i ; j < nax ; j+= i){
				prime[j] = i;
			}
		}
	}
	
}

signed main() {    
	ios::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);
	
	sieve();
	
	int n;
	cin >> n;
	
	int ans = 0;
	for(int i = n-1 ; i > 1; i--){
		//int cnt = 0;
		int val = 1;
		//unordered_set<int> s;
		int p = i;
		while(p != 1){
			int cnt = 0;
			int ben = prime[p];
			while(p != 1 && p % ben == 0){
				p = p / ben;
				cnt += 1;
			}
			val = val*(cnt + 1);
		}
		
		
		ans = ans + val;
		//debug(cnt , i , ans);
	}
	ans += 1;
	cout<<ans;
		
	return 0;
}


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

typedef long long LL;

const int N = 5005;
const int MOD = 1000000007;

int n, po[N], f[N], g[N], h[N], dp[N][N], a[N], m;

int find(int x)
{
	return f[x] == x ? x : f[x] = find(f[x]);
}

int main()
{
	scanf("%d", &n);
	po[0] = 1;
	for (int i = 1; i <= n; i++) f[i] = i, g[i] = 1, po[i] = (LL)po[i - 1] * (n - 1) % MOD;
	int tot = 0;
	for (int i = 1; i <= n; i++)
	{
		int x; scanf("%d", &x);
		if (x == -1) {tot++; continue;}
		if (find(x) == find(i)) h[find(x)] = 1;
		else h[find(x)] ^= h[find(i)], g[find(x)] += g[find(i)], f[find(i)] = find(x);
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) if (f[i] == i)
	{
		if (h[i]) (ans += po[tot]) %= MOD;
		else a[++m] = g[i], (ans += (LL)(g[i] - 1) * po[tot - 1] % MOD) %= MOD;
	}
	for (int i = 1; i <= m; i++)
	{
		dp[i][1] = (dp[i - 1][1] + a[i]) % MOD;
		for (int j = 2; j <= i; j++)
			dp[i][j] = (dp[i - 1][j] + (LL)dp[i - 1][j - 1] * (j - 1) % MOD * a[i] % MOD) % MOD;
	}
	for (int i = 2; i <= m; i++) (ans += (LL)dp[m][i] * po[tot - i] % MOD) %= MOD;
	printf("%d\n", ((LL)n * po[tot] % MOD + MOD - ans) % MOD);
	return 0;
}

Measured memory_bytes: 70520
n = int(input())
a = tuple(map(int,input().split()))
a = sorted(a)

alice = []
bob = []

if n%2 == 0:
  while(len(a)>0):
    alice.append(a.pop())
    bob.append(a.pop())
else:
  alice.append(a.pop())
  while(len(a)>0):
    bob.append(a.pop())
    alice.append(a.pop())
print(sum(alice)-sum(bob))


Measured memory_bytes: 3060
// コメントなど修正して, 再提出.
#include <bits/stdc++.h>
using namespace std;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
int C[111][111]; // nCr の 事前計算.
int p9[5] = {1, 9, 81, 729, 6561};

// 0でない数字が, ちょうどK個あるようなものの個数を計算.
// @param N: 与えられた整数.
// @param c: 現在見ている桁.
// @param k: 0でない数字が使える残りの桁数.
// @return : 計算結果.
int recursive(string N, int c, int k){
    int ret = 0, d = N.size();
    // ex.
    // 10
    //  2
    // -> 0 が 正解だが, 1 と 出力された.
    // -> 以下の桁数チェックのロジックを追加.
    // -> hand_02 で WA版 となったので, 最初にチェックさせるように修正.
    if(d - c < k) return 0;
    
    // hand_03 ～ hand_05 で, WA版.
    // ex.
    // 1
    // 1
    // -> 1 が 正解だが, 3 と 出力されたため, ロジック修正.
    // if(c >= d) return 1;
    if(c >= d - 1) return N[d - 1] - '0';
    if(k == 0) return 1;
    
    if(N[c] > '0'){
        // c桁目が, 0 だった場合, (c + 1)桁目 ～ d桁目 の中で, 1 ～ 9 を k回選択できる.
        ret += C[d - 1 - c][k] * p9[k];
        
        // c桁目が, 1 ～ (N[c] - 1) だった場合, (c + 1)桁目 ～ d桁目 の中で, 1 ～ 9 を (k - 1)回選択できる.
        ret += (N[c] - '1') * C[d - 1 - c][k - 1] * p9[k - 1];
        
        // c桁目が, N[c] だった場合, (c + 1)桁目 ～ d桁目 の中で, 1 ～ 9 を (k - 1)回選択できる.
        ret += recursive(N, c + 1, k - 1);
    }else{
        // c桁目が, 0 だった場合, (c + 1)桁目 ～ d桁目 の中で, 1 ～ 9 を k回選択できる.
        ret += recursive(N, c + 1, k);
    }
    return ret;
}

int main(){
    
    // 1. 入力情報.
    int K;
    char c[111];
    scanf("%s %d", c, &K);
    string N(c);
    int d = N.size();
    
    // 2. nCr の 事前計算.
    C[0][0] = 1;
    rep(n, 111) C[n][0] = C[n][n] = 1;
    rep(n, 110) repx(k, 1, 111) C[n + 1][k] = C[n][k - 1] + C[n][k];
    
    // 3. 0でない数字が, ちょうどK個あるようなものの個数を計算.
    // ex.
    // 1111
    // 3
    // 
    // 1011 ～ 1099: 81通り
    // 1101 ～ 1109: 9通り
    // 1110 ～ 1110: 1通り
    // 0111 ～ 0999: 729通り
    // => 合計 820通り
    int ans = recursive(N, 0, K);
    
    // 4. 出力.
    printf("%d\n", ans);
    return 0;
    
}

Measured memory_bytes: 256
import collections
N = int(input())
a=[]
ans=[]
max =0
for i in range(N):
    a.append(input())
c = collections.Counter(a)
score_sorted = sorted(c.items(), key=lambda x:x[1], reverse=True)
for i in range(len(score_sorted)):
    max=score_sorted[0][1]
    if score_sorted[i][1] == max:
        ans.append(score_sorted[i][0])
    else:
        break
ans.sort()
for j in range(len(ans)):
    print(ans[j])
#print(c.values())


Measured memory_bytes: 121032
#include <stdio.h>
 
int main(void){
  char S[3];
  int i, cnt = 0;
  scanf("%s", S);
  for(i=0;i<3;i++){
    if(S[i] == '1'){
      cnt++;
    }
  }
  printf("%d", cnt);
  return 0;
}

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

// 簡易UF
struct UF{
    vector<int> p, cnt;
    int n;

    UF(int siz){
        n = siz;
        p.resize(n, 0);
        cnt.resize(n, 1);
        for(int i = 0; i < n; i++)  p[i] = i;
    }

    int parent(int x){
        if(p[x] != x)   p[x] = parent(p[x]);
        return p[x];
    }

    bool same(int x, int y){
        return parent(x) == parent(y);
    }
    
    void unite(int x, int y){
        x = parent(x), y = parent(y);
        if(x == y)  return;
        cnt[y] += cnt[x];
        p[x] = y;
    }
};

int main(){
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> ans(n, 0), deg(n, 0);
    UF uf(n);
    while(m--){
        int a, b;
        cin >> a >> b;
        a--, b--;
        uf.unite(a, b);
        deg[a]++, deg[b]++;
    }
    for(int i = 0; i < n; i++)  ans[i] = uf.cnt[uf.parent(i)]-deg[i];
    while(k--){
        int a, b;
        cin >> a >> b;
        a--, b--;
        if(uf.same(a, b)){
            ans[a]--, ans[b]--;
        }
    }
    for(int i = 0; i < n; i++)  cout << ans[i]-1 << " \n"[i==n-1];
    return 0;
}

Measured memory_bytes: 3200