akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String input = scanner.nextLine();

        List<String> inputs = Arrays.asList(input.split(" "));

        int result = Integer.valueOf(inputs.get(1)) / Integer.valueOf(inputs.get(0));

        if (result > Integer.valueOf(inputs.get(2))) {
            System.out.println(Integer.valueOf(inputs.get(2)));
        } else {
            System.out.println(result);
        }
    }
}


Measured memory_bytes: 22612
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define pb push_back
#define ppb pop_back
#define cs(n) cout<<n<<" "
#define cn(n) cout<<n<<"\n"
#define rep(i,j,k) for(int i=j;i<k;i++)
#define rrep(i,j,k) for(int i=j;i>=k;i--)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll bin(ll a, ll b)
{
	if (b == 0)
		return 1;
	if (b % 2 == 0)
		return bin((a * a) % mod , b / 2) % mod;
	return ((a % mod) * (bin((a * a) % mod , b / 2) % mod)) % mod;
}
void solve()
{
	int a, b, c, d, e;
	cin >> a >> b >> c >> d >> e;
	if (a == 0) {
		cout << 1;
	}
	if (b == 0)
		cout << 2;
	if (c == 0)
		cout << 3;
	if (d == 0)
		cout << 4;
	if (e == 0)
		cout << 5;
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r" , stdin);
	freopen("output.txt" , "w" , stdout);
#endif
	fastio;
	int t;
	//cin >> t;
	t = 1;
	while (t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3604
#include<iostream>
#include<string>
#include<map>
using namespace std;

int main() {
	map<char, int> m;
	string v; cin >> v;
	for (int i = 0; i < v.size(); i++) {
		char c = v[i];
		m[c]++;
	}
	for (auto val : m) {
		if (val.second % 2 != 0) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template <typename T>
inline void readin(T &x) {
	x = 0;
	T fh = 1;
	char ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') fh = -1;
	for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48);
	x *= fh;
}
inline void d_read(double &x) {
	x = 0.0;
	int fh = 1;
	char ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') fh = -1;
	for (; isdigit(ch); ch = getchar()) x = x * 10 + (ch ^ 48);
	if (ch == '.') {
		double num = 1.0;
		ch = getchar();
		for (; isdigit(ch); ch = getchar()) x = x + (num /= 10) * (ch ^ 48);
	}
	x *= fh;
}

template <typename T>
inline void wt(T x) {
	if (x > 9) wt(x / 10);
	putchar(x % 10 + 48);
}
template <typename T>
inline void writeln(T x, char c) {
	if (x < 0) {
		putchar('-');
		x = -x;
	}
	wt(x);
	putchar(c);
}
int a[9] = {0, 1800, 1600, 1400, 1200, 1000, 800, 600, 400};
int main() {
	int x;
	readin(x);
	for (int i = 1; i <= 8; i ++) {
		if (x >= a[i]) {
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}




Measured memory_bytes: 3616
open System

let a = stdin.ReadLine()
let b = stdin.ReadLine()
let calc =
    let mutable x = 0
    for i in 0..(a.Length-1) do
        if a.[i] = b.[i] then
            x <- x + 0
        else
            x <- x + 1
    x
calc |> printf "%d"


Measured memory_bytes: 31268
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c==' '||c=='\n')c=_buff.get();return c;}
int n,a[100111];
ll L;
int main()
{
	getii(n,L);
	for(int i=1;i<=n;i++)geti(a[i]);
	for(int i=1;i<n;i++)
	{
		if(a[i]+a[i+1]>=L)
		{
			puts("Possible");
			for(int j=1;j<i;j++)putsi(j);
			for(int j=n-1;j>=i;j--)putsi(j);
			return 0;
		}
	}
	puts("Impossible");
	return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'
int main()
{
    Hello
    int n;
    cin >> n;
    int arr[n + 5];
    map<int,int> mp;
    map<int,int> :: iterator it;
    for(int i = 0; i < n; i++){
        cin >> arr[i];
        mp[arr[i]]++;
    }
    for(int i = 0; i < n; i++){
        mp[arr[i]]--;
        if(mp[arr[i]] == 0)
            mp.erase(arr[i]);
        it = mp.end();
        it--;
        cout << it->first << endl;
        mp[arr[i]]++;
    }
    return 0;
}

Measured memory_bytes: 7936
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#define each(it,o) for(auto it= (o).begin(); it != (o).end(); ++ it)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define inrep int t;cin>>t; while(t--)
#define pb emplace_back
using namespace std;
using namespace __gnu_pbds; 


typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii > vpii;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef vector<pll > vpll; 
typedef vector<string> vs;
typedef long double ld;
const ll MOD = 1e9+7;
template<typename T> istream& operator>> ( istream &in,vector<T> &v ) {

    for ( unsigned   i=0; i<v.size(); i++ )
        in>>v[i];
    return in;
}

ll power(ll x, ll y,ll m) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2,m)%m; 
    p = (p * p)%m; 
  
    return (y%2 == 0)? p : (x * p)%m ; 
} 

ll modInverse(ll a, ll m) 
{ 
        // If a and m are relatively prime, then modulo inverse 
        // is a^(m-2) mode m 
    return power(a, m-2,m); 
} 
  
// To compute x^y under modulo m 
vector<int> a;
int dp[100005][3];
int n;
ll rec(int k,int i)
{
  if(k<a[0])
    return (i+1)%2;
  if(dp[k][i]!=-1)
    return dp[k][i];
  ll ans = 0;
  for(int j=0;j<n;j++)
  {
    if(k>=a[j])
    {
      ans = rec(k-a[j],(i+1)%2);
    }
    if(ans==i)
      break;
  }
  dp[k][i] = ans;
  return dp[k][i];
}
int main()
{
   
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int k;
    cin>>n>>k;
    for(int i=0;i<n;i++)
    {
      int ai;
      cin>>ai;
      a.push_back(ai);
    }
    sort(a.begin(),a.end());
    mset(dp,-1);
    ll ans = rec(k,0);
    if(ans==0)
      cout<<"First";
    else
      cout<<"Second";
   
    
    return 0;
}

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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

const double EPS = 1e-14;
const double PI  = acos(-1.0);


int main(){
  int n, h, w;
  scanf("%d", &n);
  scanf("%d %d", &h, &w);

  int ans = 0;

  int a, b;
  REP (i, n) {
    scanf("%d %d", &a, &b);
    if (h <= a && w <= b) ans++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <bits/stdc++.h>
#define ff first
#define ss second
#define M 1000000007
typedef long long int ll;
using namespace std;
vector <vector <ll>> adj;
vector <vector <ll>> dp;
vector <bool> visited;
ll power(ll a,ll b){
    ll ans = 1;
    while(b>0){
        if(b%2!=0){
            ans = ((ans)*(a));
        }
        a = ((a)*(a));
        b=b/2;
    }
    return ans;
}
ll add(ll a,ll b){
    ll temp = (a%M + b%M)%M;
    if(temp>M){
        temp=temp-M;
    }
    return temp;
}
void dfs(ll u){
    visited[u]=true;
    ll black = 1;
    ll white = 1;
    for(auto i:adj[u]){
        if(!visited[i]){
            dfs(i);
            black = ((black%M)*((dp[i][0])%M))%M;
            while(black>M){
                black=black%M;
            }
            white = ((white%M)*(add(dp[i][0],dp[i][1])%M))%M;
            while(white>M){
                white=white%M;
            }
        }
    }
        dp[u][0]=white%M;
        dp[u][1]=black%M;


}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    adj.assign(n+1,vector <ll> ());
    visited.assign(n+1,false);
    dp.assign(n+1,vector <ll> (2,0));
    for(ll i=0;i<n-1;i++){
        ll u,v;
        cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs(1);
    cout<<add(dp[1][0],dp[1][1])<<endl;
    return 0;
}


Measured memory_bytes: 18176
N,M,X=map(int,input().split())
A=list(map(int,input().split()))
AS=[]
cost1=0
cost2=0
for i in range(X,N+1):
	for j in range(len(A)):
		if i==A[j]:
			cost1+=1
for i in range(0,X+1):
	for j in range(len(A)):
		if i==A[j]:
			cost2+=1
if cost1<=cost2:
	print(cost1)
else:
	print(cost2)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
map<string,bool> used;

bool rec(string str){
  if(used.find(str) != used.end()) return used[str];

  if(str.empty()) return true;
  if(str[0] != 'm' || str[str.size() - 1] != 'w') return used[str] = false;

  //適当に真ん中を決める
  for(int i = 1; i < str.size() - 1; i++){
    if(str[i] == 'e'){
      if(i == 1 || i == str.size() - 2 || (i >= 4 || i <= str.size() - 5)){ //可能性がありそう(てきとー
        string right = str.substr( 1, i - 1);
        string left = str.substr( i + 1, str.size() - i - 2);
        if(rec(right) && rec(left)) return used[str] = true;
      } 
    }
  }
  return used[str] = false;
}

int main(){
  string str;
  cin >> str;

  if(rec(str)) puts("Cat");
  else puts("Rabbit");

}

Measured memory_bytes: 5736
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] ary = new int[n];
		List<Integer> temp = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			int x = sc.nextInt();
			ary[i] = x;
			temp.add(x);
		}
		Collections.sort(temp);
		int min = temp.get(n / 2 - 1);
		int max = temp.get(n / 2);
		for (int i = 0; i < n; i++) {
			if (ary[i] <= min) {
				System.out.println(max);
			} else {
				System.out.println(min);
			}
		}
	}
}


