akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
//const N = 2e6, inf = 1e18;

string a, b;
vector<string>v;
vector<string>ans;
int main()
{
    bool okay = 1;
    ll n;
    cin>>n;
    for(int i = 0; i < n; i++)
    {
        ll x;
        cin>>x;
        if(x%2 == 0 && (x%3 != 0 && x % 5 != 0))
        {
            okay = 0;
        }
    }
    if(okay) puts("APPROVED");
    else puts("DENIED");
    return 0;
}


Measured memory_bytes: 256
/*input
3 5 -4 -2
*/

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

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans = max({a*c, a*d, b*c, b*d});
    cout << ans << endl;
}

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

int main() {
 int n;
  cin >> n;
  
  vector<int> a(n);
  rep(i,n) {
  cin >> a.at(i);
  }
  
  sort(a.begin(), a.end());
  int sum = 0;
  rep(i,n-1){
  sum += a.at(i);
  }
  
  if(sum > a.at(n - 1)) {
    cout << "Yes";
  }
  else {
 cout << "No";
  }
  
}

Measured memory_bytes: 3644
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecVec = vector<Vec>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T& b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a > b){a = b; return true;} return false;}
template <typename T>
void co(const T n){cout << n << endl;}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void coVec(const Vec &v){for(ll i : v) cosp(i); cout << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

int main(void){
	ll n, z, w;
	cin >> n >> z >> w;
	Vec a(n);
	rep(i, n) cin >> a[i];

	ll ans = 0;
	if(n == 1) ans = abs(a[0]-w);
	else if(n == 2) ans = max(abs(a[0]-a[1]), abs(a[1]-w));
	else ans = max(abs(a[n-2]-a[n-1]), abs(a[n-1]-w));
	co(ans);

	return 0;
}


Measured memory_bytes: 256
n=int(input())-1
def n_len():
    global n
    i=1
    while n>=26**i:
        n-=26**i
        i+=1
    return i
l=n_len()
alp=[chr(i) for i in range(97, 97+26)]
ans=""
for i in range(l):
    k=n%26
    ans=alp[k]+ans
    n//=26
print(ans)

Measured memory_bytes: 9120
#include <bits/stdc++.h>
using namespace std;
int N, M;
int par[100];
void init() {
    for (int i = 1; i <= N; i++) {
        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), ry = root(y);
    par[rx] = ry;
}
int main () {
    cin >> N >> M;
    vector<pair<int, int>> v(M);
    for (int i = 0; i < M; i++) {
        cin >> v[i].first >> v[i].second;
    }
    int ans = 0;
    for (int i = 0; i < M; i++) {
        init();
        for (int j = 0; j < M; j++) {
            if (i == j) continue;
            unite(v[j].first, v[j].second);
        }
        for (int j = 2; j <= N; j++) {
            if (root(j) != root(1)) {
                ans++;
                break;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <vector>
using namespace std;

int H, W;
string field[1010][1010];
string diff[1010][1010];
int totals[2][1010];
int total;

int toInt(string s){
  istringstream iss(s);
  int n;
  iss >> n;
  return n;
}

string toString(int n){
  ostringstream oss;
  oss << n;
  return oss.str();
}

void Wcalc(int h, int x){
  int sum = 0;
  for(int j = 0 ; j < W ; j++){
    if(field[h][j] == "?") continue;
    else sum += toInt(field[h][j]);
  }
  /*
  cout << "x = " << x << ", y = " << h << endl;
  cout << "sum = " << sum << endl;
  cout << totals[0][h] << endl;
  */
  field[h][x] = toString(totals[0][h] - sum);
}

void Hcalc(int w, int y){
  int sum = 0;
  for(int i = 0 ; i < H ; i++){
    if(field[i][w] == "?") continue;
    else sum += toInt(field[i][w]);
  }
  /*
  cout << "x = " << w << ", y = " << y << endl;
  cout << totals[1][w] << endl;
  */
  field[y][w] = toString(totals[1][w] - sum);
}


int main(){
  bool flag = false;
  while(cin >> H){
    if(H == 0) break;
    if(flag) cout << endl;
    if(!flag) flag = true;
    
    cin >> W;
    
    
    int q = 0;
    
    for(int i = 0 ; i < H ; i++){
      for(int j = 0 ; j < W ; j++){
	cin >> field[i][j];
	diff[i][j] = field[i][j];
	if(field[i][j] == "?") q++;
      }
      cin >> totals[0][i];
    }
    
    for(int i = 0 ; i < W ; i++){
      cin >> totals[1][i];
    }
    cin >> total;
        
    bool cansolve = true;
    while(1){
      int tmp = q;
      for(int i = 0 ; i < H ; i++){
	int qcnt = 0;
	int w;
	for(int j = 0 ; j < W ; j++){
	  if(field[i][j] == "?") w = j, qcnt++;
	}
	if(qcnt == 1){
	  Wcalc(i, w);
	  q--;
	}
      }
      
      for(int j = 0 ; j < W ; j++){
	int qcnt = 0;
	int h;
	for(int i = 0 ; i < H ; i++){
	  if(field[i][j] == "?") h = i, qcnt++;
	}
	if(qcnt == 1){
	  Hcalc(j, h);
	  q--;
	}
      }
      
      if(q == 0) break;
      
      if(q == tmp){
	cansolve = false;
	break;
      }
    }
    
    if(!cansolve){
      cout << "NO" << endl;
      continue;
    }
    
    vector<string> ans;
    for(int i = 0 ; i < H ; i++){
      for(int j = 0 ; j < W ; j++){
	if(diff[i][j] == "?"){
	  ans.push_back(field[i][j]);
	}
      }
    }
    
    for(int i = 0 ; i < ans.size() ; i++){
      cout << ans[i] << endl;
    }
    /*
    for(int i = 0 ; i < H ; i++){
      for(int j = 0 ; j < W ; j++){
	cout << field[i][j] <<  ' ';
      }
      cout << endl;
    }
    cout << endl;
    */
  } 
  return 0;
}

Measured memory_bytes: 17224
#

import sys
input=sys.stdin.readline
MOD=10**9+7

def main():
    n,a,b=map(int,input().split())
    nca=1
    for i in range(a):
        nca=(nca*(n-i))%MOD
    for i in range(a):
        nca=(nca*pow(i+1,MOD-2,MOD))%MOD
    ncb=1
    for i in range(b):
        ncb=(ncb*(n-i))%MOD
    for i in range(b):
        ncb=(ncb*pow(i+1,MOD-2,MOD))%MOD
    print((pow(2,n,MOD)-1-nca-ncb)%MOD)
    
    
    
if __name__=="__main__":
    main()


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

int main() {
	int w, h, x, y, r;
	cin>>w>>h>>x>>y>>r;

	if(x<0 || y<0)  //checking constraint condition since x, y can be less then 0
        {
    	    cout<<"No" <<endl; 
            return 0 ; 
	} 

	if( (x+r)<=w && (y+r)<=h) cout<< "Yes" <<endl;
	else cout <<"No" <<endl;
	return 0;
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,M,C,n=0,ans=0;
  cin>>N>>M>>C;
  
  int B[M],A;
      for(int i=0;i<M;i++)
      cin>>B[i];
  for(int i=0;i<N;i++){
    n=0;
    for(int j=0;j<M;j++){
      cin>>A;
      n+=A*B[j];
    }
    if((n+C)>0)
      ans++;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
<?php
// C
fscanf(STDIN, '%d', $K);
$ans = 0;
for ($i = 1; $i <= $K; $i++) {
    for ($j = $i; $j <= $K; $j++) {
        $gcd[$i][$j] = gcd($i, $j);
    }
}
for ($i = 1; $i <= $K; $i++) {
    for ($j = $i; $j <= $K; $j++) {
        for ($k = $j; $k <= $K; $k++) {
            $a = [$i, $j, $k];
            $au = array_unique($a);
            if (count($au) === 3) $t = 6;
            elseif (count($au) === 2) $t = 3;
            else $t = 1;
            $ans += $gcd[$gcd[$a[0]][$a[1]]][$a[2]] * $t;
        }
    }
}
echo $ans;

// 最大公約数（2つ）
function gcd($m, $n)
{
    if (!$n) return $m;
    return gcd($n, $m % $n);
}

// 最大公約数（3つ以上）
function gcdAll($arr)
{
    $gcd = $arr[0];
    foreach ($arr as $a) {
        $gcd = gcd($gcd, $a);
    }
    return $gcd;
}

Measured memory_bytes: 17248
void main()
{
    long n = readln.chomp.to!long;
    long[] a = readln.split.to!(long[]);

    a.sort!"a > b";
    a[1..$].stride(2).take(n).sum.writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 15076
#include<iostream>

using namespace std;

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

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

    if(b<=a){
        cout << "delicious" << endl;
    } else if (b<=a+x){
        cout << "safe" << endl;
    } else {
        cout << "dangerous" << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
using namespace std;

using VI = vector <int>;
using VVI = vector <VI>;
using VPI = vector <pair<int, int>>;
using VVPI = vector <VPI>;
using VMII = vector <map<int, int>>;

const int MAXH = 10;

inline int getHeight(int now) {
    int ret = 0;

    while (now >= 1) {
        now >>= 1;
        ++ret;
    }

    return ret;
}

void solveDP(VMII& dp, int now, int sum, int val, const VI& V, const VI& W, const VI& H) {
    int N = V.size()-1;

    dp[now][sum] = max(dp[now][sum], val);
    dp[now][(sum + W[now])] = max(dp[now][(sum + W[now])], val + V[now]);

    if (H[now] >= MAXH) {
        return ;
    }

    if (now*2 <= N) {
        solveDP(dp, now*2, sum+W[now], val+V[now], V, W, H);
        solveDP(dp, now*2, sum, val, V, W, H);
    }

    if (now*2+1 <= N) {
        solveDP(dp, now*2+1, sum+W[now], val+V[now], V, W, H);
        solveDP(dp, now*2+1, sum, val, V, W, H);
    }
}

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

    VI V(N+1);
    VI W(N+1);
    VI H(N+1);

    for (int i = 1; i <= N; ++i) {
        H[i] = getHeight(i);
    }

    for (int i = 1; i <= N; ++i) {
        cin >> V[i] >> W[i];
    }

    VMII dp(N+1);
    VVPI vdp(N+1);

    // table creation => O(N) * 2^MAXH
    solveDP(dp, 1, 0, 0, V, W, H);

    // stay monotone
    for (int i = 1; i <= N; ++i) {
        if (!dp[i].empty()) {
            auto iter = dp[i].begin();

            while (iter != dp[i].end()) {
                if (vdp[i].empty() || iter->second > vdp[i].back().second) {
                    vdp[i].push_back(make_pair(-iter->first, iter->second));
                }

                ++iter;
            }

            reverse(vdp[i].begin(), vdp[i].end());
        }
    }

    int Q;
    cin >> Q;

    // Q * 2^(LEVEL-MAXH) * dp Query
    while (Q--) {
        int v;
        int L;

        cin >> v >> L;

        if (H[v] <= MAXH) {
            auto iter = lower_bound(vdp[v].begin(), vdp[v].end(), make_pair(-L, 0));
            cout << iter->second << endl;
        } else {
            VI cand;
            int p = v;

            while (H[p] > MAXH) {
                cand.push_back(p);
                p /= 2;
            }

            int allMask = 1<<cand.size();
            int ans = -1;

            // 2^9 * 18
            for (int cho = 0; cho < allMask; ++cho) {
                int sum = 0;
                int val = 0;

                for (int i = 0; i < cand.size(); ++i) {
                    int nowv = cand[i];
                    if (cho & (1<<i)) {
                        sum += W[nowv];
                        val += V[nowv];
                    }
                }

                if (sum <= L) {
                    auto iter = lower_bound(vdp[p].begin(), vdp[p].end(), make_pair(-(L-sum), 0));
                    if (iter != vdp[p].end()) {
                        ans = max(ans, val + iter->second);
                    }
                }
            }

            cout << ans << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 62692
#include <stdio.h>
#include <stdlib.h>

#define MAX_H (100)
#define MAX_W (8)
#define MOD (1000000007)

long fib[MAX_H + 1];
long dp[MAX_H + 1][MAX_W];

int main(int argc, char *argv[]) {
  // read inputs
  long H, W, K;
  scanf("%ld %ld %ld", &H, &W, &K);

  // calculate fibonacci
  fib[0] = 1; fib[1] = 2;
  for (int i = 2; i <= MAX_H; i++) {
    fib[i] = fib[i - 1] + fib[i - 2];
  }

  // calculate dp
  for (int s = 0; s < W; s++)
    dp[0][s] = (s == K - 1);
  for (int h = 1; h <= H; h++) {
    for (int s = 0; s < W; s++) {
      long val_down = 0, val_left = 0, val_right = 0;
      // don't move at this level
      val_down = dp[h - 1][s];
      if (s >= 1)
        val_down = (val_down * fib[s - 1]) % MOD;
      if (s <= W - 2)
        val_down = (val_down * fib[W - s - 2]) % MOD;
      // try moving left if possible
      if (s >= 1) {
        val_left = dp[h - 1][s - 1];
        if (s >= 2)
          val_left = (val_left * fib[s - 2]) % MOD;
        if (s <= W - 2)
          val_left = (val_left * fib[W - s - 2]) % MOD;
      }
      // try moving right if possible
      if (s <= W - 2) {
        val_right = dp[h - 1][s + 1];
        if (s >= 1)
          val_right = (val_right * fib[s - 1]) % MOD;
        if (s <= W - 3)
          val_right = (val_right * fib[W - s - 3]) % MOD;
      }
      // printf("%d %d: %d %d %d\n", h, s, val_left, val_down, val_right);
      dp[h][s] = (val_down + val_left + val_right) % MOD;
    }
  }
  printf("%ld\n", dp[H][0]);
  
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>

using namespace std;
int main() {
	int n;
	int max;
	int a, b, c;
	cin >> n;
	
	if (n == 2) {
		cin >> a >> b;
		max = a;
		if (max < b) max = b;

		for (int i = 1; i<max; i++) {
			if (a%i == 0 && b%i == 0) cout << i << endl;
		}
	}

	if (n == 3) {
		cin >> a >> b>>c;
		max = a;
		if (max < b) max = b;
		if (max < c) max = c;

		for (int i = 1; i< max; i++) {
			if (a%i == 0 && b%i == 0 && c%i == 0) cout << i << endl;
		}
	}
	


	
	


	//getchar();
	//getchar();
}

Measured memory_bytes: 3100
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
	static void solve(){//Here is the main function
		int N = nextInt();
		if(N == 1){
			myout("Hello World");
		}else{
			myout(nextInt() + nextInt());
		}
	}
	//Method addition frame start



	//Method addition frame end
}


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


long double calc_s(ll m){
	long double ans(0);
	while(m >= 1){
		ans += m%10;
		m /= 10;
	}
	return ans;
}

int main(){
	ll k;
	cin >> k;
	ll ans(1), d(1);
	rep(i,k){
		cout << ans << endl;
		while ((ans + d - 1) / calc_s(ans + d) >= d) {
			d *= 10;
		}
		ans += d;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define vec vector<int>
#define fo(i, n) for (int i = 0; i < n; i++)
#define foo(i, a, b) for (int i = a; i < b; i++)
#define mp make_pair
#define deb(x) cout << #x << "-->" << x << endl;
#define deb1a(v)                  \
    cout << #v << "--->" << endl; \
    for (auto it : v)             \
    {                             \
        cout << it << " ";        \
    }                             \
    cout << endl;
#define deb2a(v)                  \
    cout << #v << "--->" << endl; \
    for (auto it : v)             \
    {                             \
        for (auto it1 : it)       \
        {                         \
            cout << it1 << " ";   \
        }                         \
        cout << endl;             \
    }
    #define mod 998244353
 
#define fi first
#define se second
int32_t main() 
{
   set<int> s;
   fo(i,3){
       int x;
       cin >> x;
       s.insert(x);
   }
   if(s.size()==2)
   cout<<"Yes";
   else
   {
       cout << "No";
   }
   
} 


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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 60;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N, M; cin >> N >> M;
    ll A[N]; rep(i, N) cin >> A[i];
    sort(A, A+N);
    reverse(A, A+N);
    ll ok = 0, ng = LLINF;
    ll m = (ok+ng)/2;
    while(abs(ok-ng) > 1){
        //mを超えるような握手は何通りあるか
        ll res = 0;
        rep(i, N){
            ll key = m-A[i];
            ll left = -1, right = N;
            ll mid = (left+right)/2;
            while(abs(left-right) > 1){
                if(A[mid] >= key) left = mid;
                else right = mid;
                mid = (left+right)/2;
            }
            res += left+1;
        }
        if(res >= M) ok = m;
        else ng = m;
        m = (ok+ng)/2;
    }
    //ok*M + はみ出し分が答え
    ll ans = ok*M;
    vector<ll> ruiseki(N+1, 0);
    rep(i, N) ruiseki[i+1] = ruiseki[i] + A[i];
    rep(i, N){
        //A[i]+A[j] >= ok -> A[i]+A[j]-okを足す
        ll key = ok-A[i]; //key=5で[7,7,6,5,5,4,...]のときはruiseki[5]-key*5を足す
        ll left = -1, right = N;
        ll mid = (left+right)/2;
        while(abs(left-right) > 1){
            if(A[mid] >= key) left = mid;
            else right = mid;
            mid = (left+right)/2;
        }
        ans += ruiseki[left+1] - (left+1)*key;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

double dist(double x1, double y1, double z1,
            double x2, double y2, double z2 ){
    return sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) + (z1-z2)*(z1-z2) );
}

const double INF = (double)(1<<30);
double G[100][100];
double mindist[100];
bool used[100];
double x[100], y[100], z[100], r[100];

int main(){
    int n, i, j;
    while(cin>>n,n){
        for(i = 0; i < n; i++) used[i] = false;
        for(i = 0; i < n; i++){
            cin >> x[i] >> y[i] >> z[i] >> r[i];
        }
        for(i = 0; i < n; i++){
            for(j = 0; j < n; j++){
                if( i == j ) G[i][j] = 0.0;
                double d = dist(x[i],y[i],z[i],x[j],y[j],z[j]);
                if( d <= r[i] + r[j] ){
                    G[i][j] = 0.0;
                    G[j][i] = 0.0;
                }else{
                    G[i][j] = d - r[i] - r[j];
                    G[j][i] = d - r[i] - r[j];
                }
            }
        }
        used[0] = true;
        double ans = 0.0;
        for(i = 0; i < n; i++){
            mindist[i] = G[0][i];
        }
        for(i = 0; i < n; i++){
            int id = -1;
            double m = INF;
            for(j = 0; j < n; j++){
                if( used[j] ) continue;
                if( mindist[j] < m ){
                    m = mindist[j];
                    id = j;
                }
            }
            if( id == -1 ) break;
            used[id] = true;
            ans += m;
            for(j = 0; j < n; j++){
                mindist[j] = min( mindist[j], G[id][j] );
            }
        }
        printf("%.3lf\n", ans);
    }
    return 0;
}

Measured memory_bytes: 1324
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long>vll;
typedef pair<int,int> pi;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  ll a, b;
  cin >> a >> b;
  cout << (a + b) / 2 << endl;
  return 0;
}



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

long long fact(int n){
    long long sum = 1;
    for (int i = 1; i <= n; ++i)
    {
      sum = (sum* i)%1000000007;
    }
    return sum;
}

int main(){
  int n;
  cin>>n;
  long long ans=fact(n);
  cout<<ans<<endl;
  
  return 0;

}


Measured memory_bytes: 256
use std::io::{BufRead, Write, stdin, stdout};

fn solve<R: BufRead, W: Write>(mut input: R, mut output: W) {
    let mut s = String::new();
    input.read_line(&mut s).unwrap();
    let mut split = s.split_whitespace();
    let a = split.next()
        .unwrap()
        .parse::<i64>()
        .unwrap();
    let b = split.next()
        .unwrap()
        .parse::<i64>()
        .unwrap();
    writeln!(output, "{}", (a + b) % 24).unwrap();
}

fn main() {
    let stdin = stdin();
    let stdout = stdout();
    solve(stdin.lock(), stdout.lock());
}

#[cfg(test)]
mod tests {
    fn test(input: &str, output: &str) {
        let mut v = Vec::<u8>::new();
        ::solve(input.as_bytes(), &mut v);
        assert_eq!(String::from_utf8(v).unwrap(), output);
    }
    #[test]
    fn case1() {
        test("9 12\n", "21\n");
    }
    #[test]
    fn case2() {
        test("19 0\n", "19\n");
    }
    #[test]
    fn case3() {
        test("23 2\n", "1\n");
    }
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int tblData[] = new int[3];
		int k = 2;
		int tmp;
		
		//?????????????´?
		for(int i = 0; i < 3; i++) {
			tblData[i] = sc.nextInt();
		}
		
		//??´???(??????)
		while(k > 0) {
			int i = 0;
			while(i < k) {
				if(tblData[i] > tblData[i+1]) {
					tmp = tblData[i];
					tblData[i] = tblData[i+1];
					tblData[i+1] = tmp;
				}
				i++;
			}
			k--;
		}
		
		System.out.println(tblData[0] + " " + tblData[1] + " " + tblData[2]);
	}
}

Measured memory_bytes: 26108
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int h = sc.nextInt();
      int w = sc.nextInt();
      int[][] grid = new int[h][w];
      for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
          grid[i][j] = sc.nextInt();
        }
      }
      List<String> res = new ArrayList<>();
      for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
          if(grid[i][j] % 2 == 0) continue;
          if(j == w - 1) {
            if(i < h - 1) {
                grid[i+1][j]++;
                res.add((i+1) + " " + (j+1) + " " + (i+2) + " " + (j+1));
            }
                
        } else {
            grid[i][j]--;
            grid[i][j+1]++;
            res.add((i+1) + " " + (j+1) + " " + (i+1) + " " + (j+2));
          }
        }
      }
      System.out.println(res.size());
      for(String s : res)
         System.out.println(s);
  }
}

Measured memory_bytes: 101420
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

#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>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;


int main()
{
	int M, T, P, R;
	while (cin >> M >> T >> P >> R,M)
	{
		vector<vector<int>>data;
		vector<pair<int,pair<int,int>>>ans;
		data.resize(T);
		ans.resize(T);
		for (size_t i = 0; i < T; i++)
		{
			ans[i] = pair < int, pair<int,int> > {i, pair < int, int > {0, 0}};
			data[i].resize(P);
		}
		int a, b, c, d;
		for (size_t i = 0; i < R; i++)
		{
			cin >> a >> b >> c >> d;
			b--;
			c--;
			if (d)
			{
				data[b][c]+=1;
			}
			else
			{
				ans[b].second.first++;
				ans[b].second.second += data[b][c]*20+a;
			}
		}
		sort(ans.begin(), ans.end(), [](const pair<int,pair<int, int>>a, const pair<int,pair<int, int>>b) {
			if (a.second.first == b.second.first)
			{
				if (a.second.second == b.second.second)
				{
					return a.first > b.first;
				}
				return (a.second.second < b.second.second);
			} else return a.second.first > b.second.first;
		});
		
		cout << ans[0].first+1;
		for (size_t i = 1; i < T; i++)
		{
			if (ans[i - 1].second.first == ans[i].second.first&&ans[i - 1].second.second == ans[i].second.second)
			{
				cout << '=';
			} else
			{
				cout << ',';
			}
			cout << ans[i].first+1;
		}
		cout << endl;
	}
}

Measured memory_bytes: 1204
import sys
import bisect
input = sys.stdin.readline
n,q = map(int,input().split())
s = list(input())
lr = [list(map(int,input().split())) for _ in range(q)]
ac = []
for i in range(n-1):
  if s[i] == "A" and s[i+1] == "C":
    ac.append(i)
for i in range(q):
  print(bisect.bisect_left(ac,lr[i][1]-1)-bisect.bisect_left(ac,lr[i][0]-1))

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

//vector<int> s[2];
//vector<ull> u[2];
//const int N=500;
//int n;
//int d[N][N];

int main(){
  int k;
  string s;
  cin >>k;
  cin >>s;
  
  if (k>=s.size()){
  cout <<s<<endl;
  }else{
    s.erase(k);
    cout <<s<<"..."<<endl;
  }
  return 0;

}


Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
using namespace std;
using ll = long long;

unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    int a,b,c;
    cin >> a >> b >> c;
    cout << max((a - b + 1),0) * max((a - c + 1),0) << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main
{
    public static void main(String [] args)
    {
        Scanner key = new Scanner(System.in);
        long num = key.nextLong();
        long blue = key.nextLong();
        long red = key.nextLong();
        
        long total = num % (blue+red);
        long rem = (num - total)/(blue+red)*blue;

        if(total - blue >= 0)
        {
            rem = rem + blue;
        }
        else
        {
            rem = rem + total;
        }

        System.out.println(rem);


    }
}

Measured memory_bytes: 23764
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {return (a%b) ? gcd(b, a%b) : b;}

ll ngcd(vector<ll> a) {
    ll res;
    res = a[0];
    for(ll i=1; i<a.size() && res !=1; ++i) {
        res = gcd(a[i], res);
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll k; cin >> k;
    ll ans = 0;
    vl t;
    for(ll i=1; i<=k; ++i) {
        for(ll j=1; j<=k; ++j) {
            for(ll kk=1; kk<=k; ++kk) {
                ans += gcd(gcd(i,j),kk);
            }
        }
    }
    ct(ans);
}



Measured memory_bytes: 3652
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author cherrypi59
 */

#pragma GCC optimize ("O2")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class ABlackjack {
public:
    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        int a, b, c;
        in>>a>>b>>c;
        if(a+b+c>=22) out<<"bust\n";
        else out<<"win\n";
    }
};


int main() {
	ABlackjack solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3604
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

#ifdef DEBUG
mt19937 mrand(300); 
#else
mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count()); 
#endif

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int mod = 998244353;

int mul(int a, int b) {
  return (long long) a * b % mod;
}

void add(int &a, int b) {
  a += b;
  if (a >= mod) {
    a -= mod;
  }
}

const int maxn = 305;
char tmp[maxn];
int n, k;
string s;

bool read() {
  if (scanf("%s%d", tmp, &k) < 2) {
    return false;
  }
  s = tmp;
  return true;
}

int bal[maxn];
int a[maxn];
int nxt[maxn];
int dp[maxn][maxn][maxn];

void solve() {
  {
    n = 0;
    int cur = 0;
    for (int i = 0; i < sz(s); i++) {
      bal[i] = cur;
      if (s[i] == '0') {
        cur++;
      } else {
        a[n++] = cur;
      }
    }
  }
  nxt[sz(s) - 1] = sz(s);
  for (int i = sz(s) - 2; i >= 0; i--) {
    if (s[i + 1] == '0') {
      nxt[i] = i + 1;
    } else {
      nxt[i] = nxt[i + 1];
    }
  }
  memset(dp, 0, sizeof(dp));
  dp[0][0][0] = 1;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j < sz(s); j++) {
      for (int k = 0; k <= i; k++) {
        auto cur = dp[i][j][k];
        if (!cur) {
          continue;
        }
        if (s[j] == '0') {
          add(dp[i][j + 1][k], cur);
          if (bal[j] <= a[i]) {
            add(dp[i + 1][j][k + 1], cur);
          }
        } else {
          add(dp[i][min(nxt[j] + 1, sz(s))][k], cur);
          if (bal[j] <= a[i]) {
            add(dp[i + 1][j + 1][k], cur);
          }
        }
      }
    }
  }
  int res = 0;
  for (int i = 0; i <= min(n, k); i++) {
    add(res, dp[n][sz(s)][i]);
  }
  printf("%d\n", res);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 114664
import java.util.*;
public class Main {
    public static void main(String...args){
    Scanner scan = new Scanner(System.in);
    int cards = scan.nextInt();
    List<String> sCards = new ArrayList<>(Arrays.asList("1","2","3","4","5","6","7","8","9","10","11","12","13"));
    List<String> hCards = new ArrayList<>(Arrays.asList("1","2","3","4","5","6","7","8","9","10","11","12","13"));
    List<String> cCards = new ArrayList<>(Arrays.asList("1","2","3","4","5","6","7","8","9","10","11","12","13"));
    List<String> dCards = new ArrayList<>(Arrays.asList("1","2","3","4","5","6","7","8","9","10","11","12","13"));
    while(scan.hasNextLine()) {
        String[] whatCard = scan.nextLine().split(" ");
        switch(whatCard[0]) {
            case "S" : 
                sCards.remove(whatCard[1]);
                break;
            case "H" : 
                hCards.remove(whatCard[1]);
                break;
            case "C" : 
                cCards.remove(whatCard[1]);
                break;
            case "D" : 
                dCards.remove(whatCard[1]);
                break;
        }
    }
        for(String i : sCards) {
                System.out.println("S "+i);
        }
        for(String i : hCards) {
                System.out.println("H "+i);
        }
        for(String i : cCards) {
                System.out.println("C "+i);
        }
        for(String i : dCards) {
                System.out.println("D "+i);
        }
 }
 }





Measured memory_bytes: 26260
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a =sc.nextInt(),n;boolean x ;
        for(int i=1;i<a+1;i++){
            n=i;x=false;
            if(n%3==0)x=true;
            while(n>0){
                if(n%10==3)x=true;
                n/=10;
            }
            if(x)System.out.printf(" %d",i);
        }
        System.out.println();
    }
}


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

