akhauriyash/Code-Regression huggingface dataset:
n = gets.chomp.to_i

ary = []
for i in 1..n
    for j in i..n
        if i < j
            ary << [i,j]
        end
    end
end

if n % 2 == 1
    for i in 1..(n-1)
        if i < n-i
            ary.delete([i, n-i])
        else
            ary.delete([n-i, i])
        end
    end
else
    for i in 1..(n-1)
        if i < n-i+1
            ary.delete([i, n-i+1])
        else
            ary.delete([n-i+1, i])
        end
    end
end
puts ary.length
ary.each do |i|
    print(i[0].to_s+" "+i[1].to_s+"\n")
end

Measured memory_bytes: 2172
#include<iostream>
#include<bits/stdc++.h>
#include<string>
using namespace std;
int main()
{
   char s[1000];
   cin>>s;
   int l,k=0,i,j,m=1;
   l=strlen(s);
   sort(s,s+l);
  // cout<<s<<endl;
   for(i=0;i<l-1;i++){
    if(s[i]==s[i+1]){
      m++;
    }
    else{
        if(m%2==0){
            m=1;
        }
        else{
                //cout<<i<<endl;
      //  cout<<m<<endl;
            cout<<"No"<<endl;
            return 0;
        }
    }
   }
   if(m%2==0){
     cout<<"Yes"<<endl;
   }
   else{
    cout<<"No"<<endl;
   }
}


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


int main(void){
  int a, b, c, k, ans;
  cin >> a >> b >> c >> k;
  if(k <= a) cout << k << endl;
  else if(k <= a+b) cout << a << endl;
  else cout << a - (k - a - b) << endl;
  return 0;
}

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

int main() {
    int n;
    vector<int> vi;
    cin>>n;
    for (size_t i = 0; i < n; i++)
    {
        int x;
        cin>>x;
        vi.push_back(x);
    }
    int min_value = INT32_MAX;
    for (size_t i = 1; i < 101; i++)
    {
        int sum = 0;
        for (size_t j = 0; j < n; j++)
        {
            sum += (i-vi[j])*(i-vi[j]);
            /* code */
        }
        if(sum<min_value){
            min_value = sum;
        }
        
    }
    cout << min_value<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#define int long long
using namespace std;
signed main() {
	string A,B,C;
    cin>>A>>B>>C;

    string X=B+C;

    if(stoi(X)%4==0){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }
}

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

long D[100][6];

void rotate(long n, long a, long b, long c, long d){
    swap(D[n][a], D[n][b]);
    swap(D[n][b], D[n][c]);
    swap(D[n][c], D[n][d]);
}

void spin(long n, char c)
{
    if(c=='E'){ rotate(n, 0, 3, 5, 2);
        //swap(D[n][0],D[n][3]);swap(D[n][3],D[n][5]);swap(D[n][5],D[n][2]);
    }
    else if(c=='W'){ rotate(n, 0, 2, 5, 3);
        //swap(D[n][0],D[n][2]);swap(D[n][2],D[n][5]);swap(D[n][5],D[n][3]);
    }
    else if(c=='S'){ //rotate(n, 0, 1, 4, 5);
        swap(D[n][0],D[n][1]);swap(D[n][0],D[n][4]);swap(D[n][4],D[n][5]);
    }
    else if(c=='N'){ rotate(n, 0, 1, 5, 4);
        //swap(D[n][0],D[n][1]);swap(D[n][1],D[n][5]);swap(D[n][5],D[n][4]);
    }
}

int main() {
    int ans = 0;
    int n;
    cin >> n;
    for (int i = 0; i < n ; ++i) {
        for (int j = 0; j < 6; ++j) {
            cin >> D[i][j];
        }
    }
    for (int i = 0; i < n ; ++i) {
        for (int j = i + 1 ; j <= n ; ++j) {
            char SWS[8]={"NNNWNNN"};
            for(int k=0; k < 8; ++k){
                if(D[i][1] == D[j][1])break;
                spin(j,SWS[k]);
            }
            for(int k=0;k<4;++k){
                if(D[i][0] == D[j][0]){
                    if(D[i][1] == D[j][1] && D[i][2] == D[j][2] && D[i][3]==D[j][3] && D[i][4] == D[j][4] && D[i][5] == D[j][5])
                        ans++;
                }
                spin(j,'W');
            }
        }
    }

    if (ans == 0) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

typedef int64_t ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const ll INFL = (1LL<<60);
const double eps = (1e-9);

const ll mod = 1e9 + 7;

int dp[105][105];   // (i, j) に到達するために白黒の変化を経る回数が最も少ない場合をとると何回？

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

  int h, w;
  cin >> h >> w;

  vector<string> s(h);
  rep(i, h) cin >> s[i];

  rep(i, h) rep(j, w) dp[i][j] = INF;

  if (s[0][0] == '#') dp[0][0] = 1;
  else dp[0][0] = 0;

  rep(i, h) rep(j, w) {
    if (j < w -1) {                  // 右に配る
      if (s[i][j] == s[i][j+1]) {
        chmin(dp[i][j+1], dp[i][j]);
      } else {
        chmin(dp[i][j+1], dp[i][j] + 1);
      }
    }
    if (i < h - 1) {                // 下に配る
      if (s[i][j] == s[i+1][j]) {
        chmin(dp[i+1][j], dp[i][j]);
      } else {
        chmin(dp[i+1][j], dp[i][j] + 1);
      }
    }
  }

  if (s[h-1][w-1] == '#') dp[h-1][w-1]++;

  cout << dp[h-1][w-1] / 2 << endl;

  return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

#define N 8
#define FREE -1
#define NOT_FREE 1

void putQueen(int );
void printBoard();

int Q[N][N],row[N],col[N],dpos[2*N-1],dneg[2*N-1];
int r,c;

int main(){

  int i,j,k;

  for(i=0;i<N;i++){
    row[i]=col[i]=FREE;
  }

  for(i=0;i<2*N-1;i++){
    dpos[i]=dneg[i]=FREE;
  }

  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      Q[i][j]=FREE;
    }
  }

  scanf("%d",&k);

  for(i=0;i<k;i++){
    scanf("%d%d",&r,&c);
    Q[r][c]=NOT_FREE;
  }

  putQueen(0);

  return 0;
}

