akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
  static InputReader in;
  static PrintWriter out;

  static class Solution {
    void solve() throws IOException {
      int n = in.nextInt();
      int m = in.nextInt();
      int l = in.nextInt();
      
      int[][] a = new int[n][m];
      int[][] b = new int[m][l];
      long[][] c = new long[n][l];
      
      for (int i = 0; i < n; i++) {
        for (int j= 0; j < m; j++) {
          a[i][j] = in.nextInt(); 
        }
      }
      
      for (int i = 0; i < m; i++) {
        for (int j= 0; j < l; j++) {
          b[i][j] = in.nextInt();
        }
      }
      
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < l; j++) {
          for (int k = 0; k < m; k++) {
            c[i][j] += a[i][k] * b[k][j];
          }
        }
      }
      
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < l; j++) {
          out.print(c[i][j]);
          if (j != l - 1) {
            out.print(" ");
          } else {
            out.print("\n");
          }
        }
      }
//      End solve()
    }
//    End Solution
}

  public static void main(String[] args) throws IOException {
    in = new InputReader(System.in);
    out = new PrintWriter(System.out);
    Solution solver = new Solution();
    solver.solve();
    out.close();
}

  static class InputReader {
    public BufferedReader br;
    public StringTokenizer st;

    public InputReader(InputStream stream) {
      br = new BufferedReader(new InputStreamReader(stream));
    }

    public int nextInt() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Integer.parseInt(st.nextToken());
    }

    public long nextLong() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Long.parseLong(st.nextToken());
    }

    public String next() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return st.nextToken();
    }

    public double nextDouble() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Double.parseDouble(st.nextToken());
    }


  }

}

Measured memory_bytes: 34236
#include<cstdio>
using namespace std;

const int MOD = 1000000007;

