akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int A = sc.nextInt();
		int B = sc.nextInt();
		int now = 1;
		int ans = 0;
		while (now < B) {
			now += A - 1;
			ans++;
		}
		System.out.println(ans);
	}

}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 21972
/*  -*- coding: utf-8 -*-
 *
 * 1591.cc: Graph Making
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

typedef long long ll;

/* global variables */

/* subroutines */

/* main */

int main() {
  int n, d;
  scanf("%d%d", &n, &d);

  ll sum = d - 1;
  sum += (ll)(n - d + 1) * (n - d) / 2;
  if (d > 1) sum += n - d - 1;

  printf("%lld\n", sum);
  return 0;
}



Measured memory_bytes: 3232
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <cassert>
#include <cmath>
using namespace std;

int main() {
        int n;
        scanf("%d", &n);
        vector<int> a(n);
        for (int i = 0; i < n; i ++) {
                scanf("%d", &a[i]);
        }
        vector<long long> acc(n);
        acc[0] = a[0];
        for (int i = 1; i < n; i ++) {
                acc[i] += acc[i - 1] + a[i];
        }
        map<long long, int> cnt;
        long long ans = 0;
        for (int i = 0; i < n; i ++) {
                if (acc[i] == 0) {
                        ans ++;
                }
                if (cnt.count(acc[i])) {
                        ans += cnt[acc[i]];
                }
                cnt[acc[i]] ++;
        }
        printf("%lld\n", ans);
        return 0;
}



Measured memory_bytes: 15104
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n, m, l;
    cin >> n >> m >> l;
    int a[n][m], b[m][l];
    long long int c[n][l];
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++)
            cin >> a[i][j];
    }
    for (int i = 0; i < m; i++){
        for (int j = 0; j < l; j++)
            cin >> b[i][j];
    }
    long long int data;
    for (int i = 0; i < n; i++){
        for (int j = 0; j < l; j++){
            data = 0;
            for (int k = 0; k < m; k++){
                data += a[i][k] * b[k][j];
            }
            c[i][j] = data;
        }
    }
    for (int i = 0; i < n; i++){
        for (int j = 0; j < l; j++){
            cout << c[i][j];
            if (j != l - 1)
                cout << " ";
        }
        cout << endl;
    }
}



Measured memory_bytes: 3232
#include<iostream>

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

/**
 * 引数が２で何回割れるかを求めます．
 * @param ２で割られる数
 * @return 割れる回数
 */
int whatTimesDivides(int n) {
    int res = 0; // 割れた回数
    while(true) {
        if (n % 2 == 0) {
            res++;
            n /= 2;
        } else {
            break;
        }
    }
    return res;
} 

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

    int res = 1; // ２で割れる回数がもっとも多いもの
    int max_times = 0;
    // 1 から N までのループ
    rep2(i, 1, N+1) {
        int times = whatTimesDivides(i);        
        if (times > max_times) {
            max_times = times;
            res = i;
        }
    }

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <string>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<long long,long long> P;
typedef pair<long long,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
long long n,h[100005];
ll dp[100005];
#define ALL(v)  (v).begin(),(v).end()
std::set<long long> st;
//#define MAX(a,b) if(a>b)
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))

    /*  ペア関連
    //vector<pair<long long, long long> > pairs(N);
    for(long long i=0; i<N; i++){
        long long a, b;
        cin >> a >> b;
        pairs[i] = make_pair(a, b);
    }
    
    //sort(pairs.begin(), pairs.end(),greater<pair<long long,long long> >());
	sort(pairs.begin(), pairs.end());
    */

 	//stack<long long> sta;   
    //queue<long long> que;


int main(){
	
	long long N,M,K;
	string s;
    long long sum,sum1;
	sum=0;
	sum1=0;
	long long flg,flg1,cnt,cnt1;
	flg=0;
	flg1=0;
	cnt=0;
	cnt1=0;
	long long max;
	long long max1;
	max=0;
	max1=0;
	long long min;
	long long min1;
	min=INF;
	min1=INF;

	long long work1,work2,work3,work4;
	work1=0;
	work2=0;
	work3=0;
	work4=0;
    
	//std::cin >> N;
    std::cin >> N >> K;
    //std::cin >> N >> M >> K;
    
	//std::vector<long long> v(N);
	//std::vector<long long> w(N);
    //std::cin >> s;
    
    
    // 配列入力1
    /*
    for(long long i=0; i<N; i++){
		std::cin >> v[i];
	}
	*/
	// 配列入力2
	/*
	for(long long i=0; i<N; i++){
		std::cin >> w[i];
	}
	*/
    
	
	//通常
	/*
    for(long long i=0; i<N; i++){
		
	}
	*/
	

	//文字列入力
	/*
	for(long long i=0; i<s.length(); i++){
		
		if(s[i]!='1'){
	}
	*/

	
	
	//ソート
    //std::sort(v.begin(),v.end());//昇順ソート
    //std::sort(v.begin(),v.end(),std::greater<long long>());//降順ソート
    //std::sort(w.begin(),w.end());//昇順ソート
    //std::sort(w.begin(),w.end(),std::greater<long long>());//降順ソート
    /*
    
    //S.substr(i, 5);
    //S.size();
    
    for(long long i=0; i<N; i++){
		std::cin >> v[i];
		if(st.find(v[i])==st.end()){
			st.insert(v[i]);
		}
		else{
			st.erase(v[i]);
		}
	}
	*/


	/*
	long long a[4];
	long long value;
	value=0;
	
	a[0] = (value % 10); 
	value /= 10;// 1桁目を取り出す
	a[1] = (value % 10); 
	value /= 10;// 2桁目を取り出す
	a[2] = (value % 10); 
	value /= 10;// 3桁目を取り出す
	a[3] = (value % 10); 
	value /= 10;// 4桁目を取り出す
    work1=a[0]+10*a[1];
    work2=a[2]+10*a[3];
    */
	
	
    if(K!=1){
    	printf("%d",N-K);
    	//printf("%lld",N);
    	//puts("Yes");
    	//printf("%d",st.size());
    	//文字列の出力
    	//std::cout << s << std::endl;
    	//printf("%.12f\n",ret);
    	//cout << sum << endl;
	}
	else{
		puts("0");
	}
	return 0;
}


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