void putQueen(int i){
  int j;

  if(i==N){
    printBoard();
    return;
  }
  
  for(j=0;j<N;j++){
  
      if(col[j]==NOT_FREE || dpos[i+j]==NOT_FREE || dneg[i-j+N-1]==NOT_FREE) continue;

      row[i]=j;
      col[j]=dpos[i+j]=dneg[i-j+N-1]=NOT_FREE;

      putQueen(i+1);

      col[j]=dpos[i+j]=dneg[i-j+N-1]=FREE;
     
  }
}

void printBoard(){
  int i,j;

  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(Q[i][j]==NOT_FREE && row[i]!=j) return;
    }
  }

  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i]==j) printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}

Measured memory_bytes: 572
#define _USE_MATH_DEFINES
#include  <iostream>
#include  <algorithm>
#include  <climits>
#include  <vector>
#include  <string>
#include  <cstring>
#include  <stack>
#include  <queue>
#include  <cmath>
#include  <iomanip>
#include  <set>
#include  <map>
#include  <new>
#include <cstdint>
#include <cctype>
using namespace std;
#define rep(i,n)  for(int i = 0; i < n; i++)
#define lrep(i,n,m)  for(int i = n; i < m; i++)

using ll = long long;
using Vii = vector<vector<int> >;
using Gjudge = vector<vector<bool>>;
using Vi = vector<int>;
using Vl = vector<ll>;
using Vll = vector<vector<ll> >;
using Vs = vector<string>;
using Vb = vector<bool>;
using the = pair<int, int>;
using lthe = pair<ll, ll>;

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; }

const int Mod = static_cast<int>(1e9 + 7);
const int INF = INT_MAX;
const int dx[4] = { 1,0,-1,0 };
const int dy[4] = { 0,1,0,-1 };

int main()
{
	int n;
	cin >> n;
	Vi A(n);
	rep(i, n)  cin >> A[i];

	for (int u : A) {
		if (u % 2 == 0) {
			if (u % 3 != 0 && u % 5 != 0) {
				cout << "DENIED" << endl;
				return 0;
			}
		}
	}
	cout << "APPROVED" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

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

  int j = 0;
  for(int i = 0; i < n; i++){
    if(a[i] > a[j]) j = i;
  }

  int ans = a[j] + b[j];

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
package main

import (
  "fmt"
)

func main() {
  vowels := make(map[rune]bool)
  for _, c := range "aeiou" {vowels[c] = true}
  var c string; fmt.Scan(&c)
  var ans string
  if _, ok := vowels[rune(c[0])]; ok {ans = "vowel"} else {ans = "consonant"}
  fmt.Println(ans)
}

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

typedef long long ll;
typedef pair<int, int> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main() {
  int n;
  while(cin >> n) cout << "3C" << (n % 39 < 10 && n % 39 != 0 ? "0" : "") << (!(n % 39) ? 39 : n % 39) << endl;
}

Measured memory_bytes: 3128
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define endl '\n'

map <ll,ll > visited;
ll dp[ll(1e5+7)];


vector < vector<ll> > graph(1e5+7);

void dfs(ll a){
    visited[a]++;
    for(ll j=0;j<graph[a].size();j++)
    {
        if(visited[graph[a][j]]==0)
          {
             // cout<<graph[a][j]<<endl;
              dfs(graph[a][j]);

          }
        dp[a]=max(dp[a],dp[graph[a][j]]+1);
    }


}

int main()
{
    ll n,m;
    cin>>n>>m;
   for(ll j=1;j<=n;j++)dp[j]=0;
    for(ll j=0;j<m;j++)
    {
        ll a,b;
        cin>>a>>b;
        graph[a].push_back(b);
       // cout<<"Bey"<<endl;

    }
    for(ll j=1;j<=n;j++)
    {
        if(visited[j]==0)
        dfs(j);


        //cout<<"Hi"<<endl;
    }
   // cout<<"Hi"<<endl;
    ll *it;
    it=max_element(dp+1,dp+n+1);
    ll ans=ll(*it);
   // for(ll j=1;j<=n;j++)cout<<dp[j]<<" ";
   // cout<<endl;
    cout<<ans<<endl;

    return 0;
}



Measured memory_bytes: 16128
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    int H, N;
    cin >> H >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    ll sm = accumulate(A.begin(), A.end(), 0);
    cout << ((sm >= H) ? ("Yes") : ("No")) << endl;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int s = sc.nextInt();
        sc.close();

        int count = 0;
        for (int x = 0; x <= k; x++) {
            for (int y = 0; y <= k; y++) {
                int z = s - x - y;
                if (z <= k && z >= 0) count++;
            }
        }

        System.out.println(count);
    }
}


Measured memory_bytes: 22228
import java.util.*;
public class Main{
	public  static void main(String args[]) {
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		String a=n+"";
		char b[]=a.toCharArray();
		int temp=0;
		for(int i=0;i<b.length;i++) {
			if(b[i]=='9') {
				temp++;
				break;
			}
		}
		if(temp==0) {	
			System.out.println("No");
			//System.out.println(n+" does not contain 9.");
		}
		else {
			System.out.println("Yes");
			//System.out.println("The one's digit of "+n+" is 9.");
		}
		in.close();
	}
}

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

