akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long lli;

int main() {
  lli A, B, C;
  cin >> A >> B >> C;
  lli res;
  if (A % 2 == 0 || B % 2 == 0 || C % 2 == 0) {
    res = 0;
  } else {
    res = min(min(B * C, A * C), A * B);
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#解説より二分探索
import bisect
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
a.sort()
b.sort()
c.sort()
bans = []
for bi in range(n):
  bnow = b[bi]
  here = bisect.bisect_right(c,bnow)
  bans.append([bnow,n-here])
bsun = 0
for bi in range(n):
  bsun += bans[n-1-bi][1]
  bans[n-1-bi].append(bsun)
ans = 0
for ai in range(n):
  anow = a[ai]
  here = bisect.bisect_right(b,anow)
  if here != n:
    ans += bans[here][2]
#print(bans)
print(ans)

Measured memory_bytes: 35440
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        TreeMap<Integer,Integer> oddmap = new TreeMap<Integer,Integer>(Comparator.reverseOrder());
        TreeMap<Integer,Integer> evenmap = new TreeMap<Integer,Integer>(Comparator.reverseOrder());
        for(int i = 0; i < n; i++){
            int a = sc.nextInt();
            if(i % 2 == 0){
                if(evenmap.containsKey(a)){
                    evenmap.put(a,evenmap.get(a)+1);
                }else{
                    evenmap.put(a,1);
                }
            }else{
                if(oddmap.containsKey(a)){
                    oddmap.put(a,oddmap.get(a)+1);
                }else{
                    oddmap.put(a,1);
                }
            }
        }
        PriorityQueue<Point> odd = new PriorityQueue<>();
        PriorityQueue<Point> even = new PriorityQueue<>();
        for(Map.Entry<Integer,Integer> e : oddmap.entrySet()){
            odd.add(new Point(e.getKey(), e.getValue()));
        }
        for(Map.Entry<Integer,Integer> e : evenmap.entrySet()){
            even.add(new Point(e.getKey(), e.getValue()));
        }
        Point odd1 = odd.poll();
        Point even1 = even.poll();
        if(odd1.key != even1.key){
            System.out.println(n - odd1.value - even1.value);
        }else{
            int odd2 = odd.size() != 0 ? odd.poll().value : 0;
            int even2 = even.size() != 0 ? even.poll().value : 0;
            System.out.println(Math.min(n - odd1.value - even2 , n - odd2 - even1.value));
        }
    }
}

class Point implements Comparable<Point>{
    int key,value;
    public Point(int k, int v){
        this.key = k;
        this.value = v;
    }
    
    public int compareTo(Point p){
        if(this.value > p.value){
            return -1;
        }else if(this.value < p.value){
            return 1;
        }
        return 0;
    }
}


Measured memory_bytes: 64924
#include <iostream>
using namespace std;
int main()
{
    string S;
    cin >> S;
    int N = S.size(), MOD = 1000000007;

    long long dp[100010][4] = {};
    for (int i = N; i >= 0; --i)
    {
        for (int j = 3; j >= 0; --j)
        {
            if (i == N)
            {
                dp[i][j] = (j == 3 ? 1 : 0);
            }
            else
            {
                dp[i][j] = dp[i + 1][j] * (S[i] == '?' ? 3LL : 1LL);
                if (j < 3 && (S[i] == '?' || S[i] == "ABC"[j]))
                {
                    dp[i][j] += dp[i + 1][j + 1];
                }
                dp[i][j] %= MOD;
            }
        }
    }
    cout << dp[0][0] << endl;
}


Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <map>

using namespace std;

double entropy(int N, const map<int,int> &x) {
    double H = 0;
    for (map<int,int>::const_iterator it=x.begin(); it!=x.end(); ++it) {
        H -= (double)it->second / N * log((double)it->second / N);
    }
    return H;
}

int main() {
    ios::sync_with_stdio(false);
    int N;
    while (cin >> N && N) {
        vector<int> I(N+1);
        for (int i=1; i<=N; ++i) cin >> I[i];
        int M = 256;
        double Hmin = 999999;
        vector<int> ans(3);
        for (int S=0; S<=15; ++S) {
            for (int A=0; A<=15; ++A) {
                for (int C=0; C<=15; ++C) {
                    map<int,int> x;
                    int R = S;
                    int O;
                    for (int i=1; i<=N; ++i) {
                        R = (A * R + C) % M;
                        O = (I[i] + R) % M;
                        x[O] ++;
                    }
                    double H = entropy(N, x);
                    if (H + 1e-8 < Hmin) {
                        Hmin = H;
                        ans[0] = S;
                        ans[1] = A;
                        ans[2] = C;
                    }
                }
            }
        }
        cout << ans[0] << " " << ans[1] << " " << ans[2] << endl;
    }
    return 0;
}

Measured memory_bytes: 1264
#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <numeric>
using namespace std;
using ll = long long;

typedef pair <int, int> pii;

int main()
{

	ll a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, ans = 0;
	string s, t;
	ll x[200005] = {}, y[200005] = {};
	cin >> a;
	for (int i = 0; i < a; i++)
	{
		cin >> x[i];
		y[i] = x[i];
	}
	sort(x, x + a);
	for (int i = 0; i < a; i++)
	{
		if (y[i]<=x[a/2-1])
		{
			cout << x[a / 2] << endl;
		}
		else
		{
			cout << x[a / 2-1] << endl;
		}
	}


	//cout << ans << endl;
	//cout <<  << endl;

	////std::cout << std::fixed;
	//cout << std::setprecision(20) << << endl;
	//cout << d+1 << endl;
	//cout << "" << endl;

	return 0;
}
//char型の文字数字は、-'0'で数値に変換できる
//accumulate(x, x + a, 0);//int型までの配列の合計
//memcpy(x, visited, sizeof(ll)*n);
//void kansuu(ll num, ll visited[10]) {}
//kansuu(1, zz);
//cout << setprecision(15) << v << endl;
//cout << char(z - 'a');
//log10(i) + 1 //10進数の桁数を取得

