akhauriyash/Code-Regression huggingface dataset:
Public Class Main
    Public Shared Sub Main()
        Dim arr() As Integer = sc.IntArr()
        Dim A() As Integer = sc.IntArr()
        Dim H As Integer = arr(0)
        Dim N As Integer = arr(1)
        Dim accum As Integer = 0
        For i As Integer = n - 1 To 0 Step -1
          accum += A(i)
        Next
        Console.WriteLine(If(accum < h, "No", "Yes"))
    End Sub
End Class

' FastScanner start
Public Class sc
    Public Shared Function Str() As String
        Return Console.ReadLine()
    End Function
    Public Shared Function Int() As Integer
        Return Integer.Parse(Str())
    End Function
    Public Shared Function Lng() As Long
        Return Long.Parse(Str())
    End Function
    Public Shared Function Dbl() As Double
        Return Double.Parse(Str())
    End Function
    Public Shared Function StrArr(Optional separator As String = " ") As String()
        Return Str().Split(separator)
    End Function
    Public Shared Function IntArr(Optional separator As String = " ") As Integer()
        Return Array.ConvertAll(Of String, Integer)(StrArr(separator), AddressOf Integer.Parse)
    End Function
    Public Shared Function LngArr(Optional separator As String = " ") As Long()
        Return Array.ConvertAll(Of String, Long)(StrArr(separator), AddressOf Long.Parse)
    End Function
    Public Shared Function DblArr(Optional separator As String = " ") As Double()
        Return Array.ConvertAll(Of String, Double)(StrArr(separator), AddressOf Double.Parse)
    End Function
End Class
' FastScanner end

Measured memory_bytes: 16864
n, k = gets.split(" ").map(&:to_i)
sn = Array.new(n, false)
k.times do |i|
  d = gets.to_i
  a = gets.split(" ").map(&:to_i)
  a.each do |s|
    sn[s-1] = true
  end
end
puts sn.count(false)

Measured memory_bytes: 14400
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int count = 0;

        var flag = true;
        while (flag)
        {
            flag = false;
            for (int i = n - 1; i >= 1; i--)
            {
                if (a[i] < a[i - 1])
                {
                    var tmp = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = tmp;
                    flag = true;
                    count++;
                }
            }
        }


        Console.WriteLine(string.Join(" ", a));
        Console.WriteLine(count);
    }
}