bool G[101][101];
char K[2] = {'.','#'};
int A, B;

int main(){
    cin >> A >> B;
    for(int i = 0; i < 50; i++){
        for(int j = 0; j < 100; j++) G[i][j] = 1;
    }
    int cntA = 1;
    for(int i = 0; i < 50; i += 2){
        for(int j = 0; j < 100; j += 2){
            if(cntA == A) break;
            ++cntA;
            G[i][j] = 0;
        }
    }
    int cntB = 1;
    for(int i = 51; i < 100; i += 2){
        for(int j = 0; j < 100; j += 2){
            if(cntB == B) break;
            ++cntB;
            G[i][j] = 1;
        }
    }
    printf("%d %d\n",100,100);
    for(int i = 0; i < 100; i++){
        for(int j = 0; j < 100; j++){
            putchar(K[ G[i][j] ]);
        }
        putchar(0x0A);
    }
    return 0;
}

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

for i in range(h):
    for j in range(w):
        if s[i][j]=='#':
            continue

        v = 0
        for dy in range(-1,2):
            for dx in range(-1,2):
                ny,nx = i+dy,j+dx
                if 0<=ny<h and 0<=nx<w and s[ny][nx]=='#':
                    v += 1
        s[i][j] = str(v)

for i in range(h):
    print(''.join(s[i]))


Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int[] p = new int[24];
	double[] t = new double[24];

	for (int i = 0; i < 24; i++) {
	    p[i] = sc.nextInt();
	    t[i] = sc.nextDouble();
	}

	sort(p, t, 0, 7);
	System.out.println(p[0] +" "+ t[0]);
	System.out.println(p[1] +" "+ t[1]);
	t[0] = 101.0;
	t[1] = 101.0;

	sort(p, t, 8, 15);
	System.out.println(p[8] +" "+ t[8]);
	System.out.println(p[9] +" "+ t[9]);
	t[8] = 101.0;
	t[9] = 101.0;

	sort(p, t, 16, 23);
	System.out.println(p[16] +" "+ t[16]);
	System.out.println(p[17] +" "+ t[17]);
	t[16] = 101.0;
	t[17] = 101.0;

	sort(p, t, 0, 23);
	System.out.println(p[0] +" "+ t[0]);
	System.out.println(p[1] +" "+ t[1]);
    }

    public static void sort(int[] a, double[] b, int start, int last) {
	for (int i = 0; i <= last; i++)
	    for (int j = i; j > start; j--)
		if (b[j-1] > b[j]) {
		    double t = b[j-1];
		    b[j-1] = b[j];
		    b[j] = t;
		    int s = a[j-1];
		    a[j-1] = a[j];
		    a[j] = s;
		}
    }
}

Measured memory_bytes: 28088
#pragma warning(disable:4996)
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<time.h>

using namespace std;

int main() {
	int a;
	cin >> a;
	if (a > 81) {
		cout << "No";
		return 0;
	}
	for (int i = 1; i < 10; ++i) {
		if (a % i == 0 && a / i < 10) {
			cout << "Yes";
			return 0;
		}
	}
	cout << "No";
	return 0;
}


Measured memory_bytes: 256
import java.util.*

fun main(args:Array<String>){
    val (h,w) = readLine()!!.split(" ").map{it.toInt()}
    val s = Array(h) {readLine()!!}
    var sum1 = Array(h) {IntArray(w)}
    var sum2 = Array(h) {IntArray(w)}
    for(i in 0 until h){
        for(j in 0 until w){
            if(s[i][j] == '.'){
                sum1[i][j]++
                sum2[i][j]++
            }
            if(j > 0 && s[i][j] == '.') sum1[i][j] += sum1[i][j - 1]
        }
        for(j in w - 2 downTo 0){
            if(s[i][j] == '.' && s[i][j + 1] == '.') sum1[i][j] = sum1[i][j + 1]
        }
    }
    for(j in 0 until w){
        for(i in 0 until h){
            if(i > 0 && s[i][j] == '.') sum2[i][j] += sum2[i - 1][j]
        }
        for(i in h - 2 downTo 0){
            if(s[i][j] == '.' && s[i + 1][j] == '.') sum2[i][j] = sum2[i + 1][j]
        }
    }
    var ans = 0
    for(i in 0 until h){
        for(j in 0 until w){
            ans = Math.max(ans, sum1[i][j] + sum2[i][j] - 1)
        }
    }
    println(ans)
}


Measured memory_bytes: 86452
N = int(input())
red = [list(map(int, input().split())) for _ in range(N)]
blue = [list(map(int, input().split())) for _ in range(N)]

# x座標でソート
blue.sort(key=lambda x: x[1])

# y座標で降順ソート
red.sort(reverse=True)

# print(blue)
# print(red)

blue_list = [0] * N
red_list = [0] * N


for b in range(N):
    for r in range(N):
        if red_list[r] == 1:
            continue
        if red[r][0] < blue[b][0] and red[r][1] < blue[b][1]:
            # print(b, r)
            blue_list[b] = 1
            red_list[r] = 1
            break

print(sum(blue_list))


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

using namespace std;

#define EPS 1e-10
 
struct Point {
    double x, y;
 
    Point(){}
    Point(double x, double y) : x(x), y(y) {}
 
    Point operator + (const Point &p)const{ return Point(x+p.x,y+p.y); }
    Point operator - (const Point &p)const{ return Point(x-p.x,y-p.y); }
    Point operator * (const double &k)const{ return Point(x*k,y*k); }
};
 
double dot(const Point &a, const Point &b)
{
    return a.x * b.x + a.y * b.y;
}
 
