akhauriyash/Code-Regression huggingface dataset:
unittest
{
	assert( [ "25" ].solve == 17 );
	assert( [ "1" ].solve == 1 );
	assert( [ "100" ].solve == 108 );
	assert( [ "2020" ].solve == 40812 );
	assert( [ "200000" ].solve == 400000008 );
}



import std.conv;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	
	// 先頭の桁と末尾の桁ごとに集計
	auto css = new long[][]( 10, 10 );
	foreach( i; 1L .. n + 1 )
	{
		auto u = 1L;
		for( auto r = i; 10 <= r; r /= 10 ) u *= 10;
		css[ i / u ][ i % 10 ]++;
	}
	
	// ペアの数をカウント
	auto ans = 0L;
	foreach( a; 1L .. 10L )
	{
		foreach( b; 1L .. 10L )
		{
			ans += css[ a ][ b ] * css[ b ][ a ];
		}
	}
	return ans;
}


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

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define pb push_back

using namespace std;

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

int n, m, k;

bool ok(const vector<vector<char> >& a, int i, int j)
{
    if (k == 2) {
        if (j + 1 < m && a[i][j + 1] == a[i][j]) {
            return true;
        }
        if (j - 1 >= 0 && a[i][j - 1] == a[i][j]) {
            return true;
        }
        return false;
    }
    for (int y = j - 2; y <= j; ++y) {
        if (y >= 0 && y + 2 < m && a[i][y] == a[i][y + 1] && a[i][y] == a[i][y + 2]) {
            return true;
        }
    }
    return false;
}

int solve(vector<vector<char> >& a, int step)
{
    for (int i = n - 1; i >= 0; --i) {
        for (int j = 0; j < m; ++j) {
            if (a[i][j] != '0') {
                int curr = i;
                char d = a[i][j];
                a[i][j] = '0';
                while (curr + 1 < n && a[curr + 1][j] == '0') {
                    ++curr;
                }
                a[curr][j] = d;
            }
        }
    }
    int sum = 0;
    vector<pii> p;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (a[i][j] != '0' && ok(a, i, j)) {
                sum += (a[i][j] - '0');
                p.pb({i, j});
            }
        }
    }
    for (int i = 0; i < sz(p); ++i) {
        a[p[i].first][p[i].second] = '0';
    }
    if (sum == 0) {
        return sum;
    } else {
        return sum * (1 << step) + solve(a, step + 1);
    }
}

int main()
{

    //freopen("input.txt", "r", stdin);

    //ios_base::sync_with_stdio(false);
    //cin.tie(0);

    cin >> n >> m >> k;

    vector<vector<char> > c(n, vector<char>(m));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            cin >> c[i][j];
        }
    }

    int ans = 0;

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            vector<vector<char> > a = c;
            a[i][j] = '0';
            ans = max(ans, solve(a, 0));
        }
    }

    cout << ans << "\n";

}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define ll int64_t
#define _GLIBCXX_DEBUG
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
//約数列挙(√N)
vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}
//素因数分解(√N)
map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}
//素数テーブル(NloglogN)
vector< bool > prime_table(int n) {
  vector< bool > prime(n + 1, true);
  if(n >= 0) prime[0] = false;
  if(n >= 1) prime[1] = false;
  for(int i = 2; i * i <= n; i++) {
    if(!prime[i]) continue;
    for(int j = i + i; j <= n; j += i) {
      prime[j] = false;
    }
  }
  return prime;
}
//二項係数(K)
template< typename T >
T binomial(int64_t N, int64_t K) {
  if(K < 0 || N < K) return 0;
  T ret = 1;
  for(T i = 1; i <= K; ++i) {
    ret *= N--;
    ret /= i;
  }
  return ret;
}
//二項係数テーブル(N^2)
template< typename T >
vector< vector< T > > binomial_table(int N) {
  vector< vector< T > > mat(N + 1, vector< T >(N + 1));
  for(int i = 0; i <= N; i++) {
    for(int j = 0; j <= i; j++) {
      if(j == 0 || j == i) mat[i][j] = 1;
      else mat[i][j] = mat[i - 1][j - 1] + mat[i - 1][j];
    }
  }
  return mat;
}
//unionfind
struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};