Measured memory_bytes: 18300
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(ll i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln = '\n';

const int mx=200010;
const ll mod=1e9+7;

int main(){
  int n;
  cin >> n;
  vector<ll> a(n); 
  priority_queue<ll> q;
  rep(i,n){
    cin >> a[i];
    q.push(a[i]);
    q.push(a[i]);
  }
  sort(a.rbegin(),a.rend());
  ll ans = 0;
  q.pop();
  rep(i,n-1){
    auto p = q.top(); q.pop();
    ans += p;
  }
  cout << ans << ln;
  return 0;
}

Measured memory_bytes: 9028
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <map>
#include <vector>

#define div 1000000000+7

typedef long long ll;

using namespace std;

void solve(){
    int a, b, c;
    cin >> a >> b >> c;
    if(c >= a && c <= b){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

Measured memory_bytes: 256
def partition(A, p, r):
	x = A[r]
	i = p - 1

	for j in range(p, r):
		# A[j] > xの時は，何もせず，jを増加させるのみ
		if A[j] <= x:
			# A[j] <= x(A[j]がx以下の時)
			i += 1
			tmp = A[i]
			A[i] = A[j]
			A[j] = tmp
	tmp = A[i + 1]
	A[i + 1] = A[r]
	A[r] = tmp

	return i + 1

if __name__ == '__main__':
	#MAX = 100000
	#A = [0] * MAX

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

	q = partition(A, 0, n - 1)

	for i in range(n):
		if i:
			print(" ", end="")
		if i == q:
			print("[", end="")
		if i == n - 1:
			print(A[i])
		else:
			print(A[i], end="")
		if i == q:
			print("]", end="")


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

const long double PI = acos(-1);
 
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

int main(){
    int n, y;
    cin >> n >> y;

    for(int i = 0; i < n + 1; i++){
        for(int j = 0; j < n - i + 1; j++){
            int k = n - i - j;
            if(i * 1000 + j * 5000 + k * 10000 == y){
                cout << k << " " << j << " " << i << endl;
                return 0;
            }
        }
    }

    cout << -1 << " " << -1 << " " << -1 << endl;
    return 0;
}

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

using namespace std;
using std::vector;

#define ll long long
#define vi vector<int>
#define vl vector<long long>
#define vvi vector<vi>
#define pi  pair<int,int>
#define mp  make_pair
#define pb  push_back
#define MOD int(1e9) + 7
#define PAI  3.1415926535
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define chmax(x, y) x = max(x,y)
#define chmin(x, y) x = min(x,y)
#define pr(x) cout << x << endl
#define Endl endl
#define rep(i, n) for(int i = 0 ; i < n; i++)

const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int ddx[8] = {-1,0,1,-1,1,-1,0,1};
const int ddy[8] = {-1,-1,-1,0,0,1,1,1};
const int inf = 99999999;
const ll linf = 1LL << 62;

ll gcd(ll a,ll b){
  if(a < b)swap(a , b);
  if(a % b != 0) gcd(b, a%b);
  return b;
}

ll lcm(ll a,ll b){
  if(a < b)swap(a , b);
  return (a / gcd(a , b)) * b;
}

int main(){

  int n; cin >> n;
  vi v(n + 1, 0);
  rep(i, n) cin >> v[i];

  int ans = 0;
  
  while(1){
    int l = 0, r = 0;;
    int cnt = 0;
    int vmin = inf;

    for(int i = 0; i <= n; i++){
      if(v[i] != 0 and cnt == 0){
        cnt ++;
        l = i;
      }
      else if(v[i] == 0 and cnt == 1){
        r = i;     
        break;
      }
      if(v[i] != 0)
      chmin(vmin, v[i]);
    } 

    if(r == 0)
      break;

    ans += vmin;

    for(int i = l; i < r; i++)
      v[i] -= vmin;
    
  }

  pr(ans);

  return 0;
}


Measured memory_bytes: 256
#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 pq              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--)
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
*/
}

int32_t main()
{
	c_p_c();
/*	w(t)
	{
	}
	 */
	 int r;
	 cin>>r;
	 double ar= 2*M_PI*r;
	 cout<<ar<<endl;
	
	return 0;
}


Measured memory_bytes: 3800
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
int board[5][5];
signed main() {
	for(int i=0; i<3; i++) {
		for(int j=0; j<3; j++) {
			cin >> board[i][j];
		}
	}

	const int UB = 100;
	for(int i=0; i<=UB; i++) {
		for(int j=0; j<=UB; j++) {
			for(int k=0; k<=UB; k++) {
				bool ok = true;
				for(int x=0; x<3; x++) {
					vector<int> vec(3);
					vec[0] = board[x][0] - i;
					vec[1] = board[x][1] - j;
					vec[2] = board[x][2] - k;
					ok &= (vec[0] == vec[1] and vec[1] == vec[2] and vec[2] == vec[0]);
				}

				if(ok) {
					cout << "Yes" << endl;
					return 0;
				}
			}
		}
	}
	cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner std = new Scanner(System.in);
		while(true){
			int n = Integer.parseInt(std.next());
			int x = Integer.parseInt(std.next());
			int combo = 0;
			if(n==0 && x==0){
				break;
			}else{
				for(int i=1; i<=n; i++){
					for(int j=i+1; j<=n; j++){
						if(j<x-i-j && x-i-j<=n){
							combo++;
						}
					}
				}
			}
			System.out.println(combo);
		}
	}
}

Measured memory_bytes: 26204
char m[182];c;E(p){m[p]-49||--m[p]+E(p-1)+E(p+1)+E(p-13)+E(p+13);}main(i){for(;read(0,m+13,157)>155;printf("%d\n",c))for(c=0,i=12;++i<168;)m[i]-49||E(i)+c++;exit(0);}

Measured memory_bytes: 0
#include <iostream>
#include <iomanip>
#include <math.h>
#include <string>
using namespace std;

void Main() {
    // input
    u_int64_t A;
    string B;
    cin >> A >> B;

    string B_tmp = B.substr(0, 1) + B.substr(2);
    u_int64_t B_int = atoi(B_tmp.c_str());
    
    u_int64_t ans = (A * B_int) / 100;

    cout << ans << endl; 

    // translate


    // output

}

int main() {
    std::cout << std::fixed << std::setprecision(0);
    Main();
    return 0;
}


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

int main() {
  string s;

  while(getline(cin, s)) {
    if(s[0] == '.') break;
    bool b = true;
    int x = 0, y = 0;
    char c[1000];
    int top = 0;

    for(int i = 0; i < s.size(); i++) {
      if(s[i] == '(') {
	x++;
	c[top] = s[i];
	top++;
      }
      else if(s[i] == ')') {
	x--, top--;
	if(c[top] != '(') {
	  //cout << c[top] << ' ' << s[i] << endl;
	  b = false;
	  break;
	}
      }
      else if(s[i] == '[') {
	y++;
	c[top] = s[i];
	top++;
      }
      else if(s[i] == ']') {
	y--, top--;
	if(c[top] != '[') {
	  //cout << c[top] << ' ' << s[i] << endl;
	  b = false;
	  break;
	}
      }
      if(x < 0 || y < 0) {
	//cout << x << ' ' << y << endl;
	b = false;
	break;
      }
    }
    if(x == 0 && y == 0 && b) cout << "yes" << endl;
    else cout << "no" << endl;
  }
}

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

using namespace std;

int A[105];

int main() {
	int N, K;
	scanf("%d %d", &N, &K);
	for (int i = 0; i < K; i++) {
		int aux;
		scanf("%d", &aux);
		while (aux--) {
			int p;
			scanf("%d", &p);
			A[p - 1]++;
		}
	}
	int sol = 0;
	for (int i = 0; i < N; i++) {
		if (A[i] == 0) {
			sol++;
		}
	}
	printf("%d\n", sol);
}

Measured memory_bytes: 3788
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<list>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    map<int,long long int>m;
    vector<int>l;
    rep(i,n){
      long long int a,b,c;
      cin>>a>>b>>c;
      bool h=true;
      rep(i,l.size())if(a==l[i])h=false;
      if(h)l.pb(a);
      m[a]+=b*c;
    }
    //cout<<l.size()<<endl;
    int co=0;
    rep(i,l.size())if(m[l[i]]>=1000000){cout<<l[i]<<endl;co++;}
    if(!co)cout<<"NA"<<endl;
  }
}