using namespace std;

#define ll long long

ll M = 1000000007;

ll bin_pow(ll a, ll pow) {
    if (pow == 0) return 1;
    if (pow == 1) return a;
    if (pow % 2 == 0) {
        ll tmp = bin_pow(a, pow / 2) % M;
        return tmp * tmp % M;
    }
    return a * bin_pow(a, pow - 1) % M;
}

ll inv(ll a) {
    return bin_pow(a, M - 2) % M;
}

ll fact(ll a) {
    ll ans = 1;
    for (int i = 1; i <= a; i++) {
        ans *= i;
        ans %= M;
    }
    return ans;
}

vector<vector<int>> d;
vector<pair<int, int>> a;

int ans(int n, int t) {
    if (t <= 0 || n == 0) return 0;
    if (d[n][t] == -1) {
        d[n][t] = max(ans(n - 1, t), ans(n - 1, t - a[n - 1].first) + a[n - 1].second);
    }

    return d[n][t];
}

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


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

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int N,i,j,cnt=0,temp;
  int a[100];
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&a[i]);
}
  for(i=0;i<N;i++)
    for(j=0;j<N-1;j++){
      if(a[j]  > a[j+1]){
	temp = a[j];
	a[j] = a[j+1];
	a[j+1] = temp;
	cnt++;
      }
}
  for(i=0;i<N;i++){
    if(i == N-1){
      printf("%d\n",a[i]);
      break;
  }
    printf("%d ",a[i]);
}
  printf("%d\n",cnt);

  return 0;
}



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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

int dp[1500][1500], c[1500][1500];
signed main(void)
{
  int h, w;
  cin >> h >> w;
  REP(i, h) REP(j, w) cin >> c[i][j];

  int ret = -1;
  REP(i, h) REP(j, w) {
    if(!c[i][j]) {
      if(!i || !j) dp[i][j] = 1;
      else dp[i][j] = min({dp[i-1][j], dp[i][j-1], dp[i-1][j-1]}) + 1;
    } else {
      dp[i][j] = 0;
    }
    ret = max(ret, dp[i][j]);
  }
  cout << ret*ret << endl;
  return 0;
}

Measured memory_bytes: 19460
#include <bits/stdc++.h>
typedef long long ll;;
#define int long long 
using namespace std;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPR(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size()) 
#define MAX(x) *max_element(ALL(x)) 
#define MIN(x) *min_element(ALL(x)) 
#define INF 1000000000000 
#define MOD 10000007 
#define MAXR 100000 
#define PI 3.14159265358979323846
using namespace std;

signed main(){

  int n,k ;
  cin >> n>> k;
  vector<int> S(n) ;

  REP(i,k){
   // cout << "I="<<i <<endl ;
    int d ;
    int a ;
    cin >> d;
    REP(j,d){
     // cout << "D="<<d <<endl ;
      cin >> a ;
      S[a-1]++ ;
      //out << "BBB" <<endl ;
    }
  }
  //cout << "aaa" <<endl ;
  int ans =0;
  REP(i,n){
  //  cout << "SI"<<i<<"= "<<S[i] <<endl ;
    if(S[i] == 0) ans++ ;
  }

  cout << ans <<endl ;

}


Measured memory_bytes: 3628
package main

import (
    "fmt"
)

func main() {
    var a, b int
    fmt.Scan(&a, &b)
    var s []byte
    fmt.Scan(&s)
    var ng bool
    for i, c := range s {
        if 0 <= i && i <= a-1 {
            if !isNum(c) {
                ng = true
            }
            continue
        }
        if i == a {
            if c != '-' {
                ng = true
            }
            continue
        }
        if a+1 <= i && i <= a+b {
            if !isNum(c) {
                ng = true
            }
            continue
        }
    }
    if len(s) != a+b+1 {
        ng = true
    }
    if ng {
        fmt.Println("No")
    } else {
        fmt.Println("Yes")
    }
}

func isNum(b byte) bool {
    return '0' <= b && b <= '9'
}


Measured memory_bytes: 512
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;
#define int long long


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

    int a,b; cin >> a >> b;
    int sum = 1;
    int ans = 0;

    while(sum < b){
        sum -= 1;
        sum += a;
        ans ++;
    }

    cout << ans << endl;
}


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

