akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>



int main( void )
{
	int N ;

	while( 1 )
	{
		scanf( "%d" ,&N ) ;

		if( N == 0 )
		{
			return 0 ;
		}

		int p = 0 ;

		int maxy = 0 ;

		char RBY[ 10000 + 2 ] = { 0 } ;
		char color[ 10000 + 2 ] = { 0 } ;

		
		int rby[ 10000 + 2 ] = { 0 } ;

		int i ,j ;
		for( i = 1 ; i <= N ; ++i )
		{
			scanf( "%*c%c" ,color + i ) ;
		}

		for( i = 1 ; i <= N ; ++i )
		{
			if( color[ i ] == color[ i - 1 ] || color[ i ] == color[ i + 1 ] )
			{
				if( color[ i ] != RBY[ p ] )
				{
					++p ;
				}

				++rby[ p ] ;
			}

			else
			{
				++p ;

				if( rby[ p ] == 0 )
				{
					rby[ p ] = 1 ;
				}
			}

			RBY[ p ] = color[ i ] ;
		}

		for( i = 1 ; i <= p ; ++i )
		{
			int next ;
			int prev ;

			int kale = 0 ;

			if( rby[ i ] == 1 && i % p > 1 )
			{
				for( j = 1 ; ; ++j )
				{
					next = i + j ;
					prev = i - j ;

					if( prev < 1 || next > p )
					{
						break ;
					}

					if( RBY[ prev ] == RBY[ next ] && rby[ prev ] + rby[ next ] > 3 )
					{
						kale += rby[ prev ] + rby[ next ] ;
					}

					else if( kale > 0 )
					{
						maxy = maxy < kale + rby[ i ] ? kale + rby[ i ] : maxy ;

						break ;
					}
				}
			}

			else if( rby[ i ] > 2 )
			{
				if( i % p < 2 )
				{
					maxy = maxy < rby[ i ] + 1 ? rby[ i ] + 1 : maxy ;
				}


				else
				{
					prev = i - 1 ;
					next = i + 1 ;

					for( j = 1 ; ; ++j )
					{
						if( j == 1 )
						{
							if( RBY[ prev ] == RBY[ next ] && rby[ prev ] + rby[ next ] > 3 )
							{
								kale += rby[ i ] + rby[ prev ] + rby[ next ] ;

								++next ;
								--prev ;
							}

							else
							{
								break ;
							}
						}

						else if( RBY[ prev ] == RBY[ next ] && rby[ prev ] + rby[ next ] > 3 )
						{
							kale += rby[ prev ] + rby[ next ] ;

							++next ;
							--prev ;
						}

						else
						{
							maxy = maxy < kale ? kale : maxy ;

							break ;
						}
					}
				}
			}
		}

		printf( "%d\n" ,N - maxy ) ;
	}
}

Measured memory_bytes: 1852
//
//  CGL_5_A.cpp
//  AizuOnlineJudge
//
//  Created by jiji on 2020/01/11.
//  Copyright © 2020 jiji4000. All rights reserved.
//
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iostream>
using namespace std;

struct Point {
    double x, y;
};

bool cmpX(Point a, Point b){
    return a.x < b.x;
}

bool cmpY(Point a, Point b){
    return a.y < b.y;
}

double getDistance(Point a,Point b){
    double x = b.x - a.x;
    double y = b.y - a.y;
    return sqrt(x*x + y*y);
}

double closestPair(Point *a, int n){
    if (n == 1)  return __DBL_MAX__;
    double d = __DBL_MAX__;
    int m = n/2;
    d = min(closestPair(a,m), closestPair(a + m,n - m));
    
    double mx = a[m].x;
    vector<Point> b;
    for (int i = m;i >= 0;--i){
        double x = fabs(a[i].x - mx);
        if (x > d){
            break;
        }
        else{
            b.push_back(a[i]);
        }
    }
    for (int i = m + 1;i < n;++i){
        if (fabs(a[i].x - mx) > d){
            break;
        }
        else {
            b.push_back(a[i]);
        }
    }
    sort(b.begin(), b.end(), cmpY);
    
    for(int i = 0; i < b.size();++i){
        for(int j = i + 1;fabs(b[j].y - b[i].y) < d && j < b.size(); ++j){
            double tmp = getDistance(b[i], b[j]);
            if (tmp < d) d = tmp;
        }
    }
    return d;
}

int main(){
    int n;
    scanf("%d", &n);
    Point a[n];
    for (int i = 0; i < n; ++i){
        scanf("%lg %lf", &a[i].x, &a[i].y);
    }
    sort(a,a+n,cmpX);
    printf("%7f", closestPair(a, n));
}



Measured memory_bytes: 7472
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>

#define STARTUP {(cin.tie(0));\
 (ios::sync_with_stdio(false));}

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define MAX(list) std::max(list)
#define MIN(list) std::min(list)
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())
#define VECCIN(vec) const int size = (vec).size(); REP(i,size) cin>>(vec)[i];

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

using ll = long long;
using namespace std;
ll mod = 1'000'000'007;

const int INF = 1'050'000'000;

