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

int a[305][305];
int book[305];
int use[305];

int main()
{
    int i, j, n, m;
    cin>>n>>m;
    for(i=1; i<=n; i++)
    {
        for(j=1; j<=m; j++)scanf("%d", &a[i][j]);
        a[i][0]=1;
    }
    for(i=1; i<=m; i++)use[i]=1;
    int k, ma, ans=n, id;
    for(i=1; i<=m; i++)
    {
        memset(book, 0, sizeof book);
        for(j=1; j<=n; j++)
        {
            id=a[j][0];
            if(id<=m)book[a[j][id]]++;
        }
        k=1;
        for(int i=1; i<=m; i++)
        {
            if(book[i]>book[k])k=i;
        }
        ans=min(ans, book[k]);
        use[k]=0;
        for(int i=1; i<=n; i++)
        {
            for(; a[i][0]<=m && use[a[i][a[i][0]]]==0; a[i][0]++);
        }



    }
    cout<<ans<<endl;
    
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>
#include <set>
#include <cstdlib>
#include <queue>

using namespace std;

typedef long long llint;
typedef long double ld;
#define inf 1e18

priority_queue<int,vector<int>,greater<int>> que;


llint a,b,c;

void solve(){
	cin >> a >> b >> c;
	llint p=a*b*c;
	if(p%2==0)cout << 0 << endl;
	else{
		llint ans=min(a*b,min(a*c,b*c));
		cout << ans << endl;
	}
}

int main(int argc, char *argv[]) {
  solve();
  return 0;
}


Measured memory_bytes: 256
N, K, Q = gets.chomp.split.map(&:to_i)

if K - N >= Q*2
	(N..N+Q-1).each do |a|
		puts a
	end
	(K-Q+1..K).each do |b|
		puts b
	end
else
	(N..K).each do |c|
		puts c
	end
end


Measured memory_bytes: 3836
#include<iostream>
#include<string>
using namespace std;
string s;
int main()
{
    cin >> s;
    unsigned len=s.size();
    if(s[0]==s[len-1])
    {
        if(len%2==1) 
            cout << "Second"<<endl;
        else 
            cout << "First"<<endl;
    }
    else
    {
        if(len%2==1)
            cout << "First"<<endl;
        else 
            cout << "Second"<<endl;
    }
    return 0;
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;
int main() {
    long long A,B,C,K;//1,0,-1
    long long count=0;
    long long point=0;
    cin>>A>>B>>C>>K;
  
    if(K<=A){
      point=K;
    }else{
      point+=A;//加点
      for(int i=0;i<K-A-B;i++){     
        //C
          C--;
          point-=1;
       }
    }
    
  
    cout<<point<<endl;
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define N 100010
#define pb push_back
#define fi first
#define se second
#define si size()
#define ll long long
#define mp make_pair
#define iter ::iterator
#define all(v) v.begin(), v.end()
#define pp pop_back
#define mapiter map<int, int>::iterator
#define forn(i, n) for(int i = 0; i < n; ++i)
#define forn1(i, n) for(int i = 1; i <= n; ++i)
#define forr(i, n)	for(int i = n - 1; i >= 0; --i)
#define forr1(i, n)	for(int i = n; i >= 1; --i)
#define form(l, r, i)	for(int i = l; i <= r; ++i)
#define forv(r, l, i)	for(int i = r; i >= l; --i)
#define r0 return 0
#define barnarnar ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define lld long double
#define elif else if
 
const int inf = 1e9 + 7;
const lld EPS = 0.00000001;
const ll modwdop = 998244353ll;
 
ll pp = 13337ll;
ll modw = 1e9 + 7;
 
using namespace std;

ll dp[N];
ll n, k;

ll binpow(ll a, ll n)
{
	if(n == 0)	return 1ll;
	if(n % 2 == 1)	return (binpow(a, n - 1) * a) % modw;
	else
	{
		ll b = binpow(a, n / 2);
		return (b * b) % modw;
	}
}

ll rec(ll x)
{
    if(dp[x])	return dp[x];
    dp[x] = binpow(k / x, n);
    for(int i = x * 2; i <= k;i += x)
    {
    	dp[x] -= rec(i);
		while(dp[x] < 0ll)	dp[x] += modw;
		dp[x] %= modw; 
	}
    return dp[x];
}

int main()
{
	barnarnar
	cin >> k;
	n = 3;
	ll ans = 0;
	forr1(i, k)
	{
		ans += (i * rec(i)) % modw;
		ans %= modw;
	}
	cout << ans;
}

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

using namespace std;

#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 FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;


int main(){
  string s;
  cin>>s;
  REP(i,3){
    if(s[i]==s[i+1]){
      cout<<"Bad"<<endl;
      return 0;
    }
  }
  cout<<"Good"<<endl;
}


Measured memory_bytes: 256
N = int(input())
D = [input().split() for _ in range(N)]
zoro = [d1 == d2 for d1, d2 in D]
for i in range(N-2):
  if zoro[i] and zoro[i+1] and zoro[i+2]:
    print("Yes")
    exit()
print("No")

Measured memory_bytes: 9172
import java.util.Scanner;
public class  Main{
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int a,b,c;
    a=scan.nextInt();
    b=scan.nextInt();
    c=scan.nextInt();
    if(a>b){
      if(b>c){
        System.out.println(c+" "+b+" "+a);
      }else if (a>c){
        System.out.println(b+" "+c+" "+a);
      }else {
        System.out.println(b+" "+a+" "+c);
      }
    }else if(b>a){
      if(a>c){
        System.out.println(c+" "+a+" "+b);
      }else if(b>c){
        System.out.println(a+" "+c+" "+b);
      }else {
        System.out.println(a+" "+b+" "+c);
      }
    }
  }
}


Measured memory_bytes: 26144
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <utility>
#include <queue>
#include <ios>
#include <iomanip>
#include <ctime>
#include <tuple>

#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; i++)
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 (a > b) {a = b; return 1;} return 0; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFF
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")

#define PInt pair<int, int>
#define PLL pair<long long, long long>
#define VInt vector<int>
#define VLL vector<long long>
#define MatrixInt vector<vector<int>>
#define MatrixLL vector<vector<long long>>

typedef long long ll;
using namespace std;

int main() {
    
    int a, b, q;
    cin >> a >> b >> q;
    VLL s(a, 0), t(b, 0), x(q, 0);
    REP(i, a) cin >> s[i];
    REP(i, b) cin >> t[i];
    REP(i, q) cin >> x[i];

    sort(ALL_OF(s));
    sort(ALL_OF(t));

    REP(i, q) {

        int js = lower_bound(ALL_OF(s), x[i]) - s.begin();
        int jt = lower_bound(ALL_OF(t), x[i]) - t.begin();
        
        ll ans = 0x7FFFFFFFFFFFFFFFLL;
        chmin(ans, abs(s[js] - x[i]) + abs(s[js] - t[jt]));
        chmin(ans, abs(t[jt] - x[i]) + abs(s[js] - t[jt]));
        if (js > 0) {
            chmin(ans, abs(s[js-1] - x[i]) + abs(s[js-1] - t[jt]));
            chmin(ans, abs(t[jt] - x[i]) + abs(s[js-1] - t[jt]));
        }
        if (jt > 0) {
            chmin(ans, abs(t[jt-1] - x[i]) + abs(t[jt-1] - s[js]));
            chmin(ans, abs(s[js] - x[i]) + abs(t[jt-1] - s[js]));
        }
        if (js > 0 && jt > 0) {
            chmin(ans, abs(t[jt-1] - x[i]) + abs(t[jt-1] - s[js-1]));
            chmin(ans, abs(s[js-1] - x[i]) + abs(t[jt-1] - s[js-1]));
        }
        
        cout << ans << endl;

    }
    
}

Measured memory_bytes: 3712
#include <stdio.h>

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

int main()
{
	int64_t L, R, d;
	std::cin >> L >> R >> d;

	std::cout << R / d - (L - 1) / d << std::endl;
	return 0;
}


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

int main(){
  int H,W;
  cin >> H >> W;
  
  vector <vector<char>> pic(H+2, vector<char> (W+2)); 
  for(int i=0; i<W+2; i++){
    cout << '#';
  }
  cout << endl;
  
  for (int i=1; i<H+1; i++){
    pic.at(i).at(0) = '#';
    pic.at(i).at(W+1) = '#';
    for (int j=1; j<W+1; j++){
      cin >> pic.at(i).at(j);
    }
    for(int j=0; j<W+2; j++){
      cout << pic.at(i).at(j);
    }
  cout << endl;
  }
  
  for(int i=0; i<W+2; i++){
    cout << '#';
  }
  cout << endl;
}
    

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


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String input = br.readLine();
		if(input.contains("AC")){
			System.out.println("Yes");
		}
		else{
			System.out.println("No");
		}
	}

}


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

