akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF 2 << 29
#define MOD 1000000007
#define Yes(f) puts((f)? "Yes" : "No")
#define YES(f) puts((f)? "YES" : "NO")
int gcd(int a, int b) {
	if (b != 0) return gcd(b, a % b);
	return a;
}
int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}

using Graph = vector<vector<int>>;

int main(){
	ll n, ans = 1, a;
	cin >> n;
	rep(i, n){
		cin >> a;
		if(a == 0){
			ans = 0;
			break;
		}
		else if(a > ll(1e18) / ans) ans = -1;
		else if(ans != -1) ans *= a;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3640
import sys

num = []

while True:
    try:
        num.extend([int(n) for n in input().split()])
    except EOFError:
        break
    
s = sum(num[1:num[0]+1])/num[0]
s = round(s)
r = 0
for i in range(1,num[0]+1):
    r += pow(num[i]-s,2)
print(r)

Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>

int count[9];

int check(int flag){
	int i,j,res;

	for(i = 0;i < 9;i++){
		if(count[i] != 0){
			break;
		}
	}
	if(i == 9){
		return 1;
	}

	if(count[i] >= 3){
		count[i] -= 3;
		res = check(flag);
		count[i] += 3;
		if(res){
			return 1;
		}
	}
	if(count[i] >= 2 && !flag){
		count[i] -= 2;
		res = check(1);
		count[i] += 2;
		if(res){
			return 1;
		}
	}
	if(i <= 6 && count[i] >= 1 && count[i+1] >= 1 && count[i+2] >= 1){
		for(j = 0;j < 3;j++){
			count[i+j]--;
		}
		res = check(flag);
		for(j = 0;j < 3;j++){
			count[i+j]++;
		}
		if(res){
			return 1;
		}
	}

	return 0;
}

int main(){
	int i,tmp,flag;
	int ans[9];
	char str[14];

	while(scanf("%s",str) != EOF){
		memset(ans,0,sizeof(ans));
		memset(count,0,sizeof(count));
		tmp = 0;
		flag = 0;

		for(i = 0;i < 13;i++){
			count[str[i]-'1']++;
		}
		for(i = 0;i < 9;i++){
			if(count[i] > 4){
				flag = 1;
				break;
			}
			if(count[i] < 4){
				count[i]++;
				if(check(0)){
					ans[tmp] = i+1;
					tmp++;
				}
				count[i]--;
			}
		}

		if(flag || !tmp){
			printf("0\n");
		}else{
			for(i = 0;i < tmp;i++){
				printf("%d%c",ans[i],(i == tmp-1) ? '\n' : ' ');
			}
		}
	}

	return 0;
}

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

typedef long long ll;
int n,q;
vector<int> g[200005];

int main()
{
	ios_base::sync_with_stdio(false);
	cin>>n>>q;
//	cout<<"hello1"<<"\n";
	for(int i=0;i<n-1;i++)
	{
		int a,b;
		cin>>a>>b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	
	vector<ll> cost(n+1,0);
	while(q--)
	{
		int p,x;
		cin>>p>>x;
		cost[p]+=x;
	}

	queue <int> q;

    q.push(1);
    vector<bool> vis(n+1,0);
    vis[1] = 1;
    while(!q.empty()){
        int nc = q.size();
        
        while(nc>0){
            int pa = q.front();
            q.pop();
            
            nc--;
            long long pc = cost[pa];
            for(int i=0;i<g[pa].size();i++){
                if(!vis[g[pa][i]])
				{   
                    vis[g[pa][i]]=1;             
                    q.push(g[pa][i]);
                    cost[g[pa][i]] += pc;
                }
            }
        }
    }	

	for(int i=1;i<=n;i++)
		cout<<cost[i]<<" ";
	
}


Measured memory_bytes: 16372
import bisect
import sys

def main():
  input = sys.stdin.readline
  A, B, Q = map(int, input().split())
  INF = 10**18
  S = [-INF] + [int(input()) for _ in range(A)] + [INF]
  T = [-INF] + [int(input()) for _ in range(B)] + [INF]
  
  for q in range(Q):
    x = int(input())
    b, d = bisect.bisect_right(S, x), bisect.bisect_right(T, x)
    res = INF
    for s in [S[b-1], S[b]]:
      for t in [T[d-1], T[d]]:
        d1, d2 = abs(s-x) + abs(t-s), abs(t-x) + abs(s-t)
        res = min(res, d1, d2)
    print(res)


if __name__ == '__main__':
  main()


Measured memory_bytes: 12800
n, y = map(int, input().split())
for i in range(n+1):
    for j in range(n-i+1):
        if i*10000 + j*5000 + (n-i-j)*1000 == y:
            print(i, j, (n-i-j))
            exit()

print(-1, -1, -1)

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
long long int n,k;
int main(){
    cin >>n >> k;
    long long int res1 = n%k;
    long long int res2 = k-res1;
    if(res1<res2){
        cout << res1<<'\n';
    }
    else{
        cout << res2 <<'\n';
    }

}

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

int main() {
  string S,T;
  cin >> S >> T;
  int x;
  x = S.size();
  int counter = 0;
  for(int i = 0; i < x; i++){
    if(S.at(i) != T.at(i)){
      counter++;
    } 
  }
  if(counter != 0){
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

int main() {

    fast
    long long n;
    cin>>n;
    long long ans=(n*(n-1))/2;
    cout<<ans;





	return 0;
}


/*
ll  modularExponentiation(ll x,ll n,ll M)
{

    ll result=1;

    while(n>0)
    {

	if(n%2==1)

 result=(result*x)%M;

  x=(x*x)%M;

  n=n/2;

}

  return result;
}



*/


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	  
	public static void main(String args[]) {
		    Scanner scanner = new Scanner(System.in);
		    
		    String s = scanner.nextLine();
		    if( s.indexOf("a") != -1 && s.indexOf("b") != -1 
		    		&& s.indexOf("c")!= -1 )
		    {
		    	System.out.println("Yes");
		    }
		    else 
		    {
		    	System.out.println("No");
		    }
		    
		    scanner.close(); }
		  }

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int A, B, K;
vector<int> X;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> A >> B >> K;


	FOR(i,1,max(A,B) + 1){
		if(A % i == 0 && B % i == 0){
			X.push_back(i);
		}
	}

	cout << X[X.size() - K] << endl;

}

Measured memory_bytes: 256
n = int(input())
p = list(map(int,input().split()))

ans = 0
mn = 0

for i in range(n):
  if i == 0:
    ans += 1
    mn = p[i]
  elif mn >= p[i]:
    ans += 1
    mn = min(mn,p[i])

print(ans)

Measured memory_bytes: 24744
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <list>
#include <utility>
#include <tuple>
#include <cstdio>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <cmath>
#define _GLIBCXX_DEBUG
using namespace std;
const long long INF = 1LL << 60;
typedef long long ll;
int main() {
    string S;
    cin >> S;
    int size = S.size();
    vector<char> str(size);
    for(int i=0;i<size;i++){
        str[i]=S[i];
    }
    // first black 0
    vector<char> black_first(size);
    for(int i=0;i<size;i++){
        if(i%2==0){
            black_first[i]='0';
        }
        else{
            black_first[i]='1';
        }
    }
    // first white 1
    vector<char> white_first(size);
    for(int i=0;i<size;i++){
        if(i%2==0){
            white_first[i]='1';
        }
        else{
            white_first[i]='0';
        }
    }
    //
    int requireB=0;
    int requireW=0;
    for(int i=0;i<size;i++){
        if(str[i]!=white_first[i]){
            requireW++;
        }
        if(str[i]!=black_first[i]){
            requireB++;
        }
    }
    int ans = min(requireB, requireW);
    //
    cout << ans << endl;
}

Measured memory_bytes: 3816
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

X, Y = map(int, input().split())
N = X + Y
C21 = 0
C12 = 0

if N % 3 != 0 or X > 2*Y or Y > 2*X:
  print(0)
else:
  while N != 0:
    if X >= Y:
      C21 += 1
      X -= 2
      Y -= 1
      N -= 3
    else:
      C12 += 1
      X -= 1
      Y -= 2
      N -= 3
  a = cmb(C21 + C12, C21)
  print(a % (10**9 + 7))

Measured memory_bytes: 44028
#include <bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
struct edge { int to, cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int MOD = 1e9+7;
const double EPS = 1.0e-10;
const double PI = acos(-1.0);
 
const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

int main() {
	int a,b;
	cin >> a >> b;
	for(int i = 0; i <= 10000; i++){
		if((int)(i*0.08+EPS)==a && (int)(i*0.10+EPS)==b){
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}

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

typedef long long ll; typedef unsigned long long ull; typedef unsigned int uint; typedef long double ld;

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

int n;
cin >> n;
ll t;
ld ans = 1;
for (int i = 0; i < n; i++)
{
    cin >> t;
    if (ans != -1)
       ans *= t;
    if (ans > 1000000000000000000 || ans < 0)
       ans = -1;
    if (t == 0)
       ans = 0;
}
cout << (ll)ans;
return 0;
}


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

int main(){
  int a, b, c, r;
  string ans = "No";
    cin >> a >> b >> c >> r;
    if(abs(a-c)<=r || (abs(b-c)<=r && abs(a-b)<=r)) ans = "Yes";
    cout << ans << endl;
}


Measured memory_bytes: 256
n = gets.to_i
s = []

n.times do
	s.push(gets.split("").sort.join)
end

s.sort!
sum = 0
buff = s[0]
combo = 1
1.upto(n-1) do |i|
	if buff == s[i] then
		sum += combo
		combo += 1
	else
		buff = s[i]
		combo = 1
	end
end

print(sum)

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

vector<INT>v;
set<INT>s;

INT fun(INT n,INT k)
{
    INT a,b;
    a=n%10;
    if(a!=0)
    {
        if(binary_search(v.begin(),v.end(),n*10+a-1)==false)
        {
            v.push_back(n*10+a-1);
            s.insert(n*10+a-1);
            k++;
        }
    }
    if(binary_search(v.begin(),v.end(),n*10+a)==false)
        v.push_back(n*10+a),k++,s.insert(n*10+a);
    if(a!=9 && binary_search(v.begin(),v.end(),n*10+a+1)==false)
        v.push_back(n*10+a+1),k++,s.insert(n*10+a+1);
    return k;
}

int main()
{
    INT n,i,a,b,c,k;
    scanf("%lld",&n);
    for(k=1;k<=8;k++)
    {
        v.push_back(k);
        s.insert(k);
    }
    v.push_back(k);
    s.insert(k);

    for(i=0;true;i++)
    {
        k=fun(v[i],k);
        if(k>=n) break;
    }

    sort(v.begin(),v.end());
    /*for(i=0;i<n;i++)
        cout<<v[i]<<" ";
    cout<<endl<<s.size()<<" "<<v.size()<<endl;*/
    printf("%lld\n",v[n-1]);
    return 0;
}


Measured memory_bytes: 5748
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> VI;
typedef vector<VI> VVI;
typedef pair<ll, ll> P;
#define FOR(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const ll INF = numeric_limits<ll>::max();
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main()
{
    int h, n; cin >> h >> n;
    VI a(n), b(n);rep(i, n) cin >> a[i] >> b[i];

    ll dp[10010]; rep(i, h+1) dp[i] = INF;
    dp[0] = 0;
    rep(i, h) {
        if (dp[i] == INF) continue;
        rep(j, n) {
            
            if (i + a[j] > h) {
                chmin(dp[h], dp[i] + b[j]);
            }else{
                chmin(dp[i + a[j]], dp[i] + b[j]);
            }
        }
    }
    cout << dp[h] << endl;
    return 0;
}

Measured memory_bytes: 3696
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String []args) throws IOException {
    	FastScanner in  = new FastScanner(System.in);
    	PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false);
    	solve(in, out);
    	in.close();
    	out.close();
    }
    static long gcd(long a, long b){ return (b==0) ? a : gcd(b, a%b); }
    static int gcd(int a, int b){ return (b==0) ? a : gcd(b, a%b); }
    
    public static int[] generatePrimes(int n) {
		boolean[] prime = new boolean[n + 1];
		Arrays.fill(prime, 2, n + 1, true);
		for (int i = 2; i * i <= n; i++)
			if (prime[i])
				for (int j = i * i; j <= n; j += i)
					prime[j] = false;
		int[] primes = new int[n + 1];
		int cnt = 0;
		for (int i = 0; i < prime.length; i++)
			if (prime[i])
				primes[cnt++] = i;
		return Arrays.copyOf(primes, cnt);
	}
    static class FastScanner{
	BufferedReader reader;
	StringTokenizer st;
	FastScanner(InputStream stream){reader=new BufferedReader(new InputStreamReader(stream));st=null;}
	String next(){while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;}
	     st = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();}
	String nextLine()  {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;}
	int    nextInt()   {return Integer.parseInt(next());}
	long   nextLong()  {return Long.parseLong(next());}
	double nextDouble(){return Double.parseDouble(next());}
	char   nextChar()  {return next().charAt(0);}
	int[]  nextIntArray(int n)         {int[] arr= new int[n];   int i=0;while(i<n){arr[i++]=nextInt();}  return arr;}
	long[] nextLongArray(int n)        {long[]arr= new long[n];  int i=0;while(i<n){arr[i++]=nextLong();} return arr;}
	int[]  nextIntArrayOneBased(int n) {int[] arr= new int[n+1]; int i=1;while(i<=n){arr[i++]=nextInt();} return arr;}
	long[] nextLongArrayOneBased(int n){long[]arr= new long[n+1];int i=1;while(i<=n){arr[i++]=nextLong();}return arr;}
	void   close(){try{reader.close();}catch(IOException e){e.printStackTrace();}}
    }
    
    /********* SOLUTION STARTS HERE ************/
    
    private static void solve(FastScanner in, PrintWriter out){
        String s1 = in.next();
        String s2 = in.next();
        int n1 = in.nextInt();
        int n2 = in.nextInt();
        String u = in.nextLine().trim();
        if(u.equals(s1)){
            out.write((n1-1)+" "+n2+"\n");
        } else {
            out.write(n1+" "+(n2-1)+"\n");
        }
        
        
    }
    
    /************* SOLUTION ENDS HERE **********/
}

Measured memory_bytes: 21076
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
const int INF = 1e9;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
#define PI 3.14159265358979323846264338327950L
#define MOD 1000000007
//setprecision(15)
int A[100000+1];
int main() {
	int N; cin >> N;
	int a[100000];
	rep(i, N) cin >> a[i];
	int tmp = a[0];
	int cnt = 1;
	while (1) {
		if (tmp == 2) {
			cout << cnt << endl; return 0;
		}
		if (A[tmp] == 1) {
			cout << "-1" << endl; return 0;
		}
		A[tmp] = 1;
		tmp = a[tmp-1];
		cnt++;
	}
	cout << "-1" << endl;
}

Measured memory_bytes: 4400
// #include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <math.h>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
using namespace std;
 
#define mt make_tuple
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(a) begin(a), end(a)
#define SZ(a) ((int)(a).size())
 
#ifdef __DEBUG
#define debug if (true)
#else
#define debug if (false)
#endif
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int dict[100005];

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

  int N;
  int t;
  int ans = 0;

  cin >> N;

  for(int i = 0; i <= 99999; ++i) {
    dict[i] = 0;
  }

  while(N--) {
    cin >> t;
    dict[t]++;
  }

  for(int i = 1; i <= 99998; ++i) {
    ans = max(ans, dict[i-1] + dict[i] + dict[i+1]); 
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    string s;
    cin >> s;
    int n = s.size();

    int dp[n + 1][2];
    rep (i, n + 1) rep (j, 2) dp[i][j] = 1e9;
    dp[0][0] = 0;
    dp[0][1] = 1;

    rep (i, n)
    {
        int now = s[i] - '0';
        dp[i + 1][0] = MIN(dp[i][0] + now, dp[i][1] + 10 - now);
        dp[i + 1][1] = MIN(dp[i][0] + now + 1, dp[i][1] + 10 - now - 1);
    }

    cout << MIN(dp[n][0], dp[n][1] + 1) << "\n";
    return 0;
}



Measured memory_bytes: 9116
#include <stdio.h>
#include <stdlib.h>

int main()
{
  int N, M;
  int *A;
  int Re, sum=0;
  A=(int*)malloc(sizeof(int)*M);
  
  scanf("%d %d", &N, &M);
  for (int i=0;i<M;i++)
    scanf(" %d", &A[i]);
  for (int i=0;i<M;i++)
    sum +=A[i];
  Re = N - sum;
  if (Re >= 0)
  	printf("%d\n", Re);
  else
    printf("%d\n", -1);
  fflush(stdout);
  free(A);
  return 0;
}

Measured memory_bytes: 1764
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>

#define ABS(x) ( (x)>0 ? x : -(x) )
#define MIN(x,y) ( (x) < (y) ? (x) : (y) )
#define MAX(x,y) ( (x) > (y) ? (x) : (y) )
#define INF 1000000000

int main()
{
	char str[100];
	char word[100];
	int count = 0;

	scanf("%s", word);

	int i, j;

	while (1)
	{
		scanf("%s", str);

		if (strcmp(str, "END_OF_TEXT") == 0)
			break;

		for (i = 0; i < strlen(str); i++)
		{
			if (str[i] >= 'A' && str[i] <= 'Z')
				str[i] ^= 0x20;
		}

		if (strcmp(word, str) == 0)
			count++;
	}

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

	return 0;
}



Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
 
 
int main() {
		vector<vector< int> > dp;
 string s,t;
	cin>>s>>t;

int n = s.size(), m= t.size();
 
	dp.assign(m+1, vector< int> (n+1,0));
	dp[0][0]=1;
	
	
	for(int i=1; i<=m; ++i){
		for(int j=1; j<=n; ++j){
			if(i==0 || j==0) dp[i][j]=0;
			
			else if(t[i-1]==s[j-1]) dp[i][j] = 1+ dp[i-1][j-1];
			else {
				dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
			}
		}
	}
	// cout<<dp[m][n]<<'\n';
	string ans="";
  long i=m;
  long j=n;
  while(i>0 && j>0){
    if(t[i-1]==s[j-1]){
      ans+= t[i-1];
      i--;
      j--;
    }
    else if(dp[i-1][j]>dp[i][j-1]){
      i--;
    }
    else{
      j--;
    }
  }
  reverse(ans.begin(),ans.end());
  cout<<ans<<endl;


	return 0;
}


Measured memory_bytes: 38628
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

from fractions import *

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


left = [A[0]]
right = [A[-1]]
for i in range(N-1):
    left.append(gcd(left[i], A[i+1]))
    right.append(gcd(right[i], A[-i-2]))


ans = max(right[-2], left[-2])
for i in range(1, N-1):
    tmp = gcd(left[i-1], right[N-i-2])
    ans = max(tmp, ans)

print(ans)

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

int main(){
    int H,W,i,j;
    while (1){
        cin >> H >> W;
        for (i =1; i <= H; i++ ){
            for (j = 1; j <= W; j++ ){

                if ( (i % 2 != 0 && j % 2 != 0) || (i % 2 == 0 && j % 2 == 0) ){
                    cout << "#";
                }
                else if ( (i % 2 != 0 && j % 2 == 0) || (i % 2 == 0 && j % 2 != 0) ){
                    cout << ".";
                }
            }
            cout << '\n';
        }
        if (H == 0 && W == 0) break;
        cout << '\n';
    }
    return 0;
}



Measured memory_bytes: 3076
#include <bits/stdc++.h>
#include <algorithm>
#include <functional>
#include <map>
#include <queue>
#include <set>
#include <stack>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i, m, n) for (ll(i) = (ll)(m); i < (ll)(n); ++i)
#define rep2(i, m, n) for (ll(i) = (ll)(n)-1; i >= (ll)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using Edge = pair<int, long long>;
using Graph = vector<vector<Edge>>;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
typedef vector<vector<vector<ll>>> mat3;
typedef vector<string> svec;
typedef vector<vector<string>> smat;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
// constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
template <class T> inline void print(T x) { cout << x << '\n'; }
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;
}

