akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define REP(i,n) for(int i=0,_n=(n);(i)<(int)_n;++i)
#define RANGE(i,a,b) for(int i=(int)a,_b=(int)(b);(i)<_b;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define PRINT1(table, D0) REP(d0, D0) cout<<table[d0]<<" "; cout<<"\n";
#define PRINT2(table, D0, D1) REP(d0, D0) { REP(d1, D1) cout<<table[d0][d1]<<" "; cout<<"\n"; }
#define PRINT3(table, D0, D1, D2) REP(d0, D0) { REP(d1, D1) { REP(d2, D2) cout<<table[d0][d1][d2]<<" "; cout<<"\n"; } cout<<"\n"; }
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	//ios::sync_with_stdio(false);
	ll N;
	while(cin>>N) {
		VI w(N);
		REP(i, N) cin>>w[i];
		ll sum = accumulate(ALL(w), 0LL);
		ll A=w[0], B=sum-w[0];
		ll ans = 1LL<<60;
		RANGE(i, 1, N) {
			ans = min(ans, abs(A-B));
			A+=w[i];
			B-=w[i];
		}
		
		cout<<ans<<endl;
	}
	
	return 0;
}


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

struct doll{
    int h,r;
};

bool operator<(const doll& d1,const doll& d2){
    if(d1.h == d2.h){
        return d1.r > d2.r;
    }
    return d1.h < d2.h;
}

int main() {

    while(1){

        int n;

        cin >> n;

        if(n==0) break;

        int h,r;

        vector<doll> v;
        doll tmp;

        for(int i=0;i<n;i++){
            cin >> h >> r;
            tmp.h = h;
            tmp.r = r;
            v.push_back(tmp);
        }

        int m;

        cin >> m;

        for(int i=0;i<m;i++){
            cin >> h >> r;
            tmp.h = h;
            tmp.r = r;
            v.push_back(tmp);
        }

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

        /*for(int i=0;i<n+m;i++){
            cout << v[i].h << " " << v[i].r << endl;
        }*/

        int dp[1001] = {0};

        for(int i=0;i<n+m;i++){
            int dm = 0;
            for(int j=0;j<v[i].r;j++){
                dm = max(dm,dp[j]);
            }
            dp[v[i].r] = dm+1;
        }

        int ans = 0;

        for(int i=0;i<1001;i++){
            //cout << dp[i] << endl;
            ans = max(dp[i],ans);
        }

        cout << ans << endl;


    }

    return 0;
}

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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int S, W; cin >> S >> W;
  if(S <= W){
    cout << "unsafe" << endl;
  }else{
    cout << "safe" << endl;
  }
}

Measured memory_bytes: 3628
from sys import stdin
from sys import setrecursionlimit
import numpy as np
setrecursionlimit(10 ** 7)

n,m,x = map(int,stdin.readline().rstrip().split())
a = []
li = []
mi = 10**9
for i in range(n):
    lin = list(map(int,stdin.readline().rstrip().split()))
    a.append(lin[0])
    li.append(lin[1:])

li = np.array(li)

for i in range(2**n):
    lis = np.zeros(m)
    mil = 0
    for j in range(n):
        if ((i >> j) & 1):
            lis += li[j]
            mil += a[j]
    flag = True
    for k in lis:
        if k < x:
            flag = False
    if flag:
        mi = min(mi,mil)

if mi == 10**9:
    print(-1)
    exit()

print(mi)

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

using namespace std;

int main() {
    if (fopen("A.inp", "r"))
    freopen("A.inp", "r", stdin),
    freopen("A.out", "w", stdout);
    long long a, b, n;
    cin >> a >> b >> n;
    if (n >= b) cout << a * (b - 1) / b;
    else cout << a * n / b;
}


Measured memory_bytes: 3584
#include <stdio.h>
#include <cmath>
#include <algorithm>
#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;

struct Info{
	int x,y;
};

int calc(Info left,Info right){
	return abs(left.x-right.x) + abs(left.y-right.y);
}

int main(){

	int N,num_A,num_B,num_C,num_D,tmp_x,tmp_y,tmp_dist,minimum;

	Info A,B,C,D;

	scanf("%d",&N);
	scanf("%d %d %d %d",&num_A,&num_B,&num_C,&num_D);

	minimum = BIG_NUM;

	for(int width = 1; width <= N; width++){

		tmp_x = 1;
		tmp_y = 1;
		for(int i = 1; i <= N; i++){

			if(i == num_A){
				A.x = tmp_x;
				A.y = tmp_y;
			}else if(i == num_B){
				B.x = tmp_x;
				B.y = tmp_y;
			}else if(i == num_C){
				C.x = tmp_x;
				C.y = tmp_y;
			}else if(i == num_D){
				D.x = tmp_x;
				D.y = tmp_y;
			}

			tmp_x++;
			if(tmp_x > width){
				tmp_x = 1;
				tmp_y++;
			}
		}

		tmp_dist = calc(A,B)+calc(C,D);
		minimum = min(minimum,tmp_dist);
	}

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

	return 0;
}

Measured memory_bytes: 2720
n = int(input())
l = list(map(int,input().split()))
ans = 0
l.sort()

def bisec(i,k): #ギリギリokなj<=j_を探す
    ci = i
    ck = k
    i+=1
    k-=1
    j = int((i+k)/2)
    while k-i>1:
        if l[ci]+l[j]>l[ck]:
            k = j
            j = int((i+k)/2)
        else:
            i = j+1
            j = int((i+k)/2)
    if l[ci]+l[i]>l[ck]:
        return True,i
    elif l[ci]+l[i+1]>l[ck]:
        return True,i+1
    else:
        return False,-1

for i in range(n):
    for k in range(i+2,n):
        f,j = bisec(i,k)
        if f:
            ans += k-j
