akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
int n, q, a, b, cnt[N], vis[N];
vector< vector<int> >Adj(N);
void dfs(int u, int sum)
{
    cnt[u] += sum, sum = cnt[u], vis[u] = 1;
    for(auto it : Adj[u])
        if(!vis[it])
            dfs(it, sum);
}
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> q;
    for(int i = 1;i < n;++i)
        cin >> a >> b, Adj[a].push_back(b), Adj[b].push_back(a);
    while(q--)
        cin >> a >> b, cnt[a] += b;
    dfs(1, 0);
    for(int i = 1;i <= n;++i)
        cout << cnt[i] << ' ';
    return 0;
}


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

using namespace std;

typedef long long int ll;
typedef long double ld;
typedef string str;
typedef vector<char> vc;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<ll> vll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define fin(ans) cout << (ans) << endl;
#define all(a) a.begin(), a.end()

template <typename T>
T Sum(vector<T> n, ll a = 0, ll b = 0)
{
  if (b == 0)
  {
    return (accumulate(n.begin() + a, n.end(), 0));
  }
  else
  {
    return (accumulate(n.begin() + a, n.begin() + b, 0));
  }
}
template <>
ld Sum(vector<ld> n, ll a, ll b)
{
  if (b == 0)
  {
    return (accumulate(n.begin() + a, n.end(), 0));
  }
  else
  {
    return (accumulate(n.begin() + a, n.begin() + b, 0));
  }
}

template <typename T>
void Sort(T &n, ll a = 0, ll b = 0)
{
  if (b == 0)
  {
    return (sort(n.begin() + a, n.end()));
  }
  else
  {
    return (sort(n.begin() + a, n.begin() + b));
  }
}

template <typename T>
void Reve(T &n, ll a = 0, ll b = 0)
{
  if (b == 0)
  {
    return (reverse(n.begin() + a, n.end()));
  }
  else
  {
    return (reverse(n.begin() + a, n.begin() + b));
  }
}

template <typename T>
void V(T &n)
{
  for (ll i = 0; i < n.size(); i++)
  {
    cin >> n[i];
  }
}

template <typename T, typename U>
void V2(T &n, U &m)
{
  for (ll i = 0; i < n.size(); i++)
  {
    cin >> n[i] >> m[i];
  }
}

template <typename T, typename U, typename W>
void V3(T &n, U &m, W &p)
{
  for (ll i = 0; i < n.size(); i++)
  {
    cin >> n[i] >> m[i] >> p[i];
  }
}

void fYn(bool a)
{
  if (a)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  exit(0);
}
//最大公約数
ll gcd(ll a, ll b)
{
  return b ? gcd(b, a % b) : a;
}
//最小公倍数
ll lcm(ll a, ll b)
{
  return a * b / gcd(a, b);
}
//複数個の最小公倍数
ll nlcm(vector<ll> numbers)
{
  ll res;
  res = numbers[0];
  for (ll i = 1; i < numbers.size(); i++)
  {
    res = lcm(res, numbers[i]);
  }
  return res;
}
//累乗(xのn乗%mod)
ll mod_pow(ll x, ll n, ll mod = MAX)
{
  ll res = 1;
  while (n > 0)
  {
    if (n & 1)
      res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}

//大文字->小文字(+32)
//少数はなるべく整数に

void Main()
{
  ll a, b, c;
  cin >> a >> b >> c;
  c = c - (a - b);
  if(c < 0) fin(0)
  else fin(c)
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20);
  Main();
  return 0;
}


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

const int MOD = 1000000007;
const int INF = 1e9;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n, i##_len=(n); i>=0; i--)
#define FOR(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)

//最大公約数 
 ll gcd(ll a,ll b){
 if(b == 0) return a;
 return gcd(b,a%b);
 }

//最小公倍数
 ll lcm(ll a,ll b){
 ll g = gcd(a,b);
 return a / g * b; // Be careful not to overflow  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
} 





int main(){
  int N;
  cin >> N;
  vector<int>ans(N);
  REP(i, N){
    int x;
    cin >> x;
    ans.at(x - 1) = i + 1;
  }
  REP(i, N){
    cout << ans.at(i);
    if(i < N - 1) cout << " ";
  }
cout << endl;

}

Measured memory_bytes: 1152
n = int(input())
time_li = list(map(int, input().split()))
m = int(input())
drink_li = []
for i in range(m):
    drink_li.append(list(map(int,input().split())))

reg_sum = sum(time_li)

for item in drink_li:
    id = item[0] - 1
    diffrence = item[1] - time_li[id]
    print(reg_sum + diffrence)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

vector<vector<vector<double>>> dp(301,vector<vector<double>> (301, vector<double>(301,-1)));
ll n;

double res(ll n1,ll n2,ll n3) {
  if(dp[n1][n2][n3]>-1) return dp[n1][n2][n3];
  else {
    dp[n1][n2][n3]=double(n);
    if(n3>0) {
      dp[n1][n2][n3]+=res(n1,n2+1,n3-1)*n3;
    }
    if(n2>0) {
      dp[n1][n2][n3]+=res(n1+1,n2-1,n3)*n2;
    }
    if(n1>0) {
      dp[n1][n2][n3]+=res(n1-1,n2,n3)*n1;
    }
    dp[n1][n2][n3]*=1.0/(n1+n2+n3);
    return dp[n1][n2][n3];
  }
}

int main() {
  dp[0][0][0]=0.0;
  cin >> n;
  vec num(3,0);
  for(ll i=0;i<n;i++) {
    ll tmp;
    cin >> tmp;
    num[tmp-1]++;
  }
  cout << fixed << setprecision(10) << res(num[0],num[1],num[2]) << endl;
}

Measured memory_bytes: 216960
import java.util.*;