int main(){
  int N,W; cin >> N >> W;
  int w[100000],v[100000];
  for(int i=0; i<N; i++) cin >> w[i] >> v[i];
  long long dp[101][100001];
  memset(dp,0,sizeof(dp));
  
  for(int i=0; i<N; i++){
    for(int j=0; j<=W; j++){
      if(j>=w[i]){
        dp[i+1][j]=max(dp[i][j],dp[i][j-w[i]]+v[i]);
      }else{
        dp[i+1][j]=dp[i][j];
      }
    }
  }
  cout << dp[N][W] << endl;
}

Measured memory_bytes: 79744
# include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, mod = 1e9 + 7;
long long n, m, maxL, minR = mod;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= m; i++){
        long long l, r;
        cin >> l >> r;
        maxL = max(maxL, l);
        minR = min(minR, r);
    }
    if(minR < maxL){
        cout << "0\n";
    }else{
        cout << minR - maxL + 1 << endl;
    }
}


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

public class Main{
	public static void main(String[] args)throws IOException{
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(isr);
		String string;
		char ch[];
		
		int n, res;
		while(!(string = reader.readLine()).equals("0")){
			n = Integer.valueOf(string);
			
			int map[][] = new int[n][n];
			int sum[][] = new int[n + 1][n + 1];
			ch = reader.readLine().toCharArray();
			for(int i = 0; i < n; i++){
				map[0][i] = (ch[i] == '.' ? 1 : 0);
				
				if(i > 0){
					sum[1][i + 1] = sum[1][i] + map[0][i];
				}else{
					sum[1][i + 1] = map[0][i];
				}
			}
			for(int i = 1; i < n; i++){
				ch = reader.readLine().toCharArray();
				for(int j = 0; j < n; j++){
					map[i][j] = (ch[j] == '.' ? 1 : 0) + map[i - 1][j];
					
					if(j > 0){
						sum[i + 1][j + 1] = sum[i + 1][j] + map[i][j];
					}else{
						sum[i + 1][1] = map[i][0];
					}
				}
			}
			
			if(sum[n][n] == 0){
				System.out.println(0);
				continue;
			}
			res = 1;
			x : for(int w = n + 1; w > 0; w--){
				for(int i = n; i > 0; i--){
					if(i - w < 0) break;
					for(int j = n; j > 0; j--){
						if(j - w < 0) break;
						
						if(sum[i][j] - sum[i - w][j] - sum[i][j - w] + sum[i - w][j - w] == w * w){
							res = w;
							break x;
						}
					}
				}
			}
			System.out.println(res);
		}
		reader.close();
	}
}

Measured memory_bytes: 67388
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <utility>
#include <algorithm>
#include <limits>
#include <iomanip>
#include <bitset>

#define INF 1000000000
#define Inf 1000000000000000000
#define mp make_pair
#define pb push_back
#define EPS 1e-9

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;

int n, a, b;

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

    if ((b - a) % 2 == 0) cout << "Alice" << endl;
    else cout << "Borys" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const ll INFLL = 100100100100100100;
const int MOD = (int)1e9 + 7;
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

int main () {

    int n; cin >>n;
    vector<ll> h(n); REP(i,n) cin >> h[i];

    vector<ll> dp(100100, INFLL);
    dp[0] = 0;
    for (int j = 1; j < n; j++) {
        dp[j] = min(dp[j], dp[j-1] + abs(h[j] - h[j-1]));
        if (j-2 >= 0) {
            dp[j] = min(dp[j], dp[j-2] + abs(h[j] - h[j-2]));
        } 
    }

    cout << dp[n-1] << endl;

    return 0;
}



Measured memory_bytes: 1792
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


string s;

bool solve() {
    if (s[0] == s.back()) {
        if ( s.size() % 2 == 0) return true;
    }
    else {
        if ( s.size() % 2 != 0) return true;
    }
    return false;
}

int main() {
    while (cin >> s) {
        if(solve()) puts("First");
        else puts("Second");
    }
}





Measured memory_bytes: 512
h, w, m = [int(e) for e in input().split()]

htotal = [0] * h
wtotal = [0] * w


hmax = 0
wmax = 0

s = set()
hl = []
wl = []

for i in range(m):
    hi, wi = [int(e) for e in input().split()]
    hi -= 1
    wi -= 1

    s.add((hi, wi))
    htotal[hi] += 1
    wtotal[wi] += 1

    if htotal[hi] > hmax:
        hmax = htotal[hi]
        hl = [hi]
    elif htotal[hi] == hmax:
        hl.append(hi)

    if wtotal[wi] > wmax:
        wmax = wtotal[wi]
        wl = [wi]
    elif wtotal[wi] == wmax:
        wl.append(wi)

m = hmax + wmax - 1
for he in hl:
    if m == hmax + wmax:
        break
    for we in wl:
        if m == hmax + wmax:
            break
        if not (he, we) in s:
            m += 1

print(m)
    