Measured memory_bytes: 94840
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
  int a;
  cin>>a;
  int b=a/100;
  int c=(a%100)/10;
  int d=(a%100)%10;
  if(b==1&&c==1&&d==1){
    cout<<3<<endl;
  }else if((b==0&&c==1&&d==1)||(b==1&&c==0&&d==1)||(b==1&&c==1&&d==0)){
    cout<<2<<endl;
  }else if((b==1&&c==0&&d==0)||(b==0&&c==1&&d==0)||(b==0&&c==0&&d==1)){
    cout<<1<<endl;
  }else{
    cout<<0<<endl;
  }
  
}


Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#define REP(i, n) for(int i = 0; i < n; i++)
template<class T> inline void chmin(T& a, T b) {if (a>b) a=b; }
template<class T> inline void chmax(T& a, T b) {if (a<b) a=b; }
using namespace std;
typedef long long ll;
const ll LINF = 1e18;
const int INF = 1e9;

ll N;
vector<ll> H;

int main() { 
    cin >> N;
    H.resize(N);
    ll ct = 0;
    ll tmpct = 0;
    cin >> H[0];
    for(int i=1; i<N; i++) {
        cin >> H[i];
        if(H[i-1] >= H[i]) {
            tmpct++;
        } else {
            ct = max(tmpct, ct);
            tmpct =0;
        }
    }
    cout << max(ct, tmpct) << endl;

    
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<list>
#include<bitset>
using namespace std;

int calc(int i) {
	double lim = sqrt((double)i);
	int ilim = (int)lim + 1;

	int val;
	int ans = 0;

	// �l���S������
	for (int x = 1; x <= ilim; x++) {
		val = x * x + x * x + x * x + x * x + x * x + x * x;
		if (val == i) {
			ans += 1;
		}
	}

	// �l���Q����
	for (int x = 1; x <= ilim - 1; x++) {
		for (int y = x + 1; y <= ilim; y++) {
			val = x * x + y * y + x * x + x * y + y * x + x * x;
			if (val == i) {
				ans += 3;
			}
			val = x * x + y * y + y * y + x * y + y * y + y * x;
			if (val == i) {
				ans += 3;
			}
		}
	}

	// �l���o���o��
	for (int x = 1; x <= ilim - 2; x++) {
		for (int y = x + 1; y <= ilim - 1; y++) {
			for (int z = y + 1; z <= ilim; z++) {
				val = x * x + y * y + z * z + x * y + y * z + z * x;
				if (val == i) {
					ans += 6;
				}
			}
		}
	}

	return ans;
}

int main() {

	int N;
	cin >> N;

	for (int i = 1; i <= N; i++) {
		cout << calc(i) << endl;
		
	}

	return 0;
}

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

int main() {
  int N,i,j,x,y,p=0;
  cin >> N;
  vector<pair<int,int>> R(N), B(N);
  set<pair<int,int>> RR;
  
  for(i=0; i<N; i++) {
    cin >> x >> y;
    R.at(i) = make_pair(x,y);
    RR.insert(R.at(i));
  }
  sort(R.begin(), R.end());
  
  for(i=0; i<N; i++) {
    cin >> x >> y;
    B.at(i) = make_pair(x,y);
  }
  sort(B.begin(), B.end());
  
  for(i=0; i<N; i++) {
    priority_queue<pair<int,int>> pq;
    for(j=0; j<N; j++) {
      if(RR.count(R.at(j)) && B.at(i).first>R.at(j).first && B.at(i).second>R.at(j).second)
        pq.push(make_pair(R.at(j).second, R.at(j).first));
      if(B.at(i).first<=R.at(j).first && B.at(i).second<=R.at(j).second)
        break;
    }
    if(!pq.empty()) {
      pair<int,int> m = pq.top();
      int pqx = m.second, pqy = m.first;
      RR.erase(make_pair(pqx, pqy));
      p++;
    }
  }

  cout << p << endl;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read::<usize>();
    let mut seq = vec![0; n];
    for i in 0..n {
        seq[i] = read::<usize>();
    }
    let mut ans = 0;
    let mut sum = 0;
    let mut l = 0;
    for r in 0..n {
        while (sum & seq[r]) != 0 {
            sum ^= seq[l];
            l += 1;
        }
        sum ^= seq[r];
        ans += r - l + 1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 6396
#include<bits/stdc++.h>
#define rep(i, a, b) for(int i=(a) ; i<=(b) ; ++i)
#define Task ""
using namespace std;
const int N=101;
int n, sum, a[N];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen(Task".inp", "r", stdin);
    //freopen(Task".out", "w", stdout);
    cin >> n;
    rep(i, 1, n) { cin >> a[i]; sum+=a[i]; }
    int xx=__gcd(sum, n);
    sum/=xx;
    xx=n/xx;
    int mx=1e9, num;
    rep(i, 1, n) {
        long long k=abs(xx*a[i]-sum);
        if(mx>k) mx=k, num=i-1;
    }
    cout << num;
    return 0;
}


Measured memory_bytes: 384
# エラトステネスの篩, フェルマーの小定理
max_A = 1000000

N = int(input())
A = list(map(int, input().split()))

sieve = [0] * (max_A + 1)
sieve[0] = -1
sieve[1] = -1
for i in range(2, max_A + 1):
    if sieve[i] != 0:
        continue
    sieve[i] = i
    for j in range(i * i, max_A + 1, i):
        if sieve[j] == 0:
            sieve[j] = i

lcm_factors = {}
for i in range(N):
    t = []
    a = A[i]
    while a != 1:
        if len(t) != 0 and t[-1][0] == sieve[a]:
            t[-1][1] += 1
        else:
            t.append([sieve[a], 1])
        a //= sieve[a]
    for k, v in t:
        if k not in lcm_factors or lcm_factors[k] < v:
            lcm_factors[k] = v

lcm = 1
for k in lcm_factors:
    for i in range(lcm_factors[k]):
        lcm *= k
        lcm %= 1000000007

result = 0
for i in range(N):
    result += lcm * pow(A[i], 1000000007-2, 1000000007)
    result %= 1000000007
print(result)


Measured memory_bytes: 14540
/***** author :  C0d1ngPhenomena *****/

    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define endl "\n"
    #define ll long long int
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define f first
    #define s second
    #define pb push_back
    
    using namespace std;
    int main()
    {
        std::ios::sync_with_stdio(false);
        cin.tie(NULL);
  		ll a;
  		cin >> a;
  		cout << a + (ll)pow(a,2) + (ll)pow(a,3);
        return 0;
    }


Measured memory_bytes: 4088
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;


#define REP(i, n) for(ll i = 0; i < n; i++)






























int main(){
    ll n, m, x;
    cin >> n >> m >> x;
    vector<vector<ll>> val(n + 1, vector<ll>(m + 1));
    REP(i, x){
        ll r, c, v;
        cin >> r >> c >> v;
        r--; c--;
        val[r][c] = v;
    }
    vector<vector<vector<ll>>> dp(n + 1, vector<vector<ll>>(m + 1, vector<ll>(4)));
    REP(i, n + 1){
        REP(j, m + 1){
            REP(k, 4){
                if(i < n){
                    dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][k] + (k < 3 ? val[i][j] : 0));
                }
                if(j < m){
                    if(k < 3){
                        dp[i][j + 1][k + 1] = max(dp[i][j + 1][k + 1], dp[i][j][k] + val[i][j]);
                    }
                    dp[i][j + 1][k] = max(dp[i][j + 1][k], dp[i][j][k]);
                }
            }
        }
    }
    cout << dp[n][m][0] << endl;
}

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

