akhauriyash/Code-Regression huggingface dataset:
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

ulong MOD = 1_000_000_007;
ulong INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias t = Tuple!(string, "name", long, "y");

void main()
{
    auto n = lread();
    auto a = aryread();
    auto b = aryread();
    a[] -= b[];
    a.sort();
    long minus, cnt;
    foreach (e; a)
    {
        if (e >= 0)
            break;
        
        minus -= e;
        cnt++;
    }
    foreach_reverse(e; a)
    {
        if(minus <= 0)
            break;
        
        minus -= e;
        cnt++;
    }
    if(cnt > n)
        writeln(-1);
    else
        cnt.writeln();
}

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 10004
#include<stdio.h>
#include<string.h>

void dfs(int,int);
char grid[102][102];

int main(void){

  int i,j,h,w;

  while(scanf("%d %d",&h,&w),h,w){
    
    for(i=0;i<h;i++)
      for(j=0;j<w;j++)
	scanf(" %c",&grid[i][j]);

    dfs(0,0);
  }
  return 0;
}

void dfs(int y,int x){

  char temp=grid[y][x];

  if(temp=='1'){
    printf("LOOP\n");
    return ;
  }

  if(temp=='.'){
    printf("%d %d\n",x,y);
  }

  grid[y][x]='1';
  if(temp=='>')dfs(y,x+1);
  else if(temp=='<')dfs(y,x-1);
  else if(temp=='^')dfs(y-1,x);
  else if(temp=='v')dfs(y+1,x);

}

Measured memory_bytes: 0
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())

n = int(input())
T = []
X = []
Y = []
for i in range(n):
    t,x,y = readInts()
    T.append(t)
    X.append(x)
    Y.append(y)
cx,cy,ct = 0,0,0
for i in range(n):
    dist_place = abs(X[i] - cx) + abs(Y[i] - cy)
    dist_time = abs(T[i] - ct)
    if dist_time >= dist_place and (dist_time - dist_place) % 2 == 0:
        cx = X[i]
        cy = Y[i]
        ct = T[i]

        pass
    else:
        print('No')
        exit()
print('Yes')


Measured memory_bytes: 18896
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>  
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
double eps = 1e-12;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 2e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
 
ll mpow(ll a, ll b){
	if(a==0) return 0;
	if(b==0) return 1;
	ll t1 = mpow(a,b/2);
	t1 *= t1;
	t1 %= MOD;
	if(b%2) t1 *= a;
	t1 %= MOD;
	return t1;
}
 
ll mpow(ll a, ll b, ll p){
	if(a==0) return 0;
	if(b==0) return 1;
	ll t1 = mpow(a,b/2,p);
	t1 *= t1;
	t1 %= p;
	if(b%2) t1 *= a;
	t1 %= p;
	return t1;
}
 
ll modinverse(ll a, ll m){
	ll m0 = m; 
    ll y = 0, x = 1; 
    if (m == 1) return 0; 
    while (a > 1){
        ll q = a / m; 
        ll t = m; 
        m = a % m, a = t; 
        t = y; 
        y = x - q * y; 
        x = t; 
    }
    if (x < 0) x += m0; 
    return x; 
}

mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
 
ll range(ll l, ll r){
	return l + mt()%(r-l+1);
}
 
ll rev(ll v){
	return mpow(v,MOD-2);
}

void solve(){
	ll n;
	cin >> n;
	ll ans = 1;
	while((ans*n)%360) ans++;
	cout << ans << ln;
}
 
int main()
{
	fast_cin();
    ll t=1;
    // cin >> t;
    forn(i,t) {
    	// cout << "Case #" << i+1 << ": ";
    	solve();
    }
    return 0;
}

Measured memory_bytes: 3636
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author aakas
 */
import java.util.*;
public class Main{
    static int n;
    static int m;
    static ArrayList<Integer>[] adjList;
    static boolean[] v;
    static int[] dp;
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        m = sc.nextInt();
        adjList = new ArrayList[n+1];
        //visited = new boolean[n];
        v = new boolean[n+1];
        dp = new int[n+1];
        for(int i=0;i<=n;i++)
            adjList[i] = new ArrayList<Integer>();
        for(int i=0;i<m;i++)
            adjList[sc.nextInt()].add(sc.nextInt());
        int temp = Integer.MIN_VALUE;
        for(int i=1;i<=n;i++)
        {
            //boolean[] visited = new boolean[n+1];
            temp = Math.max(dfs(i),temp);
        }
        System.out.println(temp);
    }
    public static int dfs(int s)
    {
        //System.out.println("call for "+s+" "+visited[s]);
        //if(visited[s])
          //  return 0;
        if(v[s])
            return dp[s];
        v[s] = true;
        //visited[s] = true;
        for(int i=0;i<adjList[s].size();i++)
        {
            int v = adjList[s].get(i);
            //System.out.println(s+ " -> "+v);
            //if(!visited[v])
            //{
                 dp[s] = Math.max(1+dfs(v),dp[s]);
                 //System.out.println(s+" "+dp[s]);
            
        }
        //System.out.println(s+" "+dp[s]);
        return dp[s];
    }
}


Measured memory_bytes: 103708
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<numeric>
#define ll long long
#define MOD = 1e9+7
 
using namespace std;
 
int main() {
  ll N;
  cin >> N;
  set<string> ans;
  for(int i=0;i<N;i++){
    string s;
    cin >> s;
    ans.insert(s);
  }

  cout << ans.size() << endl;
}


Measured memory_bytes: 15596
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