int main(){
  int n;
  cin >> n;
  vector<ll> a(n);
  ll now,money;
  money=1000;
  now=0;
  rep(i,n){
    cin >> a.at(i);
  }
  rep(i,n-1){
      money+=a.at(i)*now;
      now=0;
       if(a.at(i)<a.at(i+1)){
      now=money/a.at(i);
      money%=a.at(i);
    }
  }
  cout << now*a.at(n-1)+money << endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long N; cin >> N;
  long long ans = 9999999999;
  int tmp_a = 0;
  int tmp_b = 0;
  for(long long i = 1; i * i <= N; i++){
    if(N % i == 0){
      long long a,b;
      a = i;
      b = N / i;
      //printf("a:%d b:%d\n",a,b);
      while(a > 0){
        a /= 10;
        tmp_a++;
      }
      while(b > 0){
        b /=10;
        tmp_b++;
      }
      
      if(max(tmp_a,tmp_b) < ans) ans = max(tmp_a,tmp_b);
    }
    tmp_a = 0;
    tmp_b = 0;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3640
#include<iostream>
using namespace std;
int main(){
  string o,e;
  cin >> o >> e;
  string ans="";
  for(int i=0;i<o.size();i++){
    ans+=o[i];
    if(o.size()==e.size()||i!=o.size()-1)
      ans+=e[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#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 ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));

using namespace std;
using ll = unsigned long long;
ll MOD = 998244353;
int main(){
    ll n;
    cin >> n;
    ll answer = 1;
    vector<ll>d(n,0);
    REP(i,n)cin >> d[i];
    vector<ll>count(100003,0);
    
    REP(i,n){
        count[d[i]]++;
    }
    FOR(i,1,100003){
        REP(j,count[i]){
            answer=(answer*count[i-1])%MOD;
        }
    }
    REP(i,99999){
        if(count[i]==0&&count[i+1]!=0){
            cout << 0 << endl;
            return 0;
        }
    }
    if(d[0]!=0){
        cout << 0 << endl;
        return 0;
    }
    if(count[0]!= 1){
        cout << 0 << endl;
        return 0;
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ITP1_5
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string[] strArray = Console.ReadLine().Split(' ');
                int height = int.Parse(strArray[0]);
                int width = int.Parse(strArray[1]);

                if (height == 0 && width == 0)
                {
                    break;
                }

                string line0 = "";
                string line1 = "";
                bool even = true;
                for (int i = 0; i < width; ++i)
                {
                    if (even)
                    {
                        line0 += '#';
                        line1 += '.';
                    }
                    else
                    {
                        line0 += '.';
                        line1 += '#';
                    }
                    even = !even;
                }

                even = true;
                for (int i = 0; i < height; ++i)
                {
                    if (even)
                    {
                        Console.WriteLine(line0);
                    }
                    else
                    {
                        Console.WriteLine(line1);
                    }
                    even = !even;
                }
                Console.WriteLine();

            }
        }
    }
}

Measured memory_bytes: 19576
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

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

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
    for (auto& e:t) fill_v(e, v);
}

typedef pair<int, int> P;

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

    int N;
    cin >> N;

    int res = 0;
    FOR(i, 1, N) {
        int n = N - i;
        if (n / i <= i) break;
        if (n % i == 0) {
            res += n / i;
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

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

int main(){
	string str;
	int m,a;

	for(int i =0;i < 9;i++){
		cin>>str>>m>>a;
		cout <<str<<" "<<m+a<<" "<<200*m+300*a<<endl;
	}

	return 0;
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
using namespace std;
signed main()
{
	ios::sync_with_stdio(0);
    cin.tie(0);
	int a,b;
	cin>>a>>b;
	int ans=max(a,b)*2;
	if(a!=b)ans--;
	cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3640
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define PI acos(-1)
#define Mod (int)1000000007
#define INFTY (int)INT_MAX
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define All(vec) vec.begin(), vec.end()
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Count(vec, x) count(vec.begin(), vec.end(), x)
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())
#define Find(S, s) S.find(s) != string::npos

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<int>> c(10, vector<int>(10));
    Rep(i, 10) {
        Rep(j, 10) {
            cin >> c[i][j];
        }
    }
    Rep(k, 10) {
        Rep(i, 10) {
            Rep(j, 10) {
                c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
            }
        }
    }
    int ans = 0;
    Rep(i, H) {
        Rep(j, W) {
            int a;
            cin >> a;
            if (a == -1) continue;
            else ans += c[a][1];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3596
#ifndef __cplusplus
    cat << EOF
#endif
#include <bits/stdc++.h>
using namespace std;

#define rep(...) overload_rep(__VA_ARGS__, rep_1, rep_0)(__VA_ARGS__)
#define rep_0(i, end) for(int i = 0; i < (end); ++i)
#define rep_1(i, fr, ba) for(int i = (fr); i <= (ba); ++i)
#define overload_rep(arg0, arg1, arg2, name, ...) name
#define all(box) box.begin(), box.end()

template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }

int N;
char ans[1000][1000];

string four[4] = {
    "aagh",
    "bbgh",
    "efcc",
    "efdd",
};

string five[5] = {
    "aabbc",
    "j.hhc",
    "jg..d",
    "ig..d",
    "iffee"
};

string six[6] = {
    "abb.ee",
    "a.df..",
    "ccdf..",
    ".ggiij",
    "h..l.j",
    "h..lkk" 
};

string seven[7] = {
    ".aabbcc",
    "adde...",
    "ag.e...",
    "bgff...",
    "b...hhi",
    "c...k.i",
    "c...kjj"
};

string eight[8] = {
    "aagh....",
    "bbgh....",
    "efcc....",
    "efdd....",
    "....aagh",
    "....bbgh",
    "....efcc",
    "....efdd"
};

void draw_six(int x) {
    for(int i = x; i < N; i += 6) {
        rep(k, 6) rep(l, 6) ans[i + k][i + l] = six[k][l];
    }
}

int main() {

    cin >> N;
    if(N == 2) {
        cout << "-1\n";
        return 0;
    }
    rep(i, N) rep(j, N) ans[i][j] = '.';
    if(N % 3 == 0) {
        rep(i, N) rep(j, N) {
            if(i % 3 == 0 && j % 3 == 0) {
                ans[i][j] = ans[i][j + 1] = 'a';
            }
            if(i % 3 == 1 && j % 3 == 2) {
                ans[i][j] = ans[i + 1][j] = 'a';
            }
        }
    } else if(N % 6 == 1) {
        rep(i, 7) rep(j, 7) ans[i][j] = seven[i][j];
        draw_six(7);
    } else if(N % 6 == 2) {
        rep(i, 8) rep(j, 8) ans[i][j] = eight[i][j];
        draw_six(8);
    } else if(N % 6 == 4) {
        rep(i, 4) rep(j, 4) ans[i][j] = four[i][j];
        draw_six(4);
    } else if(N % 6 == 5) {
        rep(i, 5) rep(j, 5) ans[i][j] = five[i][j];
        draw_six(5);
    }
    rep(i, N) {
        rep(j, N) cout << ans[i][j];
        cout << '\n';
    }
    
}


Measured memory_bytes: 2176
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		long sum = 0;
		long temp1 = 0;
		long temp2 = 0;
		List<Integer> list = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			list.add(a[i]);
		}
		Collections.sort(list);
		if (n % 2 == 1) {
			for (int i = 0; i < n/2-1; i++) {
				sum += (list.get(i)) * -2;
			}
			sum += list.get(n/2-1) * -1;
			sum += list.get(n/2) * -1;
			for (int i = n/2+1; i < n; i++) {
				sum += list.get(i) * 2;
			}
			temp1 += (list.get(n/2-1) * -1) + (list.get(n/2) * -1) + (list.get(n/2+1) * 2);
			temp2 += (list.get(n/2)) + (list.get(n/2+1)) + (list.get(n/2-1) * -2);
			if (temp1 < temp2) {
				sum += temp2 - temp1;
			}
			System.out.println(sum);
		} else {
			for (int i = 0; i < n/2-1; i++) {
				sum += (list.get(i)) * -2;
			}
			sum += list.get(n/2-1) * -1;
			sum += list.get(n/2);
			for (int i = n/2+1; i < n; i++) {
				sum += list.get(i) * 2;
			}
			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 63332
import math
s = int(input())
if s ==2:
  print(2)
else:
  for i in range(s,2*s):
    if i%2==0:
      continue
    for k in range(3,round(math.sqrt(s))+1,2):
      t = 1
      if i%k ==0:
        t = 0
        break
    if t ==1:
      print(i)
      break
  
  

Measured memory_bytes: 9076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<l_l> vpl;
typedef vector<string> vs;
typedef pair<l_l,ll> lll;
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=1;i<=(n);i++)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=10100100100100100;
const ll dx[4]={1,-1,0,0};
const ll dy[4]={0,0,1,-1};
template<class T> inline bool chmin(T& a,T b){
if(a>b){
a=b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a,T b){
if(a<b){
a=b;
return true;
}
return false;
}
const int mod = 1000000007;
struct mint {
ll x;
mint(ll x=0):x((x%mod+mod)%mod){}
mint operator-() const { return mint(-x);}
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a) {
if ((x += mod-a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res+=a;
}
mint operator-(const mint a) const {
mint res(*this);
return res-=a;
}
mint operator*(const mint a) const {
mint res(*this);
return res*=a;
}
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t>>1);
a *= a;
if (t&1) a *= *this;
return a;
}
mint inv() const {
return pow(mod-2);
}
mint& operator/=(const mint a) {
return (*this) *= a.inv();
}
mint operator/(const mint a) const {
mint res(*this);
return res/=a;
}
};
struct combination {
vector<mint> fact, ifact;
combination(int n):fact(n+1),ifact(n+1) {
assert(n < mod);
fact[0] = 1;
for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
ifact[n] = fact[n].inv();
for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
}
mint operator()(int n, int k) {
if (k < 0 || k > n) return 0;
return fact[n]*ifact[k]*ifact[n-k];
}
};
combination c(300000);
ll h,w,n;
mint dp[3300][2];
vector<l_l> wall;
mint route(l_l s,l_l g){
    ll x=g.fi-s.fi;
    ll y=g.se-s.se;
    return c(x+y,x);
}
int main(){
    cin>>h>>w>>n;
    rep(i,n){
        ll r,c;cin>>r>>c;
        wall.pb({r,c});
    }
    wall.pb({1,1});
    sort(wall.begin(),wall.end());
    dp[0][0]=1;
    rrep(i,n){
        for(int j=0;j<i;j++){
            dp[i][0]+=dp[j][1]*route(wall[j],wall[i]);
            dp[i][1]+=dp[j][0]*route(wall[j],wall[i]);
        }
    }
    P g=P(h,w);
    mint ng=0;
    for(int i=1;i<=n;i++){
        ng-=dp[i][0]*route(wall[i],g);
        ng+=dp[i][1]*route(wall[i],g);
    }
    mint ans=c(h+w-2,h-1)-ng;
    cout<<ans.x<<endl;
    return 0;
}

Measured memory_bytes: 8236
N,M = map(int,input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
cnt = 0
for i in range(N-M+1):
    for j in range(N-M+1):
        cnt = 0
        for k in range(M):
            if B[k] == A[i+k][j:j+M]:
                cnt += 1
        if cnt == M:
            print('Yes')
            exit()
print('No')


Measured memory_bytes: 3060
#include <stdio.h>
#define N 120


main(){

  int n,u,k,ad[N][N],i,j,v;


  scanf("%d",&n);

  for(i=0; i<n; i++){

    scanf("%d%d",&u,&k);
    
    for(j=0; j<k; j++){

      scanf("%d",&v);

	ad[u-1][v-1]=1;

    }

  }

  for(i=0; i<n; i++){

    for(j=0; j<n; j++){

      if(ad[i][j]==1)
	printf("1");
      else
	printf("0");
     
      if(j!=n-1)
      printf(" ");

    }

    printf("\n");

  }

  return 0;

}

Measured memory_bytes: 616
from copy import copy
import random
D = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for _ in range(D)]
last = [0]*26
ans = [0]*D
score = 0
for i in range(D):
    ps = [0]*26
    for j in range(26):
        pl = copy(last)
        pl[j] = i+1
        ps[j] += s[i][j]
        for k in range(26):
            ps[j] -= c[k]*(i+1-pl[k])
    idx = ps.index(max(ps))
    last[idx] = i+1
    ans[i] = idx+1
    score += max(ps)
for i in range(30000):
    na = copy(ans)
    x = random.randint(1,365)
    y = random.randint(1,365)
    if x == y:
        continue
    na[x-1],na[y-1] = na[y-1],na[x-1]
    last = [0]*26
    ns = 0
    for i in range(D):
        last[na[i]-1] = i+1
        ns += s[i][na[i]-1]
        for j in range(26):
            ns -= c[j]*(i+1-last[j])
    if ns > score:
        ans = na
        score = ns
for a in ans:
    print(a)

Measured memory_bytes: 85660
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
typedef long long ll;
const ll longinf=1LL<<60;
using namespace std;
int n;
ll x[100],y[100];

int main()
{
    int ans=1000;
    cin>>n;
    for (int i=1; i<=n; ++i)
        cin>>x[i]>>y[i];
    if (n==1) 
    {
        cout<<1<<endl;
        return 0;
    }
    for (int i=1; i<=n; ++i)
        for (int j=1; j<=n; ++j)
            if (i!=j)
            {
                int p = x[i]-x[j];
                int q = y[i]-y[j];
                int tmpans=0;
                for (int k=1; k<=n; ++k)
                    for (int l=1; l<=n; ++l)
                        if (i!=j && x[k]-x[l]==p && y[k]-y[l]==q)
                            tmpans++;
                tmpans = n-tmpans;
                ans = min(ans,tmpans);
            }
    cout<<ans<<endl;

    return 0;
}



Measured memory_bytes: 256
#if 0

#endif

#include <bits/stdc++.h>
#define REP(i, n) for(int i=0;i<int(n);++i)
using namespace std;
template<class A>void p(A a){cout << (a) << endl;}
template<class A,class B>void p(A a,B b){cout << a << " "  ;p(b);}
template<class A,class B,class C>void p(A a,B b,C c){cout << a << " " ;p(b,c);}
template<class A,class B,class C,class D>void p(A a,B b,C c,D d){cout << a << " " ;p(b,c,d);}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF=numeric_limits<int>::max();
// for copy
// for(int i=0;i<N;++i) {

int main(void) {
  int N;cin>>N;
  map<string,int> S;
  REP(i,N) {
    string s;
    cin>>s;
    S[s] += 1;
  }
  int max = 0;
  string key;
  int value;
  // for (const auto& [key, value] : S){
  //   if (max < value) {
  //     max = value;
  //   }
  // }
  for (auto const& x : S){
    if (max < x.second) {
      max = x.second;
    }
  }
  for (const auto& x : S){
    if (max == x.second) p(x.first);
  }
  map<int,string> R;
  return 0;
}



Measured memory_bytes: 25216
import java.io.*;
import java.math.*;
import java.util.*;

class MyScanner {
    private final InputStream in = System.in;
    private final byte[] buf = new byte[1024];
    private int p = 0;
    private int len = 0;
    private boolean hasNextByte() {
        if (p >= len) {
            p = 0;
            try {
                len = in.read(buf);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return len >= 1;
    }
    private boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buf[p])) p++;
        return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        while (hasNextByte() && isPrintableChar(buf[p])) sb.appendCodePoint(buf[p++]);
        return sb.toString();
    }
    public BigDecimal nextBigDecimal() {
        return new BigDecimal(next());
    }
    public BigInteger nextBigInteger() {
        return new BigInteger(next());
    }
    public BigInteger nextBigInteger(int radix) {
        return new BigInteger(next(), radix);
    }
    public double nextDouble() {
        return Double.parseDouble(next());
    }
    public int nextInt() {
        return Integer.parseInt(next());
    }
    public int nextInt(int radix) {
        return Integer.parseInt(next(), radix);
    }
    public long nextLong() {
        return Long.parseLong(next());
    }
    public long nextLong(int radix) {
        return Long.parseLong(next(), radix);
    }
}

public class Main {
    public static void main(String[] args){
        MyScanner sc = new MyScanner();
        int n = sc.nextInt();
        int m = sc.nextInt();
        Integer[] h = new Integer[n];
        for (int i = 0; i < n; i++) h[i] = sc.nextInt();
        Boolean[] f = new Boolean[n];
        Arrays.fill(f, true);
        for (int i = 0; i < m; i++) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;
            if (h[a] <= h[b]) {
                f[a] = false;
            }
            if (h[b] <= h[a]) {
                f[b] = false;
            }
        }
        int c = 0;
        for (boolean i : f){
            if (i) c++;
        }
        System.out.println(c);
    }
}

Measured memory_bytes: 53020
N = int(input())


def prime_factorize(n):
    res, a = [], 2
    while a*a <= n:
        if n % a == 0:
            ex = 0
            while n % a == 0:
                ex += 1
                n //= a
            res.append([a, ex])
        a += 1
    if n != 1:
        res.append([n, 1])
    return res

cnt = [0] * 100
now = 1
tmp = 0
for i in range(1, 100):
    if tmp >= now+1:
        now += 1
        tmp = 0
    cnt[i] = now
    tmp += 1

primes = prime_factorize(N)
ans = 0
for p, i in primes:
    ans += cnt[i]

print(ans)


Measured memory_bytes: 62880
#include <stdio.h>
#include <string.h>

#define LIMIT 1002

int main() {
    char ss[LIMIT];
    while (1) {
        for (int i=0; i<LIMIT; ++i) {
            ss[i] = '\0';
        }
        fgets(ss, LIMIT, stdin);
        char *ln = strchr(ss, '\n');
        if (ln != NULL) {
            *ln = '\0';
        }
        if (ss[0] == '0' && ss[1] == '\0') {
            break;
        }

        int sum = 0;
        int len = strlen(ss);
        for (int i=0; i<len; ++i) {
            sum += (int)ss[i] - (int)'0';
        }
        printf("%d\n", sum);
    }
    return 0;
}



Measured memory_bytes: 2088
#include <bits/stdc++.h>
using namespace std;
const long long mod = pow(10, 9) + 7;
const long long INF = 1LL << 60;
template <class T> bool chmin(T& a, T b){if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b){if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, int B) {return (A + (B - 1)) / B;}
long long divCeil(int A, long long B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, long long B) {return (A + (B - 1)) / B;}

int index2(int N)
{
  int R = 0;
  while (N % 2 == 0)
  {
    N /= 2;
    R++;
  }
  return R;
}

int main()
{
  int N;
  cin >> N;
  
  int ans = 0;
  for (int i = 0; i < N; i++)
  {
    int A;
    cin >> A;
    ans += index2(A);
  }
  
  cout << ans << endl;
}

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

using namespace std;
typedef long long ll;


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

ll gcd3(ll a, ll b, ll c){
  ll temp = gcd2(a, b);
  return gcd2(temp, c);
}
  

int main(){
  ll K;
  cin >> K;
  
  ll n = 0;
  for(int i=1; i<=K; i++)
    for(int j=1; j<=K; j++)
      for(int k=1; k<=K; k++)
        n += gcd3(i, j, k);
  
  cout << n << endl;
  return 0;
}

Measured memory_bytes: 3628
from functools import reduce
from operator import mul


def cmb(n, r):
    if n < r:
        return 0

    r = min(n-r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


def solve(n):
    # 12 17 0 2 7
    p = [set() for _ in range(27)]
    for i in range(n):
        s = input()
        p[ord(s[0])-65].add(s)

    sum_of_elems = len(p[12])+len(p[17])+len(p[0])+len(p[2])+len(p[7])
    all_cmb = cmb(sum_of_elems, 3)

    for j in [12, 17, 0, 2, 7]:
        count_of_elem = len(p[j])
        all_cmb -= cmb(count_of_elem, 2) * (sum_of_elems - count_of_elem)
        all_cmb -= cmb(count_of_elem, 3)

    return all_cmb


if __name__ == '__main__':
    n = int(input())
    print(solve(n))


Measured memory_bytes: 14940
// "include" {{{
#include <deque>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
// }}}
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int> 
#define int long long
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1000000007;


signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b;
	cin >> a >> b;
	if(a * b * 1 % 2 == 1 || a * b * 3 % 2 == 1) cout << "Yes\n";
	else cout << "No\n";
	return 0;
}


Measured memory_bytes: 256
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque

if __name__ == '__main__':
    b, c = map(int, input().split())

    if b*c %2 ==1:
        print("Odd")
    else:
        print("Even")

Measured memory_bytes: 3828
N = int(input())
A = list(map(int, input().split()))
ans, d = 0, dict()

for i in range(N):
    key = A[i] + i
    if d.get(key) == None:
        d[key] = 1
    else:
        d[key] += 1
    
    key = i - A[i]
    if d.get(key) != None:
        ans += d[key]

print(ans)

Measured memory_bytes: 40664
cnt = 0

def merge(A, left, mid, right):
    global cnt
    L, R = A[left:mid], A[mid:right]
    L.append(float('inf'))
    R.append(float('inf'))

    i, j = 0, 0

    for k in range(left, right):
        cnt += 1
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1


def merge_sort(A, left, right):
    if left+1 < right:
        mid = (left + right) / 2
        merge_sort(A, left, mid)
        merge_sort(A, mid, right)
        merge(A, left, mid, right)


def main():
    global cnt
    n = int(raw_input())
    A = map(int, raw_input().split())

    cnt = 0
    merge_sort(A, 0, n);

    print " ".join(map(str, A))
    print cnt


main()

Measured memory_bytes: 71140
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt(); int k = sc.nextInt();
    if (n % k == 0) {
      System.out.println(0);
    } else {
      System.out.println(1);
    }
  }
}

Measured memory_bytes: 21844
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1)/ (y))
#define MOD 1000000007ULL