Measured memory_bytes: 1288
#include <bits/stdc++.h>
using namespace std;
int a[3][3];
int main()
{
  int i,j,k;
 
  for(i=0;i<3;i++)
  {
      for(j=0;j<3;j++)
      cin>>a[i][j];
  }
  int q;
  cin>>q;
  while(q--)
  {
      int p;
      cin>>p;
       for(i=0;i<3;i++)
  {
      for(j=0;j<3;j++)
      {
          if(a[i][j]==p)
          a[i][j]=-1;
      }
  }
  }
  if((a[0][0]==-1 && a[1][1]==-1 && a[2][2]==-1 )|| (a[0][2]==-1 && a[1][1]==-1 && a[2][0]==-1)){
  cout<<"Yes";return 0;}
  else
  {int f;
      for(i=0;i<3;i++)
      { f=0;
          for(j=0;j<3;j++)
          {
              if(a[i][j]==-1)
              f++;
          }
          if(f==3)
          {
          cout<<"Yes";return 0;}
          
      }
     
      for(i=0;i<3;i++)
      {f=0;
       for(j=0;j<3;j++)
          {
              if(a[j][i]==-1)
              f++;
          }
          if(f==3)
          {
          cout<<"Yes";return 0;}
          
      }
  }
  cout<<"No";
}

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

int main() {
  int N;
  cin >> N;
  double ans = 0;

  rep(i,N){
    double x; string u;
    cin >> x >> u;
    if(u=="JPY") ans+=x;
    else ans+=x*380000;
  }
  cout << fixed << setprecision(8);
  cout << ans << endl;
}

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

#define long long long int
using namespace std;

// @author: pashka