public class Main {

	private static boolean[] visited;
	private static List<int[]>[] g;
	private static int[] answer;
	private static int k;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		k = 0;
		answer = new int[n - 1];

		g = new ArrayList[n];
		for (int i = 0; i < n; i++) {
			g[i] = new ArrayList<>();
		}

		for (int i = 0; i < n - 1; i++) {
			int a = sc.nextInt() - 1;
			int b = sc.nextInt() - 1;
			g[a].add(new int[]{b, i});
			g[b].add(new int[]{a, i});
		}

		visited = new boolean[n];
		Arrays.fill(visited, false);

		for (int i = 0; i < n; i++) {
			if (!visited[i]) dfs(i, -1, 0);
		}

		System.out.println(k);
		for (int i = 0; i < answer.length; i++) {
			System.out.println(answer[i]);
		}
	}

	private static void dfs(int x, int p, int c) {
		if (visited[x]) return;
		visited[x] = true;

		int n = g[x].size();
		k = Math.max(k, n);

		int color = 1;

		for (int i = 0; i < n; i++) {
			if (visited[g[x].get(i)[0]]) continue;
			if (color == c) color++;
			answer[g[x].get(i)[1]] = color;
			dfs(g[x].get(i)[0], x, color);
			color++;
		}
	}
}


Measured memory_bytes: 101892
using System;

class Program {
    private static int Main() {
        var input = Console.ReadLine();
        var values = input.Split( ' ' );

        int a = int.Parse( values[ 0 ] );
        int b = int.Parse( values[ 1 ] );
        int c = int.Parse( values[ 2 ] );

        int cnt = 0;
        for( int i = a; i <= b; ++i ) {
            if( c % i == 0 ) { ++cnt; }
        }

        var output = string.Format( "{0}", cnt );
        Console.WriteLine( output );

        return 0;
    }
}

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

int main(){

  int N;
  unsigned long long sum = 0;

  cin >> N ;

  for(int i = 1; i <= N; i++){
    if(i % 3 != 0 && i % 5 != 0){
      sum += i;
    }
  }

  cout << sum << endl;
}

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

using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define sz(v) (int)v.size()
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;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
const char EOL = '\n';

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n, u, v;
    cin >> n >> u >> v;
    u--; v--;
    vector<vector<int>> t(n, vector<int>());
    int a, b;
    REP(i, n - 1) {
        cin >> a >> b;
        a--; b--;
        t[a].emplace_back(b);
        t[b].emplace_back(a);
    }

    vector<int> dist(n, 0);
    function<void(int, int, int)> dfs = [&](int c, int p, int d) {
        dist[c] = d;
        if (p != -1 && sz(t[c]) == 1) return;
        for (int x : t[c]) {
            if (x == p) continue;
            dfs(x, c, d + 1);
        }
    };
    dfs(v, -1, 0);
    int ans = 0;
    function<void(int, int, int)> dfst = [&](int c, int p, int d) {
        if (dist[c] == d) {
            chmax(ans, d - 1);
            return;
        }
        if (sz(t[c]) == 1) {
            chmax(ans, dist[c] - 1);
            if (p != -1) return;
        }
        for (int x : t[c]) {
            if (x == p) continue;
            if (dist[x] < d + 1) {
                continue;
            }
            dfst(x, c, d + 1);
        }
    };
    dfst(u, -1, 0);
    cout << ans << EOL;
}


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]C - Chocolate Bar
            var line = ReadLine();
            long h = line[0];
            long w = line[1];

            long min = h;

            if (h % 3 == 0 | w % 3 == 0)
            {
                min = 0;
            }
            else if (h > w)
            {
                min = w;
            }
            
            for(int y = 1; y < h; y++)
            {
                var s = new long[3];

                s[0] = y * w;
                s[1] = (h - y) * (w / 2);
                s[2] = h * w - (s[0] + s[1]);
             
                long diff = s.Max() - s.Min();

                if (diff < min)
                {
                    min = diff;
                }
            }

            for (int x = 1; x < w; x++)
            {
                var s = new long[3];

                s[0] = h * x;
                s[1] = (h / 2) * (w - x);
                s[2] = h * w - (s[0] + s[1]);

                long diff = s.Max() - s.Min();

                if (diff < min)
                {
                    min = diff;
                }
            }

            Console.WriteLine(min);
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => int.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 17488
#include<bits/stdc++.h>
using namespace std;
#define MAXN 100001
#define w 1000000007
 
