akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<map>
#define vi vector<int>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n) 

double compute(){
  int n,m;
  double ret = 0;
  double imp=1,p=1;/*ツ振ツづィツづ按つィツつオツづ可づ按づゥ*/
  cin>>n>>m;
  vector<double> v(m),prob(m);
  rep(i,m){
    cin>>v[i]>>prob[i];
    imp -= prob[i];
  }
  rep(i,100){
    rep(j,m){
      ret += p * prob[j] * v[j];
    }
    p *= imp;
  }
  return ret;
}

main(){
  int t;
  while(cin>>t && t){
    vector<double> ep(t);
    rep(i,t)ep[i] = compute();
    double p=compute();;
    rep(i,(int)ep.size()){
      if (p + 0.0000001 < ep[i]){
	cout <<"YES"<<endl;
	goto end;
      }
    }
    cout <<"NO"<<endl;
  end:;
  }
}

Measured memory_bytes: 0
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

ll a[51] = {1}, p[51] = {1};

ll f(ll N, ll X) {
    if (N == 0) {
        return X <= 0 ? 0 : 1;
    } else if (X <= 1 + a[N - 1]) {
        return f(N - 1, X - 1);
    } else {
        return p[N - 1] + 1 + f(N - 1, X - 2 - a[N - 1]);
    }
}

