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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
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 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++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };




void solve() {
    int n; cin >> n;
    modint res = 0;
    rep1(i, 2000){
        int tmp = n - i*3;
        if(tmp < 0) break;
        res += comb(tmp+i-1, i-1);
    }
    cout << res << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 7748
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq

n = ni()
S =[]
for i in range(n):
    S.append(input())
def isok(a,b):
    for j in range(n):
        for i in range(j+1,n):
            if not S[(j+b)%n][(i+a)%n] == S[(i+b)%n][(j+a)%n]:
                return False
    return True

ans = 0
if isok(0,0):
    ans +=n
for a in range(1,n):
    if isok(a,0):
        ans+=n-a
    if isok(0,a):
        ans+=n-a
    #print("a",a,ans)
print(ans)

def solve2():
    ret=0
    for a in range(n):
        for b in range(n):
            if isok(a,b):
                ret+=1
                print(a,b)
    print(ret)
#solve2()


Measured memory_bytes: 74544
"""
author : halo2halo
date : 24, Jan, 2020
"""

import sys

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

a, b = map(int, readline().split())

print(max(a+b,a-b,a*b))


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

using namespace std; 
  
int main() 
{ 
 int n=0;
 cin>>n;
 if(n%10==2||n%10==4||n%10==5||n%10==7||n%10==9)
   cout<<"hon";
 if(n%10==0||n%10==1||n%10==6||n%10==8)
   cout<<"pon";
 if(n%10==3)
   cout<<"bon";
 return 0;
} 


Measured memory_bytes: 3584
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a%b)

def lcm(a, b):
    return a * b // gcd(a, b)
 
from functools import reduce

n = int(input())
a = list(map(int, input().split()))
print(reduce(lcm, a))


Measured memory_bytes: 6284
S = input()
N = len(S)

i = 0
p = ''
ans = 0
while i < N:
    if p == S[i]:
        if i+1 < N:
            p = S[i:i+2]
            i += 1
        else:
            break
    else:
        p = S[i]
    ans += 1
    i += 1

print(ans)


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

#define N 1000
#define pb push_back
#define mp make_pair
#define ll long long
#define mod 1000000007
#define fastio ios::sync_with_stdio(false); cin.tie(0)

int main(){
    fastio;
    // #ifndef ONLINE_JUDGE
    //     freopen("input.in", "r", stdin);
    //     freopen("output.out", "w", stdout);
    // #endif
    int a, b;
    cin >> a >> b;
    if(a > 12) cout << b;
    else if(a >= 6) cout << b/2;
    else cout << 0;
    cout << endl;


    return 0;
}

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

unsigned int xorshift() {
  static unsigned int nowx = 123456789, nowy = 362436069, nowz = 521288629,
                      noww = 88675123;
  unsigned int temp;
  temp = (nowx ^ (nowx << 11));
  nowx = nowy;
  nowy = nowz;
  nowz = noww;
  return (noww = (noww ^ (noww >> 19)) ^ (temp ^ (temp >> 8)));
}

long long d, score = -1;
const long long t = 26;
vector<long long> c, res;
vector<vector<long long>> s;
vector<set<int>> st;

void solve();
long long calc();
long long change(int day, int id, bool ch = false);

int main() {
  cin >> d;
  c.resize(t);
  res.resize(d);
  for (auto &p : c) cin >> p;
  s.resize(d, vector<long long>(t, 0));
  for (auto &v : s)
    for (auto &p : v) cin >> p;
  solve();
  calc();
  for (auto p : res) cout << p + 1 << endl;
  return 0;
}

void solve() {
  auto start = chrono::system_clock::now();
  auto nowt = chrono::system_clock::now();
  auto dur = nowt - start;
  auto msec = chrono::duration_cast<chrono::milliseconds>(dur).count();
  long long lim = 19500;
  vector<long long> memo(t, 0);
  for (int i = 0; i < d; ++i) {
    int id = 0;
    for (int j = 0; j < t; ++j)
      if (s[i][id] < s[i][j]) id = j;
    if (s[i][id] >= lim || i < t)
      res[i] = id;
    else {
      int cid = 0;
      for (int j = 0; j < t; ++j)
        if (memo[j] + c[j] > memo[cid] + c[cid]) cid = j;
      res[i] = cid;
    }
    for (int j = 0; j < t; ++j)
      if (j != res[i])
        memo[j] += c[j];
      else
        memo[j] = 0;
  }
  change(0, res[0], 1);
  while (msec < LIMTIME) {
    long long now = score, nowd = xorshift() % d, nowid = xorshift() % t,
              bf = 0;
    bf = res[nowd];
    if (now > change(nowd, nowid)) change(nowd, bf);
    nowt = chrono::system_clock::now();
    dur = nowt - start;
    msec = chrono::duration_cast<chrono::milliseconds>(dur).count();
  }
  cerr << calc() + (1000000) << endl;
}

long long calc() {
  long long sum = 0;
  vector<long long> memo(t, 0);
  for (int i = 0; i < d; ++i) {
    int num = res[i];
    sum += s[i][num];
    for (int j = 0; j < t; ++j)
      if (j != num)
        sum -= (memo[j] += c[j]);
      else
        memo[j] = 0;
  }
  return sum;
}

