akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

long long n, x, a[100000], e;

int main() {
    cin >> n >> x;
    for (int i = 0; i < n; ++i) cin >> a[i];
    for (int i = 1; i < n; ++i) {
        long long d = a[i-1] + a[i] - x;
        if (d < 0) continue;
        e += min(a[i], d);
        a[i] -= min(a[i], d);
        d = a[i-1] + a[i] - x;
        e += min(a[i-1], d);
        a[i-1] -= min(a[i-1], d);
    }
    cout << e << '\n';
    return 0;
}


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

int main(){
  int x;
  cin>>x;
  long long  kotae=0;
  for(int i=1;i<=31;i++){
    for(int j=2;j<=10;j++){
      long long kazu=pow(i,j);
      if(kazu<=x)kotae=max(kazu,kotae);
      else break;
    }
  }
  cout<<kotae;
  return 0;
}

Measured memory_bytes: 4032
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

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

	int n;
	cin >> n;

	if(n == 3){
		cout << "2 5 63" << endl;
		return 0;
	}
	
	if(n == 4){
		cout << "2 3 4 9" << endl;
		return 0;
	}

	if(n == 5){
		cout << "2 3 4 6 9" << endl;
		return 0;
	}

	multiset<ll> ms;
	ll sm = 0;
	ll t = 0;

	// 2 3 4 6 / 8 9 10 12 / ...
	for(int i = 0; i < n; i++){
		if(i % 4 == 0) t += 2;
		else if(i % 4 == 1) t += 1;
		else if(i % 4 == 2) t += 1;
		else if(i % 4 == 3) t += 2;
		ms.insert(t);
		sm += t;
	}

	if(sm % 6 == 2){
		ms.erase(8);
		ms.insert(30000);
	}else if(sm % 6 == 3){
		ms.erase(9);
		ms.insert(30000);
	}else if(sm % 6 == 5){
		ms.erase(9);
		ms.insert(29998);
	}

	for(ll x : ms){
		cout << x << " ";
	}
	cout << endl;
}


Measured memory_bytes: 1280
import java.util.Scanner

object Main extends App {

  val sc = new Scanner(System.in)
  val n = sc.nextInt()

  private val kuku: Seq[Int] = (1 to 9).flatMap(i => (1 to 9).map(_ * i))

  kuku.contains(n) match {
    case true => println("Yes")
    case false => println("No")
  }

}


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

using namespace std;
using ll = long long;

string s, t;
int nex[3003][3003];
int dp[3003][3003];
int find(int i, int j) {
  if (i >= s.size() || j >= t.size())
    return 0;
  if (dp[i][j] == -1) {
    dp[i][j] = 0;
    nex[i][j] = -1;
    if (s[i] == t[j]) {
      dp[i][j] = 1 + find(i + 1, j + 1);
      nex[i][j] = 2;
    }
    if (find(i + 1, j) > dp[i][j]) {
      dp[i][j] = dp[i + 1][j];
      nex[i][j] = 0;
    }
    if (find(i, j + 1) > dp[i][j]) {
      dp[i][j] = dp[i][j + 1];
      nex[i][j] = 1;
    }
  }
  return dp[i][j];
}

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

  cin >> s >> t;
  memset(dp, -1, sizeof(dp));
  find(0, 0);
  string ans = "";
  int i = 0, j = 0;
  while (i < s.size() && j < t.size() && nex[i][j] != -1) {
    if (nex[i][j] == 0) i++;
    if (nex[i][j] == 1) j++;
    if (nex[i][j] == 2) {
      ans += s[i];
      i++;
      j++;
    }
  }
  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 71040
#include <iostream>
#include <string>

constexpr int SIZE=(int)1e5+1;

int s[SIZE],t[SIZE];

int sol(int x,int y){

    if(x==2&&y==0)
        return 2;
    if(x==0&&y==2)
        return 0;

    if(x>y)
        return 0;
    else if(x==y)
        return 1;
    else
        return 2;
}

int main() {

    std::string in;

    std::cin>>in;

    for(int i=0;i<in.size();++i){

        s[i+1]=(in[i]=='A')? 0 : 1;

        s[i+1]+=s[i];
    }

    std::cin>>in;

    for(int i=0;i<in.size();++i){

        t[i+1]=(in[i]=='A')? 0 : 1;

        t[i+1]+=t[i];
    }

    int q;

    std::cin>>q;

    int a,b,c,d;

    int x1,y1,x2,y2;

    for(int i=0;i<q;++i){

        std::cin>>a>>b>>c>>d;

        y1=s[b]-s[a-1];

        x1=b-a+1-y1;

        y2=t[d]-t[c-1];

        x2=d-c+1-y2;

        x1%=3;

        x2%=3;

        y1%=3;

        y2%=3;

        if(sol(x1,y1)==sol(x2,y2))
            std::cout<<"YES"<<std::endl;
        else
            std::cout<<"NO"<<std::endl;
    }

    return 0;
}

Measured memory_bytes: 1664
#include <iostream>

using namespace std;
typedef long long ll ;

int main()
{
    ll a,b ;
    cin >> a >> b ;
    ll sum=a+b ;
    if (a%3==0 || b%3==0 || sum%3==0)
    {
        cout << "Possible" << endl ;
    }
    else
    {
        cout << "Impossible" << endl ;
    }
    return 0;
}


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

const int N=3009,mod=998244353;
int dp[N][N],a,b,c,d;

int fn(int i,int j){
    if(i==a and j==b)return 1;
    if(dp[i][j]!=-1)return dp[i][j];
    dp[i][j]=0;
    if(i>a)dp[i][j]=(dp[i][j]+j*fn(i-1,j)%mod)%mod;
    if(j>b)dp[i][j]=(dp[i][j]+i*fn(i,j-1)%mod)%mod;;
    if(i>a and j>b)dp[i][j]+=mod-(i-1)*(j-1)%mod*fn(i-1,j-1)%mod;
    dp[i][j]%=mod;
    return dp[i][j];
}
int32_t main(){
    ios::sync_with_stdio(0),cin.tie(0);
    memset(dp,-1,sizeof dp);
    cin >> a >> b >> c >> d;
    cout << fn(c,d);
}