long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }

vector<pair<long long, long long>> prime_factorize(long long N) {
    vector<pair<long long, long long>> res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0;
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
        res.push_back({a, ex});
    }
    if (N != 1) res.push_back({N, 1});
    return res;
}
bool is_prime(ll x) {
    if (x <= 1) return false;
    for (ll i = 2; i * i <= x; i++)
        if (x % i == 0) return false;
    return true;
}
// ~~~~~~~~~~~~~~memo~~~~~~~~~~~~~~
// for (int i = 0; i < n; ++i)
// v ector<long long> v(n), c(n);
// cout << res << endl;
// cout << res << '\n';
// int型の2次元配列(h×w要素の)の宣言
// vector<vector<int>> data(h, vector<int>(w));
// rotate(s.begin(), s.begin() + 1, s.end());
// sort(all(a),greater<int>());
// s.substr(0,2) 先頭から2文字切り出す
// for (auto it = mp.rbegin();it != mp.rend(); ++it)
// vector<vector<vector<int>>> dp(n + 1, vector<vector<int>>(w + 1, vector<int>(k+1, 0)));

// ll dp[1005][3] = {99999999};

int main() {
    // ios::sync_with_stdio(false);
    // cin.tie(0);
    ll x;
    cin >> x;
    ll res = 0;
    rep(i,x,110000) {
        if (is_prime(i)) {
            print(i);
            exit(0);
        }

    }

    return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
int g(int c,int d){
  if(c>d)
    return g(d,c);
  if(c==0)
    return d;
  return g(d%c,c);
}
int main(){
  int64_t a,b,c,d;
  cin>>a>>b>>c>>d;
  a--;
  int64_t l=c*d/g(c,d);
  cout<<(b-b/c-b/d+b/l)-(a-a/c-a/d+a/l)<<endl;
}

Measured memory_bytes: 764
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll a,b,c,k;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    cin>>a>>b>>c>>k;
    if(k>a+b){
        print(a-(k-a-b));
    }else{
        print(min(k,a));
    }
    return 0;
}

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


