akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func fill(s []int, x int) {
	for i := 0; i < len(s); i++ {
		s[i] = x
	}
}

func main() {
	N := readInt()
	M := readInt()

	dp := make([]int, 1<<uint(N))
	fill(dp, math.MaxInt64)

	dp[0] = 0
	maxM := 0
	for i := 0; i < M; i++ {
		a := readInt()
		b := readInt()
		m := 0
		for i := 0; i < b; i++ {
			c := readInt()
			m |= 1 << uint(c-1)
		}
		for j := maxM; j >= 0; j-- {
			if dp[j] == math.MaxInt64 {
				continue
			}
			if j|m > maxM {
				maxM = j|m
			}
			if dp[j]+a < dp[j|m] {
				dp[j|m] = dp[j]+a
			}
		}
	}
	if dp[(1<<uint(N))-1] == math.MaxInt64 {
		fmt.Println(-1)
	} else {
		fmt.Println(dp[(1<<uint(N))-1])
	}
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}


Measured memory_bytes: 768
A, B, K = list(map(int, input().split()))
ansA = A
ansB = B
a = A - K
if a > 0:
    ansA = A - K
else:
    ansA = 0
    ansB = B - (K - A)
    if ansB < 0:
        ansB = 0


print(ansA, end="")
print(" ", end="")
print(ansB)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define isLeap(x) ((x % 400 == 0) || (x % 100 ? x % 4 == 0 : false))
#define FAST ios_base::sync_with_stdio(0), cin.tie(0)
#define LCM(a, b) (a / __gcd(a, b)) * b;
#define PI acos(-1.0)
#define inf 0x3f3f3f3f
#define fr(m,n,c) for(int i = m; i < n; i+=c)
const int N = 1e5+3;
int ara[N+2];
pair<int, int> pp[N];
vector<int> vv[4*N];
set<int> st;
map<ll, ll> mp;
int ara4[N+3], ara5[30];
int dp[N+3];
int main() {
	int n,k;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> ara[i];
	}
	for (int i = 0; i < n; i++) dp[i] = inf;
	dp[0] = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i+1; j <= k+i and j<n ; j++) {
			dp[j] = min(dp[j], dp[i] + abs(ara[i] - ara[j]));
			//cout << dp[j] << "  ";
		}
	}
	cout << dp[n - 1] << "\n";
}

Measured memory_bytes: 13748
S = input()

peaple = [0]*len(S)

l_count = 1
r_count = 1
update_r = 1

for i in range(1,len(S)):
  if S[i] == 'R' and S[i-1] == 'R':
      r_count+=1
  elif S[i] == 'L' and S[i-1] == 'R':
      add_peaple = r_count // 2
      if r_count % 2 == 0:
        peaple[i-1] += add_peaple
      else:
        peaple[i-1] += add_peaple + 1
      peaple[i] += add_peaple
      update_r = i-1
      r_count = 1
  elif S[i] == 'L' and S[i-1] == 'L':
      l_count+=1
  elif S[i] == 'R' and S[i-1] == 'L':
      add_peaple = l_count // 2
      if l_count % 2 == 0:
         peaple[update_r+1] += add_peaple
      else:
         peaple[update_r+1] += add_peaple + 1
      peaple[update_r] += add_peaple
      l_count = 1
      
add_peaple = l_count // 2
if l_count % 2 == 0:
    peaple[update_r+1] += add_peaple
else:
    peaple[update_r+1] += add_peaple + 1
peaple[update_r] += add_peaple
      
for idx, p in enumerate(peaple):
    if idx < (len(S)-1):
      print(p,end = ' ')
    else:
      print(p)

Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 998244353;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd_calc(T a, T b){ if(b){ return gcd_calc(b, a % b); }else{ return a; }}
template<class T> T gcd(T a, T b){ if(a < b) swap(a, b); return gcd_calc(a, b); }
template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
inline int at(int x, int k){ return (x >> k) & 1; }
random_device rnd;

string day[7] =  {"SUN", "MON","TUE","WED","THU","FRI","SAT"};