//int temp;
//for (int i = 0; i < n - 1; i++) {
//	for (int j = n - 1; j > i; j--) {
//		if (w[j - 1] < w[j]) {  /* 前の要素の方が大きかったら */
//			temp = w[j];        /* 交換する */
//			w[j] = w[j - 1];
//			w[j - 1] = temp;
//		}
//	}
//}

//最小公倍数
//ll x = a * b;
//ll tmp;
///* 自然数 a > b を確認・入替 */
//if (a<b) {
//	tmp = a;
//	a = b;
//	b = tmp;
//}
///* ユークリッドの互除法 */
//ll r = a % b;
//while (r != 0) {
//	a = b;
//	b = r;
//	r = a % b;
//}
//a = x / b;//答え

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll a, b, h;
    cin >> a >> b >> h;
    cout << (a + b) * h / 2 << endl;
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

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

using namespace std;

struct kraw
{
    int b, nr;
};

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector< vector<kraw> > T(n);
    for (int i = 0; i < n - 1; ++i)
    {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        T[a].push_back({b, i});
        T[b].push_back({a, i});
    }
    int root = 0;
    for (int i = 0; i < n; ++i)
        if (T[i].size() > T[root].size())
            root = i;
    cout << T[root].size() << endl;
    stack<int> S;
    vector<bool> odw(n, false);
    S.push(root);
    odw[root] = true;
    vector<int> col(n, -1);
    while (!S.empty())
    {
        int akt = S.top();
        S.pop();
        if (akt == root)
        {
            for (int i = 0; i < T[akt].size(); ++i)
            {
                S.push(T[akt][i].b);
                odw[T[akt][i].b] = true;
                col[T[akt][i].nr] = i;
            }
        }
        else
        {
            int colOj;
            for (int i = 0; i < T[akt].size(); ++i)
                if (odw[T[akt][i].b])
                    colOj = col[T[akt][i].nr];
            int aktCol = 0;
            for (int i = 0; i < T[akt].size(); ++i)
            {
                if (!odw[T[akt][i].b])
                {
                    S.push(T[akt][i].b);
                    odw[T[akt][i].b] = true;
                    if (aktCol == colOj)
                        ++aktCol;
                    col[T[akt][i].nr] = aktCol;
                    ++aktCol;
                }
            }
        }
    }
    for (int i = 0; i < n - 1; ++i)
        cout << col[i] + 1 << endl;
    return 0;
}


Measured memory_bytes: 6912
#include<bits/stdc++.h>                          
using namespace std;
int a,b;
string s;
int main(){
    cin>>a>>b>>s;
    for(int i=0;i<s.size();i++)
        if((s[i]=='-'&&i!=a)||s[a]!='-') {cout<<"No";return 0;}
    cout<<"Yes";
	return 0;
}
//68871358
//76140264
//25446011
//200841159
//914174775

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

int main() {
  
  string n;
  cin >> n;
  
  if (n.at(0)=='7') cout << "Yes" << endl;
  else if (n.at(1)=='7') cout << "Yes" << endl;
  else if (n.at(2)=='7') cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3608
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5+5;

const int mod = 1e9+7;


long long inv[N];
long long fac[N];
long long finv[N];

void cominit(){
    fac[0] = fac[1] =1;
    finv[0] = finv[1] =1;
    inv[1] = 1;
    for(int i = 2; i < N; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i]= mod - inv[mod % i] * (mod / i) % mod;
        finv[i]= finv[i - 1] * inv[i] % mod;
    }
}

long long nCr(long long n , long long r){
    if(n < r)
        return 0;
    if(n < 0 || r < 0)
        return 0;
    return fac[n] * (finv[r] * finv[n - r] % mod) %mod;
}

long long nPr(long long n , long long r){
    if(n < r)
        return 0;
    if(n < 0 || r < 0)
        return 0;
    return (fac[n] * finv[n - r]) %mod;
}

int fastP(int b, int e){
    if(!e)
        return 1;
    if(e & 1)
        return b * 1ll * fastP(b * 1ll * b % mod, e >> 1) % mod;
    return fastP(b * 1ll * b % mod, e >> 1) % mod;
}

int n;
int m;

vector < int > primeFactors(long long num){
    vector < int > prm;
    while (num % 2 == 0){
        prm.push_back(2);
        num = num/2;
    }
    for (long long i = 3; i*i <= num; i = i + 2){
        while (num % i == 0){
            prm.push_back(i);
            num = num/i;
        }
    }
    if (num > 2)
        prm.push_back(num);
    return prm;
}

void mul_itself(long long & a , long long b){
     a *= b;
     a %= mod;
}