print(ans)

Measured memory_bytes: 48092
N = int(input())
A = list(map(int, input().split()))
cnt1 = A.count(1)
cnt2 = A.count(2)
cnt3 = A.count(3)

# PyPyでは事前の型推論によりチェックを一部省略することで高速化を図っている部分があるが、
# 処理の中でintもfloatも取り得る変数にしてしまうとその推論が上手く働かない。
# 今回のように小数が入るとわかっている場合は、初期化する値も小数にしておけば、よりPyPyの恩恵を享受できる
# ↑ほんと？

dp = [[[-1.0] * (N + 1) for _ in range(N + 1)] for _ in range(N + 1)]
dp[0][0][0] = 0


def func(c1, c2, c3):
    if dp[c1][c2][c3] != -1:
        return dp[c1][c2][c3]

    prob0 = (N - c1 - c2 - c3) / N
    temp = 1 / (1 - prob0)
    if c1 > 0:
        temp += func(c1 - 1, c2, c3) * (c1 / N) / (1 - prob0)
    if c2 > 0:
        temp += func(c1 + 1, c2 - 1, c3) * (c2 / N) / (1 - prob0)
    if c3 > 0:
        temp += func(c1, c2 + 1, c3 - 1) * (c3 / N) / (1 - prob0)

    dp[c1][c2][c3] = temp
    return temp


print(func(cnt1, cnt2, cnt3))


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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

void solve() {
  int n, x, t;
  cin >> n >> x >> t;
  cout << (n + x - 1) / x * t << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) solve();
}


Measured memory_bytes: 3608
//  ALDS1-ALDS1_7_B  Tree - Binary Trees
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
using namespace std;

const int MAX = 30;
const int NIL = -1;

struct Node
{
	int id = MAX;
	int parent = NIL;
	int left = NIL;
	int right = NIL;
	int sibling = NIL;
	int degree = NIL;
	int depth = NIL;
	int height = NIL;
};

Node nodes[MAX]; 
int numberOfnodes;

struct Nodes
{
		
	Nodes()
	{
		int parentId = getParentId();
		setDeps(parentId,0);
		setHeight(parentId);
	}

	int getParentId()
	{
		for (int i = 0; i < numberOfnodes; i++)
		{
			if(nodes[i].parent==NIL)
			{
				return nodes[i].id;
			}
		}
		return NIL;
	}	

	void setDeps(int id, int depth)
	{
		nodes[id].depth = depth;
		if (nodes[id].left != NIL ) setDeps(nodes[id].left, depth + 1);
		if (nodes[id].right != NIL ) setDeps(nodes[id].right, depth + 1);
	}

	int setHeight(int id)
	{
		int h1 = 0;
		int h2 = 0;
		
		if (nodes[id].right != NIL )
		{
			h1 = setHeight(nodes[id].right ) + 1;
		}

		if (nodes[id].left != NIL )
		{
			h2 = setHeight(nodes[id].left ) + 1;
		}

		nodes[id].height = max(h1,h2);

		return nodes[id].height;
	}

	string getType(int id)
	{
		if (nodes[id].parent == NIL ) return "root";
		else if (nodes[id].left == NIL && nodes[id].right == NIL) return "leaf";
		else return "internal node";
	}

	void dump()
	{
		for (int i = 0; i < numberOfnodes; i++)
		{
			printf("ID:%2d, parent:%2d, left:%2d, right:%2d\n"
				,nodes[i].id,nodes[i].parent,nodes[i].left,nodes[i].right);
		}
	}

	void print()
	{
        for (int i = 0; i < numberOfnodes; i++)
		{
			printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, %s\n"
				,nodes[i].id,nodes[i].parent,nodes[i].sibling,nodes[i].degree,nodes[i].depth,nodes[i].height,getType(nodes[i].id).c_str());
		}
	}
};

int main()
{
	cin >> numberOfnodes;

	for (int i=0;i<numberOfnodes;i++)
	{
		int num,left,right;
		cin >> num >> left >> right;
		nodes[num].id = num;
		nodes[num].left = left;
		nodes[num].right = right;
		if(left!=NIL)
			nodes[left].parent = num;
		if(right!=NIL)
			nodes[right].parent = num;
	}

	for (int i=0;i<numberOfnodes;i++)
	{
		//sibling
		if (nodes[i].parent != NIL)
		{
			if (nodes[nodes[i].parent].left == nodes[i].id)
			{
				nodes[i].sibling = nodes[nodes[i].parent].right;
			}

			if (nodes[nodes[i].parent].right == nodes[i].id)
			{
				nodes[i].sibling = nodes[nodes[i].parent].left;
			}
		}

		// degrees
		int deg = 0;
		if (nodes[i].left !=NIL) deg++;
		if (nodes[i].right != NIL) deg++;	
		nodes[i].degree = deg;
	}
	Nodes n;
	n.print();		
}