int main(){
    int N;
    cin >> N;
    fcout << ((N + 1) / 2) / double(N) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int N;
long long A,B;
vector<long long> H;

bool solve( long long a ) {
    vector<long long> X;
    for ( int i = 0; i < N; i++ ) {
        X.push_back( max( 0LL, H[i]-(B*a) ) );
    }
    long long b = 0;
    for ( int i = 0; i < N; i++ ) {
        b += X[i]/(A-B) + ( (X[i]%(A-B) == 0) ? 0 : 1 );
    }
    // cout << a << " " << b << endl;
    return b <= a;
    
}

int main() {
    
    cin >> N >> A >> B;
    H.resize(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> H[i];
    }
    
    long long ng = 0;
    long long ok = 1000000000;
    while( abs(ng-ok) > 1 ) {
        long long mid = (ng+ok) / 2;
        if ( solve(mid) ) {
            ok = mid;
        }
        else {
            ng=  mid;
        }
    }
    cout << ok << endl;

    return 0;
}

Measured memory_bytes: 2896
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
bool isprime(ll a){
  if(a==2)return 1;
  if(!(a&1))return 0;
  for(ll i=3;i*i<=a;i+=2)
    if(a%i==0)return 0;
  return 1;
}
ll mpow(ll base,ll exponent,ll modulus){
  if(modulus==1)return 0;
  long long result = 1;
  base=base%modulus;
  while(exponent){
    if(exponent%2 == 1)
    result=(result*base)%modulus;
    exponent=exponent>>1;
    base=(base*base)%modulus;
  }
  return result;
}
ll minv(ll a,ll mod){
  ll _gcd=gcd(a,mod);
  assert(_gcd==1);
  return mpow(a,mod-2,mod);
}


/*
ll ncr(ll N,ll K){
  if(N<K)return 0;
  if(K==0)return 1;
  if(N==0)return 0;

  ll den=1;
  for(ll i=1;i<=K;i++)den*=i;
  ll num=1;
  while(K--){
    num*=N;
    if(num%den==0){
      num/=den;
      den=1;
    }
    N--;
  }

  return num;
}
*/
ll n;
set<ll>s;
int main(){FAST;
cin>>n;
for(int i=1;i<=n;++i){
  ll x;cin>>x;
  s.insert(x);
}
if(s.size() == n)cout<<"YES";
else cout<<"NO";
return 0;
}

Measured memory_bytes: 9600
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	static final PrintStream out = System.out;
	static final Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	int MAX = 500;
	int INF = 1<<29;
	int[] dx = {1, 0, -1, 0};
	int[] dy = {0, 1, 0, -1};
	int[][] dp = new int[MAX][MAX];
	int H,W;

	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}

	void solve() {
		H = nextInt(); W = nextInt();
	    String[][] s = new String [H][W];
	    for (int i = 0; i < H; ++i) s[i] = next().split("");

	    // 初期化
	    for (int i = 0; i < MAX; ++i) {
	        for (int j = 0; j < MAX; ++j) dp[i][j] = INF;
	        dp[i][i] = 0; // これを忘れないように
	    }


	    // make graph
	    for (int x = 0; x < H; ++x) {
	        for (int y = 0; y < W; ++y) {
	            if (s[x][y].equals("#")) continue;
	            for (int dir = 0; dir < 4; ++dir) {
	                int nx = x + dx[dir], ny = y + dy[dir];
	                if (nx < 0 || nx >= H || ny < 0 || ny >= W || s[nx][ny].equals("#"))continue;
	                dp[id(x, y)][id(nx, ny)] = 1;
	                dp[id(nx, ny)][id(x, y)] = 1;
	            }
	        }
	    }

	    // Floyd--Warshall
	    int V = H*W;
	    for (int k = 0; k < V; ++k)
	        for (int i = 0; i < V; ++i)
	            for (int j = 0; j < V; ++j)
	            	dp[i][j] = Math.min(dp[i][j], dp[i][k] + dp[k][j]);

	    int res = 0;
	    for (int x = 0; x < H; ++x) {
	        for (int y = 0; y < W; ++y) {
	            if (s[x][y].equals("#")) continue;
	            for (int x2 = 0; x2 < H; ++x2) {
	                for (int y2 = 0; y2 < W; ++y2) {
	                    if (s[x2][y2].equals("#")) continue;
	                    res = Math.max(res, dp[id(x, y)][id(x2, y2)]);
	                }
	            }
	        }
	    }
	    out.println(res);
	}
	public int id (int x,int y) {
		return x * W + y;
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)a[i] = nextInt();
		return a;
	}
	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)a[i] = nextLong();
		return a;
	}
	public int nextInt() {
		return Integer.parseInt(next());
	}
	public long nextLong() {
		return Long.parseLong(next());
	}
	public String next() {
		return sc.next();
	}

	long gcd(long m,long n) {
		if (m<n) return gcd(n,m);
		if (n==0)return m;
		return gcd(n,m%n);
	}

	long lcm(long m, long n) {
	        return m * n / gcd(m, n);
	}
}

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

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		String[] st = r.readLine().split(" ");

		int s = Integer.parseInt(st[0]);
		int w = Integer.parseInt(st[1]);

		if (s <= w) {
			System.out.println("unsafe");
		} else {
			System.out.println("safe");
		}

		r.close();
	}
}

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

ll n,a,b,c,l[10],p[10],ans=1<<30;

void cal(){
	ll A,B,C;
	ll mp=0;
	A=B=C=0;
	for(int i=0;i<n;i++){
		if(p[i]==0){
			if(A){
				mp+=10;
			}
			A+=l[i];
		}
		else if(p[i]==1){
			if(B){
				mp+=10;
			}
			B+=l[i];
		}
		else if(p[i]==2){
			if(C){
				mp+=10;
			}
			C+=l[i];
		}
	}
	if(A==0||B==0||C==0){
		return ;
	}
	mp+=abs(A-a)+abs(B-b)+abs(C-c);
	ans=min(ans,mp);
}
void dep(int d){
	if(d==n){
		cal();
		return;
	}
	p[d]=0;dep(d+1);
	p[d]=1;dep(d+1);
	p[d]=2;dep(d+1);
	p[d]=3;dep(d+1);
}