double cross(const Point &a, const Point &b)
{
    return a.x * b.y - b.x * a.y;
}
 
double norm(const Point &p)
{
    return dot(p, p);
}
 
#define COUNTER_CLOCKWISE +1
#define CLOCKWISE         -1
#define ONLINE_BACK       +2
#define ONLINE_FRONT      -2
#define ON_SEGMENT        +0
typedef Point Vector;
 
int ccw(const Point &p0, const Point &p1, const Point &p2)
{
    Vector a = p1 - p0;
    Vector b = p2 - p0;
    if (cross(a, b) > EPS) return COUNTER_CLOCKWISE;
    if (cross(a, b) < -EPS) return CLOCKWISE;
    if (dot(a, b) < -EPS) return ONLINE_BACK;
    if (norm(a) < norm(b)) return ONLINE_FRONT;
    return ON_SEGMENT;
}
 
typedef vector<Point> Polygon;
 
bool sortY(Point p1, Point p2)
{
    if (p1.y != p2.y) {
    return (p1.y - p2.y < -EPS);
    } else { 
    return (p1.x - p2.x < -EPS);
    }
}
 
Polygon convex_hull(Polygon &ps)
{
    int N = ps.size(), j = 0;
    Polygon pg(N*2);
    sort(ps.begin(), ps.end(), sortY);
    for (int i = 0; i < N; i++, j++) {
    while (j >= 2 && ccw(pg[j-2], pg[j-1], ps[i]) == -1) {
        j--;
    }
    pg[j] = ps[i];
    }
    int k = j+1;
    for (int i = N-2; i >= 0; i--, j++) {
    while (j >= k && ccw(pg[j-2], pg[j-1], ps[i]) == -1) {
        j--;
    }
    pg[j] = ps[i];
    }
    pg.resize(j-1);
    return pg;
}
 
int main()
{
    int N;
    char c;
    while (cin >> N, N) {
        Polygon pg(N);
        for (int i = 0; i < N; i++) {
            cin >> pg[i].x >> c >> pg[i].y;
        }        
        cout << N - convex_hull(pg).size() << endl;
    }
    return 0;
}

Measured memory_bytes: 3208
#初期地点
h,w = map(int,input().split())
n=[]
a=[]
a.append(["&"]*(w+2))
for i in range(h):
    arrc = list(input())
    arrc = ["&"]+arrc+["&"]
    b = arrc
    for j in range(len(arrc)):
        if b[j] == "#":
            n.append((i+1,j))
    a.append(b)
a.append(["&"]*(w+2))


#方向
p=[[1,0],[0,1],[-1,0],[0,-1]]
#距離のカウント
cnt=-1
#探索
while n:
    cnt +=1
    n2=[]
    #通った所で総当り
    for i,j in n:
        for di,dj in p:
            di +=i
            dj +=j
            if a[di][dj]==".":
                a[di][dj]="#"
                n2.append((di,dj))
    n=n2
print(cnt)

Measured memory_bytes: 125236
#include <iostream>

using namespace std;
int p[110],t[110];
int main(){
	int i,j,k,l,n,mx = 1000000000;
	cin >> n;
	for(i=0;i<4;i++){
		cin >> p[i];
	}
	for(i=0;i<4;i++){
		cin >> t[i];
	}
	for(i=0;i<=100;i++){
		for(j=0;j<=100;j++){
			for(k=0;k<=100;k++){
				for(l=0;l<=100;l++){
					if(t[0]*i + t[1]*j + t[2]*k + t[3]*l>=n){
						mx = min(mx,p[0]*i + p[1]*j + p[2]*k + p[3]*l);
					}
				}
			}
		}
	}
	cout << mx << endl;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
#define mx 15000000
#define MK 200005
#define pii pair<int,int>
#define tii pair<pii,int>
#define fs first
#define sc second
#define mp make_pair

int dp[105][105],ara[105],n;
int dp_func(int pos,int col)
{
    if(pos>n)return 0;
    if(dp[pos][col]!=-1)return dp[pos][col];
    int ret=20000;
    for(int i=1;i<=101;i++)
    {
        if(i==col)continue;
        ret=min(ret,dp_func(pos+1,i)+(i!=ara[pos]));
    }
    return dp[pos][col]=ret;

}
int name[200000];
int main()
{
    int id=0;
    memset(dp,-1,sizeof dp);
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
            scanf("%d",&ara[i]);
            if(name[ara[i]]==0)
            {
                name[ara[i]]=++id;
            }
            ara[i]=name[ara[i]];
           // cout<<ara[i]<<endl;
    }
    int ans=dp_func(1,0);
    cout<<ans<<endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;

int main(){
	int n;
	int a[100];
	cin >> n;
	for(int i=0;i<n;i++) cin >> a[i];
	for(int i=n-1;i>=0;i--) {
		if(i == 0 )cout << a[i] << endl;
		else cout << a[i] << " ";
	}
	return 0;
}


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

int main() {
  
  int A=0, B=0, C=0;
  
  cin >> A >> B >> C;
  
  vector<int> vec = {A, B, C};
  sort(vec.begin(), vec.end());
  
  int tens = vec.at(2)*10;
  int ones = vec.at(1);
  int remain = vec.at(0);
  
  int pocket = tens+ones+remain;
  
  cout << pocket << endl;
  
}

Measured memory_bytes: 256
fun main(args:Array<String>?): Unit {
    val s = readLine()!!.trim()
    val counts = ('a' .. 'z').map{c -> s.count{it == c}}.toIntArray()
    if (counts.count{it % 2 == 1} <= 1){
        val n = s.length / 2
        counts.indices.forEach{counts[it] /= 2}
        if (n == 0) println(1)
        else println((n.toLong() downTo 1).reduce { acc: Long, l: Long ->
            var res = acc * l
            for (i in counts.indices) {
                if (counts[i] != 0 && res % counts[i] == 0L) {
                    res /= counts[i]
                    counts[i]--
                }
            }
            res
        })
    }else {
        println(0)
    }
}


Measured memory_bytes: 32652
#include <iostream>
#include <vector>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <map>

using namespace std;

int main(int argc, const char * argv[]) {

    string s, t;
    int ans = 0;
    
    cin >> s >> t;
    
    for(int i=0; i<s.length(); i++)
    {
        if(s[i] != t[i]) ans++;
    }
    
    
    cout << ans << endl;
    
}


Measured memory_bytes: 3916
#include <bits/stdc++.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
bool isPalindrome(string str) {
    int l = 0; 
    int h = str.size() - 1; 
    while (h > l){
        if(str[l++] != str[h--]){
            return false; 
        }
    }
    return true; 
}

int main(int argc, char** argv){
	string s;
	cin >> s;
	string first,sec;
	int n{s.size()};
	first = s.substr(0,(n-1)/2);
	sec = s.substr((n+3)/2 - 1,n - (n+3)/2 + 1);
	if(!isPalindrome(s)){
		cout << "No";
		return 0;
	}
	if(!isPalindrome(first)){
		cout << "No";
		return 0;
	}
	if(!isPalindrome(sec)){
		cout << "No";
		return 0;
	}
	cout << "Yes";
	return 0;
}

Measured memory_bytes: 256
#include <cassert>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>
#include <string>
#include <map>
#include <set>
#include <tuple>

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

  size_t N;
  std::cin >> N;
  assert(N <= 100);

  std::vector<double> A(N);
  for (auto& ai: A) std::cin >> ai;

  double res = 0;
  for (auto ai: A) res += 1.0 / ai;
  res = 1.0 / res;

  std::cout << std::fixed << std::setprecision(40000000) << res << std::endl;
}


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