int main() {
    STARTUP;

    int N, K;
    cin >> N >> K;
    vector<int>X(N);
    VECCIN(X);

    int ans = 0;
    REP(i, N) {
        ans += min(X[i], abs(X[i] - K)) * 2;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    int N, M;
    std::cin >> N >> M;
    std::vector<int> city(M), prefec(M);
    for(int i = 0; i < M; i++){
        std::cin >> prefec[i] >> city[i];
    }

    // val[n] := P[i] = nなiについてY[i]を集める
    std::vector<std::vector<int>> vals(N + 1);
    for(int i = 0; i < M; i++){
        vals[prefec[i]].push_back(city[i]);
    }
    for(int v = 1; v <= N; v++){
        std::sort(vals[v].begin(), vals[v].end());
        // 重複要素を削除
        vals[v].erase(std::unique(vals[v].begin(), vals[v].end()), vals[v].end());
    }

    // 出力
    for(int i = 0; i < M; i++){
        int v = prefec[i];
        printf("%06d", v);
        int id = std::lower_bound(vals[v].begin(), vals[v].end(), city[i]) - vals[v].begin();
        printf("%06d\n", id + 1);
    }

    return 0;
}

Measured memory_bytes: 7808
x1,y1,x2,y2 = map(int,input().split())


A=0

x3=x1+(x2-x1-y2+y1)
y3=y2+x2-x1
x4=x1-y2+y1
y4=y1+x2-x1

print(x3, y3, x4, y4)

Measured memory_bytes: 2940
/*
 * SimpleCalculator.cpp
 *
 *  Created on: 2014/07/21
 *      Author: WanWan1985
 */
#include <iostream>
#include <string>
#include <vector>
using namespace std;

typedef unsigned int u_int;
typedef struct {
	int a, b;
	string strOperant;
}DataSet;

int main(void) {

	vector<DataSet> vecDataSet;
	while(1) {
		DataSet data;
		int a, b;
		string op;
		cin >> a >> op >> b;
		if ("?" == op) {
			break;
		}
		data.a = a;
		data.strOperant = op;
		data.b = b;
		vecDataSet.push_back(data);
	}

	for (u_int i = 0; i < vecDataSet.size(); i++) {
		DataSet data = vecDataSet.at(i);

		if ("+" == data.strOperant) {
			cout << data.a + data.b << endl;
		} else if ("-" == data.strOperant) {
			cout << data.a - data.b << endl;
		} else if ("*" == data.strOperant) {
			cout << data.a * data.b << endl;
		} else {
			cout << data.a / data.b << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1216
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        // 標準入力からデータを読み込む準備
        Scanner sc = new Scanner(System.in);
        // 2つの文字の固まりをそれぞれ整数値と想定して読み込む
        int a = sc.nextInt(); int b = sc.nextInt();
        int area = a * b;
        int length = 2 * (a + b);
        System.out.println(area + " " + length);
        sc.close();
    }
    }


Measured memory_bytes: 26184
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> V;

int main() {
  ll a, b, x;
  cin >> a >> b >> x;
  ll cnt = 0;
  if (a%x == 0) cnt = 1;
  cnt += b/x;
  cnt -= a/x;
  dump(cnt);
  return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	static Scanner scanner;
	static int n;
    static int m;
    static int[] A;
    static int[] B;
	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    n=gi();
	    m=gi();
	    A=new int[m];
	    B=new int[m];

	    for (int i=0; i<m;i++) {
	    	A[i]=gi();
	    	B[i]=gi();
	    }
	    int c=0;
	    for(int i=0; i<m;i++) {
	    	List<Integer> l = new ArrayList<Integer>();
	    	l.add(A[i]);
	    	if(!f(i, l)) {
	    		c++;
	    	}
	    }
	    System.out.println(c);
//	    if (isNumber(s1) && isNumber(s2) && s.charAt(a) == '-') {
//	    	System.out.print("Yes");
//	    }else {
//	    	System.out.print("No");
//	    }



	}

    public static boolean f(int b, List<Integer> l) {
    	boolean g= false;
    	int ln=l.get(l.size()-1);
        for (int i=0; i<m; i++) {
        	if(i==b) continue;
        	if(ln==A[i] && !l.contains(B[i])) {
        		if(B[i]==B[b])return true;
        		List<Integer> l2 = new ArrayList<Integer>();
        		l2.addAll(l);
        		l2.add(B[i]);
        		g=f(b,l2);
        		if(g)return true;
        	} else if(ln== B[i] && !l.contains(A[i])) {
        		if(A[i]==B[b])return true;
        		List<Integer> l2 = new ArrayList<Integer>();
        		l2.addAll(l);
        		l2.add(A[i]);
        		g=f(b,l2);
        		if(g)return true;
        	}
        }

        return false;
    }

	public static int d(int n) {
		int m=0;
		while(true) {
			if(n<1) {
				break;
			}
			int l= n%10;
			m+=l;
			n= (n-l)/10;
		}
		return m;
	}
	public static long d(long n) {
		String a=String.valueOf(n);
		return (long)a.length();
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 67484
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
/* clang-format on */

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

  int h, w, sy, sx, gy, gx;
  deque<tuple<int, int, int>> p;
  set<pair<int, int>> passed;
  vector<pair<int, int>> d = {{0, -1}, {0, 1}, {-1, 0}, {1, 0}};
  cin >> h >> w >> sy >> sx >> gy >> gx;
  sy--, sx--, gy--, gx--;
  vector<string> m(h);
  vector<vector<int>> warp_map(h, vector<int>(w, INF));
  REP(i, h) { cin >> m[i]; }

  warp_map[sy][sx] = 0;
  p.push_front({sy, sx, 0});
  passed.insert({sy, sx});

  while (!p.empty()) {
    int y, x, warp;
    tie(y, x, warp) = p.front();
    p.pop_front();
    if (warp_map[y][x] < warp) continue;
    warp_map[y][x] = warp;

    //四方に歩いて探索
    for (auto [dy, dx] : d) {
      int cy = y + dy, cx = x + dx;
      if (0 <= cy && cy < h && 0 <= cx && cx < w && !passed.count({cy, cx}) &&
          m[cy][cx] == '.') {
        p.push_front({cy, cx, warp});
        passed.insert({cy, cx});
      }
    }

    // 5x5四方にワープして探索
    for (int dy = -2; dy <= 2; dy++) {
      for (int dx = -2; dx <= 2; dx++) {
        int cy = y + dy, cx = x + dx;
        if (0 <= cy && cy < h && 0 <= cx && cx < w && m[cy][cx] == '.' &&
            warp_map[cy][cx] > warp + 1)
          p.push_back({cy, cx, warp + 1});
      }
    }
  }

  cout << (warp_map[gy][gx] == INF ? -1 : warp_map[gy][gx]) << endl;
  return 0;
}


Measured memory_bytes: 31372
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<cstdint>
#include<bits/stdc++.h>
#include<queue>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mod 1000000007

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; }

using namespace std;
using uif=uint_fast64_t;
using ll=long long int;

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(void){

  ll n;
  cin>>n;
  vector<ll> a(3*n);
  vector<ll> diff(n+1,0);
  rep(i,3*n){
    cin>>a[i];
  }
  priority_queue<ll,vector<ll>,greater<ll>> f_q;
  priority_queue<ll,vector<ll>,less<ll>> l_q;
  ll f_total=0;
  ll l_total=0;
  rep(i,n){
    f_q.push(a[i]);
    f_total+=a[i];
  }
  for(ll i=3*n-1;i>=2*n;i--){
    l_q.push(a[i]);
    l_total+=a[i];
  }
  //ll min=f_total-l_total;
  diff[0]+=f_total;
  diff[n]-=l_total;

  //cout << f_q.top() << "," << l_q.top() << endl;

  rep(i,n){
    ll fp;
    ll lp;
    f_q.push(a[ n+i ]);
    fp=f_q.top();
    f_q.pop();
    f_total=f_total+a[n+i]-fp;
    //cout << "f_total:" << f_total << endl;

    l_q.push(a[ 2*n-1-i ]);
    lp=l_q.top();
    l_q.pop();
    l_total=l_total+a[2*n-1-i]-lp;
    //cout << "l_total:" << l_total << endl;

    diff[i+1]+=f_total;
    diff[n-1-i]-=l_total;
  }

  rep(i,n){
    //cout << diff[i] << ",";
  }
  //cout << endl;
  cout << *max_element(all(diff)) << endl;

  return 0;
}


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

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

    vector<int> Ass(N);

    for(int i = 0;i<N-1;i++){
        int c;
        cin >> c;
        c--;
        Ass.at(c)++;
    }

    for(int j = 0;j<N;j++){
        cout << Ass.at(j) << endl;
    }
}