int main() {
	cin>>n>>a>>b>>c;
	for(int i=0;i<n;i++){
		cin>>l[i];
	}
	dep(0);
	cout <<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repr(i, n) for(int i=n; i>=0; i--)
#define reps(i, s, e) for(int i=s; i<e; i++)
#define inf 1e10
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<lli>())
#define sz(x) x.size()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
using namespace std;
using ll = long long;
template<typename T> bool chmax(T &a, T &b){ if(a<b) { a=b; return 1; }}
template<typename T> bool chmin(T &a, T &b){ if(b<a) { a=b; return 1; }}
template<typename T> T gcd(T a, T b){ if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b){ return a*b/gcd(a, b); }
template<typename T> T vdebug(vector<T> v){ for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> T arrdebug(T arr[], int n){ rep(i, n){ cout << arr[i] << " "; } cout << endl; }
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int keta(ll num){ int k=0; while(num>0){ num/=10; k++; } return k; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};



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

    int n, ind;
    vector<ll> x(101, 0);
    vector<ll> y(101, 0);
    vector<ll> h(101, 0);
    cin >> n;
    rep(i, n){
        cin >> x[i] >> y[i] >> h[i];
        if(h[i]!=0) ind = i;
    }

    rep(cy, 101){
        rep(cx, 101){
            bool flg = true;
            ll height = h[ind]+abs(x[ind]-cx)+abs(y[ind]-cy);
            rep(i, n){
                ll tmph = max(0, int(height-abs(x[i]-cx)-abs(y[i]-cy)));
                if( tmph != h[i] ){
                    flg = false;
                    break;
                }
            }
            if(flg){
                cout << cx << " " << cy << " " << height << endl;
                return 0;
            }
        }
    }

    return 0;
}

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

typedef long long LL;

LL N;

int main() {
	scanf("%lld", &N);
	int X = sqrt(N);
	while ((LL)X * X < N) ++X;
	while ((LL)(X - 1) * (X - 1) >= N) --X;
	if (N >= (LL)X * (X - 1)) printf("0 0 %d 1 %lld %d\n", X, (LL)X * X - N, X);
	else printf("0 0 %d 1 %lld %d\n", X, (LL)X * (X - 1) - N, X - 1);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
//cervello|Phoenix
using namespace std;
#define ll long long int
#define eb emplace_back
#define mk make_pair
#define all(x) x.begin(),x.end()
#define mod 1000000007

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n,k; cin>>n>>k;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  sort(all(a));
  ll sum=0;
  for(int i=0;i<k;i++)
    sum+=a[i];
  cout<<sum<<"\n";
  return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<vector<int>> h(101, vector<int>(101, 0));
    vector<P> xy;
    rep(i, n){
        int x, y, h1;
        cin >> x >> y>> h1;
        h[x][y] = h1;
        xy.push_back(P(x, y));
    }
    ll cx, cy, hans;
    bool flag = false;
    rep(i, 101){
        if(flag) break;
        rep(j, 101){
            if(flag) break;
            cx = i; cy = j;
            for(P w:xy){
                int x0 = w.first, y0 = w.second;
                hans = h[x0][y0];
                hans += abs(cx - x0);
                hans += abs(cy - y0);
                if(hans == 0)continue;
                bool ok = true;
                for(P z:xy){
                    ll memo = hans;
                    memo -= abs(z.first - cx);
                    memo -= abs(z.second - cy);
                    memo = max(memo, (ll)0);
                    if(memo != h[z.first][z.second]) {
                        ok = false;
                        break;
                    }
                }
                if(ok){
                    flag = true;
                    break;
                }
            }
        }
    }
    cout << cx << " " << cy << " " << hans << endl;
    return 0;
}

Measured memory_bytes: 256
import numpy as np
MOD = 10 ** 9 + 7


def mult(N, A, B):
    C = np.zeros((N, N), np.int64)
    for n in range(N):
        C[n] = (A[n, :][:, None] * B % MOD).sum(axis=0) % MOD
    return C