Measured memory_bytes: 67932
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
long long a[100001],c,f,l,r,n,z,x,maxz=0;
long long s;
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin>>n;
    for(int i=1; i<=n; i++)
        cin>>a[i];
    l=2;
    r=n;
    s=a[1];
    while(l!=r)
    {
        if(__gcd(s,a[l])<__gcd(s,a[r])){
            r--;
            s=__gcd(s,a[r+1]);
        }
        else{
            l++;
            s=__gcd(s,a[l-1]);
        }
    }
    maxz=max(maxz,s);
    s=a[n];
    l=1;
    r=n-1;
    while(l!=r)
    {
        if(__gcd(s,a[l])<__gcd(s,a[r])){
            r--;
            s=__gcd(s,a[r+1]);
        }
        else{
            l++;
            s=__gcd(s,a[l-1]);
        }
    }
    maxz=max(s,maxz);
    cout<<maxz<<endl;
}


Measured memory_bytes: 1024
def isCLKWISE(ph) : return not ((ph[-1][0] - ph[-3][0])*(- ph[-3][1] + ph[-2][1]) - (ph[-2][0] - ph[-3][0])*(- ph[-3][1] + ph[-1][1] ) < 0)
      
def ConvexHullScan(P):
    P = sorted(P)
    phU = [P[0],P[1]]
    for p in P[2:]:
        phU.append(p)
        if isCLKWISE(phU) : continue
        while(True):
            del phU[-2]
            try:
                if isCLKWISE(phU) : break
            except IndexError : break
    phL = [P[-1],P[-2]]
    for p in P[-3::-1]:
        phL.append(p)
        if isCLKWISE(phL) : continue
        while(True):
            del phL[-2]
            try:
                if isCLKWISE(phL) : break
            except IndexError : break
      
    ph = phU + phL[1:-1]
    return ph
  
n = range(int(input()))
P = [[int(x) for x in input().split()] for _ in n]
Q = ConvexHullScan(P)
Q.reverse()
print(len(Q))
idx = min([[x[1][1],x[1][0],x[0]] for x in enumerate(Q)])[2]
R = Q[idx:] + Q[:idx]
for r in R : print(r[0],r[1])

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

using namespace std;

int main(){
        int N, K;
        cin >> N >> K;
        vector< vector<int> > assign(K);
        for(int i = 0; i < K; ++i){
                int m;
                cin >> m;
                assign[i].resize(m);
                for(int j = 0; j < m; ++j){
                        cin >> assign[i][j];
                        --assign[i][j];
                }
        }
        int R;
        cin >> R;
        vector< vector<int> > mat(N, vector<int>(N));
        while(R--){
                int p, q;
                cin >> p >> q;
                --p; --q;
                mat[p][q] = mat[q][p] = 1;
        }
        int answer = 0;
        for(int i = 0; i < K; ++i){
                for(int j = 0; j < assign[i].size(); ++j){
                        for(int k = 0; k < assign[i].size(); ++k){
                                if(mat[assign[i][j]][assign[i][k]]){
                                        ++answer;
                                        break;
                                }
                        }
                }
        }
        cout << answer << endl;
        return 0;
}

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