using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifdef OJ
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define all(x) (x).begin(), (x).end()
#define rsort(x) sort((x).rbegin(), (x).rend())
#define sz(x) ((int)x.size())
#define fori(i, n) for (int i = 0; i < (int)(n); ++i)
#define ford(i, n, e) for (int i = (int)(n); i >= (int)(e); --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
#define RETURN(x) do{cout << (x) << '\n'; return 0;}while(0)

const char en = '\n';
const int MOD = 0;
const int MAXN = 0;
const int INF = 1e9;

int solve() {
    int n; cin >> n;
    string s; cin >> s;
    vector<int> r(n+1), w(n+1);
    fore(i,1,n) {
        r[i] = r[i-1];
        w[i] = w[i-1];
        if(s[i-1] == 'R') {
            r[i]++;
        } else {
            w[i]++;
        }
    }

    debug(r);
    debug(w);
    int ans = 1e9;
    fore(i,1,n+1) {
        int tmp = 0;
        int wc = w[i-1];
        int rc = r[n]-r[i-1];
        int mn = min(rc,wc);
        tmp += mn;
        rc -= mn; wc -= mn;
        tmp += max(wc,rc);
        mmin(ans, tmp);
        debug(i);
        debug(ans);
    }

    cout << ans << en;
    return 0;
} 

