akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long ll;
typedef long long l;
int main()
{
    l m = 1000000007;
l h,w;
cin>>h>>w;
char arr[h][w];

for( l i = 0 ; i<h ; i++)
{
    for( l j = 0 ;j<w ; j++)
    cin>>arr[i][j];
}


l dp[h][w];
for( l i = 0 ; i<h ; i++)
{
    for( l j = 0 ;j<w ; j++)
    dp[i][j]=0;
}
dp[0][0]=1;

l temp = h+w;
for( l i = 0 ; i< h ; i++)
{
    if(arr[i][0]=='#')
   {
       dp[i][0]=0;
       temp = i;
       break;
   }
   else
   dp[i][0]=1;
}
for(l i = temp ; i<h;i++)
dp[i][0]=0;
for( l i = 0 ; i< w ; i++)
{
    if(arr[0][i]=='#')
    {
        dp[0][i]=0;
        temp = i;
    break;
    }
    else 
    dp[0][i]=1;
}
for(l i = temp ; i<w;i++)
dp[0][i]=0;
l a , b;
for( l i = 1 ; i< h ; i++)
{
    for( l j = 1 ; j<w;j++)
    {
        a = ((arr[i-1][j]=='#')?0:dp[i-1][j])%m;
        b = ((arr[i][j-1]=='#')?0:dp[i][j-1])%m;
        dp[i][j]=(a+b)%m;
    }
}

/*for( l i = 0 ; i<h ; i++)
{
    for( l j = 0 ;j<w ; j++)
    {cout<<dp[i][j]<<" ";}
    cout<<endl;
} */
cout<<dp[h-1][w-1];
return 0;
}


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

int main(){
    int n;
    cin >> n;
    if(((n/100%10)==(n/10%10)&&(n/10%10)==(n%10))||((n/1000%10)==(n/100%10)&&(n/100%10)==(n/10%10)))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<int,pii> pip;

int dp[105][105];

int main(void) {
    int i,j;
    int n, m, l;
    while(cin >> n >> m >> l, n){
        vector<vector<pip> > v(n);
        rep(i,m){
            int a,b,d,e;
            cin >> a >> b >> d >> e;
            a--,b--;
            v[a].push_back(pip(b,pii(d,e)));//to,cost,num
            v[b].push_back(pip(a,pii(d,e)));
        }
        priority_queue<pip,vector<pip>,greater<pip> > q;

        rep(i,105)rep(j,105)dp[i][j] = INF;
        dp[0][0] = 0;
        q.push(pip(0,pii(0,0)));//num,v,cost
        while(q.size()){

            int now_v = q.top().second.first;
            int now_cost = q.top().second.second;
            int now_num = q.top().first;
            q.pop();

            if(dp[now_v][now_cost] < now_num)continue;

            rep(i,v[now_v].size()){
                int next_v = v[now_v][i].first;

                //護衛するときは、お金がかかるが襲われる人数は増えない
                int next_cost1 = now_cost + v[now_v][i].second.first;
                int next_num1 = now_num;

                if(next_cost1 <= l && dp[next_v][next_cost1] > next_num1){
                    dp[next_v][next_cost1] = next_num1;
                    q.push(pip(next_num1,pii(next_v,next_cost1)));
                }

                //護衛しないときは、お金はかからないが襲われる人数が増える
                int next_cost2 = now_cost;
                int next_num2 = now_num + v[now_v][i].second.second;

                if(next_cost2 <= l && dp[next_v][next_cost2] > next_num2){
                    dp[next_v][next_cost2] = next_num2;
                    q.push(pip(next_num2,pii(next_v,next_cost2)));
                }

            }
        }
        int ans = INF;
        rep(i,l+1){
            ans = min(ans, dp[n-1][i]);
        }
        cout << ans << endl;
    }
}



Measured memory_bytes: 3488
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
struct BIT {
	ll M;
	std::vector<ll> bit;
	BIT(ll n) {
		init(n);
	}
	void init(ll n) {
		M = n;
		bit.resize(M + 1);
		fill(bit.begin(), bit.end(), 0);
	}
	ll sum(ll i) {
		ll s = 0;
		while (i > 0) {
			s += bit[i];
			i -= i & -i;
		}
		return s;
	}
	void add(ll i, ll x) {
		while (i <= M) {
			bit[i] += x;
			i += i & -i;
		}
	}
};


int main() {
	int N;
	cin >> N;
	vector<int>A(N);
	vector<int>A_Sort(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
		A_Sort[i] = A[i];
	}
	sort(A_Sort.begin(), A_Sort.end());
	int l = 0;
	int r = N;
	while (l + 1 < r) {
		int c = (l + r) / 2;
		vector<int>B(N);
		for (int i = 0; i < N; ++i) {
			B[i] = (A[i] < A_Sort[c]) ? -1 : 1;
		}
		vector<int>S(N);
		for (int i = 0; i < N; ++i) {
			S[i] = (i == 0) ? B[i] : S[i - 1] + B[i];
		}
		long long cnt = 0;
		BIT bit(2 * N + 1);
		bit.add(N, 1);
		for (int i = 0; i < N; ++i) {
			cnt += bit.sum(S[i] + N);
			bit.add(S[i] + N, 1);
		}
		if (cnt >= (long long)N*(N + 1) / 4) {
			l = c;
		}
		else {
			r = c;
		}
	}
	cout << A_Sort[l] << endl;
	return 0;
}


Measured memory_bytes: 6424
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

int main(){
    ll N;
    cin >> N;
    vector<ll> V(5);
    ll min_v = 1e16;
    for(int i=0; i<5; i++) {
        cin >> V[i];
        min_v = min(min_v, V[i]);
    }
    ll X = N/min_v;
    if(N % min_v == 0) {
        X--;
    }
    cout << 5 + (ll)(X) << endl;
}

Measured memory_bytes: 3536
#include <iostream>
#include <cmath>
#include <climits>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <numeric>
using namespace std;
// scanf
#pragma warning(disable: 4996)
// v:vector  type:型  order:greater or less
#define _sort(v,type,order) do { sort(v.begin(),v.end(),order<type>()); } while(0)
// v:vector  default_value:初期値
#define _sum(v,default_value) accumulate(v.begin(),v.end(),default_value )
// 丸め
#define _round(v) round(v)
// 2乗 / 3乗
#define _square(v) pow(v,2)
#define _cube(v)   pow(v,3)
// 大小判定
#define _max(x,y) max(x,y)
#define _min(x,y) min(x,y)
// string ⇒ int
#define _stringtoi(s) stoi(s)
// double 平方根
#define _sqrt(x) sqrt(x)
// double 引数 x 以上で最小の整数値
#define _ceil(x) ceil(x)

int main()
{
	uint32_t a, b, k;
	cin >> a >> b >> k;

	uint32_t i;
	for (i = a; i <= min(b,a+k-1); i++) {
		printf("%d\n", i);
	}
	if (i > b) {
		return 0;
	}
	i = (i >= (b-k+1) ? i : b-k+1);
	for (;i <= b; i++) {
		printf("%d\n", i);
	}
	return 0;
	//	std::cout << "Hello World!\n"; 
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int 
#define w(x) int x; cin>>x; while(x--)
#define pb push_back
#define mp make_pair
#define mod 1000000007
using namespace std;
int main(){
#ifndef ONLINE_JUDGE 
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll a,b,c,x,y;
	cin>>a>>b>>c>>x>>y;
	ll z=min(x,y);
	ll ab=c*z*2;
	if(x>y)
		ab+=(x-y)*a;
	else
		ab+=(y-x)*b;
	ll m=a*x+b*y;
	ll n=c*2*(max(x,y));
	cout<<min(m,min(n,ab));
	

}

Measured memory_bytes: 3636
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        h: usize,
        w: usize,
        c: [Chars;h],
    }

    for i in 0..h {
        for _ in 0..2 {
            for j in 0..w {
                print!("{}", c[i][j]);
            }
            print!("\n");
        }
    }

}