int main() {
int n,m,x;
cin>>n>>m>>x;
int a[m];
REP(i,m){
  cin>>a[i];
}

int left=0,right=0;
for (int i = x; i <n+1 ; i++)
{
  /* code */
  for (int j = 0; j < m; j++)
  {
    /* code */
    if (i==a[j])
  {
    /* code */
    right++;
  }
  }
}

for (int i = x; i >=0 ; i--)
{
  /* code */
  for (int j = 0; j < m; j++)
  {
    /* code */
    if (i==a[j])
  {
    /* code */
    left++;
  }
  }

}

cout<<min(left,right)<<endl;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const string EMP = " ";
const ll INF = 1LL<<60;
const ll MOD = 1000000007;
const double PI = acos(-1);

int n,m,q,ans = 0;
vector<int> a,b,c,d;

int chk(vector<int> g){
  int tt = 0;
  for(int i = 0; i < q; i++){
    if(g[b[i]] - g[a[i]] == c[i]) tt += d[i];
  }
  return tt;
}

void dfs(vector<int> g){
  if(g.size() == n){
    int now = chk(g);
    ans = max(ans, now);
    return;
  }
  for(int i = g.back(); i <= m; i++){
    g.push_back(i);
    dfs(g);
    g.pop_back();
  }
}

int main(){
  cin >> n >> m >> q;
  a.resize(q);
  b.resize(q);
  c.resize(q);
  d.resize(q);
  for(int i = 0; i < q; i++){
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    a[i]--; b[i]--;
  }
  vector<int> g;
  g.push_back(1);
  dfs(g);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3600
#include<stdio.h>

int main() {
  int i;
  scanf("%d", &i);
  float kisu = 0.f;
  for(int n = 1; n <= i; n++) {
    if(n % 2 == 1) kisu += 1.0f;
  }
  printf("%f\n", kisu/i * 1.0f);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    
    rep(i,n){
        cin >> a[i];
    }
    ll ans=0;
    rep(i,n){
        ans += a[i] -1;
    }
    cout << ans <<endl;
}

Measured memory_bytes: 256
#問題C
import numpy as np
N = int(input())
A = list(map(int,input().split())) #準備度
B = list(map(int,input().split())) #試験

A = np.array(A)
B = np.array(B)


sumA = sum(A)
sumB = sum(B)

if sumA < sumB:
    print(-1)
else:
    gap = A - B
    minus = gap[gap<0]
    numminus = len(gap[gap<0])
    if numminus == 0:
        print(0)
    else:
        needs = - minus.sum()
        sortgap = np.sort(gap)[::-1]
        s = 0
        for i in range(N):
            s += sortgap[i]
            if s >= needs:
                changedplus = i+1
                break
        print(changedplus + numminus)

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#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 FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll n;
  cin>>n;
  vll c(n);
  vvll edge(n);
  REP(i,n-1){
    ll a,b;
    cin>>a>>b;
    a--;
    b--;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }

  REP(i,n)cin>>c[i];
  sort(ALL(c));
  ll sum=0;
  REP(i,n-1)sum+=c[i];

  vll ans(n);
  ll cur=n-1;
  REP(i,n){
    if(edge[i].size()==1)
      continue;

    queue<pll> que;
    que.push(pll(i,-1));
    while(!que.empty()){
      ll v=que.front().FI;
      ll par=que.front().SE;
      que.pop();
      ans[v]=c[cur];

      for(auto e:edge[v]){
        if(e==par)
          continue;

        que.push(pll(e,v));
      }
      cur--;
    }

    break;
  }


  cout<<sum<<endl;
  cout<<ans[0];
  REP1(i,n)cout<<" "<<ans[i];
  cout<<endl;

}



Measured memory_bytes: 1280
#include<iostream>
#include<iomanip>
#include<cmath>
#include<tuple>
#include<queue>
#include<algorithm>
//s.k
 
int const MAXN = 50;
double const INF = 1e9;
double const eps = 5e-7;
int x[MAXN], y[MAXN], N;
 
double min_possible(double cx, double cy, double r) {
  double res = 0.0;
  for(int i = 0; i < N; ++i) {
    double dx = x[i] - cx, dy = y[i] - cy;
    dx = std::max(std::fabs(dx) - r, 0.0);
    dy = std::max(std::fabs(dy) - r, 0.0);
    res = std::max(res, dx*dx + dy*dy);
  }
  return std::sqrt(res);
}
 
double calc(double cx, double cy) {
  double res = 0.0;
  for(int i = 0; i < N; ++i) {
    double dx = x[i] - cx, dy = y[i] - cy;
    res = std::max(res, dx*dx + dy*dy);
  }
  return std::sqrt(res);
}
 
int main() {
  std::cin >> N;
  for(int i = 0; i < N; ++i) std::cin >> x[i] >> y[i];
  
  std::queue<std::tuple<double, double, double>> q;
  double ans = INF;
  q.emplace(500.0, 500.0, 500.0);
  while(q.size()>0) {
    double xx, yy, rr; 
    std::tie(xx, yy, rr) = q.front(); q.pop();
    double d = min_possible(xx, yy, rr);
    if(d >= ans - eps*std::max(d, 1.0)) continue; // cut-off no improve
    ans = std::min(ans, calc(xx, yy));
    for(double rx: {-0.5, 0.5}) for(double ry: {-0.5, 0.5}) {
      q.emplace(xx+rx*rr, yy+ry*rr, rr*0.5);
    }
  }
  std::cout << std::setprecision(10) << std::fixed << ans << std::endl;
  return 0;
}

Measured memory_bytes: 512
// luogu-judger-enable-o2
#include<iostream>//头文件~~~ 
using namespace std;//emm……
int main(){
    string a;   bool v[2]={0};//这个初始化害人不浅啊 
    cin>>a;//读入 
    for(int i=0;i<a.length();i++){//a[0]==>a[n-1]全部看一遍 
        if(a[i]=='C') v[0]=1;//出现了C 
        if(a[i]=='F'&&v[0])  v[1]=1;//出现了F 
    }
    if(v[1]) cout<<"Yes";//可以 
    else cout<<"No";//不行 
    return 0;
}

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

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

int R, C;
char table[32][32];
bool visited[16][20][20][4];

struct State {
  int m, r, c, d;
  bool &ref() {
    return visited[m][r][c][d];
  }
  char here() {
    return table[r][c];
  }

  State move() {
    const int dr[] = {0, -1, 0, 1};
    const int dc[] = {1, 0, -1, 0};
    State cp = *this;
    cp.r += dr[d]; cp.r %= R;
    cp.c += dc[d]; cp.c %= C;
    if (cp.r < 0) cp.r += R;
    if (cp.c < 0) cp.c += C;
    return cp;
  }

};

int main() {
  while (cin >> R >> C) {
      memset(visited, 0, sizeof(visited));
      REP(r, R) {
          cin >> table[r];
      }

      queue<State> q;
      q.push((State){0, 0, 0, 0});
      visited[0][0][0][0] = true;

      bool stoppable = false;
      while (!q.empty()) {
          State cur = q.front(); q.pop();

          switch (cur.here()) {
          case '<': cur.d = 2; break;
          case '>': cur.d = 0; break;
          case '^': cur.d = 1; break;
          case 'v': cur.d = 3; break;
          case '_': cur.d = cur.m == 0 ? 0 : 2; break;
          case '|': cur.d = cur.m == 0 ? 3 : 1; break;
          case '?': break;
          case '.': break;
          case '@': stoppable = true; break;
          case '+': cur.m = (cur.m + 1) & 15; break;
          case '-': cur.m = (cur.m + 15) & 15; break;
          default : cur.m = cur.here() - '0'; break;
          }

          if (stoppable) break;

          if (cur.here() == '?') {
              REP(d,4) {
                  cur.d = d;
                  State next = cur.move();
                  if (!next.ref()) {
                      q.push(next);
                      next.ref() = true;
                  }
              }
          } else {
              State next = cur.move();
              if (!next.ref()) {
                  q.push(next);
                  next.ref() = true;
              }
          }
      }

      cout << (stoppable ? "YES":"NO") << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<ll> X(N);
  vector<ll> Y(N);
  rep(i, N) { cin >> X[i] >> Y[i]; }

  double Ans = 0;
  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      ll x = X[i] - X[j];
      ll y = Y[i] - Y[j];
      Ans += (sqrt(x * x + y * y)) * 2 / N;
    }
  }
  cout << setprecision(16) << Ans << endl;
  return 0;
}


