akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)

int main(){
  int a,b,k;
  cin >> a >> b >> k;
  int lim = min(a,b);
  
  int n = 0;
  for(int i = lim; ;i--){
    if(a%i==0&&b%i==0) n++;
    if(n==k){
      cout << i << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3620
using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] h = Console.ReadLine().Split(' ').Select(e =>int.Parse(e)).ToArray();
            int i = 0;
            int res = 0;
            while (i<n)
            {
                int temp = 0;
                for (int j = i; j < n-1; j++)
                {
                    if (h[j]< h[j+1])
                    {
                        break;
                    }
                        temp++;
                }
                i += temp+1;
                res = Math.Max(res, temp);
            }
            Console.WriteLine(res);
        }
    }
}


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

int D,N;

int main(){
	
  	int A = 1;
  	
  	cin >> D >> N ;
  	
  	if(N != 100){
      
      if(D == 0){

        cout << N << endl;

      }else{

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

          A *= 100;

        }

        cout << A*N << endl;

      }
      
    }else{
    
      	if(D == 0){

          cout << 101 << endl;

		}else{

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

            	A *= 100;

       		}

          cout << A*(N + 1) << endl;

        }
    
    
    }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

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

const int MOD=1000000007;
int INF=100100100100100;

int a[100010];
signed main(){
  int n,k;cin>>n>>k;
  rep(i,n)cin>>a[i];
  sort(a,a+n);
  int ans=0;
  rep(i,k)ans+=a[i];
  cout<<ans<<endl;
  return 0;
}


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

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

  ll ans = 0;
  for (int i=0; i<N; i++) {
    for (int j=i+1; j<N; j++) {
      ans += d[i] * d[j];
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
#define cinl(str) getline(cin,(str))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=1000000007;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };


int main() {
	int n;
	int p[15],sum=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>p[i];
	}
	sort(p,p+n);
	p[n-1] /= 2;
	for(int i=0;i<n;i++){
		sum += p[i];
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
#define rreps(i, n) for(int i=((int)(n)); i>0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pl(s) cout << (s) << "\n";
#define pls(...) {bool space = false; for(auto i : __VA_ARGS__) (cout << (space?" ":"") << i), space = true; cout << "\n";}
#define plexit(s) {cout << (s) << "\n"; exit(0);}
#define yes(s) cout << ((s)?"Yes":"No") << "\n";
#ifdef __LOCAL
#include <dump.hpp>
#define dump(...) DUMPOUT << "  " << string(#__VA_ARGS__) << ": " << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl << "    ", dump_func(__VA_ARGS__)
#else
#define dump(...)
#endif
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
struct IOInit { IOInit() { cin.tie(nullptr); ios::sync_with_stdio(false); dump("READY"); /*cout << unitbuf;*/} } IO_INIT;
using ll = long long; using ull = unsigned long long; using ld = long double;
template<typename T = int> using V = vector<T>; template<typename T = int> using P = pair<T, T>;
using Vi = V<int>; using Vl = V<ll>; using Vd = V<ld>; using VVi = V<Vi>; using VVl = V<Vl>; using Pi = P<int>; using Pl = P<ll>; using Pd = P<ld>;
constexpr ll MOD = 1000000007; constexpr int INF = (1 << 30) - 1; constexpr ll INFL = 1LL << 60; constexpr ld EPS = 1e-12; constexpr ld PI = 3.141592653589793238462643383279;

int op(int a, int b) { return max(a, b); }
int e() { return -1; }

int target;
bool f(int v) { return v < target; }

signed main(void) {
  int n, q; cin >> n >> q;
  Vi a(n);
  rep(i,n) cin >> a[i];
  segtree<int, op, e> seg(a);

  rep(i,q) {
    int t; cin >> t;
    if (t == 1) {
      int x, v; cin >> x >> v;
      --x;
      seg.set(x, v);
    } else if (t == 2) {
      int l, r; cin >> l >> r;
      --l;
      pl(seg.prod(l, r))
    } else {
      int p; cin >> p >> target;
      --p;
      pl(seg.max_right<f>(p)+1)
    }
  }

  return 0;
}


Measured memory_bytes: 6152
#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) ((int)(a).size())
#define PB(a) push_back(a)
#define EB(...) emplace_back(__VA_ARGS__)
#define MP(a, b) make_pair(a, b)
#define MT(...) make_tuple(__VA_ARGS__)
#define Bit(n) (1LL << (n))
using namespace std;
using pii = pair<int, int>;
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
const int MOD = 1000000007;
const int INF = 1LL << 30;
const double EPS = 1e-10;

const int MAX_N = 2010;
int ext_gcd(int a,int b,int& x,int& y) {
  if(b==0){
    x=1;y=0;return a;
  }
  int q=a/b;
  int g=ext_gcd(b,a-q*b,x,y);
  int z=x-q*y;
  x=y;y=z;
  return g;
}
int inv_mod(int a,int m) {
  int x,y;
  ext_gcd(a,m,x,y);
  x%=m;
  if(x<0)x+=m;
  return x;
}
int fac[MAX_N],finv[MAX_N],inv[MAX_N];
void make(){
  fac[0]=1%MOD;
  for(int i=1;i<MAX_N;i++)fac[i]=fac[i-1]*i%MOD;
  finv[MAX_N-1]=inv_mod(fac[MAX_N-1],MOD);
  for(int i=MAX_N-2;i>=0;i--)finv[i]=finv[i+1]*(i+1)%MOD;
  for(int i=1;i<MAX_N;i++)inv[i]=finv[i-1]%MOD;
}

int pow_mod(int x, int n, int m) {
  int r = 1;
  while (n) {
    if (n & 1) r = r*x%m;
    x = x*x%m;
    n >>= 1;
  }
  return r;
}

int N, A, B, C, D;
int dp[1010];

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  make();
  cin >> N >> A >> B >> C >> D;
  dp[0] = 1;
  REP(i, N) {
    int p = i+1;
    if (A <= p && p <= B) {
      REPR(j, N) {
        FOR(k, C, D+1) {
          if (j-k*p < 0) break;
          int tmp = fac[j] * finv[j-k*p] % MOD * finv[k] % MOD * inv_mod(pow_mod(fac[p], k, MOD), MOD) % MOD;
          (dp[j] += dp[j-k*p] * tmp % MOD) %= MOD;
        }
      }
    }
  }
  cout << dp[N] << endl;

  return 0;
}

Measured memory_bytes: 256
IDENTIFICATION DIVISION.
PROGRAM-ID. PROGRAM_ID.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 N              PIC 9(10).
01 K              PIC 9(10).
01 idx            PIC 9(10).
01 ln             PIC X(599).
01 maxlen         PIC 9(10) VALUE 100.
01 cur            PIC 9(10) VALUE 1.
01 i              PIC 9(10) VALUE 1.
01 j              PIC 9(10).
01 len            PIC 9(10).
01 ans            PIC 9(10).
01 zs             PIC Z(9)9.
01 A1.
    03 A11 OCCURS 100 DEPENDING ON N.
        05 A      PIC S9(10) VALUE 1.

PROCEDURE DIVISION.
  ACCEPT ln.
  UNSTRING ln DELIMITED BY SPACE INTO N K.
  PERFORM K TIMES
      ACCEPT maxlen
      ACCEPT ln
      MOVE 1 TO cur
      PERFORM maxlen TIMES
          PERFORM VARYING j FROM cur BY 1 UNTIL ln(j:1) = SPACE
          END-PERFORM
          COMPUTE len = j - cur
          MOVE ln(cur:len) TO idx
          MOVE ZERO TO A(idx)
          COMPUTE cur = j + 1
          ADD 1 TO i
      END-PERFORM
  END-PERFORM.
  PERFORM VARYING j FROM 1 BY 1 UNTIL N < j
      ADD A(j) TO ans
  END-PERFORM.
  MOVE ans TO zs.
  DISPLAY FUNCTION TRIM(zs).
  STOP RUN.


Measured memory_bytes: 3872
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define pp pair<int,int>
#define ll long long
#define ld long double
int inf=100000000;
ll INF=4000000000000000000;
ll MOD=1000000007;


int main() {
    ll n;
    cin >> n;
    vector<pair<ll,ll>> a(n);
    vector<vector<ll>> d(n+1,vector<ll>(n+1));
    rep(i,n+1){
      rep(j,n+1){
        if (j==0) d.at(i).at(j)==0;
        else d.at(i).at(j)=INF;
      }
    }
    rep(i,n){
      ll f,g;
      cin >> f >> g;
      a.at(i).second=f;a.at(i).first=g;
    }
    sort(a.begin(),a.end());
    for (int i=1;i<n+1;i++){
      rep(j,n){
        if (a.at(i-1).second+d.at(i-1).at(j)<=a.at(i-1).first){
          d.at(i).at(j+1)=min(a.at(i-1).second+d.at(i-1).at(j),d.at(i-1).at(j+1));
        }
        d.at(i).at(j)=min(d.at(i).at(j),d.at(i-1).at(j));
      }
    }
    for (int i=n;i>=0;i--){
      if (d.at(n).at(i)!=INF) {cout << i << endl;return 0;}
    }
}



Measured memory_bytes: 3160
a, b, c, x, y = map(int, input().split())
v1 = a * x + b * y
min_xy = min(x, y)
v2 = min_xy * 2 * c + (x - min_xy) * a + (y - min_xy) * b
max_xy = max(x, y)
v3 = max_xy * 2 * c
print(min(v1, v2, v3))

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

const int INF = (1 << 30) - 1;

int N, M;
char seat[105];

int left_insert()
{
    int k = 1;
    while ( k <= N && seat[k] != '#') {
        k++;
    }
    return ( k );
}

int main()
{

    while ( cin >> N >> M, N || M ) {

        fill_n(seat, 105, '#');
        for ( int i = 0; i < M; i++ ) {
            char c;
            bool flag = false;
            int d[105];
            int k;

            cin >> c;
            fill_n(d, 105, INF);
            switch ( c ) {
                case 'A' :
                    seat[ left_insert() ] = 'A';
                    break;
                case 'B' :
                    k = N;
                    while ( k > 0 && (seat[k] != '#' || seat[k - 1] == 'A' || seat[k + 1] == 'A') ) {
                        k--;
                    }
                    if ( k > 0 ) {
                        seat[k] = 'B';
                    } else {
                        seat[ left_insert() ] = 'B';
                    }
                    break;
                case 'C' :
                    for ( int i = 1; i <= N; i++ ) {
                        if ( seat[i] != '#' ) {
                            if ( i < N && seat[i + 1] == '#' ) {
                                seat[i + 1] = 'C';
                                flag = true;
                                break;
                            }
                            if ( i > 1 && seat[i - 1] == '#' ) {
                                seat[i - 1] = 'C';
                                flag = true;
                                break;
                            }
                        }
                    }
                    if ( !flag ) {
                        seat[N / 2 + 1] = 'C';
                    }
                    break;
                case 'D' :
                    for ( int i = 1; i <= N; i++ ) {
                        if ( seat[i] != '#' ) {
                            d[i] = 0;
                        }
                        d[i] = min(d[i - 1] + 1, d[i]);
                    }
                    for ( int i = N; i > 0; i-- ) {
                        d[i] = min(d[i], d[i + 1] + 1);
                    }
                    int maxp = 1;
                    for ( int i = 2; i <= N; i++ ) {
                        if ( d[i] > d[maxp] ) {
                            maxp = i;
                        }
                    }
                    seat[maxp] = 'D';
                    break;
            }
        }
        for ( int i = 1; i <= N; i++ ) {
            cout << seat[i];
        }
        cout << endl;
    }
}



Measured memory_bytes: 3056
n = int(input())

if n < 10:
    print(n)
else:
    n = str(n)
    l = len(n)
    if n == n[0] + '9'*(l-1):
        print(int(n[0]) + 9 * (l-1))
    else:
        print(int(n[0]) + 9*(l-1) -1)


Measured memory_bytes: 2940
while True :

    m, f, r = map(int, input().split())
    if m == -1 and f == -1 and r == -1 :
        break

    if m == -1 or f == -1 :
        print("F")
    elif (m + f) >= 80 :
        print("A")
    elif (m + f) >= 65 :
        print("B")
    elif (m + f) >= 50 :
        print("C")
    elif (m + f) >= 30 and r >= 50 :
        print("C")
    elif (m + f) >= 30 :
        print("D")
    else :
        print("F")


Measured memory_bytes: 5592
L, R = map(int, input().split())
ans = 2019
if R - L >= 2018:
    print(0)
else:
    for i in range(L, R):
        for j in range(i + 1, R + 1):
            if i * j % 2019 < ans:
                ans = i * j % 2019
    print(ans)

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

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;
}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define INF 999999999

    /*Solve*/

int main(){
    int n,k;
    cin >> n >> k;
    int h[n];
    rep(i,n)cin >> h[i];
    
    ll ans = INF;   //ansをINF(=999999999)で初期化
    ll tmp;     //一時保存用
    sort(h,h+n);
    rep(i,n-k+1){
        tmp = abs(h[i]-h[i+k-1]);
        chmin(ans,tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

struct UnionFind{
  vector<int> d;
  UnionFind(int n) : d(n, -1){}
  int find(int x){
    if(d.at(x) < 0) return x;
    return d.at(x) = find(d.at(x));
  }
  bool unite(int x, int y){
    x = find(x); y = find(y);
    if(x == y) return false;
    if(d.at(x) > d.at(y)) swap(x, y);
    d.at(x) += d.at(y);
    d.at(y)= x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return -d.at(find(x)); }
};

int main(){
  int n;
  cin >> n;
  vector<tuple<int, int, int>> vt(n);
  vector<tuple<ll, int, int>> path;
  rep(i, n){
    int x, y;
    cin >> x >> y;
    vt.at(i) = make_tuple(x, y, i);
  }
  sort(vt.begin(), vt.end());
  rep(i, n-1){
    int x1, y1, i1, x2, y2, i2;
    tie(x1, y1, i1) = vt.at(i);
    tie(x2, y2, i2) = vt.at(i+1);
    path.push_back(make_tuple(x2-x1, i1, i2));
  }
  rep(i, n){
    auto &tt = vt.at(i);
    swap(get<0>(tt), get<1>(tt));
    cerr << get<0>(tt) << " " << get<1>(tt) << endl;
  }
  sort(vt.begin(), vt.end());
  rep(i, n-1){
    int x1, y1, i1, x2, y2, i2;
    tie(y1, x1, i1) = vt.at(i);
    tie(y2, x2, i2) = vt.at(i+1);
    path.push_back(make_tuple(y2-y1, i1, i2));
  }
  sort(path.begin(), path.end());
  UnionFind uf(n);
  ll ans = 0;
  for(auto t : path){
    ll l;
    int x, y;
    tie(l, x, y) = t;
    if(uf.same(x, y) == true) continue;
    ans += l;
    uf.unite(x, y);
  }
  cout << ans << endl;

  return 0;
}

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

int main(){

	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n;
	string a, b, ans = "";
	cin >> n >> a >> b;
	for(int i = 0; i < a.size(); ++i){
		ans += a[i];
		ans += b[i];
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>


using namespace std;

// vector<vector<int>> mat(N, vector<int>(M, 0));

int main(int argc, const char *argv[])
{
    //ABC139 D

    long long N;
    cin>>N;
    cout<<N*(N-1)/2;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>


//#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long
#define pb push_back

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

uint64_t combinations2(uint64_t n, uint64_t k) {
    if (n == 0 || n == 1) return 0;
    uint64_t r = 1;
    for (uint64_t d = 1; d <= k; ++d) {
        r *= n--;
        r /= d;
    }
    return r;
}

int main() {
  // オーダー計算ができないがO(NlogN)なはず
  // 完全にsort関数に頼ってしまった
  int N;
  cin >> N;
  vector<vector<char> > s(N);
  vector<char> a(10);
  string tmp;

  // 各文字のアルファベットの数を数えていく
  rep(i, N){
    cin >> tmp;
    rep(j, 10){
      a[j] = tmp.at(j);
    }
    sort(a.begin(), a.end());
    s[i] = a;
  }
  sort(s.begin(), s.end());

  // 同じ文字列を数える
  vector<int> result(N);
  int cnt = 1;
  rep(i, N - 1){
    if (s[i] == s[i+1]) cnt++;
    else {
      result[i] = cnt;
      cnt = 1;
    }
  }
  result[N-1] = cnt;

  // 答えを計算する
  ll ans = 0;
  rep(i, N){
    ans += combinations2(result[i], 2);
    // cout << combinations2(result[i], 2) << endl;
  }
  
  cout << ans << endl;

}


Measured memory_bytes: 6144
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

int main()
{
	string s, t;
	char input[101];
	int n;

	scanf("%d", &n);

	scanf("%s", input);
	s = input;
	scanf("%s", input);
	t = input;
	
	for (int i = 0; i < n; i++)
	{
		printf("%c%c", s[i], t[i]);
	}

	printf("\n");

	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize(2)
#pragma G++ optimize(2)
#include<bits/stdc++.h>
#define si(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define sd(a) scanf("%lf",&a)
#define ss(a) scanf("%s",a)
#define ms(a) memset(a,0,sizeof(a))
#define repi(i,a,b) for(register ll i=a,bbb=b;i<=bbb;++i)
#define repd(i,a,b) for(register int i=a,bbb=b;i>=bbb;--i)
#define reps(s) for(register int i=head[s],v=e[i].to;i;i=e[i].nxt,v=e[i].to)
#define ce(i,r) i==r?'\n':' '
#define pb push_back 
#define all(x) x.begin(),x.end()
#define gmn(a,b) a=min(a,b)
#define gmx(a,b) a=max(a,b)
#define fi first
#define se second
#define pr(x) cout<<#x<<": "<<x<<endl
using namespace std;
std::mt19937 rnd(time(0));//std::mt19937_64 rnd(time(0));
typedef long long ll;
typedef double db;
inline int qi(){
    int f=0,fu=1; char c=getchar();
    while(c<'0'||c>'9'){ if(c=='-')fu=-1; c=getchar(); }
    while(c>='0'&&c<='9'){ f=(f<<3)+(f<<1)+c-48; c=getchar(); }
    return f*fu;
}
inline ll ql(){
	ll f=0;int fu=1; char c=getchar();
    while(c<'0'||c>'9'){ if(c=='-')fu=-1; c=getchar(); }
    while(c>='0'&&c<='9'){ f=(f<<3)+(f<<1)+c-48; c=getchar(); }
    return f*fu;
}
inline ll ceil_div(ll a,ll b){ return (a+b-1)/b; }
//start!
const int MAX_N=1e5+5;
int pos[MAX_N];
ll sum[MAX_N];
int main()
{
	ll n=ql(),x=ql(),m=ql(); sum[1]=x,x%=m,pos[x]=1;
	ll loop=-1,len,before;
	repi(i,2,n){
		x=x*x%m;
		if(pos[x]){ before=pos[x]-1,loop=sum[i-1]-sum[pos[x]-1],len=i-pos[x]; break; } 
		pos[x]=i;
		sum[i]=sum[i-1]+x;
		
	}
	if(loop==-1) printf("%lld\n",sum[n]);
	else{
		ll ans=sum[before]+((n-before)/len)*loop;
		int left=(n-before)%len;
		ans+=sum[before+left]-sum[before];
		printf("%lld\n",ans);
	}
	return 0;
}


Measured memory_bytes: 4556
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	
	int cnt_a=0,cnt_b=0;
	
	for(int i=0;i<s.size();i++){
		if(s[i]=='A') cnt_a++;
		else if(s[i]=='B') cnt_b++;
	}
	
	if(cnt_a>=1 && cnt_b>=1)
		cout<<"Yes";
	else
		cout<<"No";
		
	cout<<endl;
	return 0;
} 

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

using namespace std;

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define rall(x) x.rbegin(), x.rend()
#define all(x) x.begin(), x.end()
#define PB push_back
#define F first
#define S second

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

const int MOD = 1e9+7;

const double PI = acos(-1);

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

	int r; cin >> r;
	cout << setprecision(8) << fixed << 2*PI*r << '\n';

 	return 0;
}

Measured memory_bytes: 3792
#include<iostream>

using namespace std;

int main(void)
{
  int a,b,c; cin>>a>>b>>c;
  int s=a;
  
  for(int i=a,j=0;j<100000000;i+=s,j++){
    if(i%b==c){puts("YES"); return 0;}
  }
  
  puts("NO");
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

int N;
int cnt[3];
int ans, dup, res;

int main()
{
  std::cin >> N;

  rep( i, N )
  {
    std::string S;
    std::cin >> S;

    rep( i, S.size()-1 )
    {
      if( S[i] == 'A' && S[i+1] == 'B' )
        ++ans;
    }

    bool fl = false;

    if( S[0] == 'B' && S[S.size()-1] == 'A' )
      ++cnt[2];
    else if( S[0] == 'B' )
      ++cnt[1];
    else if( S[S.size()-1] == 'A' )
      ++cnt[0];
  }

  int p = 0;

  if( cnt[0] > cnt[1] )
    p = 1;
  else
    p = 0;

  int both = 0;

  while( cnt[0] != cnt[1] && cnt[2] )
  {
    if( cnt[2] > 0 )
      ++cnt[p], --cnt[2], ++both;
  }

  if( cnt[0] == cnt[1] )
  {
    // cnt[2]-1 when cnt[2]>both
    // cnt[2] when both>=cnt[2]
    res = cnt[0]+(both>=cnt[2]?cnt[2]:both>0?cnt[2]:cnt[0]>0?cnt[2]:cnt[2]-1);
  }
  else
    res = std::min(cnt[0],cnt[1])+cnt[2];

  std::cout << ans+res << std::endl;

  return 0;
}

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

using namespace std;
using ll = long long;

int main() {
    double A, B;
    cin >> A >> B;

    for (int i = 1; i < 1e8; i++) {
        if (floor(i * 0.08) == A && floor(i * 0.1) == B) {
            cout << i << endl;
            return 0;
        }
    }

    cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 3724
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
#define N 400102
const int p=998244353,iv=499122177;
int n,ps[N],m,a[N];
inline int ksm(int d,int k){int ret=1;while(k){if(k&1)ret=1ll*ret*d%p;d=1ll*d*d%p;k>>=1;}return ret;}
inline void fwt(int x[],int len,int mde)
{
    for(int i=2;i<=len;i<<=1)for(int j=0,stp=i>>1;j<len;j+=i)for(int k=j;k<j+stp;k++)
    {
        int t1=x[k],t2=x[k+stp];x[k]=(t1+t2)%p,x[k+stp]=(t1-t2+p)%p;
        if(mde<0)x[k]=1ll*x[k]*iv%p,x[k+stp]=1ll*x[k+stp]*iv%p;
    }
}
int main()
{
    scanf("%d",&n);m=(1<<n);int sum=0;
    for(int i=0;i<m;i++)scanf("%d",&ps[i]),sum=(sum+ps[i])%p;sum=ksm(sum,p-2)%p;
    for(int i=0;i<m;i++)ps[i]=1ll*ps[i]*sum%p;
    a[0]=m-1;for(int i=1;i<m;i++)a[i]=p-1;
    ps[0]=(ps[0]+p-1)%p;
    fwt(a,m,1);fwt(ps,m,1);
    for(int i=0;i<m;i++)a[i]=1ll*a[i]*ksm(ps[i],p-2)%p;
    a[0]=0;
    fwt(a,m,-1);
    for(int i=1;i<m;i++)a[i]=(a[i]-a[0]+p)%p;
    a[0]=0;
    for(int i=0;i<m;i++)printf("%d\n",a[i]);
}


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

#define long long long

using namespace std;

const int N = 2e5+5;

int n;
long A[N];
vector<long> pre, suf;

int main() {
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) scanf("%lld", A + i);
    for(int i = 1; i <= n; i++) {
        if(pre.empty()) pre.emplace_back(A[i]);
        else pre.emplace_back(pre.back() + A[i]);
    }
    for(int i = n; i; i--) {
        if(suf.empty()) suf.emplace_back(A[i]);
        else suf.emplace_back(suf.back() + A[i]);
    }
    long p, q, r, s, ans = 1e18;
    for(int i = 3; i < n; i++) {
        long left = pre[i - 2], right = suf[n - i];
        bool L = false, R = false;

        auto it1 = lower_bound(pre.begin(), pre.end(), left / 2);
        if(it1 != pre.end() && *it1 != left) {
            p = *it1, q = left - *it1;
            L = true;
        }
        if(it1 != pre.begin()) {
            --it1;
            if(!L || abs(p - q) > abs(left - 2ll * (*it1)))
                p = *it1, q = left - *it1;
        }
        auto it2 = lower_bound(suf.begin(), suf.end(), right / 2);
        if(it2 != suf.end() && *it2 != right) {
            r = *it2, s = right - *it2;
            R = true;
        }
        if(it2 != suf.begin()) {
            --it2;
            if(!R || abs(r - s) > abs(right - 2ll * (*it2)))
                r = *it2, s = right - *it2;
        }
        ans = min(ans, max({p, q, r, s}) - min({p, q, r, s}));
    }
    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 6384
#include<iostream>
using namespace std;
int main(){
    int a[25];
    int b[25];
    int c[25];
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=0;i<n;i++)
        cin>>b[i];
    for(int i=0;i<n;i++)
        c[i]=a[i]-b[i];
    int sum=0;
    for(int i=0;i<n;i++)
        if(c[i]>0) sum+=c[i];
    cout<<sum<<endl;
    return 0;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  
  int x = 1;
  int ans = 0;
  
  if ( n == 1){
    ans = 1;
  }
  else{
    while (x <= n){
      x *= k;
      ans++;
    }
  }
  
  cout << ans << endl;
}

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

int main() {
    cin.tie(0)->sync_with_stdio(false);

	int h, w, k;
	cin >> h >> w >> k;
	vector<vector<char> > c(h, vector<char>(w, '.'));
	REP(i, h) REP(j, w) cin >> c[i][j];

	int res = 0;
	REP(l, 1 << h) REP(m, 1 << w) {
		int sum = 0;
		REP(i, h) REP(j, w) {
			if (((l >> i) & 1) == 0 && ((m >> j) & 1) == 0 && c[i][j] == '#')
				sum++;
		}
		if (sum == k)
			res++;
	}

	cout << res << '\n';
    return 0;
}


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

using namespace std;

typedef long long ll;

int main()
{
    ll n, a, b, c, d, e;
    cin >> n >> a >> b >> c >> d >> e;

    ll m = min({a, b, c, d, e});
    cout << (n + m - 1) / m + 4 << endl;
}

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

int main() {
    string n;
    cin >> n;
    int ans, sumn, summ, i;
    sumn = 0;
    int k = n.size();
    summ = (n.at(0) - '0') + 9 * (k - 1) - 1;
    for (i = 0; i < k; i++) sumn += (n.at(i) - '0');
    if (sumn > summ) ans = sumn;
    else ans = summ;
    cout << ans << endl;
    return 0;
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){


}

Node treeMaximum(Node x){


}

Node treeSearch(Node u, int k){


}

Node treeSuccessor(Node x){


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key<x->key){
      x=x->left;
    }else{
      x=x->right;
    }
  }

  z->parent=y;

  if(y==NIL){
    root=z;
  }else if(z->key<y->key){
    y->left=z;
  }else{
    y->right=z;
  }
}

void inorder(Node u){
  if(u!=NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);

  }
}
void preorder(Node u){
  if(u!=NIL){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}

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

namespace AtCoder
{
    class Program
    {
        static int n;

        static void Main(string[] args)
        {
            //[summary]C - Green Bin
            n = int.Parse(Console.ReadLine());

            //読み込んだ文字列をそれぞれソートする
            var words = GetWords().ToList();

            //文字列を種類ごとにDictionaryにまとめる
            var summary = SummarizeWords(words);
            long count = 0;

            for(int i = 0; i < n; i++)
            {
                var key = words[i];
                summary[key]--;

                count += summary[key];
            }

            Console.WriteLine(count);
        }

        static Dictionary<string,int> SummarizeWords(List<string> words)
        {
            var summary = new Dictionary<string, int>();

            foreach(var word in words)
            {
                if (!summary.ContainsKey(word))
                {
                    summary.Add(word, 1);
                }
                else
                {
                    summary[word]++;
                }
            }

            return summary;
        }

        static IEnumerable<string> GetWords()
        {
            for (int i = 0; i < n; i++)
            {
                var s = Console.ReadLine().ToCharArray();
                yield return String.Join("", s.OrderBy(x => x));
            }
        }

    }
}

Measured memory_bytes: 33944
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define STRINGIFY(n) #n
#define TOSTRING(n) STRINGIFY(n)
#define PREFIX "#" TOSTRING(__LINE__) "| "
#define debug(x) \
{ \
  std::cout << PREFIX << #x << " = " << x << std::endl; \
}

std::ostream& output_indent(std::ostream& os, int ind) {
  for(int i = 0; i < ind; i++) os << " ";
  return os;
}

template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p);
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v);

template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p) {
  return (os << "(" << p.first << ", " << p.second << ")");
}
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
  os << "[";
  for(int i = 0;i < v.size();i++) os << v[i] << ", ";
  return (os << "]");
}

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) { return std::vector<T>(n, std::forward<T>(val)); }
template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}
template<class Cond> struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  template<class T> bool operator()(T& a, const T& b) const { if(cond(a, b)) { a = b; return true; } return false; }
};
template<class Cond> chain<Cond> make_chain(Cond cond) { return chain<Cond>(cond); }