int main(int argc, char **argv) {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    int ntest = 1;
    //cin >> ntest;
    int t = 1;
    fori(test, ntest) {
        //cout << "Case #" << t << ": ";
        solve();
        t++;
    }

    return 0;
}


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

signed main() {
	int H,W,N,tmp;
	cin>>H>>W>>N;
	queue<int> a;
	for(int i=0;i<N;i++){
		cin>>tmp;
		a.push(tmp);
	}
	
	vector<vector<int>> field(W,vector<int>(H));
	int color=1;
	int x=0;
	int y=0;
	while(!a.empty()){
		tmp=a.front();
		a.pop();
		for(int i=0;i<tmp;i++){
			field[x][y]=color;
			if(y%2==0){
				if(x+1<W)x++;
				else y++;
			}
			else{
				if(x-1>=0)x--;
				else y++;
			}
		}
		color++;
	}
	
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			cout<<field[j][i]<<' ';
		}
		cout<<endl;
	}
	
	return 0;
}

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

#define int long long
const int N = 1000005;
vector <int> g[N];
int n,m,c[N],ans,s1,s2,vis[N],flag,tot;

void dfs(int p) {
    ++tot;
    if(c[p]==1) s1++;
    if(c[p]==2) s2++;
    vis[p]=1;
    for(int i=0;i<g[p].size();i++) {
        int q=g[p][i];
        if(!vis[q]) {
            c[q]=3-c[p];
            dfs(q);
        }
        else if(c[p]==c[q]) flag=1;
    }
}