Measured memory_bytes: 3292
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	int n;
	while (cin >> n, n) {
		vector<pair<int, int> >v(n);
		rep(i, 0, n)cin >> v[i].second >> v[i].first;
		sort(v.begin(), v.end());
		rep(i, 1, n) {
			v[i].second += v[i - 1].second;
		}
		bool f = true;
		rep(i, 0, n) {
			if (v[i].second > v[i].first) f = false;
		}
		if (f)cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3116
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

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

int l[][3]={{0,1,2},{3,4,5},{6,7,8},{0,3,6},{1,4,7},{2,5,8},{0,4,8},{2,4,6}};
char c[9];

int main(){
	while(cin>>c[0]&&c[0]-'0'){
		rep(i,8)cin>>c[i+1];
		string ans="NA";
		rep(i,8)if(c[l[i][0]]!='+'&&c[l[i][0]]==c[l[i][1]]&&c[l[i][0]]==c[l[i][2]])ans=c[l[i][0]];
		cout<<ans<<endl;
	}
}

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

int main(){
  int N;
  cin >> N;
  if(N <= 599){
    cout << 8 << endl;
  }else if(N <= 799){
    cout << 7 << endl;
  }else if(N <= 999){
    cout << 6 << endl;
  }else if(N <= 1199){
    cout << 5 << endl;
  }else if(N <= 1399){
    cout << 4 << endl;
  }else if(N <= 1599){
    cout << 3 << endl;
  }else if(N <= 1799){
    cout << 2 << endl;
  }else{
    cout << 1 << endl;
  }

}


  

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

long long a,b;

main()
{
	int n;
	scanf("%d",&n);
	scanf("%lld %lld",&a,&b);
	for(int i=1;i<n;i++)
	{
		long long x,y,bx,by;
		scanf("%lld %lld",&bx,&by);
		x=bx;
		y=by;
		long long mul=max(a/bx,b/by);
		x=mul*bx;
		y=mul*by;
		if(x<a||y<b)
		{
			x+=bx;
			y+=by;
		}
		a=x;
		b=y;
	}
	printf("%lld",a+b);
}

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

int main (void) {

    int n, m;

    cin >> n >> m;

    if (m < n) {
        if (m == 1) {
            cout << "Bob" << endl;
        }else if(n != 1) {
            cout << "Alice" << endl;
            }
        }
    
    if (n < m) {
        if (n == 1) {
            cout << "Alice" << endl;
        }else if(n != 1) {
            cout << "Bob" << endl;
            }
    }

    if (n == m) {
        cout << "Draw" << endl;
    }

    return 0;
}


Measured memory_bytes: 3540
#include <stdio.h>
int main(void)
{
    int n,a;
    scanf("%d",&n);
    while(1)
    {
        if(n<=1000)
        {
            break;
        }
        n-=1000;
    }
    a=1000-n;
    printf("%d\n",a);
    return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int a[110];
  cin >> n;
  int minn=1000;
  int maxx=0;
  for(int i=0; i<n; i++){
    cin >> a[i];
    minn=min(minn,a[i]);
    maxx=max(maxx,a[i]);
  }
  cout << maxx-minn << endl;
}

Measured memory_bytes: 256
import scala.io.StdIn

object Main extends App {
  val Array(n, h, w) = StdIn.readLine.split(" ").map(_.toInt)
  val ans = Iterator.continually(StdIn.readLine)
    .take(n)
    .map(_.split(" ").map(_.toInt))
    .count(e => e(0) >= h && e(1) >= w)

  println(ans)
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


void solve() {
    int i,j,k,l,r,x,y; string s;
    bool exit = false;
    int N;
    cin>>N;
    int exclude_sum = -1;
    if(N%2 == 1){
        exclude_sum = N;
    }else{
        exclude_sum = N+1;
    }
    int M = 0;
    vector<pair<int,int>> ret;
    for(i=1;i<N;i++){
        for(j=i+1;j<N+1;j++){
            if(i+j==exclude_sum)
                continue;
            ret.push_back(make_pair(i,j));
            M += 1;
        }
    }
    cout<<M<<endl;
    for(auto& p:ret){
        cout<<p.first<<" "<<p.second<<endl;
    }
    /*cin>>N;
    vector<ll> V((N+1)*(N+1));
    FOR(x,N+1) {
            FOR(y,N+1) {
                    ll ret=1;
                    FOR(i,x) ret*=2;
                    FOR(i,y) ret*=5;
                    V.push_back(ret);
            }
    }
    sort(ALL(V));
    FORR(v,V) cout<<v<<endl;*/
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}



Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;

namespace Atcoder
{
    class Program
    {
        static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
        static void Main(string[] args)
        {
            try
            {
                SetOut(sw);
                Solve.Answer();
                Out.Flush();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
            }
        }
    }

    public class Solve
    {
        public static List<long[]> list = new List<long[]>();

        public static void Answer()
        {
            var s = ReadLine();
            int c = s.IndexOf('C');
            int f = s.LastIndexOf('F');

            if (c == -1 || f == -1)
                WriteLine("No");
            else if (c < f)
                WriteLine("Yes");
            else
                WriteLine("No");
        }
    }

    public class IO
    {
        #region Input
        public static int RInt => int.Parse(ReadLine());
        public static long RLong => long.Parse(ReadLine());
        public static double RDouble => double.Parse(ReadLine());

        public static string[] RSString => ReadLine().Split();
        public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray();
        public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray();
        #endregion

        #region Output
        public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
        public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");
        public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO");
        #endregion
    }

    public class Mod
    {
        #region
        private readonly static long M = 1000000007;

        public static long Add(long a, long b) => (a * b) % M;
        public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
        public static long Multi(long a, long b) => (a * b) % M;
        #endregion
    }
}

Measured memory_bytes: 17364
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using VI = vector<int>;
using VB = vector<bool>;
using Graph = vector<vector<int>>;
using ll = long long;
using P = pair<int, int>;

int main()
{
  ll n, k, q;
  cin >> n >> k >> q;

  vector<int> point(n, k - q);
  int a[q];
  rep(i, q) cin >> a[i];
  rep(i, q) a[i] -= 1;

  rep(i, q)
  {
    point[a[i]]++;
  }

  rep(i, n)
  {
    if (point[i] <= 0)
      cout << "No" << endl;
    else
      cout << "Yes" << endl;
  }
}

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

using namespace std;

int main(int argc, const char *argv[]) {
  string s;
  cin >> s;
  bool ans = false;
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == '9') {
      ans = true;
      break;
    }
  }

  cout << (ans ? "Yes" : "No") << '\n';
  return 0;
}

