akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


int N;
string S;
vector<vector<ll>> dp;
vector<vector<ll>> cls;

int main() {
  cin >>N >>S;
  cls.assign(3, vector<ll>(N+1, 0));
  // cls[0] := Rについての累積和
  // cls[1] := Gについての累積和
  // cls[2] := Bについての累積和
  rep(i, N){
    cls[0][i+1] += cls[0][i];
    cls[1][i+1] += cls[1][i];
    cls[2][i+1] += cls[2][i];
    if (S[i] == 'R') cls[0][i+1]++;
    if (S[i] == 'G') cls[1][i+1]++;
    if (S[i] == 'B') cls[2][i+1]++;
  }
  ll res = 0;
  for (int i=0; i<N-1; i++){
    for (int j=i+1; j<N-1; j++){
      if (S[i] == S[j]) continue;
      int tmp = 0;
      tmp += S[i] == 'R' ? 0 : S[i] == 'G' ? 1 : 2;
      tmp += S[j] == 'R' ? 0 : S[j] == 'G' ? 1 : 2;
      tmp = (30 - tmp) % 3;
      res += cls[tmp][N] - cls[tmp][j+1];
      int nk = j + (j - i);
      if (nk < N){
        if (cls[tmp][nk+1] == cls[tmp][nk] + 1) res--;
      }
    }
  }
  cout <<res <<endl;
}


Measured memory_bytes: 3688
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;
const int INF = 1001001001;

int main() {
    ll N, A, B, ans;

    cin >> A >> B >> N;

    if(N<B) {
        ans = floor(A*N/B) - A*floor(N/B);
    } else {
        ans = floor(A*(B-1)/B) - A*floor((B-1)/B);
    }

    cout << ans << endl;

    return 0;
    
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

//#define DEBUG


int main(void)
{
  char S[1];
  cin >> S;  
  printf("%c",S[0]+1);
  return 0;
} 

Measured memory_bytes: 256
s = gets.chop
k = gets.chop.to_i

order = s.split('').sort.uniq
result = []
order.each do |e|
  (0..s.length-1).each do |i|
    next if s[i] != e
    result << s[i]
    (i..i+4).each do |j|
      result << s.slice(i..j)
    end
  end
  result.uniq!
  break if result.size  > k
end
puts result.sort[k-1]


Measured memory_bytes: 3960
N,M = map(int,input().split())
H = list(map(int,input().split()))
A = [0]*M
B = [0]*M
Gab = [] # グラフ
g = [[] for _ in range(N+1)]
for i in range(M):
    #A[i],B[i] = map(int,input().split())
    #Gab.append(list(map(int,input().split()))) #グラフを表現する時こう書く

    #各ノードiがどのノードと繋がっているかをリストに格納する処理！！！
    a,b = map(int,input().split())
    g[a].append(b)
    g[b].append(a)

#print(A,B)
ans = 0

for i in range(1,N+1):#i番目のノードについて
    for j in g[i]: #i番目のノードと繋がっているノードとの高さを比較
        if H[i-1] <= H[j-1]:
            break
    else:
        ans+=1




#print(g)
print(ans)
#print(Gab)





Measured memory_bytes: 30916
import sys
input=sys.stdin.readline
import collections

def main():
    S = input().strip()
    mi = len(S)
    for c in collections.Counter(S).keys():
        s = list(S)
        n = 0
        while len(collections.Counter(s).keys()) > 1:
            for i in range(len(s)-1):
                if s[i+1] == c:
                    s[i] = c
            s.pop()
            n += 1
        mi = min(mi, n)
    print(mi)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <vector>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int a,b;
  cin>>a>>b;
  if(a%2==0 || b%2==0){
    cout<<"Even"<<"\n";
  }
  else{
    cout<<"Odd"<<"\n";
  }
  return 0;
}

Measured memory_bytes: 3564
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#define rep(i,n) for(int i = 0;i < (int)(n); i++)
using namespace std;
int main() {
	int n;
	cin >> n;
	int sum = 0;
	int w[100];
	rep(i, n) {
		cin >> w[i];
		sum += w[i];
	}
	int mi = 1000000;
	int now = w[0];
	for(int i=1;i<n;i++) {
		mi = min(mi, abs(2 * now - sum));
		now += w[i];
	}
	cout << mi << endl;
	return 0;
}

Measured memory_bytes: 256
a,b = [int(x) for x in input().split()]

def check(p):
  p = str(p)
  if p[0] == p[4] and p[1] == p[3]:
    return True
  return False

res = 0
for i in range(a,b+1):
  if check(i):
    res += 1
print(res)

Measured memory_bytes: 9172
#pragma region Macros

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

using ll = long long;
#define int ll
using vi = vector<int>;
using vvi = vector<vi>;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
ostream &operator<<(ostream &out, vector<T> const &v) {
    for (auto &&a : v) out << a << " ";
    out << endl;
    return out;
}

// debug methods
// usage: debug(x,y);
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cout << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << endl
#define debug_4(x1, x2, x3, x4) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#ifdef _DEBUG
#define debug(...)                                                        \
    CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \
    (__VA_ARGS__)
#else
#define debug(...)
#endif

#pragma endregion

void Main() {
    int N, M;
    cin >> N >> M;
    vi a(M);
    REP(i, M) {
        cin >> a[i];
    }
    int sum = 0;
    REP(i, M) {
        sum += a[i];
    }

    if (sum > N) {
        cout << -1;
        return;
    }
    cout << N - sum;
}

#pragma region main
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    Main();
    cout << flush;
}
#pragma endregion