Measured memory_bytes: 74716
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
ll w,h,x,y;
 
int main()
{
    scanf("%lld %lld %lld %lld",&w,&h,&x,&y);
    printf("%.6f ",w*h*1.0/2);
    if(x*2==w && y*2==h)
        printf("1\n");
    else
        printf("0\n");
    return 0;
}

Measured memory_bytes: 256
/* ex4_3
   moka223711 */

#include <stdio.h>

int main(void){
    // 高さがn(n+1)/2[m](n=1,2,…,999)の999本の塔が西から順に立っている
    // 雪に埋もれていない塔の高さから雪が何m積もっているか求める
    // 雪に埋もれていない西側の塔の高さをh_west、東側の塔の高さをh_eastとする
    
    int h_west, h_east, dif, ans;
    scanf("%d %d", &h_west, &h_east);
    
    // 東側の塔の高さから西側の塔の高さを引き、差difを求める
    dif = h_east - h_west;
    
    // 差difから西側の塔の高さを求めて、雪に埋もれていない塔の高さを引くことで
    // 雪が何m積もっているかを求める
    ans = dif * (dif - 1) / 2 - h_west;
    printf("%d", ans);
    
    return 0;
}


Measured memory_bytes: 128
S = input()
T = input()
#print(S, T)
if S == T:
    print('Yes')
    exit()
if len(S) != len(T):
    print('No')
    exit()

freqs = {}
freqt = {}

def calc_freq(S, freq):
    for s in S:
        if s not in freq:
            freq[s] = 1
        else:
            freq[s] += 1

calc_freq(S, freqs)
calc_freq(T, freqt)
# print(freqs)
# print(freqt)
anss = [freqs[x] for x in freqs]
anst = [freqt[x] for x in freqt]
anss.sort()
anst.sort()
# print(anss)
# print(anst)

if anss == anst:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 41676
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long N;
    cin >> N;
    ll count = 0;
    ll digit = to_string(N).size();
    std::vector<std::vector<ll>> origin(11, vector<ll>());
    origin[1] = {3, 5, 7};
    vector<ll> elem = {3, 5, 7};
    ll isDone = false;
    for(size_t dig=1;dig<=9; dig++)
    {
        for(const auto& org:origin[dig])
        {
            for(const auto& e:elem)
            {
                ll candidate =  org * 10 + e;
                origin[dig+1].push_back(candidate);
                if(N >= candidate)
                {
                    string _candidate = to_string(candidate);
                    bool isThree = false;
                    bool isFive = false;
                    bool isSeven = false;
                    for(const auto& c:_candidate)
                    {
                        if(c == '3') isThree = true;
                        if(c == '5') isFive = true;
                        if(c == '7') isSeven = true;
                        if(isThree && isFive && isSeven)
                        {
                            count++;
                            break;
                        }
                    }
                }
            }
        }
    }

    cout << count << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 1212
N=int(input())
H=list(map(int,input().split()))
ans=0
count=0
for i in range(N-1):
  if H[i]>=H[i+1]:
    count+=1
  else:
    if count>ans:
      ans=count
    count=0
if count>ans:
  ans=count
print(ans)

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

using namespace std;

/* alias */
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
using vpii = vector<pii>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

/* repetition */
#define rep(i, n) for(int i=0;i<(n);++i)
#define repe(i, n) for(int i=0;i<=(n);++i)
#define repr(i, n) for(int i=(n-1);i>=0;--i)
#define repre(i, n) for(int i=(n);i>=0;--i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FORE(i, a, b) for(int i=(a);i<=(b);++i)
#define FORR(i, a, b) for(int i=(b-1);i>=(a);--i)
#define FORRE(i, a, b) for(int i=(b);i>=(a);--i)