int main(){
    long long int n, k;
    scanf("%lld %lld", &n, &k);

    long long int ans = 0;

    for(long long int i = k; i <= n+1; i++){
        ans += i * (n - i) + i + 1;
        ans = ans % MOD;
    }

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

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

using namespace std;

using ll = long long;

int c[101][101], d[11][11];

bool judge(int a, int b) {
    for (int i = 1; i <= a; i++) {
        for (int j = 1; j <= b; j++) {
            int dist = 114514;
            for (int k = 0; k <= 100; k++) {
                for (int l = 0; l <= 100; l++) {
                    dist = min(dist, i * k + j * l + c[k][l]);
                }
            }
            if (dist != d[i][j]) return false;
        }
    }
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    for (int i = 1; i <= a; i++) {
        for (int j = 1; j <= b; j++) {
            cin >> d[i][j];
        }
    }

    for (int i = 1; i <= a; i++) {
        for (int j = 1; j <= b; j++) {
            for (int k = 0; k <= 100; k++) {
                for (int l = 0; l <= 100; l++) {
                    c[k][l] = max(c[k][l], d[i][j] - i * k - j * l);
                }
            }
        }
    }

    if (judge(a, b)) {
        cout << "Possible" << endl;
        cout << 202 << " " << 101 * 101 + 200 << endl;
        for (int i = 1; i <= 100; i++) {
            cout << i << " " << i + 1 << " X" << endl;
        }
        for (int i = 102; i < 202; i++) {
            cout << i + 1 << " " << i << " Y" << endl;
        }
        for (int i = 0; i <= 100; i++) {
            for (int j = 0; j <= 100; j++) {
                cout << i + 1 << " " << j + 102 << " " << c[i][j] << endl;
            }
        }
        cout << 1 << " " << 102 << endl;
    } else {
        cout << "Impossible" << endl;
    }

    return 0;
}

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

#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

main() {
    int64_t n;
    cin >> n;

    multiset<int64_t, std::greater<>> s;
    for (auto i : irange(0L, 1L << n)) {
        int64_t ss;
        cin >> ss;
        s.insert(ss);
    }

    multiset<int64_t, std::greater<>> t;
    t.insert(*s.begin());
    s.erase(s.begin());
    for (auto i : irange(0L, n)) {
        multiset<int64_t> t2;
        for (auto tt : t) {
            auto it = s.upper_bound(tt);
            if (it == s.end()) {
                cout << "No" << endl;
                return 0;
            }

            t2.insert(*it);
            s.erase(it);
        }

        for (auto tt : t2) {
            t.insert(tt);
        }
    }

    cout << "Yes" << endl;
}

Measured memory_bytes: 18688
#include<stdio.h>

int main(){
    int n, a;
    scanf("%d%d", &n, &a);
    long long int t[n+1][n+1][2501];
    int x[n+1];
    for(int i=1; i<=n; i++){
        scanf("%d", &x[i]);
    }
    for(int i=0; i<=n; i++){
        for(int j=0; j<=n; j++){
            for(int k=0; k<=2500; k++){
                if(i==0 && j==0 && k==0){
                    t[i][j][k] = 1;
                }else if(i>=1 && k<x[i]){
                    t[i][j][k] = t[i-1][j][k];
                }else if(i>=1 && j>=1 && k>=x[i]){
                    t[i][j][k] = t[i-1][j][k] + t[i-1][j-1][k-x[i]];
                }else{
                    t[i][j][k] = 0;
                }
            }
        }
    }
    long long int ans = 0;
    for(int i=1; i<=n; i++){
        ans += t[n][i][a*i];
    }
    printf("%lld", ans);

    return 0;
}

Measured memory_bytes: 50944
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
string str;
ll ans=0;
ll dp[19][19][19];
int fie[50];

void calc(int r,int b){
	memset(dp,0,sizeof(dp));
	dp[0][r][b]=1;
	for(int i=0;i<n;i++){
		for(int j=0;j<=n;j++){
			for(int k=0;k<=n;k++){
				if(dp[i][j][k]==0)continue;
				int v=(str[i+n]-'a');
				if(j<n && v==fie[j]){
					dp[i+1][j+1][k]+=dp[i][j][k];
				}
				if(k<n && v==fie[n-1-k]){
					dp[i+1][j][k+1]+=dp[i][j][k];
				}
			}
		}
	}
	ans+=dp[n][n][n];
}

void dfs(int v,int r,int b){
	if(v==n){
		calc(r,b);
	}else{
		fie[r]=str[v]-'a';
		dfs(v+1,r+1,b);
		fie[n-b-1]=str[v]-'a';
		dfs(v+1,r,b+1);
	}
}

int main(void){
	scanf("%d",&n);
	cin >> str;
	dfs(0,0,0);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int n,a[100];

  cin>>n;

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

  int minv=0,cnt=0;
  for(int i=0; i<n-1; ++i){
    minv=i;
    
    for(int j=i; j<n; ++j){
      
      if(a[minv] > a[j]){
	minv = j;
      }
      
    }


    if(!( minv == i )){
      swap(a[minv],a[i]);
      ++cnt;
    }
    
      
  }

  for(int i=0; i<n; ++i){
    cout<<a[i];
    if(i<n-1)
      cout << " ";
  }
  cout << endl << cnt << endl;;


  return 0;
}



Measured memory_bytes: 3096
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<iterator>
#include<stack>
#include<queue>
#include<utility>
#include<functional>
#include<bitset>
#include<numeric>
#include<cstring>
#include<tuple>
using namespace std;

int n, m, pos, mod = 1e9 + 7;
vector< long long > dp( 1e5 + 5, -1 ), isUnsafe( 1e5 + 5, 0 );

long long solve( int n )
{
	if( n < 0 )
	{	
		return 0;
	}
	if( n == 0 )
	{
		return 1;
	}
	if( dp[ n ] != -1 )
	{
		return dp[ n ];
	}
	dp[ n ] = 0;
	if( !isUnsafe[ n ] )
	{
		dp[ n ] = ( solve( n - 1 ) + solve( n - 2 ) ) % mod;
	}
	return dp[ n ];
}

int main( void )
{
	ios :: sync_with_stdio( 0 );
	cin.tie( 0 );
	
	cin >> n >> m;
	for( int i = 1; i <= m; ++i )
	{
		cin >> pos;
		isUnsafe[ pos ] = 1;		
	}
	cout << solve( n ) << "\n";
	return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(begin);i>(end);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())

#define ll long long
#define f first
#define s second
using namespace std;

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;

bool pairCompare(const Pii& firstElof, const Pii& secondElof)
{
    return firstElof.f > secondElof.f;	//ついでに逆順
}

int main()
{
	// 入力
	ll N, M;
	cin >> N >> M;
	vec A(N,-1);
	vec B(M,-1),C(M,-1);
	vector<Pii> bc(M);

	REP(i,N){
		cin>>A[i];
	}

	// ll bsum=0;
	// ll csum=0;

	REP(i,M){
		cin>>B[i]>>C[i];
		bc[i]=make_pair(C[i],B[i]);
		// bsum+=B[i];
		// csum+=C[i];
	}

	sort(A.begin(),A.end(),greater<ll>());
	sort(bc.begin(),bc.end(),pairCompare);
	// REVERSE(bc);

	// ll maxC=bc[0].f;

	// ll count=0;
	ll addcount=0;
	ll cardid=0;
	REP(i,N){
		if(A[i]<bc[cardid].f) {
			A[N-1-addcount]=bc[cardid].f;
			bc[cardid].s--;
			if(bc[cardid].s==0){
				if(bc.size()>cardid+1) cardid++;
				else bc[cardid].f=-1;
			}
			addcount++;
			i--;
		}
	}

	ll ans=0;
	REP(i,N){
		ans+=A[i];
	}

	cout<<ans<<endl;


	return 0;
}

Measured memory_bytes: 4224
// PUSH YOUR LIMITS.

#include<bits/stdc++.h>
using namespace std;

typedef long double ld;
#define int long long
#define RAGE ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,n) for(i=0; i <n; i++)
#define repv(i,k,n) for(i=k; i<n; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define endl '\n'
int mod = 1e9+7;
int power(int x,int n)
{   if(n==0)    return 1;
    if(n==1)    return x%mod;
    if(n%2==0)  {   int y = power(x,n/2)%mod;   return (y*y)%mod;   }
    if(n&1)     {   int y =  power(x,n-1);  return (x%mod * y%mod)%mod; }
    return 0;
}
const int maxn = 100000;
//  --------------------------------------------------------------------
void solve()
{
    int n,i,j,k,m;
    cin>>n>>k;
    int ar[n+1];
    for(i=1; i<=n; i++)
        cin>>ar[i];
    vector<int> dp(n+1 ,INT_MAX);
    dp[1] = 0;
    for(i=2; i<=n; i++)
    {
        for(j=i-1; j>=max(1ll,i-k); j--)
            dp[i] = min(dp[i] , dp[j] + abs(ar[i] - ar[j]));
    }
    cout<<dp[n];
}   
signed main()
{
    RAGE;

    int t=1;
    //  cin>>t;
    while(t--)
        solve();

    return 0;
}

Measured memory_bytes: 1792
def heian_kyoWalking()
  mx, my = gets.split.map(&:to_i)
  n = gets.to_i
  matatabiPathes = []
  count = 0

  n.times do
    matatabiPathes << gets.split.map(&:to_i)
  end

  # 平安京の道: 1 ... 通行可能. 0 ... マタタビ.
  # 縦横別の配列を用意。添字は道の出発点の座標。
  heiankyoRow    = Array.new(16).map{ Array.new(15, 1) }
  heiankyoColumn = Array.new(15).map{ Array.new(16, 1) }

  # 平安京の交差点: 交差点までの経路の総数
  heiankyoCross = Array.new(16).map{ Array.new(16, 0) }

  # マタタビのおいてある道に0を代入
  matatabiPathes.each do |x| # x: x1 y1 x2 y2
    a, b, c, d = x
    minx = [a, c].min
    miny = [b, d].min
    if a == c # 縦の道
      heiankyoColumn[miny][minx] = 0
    else      # 横の道
      heiankyoRow[miny][minx] = 0
    end
  end

  # まず、外周を初期化する.外周の交差点への経路は、マタタビがなければすべて1.
  # y = 0 の座標の交差点
  0.upto(14) do |i|
    if heiankyoRow[0][i].zero? # マタタビが見つかった場合、それ以降は中止
      break
    else
      heiankyoCross[0][i+1] = 1
    end
  end

  # x = 0 の座標の交差点
  0.upto(14) do |i|
    if heiankyoColumn[i][0].zero? # マタタビが見つかった場合、それ以降は中止
      break
    else
      heiankyoCross[i+1][0] = 1
    end
  end

  # 中の交差点
  1.upto(my) do |y|
    1.upto(mx) do |x|
      if heiankyoRow[y][x-1].zero?
        if heiankyoColumn[y-1][x].zero?  # 交差点にはたどり着けない。
          heiankyoCross[y][x] = 0
        else                             # 交差点には縦の道からのみ行ける
          heiankyoCross[y][x] = heiankyoCross[y-1][x]
        end
      elsif heiankyoColumn[y-1][x].zero? # 交差点には横の道からのみ行ける
        heiankyoCross[y][x] = heiankyoCross[y][x-1]
      else                               # 縦横両方の道から行ける
        heiankyoCross[y][x] += heiankyoCross[y][x-1] + heiankyoCross[y-1][x]
      end
    end
  end

  # p heiankyoColumn
  # p heiankyoRow
  # puts ""
  # heiankyoCross.map { |x| p x }
  puts (heiankyoCross[my][mx].zero? ? "Miserable Hokusai!" : heiankyoCross[my][mx].to_s)
end

if __FILE__ == $0
  gets.to_i.times{ heian_kyoWalking }
end

Measured memory_bytes: 6136
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+3;
int t=0, id=0, Next[maxn],in[maxn],out[maxn];
int fa[maxn][20], len[maxn];
struct node
{
    int v, next;
}edge[maxn<<1];
void add_edge(int u, int v)
{
    edge[t] = {v, Next[u]};
    Next[u] = t++;
    edge[t] = {u, Next[v]};
    Next[v] = t++;
}
 
void dfs(int cur, int pre, int d)
{
    fa[cur][0] = pre;
    len[cur] = d;
    for(int i=1; i<20; ++i)
        fa[cur][i] = fa[fa[cur][i-1]][i-1];
    in[cur] = ++id;
    for(int i=Next[cur]; i!=-1; i=edge[i].next)
    {
        int v = edge[i].v;
        if(v == pre) continue;
        dfs(v, cur, d+1);
    }
    out[cur] = id;
}
int main()
{
    int n, a, b;
     cin>>n;
    memset(Next, -1, sizeof(Next));
    for(int i=1; i<n; ++i)
    {
        cin>>a>>b;
        add_edge(a, b);
    }
    dfs(1, 0, 0);
    int tmp=(len[n]-1)/2, now=n;
    for(int i=0; i<20; ++i)
        if(tmp>>i&1) now = fa[now][i];
    int l = n-(out[now]-in[now]+1)-len[n]/2-1;
    int h = out[now]-in[now]+1-tmp-1;
    if(len[n]&1)
    {
        if(l <= h){
		cout<<"Snuke";
		}
        else {
        	cout<<"Fennec";
		}
    }
    else
    {
        if(h <= l){
        	cout<<"Fennec";
		} 
        else{ 
        cout<<"Snuke";
		}
    }
    return 0;
}

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

using namespace std;
int a,b,c,ans;
void solve(){
	ans=0;
	cin>>a>>b>>c;
	ans=min(a,min(b,c));
	if(ans==a)ans+=min(b,c);
	if(ans==b)ans+=min(a,c);
	if(ans==c)ans+=min(a,b);
	cout<<ans<<endl;
}
int main() {
	solve();
	return 0;
}


Measured memory_bytes: 256
a, b, c, x, y = map(int, input().split())

high = max(x, y)
low = min(x, y)

if a + b <= c * 2:
	res = a * x + b * y
else:
	if high == x:
		res = low * c*2 + (high - low) * a
	else:
		res = low * c*2 + (high - low) * b
	res = min( res, c*2 * high )
print(res)



Measured memory_bytes: 9160
#include <stdio.h>

int n,M[101][101];

void dijkstra(){
  int minv,i,v,u;
  int d[101],color[101];

  for(i=0;i<n;i++){
    d[i]=100000000;
    color[i]=0;
  }
  
  d[0]=0;
  color[0]=1;
  while(1){
    minv=100000000;
    u=-1;
    for(i=0;i<n;i++){
      if(minv>d[i] && color[i]!=2){
	u=i;
	minv=d[i];
      }
    }
    if(u==-1) break;
    color[u]=2;
    for(v=0;v<n;v++){
      if(color[v]!=2 && M[u][v]!=100000000){
	if(d[v] > d[u]+M[u][v]){
	  d[v]=d[u]+M[u][v];
	  color[v]=1;
	}
      }
    }
  }
  for(i=0;i<n;i++){
    printf("%d ",i);
    if(d[i]==100000000){
      printf("1\n");
    }
      else   printf("%d\n",d[i]);
    
  }
}

int main(){
  int i,j,u,k,v,c;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j]=10000000;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d %d",&v,&c);
      M[u][v]=c;
    }
  }
  
  dijkstra();
  return 0;
}

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