def solve(n, hs):
    xs = hs[::-1]
    for i in range(n - 1):
        if xs[i] >= xs[i + 1]:
            pass
        elif xs[i] + 1 == xs[i + 1]:
            xs[i + 1] -= 1
        else:
            return False
    else:
        return all(xs[i] >= xs[i + 1] for i in range(n - 1))


def main():
    n = int(input())
    hs = [int(h) for h in input().split()]
    res = solve(n, hs)
    print("Yes" if res else "No")


if __name__ == "__main__":
    main()


Measured memory_bytes: 14396
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

LL N;
std::vector<LL>A;

LL f(LL b)
{
	LL res = 0;
	rep(i, N) res += abs(A[i] - b);
	return res;
}

int main()
{
	in >> N;
	A.resize(N);
	rep(i, N)
	{
		in >> A[i];
		A[i] -= i;
	}
	LL l = -1123456789, r = 1123456789;
	while (r - l > 1)
	{
		LL m = (l + r) / 2;
		if (f(m - 1) < f(m + 1)) r = m;
		else l = m;
	}
	out << std::min(f(l), f(r)) << std::endl;
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mpair make_pair
#define pm(first, second) pb(mpair(first, second))
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()
#define rall(X) (X).rbegin(), (X).rend()
#define divcel(a, b) (((a) + ((b) - 1)) / (b))

int main(){

	int M, D;
	cin >> M >> D;
	int ans = 0;
	for(int m = 1; m <= M; m++){
		for(int d = 1; d <= D; d++){
			if(d%10 >= 2 && (d/10)%10 >= 2 && (d%10)*((d/10)%10) == m)ans++;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3580
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

const int MAX = 111;
int N;
PLL points[MAX];

int main(void) {
    cin >> N;
    REP(i, N) {
        cin >> points[i].first >> points[i].second;
    }

    sort(points, points + N, [&](const auto &l, const auto &r) {
        return atan2(l.second, l.first) < atan2(r.second, r.first);
    });

    LL ans = 0;
    REP(i, N) {
        LL cur_x = 0, cur_y = 0;
        FOR(j, i, N + i) {
            cur_x += points[j % N].first;
            cur_y += points[j % N].second;
            chmax(ans, cur_x * cur_x + cur_y * cur_y);
        }
    }

    cout << fixed << setprecision(30) << sqrtl(ans) << endl;
}


Measured memory_bytes: 384
import java.util.*;


public class Main{
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int q = sc.nextInt();
		
		
		for(int i = 0; i < q; i++) {
			String x = sc.next();
			String y = sc.next();
			System.out.println(LCS(x,y));
		}//for
	}//main
	
	
	
	static int LCS(String x, String y) {
		int [][] arr = new int[x.length() + 1] [y.length() +1];
		for (int i = 1; i < x.length()+1; i++) {
			for(int j = 1; j < y.length()+1; j++) {
				if(x.charAt(i-1) != y.charAt(j-1)) {
					arr[i][j] = Math.max(arr[i-1][j],arr[i][j-1]);
				} //if
				else {
					arr[i][j] = 1+arr[i-1][j-1];
				}//else
			}//for j
		}//for i
		return arr[x.length()][y.length()];
	}//LCS
		
}//class



Measured memory_bytes: 65368
A = gets.to_i
B = gets.to_i
C = gets.to_i
X = gets.to_i
cnt = 0
for i in 0..A
  for j in 0..B
    for k in 0..C
      cnt += 1 if i * 500 + j * 100 + k * 50 == X
    end
  end
end
puts cnt

Measured memory_bytes: 1788
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>
#include<limits>
#include<iomanip>
#include<cassert>

using namespace std;

typedef long long ll;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;

#define debug(x) cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n-1;i >= 0;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second

const long double pi = 3.141592653589793;
const int mod = 1e9 + 7;

int count_bits(int x) {
  int ct=0;
  while(x>0) {
    ct+=(x%2);
    x >>= 1;
  }
  return ct;
}

int solve_for(int temp) {
  int ans = 0;
  while (temp > 0) {
    temp = temp % count_bits(temp);
    ans += 1;
  }
  return ans;
}

int main() {

 // freopen("input.in","r",stdin);
 // freopen("output.out","w",stdout);

 ios_base::sync_with_stdio(false);
 cin.tie(NULL);

 int N;cin>>N;
 string s;cin>>s;
 int pc = 0;
 rep(i,N) pc += (s[i] == '1');

 if(pc == 0) {
   rep(i,N) cout<<1<<endl;
   return 0;
 }
 if(pc == 1) {
   rep(i,N) {
     if(s[i] == '1') cout<<0<<endl;
     else if(i == (N-1) || s[N-1] == '1') {
       cout<<2<<endl;
     } else {
       cout<<1<<endl;
     }
   }
   return 0;
 }

 // pc+1
 int x = pc+1, y = pc-1;
 vector<int> A(N,0), B(N,0);

 A[N-1]=B[N-1]=1;
 for(int i = N-2;i >= 0;i--) {
   A[i] = (2LL*A[i+1])%x;
   B[i] = (2LL*B[i+1])%y;
 }

 int xx = 0, yy = 0;
 for(int i = 0;i < N;i++) {
   if(s[i] == '1') {
     xx = (xx+A[i])%x;
     yy = (yy+B[i])%y;
   }
 }

 for(int i = 0;i < N;i++) {
   if(s[i] == '0') {
     int temp = (A[i]+xx)%x;
     cout << 1 + solve_for(temp) << endl;
   } else {
     int temp = (yy-B[i])%y;
     if(temp < 0) temp += y;
     cout << 1 + solve_for(temp) << endl;
   }
 }

 return 0;
}


Measured memory_bytes: 5172
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

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

    int n;
    cin >> n;
    vector<int> a(n), sum(n + 1);
    REP(i, n) {
        cin >> a[i];
        sum[i + 1] = a[i] + sum[i];
    }

    int num = 0;
    int diff = 0;
    // +-+-+-...
    REP(i, n) {
        int s = sum[i + 1] + diff;
        if (i % 2 == 0) {
            if (s <= 0) {
                diff += 1 - s;
                num += abs(1 - s);
            }
        } else {
            if (s >= 0) {
                diff += -1 - s;
                num += abs(-1 - s);
            }
        }
    }

    int ans = num;
    num = 0;
    diff = 0;
    // -+-+-+...
    REP(i, n) {
        int s = sum[i + 1] + diff;
        if (i % 2 == 1) {
            if (s <= 0) {
                diff += 1 - s;
                num += abs(1 - s);
            }
        } else {
            if (s >= 0) {
                diff += -1 - s;
                num += abs(-1 - s);
            }
        }
    }
    ans = min(ans, num);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
const int INF=1e9;
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define fi first
#define sc second
#define mp make_pair
int dx[]={-1,1,0,0};
int dy[]={0,0,1,-1};
int h,w;
int dist[1010][1010];
string s[1010];
int main(){
	cin>>h>>w;
	int ch,cw,dh,dw;
	cin>>ch>>cw>>dh>>dw;
	ch--;cw--;dh--;dw--;
	rep(i,h){
		cin>>s[i];
	}
	rep(i,h)rep(j,w)dist[i][j]=INF;
	deque<pii> q;
	dist[ch][cw]=0;
	q.push_back(mp(ch,cw));
	while(!q.empty()){
		pii p=q.front();
		q.pop_front();
		int x=p.fi,y=p.sc;
		rep(i,4){
			int xx=x+dx[i],yy=y+dy[i];
			if(xx<0||xx>=h||yy<0||yy>=w){
				continue;
			}
			if(s[xx][yy]=='#'){
				continue;
			}
			if(dist[xx][yy]<=dist[x][y]){
				continue;
			}
			dist[xx][yy]=dist[x][y];
			q.push_front(mp(xx,yy));
		}
		for(int i=x-2;i<=x+2;i++){
			for(int j=y-2;j<=y+2;j++){
				if(i<0||i>=h||j<0||j>=w){
					continue;
				}
				if(s[i][j]=='#'){
					continue;
				}
				if(dist[i][j]<=dist[x][y]+1){
					continue;
				}
				dist[i][j]=dist[x][y]+1;
				q.push_back(mp(i,j));
			}
		}
	}
	if(dist[dh][dw]==INF){
		cout<<-1;
		return 0;
	}
	cout<<dist[dh][dw];
	return 0;
}

Measured memory_bytes: 9444
#include <iostream>
using namespace std;
//input N, A..Anを受け取る
int N;
int A[210];
int main(){

    cin >> N;
    for (int i = 0; i < N; ++i) cin >> A[i];

    int res = 0;

    while (true) {
        bool exist_odd = false;  // A[i] がすべて偶数かどうかを判定するフラグ
        for (int i = 0; i < N; ++i) {
            if (A[i] % 2 != 0) exist_odd = true;  // 奇数があったらフラグを立てる
        }

        if (exist_odd) break;  // 奇数があったら break

        // 操作を行えるなら操作を実際に行う
        for (int i = 0; i < N; ++i) {
            A[i] /= 2;
        }
        ++res;  // 操作回数をインクリメント
    }

    cout << res << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define INF 1e9+7
using namespace std;
typedef long long int ll;


int main() {

	char c[4];
	cin >> c;
	for (int i = 0; i < 3; i++) {
		if (c[i] == '1') { c[i] = '9'; }
		else if(c[i]=='9'){
			c[i] = '1';
		}
	}

	cout << c << endl;

	return 0;
}


Measured memory_bytes: 256
from itertools import permutations, combinations,combinations_with_replacement,product
n = int(input())
d = list(map(int,input().split()))
time = [0 for i in range(13)]
for i in range(n):
    time[d[i]] += 1
    if d[i] == 0:
        print(0)
        exit()

kouho = [0]
doti = []
for i in range(13):
    if time[i] >= 3:
        print(0)
        exit()
    elif time[i] == 2:
        kouho.append(i)
        kouho.append(24-i)
    elif time[i] == 1:
        doti.append((i,24-i))


ans = 0
for i in range(2**len(doti)):
    kar = []
    for j in range(len(doti)):
        kar.append(doti[j][i>>j&1])
    c = kouho[:] + kar[:]
    now = 12
    p = list(combinations(c,2))
    for a , b in p:
        now = min(now,min(abs(a-b),24-abs(a-b)))
        
    ans = max(ans,now)
print(ans)

Measured memory_bytes: 9252
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//{akari : 1D, yukari : 2D, maki : 3D} vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//{akane : ascending order, aoi : decending order} priority queue
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Libraries ---------------------------------//

//------------------------------- Dubug Functions ---------------------------//

inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}

//------------------------------- Solver ------------------------------------//

void solve()
{
    i64 n, k;
    cin >> n >> k;
    n = n % k;
    cout << min(n, abs(n - k)) << endl;
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 256
//(UNCOMMENT WHEN SUBMITTING)
//#pragma GCC optimize("O3")

//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
// #pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN NEEDED)
// #pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>

// clang-format off
#define range(i) for (int _ = 0; _ < i; _++)
#define vprnt(v) for (auto vi : v) cout << vi << " "; cout << endl;
#define fastio() ios::sync_with_stdio(false); cin.tie(0)
#define ll long long
#define all(x) (x).begin(), (x).end()
using namespace ::std;
int nxt() {int x;cin >> x;return x;}
ll nxtll() {ll x;cin >> x;return x;}
// clang-format on

int main() {
    fastio();
    ll K = nxtll();

    set<ll> visit;
    ll last = -1;
    ll curr = 7;
    int count = 0;
    if (K % 2 == 0) {
        cout << -1 << endl;
        return 0;
    }

    while (visit.find(last) == visit.end() && last != 0) {
        // cout << curr << " : " << last << endl;
        visit.emplace(last);
        last = curr % K;
        curr = 10LL * last + 7LL;
        count++;
    }

    if (last == 0) {
        cout << count << endl;
    } else {
        cout << -1 << endl;
    }

    return 0;
}


Measured memory_bytes: 50492
<?php
fscanf(STDIN, "%d", $N);
$A = explode(' ',  trim(fgets(STDIN)));
$c = array_count_values($A);
$d = [];
foreach ($c as $k => $v) {
    $c[$k] = $v * ($v - 1) / 2;
    $d[$k] = ($v - 2) * ($v - 1) / 2;
}
// var_dump($c);
$sum = array_sum($c);
$ans = [];
for ($i = 0; $i < $N; $i++) {
    $ans[] = $sum - ($c[$A[$i]] - $d[$A[$i]]);
}
echo implode(PHP_EOL, $ans);


Measured memory_bytes: 41216
#include <stdio.h>
#include <map>
#include <algorithm>
#include <vector>
#include <queue>

#define INF 1 << 29
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)

using namespace std;

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

int abs(int x){
  return x > 0 ? x : -x;
}

int length(char c[]){
  int cnt=0;
  for(cnt=0;c[cnt]!='\0';cnt++){
  }
  return cnt;
}



int main(){
  int a[100000],n;
  map<int,int> mp;
  int sum =0;
  scanf("%d",&n);
  REP(i,n){
    scanf("%d",&a[i]);
    if(mp.find(a[i])!=mp.end()){
      mp[a[i]]++;
    }else{
      mp[a[i]]=1;
    }
  }
  for(auto mp_ite=mp.begin();mp_ite!=mp.end();mp_ite++){
    if(mp_ite->first>mp_ite->second){
      sum+=mp_ite->second;
    }else if(mp_ite->first<mp_ite->second){
      sum+=mp_ite->second-mp_ite->first;
    }
  }
  printf("%d\n",sum);
  return 0;
}


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

using namespace std;
using ll = long long;

int main() {
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  vector<int> counts(n, 0);
  vector<int> ls(n), rs(n);
  rep(i, q) { cin >> ls[i] >> rs[i]; }
  counts[0] = 0;
  for (int i = 1; i < n; i++) {
    if (s[i - 1] == 'A' && s[i] == 'C') {
      counts[i] += counts[i - 1] + 1;
    } else {
      counts[i] = counts[i - 1];
    }
  }
  rep(i, q) { cout << counts[rs[i] - 1] - counts[ls[i] - 1] << endl; }
  return 0;
}


Measured memory_bytes: 4536
/*
NOTE :
*min_element(.begin(),.end())
*max_element(.begin(),.end())
stack push pop top
queue push pop front
priority_queue<> pq
 push()  pop() size()  top()
map<>
 find() begin() end() insert(map<>::value_type())
pair<>
sort(.begin(), .end())
sort(arr, arr+N)
sort(a, a+N, greater<int>())
binary_search(vc.begin(), vc.end(), x)  //binary_search???true, false?????????
vector<int>::iterator lit = lower_bound(vc.begin(), vc.end(), x);
  lower_bound?????????????????????"??\???"????????????????????????????????????????????¬???????????????
vector<int>::iterator uit = upper_bound(vc.begin(), vc.end(), x);
  upper_bound????????????????????????"?¶???????"?????????????????????????????????????????¬???????????????
*/
#include <iostream>
#include <cstdio>
#include <climits>
#include <cmath>
#include <cassert>
#include <sstream>
#include <algorithm>
#include <valarray>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>

#define MAX 100
#define INF 1<<20
#define LLINF 10e12 // 1<<31 // 2^31
#define REP(i,n) for(int i=0;i<n;i++)
#define REP2(i,a,n) for(int i=(a);i<(n);i++)
#define SET(a,c) memset(a,c,sizeof a)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FOREACH(i,c) for(auto (i) : (c))
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique(ALL((o))), (o).end());

using namespace std;
typedef long long ll;
typedef valarray<int> array_t;
/////

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // FROM HERE
  string str; getline(cin,str);
  REP(i,str.length())
  {
    if(str[i] == '.' || str[i] == ' ') printf("%c",str[i]);
    else printf("%c",(str[i]-'a'+'A'));
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 1188
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

typedef long long int64;

typedef double float64;
typedef long double float128;

const int kMaxN = 1e5+5, kInf = 0x3f3f3f3f;

int val[3][3];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    for (int i = 0; i < 3; i += 1) {
        for (int j = 0; j < 3; j += 1) {
            cin >> val[i][j];
        }
    }

    bool k = false;
    for (int a0 = -300; a0 <= 300; a0 += 1) {
        int b[3] = {val[0][0] - a0, val[0][1] - a0, val[0][2] - a0};
        int a[3] = {val[0][0] - b[0], val[1][0] - b[0], val[2][0] - b[0]};
        
        bool ok = true;
        for (int i = 0; i < 3; i += 1) {
            for (int j = 0; j < 3; j += 1) {
                if (a[i] + b[j] != val[i][j]) {
                    ok = false;
                }
            }
        }

        k |= ok;
    }

    if (k) { cout << "Yes\n"; } else { cout << "No\n"; }
    return 0;
}


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

using namespace std;
const double PI (acos(-1));


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

 if(N == M)
 {
   cout << "Yes";
 }else
 {
   cout << "No";
 }
 
}


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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

// a^b mod M
long myPow(long a,long b,int M) {
    long ret = 1;
    long tmp = a;
    while(b>0) {
        if((b&1)==1) ret = (ret * tmp) % M;
        tmp = (tmp * tmp) % M;
        b = b>>1;
    }
    return ret;
}

 // nCk mod M
int nCk(int n,int k,int M) {
    long ret = 1;
    int mi = min(k, n-k);
    for(int i=1;i<=mi;i++) {
        ret = (ret * myPow(i,M-2,M)) % M;
    }
    for(int i=n-mi+1;i<=n;i++) {
        ret = (ret * i) % M;
    }
    return (int)ret;
};

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}


int main() {
    int N,A,B;
    cin >> N >> A >> B;
    
    string s;
    cin >> s;

    int now = 0;
    int b_now=0;
    REP(i,s.size()) {
        if(s[i]=='a') {
            if(now < A + B) {
                pl("Yes")
                now++;
            } else {
                pl("No")
            }
        } else if(s[i]=='b') {
            if(now < A + B && b_now < B) {
                pl("Yes")
                now++;
                b_now++;
            } else {
                pl("No")
            }
        } else {
            pl("No")
        }
    }

    return 0;
}

Measured memory_bytes: 896