int main(void) {
    int N;cin>>N;
    string S;cin>>S;
    int ma = 0;
    int x = 0;
    for (int i = 0; i < S.size(); i++) {
        char s = S[i];
        if (s == 'I') x++;
        else x--;
        if (ma < x) ma = x;
    }
    cout << ma << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#define ll long long
#define N 5010
using namespace std;

ll a,b,x;

int main()
{
	int i,j;
	cin>>a>>b>>x;
	cout<<b/x-a/x+(bool)(a%x==0);
	
}

Measured memory_bytes: 256
n = gets.to_i
points = (1..n).map { gets.split.map(&:to_i) }

a = [0] * (n / 2)
k = n / 2 - 1
max = 0

loop do
  b = (0..n-1).to_a
  c = []
  k.downto(0) do |i|
    c << b.shift
    c << b.delete_at(a[i])
  end

  angles = c
    .map{|i| points[i]}
    .each_slice(2)
    .map {
      |p1, p2| p1[0] == p2[0] ? Float::INFINITY : (p2[1] - p1[1]) * 1000000 / (p2[0] - p1[0])
    }
  m = angles
    .group_by(&:itself)
    .values
    .map(&:size)
    .map {|s| s * (s - 1) / 2}
    .inject(:+)
  max = m if m > max
  
  a[k] += 1
  while k > 0 && a[k] > 2 * k
    a[k] = 0
    a[k -= 1] += 1
  end
  break if k == 0
  k = n / 2 - 1
end

p max



Measured memory_bytes: 7380
#include <iostream>
#include <math.h>

using namespace std;

int main()
{
    int i,n,x,ans=0,sum=0,a[10]= {0,9,0,900,0,90000};
    cin>>n;
    x=n;
    while(x>0)
    {
        x/=10;
        sum++;
    }
    if(sum%2!=0)
    {
        ans+=n-pow(10,sum-1)+1;
        for(i=0; i<sum; i++)
            ans+=a[i];
    }
    else
    {
        for(i=0; i<sum; i++)
            ans+=a[i];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
signed main(){
  init_io();
  ll n,q,ans=0,sum=0;
  cin >> n ;
  vector<ll> a(n);
  map<ll,ll> mp;
  for(int i=0;i<n;i++){
    cin >> a[i];
    mp[a[i]]++;
    sum += a[i];
  }
  cin >> q;
  vector<ll> b(q),c(q);
  for(int i=0;i<q;i++){
    cin >>b[i] >> c[i];
    mp[c[i]] += mp[b[i]];
    sum += (c[i]-b[i])*mp[b[i]];
    mp.erase(b[i]);
    cout << sum << endl;
  }
}


Measured memory_bytes: 9532
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int N,M,a[3],dp[50];
vector<int> G[50];
int inf=1e8;
bool can[101][50][50];
int main(){
	cin>>N>>M>>a[0]>>a[1]>>a[2];
	rep(i,M){
		int v,w;
		cin>>v>>w;
		v--,w--;
		G[v].pb(w);
	}
	rep(i,N) can[0][i][i]=1;
	rep(i,100){
		rep(v,N) for(int u:G[v]) rep(x,N) if(can[i][u][x]) can[i+1][v][x]=1;
	}
	rep(i,N) dp[i]=inf;
	dp[N-1]=0;
	bool update=1;
	while(update){
		update=0;
		rep(i,N){
			int mx=-1;
			rep(j,3){
				int mn=inf;
				rep(v,N){
					if(can[a[j]][i][v]) chmin(mn,dp[v]+1);
				}
				chmax(mx,mn);
			}
			if(mx<dp[i]){
				update=1;
				dp[i]=mx;
			}
		}
	}
	if(dp[0]==inf) puts("IMPOSSIBLE");
	else cout<<dp[0]<<endl;
}

Measured memory_bytes: 3432
#include "bits/stdc++.h"
using namespace std;


int main()
{



        string s; cin >> s;
        map< char, int > mp;
        for(auto x : s) mp[ x ]++;

        if(  mp.size() == 26 ) {

                string temp = "";

                for(char ch = 'a' ; ch <= 'z' ; ch++) {
                        temp += ch;
                }
                reverse( temp.begin(), temp.end() );

                if( s == temp ) {
                        puts("-1");
                        return 0;
                }
                vector< string > v;
                map< char, int > save;
                string astro = "";
                for(auto x : s) {

                        char green = x; green++;
                        for(char ch = green; ch <= 'z' ; ch++ ) {
                                if( ch < 'a' || ch > 'z' ) break;
                                if( save.find(ch ) == save.end() ) {
                                        string test = astro + ch;
                                        //cout << test << endl;
                                        if( test > s ) {
                                                v.push_back(test);
                                        }
                                }
                        }

                        save[ x ]++;
                        astro += x;
                }
                sort( v.begin(), v.end() );
                cout << v[0] << endl;

        } else {
                for(char ch = 'a' ; ch <= 'z' ; ch++ ) {
                        if( mp.find(ch) == mp.end() ) {
                                s.push_back(ch);
                                break;
                        }
                }
                cout << s << endl;
        }


        return 0;
}


Measured memory_bytes: 256
def main():
    x,n = tuple([int(t)for t in input().split()])

    p = tuple([int(t)for t in input().split()])

    nums = set(range(0,102))

    for p_i in p:
        nums.discard(p_i)

    dist = 10**8
    ans = -1

    for i in nums:
        if dist>abs(x-i):
            dist = abs(x-i)
            ans = i

    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 9200
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using VI = vector<int>;
using VB = vector<bool>;
using Graph = vector<vector<int>>;
using ll = long long;
using P = pair<int, int>;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n ) cin >> a[i];

  vector<int> b = a;

  sort(all(a), greater<int>());
  map<int, int> mp;

  rep(i, n) {
    mp[a[i]]++;
  }

  int mx = a[0];
  int second = a[mp[mx]];

  rep(i, n){
    if (b[i] == mx && mp[b[i]] == 1){
      cout << second << endl;
    } else if (mx == b[i] && mp[b[i]] > 1){
      cout << mx << endl;
    } else {
      cout << mx << endl;
    }
  }
}

Measured memory_bytes: 8704
#include<iostream>
#include<cstdlib>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;

int l,r[12],n;
string in,tmp;
vector<int> dp[1<<12];
double dpv[1<<12];

double cal(vector<int> v){
  double res = 0;
  int i;
  if(v.size()){
    res += r[v[0]];
    for(i=0;i<(int)v.size()-1;i++)res += sqrt( pow(r[v[i]]+r[v[i+1]],2) - pow(r[v[i]]-r[v[i+1]],2));
    res += r[v[i]];
  }
  return res;
}

int main(){
  while(getline(cin,in)){
    int pos = 0;
    bool f = false;
    n = 0;
    while(1){
      if(pos>=(int)in.size() || in[pos]==' '){
	if(!f){
	  l = atoi(tmp.c_str());
	  f = true;
	}else{
	  r[n] = atoi(tmp.c_str());
	  n++;
	}
	tmp.clear();
	if(pos>=(int)in.size())break;
      }else{
	tmp.push_back(in[pos]);
      }
      pos++;
    }

    for(int i=0;i<(1<<n);i++){
      dp[i].clear();
      dpv[i] = 1000.0;
    } 
    
    for(int i=1;i<(1<<n);i++){
      for(int j=0;j<n;j++){
	if(i&(1<<j)){
	  int g = i-(1<<j);
	  vector<int> hoge = dp[g];
	  hoge.push_back(j);

	  double s = cal(hoge);
	  if(s<dpv[i]){
	    dp[i] = hoge;
	    dpv[i] = cal(hoge);
	  }
	  /*
	  for(int x=0;x<(int)hoge.size();x++)cout << r[hoge[x]] << " ";
	  cout << endl;
	  */
	  for(int k=(int)hoge.size()-1;k>=1;k--){
	    swap(hoge[k],hoge[k-1]);
	    /*
	    for(int x=0;x<(int)hoge.size();x++)cout << hoge[x] << " ";
	    cout << endl;
	    */
	    s = cal(hoge);
	    
	    if(s<dpv[i]){
	      dp[i] = hoge;
	      dpv[i] = s;
	    }
	    
	  }
	  //cout << endl;
	}
      }
    }
    /*
    cout << dpv[(1<<n)-1] << endl;
    for(int i=0;i<n;i++)cout << r[dp[(1<<n)-1][i]] << " ";
    cout << endl;
    */
    if(dpv[(1<<n)-1]>l)cout << "NA" << endl;
    else cout << "OK" << endl;
  }
}

Measured memory_bytes: 0
#include <stdio.h>

int main(void){
	int h,w;
	int i,j;

	do{
		scanf("%d %d",&h,&w);
		if(h == 0&&w == 0){
			break;
		}
		for(i = 0;i < h;i++){
			for(j = 0;j < w/2;j++){
				if(i%2==0){
					printf("#.");
				}else{
					printf(".#");
				}
			}
			if(i%2 == 0 && w%2 != 0){
				printf("#");
			}else if(i%2 != 0 && w%2 != 0){
				printf(".");
			}


			printf("\n");
		}
		printf("\n");
	}while(1);
	
	return 0;
}
					

Measured memory_bytes: 588
#include <iostream>
#include <string>
#include <cctype>
using namespace std;

int main(){
	string str;
	getline(cin, str);

	for(int i=0;i<str.length();i++){
		if(islower(str[i]))      str[i] = toupper(str[i]);
		else if(isupper(str[i])) str[i] = tolower(str[i]);
	}
	
	cout<<str<<endl;

	return 0;
}

Measured memory_bytes: 1180
#include<iostream>
#include<cstdio>
#include<map>
#include<string>
using namespace std;
int main(){
	string s;
	bool month = false;
	map<int,pair<int,int> > com;
	for(;;){
		getline(cin,s);
		if(s.find(',') == string::npos){
			if(!month){month = true;continue;}
			else{break;}
		}
		int a = 0;
		sscanf(s.c_str(),"%d,%*d",&a);
		if(!month){com[a].first |= 1;}
		if(month){com[a].first |= 2;}
		com[a].second++;
	}
	for(__typeof(com.begin()) i = com.begin(); i!=com.end(); i++){
		if(i->second.first == 3){cout << i->first << " " << i->second.second << endl;}
	}
	return 0;
}

Measured memory_bytes: 0
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use std::cmp::*;
use std::collections::*;
use std::mem::*;

fn main() {
    let (r, w, e) = (std::io::stdin(), std::io::stdout(), std::io::stderr());
    let mut io = IO::new(r.lock(), w.lock(), e.lock());
    let (n, k) = (io.read::<usize>(), io.read::<usize>());
    let mut mp = BTreeMap::new();
    for _ in 0..n {
        let (a, b) = (io.read::<usize>(), io.read::<usize>());
        let m = mp.entry(a).or_insert(0);
        *m += b;
    }
    let mut sm = 0;
    for (key, val) in mp {
        sm += val;
        if sm >= k {
            io.writeln(key);
            return;
        }
    }
}

static MX: usize = 1010101;
static MOD: i64 = 1000000007;
static INF: i64 = std::i64::MAX >> 1;
// IO
use std::io::*;
struct IO<R: Read, W: Write, E: Write> {
    Read: R,
    Write: BufWriter<W>,
    Error: BufWriter<E>,
}
impl<R: Read, W: Write, E: Write> IO<R, W, E> {
    fn new(r: R, w: W, e: E) -> IO<R, W, E> {
        IO {
            Read: r,
            Write: BufWriter::new(w),
            Error: BufWriter::new(e),
        }
    }
    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
    {
        let next: String = self
            .Read
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();
        next.parse().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    fn chari(&mut self) -> Vec<i64> {
        self.chars()
            .iter()
            .map(|&c| (c as u8 - b'0') as i64)
            .collect::<Vec<i64>>()
    }
    fn readn<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect::<Vec<_>>()
    }
    fn readmat<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n).map(|_| self.readn(m)).collect()
    }
    fn write<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
    }
    fn writeln<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
        self.Write.write(b"\n");
    }
    fn debug<S: std::fmt::Debug>(&mut self, val: S) {
        writeln!(self.Error, "(debug) {:?}", &val);
    }
    fn debug2<S: std::fmt::Debug, T: std::fmt::Debug>(&mut self, val1: S, val2: T) {
        writeln!(self.Error, "(debug2) {:?} -> {:?}", val1, val2);
    }
    fn debug3<S: std::fmt::Debug, T: std::fmt::Debug, U: std::fmt::Debug>(
        &mut self,
        val1: S,
        val2: T,
        val3: U,
    ) {
        writeln!(
            self.Error,
            "(debug3) {:?} -> {:?} -> {:?}",
            val1, val2, val3
        );
    }
}