u64 N;
u64 A, B;

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

    cin >> N;

    vector<pair<u64, u64>> vec;

    rep (i, N)
    {
        cin >> A >> B;
        vec.emplace_back(B, A);
    }

    sort(vec.begin(), vec.end());

    u64 sum = 0;
    for (auto a : vec)
    {
        sum += a.second;
        if (sum > a.first)
        {
            cout << "No\n";
            return 0;
        }
    }

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



Measured memory_bytes: 6384
vl,abcl = tuple(map(int,input().split()))
vs = list(map(int,input().split()))

ares = [0]
for v in vs:
  ares.append(ares[-1]+v)

bres = [0]
for v in reversed(vs):
  bres.append(bres[-1]+v)


best = 0
for al in range(0,min(vl+1,abcl+1)):
  for bl in range(0,min(vl+1-al,abcl+1-al)):
    re = ares[al]+bres[bl]
    got = vs[:al]+vs[vl-bl:]
    got.sort()
    cl = 0
    while cl < al+bl and cl < abcl-al-bl and got[cl]<0:
      cl += 1
    re -= sum(got[:cl])
    #print(al,bl,cl,got,re)

    if re>best:
      best=re

print(best)

Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
	int a[200];
	int x,n;
	scanf("%d %d",&n,&x);
	int j,i;
	for(j=0;j<n;j++)
	scanf("%d",&a[j]);
	int sum=0;
	int d=0;
	for(i=0;i<n;i++)
	{
	d+=a[i];
	if(d<=x)
	{
		sum++;
	}
	}
	printf("%d",sum+1);
	
}

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

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  
  int ans;
  for(int i = 1; i <= N; i++) {
    int sum = 0;
    int x = i;
    
    for(int j = 0; j < 5; j++) {
      sum += x % 10;
      x /= 10;
    }
    if(A <= sum && sum <= B) {
      ans += i;
    }
  }
  cout << ans << endl;
}  

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