Measured memory_bytes: 256
CMD=0
VAL=1

class Node
  attr_accessor :value,:left,:right
  def initialize (value)
    @value = value
    @left = nil
    @right = nil
  end

  def insert (value)
    if value < @value
      if @left.nil?
        @left = Node.new(value)
      else
        @left.insert(value)
      end
    else
      if @right.nil?
        @right = Node.new(value)
      else
        @right.insert(value)
      end
    end
  end
  
  def print_inorder
    @left.print_inorder unless @left.nil?
    print " #{value}"
    @right.print_inorder unless @right.nil?
  end
  
  def print_preorder
    print " #{value}"
    @left.print_preorder unless @left.nil?
    @right.print_preorder unless @right.nil?
  end
end

num_of_cmd = STDIN.gets()
inputs = STDIN.read().split("\n").map{ |input| input.split(' ') }

root=nil
inputs.each do |input|
  if input[CMD] == 'insert'
    if root.nil?
      root = Node.new(input[VAL].to_i)
    else
      root.insert(input[VAL].to_i)
    end
  else
    root.print_inorder unless root.nil?
    print "\n"
    root.print_preorder unless root.nil?
    print "\n"
  end
end

Measured memory_bytes: 208144
#include <bits/stdc++.h>
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define dump(x) cout << #x << " = " << (x) << endl;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