int main(){
    cominit();
    scanf("%d%d" , &n , &m);
    long long ans = 1;
    set < int > distinct;
    map < int , int > cnt;
    vector < int > mine = primeFactors(m);
    for(auto v : mine){
        cnt[v]++;
        distinct.insert(v);
    }
    auto it = cnt.begin();
    for(; it != cnt.end(); it++){
        mul_itself(ans , nCr(n - 1 + it->second , n - 1));
    }
    printf("%lld\n" , ans);
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  int cnt=0;
  for(int i=0;i<s.size();i++){
    if(s.at(i)=='A'){
      break;
    }
    cnt++;
  }
  for(int i=s.size()-1;i>=0;i--){
    if(s.at(i)=='Z'){
      break;
    }
    cnt++;
  }
  cout<<s.size()-cnt<<endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;

typedef long long LL;
const int MO=998244353;
const int M=2e5+5;

int mul(int x,int y)
{
	return (LL)x*y%MO;
}
int add(int x,int y)
{
	x+=y;
	if(x>=MO) x-=MO;
	return x;
}
int sub(int x,int y)
{
	x-=y;
	if(x<0) x+=MO;
	return x;
}

int n;

struct Point
{
	int x,y;
	int id;
	void read(int i)
	{
		id=i;
		scanf("%d%d",&x,&y);
	}
	bool operator<(const Point &B) const
	{
		return x<B.x;
	}
}p[M];

int cnt[M][4];

int bit[M];
void init()
{
	for(int i=1;i<=n;i++)
		bit[i]=0;
}
inline int lowbit(int x)
{
	return x&(-x);
}
void add(int p)
{
	for(;p<=n;p+=lowbit(p))
		bit[p]++;
}
int query(int p)
{
	int ans=0;
	for(;p;p-=lowbit(p))
		ans+=bit[p];
	return ans;
}

int rky[M];
int d[M];
int id(int x)
{
	return lower_bound(d,d+n,x)-d+1;
}

void getcnt()
{
	init();
	sort(p,p+n,[](const Point &a,const Point &b){
		return a.y<b.y;
	});
	for(int i=0;i<n;i++)
		rky[p[i].id]=i;
	sort(p,p+n);
	for(int i=0;i<n;i++)
		d[i]=p[i].y;
	sort(d,d+n);
	for(int i=0;i<n;i++)
	{
		int ld=query(id(p[i].y));
		cnt[p[i].id][0]=ld;
		cnt[p[i].id][1]=i-ld; // lu
		cnt[p[i].id][2]=rky[p[i].id]-ld; // rd
		cnt[p[i].id][3]=n-1-ld-(i-ld)-(rky[p[i].id]-ld); // ru
		add(id(p[i].y));
	}
}

int er[M];

int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		p[i].read(i);
	getcnt();
	// for(int i=0;i<n;i++)
	// {
	// 	for(int j=0;j<4;j++)
	// 		cout<<cnt[i][j]<<" ";
	// 	cout<<endl;
	// }
	er[0]=1;
	for(int i=1;i<=n;i++)
		er[i]=mul(er[i-1],2);
	int ans=0;
	for(int i=0;i<n;i++)
	{
		ans=add(ans,er[n-1]); // include
		// exclude
		for(int j=3;j<16;j++)
		{
			if(((j&1)&&(j&8)) || ((j&2)&&(j&4)))
			{
				//cout<<"!!! "<<j<<endl;
				int nans=1;
				for(int k=0;k<4;k++)
					if(j&(1<<k)) nans=mul(nans,er[cnt[i][k]]-1);
				//cout<<"!! "<<nans<<endl;
				ans=add(ans,nans);
			}
		}
		//cout<<ans<<endl;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 8832
#include <bits/stdc++.h>
#define sz(x) int(x.size())
#define in(x) freopen(x,"r",stdin)
#define out(x) freopen(x,"w",stdout)
#define N 100500
#define oo ll(1e16)
#define P pair<ll,ll>
#define F first
#define S second
#define pb push_back
#define el '\n'
#define elf endl
#define base ll(1e9+7)
#define MM 4294967296
#define re return
#define nins 4294967295
using namespace std;
typedef long long ll;
void ok() {cout<<"Yes";}
void no() {cout<<"No";}
void oke() {cout<<"Yes"; exit(0);}
void noe() {cout<<"No"; exit(0);}
ll n,m;
ll ans;
priority_queue<ll> q;
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin>>n>>m;
    for(int i=0;i<n;i++) {int x; cin>>x; q.push(x);}
    for(int i=0;i<m;i++) {
        int x=q.top()/2;
        q.pop();
        q.push(x);
    }
    for(;!q.empty();) {
        ans+=q.top();
        q.pop();
    }
    cout<<ans;
}


Measured memory_bytes: 1400
#include <iostream>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    switch (n % 10) {
        case 3: cout << "bon\n"; break;
        case 0:
        case 1:
        case 6:
        case 8: cout << "pon\n"; break;
        default: cout << "hon\n";
    }
    return 0;
}


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

int main(){
    int n, k, q, a, i;
    cin >> n >> k >> q;
    int count[n] = {};
    for(i=0; i<q; i++){
        cin >> a;
        count[a-1]++;
    }
    for(i=0; i<n; i++){
        if(k-q+count[i]>0) cout << "Yes\n";
        else cout << "No\n";
    }
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
# define ll int64_t
# define str string
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;

#define INF 2000000000
#define MAX_V 10



bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

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

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

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

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

using graph = vector<vector<ll>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n;
    cin>>n;
    graph g(n+1);
    rep(i,n){
        ll u,k;
        cin>>u>>k;
        rep(j,k){
            ll a;
            cin>>a;
            g[u].pb(a);
        }
    }
    
    vec<ll> dist(n+1,-1);
    queue<ll> que;
    dist[1]=0;
    que.push(1);
    
    while(!que.empty()){
        ll v=que.front();
        que.pop();
        for(auto nv : g[v]){
            if(dist[nv]==-1){
                dist[nv]=dist[v]+1;
                que.push(nv);
            }
        }
    }
    rrep(i,n){
        cout<<i<<" "<<dist[i]<<endl;
    }
    return 0;
}



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

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

    vector<int> temp(N);
    vector<int> num(N);

    for (int i = 0; i < N - 1; i++){
        cin >> temp.at(i);
    }

    for (int i = 0; i < N - 1; i++){
        num.at(temp.at(i) - 1)++;
    }

    for (int i =0; i < N; i++){
        cout << num.at(i) << endl;
    }
}

Measured memory_bytes: 4816
# N = int(input())
# import numpy as np
N, M = map(int, input().split())
# h, w = map(int, input().split())
lis = [[0, 0]for i in range(N)]