int main()
{
    ll N, K; cin >> N >> K;
    vector<ll> x(N, 0);
    rep(i,N) {
        ll tmp; cin >> tmp;
        x[i] = tmp;
    }
    ll num = N - K + 1;
    ll ans = 0;
    rep(i,num) {

        ll l = abs(x[i]);
        ll r = abs(x[i+K-1]);
        ll dif = abs(x[i+K-1]-x[i]);
        ll tmp = 0;
        if ((l+dif) > (r+dif)) {
            tmp = r+dif;
        }
        else {
            tmp = l+dif;
        }
        if (i == 0) {
            ans = tmp;
        }
        else if (ans > tmp) {
            ans = tmp;
        }

    }
    cout << ans << endl;



}


Measured memory_bytes: 4048
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
typedef long long ll;
typedef pair<int, int> P;
typedef struct{
  int first;
  int second;
  int third;
}T;

//昇順
bool comp_Se(T& l, T& r){
  return l.second < r.second;
}

int main(void){
  int N;
  cin >> N;
  cout << N*(N-1)/2 - N/2 << endl;
  int i,j;
  int m = (N+1)%2;
 REP(i,N){
    for(j=i+1;j<N;j++){
      if(i+j+2!=N+m) cout << i+1 << " " << j+1 << endl;
    }
  }
  return 0;
}


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