Measured memory_bytes: 4052
#include<bits/stdc++.h>
#define re register
#define inc(i,j,k) for(re int i=j;i<=k;i++)
#define ll long long
using namespace std;
const int N=5005;
const int M=205;
inline int read(){
	int x=0;
	char ch=getchar();
	while(ch<'0'||ch>'9') ch=getchar();
	while('0'<=ch&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x;
} 
int n,m,b[M][N];
ll ans[N][N],a[N],anss;
void work(int x,int l,int r){
	if(l>r) return;
	int mx=l;
	inc(i,l+1,r) if(b[x][i]>b[x][mx]) mx=i;
	ans[l][mx]+=b[x][mx];
	ans[mx+1][mx]-=b[x][mx];
	ans[l][r+1]-=b[x][mx];
	ans[mx+1][r+1]+=b[x][mx];
	work(x,l,mx-1),work(x,mx+1,r);
}
int main(){
	n=read(),m=read();
	inc(i,2,n) a[i]=a[i-1]+read();
	inc(i,1,n) inc(j,1,m) b[j][i]=read();
	inc(i,1,m) work(i,1,n);  
	inc(l,1,n){
		inc(r,1,n){
			ans[l][r]+=ans[l-1][r]+ans[l][r-1]-ans[l-1][r-1];
			if(l>r) continue;
			anss=max(ans[l][r]-a[r]+a[l],anss);
		}
	}
	printf("%lld",anss);
}

Measured memory_bytes: 199936
from sys import stdin
from collections import deque

n = int(input())
deq = deque()
for i in range(n):
    q = list(stdin.readline().split())
    if q[0] == '0':
        deq.append(q[1])
    elif q[0] == '1':
        print(deq[int(q[1])])
    else:
        deq.pop()




Measured memory_bytes: 20256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

K = INT()

tmp = 7
ans = 1
p = 1
mo = tmp%K
checked = [0]*K
checked[mo] = 1
while mo != 0:
    mo = 10*mo + 7
    mo %= K
    p += 1
    if checked[mo]:
        print(-1)
        break
    checked[mo] = 1
else:
    print(p)


Measured memory_bytes: 17484
def M():return map(int,input().split())
d='URLD'
h,w,n=M()
b=[h,w,w,h]
r,c=M()
o=[h-r+1,c,w-c+1,r]
s=input()
t=[dict(zip(d,d[::-1]))[i] for i in input()]
a=0
for i,j in enumerate(d):
  x=o[i]
  for k in range(n):
    x+=(s[k]==j)
    if x>b[i]:a=1
    x-=(t[k]==j)*x>1
print('YNEOS'[a::2])

Measured memory_bytes: 63676
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,i,sum=0;
    cin>>n>>k;
    int p[n];
    for(i=0;i<n;i++){

    cin>>p[i];

}
sort(p,p+n);
for(i=0;i<k;i++){
sum+=p[i];
}
cout<<sum<<endl;
return 0;
}



Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