using namespace std;	
typedef long long LL;
const int nn = 1e6 + 5;

int main() {
	int N, M, bil, B, C;
	priority_queue<int> pq1;
	priority_queue<pair<int, int> > pq2;
	scanf("%d %d", & N, & M);
	for (int i = 0; i < N; i++) {
		scanf("%d", & bil);
		pq1.push(-bil);
	}
	for (int i = 0; i < M; i++) {
		scanf("%d %d", & B, & C);
		pq2.push(make_pair(C, B));
	}
	while (!pq2.empty()) {
		int x = pq2.top().first;
		int cnt = pq2.top().second;
		pq2.pop();
		while (cnt > 0) {
			if (-pq1.top() < x) {
				pq1.pop();
				pq1.push(-x);
				cnt--;
			} else break;
		}
	}
	LL ans = 0;
	while (!pq1.empty()) {
		ans -= pq1.top();
		pq1.pop();
	}		
	printf("%lld\n", ans);
}

Measured memory_bytes: 1784
#include<bits/stdc++.h>
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -1,1,-1};
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; }
// ---------------------------------------------------------------------------

// Binary indexed Tree(BIT)
template <typename T>
struct BIT{
    private:
    vector<T> array;
    const int n;

    public:
    // 初期化
    BIT(int _n) : array(_n+1,0),n(_n) {}