#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repa(i,arr,n) for(int i=arr;i<=n;i++)
#define repd(i,arr,n) for(int i=arr;i>=n;i--)
#define trav(arr,x) for(auto& arr:x)
#define all(c) c.begin(), c.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(arr) arr.size()
#define pi 3.14159265358979323846
#define MAX (1000*1000*1000+7)
#define vi vector<int>
#define pii pair<int,int>
#define pqueue priority_queue<int>
#define pdqueue priority_queue<int,vi,greater<int> >

const int mod = 1e9+7;
const int inf=1e17+9;

int power(int a,int b,int p)
{
    int ans=1;
    while(b)
    {
        if(b&1)
        {
            ans=(ans*a)%p;
        }
        a=(a*a)%p;
        b>>=1;
    }
    return ans;
}
int32_t main()
{
    fast;
    int n,k;
    string str;
    cin>>n>>str>>k;
    rep(i,n)
    {
        if(str[i]!=str[k-1])
            str[i]='*';
    }
    cout<<str;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int n;
    cin >> n;
    if(n%10==3){
        cout << "bon";
    } 
    else if(n%10==0 || n%10==1 || n%10==6 || n%10==8) cout << "pon";
    else cout << "hon";
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 3000005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
ll str[N];
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l,n;
	cin>>n>>k;

	ll an=0;
	for(i=k;i>=1;i--){
		str[i]=power(k/i,n,mod);
		for(j=2*i;j<=k;j+=i){
			str[i]-=str[j];
			str[i]+=mod;
			str[i]%=mod;
		}
		an=(an+(i*str[i])%mod)%mod;
	}
	cout<<an;
	return 0;
}

Measured memory_bytes: 4408
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    w,h = LI()
    p = IR(w)
    q = IR(h)
    l = []
    for i in p:
        l.append([i,0])
    for i in q:
        l.append([i,1])
    x = 0
    y = 0
    l.sort()
    ans = 0
    for i,j in l:
        if j:
            ans += i*(w+1-x)
            y += 1
        else:
            ans += i*(h+1-y)
            x += 1
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 72284
def myInput():
  n = input()
  s = input()
  return (n, [int(i) for i in s.split()])

def func():
  n, lst1 = myInput()
  cnt = 0
  for i in range(1, int(n)-1):
    if min(lst1[i+1],max(lst1[i], lst1[i-1])) == lst1[i]:
      cnt+=1
    elif min(lst1[i-1],max(lst1[i],lst1[i+1])) == lst1[i]:
      cnt += 1
  return cnt
print(func())

Measured memory_bytes: 3064
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const S = {
    A: input[0][0].split(""),
    B: input[1][0].split(""),
    C: input[2][0].split(""),
  };

  type Players = keyof typeof S;

  let cursor: Players = "A";

  while (S[cursor].length !== 0) {
    cursor = S[cursor].shift()!.toUpperCase() as Players;
  }

  return cursor;
};

console.log(main(read()));


Measured memory_bytes: 29656
from heapq import nlargest
import sys
n = int(input())
a = [int(input()) for i in range(n)]
l1, l2 = nlargest(2, a)