Measured memory_bytes: 3652
//1

#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b)for(int i=(a); i<(b); i++)
#define REP(i,n)FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b){if (a<b){a = b; return 1;}return 0;}
template<typename A, typename B> inline bool chmin(A &a, B b){if (a>b){a = b; return 1;}return 0;}

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

const ll INF = 1e9+100;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
const bool debug = 1;

int N;
int p[300][300];
int sum[300][301];
int d[300], ma[300];

int main(){
	cin >> N;
	REP(i, N) REP(j, N) scanf("%d", &p[i][j]);
	
	REP(i, N) REP(j, N) sum[i][j + 1] = sum[i][j] + p[i][j];
	
	ll ans = -INF;
	REP(i, N) REP(j, N) {
		int sum = 0;
		FOR(h, i, N) {
			sum += p[h][j];
			chmax(ans, sum);
		}
	}
	REP(i, N) REP(j, N) {
		int sum = 0;
		FOR(w, j, N) {
			sum += p[i][w];
			chmax(ans, sum);
		}
	}
	
	FOR(x, 1, N) {
		REP(w, N) {
			// [x - 1, x + w] ?¨??£????[x, x+w)
			if (x + w >= N) break;
			d[0] = sum[0][x+w+1]-sum[0][x];
			
			REP(i, N - 1) d[i + 1] = d[i] - (sum[i][x+w] - sum[i][x]) + (sum[i + 1][x+w+1] - sum[i + 1][x - 1]);
			
			ma[N - 2] = d[N - 1];
			for (int i = N - 3; i >= 0; i--) ma[i] = max(ma[i + 1], d[i + 1]);
			
			REP(i, N - 1) {
				chmax(ans, ma[i] - d[i] + (sum[i][x+w+1]-sum[i][x-1]) + (sum[i][x+w]-sum[i][x]));
			}
		}
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3928
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <vector>
using namespace std;
int main(){
  int a,b,i,j;
  cin >> a >> b;
  if(a <= b){
    for(i = 0; i < b; i++){
      cout << a;
    }
  }else{
    for(i = 0; i< a; i++){
      cout << b;
    }
  }
}


Measured memory_bytes: 256
n = int(input())
i = 1
str_list = [chr(i) for i in range(97, 97+26)]
ans =str()

while True:
    if n- 26 **i <= 0:
        break
    n -= 26 ** i
    i += 1
    
n -= 1

for j in range(i):
    ans = str_list[n%26] + ans
    n //= 26

print(ans)

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

int solve(int,int);

int A[20],n;

int main(){

  int q,M[200];

  cin >> n;
  for(int i=0 ; i < n ; i++)cin >> A[i];
  
  cin >> q; 
  for(int i=0 ; i < q ; i++)cin >> M[i];

  for(int i=0 ; i < q ; i++){
    if(solve(0,M[i])){
      cout <<"yes"<<endl;
    }else{
      cout <<"no"<<endl;
    }
  }
  
  return 0;

}

int solve(int i,int m){
  
  if( i >= n ){
    return m == 0;
  }
  if(solve(i+1,m)){
    return true;
  }
  if(solve(i+1,m-A[i])){
    return true;
  }
  
  return false;
  
}

Measured memory_bytes: 1152
x, y = map(int, input().split())
list1 = [1,3,5,7,8,10,12,4,6,9,11,2]
list2 = [0,0,0,0,0,0,0,1,1,1,1,2]
d = dict(zip(list1, list2))
if d[x] == d[y]:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
///بِسْمِ الّٰلهِ الرَّحْمٰنِ الرَحِيْمِ
#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main()
{
     ios_base::sync_with_stdio(false);cin.tie(NULL);
     ll int i,n,p,m,x=0;
     cin>>n;
     ll int ara[n];
     for(i=0;i<n;i++){
        cin>>ara[i];

     }
     p=1;
     sort(ara,ara+n);

     p=ara[0]*p;
     for(i=1;i<n;i++){
        m=ara[i]*p;
        if(m>1000000000000000000 || m<0 || m<p){
        cout<<-1<<endl;return 0;
        }
        p=m;
     }
     cout<<m<<endl;

     return 0;
}






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

using namespace std;

typedef long long ll;

int max(int a, int b) { return (a > b) ? a : b; }

const int MAXN = 2000 * 1000 + 1;


const int INF = 1e9;

bitset<MAXN> can = 0;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n, a, b;
    int k;
    cin >> n >> a >> b;
    cout << min(a, b) << " " << max(0, a + b - n);

    return 0;
}

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

int main() {
    int N;
    cin >> N;
    int i = 1;
    while (i*2 <= N){
        i *= 2;
    }
    cout << i << endl;
}


Measured memory_bytes: 256
(* O(|s|) *)
let get_left_info s =
  let n = String.length s in
  let left = Array.make (n + 1) 0 in
  for i = 1 to n - 1 do
    if s.[i - 1] = 'A' && s.[i] = 'C' then
      left.(i + 1) <- left.(i) + 1
    else
      left.(i + 1) <- left.(i)
  done;
  left

(* O(max {n, q}) *)
let _ = Scanf.scanf " %d %d %s" @@ fun n q s ->
  let left = get_left_info s in
  for i = 1 to q do
    Scanf.scanf " %d %d" @@ fun l r ->
      Printf.printf "%d\n" @@ left.(r) - left.(l) (* l = l + |"AC"| - 1 - 1 *)
  done

Measured memory_bytes: 6272
// #include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;

#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0; i<n; i++)

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

    if (k%2==0 || k%5==0) {
        cout << -1 << endl;
        return 0;
    }

    int cnt = 1;
    int temp = 7%k;
    int sum = 7%k;
    while(sum) {
        temp = (temp*10)%k;
        sum += temp;
        sum %= k;
        cnt++;
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6;
ll a[maxn];
ll cop[5*maxn];
int main()
{
	int n;
	scanf("%d",&n);
	ll res=0;
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
	sort(a+1,a+1+n);
	for(int i=3;i<=n;i++)
	{
		ll cot=0;
		for(int k=1;k<i;k++)
			for(int j=k+1;j<i;j++)
				if(a[k]+a[j]>a[i]) cot++;
		res+=cot;
	}
	printf("%lld\n",res);
	return 0;
}

Measured memory_bytes: 2304
N = int(input())
h = [int(i) for i in input().split()]

ans = 0
tmp = 0
for i in range(N-1):
    if h[-(i+2)] >= h[-(i+1)]:
        tmp += 1
        if tmp > ans:
            ans = tmp
    else:
        tmp = 0
    
print(ans)

Measured memory_bytes: 14252
use std::io::stdin;
// use std::collections::HashMap;

fn main() {
    let mut s: String = String::new();
    stdin().read_line(&mut s).ok();
    let s: Vec<char> = s.trim().chars().collect();

    let mut counts: Vec<usize> = vec![0; 2019];
    counts[0] += 1;

    // s $B$rA`:n$7$F$$$-!"(Bmod 2019 $B$r(B count $B$H$7$FJ]B8$7$F$$$/(B
    let mut base = 1;
    let mut temp_mod = 0;
    for &s_i in s.iter().rev() {
        temp_mod = (temp_mod + (s_i as usize - 48) * base) % 2019;
        base = (base * 10) % 2019;
        if s_i != '0' {
            counts[temp_mod] += 1;
        }
    }

    let mut res = 0;
    for counts_i in counts {
        if counts_i > 1 {
            res += counts_i * (counts_i - 1) / 2;
        }
    }
    println!("{}", res);
}


// fn main() {
//     let mut s: String = String::new();
//     stdin().read_line(&mut s).ok();
//     let s: Vec<char> = s.trim().chars().collect();
// 
//     // $B8e$m$+$iAv::$7$F$$$/(B
//     // $B3FCmL\?t$K$D$$$F!">jM>$r=P$7$F!"0l$D:8$N>jM>$rB-$7$F(B... $B$r7+$jJV$7$F$$$/(B
// 
//     let mut res = 0;
//     let mut dp_dict: HashMap<usize, usize> = HashMap::new();
//     for i_upper in 0..s.len() {
//         let mut temp_mod = 0;
//         let mut temp_dp_dict: HashMap<usize, usize> = HashMap::new();
//         for i_lower in i_upper..s.len() {
//             // println!("{}, {}", s[i_lower], s[i_lower] as usize);
//             temp_mod = (temp_mod * 10 + (s[i_lower] as usize - 48)) % 2019;
// 
//             // temp_mod = (temp_mod + (s[i_upper] as usize) * base);
// 
//             // let temp_str: String = s[i_upper..i_lower + 1].iter().collect();
//             // // println!("{}, {}", temp_str, temp_str.parse::<usize>().unwrap() % 2019);
//             // // temp_mod = (temp_mod + temp_str.parse::<usize>().unwrap() % 2019) % 2019;
//             // temp_mod = temp_str.parse::<usize>().unwrap() % 2019;
//             // // println!(" === {} === ", temp_mod);
// 
//             if temp_mod == 0 {
//                 if dp_dict.contains_key(&i_lower) {
//                     res += dp_dict.get(&i_lower).unwrap();
//                     for (k, v) in temp_dp_dict.iter_mut() {
//                         *v += 1;
//                     }
//                     break;
//                 }
//                 res += 1;
//                 temp_dp_dict.insert(i_lower, 0);
//                 for (k, v) in temp_dp_dict.iter_mut() {
//                     *v += 1;
//                 }
//             }
//         }
//         for (k, v) in temp_dp_dict.iter() {
//             dp_dict.insert(*k, *v);
//         }
//     }
// 
//     println!("{}", res);
// }


Measured memory_bytes: 3020
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

ll mpow(ll a, ll b){
	if(b==0){
		return 1;
	}else if(b%2==0){
		ll memo = mpow(a,b/2);
		return memo*memo%MOD;
	}else{
		return mpow(a,b-1) * a % MOD;
	}
}

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

int main(void){
	int n;
	cin>>n;
	ll a;
	vector<ll> A;
	rep(i,n){
		cin>>a;
		A.push_back(a);
	}
	sort(all(A));
	if(A[A.size()-1] == 0){
		cout<<"Yes"<<endl;
		return 0;
	}
	if(A.size()%3 != 0){
		cout<<"No"<<endl;
		return 0;
	}
	ll memo1,memo2,memo3;
	memo1 = A[0];
	memo2 = A[n/3];
	memo3 = A[n/3*2];
	rep(i,n/3){
		if(memo1 != A[i]){
			cout<<"No"<<endl;
			return 0;
		}
		if(memo2 != A[i+n/3]){
			cout<<"No"<<endl;
			return 0;
		}
		if(memo3 != A[i+n/3*2]){
			cout<<"No"<<endl;
			return 0;
		}
	}

	if((memo1^memo2^memo3) != 0){
		cout<<"No"<<endl;
		return 0;
	}
	cout<<"Yes"<<endl;


	return 0;
}


Measured memory_bytes: 1400
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1
//{
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{
    private:
        int i;
    public:
        mint() : i(0){}
        mint(int i):i((i%m+m)%m){}
        mint operator+(const mint& o){return o.i+i;}
        mint operator*(const mint& o){return o.i*i;}
        mint operator-(){return -i;}operator int() {return i;}
        mint& operator+=(const mint& o){
            i = ((i + o.i)%m + m)%m;
            return *this;
        }
        mint& operator-=(const mint& o){
            i = ((i - o.i)%m + m)%m;
            return *this;
        }
};

//}

//typedef mint<1234567> itn;

int h,w;
bool nh[100],nw[100];

main(){
    cin>>h>>w;
    char m[h][w];
    rep(i,h)rep(j,w)cin>>m[i][j];
    rep(i,h){
        bool f=false;
        rep(j,w){
            if(m[i][j]=='#'){
                f=true;
                continue;
            }
        }
        nh[i]=f;
    }
    rep(i,w){
        bool f=false;
        rep(j,h){
            if(m[j][i]=='#'){
                f=true;
                continue;
            }
        }
        nw[i]=f;
    }
    rep(i,h){
        rep(j,w){
            if(nw[j]&&nh[i])cout<<m[i][j];
        }
        cout<<endl;
    }
}




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

using namespace std;

#define F first
#define S second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define endl '\n'

typedef long long int ll;
typedef pair<ll,ll> ii;
typedef pair<string,ll> si;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<si> vsi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vsi> vvsi;

const int INF = 2000000000;
const ll INFLL = 1LL * INF * INF;
ll mod = (int)pow(10,9)+7;
//**************************************************************
//int findSet(int i)
// {
// 	return (p[i]==i)? i:(p[i]=findSet(p[i]));
// }
// bool isSame(int i, int j)
// {
// 	return findSet(i)==findSet(j);
// }
// void unionSet(int i, int j)
// {
// 	if(!isSame(i,j))
// 	{
// 		int x = findSet(i);
// 		int y = findSet(j);
// 		if(ra[x]>ra[y])
// 			p[y] = i;
			
// 		else
// 		{
// 			p[x] = y;
// 			if(ra[x]==ra[y])
// 				ra[y]++;		
// 		}
// 	}
// }

// ***************************************************************************
// ll mulmod(ll a, ll b, ll mod) 
// { 
//     ll res = 0; // Initialize result 
//     a = a % mod; 
//     while (b > 0) 
//     { 
//         // If b is odd, add 'a' to result 
//         if (b % 2 == 1) 
//             res = (res + a) % mod; 
  
//         // Multiply 'a' with 2 
//         a = (a * 2) % mod; 
  
//         // Divide b by 2 
//         b /= 2; 
//     } 
  
//     // Return result 
//     return res % mod; 
// } 
// *****************************************************************************
// bool sieve[100005];

// void sieveoferat()
// {
// 	for(ll p = 2; p*p<100005 ; p++)
// 	{
// 		if(sieve[p])
// 		{
// 			for(int j = p*p; j<100005; j+=p)
// 				sieve[j] = false;
// 		}
// 	}
// }
//********************************************************************************
// void dp(sp_1, sp_2.....)
// {
// 	if()//exit statement
// 	if()//using the memoization 
// 	ll ans = //default/dummy answer
// 	//recursions
// 			//max/min
// 	return memo[][].. = ans;

// }
//*************************************************************************************
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
 	cout.tie(NULL);
 	//memset(memo, -1, sizeof memo);
 	// memset(sieve, true, sizeof sieve);
 	// sieveoferat();
 	// for(int i = 1; i<100005 ;i++) UFDS
		// p[i] = i;
 	int n; cin>>n;
 	if(!(n&1))
 	{

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

	 	sort(a, a+n+1);

	 	cout<< a[n/2 +1] - a[n/2] <<endl;
 	}
 	else
 		cout<<0<<endl;
	return 0;
}

Measured memory_bytes: 640
#pragma region head
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define test(s) \
  if (!(s))     \
    cout << "Line " << __LINE__ << ": [" << #s << "] is false" << endl;
#define int long long
typedef long long ll;
#define double long double
typedef double ld;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;
const double PI = acos(-1.0);

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
#pragma endregion

signed main() {
  int a;
  cin >> a;
  int ans = a + a * a + a * a * a;
  cout << ans << endl;
}

Measured memory_bytes: 3580
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<int> par;
    
//     UnionFind(int N): par(N) {
//         for (int i=0;i<N;i++) par[i] = i;
//     }

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

//     void unite(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//     }

//     bool same(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };

int main(void) {
    int N, M;
    vector<int> P(100010), Y(100010);
    cin >> N >> M;
    for (int i=0;i<M;i++) cin >> P[i] >> Y[i];

    vector<pair<int,int>> C[N+1];
    for (int i=0;i<M;i++) {
        C[P[i]].emplace_back(Y[i],i);
    }
    for (int i=1;i<=N;i++) {
        sort(C[i].begin(), C[i].end());
    }
    vector<ll> S(M);
    for (int i=1;i<=N;i++) {
        for (auto itr = C[i].begin(); itr != C[i].end(); itr++) {
            ll id = i*1000000LL + (itr-C[i].begin()+1);
            S[itr->second] = id;
        }
    }
    for (auto itr: S) {
        cout << setw(12) << setfill('0') << itr << endl;
    }

    return 0;
}


Measured memory_bytes: 8576
import java.util.*;

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

    int n = sc.nextInt();
    String s = sc.next();
    char[] c = new char[n];
    int ans = 0;
    
    for(int i = 0; i < n; i++){
      c[i] = s.charAt(i);
    }
    for(int i = 0; i < n - 2; i++){
      if(c[i] == 'A' && c[i+1] == 'B' && c[i+2] == 'C'){
        ans += 1;
      }
    }

    System.out.println(ans);
  }
}