int main() {
    string S,ans;
    cin >> S;
    if (S == "Sunny"){
        ans = "Cloudy";
    }
    else if (S == "Cloudy")
    {
        ans = "Rainy";
    }
    else
    {
        ans = "Sunny";
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
h, w, a, b = map(int, input().split())

mod = 10**9+7
fac = [1]
for n in range(1, h+w):
	fac.append(fac[n-1]*n%mod)

def modpow(a,n,mod):
	r=1
	while n>0:
		if n&1:	r = r*(a%mod)
		a *= a%mod
		n >>= 1
	return r

invfac = [0] * (h+w)
invfac[h+w-1] = modpow(fac[h+w-1], mod-2, mod)
for n in range(h+w-2, -1, -1):
	invfac[n] = invfac[n+1] * (n+1) % mod

def com(a,b):
	return fac[a] * invfac[b] * invfac[a-b] % mod

r=0
for i in range(w-b):
	r += com( h-a-1+b+i, b+i ) * com( a-1+w-b-i-1, a-1 ) % mod
	r %= mod

print(r)


Measured memory_bytes: 18964
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(long long i=0; i<x;i++)
#define mod 1000000007
#define INF 10000000000000000
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


struct UnionFind {
	vector<int> par;
  
  UnionFind(int N): par(N){
  	for(int i=0;i<N;i++) par[i] =i;
  }
};





int main(){
  ios::sync_with_stdio(false);
  
  ll N;
  cin>>N;
  
  ll ans = INF;
  
  for(ll i = 1;i<=1000000;i++){
  	if(N>=i && N%i ==0) ans = min(ans,i-1+N/i-1);
  }
  
  cout<<ans;
  
}

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


int main(){
	cin >> N >> K;
	vector<int>to(N);
	rep(i, N){
		cin >> A;
		to[i] = A - 1;
	}	
	vector<int> a(N , 0);	
		vector<int> b(1,0);
		b[0] = 0;
		int c = 0;		
		while (a[b[c]] == 0){
			a[b[c]] = 1;			
			b.push_back(to[b[c]]);
			c++;
		}		
		
		int f = b.size();
		if (K < f){
			cout << b[K] + 1 << endl;			
		}
		else{	
			auto e = find(b.begin(), b.end(), b[c]);
			b.erase(b.begin(), e);
			int g = b.size();

			long long d = (K - (f - g)) % (c - (f - g));
			cout << b[d] + 1 << endl;
		}
	return 0;
}

Measured memory_bytes: 5800
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string str;
    cin>>str;
    if(str=="abc"||str=="acb"||str=="bac"||str=="bca"||str=="cab"||str=="cba")
        return cout<<"Yes"<<endl,0;
    else
        return cout<<"No"<<endl,0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    ll N, M; cin >> N >> M;
    for(ll a=M/N; a>=1; a--){
        if(M%a == 0){
            cout << a << endl;
            return 0;
        }
    }
}

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

int main(int argc, char const *argv[]) {
  int n;
  vector<pair<int,int> > v;
  scanf("%d",&n);
  for(int i=0;i<n;i++)
  {
    int a;
    scanf("%d",&a);
    v.push_back(make_pair(a,i+1));
  }
  sort(v.begin(),v.end());
  for(int i=0;i<n;i++)
  {
    printf("%d ",v[i].second);
  }
  return 0;
}


Measured memory_bytes: 1780
# ABC131D - Megalomania
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    arr = sorted(
        [list(map(int, input().rstrip().split())) for _ in range(n)], key=lambda x: x[1]
    )
    task_sum = 0
    for i, j in arr:
        task_sum += i
        if task_sum > j:
            print("No")
            break
    else:
        print("Yes")


if __name__ == "__main__":
    main()

Measured memory_bytes: 55240
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll n;
    cin >> n;

    vl a(n);
    vl rui(n+1);
    rep(i, n) {
        cin >> a[i];
        rui[i+1] = rui[i] + a[i];
    }
    sort(all(rui));
    
    vl count(n+1);  // count[i] : ruiのi番目(iは0-index)に小さい数の個数
    ll t1 = rui[0];
    ll k1 = 0;
    rep(i, n+1) {
        if(t1 < rui[i]) {
            t1 = rui[i];
            k1++;
        }
        count[k1]++;
    }

    ll ans = 0;
    rep(i, n+1) {
        ll x = count[i];
        ans += x*(x-1)/2;
    }

    /*cout << "\n";
    rep(i, n+1) {
        cout << count[i] << " ";
    }*/

    out(ans);
    re0;
}

Measured memory_bytes: 4992
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(), b = sc.nextInt();
		//int x=sc.nextInt();//,k=sc.nextInt();
		long sum=0,count=0,flag=0,max=-999999,min=99999;
		//long[] array=new long[n];
		//String s=sc.next();//,t=sc.next();
		String buff;
		//String[] array = new String[n];
		for(int i=a;i<=b;i++) {
			buff=String.valueOf(i);
			//System.out.println(buff);
			if(buff.charAt(0)==buff.charAt(4)&&buff.charAt(1)==buff.charAt(3))count++;
		}

		System.out.println(count);
	}
	public static int sample(int n) {
		return n;
	}

}


Measured memory_bytes: 26580
import java.math.BigDecimal;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        BigDecimal atemp = sc.nextBigDecimal();
        BigDecimal b = sc.nextBigDecimal();
        String ans = atemp.multiply(b).toString();
//        System.out.println(ans);
//        System.out.println(ans.indexOf('.'));
        int index = ans.indexOf('.');
        System.out.println(ans.substring(0,index));

//        int n = sc.nextInt();
//        BigInteger ans = BigInteger.ONE;
//        BigInteger limit = new BigInteger("1000000000000000000");
//        for(int i=0;i<n;i++){
//            BigInteger val = sc.nextBigInteger();
//            ans = ans.multiply(val);
////            if(ans.compareTo(BigInteger.ZERO)==0){
////                break;
////            }
////            if(ans.compareTo(limit)==1){
////                break;
////            }
//        }
//        System.out.println(ans);
//        if(ans.compareTo(limit)==1){
//            System.out.println(-1);
//        }
//        else{
//            System.out.println(ans);
//        }
    }
}


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


// ABC132C - Divide the Problems
// https://atcoder.jp/contests/abc132/tasks/abc132_c
void ABC132C() {
	int N;
	cin >> N;
	
	vector<int> d(N);
	for (int i = 0; i < N; i++)
	{
		cin >> d[i];
	}
	sort(d.begin(), d.end());


	int a = d[N / 2 - 1];//前半部分の一番最後の数値
	int b = d[N / 2];    //後半部分の一番最初の数値

	//aより大きく、かつb以下の数値の数が求めるKの値
	int ans = 0;
	for (int i = a+1; i <= b; i++)
	{
		ans++;
	}

	cout << ans << endl;

}

int main() {
	ABC132C();

	return 0;
}

Measured memory_bytes: 640
package main

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

const MaxBuf = 200100
var buf []byte
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf,MaxBuf)
}

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

func readInt64() int64 {
	sc.Scan()
	r,_ := strconv.ParseInt(sc.Text(),10,64)
	return r
}

func readInt() int {
   sc.Scan()
   r,_ := strconv.Atoi(sc.Text())
   return r
}

func readFloat64() float64 {
	sc.Scan()
	r,_ := strconv.ParseFloat(sc.Text(),64)
	return r
}

func main() {
	a := big.NewInt(readInt64())
	b := big.NewInt(readInt64())
	x := new(big.Int)
	y := new(big.Int)
	var z big.Int
	g := z.GCD(x,y,a,b).Int64()

	ans := 1
	g2 := g
	for i := int64(2); i * i <= g ; i++ {
		if g2 % i == 0 {
			ans++
			for g2 % i == 0 { g2 /= i }
		}
	}
	if g2 != 1 {ans++}
	fmt.Println(ans)
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++) 
#define fs first
#define sc second
#define _GLIBCXX_DEBUG

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}

template <class S>
void print(vector<S> &v){for(ll i=0; i<(ll)v.size(); i++){
		cerr << v[i] << ' ';
	}
	cerr << endl;
}
template <class S>
void print(vector<vector<S>> &v) {
  	for (ll i = 0; i < (ll)v.size(); i++) {
    	for (ll j = 0; j < (ll)v[i].size(); j++) {
      		cerr << v[i][j] << ' ';
    	}
    	cerr << endl;
  	}
}