Measured memory_bytes: 3624
// Problem : D - Sum of Divisors
// Contest : AtCoder - AtCoder Beginner Contest 172
// URL : https://atcoder.jp/contests/abc172/tasks/abc172_d
// Memory Limit : 1024 MB
// Time Limit : 3000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl '\n'
#define pb push_back
#define mod 1000000007
ll power(ll x, ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % mod; 
    p = (p * p) % mod; 
  
    return (y%2 == 0)? p : (x * p) % mod; 
} 
ll factorial[1000007];
void fact(ll n)
{
    memset(factorial,0,sizeof(factorial));
    factorial[0]=1;
factorial[1]=1;

    for(int i=1;i<n;i++)
    {
        factorial[i]=(factorial[i-1]*i)%mod;
    }
    
}
ll ncr(ll n,ll r)
{
    ll ans=1;
    ll i;
    ans=factorial[n];
    ll ans1=power(factorial[n-r],mod-2);
    ll ans2=power(factorial[r],mod-2);
    ans=((ans*ans1)%mod*ans2)%mod;
    return ans;
}
ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
} 

bool prime[10000006];
int spf[10000006];
void sieve(ll n){
    memset(prime,true,sizeof(prime));
    memset(spf,-1,sizeof(spf));
	prime[1]=false; 
    for (ll p=2;p*p<=n;p++){
        if (prime[p]){  
        spf[p]=p;
            for (ll i=p*p;i<=n;i+=p)
            {
                prime[i]=false;
                if(spf[i]==-1)
                spf[i]=p;
             }
        }
    }
}
void bfs(vector<int> v[],int o,int n,int dp[]){
	queue<int> q;
	q.push(o);
	dp[o]=0;
	bool visited[n+1]={0};
	visited[o]=true;
	while(q.empty()==false){
		int a=q.front();
		q.pop();
		for(int i=0;i<v[a].size();i++){
			if(visited[v[a][i]]==false){
				visited[v[a][i]]=true;
				q.push(v[a][i]);
				dp[v[a][i]]=dp[a]+1;
			}
		}
	}
}
int nov[1000001];
bool visited[1000001];
int dp[1000001];
int dfs(vector<int> v[],int o)
{
    if(visited[o]==0)
    {
        visited[o]=1;
        for(int i=0;i<v[o].size();i++)
        {
            if(visited[v[o][i]]==0)
            {
            dp[v[o][i]]=dp[o]+1;
            nov[o]+=dfs(v,v[o][i]);
            }
        }
        return nov[o]+1;
    }
    else
    return 0;
}
// string s=bitset<64>(n).to_string();
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	ll n;
	cin>>n;
	sieve(n);
	for(int i=2;i<=n;i++)
	{
		if(prime[i]==true)
		{
			spf[i]=i;
		}
	}
	ll ans=1;
	for(int i=2;i<=n;i++)
	{
		vector<int> v;
		int temp=i;
		while(temp!=1)
		{
			v.pb(spf[temp]);
			temp/=spf[temp];
		}
		ll res=1;
		int cnt=1;
		for(int i=1;i<v.size();i++)
		{
			if(v[i]==v[i-1])
			{
				cnt++;
			}
			else
			{
				res*=(cnt+1);
				cnt=1;
			}
		}
		res*=(cnt+1);
		ans+=i*res;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 52436
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define f(a, b) for (ll i = a; i <= b; i++)
#define pb push_back
#define pf push_front
#define mp make_pair
using namespace std;
#define N 200005
const ll INF = 1000000000000000001;
const ll MOD = 1000000007;

//vector< vector<ll> > g(N);
//vector< pair<ll, pair< ll, ll > > > g(N);
//ll vis[N] = {0}, par[N] = {0}, child[N] = {0},cnt = 0;


void solve(){
    ll n, k; cin >> n >> k;
    ll a[n], ans =0;
    f(0, n-1) cin >> a[i];
    sort(a, a+n);
    f(0, k-1) ans += a[i];
    cout << ans << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif
   //ll t;cin >> t;for(ll index=1; index<=t; index++){
        //cout << "Case #" << index << ": " ;
        solve();
   // }
    return 0;
}

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

using namespace std;

int n;
vector<long long> v;

void hawawa(){
	cin >> n;
	v.resize(n + 1);
	for (auto&& i : v) {
		cin >> i;
	}
	sort(begin(v), end(v));
	long long s = v[0];
	for (auto&& i : v) {
		i -= s;
	}
	vector<long long> divs;
	for (int i = 1; i * i <= v[1]; i++) {
		if (i * i == v[1]) {
			divs.push_back(i);
			break;
		}
		if (v[1] % i == 0) {
			divs.push_back(i);
			divs.push_back(v[1] / i);
		}
	}
	sort(rbegin(divs), rend(divs));
	for (auto&& i : divs) {
		bool check = true;
		for (auto&& j : v) {
			if (j % i) {
				check = false;
				break;
			}
		}
		if (check) {
			cout << i << "\n";
			return;
		}
	}
}

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


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

int main(){
    int N, M, C;
    cin >> N >> M >> C;
    int B[21];
    for(size_t i = 0; i < M; i++)
    {
        cin >> B[i];
    }
    int ret = 0;
    int A[21];
    for(size_t i = 0; i < N; i++)
    {
        int sum = C;
        for(size_t j = 0; j < M; j++)
        {
            cin >> A[j];
            sum += A[j] * B[j];
        }
        if (sum > 0)
            ret++;
    }
    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstring>
#define ll long long
using namespace std;
int main()
{
    int n;
    cin>>n;
    ll sum = 0;
    ll x;
    for(int i = 1;i<=n;i++)
    {
        cin>>x;
        sum += x;
    }
    cout<<sum - n<<endl;
   return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	as := make([]int, n)
	for i := range as {
		fmt.Scan(&as[i])
	}
	var bs []int
	for i, a := range as {
		if i == 0 {
			bs = append(bs, a)
			continue
		}
		if a == bs[len(bs)-1] {
			continue
		}
		bs = append(bs, a)
	}

	money := 1000
	stock := 0

	for i := 0; i < len(bs)-1; i++ {
		b := bs[i]
		next := bs[i+1]
		if b < next {
			// buy
			ds := money / b
			stock += ds
			money -= ds * b
		} else {
			// sell
			money += stock * b
			stock = 0
		}
	}
	if stock > 0 {
		money += stock * bs[len(bs)-1]
		stock = 0
	}
	fmt.Println(money)

}


Measured memory_bytes: 1792
#include <iostream>

using namespace std;

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

const int N = 15;
int n, a[N], x[N][N], y[N][N], h[N];

bool check() {
  rep(i,n) {
    if(h[i] == 1) {
      rep(j,a[i]) {
        if(h[x[i][j]] != y[i][j]) {
          return false;
        }
      }
    }
  }
  return true;
}

int main() {
  cin >> n;
  rep(i,n) {
    cin >> a[i];
    rep(j,a[i]) {
      cin >> x[i][j] >> y[i][j];
      x[i][j]--;
    }
  }
  int r = 0;
  rep(c,1<<n) {
    rep(i,n) h[i] = (c>>i)%2;
    if(check()) {
      int p = 0;
      rep(i,n) p += h[i];
      r = max(r, p);
    }
  }
  cout << r << endl;
  return 0;
}

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

int main() {
    int n;
    cin >> n;
    long long sum = 0;
    for (int i=1; i<=n; i++) {
        if (i%3!=0 && i%5!=0) {
            sum += i;
        }
    }
    cout << sum << endl;
}


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

long long solve(long long h)
{
    if(h == 1)
        return 1;
    
    return 2LL * solve(h / 2) + 1;
}

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

    long long h;
    cin >> h;

    cout << solve(h) << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<algorithm>

using namespace std;

int n;
int a[100010];
int f[100010];

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	f[1]=0;
	f[2]=abs(a[2]-a[1]);
	for(int i=3;i<=n;i++)
	{
		f[i]=min(f[i-1]+abs(a[i]-a[i-1]),f[i-2]+abs(a[i]-a[i-2]));
	}
	printf("%d",f[n]);
	return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  if(a < b) {
    swap(a, b);
  }
  if((a - b) % 2 == 0) {
    cout << (a - b) / 2 + b;
  } else {
    cout << "IMPOSSIBLE";
  }
}


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

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

using namespace std;

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

	rep(i, s.size()) {
		if (s[i] == '0') ans += '0';
		else if (s[i] == '1') ans += '1';
		else {
			if (!ans.empty()) ans.pop_back();
		}
}

cout << ans << '\n';

return 0;
}