#define int long long

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H, W;
  cin >> H >> W;
  vector<string> A(H);
  REP(i, H) { cin >> A[i]; }
  int sum = 0;
  REP(i, H) REP(j, W) {
    if(A[i][j] == '#') { sum++; }
  }
  if(sum == H + W - 1) {
    cout << "Possible" << endl;
  } else {
    cout << "Impossible" << endl;
  }
  return 0;
}

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

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

    long s=0;
    for(auto& e: mp) {
        long x=e.second;
        s+=x*(x-1)/2;
    }
    
    for(auto& e: a) {
        long x=mp[e];
        cout<<(s-x*(x-1)/2+(x-1)*(x-2)/2)<<'\n';
    }
}


Measured memory_bytes: 8320
def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

def main():
    from sys import stdin, setrecursionlimit
    #setrecursionlimit(10**9)
    #r = input()
    #n = int(input())
    #a, b = map(int, input().split())
    #s, y = input().split()
    #a = input().split()
    #a = [int(input()) for i in range(n)]
    #a = list(map(int, input().split()))
    #a = [list(map(int, input().split())) for i in range(n)]
    #a = [int(s) - 1 for s in input().split()]
    #l=[int(input()) for _ in range(int(input()))]
    #res = 0

    x10,x=map(int, input().split())
    x2 = Base_10_to_n(x10, x)
    print(len(x2))


    

if __name__ == '__main__':
    main()


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

int main() {
  int a, b, c;

  cin >> a >> b >> c;
  if (a != b && a != c) cout << a << endl;
  else if (b != a && b != c) cout << b << endl;
  else if (c != a && c != b) cout << c << endl;
}

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