// main
int main() {
    ll N, X;
    cin >> N >> X;
    REP(i, N) {
        a[i + 1] = 2 * a[i] + 3;
        p[i + 1] = 2 * p[i] + 1;
    }
    cout << f(N, X) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;int h,w,k,l,m,a,b,s,t,u,v,i,j,x[999][999];main(){while(1){memset(x,0,sizeof(x));v=0;cin>>k;if(!k){break;}cin>>w>>h;for(i=0;i<k;i++){cin>>a>>b;x[a][b]=1;}cin>>s>>t;for(i=1;i<=w;i++){for(j=1;j<=h;j++){u=0;for(l=0;l<s;l++){for(m=0;m<t;m++){if(x[i+l][j+m]){u++;}}}v=max(v,u);}}cout<<v<<endl;}}

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

const ll INF = 1LL << 62;
const double PI = acos(-1);
const double eps = 1e-10;

int main() {
  int a, b;
  cin >> a >> b;
  cout << max(0, a - 2 * b) << endl;
  return 0;
}


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

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	ll total = 0;
	rep(i, n){
		int in;
		cin >> in;
		total += (ll)in;
		a.at(i) = in;
	}
	sort(a.begin(), a.end());

	vector<ll> tv(n);
	tv.at(0) = 0;
	rep(i, n){
		if(i != 0) tv.at(i) = tv.at(i-1);
		tv.at(i) += a.at(i);
	}

	int ans = 0;
	int left = 0, right = n, ii;
	while(1){
		ii = (right + left)/2;
		//cerr << left << " " << right << endl;
		if(left >= right) break;
		bool flag = true;
		ll temp = tv.at(ii);
		rep2(j, ii+1, n){
			if(temp*2 >= a.at(j)) temp +=a.at(j);
			else{
				flag = false;
				break;
			}
		}
		if(flag == true){
			right = ii;
		}else{
			left = ii+1;
		}
	}
	ans = n - left;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1408
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def main():
    N = int(input())
    print(N**3)

if __name__ == '__main__':
    main()



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

const string YES = "Yes";
const string NO = "No";

void solve(long long X, long long Y){
  for (int i=0; i<=X; i++) {
    if (i*2 + (X-i)*4 == Y) {
      cout << YES << endl;
      return;
    }
  }
  cout << NO << endl;
}

int main(){
    long long X;
    scanf("%lld",&X);
    long long Y;
    scanf("%lld",&Y);
    solve(X, Y);
    return 0;
}


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

int main(){
  int a, b;
  cin >> a >> b;
  for (int i=1;; i++) {
    int t8=0.08*i;
    int t10=0.1*i;
    if (t10>100) {
      cout << -1 << endl;
      return 0;
    } else if (t8==a && t10==b) {
      cout << i << endl;
      return 0;
    }
  }
}

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

void Main()
{
    int N, W;
    cin >> N >> W;
    vector<int> w(N), v(N);
    long total_val = 0;
    for (int i = 0; i < N; i++){
        cin >> w[i] >> v[i];
        total_val += v[i];
    }

    long max_value = 0;

    vector<vector<long>> nap(N, vector<long>(total_val+1, 1e18));
    for (int i = 0; i < N; i++)
        nap[i][0] = 0;
    for (long j = 1; j <= total_val; j++){
        if(j <= v[0]) nap[0][j] = w[0];
        if(nap[0][j] <= W) max_value = max(max_value, j);
    }
    for (int i = 1; i < N; i++)
    {
        for (int j = 1; j <= total_val; j++)
        {
            if(j <= v[i]){
                nap[i][j] = min((long)w[i], nap[i-1][j]);
            }else{
                nap[i][j] = min(nap[i-1][j-v[i]] + w[i], 
                               nap[i-1][j]);
            }
            if(nap[i][j] <= W)
                max_value = max(max_value, (long)j);
        }
    }

    cout << max_value << endl;
}

int main(int argc, char **argv)
{
    Main();
    return 0;
}


Measured memory_bytes: 79360
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>
#include <locale>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;
typedef pair<long long int, pll> lpll;


const long long int mod = 998244353;
const long long int INF = 1e18;
const long double PI=3.14159265358979323; 
const long long int pl=1000000;

long long int X;

int main(){

    cout << fixed << setprecision(18);
    cin>>X;
    for(long long int i = X; i <= 1000000; i+=X){
        if(i%360==0){
            cout<<i/X<<endl;
            return 0;
        }
    }
    


}




Measured memory_bytes: 3632
#include <bits/stdc++.h> 
using namespace std; 
  
// Driver program to test methods of graph class 
int main() 
{
    int n;
    cin >> n;
    vector<int> b(n - 1);
    for(int i = 0; i < n - 1; i++){
        cin >> b.at(i);
    }
    
    long long answer = 0;
    
    answer += b.at(0);
    
    for(int i = 0; i < n - 2; i++){
        answer += min(b.at(i), b.at(i + 1));
    }
    
    answer += b.at(n - 2);
    
    cout << answer << endl;
    
}

Measured memory_bytes: 256
a = list(map(lambda x: ord(x)-ord("a"), list(input())))
n = len(a)
m = 26

b = [0]*n
pos = [[] for i in range(m)]
s = set()
cnt = 0
for i in reversed(range(n)):
    b[i] = cnt
    if a[i] not in s:
        s.add(a[i])
    pos[a[i]].append(i)
    if len(s) == m:
        cnt += 1
        s = set()

for i in range(m):
    pos[i].sort()

k = cnt+1

from bisect import bisect_right

ans = []
cur = -1
for i in range(k):
    for j in range(m):
        pj = bisect_right(pos[j], cur)
        if pj == len(pos[j]):
            ans.append(j)
            break
        to = pos[j][pj]
        if b[to] != k-i-1:
            cur = to
            ans.append(j)
            break

ans = "".join(chr(ord("a")+i) for i in ans)
print(ans)


Measured memory_bytes: 63568
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>

using namespace std;

int pow2(long long int a){
    int c=0;
    int b;
    b=a%2;
    while(b==0){
        a/=2;
        b=a%2;
        c++;
    }
    return c;
}

int main(){

    long long int n;
    cin >> n;

    long long int a[n];

    for(int i=0;i<n;i++)cin >> a[i];

    for(int i=0;i<n;i++)a[i]=pow2(a[i]);

    long long int m=0;

    for(int i=0;i<n;i++)m+=a[i];

    cout << m << endl;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main()
{
    int n;
    int c0=0,c1=0,c2=0,c3=0;
    string s;
    cin >> n;
    while(n--){
        cin >> s;
        if(s=="AC") c0++;
        if(s=="WA") c1++;
        if(s=="TLE") c2++;
        if(s=="RE") c3++;
    }
    cout << "AC x " << c0 << endl;
    cout << "WA x " << c1 << endl;
    cout << "TLE x " << c2 << endl;
    cout << "RE x " << c3 << endl;
  return 0;
}


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

const int mxidx = 262144;
int bit[mxidx+1];

void sett(int x){
    while(x ^ mxidx){
        bit[x]++;
        x += x & (-x);
    }
}

int gett(int x){
    int ret = 0;
    while(x){
        ret += bit[x];
        x -= x & (-x);
    }
    return ret;
}

char str[200005];
int p[200005];
int last[26];
int cnt[26];
int n;

inline int bye(int x){
    return gett(x) - gett(x-1);
}

int main(){
    scanf("%s", &str[1]);
    n = (int)strlen(&str[1]);
    for(int i=0;i<26;i++) last[i] = 0;
    for(int i=1;i<=n;i++){
        int tt = str[i]-'a';
        cnt[tt]++;
        p[i] = last[tt];
        last[tt] = i;
    }
    int oddcnt = 0;
    for(int i=0;i<26;i++) oddcnt += (cnt[i] % 2);
    if(oddcnt >= 2){
        printf("-1\n");
        return 0;
    }
    int ss = 1, th = 0;
    long long ans = 0;
    while(ss <= n){
        int tt = str[ss]-'a';
        if(bye(ss)){
            ss++; continue;
        }
        if(ss == last[tt]){
            ss++;
            ans += (n / 2) - th;
            continue;
        }
        ans += (n - last[tt]) - (gett(n) - gett(last[tt]));
        sett(ss); sett(last[tt]);
        ss++; last[tt] = p[last[tt]];
        th++;
    }
    printf("%lld\n", ans);
}


Measured memory_bytes: 2048
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

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

int main(void) {
  int i,j;
  int n,h;
  cin>>n>>h;
  vi a(n),b(n);
  rep(i,n)cin>>a[i]>>b[i];
  sort(all(a));
  sort(all(b));
  int a_max=a[n-1];
  int ans=0;
  for(i=n-1;i>=0;i--){
    if(b[i]<=a_max){
      ans+=h/a_max;
      if(h%a_max!=0)ans++;
      break;
    }
    h-=b[i];
    ans++;
    if(h<=0)break;
  }
  if(i<0){
    ans+=h/a_max;
    if(h%a_max!=0)ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1024
n=int(input())
a=list(map(int,input().split()))
ans=[]
if max(a)>-min(a):
  x=max(a)
  idx=0
  for i in range(n):
    if a[i]==x:
      idx=i
      break
  for i in range(n):
    if a[i]==a[idx]:
      continue
    ans.append((idx+1,i+1))
  for i in range(n-1):
    ans.append((i+1,i+2))
else:
  x=min(a)
  idx=0
  for i in range(n):
    if a[i]==x:
      idx=i
      break
  for i in range(n):
    if a[i]==a[idx]:
      continue
    ans.append((idx+1,i+1))
  for i in range(n-1)[::-1]:
    ans.append((i+2,i+1))
print(len(ans))
for i in ans:
  print(i[0],i[1])

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using ll = long long;
using namespace std;
int main()
{
	int n;
	cin >> n;
	ll ans = 0;
	rep(i, n + 1) {
		if (i % 3 != 0 && i % 5 != 0)	ans += i;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3636
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <cstdint>
#include <tuple>
#include <numeric>
#define M_PI       3.14159265358979323846


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FILL(a, x) memset(a, x, sizeof(a))

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)

int b[22];
int a[22][22];

int main() {
	int n, m, c;
	cin >> n >> m >> c;

	REP(j, m)cin >> b[j];
	REP(i, n)REP(j, m)cin >> a[i][j];
	int ret = 0;
	REP(i, n) {
		int tmp = c;
		REP(j, m)tmp += a[i][j] * b[j];
		if (tmp > 0)ret++;
	}
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <chrono>
#include <queue>
#include <functional>

#define out(t) cout << (t) << "\n"

using namespace std;

typedef long long ll;
typedef unsigned int uint;

void swap(int &a, int &b) {
    a ^= b;
    b ^= a;
    a ^= b;
}

uint tzcnt(uint x) {
    x = ~x & (x - 1);
    x -= x >> 1 & 0x55555555;
    x = (x & 0x33333333) + (x >> 2 & 0x33333333);
    x = x + (x >> 4) & 0x0F0F0F0F;
    return x * 0x01010101 >> 24;
}

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

    int n;
    cin >> n;

    vector<int> cards;

    for (int i = 0; i < n; i++) {
        int t;
        cin >> t;
        cards.push_back(t);
    }

    sort(cards.begin(), cards.end());

    int alice = 0;
    int bob = 0;

    for (int i = n - 1; i >= 0; i--) {
        // odd
        if ((i - n + 1) & 1) {
            bob += cards[i];
        }
        else {
            alice += cards[i];
        }
    }

    out(alice - bob);

    int aaa;
    cin >> aaa;
}

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

int main() {
  char S[11];
  cin >> S;

  int ans = 0;
  int tmp = 0;
  bool coun = false;
  for (int i = 0; S[i] != '\0'; i++) {
    if (S[i] == 'A' or S[i] == 'C' or S[i] == 'G' or S[i] == 'T') {
      coun = true;
      tmp++;
    } else {
      if (coun == true) {
	coun = false;
	ans = max(ans, tmp);
	tmp = 0;
      } else {
	coun = false;
      }
    }
  }

  if (coun == true) {
    coun = false;
    ans = max(ans, tmp);
    tmp = 0;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
import sys
#import time
#import copy
from collections import deque, Counter, defaultdict
#from fractions import gcd
#import bisect
#import itertools
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
 
def ri():
    return list(map(int, input().split()))
def rs():
    return list(input().strip())

n,m = ri()
edge=[[] for _ in range(n)]
for i in range(m):
    a, b = ri()
    a+=-1
    b+=-1
    edge[a].append(b)
    edge[b].append(a)

visited=[0]*n
dis = [0]*n
ans=[0]*n
def bfs(now, p=-1):
    q = deque([])
    q.append((now, p, -1))
    visited[now]=1
    while len(q):
        now, p, d = q.popleft()
        dis[now] = d+1
        ans[now]=p+1
        
        for e in edge[now]:
            if visited[e]==1:
                continue
            q.append((e, now, dis[now]))
            visited[e]=1
        
        
        
        
bfs(0)
flag=True
for i in range(n):
    if visited[i]==0:
        flag=False
if flag:
    print("Yes")
    for i in range(1,n):
        print(ans[i])
else:
    print("No")

Measured memory_bytes: 105296
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def f(n):
    r = 2
    ret = 1
    for i in range(n, n-r, -1):
        ret *= i
    for i in range(1, r+1):
        ret //= i
    return ret * 2 + n


class Bisect:
    def __init__(self, func):
        self.__func = func

    def bisect_left(self, x, lo, hi):
        while lo < hi:
            mid = (lo+hi)//2
            if self.__func(mid) < x:
                lo = mid+1
            else:
                hi = mid
        return lo

    def bisect_right(self, x, lo, hi):
        while lo < hi:
            mid = (lo+hi)//2
            if x < self.__func(mid):
                hi = mid
            else:
                lo = mid+1
        return lo

@mt
def slv(N, M, A):
    A.sort(reverse=True)
    print(A)
    b = Bisect(f)

    i = b.bisect_left(M, 1, N)
    if f(i) != M:
        i -= 1
    l = f(i)

    ans = 0
    for j in range(i):
        ans += A[j] * 2
        ans += A[j] * (i-1)

    rem = M - l
    print(i, l, rem)
    j = 0
    while rem != 0:
        ans += A[j] + A[i]
        rem -= 1
        if rem == 0:
            break
        ans += A[j] + A[i]
        rem -= 1
        if rem == 0:
            break
        j += 1


    return ans

import numpy as np
@mt
def slv2(N, M, A):
    C = Counter(A)
    L = 1 << (max(A).bit_length() + 1)
    B = [C[i] for i in range(L)]
    D = np.fft.rfft(B)
    D *= D
    E = list(map(int, np.round(np.fft.irfft(D).real)))
    ans = 0
    c = 0
    i = L - 1
    while c != M:
        n = E[i]
        if c + n > M:
            n = M-c
        c += n
        ans += i * n
        i -= 1

    return ans

def main():
    N, M = read_int_n()
    A = read_int_n()
    print(slv2(N, M,A))

    # N = 10**5
    # M = random.randint(1, N**2)
    # A = [random.randint(1, 10**5) for _ in range(N)]
    # print(slv(N, M, A))


if __name__ == '__main__':
    main()


Measured memory_bytes: 46660
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
int num[20];
bool dfs(int x, int left, int right)
{
    if(num[x] > left)
    {
        if(x == 9)
            return true;
        if(dfs(x + 1, num[x], right))
            return true;
        return false;
    }
    else if(num[x] > right)
    {
        if(x == 9)
            return true;
        if(dfs(x + 1, left, num[x]))
            return true;
        return false;
    }
    return false;
}
int main()
{
    int T, i;
    scanf("%d", &T);
    while(T--)
    {
        for(i = 0; i < 10; i++)
            scanf("%d", &num[i]);
        if(dfs(0, -1<<30, -1<<30))
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}

Measured memory_bytes: 1168
#include<bits/stdc++.h>
using namespace std;
string H[10465270];
int getchar(char key){
	if(key == 'A'){
		return 1;
	}
	else if(key == 'C'){
		return 2;
	}
	else if(key == 'G'){
		return 3;
	}
	else if(key == 'T'){
		return 4;
	}
}

long long getkey(string key){
	long long p = 1,sum = 0;
	for(int i = 0;i<key.size();i++){
		sum += getchar(key.at(i))*p;
		p*= 5;
	}
	return sum;
}
void insert(string dic){
	int key;
	key = getkey(dic);
	H[key] = dic;
}
int find(string dic){
	if(H[getkey(dic)] == dic){
		return 1;
	}
	else{
		return 0;
	}
}
int main(){
	int n;
	string str,dic;
	cin>>n;
	for(int i = 0;i<n;i++){
		cin>>str>>dic;
		if(str.at(0) == 'i'){
			insert(dic);
		}
		else{
			if(find(dic)){
				cout<<"yes"<<endl;
			}
			else{
				cout<<"no"<<endl;
			}
		}
	}
	return 0;
}


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

template<class T> inline bool chmin(T& a, T b){
	if (a > b){
		a = b;
		return true;
	}
	return false;
}
const long long INF = 1LL << 60;
long long dp[100010];
int main()
{
	int n;
	cin >> n;
	int h[n];
	for (int i = 0; i < n; i++) cin >> h[i];
	for (int i = 0; i < 100010; i++) dp[i] = INF;
	dp[0] = 0;
	for (int i = 1; i < n; i++){
		chmin(dp[i], dp[i-1]+abs(h[i]-h[i-1]));
		if (i > 1) chmin(dp[i], dp[i-2]+abs(h[i]-h[i-2]));
	}

	cout << dp[n-1] << endl;
}


Measured memory_bytes: 1408
import java.util.*;
public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		long[] H = new long[N];
		long ans = 0;
		for(int i = 0;i < N;i++){
			H[i] = sc.nextLong();
		}
		Arrays.sort(H);
		for(int i = 0;i < K;i++){
			H[N - 1 - i] = 0;
			if(N - 1 - i == 0){
				break;
			}
		}
		for(int i = 0;i < N;i++){
			ans += H[i];
		}
		System.out.println(ans);
	}
}

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

int main() {
  int64_t H, W;
  cin >> H >> W;
  int64_t best = numeric_limits<int64_t>::max();
  for (int64_t i = 0; i < 2; ++i) {
    for (int64_t h_A = 1; h_A <= H - 1; ++h_A) {
      const int64_t S_A = h_A * W;
      {
        const int64_t B_w = W / 2;
        const int64_t S_B = (H - h_A) * B_w;
        const int64_t S_C = (H - h_A) * (W - B_w);
        const int64_t S_max = max({S_A, S_B, S_C});
        const int64_t S_min = min({S_A, S_B, S_C});
        best = min(best, S_max - S_min);
      }
      {
        const int64_t B_h = (H - h_A) / 2;
        const int64_t S_B = B_h * W;
        const int64_t S_C = (H - h_A - B_h) * W;
        const int64_t S_max = max({S_A, S_B, S_C});
        const int64_t S_min = min({S_A, S_B, S_C});
        best = min(best, S_max - S_min);
      }
    }
    swap(H, W);
  }
  cout << best << endl;
}


Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        var sc = new Scanner(System.in);
    
        long x = Long.parseLong(sc.next());
        long k = Long.parseLong(sc.next());
        long d = Long.parseLong(sc.next());
    
        BigInteger bx = BigInteger.valueOf(x);
        BigInteger bk = BigInteger.valueOf(k);
        BigInteger bd = BigInteger.valueOf(d);
        
        if(bx.abs().compareTo(bd.multiply(bk)) >= 0){
            if(x < 0) x = -x;
            System.out.println(x - d*k);
        }else if(x == 0){
            if(k%2 == 0){
                System.out.println(0);
            }else{
                System.out.println(d);
            }
        }else{
            if(x < 0) x = -x;
            long a = k - x/d;
            if(a%2 == 0){
                System.out.println(x%d);
            }else{
                System.out.println(d - x%d);
            }
        }
    }
}

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

const int INF = 1 << 30;

const int color[8][3] = { {  0,   0,   0},
			  {  0,   0, 255},
			  {  0, 255,   0},
			  {  0, 255, 255},
			  {255,   0,   0},
			  {255,   0, 255},
			  {255, 255,   0},
			  {255, 255, 255} };
const string name[] = {"black", "blue", "lime", "aqua",
		       "red", "fuchsia", "yellow", "white" };

int main()
{
  string RGB;
  while (cin >> RGB) {
    if (RGB == "0")
      break;

    int R = strtol(RGB.substr(1, 2).c_str(), NULL, 16);
    int G = strtol(RGB.substr(3, 2).c_str(), NULL, 16);
    int B = strtol(RGB.substr(5, 2).c_str(), NULL, 16);

    int d = INF, index = 0;
    for (int i = 0; i < 8; ++i) {
      int dd = (R-color[i][0]) * (R-color[i][0])
	+ (G-color[i][1]) * (G-color[i][1])
	+ (B-color[i][2]) * (B-color[i][2]);

      if (d > dd) {
	d = dd;
	index = i;
      }
    }
    cout << name[index] << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
    int main(){
        string S;
        int N;
        int B;
            cin >> N >> S;
                for(int i = 0; i < S.size(); i++){
                    if(S.at(i) + N > 'Z'){
                        S.at(i) += N - 'Z' + 'A' - 1;
                    }else{
                        S.at(i) += N;
                    }
                }
                    cout << S << endl;
    return 0;}


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

#define For(i, l, r) for(register int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define Fordown(i, r, l) for(register int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Set(a, v) memset(a, v, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define debug(x) cout << #x << ": " << x << endl
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)

using namespace std;

inline bool chkmin(int &a, int b) {return b < a ? a = b, 1 : 0;}
inline bool chkmax(int &a, int b) {return b > a ? a = b, 1 : 0;}

inline int read() {
	int x = 0, fh = 1; char ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') fh = -1;
	for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48);
	return x * fh;
}

void File() {
#ifdef zjp_shadow
	freopen ("connect.in", "r", stdin);
	freopen ("connect.out", "w", stdout);
#endif
}

const int N = 16;

int n, m, sumw;
int dp[N][1 << N], sum[1 << N], G[N][N], num[1 << N];

#define lowbit(x) (x & -x)

#define Get(i, v, k) for(register int sta = k, v = __builtin_ctz(sta), i; i = 1 << v, sta; v = __builtin_ctz(sta ^= i))

int main () {

	File(); Set(dp, 0);

	n = read(); m = read();

	For (i, 0, n - 1) num[1 << i] = i;
	For (i, 1, m) {
		int u = read() - 1, v = read() - 1, w = read(); 
		G[u][v] = G[v][u] = w; sumw += w;
	}

	int maxsta = (1 << n) - 1;
	For (i, 1, maxsta) {
		int u = __builtin_ctz(i);
		sum[i] = sum[i ^ (1 << u)];
		Get(j, v, i) sum[i] += G[u][v];
	}

	Set(dp, -0x3f);
	for (int i = 1; i <= maxsta; i += 2) {
		dp[0][i] = sum[i];
		For (S, 0, n - 1) if (dp[S][i] >= 0) {
			int rest = maxsta ^ i;
			for (register int sub =	rest; sub; (-- sub) &= rest)
				chkmax(dp[S][i | sub], dp[S][i] + sum[sub | (1 << S)]);
			Get(j, v, rest) if (G[S][v])
				chkmax(dp[v][i | j], dp[S][i] + G[S][v]);
		}
	}

	printf ("%d\n", sumw - dp[n - 1][maxsta]);

	return 0;
}

Measured memory_bytes: 4480
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a,b,c,d,e,n;
  string s,ss,sss;
  cin>>a>>b;
  cout<<ceil((double)a/b)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
   int n;
   cin>>n;
   for(int i = 1; i<10; i++){
       for(int j = 1; j<10; j++){
           if(n == i*j){
               cout<<"Yes"<<endl;
               return 0;
           }
       }
   }
   cout<<"No"<<endl;
   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1LL << 60
#define LLINF 1e12
#define PI 3.14159265359
#define ALL(a) (a).begin(), (a).end()
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int ny, nx;
typedef long long ll;
using namespace std;

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

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

ll llmin(ll x, ll y) { return x < y ? x : y; }
ll llmax(ll x, ll y) { return x > y ? x : y; }

unsigned GetDigit(unsigned num) { return to_string(num).length(); }

template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v)
{
    return (c.end() != std::find(c.begin(), c.end(), v));
}

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

ll nCr(int n, int r)
{
    if (n == r or n == 0)
        return 1;
    if (n < r)
        return 0;
    if (r == 1)
        return n;
    return nCr(n - 1, r - 1) + nCr(n - 1, r);
}

//std::cout << std::defaultfloat << std::setprecision(10);
////////////////////////////////////////
int main()
{

    int a,b,c,d; cin >> a >> b >> c  >> d;

    while(1){
        c-=b;
        if(c<=0){
            cout << "Yes"<< endl;
            return 0;
        }
        a-=d;
        if(a<=0){
            cout << "No" << endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <unordered_map>
#include <cmath>
#include <stdlib.h>
#include <queue>
#include <set>
#include <algorithm>
#include <map>

using namespace std;
typedef long long ll;

int main()
{
  ll a, b, k;
  cin >> a >> b >> k;
  if (a > k)
  {
    cout << a - k << " " << b << endl;
  }
  else
  {
    cout << 0 << " " << max(0LL, b - (k - a)) << endl;
  }
  return 0;
}


Measured memory_bytes: 760
/**
*   Bismillahir Rahmanir Rahim.
*   Imtiaz_rafi
*   PCIU, CHITTAGONG
**/
#include<bits/stdc++.h>
using namespace std;
#define speed ios::sync_with_stdio(0);cin.tie(0);
#define rep(i,a) for(ll i=0;i<a;i++)
#define rep1(i,begin,end) for(ll i=begin;i<=end;i++)
#define all(v)   v.begin(),v.end()
#define pb push_back
#define pf push_front
#define mp make_pair
// bitshift (1LL<<(3)) *2^3
typedef long long int ll;
typedef vector<ll>v;
typedef vector<ll>vi;
typedef map<ll,ll>m;
typedef map<char,ll>mc;
typedef set<ll>st;
typedef set<char>sc;

int main()
{
    speed;
    ll t=1,a,b,i,c;
    while(t--)
    {
        cin>>a;
        b=a%10;
        if(b==2 || b==4 || b==5 || b==7 || b==9)
            cout<<"hon"<<endl;
        else if(b==0 || b==1 || b==6 || b==8)
            cout<<"pon"<<endl;
        else if(b==3)
            cout<<"bon"<<endl;
    }




}

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

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required

using namespace __gnu_pbds; 
using namespace std;

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
typedef long long  ll;
typedef vector<ll> VL;
typedef pair<ll,ll> PLL;
#define pb push_back
#define F first
#define S second
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(ll i=x;i<y;i++)
#define frr(i,x,y) for(ll i=x-1;i>=y;i--)
#define inf 10000000000000000
const ll mod=998244353;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

void solve()
{
	ll n;
	cin>>n;
	VL arr(n);
	fr(i,0,n)
		cin>>arr[i];
	sort(ALL(arr));
	cout<<arr[n-1]<<" ";
	ll x=arr[n-1];
	ll y=0;
	fr(i,0,n-1)
	{
		if(arr[i]<=x/2)
			y=max(y,arr[i]);
		else
		{
			ll z=x-arr[i];
			if(z<=x/2&&z>y)
				y=arr[i];
		}
	}
	cout<<y<<endl;
	return;
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
	solve();
	return 0;
}

Measured memory_bytes: 1024
const input = require('fs').readFileSync('/dev/stdin', 'utf8');

const k = Number(input);

if (k % 2 === 0) {
  console.log((k / 2) * (k / 2));
} else {
  console.log(((k - 1) / 2) * ((k - 1) / 2 + 1));
}


Measured memory_bytes: 7372
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const ll MOD = 1000000007;
// const int INF = 2000000000;

ll N;
vector<ll> A;
bool zero = false;
int zero_idx = 0;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  A.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (A[i] == 0) {
      zero = true;
      zero_idx = i;
    }
  }

  ll ans = 0;
  if (zero) {
    for (int i = 0; i < zero_idx; i++) {
      ans += abs(A[i]);
    }
    if (zero_idx != N) {
      int num_minus = 0;
      for (int i = zero_idx; i < N; i++) {
        if (A[i] < 0) {
          num_minus++;
        }
      }

      vector<ll> abs_A;
      for (int i = zero_idx; i < N; i++) {
        abs_A.push_back(abs(A[i]));
      }
      if (num_minus % 2 == 0) {
        for (int i = 0; i < abs_A.size(); i++) {
          ans += abs_A[i];
        }
      } else {
        sort(abs_A.begin(), abs_A.end());
        ans -= abs_A[0];
        for (int i = 1; i < abs_A.size(); i++) {
          ans += abs_A[i];
        }
      }
    }
  } else {
    int num_minus = 0;
    for (int i = 0; i < N; i++) {
      if (A[i] < 0) {
        num_minus++;
      }
    }
    vector<ll> abs_A(N);
    for (int i = 0; i < N; i++) {
      abs_A[i] = abs(A[i]);
    }
    if (num_minus % 2 == 0) {
      for (int i = 0; i < N; i++) {
        ans += abs_A[i];
      }
    } else {
      sort(abs_A.begin(), abs_A.end());
      ans -= abs_A[0];
      for (int i = 1; i < N; i++) {
        ans += abs_A[i];
      }
    }
  }

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

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

//.define
// #define FILE_IN_OUT
#define RET(_x)    return cout << (_x) << '\n', 0;
#define all(_obj)  (_obj).begin(), (_obj).end()
#define loop(_n)   for (int i = 0; i < (_n); ++i)
#define sz(_obj)   static_cast<int>((_obj).size())
#ifdef SHJ_LOCAL
#define debug(_x)  std::cerr << (#_x) << " = " << (_x) << '\n' << std::flush;
#else
#define debug(_x)  {}
#endif
#define endl "\n"
template<typename Tp>
Tp CeilDiv(Tp _dividend, long long _divider) {
    return static_cast<Tp>((_dividend - 1LL + _divider) / _divider);
}
template<typename Tp>
inline void outarr(Tp _begin, Tp _end, const char* _delim = " ") {
    for (Tp current = _begin; current != _end; ++current) {
        std::cout << *current << _delim;
    }
    std::cout << '\n';
}

//.constant
using ll  = long long;
using pii = std::pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr int MOD = static_cast<const int>(1e9 + 7);

//.data

//.code
int main() {
#ifdef FILE_IN_OUT
    std::ifstream cin ("input.txt",  std::ios::in);
    std::ofstream cout("output.txt", std::ios::out);
#else
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
#endif

    int n;
    cin >> n;
    if (n < 600) {
        cout << 8 << endl;
    } else if (n < 800) {
        cout << 7 << endl;
    } else if (n < 1000) {
        cout << 6 << endl;
    } else if (n < 1200) {
        cout << 5 << endl;
    } else if (n < 1400) {
        cout << 4 << endl;
    } else if (n < 1600) {
        cout << 3 << endl;
    } else if (n < 1800) {
        cout << 2 << endl;
    } else {
        cout << 1 << endl;
    }

#ifdef FILE_IN_OUT
    cin.close();
    cout.close();
#endif
    return 0;
}

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

int main(void){
	
  	int N,R;
  
  	scanf("%d %d\n",&N,&R);
  
  	if(N<10){
    	printf("%d\n",R+(100*(10-N)));
    }else{
   
    	printf("%d\n",R);
      
    }
  


	return 0;

} 

Measured memory_bytes: 128
#include <stdio.h>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <string.h>



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main(void){

	char S[101];
	char correct[] = "keyence";
	int j = 0;

	scanf("%s", S);
	int S_size = strlen(S);
	int diff = S_size - strlen(correct);
	int begin=0;
	int end=diff;
	while(end<S_size){
		int j = 0;
		for(int i=0;i<S_size;++i){
			if(i >= begin && i < end) continue;
			else if(S[i] == correct[j]) j++;
		}

	if(j == 7) {printf("YES\n");return 0;}
		begin++;
		end++;
	}

	printf("NO\n");

	return 0;

}


Measured memory_bytes: 128
import collections
N = int(input())
S = int(input())


def prime_decomposition(n):
    i = 2
    ret = collections.defaultdict(int)
    while i * i <= n:
        while n % i == 0:
            n //= i
            ret[i] += 1
        i += 1
    if n > 1:
        ret[n] = 1
    return ret


def digitsum(x, f):
    if x < f:
        return x
    else:
        return x % f + digitsum(x // f, f)


if N == S:
    print(N + 1)
    exit()
fs_dict = prime_decomposition(N - S)
fs_set = set([1])
for p, n in fs_dict.items():
    fs_set_copy = fs_set.copy()
    for i in range(1, n + 1):
        for x in fs_set_copy:
            fs_set.add(x * p**i)
for f in sorted(fs_set):
    f += 1
    if digitsum(N, f) == S:
        print(f)
        exit()
print(-1)


Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define arep(a,i,n) for(int i=(a);i<(n);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define cinf(x,n) for(int i=0;i<(n);i++)cin>>x[i];
#define coutf(x,n) for(int i=0;i<(n);i++)cout<<x[i]<<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

ll cnt;

int main(){
	ll n;
	cin >> n;
	ll a[n];
	cinf(a,n);
	rep(i,n){
		if((i+1)%2==1&&a[i]%2==1)
			cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 3672
#include<iostream>
#include<fstream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<deque>
#include<set>
#include<map>
#include<bitset>
#include<ctime>
#include<queue>
using namespace std;
#define int long long
#define pii pair <int, int>
#define XX first
#define YY second

// constants:
const int mn = 200005;
const int mod = 1000000007;
const long long inf = 4444444444444444444;
const int sminf = 1111111111;
const bool is_multitest = 0;
const bool is_interactive = 0;

// i/o methods:
const bool input_from_file = 0;
const bool output_to_file = 0;
#define filename ""
#define in_extension "inp"
#define out_extension "out"

// data preprocessing: (e.g.: divisor generating, prime sieve)
void preprocess()
{
    
}

// global variables:
int A[4];
int n;
// main solution goes here:
void execute(int test_number)
{
    cin>>n;
    string s;
    for (int i=1; i<=n; i++) {
        cin>>s;
        if (s=="AC") A[0]++;
        else if (s=="WA") A[1]++;
        else if (s=="TLE") A[2]++;
        else A[3] ++;
    }

    cout<<"AC x "<<A[0]<<"\nWA x "<<A[1]<<"\nTLE x "<<A[2]<<"\nRE x "<<A[3]<<"\n";
}
// REMEMBER TO CHOOSE TEST METHODS
// PLEASE REMOVE cout AND cerr DEBUG LINES BEFORE SUBMITTING PROBLEMS
// Solution by low_



















signed main()
{
#ifdef lowie
    if (!is_interactive)
    {
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
#else
    if (input_from_file) freopen(filename"."in_extension, "r", stdin);
    if (output_to_file) freopen(filename"."out_extension, "w", stdout);
#endif
    if (!is_interactive)
    {
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
    }

    preprocess();
    int ntest;
    if (is_multitest) cin >> ntest;
    else ntest = 1;

    for (int testno = 1; testno <= ntest; testno++)
    // use for instead of while to serve facebook hacker cup test format
    {
        execute(testno); // only start coding in this function, not in main
    }
}
// Template by low_
// Contact me via mail: ttuandung1803@gmail.com
// ...or codeforces: www.codeforces.com/profiles/low_
// ...or if you're interested in food: www.instagram.com/lowie.exe/

Measured memory_bytes: 3660
//code_sm
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define si set<int>
#define ll long long
#define pb push_back
ll gcd(ll a,ll b)
{
	if(a==0)
	return b;
	else
	return gcd(b%a,a);
}
int main()
{
	ll k;
	cin>>k;
	ll sum=0;
	for(ll a=1;a<=k;a++)
	{
		for(ll b=1;b<=k;b++)
		{
			ll fi=gcd(min(a,b),max(a,b));
			for(ll c=1;c<=k;c++)
			{
		ll ar=gcd(min(fi,c),max(fi,c));
		sum+=ar;	 
		}
		}
	}
	cout<<sum;
}

Measured memory_bytes: 3636
#include <cstdio>

int seen[1000001];

int main() {
  int s;
  scanf("%d", &s);

  for (int i = 1; i <= 1000000; ++i) {
    if (seen[s] > 0)
      return !printf("%d\n", i);

    seen[s] = i;
    if (s % 2 == 0) {
      s /= 2;
    } else {
      s = 3*s + 1;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v)) os<<*i<<(i==end(v)-1?"":" "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
    is>>p.first>>p.second; return is; }
template <class T> bool chmax(T &a,const T &b) {if(a<b) {a=b;return 1;} return 0;}
template <class T> bool chmin(T &a,const T &b) {if(b<a) {a=b;return 1;} return 0;}
template <class T> using heap = priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int n,c;
    cin>>n>>c;
    vector<vector<int>> sum(c,vector<int>(200005,0)); 
    REP(i,n) {
        int s,t,ch;
        cin>>s>>t>>ch;
        sum[ch-1][s*2-1]++;
        sum[ch-1][t*2]--;
    }
    REP(i,200004) {
        REP(j,c) sum[j][i+1]+=sum[j][i];
    }
    int ans=0;
    REP(i,200005) {
        int cnt=0;
        REP(j,c) {
            if(sum[j][i]>0) {
                cnt++;
            }
        }
        chmax(ans,cnt);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 48768
n = gets.to_i
numbers = (1..n).to_a
array = gets.chomp.split(" ").map(&:to_i)
flag = []
answer = "NO"

array.each_index do |number|
  if array[number] != numbers[number]
    flag.push(number)
  end
end

if flag.length == 2
  tmp = array[flag.first]
  array[flag.first] = array[flag.last]
  array[flag.last] = tmp
end

if numbers == array
  answer = "YES"
end

puts answer

Measured memory_bytes: 1788
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A[] = new int[N+1];
		for (int i=0;i<=N;i++) {
			A[i] = sc.nextInt();
		}
		Arrays.sort(A);
		int B[] = new int[N];
		for (int i=0;i<N;i++) {
			B[i] =A[i+1]-A[i];
		}
		int max =B[0];
		for (int i=0;i<N-1;i++) {
			max =Main.gcd(B[i+1],max);
		}
		System.out.println(max);
	}
	public static int gcd(int a,int b) {
		if (a<b) {
			return gcd(b,a);
		}
		if (b==0) {
			return a;
		}
		return gcd(a%b,b);
	}
}

Measured memory_bytes: 49540
#include<iostream>
#include<algorithm>
using namespace std;
int t[3],x,y;
int a=0,b=0,c=0;
int main(){
  while(1){
    cin>>t[0]>>t[1]>>t[2];
    sort(t,t+3);
    x=t[0]*t[0]+t[1]*t[1];
    y=t[2]*t[2];
    if(t[0]+t[1]<=t[2]){
      break;
    }else if(x==y){
      a++;
    }else if(x>y){
      b++;
    }else if(x<y){
      c++;
    }
  }
  cout<<a+b+c<<' '<<a<<' '<<b<<' '<<c<<endl;
  return 0;
}



Measured memory_bytes: 3148