for i in range(N):
    lis[i] = list(map(int, input().split()))
# print(lis)
lis = sorted(lis, key=lambda x: x[0])

tmp = 0
i = -1
cost = 0
while tmp < M:
    i += 1
    tmp += lis[i][1]
    cost += lis[i][0]*lis[i][1]
print(cost-lis[i][0]*(tmp-M))

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

#define ln '\n'
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for(int i = (a); i <= (int)(b); ++i)
#define FORR(i, a, b) for(int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    VVI bulb(n);  // bulb[switch]
    REP(i, m) {
        int k;
        cin >> k;
        REP(j, k) {
            int s;
            cin >> s;
            bulb[s - 1].push_back(i);
        }
    }
    VI p(m);
    REP(i, m) cin >> p[i];

    int ans = 0;
    REP(i, pow(2, n)) {
        VI bulb_cnt(m, 0);
        REP(j, n) {
            // switch j is on
            bool is_on = (i >> j) & 1;
            if(!is_on) continue;
            REP(k, bulb[j].size()) bulb_cnt[bulb[j][k]]++;
        }

        // check
        REP(i, m) {
            if(bulb_cnt[i] % 2 != p[i]) break;
            if(i == m - 1) ans++;
        }
    }
    cout << ans << ln;
    return 0;
}


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

int main(){
    int i,x[10000];

    while(1){
        cin >> x[i];
        if(x[i] == 0) break;
        i++;
    }
    for(int j;j<i;j++) cout << "Case " << j+1 << ": " << x[j] << endl;
    return 0;
}



Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
bool comp(pair<long long int,long long int>a,pair<long long int,long long int>b)
{
    if(a.first==b.first)
    {
        if(a.second<=b.second)
        return true;
        else
        return false;
    }
    if(a.first>b.first)
    return true;
    else return false;
}
long long int gcd(long long int bdda,long long int chota)
{
    if(chota==0)
        return bdda;
    return gcd(chota,bdda%chota);
}
void solve()
{
    long long int n,k;
    cin>>k>>n;
    long long int a[n];
    for(long long int i=0;i<n;i++)cin>>a[i];
    long long int curr=0,val=INT_MIN;
    for(long long int i=0;i<n-1;i++)
    {
        curr=a[i+1]-a[i];
        val=max(val,curr);
    }
    curr=k-a[n-1]+a[0];
    val=max(val,curr);
    cout<<k-val;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;    
    t=1;

    //cin>>t;
    while(t--)
    {
        solve();
    }
}


Measured memory_bytes: 5244
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		
		S = S.replaceAll("eraser","-");
		S = S.replaceAll("erase","-");
		S = S.replaceAll("dreamer","-");
		S = S.replaceAll("dream","-");
		S = S.replaceAll("-","");
		if(S.length() == 0)
		System.out.println("YES");
		else
		System.out.println("NO");
	}
}


Measured memory_bytes: 31032
/*
filename:4_C-Dictionary.c
created on 17.9.2015 by charis
last edited on 17.9.2015 by charis
*/

#include<cstdio>
#include<cstring>

int m;

int getkey(char str[]){
	int sum = 0, p = 1;
	for(int k=0; k < strlen(str); k++){
		if (str[k] == 'A') sum += p*1;
		else if (str[k] == 'C') sum += p*2;
		else if (str[k] == 'G') sum += p*3;
		else if (str[k] == 'T') sum += p*4;
		p *= 5;
		}
	return sum ;
}
int h1(int key){
	return key % m;
}
int h2(int key){
	return 1 + (key % (m-1));
}
int h(int key, int i){
	return (h1(key)+i*h2(key)) % m ;
}
void insert(int T[], int key){
	int i=0;
	while(1){
		int j = h(key, i) ;
		if (T[j] == 0) {
			T[j] = key ;
			break;
		}
		else i++ ;
	}
}
bool search(int T[], int key){
	int i = 0;
	while(1){
		int j = h(key, i) ;
		if (T[j] == key) return true;
		else if (T[j] == 0 || i >= m) return false;
		else i++;
	}
}

int main(){
	int n;
	scanf("%d", &n);
	m = 1046527;
	int T[m];
	for(int k=0; k<m; k++){
		T[k] = 0;
	}
	
	for(int k=0; k<n; k++){
		char com[9], str[13] ;
		scanf("%s %s", com, str);
		int key = getkey(str);		
		if (com[0] == 'i') insert(T, key);
		else if (com[0] == 'f') {
			if (search(T, key)) printf("yes\n");
			else printf("no\n") ;
		}	
	}
	return 0;
}

Measured memory_bytes: 5104
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();

		if (a == b) {
			System.out.println(a);
		} else if (a <= b) {
			System.out.println(a);
		} else {
			System.out.println(a - 1);
		}
	}
}

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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) ((v).begin(),(v).end())
#define COUT(x) cout<<(x)<<"\n"

int main(){
    int n;
    cin >> n;
    string s;cin >> s;
    int rw=0,re=0,lw=0,le=0;
    REP(i,n){
        if(s[i]=='W')rw++;
        else re++;
    }
    int ans = re;
    REP(i,n+1){
       if(i!=n){
           if(s[i]=='W')rw--;
           else if(s[i]=='E')re--;
       }
       if(i>=1){
           if(s[i-1]=='W')lw++;
           else if(s[i-1]=='E')le++;
       }
       ans = min(ans,re+lw);
    }
    COUT(ans);
    return 0;
}


Measured memory_bytes: 900
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;

int main()
{
    char c;
    cin >> c;
    if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
        cout << "vowel" << endl;
        return 0;
    }
    cout << "consonant" << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1 << 25)
readline = sys.stdin.buffer.readline
read = sys.stdin.readline  # 文字列読み込む時はこっち
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(readline())