#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
#define repp(i, start, to) for (li i = (li)(start); i < ((li)(to)); i++)

li a[100100];

int main(void)
{
	li n;
	li x;
	cin >> n >> x;

	rep(i, n) {
		cin >> a[i];
	}
	li res = 0;
	li prev = 0;
	rep(i, n) {
		li diff = prev + a[i] - x;
		if (diff > 0) {
			res += diff;
			a[i] -= diff;
		}
		prev = a[i];
	}
	cout << res << endl;


	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

//Lightest Mobile
public class Main{

	static long gcd(long a, long b){
		if(a < b){
			long tmp = a;
			a = b;
			b = tmp;
		}
		while(b!=0){
			long r = a%b;
			a = b;
			b = r;
		}
		return a;
	}

	class R{
		long p, q;
		R l, r, parent;
		public R() {
			l = r = parent = null;
		}
		long get(){
			if(p==0)return 1;
			int k = 1;
			long w1 = l.get();
			long w2 = r.get();
			while(true){
				if((k*q)%w1==0&&(k*p)%w2==0)break;
				k++;
			}
			return k*(p+q);
		}
	}

	void run(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n==0)break;
			R[] s = new R[n+1];
			for(int i=0;i<=n;i++)s[i]=new R();
			for(int i=1;i<=n;i++){
				s[i].p = sc.nextLong();
				s[i].q = sc.nextLong();
				long g = gcd(s[i].p, s[i].q);
				s[i].p/=g;
				s[i].q/=g;
				int l = sc.nextInt();
				int r = sc.nextInt();
				s[i].l = s[l];
				s[i].r = s[r];
				s[l].parent = s[i];
				s[r].parent = s[i];
			}
			R root = null;
			for(int i=1;i<=n;i++)if(s[i].parent==null)root = s[i];
			System.out.println(root.get());
		}
	}

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

Measured memory_bytes: 12000
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include <map>
#include <fstream>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <assert.h>
#include <complex>
#include <omp.h>
using namespace std;
#define eps 0.000001
#define LONG_INF 10000000000000
#define GOLD 1.61803398874989484820458
#define seg_size 65536*4
#define REP(i,n) for(long long i = 0;i < n;++i)
unsigned long xor128() {
	static unsigned long x = time(NULL), y = 362436069, z = 521288629, w = 88675123;
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}




void solve(long long N, std::vector<long long> V, std::vector<long long> C){
    long long ans = 0;
    for(int i = 0;i < N;++i){
        ans += max(0LL,V[i] - C[i]);
    }
    cout << ans << endl;

}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> V(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&V[i]);
    }
    std::vector<long long> C(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&C[i]);
    }
    solve(N, std::move(V), std::move(C));
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>

using namespace std;

typedef vector<int> vi;

#define rep(i,n) for(int i=0;i<n;i++)
#define pb push_back
#define all(c) c.begin(),c.end()

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

int w,h,n;
int x1[1000],x2[1000],y1[1000],y2[1000],X,Y;
bool v[2006][2006];
vi x,y;