int main() {
	string S, T;
	cin >> S >> T;
	int count = 0;
	for (int i = 0; i < 3; i++) {
		if (S[i] == T[i]) count++;
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
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; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;
ll ans=0;
ll n;

void dfs(string s){
	if(s.size()>9)return;
	ll m=stol(s);
	if(m>n)return;
	map<char,int> mp;
	rep(i,0,s.size()){
		mp[s[i]]++;
	}
	if(mp.size()==3)ans++;
	dfs(s+'3');
	dfs(s+'5');
	dfs(s+'7');
	return;
}

string p(ll i,string s){
	if(i==0)s.push_back('3');
	else if(i==1)s.push_back('5');
	else s.push_back('7');
	return s;
}

signed main(){
	//cout << fixed << setprecision(10);
	cin>>n;
	if(n<357){
		cout<<0<<endl;
		return 0;
	}
	dfs("3");
	dfs("5");
	dfs("7");
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

map<ll, ll> primeFactor(ll n) {
  map<ll, ll> res;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if(n != 1) res[n] = 1;
  return res;
}

int main() {
  ll n;
  cin >> n;
  map<ll, ll> mp;
  rep2(i, 2, n + 1) {
    auto pf = primeFactor(i);
    for(auto v : pf) mp[v.first] += v.second;
  }
  ll ans = 0;
  ll n2 = 0, n4 = 0, n14 = 0, n24 = 0, n74 = 0;
  for(auto v : mp) {
    ll m = v.second;
    if(m >= 2) n2++;
    if(m >= 4) n4++;
    if(m >= 14) n14++;
    if(m >= 24) n24++;
    if(m >= 74) n74++;
  }
  ans += max(0LL, n24 * (n2 - 1));
  ans += max(0LL, n4 * (n4 - 1) / 2 * (n2 - 2));
  ans += max(0LL, n14 * (n4 - 1));
  ans += n74;
  cout << ans << endl;
}

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

using namespace std;

int main(){
    long long n, m;
    while(cin >> n >> m, n+m){
        vector<pair<int, int>> v(n);
        for(int i=0; i< n; i++) cin >> v[i].second >> v[i].first;
        sort(v.begin(), v.end());
        for(int i=v.size()-1; 0 <= i; i--){
            if(n != 0){
                long long d = min((long long)v[i].second, m);
                v[i].second -= d; m -= d;
            }
            else break;
        }
        int ret = 0;
        for(int i=0; i< n; i++) ret += v[i].second*v[i].first;
        cout << ret << endl;
    }
}

Measured memory_bytes: 1284
using System;
using System.Linq;
using System.Collections.Generic;

namespace AtCoder0802
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int X = int.Parse(Console.ReadLine());
            //int[] input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            if (X >= 30)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


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


int main() {
	
	int N, sum=0;
	cin >> N;
	vector<int> p(N);
	for(auto &i:p) cin >> i;
	sort(p.begin(),p.end());
	for(int i=0; i<N; i++){
		if(i!=N-1) sum += p.at(i);
		else sum += p.at(i)/2;
	}
	cout << sum << endl; 
	
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int res,ll,rr,uu,dd,ad,R,L,D,U,sx,sy,h,w,pr[105][105],pc[105][105];
short dp[105][105][105][105];
char s[105][105];
void print() {
    for (int i=1;i<=h;++i)
        for (int j=1;j<=w;++j)
            printf("%d%c",pr[i][j],j==w?'\n':' ');
    for (int i=1;i<=h;++i)
        for (int j=1;j<=w;++j)
            printf("%d%c",pc[i][j],j==w?'\n':' ');
}
int max(int a,int b) {
    return a>b?a:b;
}
int main()
{
    //freopen("in.txt","r",stdin);
    scanf("%d%d",&h,&w);
    for (int i=1;i<=h;++i)
        scanf("%s",s[i]+1);
    for (int i=1;i<=h;++i)
        for (int j=1;j<=w;++j) {
            pr[i][j]=pr[i-1][j]+(s[i][j]=='o');
            pc[i][j]=pc[i][j-1]+(s[i][j]=='o');
            if (s[i][j]=='E')
                sx=i,sy=j;
        }
    //print();
    memset(dp,-1,sizeof dp);
    dp[0][0][0][0]=0;
    L=sy-1,R=w-sy,U=sx-1,D=h-sx;
    for (int l=0;l<=L;++l)
        for (int r=0;r<=R;++r)
            for (int u=0;u<=U;++u)
                for (int d=0;d<=D;++d) {
                    if (dp[l][r][u][d]==-1)
                        continue;
                    rr=min(sy+r,w-l);
                    ll=max(sy-l,r+1);
                    uu=max(sx-u,d+1);
                    dd=min(sx+d,h-u);
                    res=max(res,dp[l][r][u][d]);
                    //printf("(%d,%d,%d,%d)->%d\n",l,r,u,d,dp[l][r][u][d]);
                    if (l+r<L) {
                        ad=pr[dd][sy-l-1]-pr[uu-1][sy-l-1];
                        //printf("l:%d\n",ad);
                        dp[l+1][r][u][d]=max(dp[l+1][r][u][d],dp[l][r][u][d]+ad);
                    }
                    if (l+r<R) {
                        ad=pr[dd][sy+r+1]-pr[uu-1][sy+r+1];
                        //printf("r:%d\n",ad);
                        dp[l][r+1][u][d]=max(dp[l][r+1][u][d],dp[l][r][u][d]+ad);
                    }
                    if (u+d<U) {
                        ad=pc[sx-u-1][rr]-pc[sx-u-1][ll-1];
                        //printf("u:%d\n",ad);
                        dp[l][r][u+1][d]=max(dp[l][r][u+1][d],dp[l][r][u][d]+ad);
                    }
                    if (u+d<D) {
                        ad=pc[sx+d+1][rr]-pc[sx+d+1][ll-1];
                        //printf("d:%d\n",ad);
                        dp[l][r][u][d+1]=max(dp[l][r][u][d+1],dp[l][r][u][d]+ad);
                    }
                }
    printf("%d\n",res);
    return 0;
}


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

using namespace std;

int main(){
	int n;
	cin>>n;
	int k;
	cin>>k;
	long long int a[n];
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	long long int sum=0;
	for(int i=n-1-k;i>=0;i--)sum+=a[i];
	cout<<sum;
	return 0;
}


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

int main(){
  int a[6];
  a[0] = 3*5*7;
  a[1] = 3*5*11;
  a[2] = 3*5*13;
  a[3] = 3*7*11;
  a[4] = 3*3*3*5;
  a[5] = 3*3*3*7;
int ans = 0;
int b;
cin >> b;
  for(int i = 0;i < 6;i++){
    if(a[i] <= b){
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<numeric>
using namespace std;
using ll = long long;
int main(){
  ll n, a, b;
  cin >> n >> a >> b;
  if(a > b){
    cout << 0 << endl;
    return 0;
  }
  if(n == 1 && a != b){
    cout << 0 << endl;
    return 0;
  }
  ll maxi = b * (n - 1) + a;
  ll mini = b + (n - 1) * a;
  cout << maxi - mini + 1 << endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
A = [int(_) for _ in input().split()]

def gcd(x,y):
    if x < y:
        return gcd(y,x)
    else:
        if x % y == 0:
            return y
        else:
            return gcd(y,x%y)
ans = A[0]
for i in range(1,n):
    ans = gcd(ans,A[i])
print(ans)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long

int main(){
    fastio
    int h,w,sx,sy,ex,ey;
    vector<string> vals; string s;
    cin >> h >> w >> sx >> sy >> ex >> ey;sx--;sy--;ex--;ey--;
    for(int i=0;i<h;i++) {
        cin >> s;
        vals.push_back(s);
    }

    queue<vector<int>> q;
    vector<vector<bool>> vis(h, vector<bool>(w));

    int steps = 0;
    vector<vector<int>> dirs = {{1,0},{0,1},{-1,0},{0,-1}};
    q.push({sx,sy});
    vis[sx][sy] = 1;
    while(!q.empty()) {
        set<vector<int>> nxt;
        while(!q.empty()) {
            auto top = q.front(); q.pop();
            int x = top[0], y = top[1];
            if(x==ex && y==ey) {
                cout << steps; return 0;
            }
            for(auto d : dirs) {
                int nx = d[0]+x, ny = d[1]+y;
                if(nx<0||ny<0||nx>=h||ny>=w||vals[nx][ny]=='#'||vis[nx][ny]) continue;
                vis[nx][ny] = 1;
                q.push({nx,ny});
            }
            // magic
            for(int j=-2;j<=2;j++) {
                for(int k=-2;k<=2;k++) {
                    int nx = x+j, ny = y+k;
                    if(nx<0||ny<0||nx>=h||ny>=w||vals[nx][ny]=='#'||vis[nx][ny]) continue;
                    nxt.insert({nx,ny});
                }
            }
        }
        for(auto p : nxt) {
            int nx = p[0], ny = p[1];
            if(vis[nx][ny]) continue;
            vis[nx][ny] = true;
            q.push({nx,ny});
        }
        steps++;
    }
    cout << -1;
}


Measured memory_bytes: 6028
program EDPCB
    implicit none
    integer(8)::N,K,i,j
    integer(8),allocatable,dimension(:)::H,dp
    read(5,*)N,K
    allocate(H(N))
    allocate(dp(N))
    read(5,*)(H(i),i=1,N)

    dp=0

    do j=2,N
        do i=1,K
            if(j>i)then
                if(i==1)then
                    dp(j)=dp(j-1)+abs(H(j)-H(j-1))
                else
                    dp(j)=min(dp(j),dp(j-i)+abs(H(j)-H(j-i)))
                end if
            else
                exit
            end if
        end do
    end do

    print'(i0)',dp(N)
end program EDPCB

Measured memory_bytes: 2304
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
  int P;
  int Q;
  int R;
  cin >>P>>Q>>R;
  int a=P+Q;
  int b=P+R;
  int c=Q+R;
  int Z=min(min(a,b),c);
  cout << Z<< endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace ABC173
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            Dictionary<string, int> results = new Dictionary<string, int>();
            results["AC"] = 0;
            results["WA"] = 0;
            results["TLE"] = 0;
            results["RE"] = 0;

            for (var i = 0; i< N; i++)
            {
                string input = Console.ReadLine();
                results[$"{input}"]++;
            }

            Console.WriteLine($"AC x {results["AC"]}");
            Console.WriteLine($"WA x {results["WA"]}");
            Console.WriteLine($"TLE x {results["TLE"]}");
            Console.WriteLine($"RE x {results["RE"]}");
        }
    }
}


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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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

    vector<ll> East;
    vector<ll> West;
    East.push_back(0);
    West.push_back(0);


    rep(i,N)
    {
        if(s[i] == 'E' )
        {
            East.push_back(East[East.size()-1]+1);
            West.push_back(West[West.size()-1]);
        }
        else
        {
            East.push_back(East[East.size()-1]);
            West.push_back(West[West.size()-1]+1);
        }
    }

    ll ans = INF;
    for(ll i = 1; i <= N; i++)
    {
        ll tmp = (East[East.size()-1] - East[i] ) + West[i-1];
        if( tmp < ans ) ans = tmp;
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 10988
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<ctime>
#include<utility>
#include<vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
struct graph
{
	int v[200010];
	int t[200010];
	int h[100010];
	int n;
	graph()
	{
		memset(h,0,sizeof h);
		n=0;
	}
	void add(int x,int y)
	{
		n++;
		v[n]=y;
		t[n]=h[x];
		h[x]=n;
	}
};
graph g;
void fail()
{
	printf("NO\n");
	exit(0);
}
int d[100010];
ll f[100010];
int a[100010];
void dfs(int x,int fa)
{
	int c=0;
	int i;
	ll s=0;
	ll mx=0;
	for(i=g.h[x];i;i=g.t[i])
		if(g.v[i]!=fa)
		{
			dfs(g.v[i],x);
			c++;
			s+=f[g.v[i]];
			mx=max(mx,f[g.v[i]]);
		}
	if(!c)
	{
		f[x]=a[x];
		return;
	}
	ll db=s-a[x];
	if(db<0)
		fail();
	ll e;
	if(2*mx<=s)
		e=s/2;
	else
		e=s-mx;
	if(db<=e)
		f[x]=s-2*db;
	else
		fail();
	if(f[x]<0)
		fail();
}
int main()
{
#ifdef DEBUG
	freopen("c.in","r",stdin);
	freopen("c.out","w",stdout);
#endif
	int n;
	scanf("%d",&n);
	int i,x,y;
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]);
	if(n<=2)
	{
		if(a[1]==a[2])
			printf("YES\n");
		else
			printf("NO\n");
		return 0;
	}
	for(i=1;i<=n-1;i++)
	{
		scanf("%d%d",&x,&y);
		g.add(x,y);
		g.add(y,x);
		d[x]++;
		d[y]++;
	}
	int rt;
	for(i=1;i<=n;i++)
		if(d[i]>=2)
			rt=i;
	dfs(rt,0);
	if(f[rt])
		printf("NO\n");
	else
		printf("YES\n");
	return 0;
}

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

int EyeTest(float num){
	if(1.1 <= num) return 0;
	else if(0.6 <= num) return 1;
	else if(0.2 <= num) return 2;
	else return 3;
}

int main(){
	float n, m;
	int ans[2][4];
	for(int i=0; i < 2; i++){
		for(int j=0; j < 4; j++) ans[i][j] = 0;
	}
	while(cin >> n >> m){
		ans[0][EyeTest(n)]++;
		ans[1][EyeTest(m)]++;
	}
	for(int i=0; i < 4; i++){
		cout << ans[0][i] << ' ' << ans[1][i] << endl;
	}
}

Measured memory_bytes: 1224
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();

        HashSet<Integer> holeList  = new HashSet<>();

        for (int i = 0; i < m; i++){
            holeList.add(sc.nextInt());
        }

        long count = 0;
        long countOneBefore = 1;
        long countTwoBefore = 0;

        for (int i = 0 ; i < n; i++){
            if (holeList.contains(i + 1)){
                // 穴が開いている場合
                count = 0;
                countTwoBefore = countOneBefore;
                countOneBefore = count;
            }else {
                count = countOneBefore + countTwoBefore;
                if (count >= 1000000007L){
                    count = count % 1000000007L;
                }
                countTwoBefore = countOneBefore;
                countOneBefore = count;
            }
        }

        System.out.println(count);
    }

}

Measured memory_bytes: 64500
L=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]

a=list(str(input()))
b=len(a)
for i in range(b):
    c=L.index(a[i])
    print(L[c-3],end="")
print()


Measured memory_bytes: 5716
from collections import deque
import sys

n, m = tuple([int(e) for e in input().split()])
adj = [[] for _ in range(n)]
for _ in range(m):
    a, b = tuple([int(e) - 1 for e in input().split()])
    adj[a].append(b)
    adj[b].append(a)

D = [float('inf')] * n
P = [None] * n
D[0] = 0
qt = deque()
qt.append(0)
while qt:
    v = qt.popleft()
    for n_v in adj[v]:
        if D[n_v] > D[v] + 1:
            P[n_v] = v + 1
            D[n_v] = D[v] + 1
            qt.append(n_v)

for i in range(n):
    if D[i] == float('inf'):
        print('No')
        sys.exit(0)
print('Yes')        
print('\n'.join(list(map(str, P[1:]))))
    

Measured memory_bytes: 100772
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;

typedef long long LL;
typedef pair <int, int> pii;

inline int Read()
{
	int x = 0, f = 1, c = getchar();
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (;  isdigit(c); c = getchar())
		x = x * 10 + c - '0';
	return x * f;
}

const int MAXN = 1000005;
const int mod = 1e9 + 7;

int n, sum, f[MAXN];

int main()
{
#ifdef wxh010910
	freopen("data.in", "r", stdin);
#endif
	f[1] = n = Read(), f[2] = 1LL * n * n % mod, sum = (f[1] + f[2]) % mod;
	for (int i = 3; i <= n; i ++)
		f[i] = (1LL * (n - 1) * (n - 1) + sum - f[i - 2] + n - i + 2) % mod, sum = (sum + f[i]) % mod;
	return printf("%d\n", (f[n] + mod) % mod), 0;
}


Measured memory_bytes: 4096
#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <utility>
#include <vector>

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

using namespace std;
#define INF 987654321
int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> graph(N, vector<int>(N, INF));

    REP(i, M) {
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;

        graph[a][b] = c;
        graph[b][a] = c;
    }

    auto graph_backup = graph;

    REP(k, N)
    REP(i, N)
    REP(j, N)
    graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j]);

    int ans = 0;
    REP(i, N)
    REP(j, N)
    if (graph_backup[i][j] != INF && graph[i][j] < graph_backup[i][j]) ans++;

    cout << ans / 2 << endl;

    return 0;
}