def ints(): return list(map(int, readline().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, readline().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, readline().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, readline().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter, xor, add
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
from functools import reduce
from math import gcd


class FastFactorization:
    def __init__(self, N: int):
        '''構築O(NloglogN)、クエリO(logN)'''
        self.N = N
        self.min_prime = self._make_minimum_prime()

    def _make_minimum_prime(self):
        # xの最小の素因数表を作成
        min_prime = [x for x in range(self.N + 1)]
        # min_prime[0] = 0  # 0と1は素数ではない
        # min_prime[1] = 1
        for i in range(2, int(self.N ** 0.5) + 1):
            if min_prime[i] == i:  # 素数だったら更新
                for j in range(2 * i, self.N + 1, i):  # iの倍数は素数でない
                    if min_prime[j] == j:
                        min_prime[j] = i
        return min_prime

    def query(self, x: int):
        # 最小素数配列min_primeを使ってO(log N)で因数分解
        # -> Counter[p,n] (素数,冪数) を格納
        # xはself.N以下
        if x == 1:
            return Counter()  # 1は素数ではない

        # 素因数分解
        arr = []
        tmp = x
        while tmp != 1:
            p = self.min_prime[tmp]
            tmp //= p
            arr.append(p)
        return Counter(arr)


# a*b = N-c
# 1 <= N-c <= N-1
# N-c=X
# a*b = X #Xの約数の個数は？
# N-cを素因数分解 -> 冪数 p1^m1 p2^m2 p3^m3  の+1の積

# 素因数分解 -> O(√X)
# O(N√N) ~ 10^9 ← TLE

# 高速素因数分解 -> 前処理 O(N) クエリ O(log(X))
# →O(N + NlogN) ~ 10^7 ←ちょうどいい感じ
# table[i] ... 整数iを構成する最小の素因数
# while X: X//=table[X];cnt+=1 <-cntが冪数になる

N = a_int()
fact = FastFactorization(N + 1)
ans = 0
for x in range(1, N):
    tmp = 1
    for v in fact.query(x).values():
        tmp *= v + 1
    ans += tmp

print(ans)

# たてのアイデアが天才的だった


Measured memory_bytes: 149196
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#define biu (puts("-1"), exit(0))  // manshinsoui
using namespace std;

template <typename Tp> inline void getint(Tp &num){
	register int ch, neg = 0;
	while(!isdigit(ch = getchar())) if(ch == '-') neg = 1;
	num = ch & 15;
	while(isdigit(ch = getchar())) num = num * 10 + (ch & 15);
	if(neg) num = -num;
}

int n; char s[100005];

int main(){
	scanf("%s", s + 1), n = strlen(s + 1);
	if(s[1] == '0' || s[n] == '1') biu;
	for(register int i = 1; i < n - i; i++) if(s[i] != s[n - i]) biu;
	for(register int i = 2, cur = 0; i <= n; i++) if(s[i] == '1')
		for(; cur < i; cur++) if(cur) printf("%d %d\n", cur, i);
	return printf("%d %d\n", n - 1, n), 0;
}

Measured memory_bytes: 1536
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            double a = sc.nextDouble();
            double b = sc.nextDouble();
            double c = sc.nextDouble();
            double d = sc.nextDouble();
            double e = sc.nextDouble();
            double f = sc.nextDouble();
            double resultX = (c * e - b * f) / (a * e - b * d);
            double resultY =  (c - a * resultX) / b;
            BigDecimal x = new BigDecimal(resultX).setScale(3, BigDecimal.ROUND_HALF_UP);
            BigDecimal y = new BigDecimal(resultY).setScale(3, BigDecimal.ROUND_HALF_UP);
            System.out.println(x + " " + y);
        }
    }
}



Measured memory_bytes: 28284
#include <iostream>
#include <vector>
#include <climits>
#include <queue>

//ダイクストラ法
std::vector<long long> dijkstra(long long n, std::vector<std::vector<std::vector<long long>>> &nx, long long start) {
	std::vector<long long> ret(n, LLONG_MAX);
	std::priority_queue<std::vector<long long>, std::vector<std::vector<long long>>, std::greater<std::vector<long long>>> task;
	task.push({0, start});
	while (task.size()) {
		while (task.size() && ret[task.top()[1]] < LLONG_MAX) task.pop();
		if (task.empty()) break;
		std::vector<long long> v = task.top();
		task.pop();
		ret[v[1]] = v[0];
		for (long long i = 0; i < nx[v[1]].size(); i++) {
			std::vector<long long> w = nx[v[1]][i];
			//if (ret[w[1]] < LLONG_MAX) continue;
			task.push({ret[v[1]] + w[0], w[1]});
		}
	}
	return ret;
}

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

	long long n, m, s;
	std::cin >> n >> m >> s;
	s = std::min(s, 2500ll);

	//頂点aで銀貨b枚所持
	auto index = [&] (long long a, long long b) {return a + b * n;};

	std::vector<std::vector<std::vector<long long>>> nx(n * 2501, std::vector<std::vector<long long>>(0));
	for (long long i = 0; i < m; i++) {
		long long u, v, a, b;
		std::cin >> u >> v >> a >> b;
		u--;
		v--;
		for (long long j = a; j <= 2500; j++) {
			nx[index(u, j)].push_back({b, index(v, j - a)});
			nx[index(v, j)].push_back({b, index(u, j - a)});
		}
	}

	for (long long i = 0; i < n; i++) {
		long long c, d;
		std::cin >> c >> d;
		for (long long j = 0; j <= 2500 - c; j++) {
			nx[index(i, j)].push_back({d, index(i, j + c)});
		}
	}

	std::vector<long long> ans = dijkstra(n * 2501, nx, index(0, s));
	for (long long i = 1; i < n; i++) {
		long long x = LLONG_MAX;
		for (long long j = 0; j <= 2500; j++) {
			x = std::min(x, ans[index(i, j)]);
		}
		std::cout << x << std::endl;
	}
}