Measured memory_bytes: 3600
#include<stdio.h>
int main(void){
    int N, X, fX, i;
    scanf("%d", &N);
    X = N;
    fX = 0;
    for(i = 0; i < 8; i++){
        fX += N % 10;
        N /= 10;
    }
    if(X % fX == 0) printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
typedef long long ll ;
int main() {
  string S ;
  cin >> S ;
  int N    ;
  cin >> N ;
  bool frag = false ;
  string T , U ;
  rep(i,N){
      int E ;
      cin >> E ;
      if( E == 1 ){
          if(frag) frag = false ;
          else frag = true      ;
          swap(T,U) ;
      }
      else{
          int F ;
          cin >> F ;
          string C ;
          cin >> C ;
          if( F == 1 ) T += C ;
          else U += C ; 
      }
  }
  reverse(T.begin(),T.end()) ;
  if(frag) reverse(S.begin(),S.end()) ;
  cout << T << S << U <<endl;
}

Measured memory_bytes: 1088
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a[3];
	int k, max, temp;
	cin >> a[0] >> a[1] >> a[2] >> k;
	for(int i=0;i<2;i++){
		for(int j=i+1;j<3;j++){
			if(a[i]>a[j]){
				temp = a[i];
				a[i] = a[j];
				a[j] = temp;
			}
		}
	}
	for(int i=0;i<k;i++){
		a[2]*=2;
	}
	max = a[0]+a[1]+a[2];
	cout << max << endl;
}

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