Measured memory_bytes: 384
#!/usr/bin/ruby
#
# 1157.rb: Roll-A-Big-Ball
#

### constant

INF = Float::INFINITY

### subroutines

def i_prod(vx0, vy0, vx1, vy1)
  vx0 * vx1 + vy0 * vy1
end

def o_prod(vx0, vy0, vx1, vy1)
  vx0 * vy1 - vy0 * vx1
end

def d2_p_seg(px, py, x0, y0, x1, y1)
  dx01 = x1 - x0
  dy01 = y1 - y0
  dx0p = px - x0
  dy0p = py - y0
  dx1p = px - x1
  dy1p = py - y1

  return (dx0p ** 2 + dy0p ** 2) if i_prod(dx01, dy01, dx0p, dy0p) <= 0.0
  return (dx1p ** 2 + dy1p ** 2) if i_prod(-dx01, -dy01, dx1p, dy1p) <= 0.0
  o_prod(dx01, dy01, dx0p, dy0p) ** 2 / (dx01 ** 2 + dy01 ** 2)
end

def cross_segs?(ax0, ay0, ax1, ay1, bx0, by0, bx1, by1)
  dax = ax1 - ax0
  day = ay1 - ay0
  dbx = bx1 - bx0
  dby = by1 - by0

  if o_prod(dax, day, dbx, dby) == 0.0
    if ay0 * (ax1 - bx0) + ay1 * (bx0 - ax0) * by0 * (ax0 - ax1) == 0.0 &&
        (i_prod(bx0 - ax0, by0 - ay0, bx1 - ax0, by1 - ax0) <= 0.0 ||
         i_prod(bx0 - ax1, by0 - ay1, bx1 - ax1, by1 - ax1) <= 0.0 ||
         i_prod(ax0 - bx0, ay0 - by0, ax1 - bx0, ay1 - bx0) <= 0.0 ||
         i_prod(ax0 - bx1, ay0 - by1, ax1 - bx1, ay1 - bx1) <= 0.0)
      return true
    end
    return false
  end

  (o_prod(dax, day, bx0 - ax0, by0 - ay0) *
   o_prod(dax, day, bx1 - ax0, by1 - ay0) <= 0.0 &&
   o_prod(dbx, dby, ax0 - bx0, ay0 - by0) *
   o_prod(dbx, dby, ax1 - bx0, ay1 - by0) <= 0.0)