Measured memory_bytes: 4352
#include <stdio.h>
int main()
{
    int m,b,c,x,y;
    scanf("%d %d %d", &m, &b, &c);

    x=b-m;

    y=c-b;


    if(x==y)
    {
        printf("YES");
    }
    else{
        printf("NO");
    }
    return 0;
}

Measured memory_bytes: 1708
import Foundation

extension String {
    func split(separator: String) -> [Int] {
        return self.componentsSeparatedByString(separator).map { Int($0)! }
    }
}

let S = readLine()!

var ans: [Int] = [0]
var i = 0
for c in S.characters {
    if c == "A" || c == "C" || c == "G" || c == "T" {
        ans[i] += 1
    } else {
        ans.append(0)
        i += 1
    }
}


print(ans.maxElement()!)

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


int main()
{
	int n,k,m,x,c=0;
	cin>>n>>k;
	int A[n+1]={0};
	for(int p=1;p<=k;p++)
	{
		cin>>x;
		for(int i=1;i<=x;i++)
		{
			cin>>m;
			A[m]++;
		}
	}
	for(int i=1;i<=n;i++)
	{
		if(A[i]==0)
		c++;
	}
	cout<<c<<endl;

}

Measured memory_bytes: 3636
import sys
import itertools
input = sys.stdin.readline

