akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
using ll = long long;
const int inf = int(1e19);
const int mod = int(1e9) + 7;
const int n_max = 200;
ll d[n_max][n_max];

void floyd_warshall(int n){
    rep(k, n)
        rep(i, n)
            rep(j, n) d[i][j] = min(d[i][k] + d[k][j], d[i][j]);
}

int main(){
    int n, m, r; cin >> n >> m >> r;
    vector<int> R(r);
    rep(i, r) cin >> R[i];
    rep(i, n_max){
        rep(j, n_max){
            if(i == j) d[i][j] = 0;
            else d[i][j] = inf;
        }
    }

    rep(i, m){
        int a, b, c; cin >> a >> b >> c;
        d[a - 1][b - 1] = c;
        d[b - 1][a - 1] = c;
    }

    floyd_warshall(n);
    sort(all(R));
    ll res = inf;
    do{
        ll temp = 0;
        rep(i, r - 1){
            temp += d[R[i] - 1][R[i + 1] - 1];
        }
        res = min(res, temp);
    }
    while(next_permutation(all(R)));
    cout << res << endl;

}

Measured memory_bytes: 3904
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int n,cnt=0;
    cin>>n;
    char c;
    rep(i,n){
        cin>>c;
        if(c=='Y') cnt++;
    }
    if(cnt>0) cout<<"Four";
    else cout<<"Three";
}

Measured memory_bytes: 3624
#include <iostream>

using namespace std;

int main() {
	int N, Y;
	cin >> N >>  Y;
	// 10,000
	for (int i = 0; i <= N; i++) {
		// 5,000
		for (int j = 0; j <= N; j++) {
			int remainder = Y - 10000 * i - 5000 * j;
			if (remainder < 0) {
				continue;
			}
			int k = remainder / 1000;
			//cout << k << endl;
			if (i + j + k == N) {
				//cout << "GET====" << endl;
				cout << i << " " << j << " " << k << endl;
				return 0;
			}
		}
	}
	cout << "-1 -1 -1" << endl;
}


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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    int n, k; cin >> n >> k;
    vector<bool> v(n);
    for (int i = 0; i < k; i++) {
        int d; cin >> d;
        for (int j = 0; j < d; j++) {
            int a; cin >> a; a--;
            v[a] = true;
        }
    }
    cout << count(v.begin(), v.end(), false) << endl;
    return 0;
}


Measured memory_bytes: 3640
import java.util.*;
import java.util.List;
import java.util.ArrayList;
import java.math.*;
class Main{
    public static void main(String[]args){
        Scanner scanner = new Scanner(System.in);
        int A = scanner.nextInt();
        int B = scanner.nextInt();
        int C = scanner.nextInt();
        int K = scanner.nextInt();

        if(A+B<=K){
            System.out.println(A+(-1)*(K-A-B));
        }
        else{
            if(A>=K) System.out.println(K);
            else System.out.println(A);
        }

    }

}

Measured memory_bytes: 35780
n = gets.to_i
array = gets.chomp.split(" ").map(&:to_i)
answer = 0
flag = []

(0...n-1).each do |number|
  flag.push(array[number] >= array[number + 1])
end

cnt = 0
local_cnt = 0

flag.each do |number|
  if number
    local_cnt += 1
  else
    if local_cnt >= cnt
      cnt = local_cnt
    end
    local_cnt = 0
  end
end

cnt = local_cnt if local_cnt >= cnt
puts cnt



Measured memory_bytes: 10500
import std.stdio, std.array, std.string, std.conv;

void main() {
  int n = to!int(chomp(readln()));
  string[] a = split(readln());

  for (int i = n - 1; i >= 0; --i) {
    write(a[i]);
    write(i ? " ": "\n");
  }
}

Measured memory_bytes: 2480
import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
import scala.io.StdIn._

object Main extends App {
  val n = readInt
  val nodes = Array.fill(n){Nil: List[Int]}
  for (i ← 0 until n) {
    val _::t = readLine.trim.split(' ').map(_.toInt).toList
    nodes(i) = t
  }
  val parents = Array.fill(n){ArrayBuffer[Int]()}
  val height = Array.fill(n){0}
  val queue = mutable.Queue(0)
  while (queue.nonEmpty) {
    val current = queue.dequeue()
    for (next ← nodes(current)) {
      height(next) = height(current) + 1
      parents(next).append(current)
      while (parents(parents(next).last).length >= parents(next).length){
        parents(next).append(parents(parents(next).last)(parents(next).length - 1))
      }
      queue.enqueue(next)
    }
  }
  val q = readInt
  for (_ ← 0 until q) {
    val Array(u, v) = readLine.trim.split(' ').map(_.toInt)
    var ua = u
    var uv = v
    while (ua != uv) {
      if (height(ua) == height(uv)){
        var left = 0
        var right = parents(ua).length
        while (left < right) {
          val mid = (left + right) / 2
          if (parents(ua)(mid) != parents(uv)(mid)) left = mid + 1
          else right = mid
        }
        if (right != 0) right -= 1
        ua = parents(ua)(right)
        uv = parents(uv)(right)
      }else if (height(ua) < height(uv)) {
        var left = 0
        var right = parents(uv).length
        while (left < right) {
          val mid = (left + right) / 2
          if (height(parents(uv)(mid)) >= height(ua)) left = mid + 1
          else right = mid
        }
        uv = parents(uv)(right - 1)
      }else {
        var left = 0
        var right = parents(ua).length
        while (left < right) {
          val mid = (left + right) / 2
          if (height(parents(ua)(mid)) >= height(uv)) left = mid + 1
          else right = mid
        }
        ua = parents(ua)(right - 1)
      }
    }
    println(ua)
  }
}