int main(void)
{
	int ans = 0;
	int N, M; cin >> N >> M;
	vector<int> X(M), D(M-1);
	for (int i = 0; i < M; i++)cin >> X[i];
	if (N < M) {
		sort(X.begin(), X.end());
		for (int i = 0; i < M - 1; i++)D[i] = X[i + 1] - X[i];
		sort(D.begin(), D.end());
		ans = X[M - 1] - X[0];
		for (int i = M - 2; i >= M - N; i--)ans -= D[i];
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1024
def combi(n,k)
  sum = 1
  (n-k).times do|i|
    sum = sum*(i + k+1)
  end
  return sum
end


n = gets.chomp.to_i
s = []
n.times do
  s << gets.chomp
end

hash = {}

n.times do|i|
  str = s[i].chars.sort.join

  if( hash[str] == nil )
    hash[str] = 1
  else 
    hash[str] += 1
  end
end
#puts hash
sum = 0
hash.each {|name, count|
  if(count > 1) then
    sum += (count * (count-1)) /2
  end
}
puts sum


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

int main() {
	int n, x;
	scanf("%d%d", &n, &x);
	vector<int> a(n);
	rep(i, n) {
		scanf("%d", &a[i]);
	}
	sort(a.begin(), a.end());
	int ans = 0;
	rep(i, n) {
		if (x - a[i] >= 0) {
			x -= a[i];
			ans ++;
		}
	}
	if (x != 0 && ans == n) ans --;
	printf("%d\n", ans);
        return 0;
}


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

using namespace std;

int main ()
{
    string S;
    cin >> S;
    if(S.at(2) == S.at(3) && S.at(4) == S.at(5)){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath> 
#include <vector>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> player(N, 0);
  vector<int> game(M);
  for(int i=0;i<M;i++)
    cin >> game[i];
  for(int i=0;i<M;i++){
    int sum = 0;
    for(int j=0;j<N;j++){
      int a;
      cin >> a;
      if(a == game[i])
        player[j]++;
      else 
        sum++;
    }
    player[game[i]-1] += sum;
  }
  for(int i=0;i<N;i++){
    cout << player[i] << endl;
  }
  return 0;
}

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

class Baseball{

private:
	int point;
	int out;
	int base;   //0:no runner 1:runner
				//home,third,second,first

public:
	
	//constructor
	Baseball(int fir_point, int fir_out, int fir_base){
		point = fir_point;
		out = fir_out;
		base = fir_base;
	}

	//get point
	int get_point(){
		return point;
	}
	
	//get out count
	int get_out(){
		return out;
	}

	//hit
	void hit(){
		base = (base * 10) + 1;
		
		if(base >= 1000){ //home,third,second,first
			base -= 1000; 
			point += 1;	  //get one point
		}
	}
    
	//home run
	void home_run(){
		point += 1;  //batter point
		for(int i = base; i > 0; i /= 10){
			point += i%10;   //"1" count > point
		}
		base = 0;
	}
    //out
	void add_out(){
		out += 1;
	}
};	

int main(){

	int N;
	std::cin >> N;

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

		Baseball baseball(0, 0, 0);

		while(true){
			std::string str;
			std::cin >> str;

			if(str == "HIT") baseball.hit();
			
			else if(str == "HOMERUN") baseball.home_run();

			else if(str == "OUT"){
				baseball.add_out();
			
				if(baseball.get_out() == 3)
					break;
				
			}
		}
	std::cout << baseball.get_point() << std::endl;
	}

	return 0;
}

Measured memory_bytes: 1216
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }
//V,P(大文字)使用不可

const ll INF=1000000000000000000;

signed main(){
    int a,b;
    cin>>a>>b;
    cout<<fixed<<setprecision(10)<<(double)a/b<<endl;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
a = list(map(int,input().split()))
sum_a = [0]
for x in a:
    sum_a.append(sum_a[-1]+x)

ans = 0
ideal_a = [0]
for x in a:
    ideal_a.append(ideal_a[-1]+max(0,x))

for i in range(n-k+1):
    t = max(0,sum_a[i+k]-sum_a[i]) + ideal_a[n]-ideal_a[k+i]+ideal_a[i]
    #print(t)
    ans = max(t,ans)

print(ans)

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

using namespace std;

int main() {

    long long n, x, arr[int(2e5 + 5)]{};

    cin >> n;
    for (int i = 0; i < n - 1; i++)
    {
        cin >> x;
        arr[x]++;
    }
    for (int i = 1; i <= n; i++)
    {
        cout << arr[i];
        if (n != 1 && i != n)
            cout <<"\n";
    }

    return 0;
}

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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int K;
	cin >> K;
	int sum = 0;
	for (int i = 1; i <= K; i++) {
		for (int j = 1; j <= K; j++) {
			for (int g = 1; g <= K; g++) {
				sum += gcd(gcd(i, j), g);
			}
		}
	}
	cout << sum << '\n';
	
	return 0;
}

// Euclid's algorithm provides an efficient way to find
// the greatest common divisor of two numbers
int gcd(int a, int b) {
	if (b == 0) {
		return a;
	}
	return gcd(a, a % b);
}


Measured memory_bytes: 3656
def solve():
    from itertools import combinations
    N, K = map(int, input().split())
    vertices = [tuple(map(int, input().split())) for _ in [0]*N]
    sorted_v = sorted(vertices)
    result = float("inf")
 
    for l in combinations(sorted_v, min(4, K)):
        xs = sorted(x for x, y in l)
        ys = sorted(y for x, y in l)
        min_x, max_x = xs[0], xs[-1]
        min_y, max_y = ys[0], ys[-1]
        if sum(1 for x, y in vertices if min_x <= x <= max_x and min_y <= y <= max_y) >= K:
            s = (max_x-min_x)*(max_y-min_y)
            if result > s:
                result = s
 
    print(result)
 
 
if __name__ == "__main__":
    solve()

Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
int main() {
	int r, d, x[11];
	cin >> r >> d >> x[0];
	
	for (int i = 0; i < 10; i++) {
	    x[i + 1] = r * x[i] - d;
	    std::cout << x[i + 1] << std::endl;
	}
	return 0;
}

Measured memory_bytes: 256
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
long long fac[200005], finv[200005], inv[200005];
vector<long long>dij;
struct edge { long long to, cost; };
vector<vector<edge> >G;

long long mod_pow(long long a, long long b) {
	long long res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}

	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

//↑template↑


string a, b, ans;
int dp[3005][3005];
int main() {
	cin >> a >> b;
	for (int i = 0; i < a.length(); ++i) {
		for (int j = 0; j < b.length(); ++j) {
			if (a[i] == b[j]) { dp[i + 1][j + 1] = dp[i][j] + 1; }
			else { dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]); }
		}
	}

	int n = a.length(), m = b.length();
	while (n&&m) {
		if (dp[n - 1][m] == dp[n][m]) { --n; }
		else if (dp[n][m - 1] == dp[n][m]) { --m; }
		else {
			ans += a[n - 1];
			--n, --m;
		}
	}reverse(all(ans));
	cout << ans << endl;
}