int main() {
    int W, H, x , y;
    cin >> W >> H >> x >> y;
    cout << (float)W*(float)H/2. << " ";
    if(W  == 2*x && H == 2*y){
        cout << 1 << endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
N = gets.to_i
Ss = Array.new(N) { gets.chomp }


count_hash = hash = Hash.new
Ss.each do |item|
  case item
  when 'AC'
    count = count_hash['AC'] || 0
    count += 1
    count_hash['AC'] = count
  when 'WA'
    count = count_hash['WA'] || 0
    count += 1
    count_hash['WA'] = count
  when 'TLE'
    count = count_hash['TLE'] || 0
    count += 1
    count_hash['TLE'] = count
  when 'RE'
    count = count_hash['RE'] || 0
    count += 1
    count_hash['RE'] = count
  else
    raise "#{item}は無いエラー"
  end
end

puts "AC x #{count_hash['AC'] || 0}"
puts "WA x #{count_hash['WA'] || 0}"
puts "TLE x #{count_hash['TLE'] || 0}"
puts "RE x #{count_hash['RE'] || 0}"

Measured memory_bytes: 20728
#include <bits/stdc++.h>
using namespace std;
template<typename M>
bool rMin(M &a, M b) {
    return b < a ? a = b, true : false;
}
const int maxV = 1e5 + 1;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    if (fopen("input.in", "r")) {
        freopen("input.in", "r", stdin);
        freopen("output.out", "w", stdout);
    }
    int n, w;
    cin>>n>>w;
    vector<long long> dp(maxV, 1e12);
    vector<long long> nextDP(maxV);
    dp[0] = 0;
    for(int i = 0; i< n; i++){
        long long a, b;
        cin>>a>>b;
        for(int j = 0; j<maxV; j++){
            nextDP[j] = dp[j];
            if(j - b < 0) continue;
            rMin(nextDP[j], dp[j-b] + a);
        }
        dp = nextDP;
    }
    int ans = 0;
    for(int i = 0; i< maxV; i++)
        if(dp[i] <= w)
            ans = i;
    cout<<ans<<"\n";
}


Measured memory_bytes: 4716
#include <stdio.h>

char grid[2000][2000];
int score[2000][2000];

int main(void) {
	int h, w;
	scanf("%d%d ", &h, &w);

	for (int i = 0; i < h; i++) {
		gets(grid[i]);
		for (int j = 0; j < w; j++) grid[i][j] = grid[i][j] == '.';
	}

	for (int i = 0; i < h; i++) {
		int sum = 0;
		for (int j = 0; j < w; j++) {
			if (grid[i][j]) sum++;
			else sum = 0;
			score[i][j] += sum;
		}
		sum = 0;
		for (int j = w-1; j >= 0; j--) {
			if (grid[i][j]) sum++;
			else sum = 0;
			score[i][j] += sum;
		}
	}

	for (int j = 0; j < w; j++) {
		int sum = 0;
		for (int i = 0; i < h; i++) {
			if (grid[i][j]) sum++;
			else sum = 0;
			score[i][j] += sum;
		}
		sum = 0;
		for (int i = h-1; i >= 0; i--) {
			if (grid[i][j]) sum++;
			else sum = 0;
			score[i][j] += sum;
		}
	}

	int max = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (max < score[i][j]) max = score[i][j];
		}
	}
	printf("%d\n", max-3);
}


Measured memory_bytes: 19712
#include <bits/stdc++.h>
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

#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

void pre(){


}

void solve(){


}
const ll mod = 998244353;
bool p[309][309][309];
ll f[309][309];
ll dp[2][309][309];
int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
	pre();
	string s;cin>>s;
	p[0][0][0]=1;
	int n = sz(s);
	repA(i,1,n){
		rep(j,301) rep(k,301) p[i][j][k] = p[i-1][j][k];
		if(s[i-1]=='0'){
			rep(k,301) repA(j,1,300) p[i][j][k]|=p[i-1][j-1][k+1];
		}
		if(s[i-1]=='1'){
			rep(j,301) repA(k,1,300) p[i][j][k]|=p[i-1][j+1][k-1];
		}
		if(i>=2&&(s[i-2]=='0'||s[i-1]=='0')){
			rep(j,301) rep(k,301) p[i][j+1][k]|=p[i-2][j][k];
		}
		if(i>=2&&(s[i-2]=='1'||s[i-1]=='1')){
			rep(j,301) rep(k,301) p[i][j][k+1]|=p[i-2][j][k];
		}
	}
	int cnt0=0,cnt1=0;
	ll fns = 0;
	int cur = 0;
	dp[0][0][0]=1;
	rep(j,301) rep(k,301) {
		if(j) dp[0][j][k]+=dp[0][j-1][k];
		if(k) dp[0][j][k]+=dp[0][j][k-1];
		dp[0][j][k]%=mod;
	}
	repD(i,n,0){
		repA(j,cnt0,300) repA(k,cnt1,300) if(!f[j][k]&&p[i][j-cnt0][k-cnt1]){
			f[j][k]=1;
			fns+=dp[cur][j][k];
		}
		if(i){
			if(s[i-1]=='1'){
				rep(j,301) dp[1-cur][j][0] = 0;
				repA(k,1,300) dp[1-cur][0][k] = dp[cur][0][k-1];
				repA(j,1,300) repA(k,1,300) dp[1-cur][j][k]=(dp[1-cur][j-1][k]+dp[cur][j][k-1])%mod;
				cnt1++;
			}
			else{
				rep(j,301) dp[1-cur][0][j] = 0;
				repA(k,1,300) dp[1-cur][k][0] = dp[cur][k-1][0];
				repA(j,1,300) repA(k,1,300) dp[1-cur][j][k]=(dp[cur][j-1][k]+dp[1-cur][j][k-1])%mod;
				cnt0++;	
			}
			cur=1-cur;
		}
	}
	cout<<(fns+mod-1)%mod;
	return 0;
}



Measured memory_bytes: 33680
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
using namespace std;
int main(){
  string s;
  cin>>s;
  int a=0,b=0,c=0;
  bool check=true;
  if (s.size()!=3)
    check=false;
  for (int i=0;i<s.size();i++){
    if (s[i]=='a') a++;
    if (s[i]=='b') b++;
    if (s[i]=='c') c++;
  }
  if ((a == 1) and (b == 1) and (c == 1) and (check))
    cout<<"Yes";
  else
    cout<<"No"; 
  system ("pause");
  return 0;
}

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

const int MAXK = 1e5 + 10;
const int MAXN = 1e3 + 10;

int A[MAXN],dp[MAXK],N,K;

int solve(int k){

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

	if(k == 0) return dp[k] = 0;

	int ans = 0;
	for(int i = 1;i<=N;i++){
		if(A[i] > k) continue;
		if(solve(k - A[i]) == 0){
			ans = 1;
			break;
		}
	}

	return dp[k] = ans;

}