Measured memory_bytes: 338744
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b) - 1; (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    ll n,a,b;
    cin >> n >> a >> b;
    if (a > b) {
        cout << 0 << endl;
    }else if(n == 1 && a != b){
        cout << 0 << endl;
    }else{
        cout << (b - a) * (n - 2) + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head=0, tail=0, n;

void enqueue(P x){
  Q[tail]=x;
  if((tail+1)==n){
    tail=0;
  }else{
    tail++;
  }



}

P dequeue(){
  P x;
  x = Q[head];
  if((head+1)==n){
    head=0;
  }else{
    head++;
  }
  return x;

}


int main(){
  int elaps = 0, c=0;
  int i, q;
  P u;

  scanf("%d %d", &n, &q);

  for ( i = 0; i < n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);

    //tail++;
  }

  //printf("ok5\n");


  while(c!=n){
  //  printf("ok4\n");
    if(Q[head].t==0){
      //printf("ok1\n");
      enqueue(Q[head]);
      u = dequeue();


    }
    else if(Q[head].t<=q){
    //  printf("ok2\n");

      elaps+=Q[head].t;
      Q[head].t=0;
      u = dequeue();



      printf("%s %d\n", u.name, elaps);
        c++;

    }
    else{
  //    printf("ok3\n");

      elaps+=q;
      Q[head].t-=q;

      enqueue(Q[head]);

      u = dequeue();


    //  printf("%s %d\n", u.name, u.t);


    }

  }



  return 0;
}



Measured memory_bytes: 6788
#define P(x) cout << #x" = " << x << endl
#define PP(x, y) cout << "("#x", "#y") = (" << x << ", " << y << ")" << endl
#define PPP(x, y, z) cout << "("#x", "#y", "#z") = (" << x << ", " << y << ", " << z << ")" << endl

#include <iostream>
#include <vector>

using namespace std;

int n;
int a[100000];
int main(){
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    while(true) {
        bool same = true;
        for (int i = 0; i < n - 1; ++i) {
            if (a[i] != a[i + 1]) {
                same = false;
                break;
            }
        }
        if (same) break;
        int mina = *min_element(a, a + n);
        for (int i = 0; i < n; ++i) {
            a[i] = (a[i] - 1) % mina + 1;
        }
    }
    cout << a[0] << endl;
}

Measured memory_bytes: 1144
#include <iostream>

using namespace std;

int main()
{
    unsigned long long n, a, b;
    cin >> n >> a >> b;
    unsigned long long sum = 0;

    if (a == 0)
    {
        cout << 0;
        return 0;
    }
    if (b == 0)
    {
        cout << n;
        return 0;
    }

    unsigned long long times = n / (a + b);
    sum += a * times;
    n %= a + b;

    if (n > a)
    {
        sum += a;
    }
    else
    {
        sum += n;
    }

    cout << sum;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

int n;
int a[3000];
int ans = 0;

int main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
		ans += a[i];
	}
	cout << ans - n << endl;
	return 0;
	
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    int n; std::cin >> n;
    std::vector<int> x(n), y(n);
    for (int i = 0; i < n; i++) std::cin >> x[i];
    y = x;
    std::sort(y.begin(), y.end());
    for (int i = 0; i < n; i++) {
        if (x[i] <= y[n / 2 - 1]) std::cout << y[n / 2] << std::endl;
        else std::cout << y[n / 2 - 1] << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3712
w, h, n = list(map(int, input().split()))
xl, xr, yd, yu = 0, w, 0, h
for _ in range(n):
    x, y, a = list(map(int, input().split()))
    if a == 1:
        xl = max(xl, x)
    elif a == 2:
        xr = min(xr, x)
    elif a == 3:
        yd = max(yd, y)
    else:
        yu = min(yu, y)

if xr > xl and yu > yd:
    print((xr - xl) * (yu - yd))
else:
    print(0)

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;

public class Main {
	public static void main(String[] args){
		ArrayList<String> list1 = new ArrayList<String>();
		ArrayList<Integer> list2 = new ArrayList<Integer>();
		String str;
		int a,b,c;
		BufferedReader br;
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			while((str = br.readLine())!=null){
				list1.add(str);		//とりあえず全部ArrayListに入れる
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		for(int i=1; i<list1.size(); i++){
			String[] numbers = list1.get(i).split(" "); //空白で区切って配列作成
			for(String s : numbers){					//ArrayListに入れる
				list2.add(Integer.parseInt(s));
			}
			Collections.sort(list2);					//小さい順に並べる
			Collections.reverse(list2);					//逆順に並べる

			a	=	list2.get(0);						//要素を辺の長さとする。aは斜辺となる。
			b	=	list2.get(1);
			c	=	list2.get(2);
			
			
			if(a*a==b*b + c*c){							//判定
				System.out.println("YES");
			}else{
				System.out.println("NO");
			}
			list2.clear();
		}
	}
}

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

int main() {
		ll l, r;
		cin >> l >> r;
		r = min(r, l+4038);
		int ans = 2018;
		for (ll i=l; i<=r; ++i) {
				for(ll j=i+1; j<=r; ++j){
						int x = i*j%2019;
						ans = min(ans, x);
				}
		}
		cout << ans << endl;
		return 0;
}


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

template<typename F, typename S>
ostream &operator<<(ostream &os, const pair<F, S> &p) {
    return os << "(" << p.first << ", " << p.second << ")";
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "{";
    typename vector<T>::const_iterator it;
    for (it = v.begin(); it != v.end(); it++) {
        if (it != v.begin()) os << ", ";
        os << *it;
    }
    return os << "}";
}

template<typename T>
ostream &operator<<(ostream &os, const set<T> &v) {
    os << "[";
    typename set<T>::const_iterator it;
    for (it = v.begin(); it != v.end(); it++) {
        if (it != v.begin()) os << ", ";
        os << *it;
    }
    return os << "]";
}

template<typename F, typename S>
ostream &operator<<(ostream &os, const map<F, S> &v) {
    os << "[";
    typename map<F, S>::const_iterator it;
    for (it = v.begin(); it != v.end(); it++) {
        if (it != v.begin()) os << ", ";
        os << it->first << " = " << it->second;
    }
    return os << "]";
}

#define debug(x) cout << #x << " = " << x << endl;

typedef long long int ll;
typedef long double ld;

#define endl "\n";
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define tr(cont, it) for(decltype((cont).begin()) it = (cont).begin(); it != (cont).end(); it++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c),x) != (c).end())
#define F first
#define S second

const ll mod = 1000000007;
const ll inf = (ll) 1e15;

ll power(ll a, ll b, ll m = mod) {if (b == 0) return 1; if (b == 1) return (a % m); ll x = power(a, b / 2, m); x = (x * x) % m; if (b % 2) x = (x * a) % m;return x;}
ll max(ll a, ll b) { return (a > b ? a : b); }
ll min(ll a, ll b) { return (a < b ? a : b); }

const int N=1e5+5;
int n,a[N],q;
ll sum[N],even[N];

ll query(int x)
{
    if(x>=a[n])
    {
        if(!(n%2))
            return even[n];
        else
            return sum[n]-even[n];
    }
    int low=1,high=n;
    //debug(low);
    int ans=-1;
    while(low<=high)
    {
        int mid=(low+high)/2;
        int numa=n-mid+1;
        int numb=mid-1-(lower_bound(a+1,a+n+1,x-(a[mid]-x))-a)+1;
        if(numa-numb<=1)
        {
            ans=mid;
            high=mid-1;
        } else
        {
            low=mid+1;
        }
    }
    assert(ans!=-1);
    ll ret=sum[n]-sum[ans-1];
    int rem=n-2*(n-ans+1);
    if(!(rem%2))
        ret+=even[rem];
    else
        ret+=sum[rem]-even[rem];
    return ret;
}

void solve() {

    cin >> n >>q;
    a[0]=-10000;
    for(int i=1;i<=n;i++)
    {
        cin >> a[i];
        sum[i]=sum[i-1]+a[i];
        even[i]=even[i-1]+(!(i%2)?a[i]:0);
    }
    while(q--)
    {
        int x;
        cin >> x;
        ll ans=query(x);
        cout << ans << endl;
    }

}

int main() {
    IOS;
    int t = 1, num = 1;   ///// change this t for number of testcase globally
    while (t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3712
#include<iostream>
#include <cmath>
#include <string>
#include <iomanip>

#define loop(k) for(int i=0;i<k;i++)
#define looop(k) for(int j=0;j<k;j++)
#define solve(s,c) {int judge{}; loop(n){if(s[i]!=c[i%3]) {judge=-1;break;}}cout<<(judge==-1?-1:m)<<endl;}
#define swap(a,b) a^=b^=a^=b;

using namespace std;

int main(){
    long int n,k;
    cin>>n>>k;
    cout.precision(10);
    cout<<k*pow(k-1,n-1)<<endl;
    return 0;
}

Measured memory_bytes: 256
// AOJ ALDS1_5_D The Number of Inversions
// 2018.4.30 bal4u

#include <stdio.h>
#include <string.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

#define MAX_N 200002
#define INF   0x7f7f7f7f

int a[MAX_N];
int w[MAX_N/2+2];

long long number_of_inversions(int low, int high) 
{ 
	int i, j, k, p, mid;
	long long ans = 0;

	if (low < high) {
		mid = (low + high) >> 1;
		ans += number_of_inversions(low,   mid);
		ans += number_of_inversions(mid+1, high);

		p = mid-low+1;
		memcpy(w, a+low, p << 2);
		i = mid+1, j = 0; k = low;

		w[p] = INF;
		while (i <= high) {
			if (w[j] <= a[i]) a[k++] = w[j++];
			else              a[k++] = a[i++], ans += i-k;
		}
		memcpy(a+k, w+j, (p-j) << 2);
	}
	return ans;
}

int main()
{
	int n, i;
	
	n = in(); for (i = 0; i < n; i++) a[i] = in();
	printf("%lld\n", number_of_inversions(0, n-1));
	return 0;
}


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

int main()
{
    int n, x;
    cin >> n >> x;
    vector<int> l(n);
    rep(i, n) cin >> l[i];
    int sum = 0;
    int count = 1;
    rep(i, n)
    {
        sum += l[i];
        if (x < sum)
            break;
        ++count;
    };
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <set>
#include <unordered_set>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <numeric>

using namespace std;

typedef long long ll;

#define forn(i, n) for(int i = 0; i < (int)(n);++i)
#define fore(i, a, b) for(int i = (int)(a); i <= (int)(b); ++i)
#define fi first
#define se second
#define pb push_back
#define pll pair<ll,ll>
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vb vector<bool>
#define vvi vector<vi>
#define vpll vector<pll>
#define vll vector<ll>
#define vvll vector<vll>
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

ll n;

void fastik() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
}

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

int main() {
    fastik();
    ll a,b,k;cin>>a>>b>>k;
    vll x={1};
    fore(i,2,min(a,b)){
        if(a % i == 0 && b % i == 0){
            x.pb(i);
        }
    }
    sort(all(x));
    cout << x[sz(x)-k];
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << 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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  ll n;
  cin>>n;
  vl a(3 * n);
  rep(i,3*n){
    cin >> a[i];
  }
  sort(all(a));
  ll total = 0;
  for (ll i = 3*n - 2; i >= n; i -= 2){
    total += a[i];
  }
  print(total);
}

Measured memory_bytes: 5572
<?php

    list($N,$M) = array_map('intval',explode(" ",trim(fgets(STDIN))));
    
    $A_array = array_map('intval',explode(" ",trim(fgets(STDIN))));

    $ans = $N - array_sum($A_array);
    
    if($ans < 0){
        echo "-1";
    }else{
        echo $ans;
    }
?>

Measured memory_bytes: 17120
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <cmath>
#include <tuple>
#include <cassert>
#include <array>
#include <iomanip>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using ti = tuple<int, int, int>;

#define pb push_back
#define mp make_pair
#define debug(x) cerr << #x << ": " << x << endl
// #define int long long 

const double eps=1e-14;
const int mod = 1e9 + 7;
const int inf = ((1<<30)-1);
const ll linf = (1LL<<60);
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    set<string> st;
    for(int i=0; i<n; i++)
    {
      string tmp;
      cin >> tmp;
      st.insert(tmp);
    }
    cout << st.size() << endl;
    return 0;
}


Measured memory_bytes: 19128
# 2019/02/02
# AtCoder Beginner Contest115 - A

# Input
d = int(input())

# Choose String
if d == 25:
    ans = "Christmas"
elif d == 24:
    ans = "Christmas Eve"
elif d == 23:
    ans = "Christmas Eve Eve"
elif d == 22:
    ans = "Christmas Eve Eve Eve"

# Output
print(ans)

Measured memory_bytes: 2940
import Control.Monad
import Control.Applicative
import Data.List

main = do
    n <- readLn
    lines <- replicateM n getLine
    putStr $ unlines $ map (unwords . listToMatrics n . lineToIntList) lines
    where
      -- lineToIntList::String -> [Int]
      lineToIntList line =
        map read $ words line

      -- listToMatrics::Int -> [Int] -> [Int]
      listToMatrics n (_:_:vs) =
        let
          -- transposeTo::Int->[Int]->[Int]
          transposeTo n xs=
            map (\_ -> n) xs

          p m [] xs =
            m ++ transposeTo "0" xs

          p m (v:vs) xs = 
            let
              (b,a) = span (\x -> v /= x) xs
            in
              p (m ++ transposeTo "0" b ++ ["1"]) vs (tail a)

        in
          p [] vs [1..n]

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

// https://atcoder.jp/contests/dp/tasks/dp_a

int main() {
  
  int n;
  cin >> n;
  
  int h[n];
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  
  int array[n];
  array[0] = 0;
  array[1] = abs(h[1] - h[0]);
  for (int i = 2; i < n; i++) {
    array[i] = min(array[i-2] + abs(h[i] - h[i-2]), array[i-1] + abs(h[i] - h[i-1]));
  }
  
  cout << array[n-1];
  return 0;
}

Measured memory_bytes: 1024
n = int(input())
h = list(map(int, input().split()))

ans = 0
for i in range(n):
    ans += h[i]
    tmp = h[i]
    for j in range(i, n):
        if h[j] >= tmp:
            h[j] -= tmp
        else:
            tmp = h[j]
            h[j] = 0
print(ans)

Measured memory_bytes: 9100
import java.util.Scanner;

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

        String S = scanner.next();

        if (S.equals("Sunny")) {
            System.out.println("Cloudy");
        } else if (S.equals("Cloudy")) {
            System.out.println("Rainy");
        } else {
            System.out.println("Sunny");
        }
    }
}