if l1 == l2:
  for i in range(n):
    print(l1)
  sys.exit()

for i in a:
  if i == l1:
    print(l2)
  else:
    print(l1)


Measured memory_bytes: 16944
from sys import stdin
from heapq import heappop, heappush
FORE = 1
BACK = 0
adjacent = ((1,3), (0,2,4), (1,5), (0,4,6), (1,3,5,7), (2,4,8), (3,7), (4,6,8), (5,7))
start = [int(a) for _ in range(3) for a in stdin.readline().split()]
end = [1, 2, 3, 4, 5, 6, 7, 8, 0]
def next_board(board, space, prev):
    for nxt in adjacent[space]:
        if nxt == prev: continue
        b = board[:]
        b[space], b[nxt] = b[nxt], 0
        yield b, nxt
def search(start):
    if start == end: return 0
    table = {}
    table[tuple(start)] = (FORE, 0)
    table[tuple(end)] = (BACK, 0)
    heap = [(0, start, start.index(0), None, FORE), (0, end, end.index(0), None, BACK)]
    while heap:
        i, board, space, prev, direction = heappop(heap)
        i += 1
        for b, nxt in next_board(board, space, prev):
            key = tuple(b)
            if key in table:
                if table[key][0] != direction: return table[key][1] + i
                continue
            table[key] = (direction, i)
            if b == end: return i
            heappush(heap, (i, b, nxt, space, direction))
print(search(start))