int descending_compare(const void *a, const void *b){
    if (*(int*)a > *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}

int ascending_compare(const void *a, const void *b){
    if (*(int*)a < *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}


int lower_bound(int *a, int n, int key){
    int left, mid, right;
    left = 0, right = n;
    mid = (left + right)/2;
    while ((left+1 != mid || mid+1 != right) && mid != left){
        if (key > a[mid]){
            left = mid;
        }else{
            right = mid+1;
        }
        mid = (left + right)/2;
    }
    if (a[left] >= key)return left;
    if (a[mid] >= key)return mid;
    if (a[right] >= key)return right;
    return n;
}

//greatest common divisor
unsigned long  gcd(unsigned long x, unsigned long y){
    if (y == 0){ 
        return x;
    }else if (x > y){
        return gcd(y, x % y);
    }else{
        return gcd(x, y % x);
    }
}



long long factorial(int x){
    long long rtn = 1;
    int i;
    for (i = x; i > 1; i--){
        rtn = (rtn*i);
    }
    return rtn;
}



int main(void){
    int a, b, c, x;
    int cnt = 0;
    scanf("%d %d %d %d", &a, &b, &c, &x);
    for (int i = 0; i <= a; i++){
        for (int j = 0; j <= b; j++){
            for (int k = 0; k <= c; k++){
                if (500*i+100*j+50*k == x){
                    cnt++;
                }
            }
        }
    }
    
    printf("%d\n", cnt);
    return 0;

}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <queue>
using namespace std;
 
map<string, int> dp;
int direction[4] = { 1, -1, 4, -4 };
 
//************************************
// Method:    bfs
// FullName:  bfs
// Access:    public 
// Returns:   void
// Qualifier: 让0漫游整个字串
//************************************
void bfs()
{
	queue<string> que;
	que.push("01234567");
	dp["01234567"] = 0;
	while (!que.empty())
	{
		string now = que.front(); que.pop();
		// p是'0'的位置
		int p = 0;
		for (int j = 0; j < 8; ++j)
		{
			if (now[j] == '0')
			{
				p = j;
				break;
			}
		}
 
		for (int i = 0; i < 4; ++i)
		{
			int n = p + direction[i];
			if (0 <= n && n < 8 && 
				!(p == 3 && i == 0) && // 右上角不能再往右了
				!(p == 4 && i == 1))   // 左下角不能再往左了
			{
				string next = now;
				swap(next[p], next[n]);
				if (dp.find(next) == dp.end())
				{
					dp[next] = dp[now] + 1;
					que.push(next);
				}
			}
		}
	}
}
 
///////////////////////////SubMain//////////////////////////////////
int main(int argc, char *argv[])
{
 
	bfs();
	string line;
	while (getline(cin, line))
	{
		line.erase(remove(line.begin(), line.end(), ' '), line.end());
		cout << dp[line] << endl;
	}
 
	return 0;
}
///////////////////////////End Sub//////////////////////////////////


Measured memory_bytes: 5364
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll dep(ll a,ll b){
	if(b==0){
		return a;
	}
	return dep(b,a%b);
}
bool ch[3];
int main() {
	ll a,b;
	cin>>a>>b;
	if(a<b){
		swap(a,b);
	}
	cout <<a/dep(a,b)*b;
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{ 
	
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)) {
			int cnt = 0;
			int[][] dp = new int[1001][1001];
			while(sc.hasNext()) {
				cnt++;
				int W = sc.nextInt();
				if(W==0)break;
				int n = sc.nextInt();
				int[] v = new int[n+1];
				int[] w = new int[n+1];
				for(int i=1;i<=n;i++) {
					String[] str = sc.next().split(",");
					v[i] = Integer.parseInt(str[0]);
					w[i] = Integer.parseInt(str[1]);
				}
				dp = new int[n+2][W+1];
				for(int i=0;i<=W;i++) {
					dp[0][i] = 0;
				}
				
				int answ= Integer.MAX_VALUE;
				int ansv = Integer.MIN_VALUE;
				for(int i=1;i<=n;i++){
	                for(int j=1;j<=W;j++){
	                    if(j-w[i]>=0){
	                        dp[i][j] = Math.max(dp[i-1][j], dp[i-1][j-w[i]]+v[i]);
	                        if(ansv < dp[i][j]){
	                            ansv = dp[i][j];
	                            answ = j;
	                        }
	                        else if(ansv == dp[i][j]){
	                            answ= Math.min(answ, j);
	                        }
	                    }
	                    else dp[i][j] = dp[i-1][j];
	                }
	            }
				System.out.println("Case "+cnt+":");
				System.out.println(ansv);
				System.out.println(answ);
				
			}
			
			return;
		}
	}
}



Measured memory_bytes: 41288
#include <iostream>
#include <queue>

using namespace std;
const int N=100;
const int INFTY=(1<<21);

int n,M[N][N];
//??????????????????????????¶??????color???
int d[N];

void bfs(int s){
    queue<int> q;
    q.push(s);
    for(int i=0;i<n;i++)
        d[i]=INFTY;
    d[s]=0;
    int u=0;
    while(!q.empty()){
        u=q.front();q.pop();
        for(int v=0;v<n;v++)
            if(M[u][v]!=0&&d[v]==INFTY){
                d[v]=d[u]+1;
                q.push(v);
            }
    }
    for(int i=0;i<n;i++)
        cout<<i+1<<" "<<(d[i]==INFTY?-1:d[i])<<endl;
}

int main(){
    int u,k,v;
    
    cin>>n;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            M[i][j]=0;
    
    for(int i=0;i<n;i++){
        cin>>u>>k;
        u--;
        for(int j=0;j<k;j++){
            cin>>v;
            v--;
            M[u][v]=1;
        }
    }
    
    bfs(0);
}

Measured memory_bytes: 3120
#include<stdio.h>

int main(void){
    int a,b;
  
    scanf("%d %d",&a,&b);
  
    if(a < 10 && b < 10)
    { 
        printf("%d\n",a * b);
    }    
    else
    { 
        printf("-1\n");
    }
        
    return 0;
}    
    

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

int main() {
  int N;
  cin >> N;
  vector<int> h(N);
  rep(i, N) {
    cin >> h[i];
  }
  vector<int> v(N);
  v[0] = 0;
  v[1] = abs(h[1] - h[0]);
  for (int i = 2; i < N; i++) {
    if (v[i - 2] + abs(h[i] - h[i - 2]) > v[i - 1] + abs(h[i] - h[i - 1])) {
      v[i] = v[i - 1] + abs(h[i] - h[i - 1]);
    }
    else {
      v[i] = v[i - 2] + abs(h[i] - h[i - 2]);
    }
  }
  cout << v[N - 1] << endl;
}



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