int main(){
	int n,m; cin >> n >> m;
	vector<pair<int,int>> ba;
	Rep(n){
		int a,b; cin >> a >> b;
		ba.push_back(make_pair(b,a));
	}
	ll ans =  0;
	set<int> r;
	rep(i,m){
		r.insert(i+1);
	}
	sort(ba.rbegin(), ba.rend());
	for(auto p: ba){
		int a = p.sc;
		int b = p.fs;
		if(r.lower_bound(a) != r.end()){
			r.erase(*r.lower_bound(a));
			ans += (ll)b;
			if(r.empty()) break;
		}
	}
	cout << ans << endl;;
}

Measured memory_bytes: 5748
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [n,m,k] <- getIntList
    let x = null [()|p <- [0..n], q <- [0..m], p*m + q*n - 2*p*q == k]
    putStrLn $ if x then "No" else "Yes"

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

using namespace std;

int main(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int hoge;
		cin>>hoge;
		n-=hoge;
	}

	cout<<(n>=0 ? n : -1)<<endl;

	return 0;
}


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


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n, k;
	cin >> n >> k;
	vector<ll> h(n);
	vector<P> res(n);
	rep(i, n) cin >> h[i];
	sort(h.begin(), h.end());
	ll ans = 1000000000;
	for (int i = 0; i < n - k + 1; ++i) {
		ans = min(ans, h[i + k - 1] - h[i]);
	}
	cout << ans << endl;
	return 0;
}

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

int main()
{ ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   int n,i,max=-1,x,c=1,ind,maxim=-1;
    cin>>n;
   int a,look[100010]={0},j;
     for(i=0;i<n;i++)
     { cin>>a;
       look[a]++;
       if(a-1>=0)
        look[a-1]++;
        if(a+1<100001)
        look[a+1]++;
        if(a>max)
        max=a;
     }
      for(i=0;i<=max;i++)
       if(look[i]>maxim)
         maxim=look[i];
         cout<<maxim;
       
      
    
	return 0;
	
}

Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <cstring>
using namespace std;

#define REP(i,n,m) for(int i=n;i<m;i++)
#define MAX 11 //³µÈ¢A±
#define MAX_N 100002

double dp[MAX_N][MAX];
double per[MAX];
double ans[MAX_N];