def mat_power(A, N, k):
    if k == 0:
        return np.eye(N, dtype=np.int64)
    X = mat_power(A, N, k//2)
    X = mult(N, X, X)
    return mult(N, A, X) if k & 1 else X


n, k = map(int, input().split())
a = np.array([list(map(int, input().split())) for _ in range(n)], np.int64)
print(mat_power(a, n, k).sum() % MOD)


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

/*-------------------Define Start-------------------*/
typedef bool BL;    					// 布尔类型
typedef char SB;    					// 有符号1字节,8位
typedef unsigned char UB;    			// 无符号1字节,8位
typedef short SW;    					// 有符号短整型,16位
typedef unsigned short UW;    			// 无符号短整型,16位
typedef long SDW;    					// 有符号整型,32位
typedef unsigned long UDW;   			// 无符号整型,32位
typedef long long SLL;    				// 有符号长整型,64位
typedef unsigned long long ULL;			// 无符号长整型,64位
typedef char CH;    					// 单个字符
typedef float R32;    					// 单精度浮点数
typedef double R64;    					// 双精度浮点数

#define Rep(i, n) for (register SDW i = 0; i < (n); ++i)
#define For(i, s, t) for (register SDW i = (s); i <= (t); ++i)
#define rFor(i, t, s) for (register SDW i = (t); i >= (s); --i)
#define foreach(i, c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i)
#define ms0(a) memset(a,0,sizeof(a))
#define msI(a) memset(a,0x7f,sizeof(a))
#define LOWBIT(x) ((x)&(-x))

#define MP make_pair
#define PB push_back
#define ft first
#define sd second

#define pr(x) cout << #x << " = " << x << "  "
#define prln(x) cout << #x << " = " << x << endl

const ULL mod = 998244353;				//常用模数(可根据题目需要修改)
const ULL inf = 0x7fffffff;				//用来表示无限大
const ULL infLL = 0x7fffffffffffffffLL;	//用来表示无限大
/*-------------------Define End-------------------*/

const UDW maxN = 3e3 + 7;
SDW N, S;
SDW A[maxN];
SLL dp[maxN]; // dp[i][j] 表示当 R == i 时,和为 j 的序列个数 
SLL ans;

// Calculate x^y % p
inline SLL pow_mod(SLL x, SLL y, ULL p = mod){
    SLL ret = 1;
    while(y){
        if(y & 1) {
            ret = (ret * x) % p;
        }
        x = (x * x) % p;
        y >>= 1;
    }
    return ret;
} 

void input(){
	cin >> N >> S;
	For(i, 1, N) {
		cin >> A[i];
	}
}

void solve(){
	For(i, 1, N) {
		rFor(j, S, A[i]) {
			// 更新,不选和选两种情况 
			dp[j] = (dp[j] + dp[j - A[i]]) % mod;
		}
		if(A[i] <= S) {
			dp[A[i]] = (dp[A[i]] + i) % mod; // j == A[i]的情况需要特殊讨论 
		}
		ans = (ans + dp[S]) % mod;
	}
}

void output(){
	cout << ans << endl;
}

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


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <algorithm>
#include <numeric>
using namespace std;
const long long INF = 1LL<<40;

int main() {
    long long N, K; cin >> N >> K;
    vector<vector<long long> > s(N); // s[i] := 種類 i の美味しさの集合
    for (int i = 0; i < N; ++i) {
        long long t, d; cin >> t >> d; --t;
        s[t].push_back(d);
    }

    // 各種類について、美味しい順に並べる
    for (auto &v : s) {
        sort(v.begin(), v.end(), greater<long long>());
        if (v.empty()) v.push_back(-INF); // 番兵
    }

    // 「美味しさの最大値」の大きいネタ順
    sort(s.begin(), s.end(), [&](vector<long long> a, vector<long long> b) {
            return a[0] > b[0];});
 
    // まず K 種類選ぶ場合
    long long cur = 0;
    priority_queue<long long> que;
    for (int i = 0; i < K; ++i) {
        cur += s[i][0];
        for (int j = 1; j < s[i].size(); ++j) que.push(s[i][j]);
    }
    for (int i = K; i < N; ++i) for (int j = 0; j < s[i].size(); ++j) que.push(s[i][j]);

    // 走査
    long long res = cur + K*K;
    for (long long x = K-1; x >= 1; --x) {
        long long v = s[x][0];
        long long w = que.top();
        if (v < w) {
            que.pop(); cur += w;
            que.push(v); cur -= v;
        }
        res = max(res, cur + x*x);
    }
    cout << res << endl;
}

Measured memory_bytes: 11596
line = gets.split(' ')
a = line[0].to_f
b = line[1].to_f
x = line[2].to_f
s = x/a

if s>a*b/2 then
  s = a*b-s
  c = Math.atan((s*2/a)/a)
elsif s<=a*b/2 then
  c = Math.atan(b/(s*2/b))
end
p (c/Math::PI)*180

Measured memory_bytes: 1788
#include<stdio.h>
int main()
{
  int a,b,c,d;
  scanf("%d%d%d",&a,&b,&c);
  for(a;a<b+1;a++)
    {
      if(c%a==0)d++;
    }
  printf("%d\n",d);
  return 0;
}



Measured memory_bytes: 2108
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (ll)(1E9+7)
#define PI 3.1415926535897932384

template <class T>ostream &operator<<(std::ostream &o, const vector<T> &v)
{
	rep(i, v.size()) {
		o << (i > 0 ? " " : "") << v[i];
	}
	return o;
}



int main() {
	int w, h;
	int dx[8] = { -1, 0 , 1,-1,1,-1,0,1};
	int dy[8] = { -1,-1 ,-1, 0,0, 1,1,1};
	int input;
	while (1) {
		cin >> w >> h;
		if (w == 0) break;
		vector<vector<int>> field(h + 2, vector<int>(w + 2, 2));
		for (int i = 1; i < h + 1; i++) {
			for (int j = 1; j < w + 1; j++) {
				cin >> input;
				if (input == 1) {
					field[i][j] = 1;
				}
				else {
					field[i][j] = 0;
				}
			}
		}
		/*
		rep(i, h + 2) {
			rep(j, w + 2) {
				cout << field[i][j] << " " ;
			}
			cout << endl;
		}
		*/
		int ans = 0;
		for (int i = 1; i < h + 1; i++) {
			for (int j = 1; j < w + 1; j++) {
				if (field[i][j] == 1) {
					queue<pair<int, int>> que;
					que.emplace(i, j);
					ans++;
					while (!que.empty()) {
						pair<int, int> now = que.front();
						que.pop();
						if (field[now.first][now.second] == 0) continue;
						field[now.first][now.second] = 0;
						rep(k, 8) {
							if (field[now.first + dy[k]][now.second + dx[k]] == 1) {
								que.emplace(now.first + dy[k], now.second + dx[k]);
							}

						}
					}
				}
			}
		}
		cout << ans << endl;
	}
}



Measured memory_bytes: 2984
#include <bits/stdc++.h>
#define int long long
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a+MOD)%MOD)+((b+MOD)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define MOD 1000000007
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using Complex = complex<double>;


int N, K;
int h[100010];


signed main(){
    cin >> N >> K;
    rep(i, 0, N) cin >> h[i];

    sort(RNG(h, 0, N));

    int ans = INF;
    rep(i, 0, N-K+1) chmin(ans, h[i+K-1]-h[i]);

    cout << ans << endl;

    return 0;
}

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

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] l = new int[n];
		for (int i = 0; i < n; i++) {
			l[i] = sc.nextInt();
		}
		sc.close();

		Arrays.sort(l);
		long ans = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				int idx = binarySearch(l, l[i] + l[j] - 0.5);
				ans += idx - 1 - j;
			}
		}
		System.out.println(ans);
	}

	static int binarySearch(int[] array, double val) {
		int ng = -1;
		int ok = array.length;

		while (ok - ng > 1) {
			int mid = (ok + ng) / 2;
			if (array[mid] >= val) {
				ok = mid;
			} else {
				ng = mid;
			}
		}
		return ok;
	}
}