Measured memory_bytes: 21972
n=int(input())
dp=[100000 for i in range(n+1)]
dp[0]=0
dp[1]=1
for i in range(1,n+1):
  dp[i]=dp[i-1]+1
  j,k=0,0
  while 6**j<=i:
    dp[i]=min(dp[i],dp[i-6**j]+1)
    j+=1
  while 9**k<=i:
    dp[i]=min(dp[i],dp[i-9**k]+1)
    k+=1
print(dp[n])


Measured memory_bytes: 3864
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Diagnostics;
using static System.Math;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;

public static class P
{
    public static void Main()
    {
        var nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
        SegmentTree<long> segTree = new SegmentTree<long>(nm[0], 1L << 60, Min);
        
        segTree.Operate(0, 0);
        var ranges = Enumerable.Repeat(0, nm[1]).Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).ToArray();
        foreach (var item in ranges.OrderBy(x => x[0]))
            segTree.Operate(item[0] - 1, item[1] - 1, segTree[item[0] - 1] + item[2]);

        var res = segTree[nm[0] - 1];
        Console.WriteLine(res == (1L << 60) ? -1 : res);
    }
}


class SegmentTree<T>
{
    public readonly int Size;
    T[] Operators;
    Func<T, T, T> Merge;
    int LeafCount;
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public SegmentTree(int size, T identity, Func<T, T, T> merge)
    {
        Size = size;
        Merge = merge;
        LeafCount = 1;
        while (LeafCount < size) LeafCount <<= 1;
        Operators = new T[LeafCount << 1];
        for (int i = 0; i < Operators.Length; i++)
            Operators[i] = identity;
    }
    public T this[int index]
    {
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        get { return Query(index); }
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public void Operate(int i, T x) { Operators[i + LeafCount] = Merge(Operators[i], x); }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public void Operate(int l, int r, T x)
    {
        for (l += LeafCount, r += LeafCount; l <= r; l = (l + 1) >> 1, r = (r - 1) >> 1)
        {
            if ((l & 1) == 1) Operators[l] = Merge(Operators[l], x);
            if ((r & 1) == 0) Operators[r] = Merge(Operators[r], x);
        }
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public T Query(int i)
    {
        i += LeafCount;
        T res = Operators[i];
        while (0 < (i >>= 1)) res = Merge(res, Operators[i]);
        return res;
    }
}


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

int main() {
    int ans = 0;
    for (int i = 0; i < 5; i++) {
        int x;
        cin >> x;
        ans++;
        if (x == 0) {
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3564
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long int ll;

ll mod=1e9+7;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n,m; cin >> n >> m;
	vector<int> a(n),b(m);
	map<int,int> mp,mp2;
	for(int i=0;i<n;i++){
		cin >> a[i];
		if(mp[a[i]]){
			cout << 0 << endl;
			return 0;
		}
		mp[a[i]]++;
	}
	for(int i=0;i<m;i++){
		cin >> b[i];
		if(mp2[b[i]]){
			cout << 0 << endl;
			return 0;
		}
		mp2[b[i]]++;
	}
	ll ans=1;
	ll cnt=0,cnt2=0;
	for(int i=1;i<=n*m;i++){
		if(mp[i]&&mp2[i]){
			cnt++; cnt2++;
		}
		else if(mp[i]){
			ans*=(m-cnt);
			ans%=mod;
			cnt2++;
		}
		else if(mp2[i]){
			ans*=(n-cnt2);
			ans%=mod;
			cnt++;
		}
		else{
			ans*=((m-cnt)*(n-cnt2)-(n*m-i))%mod;
			ans%=mod;
		}
	}
	cout << ans << endl;
}

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


int main(){
  int n, t, a;
    cin >> n;
    cin >> t >> a;
 
    int h, ans;
    double diff, MIN = double(1e9);
    rep(i, n) {
        cin >> h;
        diff = abs(a - (t - h * 0.006));
        if (diff < MIN) {
            MIN = diff;
            ans = i + 1;
        }
    }
 
    cout << ans << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  int h, w, n;
  cin >> h >> w >> n;
  vector<vector<int>> walls(h + 2);
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    walls[x].push_back(y);
  }
  for (int i = 1; i <= w; i++) walls[h + 1].push_back(i);
  int right = 1;
  for (int i = 1; i <= h; i++) {
    sort(walls[i + 1].begin(), walls[i + 1].end());
    int ex = 1;
    for (int j : walls[i + 1]) {
      if (j <= right) {
        cout << i << endl;
        return 0;
      }
      if (right + 1 == j) ex = 0;
    }
    right += ex;
  }
  return 0;
}

Measured memory_bytes: 12412
n = int(input())
w = list(map(int, input().split()))

total = sum(w)

# accumerate w
for i, wi in enumerate(w):
    if i == 0:
        continue
    w[i] = w[i-1] + wi

diff = []
for i in range(n):
    diff.append(abs(total - 2 * w[i]))

print(min(diff))

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;


int main(){
    ll n,m;cin >>n>>m;
    vector <string> a(n);
    vector<string>b(m);
    for (int i = 0; i < n; ++i) {
        cin >>a[i];
    }
    for (int i = 0; i < m; ++i) {
        cin >>b[i];
    }
    bool flg=false;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            bool now=true;
            if(i+m>n)continue;
            if(j+m>n)continue;
            for (int k = 0; k < m; ++k) {
                if(a[j+k].substr(i,m)!=b[k])now=false;
            }
            if(now)flg=true;
        }
    }
    if(flg)puts("Yes");
    if(!flg)puts("No");
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		if((A+B)%2==0) {
			System.out.println((A+B)/2);
		}else {
			System.out.println("IMPOSSIBLE");
		}
	}
}


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