int main(void){
	int n;
	double sum = 0;

	REP(i,1,MAX) per[i] = pow(0.5,i-1);
	dp[1][1] = 1.0;

	REP(i,1,MAX_N){
		REP(j,1,MAX){
			if(dp[i][j] > 0){
				sum += dp[i][j] * per[j];
				if(j == 1){
					dp[i+1][j+1] += dp[i][j]; //ÅÍK¸æêé
				}
				else{
					dp[i+1][1] += dp[i][j] * (1 - per[j]); //æêÈ¢ÌJÚ
					dp[i+1][j+1] += dp[i][j] * per[j]; //æêéÌJÚ
				}
			}
		}

		ans[i] = sum;
	}

	while(cin>>n,n) printf("%.3lf\n",ans[n]);

	return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<vl> vvl;

double EPS=1e-9;
int INF=1000000005;
long long INFF=1000000000000000005ll;
double PI=acos(-1);
int dirx[8]={ -1, 0, 0, 1, -1, -1, 1, 1 };
int diry[8]={ 0, 1, -1, 0, -1, 1, -1, 1 };
const ll MOD = 1000000007;

ll sum() { return 0; }
template<typename T, typename... Args>
T sum(T a, Args... args) { return a + sum(args...); }

#define DEBUG fprintf(stderr, "====TESTING====\n")
#define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
#define OUT(x) cout << x << endl
#define OUTH(x) cout << x << " "
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define READ(x) for(auto &(z):x) cin >> z;
#define FOR(a, b, c) for (int(a)=(b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a)=(b); (a) <= (c); ++(a))
#define FORD(a, b, c) for (int(a)=(b); (a) >= (c); --(a))
#define FORSQ(a, b, c) for (int(a)=(b); (a) * (a) <= (c); ++(a))
#define FORC(a, b, c) for (char(a)=(b); (a) <= (c); ++(a))
#define EACH(a, b) for (auto&(a) : (b))
#define REP(i, n) FOR(i, 0, n)
#define REPN(i, n) FORN(i, 1, n)
#define MAX(a, b) a=max(a, b)
#define MIN(a, b) a=min(a, b)
#define SQR(x) ((ll)(x) * (x))
#define RESET(a, b) memset(a, b, sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define PERMUTE next_permutation
#define TC(t) while (t--)
#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define what_is(x) cerr << #x << " is " << x << endl;

void solve() {

}

int main()
{
    FAST_INP;
//    #ifndef ONLINE_JUDGE
//    freopen("input.txt","r", stdin);
//    freopen("output.txt","w", stdout);
//    #endif

//    int tc; cin >> tc;
//    TC(tc) solve();
	int n, x, y;
	cin >> n;
//	vector<pll> v;
//	REP(i,n){
//		cin >> x >> y;
//		v.pb({x,y});
//	}
//	ll r0=INFF, c0=INFF;
//	sort(ALL(v), [r0,c0](pll& a, pll& b){
//		return abs(r0-a.fi)+abs(c0-a.se) < abs(r0-b.fi)+abs(c0-b.se);
//	});
//	ll ans=0;
//	REP(i,n){
//		FOR(j,i+1,n){
//			MAX(ans, (abs(v[i].fi-v[j].fi)+abs(v[i].se-v[j].se)));
//		}
//	}
//	OUT(ans);
//	cout << v[n-1].fi << " " << v[n-1].se << endl;
//	OUT((abs(v[0].fi-v[n-1].fi)+abs(v[0].se-v[n-1].se)));
	int miA=INT_MAX, miB=INT_MAX, mxA=INT_MIN, mxB=INT_MIN;
	REP(i,n){
		cin >> x >> y;
		MIN(miA,x+y);
		MAX(mxA,x+y);
		MIN(miB,x-y);
		MAX(mxB,x-y);
	}
	OUT(max({
		abs(mxA-miA),
		abs(mxB-miB)
	}));
    return 0;
}

Measured memory_bytes: 3644
// https://atcoder.jp/contests/abc143/tasks/abc143_e

#include <bits/stdc++.h>
using namespace std;
#define watch(x) cerr << (#x) << " is " << (x) << endl;
#define endl '\n' 
#define int long long

const int maxn = 305;
const int INF = LLONG_MAX/2-100;

int N, M, L, Q;
int cost[maxn][maxn], cost2[maxn][maxn];

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

    cin >> N >> M >> L;

    for(int i = 1; i <= N; i++) {
        for(int j = 1; j <= N; j++) {
            cost[i][j] = INF;
            if(i == j) cost[i][j] = 0;
        }
    }
    for(int i = 1; i <= M; i++) {
        int a, b, c;
        cin >> a >> b >> c;

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

    for(int k = 1; k <= N; k++) {
        for(int i = 1; i <= N; i++) {
            for(int j = 1; j <= N; j++) {
                cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
            }
        }
    }

    for(int i = 1; i <= N; i++) {
        for(int j = 1; j <= N; j++) {
            if(cost[i][j] <= L) {
                cost2[i][j] = 1;
            } else if(i == j) {
                cost2[i][j] = 0;
            } else {
                cost2[i][j] = INF;
            }
        }
    }

    for(int k = 1; k <= N; k++) {
        for(int i = 1; i <= N; i++) {
            for(int j = 1; j <= N; j++) {
                cost2[i][j] = min(cost2[i][j], cost2[i][k] + cost2[k][j]);
            }
        }
    }
    // for(int i = 1; i <= N; i++) {
    //     for(int j = 1; j <= N; j++) {
    //         cerr << cost[i][j] << " ";
    //     }
    //     cerr << endl;
    // }
    // for(int i = 1; i <= N; i++) {
    //     for(int j = 1; j <= N; j++) {
    //         cerr << cost2[i][j] << " ";
    //     }
    //     cerr << endl;
    // }

    cin >> Q;

    while(Q--) {
        int s, t;
        cin >> s >> t;

        if(cost2[s][t] == INF) {
            cout << -1 << endl;
        } else {
            cout << cost2[s][t]-1 << endl;
        }
    }
}


Measured memory_bytes: 5104
n = int(input())

def koch(n,x1,y1,x2,y2):
    if n == 0:
        print(x1,y1)
    else:
        a = 3**(1/2)/2
        p1 = koch(n-1,x1,y1,(2*x1+x2)/3,(2*y1+y2)/3)
        if abs(y1 - y2) <= 10**(-4):
            s = koch(n-1,(2*x1+x2)/3,(2*y1+y2)/3,(x1+x2)/2,y1+(x2-x1)*a/3)
            u = koch(n-1,(x1+x2)/2,y1+(x2-x1)*a/3,(x1+2*x2)/3,(y1+2*y2)/3)
        else:
            if x1 < x2 and y1 < y2:
                s = koch(n-1,(2*x1+x2)/3,(2*y1+y2)/3,x1,(y1+2*y2)/3)
                u = koch(n-1,x1,(y1+2*y2)/3,(x1+2*x2)/3,(y1+2*y2)/3)
            elif x1 < x2 and y1 > y2:
                s = koch(n-1,(2*x1+x2)/3,(2*y1+y2)/3,x2,(2*y1+y2)/3)
                u = koch(n-1,x2,(2*y1+y2)/3,(x1+2*x2)/3,(y1+2*y2)/3)
            elif x1 > x2 and y1 < y2:
                s = koch(n-1,(2*x1+x2)/3,(2*y1+y2)/3,x2,(2*y1+y2)/3)
                u = koch(n-1,x2,(2*y1+y2)/3,(x1+2*x2)/3,(y1+2*y2)/3)
            else:
                s = koch(n-1,(2*x1+x2)/3,(2*y1+y2)/3,x1,(y1+2*y2)/3)
                u = koch(n-1,x1,(y1+2*y2)/3,(x1+2*x2)/3,(y1+2*y2)/3)
        t = koch(n-1,(x1+2*x2)/3,(y1+2*y2)/3,x2,y2)
        return p1,s,u,t

X = koch(n,0,0,100,0)
print(100,0)



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

int main() {
  string s, t;
  cin >> s >> t;
  int n = sz(s), m = sz(t);
  vector<vector<int>> is(26);
  rep(i,n) is[s[i]-'a'].push_back(i);
  rep(i,n) is[s[i]-'a'].push_back(i+n);
  ll ans = 0;
  int p = 0; // after p
  rep(i,m) {
    int c = t[i]-'a';
    if (sz(is[c]) == 0) {
      puts("-1");
      return 0;
    }
    p = *lower_bound(is[c].begin(), is[c].end(), p)+1;
    if (p >= n) {
      p -= n;
      ans += n;
    }
  }
  ans += p;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1724
#include<stdio.h>
int main()
{
int i,j,flag1=0,flag2=0,flag3=0,len,count=0;
char a[1000];
gets(a);
for(i=0;a[i];i++){}len=i;
if(a[0]=='A'){flag1=1;count++;}
for(i=2;i<len-1;i++){if(a[i]=='C'){flag2=1;}}
for(i=1;i<len;i++){if(a[i]<=90)count++;}
if(count==2){flag3=1;}
if(flag1&&flag2&&flag3){printf("AC\n");}
else{printf("WA\n");}
return 0;


}


Measured memory_bytes: 128
// includes, macros {{{
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <climits>
#include <cassert>
#include <functional>
#include <numeric>
#include <limits>
using namespace std;

#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)

#define rep(i, s, e)    for (int i = (s); i < (int)(e); i++)
//#define PB(e) push_back(e)
//#define MP(a, b) make_pair(a, b)

// for debug
#define kita            cout << "kita\n"
#define print2(i, n)    cout << (i) << ": " << (n) << endl
#define print3(i, j, n)     cout << "(" << (i) << ", " << (j) << ") : " << (n) << endl
#define print4(i, j, n, m)  cout << "(" << (i) << ", " << (j) << ") : " << (n) << ", " << (m) << endl
#define print_mat(mat, h, w) for(int i=0;i<(h);i++){for(int j=0;j<(w);j++){cout << mat[i][j] << " ";}cout << endl;}
 
typedef long long ll;
typedef unsigned long long ull; // }}}

int H, W;
char mmap[10][10];
char mmap2[10][10];
bool ans=true;

void solve(int ni, int nj){
    mmap2[ni][nj] = '#';
    
    if(ni == H-1 && nj == W-1){
        return;
    }
    if(ni+1 < H && nj+1 < W){
        if(mmap[ni+1][nj] == '#' && mmap[ni][nj+1] == '#'){
            ans=false;
        }
    }
    if(ni+1 < H){
        if(mmap[ni+1][nj] == '#'){
            solve(ni+1, nj);
        }
    }
    if(nj+1 < W){
        if(mmap[ni][nj+1] == '#'){
            solve(ni, nj+1);
        }
    }
    return;
}

int main(){
    cin >> H >> W;
    for(int i=0;i<H;i++){
        string s;
        cin >> s;
        for(int j=0;j<W;j++){
            mmap[i][j] = s[j];
            mmap2[i][j] = '.';
        }
    }
    solve(0, 0);
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(mmap[i][j] != mmap2[i][j]){
            //kita;
                ans=false;
            }
        }
    }
    if(ans){
        cout << "Possible" << endl;
    }else{
        cout << "Impossible" << endl;
    }
    return 0;
}


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

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var seqV = Console.ReadLine().Split().Select(x => double.Parse(x)).ToArray();

        Array.Sort(seqV);

        var mean = seqV[0];
        for (int i = 1; i < seqV.Length; ++i)
        {
            mean = (mean + seqV[i]) / 2;
        }
        Console.WriteLine(mean);
    }
}