    // 1番目からi番目までの累積和を求める
    T sum(int i){
        T s = 0;
        while(i > 0){
            s += array[i];
            // LSB減算
            i -= i & -i;
        }
        return s;
    }
    
    // [i,j]の要素の総和
    T sum(int i,int j){
        // 1番目からi-1番目までの総和
        T ret_i = sum(i-1);
        // 1番目からj番目までの総和
        T ret_j = sum(j);
        // i番目からj番目までの総和
        return ret_j - ret_i;
    }

    // i番目に要素xを追加
    void add(int i,T x){
        while(i <= n){
            array[i] += x;
            // LSB加算
            i += i & -i;
        }
    }
};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,Q;
    cin >> N >> Q;
    BIT<int> bit(N);
    for(int i=0; i<Q; i++){
        int com;
        cin >> com;
        int x,y;
        cin >> x >> y;
        if(com == 0){
            bit.add(x,y);
        }else{
            cout << bit.sum(x,y) << enld;
        }
    }

    return 0;
}



Measured memory_bytes: 3352
x, y = [int(_) for _ in input().split()]

def solve(x, y):
    d = abs(abs(x) - abs(y))
    if y == 0:
        if x <= 0:
            return d
        return d + 1
    if 0 <= y:
        if 0 <= x <= y:
            return d
        if x < 0:
            return d + 1
        return d + 2
    if y <= 0:
        if x <= y:
            return d
        if 0 <= x:
            return d + 1
        return d + 2

print(solve(x, y))


Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] arr = new int[10];
            for (int i = 0; i < 10; i++)
            {
                arr[i] = int.Parse(Console.ReadLine());
            }
            Array.Sort(arr);
            for (int i = 9; i >= 7; i--)
            {
                Console.WriteLine(arr[i]);
            }
        }
    }
}

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

