akhauriyash/Code-Regression huggingface dataset:
#include <cmath>
#include <cstdio>
#include <complex>
#include <algorithm>
using namespace std;
// ------ Defines ------ //
#define Point complex<long double>
#define px real()
#define py imag()
// ------ Classes ------ //
class Segment {
public:
	Point p1, p2;
	Segment(Point p1_, Point p2_) : p1(p1_), p2(p2_) {};
	Segment(long double p1x, long double p1y, long double p2x, long double p2y) : p1(Point(p1x, p1y)), p2(Point(p2x, p2y)) {};
	friend bool operator==(const Segment& s1, const Segment& s2) { return (s1.p1 == s2.p1 && s1.p2 == s2.p2) || (s1.p1 == s2.p2 && s1.p2 == s2.p1); }
	friend bool operator!=(const Segment& s1, const Segment& s2) { return !(s1 == s2); }
};
class Line {
public:
	Point p1, p2;
	Line(Point p1_, Point p2_) : p1(p1_), p2(p2_) {};
	Line(long double p1x, long double p1y, long double p2x, long double p2y) : p1(Point(p1x, p1y)), p2(Point(p2x, p2y)) {};
	friend bool operator==(const Line& s1, const Line& s2) { return (s1.p1 == s2.p1 && s1.p2 == s2.p2) || (s1.p1 == s2.p2 && s1.p2 == s2.p1); }
	friend bool operator!=(const Line& s1, const Line& s2) { return !(s1 == s2); }
};
// ------ Functions ------ //
long double dot(const Point& a, const Point& b) { return a.px * b.px + a.py * b.py; }
long double crs(const Point& a, const Point& b) { return a.px * b.py - a.py * b.px; }
int ccw(Point p0, Point p1, Point p2) {
	Point a = p1 - p0, b = p2 - p0;
	if (crs(a, b) > 1e-10) return 1;
	if (crs(a, b) < -1e-10) return -1;
	if (dot(a, b) < -1e-10) return 2;
	if (norm(a) < norm(b)) return -2;
	return 0;
}
bool its(Point p1, Point p2, Point p3, Point p4) {
	return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 && ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0);
}
bool its(Segment s1, Segment s2) {
	return its(s1.p1, s1.p2, s2.p1, s2.p2);
}
long double dst(const Line& a, const Point& b) {
	return abs(crs(a.p2 - a.p1, b - a.p1) / abs(a.p2 - a.p1));
}
long double dst(const Segment& a, const Point& b) {
	if (dot(a.p2 - a.p1, b - a.p1) < 0.0) return abs(b - a.p1);
	if (dot(a.p1 - a.p2, b - a.p2) < 0.0) return abs(b - a.p2);
	return abs(crs(a.p2 - a.p1, b - a.p1) / abs(a.p2 - a.p1));
}
long double dst(const Segment& a, const Segment& b) {
	if (its(a, b)) return 0;
	return min({ dst(a, b.p1), dst(a, b.p2), dst(b, a.p1), dst(b, a.p2) });
}
int q, px1, py1, px2, py2, qx1, qy1, qx2, qy2;
int main() {
	scanf("%d", &q);
	for (int i = 0; i < q; i++) {
		scanf("%d%d%d%d%d%d%d%d", &px1, &py1, &px2, &py2, &qx1, &qy1, &qx2, &qy2);
		printf("%.9Lf\n", dst(Segment(px1, py1, px2, py2), Segment(qx1, qy1, qx2, qy2)));
	}
	return 0;
}

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

h,w = LI()
s = [input() for _ in range(h)]
cnt = h*w-1
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            cnt -= 1

dx,dy = [1,0,-1,0],[0,1,0,-1]
que = deque()
que.append((0,0))
d = [[0]*w for _ in range(h)]
check = [[True]*w for _ in range(h)]
check[0][0] = False
while que:
    x,y = que.popleft()
    for i in range(4):
        nx,ny = x+dx[i], y+dy[i]
        if 0 <= nx < w and 0 <= ny < h:
            if check[ny][nx] and s[ny][nx] == '.':
                check[ny][nx] = False
                d[ny][nx] = d[y][x] + 1
                que.append((nx,ny))
if d[h-1][w-1] == 0:
    print(-1)
else:
    print(cnt-d[h-1][w-1])

Measured memory_bytes: 40816
H, W = map( int, input().split() )
s = [ list( map( str, input().split() ) ) for i in range(H) ] 
for i in range(H) : 
    for j in range(W) : 
       if s[i][j] == "snuke" : 
           w = chr( j + ord( "A" ) )
           h = i + 1
           print( w + str( h ) )
           exit()


Measured memory_bytes: 3060
n = int(input())
UV = [list(map(int, input().split())) for _ in range(n - 1)]

ans = 0
for i in range(1, n + 1):
  ans += i * (i + 1) // 2

for uv in UV:
  u, v = sorted(uv)
  ans -= u * (n - v + 1)