int main() {
    int N; cin >> N;
    vector<ll> A(N), B(N);
    REP(i, 0, N) cin >> A[i];
    REP(i, 0, N) cin >> B[i];

    ll cnta = 0, cntb = 0;
    REP(i, 0, N) {
        if (A[i] > B[i]) {
            cntb += A[i] - B[i];
        } else if (A[i] < B[i]) {
            if ((B[i] - A[i]) % 2 == 0) {
                cnta += (B[i] - A[i]) / 2;
            } else {
                cnta += (B[i] - A[i]) / 2 + 1;
                cntb++;
            }
        }
    }
    // cout << cnta << " " << cntb << endl;
    if (cnta >= cntb) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define base 1000000007LL
#define ll long long
#define X first
#define Y second
#define pb push_back
#define MAXN 21010
#define Scan(a) scanf("%I64d", &a)
#define CLR(a) memset(a,0,sizeof(a))
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define FORE(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)

using namespace std;

typedef pair<ll, ll> II;
typedef vector<II> vi;

int k, s, res;

int main()
{
    ios::sync_with_stdio(0);
    //freopen("inp.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    cin >> k >> s;
    FOR(i,0,k)
        FOR(j,0,k)
            if (s-i-j >= 0 && s-i-j <= k) res++;
    cout << res;
    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
	string s;cin>>s;
	int cnt1=0,cnt2=0;
	rep(i,s.size()){
		if(s[i]=='1')cnt1++;
		else cnt2++;
	}
	cout<<min(cnt1,cnt2)*2<<endl;
}

Measured memory_bytes: 512
//#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <cstring>
#include <climits>
#include <queue>
#include <algorithm>
#include <utility>
#define INF INT_MAX / 2
using namespace std;

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

int next(int x,int a,int b,int c){
	return (a*x+b)%c;
}

int main(void) {
	int n,a,b,c,x;
	while(cin >> n >> a >> b >> c >> x,n+a+b+c+x!=0){
	vector<int> col(n);
	for(int i=0;i<n;i++){
		cin >> col[i];
	}
	int cnt = 0;
	bool f=false;
	for(int i=1;i<=10001;i++){
		if(col[cnt] == x){
			cnt++;
			if(cnt == n){
				f = true;
				cout << i-1 << endl;
				break;
			}
		}
		x = next(x,a,b,c);
	}
	if(!f)cout << -1 << endl;
}
}

// command shift d duplicate
// command ctrl 上下
// command D
// command caps G → '' ""
// vector<vector<int>> a(N,vector<int>(M,-1));

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
#define lp(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()
#define ll long long
#define mod 1000000007

string str;
int n;
ll dp[100001][14];

ll calc(int idx, int rem) {
        if (idx == n) if (rem == 5) return 1; else return 0;
        ll &ret = dp[idx][rem];
        if (ret != -1) return ret;
        ret = 0;
        if (str[idx] == '?') {
                lp(i, 10) {
                        int ne = (rem * 10 + i) % 13;
                        ret += calc(idx + 1, ne) % mod;
                }
        }else ret += calc(idx + 1, (rem * 10 + str[idx]-'0') % 13) % mod;
        return ret % mod;
}

int main(){
ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
        cin >> str;
        n = str.size();
        lp(i, n + 1) lp(j, 14) dp[i][j] = -1;
        cout << calc(0, 0);
return 0;
}


Measured memory_bytes: 19280
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

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

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

  int mini = m[0];
  int sum = 0;
  for(int i = 0; i < n; i++){
    sum += m[i];
    mini = min(mini, m[i]);
  }

  int ans = n + (x - sum) / mini;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define all(a) 			a.begin(),a.end()
#define pb 				push_back
#define vi				vector<int>
#define vl 				vector<long long>
#define MOD 			1000000007
#define FOR(i,a,b) 		for(int i = a; i <= b ; i++)
#define forn(i,n) 		for(int i = 0 ; i < n; i++)
#define br 				cout<<endl;
#define testc()			int t;cin>>t;while(t--)
#define ll				long long
#define printv(v)		for(auto x : v) cout<<x<<' ';br;
#define ff				first
#define ss 				second
#define fast 			ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define vb 				vector<bool>

using namespace std;
using pii = pair<int,int>;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll power(ll a,ll b,ll mod)
{
	ll res = 1;
	a = a % mod;
	while(b)
	{
		if(b & 1)
			res = (res * a) % mod;
		b = b >> 1;
		a = (a * a) % mod;
	}
	return res;
}
/*-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/


int main()
{
	fast
	int n;cin>>n;vi a(n);forn(i,n)cin>>a[i];
	sort(all(a));
	int mid = n / 2;
	cout<<a[mid] - a[mid - 1];br;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int array[n];
	for(int i=0; i<n; i++){
		cin>>array[i];
	}
	int maxi=0;
	long long sum=0;
	for(int i=0; i<n; i++){
		maxi= max(array[i], maxi);
		int k=maxi;
		sum+=k-array[i];
	}
	cout<<sum;
}

Measured memory_bytes: 4380
#include <bits/stdc++.h>
#include <fstream>
#include <vector>
#include <bitset>
#include <unordered_map>
#include <algorithm>
#include <queue>
#include <math.h>
#include <iomanip>

using namespace std;

/********** TEMPLATE STARTS HERE ***********/

#define IOS ios::sync_with_stdio(false), cin.tie(0);
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define pb push_back
#define PI 3.1415926535897932384626433832795
#define gcd __gcd 
#define digits(n) (int)(log10(n) + 1)

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <long long> vl;
typedef vector <pll> vll;
typedef vector <pii> vii;

const int INF = 0x3f3f3f3f;
const int LINF = 0x3f3f3f3f3f3f3f3f;

template <typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template <typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

/********** TEMPLATE ENDS HERE ***********/

const int DIM = 1e5 + 7;

int v[DIM];

int main()
{
	IOS
	
	int n;
	cin >> n;
	
	for(int i = 1; i <= n; i++)
		cin >> v[i];
	
	sort(v + 1, v + 1 + n);
    
	int s = v[n] / 2;
	int e = 1;
    int dif = abs(s - v[1]);
    
	for(int i = n - 1; i > 0; i--)
	{
		if(abs(s - v[i]) < dif)
		{
			dif = abs(s - v[i]);
			e = i;
		}
	}
	
    cout << v[n] << ' ' << v[e];
    return 0;
}

Measured memory_bytes: 640
n=int(input())
a=list(map(int,input().split()))
accum=[0]
for i in range(n):
    accum.append(accum[i]+a[i])
ans=0
for i in range(0,n-1):
    ans+=a[i]*(accum[n]-accum[i+1])
    ans%=10**9+7
print(ans)

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

// #undef LOCAL
#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

// フェルマーの小定理を使った計算
class Felmat
{
  ll M;
  vector<ll> fac;  // n! (mod M)
  vector<ll> ifac; // k!^{M-2} (mod M)

public:
  Felmat(ll max_nk, ll m)
  {
    M = m;
    fac.reserve(max_nk + 1);
    ifac.reserve(max_nk + 1);
    fac[0] = 1;
    ifac[0] = 1;
    for (ll i = 0; i < max_nk; i++) {
      fac[i + 1] = fac[i] * (i + 1) % M;              // n! (mod M)
      ifac[i + 1] = ifac[i] * mpow(i + 1, M - 2) % M; // k!^{M-2} (mod M)
    }
  }
  ll mpow(ll x, ll n)
  { // x^n (mod M)
    ll ans = 1;
    while (n != 0) {
      if (n & 1)
        ans = ans * x % M;
      x = x * x % M;
      n = n >> 1;
    }
    return ans;
  }
  ll minv(ll a)
  { // 1/a (mod M)
    ll b = M, u = 1, v = 0;
    while (b) {
      ll tmp = a / b;
      a -= tmp * b;
      swap(a, b);
      u -= tmp * v;
      swap(u, v);
    }
    u %= M;
    if (u < 0)
      u += M;
    return u;
  }
  ll mfac(ll x)
  { // n! (mod M)
    int i;
    return fac[x];
  }
  ll comb(ll n, ll k)
  { // nCk (mod M)
    if (n == 0 && k == 0)
      return 1;
    if (n < k || n < 0)
      return 0;
    ll tmp = ifac[n - k] * ifac[k] % M;
    return tmp * fac[n] % M;
  }
  ll perm(ll n, ll k)
  { // nPk (mod M)
    if (n < k)
      return 0;
    ll tmp = ifac[n - k] % M;
    return tmp * fac[n] % M;
  }
};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("temp.1", "r", stdin);
  
  Felmat fm(4005, MOD);

  int N, K;
  cin >> N >> K;
  for (int i = 1; i <= K; i++) {
    ll a = fm.comb(K - 1, i - 1);
    ll b = fm.comb(N - K + 1, i);
    // ll b = fm.comb(N - K + i, i);
    dump(a, b);
    cout << a * b % MOD << endl;
  }
  return 0;
}

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