Measured memory_bytes: 2192
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{

    static class Program
    {
        static void Main()
        {
            Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
            //

            var cin = GetIntArray();
            var ans = Math.Max(cin[0] - cin[1], 0);

            Console.WriteLine(ans);

            //
            Console.Out.Flush();
            Console.ReadKey();
        }

        static void Solve()
        {

        }





        static public string GetStr() { return Console.ReadLine().Trim(); }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public string[] GetStrArray() { return Console.ReadLine().Split(' '); }
        static public int[] GetIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
        static public long[] GetLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
        static public char[] GetCharArray() { return Console.ReadLine().Split(' ').Select(char.Parse).ToArray(); }
        static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
        static public void WriteObjects<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
        static string yesno(this bool b) { return b ? "yes" : "no"; }
        static string YesNo(this bool b) { return b ? "Yes" : "No"; }
        static string YESNO(this bool b) { return b ? "YES" : "NO"; }

        static bool eq<T, U>() => typeof(T).Equals(typeof(U));
        static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
        static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
                           : eq<T, long>() ? ct<T, long>(long.Parse(s))
                           : eq<T, double>() ? ct<T, double>(double.Parse(s))
                           : eq<T, char>() ? ct<T, char>(s[0])
                                             : ct<T, string>(s);
        static void Multi<T>(out T a) => a = cv<T>(GetStr());
        static void Multi<T, U>(out T a, out U b)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]);
        }
        static void Multi<T, U, V>(out T a, out U b, out V c)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]);
        }
        static void Multi<T, U, V>(out T a, out U b, out V c, out V d)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<V>(ar[3]);
        }
    }
}

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

long long a[300000], b[300000], c[300000];
long long sums[300000]={0}; //a[0]~a[i]?????§??????