Measured memory_bytes: 26012
#include <algorithm>
#include <cctype>
#include <complex>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::to_string;
using std::vector;
using std::set;
using std::queue;
using std::priority_queue;

using std::min;
using std::max;
using std::sort;
using std::abs;

int main() {
    int sx, sy;
    int tx, ty;

    cin >> sx >> sy >> tx >> ty;

    const int dx = tx - sx;
    const int dy = ty - sy;

    string ans;

    for(int i = 0; i < dx; i++){
        ans.push_back('R');
    }
    for(int i = 0; i < dy; i++){
        ans.push_back('U');
    }

    for(int i = 0; i < dx; i++){
        ans.push_back('L');
    }
    for(int i = 0; i < dy; i++){
        ans.push_back('D');
    }

    ans.push_back('D');
    for(int i = 0; i < dx + 1; i++){
        ans.push_back('R');
    }
    for(int i = 0; i < dy + 1; i++){
        ans.push_back('U');
    }
    ans.push_back('L');

    ans.push_back('U');
    for(int i = 0; i < dx + 1; i++){
        ans.push_back('L');
    }
    for(int i = 0; i < dy + 1; i++){
        ans.push_back('D');
    }
    ans.push_back('R');

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int i, eye[4][2]={0};
	
	while(1){
		int j, flag=0;
		double a[2];
		
		for(i=0; i<40; i++){
			if(scanf(" %lf %lf", &a[0], &a[1]) == EOF)	 {
				flag=1;
				break;
			}
			
			for(j=0; j<2; j++){
				if(a[j] >= 1.1) eye[0][j]++;
				else if(a[j] >= 0.6) eye[1][j]++;
				else if(a[j] >= 0.2) eye[2][j]++;
				else eye[3][j]++;
			}
		}
		if(flag==1) break;
	}
	
	for(i=0; i<4; i++)
		printf("%d %d\n", eye[i][0], eye[i][1]);

	return 0;
}

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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