const int mxN = 2e5+1;
ll a[mxN];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	ll n, total = 0;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        total ^= a[i];
    }
    for(int i = 0; i < n; i++) {
        cout << (total^a[i]) << ' ';
    }
    return 0;
}


Measured memory_bytes: 5152
import java.util.Scanner;

fun main (args: Array<String>) {
  val input = Scanner(System.`in`)
  
  while (input.hasNext()) {
    val N = input.nextLong();
    
    if (N % 2 != 0L) {
      println(0)
    } else {
      val halfN = N / 2
      var mod = 5L
      var count = halfN / 5
      
      do {
        mod *= 5
        count += halfN / mod
      } while (halfN / mod > 0L)
      
      println(count)
    }
    
  }
}

Measured memory_bytes: 36356
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

class UnionFind:
    __slots__ = ['id','sz']

    def __init__(self, n):
        self.id = [-1] * n
        self.sz = n

    def root(self, x):
        if self.id[x] < 0:
            return x
        else:
            self.id[x] = self.root(self.id[x])
            return self.id[x]

    def find(self, x, y):
        return self.root(x) == self.root(y)

    def union(self, x, y):
        s1, s2 = self.root(x), self.root(y)
        if s1 != s2:
            if self.id[s1] <= self.id[s2]:
                self.id[s1] += self.id[s2]
                self.id[s2] = s1
            else:
                self.id[s2] += self.id[s1]
                self.id[s1] = s2
            self.sz-=1
            return True
        return False

