akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {

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

	int a[];
	int color;
	public void run() {
		Scanner sc = new Scanner(System.in);
		int h=sc.nextInt();
		int w=sc.nextInt();
		int n=sc.nextInt();
		a = new int[n];
		color=0;
		for(int i=0; i<n; i++) {
			a[i]=sc.nextInt();
		}

		int ans[][] = new int[h][w];
		for(int i=0; i<h; i++) {
			if(i%2==0) {
				for(int j=0; j<w; j++) {
					ans[i][j]=nextc();
				}
			}else {
				for(int j=w-1; j>=0; j--) {
					ans[i][j]=nextc();
				}
			}
		}
		for(int i=0; i<h; i++) {
			for(int j=0; j<w; j++) {
				if(j>0)System.out.print(" ");
				System.out.print(ans[i][j]);
			}
			System.out.println();
		}
		sc.close();
	}

	public int nextc() {
		if(a[color]==0) {
			color++;
		}
		a[color]--;
		return color+1;
	}



}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  vector<int> dp(n, 0);
  for(int i = n - 2; i >= max(0, n - k); --i) {
    dp[i] = abs(a[i] - a[n - 1]);
  }
  for(int i = n - k - 1; i >= 0; --i) {
    int bar = (int)2e9;
    for(int j = i + 1; j <= i + k; j++) {
      bar = min(bar, abs(a[i] - a[j]) + dp[j]);
    }
    dp[i] = bar;
  }
  cout << dp[0] << '\n';
  return 0;
}


Measured memory_bytes: 3948
/*==============================================*\
Codeforces ID:    mdshihab
                                                  |
Name:     Md. Shihabul Minhaz                     |
Study:      CSE, JKKNIU                           |
Address:  Trishal, Mymensingh, Bangladesh         |
                                                  |
 mail:   mdshihabul20171@gmail.com                |
 FB  :   fb.com/mdshihabul.minhaz.7               |
 github: Shihabulminhaz                           |
stopstalk :  mdshihab                             |
                                                  |
@uthor   Md. Shihabul Minhaz (shihab)             |
\*===============================================*/


#include<bits/stdc++.h>
using namespace std;
#define fi(a) scanf("%d",&a);
#define fli(a) scanf("%ld",&a);
#define fll(a) scanf("%lld",&a);
#define pi(a) printf("%d\n",a);
#define ppi(i,a) printf("Case %d: %d\n",i,a);
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int shihab;
void FI()
{
#ifndef ONLINE_JUDGE
    freopen("C:\\Users\\SHIHAB\\Desktop\\input.in","r",stdin);
#endif // ONLINE_JUDGE
}

int main()
{
    fast
  //  FI(); /// skip this line for compile
    int H,W,h,w;
    cin >> H >> W >> h >> w;
    H = H-h;
    W=W-w;
    cout << W*H << endl;
    return 0;
    //code end
}
//okbye


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

int main() {
    long long N, K;
    while (cin >> N >> K) {
        if (N == 0) break;
        vector<long long> p(N);
        for (int i = 0; i < N; ++i) cin >> p[i];

        vector<long long> s(N+1, 0);
        for (int i = 0; i < N; ++i) s[i+1] = s[i] + p[i];

        long long res = -INF;
        for (int i = 0; i <= N-K; ++i) {
            long long val = s[K+i] - s[i];
            if (res < val) res = val;
        }
        double ans = double(res+K)/2.0;
        printf("%.10f", ans);
    }
}

Measured memory_bytes: 3328
from math import cos, sqrt, radians


A, B, H, M = map(int, input().split())
Md = M * 6
Hd = (H * 30) + ((M/60) * 30)
Cd = (Hd - Md)
As = A ** 2
Bs = B ** 2
D = 2 * A * B
X = sqrt(As + Bs - (D * cos(radians(Cd))))
print(X)

Measured memory_bytes: 9536
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;