end

### main

loop do
  n = gets.to_i
  break if n == 0

  sx, sy, ex, ey = gets.split.map(&:to_f)
  #p [sx, sy, ex, ey]

  rects = n.times.map{gets.split.map(&:to_f)}
  #p rects

  min_r2 = INF

  rects.each do |minxi, minyi, maxxi, maxyi, hi|
    #p [minxi, minyi, maxxi, maxyi, hi]

    pts = [[minxi, minyi], [maxxi, minyi], [maxxi, maxyi], [minxi, maxyi]]

    incl = true
    min_d2 = INF

    for i in (0...4)
      j = (i + 1) % 4

      xi, yi = pts[i]
      xj, yj = pts[j]

      if incl
        if o_prod(xj - xi, yj - yi, sx - xi, sy - yi) < 0.0 ||
            o_prod(xj - xi, yj - yi, ex - xi, ey - yi) < 0.0
          incl = false
        end
      end

      if cross_segs?(sx, sy, ex, ey, xi, yi, xj, yj)
        #p ['cross_segs?', sx, sy, ex, ey, xi, yi, xj, yj]
        min_d2 = 0.0
        break
      end

      min_d2 = [min_d2,
                d2_p_seg(sx, sy, xi, yi, xj, yj),
                d2_p_seg(ex, ey, xi, yi, xj, yj),
                d2_p_seg(xi, yi, sx, sy, ex, ey),
                d2_p_seg(xj, yj, sx, sy, ex, ey)].min
      break if min_d2 == 0.0
    end

    #p [incl, min_d2]
    if incl || min_d2 == 0.0
      min_r2 = 0.0
      break
    end

    r2 = 0.0
    h2 = hi ** 2

    if min_d2 <= h2
      r2 = min_d2
    else
      r2 = ((min_d2 + h2) / (2 * hi)) ** 2
    end

    min_r2 = r2 if min_r2 > r2
    #p [r2, min_r2]
  end

  puts Math.sqrt(min_r2)