int main(){
    int n,m,k;
    scanf("%d%d",&n,&m);
    int max=-1,ti=0,min=1e9,x;
    for(k=1;k<=n;k++){
        scanf("%d",&x);
        if(k==1){
            min=x;
            continue;
        }
        if(x<min){
            min=x;
            continue;
        }
        int qq=x-min;
        if(qq==max){
            ti++;
        }
        else if(qq>max){
            max=qq;
            ti=1;
        }
    }
    printf("%d",ti);
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	a := nextInt(sc)
	b := nextInt(sc)
	c := nextInt(sc)
	fmt.Println(resolve(a, b, c))
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextInt(sc *bufio.Scanner) int64 {
	i, err := strconv.ParseInt(nextString(sc), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func resolve(a, b, c int64) string {
	slice := []int64{a, b, c}
	sort.Slice(slice, func(i, j int) bool {
		return slice[i] < slice[j]
	})
	s := fmt.Sprint(slice)
	s = strings.TrimLeft(s, "[")
	s = strings.TrimRight(s, "]")
	return s
}



Measured memory_bytes: 1184
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (size_t i = 0; i < size_t(n); i++)
#define forn1(i,n) for (size_t i = 1; i <= size_t(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

const int MAX_N = 100000;
int n;
pii a[MAX_N];

int main() {
    fastio();

    cin >> n;
    forn(i, n) {
        cin >> a[i].fst;
        a[i].snd = i;
    }

    sort(a, a + n);

    int c = 0;
    forn(i, n) {
        c += i % 2 != a[i].snd % 2;
    }

    assert(c % 2 == 0);

    cout << c / 2 << endl;

    return 0;
}

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

int main()
{
    int a,b;

    while(cin>>a>>b)
    {
        int x=a+b;
        int cnt = 0;

        while(x)
        {
            cnt++;
            x/=10;        }

        cout<<cnt<<endl;
    }

    return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define x first
#define LL long long 
#define y second
#define sqr(x) ((x)*(x))
#define pii pair<int,int>
#define pll pair<LL,LL>
#define pdd pair<double,double>
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
using namespace std;
vector<pair<int,pii> > v[200005];
map<int,pii> ma[200005];
LL fra[200005];
LL inv[200005];
LL val[200005];
LL Size[200005];
int mod=1e9+7;
LL f_pow(LL a,LL b){
    LL res=1,temp=a;
    while(b){
        if(b&1)res=res*temp%mod;
        temp=temp*temp%mod;
        b>>=1;
    }
    return res;
}
pll dfs(int x,int f){
    LL a=val[x],b=Size[x];
    for(auto &it:v[x]){
        if(it.x==f){
            swap(v[x][0],it);
        }
        if(it.x!=f){
            if(it.y.x==-1){
                it.y=dfs(it.x,x);
                ma[x][it.x]=it.y;
                a*=it.y.x;
                a%=mod;
                a*=inv[it.y.y];
                a%=mod;
                val[x]*=it.y.x;
                val[x]%=mod;
                val[x]*=inv[it.y.y];
                val[x]%=mod;
                Size[x]+=it.y.y;
                b+=it.y.y;
            }
            
        }
    }
    
    if(v[x][0].x==f)
    v[x].resize(1);
    else
    v[x].clear();
    if(ma[x].find(f)!=ma[x].end())
    {
        pii p=ma[x][f];
        a*=f_pow(p.x,mod-2);
        a%=mod;
        a*=fra[p.y];
        a%=mod;
        b-=p.y;
    }
   // printf("%d %d %lld %lld\n",x,f,a,b);
    a*=fra[b];
    a%=mod;
    
    b++;
    return mp(a,b);
}
int main(){
    int n;
    scanf("%d",&n);
    fill(val,val+n+1,1);
    fra[0]=1;
    for(int i = 1;i<=n;i++)fra[i]=fra[i-1]*i%mod;
    inv[n]=f_pow(fra[n],mod-2);
    for(int i =n-1;i>=0;i--)inv[i]=inv[i+1]*(i+1)%mod;
    for(int i = 1;i<n;i++){
        int x,y;
        scanf("%d %d",&x,&y);
        v[x].pb(mp(y,mp(-1,-1)));
        v[y].pb(mp(x,mp(-1,-1)));
    }
    for(int i = 1;i<=n;i++){
        printf("%lld\n",dfs(i,0).x);
    }
}

Measured memory_bytes: 56624
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
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, N = MAP()
A = LIST()
diff = K - A[-1] + A[0]
d = K - A[-1] + A[0]
if N == 2:
  print(min(d, A[1] - A[0]))
  exit()
for i in range(1, N):
  d += A[i] - A[i-1]
  diff = max(diff, A[i] - A[i-1])
print(d - diff)

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

typedef long long int ll;
#define REP(i,a,b) for(ll i = ll(a); i < ll(b); i++)

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	string s;
	cin>>s;
	if(s == "AAA" || s == "BBB")
		cout<<"No";
	else
		cout<<"Yes";
	return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc126/tasks/abc126_d

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(_i, n) printf("%d%c", a[_i], _i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(_i, n) REP(_j, m) printf("%d%c", a[_i][_j], _j + 1 == m ? '\n' : ' '); puts("")

//------------------------------------------------------------------------------
const int V_MAX = 1e5;

struct edge { int to, w; };
vector<edge> G[V_MAX];
int color[V_MAX];

void add_edge(int u, int v, int w) {
  G[u].push_back({v, w});
  G[v].push_back({u, w});
}

void dfs(int p, int v, int c) {
  color[v] = c;
  for (edge e : G[v]) {
    if (e.to == p) continue;
    dfs(v, e.to, c ^ e.w & 1);
  }
}

//------------------------------------------------------------------------------
const int N_MAX = 1e5;
const int W_I_MAX = 1e9;

int N;
// int u[N_MAX-1];
// int v[N_MAX-1];
// int w[N_MAX-1];


void solve() {
  dfs(-1, 0, 0);
  REP(i, N) printf("%d\n", color[i]);
}

void input() {
  scanf("%d", &N);
  REP(i, N-1) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    add_edge(u - 1, v - 1, w);
  }
}

int main() {
  input();
  solve();
  return 0;
}


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

int main(){
  int a,b,c;
  cin >> a;
  b=a;
  while(b){
    c += (b%10);
    b /= 10;
  }
  if(a%c == 0) {
    cout << "Yes";
  }
  else cout <<"No";
  
} 

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

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] d = new int[n];

        for (int i = 0; i < n; i++) {
            d[i] = scanner.nextInt();
        }
        Arrays.sort(d);

        if(d[d.length/2 - 1] == d[d.length/2]){
            System.out.println(0);
        } else {
            System.out.println(d[d.length/2] - d[d.length/2 - 1]);
        }
    }
}


Measured memory_bytes: 50240
def main():
    n = int(input())
    res = ''
    d = 1
    base = []
    alp = 'abcdefghijklmnopqrstuvwxyz'
    for b in range(12):
        mod = n % 26
        if mod == 0:
            mod = 26
        res = alp[mod-1] + res
        if n - mod == 0:
            break
        else:
            n = int((n - mod) / 26)
            
    print(res)




if __name__ == '__main__':
    main()



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

int dfs(ll num, int mask, int n) {
	if (num > n) return 0;
	int ret = (mask == 7) ? 1 : 0;
	ret += dfs(num * 10 + 7, mask | 4, n);
	ret += dfs(num * 10 + 5, mask | 2, n);
	ret += dfs(num * 10 + 3, mask | 1, n);
	return ret;
}

int main(int argc, char const *argv[])
{
	int n; cin >> n;
	cout << dfs(0ll, 0, n) << endl;
	return 0;
}


Measured memory_bytes: 256
n = int(raw_input())
a = []
for i in range(n):
    a.append(int(raw_input()))

nprimes = 0
a = sorted(a)
while True:
    for d in range(2,10001):
        if d**2>a[0]:
            nprimes+=1
            del a[0]
            break
        elif a[0]%d==0:
            del a[0]
            break
    if len(a) <= 0:
        break

print nprimes

Measured memory_bytes: 6944
let N = Int(readLine()!)!
let tasks: [(Int, Int)] = (0..<N).map { _ in
    let input = readLine()!.characters.split(" ").map{Int(String($0))!}
    return (input[0], input[1])
}
var ans = "Yes"
var time = 0
for AB in tasks.sort({$0.1<$1.1}) {
    time += AB.0
    if time > AB.1 {
        ans = "No"
        break
    }
}
print(ans)

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

using namespace std;

int main() 
{ 
  int X;
  int count=0;
  cerr<<"Enter the no";
  cin>>X;
  for(int i=1; i<=X;i++)
     { if(X%i==0)
        count++;
     }
     if(count==2)
      cout<<X;

      else
      { 
        
        while(true)
        {count=0;
          X++;
          
          for(int i=1; i<=X;i++)
           { 
           if(X%i==0)
            count++;
           }
            if(count==2)
              { 
                cout<<X;
              return 0;}
        }
      }

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int myabs(int n)
{
	return n>0?n:-n;
}
 
int main()
{
	int n, i;
	scanf("%d", &n);
	int flag = 1;
	int t0 = 0, x0 = 0, y0 = 0;
	for(i=0;i<n;i++)
	{
		int t, x, y;
		scanf("%d%d%d", &t, &x, &y);
		int dt = myabs(t-t0);
		int dx = myabs(x-x0);
		int dy = myabs(y-y0);
		if((dx+dy)%2!=dt%2)
			flag = 0;
		else if((dx+dy)>dt)
			flag = 0;
		t0 = t;
		x0 = x;
		y0 = y;
	} 
	if(flag)
		printf("Yes\n");
	else
		printf("No\n");
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
inline void cmax(int &a,int b){if(a<b)a=b;}
inline void cmin(int &a,int b){if(b<a)a=b;}
const int N=2005,inf=1000000000;
vector<int>e[N];
int c[N],h[N],l[N];
char a[N];
void dfs(int v,int f){
	int i=e[v].size(),u,s=0,t=0,z=0;
	while(i--)if((u=e[v][i])!=f){
		dfs(u,v);
		z+=c[u];
		t+=(h[u]+=c[u]);
		cmax(s,h[u]+(l[u]+c[u]));
	}
	c[v]=z+a[v];
	h[v]=t;
	l[v]=max(s-t,t&1);
}
int main(){
	int n,i,v,u;
	scanf("%d%s",&n,a+1);
	for(i=1;i<=n;++i)a[i]^=48;
	for(i=1;i!=n;++i){
		scanf("%d%d",&v,&u);
		e[v].push_back(u);
		e[u].push_back(v);
	}
	v=inf;
	for(i=1;i<=n;++i){
		dfs(i,0);
		if(!l[i])cmin(v,h[i]);
	}
	if(v==inf){
		putchar('-');
		putchar('1');
	}else printf("%d",v>>1);
	return 0;
}

Measured memory_bytes: 512
from math import sqrt
while True:
    n = int(input())
    if n==0:
        break

    s = list(map(int, input().split()))
    a2=0
    m = sum(s)/n
    for i in range(n):
        a2 += (s[i]-m)**2
    a2 /= n
    a = sqrt(a2)
    print(a)




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

class unionfind {
  vector<int> p;
public:
  void init(int n) {
    for (int i = 0; i < n; i++) {
      p.push_back(i);
    }
  }
  
  void merge(int m, int n) {
    if (find(m) == find(n)) return;
    p.at(find(m)) = find(n);
  }
  
  int find(int n) {
    if (p.at(n) == n) return n;
    return p.at(n) = find(p.at(n));
  }
};

int main()
{
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < h; i++) cin >> s.at(i);
  unionfind t;
  t.init(h * w);
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (j < w - 1 && s.at(i).at(j) != s.at(i).at(j + 1)) {
        t.merge(i * w + j, i * w + j + 1);
      }
      if (i < h - 1 && s.at(i).at(j) != s.at(i + 1).at(j)) {
        t.merge(i * w + j, (i + 1) * w + j);
      }
    }
  }
  vector<pair<int, int>> c(h * w);
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      int root = t.find(i * w + j);
      if (s.at(i).at(j) == '#') {
        c.at(root).first++;
      } else {
        c.at(root).second++;
      }
    }
  }
  long total = 0;
  for (int i = 0; i < h * w; i++) {
    total += (long)c.at(i).first * c.at(i).second;
  }
  cout << total << endl;
}


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