int main()
{
	while(cin>>w>>h,w)
	{
		cin>>n;
		x.clear(); y.clear();
		
		rep(i,n)
		{
			cin>>x1[i]>>y1[i]>>x2[i]>>y2[i];
			x.pb(x1[i]),y.pb(y1[i]);
			x.pb(x2[i]),y.pb(y2[i]);
		}
		
		x.pb(0),y.pb(0); x.pb(w),y.pb(h);
		sort(all(x)); sort(all(y));
		x.erase(unique(all(x)),x.end()); y.erase(unique(all(y)),y.end());
		
		X=x.size(),Y=y.size();
		rep(i,n)
		{
			x1[i]=lower_bound(all(x),x1[i])-x.begin();
			y1[i]=lower_bound(all(y),y1[i])-y.begin();
			x2[i]=lower_bound(all(x),x2[i])-x.begin();
			y2[i]=lower_bound(all(y),y2[i])-y.begin();
		}
		
		rep(i,Y)rep(j,X)v[i][j]=i==Y-1||j==X-1;
		rep(i,n)for(int a=x1[i];a<x2[i];a++)
		for(int b=y1[i];b<y2[i];b++)v[b][a]=1;
		
		int ans=0;
		rep(i,Y)rep(j,X)if(!v[i][j])
		{
			ans++;
			v[i][j]=1;
			queue<pair<int,int> > Q; Q.push(make_pair(i,j));
			while(!Q.empty()){
				int a=Q.front().first,b=Q.front().second; Q.pop();
				rep(d,4)
				{
					int ny=a+dy[d],nx=b+dx[d];
					if(ny<0||nx<0||ny>=Y-1||nx>=X-1||v[ny][nx])continue;
					v[ny][nx]=1;
					Q.push(make_pair(ny,nx));
				}
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

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

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    ll a, b, c;
    cin >> a >> b >> c;
    ll x = c - a - b;
    if (x < 0) {
        cout << "No" << endl;
        return 0;
    }
    if (4 * a * b < x * x) {
        cout << "Yes" << endl;
        return 0;
    }
    else {
        cout << "No" << endl;
        return 0;
    }
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr int INF = 1e9;
int main(){ 
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i,n) cin >> h[i];
  vector<int> dp(n,INF);
  dp[0] = 0;
  for (int i = 0; i < n-1; i++) {
    for (int j = 1; j <= k; j++) {
      if (i+j < n) {
        dp[i+j] = min(dp[i+j], dp[i] + abs(h[i+j] - h[i]));
      }
    }
  }
  cout << dp[n-1] << endl;
  return 0;
} 

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
N = int(input())
X = input()
X_10 = int(X, 2)
popcount_X = X.count("1")
popcount_X_plus = popcount_X + 1
popcount_X_minus = popcount_X - 1
f_plus = X_10 % popcount_X_plus
f_minus = X_10 % popcount_X_minus if popcount_X_minus != 0 else 0

def popcount(n):
  return bin(n).count("1")

def f(n):
  if n == 0:
    return 0
  return n % popcount(n)

for i in range(N):
  j = N - (i + 1)
  n = 0
  ans = 1
  
  if X[i] == '0':
#    n = (f_plus + (2**j % popcount_X_plus)) % popcount_X_plus
    n = (f_plus + pow(2, j, popcount_X_plus)) % popcount_X_plus
  else:
    if popcount_X_minus == 0:
      print(0)
      continue
    else:
#      n = (f_minus - (2**j % popcount_X_minus) + popcount_X_minus) % popcount_X_minus
      n = (f_minus - pow(2, j, popcount_X_minus) + popcount_X_minus) % popcount_X_minus
  
  while n > 0:
    n = f(n)
    ans += 1
  print(ans)

Measured memory_bytes: 82704
<?php

fscanf(STDIN,"%d",$n);	
$p = explode(" ",trim(fgets(STDIN)));
 
$max = $n;
$cnt=0;
for($i=0;$i<count($p);$i++){
	if($max>=$p[$i]){
      $max = $p[$i];
      $cnt++;
    }
}
echo $cnt;

?>

Measured memory_bytes: 39684
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define ll long long
#define fr(i,k,N) for(ll i=k; i<N;i++)
#define rep(i,N) for(ll i=0; i<N;i++)
#define ALL(v) v.begin(),v.end()
#define mp make_pair
using namespace std;
template <class X> void pr(X test){cout<<test<<endl;}
template <class X> void prr(X test){for(auto it:test){cout<<it<<endl;}}
template <class X> void prrr(X test){int f=0;for(auto it:test){cout<<(f++!=0?" ":"")<<it;}cout<<endl;}

class UF { // union find from https://github.com/kartikkukreja/blog-codes (MIT)
    // [usage]
    // auto uf = new UF(n);
    // uf->merge(l, r); // 0 <= l, r <= n-1
    // ...
public:
    int *id; // inner id
    int cnt; // number of all vartices
    int *sz; // sz[i] means size of i's set
    UF(int N)   {
        cnt = N;
        id = new int[N];
        sz = new int[N];
        for(int i=0; i<N; i++) {
            id[i] = i;
            sz[i] = 1;
        }
    }
    ~UF() {
        delete [] id;
        delete [] sz;
    }
    int find(int p) {
        int root = p;
        while (root != id[root]) root = id[root];
        while (p != root) {
            int newp = id[p];
            id[p] = root;
            p = newp;
        }
        return root;
    }
    void merge(int x, int y) {
        int i = find(x);
        int j = find(y);
        if (i == j) return;
        
        if (sz[i] < sz[j]) {
            id[i] = j;
            sz[j] += sz[i];
        } else {
            id[j] = i;
            sz[i] += sz[j];
        }
        cnt--;
    }
    bool connected(int x, int y) {
        return find(x) == find(y);
    }
    int count() {
        return cnt;
    }
};

// return sorted 約数s 1 <= x <= n
vector<ll> divv(ll n) {
  vector<ll> v;
  for(ll i = 1; i*i <= n; i++) {
    if(n%i == 0) {
      v.push_back(i);
      if(i*i != n) v.push_back(n/i);
    }
  }
  sort(ALL(v));
  return v;
}

int main() {
    ll n,m,l;
    string s;
    cin>>n>>m;
    ll y = n * 3 + m;
    pr(y/2);
    return 0;
}

Measured memory_bytes: 888
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [input() for _ in range(n)]

H,W=map(int, input().split())
h,w=map(int, input().split())

print(H*W-h*W-w*H+h*w)




Measured memory_bytes: 9056
#include <algorithm>
#include <bitset>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/
const int MOD = 1000000007;

int n;
bool a[21][21];
vector<vector<long long> > dp(21, vector<long long>(1<<21, -1));
long long rec(int now, int used) {
  if (now == n) return 1;
  if (dp[now][used] != -1) return dp[now][used];
  dp[now][used] = 0;
  REP(i, n) if (!(used >> i & 1) && a[now][i]) {
    (dp[now][used] += rec(now + 1, used | 1 << i)) %= MOD;
  }
  return dp[now][used];
}

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  cin >> n;
  REP(i, n) REP(j, n) {
    int aa; cin >> aa;
    a[i][j] = aa;
  }
  cout << rec(0, 0) << '\n';
  return 0;
}


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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int>A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    priority_queue<int> que;
    for (int i = 0; i < N; ++i) {
        que.push(A[i]);
    }
    for (int i = 0; i < M; ++i) {
        int top = que.top();
        que.pop();
        top /= 2;
        que.push(top);
    }
    ll ans = 0;
    for (int i = 0; i < N; ++i) {
        ans += que.top();
        que.pop();
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1276
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	string s;
	cin >> s; 
	reverse(s.begin(), s.end());
	//vector<string>t={ "dream","dreamer","erase","eraser" };
	for (long long i = 0; i < s.size();) {
		if (s.substr(i, 7) == "remaerd") {
			i += 7;
			//cout<< i << endl;
		}
		else if (s.substr(i, 6) == "resare") {
			i += 6;
			//cout << i << endl;
		}
		else if (s.substr(i, 5) == "maerd" || s.substr(i, 5) == "esare") {
			i += 5;
			//cout << i << endl;
		}
		else {
			cout << "NO" << endl;
			exit(0);
		}
		
	
	}
	cout << "YES" << endl;
	
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rep2(i,s,t) for(int i = s; i <= t; ++i)
#define rev(i,n) for(int i = n-1; i >= 0; --i)
#define rev1(i,n) for(int i = n; i > 0; --i)
#define rev2(i,s,t) for(int i = s; i >= t; --i)
#define F first
#define S second
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(a > b){ a = b; return 1; } return 0; }
using ll = long long;
using pi = pair<int,int>;
using vi = vector<int>;
using vii = vector<vi>;
int main()
{
  int n,k; cin >> n >> k;
  vi a(n);
  rep(i,n) cin >> a[i];

  vi dp(k+1, 0);
  rep(i,k) {
    if(dp[i] == 1) continue;
    rep(j,n) {
      if(i + a[j] <= k) {
	dp[i + a[j]] = 1;
      }
    }
  }

  cout << (dp[k] == 1 ? "First" : "Second") << "\n";
  return 0;
}


Measured memory_bytes: 3768
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

int main() {
	std::string A, B; std::cin >> A >> B;
	if (A.size() > B.size()) {
		std::cout << "GREATER" << std::endl;
		return 0;
	}
	else if (A.size() < B.size()) {
		std::cout << "LESS" << std::endl;
		return 0;
	}
	else {
			for (int i = 0; i < A.size(); ++i) {
				if (A[i] > B[i]) {
					std::cout << "GREATER" << std::endl;
					return 0;
				}
				else if (A[i] < B[i]) {
					std::cout << "LESS" << std::endl;
					return 0;
				}
			}
	}
	std::cout << "EQUAL" << std::endl;
	return 0;
}

Measured memory_bytes: 3624
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
if (a < b) {
if (b < c) {
System.out.println(a+" "+b+" "+c);
} else if (a < c) {
    System.out.println(a+" "+c+" "+b);
} else {
    System.out.println(c+" "+a+" "+b);
}
} else {
    if(b>c){
        System.out.println(c+" "+b+" "+a);
    }else if(a>c){
        System.out.println(b+" "+c+" "+a);
    }else {
        System.out.println(b+" "+a+" "+c);
    }
}
}
}