int main(){

	memset(dp,-1,sizeof(dp));
	cin >> N >> K;
	for(int i = 1;i<=N;i++){
		cin >> A[i];
	}

	if(solve(K)) printf("First\n");
	else printf("Second\n");

	return 0;

}

Measured memory_bytes: 7040
#include <bits/stdc++.h>
using namespace std;
const int N=5e5;

#define C getchar()-48
int read()
{
  int s=0,t=1,k=C;
  for (;k<0||9<k;k=C) if (k==-3) t=-1;
  for (;0<=k&&k<=9;k=C) s=(s<<1)+(s<<3)+k;
	return s*t; 
}

  int n,m,A;
  int f[N],s[N];
int main()
{
  cin>>n>>m;
  f[1]=1;
  for (int i=0;++i<=n;)
    s[i]=1;
  while (m--)
    {
      int x=read(),y=read();
      f[y]|=f[x];
      if (--s[x]==0) f[x]=0;
      ++s[y];
    }
  for (int i=0;++i<=n;)
    A+=f[i];
  cout<<A;
  exit(0);
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cmath>
#include <climits>
#include <map>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)
#define rep1(i, n) for(int i = 1; i <= (int) n; i++)
#define all(v) v.begin(),v.end()

int main() {
    ll a;
    long double b;
    cin >> a >> b;
    cout << (ll) floor(b*a) << endl;
    return 0;
}

Measured memory_bytes: 3728
A,B,C = map(int,input().split())
K = int(input())
if A < B:
    if B < C * (2**K):
        print("Yes")
    else:
        print("No")
else:
    for i in range(1,K+1):
        if A < B * (2**i):
            if B * (2**i) < C * (2**(K-i)):
                print("Yes")
                break
            else:
                print("No")
                break


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

const int N = 2e5 + 10, mod = 1e9 + 7;

long long cnt[N];
int arr[N];

int main() {
    // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int tc = 1; 
    //scanf("%d", &tc);
    while(tc--) {
        int n; scanf("%d", &n);
        long long ans = 0;
        for(int i = 0; i < n; i++) {
            int x; scanf("%d", &x);
            cnt[x]++;
            arr[i] = x;
        }
        for(int i = 1; i <= n; i++) {
            ans += cnt[i] * (cnt[i] - 1) / 2;
        }
        for(int i = 0; i < n; i++) {
            int x = arr[i];
            ans -= cnt[x] * (cnt[x] - 1) / 2;
            cnt[x]--;
            ans += cnt[x] * (cnt[x] - 1) / 2;
            printf("%lld\n", ans);
            ans -= cnt[x] * (cnt[x] - 1) / 2;
            cnt[x]++;
            ans += cnt[x] * (cnt[x] - 1) / 2;
        }
    }    
    return 0;
}

Measured memory_bytes: 3968
#include <stdio.h>

int main(){
  int n,count=0;
  scanf("%d",&n);
  int a[n],b[n],c[n-1];
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
  }for(int i=0;i<n;i++){
    scanf("%d",&b[i]);
  }
  for(int i=0;i<n;i++){
    scanf("%d",&c[i]);
  }
  
  for(int i=0;i<n-1;i++){
    if(a[i+1]-a[i]==1){
      count+=b[a[i]-1]+c[a[i]-1];
    } else{
       count+=b[a[i]-1];
    }
  }
  count+=b[a[n-1]-1];
  printf("%d",count); 
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <set>
#include <algorithm>

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=100005;
using namespace std;

ll dp[20001][256];

vector<int> c,x;

void solve(ll n, ll m){
    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= 255; j++){
            dp[i][j] = INF;
        }
    }
    dp[0][128] = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            for(int k = 0; k <= 255; k++){
                int cc = k+c[j];
                if(cc < 0) cc = 0;
                else if(cc > 255) cc = 255;
                dp[i+1][cc] = min(dp[i+1][cc], dp[i][k]+abs(x[i]-cc)*abs(x[i]-cc));
            }
        }
    }
    ll ans = INF;
    for(int i = 0; i <= 255; i++){
        ans = min(ans, dp[n][i]);
    }
    cout << ans << endl;
}

int main(){
    while(true){
        c.clear();
        x.clear();
        ll n, m;
        cin >> n >> m;
        if(n == 0 && m == 0) break;
        for(int i = 0; i < m; i++){
            int tmp;
            cin >> tmp;
            c.push_back(tmp);
        }
        for(int i = 0; i < n; i++){
            int tmp;
            cin >> tmp;
            x.push_back(tmp);
        }
        solve(n, m);
    }
    return 0;
}


Measured memory_bytes: 43232
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>
#include<stack>
#include<iomanip>

using namespace std;

#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPL(i,a,n) for(ll i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define SRTVG(v) sort(v.begin(),v.end(),greater<>())
#define SRTV(v) sort(v.begin(),v.end())
#define SRTAG(a,n) sort(a,a+n,greater<>())
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define INF LLONG_MAX/2

typedef long long ll;
typedef tuple<int,int,bool> Tb;
typedef pair<int,int> Pii;
typedef vector<int> Vi;

template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}
template<class T> void YesNo(T& a) {if(a){cout << "Yes" << ENT;}else{cout << "No" << ENT;}}
template<class T> void YESNO(T& a) {if(a){cout << "YES" << ENT;}else{cout << "NO" << ENT;}}

int atcoder(){
    int n;
    cin>>n;
    int a[55]={2,11,31,41,61,71,101,131,151,181,191,211,241,251,271,281,311,331,401,421,431,461,491,521,541,571,601,631,641,661,691,701,751,761,811,821,881,911,941,971,991,1021,1031,1051,1061,1091,1151,1171,1181,1201,1231,1291,1301,1321,1361};
    REP(i,0,n) cout<<a[i]<<" ";
    return 0;
}


signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    atcoder();
    return 0;
}




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

int main(void)
{
  std::string str;
  std::cin >> str;
  if("SUN" == str)
  {
    std::cout << '7';
  }
  if("MON" == str)
  {
    std::cout << '6';
  }
  if("TUE" == str)
  {
    std::cout << '5';
  }
  if("WED" == str)
  {
    std::cout << '4';
  }
  if("THU" == str)
  {
    std::cout << '3';
  }
  if("FRI" == str)
  {
    std::cout << '2';
  }
  if("SAT" == str)
  {
    std::cout << '1';
  }
}

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


int main() {
    int N;
  cin >> N;
  
  string Ans = "No";
  
  if(N == 1)Ans = "Yes";
  
  for(int i = 2; i < 10; i++){
    if(N%i == 0 && N/i < 10) {
      Ans = "Yes";
      break;
    }
    else continue;
  }
  
  cout << Ans << endl;
  
}


Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
keta = 1
su = 0
while True:
    su += 26**keta
    if su >= n:
        break
    keta += 1
n -= su - pow(26,keta) + 1
# print(n)
res = []
for i in range(keta):
    now = keta-i-1
    d,m = divmod(n,pow(26,now))
    res.append(chr(ord('a') + d))
    n = m
print(''.join(res))

Measured memory_bytes: 10440
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

lint m, d;

int main() {
    cin >> m >> d;

    lint ans = 0;
    for(lint mi = 1; mi <= m; mi++) {
        for(lint di = 1; di <= d; di++) {
            lint d1 = di % 10;
            lint d10 = di / 10;
            if(d1 >= 2 && d10 >= 2 && mi == d1 * d10)  ans++;
        }
    }
    cout << ans << endl;
}

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

const int N = 3e3+3;
int memo[N][N];
int n, t;
pair<int, int> arr[N];

int dp(int i, int r) {
    if (i == n || r <= 0)
        return 0;
    if (memo[i][r] != -1)
        return memo[i][r];
    return memo[i][r] = max(dp(i+1, r), dp(i+1, r-arr[i].first)+arr[i].second);
}

int main() {
    cin >> n >> t;
    for (int i=0; i<n; i++)
        cin >> arr[i].first >> arr[i].second;
    memset(memo, -1, sizeof memo);
    sort(arr, arr+n);
    cout << dp(0, t);
}

Measured memory_bytes: 35584
#include <iostream>
using namespace std;
typedef long long ll;

const int MAX = 510000;
const int MOD = 1000000007;
ll fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    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;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
    int s;
    cin >> s;
    COMinit();
    int yama = s/3, nokori = s%3;
    ll result = 0;
    for (int i=0; i<yama; i++) {
        int bou = yama-i-1, maru=nokori+i*3;
        result += COM(bou+maru, bou);
        result %= MOD;
    }
    cout << result << endl;
}

Measured memory_bytes: 15572
#include<bits/stdc++.h>
#define lld long long int
#define vec vector<lld>
#define pll pair<lld,lld>
#define pb push_back
#define ss second
#define ff first
#define mp make_pair
#define mod 1000000007
#define f(a, b) for (i = a; i < b; i++)
#define fr(a, b) for (j = a; j >= b; j--)
#define fi(a, b) for (j = a; j < b; j++)
#define fii(a, b) for (k = a; k < b; k++)
#define answer cout<<endl<<"answer : ";
#define messi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main() {messi //lld t=0;cin>>t;while(t--){
        lld n=0,m=0,k=0,i=0,j=0,p=0,q=0,x=0,y=0,z=0,ans=0,cnt=0;string s;bool flag=false;
        cin>>n; lld a[n]; for(i=0;i<n;i++) cin>>a[i];
        lld dp[n];
        for(i=0;i<n;i++) dp[i]=INT_MAX;
        dp[0]=0;
        for(i=0;i<n;i++)
        {
            if(i+1<n)
                dp[i+1]=min(dp[i+1],dp[i]+ abs(a[i]-a[i+1]));
            if(i+2<n)
                dp[i+2]=min(dp[i+2],dp[i]+ abs(a[i]-a[i+2]));
        }
        cout<<dp[n-1]<<endl;
	return 0;
}
/*  CODED BY:-
           __        __
 /\   /\  |__)  /\  |  \ |__| \ /  /\
/~~\ /~~\ |  \ /~~\ |__/ |  |  |  /~~\

*/


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define dup(x,y) (((x)+(y)-1) / (y)) //整数型のまま切り上げ演算する
#define PI 3.14159265359
typedef long long LL;
template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> inline T gcd(T x, T y) { if (y == 0) { return x; } else if (x == 0) { return y; }return gcd(y, x % y); }
template<class T> inline T lcm(T x, T y) { return (x * y) / gcd(x, y); }
template<class T> inline vector<T> convert_to_binary_number(T x) { vector<T> binary_num; while (x != 1) { binary_num.push_back(x % 2); x /= 2; } binary_num.push_back(1); return binary_num; }
template<class T> inline void print_vector(vector<T> vec) { for (int i = 0; i < vec.size(); i++) { cout << vec[i] << " "; } cout << endl;}
vector<LL> make_divisors(LL n){vector<LL> divisors;for(int i = 1; i <= sqrt(n); i++) {if(n%i == 0){divisors.push_back(i);if(i != n/i){divisors.push_back(n / i);}}}return divisors;}
const LL MOD = 1e9 + 7;
const int INF = 1 << 30;
const LL LLINF = 1LL << 60;
using namespace std;

const LL MAX_V = 1010;
const LL MAX_E = 2010;

//辺の構造体
struct edge {
    LL before_node;
    LL next_node;
    LL cost;
};