int main(){
	int n, m;
	
	scanf(" %d", &n);
	for(int i=0; i<n; ++i) scanf(" %lld", &a[i]);
	sort(a, a+n);
	
	sums[0]=a[0];
	for(int i=0; i<n-1; ++i) sums[i+1]=a[i+1]+sums[i]; 
		
	scanf(" %d", &m);
	for(int i=0; i<m; ++i) scanf(" %lld", &b[i]);	
	for(int i=0; i<m; ++i) scanf(" %lld", &c[i]);
	
	//?????????i??????????????????
	for(int i=0; i<m; ++i){
		bool ans;
		if(b[i]<a[0]){
			if(c[i]==0) ans=true;	
			else ans=false;
		}
		else if(a[n-1]<=b[i]){
			if(c[i]<=sums[n-1]) ans=true;
			else ans=false;	
		}
		else{
			//cout << upper_bound(a, a+n, b[i])-a-1 << " <-point" << endl;
			if(sums[upper_bound(a, a+n, b[i])-a-1] >= c[i]) ans=true;
			else ans=false;
		}		
		
		if(ans) printf("Yes\n");
		else printf("No\n");
	}
	
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define inv(n, a) for(int i = 0; i < n; i++) cin >> a[i]
#define MOD 1000000007
#define INF 1e7
#define LINF 1e15
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<int>>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
// 'a' = 97 'z' = 122 => 'a' = 0 'z' = 25

int main() {
    int n; cin >> n;
    vector<int> a(n), b(n);
    bool ng = false;
    rep(i, n){
        cin >> a[i];
        b[a[i]]++;
        if(b[a[i]] == 3) ng = true; // A の値が同じものが 3つ以上あると矛盾
    }
    if(b[0] >= 2 || ng){ // A の値が 0 のものが 2つ以上あっても矛盾
        cout << 0 << endl;
        return 0;
    }
    ll ans = 1;
    rep(i, n){
        if(b[i] == 0) continue;
        ans = ((ans % MOD) * b[i]) % MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<int>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
int comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*invkaijo[a-b]%mod*invkaijo[b]%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}

signed main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int x;
    cin>>x;
    if(x<600)cout<<8<<endl;
    else if(x<800)cout<<7<<endl;
    else if(x<1000)cout<<6<<endl;
    else if(x<1200)cout<<5<<endl;
    else if(x<1400)cout<<4<<endl;
    else if(x<1600)cout<<3<<endl;
    else if(x<1800)cout<<2<<endl;
    else if(x<2000)cout<<1<<endl;
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

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

int main() {

    int N, M;
    cin >> N >> M;

    for (int i = 1; i <= (M + 1) / 2; i++) {
        int k = (M + 1) / 2 - i;
        k = 2 * k + 1;
        printf("%d %d\n", i, i + k);
    }

    int start_even = 1 + 2 * ((M + 1) / 2 - 1) + 1;
    for (int i = 1; i <= M / 2; i++) {
        int k = M / 2 - i;
        k = 2 * (k + 1);
        printf("%d %d\n", start_even + i, start_even + i + k);
    }
    
    return 0;
}

Measured memory_bytes: 3748
from math import *
from statistics import median
N=int(input())
A,B=[],[]
for i in range(N):
    a,b=map(int,input().split())
    A.append(a);B.append(b)
A.sort();B.sort()
if N%2:
    ans=median(B)-median(A)+1
else:
    ans=(median(B)-median(A))*2+1
print(int(ans))

Measured memory_bytes: 28740
from collections import deque

H,W=map(int,input().split())
Sx,Sy=map(int,input().split())
Gx,Gy=map(int,input().split())
Sx-=1
Sy-=1
Gx-=1
Gy-=1
tmp=False
check=deque()

M=[[0 if j=='.' else 1 for j in input()]for i in range(H)]

# 0通路 1壁 2確認済み

ans=0
check.append([Sx,Sy])
while True:
    hit=set()
    while check:
        x,y = check.pop()
        #goul
        if x==Gx and y==Gy:
            tmp=True
            break
        M[x][y]=2
        #壁があるか
        for dx,dy in [ [x+1,y],[x-1,y],[x,y-1],[x,y+1] ]:
            if not(0<=dx and dx<H and 0<=dy and dy<W):
                continue
            if M[dx][dy]==1:
                hit.add((x,y))
            if M[dx][dy]==0:
                check.append([dx,dy])
    if tmp:
        print(ans)
        break
    if len(hit)==0:
        print(-1)
        break
    for e in hit:
        x,y=e
        for i in range(-2,3):
            for j in range(-2,3):
                if 0<=x+i and x+i<H and 0<=y+j and y+j<W and M[x+i][y+j]==0:
                    check.append([x+i,y+j])
    if len(check)==0:
        print(-1)
        break

    ans+=1

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

struct sushi {
  int d, t;
};

int main () {
  int k, n;
  cin >> n >> k;
  vector<sushi> s(n);
  vector<int> usedT(n+1, 0);
  rep(i,n) {
    cin >> s[i].t >> s[i].d;
  }

  sort(s.begin(), s.end(), [](const sushi &a, const sushi &b){
      return a.d > b.d;
    });
  ll ans = 0;
  ll tc = 0;
  priority_queue<ll, vector<ll>> q;
  priority_queue<int, vector<int>, greater<int>> surplus;
  rep(i,k) {
    ans += s[i].d;
    if(usedT[s[i].t]) {
      surplus.push(s[i].d);
    } else {
      usedT[s[i].t] = 1;
      ans += 2*tc + 1;
      tc++;
    }
  }
  q.push(ans);

  for(int i = k; i < n; i++) {
    if(surplus.size() == 0) break;
    if(usedT[s[i].t]) continue;
    ans += s[i].d - surplus.top() + 2*tc + 1;
    tc++;
    surplus.pop();
    q.push(ans);
    usedT[s[i].t] = 1;
  }

  cout << q.top() << endl;

  return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int, int>;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int main() {
  int s, w;
  cin >> s >> w;

  if (w >= s) cout << "unsafe" << endl;
  else cout << "safe" << endl;
}

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

int main(){
  int N;
  ll cnt=0;
  cin >> N;
  vector<string> S(N);
  map<string,int> m;
  rep(i,N){
    cin >> S.at(i);
    sort(S.at(i).begin(),S.at(i).end());
  }
  rep(i,N){
    if(m.count(S.at(i))){
      cnt += m.at(S.at(i));
      ++m.at(S.at(i));
    }else{
      m[S.at(i)] = 1;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 18176
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int a = in.nextInt();
		int p = in.nextInt();
		System.out.println(solve(a, p));
		in.close();
	}

	private static int solve(int a, int p) {
		return (a * 3 + p) / 2;
	}
}

Measured memory_bytes: 21716
def get_last(num):
    str_num = str(num)
    last_num = str_num[-1]
    if int(last_num) == 0:
        return 10
    else:
        return int(last_num)

def gauss_10(num):
    if get_last(num) == 10:
        return num
    else:
        return num + (10-get_last(num))

list = []
for i in range(5):
    list.append(int(input()))


list_last = [get_last(i) for i in list]
last_index = list_last.index(min(list_last))

total = 0
for i, minutes in enumerate(list):
    if i == last_index:
        total += minutes
    else:
        total += gauss_10(minutes)
print(total)


Measured memory_bytes: 3064
import java.util.*

fun main(args: Array<String>) {
    var list = IO.readIntList()
    var ans = list[2] - (list[0] - list[1])
    ans = if (ans < 0) 0 else ans
    println(ans)
}

object IO {
    fun readInt(): Int {
        return readLine()!!.toInt()
    }
    fun readIntList(): List<Int> {
        return readLine()!!.split(" ").map(String::toInt)
    }
}

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

struct Point{
    long x;
    long y;
    Point(double x, double y) : x(x), y(y) {}
};
typedef Point Vector;
long get_dot(Vector v1, Vector v2){
    return v1.x * v2.x + v1.y * v2.y;
}
long get_cross(Vector v1, Vector v2){
    return v1.x * v2.y - v1.y * v2.x;
}

int main(){
    int x_p0, y_p0, x_p1, y_p1;
    cin >> x_p0 >> y_p0 >> x_p1 >> y_p1;
    Vector v1(x_p1 - x_p0, y_p1 - y_p0);
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int x_p2, y_p2;
        cin >> x_p2 >> y_p2;
        Vector v2(x_p2 - x_p0, y_p2 - y_p0);
        double cross = get_cross(v1, v2);
        if (cross > 0) {
            cout << "COUNTER_CLOCKWISE" << endl;
            continue;
        }
        if (cross < 0) {
            cout << "CLOCKWISE" << endl;
            continue;
        }
        long dot = get_dot(v1, v2);
        if (dot < 0) {
            cout << "ONLINE_BACK" << endl;
            continue;
        }
        long norm1 = get_dot(v1, v1);
        long norm2 = get_dot(v2, v2);
        if (norm1 < norm2) {
            cout << "ONLINE_FRONT" << endl;
            continue;
        }
        cout << "ON_SEGMENT" << endl;
    }
    return 0;
}



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

int main(void)
{
    int n,a[101],b[101],sum=0,i;
    scanf("%d",&n);
    for(i=0;i<n;i++) a[i]=b[i]=0;
    for(i=0;i<n-1;i++)
    {
        scanf("%d",&a[i]);
    }
    b[n-1]=a[n-2];b[0]=a[0];
    for(i=n-2;i>0;i--)
    {
        if(a[i-1]>a[i]) b[i]=a[i];
        else b[i]=a[i-1];
    }
    for(i=0;i<n;i++) sum+=b[i];
    printf("%d",sum);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

ll rec(int n, ll x)
{
  if (n == 0)
    return 1;
  ll len = (1LL << (n + 1)) - 3;
  ll num = (1LL << n) - 1;
  if (x == 1)
    return 0;
  else if (x <= len + 1)
    return rec(n - 1, x - 1);
  else if (x == len + 2)
    return num + 1;
  else if (x <= (len + 1) * 2)
    return num + 1 + rec(n - 1, x - len - 2);
  else
    return num * 2 + 1;
}


int main()
{
  int n;
  ll x;
  cin >> n >> x;
  cout<<rec(n,x)<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int a = 0;
    int b = 0;
    int c = 0;
    int temp = 0;
    
    scanf("%d%d%d",&a,&b,&c);
    
    if(b < a){
        temp = a;
        a = b;
        b = temp;
    }
    
    if(c < b){
        temp = b;
        b = c;
        c = temp;
    }
    
    if(b < a){
        temp = a;
        a = b;
        b = temp;
    }
    
    printf("%d %d %d\n",a,b,c);
    
    return 0;
}



Measured memory_bytes: 2112
#include <iostream>

using namespace std;
int main() {
    int N,K;
    cin>>N>>K;
    int d[K];//iのお菓子を持っている人数
    int A[N];//お菓子を持っているかフラグ
    for(int i=0;i<N;i++){
        A[i]=0;
    }
    int count =0;
    for(int i =0;i<K;i++)
    {
      cin>>d[i];
      //cout<<d[i]<<endl;
      for(int t=0;t<d[i];t++)
      {
        int num=0;
        cin>>num;
        A[num-1]=1;
      }
    }
    for(int t=0;t<N;t++)
      {
        bool flg =true;
        //cout<<A[t]<<endl;
        if(A[t]==1)flg=false;      
        if(flg)count++;
      }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 3616
#include <stdio.h>
#define BUF (101)

int N,K;
int x[BUF];
void input(void){
	scanf("%d",&N);
	scanf("%d",&K);
	x[0]=0; //dummy
	for(int i=1;i<=N;i++)scanf("%d",&x[i]);
}

int main(void){
	input();
	int dis=0;
	int k=K/2;
	for(int i=1;i<=N;i++){
		if(x[i]>k){
			 dis+=2*(K-x[i]);
		}else{
			dis+=2*x[i];
		}
	}

	printf("%d\n",dis);

	return 0;
}

Measured memory_bytes: 128
n,m=map(int, input().split())
an=[int(i) for i in input().split()]
import fractions
ans=an[0]
for i in range(1, n):
    ans = ans * an[i] // fractions.gcd(ans, an[i])

def count2(i):
    if i%2==0:
        c=0
        while i%2==0:
            i//=2
            c+=1
        return c
    else:
        return 0
    
c2=count2(ans)

for ak in an:
    if ak%(2**c2)==0:
        d=1
        pass
    else:
        d=0
        break

if d==0:
    print(0)
else:
    lca=ans//2
    if (m//lca)%2==0:
        print((m//lca)//2)
    else:
        print(((m//lca)+1)//2)


Measured memory_bytes: 14400
N, P = map(int, input().split())
S = input()

if P != 2 and P != 5:
    p_array = [0] * P
    mod = 0
    amari = 1
    for i, s in enumerate(S[::-1]):
        s = int(s)
        mod = (mod + s * amari) % P
        amari = amari * 10 % P
        p_array[mod] += 1

    ans = 0
    for i, p in enumerate(p_array):
        if i == 0:
            ans += p
        ans += (p * (p-1) // 2)

    print(int(ans))

else:
    ans = 0
    for i, s in enumerate(S):
        if int(s) % P == 0:
            ans += (i+1)
    print(ans)


Measured memory_bytes: 42096
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
#include <iostream>
#include <stack>
#include <vector>
#include <string>
#include <map>
#include <cmath>
#include <queue>

using namespace std;

const int maxn = (1 << 21) + 5;

int n;

int a[25][25];

int dp[maxn];
const int mod = 1e9 + 7;

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

int main(){
    cin >> n;
    for(int i = 0;i < n;i++){
        for(int j = 0;j < n;j++){
            scanf("%d", &a[i][j]);
        }
    }
    dp[0] = 1;
    for(int i = 0;i < n;i++){
        for(int mask = 0;mask < (1 << n);mask++){
            int num = __builtin_popcount(mask);
            if(num != i)
                continue;
            for(int j = 0;j < n;j++){
                if(a[i][j] == 0)
                    continue;
                if(mask & (1 << j))
                    continue;
                int mask1 = mask | (1 << j);
                add(dp[mask1], dp[mask]);
            }
        }
    }
    cout << dp[(1 << n) - 1] << endl;
    return 0;
}


Measured memory_bytes: 8448
N, M, K = map(int, input().split())
for r in range(N + 1):
    black = r * M
    b_c, w_c = r, N - r
    for c in range(M + 1):
        if black - b_c * c + w_c * c == K:
            print("Yes")
            quit()
print("No")


Measured memory_bytes: 2940
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
#include <numeric>
#include <bitset>
#include <cassert>
#include <functional>

using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<ll, ll> P;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#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)

int main()
{
    int H, A;
    cin >> H >> A;
    int cnt = 0;
    while (H > 0)
    {
        H -= A;
        cnt++;
    }
    cout << cnt;
    return 0;
}

Measured memory_bytes: 256
num_sunuke, num_okashi = map(int, input().split())

have_okashi_sunuke_dict = {}
for i in range(num_okashi):
    input()
    num_have_okashi_sunukes = map(int, input().split())
    for num_have_okashi_sunuke in num_have_okashi_sunukes:
        have_okashi_sunuke_dict[num_have_okashi_sunuke] = ''

print(num_sunuke - len(have_okashi_sunuke_dict))


Measured memory_bytes: 9168
import sys
s=input()
T=input()
for i in range(len(s)-len(T)+1,0,-1):
  for j in range(len(T)):
    if T[j]!=s[i-1+j] and "?"!= s[i-1+j] :
      break
  else:
    s=s[:i-1]+T+s[i+len(T)-1:]
    s = s.replace('?', 'a')
    print(s)
    sys.exit()
else: print("UNRESTORABLE")

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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

const int T = 400000;
const double PI = atan2(0, -1);

int n;
int x[100], y[100];
double len[100];
double ang[100];
double ans[100];

int main() {
    if (0) {
        mt19937 mt(123);
        n = 100;
        forn(i, n) x[i] = mt() % 2000001 - 1000000;
        forn(i, n) y[i] = mt() % 2000001 - 1000000;
    } else {
        scanf("%d", &n);
        forn(i, n) scanf("%d%d", x + i, y + i);
    }
    forn(i, n) {
        if (x[i] == 0 && y[i] == 0) {
            len[i] = 0;
        } else {
            ang[i] = atan2(y[i], x[i]) + PI;
            len[i] = sqrt((double)x[i] * x[i] + (double)y[i] * y[i]);
        }
    }
    forn(i, T) {
        double a = 2 * PI * i / T;
        pair<double, int> res = mp(1e20, 0);
        forn(j, n) {
            res = min(res, mp(cos(ang[j] - a) * len[j], j));
        }
        ans[res.second] += 1.0 / T;
    }
    forn(i, n) printf("%.12f\n", ans[i]);
    return 0;
}


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

#define f first
#define s second
#define pb push_back
#define all(x) x.begin(), x.end()

using LL   =  long long;
using pii  =  pair <int, int>;
using vii  =  vector <pii>;

const int INF = INT_MAX;
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;

int C[N];
int S[N];
int F[N];

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

    int n;
    cin>>n;

    for(int i = 1; i < n; i++)
    {
        cin>>C[i]>>S[i]>>F[i];
    }

    for(int i = 1; i < n; i++)
    {
        int t = 0;
        for(int j = i; j < n; j++)
        {
            if(S[j] > t)
            {
                t = S[j];
            }
            if(t > S[j])
            {
                int x = ceil(1.0 * (t - S[j]) / F[j]);
                t = S[j] + x * F[j];
            }
            t += C[j];
        }
        cout<<t<<"\n";
    }

    cout<<"0\n";
    return 0;
}


Measured memory_bytes: 256
def warshall_floyd(d):
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])

    return d

N, M = map(int, input().split())
d = [[float('inf') for i in range(N)] for i in range(N)]
edges = []

for i in range(M):
    a,b,c = map(int, input().split())
    a -= 1
    b -= 1
    d[a][b] = c
    d[b][a] = c
    edges.append([a,b,c])

warshall_floyd(d)

# 与えられた頂点間の辺の距離が求めた最短距離より大きければ
# その辺は使われない
cnt = 0
for edge in edges:
    if d[edge[0]][edge[1]] != edge[2]:
        cnt += 1

print(cnt)

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  
  ll n,k; cin >> n >> k; k -= 1;
  string s; cin >> s;
  if (s[k] == 'A') s[k] = 'a';
  else if (s[k] == 'B') s[k] = 'b';
  else s[k] = 'c';
  
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
#include<cstring>
#include<sstream>
using namespace std;

typedef long long ll;

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

  vector<int> num;
  int now = 1;
  int cnt = 0;
  for ( int i = 0; i < s.length(); i++ ) {
    if ( s[i] == (char)('0' + now) ) cnt++;
    else {
      num.push_back(cnt);
      now = 1 - now;
      cnt = 1;
    }
  }
  num.push_back(cnt);

  vector<int> data(num.size()+1);
  for ( int i = 0; i < num.size(); i++ ) {
    data[i+1] = data[i] + num[i];
  }
  int Add = K * 2 + 1;
  int ans = 0;
  for ( int i = 0; i < num.size(); i += 2 ) {
    int left = i;
    int right = min(i + Add, (int)num.size() );
    int sum = data[right] - data[left];
    ans = max(sum, ans);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1272
import sys

def input():
    return sys.stdin.readline().rstrip('\n')

N = int(input())
S = input()
#D = list(map(int, input().split()))

if N % 2 == 1:
    print('No')
    sys.exit()

s1 = S[:N//2]
s2 = S[N//2:]

if s1 == s2:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 38384
use std::fmt::Debug;
use std::io;
use std::io::{Read, Stdin};
use std::str;
use std::str::FromStr;
use std::usize;
use std::cmp;

struct Rule {
    left: usize,
    x: usize,
}

fn main() {
    let mut sc = Scanner::new();
    let n = sc.parse::<usize>();
    let m = sc.parse::<usize>();

    let mut rules: Vec<Vec<Rule>> = Vec::new();
    for _ in 0..(n + 1) {
        rules.push(Vec::new());
    }
    for _ in 0..m {
        let l = sc.parse::<usize>();
        let r = sc.parse::<usize>();
        let x = sc.parse::<usize>();
        rules[r].push(Rule { left: l, x: x });
    }

    let mut dp = vec![vec![vec![0;(n+1)];(n+1)];(n+1)];
    dp[0][0][0] = 1;
    let modulo = 1000000007;
    for r in 0..n {
        for g in 0..n {
            for b in 0..n {
                let k = cmp::max(cmp::max(r, g), b);
                if check(&rules, k + 1, g, b) {
                    dp[k + 1][g][b] += dp[r][g][b];
                    dp[k + 1][g][b] %= modulo;
                }
                if check(&rules, r, k + 1, b) {
                    dp[r][k + 1][b] += dp[r][g][b];
                    dp[r][k + 1][b] %= modulo;
                }
                if check(&rules, r, g, k + 1) {
                    dp[r][g][k + 1] += dp[r][g][b];
                    dp[r][g][k + 1] %= modulo;
                }
            }
        }
    }

    let mut ans = 0;
    for i in 0..n {
        for j in 0..n {
            ans += dp[i][j][n];
            ans %= modulo;
            ans += dp[i][n][j];
            ans %= modulo;
            ans += dp[n][i][j];
            ans %= modulo;
        }
    }
    println!("{}", ans);
}

fn check(rules: &Vec<Vec<Rule>>, r: usize, g: usize, b: usize) -> bool {
    let k = cmp::max(cmp::max(r, g), b);
    for rule in &rules[k] {
        let left = rule.left;
        let mut count = 0;
        if r >= left {
            count += 1;
        }
        if g >= left {
            count += 1;
        }
        if b >= left {
            count += 1;
        }
        if count != rule.x {
            return false;
        }
    }
    return true;
}

struct Scanner {
    stdin: Stdin,
    buf: Vec<u8>,
}

impl Scanner {
    fn new() -> Scanner {
        Scanner {
            stdin: io::stdin(),
            buf: Vec::with_capacity(256),
        }
    }

    fn parse<T: FromStr>(&mut self) -> T
        where <T as FromStr>::Err: Debug
    {
        self.buf.clear();
        let mut it = self.stdin.lock().bytes();
        let mut c = it.next().unwrap().unwrap();
        while c == ' ' as u8 || c == '\n' as u8 {
            c = it.next().unwrap().unwrap();
        }
        while !(c == ' ' as u8 || c == '\n' as u8) {
            self.buf.push(c);
            c = it.next().unwrap().unwrap();
        }
        str::from_utf8(&self.buf).unwrap().parse::<T>().unwrap()
    }
}

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

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

ll d[200001];
int a[200001];

int main(){
    int n;
    cin>>n;
    for(int i=0;i<=n;i++){
        d[i]=0;
    }
    for(int i=0;i<n;i++){
                cin>>a[i];
                d[a[i]]++;
    }
    ll count=0;
    for(int i=0;i<=n;i++){
        count+=d[i]*(d[i]-1)/2;
    }
    for(int i=0;i<n;i++){
        cout<<count-d[a[i]]+1<<endl;
    }
    return 0;
}

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

long long stick[100000];

int main() {
    int N, count;
    long long now_stick = 0, first_stick = 0, second_stick = 0;
    cin >> N;
    for (int i = 0; i < N; i++) cin >> stick[i];
    sort(stick, stick + N);
    for (int i = N - 1; i >= 0; i--) {
        if (now_stick != stick[i]) {
            count = 1;
            now_stick = stick[i];
        }
        else {
            if (count == 1) {
                if (first_stick == 0) {
                    first_stick += now_stick;
                    now_stick = 0;
                    continue;
                }
                else {
                    second_stick += now_stick;
                    break;
                }
            }
            count++;
        }
    }
    if (first_stick == 0 || second_stick == 0) cout << 0 << endl;
    else cout << first_stick * second_stick << endl;
    return 0;
}

Measured memory_bytes: 1024
//入力マクロここから
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
//入力マクロここまで

fn main() {
    input! {
        s: chars,
    }

    let n = s.len();
    let mut cnt = 0;

    for (f, b) in s[..n / 2].iter().zip(s[n / 2..].iter().rev()) {
        if f != b {
            cnt += 1;
        }
    }

    println!("{}", cnt);
}


Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<cmath>
#include<iomanip>
using namespace std;

int gcd(int a, int b){
	
	if(a > b){
		int a0 = a;
		a = b;
		b = a0; 
		
	}
		
	if(b % a == 0) return a;
	
	return gcd(b % a, a); 

}


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

	int ans = 0;
	for(int a = 1; a <= K; a++){
		for(int b = 1; b <= K; b++){
			for(int c = 1; c <= K; c++){
				ans += gcd(gcd(a,b),c);
			}
		}
	}
	
	cout << ans << endl;
	return 0;
}

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

/*
struct Edge
{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
*/

using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int H, W;
    cin >> H >> W;

    map<int, int> s; // s[今]=開始の最大
    multiset<int> vals;

    for (int i = 0; i < W; i++)
        s[i] = i;
    for (int i = 0; i < W; i++)
        vals.insert(0);

    for (int i = 0; i < H; i++)
    {
        int l, r;
        cin >> l >> r;
        l--; // 半開区間
        auto it = s.lower_bound(l);
        int mr = -1;
        while (it != s.end() && it->first <= r)
        {
            mr = max(mr, it->second);
            int x = it->first - it->second;
            vals.erase(vals.find(x));
            s.erase(it++); // 消去してイテレータを進める
        }
        if (mr != -1 && r < W)
        {
            vals.insert(r - mr);
            s[r] = mr;
        }
        int ans = -1;
        if (vals.size() > 0)
        {
            ans = *vals.begin() + (i + 1);
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 22408
def get_divisor(num, max_val):
    ret = []
    num_sq = int(num**0.5)
    for k in range(1, num_sq+1):
        if num % k == 0:
            if k <= max_val: ret.append(k)
            if num//k <= max_val: ret.append(num//k)
            
    return ret

# 下からmodが低いのを取ってきてマッチングを取る
def solve():
    N,K = map(int, input().split())
    A = list(map(int, input().split()))
    sum_A = sum(A)
    max_A = max(A)
    div = get_divisor(sum_A, max_A+K)
    ret = 1
    for d in div:
        sum_k = 0
        red_k = 0
        flag = True
        mod_d = [a%d for a in A]
        mod_d.sort()
        # print(d, mod_d)
        for a in mod_d:
            if sum_k+a <= K:
                sum_k += a
            else: 
                red_k += d-a
            if sum_k-red_k < 0:
                break

        if (sum_k-red_k)%d == 0: ret = max(ret, d)
            
    print(ret)
    
solve()

Measured memory_bytes: 3064
from bisect import bisect_left


class score:
    def __init__(self,t) -> None:
        self.t = t
        score = 0
        last = [[] for i in range(26)]
        for i,ti in enumerate(t):
            score += s[i][ti-1]
            last[ti-1].append(i+1)
            for tj in range(26):
                if last[tj-1] == []:
                    score -= c[tj-1]*(i+1)
                else:
                    #print(last)
                    score -= c[tj-1]*((i+1)-last[tj-1][-1])
            print(score)
        self.score = score
    def a__init__(self,t) -> None:
        score = 0
        last = [[] for i in range(26)]
        for i,ti in enumerate(t):
            # 開催分を加算
            score += s[i][ti-1]
            # 減らす
            if last[ti-1] == []:
                score -= c[i]*i+1
            else:
                score -= c[i]*((i+1)-last[ti-1][-1])
            last[ti-1].append(i+1)
            print(score)
        for i in range(26):
            if last[i] == []:
                score -= c[i]*D
            else:
                score -= c[i]*(D-last[i][-1])
        self.score = score
        self.t = t


D = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for i in range(D)]
t = [int(input()) for i in range(D)]

sc = score(t)
#print(sc.score)

Measured memory_bytes: 9448
#include <iostream>

using namespace std;

int main()
{
	int num1, num2;

	cin >> num1 >> num2;

	if (num2 % num1 != 0)
	{
		cout << num2 - num1 << endl;
	}
	else
	{
		cout << num2 + num1 << endl;
	}

	return 0;
}


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

using namespace std;
using std::vector;

#define ll long long
#define vi vector<int>
#define vl vector<long long>
#define vvi vector<vi>
#define pi  pair<int,int>
#define mp  make_pair
#define pb  push_back
#define MOD int(1e9) + 7
#define PAI  3.1415926535
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define chmax(x, y) x = max(x,y)
#define chmin(x, y) x = min(x,y)
#define pr(x) cout << x << endl
#define Endl endl
#define rep(i, n) for(int i = 0 ; i < n; i++)

const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int ddx[8] = {-1,0,1,-1,1,-1,0,1};
const int ddy[8] = {-1,-1,-1,0,0,1,1,1};
const int inf = 99999999;
const ll linf = 1LL << 62;

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

ll lcm(ll a,ll b){
  if(a < b)swap(a , b);
  return (a / gcd(a , b)) * b;
}

int main(){
 
  int n; cin >> n;
  vi v(n);
  rep(i, n) cin >> v[i];
  sort(rall(v));

  int sum;
  rep(i, n){
    if(i == 0)
      sum = v[i] / 2;
    else 
      sum += v[i];
  }

  pr(sum);

  return 0;
}


Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
if b-a > k or c-a > k or d-a > k or e-a > k or e-d > k or e-c > k or e-b > k or e-a > k:
  print(':(')
else:
  print('Yay!')


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

int main() {
    string s; cin >> s;
    int ss = s.size();
    for (int i = 0; i < ss-1; i++){
        if(i != ss-2){
            char x = s[i];
            if(x == s[i+1]){
                cout << i+1 << " " << i+2 << endl;
                return 0;
            } else if(x == s[i+2]){
                cout << i+1 << " " << i+3 << endl;
                return 0;
            }
        } else {
            char x = s[i];
            if(x == s[i+1]){
                cout << i+1 << " " << i+2 << endl;
                return 0;
            }
        }
    }

    cout << -1 << " " << -1 << endl;
    return 0;
}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

int main() {
    int n,m;
    ll sum = 0;
    cin >> n >> m;
    vector<int> a(m);
    for (int i = 0; i < m; ++i) {
        cin >> a[i];
        sum += a[i];
    }
    if(n-sum < 0){
        cout << -1 << endl;
    }else{
        cout << n-sum << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

using graph = vector<vector<int>>;

int main() {
    constexpr int mod = 1e9 + 7;
    int n, k; cin >> n >> k;

    graph g(n);
    REP(i, n-1) {
        int a, b; cin >> a >> b;
        --a; --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    function<ll(int, int)> rec = [&](int v, int bv) {
        ll ret = 1, t = bv == -1 ? k-1 : k-2;

        for(int u : g[v]) {
            if(u != bv) {
               (ret *= t * (rec(u, v)) % mod) %= mod;
               --t;
            }
        }

        return ret;
    };

    cout << k * rec(0, -1) % mod << endl;

    return 0;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,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 (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b?gcd(b, a%b):a;}
ll lcm(ll a, ll b) { return a*b/gcd(a,b);}
ll MOD=1000000007;

int main(){
  int n;
  string s;
  cin>>n>>s;
  int tmp=0;
  int ans=0;
  for(int i=2;i<n;i++){
    if(s.at(i)=='C'){
      if(s.at(i-2)=='A' && s.at(i-1)=='B'){
        ans++;
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256