Measured memory_bytes: 12804
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T&v)
{fill((T*)array,(T*)(array+N),v);}
ll gcd(ll a,ll b){if(a>b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;}
int modpow(ll a,ll n,int m){if(a==0)return a;ll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(int)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
string s;
int z = 26;
bool u[26];
vector<vector<bool> > vu(26);
vector<vector<vector<bool> > > vuu;
vvi dp;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> s;
  each(itr, vu) (*itr).resize(26);
  FOR(i, 0, sz(s)){
    int c = s[i] - 'a';
    FOR(j, 0, 26) vu[j][c] = u[j];
    if(!u[c]) z--, u[c] = true;
    if(z == 0){
      vuu.pb(vu);
      z = 26;
      fill(u, u+26, false);
      vu = vector<vector<bool> >(26);
      each(itr, vu) (*itr).resize(26);
    }
  }
  dp.resize(sz(vuu) + 1);
  {
    vi v(26, 26);
    FOR(j, 0, 26) if(u[j] == false) v[j] = -1;
    dp[sz(vuu)] = v;
  }
  FORR(i, sz(vuu)-1, 0){
    dp[i] = vi(26, 26);
    int idx = 0;
    FOR(j, 0, 26)FOR(k, 0, 26) if(!vuu[i][j][k] && dp[i+1][k] != 26){
      dp[i][j] = k;
      break;
    }
  }
  int idx, j = 0;
  FOR(i, 0, 26)if(dp[0][i] != 26){
    idx = i;
    break;
  }
  string t = "abcdefghijklmnopqrstuvwxyz";
  while(idx >= 0){
    cout << t[idx];
    idx = dp[j][idx];
    j++;
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 15892
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define ALL(x) (x).begin(),(x).end()
const long long MOD = 1000000007;
const long long INF = 1LL << 60;

int main(){
	int N;
	cin >> N;
	cout << pow(N, 3) << endl;
}

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int ans;
string s;

signed main() {
    cin >> s;
    ans = s.size();
    rep11(i,s.size()) if (s[i-1] != s[i]) ans = min(ans, max(i, (int)s.size()-i));
    cout << ans << endl;
}





Measured memory_bytes: 512
#include <stdio.h>

int d(int x);

int main(void){
  int n,a,b,x,t,ans=0;
  scanf("%d%d%d",&n,&a,&b);
  for (x=1;x<=n;x++){
    t=d(x);
    if (t>=a&&t<=b) ans+=x;
  }
  printf("%d\n",ans);
  return 0;
}

int d(int x){
  int ret=0;
  while (x){
    ret+=x%10;
    x=(x-x%10)/10;
  }
  return ret;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
using vc=vector<char>;

int dr[4]={-1,0,0,1};
int dc[4]={0,-1,1,0};

void around(vector<vc> &field, int sr, int sc, queue<pair<int,int>> &que){
    field[sr][sc]='X';
    for(int i=0;i<4;i++){
        int nr=sr+dr[i];
        int nc=sc+dc[i];
        if(field[nr][nc]=='X'||field[nr][nc]=='#') continue;
        field[nr][nc]='#';
        que.push({nr,nc});
    }
}

int main(){
    int r,c;
    cin >> r >> c;
    vector<vc> field(r+2,vc(c+2,'#'));
    int cnt=0;
    queue<pair<int,int>> que2;
    for(int i=1;i<=r;i++){
        for(int j=1;j<=c;j++){
            cin >> field[i][j];
            if(field[i][j]=='#') que2.push({i,j});
        }
    } 
    int ans=0;
    queue<pair<int,int>> que;
    int count=0;
    while(1){
        count=0;
        while(!que2.empty()){
            auto x=que2.front();
            que2.pop();
            que.push(x);
            count++;
        }
        while(!que.empty()){
            auto x=que.front(); que.pop();
            //cout << x.first << " " << x.second << endl;
            around(field,x.first,x.second,que2);
            count++;
        }
        if(count==0) break;
        ans++;
    }

    cout << ans-1 << endl;
}

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

#define REP(i, s,  n) for(int i = s;i < (n);i++)
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;

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

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

//---------------------------------------------------------------
// 20:43 - 
//---------------------------------------------------------------

int N, K;

signed main(){
	cin >> N >> K;
	
	// Ｎ以下でＫで割り切れる数字の数（これが a, b, c の対象）
//	int x1 = N / K;
	long long x1 = 0;
	REP(i, 1, N+1) {
		if(i % K == 0)	x1++;
	}
	
	long long x2 = 0;
	if(K % 2 == 0) {
		// 偶数ならあまりがＫ／２も a, b, c の対象
//		x2 = (N + (K / 2)) / K;
		REP(i, 1, N+1) {
			if(i % K == K/2)	x2++;
		}
	}
	// x1 と x2 は混ざらない
	long long ans = x1 * x1 * x1 + x2 * x2 * x2; 
	
	cout << ans << endl;

	return 0;
}


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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    int a,b;
    int dinheiros;
    cin >> a >> b;
    if(a == b)
    {
        dinheiros = a+b;
    }
    else if (a >= b+2)
    {
        dinheiros = a + a - 1;
    }
    else if (b >= a+2)
    {
        dinheiros = b + b - 1;
    }
    else
    {
        dinheiros = a + b;
    }
    
    cout << dinheiros << endl;

    return 0;
}


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

int main(){
    int n,k,c;
    cin >> n >> k >> c;
    string s;
    cin >> s;
    int left[n+c],right[n+c];
    left[0] = 0;
    for(int i=1; i<=n;){
        if(s[i-1] == 'o'){
            left[i] = left[i-1]+1;
            for(int j=1; j<=c; j++){
                left[i+j] = left[i];
            }
            i = i+c+1;
        }
        else {
            left[i] = left[i-1];
            i++;
        }
    }
    right[0] = 0;
    for(int i=1; i<=n; ){
        if(s[n-i] == 'o') {
            right[i] = right[i-1]+1;
            for(int j=1; j<=c; j++){
                right[i+j] = right[i];
            }
            i = i+c+1;
        }
        else{
            right[i] = right[i-1];
            i++;
        }
    }
    for(int i=1; i<=n; i++){
        if(s[i-1] == 'x') continue;
        if(left[i-1] + right[n-i] < k) cout << i << endl;
    }
    return 0;
}


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

int main(){
  string a, b;
  cin >> a >> b;
  string A=a+b;
  int N=stoi(A);
  if(N==((int)sqrt(N))*((int)sqrt(N))){
    cout << "Yes" << endl;
  }
  else{
    cout <<"No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

int main(){
    int n; cin >> n;
    string s; cin >> s;
    rep(i,s.length()){
        s[i] = (s[i]-'A'+n)%26 + 'A';
    }
    cout << s << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define endl            "\n"
#define forn(i,n)       for(int i=0; i<n; i++)
#define forit(it, m)    for(decltype(m)::iterator it = m.begin(); it!=m.end(); ++it)
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void zeus()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

int32_t main()
{
    zeus();

    int a,b; cin>>a>>b;

    cout<<a*b<<endl;

}





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

// k文字でいけるならtrue
bool C(int k, vector<int> A){
    stack<pair<int, int>> st;
    // st.push({A[0], 0});
    for (int i = 1; i < A.size(); ++i) {
        if(A[i-1] >= A[i]){
            if(A[i-1] != A[i]){
                while (! st.empty() && st.top().first > A[i]) st.pop();
            }
            int cur = A[i]; // 1を足す桁
            while (1){
                if(st.empty() || st.top().first < cur) st.push({cur, 0});
                if(st.top().second < k-1) {
                    st.top().second++;
                    break;
                } else{
                    st.pop();
                    cur--;
                    if(cur <= 0) return false;
                }
            }
        }
    }
    return true;
}

int main() {
    int N;
    cin >> N;
    vector<int>A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }

    int lb = 0, ub = 1000000007;
    while( ub-lb > 1 ){
        int mid = (lb + ub)/2;
        if(C(mid, A)){
            ub = mid;
        }else{
            lb = mid;
        }
    }
    cout << ub;
    return 0;
}

Measured memory_bytes: 1920
# 約数を全列挙する関数
def make_divisors(n):
    divisors = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)
    divisors.sort()
    return divisors

N0 = int(input())
ans = 0

# N = K^a (bK + 1) と表現できるので K は N or N-1 の約数であることが必要
K_cand = set(make_divisors(N0) + make_divisors(N0-1))

for K in K_cand:
    N = N0
    if K == 1:  # K = 1 を除外
        continue
    else:
        while N%K == 0:
            N = N // K  # 割れるだけ割る
        N = N%K  # 引けるだけ引く
        if N == 1:
            ans += 1

print(ans)


Measured memory_bytes: 3828
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;



void solve(long long P, long long Q, long long R){
    ll tmp = min({P+Q, Q+R, R+P});
    cout << tmp << endl;
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long P;
    scanf("%lld",&P);
    long long Q;
    scanf("%lld",&Q);
    long long R;
    scanf("%lld",&R);
    solve(P, Q, R);
    // return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from itertools import chain

N = int(input())
ts = list(map(int, input().split()))
vs = list(map(int, input().split()))

vm = list(chain.from_iterable([v] * (2 * t) for t, v in zip(ts, vs)))
vm = [min(v1, v2) for v1, v2 in zip([0] + vm, vm + [0])]
T = len(vm)

for i in range(T - 1):
    vm[i + 1] = min(vm[i + 1], vm[i] + 0.5)

for i in range(T - 1)[::-1]:
    vm[i] = min(vm[i], vm[i + 1] + 0.5)

print(sum((v1 + v2) / 4 for v1, v2 in zip(vm, vm[1:])))


Measured memory_bytes: 4384
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;



signed main() {
    ll r, d, x;
    cin >> r >> d >> x;
    ll ans = x;
    
    
    rrep(i, 10) {
        ans = ans * r - d;
        mes (ans);
        
    }
    
   
    
    
}


Measured memory_bytes: 3568
import java.util.*;

/**
 * @author kawakami
 *
 */
class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner as = new Scanner(System.in);
		
		int m;
		int f;
		int r;
		
		while(true){
			
			m=as.nextInt();
			f=as.nextInt();
			r=as.nextInt();
			
			if(m == -1 && f == -1 && r == -1){
				break;
			}
			
			if(m == -1 || f == -1){
				
				System.out.println("F");
				
			}
			else if(m+f >= 80){
				
				System.out.println("A");
				
			}
			else if(m+f >= 65 && m+f < 80){
				
				System.out.println("B");
				
			}
			else if(m+f >= 50 && m+f < 65){
				
				System.out.println("C");
				
			}
			else if(m+f >= 30 && m+f < 50){
				
				if(r >= 50)
					System.out.println("C");
				
				else{
					System.out.println("D");
				}
				
			}
			else{
				System.out.println("F");
			}
			
			
			
			
		}

	}

}

Measured memory_bytes: 26440
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.nextLine());
    String str = sc.nextLine();
    List<String> strList = Arrays.asList(str.split(" "));
    List<List<Integer>> list = new ArrayList<List<Integer>>();
    for(int i = 0; i < n - 2; i++){
      	List<Integer> tmp = new ArrayList<Integer>();
      	tmp.add(Integer.parseInt(strList.get(i)));
      	tmp.add(Integer.parseInt(strList.get(i+1)));
      	tmp.add(Integer.parseInt(strList.get(i+2)));
      	list.add(tmp);
    }
    int count = 0;
    for(int i = 0; i < list.size(); i++){
      List<Integer> tmp = list.get(i);
      if(test(tmp, tmp.get(1)) == true){
        count++;
      }
    }
    System.out.print(count);
  }
  public static boolean test(List<Integer> list, int secondElem){
  	boolean ret = false;
    Collections.sort(list);
    if(list.get(1) == secondElem){
      if(list.get(1) != list.get(0) && list.get(1) != list.get(2)){
	    ret = true;
      }
    }
    return ret;
  }
}