int main() {
  i64 N, K;
  cin >> N >> K;
  vector<i64> A(N);
  rep(i,0,N) cin >> A[i];
  rep(i,K, N) {
    if(A[i - K] < A[i]) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
}


Measured memory_bytes: 4840
#include <stdio.h>
#include <string.h>
#define N 100000
#define Name 10

struct process{
	char n[Name];
	int p;
};

int tail,head,n,t,total=0;
struct process S[N],f[N];

void init(){
	tail = head = 0;
}

void enque(struct process x){
	S[tail++] = x;
	tail = tail % N;
}

struct process deque(){
	struct process x;
	x = S[head++];
	head = head % N;
	return x;
}

int isEmpty(){
	if(tail == head) return 1;
	return 0;
}

int calc(){
	struct process l;
	int count=0;
	l = deque();
	while(count != n){
		if(l.p - t > 0) {
			l.p -= t;
			enque(l);
			total += t;
		}
		else {
			strcpy(f[count].n,l.n);
			total += l.p;
			f[count++].p = total;
		}
		l = deque();
	}
	return 1;

}

int main(){
	scanf("%d%d",&n,&t);
	int i;
	struct process s[N];
	for(i=0;i<n;i++){
		scanf("%s",s[i].n);
		scanf("%d",&s[i].p);
		enque(s[i]);
	}
	calc();
	for(i=0;i<n;i++){
		printf("%s %d\n",f[i].n,f[i].p);
	}
	return 0;
}

Measured memory_bytes: 5732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    int n;
    string s;
    cin >> n >> s;

    int ans = 0;
    char c[3];
    for (int i = 0; i <= 9; i++) {
        c[0] = '0' + i;
        for (int j = 0; j <= 9; j++) {
            c[1] = '0' + j;
            for (int k = 0; k <= 9; k++) {
                c[2] = '0' + k;
                int m = 0;
                for (int p = 0; p < n; p++) {
                    if (s[p] == c[m]) {
                        m++;
                        if (m == 3) {
                            ans++;
                            break;
                        }
                    }
                }
            }
        }
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define int long long
#define INF 1061109567
#define pb push_back
#define in(s) freopen(s,"r",stdin);
#define out(s) freopen(s,"w",stdout);
#define fi first
#define se second
#define bw(i,r,l) for (int i=r-1;i>=l;i--)
#define fw(i,l,r) for (int i=l;i<r;i++)
#define fa(i,x) for (auto i:x)
using namespace std;
const int N=5e5+5;
string s;
int n,pw[N];
bool bad1[N],bad2[N];
bool check=true;
struct hash {
	int hs[N]; //This hash hashes lowercase - letters only strings
	void build(string s) {fw (i,0,s.length()) hs[i]=((i?hs[i-1]*26:0)+s[i]-'a')%MOD;}
	int get(int l,int r) {
		int ans=hs[r]-(l?(hs[l-1]*pw[r-l+1]%MOD):0);
		if (ans<0) ans+=MOD;
		return ans;
	}
} h;
signed main() {
	//in("aome.inp");
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin>>s; n=s.length(); s='~'+s;
	fw (i,1,n+1) if (s[i]!=s[1]) check=false;
	if (check) {
		cout<<n<<"\n"<<1;
		return 0;
	}
	pw[0]=1;
	fw (i,1,N) pw[i]=pw[i-1]*26%MOD;
	h.build(s);
	memset(bad1,false,sizeof(bad1));
	memset(bad2,false,sizeof(bad2));
	fw (i,1,n+1) {
		for (int j=i+i;j<=n;j+=i) if (h.get(j-i+1,j)==h.get(1,i)) bad1[j]=true; else break;
	}
	fw (i,1,n+1) {
		for (int j=n-i-i+1;j>0;j-=i) if (h.get(j,j+i-1)==h.get(n-i+1,n)) bad2[j]=true; else break;
	}
	if (!bad1[n]) {cout<<"1\n1"; return 0;}
	int cnt=0;
	fw (i,1,n) if (!bad1[i]&&!bad2[i+1]) cnt++;
	cout<<2<<"\n"<<cnt;
	return 0;
}

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

using namespace std;

int gcd(int a, int b) {
	return b ? gcd(b, a % b) : a;
}

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

	int a, b, k;
	cin >> a >> b >> k;
	int g = gcd(a, b);
	vector<int> d;
	for (int i = 1; i <= g; i++) {
		if (g % i == 0) {
			d.push_back(i);
		}
	}
	reverse(d.begin(), d.end());
	/*
	for (auto l : d) {
		cerr << l << ' ';
	}
	cerr << '\n';
	*/
	cout << d[k - 1] << '\n';

	
	return 0;
}


Measured memory_bytes: 256
import sys
from collections import Counter
readline = sys.stdin.buffer.readline
MOD = 10**9+7
INF = float('inf')

def main():
    S = list(readline().rstrip().decode('utf-8'))

    bl = S[0] == 'A'
    bl &= ('C' in S[2:-1])

    if bl:
        S.remove('A');
        S.remove('C')

    bl &= all('a' <= x <= 'z' for x in S)

    answer = 'AC' if bl else 'WA'
    print(answer)




if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e4+7;
int l[maxn];
int m[maxn];
int cnt[maxn];
int main()
{
	//freopen("1.txt","r",stdin);
	//freopen("2.txt","w",stdout);
	int n;scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&l[i]);
		m[l[i]]++;
	}
	for(int i=1;i<=10000;i++)
	{
		cnt[i]=cnt[i-1]+m[i];
	}
	ll ans=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1+i;j<=n;j++)
		{
			int mn=abs(l[i]-l[j]);
			int mx=abs(l[i]+l[j]);
			ans+=cnt[mx-1]-cnt[mn];
			if(l[i]>=mn+1&&l[i]<=mx-1) ans--;
			if(l[j]>=mn+1&&l[j]<=mx-1) ans--;
			//cout<<l[i]<<" "<<l[j]<<" "<<mn+1<<" "<<mx-1<<" "<<cnt[mx-1]<<" "<<cnt[mn]<<endl;
		}
	}
	cout<<ans/3<<endl;
 } 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
     
     