Measured memory_bytes: 26168
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
    static int gcd(int a, int b) {
        if (a % b != 0) {
            return gcd(b, a % b);
        } else {
            return b;
        }

    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int count = 0;
        int n = sc.nextInt();
        int x = sc.nextInt();
        int[] input = new int[n];
        for (int i = 0; i < n; i++) {
            input[i] = sc.nextInt();
        }
        int max = Integer.MAX_VALUE;
        if (input.length == 1) {
            System.out.println(Math.abs(x - input[0]));
            return;
        }
        for (int i = 1; i < n; i++) {
            int temp = Math.abs(x - input[i]);
            int temp2 = Math.abs(x - input[i - 1]);
            int gcd = gcd(temp, temp2);
            if (gcd < max)
                max = gcd;
        }
        System.out.println(max);
    }
}

Measured memory_bytes: 50184
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

using i64 = int64_t;

string s;

int main() {
    cin >> s;

    int N = s.size();
    int ans = 1000;
    for (char c = 'a'; c <= 'z'; ++c) {
        int a = 0;
        int last = -1;
        for (int j = 0; j < N; ++j) {
            if (s[j] == c) {
                a = max(a, j - last - 1);
                last = j;
            }
        }
        a = max(a, N-1-last);
        ans = min(ans, a);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <algorithm>
using namespace std;

#define LOOP(i,n) for(int i=0;i<(n);i++)
#define ULL unsigned long long
#define LL long long

ULL func(ULL c, ULL d){
	ULL e = c % d;
	if (e == 0)return d;
	else return func(d, e);
}

int main(void){
	ULL a, b, c, d;
	cin >> a >> b >> c >> d;

	ULL cd = c * d / func(c, d);
	ULL a_1 = a - 1;

	ULL b_ud, a_1_ud;

	b_ud = b - b / c - b / d + b / cd;
	a_1_ud = a_1 - a_1 / c - a_1 / d + a_1 / cd;
	cout << (b_ud - a_1_ud) << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;

class Main{
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		double T=sc.nextDouble();
		double X=sc.nextDouble();
		pl(T/X);
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
}

Measured memory_bytes: 23124
import math
from functools import reduce

k=int(input())

def gcd(*numbers):
    return reduce(math.gcd,numbers)

ans=0  
for i in range(1,k+1):
  for j in range(1,k+1):
    for l in range(1,k+1):
      ans+=gcd(i,j,l)

print(ans)

Measured memory_bytes: 74708
#include <iostream>
#include <vector>
#include <string>
#include <queue>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define MP make_pair
#define X first
#define Y second

using namespace std;

typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> P;

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

int main(){
	//freopen("test.txt", "r", stdin);
	int w, h;
	while(cin >> w >> h, w|h){
		vector<vi> v(h, vi(w, 0));
		rep(i, h){
			rep(j, w){
				cin >> v[i][j];
			}
		}

		int ans = 0;
		rep(i, h){
			rep(j, w){
				if(v[i][j] != 1)continue;
				ans++;
				queue<P> q;
				q.push(MP(j,i));
				while(!q.empty()){
					P p = q.front();
					q.pop();
					if(v[p.Y][p.X] != 1) continue;
					v[p.Y][p.X] = 0;
					rep(k, 8){
						int x = p.X+dx[k];
						int y = p.Y+dy[k];
						if(x < 0 || x >= w || y < 0 || y >= h) continue;
						q.push(MP(x, y));
					}
				}
			}
		}
		cout << ans << endl;
	}


	return 0;
}

Measured memory_bytes: 1236
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

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

    ll ans = 1e13;
    for(ll i = 1; i * i <= N; i++){
        if(N % i == 0){
            ll tmp = i + (N / i) - 2;
            ans = min(ans, tmp);
        }
    }

    cout << ans << endl;
    return 0;
}

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;
#define vecout(V) for(int i=0;i<V.size();i++) {cout<<V[i]<<endl;}

const int INF = 1001001001;

int main() {
  int h, n;
  cin >> h >> n;
  vector<int> dp(h+1, INF);
  dp[0] = 0;
  rep(i,n) {
    int a, b;
    cin >> a >> b;
    rep(j,h) {
      int nj = min(j+a,h);
      dp[nj] = min(dp[nj], dp[j]+b);
      //cout<<dp[nj]<<" ";
    }
    cout<<endl;
  }
  cout << dp[h] << endl;
  return 0;
}


Measured memory_bytes: 256
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
q = int(input())

ans = sum(a)
count = Counter(a)
for _ in range(q):
  b,c = map(int, input().split())
  count[c] += count[b]
  ans -= b*count[b]
  ans += c*count[b]
  count[b] = 0
  print(ans)

Measured memory_bytes: 24092
ii = lambda:int(input())
mi = lambda:list(map(int,input().split()))
ix = lambda x:list(input() for _ in range(x))
mix = lambda x:list(mi() for _ in range(x))
iix = lambda x:list(int(input()) for _ in range(x))
##########
def main(n,l):
    maxval = max(l)
    th = sum(l) - maxval
    return "Yes" if maxval < th else "No"

n = ii()
l = mi()
print(main(n,l))

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<algorithm>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <set>
#include <queue>
#include <stack>
#include <map>

using namespace std;
typedef long long LL;

int main()
{
   int N,K;
   cin>>N>>K; int sum = 0;
   for(int i = 1;i<=N;i++){
    int temp;
    cin>>temp;

    if(temp>K-temp)
        sum += 2*(K-temp);
    else
        sum += 2*temp;
   }

   cout<<sum<<endl;



    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

std::vector<long long> primes(long long n)
{
  std::vector<long long> res;
  std::vector<char> cand(n);
  for (long long i = 2; i < n; i++) {
    if (cand[i] == 0) {
      res.push_back(i);
      for (int j = i; j < n; j += i) {
        cand[j]++;
      }
    }
  }

  return res;
}

long long greatest_common_divisor(long long n, long long m)
{
    long long s, b;
    if (n > m) {
        b = n;
        s = m;
    }
    else {
        b = m;
        s = n;
    }

    long long mod = 1;
    do {
        mod = b % s;
        b = s;
        s = mod;
    } while(mod != 0);

    return b;
}

long long least_common_multiple(long long n, long long m)
{
    long long g = greatest_common_divisor(n, m);
    return (n * m) / g;
}

long long abc131c(long long A, long long B, long long C, long long D)
{
    long long ans = 0;
    if (C == D || std::max(C, D) % std::min(C, D) == 0) 
    {
        C = std::min(C, D);
        ans = (B - (B / C)) - A + (A - (A / C));
    }
    else {
        long long CD = least_common_multiple(C, D);
        ans = (B - (B / C) - (B / D) + (B / CD)) - A + ((A / C) + (A / D) - (A / CD));
    }

    return ans; 
}

int main()
{
    long long A, B, C, D;
    std::cin >> A >> B >> C >> D;

    long long CD = least_common_multiple(C, D);
    long long b = (B - (B / C) - (B / D) + (B / CD));
    long long a = ((A-1) - ((A-1) / C) - ((A-1) / D) + ((A-1) / CD));
    long long ans = b - a;

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
int main()
{int i;
char str[4];
scanf("%s",str);
for(i=0;i<3;i++)
{
  if(str[i]==str[i+1])
  {
      printf("Bad");
      return 0;
  }
}
printf("Good");
return 0;
}  
    
    
    
    
    
    
    


Measured memory_bytes: 128