long long change(int day, int id, bool ch) {
  if (ch) {
    res[day] = id;
    score = calc();
    st.resize(t);
    for (int i = 0; i < t; ++i) st[i].insert(0), st[i].insert(d + 1);
    for (int i = 0; i < d; ++i) st[res[i]].insert(i + 1);
    return score;
  }
  int bf = res[day];
  score -= s[day][bf];
  score += s[day][id];
  st[bf].erase(day + 1);
  auto it = st[bf].upper_bound(day + 1);
  int righ = *it, lef;
  --it;
  lef = *it;
  score += ((righ - day - 1) * (righ - day - 2) +
            (day + 1 - lef) * (day - lef) - (righ - lef) * (righ - lef - 1)) *
           c[bf] / 2;
  it = st[id].upper_bound(day + 1);
  righ = *it;
  --it;
  lef = *it;
  score -= ((righ - day - 1) * (righ - day - 2) +
            (day + 1 - lef) * (day - lef) - (righ - lef) * (righ - lef - 1)) *
           c[id] / 2;
  res[day] = id;
  st[id].insert(day + 1);
  return score;
}


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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define INF 2000000000

#ifdef LOCAL
  #define eprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define eprintf(...) 0
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;

int main() {
  ULL n, k;
  cin >> n >> k;
  ULL ans = k * (pow(k-1, n-1));
  cout << ans;


  return 0;
}


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

using namespace std;

int main() {
    int N, M;
    int64_t K;

    int64_t time = 0;

    

    cin >> N >> M >> K;
  
  	int max_ij = 0;
    int max_j = M;

    vector<int> A(N, 0);
    vector<int> B(M, 0);

    vector<int64_t> A_sum(N+1, 0);
    vector<int64_t> B_sum(M+1, 0);

    int i, j;

    for(i = 0; i < N; i++) {
        cin >> A.at(i);
    }

    for(i = 0; i < M; i++) {
        cin >> B.at(i);
    }

    for(i = 0; i <= N; i++) {
        if(i == 0) {
            A_sum[i] = 0;
        } else {
            A_sum[i] += A_sum[i-1] + A.at(i-1);
        }
    }

    for(i = 0; i <= M; i++) {
        if(i == 0) {
            B_sum[i] = 0;
        } else {
            B_sum[i] += B_sum[i-1] + B.at(i-1);
        }
    }

    
    for(i = 0; i <= N; i++) {
        if(A_sum[i] > K) {
            break;
        }

        for(j = max_j; j >= 0; j--) {
            if(B_sum[j] <= K - A_sum[i]) {
                max_j = j;
                break;
            } 
        }

        max_ij = max(i + j, max_ij);
    }    

    cout << max_ij << endl;

	return 0;
}

Measured memory_bytes: 7968
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace MyProject
{
    class Program
    {
        static void Main(string[] args)
        {
#if Local
            var sw = new Stopwatch();
            sw.Start();
            Console.SetIn(new StreamReader("input.in"));
#endif

            var solver = new Solver();
            solver.Solve();
#if Local
            Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
        }
    }

    class Solver
    {
        public List<int> Update(IReadOnlyList<int> A)
        {
            var B = Enumerable.Repeat(0, A.Count).ToList();
            foreach (var i in Enumerable.Range(0, A.Count))
            {
                var l = Math.Max(0, i - A[i]);
                B[l]++;

                var r = Math.Min(A.Count - 1, i + A[i]);
                if (r + 1 < A.Count)
                {
                    B[r + 1]--;
                }
            }

            var sum = 0;
            return Enumerable.Range(0, A.Count).Select(i => sum += B[i]).ToList();
        }

        public void Solve()
        {
            var items = Console.ReadLine().Split().Select(elem => int.Parse(elem)).ToList();
            var N = items[0];
            var K = items[1];
            var A = Console.ReadLine().Split().Select(elem => int.Parse(elem)).ToList();

            foreach (var _ in Enumerable.Range(0, K))
            {
                A = this.Update(A);
                if (A.All(elem => elem == N))
                {
                    break;
                }
            };

            Console.WriteLine(string.Join(" ", A));
        }
    }
}