typedef long long ll;
typedef vector <int> vi;
typedef pair <int,int> pi;
typedef tuple <int,int,int> ti;

#define forn(i,a,n) for(int i = a; i < n ; i++)
#define mem(str,a) memset(str, a, sizeof(str));
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(nullptr)
const int MOD = 1e9+7, N = 1e7 + 10, E = 1e-9;
/*
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
//vector <int> show;
//for (auto x : show)
//   cout << x << " ";
getline(cin,s);


*/

int main() {
    int x,a,b;
    cin >> x >> a >> b;
    if(b-a <= 0)
        cout << "delicious" << endl;
    else if(b-a <= x)
        cout << "safe" << endl;
    else 
        cout << "dangerous" << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
int q;

ll Kth_root(ll x,int k){
    if(x==1) return 1;
    if(k>64) return 1;
    ll l=0,r=numeric_limits<ll>::max();
    while(r-l>1){
        ll mid=(l+r)/(ll)2;
        ll d=mid;
        bool larger=false;
        rep(i,k-1){
            if(d>x/mid+(ll)1){
                larger=true;
                break;
            }
            d*=mid;
        }
        if(d>x) larger=true;
        if(larger) r=mid;
        else l=mid;
    }
    return l;
}

void solve(){
  cin >> q;
  rep(_,q){
    ll a,b;
    cin >> a >> b;
    if(a>b) swap(a,b);
    ll x=a*b-1;
    if(a==b){
      cout << 2*a-2 << endl;
      continue;
    }
    ll l=0,r=mod;
    ll k=Kth_root(a*b-1,2);
    cout << 2*k-1-(k==(x/k)) << endl;
  }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

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

namespace _159b
{
    class Program
    {
        static void Main(string[] args)
        {
            long N = long.Parse(Console.ReadLine());
            long[] A = Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
            long[] resArray = new long[N];
            long[] countArray = new long[N+1];
            long res = 0;
            long comSum = 0;
            
            for(int i = 0; i<N;i++){
                countArray[A[i]]++;
            }
            for(int i = 0; i<= N;i++){
                comSum += countArray[i] * (countArray[i]-1)/2;
            }
            for(int i = 0;i<N;i++){
                res = comSum - (countArray[A[i]] - 1);
                Console.WriteLine(res);
            }
         }
    }
}


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

int main()
{
    int N;
    scanf("%d", &N);
    vector<int> p(N + 1), A(N + 1), B(N + 1), r(N + 1);
    for (int i = 1; i <= N; i++) {
        scanf("%d", &p[i]);
    }
    for (int i = 1; i <= N; i++) {
        r[p[i]] = i;
    }
    for (int i = 1; i <= N; i++) {
        A[i] = 30000 * i;
        B[i] = 30000 * (N - i) + r[i];
    }
    for (int i = 1; i <= N; i++) {
        printf("%d ", A[i]);
    }
    printf("\n");
    for (int i = 1; i <= N; i++) {
        printf("%d ", B[i]);
    }
    printf("\n");
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>

using namespace std;

int N, K;

int main() {
    long long Height[15];
    long long copyHeight[15];

    long long ans = 1000000000000;

    cin >> N >> K;
    for ( int i = 0; i < N; ++i ) {
        cin >> Height[i];
    }


    for ( int bit = 0; bit < (1 << N); ++bit ) {
        int count = 0;

        for ( int p = 0; p < N; ++p ) {
            if ( bit & (1 << p)) count++;
        }
        if ( count < K ) continue;

        else {

            for ( int i = 0; i < N; ++i ) copyHeight[i] = Height[i];
            int flag_num = 0;
            long long cost = 0;
            for ( int i = 0; i < N; ++i ) {
                if ( bit & (1 << i) ) {
                    long long max_h = 0;
                    for ( int j = flag_num; j < i; ++j ) {
                        max_h = (copyHeight[j] > max_h) ? copyHeight[j] : max_h;
                    }
                    if ( max_h >= copyHeight[i] ) {
                        cost += max_h - copyHeight[i] + 1;
                        copyHeight[i] = max_h + 1;
                    }
                    flag_num = i;
                } 
            }
            ans = (cost < ans) ? cost : ans;
        }

    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod=998244353;
 
int n,q,l,r,k;
int tag[2000005],num[200005],all_1[200005];
 
struct segment_tree
{
	int l,r;
	int num;
}tree[2000005];
 
inline void pushup(int rt)//5 5 6 6
{
	tree[rt].num=(tree[2*rt].num*num[tree[2*rt+1].r-tree[2*rt].r]+tree[2*rt+1].num)%mod;
}
 
inline void get_lr(int l,int r,int rt)
{
	tree[rt].l=l,tree[rt].r=r;
	if (l==r)  return;
	int mid=(l+r)>>1;
	get_lr(l,mid,2*rt);
	get_lr(mid+1,r,2*rt+1);
}
 
inline void build_tree(int l,int r,int rt)
{
	if (l==r)
	{
		tree[rt].num=1;
		return;
	}
	int mid=(l+r)>>1;
	build_tree(l,mid,2*rt);
	build_tree(mid+1,r,2*rt+1);
	pushup(rt);
}
 
inline void f(int l,int r,int rt,int k)//3 4 5 3
{
	tag[rt]=k;
	tree[rt].num=(k*all_1[tree[rt].r-tree[rt].l+1])%mod;
}
 
inline void pushdown(int rt,int l,int r)
{
	int mid=(l+r)>>1;
	if (tag[rt]!=0)
	{
		f(l,mid,2*rt,tag[rt]);
		f(mid+1,r,2*rt+1,tag[rt]);
	}
	tag[rt]=0;
}
 
inline void change(int nl,int nr,int l,int r,int rt,int k)
{
	pushdown(rt,l,r);
	
	int mid=(l+r)>>1;
	if (nl<=l&&r<=nr)
	{
		f(l,r,rt,k);
		return;
	}
	if (nl<=mid)  change(nl,nr,l,mid,2*rt,k);
	if (nr>mid)  change(nl,nr,mid+1,r,2*rt+1,k);
	
	pushup(rt);
}
 
inline int query(int nl,int nr,int l,int r,int rt)
{
	pushdown(rt,l,r);
	
	int mid=(l+r)>>1,lson=0,rson=0,tot=0;
	if (nl<=l&&r<=nr)  return tree[rt].num;
	
	if (nl<=mid)  lson=query(nl,nr,l,mid,2*rt);
	if (nr>mid)  rson=query(nl,nr,mid+1,r,2*rt+1);
	tot=(lson*(n-tree[2*rt].r)+rson)%mod;
	
	return tot;
}

inline int read()
{
	int s=0,w=1;
	char ch=getchar();
	
	while (ch<'0'||ch>'9')
	{
		if (ch=='-')  w=-w;
		ch=getchar();
	}
	while (ch>='0'&&ch<='9')
	{
		s=(s<<1)+(s<<3)+(ch^'0');
		ch=getchar();
	}
	return s*w;
}
 
signed main()
{
	n=read(),q=read();
	num[0]=1;
	for (int i=1;i<=n;i++)  num[i]=(num[i-1]*10)%mod;
	
	all_1[1]=1;
	for (int i=2;i<=n;i++)  all_1[i]=(all_1[i-1]*10+1)%mod;
	
	get_lr(1,n,1);
	build_tree(1,n,1);
	while (q--)
	{
		l=read(),r=read(),k=read();
		change(l,r,1,n,1,k);
		cout<<query(1,n,1,n,1)<<endl;
	}
	return 0;
}

Measured memory_bytes: 39548
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

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

ll func(ll n){
    return n*(n+1)/2;
}
int main(){

    ll x;
    cin >> x;

    ll ans = 0;
    for(ll i = 1; i <= x; i++){
        ll r = x/i;
        ans += i*func(r);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#include <stdio.h>
 
using namespace std;
 
#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(i, a) for (auto &i: (a))
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()

void solve();

signed main () {
	clock_t beg = clock();
    cout << fixed << setprecision(15);
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif
    int t = 1; 
    // cin >> t;    
    int tt = t;
    while (t--) { 
        solve();
    }
    cerr << "\nExecution time: " << (clock() - beg) / 1000 << '\n';
    return 0;
}
const int N = 1e5 + 55;
int arr[N];
int n, k;
typedef long long ll;
const int mod = 1e9 + 7; // change to something else

ll euclid(ll a, ll b, ll &x, ll &y) {
	if (b) { ll d = euclid(b, a % b, y, x);
		return y -= a/b * x, d; }
	return x = 1, y = 0, a;
}

struct Mod {
	ll x;
	Mod(ll xx) : x(xx) {}
	Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
	Mod operator-(Mod b) { return Mod((x - b.x + mod) % mod); }
	Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
	Mod operator/(Mod b) { return *this * invert(b); }
	Mod invert(Mod a) {
		ll x, y, g = euclid(a.x, mod, x, y);
		assert(g == 1); return Mod((x + mod) % mod);
	}
	Mod operator^(ll e) {
		if (!e) return Mod(1);
		Mod r = *this ^ (e / 2); r = r * r;
		return e&1 ? *this * r : r;
	}
};
const int M = 1e9 + 7;
int fac[N];
int ifac[N];
int c (int n, int r) {
	if (r > n)
		return 0;
	int ans = fac[n];
	ans *= ifac[n - r];
	ans %= M;
	ans *= ifac[r];
	ans %= M;
	return ans;
}
void solve() {
	fac[0] = 1;
	for (int i = 1; i < N; ++i)
		fac[i] = (fac[i - 1] * i) % M;
	ifac[N - 1] = (Mod(1)/Mod(fac[N - 1])).x;
	for (int i = N - 2; i >= 0; --i) {
		ifac[i] = (ifac[i + 1] * (i + 1)) % M;
	} 
	cin >> n >> k;
	for (int i = 1; i <= n; ++i) {
		cin >> arr[i];
	}
	sort(arr + 1, arr + n + 1);
	int ans1 = 0;
	int ans2 = 0;
	for (int i = 1; i <= n; ++i) {
		ans1 += (arr[i] * c(i - 1, k - 1)) % M;
		ans1 %= M;
		ans2 += (arr[i] * c(n - i, k - 1)) % M;
		ans2 %= M;
	}
	cout << (ans1 - ans2 + M) % M; 
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define  rep(i,n) for(li i = 0; i < (n); ++i)
#define  red(i,n) for(li i = (n)-1; i >= 0; --i)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a) 
using namespace std;
using li = long long;
using ul = unsigned long long;
using vi = vector<li>;
using vs = vector<string>;
inline ul gcd(ul a,ul b) { return b?gcd(b,a%b):a; }
const int INF=1000000009;


int main()
{
    int n,a;
    cin>>n;
    map<int,int>x;
    rep(i,n)cin>>a,x[a]=1;
    cout<<x.size()<<endl;
    return 0;
}


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

int main(){
  	int i=0,j=0,count=0;
	string s;
  	string t="abcdefghijklmnopqrstuvwxyz";
  	cin>>s;
	sort(s.begin(),s.end());
  	if(s[0]!='a'){cout<<"a"<<endl;return 0;}
    while(1){
      	if(count!=0)i++;
		if(s[i]!=t[j]){
          j++;
          if(s[i]!=t[j]){cout<<t[j]<<endl;return 0;}
        }
          if(j==25){cout<<"None"<<endl;return 0;}
      	++count;
        }
        
}


Measured memory_bytes: 512
#include<iostream>
#include<cstring>
using namespace std;
int K;
char S[110];
char T[110];
int main()
{
	cin >> K >> S;
	int a = strlen(S);
	if (a <= K)		cout << S << endl;
	
	else
	{				
		strncpy(T, S, K);
		strcat(T, "...");
		cout << T << endl;
	}
	return 0;
}

Measured memory_bytes: 3592