#define int ll
#define FOR(i, a, b) for (int i = (a), i##_cond = (b); i < i##_cond; ++i)
using ll = long long;

map<int, int> pf(int n) {
  map<int, int> res;
  FOR(i, 2, sqrt(n) + 1) {
    if (n == 1)
      break;
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1)
    res[n]++;
  return res;
}

// a以下の最大の三角数n
// すなわちn(n-1)/2 <= aとなる最大のn
int maximum_triangle(int a) {
  int tmp = sqrt(2 * a);
  if (a < tmp * (tmp + 1) / 2)
    return tmp - 1;
  else
    return tmp;
}

signed main() {
  int n;
  cin >> n;
  auto m = pf(n);

  int ans = 0;
  for (auto p : m) {
    ans += maximum_triangle(p.second);
  }
  cout << ans << endl;
}

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

#define pb push_back
#define mp make_pair
#define st first
#define nd second
typedef pair < int , int > pp;
const int mod = 1e9 + 7;
const int N   = 1e5 + 5;

map < int , int > M;
map < int , int > :: iterator it;
int n,i,x,ans;

int main(){
    cin >> n;
    for(i=1;i<=n;i++) { cin >> x; M[x]++; }
    for(it=M.begin(); it!=M.end(); it++){
        ans += it->nd - (it-> nd >= it->st ? it->st : 0);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 4736
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define sort(s) sort(s.begin(),s.end())
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<int>>
constexpr auto mod = 1000000007;


//2のn乗を求めるよ！！！
int ni(int n) {
	if (n == 0)return 1;
	int x = ni(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;
}

//フィボナッチ数列のx番目を求めるよ！
int f(int x, vector<int> s) {
	if (x == 0)return 0;
	if (x == 1)return 1;
	if (s[x] != 0)return s[x];
	s[x] = f(x - 1, s) + f(x - 2, s);
	return s[x];
}

//aとｂの最大公約数を求めるよ！
llint gcd(llint a, llint b) {
	if (a < b)swap(a, b);
	if (b == 0)return a;
	return gcd(b, a % b);
}



// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

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


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

//m進数のn桁を全列挙やで
void dfs(int m, int n) {

	stack<string> st;
	st.push("");
	while (!st.empty()) {
		string now = st.top();
		st.pop();
		if (now.size() == n) {
			cout << now << endl;
		}
		else {
			for (int i = m - 1; i >= 0; i--) {
				string next = now + to_string(i);
				st.push(next);
			}
		}
	}
}

int main() {
	int n;
	int sum = 0;
	cin >> n;
	hei(int) s(n);
	rep(i, 0, n) {
		cin >> s[i];
		sum += s[i];
	}

		sort(s);
		rep(i, 0, n) {
			if ((sum - s[i]) % 10 != 0&&(sum%10==0))sum -= s[i];
		}
		if (sum % 10 == 0)sum = 0;
	
	cout << sum << endl;



	return 0;
}

Measured memory_bytes: 256
def e(x,y):
 A[y][x]='0'
 for dx,dy in[[-3,0],[-2,0],[-1,0],[1,0],[2,0],[3,0],[0,-3],[0,-2],[0,-1],[0,1],[0,2],[0,3]]:
  if 0<=x+dx<8 and 0<=y+dy<8 and A[y+dy][x+dx]=='1':e(x+dx,y+dy)

for i in range(int(input())):
 print(f'Data {i+1}:')
 input()
 A=[list(input())for _ in[0]*8]
 e(int(input())-1,int(input())-1)
 for r in A:print(''.join(r))


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

int main(){
  int X,Y;
  cin >> X >> Y;
  int64_t ans=0;
  if(X==1){
    ans+=3*1e5;
  }else if(X==2){
    ans+=2*1e5;
  }else if(X==3){
    ans+=1e5;
  }
  if(Y==1){
    ans+=3*1e5;
  }else if(Y==2){
    ans+=2*1e5;
  }else if(Y==3){
    ans+=1e5;
  }
  if((X==1)&&(Y==1)){
    ans+=4*1e5;
  }
  cout << ans << endl;
}


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

int main(){
	int N;
	cin >> N;
	vector<int> p(N);
	for(int i = 0; i < N; i++){
		cin >> p[i];
	}
	
	int count = 0;
	
	for(int i = 1; i < N - 1; i++){
		int maxp = max(max(p[i - 1], p[i]), p[i + 1]);
		int minp = min(min(p[i - 1], p[i]), p[i + 1]);
		
		if(maxp != p[i] && minp != p[i]){
			count++;
		}
	}
	
	cout << count << endl;
}

Measured memory_bytes: 256
import string
strings = list(input())
uppers = string.ascii_uppercase
lowers = string.ascii_lowercase

for i in range(len(strings)):
    if strings[i] in uppers:
        strings[i] = str.lower(strings[i])
    elif strings[i] in lowers:
        strings[i] = str.upper(strings[i])

print(''.join(map(str, strings)))


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

#define all(X) (X).begin(), (X).end()
#define ll long long
#define linf (1ll << 60)

using namespace std;

// -------- FUNCS -------- //
vector<string> SPLIT(string str,char ch){vector<string> res;stringstream ss(str);string s;while(getline(ss, s, ch))res.push_back(s);return res;}
ll STOI(string str,int base){ll res=0;for(auto c:str){res*=base;res+=c-'0';}return res;}
string ITOS(ll val,int base){string res;while(val>0){res+='0'+(val%base);val/=base;}reverse(all(res));return res;}


// -------- Main Code -------- //
int n;
vector<ll> mem;
vector<ll> arr;
ll mod = 1e9+7;

ll pm(ll x, ll y, ll mod) {
    ll res = 1;
    x = x % mod;
    while (y > 0) {
        if ((y & 1) == 1) res = (res * x) % mod;
        y = y >> 1;
        x = (x * x) % mod;
    }
    return res;
}


ll dfs() {
    ll res = 0;
    
    ll sum = arr[n-1]; 
    for (int i=n-2; i>=0; i--) {
        ll t = sum * arr[i] % mod;
        sum += arr[i];
        sum %= mod;
        res += t;
        res %= mod;
    }

    return res;

    // ll sum = 0;
    // for (auto u: arr) {
    //     sum += u; 
    // }
    // ll sum_sq = pm(sum, 2, mod);
    // // cout << sum_sq << '\n';
    // ll res = sum_sq;
    // ll t = 0;
    // for (auto u : arr) {
    //     t += u * u;
    //     // if (res < t) {
    //     //     ll toAdd = t - res;
    //     //     res += ceil(1.0 * toAdd / mod) * mod;
    //     //     // res += mod;
    //     // } 
    //     // res -= t;
    //     t %= mod;
    // }
    // // cout << res << '\n';

    // return (res - t + mod) / 2; 
} 


void runcase() {
    cin >> n; 
    arr.resize(n, 0);
    for (auto& u : arr) cin >> u;
    sort(all(arr));
    ll res = dfs() % mod;
    cout << res << '\n';
    return;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    // int t;
    // cin >> t;
    // while (t-- > 0)
        runcase();
    return 0;
}


Measured memory_bytes: 4792
import sys
from pprint import pprint

mod = 10**9 + 7

def pow_r(x, n):
    """
    O(log n)
    """
    if n == 0:  # exit case
        return 1
    if n % 2 == 0:
        return pow_r(x ** 2, n // 2) % mod
    else:
        return (x * pow_r(x ** 2, (n - 1) // 2)) % mod


def solve(n, a):

    zero_count = [0] * 60
    for a_i in a:
        # binary = format(a_i, '060b')
        # for j, b_j in enumerate(binary):
        #    zero_count[j] += int(b_j)
        for j in range(61):
            if a_i >> j & 1:
                zero_count[j] += 1

    ans = 0
    # for i, count in enumerate(zero_count[::-1]):
    for i, count in enumerate(zero_count):
        # ans += (2**i) * (count * (n - count)) 
        ans += pow_r(2, i) * (count % mod) * ((n - count) % mod) 
        ans %= mod
    print(ans)

if __name__ == '__main__':
    n = int(sys.stdin.readline().strip())
    a = map(int, sys.stdin.readline().strip().split(" "))
    
    solve(n, a)

Measured memory_bytes: 116560
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        int [][]a=new int[3][3];
        for(int i=0;i<3;i++) {
            for (int j = 0; j < 3; j++) {
                a[i][j] = scanner.nextInt();
            }
        }

        int n=scanner.nextInt();
        while(n>0)
        {
           int x= scanner.nextInt();
            n--;
            for(int i=0;i<3;i++)
            {
                for(int j=0;j<3;j++)
                {
                    if(a[i][j]==x)a[i][j]=-1;
                }
            }
        }
        for(int i=0;i<3;i++)
        {
            int cnt=0;

            for(int j=0;j<3; j++)
            {
               if(a[i][j]==-1)cnt++;
            }
            if(cnt==3)
            {
                System.out.println("Yes");
                System.exit(0);
            }
            cnt=0;
            for(int j=0;j<3; j++)
            {
                if(a[j][i]==-1)cnt++;
            }
            if(cnt==3)
            {
                System.out.println("Yes");
                System.exit(0);
            }
        }
        if(a[0][0]==-1&&a[1][1]==-1&&a[2][2]==-1||a[0][2]==-1&&a[1][1]==-1&&a[2][0]==-1)
        {
            System.out.println("Yes");
            System.exit(0);
        }
        System.out.println("No");
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main(){
	char b;
	cin>>b;
	if(b=='A'){
		cout<<"T";
	}
	if(b=='G'){
		cout<<"C";
	}
	if(b=='T'){
		cout<<"A";
	}
	if(b=='C'){
		cout<<"G";
	}
} 

Measured memory_bytes: 256
#include <cstdlib>
#include <iostream>
#include <string>
#include <time.h>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
//#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,b) for(int i=(a);i<(b);++i)


#define huge 1000000007
typedef long long ll;

int main(void) {

	ll N = 0;
	ll A = 0;
	ll B = 0;
	ll K = 0;
	ll Y = 0;
	ll X = 0;
	ll x[100000] = {};
	//ll c[10000] = {};
	//ll d[10000] = {};
	//ll *x, *c, *d;
	//string w;
	ll count = 0;
	ll sum = 0;
	ll i = 0;
	cin >> N >> X;
	
	rep(i, 0, N) {
		cin >> x[i];
	}

	if (x[0] > X) {
		count += (x[0]) - X;
		x[0] -= count;
	}

	rep(i, 0, N-1) {
		

		if (x[i] + x[i + 1] > X) {
			count += (x[i] + x[i + 1]) - X;
			x[i + 1] -= (x[i] + x[i + 1]) - X;
		}
	}
	

	cout << count << endl;
	return 0;

}



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

int main() { 
long long  a,b; 
char c; 
scanf ("%lld %c %lld" , &a ,&c , &b); 

if (c == '+') { 
printf("%lld\n",a+b) ;
  }
else {

printf("%lld \n",a-b) ; 
}



return 0;
}

Measured memory_bytes: 256
def partition(a,p,r):
    x=a[r]
    i=p-1
    for j in range(p,r):
        if a[j]<=x:
            i+=1
            temp=a[i]
            a[i]=a[j]
            a[j]=temp
    temp=a[i+1]
    a[i+1]=a[r]
    a[r]=temp
    return i+1

n=int(input())
*a,=map(int,input().split())

ans=partition(a,0,n-1)
a=list(a)
a[ans]="["+str(a[ans])+"]"
print(*a)



Measured memory_bytes: 16392
#include <stdio.h>

int main()
{
	int x, y, flag[13] = {-1, 0, 1, 0, 2, 0, 2, 0, 0, 2, 0, 2, 0};
	scanf("%d %d", &x, &y);
	if (flag[x] == flag[y]) printf("Yes\n");
	else printf("No\n");
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1660
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int main()
{
    int n, x;
    cin >> n >> x;
    if (x == 1 || x == 2 * n - 1)
    {
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;

    vector<int> ans(2 * n - 1);
    for (int i = 0; n + i - 1 < 2 * n - 1; i += 2)
    {
        ans[n + i - 1] = (x + i - 1) % (2 * n - 1) + 1;
    }
    for (int i = 0; n - i - 1 >= 0; i += 2)
    {
        ans[n - i - 1] = (x - i - 1 + 2 * n - 1) % (2 * n - 1) + 1;
    }
    for (int i = 0; n + i < 2 * n - 1; i += 2)
    {
        ans[n + i] = (x - 1 - i - 1 + 2 * n - 1) % (2 * n - 1) + 1;
    }
    for (int i = 0; n - i >= 0; i += 2)
    {
        ans[n - i] = (x - 1 + i - 1 + 2 * n - 1) % (2 * n - 1) + 1;
    }

    rep(i, ans.size())
    {
        cout << ans[i] << endl;
    }
    return 0;
}

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

using namespace std;

int main(int argc, char *argv[]) {
    int64_t N, P;
    cin >> N >> P;

    vector<int64_t> v;
    map<int64_t, int64_t> m;
    int64_t i;

    if (N == 1) {
        // do nothing
    } else {
        for (i = 2; i * i <= P; i++) {
             while (P % i == 0) {
                if (m.count(i) > 0) {
                    m[i] += 1;
                } else {
                    m[i] = 1;
                }
                v.push_back(i); 
                P /= i;
             }
        }
    }

    if (P != 1) {
        v.push_back(P);
        if (m.count(P) > 0) {
            m[P] += 1;
        } else {
            m[P] = 1;
        }
    }

    int64_t ans = 1;
    for (auto p: m) {
        if (p.second < N) {
            continue;
        } else {
            ans *= static_cast<int64_t>(pow(p.first, (p.second / N)));
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
// Problem : A - Five Variables
// Contest : AtCoder - AtCoder Beginner Contest 170
// URL : https://atcoder.jp/contests/abc170/tasks/abc170_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<long,long> pl;
typedef pair<ll,ll> pll;
typedef vector<long> vl;
typedef vector<bool> vb;
typedef vector<ll> vll;
typedef vector<vl> vvl;
typedef vector<vb> vvb;
typedef vector<vll> vvll;
typedef vector<pll> vpll;
typedef vector<string> vs;

#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define REV(i,a,b) for(long long i=a;i>=b;i--)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define all(v) v.begin(),v.end()
#define tc ll tests;cin>>tests;while(tests--)
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define coutv(v) for(auto it: (v))cout<<it<<" ";newl;
#define cout2d(v) for(auto it: (v)) {for(auto j:it) cout<<j<<" ";newl;}
#define cinv(v,n) vll (v)(n);FOR(i,0,(n)){cin>>v[i];}
#define cinvg(v,n) (v).resize(n);FOR(i,0,(n)){cin>>v[i];}
#define cin2d(v,n,m) vvll (v)(n,vll(m,0));FOR(i,0,n){FOR(j,0,m){cin>>v[i][j];}}
#define cin2dg(v,n,m) (v).resize(n,vll(m));FOR(i,0,n){FOR(j,0,m){cin>>v[i][j];}}
#define newl cout<<"\n"
#define mod 1000000007
#define INF 1e18

int main()
{
	io;
	cinv(a,5)
	FOR(i,0,5)
	{
		if(a[i]==0){cout<<i+1;break;}
	}
	return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#define MOD 1000000007LL
using namespace std;

int main(){
	int n, l;
	cin >> n >> l;
	string s[n];
	for(int i = 0; i < n; i++){
		cin >> s[i];
	}
	string ans = "";
	for(int i = 0; i < n; i++){
		string max = "";
		int m = -1;
		for(int j = 0; j < n; j++){
			if(s[j].compare(max) > 0){
				m = j;
				max = s[j];
			}
		}
		ans = max + ans;
		s[m] = "";
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256