int main() {
    ios::sync_with_stdio(false);

    long n, a, b;
    cin >> n >> a >> b;
    
    long x = n / (a + b);
    cout << x * a + min(a, n % (a + b));

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    #include<math.h>
    #define rep(i,n) for (int i = 0; i < (n) ; ++i)
    using namespace std;
    using ll = long long ;
    using P = pair<int , int> ;
    #define PI 3.14159265358979323846264338327950
    #define INF 1e18 
     
    int main(){
        int n, m ,k ;
        cin >> n >> m >> k ;
        vector<int> a (n) ;
        vector<ll> b (m) ;
        rep(i, n) cin >> a[i] ;
        rep(i, m) cin >> b[i] ;
        ll sum = 0 ;
        rep(i, n){
            sum += a[i] ;
        }
        rep(i, m - 1) {
            b[i+1] += b[i] ;
        }

        int ans = 0 ;
        int f = n ;
        ll o = k - sum ;

        if(o >= 0) {
            int pp = lower_bound(b.begin(), b.end(), o) - b.begin() ;
            if(b[pp] == o){
                 pp++ ;
            }
            ans= max(ans, pp + f) ;
        }
        for(int i = n - 1 ; i >= 0 ; i--){
            f-- ;
            sum -= a[i] ;
            ll t = k - sum ; 
            if(t <= 0){
                continue ;
            }
            else {
                int p = lower_bound(b.begin(), b.end(),t) - b.begin() ;
                if(b[p] == t){
                    p++ ;
                }
                ans= max(ans, p + f) ;
            }
        }
        cout << ans << endl ;
        return 0 ;
    }

Measured memory_bytes: 5536
#include <cstdio>

void process() {
    int H, W;

    do {
        scanf(" %d %d", &H, &W);
        if( H == 0 && W == 0 ) return;

        for(int i = 0; i < H; i++) {
            for(int j = 0; j < W; j++) putchar('#');
            putchar('\n');
        }
        putchar('\n');

    } while( true );
}

int main() {
    process();
    return 0;
}


Measured memory_bytes: 2696
N = int(input())
Plist = list(map(int,input().split()))
ctr = 0
 
for i in range(1,N-1):
  if (Plist[i+1] > Plist[i] > Plist[i-1]) or (Plist[i+1] < Plist[i] < Plist[i-1]):
    ctr += 1
 
print(ctr)

Measured memory_bytes: 3060
class PriorityQueue
  attr_reader :size

  def initialize(order: :asc)
    @size = 0
    @nodes = []
  end

  def empty?
    @size.zero?
  end

  def push(node)
    index = size

    while index > 0
      parent = (index - 1) / 2

      break if @nodes[parent].last <= node.last

      @nodes[index] = @nodes[parent]
      index = parent
    end

    @nodes[index] = node
    @size += 1
  end

  alias_method :<<, :push

  def pop
    node = @nodes.first
    @nodes[0], @nodes[size - 1] = @nodes[size - 1], nil
    @size -= 1
    index = 0

    while index * 2 + 1 < @size
      left = 2 * index + 1
      right = left + 1

      target = if @nodes[left] && @nodes[right]
                 @nodes[right].last < @nodes[left].last ? right : left
               elsif @nodes[left]
                 left
               elsif @nodes[right]
                 right
               end

      break if @nodes[target].last >= @nodes[index].last

      @nodes[index], @nodes[target] = @nodes[target], @nodes[index]
      index = target
    end

    node.first
  end

  def top
    @nodes.first
  end
end

N = gets.to_i
A = gets.split.map(&:to_i)

front = PriorityQueue.new
front_sum = 0

back = PriorityQueue.new(order: :desc)
back_sum = 0

N.times do
  v = A.shift
  front.push([v, v])
  front_sum += v

  w = A.pop
  back.push([w, -w])
  back_sum += w
end

f_sums = [front_sum]
b_sums = [back_sum]

A.each do |a|
  if front.top[0] < a
    front_sum -= front.pop
    front.push([a, a])
    front_sum += a
  end

  f_sums << front_sum
end

A.reverse_each do |a|
  if back.top[0] > a
    back_sum -= back.pop
    back.push([a, -a])
    back_sum += a
  end

  b_sums << back_sum
end

puts f_sums.zip(b_sums.reverse).map { |a, b| a - b }.max



Measured memory_bytes: 45716
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

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

    int ans=1e9;
    REP(i,N){
        int a; cin>>a;
        int cnt=0;
        while(a%2==0){
            a/=2,cnt++;
        }
        ans=min(ans,cnt);
    }
    cout<<ans<<endl;
    
}


Measured memory_bytes: 256
import numpy as np
n = int(input())
a = []
b = []
for i in range(n):
    c,d = map(int,input().split())
    e = np.array([c,d])
    if a!=[]:
        for j in range(len(a)):
            b.append(list(a[j]-e))
            b.append(list(e-a[j]))
    a.append(e)
f = []
for x in b:
    if x not in f:
        f.append(x)
m = -100
for i in range(len(f)):
    if b.count(f[i])>m:
        m = b.count(f[i])
m = max(0,m)
print(n-m)

Measured memory_bytes: 12660
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<ll, ll>
using namespace std;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
// 出力は.xで！！！！

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main(){
    int n,k; cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(all(a));
    mint miner,maxmer;
    miner=maxmer=0;

    combination c(n);
    rep(i,n){
        if(n-i-1>=k-1) miner+=c(n-i-1,k-1)*a[i];
        if(i>=k-1) maxmer+=c(i,k-1)*a[i];
    }
    mint ans=maxmer-miner;
    cout << ans.x << endl;


return 0;
}


Measured memory_bytes: 2176
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;
#define Int int64_t
using ll = long long;

int main() {

	int k;
	cin >> k;

	string s;
	cin >> s;
	int m;
	m = s.size();

	if (m <= k) {
		cout << s << endl;
	}
	else {
		for (int i = 0; i < k; i++) {
			cout << s.at(i);
		}
		cout << "..." << endl;
	}


}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define MAXN 1005
#define int long long
using namespace std;

int n, c;
int v[100005], x[100005];
int ida[100005], volta[100005];


main(){
    cin >> n >> c;

    for(int i = 1 ; i <= n; i++){
        cin >> x[i] >> v[i];
    }

    int sum = 0;
    int best = 0;
    for(int i = 1; i <= n; i++){
        sum += v[i] - (x[i]-x[i-1]);
        best = max(sum, best);
        ida[i] = best;
        //printf("indo _ Melhor ate %lld - %lld\n", i, ida[i]);
    }
    reverse(x+1, x+n+1);
    reverse(v+1, v+n+1);
    sum = 0;
    best = 0;
    x[0] = c;
    for(int i = 1; i <= n; i++){
        sum += v[i] - (x[i-1]-x[i]);
        best = max(sum, best);
        volta[i] = best;
        //printf("voltando _ Melhor ate %lld - %lld\n", i, volta[i]);
    }

    reverse(x+1, x+n+1);
    reverse(v+1, v+n+1);
    x[0] = 0;
    int ans = 0;
    for(int i = 0; i <= n; i++){
        ans = max( ans, max(ida[i], max( volta[i], ida[i] + volta[n-i] - min(x[i],c-x[i+1]) )) );
    }
    cout << ans << endl;

}