m1 = dict()
for i, v in enumerate(a):
    t = (i+1) + v
    if t not in m1:
        m1[t] = set()
    m1[t].add(i+1)

m2 = dict()
for i, v in enumerate(a):
    t = (i+1) - v
    if t <= 1:
        continue
    if t not in m1:
        continue
    if t not in m2:
        m2[t] = set()
    m2[t].add(i+1)

ans = 0
for k in m2:
    ans += len(m1[k]) * len(m2[k])

print(ans)


Measured memory_bytes: 144028
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>

using namespace std;

#define int long long

signed main() {
	int a, b, h;
	cin >> a >> b >> h;
	cout << (a + b)*h / 2 << endl;
	return 0;
}



Measured memory_bytes: 256
// clang-format off
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i,n) for(ll i=n-1; i>=0; --i)
#define rrep1(i,n) for(ll i=n; i>0; --i)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define SORT_DESC(x) sort(all(x), greater<>())
#define pb push_back
#define mp make_pair
#define coutl cout<<fixed<<setprecision(10)
#define ANS(ans) cout<<ans<<endl;
const ll LINF = (1LL << 62) - 1;
const int INF = (1 << 30) - 1;
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;}
// clang-format on

void solve(long long H, long long W, long long N) {
  ll l = max(W, H);
  ll ans = N / l;
  if (N % l > 0)
    ans++;
  ANS(ans);
}

// clang-format off
int main() {
  long long H;
  scanf("%lld",&H);
  long long W;
  scanf("%lld",&W);
  long long N;
  scanf("%lld",&N);
  solve(H, W, N);
  return 0;
}


Measured memory_bytes: 256
N = int(input())
S = input()

ans = 0

for i in range(N - 1):
    A = S[:i + 1]
    B = S[i + 1:]
    C = set()
    for a in A:
        if a in list(B):
            C.add(a)
        ans = max(ans, len(C))

print(ans)

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

typedef long long int ll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll INF = (1 << 30) + 6;//2 * 100000 * 100000000 + 5;
const ll MOD = 1000000007;

using namespace std;

ll A[200005];
ll R[200005];
ll M[200005];

ll rangeSum(int s, int e)
{
	if (s > e)swap(s, e);
	return R[e] - R[s] + A[s];
}

int main()
{
	ll N;
	cin >> N;
	REP(i, N)
	{
		cin >> A[i];
		R[i] = A[i];
		if (i > 0)R[i] += R[i - 1];
	}

	ll min = INF;
	FOR(i, N - 1, 1)
	{
		//! iを真ん中の区切りとする(iはA[i]とA[i+1]の間の線)

		//! 左側の差が小さくなるようなindex
		ll l_l = 0, l_r = i;
		while (std::abs(l_l - l_r) > 1)
		{
			ll m = (l_l + l_r) / 2;
			//if (R[m] <= R[i - 1] / 2)
			if (rangeSum(0, m) <= rangeSum(0, i) / 2 && rangeSum(0, m) <= rangeSum(i, m + 1))
			{
				l_l = m;
			}
			else
			{
				l_r = m;
			}
		}
		//if (abs(R[l_l + 1] - (R[i - 1] - R[l_l + 1])) < abs(R[l_l] - (R[i - 1] - R[l_l])))
		if (l_l + 1 != i&&abs(rangeSum(i, l_l + 2) - rangeSum(l_l + 1, 0)) < abs(rangeSum(i, l_l + 1) - rangeSum(l_l, 0)))
		{
			l_l++;
		}
		//! 右側の差が小さくなるようなindex
		ll rl = i + 1, rr = N;
		while (std::abs(rl - rr) > 1)
		{
			ll m = (rl + rr) / 2;
			//if ((R[m - 1] - R[i - 1]) <= (R[N - 1] - R[i - 1]) / 2)
			if (rangeSum(i + 1, m) <= rangeSum(N - 1, i) / 2 && rangeSum(i + 1, m) <= rangeSum(N - 1, m + 1))
			{
				rl = m;
			}
			else
			{
				rr = m;
			}
		}
		//if (abs((R[rl] - R[i - 1]) - (R[N - 1] - R[rl])) < abs((R[rl - 1] - R[i - 1]) - (R[N - 1] - R[rl - 1])))
		if (rl + 1 != N - 1 && abs(rangeSum(N - 1, rl + 2) - rangeSum(rl + 1, i + 1)) < abs(rangeSum(N - 1, rl + 1) - rangeSum(rl, i + 1)))
		{
			rl++;
		}
		//! 計算
		//ll tmax = std::max(R[l_l - 1], std::max(R[i - 1] - R[l_l - 1], std::max(R[rl - 1] - R[i - 1], R[N - 1] - R[rl - 1])));
		ll tmax = std::max(rangeSum(l_l, 0), std::max(rangeSum(i, l_l + 1), std::max(rangeSum(i + 1, rl), rangeSum(N - 1, rl + 1))));
		ll tmin = std::min(rangeSum(l_l, 0), std::min(rangeSum(i, l_l + 1), std::min(rangeSum(i + 1, rl), rangeSum(N - 1, rl + 1))));
		//ll tmin = std::min(R[l_l - 1], std::min(R[i - 1] - R[l_l - 1], std::min(R[rl - 1] - R[i - 1], R[N - 1] - R[rl - 1])));
		min = std::min(min, tmax - tmin);
	}

	cout << min << endl;
	return 0;
}