Measured memory_bytes: 13396
#include<iostream>

using namespace std;

int main() {
	int x,y, i;
	while (1) {
		cin >> x;
		cin >> y;
		if (x == 0 && y == 0)break;
		if (x < y) {
			cout << x << " " << y << endl;
		}
		else {
			cout << y << " " << x << endl;
		}
		i++;
	}
}

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

using namespace std;

int main() {
    int H, W, h, w;
    int row;
    cin >> H >> W;
    cin >> h >> w;
    row = H - h;
    cout << (H*W - W*h) - (row*w) << endl;


    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int n, i;
  int num[10];

  i = 0;
  while(scanf("%d", &n) != EOF)
    {
      if(n == 0)
	{
	  i--;
	  printf("%d\n", num[i]);
	}
      else
	{
	  num[i] = n;
	  i++;
	}
    }

  return 0;
}

Measured memory_bytes: 600
a,b,n=map(int,input().split())
if n<b:
    x=n
    ans=int(a*x/b)-a*(int(x/b))
    print(ans)
else:
    c=n//b
    x1=n
    x2=c*b-1
    ans1=(a*x1)//b-a*(x1//b)
    ans2=(a*x2)//b-a*(x2//b)
    print(max(ans1,ans2))


Measured memory_bytes: 9076
h, w = map(int, input().split())
A = [list(input()) for _ in range(h)]

temp = []
for i in range(h):
    if A[i] == ['.' for _ in range(w)]:
        temp.append(i - len(temp))
h -= len(temp)
for i in temp:
    A.pop(i)

B = []
for i in range(w):
    B_row = []
    for v in A:
        B_row.append(v[i])
    B.append(B_row)

temp = []
for i in range(w):
    if B[i] == ['.' for _ in range(h)]:
        temp.append(i - len(temp))
for i in temp:
    B.pop(i)
w -= len(temp)

C = []
for i in range(h):
    C_row = []
    for v in B:
        C_row.append(v[i])
    C.append(C_row)

for r in C:
    for c in r:
        print(c, end='')
    print()

Measured memory_bytes: 4724
#include <bits/stdc++.h>
#include <cassert>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
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; }
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll,ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int N,M,C;
int B[22];
int A[22][22];
int main() {
  cin >> N >> M >> C;
  rep(i,M)cin>>B[i];
  rep(i,N) rep(j,M) cin >> A[i][j];
  int ans = 0;
  rep(i,N) {
    int sum = 0;
    rep(j,M) {
      sum += A[i][j] * B[j];
    }
    sum += C;
    if (sum > 0) ans ++;
  }
  cout << ans <<endl;
  return 0;
}

Measured memory_bytes: 3636
fun main(args: Array<String>) {
    val (H, W) = readLine()!!.split(" ").map { it.toLong() }

    // Tips: 全てを解析的に求める方針は筋が悪い 数値 * 解析 の組み合わせで実装する方針だと簡単に解ける良い例


    var ans = Long.MAX_VALUE

    fun calc(h: Long, w: Long) {
        for ( i in 1..h-1) {
            var one = i * w

            // 全て横分割ケース
            var two = ((h-i)/2) * w
            var three = ((h-i) - (h-i)/2) * w

            var listH = listOf(one, two, three)
            ans = Math.min(listH.max()!!-listH.min()!!, ans)

            // 横１縦２分割ケース
            var twoV = (h-i) * (w/2)
            var threeV = (h-i) * (w - w/2)
            var listV = listOf(one, twoV, threeV)
            ans = Math.min(listV.max()!!-listV.min()!!, ans)
        }
    }


    calc(H, W)
    // 縦横入れ替えた場合も計算
    calc(W, H)

    println(ans)

    /**
    // ２パターンの方法で行ける気がする
    if ( h%3==0L || w%3==0L) {
        println(0)
        return
    }

    // どちらか一方でも偶数の場合
    if ( h%2==0L || w%2==0L) {
        // 奇数の側でまず分割し，偶数側で残った大きい方を分割
        if( w%2 == 0L) {
            val one = h/2 * w
            val two = (h/2 + 1) * (w/2)

            println(Math.abs(one-two))
            return
        } else {
            val one = w/2 * h
            val two = (w/2 + 1) * (h/2)

            println(Math.abs(one-two))
            return
        }

    }

    // 両方とも奇数の場合
    val one = h/2 * w
    val two = (h/2 + 1) * (w/2)

    println(Math.abs(one-two))
    **/
}