Measured memory_bytes: 37120
from itertools import product

n = int(input())
s = input()

ans = 0

for cmb in product(range(10), range(10), range(10)):
    idx = -1
    for i in cmb:
        idx = s.find(str(i), idx + 1)
        if idx < 0:
            break
    else:
        ans += 1

print(ans)





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

using namespace std;

typedef long long ll;
typedef long double ld;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.setf(ios::fixed); cout.precision(20);
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    int n;
    cin >> n;
    vector <int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        --a[i];
    }
    vector <int> op;
    for (int i = 0; i < n; ++i) {
        bool fl = false;
        for (int j = (int)a.size() - 1; j >= 0; --j) {
            if (a[j] == j) {
                fl = true;
                op.push_back(j);
                a.erase(a.begin() + j);
                break;
            }
        }
        if (!fl) {
            cout << "-1\n";
            return 0;
        }
    }
    reverse(op.begin(), op.end());
    for (auto x : op) {
        cout << x + 1 << '\n';
    }
}

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

int main(){
    int h,w;
    cin>>h>>w;
    int a[h][w];
    rep(i,h) rep(j,w) cin>>a[i][j];

    vector<int> x1,y1,x2,y2;
    rep(i,h){
        if(i%2==0){
            rep(j,w){
                if(a[i][j]%2==0) continue;
                if(j!=w-1){
                    a[i][j+1]++;
                    x1.push_back(i);
                    y1.push_back(j);
                    x2.push_back(i);
                    y2.push_back(j+1);
                }
                else{
                    if(i==h-1) continue;
                    a[i+1][j]++;
                    x1.push_back(i);
                    y1.push_back(j);
                    x2.push_back(i+1);
                    y2.push_back(j);
                }
            }
        }
        else{
            for(int j=w-1;j>=0;j--){
                if(a[i][j]%2==0) continue;
                if(j!=0){
                    a[i][j-1]++;
                    x1.push_back(i);
                    y1.push_back(j);
                    x2.push_back(i);
                    y2.push_back(j-1);
                }
                else{
                    if(i==h-1) continue;
                    a[i+1][j]++;
                    x1.push_back(i);
                    y1.push_back(j);
                    x2.push_back(i+1);
                    y2.push_back(j);
                }
            }
        }
    }

    cout<<x1.size()<<endl;
    rep(i,x1.size()){
        cout<<x1[i]+1<<" "<<y1[i]+1<<" "<<x2[i]+1<<" "<<y2[i]+1<<endl;
    }

}




Measured memory_bytes: 5220
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC(T, v) static_cast<T>(v)
#define SI(v) SC(int, v.size())
#define SL(v) SC( LL, v.size())
#define RF(e, v) for(auto & e: v)
#define ei else if
#define UR assert(false)

// ---- ----

LL n, a[100000];

int main() {
	cin >> n;
	inc(i, n) { cin >> a[i]; }
	
	int c = 0;
	inc(i, n) { if(a[i] < 0) { c++; } }
	
	inc(i, n) { a[i] = abs(a[i]); }
	sort(a, a + n);
	
	LL ans = 0;
	inc(i, n) { ans += a[i]; }
	
	if(c % 2 != 0) { ans -= 2 * a[0]; }
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
typedef long long ll;


int main()
{
    double a,h,x;
    cin>>a>>h>>x;
    //cout<<atan(2*(a*a*h-x)/(a*a*a));
    if(x<a*a*h/2)
        printf("%.8f",atan(a*h*h/2/x)*(360/acos(-1))/2);
        //printf("%.8f",atan(2*x/(a*h*h))*(360/acos(-1)));
    else
        printf("%.8f",atan(2*(a*a*h-x)/(a*a*a))/2*(360/acos(-1)));
    return 0;
}


Measured memory_bytes: 256
#include <iostream>  
#include <vector>   
# define MAX 1000000
int less1[MAX];  
int v[12]={1,6,9,36,81,216,729,1296,6561,7776,46656,59049}; 
using namespace std;  
int min(int i){  
    int lessNum = MAX;  
    for (int t = 11; t>=0; t--){  
        if (i - v[t] >= 0){  
            if (lessNum > 1 + less1[i - v[t]]){  
                lessNum = 1 + less1[i - v[t]];  
            }  
        }  
    }  
    return lessNum;  
}  
int main(){  
      
    int pos = 0;   
	int item;
	cin>>item;   
    for (int i = 1; i <= item; i++){  
        less1[i] = min(i);  
    }  
    //for(int i=0;i<=item;i++) cout<<"i:"<<i<<"  "<<less1[i]<<endl;
    cout << less1[item];  
}  

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int s = 0;
		int count =0;
		for (int i=0;i<S.length();i++) {
			if (S.charAt(i)=='S') {
				s++;
			} else if(s>0) {
				s--;
				count +=2;
			}
		}
		System.out.println(S.length()-count);
	}
}