Measured memory_bytes: 22732
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <bitset>
#include <set>
#include <map>
#include <string>
#include <math.h>

using namespace std;

#define fastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define swap2(x, y) x=x^y; y=x^y; x=x^y;
#define print(x) if (false) {cout << "[" << #x << " = " << x << "] ";}
#define printNL() if (false) {cout << endl;}

const int BASE = 1e9 + 7;

int main() {
    int n; cin >> n;
    vector<int> a(n);
    vector<long long> prefix(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        prefix[i] = a[i];
    }
    for (int i = 1; i < n; ++i) prefix[i] += prefix[i-1];

    long long ans = 0;
    for (int i = 1; i < n; ++i) {
        ans += (prefix[i-1] % BASE) * a[i] % BASE;
        ans %= BASE;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5620
#include <bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    const LL MOD = 1e9 + 7;
    bool notprime[1001];
    int main() {
      ios_base::sync_with_stdio(false); cin.tie(NULL);
      int n; cin >> n;
      LL ans = 1;
      for (int i = 2; i <= n; i++) {
        if (notprime[i]) continue;
        for (int j = 2 * i; j <= n; j += i) notprime[j] = true;
        int res = 1;
        for (int m = n / i; m > 0; m /= i) res += m;
        ans = (ans * res) % MOD;
      }
      cout << ans << '\n';
     
      return 0;
    }

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

v_odd = [0] * (n // 2)
v_even = [0] * (n // 2)

for i in range(n):
  if (i + 1) % 2 == 1:
    v_odd[i//2] += v_lis[i]
  else:
    v_even[i//2] += v_lis[i]
    
v_odd, v_even = Counter(v_odd).most_common(), Counter(v_even).most_common()

if v_odd[0][0] != v_even[0][0]:
  cnt = v_odd[0][1] + v_even[0][1]

else:
  tmp1 = v_odd[0][1] + (v_even[1][1] if len(v_even) >= 2 else 0)
  tmp2 = v_even[0][1] + (v_odd[1][1] if len(v_odd) >= 2 else 0)
  cnt = max(tmp1, tmp2)

print(n - cnt)

Measured memory_bytes: 28936
N = int(input())
a = list(map(int,input().split()))

a.sort()

left = 0
right = N

center = (left+right)//2

def check(i):
	s = sum(a[:i+1])
	now = s
	# print("now",a[:i+1])
	for j in range(i, N-1):
		# print("vs",now,a[j+1])
		if now*2 < a[j+1]:
			return(False)
		now += a[j+1]
	# print("now",s)
	return(True)

while right - left > 1:
	center = (left+right)//2
	# print("check",a[center],center)
	if check(center):
		right = center
		# print("able")
	else:
		left = center
		# print("not")

if check(left):
	print(N-left)
else:
	print(N-right)


Measured memory_bytes: 14320
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn main() {
    let abk: Vec<u64> = read_vec();
    let a = abk[0];
    let b = abk[1];
    let k = abk[2];

    if a >= k {
        println!("{} {}", a - k, b);
    } else if a + b >= k {
        println!("{} {}", 0, b + a - k);
    } else {
        println!("0 0");
    }
}


Measured memory_bytes: 4352
#include<stdio.h>
 
int main(){
    int a[40]={0},i,n;
    for(i=0;i<28;i++){
        scanf("%d",&n);
        a[n]=1;
    }
    for(i=1;i<=30;i++){
        if(a[i]==0) printf("%d\n",i);
    }
    return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <cassert>

using namespace std;
using ll = long long;

int main()
{
    int n;
    cin >> n;
    vector<pair<int, int>> t(n);
    for(int i = 0; i < n; i++){
        cin >> t[i].second >> t[i].first;
    }
    sort(t.begin(), t.end());
    ll tot = 0;
    for(int i = 0; i < n; i++){
        tot += t[i].second;
        if(tot > t[i].first){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 4844
#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
using namespace std;
int main()
{
    int n;
    cin>>n;
    int i,j,k,x,y;
    vector<pair<int,int>> vp;
    
    for(i=0;i<n;i++)
    {
        cin>>x>>y;
        vp.pb({x,y});
    }
    sort(vp.begin(),vp.end());
    map<pair<int,int>,int> mp;
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            mp[{vp[j].fi-vp[i].fi, vp[j].se-vp[i].se}]++;
        }
    }
    
    int mx=0;
    for(auto m :mp)
    {
        if(m.se>mx) mx=m.se;

    }
    cout<<n-mx;
    return 0;
}

Measured memory_bytes: 764
n,m=map(int,input().split())
d={}
for i in range(m):
	x,y=map(int,input().split())
	if x in d:
		d[x].append(y)
	else:
		d[x]=[y]
	if y in d:
		d[y].append(x)
	else:
		d[y]=[x]

parent=[0]*(n+1)
bfs=[1]
visited=set([1])
while len(bfs)!=0:
	x=bfs.pop(0)
	visited.add(x)
	for i in d[x]:
		if i not in visited:
			bfs.append(i)
			parent[i]=x
			visited.add(i)


if len(visited)==n:
	print('Yes')
	for i in range(2,n+1):
		print(parent[i])
else:
	print('No')




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

int main() {
  int n, k, f;
  f = 1;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    if ((2 * f) > (f + k)) {
      f += k;
    } else {
      f *= 2;
    }
  }

  cout << f << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
int a, b;
scanf("%d %d", &a, &b);
if(a == b){
printf("a == b\n");
}
else if(a > b){
printf("a > b\n", a, b);
}
else {
printf("a < b\n", a, b);
}
return 0;
}


Measured memory_bytes: 2044
import java.util.Scanner;
 class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int count = 0;
		double[][] a = new double[N][D];
		for(int i=0;i<N;i++) {
			for(int j=0;j<D;j++) {
				 a[i][j]  = sc.nextInt(); 
			}
		}
		for(int i=0;i<N-1;i++) {
			for(int j=i+1;j<N;j++) {
				double sum = 0;
				for(int k=0;k<D;k++) {
				sum +=  Math.pow(a[i][k]-a[j][k],2);
			}
				sum=Math.sqrt(sum);
				if(sum%1==0) {
					count++;
				}
		}
	}
		System.out.println(count);
}
}


Measured memory_bytes: 21844
/**
	Language: C++
	Author  : ebby21
**/

#include <bits/stdc++.h>

using namespace std;

#define FastIO() ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define Debug(v) cerr << '\n' << #v << ":\t" << v << '\n'
#define Loop(i, L, U) for (ll i = (L); i <= (U); ++i)
#define RLoop(i, U, L) for (ll i = (U); i >= (L); --i)
#define All(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;

int main() {
//	FastIO();
	int x;
	cin >> x;

	int f = x/500, s;
	x %= 500;

	s = x/5;

	cout << 1000*f + 5*s << '\n';



	return 0;
}


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

using namespace std;

constexpr double EPS = 1.0e-10;

int main()
{
    double xA, yA, xB, yB, xC, yC, xD, yD;

    while (cin >> xA >> yA >> xB >> yB >> xC >> yC >> xD >> yD) {
        double dot = (yA-yB) * (yC-yD) + (xC-xD) * (xA-xB);
        cout << ((abs(dot) < EPS)? "YES": "NO") << endl;
    }

    return 0;
}

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

int main(){
  int A,B,K; cin >> A >> B >> K;
  if( A + K - 1 < B - K + 1){
    for(int i = 0; i < K; i++){
      cout << A + i << endl;}
    for(int j = K - 1; j >= 0; j--){
      cout << B - j << endl;} }
  else{
    for(int i = A; i <= B; i++){cout << i << endl;}}
  
  return 0;}
                                

Measured memory_bytes: 256
#include <iostream>
#include <limits.h>
#include <string>
using namespace std;

int main(void){
    unsigned long long n, m = 0, a = 0, r = 0, c = 0, h = 0;
    char s[100010][15];
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> s[i];
        if (s[i][0] == 'M') m++;
        if (s[i][0] == 'A') a++;
        if (s[i][0] == 'R') r++;
        if (s[i][0] == 'C') c++;
        if (s[i][0] == 'H') h++;
    }
    cout << m * a * (r + c + h) + m * r * (c + h) + m * c * h + a * r * (c + h) + (a + r) * c * h;
    return 0;
}

Measured memory_bytes: 1664