Measured memory_bytes: 55640
#include<stdio.h>
#include<iostream>

using namespace std;

int N;
int d[110];
int main(){
    cin >> N;
    for(int i=0; i<N; i++) {
        int x;
        cin >> x;
        d[x]++;
    }
    int cnt = 0;
    for(int i=0; i<101; i++) if(d[i]) cnt++;
    cout << cnt << endl;
    return 0;
}

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

Measured memory_bytes: 580
import java.util.Scanner;

public class Main{
public static void main(String[] args){
 Scanner scan = new Scanner(System.in);
 
 int S = scan.nextInt();
 
 int h = S / 3600;
 int m = (S % 3600) / 60;
 int s = S % 60;
 
    System.out.println(h + ":" + m + ":" + s);
}
}


Measured memory_bytes: 26344
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int N = s.nextInt();
        long[] A = new long[N];
        long count = 0;

        A[0] = s.nextLong();
        for (int i = 1; i < N; i++) {
            A[i] = s.nextLong();
            if (A[i - 1] > A[i]) {
                count += (A[i - 1] - A[i]);
                A[i] = A[i - 1];
            }
        }

        System.out.println(count);
    }
}

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

int sum_vec(vector<int> a)
{
    int sum = 0;
    for (auto aa : a)
        sum += aa;
    return sum;
}

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

    ll V[N];
    for (int i = 0; i < N; i++)
        cin >> V[i];

    ll ans = 0;
    for ( int l = 0; l <= N; l++)
        for (int r = 0; r <= N; r++)
        {
            if (l + r > K or l + r > N) break;
            int k = K - l - r;
            ll now = 0;
            vector<ll> s;
            for (int i = 0; i < l; i++)
            {
                now += V[i];
                s.push_back(V[i]);
            }
            for (int i = 0; i < r; i++)
            {
                now += V[N - i - 1];
                s.push_back(V[N - i - 1]);
            }
            sort(s.begin(), s.end());
            // cout << now << "*********" << l << ' ' << r << ' ' << k << endl;
            for (auto ss: s)
            {
                if (k <= 0) break;
                if (ss >= 0) break;
                now += abs(ss);
                // cout << abs(ss) << ' ' << now << endl;
                k --;
            }
            // cout << now << endl;
            if (ans < now) ans = now;
        }
    cout << ans << endl;
   	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    //cout.precision(10);
    long long n;
    cin >> n;
    vector<long long> v(n);
    for(int i = 1; i <= n; i++){
        cin >> v[i - 1];
        v[i - 1] -= i;
    }
    sort(v.begin(), v.end());
    long long k = v[n / 2];
    long long ans = 0;
    for(int i = 0; i < n; i++){
        ans += abs(v[i] - k);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
main(){
  int n;
  scanf("%d", &n);
  int l[n];
  for(int i=0;i<n;i++)
    scanf("%d", &l[i]);
  int c=0;
  for(int i=0;i<n-2;i++){
    for(int j=i+1;j<n-1;j++){
      for(int k=j+1;k<n;k++){
        if(l[i] == l[j]) continue;
        if(l[i] == l[k]) continue;
        if(l[j] == l[k]) continue;
        if(l[i]<l[j]+l[k] && l[j]<l[i]+l[k] && l[k]<l[i]+l[j]) c++;
      }
    }
  }
  printf("%d", c);
  return 0;
}


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

using namespace std;

#define all(x) (x).begin(), (x).end()
#define sfl(i,a,n) for (int i=a;i<n;i++)
#define ufl(i,a,n) for (int i=n-1;i>=a;i--)
#define SZ(x) ((int)(x).size())
#define endl '\n'
typedef long long ll;

ll power(ll a, ll b){
    ll res = 1;
    for(int i = 0; i<b; i++)
        res *= a;

    return res;
}

void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
}


int main()
{
    init();
    int n;
    cin>>n;
    int MAX=-1001;
    int MINUM=1001;
    int arr[n];
    sfl(i,0,n)
    {
        cin >>arr[i];
        MAX=max(MAX,arr[i]);
        MINUM=min(MINUM,arr[i]);
    }
    int MIN=1000001;
    for(int i=MINUM;i<=MAX;i++)
    {
        int cost=0;
        sfl(j,0,n)
        {
            cost+=(arr[j]-i)*(arr[j]-i);
        }
        MIN=min(MIN,cost);
    }
    cout<<MIN;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] a_asArgs)
        {
			int l_iN = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray()[0];
			int l_iA = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray()[0];

			Console.WriteLine((l_iN % 500) <= l_iA ? "Yes": "No");
		}
	}
}


Measured memory_bytes: 13396
#include <vector>
#include <queue>
#include <cstdio>
#include <cassert>

using namespace std;

int main() {
    int N;
    scanf("%d", &N);
    vector<int> T(N);
    queue<int> U;
    queue<int> V;
    {
        int _;
        scanf("%d", &_); _ = _-1;
        U.emplace(_);
    }
    {
        int _;
        scanf("%d", &_); _ = _-1;
        V.emplace(_);
    }
    vector<vector<int> > E(N);
    for(int _=0; _<N; ++_) {
        E[_] = vector<int>();
    }
    for(int _=0; _<N-1; ++_) {
        int a;
        int b;
        scanf("%d", &a); a = a-1;
        scanf("%d", &b); b = b-1;
        E[a].emplace_back(b);
        E[b].emplace_back(a);
    }
    int turn = 0;
    int count = 0;
    while(true) {
        assert(!(U.empty() && V.empty()));
        {
            queue<int> _ = move(U);
            while(!_.empty()) {
                int u = _.front();
                _.pop();
                T[u] |= 1;
                if(!(T[u]&2)) {
                    ++count;
                }
                for(int e : E[u]) if(!(T[e]&1)) {
                    U.emplace(e);
                }
            }
        }
        {
            queue<int> _ = move(V);
            while(!_.empty()) {
                int v = _.front();
                _.pop();
                T[v] |= 2;
                if(T[v]&1) {
                    --count;
                }
                for(int e : E[v]) if(!(T[e]&2)) {
                    V.emplace(e);
                }
            }
        }
        if(count==0) {
            break;
        }
        ++turn;
    }
    printf("%d\n", turn-1);
    return 0;
}