LL V, E;//V = 頂点の数, E = 辺の数
vector<LL> dp(MAX_V,LLINF);
vector<edge> edges(MAX_E);//ノードではなく辺に着目
vector<bool> negative(MAX_V, false);

void bellman_ford(LL start){
    dp[start] = 0;

    for(int v = 0; v < V; v++) {       
        for (int i = 0; i < E; i++) {
            edge e = edges[i];
            if(dp[e.before_node] != LLINF and dp[e.next_node] > dp[e.before_node] + e.cost){
                dp[e.next_node] =  dp[e.before_node] + e.cost;
            }
        }
    }
}

void find_negative_loop(){
    for (int v = 0; v < V; v++) {
        for (int i = 0; i < E; i++) {
            edge e = edges[i];
            if(dp[e.before_node] != LLINF and dp[e.next_node] > dp[e.before_node] + e.cost){
                negative[e.next_node] = true;
            }

            if(negative[e.before_node]){
                negative[e.next_node] = true;
            }
        }
    }
}

int main(void){
    cin >> V >> E;
    rep(i, E) {
        LL a, b, c;
        cin >> a >> b >> c;
        a--;b--;

        edges[i] = {a, b, -c};
    }

    bellman_ford(0);
    LL ans = dp[V - 1];
    find_negative_loop();


    if(negative[V - 1]) {
        cout << "inf" << endl;
    }else{
        cout << -ans << endl;
    }

    return 0;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
l=0
r=10**9+1
ww=[]
for i in range(n):
	ww.append(int(input()))
while l<r:
	mid=(r+l)//2
	cnt=0
	tr=1
	for i in range(n):
		w=ww[i]
		if w>mid or tr>k:
			tr=10**18
			l=mid+1
			break
		if w+cnt<=mid:
			cnt+=w
		else:
			cnt=w
			tr+=1
	if tr<=k:
		r=mid
	else:
		l=mid+1
print(l)

	



Measured memory_bytes: 9556
import collections, itertools

h, w = map(int, input().split())
a = [input() for _ in range(h)]

b = [[None] * w for _ in range(h)]
count = 0
for x in range(h):
    for y in range(w):
        if b[x][y] is not None:
            continue
        b[x][y] = count
        b[h-x-1][y] = count
        b[x][w-y-1] = count
        b[h-x-1][w-y-1] = count
        count += 1

d1 = collections.Counter(a[x][y] for x, y in itertools.product(range(h), range(w)))
d2 = collections.Counter(b[x][y] for x, y in itertools.product(range(h), range(w)))

for k2 in sorted(d2, key=lambda k: d2[k], reverse=True):
    ok = False
    v2 = d2[k2]
    for k1 in sorted(d1, key=lambda k: d1[k], reverse=True):
        v1 = d1[k1]
        if v2 <= v1:
            d1[k1] -= v2
            ok = True
            break
    if not ok:
        print('No')
        exit(0)

print('Yes')

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

namespace test
{
    class MainClass
    {
        public static void Main(string[] args)
        {

            //問題155

            int n = int.Parse(Console.ReadLine());

            List<string> s = new List<string>();

            for (int i = 0; i < n; i++)
            {
                s.Add(Console.ReadLine());
            }

            s.Sort();

            //foreach (var a in s)
            //{
            //    Console.WriteLine(a);
            //}


            List<string> ans = new List<string>();
            int ans_count = 0;
            int count = 1;


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

                if (s[i - 1] != s[i])
                {

                    if (count > ans_count)
                    {
                        //Console.WriteLine("a" + i);

                        ans.Clear();

                        ans.Add(s[i - 1]);
  

                        ans_count = count;
                    }
                    else if (count == ans_count)
                    {
                        ans.Add(s[i - 1]);
    
                    }

                    count = 1;
                }
                else
                {
                    count++;
                }

            }

            if (s[n - 2] == s[n - 1])
            {
                //count++;
            }
            else
            {
                count = 1;
            }

            if (count > ans_count)
            {
                //Console.WriteLine("a" + i);

                ans.Clear();

                ans.Add(s[n - 1]);

            }
            else if (count == ans_count)
            {
                ans.Add(s[n - 1]);

            }


            foreach (var a in ans)
            {
                Console.WriteLine(a);
            }
        }

    }





    
}


Measured memory_bytes: 41776
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        Integer N = input.nextInt();
        Integer M = input.nextInt();
        int sum = 0;
        for (int i = 0; i < M; i++) {
            sum += input.nextInt();
        }
        if (N >= sum) System.out.println(N - sum);
        else System.out.println(-1);
    }
}


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

typedef long long  ll;

ll MOD = 1000000007;
ll INF = 100000000000000000;
double PI = 3.1415926535;

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

ll GCD(ll a,ll b){
    if(a < b)return GCD(b,a);
    ll r = INF;
    while(r){
        r = a % b;
        a = b;
        b = r;
    }
    return a;
}

int main(){
  ll N;cin >> N;
  vector<ll> A(N);
  for(int i = 0;i < N;i++){
      cin >> A[i];
  }
  ll ans = 0;
  ll l = 1,r = 1;
  vector<ll> memol(N),memor(N);
  for(int i = 0;i < N;i++){
      if(i == 0){memol[i] = A[i];
      }else{
          memol[i] = GCD(memol[i-1],A[i]);
      }
  }
  for(int i = N-1;i >= 0;i--){
      if(i == N-1){memor[i] = A[i];
      }else{
          memor[i] = GCD(memor[i+1],A[i]);
      }
  }
  for(int i = 0;i < N;i++){
      ll G;
      if(i == 0){
          G = memor[1];
      }else if(i == N-1){
          G = memol[N-2];
      }else{
          G = GCD(memol[i-1],memor[i+1]);
      }
      ans = max(ans,G);
  }
  cout << ans << endl;
}


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