Measured memory_bytes: 35696
from functools import lru_cache

@lru_cache(maxsize=None) 
def check(data):   
        if A in data:
                print("A")
        elif B in data:
                print("B")
        elif C in data:
                print("C")
        elif D in data:
                print("D")
        elif E in data:
                print("E")
        elif F in data:
                print("F")
        elif G in data:
                print("G")
                

A = '1'*2 + '0'*6 +'1'*2
B = '1' + '0'*7 + '1' + '0'*7 + '1' + '0'*7 + '1'
C = '1'*4
D = '1' + '0'*6 +'1'*2 + '0'*6 +'1'
E = '1'*2 + '0'*7 + '1'*2
F = '1' + '0'*7 + '1'*2 + '0'*7 +'1'
G = '1'*2 + '0'*5 +'1'*2

while True: 
        data = ''.join(map(lambda x: input(), range(8)))
        check(data)
        try: input()
        except: break


Measured memory_bytes: 6256
import sys
N = int(input())
A = list(map(int, input().split()))
A_max = max(A)
if A_max == 1:
    print("pairwise coprime")
    sys.exit()
dp = [0]*(A_max+10)
K = [0]*(A_max+10)
p = 0
s = 0
for i in range(N):
    K[A[i]] += 1
for i in range(2, A_max+1):
    c = 0
    if dp[i] == 0:
        dp[i] = 1
        for j in range(i, A_max+1, i):
            dp[j] = 1
            c += K[j]
        if c >= 2:
            p = 1
        if c == N:
            s = 1