Measured memory_bytes: 40664
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <unordered_map>
using namespace std;
int main()
{
    vector<string> s(100005);
    unordered_map <string, int> mp; 
    long long i, ans=0, n, f=0, j, k;
    cin >> n;
    for(i=0;i<n;i++){
        cin >> s[i];
        sort(s[i].begin(), s[i].end());
        ans=ans+mp[s[i]];
        mp[s[i]]++;
    }

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

Measured memory_bytes: 17700
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


void dfs(int pos, int prev, ll x, vector<ll>& dist, vector<vector<pair<int,int>>>&tree) {
	dist[pos] = x;
	for (int i = 0; i < tree[pos].size(); i++) {
		if (prev != tree[pos][i].first) {
			dfs(tree[pos][i].first, pos, x + tree[pos][i].second, dist, tree);
		}
	}
}

int main() {
	int N;
	cin >> N;
	vector<vector<pair<int,int>>> tree(N + 1, vector<pair<int,int>>());
	for (int i = 0; i < N-1; i++) {
		int u, v, w;
		cin >> u >> v >> w;
		tree[u].push_back({ v,w });
		tree[v].push_back({ u,w });
	}
	vector<ll> dist(N + 1);
	dfs(1, 0, 0, dist, tree);
	for (int i = 1; i <= N; i++) {
		cout << dist[i] % 2 << endl;
	}
}

Measured memory_bytes: 7936
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define fori(i, m, n) for(int i = m; i < (int)n; i++)
#define forl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define all(v) v.begin(), v.end()
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);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string btos(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  int a,b,c;cin>>a>>b>>c;
  int mn=max(max(a,b),c);
  int ans=0;
  if(mn==a)ans=b+c;
  else if(mn==b)ans=a+c;
  else if(mn==c)ans=a+b;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
/*"for if God is with them who can be against them."
   it's beter to die struggling than to abandon the effort where there is still
   a chance of accomlishing something more..NEVER GIVE UP.
   */

/* "IF THERE IS NO WAY OUT LOOK AT THE BOTTOM". */
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define endl '\n'
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define all(a) a.begin(),a.end()
#define watch(x) cout << (#x) << " is " << (x) << endl
void solve() {
	int n;
	cin >> n;
	int a[n + 1], b[n + 1];
	REP(i, 1, n ) {
		cin >> a[i];
		b[i] = a[i];
	}
	sort(b + 1, b + n + 1);
	int k = n / 2;
	int x = b[k], y = b[k + 1];
	bool ok = false;
	if (x == y) {
		ok = true;
	}
	if (ok) {
		REP(i, 0, n - 1) {
			cout << x << endl;
		}
		return;
	}
	for (int i = 1; i <= n; i++) {
		if (a[i] <= x) {
			cout << y << endl;
		}
		else
			cout << x << endl;
	}
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
	IOS;
	int t = 1;
	//cin >> t;
	while (t--) {
		solve();
	}
#ifndef ONLINE_JUDGE
	cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
#endif
	return 0;
	/*TRY AGAIN, NO MATTER HOW MANY TIMES YOU FAILED ALWAYS TRY ONCE MORE*/
}

Measured memory_bytes: 5080
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define ull unsigned long long
#define F first
#define S second
#define eps 1e-6
#define mp make_pair
const long long INF=1e18+2;
const int MX=100004;
int N, M, k;
int arr[MX];

int main()
{
   scanf("%d", &N);
   ll an=0;
   for(int i=1;i<=N;i++)
   {
       scanf("%d", &arr[i]);
   }
   for(int i=1;i<=N;i++)
   {
       an+=arr[i]/2;
       arr[i]=arr[i]%2;
       if(arr[i] && arr[i+1]) {
        arr[i+1]--;
        ++an;
       }
   }
   cout<<an<<"\n";
    return 0 ;
}



Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int S[1000];
int top;
int pop();
void push(int);
int main(){

  int top=0;
  int a,b;
  char anos[1000];

  while(scanf("%s",anos)!=EOF){

    if(anos[0]=='+'){
      a=pop();
      b=pop();
      push(a+b);
    }

    else if(anos[0]=='*'){
      a=pop();
      b=pop();
      push(a*b);
    }

    else if(anos[0]=='-'){
      b=pop();
      a=pop();
      push(a-b);
    }
    else {
      push(atoi(anos));
    }
  }


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

  return 0;

}

int pop(){

  return S[top--];

}

void push(int x){

   top++;
   S[top]=x;

 }

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

#define NDEBUG
#include <cassert>


typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair

#define PQ(T) priority_queue<T>
#define RPQ(T) priority_queue<T,vector<T>,greater<T>>

template<class T> inline void amin(T & a, T const & b) { a = min(a, b); }
template<class T> inline void amax(T & a, T const & b) { a = max(a, b); }

inline ll square(ll x) { return x * x; }
inline ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }
template <typename T>
inline T mod(T a, T b) { return ((a % b) + b) % b; }


const ll MOD=1000003LL;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

ll NEG(ll x) { return (MOD - x) % MOD; }

ll f[MOD];

ll solve(int x, int d, int n){
    if (x == 0) return 0;
    if (d == 0) return POW(x, n);

    ll y = DIV(x, d);
    if (y+n-1 >= MOD) return 0;

    ll ans = f[y+n-1];
    if (y > 1) {
        ans = DIV(ans, f[y-1]);
    }
    ans = MUL(ans, POW(d, n));
    return ans;
}

int main() {
    f[0] = f[1] = 1;
    for(int i=2; i<MOD; ++i){
        f[i] = (f[i-1] * i) % MOD;
    }

    int Q; scanf("%d%*c", &Q);
    rep(i,Q){
        int x,d,n; scanf("%d %d %d%*c", &x, &d, &n);
        printf("%lld\n", solve(x,d,n));
    }
    return 0;
}