int main(void) {
    int K;
    cin >> K;
    int s[33] = {0, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

    for (int i = 1; i <= 32; i++) {
        if (i == K) {
            cout << s[i] <<endl;
        }
    }
}

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

int main() {
    int a,k,b;
    bool f=false;
    cin >> k;
    cin >> a >> b;

    for (int i = a; i <= b; i++){
        if (i % k == 0){
            f = true;
            break;
        }
    }
    if (f){
        cout << "OK" << endl;
    }
    else{
        cout << "NG" << endl;
    }
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sqr(x) ((x)*(x))
#define mp make_pair
#define uint unsigned
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){
	int x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(int a){
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
	write(a); puts("");
}
#define inf 1000000000000000000
long long a,b,c,k;
int main(){
	cin>>a>>b>>c>>k;
	ll t1=a-b; 
	if(k&1)cout<<(-t1)<<endl; else cout<<t1<<endl;
}
/*
a b c
b+c b c
b+c b+c+c b+b+c+c+c
*/

Measured memory_bytes: 256
N,L=map(int,input().split())
sum1=0
sum2=0
ans=0
min=100000000000000000000000000000
result=0

taste_list=[1]*N
for i in range(N):
    taste_list[i]=(L+i)
    

for i in range(N):
    sum1=sum(taste_list)
    sum2=sum(taste_list[:i])+sum(taste_list[i+1:])
    ans=abs(sum1-sum2)
    if min>ans:
        min=ans
        result=sum2
        

print(result)
    




Measured memory_bytes: 3064
package main

import "fmt"

func main(){
	var s string
	fmt.Scan(&s)
	n := len(s)
	a := make([]int,n+1)
	var con,ans int
	for i:=1 ; i<=n ; i++{
//fmt.Println(ans)
		if s[i-1:i] == "<" {
			con = 0
			a[i] = a[i-1] + 1
			ans += a[i]
		} else {
			con++
			a[i] = a[i-1] -1
			ans += a[i]
			if (i!=n && s[i:i+1] == "<") || i==n {
//fmt.Println(i,con)
				if con == 1 {
					if a[i-1] == 0 {
//fmt.Println("0")
						ans += 2
					} else {
						ans -= a[i]
					}
				} else if a[i] < 0{
					ans += (con+1)*(-a[i])
				} else {
					ans -= con*(a[i])
				}
				con = 0
				a[i] = 0
			}
		}
	}
//fmt.Println(a)
	fmt.Println(ans)
}


Measured memory_bytes: 8064
from collections import Counter

n = int(input())
s = input()
cnt = Counter(s)
ans = cnt['R'] * cnt['G'] * cnt['B']

for i in range(n):
    l = 1
    si = s[i]
    while i + l * 2 < n:
        if si != s[i + l] and si != s[i + l * 2] and s[i + l] != s[i + l * 2]:
            ans -= 1
        l += 1
print(ans)


Measured memory_bytes: 83848
#include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
using namespace std;

int main()
{
    long double x, y, z;
    cin >> x >> y >> z;
    long double d = sqrt(x) * sqrt(y);
    if (x + y + 2 * d - z < 0.0)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
}

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

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

	int N;
	int i,j;
	int ans=0;
	int ctr=0;

	cin >> N;

	if(N%2)
		ans=N/2+1;
	else
		ans=N/2;

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
int nRocher;
int tab[100005];
int memo[100005][2];
int DP(int iRocher)
{
    if(iRocher==nRocher-1)
    {
        return 0;
    }
    else if(iRocher==nRocher)
    {
        return 1000000000;
    }
    else if(memo[iRocher][1]==0)
    {
        memo[iRocher][0]=min(DP(iRocher+1)+abs(tab[iRocher]-tab[iRocher+1]),DP(iRocher+2)+abs(tab[iRocher]-tab[iRocher+2]));
        memo[iRocher][1]=1;
    }
    return memo[iRocher][0];
}
int main()
{
    scanf("%d", &nRocher);
    for(int i=0;i<nRocher;i++)
    {
        scanf("%d", &tab[i]);
    }
    printf("%d", DP(0));
}

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

import static java.lang.System.in;

public class Main {
    static long[][] selfCon, selfUncon;
    static long mod = 1000000000+7;
    static int n;
    public static void main(String[] args) throws FileNotFoundException {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i=0;i<n;i++) a[i]=sc.nextInt();
        int[] left = new int[n], right = new int[n];

        left[0]=a[0];right[n-1]=a[n-1];
        for(int i=1;i<n;i++) left[i]=gcd(left[i-1],a[i]);
        for(int i=n-2;i>=0;i--) right[i] = gcd(right[i+1],a[i]);
        int ans = Math.max(right[1],left[n-2]);
        for(int i=1;i<n-1;i++){
            int cur = gcd(left[i-1],right[i+1]);
            ans = Math.max(cur,ans);
        }
        System.out.println(ans);
    }
    static int gcd(int a, int b){
        int c;
        if(a<b){
            c = a;
            a = b; b = c;
        }
        while(a%b!=0){
            c = a%b;
            a = b; b = c;
        }
        return b;
    }
}


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


int main() {
    int N;
    long long sum_left, sum_right, sum;
    cin >> N;
    vector<long long>A(N);
    for(auto&a:A) cin>>a;

    long int min = LONG_MAX;
    for(int t=0;t<N;t++){
        sum_left = accumulate(A.begin(), A.begin()+t, 0LL);
        sum_right = accumulate(A.begin()+t, A.end(), 0LL);
        // cout << "left:" << sum_left << endl;
        // cout << "right:" << sum_right << endl;
        sum = abs(sum_left-sum_right);
        if(sum<min){
            min = sum;
        }
    }
    cout << min << endl;
    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <sstream>
#include <algorithm>
#include <fstream>
#include <list>
#include <map>
#include <istream>
#include <bitset>
#include <sstream>
#include <unordered_map>
#include <stack>
#include <set>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <queue>
#include <string>

#define int long long
#define endl "\n"
#define all(x) x.begin(),x.end()
#define rr return 0
#define xx first
#define yy second
#define pii pair<int,int>

using namespace std;

typedef long long ll;
typedef long double ld;


signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    if(s[0] == s[1]){
        cout << "Bad";
        rr;
    }else if(s[1] == s[2]){
        cout << "Bad";
        rr;
    }else if(s[2] == s[3]){
        cout << "Bad";
        rr;
    }else{
        cout << "Good";
    }
    rr;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] t = new int[n];
		int[] a = new int[n];

		for(int i=0;i<n;i++){
			t[i] = sc.nextInt();
		}
		for(int i=0;i<n;i++){
			a[i] = sc.nextInt();
		}
		sc.close();

		int[] hmax = new int[n];
		int[] hmin = new int[n];

		boolean alien = false;
		//takahashi
		hmax[0] = t[0];
		hmin[0] = t[0];
		for(int i=1;i<n;i++){
			if(t[i-1]<t[i]){
				hmax[i] = t[i];
				hmin[i] = t[i];
			} else {
				hmax[i] = t[i];
				hmin[i] = 1;
			}
		}
		if(a[n-1]>hmax[n-1]||a[n-1]<hmin[n-1]){
			System.out.println(0);
			return;
		} else {
			hmax[n-1] = a[n-1];
			hmin[n-1] = a[n-1];
		}
		for(int i=n-1;i>=1;i--){
			if(a[i-1]>a[i]){
				if(a[i-1]>hmax[i-1]||a[i-1]<hmin[i-1]){
					System.out.println(0);
					return;
				} else {
					hmax[i-1] = a[i-1];
					hmin[i-1] = a[i-1];
				}
			} else if(hmax[i-1]!=hmin[i-1]){
				hmax[i-1] = Math.min(hmax[i-1], a[i-1]);
			}
		}
		long ans = 1;
//		for(int i=0;i<n;i++){
//			System.out.print(hmax[i]+" ");
//		}
//		System.out.println();
//		for(int i=0;i<n;i++){
//			System.out.print(hmin[i]+" ");
//		}
//		System.out.println();
		for(int i=0;i<n;i++){
			long sub = (long)(hmax[i]-hmin[i]+1);
			ans *= sub;
			ans %= 1000000007;
		}
		System.out.println(ans);
	}

}

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