int main() {
    string S, ABC = "ABC";
    cin >> S;
    int N = S.length();
    long long dp[N + 100][4];

    dp[N][3] = 1;
    dp[N][0] = 0;
    dp[N][1] = 0;
    dp[N][2] = 0;

    for(int i = N - 1; i >= 0; i--) {
        dp[i][3] = S.at(i) == '?' ? 3 * dp[i + 1][3] % mod : dp[i + 1][3];
    }
    for(int j = 2; j >= 0; j--) {
        for(int i = N - 1; i >= 0; i--) {
            dp[i][j] = S.at(i) == '?' ? 3 * dp[i + 1][j] : dp[i + 1][j];
            dp[i][j] +=
                S.at(i) == '?' || S.at(i) == ABC.at(j) ? dp[i + 1][j + 1] : 0;
            dp[i][j] %= mod;
        }
    }

    cout << dp[0][0] << endl;

    return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
ll n;
ll m;
const ll mod = 1e9+7;
const ll maxn = 500005;
ll inv[maxn+3];
ll fac[maxn+3];
ll qpow(ll x,ll n)
{
    ll res =1;
    while(n>0)
    {
        if(n&1) res=res*x%mod;
        x=x*x%mod;
        n>>=1;
    }
    return res;
}
inline ll A(ll n,ll m){
    return fac[n]*inv[n-m]%mod;
}
inline ll C(ll n,ll m){
	return A(n,m)*inv[m]%mod;
}

int main(){
	//freopen("in.txt","r",stdin);
	cin>>n>>m;
	fac[0] = 1;
	fac[1] = 1;
	for(ll i=2;i<maxn;i++){
		fac[i] = i * fac[i-1];
		fac[i] %= mod;
	}
	inv[0]=1;inv[1]=1;      //inv[0]=1 !!! 
    for(ll i=2;i<=maxn;i++){
        inv[i]=(mod-mod/i)*inv[mod%i]%mod;
    }
    for(ll i=2;i<=maxn;i++){
        inv[i]=(inv[i]*inv[i-1])%mod;
    }
    ll ans =0;
    for(ll i=0;i<=n;i++){
    	ll tmp = C(n,i) * A(m-i,n-i);
    	tmp %= mod;
    	if(i%2==0){
    		ans += tmp;
		}else ans -= tmp;
		ans += mod;
		ans %= mod;
	}
	ans *= A(m,n);
	ans += mod;
	ans %= mod;
	cout<<ans<<endl;
	//cout<<tmp<<endl;
	return 0;
}

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

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
// clang-format on

int N, M;
int p[MAX_N], y[MAX_N];

void solve()
{
  priority_queue<PP, vector<PP>, greater<PP>> q;
  priority_queue<PP, vector<PP>, greater<PP>> qq;
  map<int, int> mp;
  REP(i, M) { q.push(PP(y[i], P(p[i], i))); }
  REP(i, M)
  {
    PP pp = q.top();
    q.pop();
    mp[pp.second.first]++;
    qq.push(PP(pp.second.second, P(pp.second.first, mp[pp.second.first])));
  }
  while (!qq.empty()) {
    PP pp = qq.top();
    qq.pop();
    printf("%06d%06d\n", pp.second.first, pp.second.second);
    mp[pp.first]--;
  }
}

int main(void)
{
  cin >> N >> M;
  REP(i, M) cin >> p[i] >> y[i];
  solve();
  return 0;
}


Measured memory_bytes: 9348
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use rand::Rng;


fn main() {
    input! {
        D: usize,
        C: [i64; 26],
        S: [[i64; 26]; D],
    }

    let score = |sol: &Vec<i64>| -> i64 {
        let mut sat: i64 = 0;
        let mut last = vec![0; 26];
        for (d, v) in sol.iter().enumerate() {
            let j: usize = (v - 1) as usize;
            last[j] = d + 1;
            for i in 0..26 {
                sat -= (d + 1 - last[i]) as i64 * C[i];
            }
            sat += S[d][j];
        }

        return sat;
    };

    let mut ans:Vec<i64> = vec![];
    let mut last = vec![0; 26];
    for d in 0..D {
        let mut ma = 0;
        let mut mai = 0;
        for j in 0..26 {
            let a = (d + 1 - last[j]) as i64 * C[j] + S[d][j];
            if a > ma {
                ma = a;
                mai = j;
            }
        }
        last[mai] = d + 1;
        ans.push((mai+1) as i64);
    }

    let mut rng = rand::thread_rng();
    let mut s = score(&ans);
    for _ in 0..350000 {
        let c = rng.gen_range(1, 27);
        let d = rng.gen_range(0, D);
        let b = ans[d];
        ans[d] = c;
        let ss = score(&ans);
        if ss > s{
            s = ss;
        }else{
            ans[d] = b;
        }
    }

    for c in ans {
        println!("{}", c);
    }
}


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

namespace Atcoder
{
    class Atcoderrrrrrr
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            Console.WriteLine(s[0]==s[1] ?"H":"D");
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#include <numeric>
#define REP(i, n) for(LL i = 0;i < n;i++)
#define REPR(i, n) for(LL i = n;i >= 0;i--)
#define FOR(i, m, n) for(LL i = m;i < n;i++)
#define FORR(i, m, n) for(LL i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define INF (LL)1e15
#define MOD 1000000007
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

/*************** using variables ***************/
int a, b, c, x;
int ans = 0;
/**********************************************/

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

    REP(i, a+1){
        REP(j, b+1){
            REP(k, c+1){
                if(i*500 + j*100 + k*50 == x) ans++;
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100005;
const ll INF=1LL<<60;
int par[MAX],size[MAX];

void init(int n){
    for(int i=0;i<n;i++){
        par[i]=i;
        size[i]=1;
    }
}

int root(int a){
    if(par[a]==a) return a;
    else return par[a]=root(par[a]);
}

void unite(int a,int b){
    if(root(a)!=root(b)){
        size[root(a)]+=size[root(b)];
        par[root(b)]=root(a);
    }
}

bool check(int a,int b){
    return root(a)==root(b);
}

vector<int> G[MAX];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,M,K;cin>>N>>M>>K;
    init(N);
    
    for(int i=0;i<M;i++){
        int a,b;cin>>a>>b;
        a--;b--;
        unite(a,b);
        G[a].push_back(b);
        G[b].push_back(a);
    }
    
    for(int i=0;i<K;i++){
        int a,b;cin>>a>>b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    
    for(int i=0;i<N;i++){
        int ans=size[root(i)]-1;
        
        for(int to:G[i]){
            if(check(i,to)) ans--;
        }
        
        cout<<ans<<" ";
    }
    cout<<endl;
}



Measured memory_bytes: 8696
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define Pll pair<llint,llint>
#define keta(a)  fixed << setprecision(a)
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
const llint INF = 100000000;

struct edge { int to, cost; };

int b_s(vector<vector<int>>& a, int key,int z) {
	int left = -1;
	int right = a[z].size();
	while (right - left > 1) {
		int mid = left + (right - left) / 2;
		if (a[z][mid] > key)right = mid;
		else left = mid;
	}
	return left;
}

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

// mod. m での a の逆元 a^{-1} を計算するよ！
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


//aCbをmod.mで割った余りを求める
int c(int a, int b, int m) {
	int ans = 1;
	for (int i = 0; i < b; i++) {
		ans *= a - i;
		ans %= m;
	}
	for (int i = 1; i <= b; i++) {
		ans *= modinv(i, m);
		ans %= m;
	}
	return ans;
}


int main() {
	llint n;
	cin >> n;
	llint M = 0;
	rep(i, 0, n + 2) {
		M += 7*modpow(10, i, n);
		M %= n;
		if (M == 0) {
			cout << (i+1)  << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 3644
#include <stdio.h>
int main(){
  int n;
  int num_b, num_f, num_r, num_v;
  int b, f, r;
  int arr[4][3][10];
  int i;

  //setting initialization
  for(b=0; b<4; b++){
    for(f=0; f<3; f++){
      for(r=0; r<10; r++){
        arr[b][f][r]=0;
      }
    }
  }

  //input information
  scanf("%d", &n);
  for(i=0; i<n; i++){
    scanf("%d %d %d %d", &num_b, &num_f, &num_r, &num_v);
    arr[num_b-1][num_f-1][num_r-1]+=num_v;
    }

  //output information
  for(b=0; b<4; b++){
    for(f=0; f<3; f++){
      for(r=0; r<10; r++){
        printf(" %d", arr[b][f][r]);
      }
      printf("\n");
    }
    if(b<3){
      printf("####################\n");
    }
  }
  return 0;
}



Measured memory_bytes: 2036
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	vector<ii> vec;
	for(int i=0;i<n;i++)
	{
		ll x,y; cin>>x>>y; vec.pb({x+y,x-y});
	}
	sort(vec.begin(),vec.end());
	ll curd=-ll(1e18); int cnt=0;
	for(int i=0;i<n;i++)
	{
		if(vec[i].se>=curd)
		{
			curd=vec[i].fi; cnt++;
		}
	}
	cout<<cnt<<'\n';
}


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

int main(){
    int n;
    string s;
    cin >> n >> s;

    vector<int> a(n);
    rep(i, n){
        if (s[i] == 'R') a[i] = 0;
        else if (s[i] == 'G') a[i] = 1;
        else a[i] = 2;
    }

    vector<ll>count(3);
    rep(i, n) count[a[i]] ++;

    ll ans = 1;
    rep(i, count.size()) ans *= count[i];

    // rep(i, n) rep()
    for (int i = 0; i < n; i++){
        for (int j = i+1; j < n; j ++){
            int k = 2*j - i;
            if (k <= n-1){
                if (a[i] == a[j]) continue;
                else if (a[j] == a[k]) continue;
                else if (a[k] == a[i]) continue;
                ans--;
            }
        }
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <algorithm>


using namespace std;

// int gcd( int m, int n )
// {
// 	// 引数に０がある場合は０を返す
// 	if ( ( 0 == m ) || ( 0 == n ) )
// 		return 0;
	
// 	// ユークリッドの方法
// 	while( m != n )
// 	{
// 		if ( m > n ) m = m - n;
// 		else         n = n - m;
// 	}
// 	return m;
// }//gcd

// // 最小公倍数（Least Common Multiple）を返す。
// // 引数に０がある場合は０を返す。
// //*********************************************************
// int lcm( int m, int n )
// {
// 	// 引数に０がある場合は０を返す
// 	if ( ( 0 == m ) || ( 0 == n ) )
// 		return 0;
	
// 	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
// }//lcm




int main(){
    int N;
    cin >> N;
    int a[N];
    int ans = 0;
    
    for(int i=0; i < N; i++)
    {
        cin >> a[i];
        // cout << " " << a[i];
    }
    for(int i=0; i < N; i++)
    {
        ans += a[i];
        // cout << " " << a[i];
    }
    ans -= N;
    
    // long long int maxM = a[0];
    // for(int i=1; i < N; i++){
        
    //     if ( > maxM){
    //         maxM = a[i];
    //     }
    // }
    // cout << "max::" << maxM << endl;
    // // long long int lcmT = lcm(temp, a[i]);
    
    // for(int j=1; j <= maxM; j++)
    // {
    //     long long int t_ans=0;
    //     for(int i=0; i < N; i++)
    //     {
    //         t_ans += j % a[i];
    //     }
    //     if (t_ans > ans)
    //     {
    //         ans = t_ans;
    //         cout << "Ans =" << ans <<endl;
    //     }
    // }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{


    ll i,j,k,a,b,c,n,t,m;
    vector<ll> v,s;
    string st,et;
    cin>>n>>t;
    v.clear();
    for(i=1; i<=n; i++)
    {
        cin>>a;
        v.push_back(a);
    }
    a = 0;
    for(i=0; i+1<n; i++)
    {
        b = abs(v[i]-v[i+1]);
        if(b<t)
        {
            a = a+abs(v[i]-v[i+1]);
        }
        else{
            a = a+t;
        }
    }
    if(n==1){
        a = t;
    }
    else {
        a = a+t;
    }
    cout<<a<<endl;

}


Measured memory_bytes: 2548
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	#a = int(input())
	#b , c = tin()
	s = input()
	sa = sum([int(c) for c in s])
	return 'Yes' if sa % 9 == 0 else 'No'
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 75960
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for(int i=0; i<n; i++)
const ll MOD=1e9+7;

int main(){

  int a, b, c;
  cin >> a >> b >> c;
  if(a+b+c>=22){
    cout << "bust" << endl;
  } else {
    cout << "win" << endl;
  }

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <set>
#include <algorithm>
typedef long long ll;
using namespace std;

int main(void) {
  ll i, j, k, n, sum = 0, now, t, t2;
  scanf("%lld%lld", &n, &k);
  ll a[n];
  for(i = 0; i < n; ++i) scanf("%lld", &a[i]), sum += a[i];
  vector<ll> d;
  multiset<ll>::iterator it;
  for(i = 1; i * i <= sum; ++i) if(!(sum % i)) d.push_back(i);
  for(i = d.size() - 1; i >= 0; --i) if(d[i] * d[i] != sum) d.push_back(sum / d[i]);
  for(i = d.size() - 1; i >= 0; --i) {
    multiset<ll> s;
    now = 0;
    for(j = 0; j < n; ++j) if(a[j] % d[i]) s.insert(a[j] % d[i]);
    while(s.size()) {
      t = *s.begin();
      s.erase(s.begin());
      now += t;
      while( t ) {
        it = s.end();
        it--;
        t2 = *it;
        s.erase(it);
        if(t + t2 < d[i]) s.insert(t + t2), t = 0;
        else t -= d[i] - t2;
      }
    }
    if(now <= k) {
      printf("%lld", d[i]);
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
#include <numeric>
using namespace std;

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define vi vector<int>
#define ALL(a) (a).begin(), (a).end()
#define sort_v(a) sort(a.begin(), a.end())

void print(bool a)
{
    if (a == true)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

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

int main()
{
    int n, q, l, r;
    string s;
    vi pos(100002);

    cin >> n >> q >> s;
    //cout << pos[0] << endl;
    pos[0] = 0;
    rep(i, 0, s.size() - 1)
    {
        //if (i != 0)
        //{
        if (s[i] == 'A' && s[i + 1] == 'C')
            pos[i + 1] = pos[i] + 1;
        else
            pos[i + 1] = pos[i];
        //}
        /*else
        {
            if (s[i] == 'A' && s[i + 1] == 'C')
                pos[i] = 1;
            else
                pos[i] = 0;
        }*/
    }
    /*rep(i, 0, s.size())
    {
        cout << pos[i] << " ";
    }
    cout << endl;*/
    rep(i, 0, q)
    {
        cin >> l >> r;
        cout << pos[r - 1] - pos[l - 1] << endl;
    }
}


Measured memory_bytes: 1408
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> Pint;
typedef pair<ll, ll> Pll;
#define rep(begin, i, end) for (ll i = begin; i < (ll)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    ll H, W;
    cin >> H >> W;
    vector<vector<char>> grid(H + 2, vector<char>(W + 2, '#'));
    rep(1, i, H + 1)
    {
        rep(1, j, W + 1)
        {
            cin >> grid.at(i).at(j);
        }
    }

    vector<vector<ll>> d1(H + 2, vector<ll>(W + 2)), d2(H + 2, vector<ll>(W + 2));
    rep(0, i, H + 2)
    {

        ll r = 0, l, count = 0;
        rep(0, j, W + 2)
        {
            if (grid.at(i).at(j) == '#')
            {
                l = max((ll)0, j - 1);
                rep(r, k, l + 1)
                {
                    d1.at(i).at(k) = count;
                }
                d1.at(i).at(j) = 0;
                r = j + 1;
                count = 0;
                continue;
            }
            count++;
        }
    }

    rep(0, i, W + 2)
    {
        ll r = 0, l, count = 0;
        rep(0, j, H + 2)
        {
            if (grid.at(j).at(i) == '#')
            {
                l = max((ll)0, j - 1);
                rep(r, k, l + 1)
                {
                    d2.at(k).at(i) = count;
                }
                d2.at(j).at(i) = 0;
                r = j + 1;
                count = 0;
                continue;
            }
            count++;
        }
    }

    ll ans = 0;
    rep(0, i, H + 2)
    {
        rep(0, j, W + 2)
        {
            ans = max(d1.at(i).at(j) + d2.at(i).at(j) - 1, ans);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 67072
X,Y=input().split()
H="ABCDEF"
if X==Y:
    p="="
else:
    p="<"
    i=0
    while H[i]!=X:
        i+=1
    while i<6 and H[i]!=Y:
        i+=1
    if i>=6:
        p=">"
print(p)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  vector<int> A;
  vector<int> ans(S.size());
  int sum = 1;
  for(int i = 1; i < S.size(); i++) {
    if(S[i] == S[i - 1]) {
      sum++;
    }
    else {
      A.push_back(sum);
      sum = 1;
    }
  }
  A.push_back(sum);
  
  int now = 0;
  for(int i = 0; i < A.size(); i += 2) {
    now += A[i] - 1;
    if((A[i] + A[i + 1]) % 2 == 0) {
      ans[now] = (A[i] + A[i + 1])/2;
      now++;
      ans[now] = (A[i] + A[i + 1])/2;
    } else {
      if(A[i] % 2 == 0) {
        ans[now] = (A[i] + A[i + 1] - 1)/2;
        now++;
        ans[now] = (A[i] + A[i + 1] + 1)/2;
      } else {
        ans[now] = (A[i] + A[i + 1] + 1)/2;
        now++;
        ans[now] = (A[i] + A[i + 1] - 1)/2;
      }
    }
    now += A[i + 1];
  }
  cout << ans[0];
  for(int i = 1; i < ans.size(); i++) {
    cout << " " << ans[i];
  }
  cout << endl;
}

Measured memory_bytes: 1528
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define all(sdk) sdk.begin(),sdk.end()
#define mll map<int, int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repd(i,a,b) for(int i=a;i>=b;--i)
#define mp make_pair
#define hell 1000000007
#define endl '\n'
#define vvll vector<vector<int> >
#define vll vector<int>
#define mint map<int,int> 
#define sz(x) (int)x.size()
#define sll set<int>
#define pll pair<int,int>
#define F first
#define S second


void solve(){
	
	int n;
	cin>>n;
	int height[n];
	rep(i,0,n){
		cin>>height[i];
	}
	int dp[n];
	dp[0]=0;
	dp[1] = abs(height[1]-height[0]);
	rep(i,2,n){
		dp[i] = min(dp[i-1] + abs(height[i]-height[i-1]), dp[i-2] + abs(height[i]-height[i-2]));
	}

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


}
signed main(){
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    srand (static_cast <unsigned> (time(0)));
    int t=1;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <complex>

using namespace std;

typedef complex<double> P;

int cross(P a, P b)
{
    return imag(conj(a) * b);
}

int ccw(P a, P b, P c)
{
    b -= a;
    c -= a;
    if (cross(b, c) > 0)   return +1; // counter clockwise
    if (cross(b, c) < 0)   return -1; // clockwise
    // if (dot(b, c) < 0)     return +2; // c--a--b on line
    // if (norm(b) < norm(c)) return -2; // a--b--c on line
    return 0;
}

int main()
{
    for (;;) {
        P p[4];
        double x, y;
        if (scanf("%lf,%lf,", &x, &y) == EOF)
            break;
        p[0] = P(x, y);
        scanf("%lf,%lf,", &x, &y);
        p[1] = P(x, y);
        scanf("%lf,%lf,", &x, &y);
        p[2] = P(x, y);
        scanf("%lf,%lf,", &x, &y);
        p[3] = P(x, y);

        int sign = ccw(p[0], p[1], p[2]);
        if (ccw(p[1], p[2], p[3]) == sign
                && ccw(p[2], p[3], p[0]) == sign
                && ccw(p[3], p[0], p[1]) == sign)
            puts("YES");
        else
            puts("NO");
    }

    return 0;
}

Measured memory_bytes: 1040
from itertools import permutations

N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
p = 0
q = 0
for idx, t in enumerate(permutations(range(1, N + 1))):
    if t == P:
        p = idx + 1
    if t == Q:
        q = idx + 1
    if p and q:
        break
print(abs(p - q))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)

int main(){
	int N; cin>>N;
	string S; cin>>S;
	int ans = 0;
	rp(i,0,N-2){
		if(S[i]=='A' && S[i+1]=='B' && S[i+2]=='C'){
			ans++;
		}
	}
	ote(ans);
}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(deprecated)]

use std::cell::{Cell, Ref, RefCell, RefMut};
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;
use std::usize;

const MOD_10_9_7: u64 = 1_000_000_007;
const INF: i64 = 1_000_000_000_000;
const MIN_INF: i64 = -1_000_000_000_000;

/// FYI: https://github.com/vain0x/scan-bench
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}

#[allow(unused_macros)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn main() {
    let n = read!(usize);
    let a: Vec<f64> = read![[f64]];

    let mut x = 0.0;
    for aa in a {
        x += 1.0 / aa;
    }

    println!("{}", 1.0 / x);
}


Measured memory_bytes: 4352
//#include <bits/stdc++.h>
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#define FOR(N) for(int i=0;i<N;i++)
#define FOR2(N) for(int j=0;j<N;j++)
using namespace std;
typedef long long ll;



int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b || b == c || a == c)
		if (a == b && a == c) {
			cout << "No" << endl;
			return 0;
		}
		else {
			cout << "Yes" << endl;
			return 0;
		}
	cout << "No" << endl;
}

Measured memory_bytes: 256
N, M = map(int, input().rstrip().split(' '))
m = {}
for i in range(N):
    row = list(map(int, input().rstrip().split(' ')))
    for j in range(row[0]):
        k = row[1 + j]
        if k in m:
            v = m[k]
            m[k] = v + 1
        else:
            m[k] = 1


num = 0
for v in m.values():
    if v == N:
        num = num + 1


print(num)




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

using namespace std;

typedef pair<int, int> P;

const int N = 1e5, M = 1e5;
int visited[N];

void traverse(int p, const vector<vector<int>> &g) {
	for(auto& next: g[p]) {
		if(!visited[next]) {
			visited[next] = 1;
			traverse(next, g);
		}
	}
}

int main() {
	int n, m, x, y, z, ans = 0;
	cin >> n >> m;
	vector<vector<int> > g(n, vector<int>());
	memset(visited, sizeof(visited), 0);

	for(int i = 0;i < m;++i) {
		cin >> x >> y >> z;
		--x; --y;
		z = z % 2;
		g[x].emplace_back(y);
		g[y].emplace_back(x);
	}

	for(int i = 0;i < n;++i) {
		if(g[i].size() == 0) {
			++ans;
			visited[i] = 1;
		}
	}

	for(int i = 0;i < n;++i) {
		if(!visited[i]) {
			traverse(i, g);
			++ans;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 9216
#include <cstdio>
 
bool has3(int x) {
  while (x) {
    if (x % 10 == 3) return true;
    x /= 10;
  }
  return false;
}
 
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    int x = i;
    if (x % 3 == 0 || has3(x)) {
      printf(" %d", i);
    }
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1e9+7;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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

int main(){
    int N;
    cin >> N;
    vector<Pll> a(N);
    rep(i,N){
        ll A,B;
        cin >> A >> B;
        a[i]=Pll(A+B,A);
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    ll p=0,q=0;
    rep(i,N){
        if (i%2==0) p+=a[i].second;
        else q+=a[i].first-a[i].second;
    }
    cout << p-q << endl;
}


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

using namespace std;
const long mod = 1000000007;
typedef long long lint;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(N) for(int i = 0; i < (int)(N); i++)
#define all(x) (x).begin(),(x).end()
#define length(x) ((int)(x).size())
#define prln(s) cout<<s<<endl;

#define str(s) string s;cin>>s;
#define int1(x) int x;cin>>x;
#define int2(x,y) int x,y;cin>>x>>y;


int main() {
  int2(a,b);
  int x = 0;
  // [x * 0.08] = A, [x * 0.1] = B, ret min x

  // a <= x*0.08 < a+1 && b <= x*0.1 < b+1
  // a*12.5 <= x < (a+1)/0.08 && (ry)

  int s1 = 10*b;
  int e1 = 10*(b+1);
  int s2 = ceil(12.5*(double)a);
  int e2 = floor(12.5*(double)(a+1));
  
  if(e1 <= s2 || e2 <= s1) {
    prln("-1");
    return 0;
  }
  if(s1 < s2) {
    prln(s2);
  }else {
    prln(s1);
  }
}


Measured memory_bytes: 256
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <typename T>
class UnionFind
{
public:
    vector<T> par;
    UnionFind(T n) : par(n, -1) {}
    void init(T n)
    {
        par.resize(n, -1);
    }

    ll root(T x)
    {
        if (par[x] < 0)
            return x;
        else
            return par[x] = root(par[x]);
    }

    bool same(T x, T y)
    {
        return root(x) == root(y);
    }

    bool unite(T x, T y)
    {
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        if (par[x] > par[y])
            swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    ll size(T x)
    {
        return -par[root(x)];
    }
};
int main()
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    ll n, m;
    cin >> n >> m;
    UnionFind<ll> uf(n);
    uf.init(n);
    vector<pair<ll, ll>> bridge(m);
    for (int i = 0; i < m; i++)
    {
        cin >> bridge[i].first >> bridge[i].second;
        bridge[i].first--;
        bridge[i].second--;
    }
    vector<ll> res;
    ll all = n * (n - 1) / 2;
    for (int i = 0; i < m; i++)
    {
        res.emplace_back(all);
        ll a = bridge[m - i - 1].first, b = bridge[m - i - 1].second;
        if (uf.same(a, b))
            continue;

        ll sa = uf.size(a), sb = uf.size(b);
        all -= sa * sb;
        uf.unite(a, b);
    }
    reverse(res.begin(), res.end());
    for (int i = 0; i < res.size(); i++)
        cout << res[i] << endl;
}

Measured memory_bytes: 4596
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    string s; cin >> s;
    int n = s.size();
    cout << s;
    if(s[n-1] == 's') cout << 'e';
    cout << 's' << endl;
    return 0;
}




Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
 
int main() {

  int A,B,C,X,Y;

  cin >> A >> B >> C >> X >> Y ;

  int64_t ans=1000000000;

  for(int i=0;i<=100000;i++){
    
    int64_t sum = 2*C*i + A*max(0,X-i) + B*max(0,Y-i);

    if(ans>sum) ans = sum;

  }

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

Measured memory_bytes: 256
program takaku
  implicit none
  integer :: N,i,suml,yn
  integer,allocatable :: L(:)
  read(*,*) N
  allocate(L(N))
  read(*,*) L
  suml=sum(L)
  yn=0
  do i=1,N
     if(L(i).lt.(suml-L(i))) then
 
     else
        yn=1
     endif
  enddo
  if(yn.eq.1) then
     write(*,'(a)') 'No'
  else
     write(*,'(a)') 'Yes'
  endif
 
  deallocate(L)
 
 
 
end program takaku

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define INF 10000000
using ll = long long ;

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

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> l(n),r(n);
    int ans = 1;
    rep(i,n) cin >> a[i];
    rep(i,n-1) l[i+1] = gcd(l[i],a[i]);
    for(int i=n-1;i>=1;i--){
        r[i-1]=gcd(r[i],a[i]);
    }
    rep(i,n) ans=max(ans,gcd(l[i],r[i]));
    cout << ans << endl;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define _for(i,b,e) for (common_type_t<decltype(b),decltype(e)> i = (b), i ## __end = (e); i < i ## __end; ++ i)
#define FOR(...)   _for (__VA_ARGS__)
#define rep(i,n)   FOR (i, size_t{}, n)
#define ALL(x)     begin (x), end (x)
using namespace std;
using ll = int64_t;

auto main () -> int
{
  cin.tie (nullptr);
  ios::sync_with_stdio (false);

  size_t n, k;
  cin >> n >> k;
  vector <double> r (n);
  rep (i, n)
  {
    ll p; cin >> p;
    r [i] = p * (p + 1) / 2.0 / p;
  }
  auto sum = 0.0;
  rep (i, k)
  {
    sum += r [i];
  }
  auto ans = sum;

  FOR (i, k, n)
  {
    sum -= r [i - k];
    sum += r [i];
    ans = max (ans, sum);
  }
  cout << fixed << setprecision (15) << ans << endl;
}


Measured memory_bytes: 1792
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string.h>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <stdio.h>

using namespace std;

int main(void) {
    int X;
    cin>>X;

    if(X>29){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<"\n"
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define mp make_pair
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef tuple<ll,ll,ll> tll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using vc = vector<char>;
using vvc = vector<vc>;
using vb = vector<bool>;
using vvb = vector<vb>;
template<class T> inline bool chmax(T& a, T b) { 
 if (a < b) { a = b; return true; } return false; 
}
template<class T> inline bool chmin(T& a, T b) {
 if (a > b) { a = b; return true; } return false; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,x,m;
  cin>>n>>x>>m;
  vll f(0);
  f.pb(x);
  set<ll> s;
  s.insert(x);
  ll cu=x;
  ll k= -1;
  rep(i,n){
      if(i==0) continue;
      cu*=cu;
      cu%=m;
      if(cu==0){
          break;
      }
      if(s.count(cu)){
          k=cu;
          break;
      }
      s.insert(cu);
      f.pb(cu);
  }
  ll ans=0;
  if(k==-1){
    rep(i,sz(f)){
        ans+=f[i];
    }
    COUT(ans);
  }
  else{
      ll ff,ss;
      ff=-1;ss=sz(f);
      rep(i,sz(f)){
          if(cu==f[i]){
              ff=i;
              break;
          }
      }
      rep(i,ff){
          ans+=f[i];
      }
      n-=ff;
      ll j=0;
      for(int i=ff;i<sz(f);i++){
          j+=f[i];
      }
      ans+=j*(n/(ss-ff));
      n%=(ss-ff);
      for(int i=ff;i<ff+n;i++){
          ans+=f[i];
      }
      COUT(ans);
  }
}


Measured memory_bytes: 5952
#include<bits/stdc++.h>
using namespace std;
typedef complex<double> qua;
vector<qua> v;
double cross(qua a,qua b)
{
    return imag(b*conj(a));
}
double calc_area(vector<qua> &ve)
{
    double ans=0;
    int n=ve.size();
    for(int i=0;i<n;i++) ans+=cross(ve[i],ve[(i+1)%n]);
    return abs(ans/2.0);
}
int main()
{
    int n;
    scanf("%d",&n);
    double x,y;
    while(n--)
    {
        scanf("%lf%lf",&x,&y);
        v.push_back(qua(x,y));
    }
    printf("%.1f\n",calc_area(v));
}



Measured memory_bytes: 3244
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <iterator>
#include <cassert>

using namespace std;
typedef long long ll;
const int MODULO = 1000000007;
const int INF = 100000000; //1e8

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef complex<double> Cd;

#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)(c).size())

template<class T>
void splitstr(const string &s, vector<T> &out)
{
    istringstream in(s);
    out.clear();
    copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out));
}

vector<int> a;
double memo[12][1 << 12];

double solve(int start,int flag,int rest){
	if(memo[start][flag] > 0) return memo[start][flag];
	if(rest == 0)
		return memo[start][flag] = a[start];
	double ret = INF;
	FOR(i,sz(a)){
		if((1<<i)&flag) continue;
		double add = solve(i,flag|(1<<i),rest - 1) + sqrt((double)a[start] * a[i]) * 2;
		ret = min(ret,add);
	}
	return memo[start][flag] = ret;
}

int main(){
	string s;
	while(getline(cin,s)){
		splitstr(s,a);
		int n = a[0];
		a.erase(a.begin());
		int m = sz(a);

		double mn = INF;
		FOR(j,m) fill(memo[j],memo[j] + (1 << m),-1.0);
		FOR(i,m){
			mn = min(mn,solve(i,1<<i,m-1) + a[i]);
		}

		cout << (n >= mn ? "OK" : "NA") << endl;
	}
	return 0;
}

Measured memory_bytes: 1304
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(defstruct (queue (:constructor make-queue
                    (&optional list &aux (tail (last list)))))
  (list nil :type list)
  (tail nil :type (or null (cons t null))))

(declaim (inline enqueue))
(defun enqueue (obj queue)
  (symbol-macrolet ((list (queue-list queue))
                    (tail (queue-tail queue)))
    (if (null list)
        (setf tail (list obj)
              list tail)
        (setf (cdr tail) (list obj)
              tail (cdr tail))))
  queue)

(declaim (inline enqueue-front))
(defun enqueue-front (obj queue)
  (symbol-macrolet ((list (queue-list queue))
                    (tail (queue-tail queue)))
    (if (null list)
        (setf tail (list obj)
              list tail)
        (push obj list))
    queue))

(defun read-fixnum+ (&optional (in *standard-input*))
  (declare (optimize (speed 3) (safety 0) (debug 0)))
  (macrolet ((%read-byte ()
               `(the (unsigned-byte 8)
                     #+swank (char-code (read-char in nil #\Nul))
                     #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\Nul) nil))))
    (let ((result (loop (let ((byte (%read-byte)))
                          (cond ((<= 48 byte 57)
                                 (return (- byte 48)))
                                ((zerop byte) ; #\Nul
                                 (return-from read-fixnum+ 0)))))))
      (declare ((integer 0 #.most-positive-fixnum) result))
      (loop
        (let* ((byte (%read-byte)))
          (if (<= 48 byte 57)
              (setq result (+ (- byte 48) (the fixnum (* result 10))))
              (return nil))))
      result)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(defmacro println (obj &optional (stream '*standard-output*))
  `(let ((*read-default-float-format* 'double-float))
     (prog1 (princ ,obj ,stream) (terpri ,stream))))

(defconstant +mod+ 1000000007)

;; Hauptteil

(defun main ()
  (declare #.OPT)
  (let* ((n (read))
         (queue (make-queue)))
    (declare (uint31 n))
    (if (evenp n)
        (dotimes (i n)
          (if (evenp i)
              (enqueue (read-fixnum+) queue)
              (enqueue-front (read-fixnum+) queue)))
        (dotimes (i n)
          (if (oddp i)
              (enqueue (read-fixnum+) queue)
              (enqueue-front (read-fixnum+) queue))))
    (format t "~{~D~^ ~}~%" (queue-list queue))))

#-swank(main)


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

int main() {
  int D;
  cin>>D;
  vector<int> c(26);
  for(int i=0;i<26;i++){
    cin>>c.at(i);
  }
  vector<vector<int>> S(D, vector<int>(26));
  for(int i=0;i<D;i++){
    for(int j=0;j<26;j++){
      cin>>S.at(i).at(j);
    }
  }
  for(int i=0;i<D;i++){
    int deka=S.at(i).at(0);
    int ban=0;
    for(int j=1;j<26;j++){
      if(deka<=S.at(i).at(j)){
        deka=S.at(i).at(j);
        ban=j;
      }
    }
    cout<<ban+1<<endl;
  }
      
    
    
}

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

int main(void)
{
    int h,w,ans = 0;
    int dx[4] = {-1,0,1,0},dy[4] = {0,-1,0,1};
    bool flag = true;

    cin >> h >> w;
    string s[h];

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

    rep(i,h){
        rep(j,w){
            if(s[i][j] == '#'){
                flag = false;
                for(int a = 0;a < 4;a++){
                    if(i+dx[a] >= 0 && i+dx[a] < h  && j+dy[a] >= 0 && j+dy[a] < w && s[i+dx[a]][j+dy[a]] == '#')
                        flag = true;
                }
                if(flag == false){
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 3612
from math import gcd

from math import factorial as f

from math import ceil, floor, sqrt
import math

import bisect
import re
import heapq

from copy import deepcopy
import itertools
from itertools import permutations

from sys import exit

ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(map(int, input().split()))

yes = "Yes"
no = "No"


def main():
    a,b,c,d = mi()
    ans = -100000000000000000000
    ans = max(a*c,ans)
    ans = max(b*c,ans)
    ans = max(a*d,ans)
    ans = max(b*d,ans)
    print(ans)




main()


Measured memory_bytes: 10016