n,m = map(int,input().split())
uf=UnionFind(n)
for i in range(m):
  a,b = map(int,input().split())
  a-=1
  b-=1
  
  uf.union(a,b)
M = 0
for i in range(n):
  M = min(M,uf.id[i])
print(abs(M))
# print(*uf.id)

Measured memory_bytes: 80284
#include<bits/stdc++.h>
using namespace std;
int n;
int a[200];
int main()
{
    scanf("%d",&n);
    int ans1=0,ans2=0,sum=0;
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    int t1=sum/n,t2=(sum+n-1)/n;
    for(int i=1;i<=n;i++){
        ans1+=(t1-a[i])*(t1-a[i]);
        ans2+=(t2-a[i])*(t2-a[i]);
    }
    printf("%d\n",min(ans1,ans2));
    return 0;
}

Measured memory_bytes: 384
import java.util.Arrays;
import java.util.Scanner;


public class Main {


    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int K = sc.nextInt();

        int[] h = new int[N];
        int[] dp = new int[N];

        for (int i = 0; i < N; i++) {
            h[i] = sc.nextInt();
        }

        sc.close();

        Arrays.fill(dp, (int)2e9);
        dp[0] = 0;

        for (int i = 0; i < N; i++) {
            for (int j = 1; j <= K; j++) {
                if (i + j < N) {
                    dp[i+j] = Math.min(dp[i+j], dp[i] + Math.abs(h[i] - h[i+j]));
                }
            }
        }