Measured memory_bytes: 3328
n,a,b = [int(x) for x in input().split()]

INF = (10**9 + 7)

def c(n,r,p):
    r = min(r,n-r)
    numer = 1
    denom = 1
    for i in range(1,r+1):
        numer = numer * (n+1-i) % p
        denom = denom * i % p
    return numer * pow(denom,p-2,p) % p

ans = pow(2,n,INF) - 1 - c(n,a,INF) - c(n,b,INF)

while ans < 0:
    ans += INF
print(ans)

Measured memory_bytes: 3064
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    ll N; cin >> N;
    int ans = 0;
    for(int i=2;i<=1000010;i++) 
    {
        int cur = 0;
        while (N % i == 0) 
        {
            cur++;
            N /= i;
        }
        for(int j=1;j<=10000;j++) 
        {
            if (cur < j) break;
            ans++; cur -= j;
        }
    }
    if (N > 1) ans++;
    cout << ans << nl;
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



Measured memory_bytes: 3656
#include <iostream>
#include <fstream>
#include <iomanip>
#include <math.h>
#include <limits.h>
#include <algorithm>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <string>
#include <string.h>
#include <sstream>
#include <ctime>

using namespace std;

#define eps 1e-12
#define pi 3.14159265358979323846
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define bgn begin
#define ll long long
#define ld long double
#define ull unsigned long long
#define ii pair<ll,ll>









ll n,m,x;



void solve()
{
	cin>>n>>m;
	x=1;
	for(int i=1;i<=m;i++)x*=2;
	x*=(100*(n-m))+(1900*m);
	cout<<x<<"\n";
}

int main()
{
	std::ios::sync_with_stdio(0);
	cin.tie(0);
#ifdef localProject
	freopen("in.txt","r",stdin);
#endif
	solve();
	return 0;
}

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