Measured memory_bytes: 61224
from itertools import accumulate


# ある自然数未満までのエラトステネスの篩をつくる
def mark(s, x):
    for i in range(x + x, len(s), x):
        s[i] = False


def eratosthenes(n):
    s = [True] * n
    for x in range(2, int(n ** 0.5) + 1):
        if s[x]: mark(s, x)
    return [i for i in range(0, n) if s[i] and i > 1]


E = eratosthenes(10 ** 5 + 1)
P = [0] * (10 ** 5 + 1)
for e in E:
    P[e] = 1

like2017 = [0] * (10 ** 5 + 1)
for n in range(10 ** 5 + 1):
    if ((n + 1) / 2).is_integer():
        if P[n] and P[(n + 1) // 2]:
            like2017[n] = 1
like2017 = list(accumulate(like2017))

Q = int(input())
for i in range(Q):
    l, r = map(int, input().split())
    print(like2017[r] - like2017[l - 1])


Measured memory_bytes: 8648
#include <stdio.h>

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


Measured memory_bytes: 2752
#include <iostream>
#include<vector>
using namespace std;
int main(int argc, const char** argv) {

    int n;
    cin>>n;
    vector<int> arr;
    for(int i=0;i<n;i++){
        int j;
        cin >> j;
        arr.push_back(j);
    }
    int all = 0;
    for(int i=0;i<n;i++){
        all ^= arr[i];
    }
    for(int i=0;i<n;i++){
        
        cout<< (all^arr[i])<<' ';
    }
    

    return 0;
}


Measured memory_bytes: 4248
def resolve():
	n, m = map(int, input().split())
	a = []
	sb = ""
	ans = "No"
	for _ in range(n):
		a.append(input())
	for _ in range(m):
		sb += input()
	for i in range(n-m or n):
		for j in range(n-m or n):
			sa = ""
			for k in range(m):
				sa += a[i+k][j:j+m]
			if sa == sb:
				ans = "Yes"
				break
	print(ans)
resolve()

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

int n;
vector<string> s(0);

void dfs(char c, string t, char mc){
  if(t.size() == n){
    s.emplace_back(t);
    return;
  }
  for(char i = 'a'; i <= mc + 1; i++){
    string tmp = t; tmp.push_back(i);
    mc = max(c, mc);
    dfs(i, tmp, mc);
  }
  return;
}

int main(){
  cin >> n;
  dfs('a', "a", 'a');
  for(auto x : s) cout << x << endl;
  return 0;
}

Measured memory_bytes: 7796
N, M, X = [int(x) for x in input().split()]
C = [None] * N
A = [None] * N
for i in range(N):
    K = [int(x) for x in input().split()]
    C[i] = K[0]
    A[i] = K[1:]
INF = float('inf')

ans = INF
for n in range(1, 2 ** N):
    select = bin(n)[2:].zfill(N)
    cost = 0
    S = [0] * M # 理解度
    for i in range(N): # 各本について
        if int(select[i]) == 0: continue
        cost += C[i]
        for j in range(M): # 各スキルについて
            S[j] += A[i][j]

    if cost >= ans: continue
    for j in range(M):
        if S[j] < X: break
    else:
        ans = cost

if ans < INF:
    print(ans)
else:
    print(-1)

Measured memory_bytes: 9252
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vpll vector < pair<long long,long long> >
#define fill(a,val)  memset(a,val, sizeof (a))
#define sort_unique(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(cont) cont.begin(), cont.end()
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MAX   1e9
#define MIN  -1e9
typedef map<int,int> mpi;
typedef set<int> seti;
typedef multiset<int> mseti;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i, n)    for(long long int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define repn(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define trav(a, x) for(auto& a : x)
struct Interval{ll start,end;};
bool compare(Interval i1, Interval i2) {return (i1.start < i2.start);}

vll divisors[10000001];
int main(){
	fio;
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	ll n,k;
	cin>>n>>k;
	ll a[n];
	rep(i,n){
		cin>>a[i];
	}
	sort(a,a+n);
	ll l = 1,r = a[n-1];
	ll ans = 10000000000;
	while(l <= r){
		ll mid = (l+r)/2;
		ll total = 0;
		rep(i,n){
			if(mid<a[i]){
				if(a[i]%mid == 0){
					total+=a[i]/mid - 1;
				}
				else{
					total+=a[i]/mid;
				}
			}
		}
		if(total<=k){
			ans = min(ans,mid);
			r = mid-1;
		}
		else{
			l = mid+1;
		}
	}
	cout<<ans;
	return 0;
}

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

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#pragma GCC optimize("Ofast")
//1.0 * clock() / CLOCKS_PER_SEC

#define fi first
#define se second
#define ll long long
#define dl double long

using namespace std;

const ll NN = 1e10 + 7;
const int N = 1e5 + 7;
const int M = 11;
const ll mod = 1e9 + 7;
const ll inf = 1e18 + 7;
const dl rf = 1e-14;

void solve1()
{
	char a;
	set<char> st;
	for(int i = 0; i < 3; i++)
		cin >> a, st.insert(a);
	if(st.size() == 2)
		cout << "Yes";
	else
		cout << "No";
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0); srand(time(0));
    //freopen( "input.txt" , "r" , stdin );
    //freopen( "output.txt" , "w" , stdout );

    int cghf = 1;//cin >> cghf;
    while( cghf-- ){
        solve1();
    }
}


Measured memory_bytes: 256
S=input()
if(S=='SUN'):
  print(7)
elif(S=='MON'):
  print(6)
elif(S=='TUE'):
  print(5)
elif(S=='WED'):
  print(4)
elif(S=='THU'):
  print(3)
elif(S=='FRI'):
  print(2)
elif(S=='SAT'):
  print(1)

Measured memory_bytes: 38256
#include <iostream>
#include <cstring>

using namespace std;

#define ll long long

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

    int n;
    cin >> n;
    int in[n + 1], a[n + 1];
    memset(a, 0, sizeof(a));
    for (int i = 1; i <= n; i++) {
        cin >> in[i];
        a[in[i]]++;
    }
    ll res = 0, t;
    for (int i = 1; i <= n; i++) {
        t = a[i];
        res += (t * (t - 1)) / 2;
    }
    for (int i = 1; i <= n; i++) {
        cout << res - a[in[i]] + 1 << "\n";
    }
    return 0;
}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef long double ld;
typedef vector<ll>VI;
typedef pair<ll,ll>P;
#define VV(T) vector<vector<T>>
#define sz(x) int(x.size())
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX6 1001001//6
#define MAX7 10010010//7
#define SENTINEL 2000000000//9
const int MOD = 1000000007;
#define INF 1<<30
#define INFTY 1LL<<61
#define MAX_INT INT_MAX
#define Endl '\n'
#define CLR(mat) memset(mat, 0, sizeof(mat))
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
template<class T> bool contain(const std::string& s, const T& v) {
   return s.find(v) != std::string::npos;
}
using Edge=pair<int,ll>;
using Graph=vector<vector<ll> >;//ll or Edge
//const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// sort_reverse -> greater<long long>()
// vector型から重複を削除 list.erase(unique(ALL(list)),list.end());
// g++ -o a a.cpp -Wall -lm -std=c++17
//push_back -> emplace_back