        System.out.println(dp[N-1]);
    }

}

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

long long int N;
string s;

int main(){
    scanf("%lld", &N);
    if(!N)puts("0");
    while(N){
        s.push_back((N & 1) + '0');
        N -= N & 1;
        N /= -2;
    }
    reverse(s.begin(), s.end());
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main(){
	int n,ans=0x7fffffff,num=0;
	int a[201];
	cin>>n;
	for (int i=1;i<=n;i++) cin>>a[i];
	for (int i=1;i<=n;i++){
		while(a[i]%2==0){
			a[i]=a[i]/2;
			num++;
		}
		ans=min(ans,num);
		num=0;
	}
	cout<<ans; 
}

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

public class Main {
	public static void main(String[] args) throws IOException {
		// 「ABC → BCA」の置換はAとBCの交換とみなせるはず
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String base = br.readLine();
		base = base.replace("BC", "X");

		int cntA = 0;
		long answer = 0;
		
		char[] targ = base.toCharArray();
		for ( int i = 0; i < targ.length; i++ ) {
			if ( targ[i] == 'A' ) cntA++;
			else if ( targ[i] == 'X' ) answer += cntA;
			else cntA = 0;
		}

		System.out.println(answer);
		br.close();
	}
}

Measured memory_bytes: 32652