int main()
{
    int h[20];
    int n;
    cin >> n;
    for(int i = 0 ; i < n ; i ++){
        cin >> h[i];
    }
    int count = 1;
    for(int i = 1 ; i < n ; i++){
        bool a = true;
        for(int j = 0; j < i; j++){
            if(h[j] > h[i]) a = false;
        }
        if(a) count++;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int N,K,t;
    scanf("%d %d ",&N,&K);
    int p[1000];
    int i,j,sum=0;
    for(i=0;i<N;i++){
        scanf("%d",&p[i]);
    }


    for(i=0;i<N;i++){

            for(j=i+1;j<N;j++){
                    if(p[i]>p[j]){
                        t=p[i];
                        p[i]=p[j];
                        p[j]=t;

                    }

            }

    }
          for(i=0;i<K;i++){
                    sum=sum+p[i];
    }


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



    return 0;
}


Measured memory_bytes: 1736
def solve():
    n = int(input())
    
    P = set()
    for i in range(n):
        x,y,h = map(int,input().split())
        if h != 0:
            P.add((x,y,h))
    x,y,h = P.pop()
    if not P:
        return x,y,h
    for cx in range(101):
        for cy in range(101):
            H = h + abs(x-cx) + abs(y-cy)
            for p in P:
                if H != p[2] + abs(p[0]-cx) + abs(p[1]-cy):
                    break
            else:
                return cx,cy,H
        
if __name__ == '__main__':
    print(*(solve()))

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

using namespace std;

int main() {
	int n, m, x, y;
	cin >> n >> m >> x >> y;
	vector<int> a(n);
	vector<int> b(m);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	reverse(a.begin(), a.end());

	for (int j = 0; j < m; j++) {
		cin >> b[j];
	}
	sort(b.begin(), b.end());
	reverse(b.begin(), b.end());

	for (int i = x+1; i <= y; i++) {
		if (i > a[0] && i <= b[0]) {
			if (i > a.back() && i <= b.back()) {
				cout << "No War" << endl;
				return 0;
			}
		}
	}

	cout << "War" << endl;

	return 0;
}

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

const int mo=int(1e9+7);
struct edge{int s,t,n;}e[205];
int n,m,k,h[55],ans,C[205][205],dfn[55],low[55],tot,st[55],top,a[55];

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

int qpow(int a,int b)
{
	int x=a;  a=1;
	while (b)
		{
			if (b&1)  a=1LL*a*x%mo;
			x=1LL*x*x%mo,b>>=1;
		}
	return a;
}

int polya(int n)
{
	int s=0;
	for (int i=1; i<=n; i++)  s=(s+qpow(k,gcd(i,n)))%mo;
	return 1LL*s*qpow(n,mo-2)%mo;
}

void calc(int x,int y)
{
	int z,cnt=1,ecnt=0;
	a[x]=++a[0];
	do  a[z=st[top--]]=a[0],cnt++;  while (z!=y);
	if (cnt==2)  {ans=1LL*ans*k%mo;  return;}
	for (int i=1; i<=n; i++)
		if (a[i]==a[0])
			for (int j=h[i]; j; j=e[j].n)
				ecnt+=(a[e[j].t]==a[0]);
	ecnt/=2;
	if (cnt==ecnt)  ans=1LL*ans*polya(cnt)%mo;
	else  ans=1LL*ans*C[ecnt+k-1][k-1]%mo;
}

void tarjan(int x,int f)
{
	dfn[x]=low[x]=++tot,st[++top]=x;
	for (int i=h[x],y; y=e[i].t,i; i=e[i].n)
		if (y!=f)
			{
				if (!dfn[y])
					{
						tarjan(y,x),low[x]=min(low[x],low[y]);
						if (low[y]>=dfn[x])  calc(x,y);
					}else  low[x]=min(low[x],dfn[y]);
			}
}

void work()
{
	scanf("%d %d %d",&n,&m,&k),ans=1;
	for (int i=1,u,v,tot=0; i<=m; i++)
		{
			scanf("%d %d",&u,&v);
			e[++tot]=(edge){u,v,h[u]},h[u]=tot;
			e[++tot]=(edge){v,u,h[v]},h[v]=tot;
		}
	for (int i=0; i<=200; i++)
		{
			C[i][0]=1;
			for (int j=1; j<=i; j++)
				C[i][j]=(C[i-1][j]+C[i-1][j-1])%mo;
		}
	for (int i=1; i<=n; i++)
		if (!dfn[i])  tarjan(i,0);
	printf("%d",ans);
}

int main()
{
	work();
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,l;
  cin >> n >> l;
  vector<string> v;
  string s;
  int i,j,k;
  for(i=0;i<n;i++){
    cin >> s;
    v.push_back(s);
  }
  sort(v.begin(),v.end());
  for(i=0;i<n;i++) cout << v[i] ;
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long
#define ull unsigned long long
#define EPS 1e-8
using namespace std;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
const double pi = acos(-1.0);
int read()
{
	int ret=0;char ch=getchar();
	while(ch<'0'||ch>'9') ch=getchar();
	for(;ch>='0'&&ch<='9';ch=getchar()) ret=ret*10+ch-'0';
	return ret;
}
int ans,cnt1,cnt2,cnt3,cnt4,cnt5,cnt6,cnt7,cnt8,cnt9,n,x;
int main()
{
 	#ifdef TEST
	 	freopen("input.txt","r",stdin);
	#endif
	cnt1=cnt2=cnt3=cnt4=cnt5=cnt6=cnt7=cnt8=cnt9=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&x);
		if(x<=399)
		{
			cnt1++;
		}
		else if(x<=799)
		{
			cnt2++;
		}
		else if(x<=1199)
		{
			cnt3++;
		}
		else if(x<=1599)
		{
			cnt4++;
		}
		else if(x<=1999)
		{
			cnt5++;
		}
		else if(x<=2399)
		{
			cnt6++;
		}
		else if(x<=2799)
		{
			cnt7++;
		}
		else if(x<=3199)
		{
			cnt8++;
		}
		else
		{
			cnt9++;
		}
	}
	int cnt=0;
	if(cnt1)
	{
		cnt++;
	}
	if(cnt2)
	{
		cnt++;
	}
	if(cnt3)
	{
		cnt++;
	}
	if(cnt4)
	{
		cnt++;
	}
	if(cnt5)
	{
		cnt++;
	}
	if(cnt6)
	{
		cnt++;
	}
	if(cnt7)
	{
		cnt++;
	}
	if(cnt8)
	{
		cnt++;
	}
	ans=cnt;
	if(ans==0&&cnt9)
	{
		ans=1;
	}
	printf("%d %d\n",ans,cnt+cnt9);
	return 0;
}



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