int main(){
   ll n;cin>>n;
   rep(i,n){
      ll a;cin>>a;
      if(a%2==1){
         cout<<"first"<<endl;
         return 0;
      }
   }
   cout<<"second"<<endl;
}

Measured memory_bytes: 3600
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def dfs(a, ans):
    if a > n:
        return ans
    if set(list(str(a))) == rule:
        ans += 1
    for v in [3, 5, 7]:
        a = a * 10 + v
        ans = dfs(a, ans)
        a //= 10
    return ans


n = int(readline())

rule = set(('3', '5', '7'))
ans = 0

print(dfs(0, ans))

Measured memory_bytes: 9264
/*
  Problem:
  Date:
*/
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<string>
#define line cout << endl
using namespace std;
int a;
int main () {
	cin >> a;
	cout << a + a * a + a * a * a << endl;
	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main() {
  int K;
  int N;
  cin>>K>>N;
  vector<int> vec(N);
  for (int i=1;i<=N;i++){
    cin>>vec.at(i-1);
  }
  int j=K+vec.at(0)-vec.at(N-1);
  for (int k=1;k<N;k++) {
    if (vec.at(k)-vec.at(k-1)>j){
      j=vec.at(k)-vec.at(k-1);
    }
  }
  cout<<K-j<<endl;
}

Measured memory_bytes: 1152
list=[]
alphabet = dict.fromkeys("\
abcdefghijklmnopqrstuvwxyz",0)

while True:
    try:
        str=input()
    except EOFError:
        break
        continue
    if str=='':
        break
    new=str.lower()
    list.append(new)

s = "".join(list)
for c in "abcdefghijklmnopqrstuvwxyz":
    countable=s.count(c)
    print(c,":",countable)


Measured memory_bytes: 5580
#include <cstdio>
#include <stack>
#include <set>
#include <cmath>
#include <map>
#include <time.h>
#include <vector>
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <memory.h>
#include <cstdlib>
#include <queue>
#include <iomanip>
// #include <unordered_map>
#define P pair<int, int>
#define LL long long
#define LD long double
#define PLL pair<LL, LL>
#define mset(a, b) memset(a, b, sizeof(a))
#define rep(i, a, b) for (int i = a; i < b; i++)
#define PI acos(-1.0)
#define random(x) rand() % x
#define debug(x) cout << #x << " " << x << "\n"
using namespace std;
const int inf = 0x3f3f3f3f;
const LL __64inf = 0x3f3f3f3f3f3f3f3f;
#ifdef DEBUG
const int MAX = 2e3 + 50;
#else
const int MAX = 1e6 + 50;
#endif
const int mod = 1e9 + 7;

PLL a[MAX];
LL dp[2005][2005];
int main(){
#ifdef DEBUG
    freopen("in", "r", stdin);
#endif
    int n;
    scanf("%d", &n);
    for(int i = 1; i <= n; i++){
        scanf("%lld", &a[i].first);
        a[i].second = i;
    }
    sort(a+1,a+1+n, [](const PLL&x, const PLL&y){
        return x.first > y.first;
    });
    for(int i = 1; i <= n; i++){
        for(int j = 0; j < i; j++){
            dp[j][i-j]=max(dp[j][i-j], dp[j][i-j-1]+a[i].first*abs(a[i].second-(n-i+j+1)));
            dp[j+1][i-j-1]=max(dp[j+1][i-j-1], dp[j][i-j-1]+a[i].first*abs(a[i].second-(j+1)));
        }
    }
    LL ans = 0;
    for(int i = 0; i <= n; i++){
        ans = max(ans, dp[i][n-i]);
    }
    printf("%lld\n",ans);
}

Measured memory_bytes: 26492
import sys
input = sys.stdin.readline
n = int(input())
As = [int(input()) for i in range(n)]

ans = 0
for i in range(n-1):
    ans += As[i] // 2 
    As[i] = As[i] % 2
    if As[i] == 1 and As[i+1] > 0:
        As[i+1] -= 1
        ans += 1
ans += As[n-1]//2    

print(ans)

Measured memory_bytes: 7072
x, y = map(int, input().split())

g1 = [1, 3, 5, 7, 8, 10, 12]
g2 = [4, 6, 9, 11]
g3 = [2]

# if (x in g1 and y and g1) or (x in g2 and y in g2) or (x in g3 and y in g3):
#     print("Yes")
# else:
#     print("No")


if x in g1 and y in g1:
    print("Yes")
elif x in g2 and y in g2:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <numeric>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define vint vector<int>
#define pint pair<int,int>
#define pb(a) push_back(a)
#define all(v) v.begin(),v.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl

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

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

	int N, Q;
	string S;
	cin >> N >> Q >> S;

	int T[100010] = {0};

	for(int i = 1; i < N; i++)
	{
		T[i] = T[i - 1];
		if(S[i]=='C'){
			if(S[i-1]=='A'){
				T[i] = T[i - 1] + 1;
			}
		}
	}
	
	for(int i = 0; i < Q; i++)
	{
		int a, b;
		cin >> a >> b;
		cout << T[b - 1] - T[a - 1] << endl;
	}
	

	return 0;
}