n, m = map(int, input().split())
k, s = [0]*m, [0]*m
for i in range(m):
    k[i], *s[i] = map(int, input().split())

p = list(map(int, input().split()))
ans = 0
state = [i for i in itertools.product((0, 1), repeat=n)]

for case in state:
    flag = True
    for i in range(m):  # 電球iにおいて
        sum = 0
        for j in s[i]:
            sum += case[j-1]
        if sum % 2 != p[i]:
            flag = False
        if not flag:  # 電球消えてたら次のケースに移る
            break
    if flag:
        ans += 1

print(ans)


Measured memory_bytes: 3188
A, B, C, X, Y = map(int, input().split())
total = 0
ans = 10**10

for i in range(0, max(X, Y)*2+2, 2):
  total = A*(max(X-(i/2),0)) + B*(max(Y-(i/2),0)) + C*i
  # print(total)
  ans = min(ans, total)
  
print(int(ans))

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

int N;
int A[100010];

int main()
{
    long long ans = 0;
    scanf("%d",&N);
    for(int i = 0; i < N; i++)
    {
        scanf("%d",&A[i]);
    }
    long long now = 0;
    for(int i = 0; i < N; i++)
    {
        now += A[i];
        if(i % 2)
        {
            if(now >= 0)
            {
                ans += now + 1;
                now = -1;
            }
        }
        else
        {
            if(now <= 0)
            {
                ans += now * -1 + 1;
                now = 1;
            }
        }
    }
    long long mem = ans;
    ans = 0;
    now = 0;
    for(int i = 0; i < N; i++)
    {
        now += A[i];
        if(!(i % 2))
        {
            if(now >= 0)
            {
                ans += now + 1;
                now = -1;
            }
        }
        else
        {
            if(now <= 0)
            {
                ans += now * -1 + 1;
                now = 1;
            }
        }
    }
    mem = min(mem,ans);
    printf("%lld\n",mem);
}


Measured memory_bytes: 640
#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 G = vector<vector<int>>;
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; }
    
int main(){
    int r, c, k;
    cin >> r >> c >> k;
    vector<vector<ll>> val(r, vector<ll>(c));
    rep(i,k){
        int a, b;
        ll v;
        cin >> a >> b >> v;
        a--; b--;
        val[a][b] = v;
    }

    vector<vector<vector<ll>>> dp(3005, vector<vector<ll>>(3005, vector<ll>(4)));

    rep(i,r)rep(j,c){
        for(int l=2; l>=0; l--) chmax(dp[i][j][l+1],dp[i][j][l]+val[i][j]);
        rep(l,4){
            chmax(dp[i][j+1][l],dp[i][j][l]);
            chmax(dp[i+1][j][0], dp[i][j][l]);
        }
    }

    ll ans = *max_element(dp[r-1][c-1].begin(), dp[r-1][c-1].end());
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 708768
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))

using namespace std;


int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int dxx[8] = { 0,0,1,1,1,-1,-1,-1 };
int dyy[8] = { 1,-1,0,1,-1,0,1,-1 };


ll m = 1000000007;

const int MOD = 1000000007;

ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}



long long nCr(int n, int r) {
	if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
	long long ans = 1;
	int i;

	for (i = 1; i <= r; i++) {
		ans *= n - r + i;
		ans /= i;
	}

	return ans;
}


ll dif(ll a, ll b, ll c) {
	ll MIN = min(min(a, b), c);
	ll MAX = max(max(a, b), c);
	return MAX - MIN;
}
int main() {
	ll H, W;
	cin >> H >> W;
	ll ans = 9999999999999;
	if (H % 3 == 0 || W % 3 == 0) {
		ans = 0;
		cout << ans << endl;
		return 0;
	}
	else {
		ll ans = INF;
		FOR(i,0, H) {
			ll a = i * W;
			ll b, c, B, C;
			ll d1 = (H - i) / 2;
			ll d2 = H - i - d1;
			B = d1 * W;
			C = d2 * W;
			if (W % 2 == 0) {
				b = (H - i)*(W / 2);
				c= (H - i)*(W / 2);
			}
			else {
				b= (H - i)*(W / 2);
				c = (H - i)*(W / 2 + 1);
			}
			ans = min(ans, dif(a, b, c));
			ans = min(ans, dif(a, B, C));
		}
		FOR(i,0, W) {
			ll a = i * H;
			ll b, c,B,C;
			ll d1 = (W - i) / 2;
			ll d2 = W - i - d1;
			B = d1 * H;
			C = d2 * H;
			if (H % 2 == 0) {
				b = (W - i)*(H / 2);
				c = (W - i)*(H / 2);
			}
			else {
				b = (W - i)*(H / 2);
				c = (W - i)*(H / 2 + 1);
			}
			ans = min(ans, dif(a, b, c));
			ans = min(ans, dif(a, B, C));
		}
		cout << ans << endl;
		return 0;
	}
}