signed main() {
    scanf("%lld%lld",&n,&m);
    for(int i=1;i<=m;i++) {
        int t1,t2;
        scanf("%lld%lld",&t1,&t2);
        g[t1].push_back(t2);
        g[t2].push_back(t1);
    }
    for(int i=1;i<=n;i++) {
        if(vis[i]) continue;
        s1=s2=flag=tot=0;
        c[i]=1;
        dfs(i);
        if(flag==0) ans+=s1*s2;
        else ans+=tot*(tot-1)/2;
    }
    cout<<ans-m;
}


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

long long minf[1000003],ans;
int main()
{
    long long N;
    scanf("%lld",&N);
    for(long long x=1;x*x<=N;x++)
    {
        if(N%x!=0) continue;
        long long m = x-1;
        if(m>0) {
            if((N/m) == N%m) ans+=m;}
        m = N/x -1;
        if(m>0){
            if((N/m) == N%m) ans+=m;}

    }
    printf("%lld",ans);
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
main(){
  int i,j,k,x=0;
  char str[21];
  scanf("%s",str);
  x = strlen(str);
  for(i=x-1;i>=0;i--){
    printf("%c",str[i]);
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 524
require 'complex'

n = gets.to_i
array = []
n.times do
  array << gets.split(" ").map(&:to_i)
end

routes = []
(1..n).to_a.permutation(n) do |route|
  routes << route
end

total = 0
routes.each do |route|
  (1...route.length).each do |i|
    total += Math.sqrt((array[route[i - 1] - 1][0] - array[route[i] - 1][0]).abs ** 2 + (array[route[i - 1] - 1][1] - array[route[i] - 1][1]).abs ** 2)
  end
end

puts total / routes.length.to_f

Measured memory_bytes: 8188
from statistics import median
n = int(input())
nums = list(map(int, input().split()))
bs = nums.copy()
tmp = 0

for i in range(n):
    bs[i] -= i + 1


med = median(bs)

ans = 0
for i in range(n):
    ans += abs(bs[i] - med)

print(int(ans))

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

signed main(){
  string s, w;
  cin >> s >> w;
  if(s==w) {
    cout << "EQUAL";
    return 0;
  }
  if(s.size()>w.size())cout << "GREATER";
  else if(s.size()==w.size()){
    if(s[0]-'0'>w[0]-'0') cout << "GREATER";
    else cout << "LESS";
  }
  else cout << "LESS";
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
 
int main()
{
  long long a, b, c, X, Y;
  int D, G;
//  char s[101]={};
//  char s_temp[101]={};
  char t[101]={};
//  char s[10000000000000000001]={};
  char s[101]={};
  int len=0;
  int N, M;
  int A[20000]={};
  int B[20000]={};
  int C[20000]={};
  int i,j,k;
  int flag=0;
  int tmp=0;
  int min=101;
  int cnt=0;
  int max=0;
  int ans=0;

//  long cnt =0;
  long long A_temp;
//    int k=0;

  scanf("%d %d", &a, &b);
//  printf("%d %d\n",D,G);

//  for(i=0;i<D;i++){
//    scanf("%d %d", &A[i], &B[i]);
//    printf("%d %d", A[i], B[i]);
//  }

   
   printf("%d\n",a-b+1);
  
return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/operators.hpp>
#include <boost/dynamic_bitset.hpp>

namespace adaptor = boost::adaptors;
using index_t = std::size_t;

void Main()
{
	int N, M;
	std::cin >> N >> M;
	std::vector<int> count(N);
	boost::dynamic_bitset<> flag(N);
	for (auto i : boost::irange(0, M))
	{
		int p;
		std::string str;
		std::cin >> p >> str;
		--p;
		if (!flag[p])
		{
			if (str == "AC")
			{
				flag[p] = true;
			}
			else
			{
				++count[p];
			}
		}
	}
	int AC = 0, WA = 0;
	for (auto i : boost::irange(0, N))
	{
		if (flag[i])
		{
			++AC;
			WA += count[i];
		}
	}
	std::cout << AC << " " << WA << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>


#define REP(i,N) for(auto i = 0; i <N; i++)

using namespace std;
typedef long long ll;


int in(){
    int temp;
    scanf("%d",&temp);
    return temp;
}

ll lin(){
    ll temp;
    scanf("%lld",&temp);
    return temp;
}

int same_strings(string A, string B){
    
    for(auto i = 0; i <A.size(); i++){
        
        if (A[i] != B[i] && A[i] != '?'){
            return 0;
        }
    }
    
    return 1;
    
}


int main() {
    
    string S;
    string T;
    
    cin >> S;
    cin >> T;
    
    if (S.size() < T.size()) {
        cout <<  "UNRESTORABLE" << endl;
        return 0;
    }
    
    int position = -1;
    
    for(int i = 0; i+T.size()-1<S.size(); i++){
        if (same_strings(S.substr(i,T.size()),T)){
            position = i;
        }
        
    }

    if (position == -1){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    
    for(auto i = 0; i < position; i++){
        
        if (S[i] == '?'){
            cout << 'a';
        }else{
            cout << S[i];
        }
    }
    cout << T;
    
    for(auto i = position + T.size(); i < S.size() ; i++){
        
        if (S[i] == '?'){
            cout << 'a';
        }else{
            cout << S[i];
        }
    }
    
    cout << endl;
    
    
    return 0;
    
    
}






Measured memory_bytes: 256