int main()
{
	int N;
	cin >> N;
	ll sum = 0;
	for (int i = 1; i <= N; ++i)
	{
		if (i % 3 != 0 && i % 5 != 0) sum += i;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define PI 3.141592653589793
#define MOD 1000000007
//#define DEBUG

//qsort用、昇順
int compare_int(const void *a, const void *b)
{
	return *(int*)a-*(int*)b;
}
//qsort(array, 10, sizeof(int), compare_int)

int main(){
	int a, b, c, k;
	scanf("%d%d%d%d", &a, &b, &c, &k);
	
	while((k>0) && (b<=a)){
		b *= 2;
		k--;
	}
	while((k>0) && (c<=b)){
		c *= 2;
		k--;
	}

	if((c>b) && (b>a)) printf("Yes\n");
	else printf("No\n");
	
	
	return 0;
}



Measured memory_bytes: 1664
from collections import Counter


cntr = Counter(input())
x_ok, y_ok = False, False
if (cntr["E"] and cntr["W"]) or (not cntr["E"] and not cntr["W"]):
    x_ok = True
if (cntr["N"] and cntr["S"]) or (not cntr["N"] and not cntr["S"]):
    y_ok = True
print("Yes") if x_ok and y_ok else print("No")


Measured memory_bytes: 9396
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
int N;
bool A[50][50],B[50][50];
bool e[50][50];
void dfsA(int v, int p, vector<bool>& isfixed){
    rep(u,N) if(u!=p && A[v][u]){
            if(!isfixed[v] && !isfixed[u]){
                e[v][u] = 1;
//			printf("(%d->%d)\n",v,u);
            }
            dfsA(u,v,isfixed);
        }
}
void dfsB(int v, int p, vector<bool>& isfixed){
    rep(u,N) if(u!=p && B[v][u]){
            if(!isfixed[v] && !isfixed[u]){
                e[u][v] = 1;
//			printf("(%d->%d)\n",u,v);
            }
            dfsB(u,v,isfixed);
        }
}
vector<int> vis;
bool dfsCycle(int v){
    if(vis[v]==1){
        return 1;
    }
    if(vis[v]==2) return 0;
    vis[v] = 1;
    rep(u,N) if(e[v][u]){
            if(dfsCycle(u)) return 1;
        }
    vis[v]=2;
    return 0;
}
bool hascycle(){
    vis = vector<int>(N,0);
    rep(i,N) if(vis[i]==0){
            if(dfsCycle(i)) return 1;
        }
    return 0;
}
int solve(){
    cin>>N;
    rep(i,N) rep(j,N) A[i][j] = B[i][j] = 0;
    rep(i,N-1){
        int x,y;
        cin>>x>>y;
        x--,y--;
        A[x][y] = A[y][x] = 1;
    }
    rep(i,N-1){
        int x,y;
        cin>>x>>y;
        x--,y--;
        B[x][y] = B[y][x] = 1;
    }

    int ans = 100;
    rep(x,N) rep(y,N){
        vector<bool> isfixed(N,false);
        if(x==y){
            int r = x;
            queue<int> que;
            isfixed[r] = true;
            que.push(r);
            while(!que.empty()){
                int v = que.front();
                que.pop();
                rep(u,N) if(A[v][u] && B[v][u] && !isfixed[u]){
                        isfixed[u] = 1;
                        que.push(u);
                    }
            }
        }
        rep(i,N) rep(j,N) e[i][j] = 0;
        dfsA(x,-1,isfixed);
        dfsB(y,-1,isfixed);
        if(!hascycle()){
            int fixedNum = 0;
            rep(i,N) if(isfixed[i]) fixedNum++;
            int tmp = N-fixedNum;
            chmin(ans,tmp);
        }
    }
    if(ans==100) return -1;
    return ans;
}
int main(){
    int T;
    cin>>T;
    rep(i,T) cout<<solve()<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define M 998244353
#define F first
#define S second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<double,ll> pll;
#define pb push_back
#define M6 5000009
#define M5 500009
#define pi 3.14159265
ll power(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=(res*x)%M;
        n/=2;
        x=(x*x)%M;
    }
    return res;
}
ll prime[M6];
void sieve(){
    for(int i=2;i<M6;i++) prime[i]=1;
    for(int i=2;i*i<M6;i++){
        if(prime[i]==0) continue;
        for(int j=i*2;j<M6;j+=i) prime[j]=0;
    }
}
ll n,m,A[M5];
int  main()
{   ios_base::sync_with_stdio (0), cin.tie (0);
    //sieve();
    //init();
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll tc=1,t=0,i,j,k,l,a,b,c,d;
    //cin>>tc;
    while(t++<tc){
        cin>>n;
        unordered_map<string,ll> cnt;
        for(i=1;i<=n;i++){
            string s;
            cin>>s;
            sort(s.begin(),s.end());
            cnt[s]++;
        }
        ll ans=0;
        for(auto u:cnt){
            if(u.S>1) ans+=u.S*(u.S-1)/2;
        }
        cout<<ans;
    }
    return 0;
}

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

int main()
{
    string S;
    cin >> S;
    int n = 0;
    string sub;
    int prev_n = 0;
    while (n != S.length())
    {

        if (S.length() - n >= 5 && S.substr(n, 5) == "dream" || S.substr(n, 5) == "erase")
        {
            n += 5;
            prev_n = 5;
        }
        else
        {
            if(prev_n == 6 || prev_n == 7)
            {
                cout << "NO" << endl;
                return 0;
            }
            n -= prev_n;
            if (S.length() - n >= 6 && S.substr(n, 6) == "eraser")
            {
                n += 6;
                prev_n = 6;
            }
            else if (S.length() - n >= 7 && S.substr(n, 7) == "dreamer")
            {
                n += 7;
                prev_n = 7;
            }
            else
            {
                cout << "NO" << endl;
                return 0;
            }
        }
    }
    cout << "YES" << endl;
}

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

void sort(int n, int* array) {
    for (int i = 0; i < n - 1; i++) {
        for (int j = 0; j < n - 1 - i; j++) {
            if (array[j] < array[j + 1]) {
                int temp = array[j];
                array[j] = array[j + 1];
                array[j + 1] = temp;
            }
        }
    }
}

int main() {
    int scoreW[10];
    for (int i = 0; i < 10; i++) {
        cin >> scoreW[i];
    }
    int scoreK[10];
    for (int i = 0; i < 10; i++) {
        cin >> scoreK[i];
    }
    sort(10, scoreW);
    sort(10, scoreK);
    cout << scoreW[0] + scoreW[1] + scoreW[2] << " "
         << scoreK[0] + scoreK[1] + scoreK[2] << endl;
}

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

int main() {	
	for (;;) {
		int h, w;
		cin >> h >> w;
		if (h == 0 && w == 0) {
			break;
		}
		for (int y = 0; y < h; y++) {
			for (int x = 0; x < w; x++) {
				cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}



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

int main () {
     int N, M; cin >> N >> M;
    vector < long  long > X (M);
     for ( int i = 0 ; i <M; ++ i) cin >> X [i];
    sort (X.begin (), X.end ());
        
    vector < long  long > diffs;
     for ( int i = 1 ; i <X.size (); ++ i) diffs.push_back (X [i]-X [i- 1 ]);
    sort (diffs.begin (), diffs.end (), greater < long  long > ());
        
    long  long res = X.back ()-X [ 0 ];
     for ( int i = 0 ; i <min (( int ) diffs.size (), N- 1 ); ++ i) res-= diffs [i ];
    cout << res << endl;
}

Measured memory_bytes: 2168
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>

using namespace std;
using value_t = unsigned long long;

int main() {
    value_t A, B;
    cin >> A; // 010
    cin >> B; // 100

    if (A == B) {
        cout << A;
        return 0;
    }

    bool oddA = A % 2 == 0; // 1
    bool oddB = B % 2 == 0; // 1

    value_t result = 0;
    if (oddA == oddB) {
        result = oddA ? 0 : 1;
        result += (B - A) >> 1;
    } else {
        result = 1 + ((B - A - 1) >> 1);
    }
    result %= 2;
    int k = 1;
    value_t pow2K = 2;

    while (pow2K <= B) {
        int modA = (A >> k) % 2;
        int modB = (B >> k) % 2;

        int resA = (modA == 1 && !oddA) ? 1 : 0;
        int resB = (modB == 1 &&  oddB) ? 1 : 0;

        if ((resA + resB) % 2 == 1)
            result += pow2K;

        pow2K = pow2K << 1;
        k += 1;
    }

    cout << result;
    return 0;
}


Measured memory_bytes: 256
/**
 *   @FileName	d.cpp
 *   @Author	kanpurin
 *   @Created	2020.05.17 23:28:27
**/

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

 
int main() {
    int n,m;cin >> n >> m;
    vector<vector<int>> g(n);
    for (int i = 0; i < m; i++) {
        int a,b;cin >> a >> b;
        a--;b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    queue<int> que;
    vector<int> ans(n,-1);
    que.push(0);
    ans[0] = 0;
    while(!que.empty()) {
        int q = que.front(); que.pop();
        for(int v : g[q]) {
            if (ans[v] == -1) {
                ans[v] = q + 1;
                que.push(v);
            }
        }
    }
    puts("Yes");
    for (int i = 1; i < n; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}

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

#define INF_LL (int64)1e18
//#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

class UnionFind{
private:
    ::std::vector<int_fast32_t> par, edge;
    size_t n;

public:
    UnionFind(){}
    UnionFind(size_t n):n(n){
        par.resize(n, -1);
        edge.resize(n, 0);
    }

    uint_fast32_t find(uint_fast32_t x){
        return par[x] < 0 ? x : par[x] = find(par[x]);
    }

    size_t size(uint_fast32_t x){
        return -par[find(x)];
    }

    bool unite(uint_fast32_t x, uint_fast32_t y){
        x = find(x);
        y = find(y);
        edge[x] += 1;
        if(x == y) return false;
        if(size(x) < size(y)) std::swap(x, y);
        par[x] += par[y];
        edge[x] += edge[y];
        par[y] = x;
        return true;
    }

    bool same(uint_fast32_t x, uint_fast32_t y){
        return find(x) == find(y);
    }

    size_t esize(uint_fast32_t x) {
        return edge[find(x)];
    }
};

bool can_month(int a) {
    return 1 <= a && a <= 12;
}

int main(void) {
    string s;
    cin >> s;
    int64 l = stoi(s.substr(0, 2)), r = stoi(s.substr(2, 2));
    if (can_month(l)) {
        if (can_month(r)) {
            cout << "AMBIGUOUS" << endl;
        } else {
            cout << "MMYY" << endl;
        }
    } else {
        if (can_month(r)) {
            cout << "YYMM" << endl;
        } else {
            cout << "NA" << endl;
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
#define mod 1000000007

ll gcd(ll x,ll y) {return y ? gcd(y,x%y) : x;} 
ll lcm(ll x,ll y) {return x/gcd(x,y)*y;}

int main(){
    int n,k;
    cin >> n >> k;
    
    vector<ll> a(n);
    rep(i,n){
        cin >> a[i];
    }
    ll ans=0;
    sort(a.begin(),a.end());
    rep(i,k){
        ans+=a[i];
    }
    cout << ans << endl;

    return 0;
}











Measured memory_bytes: 3636
import Data.List

solve :: [(Char, Char)] -> String
solve [] = "None"
solve ((c1, c2):cs)
  | c1 == '-' = [c2]
  | c1 > c2 = [c2]
  | otherwise = solve cs

main :: IO ()
main = do
  s <- take 26 . (++ replicate 26 '-') . nub . sort <$> getLine
  putStrLn . solve $ zip s ['a'..'z']

Measured memory_bytes: 11644