double a,b,x;

int main() {
  cin >> a >> b >> x;
  if (x/a > (a*b)/2) {
    double theta=atan((2*b)/a-(2*x)/(a*a*a));
    cout << setprecision(15) << theta*180/acos(-1.0) << endl;
  }
  else {
    double theta=atan((a*b*b)/(2*x));
    cout << setprecision(15) << theta*180/acos(-1.0) << endl;
  }
}

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

int main(){
  int n,now=0;
  cin >> n;
  vector<int>a(n);
  for(int i=0;i<n;i++)
    cin >> a.at(i);
  int64_t ans=0;
  for(int i=0;i<n;i++){
    if(now>a.at(i))
      ans+=now-a.at(i);
    now=max(now,a.at(i));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3996
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
#include<map>
#include<vector>
#include<iomanip>
using namespace std;
typedef long long ll;
ll inf = 100000000;
ll v[205];
ll x[20000005];
ll a[10000005];
ll dp[10005][10005];
int dx[4] = { 1,-1,0,0 };
int dy[4] = { 0,0,1,-1 };
typedef pair<ll, ll> P;
double q[200005];
ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if ((a == b && b == c)||(a!=b&&a!=c&&b!=c)) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<vector>
#define inf 2147483647
#define rep(i,a,b) for(int i=a;i<b;i++)
#define  rr read()
#define ll long long
#define repb(i,a,b) for(int i=a;i<=b;i++)
#define CloseIo   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
int read()
{
    char ch = getchar();
	int x = 0, f = 1;
    while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
    while('0' <= ch && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
    return x * f;
}
ll gcd(ll a,ll b)
{
	return (!b)?a:gcd(b,a%b);
}
int main()
{
 ll l,r;
 CloseIo;
 ll j=1;
 vector<ll>v;
 while(2019*j<=4*1e9)
 {
 	v.push_back(2019*j);
 	j++;
 }
 cin >> l >> r;
 
 if(l/2019!=r/2019)
 {
 	cout<<0<<"\n";
 	return 0;
 }
 ll minx=inf;
 for(ll i=l;i<=r;i++)
 {
 	for(ll j=i+1;j<=r;j++)
 	minx=min(minx,(i*j)%2019);
 }
 cout<<minx;

}




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

int main(){
	string s;
	while(cin >> s && s != "-"){
		int m;
		cin >> m;
		while(m--){
			int h;
			cin >> h;
			string t;
			for(int i = h; i < s.size(); i++) t += s[i];
			for(int i = 0; i < h; i++) t += s[i];
			s = t;
		}
		cout << s << endl;
	}
}

Measured memory_bytes: 3176
local function gcd(a,b)
    if b>0 then
        return gcd(b,a%b)
    else
        return a
    end
end

local a,b=io.read("n","n")
local gcdab=gcd(a,b)

local counter=1
for i=2,math.sqrt(gcdab) do
    if gcdab%i==0 then
        while gcdab%i==0 do
            gcdab=gcdab//i
        end
        counter=counter+1
    end
end
print(gcdab>1 and counter+1 or counter)

Measured memory_bytes: 760
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <cstdint>
#include <unordered_set>
typedef long long int llint;

template <std::uint_fast64_t Modulus> class modint {
public:
  llint a;
  
  modint(llint x = 0){while(x<0){x+=Modulus;} a=x%Modulus; }
  llint &value() noexcept { return a; }
  const llint &value() const noexcept { return a; }
  modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  modint &operator/=(modint rhs) noexcept {
    llint exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
	*this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};

modint<1000000007> fac[100005] = {};

void init_C(std::vector<modint<1000000007> >& C, int r){

  fac[0] = 1;
  for(int i=1; i<100005; i++){
    fac[i] = fac[i-1]*i;
  }
  
  if(r==0){
    for(int i=0; i<C.size(); i++){
      C[i] = 1;
    }
  }

  
  for(int i=0; i<C.size(); i++){
    if(i<r){
      C[i] = 0;
    }else if(i==r){
      C[i] = 1;
    }else{
      C[i] = fac[i] / fac[i-r] / fac[r];
    }
  }
  
}

int main(void){

  int n, k;
  std::cin >> n >> k;
  std::vector<modint<1000000007> > C(n);

  std::vector<llint> A(n);
  for(int i=0; i<n; i++){
    std::cin >> A[i];
  }

  std::sort(A.begin(), A.end());

  if(k-2<0){
    std::cout << 0 << std::endl;
    return 0;
  }

  init_C(C, k-2);

  modint<1000000007> now = 0;
  modint<1000000007> total = 0;
  for(int i=0; i<n; i++){
    if(n-i-2 < 0) break;
    //std::cout << now.a << std::endl;
    now+=A[n-1-i];
    now+=(-A[i]);

    //std::cout << A[n-1-i] << " " << A[i]<< " " << now.a << " " << n-i-2 << " " << C[n-i-2].a << std::endl;
    
    total += now * C[n-i-2];
  }
  std::cout << total.a << std::endl;
  
  
  return 0;
}


Measured memory_bytes: 2560
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
typedef long long ll;


int main()
{
    int n;
    scanf("%d",&n);
    ll a[n];
    for(int i=0;i<n;i++)
    {
        scanf("%lld",&a[i]);
    }

    ll line=a[0];
    ll ans=0;
    
    for(int i=1;i<n;i++)
    {
        if(line>a[i])
        {
            ans=ans+line-a[i];
        }
        else
        {
            line=a[i];
        }
    }

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

    return 0;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define X real()
#define Y imag()
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using comd = complex<double>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

double CalcDist(comd p1, comd p2){
  return sqrt(pow(p1.X - p2.X,2.0) + pow(p1.Y -p2.Y,2.0));
}

template <typename T>
void out(deque < T > d)
{
  for(size_t i = 0; i < d.size(); i++)
  {
    debug(d[i]);
  }
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N,a,b,c;
  cin >> N;
  rep(i,N){
    cin >> a >> b >> c;
    if(a * a == b * b + c * c || b * b == a * a + c*c|| c * c == a*a+b*b)cout <<"YES"<<endl;
    else cout << "NO"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3084
a = input().split()
n = 1001
for i in range(int(a[0])):
    b = input().split()
    if int(b[0]) < n and int(b[1]) <= int(a[1]):
        n = int(b[0])

if n == 1001:
    print("TLE")
else:
    print(n)


Measured memory_bytes: 2940
# Aizu Problem 0059: Intersection of Rectangles
#
import sys, math, os, bisect

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


def overlap(x1, y1, x2, y2, x3, y3, x4, y4):
    if y3 > y2 or y4 < y1:
        return False
    if x4 < x1 or x3 > x2:
        return False
    return True

    
for line in sys.stdin:
    x1, y1, x2, y2, x3, y3, x4, y4 = [float(_) for _ in line.split()]
    print("YES" if not overlap(x1, y1, x2, y2, x3, y3, x4, y4) < 1e-10 else "NO")

Measured memory_bytes: 7528
#include<stdio.h>
#define MAX 100005
#define NIL -1
struct Node_struct{int p, l, r;}; /*p: 親(parent), l: 一番左の子(left child), r:右の兄弟(right sibling)*/
typedef struct Node_struct Node;
Node T[MAX];
int D[MAX];

void print(int u){
  int i, c;
  printf("node %d: parent = %d, depth = %d, ", u, T[u].p, D[u]);

  if(T[u].p==NIL) printf("root, ");
  else if(T[u].l==NIL) printf("leaf, ");
  else printf("internal node, ");

  printf("[");
  for (i=0, c = T[u].l; c != NIL; i++, c = T[c].r){
    if(i) printf(", ");
    printf("%d", c);
  }
  printf("]\n");

}

void calcDepth(int u, int p){
  D[u] = p;
  if(T[u].r != NIL) calcDepth(T[u].r, p);
  if(T[u].l != NIL) calcDepth(T[u].l, p+1);
}

int main(){
  int i, j, k;
  int n;
  int id, sib, child;
  int root = NIL;
  scanf("%d", &n);
  for(i=0; i<n; i++) T[i].p = T[i].l = T[i].r = NIL;

  for(i=0; i<n; i++){
    scanf("%d %d", &id, &k);
    for(j = 0, sib = NIL; j<k; j++){ //子を入力する (input children)                                                                                                                                        
      scanf("%d", &child);
      T[child].p = id;
      if(j == 0) T[id].l = child; //idの一番左の子 (the most left child of id)                                                                                                                              
      else T[sib].r = child; //左の兄弟に繋げる (connect to left sibling)                                                                                                                                   
      sib = child;//次の子供の左の兄弟 (the left sibling of the next child)                                                                                                                                 
    }
  }

  //根を求める (find the root)                                                                                                                                                                              
  for(i=0; i<n; i++){
    if(T[i].p == -1) root = i;
  }

  //それぞれのノードの深さを求める (find depth of each node)                                                                                                                                                
  calcDepth(root, 0);

  //出力 (output)                                                                                                                                                                                           
  for(i=0; i<n; i++) print(i);
 return 0;
}



Measured memory_bytes: 6484
function BFS(X,Y,C,A){
   var dx=[0,-1,1,0];
   var dy=[-1,0,0,1];
   var flag=true;
   var bfs=[[X,Y,C,A]];
   var obj={};
   obj[A.join("")]=true;
   while(true){
      if(flag==false)break;
      if(bfs.length==0){cnt=-1;break;}
      var leaf=bfs.shift();
      var x=leaf[0];
      var y=leaf[1];
      var c=leaf[2];
      var yx=leaf[3];
      for(var i=0;i<4;i++){
         var j=1;
         while(true){
            xx=x+dx[i]*j;
            yy=y+dy[i]*j;
            if(xx<0 || yy<0 || xx>=w || yy>=h)break;
            if(yx[yy][xx]===1 && j===1)break;
            if(yx[yy][xx]===3){cnt=c+1;flag=false;break;}
            if(yx[yy][xx]===1 && j>1){
               var copy=yx.map(function(v){return v.slice();});
               copy[yy][xx]=0;
               var str=copy.join("");
               if(obj.hasOwnProperty(str))break;
               obj[str]=true;
               if(c+1!=10)bfs.push([xx-dx[i],yy-dy[i],c+1,copy]);
               break;
            }
            j++;
         }
      }
   }
}
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
while(true){
   var wh=(Arr.shift()).split(" ").map(Number);
   var w=wh[0];
   var h=wh[1];
   if(w==0 && h==0)break;
   var YX=[];
   var s=[];
   for(var i=0;i<h;i++){
      var arr=(Arr.shift()).split(" ").map(Number);
      if(arr.indexOf(2)!=-1)s=[arr.indexOf(2),i];
      YX.push(arr);
   }
   var cnt;
   BFS(s[0],s[1],0,YX);
   console.log(cnt);
}

Measured memory_bytes: 97352