print(ans)


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

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

  char data[3][N];
  for(int i = 0 ; i < 3 ; i++){
    for(int j = 0 ; j < N ; j++){
      cin >> data[i][j];
    }
  }

  int res = 0;
  for(int i = 0 ; i < N ; i++){
    int max_cnt = 0;
    for(int j = 0 ; j < 3 ; j++){
      int cnt = 0;
      for(int k = 0 ; k < 3 ; k++){
        if(data[j][i] == data[k][i])cnt++;
      }
      max_cnt =  max(max_cnt , cnt);
    }
    if(max_cnt == 2)res++;
    else if(max_cnt == 1)res += 2;
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
from collections import deque
def BFS(x,y,l):
   que=deque([(x,y)])
   visited=[[0]*W for i in range(H)]
   visited[0][0]=1
   while que:
      x,y=que.popleft()
      node=visited[y][x]
      if 0 < x:
         if l[y][x-1] != "#" and not visited[y][x-1]:
            visited[y][x-1]+=node+1
            que.append((x-1,y))
      if 0 < y:
         if l[y-1][x] != "#" and not visited[y-1][x]:
            visited[y-1][x]+=node+1
            que.append((x,y-1))
      if x < W-1:
         if l[y][x+1] != "#" and not visited[y][x+1]:
            visited[y][x+1]+=node+1
            que.append((x+1,y))
      if y < H-1:
         if l[y+1][x] != "#" and not visited[y+1][x]:
            visited[y+1][x]+=node+1
            que.append((x,y+1))
      if x==W-1 and y==H-1:
         return visited[H-1][W-1]
   return -1
H,W=list(map(int,input().split()))
l=[]
tmp2=0
for i in range(H):
   tmp=list(input())
   tmp2+=tmp.count("#")
   l.append(tmp)
ans=BFS(0,0,l)
if ans != -1 and l[0][0] != "#":
   print(W*H-ans-tmp2)
else:
   print(-1)

Measured memory_bytes: 3316
//~raam
//~created : Jun 04, 2020 - 3.29.11 PM IST

using namespace std;
#include "bits/stdc++.h"

#define ll long long

void solve(){
   string s,t;
   cin >> s >> t;
   for(int i = 0; i < int(s.size()); ++i){
      if(s[i] != t[i]){
         cout << "No";
         return;
      }
   }
   cout << "Yes";
}

int main(){

   ios_base::sync_with_stdio(0);
   cin.tie(0);

   int t; t=1;
   while(t--)solve();
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
int main(){
  string N;
  long long K;
  cin>>N>>K;
  long long dp[100][1000];
  dp[1][1]=9;
  dp[2][1]=0;
  dp[3][1]=0;
  for(long i=2;i<=(long long)N.size();i++){
    dp[1][i]=9*i;
    dp[2][i]=9*dp[1][i-1]+dp[2][i-1];
    dp[3][i]=9*dp[2][i-1]+dp[3][i-1];
    //cout<<dp[1][i]<<" "<<dp[2][i]<<" "<<dp[3][i]<<" "<<dp[1][i]+dp[2][i]+dp[3][i]<<endl;
  }
  if(K==1){cout<<dp[1][(long long)N.size()-1]+(N.at(0)-'0')<<endl;}
  if(K==2){
    long long ans=dp[1][(long long)N.size()-1]*(N.at(0)-'0'-1)+dp[2][(long long)N.size()-1];
    while((long long)N.size()>=2){
      N=N.substr(1);
      if(N.at(0)!='0'){
        ans+=dp[1][(long long)N.size()-1];
        ans+=N.at(0)-'0';
        break;
      }
    }
    cout<<ans<<endl;
  }
  if(K==3){
    long long ans=dp[3][(long long)N.size()-1]+dp[2][(long long)N.size()-1]*(N.at(0)-'0'-1);
    while((long long)N.size()>=3){
      N=N.substr(1);
      if(N.at(0)!='0'){
        ans+=dp[2][(long long)N.size()-1];
        ans+=dp[1][(long long)N.size()-1]*(N.at(0)-'0'-1);
        while((long long)N.size()>=2){
          N=N.substr(1);
          if(N.at(0)!='0'){
            ans+=dp[1][(long long)N.size()-1];
            ans+=N.at(0)-'0';
            if(ans!=0){
              cout<<ans<<endl;
              return 0;
            }
          }
          cout<<ans<<endl;
          return 0;
        }
      }
    }
    cout<<ans<<endl;
    return 0;
  }
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define loop(k) rep(author_is_masa,k)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const long long INF = 1e18+10;

/*--------------------------------------------------------------------*/

signed main(){
	int l,r;
	cin>>l>>r;
	int ans=INF;
	if(l/2019+1==(r+2018)/2019){
		for(int i=l;i<r;i++){
			for(int j=i+1;j<=r;j++){
				chmin(ans,(i*j)%2019);
			}
		}
		cout<<ans<<endl;

	}else{
		cout<<0<<endl;
	}

	return 0;
}



Measured memory_bytes: 3668
N,M = [int(c) for c in input().split()]
ab = [list(map(int,input().split())) for c in range(N)]
cd = [list(map(int,input().split())) for c in range(M)]
for i in range(N):
    mi = 10**9
    for j in range(M):
        tmp = abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
        if mi > tmp:
            mi = tmp
            ans = j+1
    print(ans)


Measured memory_bytes: 9144
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(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) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int n; cin>>n;
    vector<int> p(n);
    rep(i,n) cin>>p[i];

    int ans = 0;
    set<int> st;
    rep(i,n) {
        if (st.empty()) {
            ans++;
        }
        else {
            if (*st.begin() > p[i]) {
                ans++;
            }
        }
        st.insert(p[i]);
    }

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

Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repi(i,x,n) for(ll i=x;i<(ll)(n);i++)
#define lb lower_bound
#define ub upper_bound
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
//cin.tie(0);ios::sync_with_stdio(false);



signed main(){
    ll n,ans=0;cin>>n;
    vector<ll> v(n+1,-1);
    rep(i,n){
        cin>>v[i+1];
        if(v[i+1]-v[i]>1){
            cout<<-1<<endl;
            return 0;
        }
    }

    for(int i=n;1<i;i--){
        if(v[i-1]>=v[i]){
            ans+=v[i];
        }else{
            ans++;
        }
    }

    cout<<ans<<endl;

}

Measured memory_bytes: 1792
import sys
import math
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n = ni()
x, y, r = [], [], []
for i in range(n):
    xi, yi = na()
    for xj, yj in zip(x, y):
        r.append(((xi - xj)**2 + (yi - yj)**2)**0.5)
    x.append(xi)
    y.append(yi)
print((sum(r)/len(r))*(n-1))

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

int main()
{
    int k,a,b;
    cin >> k >> a >> b;
    string result = "NG";
    for(int i = a; i <= b; ++i)
    {
        if(i%k==0)
        {
            result = "OK";
        }
    }
    cout << result << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string a;
    bool flag = 1;
    cin>>a;
    int l = a.length();
    for(int i=0;i<l;++i)
    {
        if(a[i]==a[i+1])
        {
            cout<<i+1<<' '<<i+2<<endl;
            flag = 0;
            break;
        }
        else if(i<l-2&&a[i]==a[i+2])
        {
            cout<<i+1<<' '<<i+3<<endl;
            flag = 0;
            break;
        }
    }
    if(flag) cout<<"-1 -1"<<endl;
}


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

int main() {
    int N;
    string S;
    cin >> N >> S;
    int left = 0, right = 0;
    for (int i = 0; i < N; ++i) {
        if (S[i] == '(') {
            ++left;
        } else {
            if (left != 0) --left;
        }
    }
    for (int i = N - 1; i >= 0; --i) {
        if (S[i] == ')') {
            ++right;
        } else {
            if (right != 0) --right;
        }
    }
    cout << string(right, '(') << S << string(left, ')') << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 1e6+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

char S[MAXN];
int cal[10];


int main()
{
    int n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;
    int tc;

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

    cin>>n>>S;

    for(int i=0;i<n;i++){
        cur = S[i]-'1';
        cnt+=(cur&1);
        if(((n-1)|i)==(n-1))cal[cur]++;
    }

    if(cal[1]&1)cout<<1<<"\n";
    else {
        if((!cnt)&&(cal[2]&1))cout<<2<<"\n";
        else cout<<0<<"\n";
    }

    return 0;
}


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

using std::cin;
using std::cout;
using std::cerr;

using std::abs;
using std::min;
using std::max;
using std::swap;

using std::map;
using std::pair;
using std::set;
using std::string;
using std::vector;

using std::sort;
using std::reverse;

using ll = long long;

#define forn(i, n) for (ll i = 0; i < (ll) n; ++i)
#define sz(a) static_cast<int>(a.size())
#define endl '\n'

struct __init {
    __init() {
        cin.tie(nullptr);
        std::iostream::sync_with_stdio(false);
        cout << std::fixed << std::setprecision(10);
        cerr << std::fixed << std::setprecision(5);
        std::mt19937 rand(time(NULL));
    }

    ~__init() {
        #ifdef SEREZHKA
            cerr << "Time elapsed: " << static_cast<double>(clock()) / CLOCKS_PER_SEC << endl;
        #endif
    }
} init;

const ll inf = (ll) 1e9 + 7ll;
const int maxn = (int) 1e5 + 17;

struct edge {
    int u, v;
    ll w;

    edge() { }
    edge(int u, int v, ll w) : u(u), v(v), w(w) { }
};

struct dsu {
    int n;
    vector<int> p, w;

    dsu() : n(0) { p.clear(); w.clear(); }

    dsu(int n) {
        p.resize(n);
        iota(p.begin(), p.end(), 0);
        w.resize(n, 1);
    }

    int getp(int v) { return v == p[v] ? v : p[v] = getp(p[v]); }

    bool join(int u, int v) {
        if ((u = getp(u)) == (v = getp(v)))
            return false;

        if (w[u] < w[v])
            swap(u, v);

        p[v] = u;
        w[u] += (w[u] == w[v]);
        return true;
    }
};

int n, m;
ll x;
edge E[maxn];

bool read() {
    if (!(cin >> n >> m >> x))
        return false;

    forn (i, m) {
        cin >> E[i].u >> E[i].v >> E[i].w;
        --E[i].u;
        --E[i].v;
    }

    return true;
}

ll binpow(ll a, ll n) {
    ll res = 1ll;

    for (; n > 0; n >>= 1, a = a * a % inf)
        if (n & 1)
            res = res * a % inf;

    return res;
}

void solve() {
    sort(E, E + m, [](edge e1, edge e2) {
            return e1.w < e2.w;
        });

    vector<int> id1, id2;
    dsu d(n);
    ll W = 0;

    for (int l = 0; l < m; ) {
        int r = l;
        for (; r < m && E[r].w == E[l].w; ++r);

        for (int i = l; i < r; ++i)
            if (d.getp(E[i].u) != d.getp(E[i].v))
                id1.push_back(i);
            else
                id2.push_back(i);

        for (int i = l; i < r; ++i)
            if (d.join(E[i].u, E[i].v))
                W += E[i].w;

        l = r;
    }

    if (W == x) {
        cout << binpow(2ll, sz(id2)) * (inf + binpow(2ll, sz(id1)) - 2) % inf << endl;
    } else {
        int cnt = 0;
        int oth = sz(id2);

        for (auto i : id2) {
            dsu D(n);
            D.join(E[i].u, E[i].v);
            W = E[i].w;

            for (auto j : id1)
                if (D.join(E[j].u, E[j].v))
                    W += E[j].w;

            if (W == x)
                ++cnt;

            if (W <= x)
                --oth;
        }

        cout << (inf + binpow(2ll, cnt + 1) - 2) * binpow(2ll, oth) % inf << endl;
    }
}

int main() {
#if SEREZHKA
    freopen("file.in", "r", stdin);
#endif

    while (read())
        solve();

    return 0;
}


Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main(){
  double v,y,t,H,b;
  int h,a;
  while(cin>>v){
  t = v / 9.8;
  y = 4.9 * t * t;
  h = (y+5)/5;
  H = (y+5)/5;
  b = H - h; 
    if(b!=0) h = h + 1;
  cout << h << endl;
  }
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef map<int,int> mi;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;

int n,t,x,y;
int tp,xp,yp;

int main()
{
    cin >> n;
    bool f = true;
    for(int i=0;i<n;i++)
    {
        cin >> t >> x >> y;
        int dx = abs(x-xp);
        int dy = abs(y-yp);
        int dt = abs(t-tp);
        if(dx+dy<= dt && (dx+dy)%2==dt%2)
        {
            xp=x;
            yp=y;
            tp=t;
        }
        else f=false;
    }
    if(f) cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void) {
  int n, a[200], c=0, owari=0;
  
  scanf("%d",&n);
  for(int i = 0; i < n; i++) {
    scanf("%d",&a[i]);
  }
  
  while(1) {
    for (int i = 0; i < n; i++) {
      if (a[i] % 2 == 1)
        owari = 1;
    }
    if (owari == 1)
      break;
    
  	c ++;
    
    for (int i = 0; i < n; i++) {
      a[i] /= 2;
    }
  }
  printf("%d",c);
  
  return 0;
}

Measured memory_bytes: 128
n=int(input())
al=list(map(int,input().split()))
s=set(al)
s=sorted(s)
if len(s)==1 and s[0]==0:
    print('Yes')
    exit()
if len(al)%3>0 or len(s)>3 or len(s)==1:
    print('No')
    exit()
if len(s)==2 and s[0]==0:
    if al.count(0)==n//3:
        print('Yes')
        exit()
if len(s)==3 and (s[0]^s[1]^s[2])==0:
    if al.count(s[0])==n//3 and al.count(s[1])==n//3:
        print('Yes')
        exit()
print('No')

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

int main() {
	int i,j;
	int N;
	cin>>N;
	
	int A[N];
	int key;
	for(i=0;i<N;i++){
		cin>>A[i];
	}
	
	for(i=0;i<N;i++){
		key=A[i];
		j=i-1;
		while(j>=0&&A[j]>key){
			A[j+1]=A[j];
			j--;
		}
		A[j+1]=key;
		for(int n=0;n<N;n++){
			cout<<A[n];
			if(n!=N-1)cout<<" ";
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
N, K = list(map(int, input().split()))
S = input()
s=[]
for i in S:
	s.append(i)
x = s[K - 1]
if x == 'A':
	s[K - 1] = 'a'
if x == 'B':
	s[K - 1] = 'b'
if x == 'C':
	s[K - 1] = 'c'

S = "".join(s)
print(S)

Measured memory_bytes: 38256
N, K = list(map(int,input().split()))
xlist = list(map(int,input().split()))

def f(min1,max1):
  if min1>=0 and max1>=0:
    return abs(max1)
  elif min1<=0 and max1 <=0:
    return abs(min1)
  else:
    return min([-2*min1 + max1,-min1 + 2*max1])

ans = 2*10**9
for i in range(N-K+1):
  min1 = xlist[i]
  max1 = xlist[i+K-1]
  dist =f (min1,max1) 
  if dist < ans :
    ans = dist

print(ans)


Measured memory_bytes: 62576
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N];
		int[] b = new int[N];
		int[] c = new int[N];
		for(int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
			c[i] = sc.nextInt();
		}
		int[][] dp = new int[N+1][3];
		for(int i = 1; i <= N; i++) {
			dp[i][0] = Math.max(dp[i-1][1], dp[i-1][2]) + a[i-1];
			dp[i][1] = Math.max(dp[i-1][0], dp[i-1][2]) + b[i-1];
			dp[i][2] = Math.max(dp[i-1][0], dp[i-1][1]) + c[i-1];
		}
		System.out.println(Math.max(dp[N][0], Math.max(dp[N][1], dp[N][2])));

	}

}

Measured memory_bytes: 97772
N,K = map(int,input().split())
#from collections import deque

#期待値はΣ(from 1 to pi)/len(pi)
P = list(map(int,input().split()))
cumsum = [0]*(N+1)
counter = []
for k in range(N):
    cumsum[k+1]=cumsum[k]+P[k]

for i in range(N-K+1):
    counter.append(cumsum[i+K]-cumsum[i])

print((max(counter)+K)/2)


Measured memory_bytes: 73224
#include<iostream>
#include<vector>
#include<map>
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n";
#pragma GCC optimize "trapv"
using namespace std;
typedef long long int ll;

int main()
{
    string s;
    cin>>s;
    if(s[0]==s[1] and s[1]==s[2] and s[1]=='R'){
        cout<<"3"<<endl;
    }
    else if(((s[0]==s[1]) || (s[1]==s[2])) && s[1]=='R')
    {
        cout<<"2"<<endl;
    }
    else if(s[0]=='R' || s[1]=='R' || s[2]=='R' ){
        cout<<"1"<<endl;
    }
    else{
        cout<<"0"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3624
n = int(input())
AC = 0
WA = 0
TLE = 0
RE = 0

for i in range(n):
    s = input()
    if s == "AC":
        AC += 1
    elif s == "WA":
        WA += 1
    elif s == "TLE":
        TLE += 1
    elif s == "RE":
        RE += 1

print("AC x " + str(AC))
print("WA x " + str(WA))
print("TLE x " + str(TLE))
print("RE x " + str(RE))

Measured memory_bytes: 9204
from collections import Counter
import sys
sys.setrecursionlimit(10 ** 6)


def dfs(n):
    if memo[n] >= 0:
        rst = memo[n]
    else:
        tmp = n
        one = 0
        while tmp > 0:
            one += tmp & 1
            tmp >>= 1
        m = n % one
        rst = 1 if m == 0 else 1 + dfs(m)
        memo[n] = rst
    return rst


N = int(input())
X = list(map(int, list(input())))
one = Counter(X)[1]


if one > 1:
    Sm = 0
    mm = one - 1
    tm = 1
    for i in range(N - 1, -1, -1):
        tm %= mm
        if X[i] == 1:
            Sm += tm
            Sm %= mm
        tm *= 2

Sp = 0
mp = one + 1
tp = 1
for i in range(N - 1, -1, -1):
    tp %= mp
    if X[i] == 1:
        Sp += tp
        Sp %= mp
    tp *= 2


memo = [-1] * (2 * (10 ** 5) + 10)
memo[0] = 0

for i in range(N):
    if X[i] == 0:
        m = (Sp + pow(2, N - 1 - i, mp)) % mp
    elif one > 1:
        m = (Sm - pow(2, N - 1 - i, mm)) % mm
    else:
        print(0)
        continue
    print(1 + dfs(m))


Measured memory_bytes: 12720
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
#define INF (1e9)
#define PI (acos(-1))

int main() {
	int n, m, ans = 0;
	cin >> n >> m;

	if (n > 1) {
		ans += n*(n - 1) / 2;
	}
	if (m > 1) {
		ans += m*(m - 1) / 2;
	}

	cout << ans;
	return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1 << 30)
#define LLINF (1LL << 60)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

ll dp[101010][2]; // dp[i][j]:=i番目まで見た時の最大値(j=1ならi番目について操作をしたとする)

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> a(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    dp[0][1] = -LLINF;
    for (ll i = 0; i < n; i++)
    {
        dp[i + 1][0] += max(dp[i][0] + a[i], dp[i][1] - a[i]);
        dp[i + 1][1] += max(dp[i][0] - a[i], dp[i][1] + a[i]);
    }
    cout << dp[n][0] << endl;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> H(N);
    for (int &h : H) cin >> h;
    reverse(H.begin(), H.end());
    
    for (int i = 0; i + 1 < N; i++) {
        if (H.at(i) < H.at(i + 1)) H.at(i + 1)--;
        if (H.at(i) < H.at(i + 1)) return cout << "No" << "\n", 0;
    }
    
    cout << "Yes" << "\n";
}

Measured memory_bytes: 640
// https://atcoder.jp/contests/abc063/tasks/arc075_b
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
const int cm = 1 << 17;
char cn[cm], *ci = cn + cm, ct;
inline char getcha() {
    if (ci - cn == cm) {
        fread(cn, 1, cm, stdin);
        ci = cn;
    }
    return *ci++;
}
inline int getint() {
    int A = 0;
    if (ci - cn + 16 > cm)
        while ((ct = getcha()) >= '0')
            A = A * 10 + ct - '0';
    else
        while ((ct = *ci++) >= '0')
            A = A * 10 + ct - '0';
    return A;
}
int n, a, b;
vector<int> v;
bool check(ll x) {
    ll c = 0;
    auto it = lower_bound(ALL(v), b * x);
    while (it != v.end()) {
        // 全体にbダメージ * x回
        ll h = *it - x * b;
        if (h > 0) {
            // a - b の追加ダメージ
            c += ceil((double)h / (a - b));
        }
        it++;
    }
    return c <= x;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    n = getint();
    a = getint();
    b = getint();
    v.resize(n);
    REP(i, n) v[i] = getint();
    sort(ALL(v));
    int ng = 0, ok = v[n - 1] * 2;
    while (ng + 1 != ok) {
        int x = (ng + ok) / 2;
        if (check(x))
            ok = x;
        else
            ng = x;
    }
    cout << ok << endl;

    return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
#define ll long long
#define ld long double
using namespace std;

ll mod=1000000007;
const int arm=5100000;
ll fac[arm], finv[arm], inv[arm];
void COMinit(ll m){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for (int i=2; i<arm; ++i){
        fac[i]=(fac[i-1]*i)%m;
        inv[i]=m-(inv[m%i]*(m/i))%m;
        finv[i]=(finv[i-1]*inv[i])%m;
    }
}
ll COM(int n, int k, ll m){
    if(n<k) return 0;
    if(n<0 || k<0) return 0;
    return (fac[n]*((finv[k]*finv[n-k])%m))%m;
}

int main() {
	int X, Y;
	cin >> X >> Y;
	if((X+Y)%3>0){
		cout << 0 << endl;
		return 0;
	}
	int K=(X+Y)/3;
	COMinit(mod);
	cout << COM(K, X-K, mod) << endl;
	return 0;
}

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

using ll = long long;


std::string s;
ll n;
std::vector<ll> vec(5, 0);

int P[10]={0,0,0,0,0,0,1,1,1,2};
int Q[10]={1,1,1,2,2,3,2,2,3,3};
int R[10]={2,3,4,3,4,4,3,4,4,4};

int main() {
    std::cin >> n;
    for (int i = 0; i < n; i++) {
        std::cin >> s;
        if (s[0] == 'M')
            vec[0]++;
        else if (s[0] == 'A')
            vec[1]++;
        else if (s[0] == 'R')
            vec[2]++;
        else if (s[0] == 'C')
            vec[3]++;
        else if (s[0] == 'H')
            vec[4]++;
    }
    ll ans = 0;
    for (int i = 0; i < 10; i++) {
        ans += (vec[P[i]] * vec[Q[i]] * vec[R[i]]);
    }
    std::cout << ans << std::endl;

}


Measured memory_bytes: 256
use std::io::{self, BufRead, BufWriter, Write};

fn solve<R, W>(reader: R, mut writer: W)
where
    R: BufRead,
    W: Write,
{
    let mut lines = reader.lines();
    let a_line = lines.next().unwrap().unwrap();
    let mut splited = a_line.trim().split_whitespace();
    let a: i32 = splited.next().unwrap().parse().unwrap();
    let b: i32 = splited.next().unwrap().parse().unwrap();

    let ans = ((b as f64 - 1.0) / (a - 1) as f64).ceil();
    writeln!(&mut writer, "{}", ans).unwrap();
}

fn main() {
    let stdio = io::stdin();
    let input = stdio.lock();

    let stdout = io::stdout();
    let output = BufWriter::new(stdout.lock());

    solve(input, output);
}

#[cfg(test)]
mod tests {
    use super::*;

    const TESTS: &'static [(&'static [u8], &'static [u8])] = &[
        (
            br"4 10", br"3
",
        ),
        (
            br"8 9", br"2
",
        ),
        (
            br"8 8", br"1
",
        ),
    ];

    #[test]
    fn test_b() {
        for &(input, expected) in TESTS {
            let mut output = Vec::new();
            solve(input, &mut output);
            let expected_str = String::from_utf8(expected.to_vec()).unwrap();
            let output_str = String::from_utf8(output).unwrap();
            assert_eq!(expected_str, output_str);
        }
    }
}


Measured memory_bytes: 4352
import collections
from scipy.misc import comb

N = int(input())

diclist = []

i=0
while i < N:
  temp = list(input())
  temp.sort()
  tmp_el = ''.join(temp)
  diclist.append(tmp_el)
  i += 1
  
c = collections.Counter(diclist)
clist = list(c.values()) 
ccomb = [comb(clist[i], 2, exact = True) for i in range(0,len(clist))]

print(sum(ccomb))


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

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

using namespace std;

void init();
void solve();

int main()
{
	init();
	solve();
}

int x[3];

void init()
{
	rep(i, 3) cin >> x[i];
	sort(x, x+3);
	if (x[0] + x[1] == x[2]) cout << "Yes" << endl;
	else cout << "No" << endl;
}

void solve()
{
	
}

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

char s[15][15];
int n, m;
int nm[15], mm[15], cnt[12][26];
vector<int> g[12];

bool bar(int i, bool self) {
  if(i == m) return true;
  if(self) {
    bool ok = true;
    for(int j=0;j<n;j++) {
      if(s[j][i] == s[nm[j]][i]) continue;
      ok = false;
      break;
    }
    if(ok) {
      mm[i] = i;
      int j = i+1;
      while(mm[j]>=0) j++;
      if(bar(j,false)) return true;
      mm[i] = -1;
    }
  }
  for(int j=i+1;j<m;j++) {
    if(mm[j]>=0) continue;
    bool ok = true;
    for(int k=0;k<n;k++) {
      if(s[k][i] == s[nm[k]][j]) continue;
      ok = false;
      break;
    }
    if(ok) {
      mm[i] = j;
      mm[j] = i;
      int k = i+1;
      while(mm[k]>=0) k++;
      if(bar(k,self)) return true;
      mm[i] = mm[j] = -1;
    }
  }
  return false;
}

bool foo(int i, bool self) {
  if(i == n) return bar(0,m&1);
  if(self) {
    nm[i] = i;
    int j = i+1;
    while(nm[j]>=0) j++;
    if(foo(j,false)) return true;
    nm[i] = -1;
  }
  for(int j : g[i]) {
    if(nm[j]>=0) continue;
    nm[i] = j;
    nm[j] = i;
    int k = i+1;
    while(nm[k]>=0) k++;
    if(foo(k,self)) return true;
    nm[i] = nm[j] = -1;
  }
  return false;
}

int main() {
  scanf("%d%d",&n,&m);
  for(int i=0;i<n;i++) {
    scanf("%s",s[i]);
    for(int j=0;j<m;j++)
      cnt[i][s[i][j]-'a']++;
  }
  for(int i=0;i<n;i++)
    for(int j=i+1;j<n;j++) {
      bool e = true;
      for(int k=0;k<26;k++) {
        if(cnt[i][k] == cnt[j][k]) continue;
        e = false;
        break;
      }
      if(e) g[i].push_back(j);
    }
  memset(nm,-1,sizeof(nm));
  memset(mm,-1,sizeof(mm));
  puts(foo(0,n&1)?"YES":"NO");
}


Measured memory_bytes: 256
import bisect

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
cuma, cumb = [0], [0]
for i in range(1, n+1):
    cuma.append(cuma[i-1] + a[i-1])
for i in range(1, m+1):
    cumb.append(cumb[i-1] + b[i-1])
ans = [0]
for i in range(n+1):
    if cuma[i] <= k:
        t = k - cuma[i]
        j = bisect.bisect_right(cumb, t)
        ans.append(i+j-1)
print(max(ans))


Measured memory_bytes: 50664
#include<tuple>
#include<deque>
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

LL N;
deque<int> ans;

LL nCk(int n, int k) {
    LL ret = 1;
    REP (i, k) {
	ret *= n-i;
	ret /= i+1;
    }
    return ret;
}
LL F(LL a, LL b, LL c, LL d) {
    LL x = 0;
    for (int i=1; i<=min(a, c); i++) {
	x += nCk(a, i) * nCk(c, i);
    }
    LL y = 0;
    for (int i=1; i<=min(b, d); i++) {
	y += nCk(b, i) * nCk(d, i);
    }
    LL ret = x * y;
    ret += 1LL<<(a+c-1);
    ret += 1LL<<(b+d-1);
    ret -= 2;
    return ret;
}

void MAIN() {
    using Tuple = tuple<LL, int, int, int, int>;
    vector<Tuple> X;
    for (int a=0; a<=12; a++)
	for (int b=a; b<=12; b++)
	    for (int c=a; c<=12; c++)
		for (int d=b; d<=12; d++) 
		    X.emplace_back(F(a, b, c, d), a, b, c, d);
    sort(X.begin(), X.end());

    scanf("%lld", &N);
    int cur = 1;
    while (N >= 3) {
	Tuple key(N+1, -1, -1, -1, -1);
	int k = lower_bound(X.begin(), X.end(), key) - X.begin();
	k--;
	LL g;
	int a, b, c, d;
	tie(g, a, b, c, d) = X[k];
	N -= g;
	REP (i, a) ans.push_back(cur);
	REP (i, b) ans.push_back(cur+1);
	REP (i, c) ans.push_back(cur);
	REP (i, d) ans.push_back(cur+1);
	cur += 2;
    }

    while (N) {
	REP (t, 2) ans.push_back(cur);
	N--;
	cur++;
    }

    printf("%d\n", (int)ans.size());
    rprintf("%d", ans.begin(), ans.end());
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10
#define BRUTE (9*8*7*6*5*4*3*2)

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

int ge[9], ja[9];

int dfs(int n, int gp, int jp, int *used){
  //  printf("%d %d %d\n", n, gp, jp);
  if(n == 9){
    if(gp > jp) return 1;
    else return 0;
  }
  int res = 0;
  rep(i, 9){
    if(used[i]) continue;
    used[i] = 1;
    res += dfs(n+1, gp + (ge[n]>ja[i]?ge[n]+ja[i]:0), jp + (ja[i]>ge[n]?ja[i]+ge[n]:0),  used);
    used[i] = 0;
  }
  return res;
}

int main(){
  int n;
  scanf("%d", &n);
  rep(i, n){
    rep(j, 9) scanf("%d", ge+j);
    rep(j, 9) scanf("%d", ja+j);
    int used[9] = {};
    int win = dfs(0, 0, 0, used);
    printf("%lf %lf\n", (double)win/BRUTE, 1-(double)win/BRUTE);
  }
  return 0;
}

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

#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((ll)(x).size())

const double PI  = acos(-1.0);
const double EPS = 1e-9;
const ll INF = 1e9+10;
const ll MOD = 1e9+7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define print(x) cerr << #x << " is " << x << endl;
//#define print(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; 

int N;
int A[200005], B[200005], C[200005];
ll ans[200005], cnt[200005];

vector<int> G[200005];
ll dfs(int p, int v){
    ll sub = 1;
    ll cntKeep = cnt[C[v]];
    
    for(int c: G[v]){
        if (c == p)continue;
        ll pre = cnt[C[v]];
        ll sub0 = dfs(v, c);
        sub += sub0;
        ll num = sub0 - (cnt[C[v]] - pre);
        ans[C[v]] -= num * (num + 1)/2;
    }
    cnt[C[v]] = cntKeep + sub;
    return sub;
}
bool flag[200005];
int main() {
    cin >> N;
    rep(i, N){
        cin >> C[i], C[i]--;
        ans[C[i]] = (ll)N * ((ll)N + 1)/2;
    }
    rep(i, N - 1){
        cin >> A[i] >> B[i], A[i]--, B[i]--;
        G[A[i]].push_back(B[i]);
        G[B[i]].push_back(A[i]);
    }
    dfs(-1, 0);
    rep(v, N){
        if (!flag[C[v]]){
            ll num = (ll)N - cnt[C[v]];
            ans[C[v]] -= num * (num + 1)/2;
            flag[C[v]] = true;
        }
    }        
    rep(v, N)cout << ans[v] << endl;
    return 0;
}

Measured memory_bytes: 38976
#-*-coding:utf-8-*-
import itertools

def solve(like_list, n, rp,  ans):
    for i in itertools.product(like_list, repeat=rp):
        if i[0] != 0:
            num = int(''.join(map(str, i)))
            if num >= int(n):
                ans = min(ans, num)
    return ans

def main():
    n, k = input().split()
    d_list = list(map(int, input().split()))

    like_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    for i in d_list:
        like_list.remove(i)
    ans = float('inf')
    ans = solve(like_list, n, len(n), ans)
    if ans == float('inf'):
        ans = solve(like_list, n, len(n)+1, ans)

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<iostream>
#include<string>
using namespace std;
typedef long long ll;
int main(){
  ll a,b,k;
  cin>>a>>b>>k;
  if(k<a) a-=k;
  else{
    b-=k-a;
    b=max(b,(ll)0);
    a=0;
  }
  cout<<a<<" "<<b<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N,ans,counter=0;

  cin >> N;

  for(int i=0;i<N;i++){
    int x=i+1,count=0;

    while(x%2==0){
      count++;
      x/=2;
    }

    if(counter<=count) {
      ans=i+1;
      counter=count;
    }
    
  }
 
  cout << ans << endl;
 
  return 0;
}

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

int main(){
  int N;
  cin >>N;
  vector<int> d(N);
  for(int i=0;i<N;i++){
    int x;
    cin >>x;
    d[i] = x;
  }
  
  long long sum = 0;
  
  for(int i=0;i<N;i++){
    sum += d[i];
  }
  
  long long sumsq = 0;
  
  for(int i=0;i<N;i++){
    sumsq += d[i]*d[i];
  }
  
  cout << (sum*sum - sumsq)/2 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007ll
#define pb push_back
#define vl vector<ll>
#define pll pair<ll,ll>
#define mp make_pair
using namespace std; 
ll gcdExtended(ll a, ll b, ll *x, ll *y); 
  
// Function to find modulo inverse of a 
ll modInverse(ll a, ll m) 
{ 
    ll x, y; 
    ll g = gcdExtended(a, m, &x, &y); 
    if (g != 1) 
        cout << "Inverse doesn't exist"; 
    else
    { 
        // m is added to handle negative x 
        ll res = (x%m + m) % m; 
        return  res; 
    } 
} 
  
// C function for extended Euclidean Algorithm 
ll gcdExtended(ll a, ll b, ll *x, ll *y) 
{ 
    // Base Case 
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
  
    ll x1, y1; // To store results of recursive call 
    ll gcd = gcdExtended(b%a, a, &x1, &y1); 
  
    // Update x and y using results of recursive 
    // call 
    *x = y1 - (b/a) * x1; 
    *y = x1; 
  
    return gcd; 
} 
ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;      // Initialize result 
    x = x % p;  // Update x if it is more than or 
                // equal to p 
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
} 
ll nCr(ll n,ll r,ll m)
{
    ll res = 1;
    for (ll i = 1; i <= r; ++i)
    {
        res = (res*(n-i+1)%MOD)*modInverse(i,MOD);
        res%=MOD;
    }
    return res;
}
int main()
{
    ll n,a,b;
    cin>>n>>a>>b;
    cout<<(n/(a+b))*a+min(n%(a+b),a)<<endl;
    //cout<<(power(2,n,MOD)-nCr(n,a,MOD)-nCr(n,b,MOD)-1+MOD+MOD+MOD)%MOD<<endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
  #include <set>
  #include <array>
  #include <map>
  #include <unordered_map>
  #include <unordered_set>
  #include <stack>
  #include <queue>
  #include <vector>
  #include <tuple>
  #include <string>
  #include <math.h>
  #include <time.h>
  #include <bitset>
  #include <stdio.h>
  #include <string.h>
  #include <iostream>
  #include <algorithm>
  #include <limits>
  #include <climits>
  #include <numeric>
  #include <functional>
  #include <iomanip>
  #include <cmath>

  #define lnd '\n'
  // #define reverse(i, n) for(ll i = n-1; i >= 0; --i)
  #define from(i, n) for (ll i = 0; i < n; ++i)
  #define loop(i, n) for(ll i = 0; i < n; i++)
  #define REPN(i, n) for (ll i = 1; i <= n; ++i)
  #define ALL(s) (s).begin(), (s).end()
  #define rALL(s) (s).rbegin(), (s).rend()
  #define sz(s) (int)(s).size()
  #define mk make_pair
  #define pb push_back
  #define sqr(s) ((s) * (s))

  using namespace std;

  typedef long long ll;
  typedef long long int lli;
  typedef long double ld;
  typedef unsigned long long ull;
  typedef unsigned int ui;

  template <class T>
  T GCD (T a, T b) {
    if(a == 0) return b;
    return GCD(b%a, a);
  }

  template <class T>
  T LCM(T a, T b){
    return a*b/GCM(a,b);
  }

  template <class T>
  T modpow(T x, T p){
      T res = 1;
      while(p > 0){
          if(p&1) res *= x;
          x *= x;
          p /= 2;
      }
      return res;
  }

  template <class T>
  T modpow(T x, T p, ll mod){
      T res = 1;
      while(p > 0){
          if(p&1) res = (res*x)%mod;
          x = (x*x)%mod;
          p /= 2;
      }
      return res%mod;
  }

  template <class T>
  void print(T a[], ll n){
      for (ll i = 0; i < n; i++) std::cout << a[i] << ' ';
      cout << endl;
  }

  template<class T>
  void printc(T c){
      for(auto const& v: c) std::cout << v << ' ';
      cout << endl;
  }

  struct HASH{
    size_t operator()(const pair<long,long>&x)const{
      return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
    }
  };

  bool pair_sort(const pair<int, int> &p1, const pair<int,int> &p2){
      if(p1.first != p2.first) return p1.first < p2.first;
      else return p1.second < p2.second;
  }

  const int INF = std::numeric_limits<int>::max();
  const ll M_INF = std::numeric_limits<ll>::min();
  const ll LL_INF = std::numeric_limits<ll>::max();

  void solution();
  int main(){
      ios_base::sync_with_stdio(0);
      cin.tie(0);
      cout.tie(0);
      solution();
      return 0;
  }

  void solution(){
    ll n;
    cin >> n;
    ll ans = 0;
    for(ll i = 2; i <= sqrt(n); i++){
      if(n%i) continue;
      ll count = 0;
      while(n%i == 0){
        n = n/i;
        count++;
      }

      ll index = 1;
      while(count >= index){
        ans++;
        count -= index;
        index++;
      }
    }
    if(n>1) ans++;

    cout << ans << endl;
  }    
    




Measured memory_bytes: 3168
#include<stdio.h>
#include<memory.h>
#include<iostream>
#include<algorithm>
#define maxn 105
#define ll long long
using namespace std;
ll w[maxn],v[maxn];
ll w1[maxn],w2[maxn],w3[maxn],w4[maxn];
ll n,W;

bool compare(ll a,ll b)
{
    return a>b;
}

int main()
{
    while(~scanf("%d %d",&n,&W))
    {
        int i;
        for(i=1;i<=n;i++)
        {
            scanf("%lld %lld",&w[i],&v[i]);
        }

        memset(w1,0,sizeof(w1));
        memset(w2,0,sizeof(w2));
        memset(w3,0,sizeof(w3));
        memset(w4,0,sizeof(w4));

        int a=0,b=0,c=0,d=0;
        for(i=1;i<=n;i++)
        {
            switch(w[i]-w[1])
            {
                case 0: w1[a++]=v[i];break;
                case 1: w2[b++]=v[i];break;
                case 2: w3[c++]=v[i];break;
                case 3: w4[d++]=v[i];break;
            }
        }

        sort(w1,w1+a,compare);
        sort(w2,w2+b,compare);
        sort(w3,w3+c,compare);
        sort(w4,w4+d,compare);

        int j,k,l;
        ll maxx=0;
        for(i=0;i<=a;i++)
        {
            for(j=0;j<=b;j++)
            {
                for(k=0;k<=c;k++)
                {
                    for(l=0;l<=d;l++)
                    {
                        ll ww;
                        ww=i*w[1]+j*(w[1]+1)+k*(w[1]+2)+l*(w[1]+3);
                        if(ww<=W)
                        {
                            ll vv=0;
                            int m;
                            for(m=0;m<i;m++)
                                vv+=w1[m];
                            for(m=0;m<j;m++)
                                vv+=w2[m];
                            for(m=0;m<k;m++)
                                vv+=w3[m];
                            for(m=0;m<l;m++)
                                vv+=w4[m];
                            if(vv>maxx) maxx=vv;
                        }
                    }
                }
            }
        }
        printf("%d\n",maxx);
    }
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	d := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&d[i])
	}
	sort.Sort(sort.IntSlice(d))
	var ans int
	ans = d[n/2] - d[n/2-1]
	fmt.Println(ans)
}


Measured memory_bytes: 7464
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <string>
#include <utility>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstring>
#include <complex>
#include <queue>
#include <stack>
#include <numeric>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
  int n,m;
  cin>>n>>m;
  vi a(n);
  rep(i,n)cin>>a[i];
  vp p(m);
  rep(i,m)cin>>p[i].se>>p[i].fi;
  sort(all(a));
  sort(all(p));
  reverse(all(p));
  int k=0;
  rep(i,n){
    if(a[i]<p[k].fi){
      a[i]=p[k].fi;
      p[k].se--;
    }
    if(p[k].se==0)k++;
    if(k==m)break;
  }
  cout<<accumulate(all(a),0ll)<<endl;
}


Measured memory_bytes: 2560