if p == 0:
    print("pairwise coprime")
elif s == 0:
    print("setwise coprime")
else:
    print("not coprime")

Measured memory_bytes: 197044
<?php

fscanf(STDIN, "%d %d %d", $a, $b, $x);

if ($x >= $a * $a * $b / 2) {
    echo atan2(2 * ($a * $b - $x / $a) / $a, $a) * 180 / pi();
} else {
    echo atan2($b, 2 * $x / $a / $b) * 180 / pi();
}


Measured memory_bytes: 4856
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;
//ここから

void solve(){
  int n;
  cin>>n;
  vector<int>a(n);
  rep(i,n)cin>>a[i];
  sort(a.begin(),a.end());
  cout<<abs(a[0]-a.back());
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


Measured memory_bytes: 256
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
# MOD = 10 ** 9 + 7
MOD = 998244353

# 解説
N, S = list(map(int, sys.stdin.buffer.readline().split()))
A = list(map(int, sys.stdin.buffer.readline().split()))

# dp[i][k]: iまで見て、合計がkの場合の数
dp = [[0] * S for _ in range(N + 1)]
ans = 0
for i in range(N):
    for k in range(S):
        dp[i + 1][k] += dp[i][k]
        dp[i + 1][k] %= MOD
        if k == 0 and k + A[i] < S:
            # ここから使う
            # L の選び方が i + 1 ある
            dp[i + 1][A[i]] += i + 1
            dp[i + 1][A[i]] %= MOD
        elif k == 0 and k + A[i] == S:
            ans += (i + 1) * (N - i)
        elif k + A[i] < S:
            dp[i + 1][k + A[i]] += dp[i][k]
            dp[i + 1][k + A[i]] %= MOD
        elif k + A[i] == S:
            # ここまで使う
            # R の選び方が N - i ある
            ans += dp[i][k] * (N - i)
        ans %= MOD
print(ans)


Measured memory_bytes: 113884
S = int(input())

front_num = S // 100
back_num = S % 100

if 0 < front_num <= 12 and 0 < back_num <= 12:   #   両方あり得る
    print("AMBIGUOUS")
elif 0 < front_num <= 12:
    print("MMYY")
elif 0 < back_num <= 12:
    print("YYMM")
else:
    print("NA")



Measured memory_bytes: 2940
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007ll
#define INF 1000000000ll
typedef pair<int64_t, int64_t> PII;
typedef vector<int64_t> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

// まずは全探索，次にDP
// 偶奇，逆から，ソート，出現回数，出現位置，DP
// 余事象，包除
// データ構造
// 問題の特徴量
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
int main() {
cin.tie(0);
ios::sync_with_stdio(false);

int n, v, cnt;cin >> n;
VI cntv1(100001, 0), cntv0(100001, 0); 
rep(i, 0, n) {
    cin >> v;
    if (i%2) ++cntv1[v];
    else ++cntv0[v];
}

const VI::iterator max0 = max_element(ALL(cntv0));
const VI::iterator max1 = max_element(ALL(cntv1));
const int d0 = distance(cntv0.begin(), max0);
const int d1 = distance(cntv1.begin(), max1);
int64_t second0 = 0, second1 = 0;

if (d0 == d1){
    rep(i, 1, 100001) {
        if (i != d0) second0 = max(second0, cntv0[i]);
        if (i != d1) second1 = max(second1, cntv1[i]);
    }
    cnt = n - max(*max0 + second1, *max1 + second0);
}
else {
    cnt = n - *max0 - *max1;
}


cout << cnt << "\n";
}

// 境界，出力文字列 チェック



Measured memory_bytes: 1792
#include <stdio.h>

void trace(int A[], int N) {
	int i;
	for ( i = 0; i < N; i++ ) {
		if ( i > 0 ) printf(" ");
		printf("%d", A[i]);
	}
	printf("\n");
}

int insertionSort(int A[], int N) {
	int j, i, v;
	for ( i = 1; i < N; i++ ) {
		v = A[i];
		j = i - 1;
		while (j >= 0 && A[j] > v) {
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = v;
		trace(A, N);
	}
}

int main(void) {
	int N, i, j;
	int A[100];
	
	scanf("%d", &N);
	for ( i = 0; i < N; i++ ) scanf("%d", &A[i]);
	
	trace(A, N);
	insertionSort(A, N);

	return 0;
}

Measured memory_bytes: 604
#include <stdio.h>
#include <stdlib.h>
 
typedef struct {int from, to, w;} Edge;
 
int parent[100], rank[100];
Edge edge[10000];
 
int compare(const void *a, const void *b) {
    return ((Edge *)a)->w - ((Edge *)b)->w;
}
 
void init(int n) {
    int i;
    for (i = 0; i < n; i++) {
        parent[i] = i;
        rank[i] = 0;
    }
}
 
int find(int x) {
    return parent[x] != x ? parent[x] = find(parent[x]) : x;
}
 
void unite(int x, int y) {
    const int xr = find(x), yr = find(y);
    if (rank[xr] < rank[yr])
        parent[xr] = yr;
    else if (xr != yr) {
        parent[yr] = xr;
        rank[xr] += rank[xr] == rank[yr];
    }
}
 
int kruskal(int v, int e) {
    int i;
    int sum;
 
    qsort(edge, e, sizeof(Edge), &compare);
 
    init(v);
 
    sum = 0;
    for (i = 0; i < e; i++)
        if (find(edge[i].from) != find(edge[i].to)) {
            unite(edge[i].from, edge[i].to);
            sum += edge[i].w;
        }
 
    return sum;
}
 
int main(void) {
    int i, j;
    int n;
    int e;
 
    scanf("%d", &n);
 
    e = 0;
    for (i = 0; i < n; i++)
        for (j = 0; j < n; j++) {
            int a;
            scanf("%d", &a);
            if (a != -1)
                edge[e++] = (Edge){i, j, a};
        }
 
    printf("%d\n", kruskal(n, e));
 
    return 0;
}



Measured memory_bytes: 2056
#include<map>
#include<set>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<chrono>
#include<stack>
#include<fstream>
#include<math.h>
#include<list>
#include<complex>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define vtype(type) vector<type>
#define vvtype(type) vector<vector<type>>
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end()) 
#define UNIQUE_ARRAY(a,x) unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>=x;i--)
typedef long long ll;
using namespace std;


ll const MOD = 1e9 + 7;
ll mod_p(ll x, ll y) {
	x %= MOD;
	y %= MOD;
	return (x + y + MOD) % MOD;
}

ll mod_m(ll x, ll y) {
	x %= MOD;
	y %= MOD;
	return x * y%MOD;
}

ll mod_pow(ll x, ll t) {
	x %= MOD;
	if (t == 0) {
		return 1;
	}
	else {
		ll v = mod_pow(x, t / 2);
		if (t % 2 == 0) {
			return v * v % MOD;
		}
		else {
			return v * v%MOD * x %MOD;
		}
	}
}

ll mod_inv(ll x) {
	return mod_pow(x, MOD - 2);
}

struct edge
{
	long long to; ll name;
	bool operator<(const edge& rhs) const {
		return name > rhs.name;
	}
};

ll const MAX = 1e5 + 5;
vvtype(edge) G(MAX);

int main() {
	ll n, k;
	cin >> n >> k;
	if (k * 2 - 1 <= n) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 2560
#include<stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
int main(){
	
	int X,A,B;
	scanf("%d%d%d",&X,&A,&B);
	
	if(A-B>=0){
		printf("delicious\n");
	}
	else if(A+X-B>=0){
		printf("safe\n");
	}
	else{
		printf("dangerous\n");
	}
		
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 1
#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR
#endif

//改造
typedef long long int ll;
using namespace std;

//ここから編集する

bool enough(ll t, int h[], int n, int a, int b) {
    ll ch[100005];
    for (int i = 0; i < n; i++) {
        ch[i] = h[i];
    }

    ll cnt = 0;
    ll dmg = b * t;
    ll dif = a - b;
    for (int i = 0; i < n; i++) {
//        ch[i] -= b * t;
//        if(ceil((double)ch[i] / (a - b)) > 0) cnt += ceil((double)ch[i] / (a - b)) ;
//        if(ch[i]> 0) cnt += (ch[i] + (a-b) - 1)/(a-b) ;
        if(h[i] <= dmg) continue;
        cnt += (h[i] - dmg + dif - 1)/dif;

    }

    return cnt <= t;

}

int main() {
    int n, a, b;
    int h[100005];

    cin >> n >> a >> b;
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }

//        if (enough(i, h, n, a, b)) {
//            cout << i << endl;
//            break;
//        }
    //にぶんたんさく！
    ll left = 0;
    ll right = (ll) 1E10;
//    ll right = 10;

    while(right - left > 1){
        ll mid = (left + right) / 2;
//        if(mid == left) break;
        if(enough(mid,h,n,a,b)){
            right = mid;
        }else{
            left = mid;
        }
    }
    cout << right << endl;
}
/*
2 10 4
21
20
 */

Measured memory_bytes: 640
from bisect import bisect_left, bisect_right
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)

def solve():
    INF = float('inf')

    N, Q = map(int, input().split())
    adjL = [[] for _ in range(N)]
    for _ in range(N-1):
        A, B, C, D = map(int, input().split())
        A, B, C = A-1, B-1, C-1
        adjL[A].append((B, C, D))
        adjL[B].append((A, C, D))
    querys = [tuple(map(int, input().split())) for _ in range(Q)]

    def dfs(vNow, vPar, depth):
        iVFirsts[vNow] = len(vs)
        vs.append(vNow)
        depths.append(depth)
        for v2, clr, dist in adjL[vNow]:
            if v2 == vPar: continue
            iVColorss[clr].append(len(numEs))
            numEs.append(1)
            sumDs.append(dist)

            dfs(v2, vNow, depth+1)

            vs.append(vNow)
            depths.append(depth)
            iVColorss[clr].append(len(numEs))
            numEs.append(-1)
            sumDs.append(-dist)

    vs = []
    iVFirsts = [-1] * N
    depths = []
    numEs = [0]
    sumDs = [0]
    iVColorss = [[0] for _ in range(N-1)]

    dfs(0, -1, 0)

    dists = [0] * N
    accD = 0
    for i, sumD in enumerate(sumDs):
        accD += sumD
        if iVFirsts[vs[i]] == i:
            dists[vs[i]] = accD

    for iVColors in iVColorss:
        for i in range(1, len(iVColors)):
            numEs[iVColors[i]] += numEs[iVColors[i-1]]
            sumDs[iVColors[i]] += sumDs[iVColors[i-1]]

    idEle = (INF, -1)
    def _binOpe(x, y):
        return x if x <= y else y  # min
    def makeSegTree(numEle):
        numPow2 = 2 ** (numEle-1).bit_length()
        data = [idEle] * (2*numPow2)
        return data, numPow2
    def setInit(As):
        for iST, A in enumerate(As, numPow2):
            data[iST] = A
        for iST in reversed(range(1, numPow2)):
            data[iST] = _binOpe(data[2*iST], data[2*iST+1])
    def getValue(iSt, iEn):
        L = iSt + numPow2
        R = iEn + numPow2
        ans = idEle
        while L < R:
            if L & 1:
                ans = _binOpe(ans, data[L])
                L += 1
            if R & 1:
                R -= 1
                ans = _binOpe(ans, data[R])
            L >>= 1
            R >>= 1
        return ans

    data, numPow2 = makeSegTree(len(depths))
    setInit([(depth, i) for i, depth in enumerate(depths)])

    def getLCA(x, y):
        L, R = iVFirsts[x], iVFirsts[y]
        if L > R:
            L, R = R, L
        minV, iMinV = getValue(L, R)
        return vs[iMinV]

    anss = []
    for clr, distNew, u, v in querys:
        u, v = u-1, v-1
        LCA = getLCA(u, v)

        clr -= 1
        ds = [dists[u], dists[v], dists[LCA]]
        for i, vv in enumerate([u, v, LCA]):
            iIV = bisect_right(iVColorss[clr], iVFirsts[vv]) - 1
            iV = iVColorss[clr][iIV]
            ds[i] += numEs[iV] * distNew - sumDs[iV]
        ans = ds[0] + ds[1] - 2*ds[2]
        anss.append(ans)

    print('\n'.join(map(str, anss)))


solve()


Measured memory_bytes: 216076
import java.util.LinkedList;
import java.util.Scanner;

public class Main {

	String S;
	LinkedList<Character> que;

	private void solve() {
		// input

		Scanner io = new Scanner(System.in);
		S = io.next();
		
		int ans = Integer.MAX_VALUE;
		for (int k = 97; k <= 122; k++) {
			char target = (char) k;
			que = new LinkedList<Character>();

			boolean same = true;
			for (int i = 0; i < S.length(); i++) {
				if (S.charAt(i) != target) {
					same = false;
				}
				que.offer(S.charAt(i));
			}
			if (same) {
				System.out.println(0);
				return;
			}

			for (int i = S.length() - 1; i > 0; i--) {
				same = true;
				for (int j = 0; j < i; j++) {
					char next;
					if (que.peek() == target) {
						next = que.poll();
					} else {
						que.poll();
						next = que.peek();
					}
					if (next != target) {
						same = false;
					}
					que.offer(next);
				}
				
				que.poll();
				if(same){
					ans = Math.min(ans,S.length()-i);
					break;
				}
				
			}

		}

		System.out.println(ans);
	}

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


Measured memory_bytes: 24276
import java.util.Scanner;
public class Main {public static void main(String...args){
    Scanner sc = new Scanner(System.in); int X = sc.nextInt(); int ans = 0;
    ans = ans + (X/500)*1000; X = X -  (X/500)*500; ans = ans + (X/5)*5;
    System.out.println(ans);}
}

Measured memory_bytes: 21844
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*float n乗*/ll floatpow(float x,ll n){ll i;float ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
double ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
 char s[1000010];sc(s);
 ll a=0,b=0,c=0;
 ll len=strlen(s);
  
 rep(i,0,len){
  if(s[i]=='a')a++;
  if(s[i]=='b')b++;
  if(s[i]=='c')c++;
 }
 ll mn=min(a,b);mn=min(mn,c);
 ll mx=max(a,b);mx=max(mx,c);
 if(mx-mn<=1){
  pY;return 0;
 }
 pN;
  
return 0;}

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

using namespace std;

const int N = 1 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

int n;
int g[N][N];

bool read() {
    if (!(cin >> n))
        return false;

    return true;
}

void solve() {
    auto m = 0;

    for (int i = 0; i < n; ++i)
        for (int j = 0; j < i; ++j, ++m)
            g[i][j] = g[j][i] = 1;

    if (n % 2 == 0) {
        for (int i = 0; i < n / 2; ++i, --m)
            g[i][n - 1 - i] = g[n - 1 - i][i] = 0;
    } else {
        for (int i = 0; i < n / 2; ++i, --m)
            g[i][n - 2 - i] = g[n - 2 - i][i] = 0;
    }

    cout << m << endl;

    for (int i = 0; i < n; ++i)
        for (int j = 0; j < i; ++j)
            if (g[i][j])
                cout << i + 1 << ' ' << j + 1 << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    while (read())
        solve();

    return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <vector>
#define ll long long
#define PI 3.14159265358
using namespace std;
int main()
{
double a,b,h,m;
cin>>a>>b>>h>>m;
double H=(2*PI*h)/12.0+(PI/6)*(m/60);
double M=(2*PI*m)/60.0;
double angle=H-M;
double ans =a*a+b*b-2.0*a*b*cos(angle);
printf("%.10f" , sqrt(ans));
}

Measured memory_bytes: 4220
MOD = 2019
def solve(l, r)
    return 0 if r - l >= MOD
    results = Array.new()
    l.upto r do |i|
        (i+1).upto r do |j|
            results << (i*j) % MOD
        end
    end
    results.min
end

def main()
    l, r = gets.split.map(&:to_i)
    p solve(l, r)
end

main()


Measured memory_bytes: 17788
/**
    BISMILLAH
    @Author : Arham
*/
#include <bits/stdc++.h>
using namespace std;

void solve() {
    int n;
    cin >> n;
    int temp = n, sum = false;
    while(temp) {
        int r = temp % 10;
        temp /= 10;
        sum += r;
    }

    cout << (n % sum ? "No" : "Yes") << endl;

    return;
}

int main() {
    int t = true;
    //cin >> t;
    while(t--)
        solve();

    return 0;
}


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

int dp(int n, int k, vector<int>h){
  vector<ll>dp(n, INF);
  dp[0] = 0;
  for (int i=0; i<n; i++){
    for (int j=i+1; j<=i+k; j++){
      if (j<n){
        dp[j] = min(
          dp[j],
          dp[i] + abs( h[i] - h[j] )
        );
      }
    }
  }
  return dp[n-1];
}

int main(){
  int n,k; cin>>n>>k;
  vector<int>h(n); rep(i,n) cin>>h[i];
  cout << dp(n,k,h) << endl;
}

Measured memory_bytes: 4840
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=10,INF=1<<29;

int state[MAX][MAX][MAX];

vector<int> dx={1,0,0,1,1,1,1,0,0,1,1,1,1};
vector<int> dy={0,1,0,1,-1,0,0,1,1,1,1,-1,-1};
vector<int> dz={0,0,1,0,0,1,-1,1,-1,1,-1,1,-1};

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    
    while(1){
        int N,M,P;cin>>N>>M>>P;
        if(N+M+P==0) break;
        
        memset(state,0,sizeof(state));
        int ans=INF;
        
        for(int i=0;i<P;i++){
            int a,b;cin>>a>>b;
            a--;b--;
            for(int z=0;z<N;z++){
                if(state[a][b][z]==0){
                    state[a][b][z]=i%2+1;
                    break;
                }
            }
            
            for(int x=0;x<N;x++){
                for(int y=0;y<N;y++){
                    for(int z=0;z<N;z++){
                        
                        for(int k=0;k<13;k++){
                            int cnt=0;
                            int xx=x,yy=y,zz=z;
                            while(0<=xx&&xx<N&&0<=yy&&yy<N&&0<=zz&&zz<N&&state[xx][yy][zz]==i%2+1){
                                cnt++;
                                xx+=dx[k];
                                yy+=dy[k];
                                zz+=dz[k];
                            }
                            if(cnt>=M) ans=min(ans,i);
                        }
                    }
                }
            }
        }
        
        if(ans==INF) cout<<"Draw"<<endl;
        else if(ans%2==0) cout<<"Black"<<" "<<ans+1<<endl;
        else cout<<"White"<<" "<<ans+1<<endl;
    }
}



Measured memory_bytes: 3136
#include <cstdio>
#include <queue>
#include <algorithm>

using namespace std;

int h, w;
char s[111][111];
int c[256] {};

int main(void) {
  scanf("%d%d", &h, &w);
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      scanf(" %c", s[i] + j);
      c[int(s[i][j])] += 1;
    }
  }

  priority_queue<int> q;
  for (int i = 'a'; i <= 'z'; i++) {
    q.push(c[i]);
  }

  if (w%2 == 1) swap(w, h);

  bool ok = true;
  if (h%2 == 1 && w%2 == 1) {
    for (int i = 0; i < (h-1)*(w-1)/4; i++) {
      if (q.top() >= 4) {
        int p = q.top() - 4; q.pop();
        q.push(p);
      } else {
        ok = false;
      }
    }
    for (int i = 0; i < h/2; i++) {
      if (q.top() >= 2) {
        int p = q.top() - 2; q.pop();
        q.push(p);
      } else {
        ok = false;
      }
    }
    for (int i = 0; i < w/2; i++) {
      if (q.top() >= 2) {
        int p = q.top() - 2; q.pop();
        q.push(p);
      } else {
        ok = false;
      }
    }
    if (q.top() != 1) ok = false;
  } else if (h%2 == 1) {
    for (int i = 0; i < (h-1)*w/4; i++) {
      if (q.top() >= 4) {
        int p = q.top() - 4; q.pop();
        q.push(p);
      } else {
        ok = false;
      }
    }
    for (int i = 0; i < w/2; i++) {
      if (q.top() >= 2) {
        int p = q.top() - 2; q.pop();
        q.push(p);
      } else {
        ok = false;
      }
    }
  } else {
    for (int i = 0; i < h*w/4; i++) {
      if (q.top() >= 4) {
        int p = q.top() - 4; q.pop();
        q.push(p);
      } else {
        ok = false;
      }
    }
  }
  
  puts(ok ? "Yes" : "No");
  return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
	int n, v[20], c[20];
  	int sum = 0;

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> c[i];
      	if (v[i]-c[i]>0) {
          	sum += v[i]-c[i];
        }
	}
	
	cout << sum;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	long long n;
	cin >> n;
	long long ma = 1000000000000007;
	for (long long i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			if (ma > i + n / i) {
				ma = i + n / i;
			}
		}
	}
	cout << ma - 2 << endl;
}

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

int top, S[1000];

void push(int x){
	S[++top] = x;
}

int pop(){
	top--;
	return S[top+1];
}

int main(){
	int a, b;
	char s[1000];
	top = 0;
	while( scanf("%s",s) != EOF ){
		if( s[0] == '+' ){
			a = pop();
			b = pop();
			push(a + b);
		}else if( s[0] == '-' ){
			b = pop();
			a = pop();
			push(a - b);
			}else if( s[0] == '*' ){
			a = pop();
			b = pop();
			push(a * b);
			}else{
				push(atoi(s));
			}
	}
	
	printf("%d\n",pop());
	
	return 0;
}
		

Measured memory_bytes: 548