Measured memory_bytes: 60380
#include<bits/stdc++.h>
#define    ll      long long int
#define    Fori(a,b) for (ll i = a ; i<b ;i++ )
#define    Forj(a,b) for (ll j = a ; j<b ;j++ )
#define    Fork(a,b) for (ll k = a ; k<b ;k++ )
#define    W       while
#define    pb      push_back
#define    nl      cout<<endl
#define    mod     1000000007
#define    I       cin>>
#define    Out     cout<<
#define    DOD(i)  cout<<setprecision(i)<<fixed<<
#define    XXX     return 0
#define    Fast    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
using namespace std;
int main()
{
   Fast;
   ll n,m;I n>>m;
   ll e=0,o=0;
   if(n<2) e=0;
   else{
       e=n*(n-1)/2;
   }
   if(m<2) o=0;
   else{
       o=m*(m-1)/2;
   }
   cout<<e+o<<endl;
   XXX;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
 
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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
typedef long long ll;

int n;
int a[200010];
vector<pair<int, int>> v;
int main()
{

    cin >> n;
    REP(i, n)
        {
            cin >> a[i];
            v.push_back(make_pair(a[i], i));
        }
        sort(v.begin(), v.end());
    for (int i = 0; i < n; i++)
    {
        if(i==v[n-1].second){
            cout << v[n - 2].first << endl;
        }
        else{
            cout << v[n - 1].first << endl;
        }
    }
    

        return 0;
}

Measured memory_bytes: 4080
//  IT'S NEVER TOO LATE...

		    #include <bits/stdc++.h>
			#include <complex>
		    #define ll long long

			#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
			#define forn(i, n) fore(i, 0, n)
			#define fori(i, l, r) fore(i, l, (r) + 1)
			#define sz(v) int((v).size())
			#define all(v) (v).begin(), (v).end()
			#define pb push_back
			#define mp make_pair
		    #define ff first
		    #define ss second
			#define inf 1e9
		    
			#define C complex<int>
			#define X real()
			#define Y imag()

		    using namespace std; 

		    const double PI = atan(1)*4;


		    bool isprime(int n)
		    {
		        for(int i=2;i*i<=n;i++)
		            if(n%i==0)
		                return false;
		        return true;
		    }
		     
		    bool comp(pair<int,int> a, pair<int,int> b)
		    {
		    	return b.ff < a.ff ;
		    }

		    int modpow(int b,int p,int m)
		    {
		    	if(p==0) return 1%m;
		    	if(p%2) return (b*modpow(b,p-1,m))%m;
		    	int u=modpow(b,p/2,m);
		    	return (u*u)%m;
		    }

		    vector<pair<int,int>> ar[100005];
		    int vis[100005],from[100005];
		    double dis[100005];
		    
		     
		    void dikstra(int s,int n)
		    {
		    	forn(i,n+3)
		    	{
		    		dis[i]=inf;
		    		vis[i]=0;
		    		from[i]=-1;
		    	}

		    	dis[s]=0;
		    	priority_queue<pair<int,int>> q;
		    	q.push({0,s});
		    	from[s]=s;

		    	while(!q.empty())
		    	{
		    		pair<int,int> a;
		    		a=q.top();
		    		q.pop();
		    		//cout<<a.ss<<" ";

		    		if(vis[a.ss]) continue;
		    		vis[a.ss]=1;

		    		for(pair<int,int> b:ar[a.ss])
		    		{
		    			if(dis[b.ff]>dis[a.ss] + b.ss)
		    			{
		    				dis[b.ff]=dis[a.ss] + b.ss;
		    				from[b.ff]=a.ss;
		    				q.push({-dis[b.ff],b.ff});
		    			}
		    		}
		    	}
		    }


		    int main()
		    {
		    //	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
		     
		    	#ifndef ONLINE_JUDGE
		        freopen("input.txt","r", stdin);
		        freopen("output.txt", "w", stdout);
		        #endif
		     
		    	int t=1;
		    	//cin>>t;
		    	
		    	while(t--)
		    	{
		    		string s;
		    		cin>>s;

		    		cout<< ((s=="ABC")? "ARC" : "ABC");

		    	}

		    	cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";

		    	return 0;
		    }
		    				//              NOW IT'S TIME TO WAKE UP...

Measured memory_bytes: 6180
program pr2
  implicit none
  integer :: n, i, j
  integer,allocatable :: a(:)
  read(*,*) n
  allocate(a(n))
  read(*,*) a

  j = 0
  do i = 1, n, 2
     if ( mod(a(i),2) == 1 ) then
        j = j + 1
     end if
  end do

  write(*,'(i0)') j
  deallocate(a)
  stop
end program pr2


Measured memory_bytes: 2932
#include <stdio.h>
int main(void){
    long a,b;
    long x,y;
    
    while(scanf("%ld %ld", &a,&b) != EOF ){
        x=a;
        y=b;
        while(1){
            if(a>=b) a=a-b;
            else if(b>a) b=b-a;
            if(a==0 || b==0)break;
        }
        if(a==0){
            printf("%ld ",b);
            printf("%ld\n",x*y/b);
        }
        if(b==0){
            printf("%ld ",a);
            printf("%ld\n",x*y/a);
        }
    }
    
    return 0;
}

Measured memory_bytes: 596
//1_3_C
#include <stdio.h>
#include <math.h>

int main(void)
{
	int x, y;
	for(; scanf("%d %d", &x, &y), (x != 0 || y != 0);){
		printf("%.f %.f\n", fmin(x, y), fmax(x, y));
	}
	return 0;
}

Measured memory_bytes: 636
#![allow(dead_code)]
use std::cmp::{max, min};
fn solve(src: &str) -> String {
    let mut sc = Scanner::from_str(src);

    let n: usize = sc.read();
    let a: Vec<u64> = sc.vec(n);

    let xor_all = &a.iter().fold(0, |acc, &x| acc ^ x);
    let a: Vec<u64> = a.iter().map(|a| a & !xor_all).collect();

    let mut a = a;
    let mut r = 0;
    for d in (0..60).rev() {
        let mut j = r;
        while j < n && a[j] & (1 << d) == 0 {
            j += 1;
        }
        if j == n {
            continue;
        }
        if j > r {
            a[r] ^= a[j];
        }
        for j in r + 1..n {
            a[j] = min(a[j], a[j] ^ a[r]);
        }
        r += 1;
    }
    let a = a;

    let ans = xor_all + 2 * &a.iter().fold(0, |acc, &a| max(acc, acc ^ a));

    format!("{}\n", ans)
}
#[test]
fn test_solve() {
    assert_eq!(solve("3\n3 6 5\n"), "12\n");
    assert_eq!(solve("4\n23 36 66 65\n"), "188\n");
    assert_eq!(solve("20\n1008288677408720767 539403903321871999 1044301017184589821 215886900497862655 504277496111605629 972104334925272829 792625803473366909 972333547668684797 467386965442856573 755861732751878143 1151846447448561405 467257771752201853 683930041385277311 432010719984459389 319104378117934975 611451291444233983 647509226592964607 251832107792119421 827811265410084479 864032478037725181\n"), "2012721721873704572\n");
}
fn main() {
    let mut buf = String::new();
    use std::io::Read;
    std::io::stdin().read_to_string(&mut buf).unwrap();
    use std::io::Write;
    std::io::stdout().write_all(solve(&buf).as_bytes()).unwrap();
}
struct Scanner<I> {
    src: I,
}
impl<'a> Scanner<std::str::SplitWhitespace<'a>> {
    fn from_str(src: &'a str) -> Self {
        Scanner {
            src: src.split_whitespace(),
        }
    }
}
impl<'a, I> Scanner<I>
where
    I: std::iter::Iterator<Item = &'a str>,
{
    fn read<T: std::str::FromStr>(&mut self) -> T {
        self.src.next().unwrap().parse().ok().expect("Parse error")
    }
    fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    fn chars(&mut self) -> Vec<char> {
        self.src.next().unwrap().chars().collect()
    }
}


Measured memory_bytes: 8572
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(x) x.begin(),x.end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

ll a,v,b,w,t;
ll solve(){
   ll ans=0;
   

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

    cin>>a>>v>>b>>w>>t;
    ll d=abs(a-b);
    if(d==0){
         cout<<"YES"<<endl;
            return 0;
    }
    if(v-w<=0){
        cout<<"NO"<<endl;
        return 0;
    }else
    {
        ll d2=t*(v-w);
        if(d2>=d){
            cout<<"YES"<<endl;
            return 0;
        }else
        {
            cout<<"NO"<<endl;
            return 0;
        }
        
    }
    
    //cout<<solve()<<endl;
    return 0;
}

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

int main()
{
	int h, w;
	
	while (true){
		cin >> h >> w;

		if (!h && !w)
			break;

		for (int i = 0; i < h; i++){
			for (int j = 0; j < w; j++){

				if (i == 0 || i == h - 1)
					cout << "#";
				else if (j == 0 || j == w - 1)
					cout << "#";
				else
					cout << ".";
			}
			cout << endl;

		}
		cout << endl;

	}
	return 0;
}

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

using namespace std;

int main(){

string S;
int K;
    cin>>K;

fflush(stdin); cin>>S;

if(K>=S.length())
{
    cout<<S;
}
if(K<S.length())
{
    string k="";
    for(int i=0;i<K;i++)
        {
            k=k+S[i];
        }
        k=k+"...";
        cout<<k;
}
return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <cstdio>
#include <climits>
#include <cmath>
#include <array>
#include <functional>
#include <sstream>
#include <list>
#include <set>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const double eps=1e-9;
const int inf=1e9;
typedef pair<int,int> P;
struct Point
{
  double x,y;
  Point(){x=0;y=0;}
  Point(double d_x,double d_y){x=d_x,y=d_y;}
  double operator*(Point obj){return obj.x*x+obj.y*y;}
  double operator%(Point obj){return obj.y*x-obj.x*y;}
  Point operator*(double b){Point tmp;tmp.x=x*b;tmp.y=y*b;return tmp;}
  Point operator/(double b){Point tmp;tmp.x=x/b;tmp.y=y/b;return tmp;}
  Point operator+(Point obj){Point tmp;tmp.x=x+obj.x;tmp.y=y+obj.y;return tmp;}
  Point operator-(){Point tmp;tmp.x=-x;tmp.y=-y;return tmp;}
  Point operator-(Point obj){Point tmp;tmp.x=x-obj.x;tmp.y=y-obj.y;return tmp;}
  Point operator-=(Point obj){x-=obj.x;y-=obj.y;return *this;}
  Point operator+=(Point obj){x+=obj.x;y+=obj.y;return *this;}
  Point operator/=(double b){x=x/b;y=y/b;return *this;}
  Point operator*=(double b){x=x*b;y=y*b;return *this;}
  double size(){return hypot(x,y);}
  Point unit(){return Point(x/size(),y/size());}
  Point normal(){return Point(y,-x);}
  double atan(){return atan2(y,x);}
};

bool operator<(Point a,Point b){return a.x!=b.x?a.x<b.x:a.y<b.y;}
bool operator>(Point a,Point b){return b<a;}
bool operator<=(Point a,Point b){return !(b<a);}
bool operator>=(Point a,Point b){return !(a<b);}
bool operator==(Point a,Point b){return (a-b).size()<eps;}
bool operator!=(Point a,Point b){return !(a==b);}

bool equal(double a,double b){return abs(a-b)<eps;}
double cross(Point a,Point b){return a%b;}
double dot(Point a,Point b){return a*b;}

int ccw(Point a,Point b,Point c)
{
  b=b-a;
  c=c-a;
  if(b%c>0) return +1;
  else if(b%c<0)return -1;
  else if(b*c<0) return +2;
  else if(b.size()<c.size()) return -2;
  else return 0;
}

int quest,p,q;

string cmp(string a,string b)
{
  if(a.size()>b.size()) return a;
  if(b.size()>a.size()) return b;
  return max(a,b);
}

int main(int argc,char const* argv[])
{
  cin >> quest;
  for(int k=0;k<quest;k++)
    {
      cin >> p >> q;
      int mx=p*p+q*q;
      bool clear=false;
      for(int i=2;i*i<=mx;i++)
	{
	  if(mx%i==0)
	    {
	      int y=mx/i;
	      for(int j=0;j*j<=i;j++)
		{
		  double diff=sqrt(i-j*j);
		  int tmp=(int)diff;
		  if(diff==tmp)
		    {
		      cout << "C" << endl;
		      clear=true;
		      break;
		    }
		}
	      if(clear) break;
	      for(int j=0;j*j<=y;j++)
		{
		  double diff=sqrt(y-j*j);
		  int tmp=(int) diff;
		  if(diff==tmp)
		    {
		      cout << "C" << endl;
		      clear=true;
		      break;
		    }
		}
	      if(clear) break;
	    }
	  if((i+1)*(i+1)>mx)
	    {
	      cout << "P" << endl;
	    }
	}
    }
      return 0;
}



Measured memory_bytes: 3100
Option Strict On
Imports System.Collections.Generic
Imports System.Console

Module Program
    Sub Main()
        Dim n As Integer = NextInt()
        Dim t As Integer() = New Integer(n - 1) {}
        For i As Integer = 0 To n - 1
            t(i) = NextInt()
        Next

        Dim m As Integer = NextInt()
        Dim ans As String() = New String(m - 1) {}

        For i As Integer = 0 To m - 1
            Dim p As Integer = NextInt() - 1
            Dim x As Integer = NextInt()
            ans(i) = (Sum(t) - t(p) + x).ToString()
        Next

        WriteLine(String.Join(vbLf, ans))
    End Sub

    Function Sum(t As Integer()) As Integer
        Dim result As Integer = 0
        For Each v As Integer In t
            result += v
        Next
        Return result
    End Function

    Function NextInt() As Integer
        Return CInt(NextString())
    End Function

    Function NextString() As String
        Dim result As New List(Of Char)
        Do
            Dim tmp As Integer = Read()
            If tmp < 0 Then Exit Do
            Dim nextChar As Char = Chr(tmp)

            If Not Char.IsWhiteSpace(nextChar) Then
                result.Add(nextChar)
            ElseIf nextChar <> vbCr Then
                Exit Do
            End If
        Loop
        Return New String(result.ToArray())
    End Function

End Module


Measured memory_bytes: 19920
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll dp[51][2501];

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

  dp[0][0] = 1;

  REP(i, n){
    REPR(c, n){
      REP(s, 2501 - x[i]){
        dp[c + 1][s + x[i]] += dp[c][s];
      }
    }
  }

  ll ans = 0;
  REP(i, n) ans += dp[i + 1][(i + 1) * a];

  cout << ans << endl;

}


Measured memory_bytes: 1280
#include "iostream"
#include "algorithm"
#include "string"

using namespace std;

const long long  int MOD = 1000000007;

int main(){
	long long int A,B;
  cin>>A>>B;
	if(B%A==0)cout<<A+B<<endl;
	else cout<<B-A<<endl;
		return 0;
}

Measured memory_bytes: 256
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define ea(i, n) for(auto&& i: n)
#define so(n) sort(n.begin(), n.end())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// abs 絶対値, rtsq ルート, pow(a, n) aのn乗, int 2*10^9

int main() {
  int X;
  ci(X);
  if(X == 2){
    co(2);
    rt;
  }
  repi(i, X - 1, 100004){
    bool f = true;
    repi(j, 2, X){
      if(i % j == 0){
        f = false;
      }
    }
    if(f == true){
      co(i);
      rt;
    }
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
using namespace std;

int main(){

	int K,A[11],B[11],C[11],ans,tmp_digit,POW[10] = {1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000};
	char buf_A[11],buf_B[11];

	stack<int> S;

	for(int i = 0; i <= 10; i++){
		A[i] = 0;
		B[i] = 0;
	}

	scanf("%s %s %d",buf_A,buf_B,&K);

	int a_length,b_length;

	for(a_length = 0; buf_A[a_length] != '\0'; a_length++);
	for(b_length = 0; buf_B[b_length] != '\0'; b_length++);

	for(int i = 0;i < a_length; i++){
		A[10-i] = buf_A[(a_length-1)-i] - '0';
	}

	for(int i = 0;i < b_length; i++){
		B[10-i] = buf_B[(b_length-1)-i] - '0';
	}

	for(int digit = 10; digit >= 1; digit--){

		if(A[digit] >= B[digit]){
			C[digit] = A[digit] - B[digit];
		}else{
			C[digit] = 10 + A[digit] - B[digit];
			tmp_digit = digit-1;
			while(true){
				if(A[tmp_digit] != B[tmp_digit]){

					S.push(POW[10-tmp_digit]);
					if(A[tmp_digit] > B[tmp_digit]){
						A[tmp_digit]--;
						break;
					}else{
						if(A[tmp_digit] != 0){
							A[tmp_digit]--;
							break;
						}else{
							A[tmp_digit] = 9;
							tmp_digit--;
						}
					}
				}else{ //A[tmp_digit] = B[tmp_digit]
					if(A[tmp_digit] != 0){
						A[tmp_digit]--;
						break;
					}else{
						A[tmp_digit] = 9;
						tmp_digit--;
					}
				}
			}
		}
	}

	ans = 0;

	for(int i = 1; i <= 10; i++){
		ans += POW[10-i]*C[i];
	}

	while(S.empty() == false && K > 0){
		ans += S.top();
		K--;
		S.pop();
	}

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

	return 0;
}

Measured memory_bytes: 2760
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int n=s.size(),ans=0,ans2=0;
	char f=s[0];
	for(int i=1;i<n;i++)
	{
		if(i%2)
		{
			if(s[i]==f)
			ans++;
		}
		else
		{
			if(s[i]!=f)
			ans++;
		}
	}
	f=s[1];
	for(int i=0;i<n;i++)
	{
		if(i%2)
		{
			if(s[i]!=f)
			ans2++;
		}
		else
		{
			if(s[i]==f)
			ans2++;
		}
	}
	cout<<min(ans,ans2);
	return 0;
}

Measured memory_bytes: 512
n,k=map(int,input().split())
h=list(map(int,input().split()))
m=max(h)*(n-1)
dp=[m]*n
dp[0]=0
for i in range(n):
  if i+1+k<=n:
    r=k
  else:
    r=n-i-1
  for kk in range(1,r+1):
    dp[i+kk]=min(dp[i+kk],dp[i]+abs(h[i+kk]-h[i]))
print(dp[n-1])


Measured memory_bytes: 52448
n = int(input())
for i in range(1,25):
    if n %4*i==0:
        print('Yes')
        exit()
for i in range(1,14):
    if n %7*i==0:
        print('Yes')
        exit()
for i in range(1,25):
    for j in range(1,14):
        if n%(4*i+7*j)==0:
            print('Yes')
            exit()
else:
    print('No')

Measured memory_bytes: 3064
S = input()
T = input()

'''
same = True
for i in range(len(S)):
    for j in range(len(S)):
        second = i + j
        if second >= len(S):
            second = second - len(S)
            if S[j] != S[second]:
                same = False
        else:
            if S[j] != S[second]:
                same = False

print(same)
'''
same = False
for i in range(len(S)):
    second = ""
    for j in range(len(T)):
        value = i + j
        if value >= len(T):
            value -= len(T)
            second += T[value]
        else:
            second += T[value]
    if S == second:
        same = True
        break

if same:
    print("Yes")
else:
    print("No")

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

int main() {
  
  int N,M;
  int sum =0;
  
  cin >> N >> M;
  
  vector<int> vec(M);
  
  for (int i = 0; i < M;i++){
    cin >> vec.at(i);
    sum += vec.at(i);
  }
  
  if(N >= sum){
    cout << N - sum << endl;
  }
  
  else{
    cout << -1 << endl;
  }
  
  
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define pb push_back
#define pf push_front
#define acm ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
int main()
{
int a,b,sum=1,s;
cin>>a>>b;
s=a-1;
if(b==1){cout<<0;
return 0;}
while(a<b){
    a+=s;
    sum+=1;
}
cout<<sum;




}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main()
{
  ll N, Z, W;
  cin >> N >> Z >> W;
  ll ans = 0;
  ll a_n1;
  for (ll i = 0; i < N; ++i) {
    ll a;
    cin >> a;
    if (i == N - 2) {
      a_n1 = a;
    }
    if (i == N - 1) {
      if (N != 1) {
        ans = max(ans, abs(a_n1 - a));
      }
      ans = max(ans, abs(W - a));
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<string>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main (){
	int N,i = 0;
	while(~scanf("%d",&N)){

		while((i*i)<=N){
			if((i*i==N)||((i*i) < N)&&((i+1)*(i+1)>N)){
				printf("%d\n",i*i);
				break;
			}
			else
				i++;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n)    for(int i=a; i<=n; ++i)
#define rep1(i,a,n)   for(int i=a; i>=n; --i)
#define pb            push_back
#define int           long long
#define fr            first
#define sc            second
#define vc            vector
#define sz(v)         (int)v.size()
#define all(x)        (x).begin(),(x).end()
#define M             1000000007
#define MM            998244353
#define PI            3.14159265358979
#define INF           1000000000000000

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mii;

int n,m,ans; string str;

vi v1;
vi v[100005];
vi v3[100005];
int v2[100005];
void dfs(int x){
    v2[x]=1;
    for(int i:v[x]){
        if(!v2[i]){
            dfs(i);
        }
    }
    v1.pb(x);
}
int solve(){
    cin>>n>>m;
    rep(i,1,m){
        int a,b; cin>>a>>b;
        v[a].pb(b);
        v3[b].pb(a);
    }
    rep(i,1,n){
        if(!v2[i]){
            dfs(i);
        }
    }
    reverse(all(v1));
    rep(i,1,n) v2[i]=0;
    v2[v1[0]]=0;
    rep(i,1,sz(v1)-1){
        int t=v1[i];
        for(int j:v3[t]){
            v2[t]=max(v2[t],v2[j]+1);
        }
        ans=max(ans,v2[t]);
    }
    cout<<ans;
    return 0;
}

signed main() {
    ios::sync_with_stdio(0);
    //std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    // cin>>t;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 15228
import fractions
n, X = map(int, input().split())
x = list(map(int, input().split()))

d = []
d.append(abs(X-x[0]))
gc = d[0]
for i in range(1, n):
	d.append(abs(X-x[i]))
	gc = fractions.gcd(d[i], gc)
print(gc)


Measured memory_bytes: 16244
N = int(input())


ans = [0] * (10 ** 4 + 1)
for i in range(1, 101):
    for j in range(1, 101):
        for k in range(1, 101):
            a = i ** 2 + j ** 2 + k ** 2 + i * j + j * k + i * k
            if a <= 10 ** 4:
                ans[a] += 1

for i in ans[1:N+1]:
    print(i)
            
                

Measured memory_bytes: 9180
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

# Factoring by trial split -- START --
def getPrimeList(n):
  l=[]
  t=int(math.sqrt(n))+1
  
  for a in range(2,t):
    while n%a==0:
      n//=a
      l.append(a)
  
  if n!=1:
    l.append(n)
  
  return l
# Factoring by trial split --- END ---

# Summarize count of factor within list -- START --
def summarize_list(l):
  sl=sorted(l)

  a=sl[0]
  c=1
  res=[]

  for x in sl[1:]:
    if x==a:
      c+=1
    else:
      res.append([a,c])
      a=x
      c=1
  res.append([a,c])

  return res
# Summarize count of factor within list --- END ---

def main():
  n=I()
  if n==1:
    return 0
  l=getPrimeList(n)
  a=summarize_list(l)

  # print(l)
  # print(a)

  ans=0
  for x,y in a:
    st=1
    while True:
      if st>y:
        break

      ans+=1
      y-=st
      st+=1

  return ans

# main()
print(main())


Measured memory_bytes: 10740
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;

public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        string s = Console.ReadLine();
        if (s.Substring(0, n / 2) == s.Substring(n / 2))
        {
            Console.WriteLine("Yes");
            return;
        }
        Console.WriteLine("No");
    }
}

Measured memory_bytes: 11092
#include<iostream>

using namespace std;

int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    if(a<b && a<c)
    {
        if(b<c)
        {
            cout << a << " " << b << " " << c << endl;
        }
        else
        {
            cout << a << " " << c << " " << b << endl;
        }
    }
    else if(b<c)
    {
        if(c<a)
        {
        cout << b << " " << c << " " << a << endl;
        }
    }
    else if(b<a)
    {
        cout << c << " " << b << " " << a << endl;
    }
    else 
    {
        cout << c << " " << a << " " << b << endl;
    }
    return 0;
}


Measured memory_bytes: 3092
//Name: Gather the Maps!
//Level: 3
//Category: グラフ,Graph,幅優先探索
//Note: 

/**
 * まとめた地図を誰が持っているかは、あとで都合がいいように変えれば良い。
 * ある子孫が持っている可能性のある地図集合は一意に定まる（もしも複数の可能性があるなら、
 * マージして1つの地図にまとめられる）ので、要するに非決定性オートマトンをたどるのと同じことになる。
 *
 * オーダーは O(N log N)。
 */
#include <iostream>
#include <vector>
#include <bitset>

using namespace std;

typedef bitset<50> State;

bool solve(bool first) {
    int N;
    if(!(cin >> N)) return false;
    if(!N) return false;

    vector<int> members[30];
    vector<State> state(N);
    for(int i = 0; i < N; ++i) {
        int f;
        cin >> f;
        while(f--) {
            int d;
            cin >> d;
            --d;
            members[d].push_back(i);
        }
        state[i].set(i);
    }
    int ans = -1;
    if(N == 1) {
        ans = 1;
    } else {
        for(int d = 0; d < 30; ++d) {
            State s;
            for(int i : members[d]) {
                s |= state[i];
            }
            if(s.count() == N) {
                ans = d+1;
                break;
            }
            for(int i : members[d]) {
                state[i] = s;
            }
        }
    }
    cout << ans << endl;
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout.setf(ios::fixed);
    cout.precision(10);

    bool first = true;
    while(solve(first)) {
        first = false;
    }
    return 0;
}

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

using namespace std;

int n, p, q, r;

int main()
{
    ios_base::sync_with_stdio( false ), cin.tie( nullptr ), cout.tie( nullptr );

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

    for( int i = 2, t = n - 1; i < t; i++ )
        if ( s[ i ] == 'C' )
            p++, r = i;

    if ( p == 1 )
        for( int i = 1; i < n; i++ )
            if ( i != r and isupper( s[ i ] ) )
                q++;

    const string answer[] = { "WA", "AC" };

    cout << answer[ s[ 0 ] == 'A' and p == 1 and q == 0 ];
}

Measured memory_bytes: 256
from fractions import gcd  # for python 3.5~, use math.gcd


def main():
    N, M = list(map(int, input().split(' ')))
    half_A = list(map(lambda x: int(x) // 2, input().split(' ')))
    lcm = 1
    for half_a in half_A:
        lcm *= half_a // gcd(lcm, half_a)
        if lcm > M:
            print(0)
            exit(0)
    for half_a in half_A:
        if (lcm // half_a) % 2 == 0:
            print(0)
            exit(0)
    num_multiples = M // lcm
    print((num_multiples + 1) // 2)  # count only cases that ratios are odd numbers.


if __name__ == '__main__':
    main()

Measured memory_bytes: 16312
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s, t;
    cin >> s >> t;
    vector<set<char>> m(256);
    for(int i = 0; i < s.size(); i++) {
        m[s[i]].insert(t[i]);
    }
    vector<int> in(256), out(256);
    for(char u = 'a'; u <= 'z'; u++) {
        for(char v : m[u]) {
            out[u]++;
            in[v]++;
        }
    }
    bool can = true;
    for(char c = 'a'; c <= 'z'; c++) {
        can &= out[c] <= 1 and in[c] <= 1;
    }
    cout << (can ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 916
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

    int n;
    ll m;
    cin >> n >> m;
    vector<int> a(n);
    for(int i = 0; i < n; ++i)  cin >> a[i];
    sort(a.begin(), a.end());
    vector<ll> CumulativeSum(n + 1);
    CumulativeSum[0] = 0;
    for(int i = 0; i < n; ++i){
        CumulativeSum[i + 1] = CumulativeSum[i] + a[i];
    }

    auto check = [&](int x) -> pair<ll, ll> {
        ll sum = 0, cnt = 0;
        for(int i = 0; i < n; ++i){
            int p = lower_bound(a.begin(), a.end(), x - a[i]) - a.begin();
            sum += CumulativeSum[n] - CumulativeSum[p];
            sum += (ll)a[i] * (n - p);
            cnt += n - p;
        }
        return make_pair(sum, cnt);
    };

    int lb = 0, ub = 1e+6;
    while(ub - lb > 1){
        int mid = (lb + ub) / 2;
        auto foo = check(mid);
        if(foo.second >= m) lb = mid;
        else    ub = mid;
    }
    auto foo = check(lb);
    ll ans = foo.first;
    ans -= (ll)lb * (foo.second - m);
    cout << ans << endl;
}

Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <cctype>  // std::islower(), std::isupper(), std::tolower, std::toupper
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()

typedef long long ll;

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

  if ( N <= 999 ) std::cout << "ABC" << std::endl;
  else std::cout << "ABD" << std::endl;

  return 0;
}


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

using namespace std;

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

    vector<int> cnt(26, 50);
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;

        vector<int> c(26, 0);
        for (int j = 0; j < static_cast<int>(s.size()); j++) {
            c[s[j] - 'a']++;
        }

        for (int j = 0; j < 26; j++) {
            cnt[j] = min(cnt[j], c[j]);
        }
    }

    for (int i = 0; i < 26; i++) {
        for (int j = 0; j < cnt[i]; j++) {
            cout << static_cast<char>(i + 'a');
        }
    }
    cout << endl;
}


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

string s[4] = {"dream", "dreamer", "erase", "eraser"};

int main()
{
  string S;
  cin >> S;
  
  reverse(S.begin(), S.end());
  
  rep(i, 4)
  {
    reverse(s[i].begin(), s[i].end());
  }
  
  bool is_divide = true;
  for (int i = 0; i < S.size();)
  {
    bool tmp_is_divide = false;
    rep(j, 4)
    {
      if (s[j] == S.substr(i, s[j].size()))
      {
        tmp_is_divide = true;
        i += s[j].size();
      }
    }
    
    if (!tmp_is_divide)
    {
      is_divide = false;
      
      break;
    }
  }
  
  if (is_divide)
  {
    printf("YES");
  }
  else
  {
    printf("NO");
  }

  return 0;
}


Measured memory_bytes: 512
#define USE_MATH_DEFINES 1
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define MOD 998244353ll
#define INF 1000000000000000000ll
#define EPS 1e-9
#define getchar_unlocked _getchar_nolock
#define putchar_unlocked _putchar_nolock

typedef long long         ll;
typedef long double       ld;
typedef pair <ll,ll>      pl;
typedef tuple <ll,ll,ll>  tl;

ll N, K, A[200005], V[200005];

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin >> N >> K;
	for (ll i = 1; i <= N; i++) cin >> A[i];
	
	memset(V, -1, sizeof V);
	V[1] = 0;
	ll step = 0;
	ll luga = 1;
	ll c_luga = -1;
	ll c_step = -1;
	ll c_prev = -1;
	
	while (step < K) {
		step++;
		if (V[A[luga]] == -1) {
			V[A[luga]] = step;
			luga = A[luga];
		} else {
			c_luga = A[luga];
			c_step = step - V[A[luga]];
			c_prev = V[A[luga]];
			luga = A[luga];
			break;
		}
	}
	
	if (step == K) cout << luga;
	else {
		step = 0;
		luga = c_luga;
		ll more = (K - c_prev) % c_step;
		while (step < more) {
			step++;
			luga = A[luga];
		}
		cout << luga;
	}
	
	
	
    return 0;
}

Measured memory_bytes: 6780
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for (ll i = 0; i < (ll)(n); i++)
ll dp[3001][3001][4];
ll gds[3001][3001];
int main(){
	ll R,C,K;
	cin>>R>>C>>K;
	rep(i,K){
		ll r,c,v;
		cin>>r>>c>>v;
		gds[r-1][c-1]=v;
	}
	rep(r,R){
		rep(c,C){
			if(r==0){
				if(c==0){
					rep(i,3){
						dp[r][c][i]=gds[r][c];
					}
					dp[r][c][3]=0;
				}else{
					rep(i,3){
						dp[r][c][i]=max(dp[r][c-1][i+1]+gds[r][c],dp[r][c-1][i]);
					}
					dp[r][c][3]=dp[r][c-1][3];
				}
			}else{
				if(c==0){
					rep(i,3){
						dp[r][c][i]=gds[r][c]+dp[r-1][c][0];
					}
					dp[r][c][3]=dp[r-1][c][0];
				}else{
					rep(i,3){
						dp[r][c][i]=max(max(dp[r][c-1][i+1]+gds[r][c],dp[r][c-1][i]),dp[r-1][c][0]+gds[r][c]);
					}
					dp[r][c][3]=max(dp[r][c-1][3],dp[r-1][c][0]);
				}
			}
		}
	}
	cout<<dp[R-1][C-1][0]<<endl;
}


Measured memory_bytes: 355036
#include <iostream>

int main()
{
  int A[100];
  int N;
  std::cin >> N;
  for (int i = 0; i < N; ++i)
  {
    std::cin >> A[i];
  }

  bool ordered = false;
  int i = N - 1;
  int sw = 0;
  while (i > 0 && !ordered)
  {
    ordered = true;
    for (int j = 0; j < i; ++j)
    {
      if (A[j] > A[j + 1])
      {
        std::swap(A[j], A[j + 1]);
        ordered = false;
        ++sw;
      }
    }
    --i;
  }

  for (int i = 0; i < N; ++i)
  {
    if (i > 0) std::cout << " ";
    std::cout << A[i];
  }
  std::cout << std::endl;
  std::cout << sw << std::endl;  

  return 0;
}



Measured memory_bytes: 3124
#include<stdio.h>
#define  N 100

int main() {
	int m[N][N];
	int i ,j ,n, u, k, v; 

	scanf("%d", &n);
	for ( i = 0; i <n; i++ ) {
		for ( j = 0; j <n; j++ ) m[i][j] = 0;
	}

	for ( i = 0; i < n; i++ ) {
		scanf("%d %d", &u, &k);
		u--;
		for ( j = 0; j < k; j++ ) {
			scanf("%d", &v);
			v--;
			m[u][v] = 1;
		}
	}
  
	for ( i = 0; i < n; i++ ){
		for ( j = 0; j < n; j++ ){
			if (j) printf(" ");
			printf("%d", m[i][j]);
		}
		printf("\n");
	}

	return 0;
}


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

using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  ll ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (i % 3 != 0 && i % 5 != 0) ans += i;
  }
  cout << ans << '\n';
  return 0;
}



Measured memory_bytes: 3636