Measured memory_bytes: 3328
def shift(numbers) -> int:
    count = 0
    processed_numbers = numbers
    while(all([x % 2 == 0 for x in processed_numbers])):
        count += 1
        processed_numbers = [x // 2 for x in processed_numbers]
    return count

input()  # 捨てる
numbers = list(map(int, input().split()))
print(shift(numbers))


Measured memory_bytes: 3060
#include <stdio.h>

int main(void){
 int x,a,b,cake,cake1;
  
  scanf("%d",&x);
  scanf("%d",&a);
  scanf("%d",&b);
  
   cake = x - a;
   cake1 = cake % b;
  
  printf("%d\n" ,cake1);
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(void)
{
  char table[3][3];

  while(1) {
    cin >> table[0];
    if(table[0][0] == '0') break;
    for(int i = 1 ; i < 3 ; i++) {
      cin >> table[i];
    }
    
    if(table[0][0] == 'b' && table[0][1] == 'b' && table[0][2] == 'b') cout << 'b' << endl;
    else if(table[1][0] == 'b' && table[1][1] == 'b' && table[1][2] == 'b') cout << 'b' << endl;
    else if(table[2][0] == 'b' && table[2][1] == 'b' && table[2][2] == 'b') cout << 'b' << endl;
    else if(table[0][0] == 'b' && table[1][1] == 'b' && table[2][2] == 'b') cout << 'b' << endl;
    else if(table[2][0] == 'b' && table[1][1] == 'b' && table[0][2] == 'b') cout << 'b' << endl;
    else if(table[0][0] == 'b' && table[1][0] == 'b' && table[2][0] == 'b') cout << 'b' << endl;
    else if(table[0][1] == 'b' && table[1][1] == 'b' && table[2][1] == 'b') cout << 'b' << endl;
    else if(table[0][2] == 'b' && table[1][2] == 'b' && table[2][2] == 'b') cout << 'b' << endl;

    else if(table[0][0] == 'w' && table[0][1] == 'w' && table[0][2] == 'w') cout << 'w' << endl;
    else if(table[1][0] == 'w' && table[1][1] == 'w' && table[1][2] == 'w') cout << 'w' << endl;
    else if(table[2][0] == 'w' && table[2][1] == 'w' && table[2][2] == 'w') cout << 'w' << endl;
    else if(table[0][0] == 'w' && table[1][1] == 'w' && table[2][2] == 'w') cout << 'w' << endl;
    else if(table[2][0] == 'w' && table[1][1] == 'w' && table[0][2] == 'w') cout << 'w' << endl;
    else if(table[0][0] == 'w' && table[1][0] == 'w' && table[2][0] == 'w') cout << 'w' << endl;
    else if(table[0][0] == 'w' && table[1][1] == 'w' && table[2][1] == 'w') cout << 'w' << endl;
    else if(table[0][2] == 'w' && table[1][2] == 'w' && table[2][2] == 'w') cout << 'w' << endl;

    else cout << "NA" << endl;
  } 
  return 0;
}

Measured memory_bytes: 0
w = input()
N = int(input())

for i in range(N):
    ilist = input().split()
    a = int(ilist[1])
    b = int(ilist[2])

    if ilist[0] == 'print':
        print(w[a:b+1])
    elif ilist[0] == 'reverse':
        w = w[:a] + w[a:b+1][::-1] + w[b+1:]
    else:
        w = w[:a] + ilist[3] + w[b+1:]



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

int main() {
    int n;
    cin >> n;
    map<string, int> s;
    for (int i = 0; i < n; ++i) {
        string a;
        cin >> a;
        s[a]++;
    }
    int m;
    cin >> m;
    map<string, int> t;
    for (int i = 0; i < m; ++i) {
        string a;
        cin >> a;
        t[a]++;
    }
    int ans = -1001001001;
    for (pair<string, int> p : s) ans = max(ans, p.second - t[p.first]);
    cout << max(ans, 0) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA
//long*long<0で判定するな
//開区間と閉区間
//アルファベットが何番目かは x=s[i]-'a'
//bfsはmain()内で　rep(i,h)rep(j,w)rep(i,4)でバグ
//切り上げ：(a+(b-1))/b
//32bit以上は 1ull<<j]
// map 初期値0 for(auto itr=mp.begin();itr!=mp.end();++itr) itr->fi itr->se で全探索
// for(auto u:mp) u.fi u.se も可能
//n個のgcd,lcmは一つずつみて更新していく
const ll MOD = 1000000007;

int main(){
    char c; cin >> c;
    c++;
    cout << c<<endl;
}


Measured memory_bytes: 256
str=gets.chomp
n=gets.to_i
n.times do
    cmd = gets.chomp.split(" ")
    if cmd[0]=="print"
        puts str[cmd[1].to_i..cmd[2].to_i]
    elsif cmd[0]=="reverse"
        str[cmd[1].to_i..cmd[2].to_i]=str[cmd[1].to_i..cmd[2].to_i].reverse
    elsif cmd[0]=="replace"
        str[cmd[1].to_i..cmd[2].to_i]=cmd[3]
    end
end


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

int main(){
char a[3][3];
cin>>a[0][0]>>a[0][1]>>a[0][2];
cin>>a[1][0]>>a[1][1]>>a[1][2];
cin>>a[2][0]>>a[2][1]>>a[2][2];
  
cout<<a[0][0]<<a[1][1]<<a[2][2]<<endl;
}

Measured memory_bytes: 256
// ConsoleApplication2.cpp : アプリケーションのエントリ ポイントを定義します。
//

//#include"stdafx.h"
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
int main() {
	
	int r;
	cin >> r;
	cout << r * r << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define sz size()
#define all(s) s.begin(), s.end()
#define mkp make_pair
#define pb push_back


using namespace std;

const int mod = 1e9 + 7;
const int maxn = 2e5 + 12;

int h[maxn];
int a, b, n;

void Speed() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

bool check(int x) {
    int cnt = 0;
    for (int i = 1; i <= n; ++ i) {
        int cur = h[i] - b * x;
        if (cur > 0) {
            if (cur % (a - b))
                cnt += cur / (a - b) + 1;
            else
                cnt += cur / (a - b);
        }
    }
    return (cnt <= x);
}

void solve() {
    cin >> n >> a >> b;
    for (int i = 1; i <= n; ++ i) {
        cin >> h[i];
    }
    int l = 0;
    int r = mod;
    while(r - l > 1) {
        int mid = (l + r) / 2;
        if (check(mid))
            r = mid;
        else
            l = mid;
    }
    cout << r << '\n';
}

main() {
    Speed();
    solve();
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(void){

    int n, d;
    cin >> n >> d;
    
    vector<vector<int>> data(n);
    for(int i=0; i<n; i++) {
        vector<int> temp(d);
        for(int j=0; j<d; j++) {
            cin >> temp[j];
        }
        data[i] = temp;
    }    

    int result = 0;
    for(int i=0; i<n; i++) {
        for(int j=i+1; j<n; j++) {
            if(i!=j) {
                int sum = 0;
                for(int k=0; k<d; k++) {
                    sum += (data[i][k]-data[j][k]) * (data[i][k]-data[j][k]);
                }
                for(int k=0; k<=127; k++) {
                    if(k*k==sum) {
                        result++;
                        break;
                    }
                }
            }
        }
    }

    cout << result << endl;

    return 0;    
}


Measured memory_bytes: 256
Sp = gets.chomp.split('')
LS = Sp.length
T = gets.chomp.split('')
LT = T.length

cand = []

(0..(LS - LT)).each do |i|
    success = true
    s = Sp.dup
    LT.times do |j|
        unless T[j] == Sp[i + j] || Sp[i + j] == '?'
            success = false
            break
        end
        s[i + j] = T[j]
    end
    if success
        cand.push(s)
    end
end

if cand.length == 0
    print 'UNRESTORABLE'
else
    print cand.map{|arr| arr.join.gsub('?', 'a')}.min
end

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

int main(void){
  int N;
  cin >> N;
  
  int a[N];
  for( int i=0 ; i < N ; i++ ){
    cin >> a[i];
    }
  int w;
  for( int i=0 ; i<N-1 ; i++ ){
    for( int j=i+1 ; j<N ; j++ ){
      if( a[i] < a[j] ){
        w = a[i];
        a[i] = a[j];
        a[j] = w;
      }
    }
  }
  int h = 0, l = 0;
  for( int i=0 ; i<N ; i++ ){
    if( i%2 == 0 ){
    	h = h + a[i];
    }
    else{
    	l = l + a[i];
    }
  }
  cout << h-l << endl;
}

Measured memory_bytes: 3616
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        List<Integer> dRew=new ArrayList<Integer>();
        List<Integer> dRns=new ArrayList<Integer>();
        List<Integer> d2Rew=new ArrayList<Integer>();
        List<Integer> d2Rns=new ArrayList<Integer>();
        Integer tmpD=0;
        int comN,com1,com2;
        int[] diceN=new int[6];
        
        for(int i=0; i<6; i++)
            diceN[i]=scan.nextInt();
        
        dRns.add(diceN[4]);
        dRns.add(diceN[1]);
        dRew.add(diceN[3]);
        dRew.add(diceN[0]);
        dRew.add(diceN[2]);
        dRew.add(diceN[5]);
        
        for(int i=0; i<6; i++)
            diceN[i]=scan.nextInt();
        
        d2Rns.add(diceN[4]);
        d2Rns.add(diceN[1]);
        d2Rew.add(diceN[3]);
        d2Rew.add(diceN[0]);
        d2Rew.add(diceN[2]);
        d2Rew.add(diceN[5]);
        
        //System.out.println(dRew+"1:"+dRns);
        //System.out.println(d2Rew+"2:"+d2Rns);
         String command="EEEENEEENEEESEEESEEENEEE";
        for(int i=0; i<command.length(); i++){
            switch(command.substring(i,i+1)){
                case "E":
                    tmpD=dRew.remove(3);
                    dRew.add(0,tmpD);
                break;
                case "W":
                    tmpD=dRew.remove(0);
                    dRew.add(tmpD);
                break;
                case "S":
                    tmpD=dRns.get(0);
                    dRns.set(0,dRew.get(3));
                    dRew.set(3,dRns.get(1));
                    dRns.set(1,dRew.get(1));
                    dRew.set(1,tmpD);
                break;
                case "N":
                    tmpD=dRns.get(0);
                    dRns.set(0,dRew.get(1));
                    dRew.set(1,dRns.get(1));
                    dRns.set(1,dRew.get(3));
                    dRew.set(3,tmpD);
                break;
            }
          //  System.out.println(dRew+":"+dRns);
            if(dRew.equals(d2Rew)&&dRns.equals(d2Rns)){
                System.out.println("Yes");
                return;
            }
        }
        //System.out.println(dRew.get(1));
        
            System.out.println("No");
    }
}


Measured memory_bytes: 26304
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const long long MOD = 1000000000 + 7;//1000000000 + 7 998244353 924844033 1000000000 + 9;
constexpr long long INF = 1LL << 60;//numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourth; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
struct Edge { LL to, cost; };
struct edge {
	LL from, to, cost;
};
vector<vector<LL>>g,rev;
vector<edge>ed;
vector<Pll>pv;
set<LL>st;
map<Pll, LL>ma;
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
string str, ss;
bool f[100];
LL n, m, s, t, h, w, k, q, p, ans, sum, cnt, a[200000], b[200000];
int main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
	}
	vector<LL>v;
	rep(i, n) {
		LL mx = -1;
		cnt = 0;
		rep(j, n) {
			if (f[j]==0) {
				cnt++;
				if (cnt == a[j])
					mx = max(mx,j);
			}
		}
		if (mx != -1) {
			f[mx] = 1;
			v.push_back(a[mx]);
		}
	}
	if (v.size() == n) {
		Rrep(i, v.size()) {
			cout << v[i] << endl;
		}
	}
	else {
		cout << -1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

int main()
{
  int h,w,k;
  cin>>h>>w>>k;
  vector<string> c(h);
  for (int i = 0; i < h; ++i)
  {
    cin>>c[i];
  }
  int ans=0;
  for (int i = 0; i < (1<<h); ++i)
  {
    for (int j = 0; j < (1<<w); ++j)
    {
      int cnt=0;
      for (int x = 0; x < h; ++x)
      {
        for (int y = 0; y < w; ++y)
        {
          if(i>>x&1) continue;
          if(j>>y&1) continue;
          if(c[x][y]=='#') cnt++;
        }
      }
      if(cnt==k) ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3624
import java.util.Scanner;

class Main
{
   public static void main(String[] args)
   {
      Scanner stdIn = new Scanner(System.in);
      int a = stdIn.nextInt();
      int b = stdIn.nextInt();
      int c = stdIn.nextInt();
   	if (a<b){
   		if (b<c){
   			System.out.println("Yes");
   		}
   		else if (b>c){
   			System.out.println("No");
   		}
   	}
   	else {
   		System.out.println("No");
   	}
   }
}

Measured memory_bytes: 26144
#include <iostream>
#include <stdio.h>
#include <string> 
#include <cctype>
#include <stdlib.h>
int main()
{
	std::string input;
	while(std::getline(std::cin, input))
	{
	    if(input=="0") break;
	    int sum=0;
	    for (int i = 0; i < input.length(); i++)
	    {
	    	char c = input[i];
		    std::string str = std::string() +c;
	    	sum += atoi(str.c_str());
    	}
    	std::cout<<sum<<std::endl;
	}
}


Measured memory_bytes: 3172
n=int(input())
M=[list(map(int,input().split()))for _ in[0]*n]
d=[0]+[1e4]*n
b=[1]*n
a=0
while 1:
 u=-1
 for i in range(n):
  if b[i]and(u<0 or d[i]<d[u]):u=i
 if u<0:break
 b[u]=0
 a+=d[u]
 for v in range(n):
  t=M[u][v]
  if t+1 and d[v]>t:d[v]=t
print(a)


Measured memory_bytes: 5904
#include<iostream>
#include <bits/stdc++.h>
#include<stdio.h>
#include <stdlib.h>
#include<string>
#include<queue>
#include<algorithm>
#include<math.h>

using namespace std;

int main(){
	long long int N,M,X[100000];
	long long int ans=0;
	long long int nokosi;
	priority_queue<long long int> x;
	priority_queue<long long int> y;
	cin>>N>>M;

	for(int i=0;i<M;i++){
		cin>>X[i];
		x.push(X[i]);
	}
	if(N>=M){
		cout<<ans<<endl;
		return 0;
	}
	while(x.size()>=2){
		nokosi=x.top();
		x.pop();
		y.push(nokosi-x.top());
	}
	for(int i=0;i<N-1;i++){
		y.pop();
	}

			while(!y.empty()){
			ans+=y.top();
			y.pop();
		
	}


	cout<<ans<<endl;
}

Measured memory_bytes: 3316
# -*- coding: utf-8 -*-
import collections
import itertools


def main():
    n = int(input())
    a_i = tuple(map(int, input().split()))

    count_item = {}
    all_cnt = 0
    for items in collections.Counter(a_i).items():
        if items[1] >= 2:
            now_cnt = int(items[1] * (items[1] - 1) / 2)
            pre_cnt = now_cnt - items[1] + 1
            count_item[items[0]] = (now_cnt, pre_cnt)
            all_cnt += now_cnt
        else:
            count_item[items[0]] = (0, 0)

    for k in a_i:
        items = count_item[k]
        print(all_cnt - (items[0] - items[1]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 33052
/*数组有没有开小
有没有开long long
会不会爆long long
初始化（多组数据，一定要记得把数组清零！！！）
时刻小心数组/容器是否为空
最后容器中剩余是否需要加入答案 
位运算结果的数组，要开2倍。位运算时注意结果的范围可能大于两个数的范围
要考虑边界情况(n=0?n=1?n=最大值?) 
注意变量名(尤其注意:n,n2 i,j)
开bool时注意取值不能为0~2
*/
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pii pair<int,int>
#define pb push_back
#define r1 rt<<1
#define r2 rt<<1|1
#define fi first
#define se second
#define ri register int
#define rep(i,a,b) for(ri i=(a);i<=(b);++i)
#define rep2(i,a,b,c) for(ri i=(a);i<=(b);i+=(c))
#define REP(i,a,b) for(ri i=(a);i>=(b);--i)
#define REP2(i,a,b,c) for(ri i=(a);i>=(b);i-=(c))
using namespace std;

inline ll read(){
	ll x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^'0'),c=getchar();
	return x*f;
}
inline void write(ll x){
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10+'0');
}

const int N=1e5+5;
struct edg{
	int nxt,to,i;
}e[N<<1];
int head[N],cnt,du[N],ans[N],n;
map<pii,bool>ma;
inline void add(ri u,ri v,ri i){e[++cnt]=(edg){head[u],v,i};head[u]=cnt;}
inline void dfs(ri u,ri fa){
	ri lst=1,v;
	for(ri i=head[u];i;i=e[i].nxt){
		v=e[i].to;if(v==fa)continue;
		while(ma[mp(u,lst)])++lst;
		ans[e[i].i]=lst;
		ma[mp(u,lst)]=1;ma[mp(v,lst)]=1;
		dfs(v,u);
	}
}

int main()
{
	n=read();
	rep(i,1,n-1){
		ri u=read(),v=read();
		add(u,v,i);add(v,u,i);
		++du[u];++du[v];
	}
	ri mx=0;
	rep(i,1,n)mx=max(mx,du[i]);
	printf("%d\n",mx);
	dfs(1,0);
	rep(i,1,n-1)printf("%d\n",ans[i]);
	return 0; 
}

Measured memory_bytes: 16384
#include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
     
    using namespace std;
    using namespace __gnu_pbds;
     
    void debug_out() { cerr << endl; }
    template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
    template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
    template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
    template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
    template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
    template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}
     
    #define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
    #define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
    #define dbg_ok cerr<<"OK!\n"
    #define  st first
    #define  nd second
    #define int long long  
     
    template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
     
    typedef cc_hash_table<int, int, hash<int > > ht;
     
    const int  M    = 998244353;
    const int  MAXN = 10005 ;
    const int   INF  = 0x3F3F3F3F  ; // long long inf
    const long double eps = 1.084202e-19;


    int32_t main(){
         ios_base::sync_with_stdio(false);
         cin.tie(NULL);
        int a , b , c , d ; 
        cin >> a >> b >> c >> d ; 
        int x = 1 ;
        bool ok = true; 
        while(1){
            if(x==0){
                 a-=d;
                 if(a<=0){
                     ok = false;
                     break;
                 }
            }
            else{
                c-=b;
                if(c<=0){
                    break;
                }
            }
            x^=1;
        }
        if(ok){
            cout<<"Yes";
        }
        else{
            cout<<"No";
        }
        
       
    }

Measured memory_bytes: 3640
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i = 0; i < (n); ++i )
#define rep_rev(n,i) for(ll i = n; i >= 0; --i )
using namespace std;
using P = pair<int, int>;
const long long INF = 1LL << 60;

int main(){
  int N,A,B,ans = 0; cin >> N >> A >> B;
  for(int i = 1; i <= N; ++i){
    int sum = 0,digit = log10(i), tmp = i;
    for(int j = 0; j <= digit; ++j){
      int b = pow(10,j+1);
      int c = pow(10,j);
      int a = (tmp%b)/c;
      sum += a;
      tmp -= (a*c);
    }
    if(sum >= A && sum <= B) ans += i;

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


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const ll INF = 1e18;
int main(){
  ll N; cin >> N;
  vector<ll> sum(N+1,0);
  REP(i,N) {
    ll a; cin >> a;
    sum[i+1] = sum[i] + a;
  }

  //a[l]...a[r]を総和の差の絶対値が最小となるよう2分割する
  //sum_max, sum_minに総和の最大値，最小値を返す
  auto divide_array = [&](ll l, ll r, ll& sum_max, ll& sum_min){
    ll T = sum[r] - sum[l-1];
    auto it = upper_bound(sum.begin()+l, sum.begin()+r+1,T/2+sum[l-1]);
    REP(i,2){
      ll U = *it - sum[l-1];
      chmin(sum_max, max(U, T - U));
      chmax(sum_min, min(U, T - U));
      if(it != sum.begin()+l)it--;
    }
  };

  ll ans = 1e18;
  FOR(b,2,N-1){
    vector<ll> p(4,0);
    p[0] = INF, p[2] = INF;
    divide_array(1,b, p[0], p[1]);
    divide_array(b+1,N, p[2],p[3]);
    sort(ALL(p));
    chmin(ans, p[3]-p[0]);
  }
  cout << ans << endl;
}

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

typedef pair<int,int> P;
typedef pair<P,int> PP;
typedef pair<PP,int> PPP;
int L;
map<PPP, int> dp;
vector<int> e;

int solve(int prev2, int prev1, int prev0, int now){
	int res = 0;
	if( now == L ) return prev0;
	PPP t = PPP(PP(P(prev2,prev1),prev0),now);
	if( dp.count(t) ) return dp[t];
	if( prev0 ){
		res = max( res , solve(0,prev0-1,e[now]+prev1,now+1) );
	}
	res = max( res , solve(prev1,prev0,e[now],now+1) );
	return dp[t] = res;
}

int main(){
	int T;
	cin >> T;
	for(int t_ = 0 ; t_ < T ; t_++ ){
		cin >> L;
		e = vector<int>(L);
		for(int i=0 ; i < L ; i++ ){
			cin >> e[i];
		}
		dp.clear();
		int ans = solve(0,0,0,0);
		cout << ans << endl;
	}
}

Measured memory_bytes: 5108
package main
import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)

func Solve() {
  var N, d int
  NextInt(&N)
  ans := 0
  for k := 1; k <= N; k++ {
    d = N / k
    if d > 1 {
      ans += k * d * (d + 1) / 2
    } else {
      ans += (N - k) * (N - k + 1) / 2 + k * (N - k + 1)
      break
    }
  }
  Write(ans)
}

func main() {
  Solve()
  Output()
}

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntSlice(A *[]int) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatSlice(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(S ...interface{}) {
  fmt.Fprintln(writer, S...)
}
func WriteIntSlice(A []int) {
  B := make([]interface{}, len(A))
  for i, a := range A { B[i] = a }
  Write(B...)
}
func Output() {
  _ = writer.Flush()
}
func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}
func AbsInt(x int) int {
  if x < 0 { x = -x }
  return x
}

Measured memory_bytes: 1844
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

long long int INF = 1e18;
long long int mod = 1000000007;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "RULD";
//↓,→,↑,←

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl

ll rui(ll number1,ll number2){
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
    if(number1 > number2){
        swap(number1 , number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1 , number1);
    }
}

ll i,j,k,ii,jj,n,m,a,b,c,d,e,f,g,h,r,w,l;
ll num,ans,sum,ok,ng;
ll x[500005],y[500005],z[500005];
ll dp[500][500];
char s[500005],t[500005],u[500005];
bool dame,flag;

int main(){
	cin >> n;
	for(i=1;i<=n;i++){
		cin >> x[i];
	}
	for(i=1;i<=n;i++){
		y[i] += y[i-1] + x[i];;
	}
	for(j=1;j<=n;j++){
		for(i=1;i<=n-j+1;i++){
			if(j == 1){
				dp[i][j] = 0;
			}else{
				dp[i][j] = INF;
				for(k=1;k<j;k++){
					dp[i][j] = min(dp[i][j],dp[i][k] + dp[i+k][j-k] + y[i+j-1] - y[i-1]);
				}
			}
		}
	}
	for(j=1;j<=n;j++){
		for(i=1;i<=n+1-j;i++){
			//pe(dp[i][j]);
		}
		//el;
	}
	p(dp[1][n]);
	return 0;
}

Measured memory_bytes: 31360
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int  r[1000];
int top;


void push(int x){
	top++;
	r[top]=x;
}

int pop(){
	top--;
	return r[top+1];
}
	
int main(void){
  int x,y;
  int top=0;
  char s[1000];
  while( scanf("%s", s) != EOF )
  {
    if ( s[0] == '+' ){
		x=pop();
		y=pop();
		push(x+y);
    } 
    else if ( s[0] == '-' )
    {
		x=pop();
		y=pop();
		push(y-x);
    }
    else if ( s[0] == '*' )
    {
		x=pop();
		y=pop();
		push(x*y);
    } 
    else
    {
      push(atoi(s));
    }
  }
   printf("%d\n", pop());
     
   return 0;
}


Measured memory_bytes: 2036
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;


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

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


}


Measured memory_bytes: 256
#pragma region
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
#define rep(i, a, n) for (long long i = a; i <= n; ++i)
#define per(i, a, n) for (long long i = n; i >= a; --i)
#define IO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
/*
 *                                                     __----~~~~~~~~~~~------___
 *                                    .  .   ~~//====......          __--~ ~~
 *                    -.            \_|//     |||\\  ~~~~~~::::... /~
 *                 ___-==_       _-~o~  \/    |||  \\            _/~~-
 *         __---~~~.==~||\=_    -_--~/_-~|-   |\\   \\        _/~
 *     _-~~     .=~    |  \\-_    '-~7  /-   /  ||    \      /
 *   .~       .~       |   \\ -_    /  /-   /   ||      \   /
 *  /  ____  /         |     \\ ~-_/  /|- _/   .||       \ /
 *  |~~    ~~|--~~~~--_ \     ~==-/   | \~--===~~        .\
 *           '         ~-|      /|    |-~\~~       __--~~
 *                       |-~~-_/ |    |   ~\_   _-~            /\
 *                            /  \     \__   \/~                \__
 *                        _--~ _/ | .-~~____--~-/                  ~~==.
 *                       ((->/~   '.|||' -_|    ~~-/ ,              . _||
 *                                  -_     ~\      ~~---l__i__i__i--~~_/
 *                                  _-~-__   ~)  \--______________--~~
 *                                //.-~~~-~_--~- |-------~~~~~~~~
 *                                       //.-~~~--\
 *                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 */
#pragma endregion
const int maxn = 105;
bool dp[int(1e7 + 5)][2];
int n, k, a[maxn];
bool dfs(int x, bool f) {
    if (dp[x][f]) return dp[x][f];
    bool flag = 0;
    rep(i, 1, n) if (x >= a[i]) {
        if (!dfs(x - a[i], 1 - f))
            flag = 1;
    }
    return dp[x][f] = flag;
}
int main() {
    IO;
    cin >> n >> k;
    rep(i, 1, n) cin >> a[i];
    cout << (dfs(k, 0) ? "First\n" : "Second\n");
}

Measured memory_bytes: 11616
#include <iostream>
#include <math.h>
using namespace std;
int main() {
	long a, save_a;
	int b[9], c[9], wa;
	wa = 0;
	cin >> a;
	save_a = a;
	for (int i = 0;i < 9;i++) { /*各桁の数字を求め、waに加算*/
		c[i] = 100000000 / pow(10,i);
		b[i] = a / c[i];
		a = a - c[i] * b[i];
		wa = wa + b[i];
	}
	if (save_a%wa == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

}

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

using namespace std;

#define int long long
#define endl '\n'
#define maxn 100010
const int MOD = 1000000007;

struct Matrix {
    vector<vector<int> > mat;
    int n_rows, n_cols;

    Matrix(vector<vector<int> > values) : mat(values), n_rows(values.size()), n_cols(values[0].size()) {}

    static Matrix identity_matrix(int n) {
        vector<vector<int> > values(n, vector<int>(n, 0));
        for (int i = 0; i < n; i++)
            values[i][i] = 1;
        return values;
    }

    Matrix operator*(const Matrix &other) const {
        int n = n_rows, m = other.n_cols;
        vector<vector<int> > result(n_rows, vector<int>(m, 0));
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++) {
                for (int k = 0; k < n_cols; k++) {
                    result[i][j] = (result[i][j] + mat[i][k] * 1ll * other.mat[k][j]) % MOD;
                }
            }
        return Matrix(result);
    }

    inline bool is_square() const { return n_rows == n_cols; }
};

Matrix fast_exponentiation(Matrix m, int power) {
    assert(m.is_square());
    Matrix result = Matrix::identity_matrix(m.n_rows);
    while (power) {
        if (power & 1)
            result = result * m;
        m = m * m;
        power >>= 1;
    }
    return result;
}


void solve() {
    int n, k;
    cin >> n >> k;

    vector<vector<int>> v = vector<vector<int>>(n, vector<int>(n));
    for (int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++)cin >> v[i][j];
    }
    Matrix a(v);
    Matrix res = fast_exponentiation(a, k);
    int ans = 0;
    for (int i = 0; i < n; i++)for (int j = 0; j < n; j++)(ans += res.mat[i][j]) %= MOD;
    cout << ans << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 3740
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif
#define FILE_IO freopen("input.txt","r",stdin);
#define f first
#define int long long
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
const int MOD=1e9+7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename T>void print(T t){for(auto &it:t)cout<<it<<" ";}
inline int powerexp(int a,int b,int m){int res=1;while(b){if(b&1)res=res*a%m;a=a*a%m,b>>=1;}return res%m;}
inline int modinv(int a){return powerexp(a,MOD-2,MOD);}
inline int lcm(int a,int b){int g=__gcd(a,b);return a/g*b;}
void solve(){
    int n,x;
    cin>>n>>x;
    vector<int> l(n);
    for(auto& it:l)cin>>it;
    int ans=1;
    int d=0;
    for(auto it:l){
        d+=it;
        ans+=(d<=x);
    }
   cout<<ans<<endl;
}
//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
    IOS;
    solve();
    #ifdef LOCAL_DEFINE
    cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
    #endif
}


Measured memory_bytes: 256
N, W = map(int, input().split())
L = [[] for _ in range(4)]
wv = [tuple(map(int, input().split())) for _ in range(N)]
w0 = wv[0][0]

for w, v in wv:
    L[w-w0].append(v)

for i in range(4):
    L[i].sort(reverse=True)

acc = [[0] for _ in range(4)]

for i in range(4):
    for j in range(len(L[i])):
        acc[i].append(acc[i][-1]+L[i][j])

ans = 0

for i in range(len(L[0])+1):
    for j in range(len(L[1])+1):
        for k in range(len(L[2])+1):
            for l in range(len(L[3])+1):
                if w0*i+(w0+1)*j+(w0+2)*k+(w0+3)*l<=W:
                    ans = max(ans, acc[0][i]+acc[1][j]+acc[2][k]+acc[3][l])

print(ans)

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

using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define endl '\n'
#define snd second
#define fst first
#define fastio cin.tie(NULL),cout.sync_with_stdio(true)

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <ll,int> ii;
typedef pair <ii,int> iii;

const int mod = 1e9 + 7;
const int N = 200005;

int f[N];

void solve(){
	int n;
	cin >> n;
	for(int i = 0; i < n-1; i++){
		int x; cin >> x;
		f[x]++;
	}
	for(int i = 1; i <= n; i++)cout << f[i] << endl;
}

int main(){
	fastio;
	int t = 1;
	//cin >> t;
	while(t--)
		solve();
	return 0;
}


Measured memory_bytes: 4360
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<62;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
    int n,m;
    int ans=0;
    scanf("%d %d",&n,&m);
    ans=(m*(m-1)/2);
    ans+=(n*(n-1)/2);


    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<string,vector<int>> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int N; cin>>N;
	string init=string(N,' ');
	vector<int> idx;
	for (int i=0; i<N; i++)
		idx.push_back(i);

	set<ii> st,st2; st.insert({init,idx});
	char ch='a';
	set<ii> done;
	while(!st.empty()) {
		for (const auto &x : st)
			if(x.second.empty())
				done.insert(x);
		for (const auto &x : done)
			st.erase(x);
		for (const auto &x : st) {
			string cur=x.first;
			vector<int> idx=x.second;
			cur[idx[0]]=ch;
			idx.erase(idx.begin());
			int sz=idx.size();
			for (int bt=0; bt<(1<<sz); bt++) {
				string nxt=cur;
				set<int> tmp(idx.begin(),idx.end());
				for (int i=0; i<sz; i++)
					if((bt&(1<<i)))
						nxt[idx[i]]=ch, tmp.erase(idx[i]);
				vector<int> rem(tmp.begin(),tmp.end());
				st2.insert({nxt,rem});
			}
		}
		st=st2;
		st2.clear();
		ch++;
	}

	for (const auto &x : done)
		cout<<x.first<<"\n";
	return 0;
}

Measured memory_bytes: 24064