Measured memory_bytes: 8832
/*
  Motto - try hard to become an expert
*/
#include <bits/stdc++.h>
#include <map>
#include <algorithm>
#include <vector>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <chrono>
#include <thread>
#include <iomanip>
 
//define
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define INF (int)INT_MAX
#define all(v)  v.begin(), v.end()
#define endl "\n"
 
//typedef
typedef long long  ll;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;
 
const int N = 3*1e5 +5 ;
const long long MOD = 998244353;
const long long inf = 1e18;
 
using namespace std;
 

 
ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}
 
ll modFact(ll n, ll p) 
{ 
    if (n >= p) 
        return 0; 
  
    ll result = 1; 
    for (ll i = 1; i <= n; i++) 
        result = (result * i) % p; 
  
    return result;  
} 
 
bool isPrime(int x)
{
    if(x%2==0)
        return 0;
    for(int i=3;i<=sqrt(x);i+=2)
    {
        if(x%i==0)
            return 0;
    }
    return 1;
}
float slope(float x1 , float y1  , float x2 , float y2){

	if(x1==x2) return 0 ;
	return (y2-y1)/(x2-x1) ;
}
void solve()
{
	ll n ; 
	cin>>n ; 
	ll ans = 0 ;
	
	for(ll i = 1 ; i<=n;i++){
		for(ll j = 1 ; j<=n; j++){
			for(ll k =1 ;  k<=n; k++){
				ans += __gcd(i , __gcd(j , k));
			}
		}
	}
	cout<<ans<<endl;

}
 
int main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t = 1;
    // cin>>t;
    while(t--)
    {
        solve();
    } 
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

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

int b[2001], w[2001];
int cb[2001][2001], cw[2001][2001], f[2001][2001];

int main(){
  memset(cb, 0, sizeof(cb));
  memset(cw, 0, sizeof(cb));
  memset(f, 0, sizeof(f));
  
  int N;cin>>N;
  for (int i=1;i<=2*N;++i){
    char c;cin>>c;int a;cin>>a;
    if(c=='W') w[a]=i;
    else b[a]=i;
  }

  for (int i=1;i<=N;++i){
    for (int j=1;j<i;++j){
      cb[i][0]+=(b[j]>b[i]);
    }

    for (int j=1;j<=N;++j){
      cb[i][j]=cb[i][j-1]+(b[i]<w[j]);
    }
  }

  for (int i=1;i<=N;++i){
    for (int j=1;j<i;++j){
      cw[0][i]+=(w[j]>w[i]);
    }

    for (int j=1;j<=N;++j){
      cw[j][i]=cw[j-1][i]+(w[i]<b[j]);
    }
  }

  for (int i=1;i<=N;++i){
    f[0][i]=f[0][i-1]+cw[0][i];
    f[i][0]=f[i-1][0]+cb[i][0];
  }

  for (int i=1;i<=N;++i){
    for (int j=1;j<=N;++j){
      f[i][j]=min(f[i-1][j]+cb[i][j],f[i][j-1]+cw[i][j]);
    }
  }
  cout << f[N][N] << endl;
  return 0;
}

Measured memory_bytes: 47232
import sys

class UnionFind():
    def __init__(self, n):
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x


N, M = map(int, input().split())
info = [()] * M
for i in range(M):
    info[i] = map(int, input().split())

uf = UnionFind(N)
for a, b in info:
    a -= 1; b -= 1
    uf.union(a, b)

ans = min(uf.parents)

print(-ans)

Measured memory_bytes: 97812
#include <bits/stdc++.h>
using namespace std;
typedef  long long ll;
int mod = 1e9+7;

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

    ll n, weight;
    cin>>n>>weight;

    ll W[n], V[n];
    for(ll i=0; i<n; i++)
    	cin>>W[i]>>V[i];

    vector<vector<ll>> dp(weight+1, vector<ll>(n+1));
    for(ll i=1; i<=weight; i++){


    	for(ll j=1; j<=n; j++){
    		if(W[j-1]<=i){
    	 		dp[i][j] = max(dp[i][j-1], dp[i-W[j-1]][j-1]+V[j-1]);
    	 		// cout<<dp[i-W[j-1]][j-1]+V[j-1]<<dp[i][j]<<endl;
    		}else dp[i][j] = dp[i][j-1];
    		// cout<<dp[i][j-1]<<" "<<dp[i][j]<<"    ";
    	}
    	// cout<<endl;
    }

	cout<<dp[weight][n];
	return 0;
}		


Measured memory_bytes: 82304
#include <bits/stdc++.h>
#define cal(a,b) ((a+=b)%=mo)
#define cross(a,b,c) ((b-a)*(c-a))
using namespace std;
const int N=250,mo=998244353;
const double eps=1e-7;
int p[N],n,ans;
struct data{
    int x,y;
    data operator - (const data &c)const{
	return (data){x-c.x,y-c.y};
    }
    int operator * (const data &c)const{
	return x*c.y-y*c.x;
    }
}d[N];
int main(){
    cin>>n,p[0]=1;
    if (n<=2) return puts("0"),0;
    for (int i=1; i<=n; ++i) cin>>d[i].x>>d[i].y;
    for (int i=1; i<=n; ++i) p[i]=p[i-1]*2%mo;
    for (int i=1; i<n; ++i)
	for (int j=i+1; j<n; ++j){
	    int cnt=n-j;
	    for (int k=j+1; k<=n; ++k)
		if (cross(d[i],d[j],d[k])==0)
		    --cnt;
	    cal(ans,1ll*p[n-j-cnt]*(p[cnt]-1)%mo);
	}
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256