end

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

int main() {
	// your code goes here
	string s,t;
	cin>>s>>t;
	int ans=0;
	for(int i=0;i<3;i++)
	{
		if(s[i]==t[i])
		ans++;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
int main(){
	int n,ans=0;
	scanf("%d", &n);
	for(int i=1;i<=n;i++){
		int a;
		scanf("%d",&a);
		while(a%2==0){
			a/=2;
			ans++;
		}
	}
	printf("%d\n",ans);
}


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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void c_p_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif*/
}

int pwmd(int a, int n)
{
	if (!n)
		return 1;
	int pt = pwmd(a, n / 2);
	pt *= pt, pt %= mod;
	if (n & 1)
		pt *= a, pt %= mod;
	return pt;
}

int fct[100001], inv[100001];

int C(int n, int r)
{
	if (r > n)
		return 0;
	int ans = (fct[n] * inv[r]) % mod;

	ans = (ans * inv[n - r]) % mod;

	return ans;
}

int32_t main()
{
	c_p_c();
	int ans = 0;
	mii cnt;

	fct[0] = inv[0] = 1;

	for (int i = 1; i <= 100000; ++i)
		fct[i] = (fct[i - 1] * i) % mod, inv[i] = pwmd(fct[i], mod - 2);

	int n, k; cin >> n >> k;
	while (n--)
	{
		int x; cin >> x;
		cnt[x]++;
	}

	int tl = 0;

	//cout << C(10, 6) << ' ' << C(5, 6) << '\n';

	for (auto el : cnt)
	{
		int vl = (el.ff + mod) % mod;
		//cout << el.ff << ' ' << tl << ' ' << el.ss << '\n';
		int ways = (C(tl + el.ss, k) - C(tl, k) + mod) % mod;
		//cout << ways << '\n';
		ways = (ways * vl) % mod;

		ans += ways;
		ans %= mod;
		tl += el.ss;
	}

	tl = 0;

	for (auto it = cnt.rbegin(); it != cnt.rend(); ++it)
	{
		auto el = (*it);
		int vl = (el.ff + mod) % mod;
		int ways = (C(tl + el.ss, k) - C(tl, k) + mod) % mod;
		ways = (ways * vl) % mod;
		ans = (ans - ways + mod) % mod;
		tl += el.ss;
	}

	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 7680
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
 
const double EPS = 1e-10;
const ll INF = 100000000;
const ll MOD = 1000000007;

ll n, q;
ll a[3000];
P ind[3000];
ll x[3000], y[3000];
ll pow2[10000];
P t[3000][3000];
ll z[3000][3000];
ll to[3000];
ll sum[3000];

ll mod_pow (ll x, ll y) {
    ll ret = 1;
    while (y) {
        if (y&1) ret = ret * x % MOD;
        x = x * x % MOD;
        y /= 2;
    }
    return ret;
}

int main() {
    pow2[0] = 1;
    for (int i = 1; i < 10000; i++) pow2[i] = pow2[i-1] * 2 % MOD;
    cin >> n >> q;
    rep(i,n) cin >> a[i];
    rep(i,q) cin >> x[i] >> y[i];
    rep(i,q) { x[i]--; y[i]--; }
    rep(i,n) t[i][i] = P(1, 0);
    rep(i,q) {
        rep(j,n) {
            P tmp1 = t[j][x[i]];
            P tmp2 = t[j][y[i]];
            t[j][x[i]] = P((tmp1.first * pow2[i-tmp1.second] % MOD + tmp2.first * pow2[i-tmp2.second] % MOD) % MOD, i+1);
            t[j][y[i]] = P((tmp1.first * pow2[i-tmp1.second] % MOD + tmp2.first * pow2[i-tmp2.second] % MOD) % MOD, i+1);
        }
    }
    rep(i,n) rep(j,n) {
        z[i][j] = t[i][j].first * pow2[q-t[i][j].second] % MOD;
    }
    rep(i,n) ind[i] = P(a[i], i);
    sort(ind, ind+n);
    ll ans = 0;
    ll st = 0;
    rep(i,n) {
        for (int j = 0; j < n-1; j++) {
            ans = (ans + z[ind[i].second][j] * sum[j+1]) % MOD;
        }
        for (int j = 0; j < n; j++) {
            ans = (ans + (z[ind[i].second][j] * to[j] % MOD) * mod_pow(2,MOD-2)) % MOD;
        }
        if (i == n-1 || ind[i].first != ind[i+1].first) {
            for (int u = st; u <= i; u++) {
                rep(j,n) {
                    to[j] = (to[j] + z[ind[u].second][j]) % MOD;
                }
                sum[n-1] = to[n-1];
                for (int j = n-2; j >= 0; j--) {
                    sum[j] = (sum[j+1] + to[j]) % MOD;
                }
            }
            st = i+1;
        }
    }
    ans = ans * mod_pow(pow2[q], MOD-2) % MOD;
    cout << ans << endl;
}



Measured memory_bytes: 211456
#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;//sum=sum+i
  }
  cout<<sum;

}