int main(){

    int n;
    cin >> n;
    vector<int> up(n,0);
    vector<int> down(n,0);
    vector<int> up_sum(n,0);
    vector<int> down_sum(n,0);
    for(int i = 0; i < n; i++){
        cin >> up[i];
        if(i > 0) up_sum[i] = up_sum[i-1];
        up_sum[i] += up[i];
    }
    for(int i = 0; i < n; i++){
        cin >> down[i];
        if(i > 0) down_sum[i] = down_sum[i-1];
        down_sum[i] += down[i];
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        int tmp;
        if(i > 0) tmp = up_sum[i] + down_sum[n-1] - down_sum[i-1];
        else tmp = up_sum[i] + down_sum[n-1];
        ans = max(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include<iostream>
using namespace std;
void optimize_cpp_stdio() {
    std::ios::sync_with_stdio(false);
    std::cout.tie(NULL);
    std::cin.tie(NULL);
}
int main(){
	optimize_cpp_stdio();
	int N, R;
	while(cin >> N >> R){
		if(N >= 10) cout << R << endl;
		else cout << R + 100 * (10 - N) << endl;
	} 
	return 0;
} 

Measured memory_bytes: 256
n = gets.to_i
xs = gets.split.map(&:to_i)

min = -1

xs_min = xs.min
xs_max = xs.max

(xs_min..xs_max).to_a.each do |i|
    tmp = xs.inject(0) { |result, num| result + (num - i) ** 2 }
    # puts "i: [#{i}], tmp: [#{tmp}]"
    min = tmp if min == -1 || tmp < min
end

puts min


Measured memory_bytes: 1788
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//配列はvector<>を使う：意味わからないエラーがなくなる。
//背反な事象にちゃんとわける
//チェックリストはマップを使う
//数が大きい時の比較はstring型で行う
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//円周率
const double PI = 3.14159265358979323846;

int main() {
	int a, b; cin >> a >> b;

	if (a + b < 24)cout << a + b << endl;
	else cout << (a + b) % 24 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
char m[99][2],z,y;
int main(){
	int s,n;
	while(true){
		cin>>s;
		if(s==0)break;
		rep(i,s)cin>>m[i][0]>>m[i][1];
		cin>>n;
		rep(i,n){
			cin>>z;
			y=z;
			rep(j,s)if(m[j][0]==z)y=m[j][1];
			cout<<y;
		}
		cout<<endl;
	}
	return 0;
}

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

int main() {
	int S = 0; rep(i, 4) { int a; scanf("%d", &a); S += a; }
	int T = 0; rep(i, 4) { int a; scanf("%d", &a); T += a; }
	cout << max(S, T) << endl;
	return 0;
}

Measured memory_bytes: 1204
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdio>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(int i = 0; i < (n); ++i)
typedef long long ll;


int main(void) {
  int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k;
  cin >> k;
  cout << a[k-1] << endl;

  return 0;
}


Measured memory_bytes: 888
n, k = map(int, input().split())
p = [ int(x) for x in input().split() ]
s = [ 0 ]

for key, v in enumerate(p):
    t = (v+1)*v//2/v
    s.append(s[key] + t)

ans = -1

for i in range(n-k+1):
    v = s[i+k]-s[i]
    ans = max(ans, v)

print(ans)

Measured memory_bytes: 24676
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template<class _T> static void getint(_T& a) {
	std::cin >> a;
}
template<class _T> static void getint(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void getint(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}
template <class _T> static _T tp_abs(_T a) {
	if (a < (_T)0) {
		a *= (_T)-1;
	}
	return a;
}

static void exec();

int main()
{
	exec();
	fflush(stdout);
	return 0;
}

static void exec()
{
	int N, L;
	getint(N, L);

	int core = -1;
	LLONG bfr = 0;
	std::vector<LLONG> ai(N);
	for (int i = 0; i < N; i++) {
		getint(ai[i]);
		if (bfr + ai[i] >= L) {
			core = i + 1;
		}
		bfr = ai[i];
	}
	if (core < 0) {
		printf("Impossible\n");
		return;
	}
	printf("Possible\n");

	for (int i = N - 1; i >= core; i--) {
		printf("%d\n", i);
	}
	for (int i = 1; i < core; i++) {
		printf("%d\n", i);
	}
}


Measured memory_bytes: 4052
package main

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

func main() {
	var N, M int
	fmt.Scanf("%d %d", &N, &M)
	NS := strconv.Itoa(N)
	reader := bufio.NewReader(os.Stdin)
	s := make([][]int, M+1, M+1)
	for i := 1; i <= M; i++ {
		line, _, _ := reader.ReadLine()
		dataS := strings.Split(string(line), " ")
		dataI := make([]int, len(dataS), len(dataS))
		for j := range dataS {
			dataI[j], _ = strconv.Atoi(dataS[j])
		}
		s[i] = dataI[1:]
	}
	line, _, _ := reader.ReadLine()

	p := strings.Split(string(line), " ")
	pi := make([]int, len(p), len(p))
	for i := range p {
		pi[i], _ = strconv.Atoi(p[i])
	}

	ans := 0
	for i := 0; i < int(math.Pow(2, float64(N))); i++ {
		t := strings.Split(fmt.Sprintf("0%0"+NS+"b", i), "")
		ok := true
		for j := 1; j <= M; j++ {
			total := 0
			for k := range s[j] {
				if t[s[j][k]] == "1" {
					total += 1
				}
			}
			if total%2 != pi[j-1] {
				ok = false
				break
			}
		}
		if ok {
			ans += 1
		}
	}
	fmt.Println(ans)

}

Measured memory_bytes: 896
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
const int N = 1e5 + 5;
ll n, m, ans, a[N], acc[N];
ll sum(int l, int r){
    if(l > r) return 0;
    if(!l) return acc[r];
    return acc[r] - acc[l - 1];
}
int between(int s, int e){
    if(a[0] > e || a[n - 1] < s) return 0;
    return (upper_bound(a, a + n, e) - a) - (lower_bound(a, a + n, s) - a);
}
bool ok(int mid){
    ll res = 0;
    for(int i = 0; i < n; i++){
        if(a[i] >= mid) res += n;
        else res += between(mid - a[i], 2 * N);
    }
    return res >= m;
}
int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> m;
    for(int i = 0; i < n; i++)
        cin >> a[i];
    sort(a, a + n);
    for(int i = 0; i < n; i++)
        acc[i] = a[i] + (i? acc[i - 1] : 0);
    ll s = 0, e = 2e5, mid, res = 2;
    while(s <= e){
        mid = s + e >> 1;
        if(ok(mid))
            s = mid + 1, res = mid;
        else
            e = mid - 1;
    }
    res++;
    for(int i = 0; i < n; i++){
        if(a[i] >= res)
            ans += n * a[i] + acc[n - 1], m -= n;
        else{
            if(a[0] > 2 * N || a[n - 1] < res - a[i]) continue;
            int l = lower_bound(a, a + n, res - a[i]) - a;
            int r = upper_bound(a, a + n, 2 * N) - a;
            ans += a[i] * (r - l) + sum(l, r - 1);
            m -= r - l;
        }
    }
    res--;
    cout << ans + m * res;
    return 0;
}


Measured memory_bytes: 5176
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fsp(x) fixed << setprecision(x)
#define xout cerr
const ll inf = LLONG_MAX;
const long double pi = acosl(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//const ll p = 1e9 + 7;
	//const ll p = 998244353;

	ll n;
	cin >> n;
	vector<ll> a(n);
	for (ll i = 0; i < n; i++) cin >> a[i];

	vector<ll> cnt(1e5 + 1, 0);
	ll sum = 0;
	for (ll i = 0; i < n; i++) {
		cnt[a[i]]++;
		sum += a[i];
	}

	ll q;
	cin >> q;
	while (q--) {
		ll b, c;
		cin >> b >> c;
		sum += (c - b) * cnt[b];
		cnt[c] += cnt[b];
		cnt[b] = 0;
		cout << sum << endl;
	}
}

Measured memory_bytes: 4692
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60


int main() {
    int K;
    cin >> K;
    vector<ll> a;
    vector< vector<ll> > b(11, vector<ll>());
    FOR(i, 1, 9) {
        a.push_back(i);
        b[0].push_back(i);
    }

    FOR(d, 1, 10) {
        for(ll x: b[d-1]) {
            for(ll next = max(x%10 - 1, 0ll); next <= min(x%10+1, 9ll); next++) {
                a.push_back(x * 10 + next);
                b[d].push_back(x * 10 + next);
            }
        }
    }

    sort(ALL(a));
    cout << a[K-1] << endl;

    return 0;
}

Measured memory_bytes: 20204
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int x, y;
    cin >> x >> y;
    vector<int> g(13);
    g[1] = g[3] = g[5] = g[7] = g[8] = g[10] = g[12] = 1;
    g[4] = g[6] = g[9] = g[11] = 2;
    g[2] = 3;
    if (g[x] == g[y]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3592
#include <iostream>
using namespace std;
int p[1000],a[1000],b[1000],c[1000],v[1000],r1,r2,r3,r,n;
int main() {
	while(true){
		cin>>r1>>r2>>r3;r=r1+r2+r3;if(r==0)break;
		cin>>n;
		for(int i=0;i<1000;i++)p[i]=2;
		for(int i=0;i<n;i++){
			cin>>a[i]>>b[i]>>c[i]>>v[i];
			if(v[i]==1){p[a[i]]=1;p[b[i]]=1;p[c[i]]=1;}
		}
		for(int i=0;i<r;i++){
			for(int j=0;j<n;j++){
				if(v[j]==0){
					if(p[a[j]]==1 && p[b[j]]==1)p[c[j]]=0;
					if(p[a[j]]==1 && p[c[j]]==1)p[b[j]]=0;
					if(p[b[j]]==1 && p[c[j]]==1)p[a[j]]=0;
				}
			}
		}
		for(int i=1;i<=r;i++)cout<<p[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 3088
#include <iostream>
using namespace std;
int shu[100000];
long long co[100001];
int main (){
  int n,m;
  cin>>n>>m;
  for(int i=0;i<n-1;i++) cin>>shu[i];
  for(int i=0;i<=n;i++) co[i]=0;
  int ima=0;
  for(int i=0;i<m;i++){
    int s,e;
    int a;
    cin>>a;
    s=min(ima+a,ima);
    e=max(ima+a,ima);
    co[s]++;
    co[e]--;
    ima+=a;
  }
  for(int i=1;i<n;i++) co[i]+=co[i-1];
  long long sumco=0;
  for(int i=0;i<n-1;i++) sumco+=co[i]*shu[i],sumco%=100000;
  cout<<sumco<<endl;
  return 0;
}

Measured memory_bytes: 2328
n,k = map(int,input().split())

comb = [[0 for j in range(i+1)] for i in range(n+1)]

for i in range(n+1):
    for j in range(i+1):
        if j == 0 or j == i:
            comb[i][j] = 1
        elif j < 0 or j > i:
            comb[i][j] = 0
        else:
            comb[i][j] = (comb[i-1][j] + comb[i-1][j-1])%(10**9+7)


for i in range(1,k+1):
    if n-k+1 < i:
        print(0)
    else:
        print((comb[n-k+1][i]*comb[k-1][i-1])%(10**9+7))

Measured memory_bytes: 83728
/*16D8103008D 西村悠輝　nissy0507barista  alds11_B*/ 

#include<iostream>

#define MAX 110
using namespace std;

int n,v,k,u; ///超点数、頂点番号、出次数、隣接
int d[MAX], f[MAX];///タイムスタンプ
int a[MAX][MAX];
int cnt=0;
int flag[MAX]; ///通ったかどうか

void dfs(int x) {

	if (flag[x] == 1)return;
	cnt++;
	d[x] += cnt;
	flag[x] = 1;
	for (int i = 1; i <= n; i++) {
		if (a[x][i] == 1 && flag[i] == 0) dfs(i);
	}
	cnt++;
	f[x] += cnt;

}

int main(void)
{
	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> v >> k;
		for (int j = 0; j < k; j++) {
			cin >> u ;
			a[v][u]=1;
		}
	}
	
	for (int i = 1; i <= n; i++) dfs(i);

	for (int i = 1; i <= n; i++) {
		cout << i << " " << d[i] << " " << f[i] << endl;
	}

	return 0;
}



Measured memory_bytes: 3096
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<algorithm>
using namespace std;
int num[3];
int main() {
	const double pi = 3.1415926535898;
	double r; cin>>r;
	cout<<fixed<<setprecision(6)<<r*r*pi<<" "<<2*r*pi<<endl;
	return 0;
}


Measured memory_bytes: 3264
/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void solve() {
	int n, k; cin >> n >> k;
    if(n <= k) {
        cout << min(n, abs(k - n)) << endl;
        return;
    } else {
        int m = n - k * ((n + k - 1) / k);
        cout << min(abs(m), abs(k - abs(m))) << endl;
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;


lint D;
lint decrease[26];
lint satis[365][26];
lint prv[26];

lint downscore(lint passed) {
	lint sum = 0;
	REP(i, 26) {
		sum += decrease[i] * (passed - prv[i]);
	}
	return -sum;
}

int main() {
	cin >> D;
	REP(i, 26) {
		cin >> decrease[i];
	}
	REP(i, D) {
		REP(j, 26) {
			cin >> satis[i][j];
		}
	}

	lint score = 0;
	REP(i, D) {
		lint maxv = -INF, max_idx = -1;
		REP(s, 26) {
			lint inst = 0;
			inst += satis[i][s];
			inst += downscore(i + 1);
			chmax(inst, 0ll);
			if (maxv < inst) {
				maxv = inst;
				max_idx = s;
			}
		}
		prv[max_idx] = i + 1;
		cout << 10;
		if (i != D - 1) cout << endl;
	}
}


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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  int n;
  cin >> n;
  vector<pair<int,int>> p(n);
  for(int i=0;i<n;i++) cin >> p[i].first >> p[i].second;
  sort(all(p));
  cout << p[n-1].first+p[n-1].second << endl;
  return 0;
}


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

int main() {
    vector<ll> v(5); for (int i = 0; i < 5; ++i) cin >> v[i];
    ll k; cin >> k;
    bool flag = true;
    for(int i = 0; i < 5; i++){
        for(int j = i + 1; j < 5; j++){
            if (abs(v[i] - v[j]) > k) flag = false;
        }
    }
    if(flag) cout << "Yay!" << endl;
    else cout << ":(" << endl;
}

Measured memory_bytes: 256
# include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  int s1,s2,s3,s4,n1,n2,n3,n4;
 cin>>s;
 s1=(s[0]-'0');
 s2=s[1]-'0';
 s3=s[2]-'0';
 s4=s[3]-'0';
 n1=(s1*10)+s2;
 n2=(s3*10)+s4;
if(n1>12&&n2<=12&&n2!=0)
    cout<<"YYMM"<<endl;
else if(n1<=12&&n2>12&&n1!=0)
    cout<<"MMYY"<<endl;
    else if(n1==0&&n2<=12&&n2!=0)
   cout<<"YYMM"<<endl;
   else if(n1<=12&&n2==0&&n1!=0)
    cout<<"MMYY"<<endl;
    else if((n1<=12&&n2<=12)&&(n1!=0&&n2!=0))
    cout<<"AMBIGUOUS"<<endl;
else
cout<<"NA"<<endl;

 return  0;
}


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

int main() {
    ll n, k, x;
    vector<ll> nums(1,0);
    cin >> n >> k;
    vector<bool> visited(n+1,0);
    for (ll i=0; i<n; i++) {
        cin >> x;
        nums.push_back(x);
    }
    x = 1;
    vector<ll> path, path2;
    while (!visited[x]) {
        visited[x] = true;
        path.push_back(x);
        x = nums[x];
    }
    ll y = x;
    path2.push_back(y);
    y = nums[y];
    while (y!=x) {
        path2.push_back(y);
        y = nums[y];
    }
    if (k<path.size()) cout << path[k];
    else {
        k-=(path.size()-path2.size());
        cout << path2[k%path2.size()];
    }
    return 0;
}

Measured memory_bytes: 9180
SIZE = 200
def main():
    X = int(input())
    for A in range(-SIZE, SIZE):
        for B in range(-SIZE, SIZE):
            if A ** 5 - B ** 5 == X:
                print(A, B)
                break
        else: continue
        break
    return

if __name__ == '__main__':
    main()


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

#define MAX(a,b) (a > b) ? a : b
#define MIN(a,b) (a < b) ? a : b
const int inf = 1000000000; // 10^9

int com_dsc_int(const void *n1,const void *n2){
   if(*(int*)n1 < *(int*)n2)return 1;
   else if(*(int*)n1 > *(int*)n2)return -1;
   else return 0;
}

int main(){
   int n,k;scanf("%d%d",&n,&k);
   int l[51];
   int ans=0;
   for(int i = 0;i < n;i++)scanf("%d",&l[i]);
   qsort(l,n,sizeof(int),com_dsc_int);
   for(int i = 0;i < k;i++)ans += l[i];
   printf("%d",ans);
}

Measured memory_bytes: 128