int main() {
  int N,K;
  cin >> N >> K;
  vector<int> H(N);
  rep(i,N) cin >> H.at(i);
  sort(H.begin(),H.end());
  K = min(N,K);
  ll ans = 0;
  rep(i,K){
    H.pop_back();
  }
  rep(i,H.size()) ans += H.at(i);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {
	public static void main(String[] args) throws IOException{


		// 読み込み
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;

		line=br.readLine();

		String regex = ",";
		String result = line.replaceAll(regex," ");


		System.out.println(result);


	}
}


Measured memory_bytes: 21204
using System;
using System.Linq;
using System.Collections.Generic;
    
class Program
{
    static void Main(string[] args)
    {
        int K = int.Parse(Console.ReadLine());
        string S = Console.ReadLine();

        if(S.Length <= K) {
            Console.WriteLine(S);
        }else {
            Console.WriteLine(S.Substring(0,K) + "...");
        }
    }
}

Measured memory_bytes: 27532
#include <stdio.h>
int main(int argc, const char * argv[])
{
    int W, H;
    int i, j;
    while (1) {
        scanf("%d %d", &W, &H);
        if (W==0 && H==0) {
            break;
        }
        for (i=0; i<W; i++) {
            for (j=0; j<H; j++) {
                if (i==0) {
                    printf("#");
                }else if(j==0){
                    printf("#");
                }else if(i==W-1){
                    printf("#");
                }else if(j==H-1){
                    printf("#");
                }else{
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    
    return 0;
}



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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm(a, b) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};

vector<int> Div(int n) {
    vector<int> ret;
    for(int i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);

            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    LL n, p;
    cin >> n >> p;
    LL res = 1;
    for(LL i = 2; i * i <= p; ++i) {
        LL t = 0;
        while(p % i == 0) {
            ++t;
            p /= i;

        }
        LL cnt = t / n;
        for(int j = 0; j < cnt; ++j) {
            res *= i;

        }
    }
    if(n == 1) {
        res *= p;

    }
    cout << res << endl;
    return 0;
}



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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll n;
  cin >> n;
  ll x[100000];
  ll dist = 0;
  REP(i,n){
    cin >> x[i];
    if(i==0) dist += abs(x[i]);
    else dist += abs(x[i]-x[i-1]);
  }
  dist += abs(x[n-1]);
  REP(i,n){
    ll ans = dist;
    if(i==0){
      ans -= abs(x[i]);
      ans -= abs(x[i]-x[i+1]);
      ans += abs(x[i+1]);
    }else if(i==n-1){
      ans -= abs(x[i]);
      ans -= abs(x[i]-x[i-1]);
      ans += abs(x[i-1]);
    }else{
      ans -= abs(x[i]-x[i-1]);
      ans -= abs(x[i]-x[i+1]);
      ans += abs(x[i+1]-x[i-1]);
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 2048
/*
 * Copyright Narushima Hironori. All rights reserved.
 */
import java.io.*;
 
/**
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0106
 */
public class Main {
     
    static class Shop {
         
        int price, volume, discountedPrice, discountPer;
         
        Shop(int volume, int price, double discount, int per) {
            this.volume = volume;
            this.price = price;
             
            discountedPrice = (int) (price * per - price * per * discount);
            discountPer = per;
        }
         
        int calcPrice(int count) {
            int total = 0;
            while(count >= discountPer) {
                total += discountedPrice;
                count -= discountPer;
            }
            return total + price * count;
        }
         
        int maxBuyCount(int buyVolume) {
            return buyVolume / volume;
        }
         
    }
 
    Shop[] shops = {
            new Shop(200, 380, 0.20, 5),
            new Shop(300, 550, 0.15, 4),
            new Shop(500, 850, 0.12, 3)
    };
     
    public int calc(int volume) {
        if(volume % 100 != 0) {
            throw new IllegalArgumentException();
        }
         
        int[] buyCounts = new int[shops.length + 1];
        buyCounts[shops.length] = Integer.MAX_VALUE;
        calc(buyCounts, 0, volume);
        return buyCounts[shops.length];
    }
 
    void calc(int[] count, int shopIndex, int buyVolume) {
        if(shops.length == shopIndex) {
            if(buyVolume == 0) {
                int total = 0;
                for (int i = 0; i < shops.length; i++) {
                    total += shops[i].calcPrice(count[i]);
                }
                if(count[shopIndex] > total) {
                    count[shopIndex] = total;
                }
            }
        } else {
            Shop shop = shops[shopIndex];
            int maxBuyCount = shop.maxBuyCount(buyVolume);
            for (int buyCount = 0; buyCount <= maxBuyCount; buyCount++) {
                count[shopIndex] = buyCount;
                int nextBuyVolume = buyVolume - shop.volume * buyCount;
                calc(count, shopIndex + 1, nextBuyVolume);
            }
        }
    }
 
    public static void main(String[] args) throws IOException {
        Main calculator = new Main();
         
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        for (String l; (l = r.readLine()).length() > 0;) {
            int volume = Integer.parseInt(l);
            if(volume == 0) {
                break;
            }
            System.out.println(calculator.calc(volume));
        }
    }
 
 
}

Measured memory_bytes: 19700
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao Twitter/QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 10e16
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef long long int LL;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}

//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????统一类型        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    string s;cin>>s;
    string ss="";
    for(int i=0;i<s.length();i++){
        if(s[i]=='0')ss+="0";
        else if(s[i]=='1')ss+="1";
        else{
            if(ss!=""){
                string ss2="";
                for(int j=0;j<ss.length()-1;j++)
                    ss2+=ss[j];
                ss=ss2;
            }
        }
    }
    cout<<ss<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------








Measured memory_bytes: 764
rooms = []
rooms.append([[0 for i in range(10)] for j in range(3)])
rooms.append([[0 for i in range(10)] for j in range(3)])
rooms.append([[0 for i in range(10)] for j in range(3)])
rooms.append([[0 for i in range(10)] for j in range(3)])

num = int(raw_input())
for i in range(num):
    b,f,r,v = map(int, raw_input().split())
    rooms[b-1][f-1][r-1] += v

for number, room in enumerate(rooms):
    for row in room:
        print ' ' + ' '.join(map(str, row))
    if len(rooms) - 1 > number:
        print('####################')

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

using namespace std;

int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    long long x,k,d;
    cin >> x >> k >> d;
    if(x>0){
        long long steps = abs(x)/d;
        long long mind = x - (x/d)*d;
        if(abs(mind - d) < mind){
            mind = abs(mind-d);
            steps += 1;
        }
        if(k<steps){
            cout << abs(x - k*d);
        } 
        else{
            if((k-steps)%2) cout << min(abs(mind+d), abs(mind-d));
            else cout << mind;
        }
    }
    else{
        long long steps = abs(x)/d;
        long long mind = abs(x - (x/d)*d);
        if(abs(mind+d)<mind){
            mind = abs(mind+d);
            steps += 1;
        }
        if(k<steps) cout << abs(x+k*d);
        else{
            if((k-steps)%2) cout << min(abs(mind+d), abs(mind-d));
            else cout << mind;
        }
    }
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define fi first
#define se second
#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 srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
int X[20][10];
int main() {
  int n,d;
  cin >> n >> d;
  rep(i,n){
    rep(j,d)cin >> X[i][j];
  }
  int ans = 0;
  rep(i,n){
    srep(j,i+1,n){
      int sum = 0;
      rep(k,d){
        sum+=(X[i][k]-X[j][k])*(X[i][k]-X[j][k]);
      }
      int s = sqrt(sum);
      if(s*s == sum)ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3616
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = Integer.parseInt(sc.next());
        int w = Integer.parseInt(sc.next());
        char s[][] = new char[h][w];
        int p[][] = new int[h][w];
        for (int i = 0; i < h; i++) {
            s[i] = sc.next().toCharArray();
        }
        sc.close();
        for (int i = 0; i < h; i++) {
            int c = 0;
            int l = 0;
            for (int j = 0; j < w; j++) {
                if (s[i][j] == '.') {
                    if (c == 0) {
                        l = j;
                    }
                    c++;
                } else if (c > 0) {
                    for (int k = l; k < j; k++) {
                        p[i][k] = c;
                    }
                    c = 0;
                }
                if (j == w - 1 && c > 0) {
                    for (int k = l; k <= j; k++) {
                        p[i][k] = c;
                    }
                }
            }
        }
        int ans = 0;
        for (int j = 0; j < w; j++) {
            int c = 0;
            int l = 0;
            for (int i = 0; i < h; i++) {
                if (p[i][j] > 0) {
                    if (c == 0) {
                        l = i;
                    }
                    c++;
                } else if (c > 0) {
                    for (int k = l; k <= i; k++) {
                        ans = (ans < p[k][j] + c) ? p[k][j] + c : ans;
                    }
                    c = 0;
                }
                if (i == h - 1 && c > 0) {
                    for (int k = l; k <= i; k++) {
                        ans = (ans < p[k][j] + c) ? p[k][j] + c : ans;
                    }
                }
            }
        }
        System.out.println(ans - 1);
    }
}

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

using namespace std;

const int m = 1000;
vector<int> counts(m + 1);
const int mod = pow(10, 9) + 7;

void countDivisors(int n) {
  if (n <= 1) {
    return;
  }
  const int upper = n;
  for (int i = 2; i * i <= upper; i++) {
    while (n % i == 0) {
      n /= i;
      counts[i]++;
    }
  }
  if (n > 1) {
    counts[n]++;
  }
}

int main() {
  int x;
  cin >> x;
  for (int i = 2; i <= x; i++) {
    countDivisors(i);
  }
  long long r = 1;
  for (int i = 2; i <= m; i++) {
    r *= (counts[i] + 1);
    r %= mod;
  }
  cout << r << endl;
}


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

int main(){
  int h,m,s,a;
  while(cin>>h>>m>>s&&h!=-1){
    a=120*60-3600*h-60*m-s;
    h=a/3600;m=(a-h*3600)/60;s=a-h*3600-m*60;
    cout<<setfill('0')<<setw(2)<<h<<':'<<setw(2)<<m<<':'<<setw(2)<<s<<endl;
    a*=3;
    h=a/3600;m=(a-h*3600)/60;s=a-h*3600-m*60;
    cout<<setfill('0')<<setw(2)<<h<<':'<<setw(2)<<m<<':'<<setw(2)<<s<<endl;
  } 
  return 0;
}

Measured memory_bytes: 1168