Measured memory_bytes: 3636
s = gets.chomp.split('')
t = gets.chomp.split('')
size = t.size

answers = []

s.each_cons(size) do |chars|
  count = 0
  chars.each.with_index do |char, i|
    count += 1 unless char == t[i]
  end
  answers << count
end

puts answers.min


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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

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

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int n; std::cin >> n;
  map<int, int> cnt;
  rep(i, n) {
    int a; std::cin >> a;
    cnt[a]++;
  }
  int ma1 = 0, ma2 = 0;
  for (auto &p : cnt) {
    if (p.se >= 2 && p.fi > ma1) {
      ma2 = ma1;
      ma1 = p.fi;
      if (p.se >= 4) ma2 = p.fi;
    } else if (p.se >= 2 && p.fi > ma2) {
      ma2 = p.fi;
    }
  }
  std::cout << 1ll * ma1 * ma2 << "\n";
}


Measured memory_bytes: 4992
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

#define FOR(i, l, r) for(int i = (l); i <= (r); i++)
#define REP(i, l, r) for(int i = (l); i != (r); i++)
#define DFR(i, l, r) for(int i = (l); i >= (r); i--)
#define DRP(i, l, r) for(int i = (l); i != (r); i--)

using namespace std;

#define DEBUG(arg...) fprintf(stderr, arg)

namespace FI {
    const int SIZE = 1 << 18 | 1;
    char buf[SIZE], *front, *back;

    void Char(char &c) {
	if(front == back) back = (front = buf) + fread(buf, 1, SIZE, stdin);
	c = (front == back) ? (char)EOF : *front++;
    }

    template<typename T> void Num(T & x) {
	char c; int f = 1;
	for(Char(c); c > '9' || c < '0'; Char(c)) if(c == '-') f = -1;
	for(x = 0; c >= '0' && c <= '9'; Char(c)) x = (x << 3) + (x << 1) + c - '0';
	x *= f;
    }
}

typedef long long LL;
const int maxn = 17;

int n, a, b, num[1 << maxn];

void cal(int a, int b, int S) {
    if(__builtin_popcount(S) == 1) {
	printf("%d %d ", a, b);
	return;
    }
    REP(i, 0, n) {
	if((S >> i) & 1 && ((a >> i) & 1) ^ ((b >> i) & 1)) {
	    int na = a & (S ^ (1 << i)), nb = b & (S ^ (1 << i)), ns = S ^ (1 << i);
	    bool res = false;
	    for(int j = ns; j; j = (j - 1) & ns) {
		if((__builtin_popcount(na ^ j) & 1) && (__builtin_popcount(nb ^ j) & 1)) {
		    cal(a, j | ((((1 << n) - 1) - (S ^ (1 << i))) & a), ns);
		    cal(j | ((((1 << n) - 1) - (S ^ (1 << i))) & b), b, ns);
		    res = true; break;
		}
	    }
	    if(!res) {
		cal(a, ((((1 << n) - 1) - (S ^ (1 << i))) & a), ns);
		cal(((((1 << n) - 1) - (S ^ (1 << i))) & b), b, ns);
	    }
	    break;
	}
    }
}

int main() {
    scanf("%d%d%d", &n, &a, &b);
    if((__builtin_popcount(a ^ b) & 1) == 0) puts("NO");
    else {
	puts("YES");
	cal(a, b, (1 << n) - 1);
	puts("");
    }
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <array>
#include <tuple>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
using namespace std;
typedef long long ll;
typedef unsigned long long int ull;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define all(v) (v).begin(),(v).end()
#define clr(a,b) memset((a),(b),sizeof(a))
#define sz size()
#define pb push_back
#define print(x) cout << x << endl
int n,m;
int a,b,c;
string s,t;

int main(){
  cin >> n >> m;
  print(n*n-m);
  return 0;
}


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

int main() {
  int N;
  cin>>N;
  vector<double>A(N);
  rep(i,N) cin>>A[i];
  double ans=0;
  rep(i,N) ans+=1/A[i];
  ans=1/ans;
  printf("%.10lf\n", ans);
  
}

Measured memory_bytes: 256