Measured memory_bytes: 256
#include <vector>
#include <string>
#include <iostream>
using namespace std;
string next_str(string s) {
	vector<bool> used(26);
	for (int i = 0; i < s.size(); ++i) {
		used[s[i] - 'a'] = true;
	}
	for (char i = s.back() + 1; i <= 'z'; ++i) {
		if (!used[i - 'a']) {
			s.back() = i;
			return s;
		}
	}
	return "-1";
}
int main() {
	string s;
	cin >> s;
	if (s.size() != 26) {
		vector<bool> used(26);
		for (int i = 0; i < s.size(); ++i) {
			used[s[i] - 'a'] = true;
		}
		for (int i = 0; i < 26; ++i) {
			if (!used[i]) {
				cout << s + (char)(i + 'a') << endl;
				break;
			}
		}
	}
	else {
		string ans = "-1";
		for (int i = s.size(); i >= 1 && ans == "-1"; --i) {
			ans = next_str(s.substr(0, i));
		}
		cout << ans << endl;
	}
	return 0;
}

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

int main()
{
  long long a, b, x;

  cin >> a >> b >> x;

  if( a == 0 ) {
    cout << b / x + 1 << endl;
  }
  else {
    cout << b / x - ( a - 1 ) / x << endl;
  }

  return 0;
}


Measured memory_bytes: 760
from math import gcd 
from functools import reduce
import itertools

def resolve():
  K = int(input())
  gcds = sum([ gcd(gcd(x[0], x[1]), x[2]) for x in itertools.product(range(1, K+1), range(1, K+1), range(1, K+1)) ])
  print(gcds)

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 71968
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cout << #x << ": " << x << endl
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'

int gcd(int a, int b){ return ((b == 0) ? a : gcd(b, a % b)); }

map<int, int> m;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n, M;
	cin >> n >> M;
	ll a[n];
	rep(i, n) cin >> a[i];
	sort(a, a + n);
	rep(i, M){
		int b, c;
		cin >> b >> c;
		m[c] += b;
	}
	ll sum = 0LL;
	rep(i, n){
		if(m.size() && m.rbegin() -> fi > a[i]){
			a[i] = m.rbegin() -> fi;
			m.rbegin() -> se--;
			if(m.rbegin() -> se == 0) m.erase(m.rbegin() -> fi);
		}
		sum += a[i];
	}
	cout << sum << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 5760
package main

import "fmt"

func main() {
	var n, k, cnt int
	fmt.Scan(&n, &k)

	nums := make([]int, n)
	for i := range nums {
		fmt.Scan(&nums[i])
	}
	for _, v := range nums {
		if v >= k {
			cnt++
		}
	}

	fmt.Println(cnt)
}


Measured memory_bytes: 5504
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph= vector<vector<int>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define fi first 
#define se second
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
// ミント
const int mod = //1e9+7 ;
998244353;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
//昆布
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
  mint p(int n,int k){
    return fact[n]*ifact[n-k] ;
  }
}   ;
 
mint modpow(ll a,ll b){
 if(b==0) return 1 ;
 mint c= modpow(a,b/2) ;
 if(b%2==1) return c*c*a ;
 else return c*c ;
}

mint komb(ll n,ll m){
  mint x=1 ;mint y=1 ;
  rep(i,m){
    x*= n-i ;
    y*= i+1 ;
  }
  return x/y ;
}

 
 map<ll,ll> factor(ll n){  //素因数とオーダーをマップで管理
  map <ll,ll> ord ;  
  for(ll i=2;i*i<=n;i++){
        if(n%i==0){
            int res=0;
            while(n%i==0){
                n/=i;
                res++;
            }
            ord[i]=res;
        }
    }
   if(n!=1) ord[n]++;
   return ord ;
 }

int main(){
  ll n ; cin>> n ;
 vector<ll> A(n) ; rep(i,n) cin>>A[i] ;
 bool ok= 1 ;
 if(A[0]!=0) ok  =0 ;
 vector<ll> cnt(n) ;
 cnt[0]++ ;
 rep(i,n-1){
   if(A[i+1]==0) ok=0 ;
   cnt[A[i+1]] ++ ;
 }
 rep(i,n-1){
  if(cnt[i]==0&&cnt[i+1]!=0) ok=0 ;
 }

 if(!ok) cout<<0<<endl ;
 else{
   mint ans= 1 ;
   rep2(i,1,n-1){
    if(cnt[i]!=0) ans = ans* modpow(cnt[i-1],cnt[i]) ;
   }
   cout<<ans<<endl ;
 }
    return 0;
  }
   

Measured memory_bytes: 4824