Measured memory_bytes: 6272
#include <cstdio>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <string>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <queue>

using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
 
  int a,b;
  cin >> a >> b;
  if (a<=8&&b<=8) cout << "Yay!" << endl;
  else cout << ":(" << endl;

  return 0;
}








Measured memory_bytes: 256
l = [int(i) for i in input().split(" ")]
x1 = l[0]
y1 = l[1]
x2 = l[2]
y2 = l[3]
diff_x21 = x2-x1
diff_y21 = y2-y1
y3 = y2 + diff_x21
x3 = x2 - diff_y21
x4 = x3-diff_x21
y4 = y3-diff_y21
print(x3,y3,x4,y4)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

struct UF
{
    vector<int> par;
    vector<int> tsize;
    UF(int n) : par(n), tsize(n,1) {
        REP(i,n) {
            par[i] = i;
        }
    }

    // 親を返す
    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    // 木の統合
    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        tsize[ry] += tsize[rx];
        par[rx] = ry;
    }

    // 同じ木に属しているか
    bool same(int x, int y) {
        return root(x) == root(y);
    }

    int count(int x) {
        return tsize[root(x)];
    }
};


int main(void)
{
    IOS
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> fb(n);
    UF uf(n);
    REP(i,m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        uf.unite(a,b);
        fb[a]++;
        fb[b]++;
    }
    REP(i,k) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        if (uf.same(a,b)) {
            fb[a]++;
            fb[b]++;
        }
    }

    REP(i,n) cout << uf.count(i)-fb[i]-1 << " ";


    return 0;
}

Measured memory_bytes: 2432
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <memory.h>



using namespace std;
static const double EPS = 1e-9;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,n) for(int i=0;i<(int)n;++i)
#define FORNUM(p, x) for (int num = p; num < (int)(x); ++num)
#define FORI(p, x) for (int i = p; i < (int)(x); ++i)
#define FORJ(p, x) for (int j = p; j < (int)(x); ++j)
#define FORK(p, x) for (int k = p; k < (int)(x); ++k)
#define FORL(p, x) for (int l = p; l < (int)(x); ++l)

typedef pair<int,int>P;
#define INF 1000000000
 
struct edge { 
	int from, to; 
	edge (int from, int to){
		this->from=from; this->to=to;
	}
};
 
int V,E;
typedef vector<edge> edges;
//vector<edges> G;

vector<int> G[10];
int n, m;
bool visit[10];

int dfs(int v, int num) {
	if (num == n) {
		return 1;
	}
	int ans = 0;
	for (auto u : G[v]) {
		if (visit[u] == 0) {
			visit[u] = 1;
			ans += dfs(u, num + 1);
			visit[u] = 0;
		}
	}
	return ans;
}

int main(){
	cin >> n >> m;
	FORI(0, m) {
		int u, v;
		cin >> u >> v; u--; v--;

		G[u].push_back(v);
		G[v].push_back(u);
	}
	visit[0] = 1;
	int ans = dfs(0, 1);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
def main():
    data = []
    while True:  # Loading stdin
        h, w = [int(e) for e in input().split()]
        if h == w == 0:
            break
        else:
            data.append([h, w])

    for datum in data:
        line = "#" * datum[1]
        line = line + "\n"
        print(line * datum[0])


if __name__ == "__main__":
    main()



Measured memory_bytes: 5644
# a 200
from collections import Counter
from math import factorial

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

#累計和
wa = [0]
for ai in a:
    wa.append(wa[-1]+ai)
wa = wa[1:]

def combination(n, r):
    return factorial(n)//(factorial(r)*factorial(n-r))

c = Counter(wa)
ans = 0

for k,v in c.items():
    if v<2: continue
    ans += combination(v, 2)
    
ans += c[0]
print(ans)

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

#include <string.h>
#include <limits.h>

using namespace std;

typedef long long ll;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

const int MAX_S = 1000;

int dp[MAX_S + 1][MAX_S + 1];

int solve(const char *s1, const int l1, const char *s2, const int l2) {
    for (int i = 0; i <= l1; i++) {
        dp[i][0] = i;
        for (int j = 1; j <= l2; j++) {
            if (i == 0) {
                dp[i][j] = j;
                continue;
            }
            if (s1[i - 1] == s2[j - 1]) {
                chmin(dp[i][j], dp[i - 1][j - 1]);
            } else {
                chmin(dp[i][j], dp[i - 1][j - 1] + 1);
            }
            chmin(dp[i][j], dp[i - 1][j] + 1);
            chmin(dp[i][j], dp[i][j - 1] + 1);
        }
    }
    return dp[l1][l2];
}

int main(void) {
    char s1[MAX_S + 10], s2[MAX_S + 10];
    int len_s1, len_s2;
    cin >> s1 >> s2;
    len_s1 = strlen(s1);
    len_s2 = strlen(s2);
    reverse(s1, s1 + len_s1);
    reverse(s2, s2 + len_s2);

    for (int i = 0; i < MAX_S + 1; i++) {
        for (int j = 0; j < MAX_S + 1; j++) {
            dp[i][j] = INT_MAX / 2;
        }
    }

    if (len_s1 < len_s2) {
        cout << solve(s1, len_s1, s2, len_s2) << endl;
    } else {
        cout << solve(s2, len_s2, s1, len_s1) << endl;
    }
    
    return 0;
}



Measured memory_bytes: 7016