long long n,a,m,k,q,b,c=1;
float qq,ww,ff=2,qs;
string ss,s1,s2;
int main(){
    cin>>a>>b>>c;
    for (int i=min(a,b); i>=1; i--){
        if (a%i==0 and b%i==0){
            q++;
        }
        if (q==c){
            cout<<i<<endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Scanner;

public class Main {
	
    public static void main(String[] args) {
    	Scanner in = new Scanner(System.in);
    	
    	while(true){
				int tn = Integer.parseInt(in.nextLine());
			    if(tn == 0) break;
    			
				HashMap<String,String> c = new HashMap<String,String>();
    			for(int i=0; i < tn; i++){
    				String[] ct = in.nextLine().split(" ");
    				c.put(ct[0],ct[1]);
    			}
	    		
    			int wn = Integer.parseInt(in.nextLine());
    			StringBuilder answer = new StringBuilder(); 
    			for(int i=0; i < wn; i++){
    				String word = in.nextLine();
    				if(c.containsKey(word)){
    					answer.append(c.get(word));
    				}else{
    					answer.append(word);
    				}
    			}
             System.out.println(answer.toString());
    	}
    }
}

Measured memory_bytes: 95796
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    vll ans(50);
    ll k;
    cin >> k;
    ll x = k / 50;
    ll r = k % 50;
    rep(i, 50) {
        if (i < r) ans[i] = 49 + x + 51 - r;
        else ans[i] = 49 + x - r;
    }
    cout << 50 << endl;
    rep(i, 50) {
        if (i != 0) cout << " " << endl;
        cout << ans[i];
    }
    cout << endl;
}

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

using namespace std;

const long long INF = 1LL << 40;

int main() {
  int n;
  cin >> n;
  long long a[n], b[n], c[n];
  for(int i=1; i <= n; i++) {
    cin >> a[i] >> b[i] >> c[i];
  } 

  long long dp[n+1][3];
  dp[1][0] = a[1];
  dp[1][1] = b[1];
  dp[1][2] = c[1];

  for(int i=2; i <= n; i++) {
    dp[i][0] = max(dp[i-1][1] + a[i], dp[i-1][2] + a[i]);
    dp[i][1] = max(dp[i-1][0] + b[i], dp[i-1][2] + b[i]);
    dp[i][2] = max(dp[i-1][0] + c[i], dp[i-1][1] + c[i]);
  }

  int ans = ans = max(max(dp[n][0], dp[n][1]), dp[n][2]);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 4992
R, G, B, N = map(int, input().split())
counter = 0
r = N // R + 1
for s in range(r):
  g = (N - s*R) // G + 1
  for t in range(g):
    u = N - R*s - G*t
    if u >= 0 and u % B == 0:
      counter += 1
print(counter)

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

int main(){
  string str;
  int i, sum;
  while(1){
    cin >> str;
    if(str == "0"){
      break;
    }
    i=0;
    sum = 0;
    while(str[i]){
       sum += str[i] -'0';
       i++
;    }
     cout << sum << endl;
  }
  return 0;
}


Measured memory_bytes: 3160