Measured memory_bytes: 1872
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
struct Train{
    int city[2];
    int fee;
    int time;
};
struct City{
    int silver;
    int time;
    vector<int> trainnum;
};
void Main(){
    ll n;cin>>n;
    ll m;cin>>m;
    ll s;cin>>s;
    vector<Train> train(m);
    vector<City> city(n);
    For(i,0,m){
        cin >> train[i].city[0] >> train[i].city[1] >> train[i].fee >> train[i].time;
        train[i].city[0]--;
        train[i].city[1]--;
        city[train[i].city[0]].trainnum.push_back(i);
        city[train[i].city[1]].trainnum.push_back(i);
    }
    For(i,0,n){
        cin >> city[i].silver >> city[i].time;
    }

    vector<vector<ll>> dp(n,vector<ll> (51*n,1e18));//都市iに、銀貨j枚以上を持った状態で居るためにかかる最小時間
    For(j,0,51*n){
        if(j<=s) dp[0][j]=0;//最初
        else dp[0][j]=(j-s+city[0].silver-1)/city[0].silver*city[0].time;//都市0で全部交換する
    }
    queue<int> que;//first地点にsecond枚持っていたときから更新スタート
    que.push(0);
    while(!que.empty()){
        int from=que.front();
        que.pop();
        for(auto j:city[from].trainnum){//乗れる電車全部に対して
            int to = train[j].city[0]+train[j].city[1]-from;
            bool flag=false;
            for(int num=train[j].fee;num<51*n;num++){
                if(dp[to][num-train[j].fee]>dp[from][num]+train[j].time){
                    dp[to][num-train[j].fee]=dp[from][num]+train[j].time;
                    flag=true;
                }
            }
            for(int i=0;i<51*n;i++){
                if(i+city[to].silver<51*n) dp[to][i+city[to].silver]=min(dp[to][i+city[to].silver],dp[to][i]+city[to].time);
            }
            if(flag) que.push(to);
        }
    }
    For(i,1,n){
        ll ans=1e18;
        For(j,0,51*n){
            ans=min(ans,dp[i][j]);
        }
        cout<<ans<<endl;
    }
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

Measured memory_bytes: 4316
#include<iostream>
using namespace std;
#define MAX 100000

int A[MAX], n;

int partition(int p, int r){
    int x, i, j, t;
    x = A[r];
    i = p-1;
    for(j=p; j<r; j++){
        if(A[j] <= x){
            i++;
            t = A[i];
            A[i] = A[j];
            A[j] = t;
        }
    }
    t = A[i+1];
    A[i+1] = A[r];
    A[r] = t;
    return i+1;
}


int main(){
    int q;
    cin >> n;
    for(int i=0; i<n; i++) cin >> A[i];
    
    q = partition(0, n-1);
    
    for(int i=0; i<n; i++){
        if(i) cout << " ";
        if(i==q) cout << "[";
        cout << A[i];
        if(i==q) cout << "]";
    }
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 3396
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	char c;
	int q,t,f,sum=0;
	cin>>s;
	scanf("%d",&q);
	while(q--)
	{
		scanf("%d",&t);
		if(t==1)
			sum++;
		else
		{
			cin>>f>>c;
			if(f==1) 
				if(sum%2==0)
				s.insert(s.begin(),c);
				else s.insert(s.end(),c);
			else 
			if(sum%2==0)
			s.insert(s.end(),c);
			else s.insert(s.begin(),c);	
		}
	}
	if(sum%2==1)
		reverse(s.begin(),s.end());
	printf("%s",s.c_str());
}

Measured memory_bytes: 900
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;

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

    ll a, b;
    ll mx;
    int temp;
    int ans = INF;
    for (a = 1; a * a <= N; a++)
    {
        if (N % a == 0)
        {
            b = N / a;
            mx = max(a, b);
            temp = to_string(mx).length();
            ans = min(ans, temp);
        }
    }
    cout << ans << endl;
    return (0);
}

Measured memory_bytes: 384
import java.util.*;
public class Main{
public static void main(String[] a){
Scanner s=new Scanner(System.in);
  int i=s.nextInt();
  if(i==1){
  	System.out.println("Hello World");
  }
  else{
  int n,m;
    n=s.nextInt();
    m=s.nextInt();
    System.out.println(n+m);
  }
}
}

Measured memory_bytes: 21076
#include<stdio.h>
int main(void){
	int R;
	
	scanf("%d",&R);
	
	if(R<1200&&R>=0&&R!=1200&&R!=2800)
	printf("ABC\n");
	if(R<2800&&R>=1200&&R!=2800)
	printf("ARC\n");
	if(R>=2800)
	printf("AGC\n");
return 0;
}

Measured memory_bytes: 128