akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <sys/time.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> V;
#define F first
#define S second
#define mod 1000000007
const ll INF=3000000000000000000;
#define MAXN 200005
#define PI 3.1415926535897932384626433832795
#pragma GCC optimize ("Ofast")
static auto _ = [] { std::ios::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0); std::cerr.tie(0); return 0; } ();

ll power(ll x, ll y,ll p) 
{ 
    ll res = 1;
    while (y > 0) 
    {  
        if (y & 1) 
        res = (res*x)%p;  
        y = y>>1; 
        x = (x*x)%p;  
    } 
    return res; 
}
ll A,B,C,D;
map<ll,ll> mp;
ll rec(ll n){
    if(n<=0){
        return 0;
    }
    if(n==1){
        return D;
    }
    if(mp.find(n)!=mp.end()){
        return mp[n];
    }
    ll ans1,ans2,ans3,ans4;
    if(n%2==0){
        ans1 = A  + rec(n/2);
    }
    else{
        ans1 = min(A+D+rec((n+1)/2),A+D+rec((n-1)/2));
    }
    if(n%3==0){
        ans2 = B + rec(n/3);
    }
    else{
        ans2 = min(B + (n%3)*D + rec((n-(n%3))/3), B + (3 - n%3)*D + rec((n+(3-(n%3)))/3) );
    }
    if(n%5 == 0){
        ans3 = C + rec(n/5);
    }
    else{
        ans3 = min( C + (n%5)*D + rec((n-(n%5))/5), C + (5 - n%5)*D + rec((n+(5-(n%5)))/5));
    }
    ans4 = n*D;
    if(ans4<0){
        ans4 = 1e18;
    }
    ans1 = min(ans1,ans4);
    return mp[n]=min({ans1,ans2,ans3});
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll T=1,xp=1;
    cin>>T;
    while(T--)
    {
        struct timeval start, end; 
        ll i=0,h,j=0,n,x=0,y=0,m,l=0,k=0,r=0,o=0,cnt1=INT_MAX,cnt2=0,cnt3=INT_MIN,cnt4=0,min1=INT_MIN;
        gettimeofday(&start, NULL);
        
        cin>>n>>A>>B>>C>>D;
        ll ans = rec(n);
        cout<<ans<<endl;
        mp.clear();





        /*gettimeofday(&end, NULL); 
        double time_taken; 
      
        time_taken = (end.tv_sec - start.tv_sec) * 1e6; 
        time_taken = (time_taken + (end.tv_usec -  
                                  start.tv_usec)) * 1e-6; 
      
        cout << "Time taken by program is : " << fixed 
             << time_taken << setprecision(6); 
        cout << " sec" << endl; */
        xp++;
    } 

}       

Measured memory_bytes: 4436
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}
macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let mut x: u64 = sc.cin();
    let mut xs: Vec<u64> = sc.vec(n);
    xs.sort();
    let mut a = 0;
    for i in 0..n-1 {
        if xs[i] <= x {
            x -= xs[i];
            a += 1;
        }
    }
    if xs[n-1]==x{a+=1}
    put!(a);
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> { self.cin::<String>().chars().collect() }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> { (0..n).map(|_| self.cin()).collect() }
}


Measured memory_bytes: 4352
import numpy as np

if __name__=='__main__':
    N,K = map(int,input().split())
    hight = list( map(int,input().split()))
    hight = np.array(hight + [0]*(K+2))
    max_h = 10**9
    dp = [max_h]*(N+K+2)
    dp[0] = 0
    dp = np.array(dp)

    for i in range(N):
        a = hight[i]
        b = hight[i+1:i+K+1]
        np_abs = np.abs(b-a)
        dp[i+1:i+K+1] = np.minimum(np_abs+dp[i],dp[i+1:i+K+1])

        
    print(dp[N-1])

Measured memory_bytes: 22852
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  ll n,a,b;
  cin >> n >> a >> b;
  if(n==1&&a!=b){
    cout << 0 << endl;
  }
  else if(a>b){
    cout << 0 << endl;
  }
  else
    cout << (n-2)*(b-a)+1 << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <set>
#include <assert.h>
#include <sstream>
#include <string>
//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater <>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
using namespace std;
using ll = long long;
typedef std::pair<int,int> P;
#include <boost/multiprecision/cpp_int.hpp>
 
using bint = boost::multiprecision::cpp_int;



int main(){
    int n; cin >> n; vector<int> a(n); rep(i,n) cin >> a[i];
    int ans = 0;
    rep(i,n){
        rep(j,n){
            ans = max(ans,abs(a[i]-a[j]));
        }
    }
    cout << ans;
}

Measured memory_bytes: 256
# coding:utf-8

Black = "#"
White = "."

dir_x = [1, 0, -1, 0]
dir_y = [0, 1, 0, -1]


def main():
    H, W = map(int, input().split())
    step = 0
    count = W*H
    memo = [[-1]*W for i in range(H)]
    steplist = []

    for y in range(H):
        temp_in = input()
        for x in range(W):
            if temp_in[x] == Black:
                memo[y][x] = 0
                count -= 1
                steplist.append([y, x])

    while count > 0:
        step += 1
        next_list = []
        for l_yx in steplist:
            for i in range(4):
                temp_x = l_yx[1] + dir_x[i]
                temp_y = l_yx[0] + dir_y[i]
                if temp_x >= 0 and temp_x < W and temp_y >= 0 and temp_y < H:
                    if memo[temp_y][temp_x] < 0:
                        memo[temp_y][temp_x] = step
                        count -= 1
                        next_list.append([temp_y, temp_x])
        steplist = next_list
    print(step)


if __name__ == "__main__":
    main()


Measured memory_bytes: 137104
#include<bits/stdc++.h>
using namespace std;
int n, m;
int a, b, c;
int d[3];
int x ,y, w, h, r;
int p = 1;
int cnt = 0;
int main(){
    scanf("%d %d %d", &a, &b, &c);
    for(int i = a; i <= b; i++){
        if(c % i == 0) cnt++;
    }
    printf("%d\n", cnt);
    /*while(scanf("%d %d %d", &a, &b, &c), n||m){

    }*/
    return 0;
}


Measured memory_bytes: 3240
#include <iostream>
#include <string>
#include <cctype>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <vector>
typedef long long ll;
using namespace std;

int main(){
    string s; cin >> s;
    ll ans = 0;
    int len = s.length();
    for(int i = 0; i < (1 << (len-1)); i++){
        string t = "";
        for(int j = 0; j < len; j++){
            if(j){
                if(i&(1<<(j-1))){
                    ans += stoll(t); t = "";
                }
            }
            t += s[j];
        }
        ans += stoll(t);
    }
    cout << ans << endl;
    
  /*  for(int i = 0; i < 256; i++){
        cout << bitset<8>(i) << ": " << ((i & 16)? true : false) << endl;
    }*/
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
#define rep(i,a,b) for(register int i=(a);i<=(b);i++)
#define dep(i,a,b) for(register int i=(a);i>=(b);i--)
using namespace std;
#define maxn 100005
#define mod 1000000007
ll a,b,x,y,n,z;
char ch[maxn];
int main()
{
    scanf("%s",ch);
    n=strlen(ch);
    a=0;
    for(int i=0;i<n;i++)
    {
        if(ch[i]=='p') a++;
    }
    if(n/2-a>0)
    printf("%lld\n",n/2-a);
    else printf("0\n");
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
    using namespace std;
    int main()
    {
    	long long  n;
    	cin>>n;
    	long long i,j,sum=0;
    	for(i=1;i<=n;i++)
    	{
    		if(!(i%3==0 || i% 5==0))
    		{
    			sum+=i;
    		}
    	}
    	cout<<sum<<endl;
    	return 0;
    	
    }

Measured memory_bytes: 3640
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = (ll)(1e+9) + 7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int main() {
	int n; cin >> n;
	int id = 0;
	rep1(i, 1000) {
		if (i*(i + 1) / 2 == n) {
			id = i; break;
		}
	}
	if (!id) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
		cout << id + 1 << endl;
		vector<int> s[1000];
		int le = 1;
		per1(j, id) {
			rep(k, j) {
				s[id - j].push_back(le + k);
				s[id - j + k+1].push_back(le + k);
			}
			le += j;
		}
		rep(i, id + 1) {
			cout << id;
			rep(j, id) {
				cout << " " << s[i][j];
			}
			cout << endl;
		}
	}
	return 0;
}


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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

vvl G;
vb visited;
vl dist;
ll ans;

signed main()
{   
  gearup;
  ll n,m; cin >> n >> m;
  G.resize(n);
  rep(i,m){
    int a,b;cin>>a>>b;
    a--;b--;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
  }
  visited.resize(n);
  dist.resize(n,L_INF);
  queue<pair<int,int> > que;
  que.push({0,0});
  dist[0] = 0;
  vl dest(n);
  while(!que.empty()){
      int v = que.front().first;
      int co = que.front().second;
      que.pop();
      for(auto nv:G[v]){
          if(dist[nv] == L_INF){
              dist[nv] = co+1;
              dest[nv] = v;
              que.push({nv,co+1});
          }
      }
  }
  rep1(i,n){
      if(dist[i] == L_INF){
          out("No");
          return 0;
      }
  }
  rep1(i,n){
      if(dist[i] == L_INF){
          out("No");
          return 0;
      }
  }
  out("Yes");
  rep1(i,n)out(dest[i]+1);
}

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

using namespace std;

int main(){
  ios_base::sync_with_stdio(false);

  // int x, a, b;
  // cin >> x >> a >> b;
  //
  // if (abs(x - a) < abs(x - b))
  //   cout << "A\n";
  // else
  //   cout << "B\n";

  string s;
  cin >> s;

  for (char c = 'a'; c <= 'z'; c++){
    if (count(s.begin(), s.end(), c) == 0){
      cout << c << endl;
      return 0;
    }
  }

  cout << "None\n";

  return 0;
}


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

using ll = long long;

#define for_(i,a,b) for(int i = (a);i < (b);i++)
#define rfor_(i,a,b) for(int i = (b)-1;i >= (a);i--)
#define rep(i,n) for_(i,0,(n))
#define rrep(i,n) rfor_(i,0,(n))

int n;
int R[200002];

int main(){
	cin.tie(0);
	
	cin>>n;
	rep(i, n)cin>>R[i];
	
    int min = R[0], max = R[1] - R[0];
	for_(i, 1, n) {
        max = max < R[i] - min ? R[i] - min : max;
        min = min > R[i] ? R[i] : min;
	}
	
	cout<<max<<endl;
	
	return 0;
}



Measured memory_bytes: 3868
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define repm(i,a,b) for(ll i=(ll)(a);i>(ll)(b);i--)
#define all(v) v.begin(), v.end()
#define rall(x) (x).rbegin(),(x).rend()
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vc vector<char>
#define vvc vector<vc>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;
using vb =vector<bool>;
using vvb=vector<vb>;
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; }
//snippets:tmp,cl,cvl,cs,co,coy,con,cov,setp

int main(){
    ll a;
    cin >> a;
    ll v;
    cin >> v;
    ll b;
    cin >> b;
    ll w;
    cin >> w;
    ll t;
    cin >> t;
    if(a==b){
        cout << "YES" << endl;
        return 0;
    }
    if(w>=v){
        cout << "NO" << endl;
        return 0;
    }
    if((v-w)>(abs(a-b)-1)/t+1){
        cout << "YES" << endl;
        return 0;
    }
    if((v-w)*t>=abs(a-b)) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound

int main(){
  int N,L;
  cin>>N>>L;
  VL A(N);
  rep(i,N) cin>>A[i];
  int ans=-1;
  rep(i,N-1) if(A[i]+A[i+1]>=L){
    cout<<"Possible"<<endl;
    ans=i+1;
    break;
  }
  if(ans==-1){
    cout<<"Impossible"<<endl;
    return 0;
  }
  rep(i,ans-1) cout<<i+1<<endl;
  rep(i,N-1-ans) cout<<N-1-i<<endl;
  cout<<ans<<endl;
}

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

bool item_check(vector<string> item, string x){
    int i;
    for(i=0;i<item.size();i++){
      if(x==item.at(i)){return 1;
      break;}
    }
    return 0;
}

int main() {
  int M,N,i,j;
  cin>>N;
  vector<string> s(N);
  for(i=0;i<N;i++){
    cin>>s.at(i);
  }
  cin>>M;
  vector<string> t(M);
  for(i=0;i<M;i++){
    cin>>t.at(i);
  }
  int mscore=0;
  string x;
  vector<string> item;

  for(i=0;i<N;i++){
    x=s.at(i);
    int count1=0;
    if(i!=0){if(item_check(item,x))
      continue;}
    for(j=0;j<N;j++){
      if(x==s.at(j))count1++;
    }
    for(j=0;j<M;j++){
      if(x==t.at(j))count1--;
      if(count1<0){count1=0; break;}
    }
    if(mscore<count1)mscore=count1;
  }


  cout<<mscore<<endl;

}


Measured memory_bytes: 256
from operator import itemgetter

n = int(input())
s = [sorted(input()) for _ in range(n)]

# 2次元配列の文字を、左から優先にソート
s_sort = sorted(s, key = itemgetter(0, 1, 2, 3, 4, 5, 6, 7, 8, 9))

count = 0
s_count = 0

l = s_sort[0]

for i in range(1, n):
    if l == s_sort[i]:
        #同じ文字があるごとにカウントの数が増える（同じ文字が2つなら1個の組み合わせ、3つなら3つの組み合わせがある）
        s_count += 1
        count += s_count
    else:
        l = s_sort[i]
        s_count = 0

print(count)

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vull vector<ull>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e18)
#define PI (acos(-1))
#define EPS (1e-7)

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

int main(){
    int n;
    cin >> n;
    vi a(n+1);
    rep(i, n+1) cin >> a[i];
    if (n==0) {
        if (a[0] == 1) cout << 1 << endl;
        else cout << -1 << endl;
        return 0;
    }
    if (a[0] != 0) {
        cout << -1 << endl;
        return 0;
    }
    vll b2(n+1, 1);
    rep1(i, n) {
        b2[i] = (b2[i-1]*2<INF)?(b2[i-1]*2):INF;
    }
    vll b(n+2);
    repr(i, n+1) {
        b[i] = (b[i+1]+a[i]<=b2[i])?(b[i+1]+a[i]):b2[i];
    }
    ll ans = 1, now = 1;
    rep1(i, n) {
        now *= 2;
        now = min(now, b[i]);
        ans += now;
        now -= a[i];
        if ((i<n&&now<=0)||(i==n&&now<0)) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5104
#include <bits/stdc++.h>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;
using vecint = vector<int>;
using ll = int64_t;
constexpr ll INF = 1000000000;

using Edges = vector<int>;
using Graph = vector<Edges>;

void add_edge(Graph &g, int s, int t) {
  g[s].push_back(t);
  g[t].push_back(s);
}

void bfs(const Graph &g, vector<ll> &d, int s) {
  int n = g.size();
  queue<ll> q;
  q.push(s);
  d.assign(n, INF);
  d[s] = 0;
  while(!q.empty()) {
    ll i = q.front();
    q.pop();
    for (ll j : g[i]) {
      if (d[j] > d[i] + 1) {
        d[j] = d[i] + 1;
        q.push(j);
      }
    }
  }
}

void bfs2(const Graph &g, vector<ll> &dim, int s1, int s2) {
  int n = g.size();
  queue<ll> q;
  q.push(s1);
  q.push(s2);
  vector<ll> d(n, INF);
  d[s1] = 0;
  d[s2] = 0;
  while(!q.empty()) {
    ll i = q.front();
    q.pop();
    for (ll j : g[i]) {
      if (d[j] > d[i] + 1) {
        d[j] = d[i] + 1;
        q.push(j);
      }
    }
  }
  REP(i,n) dim[d[i]] = max(dim[d[i]], (ll)g[i].size()-1);
}

int main()
{
  ll n;
  cin>>n;
  Graph g(n);
  REP(i,n-1) {
    int a, b;
    cin>>a>>b;
    --a;--b;
    add_edge(g, a, b);
  }
  ll mx = 0;
  vector<ll> ecc(n, 0);
  REP(i,n) {
    vector<ll> dist(n);
    bfs(g, dist, i);
    REP(j,n) {
      ecc[j] = max(ecc[j], dist[j]);
      mx = max(mx, dist[j]);
    }
  }
  vector<ll> dim(n, 1);
  ll c = 0;
  REP(i,n) {
    if (ecc[i] != mx / 2) {
      dim[ecc[i]] = max(dim[ecc[i]], (ll)g[i].size()-1);
    } else {
      dim[ecc[i]] = max(dim[ecc[i]], (ll)g[i].size());
      c = i;
    }
  }
  ll mul = ((mx % 2) == 1) ? 2 : 1;
  REP(i,n) mul *= dim[i];
  if ((mx % 2) == 0) {
    for (ll i : g[c]) {
      vector<ll> dim2(n, 1);
      bfs2(g, dim2, c, i);
      ll mul2 = 2;
      REP(j,n) mul2 *= dim2[j];
      mul = min(mul, mul2);
    }
  }
  cout << mx / 2 + 1 << ' ' << mul << endl;
  return 0;
}


Measured memory_bytes: 256
from collections import deque

n = int(input())
w = list(map(int,input().split()))

d = deque(w)

s1 = d.popleft()
s2 = d.pop()

for _ in range(n-2):
	if s1 < s2:
		s1 += d.popleft()
	else:
		s2 += d.pop()

print(abs(s1 - s2))


Measured memory_bytes: 38640
#include<cstdio>
#include<iostream>

#define INF 1000000000

using namespace std;
 
int main(void){
 
    int n;
	int sco,sum;
	int max,min;

	while(1){
		cin>>n;
		if(n==0) break;
		min=INF,max=-1*INF;
		for(int i=0;i<n;i++){
			sum=0;
			for(int j=0;j<5;j++){
				cin>>sco;
				sum+=sco;
			}
			if(max<sum) max=sum;
			if(min>sum) min=sum;
		}
		cout<<max<<" "<<min<<endl;
	}

    return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int preT = 0;
		int preX = 0;
		int preY = 0;
		int N = sc.nextInt();
		boolean availableFlag = true;
		for(int i=0; i<N; i++) {
			int t = sc.nextInt();
			int x = sc.nextInt();
			int y = sc.nextInt();

			int difference = t - preT;
			int dist = Math.abs(x - preX) + Math.abs(y - preY);
			if(difference < dist || ((dist - difference) % 2 != 0)){
				availableFlag = false;
				break;
			}
			preT = t;
			preX = x;
			preY = y;
		}

		String result = availableFlag ? "Yes" : "No";
		System.out.println(result);

	}
}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
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;}

signed main(){
    int N,K;cin>>N>>K;

    rep(i,K){
        int x,y;
        cin>>x>>y;
        x--;y--;
        int mi=1001001001;
        chmin(mi,x);chmin(mi,y);
        chmin(mi,N-1-x);
        chmin(mi,N-1-y);

        cout<<mi%3+1<<endl;
    }
    return 0;
}

Measured memory_bytes: 1160
if __name__ == '__main__':
    from sys import stdin
    # from collections import defaultdict
    # from collections import deque
    # from collections import Counter
    # import numpy as np
    import math
    # import random
    input = stdin.readline

    a, b, h, m = map(int, input().split())

    total_minutes = 60*h + m
    h_degree = total_minutes*0.5
    m_degree = 6*m
    difference = h_degree - m_degree
    if difference > 180:
        difference = 360 - difference
    print((a**2+b**2-2*a*b*math.cos(math.radians(difference)))**0.5)


Measured memory_bytes: 9504
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

ans=0
for i in range(n):
    ans+=b[a[i]-1]
    if i!=n-1:
        if a[i+1]==a[i]+1:
            ans+=c[a[i]-1]
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int main(){
  ll n;cin>>n;
  string s;cin>>s;
  ll i,j;
  ll a[26];
  rep(i,26) a[i]=0;
  rep(i,n) a[s[i]-'a']++;
  ll ans=1;
  rep(i,26){
    ans*=a[i]+1;
    ans%=mod;
  }
  ans--;
  cout<<ans<<endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
  int n;
  cin>>n;
  string s;
  map<string,int> mp;
  while(n--)
  {
    cin>>s;
    mp[s]++;
  }
  cout<<"AC x "<<mp["AC"]<<"\n";
  cout<<"WA x "<<mp["WA"]<<"\n";
  cout<<"TLE x "<<mp["TLE"]<<"\n";
  cout<<"RE x "<<mp["RE"]<<"\n";
}


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

using namespace std;

string str[305];
int ans[305][305];
set<int>s;

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

    int i,j,n,m,k,r1,r2,c1,c2,cnt=1;
    cin>>n>>m>>k;
    for(i=0;i<n;i++)cin>>str[i];
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            if(str[i][j] == '#'){
                s.insert(i);
                break;
            }
        }
    }
    r1 = 0;c1 = 0;
    for(auto it=s.begin();it!=s.end();it++){
        while(true){
            r2 = *it;
            for(i=c1;i<m;i++){
                if(str[r2][i] == '#'){
                    c2=i;break;
                }
            }
            if(i == m)break;
            auto itr = it;itr++;
            if(itr==s.end())r2 = n-1;
            for(i=r1;i<=r2;i++){
                for(j=c1;j<=c2;j++)ans[i][j] = cnt;
            }
            cnt++;c1=c2+1;
        }
        cnt--;if(cnt==k)r2=n-1;
        for(i=r1;i<=r2;i++){
            for(j=c1;j<m;j++)ans[i][j] = cnt;
        }
        cnt++;
        r1 = r2+1;c1=0;
    }
    for(i=0;i<n;i++){
        for(j=0;j<m;j++)cout<<ans[i][j]<<' ';
        cout<<'\n';
    }
	return 0;
}


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

int main(void){
    long long k;
    cin >> k;
    long long n=50, tasu=k/n, sagasu=k%n, ans[50];
    for(int i=0;i<50;++i) ans[i]=i;
    for(int i=0;i<sagasu;++i){
        for(int j=0;j<50;++j){
            if(ans[j]<1) ans[j]+=n;
            else --ans[j];
        }
    }
    for(int i=0;i<50;++i) ans[i]+=tasu;
    cout << n << endl << ans[0];
    for(int i=1;i<50;++i){
        cout << " " <<ans[i];
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int pos[300][2];

int main()
{
  int n;
  pos [0][0] = 0;
  pos [0][1] = 0;

  int p,s;
  int t,b,l,r;

  cin >> n;
  while (n > 0)
    {
      t = b = l = r = 0;
      for (int i = 1; i < n; i++)
	{
	  cin >> p >> s;
	  switch(s)
	    {
	    case 0: 
	      pos[i][0] = pos[p][0] - 1;
	      pos[i][1] = pos[p][1];
	      break;
	    case 1:
	      pos[i][0] = pos[p][0];
	      pos[i][1] = pos[p][1] - 1;
	      break;
	    case 2:
	      pos[i][0] = pos[p][0] + 1;
	      pos[i][1] = pos[p][1];
	      break;
	    case 3:
	      pos[i][0] = pos[p][0];
	      pos[i][1] = pos[p][1] + 1;
	      break;
	    }
	  if (pos[i][0] > r) r = pos[i][0];
	  if (pos[i][0] < l) l = pos[i][0];
	  if (pos[i][1] > t) t = pos[i][1];
	  if (pos[i][1] < b) b = pos[i][1];
	}
      cout << r - l + 1 << " " << t - b + 1 << "\n";
      cin >> n;
    }

}

Measured memory_bytes: 1160
require 'pp'
# IS_DEBUG = true
IS_DEBUG = false
def dputs str
	if(IS_DEBUG)
		puts str
	end
end
def dpp str
	if(IS_DEBUG)
		pp str
	end
end

MAX_INT = 9999999999999999

a,b,c=gets.chomp.split(' ').map{|n| n.to_i}
if(a==b && b==c)
	case a%2
	when 0
		puts -1
	when 1
		puts 0
	end
	exit(0)
end
cnt = 0
while(a%2==0 && b%2==0 && c%2==0)
	atmp = a
	btmp = b
	ctmp = c
	a = (btmp+ctmp)/2
	b = (ctmp+atmp)/2
	c = (atmp+btmp)/2
	cnt += 1
end
puts cnt


Measured memory_bytes: 2172
n = int(input())
a = list(map(int,input().split()))
m = 1000
stocks = 0
drops = [False]*(n-1)
for i in range(n-1):
    if a[i] > a[i+1]:
        drops[i] = True
for i in range(n-1):
    if drops[i]:
        m+=stocks*a[i]
        stocks = 0
    else:
        stocks+=m//a[i]
        m -= (m//a[i])*a[i]
print(m + stocks*a[-1])

Measured memory_bytes: 61788
// #include <iostream>
// #include <vector>
// #include <unordered_map>
// #include <unordered_set>
// #include <algorithm>
// #include <numeric>
// #include <math.h>
// #include <utility>
#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;
// typedef vector<int> vi;
// typedef pair<int, int> pi;
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define MOD 1000000007
void solution() {
    ll n; cin >> n;
    vector<ll> d1(60);
    FOR (i, 0, n - 1) {
        ll a; cin >> a;
        
        FOR (j, 0, 59) {
            d1[j] += (a&1);
            a>>=1;
        }
    }
    ll sum = 0;
    ll base = 1;
    FOR (j, 0, 59) {
        sum = (sum + (((d1[j]*(n - d1[j]))%MOD)*(base % MOD))) % MOD;
        base*=2;
    }
    cout << sum << endl;
}

int main(int argc, char const *argv[])
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    solution();
    return 0;
}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

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

ll ans[111111];

int main(){
	
	ll n,q;cin >> n >> q;
	vector<ll> v(n);
	REP(i,n)cin >> v[i];
	vector<P> que(q);
	REP(i,q){
		cin >> que[i].FI;
		que[i].SE = i;
	}
	sort(ALL(que));
	
	if(n == 2){
		REP(i,q){
			cout << v[1] << endl;
		}
		return 0;
	}
	
	int l = 0;
	int r = n / 2 - 1;
	bool flag = false;
	if(n % 2 == 0)l++;
	else flag = true;
	ll now = 0;
	for(int i = r + 1;i < n;i++)now += v[i];
	
	REP(i,q){
		while(l <= r && r < n - 1 && abs(que[i].FI - v[l]) > abs(que[i].FI - v[r+1])) {
			if(flag){
				r++;now-=v[r];
				now+=v[l];l+=2;
				flag = false;
			}
			else{
				r++;now-=v[r];
				now+=v[l];l+=2;
			}
		}
		ans[que[i].SE] = now;
		//cout << l << " " << r << endl;
	}
	
	REP(i,q){
		cout << ans[i] << endl;
	}
			
			
	
	return 0;
}


Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, a, b) for (int i = a; i < b; i++)

int main(void) {
    long long N,K,Q;
    cin >> N >> K >> Q;
    long long winner[Q+2];
    repr(i,1,Q+1) cin >> winner[i];
    long long score[N+2];
    repr(i,1,N+1) score[i]=0;
    long long win;
    repr(i,1,Q+1){
        win = winner[i];
        score[win]++;
    }
    repr(i,1,N+1) score[i]=Q-score[i];

    repr(i,1,N+1){
        if(K-score[i]>0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 2176
#include <stdio.h>
#include <math.h>

double bmi[1000000];
double i[1000000], h[1000000], w[1000000];

int main(void)
{
  int n;
  int count;
  int a,b;
  double dumy = 0;
  int dumy2 = 0;

  while(1)
    {
      scanf("%d",&n);
      if(n == 0) break;
      
      for(count = 0 ; count < n ; count++)
	{
	  scanf("%lf %lf %lf",&i[count],&h[count],&w[count]);
	  
	  h[count] /= 100;
	  
	  bmi[count] = w[count] / (h[count] * h[count]);
	  bmi[count] -= 22.0;
	  bmi[count] = fabs(bmi[count]);
	}
      for(a = 0 ; a < n ; a++)
	{
	  for(b = a + 1 ; b < n ; b++)
	    {
	      if(bmi[a] > bmi[b])
		{
		  dumy = bmi[a];
		  dumy2 = i[a];
		  bmi[a] = bmi[b];
		  i[a] = i[b];
		  bmi[b] = dumy;
		  i[b] = dumy2;
		}
	    }
	}
      printf("%.0f\n",i[0]);
    }  
  return 0;
}

Measured memory_bytes: 0
n = int(input())
s = [0]*(n+1)

print(0)
a = input()
if a == "Vacant":
    exit()
s[0] = a
s[n] = a

l = 0
r = n
while True:
    m = (r+l)//2
    print(m)
    a = input()
    if a == "Vacant":
        exit()

    s[m] = a
    if s[l] == s[r]:
        if s[l] == s[m]:
            if (m-l) % 2 == 1:
                r = m
            else:
                l = m
        else:
            if (m-l) % 2 == 1:
                l = m
            else:
                r = m
    else:
        if s[l] == s[m]:
            if(m-l) % 2 == 1:
                r = m
            else:
                l = m
        else:
            if(m-l) % 2 == 1:
                l = m
            else:
                r = m


Measured memory_bytes: 4424
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

const int N = 100001;

int n, m, col[N];
vector <int> v[N];

int dfs(int node, int pnode){
    for(auto &i : v[node]){
        if(col[i] != -1){
            if(col[i] != (col[node] ^ 1)) return 1;
        }
        else{
            col[i] = col[node] ^ 1;
            int f = dfs(i, node);
            if(f == 1) return 1;
        }
    }
    return 0;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    memset(col, -1, sizeof col);
    cin >> n >> m;
    for(int i = 0 ; i < m ; i++){
        int x, y;
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    col[1] = 0;
    if(dfs(1, 0)) finish(1LL * n * (n - 1) / 2 - m);
    int r = 0, b = 0;
    for(int i = 1 ; i <= n ; i++){
        if(col[i] == 0) r++;
        else b++;
    }
    cout << 1LL * r * b - m << endl;
}


Measured memory_bytes: 9892
#include<bits/stdc++.h>
using namespace std;
int INF = 1e8;

struct edge{ int to,cap,rev; };
vector<edge> G[1000];
bool used[1000];

void add_edge(int from,int to,int cap){
  if(cap==0)return;
  G[from].push_back((edge){to,cap,(int)G[to].size()});
  G[to].push_back((edge){from,0,(int)G[from].size()-1});
}

int dfs(int v,int t,int f){
  if(v == t) return f;
  used[v] = true;
  for(int i = 0 ; i < (int)G[v].size() ; i++){
    edge &e = G[v][i];
    if(!used[e.to] && e.cap > 0){
      int d = dfs(e.to,t,min(f,e.cap));
      if(d > 0){
        e.cap -= d;
        G[e.to][e.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}
 
int max_flow(int s,int t){
  int flow = 0;
  for(;;){
    memset(used,false,sizeof(used));
    int f = dfs(s,t,INF);
    if(f == 0) return flow;
    flow += f;
  }
}

int A,B,C,D,BX,CX,DX;
int AB[500][500];
int BC[500][500];
int CD[500][500];

int main(){
  while(1){
    cin>>A>>B>>C>>D>>BX>>CX>>DX;
    if(A<0||B<0||C<0||D<0||BX<0||CX<0||DX<0)break;
    for(int i=0;i<1000;i++)G[i].clear();

    assert( A<=50 && B<=50 && C<=50 && D<=50 );
    assert( BX<=50 && CX<=50 && DX<=50 );
    
    memset(AB,0,sizeof(AB));
    memset(BC,0,sizeof(BC));
    memset(CD,0,sizeof(CD));
    
    for(int i=0;i<B;i++){
      int k,l;
      cin>>k;
      for(int j=0;j<k;j++){
        cin>>l;
        assert(1<=l && l<=A);
        l--;
        AB[l][i]=1;
      }
    }
    
    for(int i=0;i<C;i++){
      int k,l;
      cin>>k;
      for(int j=0;j<k;j++){
        cin>>l;
        assert(1<=l && l<=B);
        l--;
        BC[l][i]=1;
      }
    }
        
    for(int i=0;i<D;i++){
      int k,l;
      cin>>k;
      for(int j=0;j<k;j++){
        cin>>l;
        assert(1<=l && l<=C);
        l--;
        CD[l][i]=1;
      }
    }
    
    int si=A+B+C+D+BX+CX+DX;
    int ti=si+1;
    
    for(int i=0;i<A;i++){
      add_edge(si,i,1);
    }

    for(int i=0;i<A;i++){
      for(int j=0;j<B+BX;j++){
        int cap=AB[i][j];
        if(j>=B)cap=1;
        add_edge(i,A+j,cap);
      }
    }

    for(int i=0;i<B+BX;i++){
      add_edge(A+i,ti+A+i,1);
      for(int j=0;j<C+CX;j++){
        int cap=BC[i][j];
        if(i>=B||j>=C)cap=1;
        if(i>=B&&j>=C)cap=0;
        add_edge(ti+A+i,A+B+BX+j,cap);
      }
    }

    for(int i=0;i<C+CX;i++){
      add_edge(A+B+BX+i,ti+A+B+BX+i,1);
      for(int j=0;j<D+DX;j++){
        int cap=CD[i][j];
        if(i>=C||j>=D)cap=1;
        if(i>=C&&j>=D)cap=0;
        add_edge(ti+A+B+BX+i,A+B+BX+C+CX+j,cap);
      }
    }

    for(int i=0;i<D+DX;i++){
      add_edge(A+B+BX+C+CX+i,ti,1);
    }
    cout<< max_flow(si,ti) <<endl;
  }
  return 0;
}

Measured memory_bytes: 4984
#include <bits/stdc++.h>
using namespace std;
long long  MOD=1000000007;
long long  binary_exp(long long  a,long long  b)
{
  long long  ans=1;
  while(b>0)
  {
    if(b&1)
    {
      ans=(ans*a);
    }
    a=(a*a);
    b=b>>1;

  }
  return ans;
}

map<long long ,long long > mp;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);

  long long  T;
  T=1;
  while(T--)
  {
    int n;
    cin>>n;
    int k=n%1000;
    cout<<(1000-k)%1000<<endl;
  }
   return 0;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
const int MAXN = 4e5 + 10;
using namespace std;
inline int read() {
	char c = getchar(); int x = 0, f = 1;
	while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * f;
}
int N;
int a[MAXN], b[MAXN], ta[MAXN], tb[MAXN], sa, sb, tot = 0, date[MAXN], fa[MAXN];
map<int, bool> ti;
int find(int x) {
	return fa[x] == x ? fa[x] : fa[x] = find(fa[x]);
}
int unionn(int x, int y) {
	fa[x] = y;
}
int main() {
	N = read();
	for(int i = 1; i <= N; i++) a[i] = read(), sa ^= a[i]; a[N + 1] = sa;
	for(int i = 1; i <= N; i++) b[i] = read(), sb ^= b[i]; b[N + 1] = sb;
	N++;
	memcpy(ta, a, sizeof(a)); memcpy(tb, b, sizeof(b));
	sort(ta + 1, ta + N + 1); sort(tb + 1, tb + N + 1);
	for(int i = 1; i <= N - 1; i++) if(ta[i] != tb[i]) return puts("-1"), 0;

	int ans = 0, num = 0;
	for(int i = 1; i <= N; i++) 
		if(a[i] != b[i] || (i == N)) {
			date[++num] = a[i]; date[++num] = b[i];
			if(i < N)ans++;//最后一块单独考虑
		}
	if(ans == 0) return puts("0"), 0;

	sort(date + 1, date + num + 1);
	num = unique(date + 1, date + num + 1) - date - 1;
	for(int i = 1; i <= num; i++) fa[i] = i;
	for(int i = 1; i <= N; i++)
		if(a[i] != b[i]) {
			a[i] = lower_bound(date + 1, date + num + 1, a[i]) - date,
			b[i] = lower_bound(date + 1, date + num + 1, b[i]) - date;
			if(!ti[a[i]]) ti[a[i]] = 1;
			if(!ti[b[i]]) ti[b[i]] = 1;
			unionn(find(a[i]), find(b[i]));
		}
		
	for(int i = 1; i <= num; i++)
		if(fa[i] == i) ans++;
	printf("%d", ans - 1);

	return 0;
}

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//conversion
//------------------------------------------
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();}

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

typedef long long LL;
const LL mod=1000000007;
#define MAX 10000
#define NIL -1
const double PI  = acos(-1.0);
const int INF = 1e9 + 7;
//-------------------------------------------

int n;

int a,b;
int sum, dig;


int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    cin>>n;
/*

    if( n /10  * 10 == n ){
    a = n / 10;
    b = n -a;

    }
    else{

    }*/

/*
    while( a){
        if( a < 10){ break;}
        a = a /10;
        //dump(a);

    }

    while (b){
        if( b < 10){ break;}
        b = b/ 10;
*/
/*
while( n){
    if( n < 10){ break;}
    n = n /10;
    //dump(a);

}*/
    int s = n;

    while( s){
        if( s < 10 || s%10 != 0){ break;}
        s = s /10;
        //dump(a);
    }

    if( s == 1 ){


        cout << 10 << endl;
    }else{

        while(n){
        dig = n % 10;
        sum = sum + dig;
        n = n / 10;
        }

        cout << sum << endl;
    }







    return 0;
}


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

using namespace std;

typedef long long ll;

int main(){
  ll N,L; cin >> N >> L;
  if( 1 - N <= L && L <= 0){
    cout << N*(L-1) + (N*(N+1))/2 << endl;}
  else if( L > 0){
     cout << N*(L-1) + (N*(N+1))/2 - L << endl;}
  else if( L < ( 1 - N)){
    cout << N*(L-1) + (N*(N+1))/2  - ( L + N - 1) << endl;}
  
  return 0;}
   
 


Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

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

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        r: i64,
        g: i64
    }
    println!("{}", g * 2 - r);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
 


int main(){
  int n;
  string s;
  cin >> n >> s;
  int mx=0;
  rep(i,n-1){
    int cnt=0;
    rep(j,26){
       bool a=false;
        bool b=false;
      rep(k,n){
        if(k<=i){
			if(s.at(k)==char(j+'a'))a=true;
        }
		else if(i< k){
          if(s.at(k)==char(j+'a')) b=true;
        }
      }
        if(a && b) cnt++;
    }
    mx= max(mx,cnt);
  }
      cout << mx << endl;  
    
}

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

#define int long long
#define fi first
#define se second

int x, c=0;

int32_t main()
{	
	cin >> x;
	int h = 0;
	c = x%500;
	h += (x/500)*1000;
	c /= 5;
	h += c*5;
	cout << h << '\n';
}

Measured memory_bytes: 256
plus :: [Integer] -> Integer
plus [] = 0
plus (x:xs) = x + plus xs

mult :: [Integer] -> Integer
mult [] = 1
mult (x:xs) = x * mult xs

rect_area :: [Integer] -> Integer
rect_area xs = mult xs

rect_circumference :: [Integer] -> Integer
rect_circumference xs = plus xs * 2

strtoints :: [String] -> [Integer]
strtoints xs =  map read xs

intstostr :: [Integer] -> [String]
intstostr xs = map show xs


main = do
  str <- getLine
  putStrLn $ unwords $  intstostr (
                                   rect_area (strtoints (words str))
                                  : rect_circumference (strtoints (words str))
                                  : [])

Measured memory_bytes: 3576
n=int(input())
ans=[0]*(10**7)
for i in range(1,101):
  for j in range(1,101):
    for k in range(1,101):
      ans[(i**2+j**2+k**2+i*j+j*k+i*k)-1]+=1
for l in range(n):
  print(ans[l])

Measured memory_bytes: 87268
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b;
  cin >> a >>b;
  int ans =0;
  for(int i=a;i<=b;i++){
    string s = to_string(i);
    if( s.at(0) == s.at(4) && s.at(1)==s.at(3)){
      ans++;
    }
  }
  cout <<ans;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int ifcl(int p0[2],int p1[2],int p2[2],int p3[2]){
  long long x=p0[0],x0=p1[0]-x,x1=p2[0]-x,x2=p3[0]-x,x3=x2-x1,x4=x1-x0,x5=x2-x0;
  long long y=p0[1],y0=p1[1]-y,y1=p2[1]-y,y2=p3[1]-y,y3=y2-y1,y4=y1-y0,y5=y2-y0;
  long long c1=(x0*y1-y0*x1)*(x0*y2-y0*x2),c2=(x3*y4-y3*x4)*(x3*y1-y3*x1);
  long long d1=x1*x4+y1*y4,d2=x4*x5+y4*y5,d3=x2*x5+y2*y5,d4=x1*x2+y1*y2;
  return c1||c2?c1<=0&&c2<=0?1:0:d1>0&&d2>0&&d3>0&&d4>0?0:1;
}
int main(){
  int p[4][2],n,i;
  scanf("%d",&n);
  while(n--){
    for(i=0;i<8;i++)scanf(" %d",&p[i/2][i%2]);
    printf("%d\n",ifcl(p[0],p[1],p[2],p[3]));
  }
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
int main(void){
    std::deque<int> deq(200001,0);
    int n,k,a,count=0;;
    cin>>n>>k;
    for (int i=0;i<n;i++) {
        cin>>a;
        if (deq[a]==0) {
            count++;
        }
        deq[a]++;
    }
    sort(deq.begin(),deq.end());
    int ans=0;
    for (int j=0;j<deq.size();j++) {
        if (count<=k) {
            break;
        }
        if (deq[j]!=0) {
            count--;
            ans+=deq[j];
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>

using namespace std;
void printVec(std::vector<int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

int main() {
	int N; cin >> N;
	vector<int> a(N);
	cout << 3 * N * N;
	


	return 0;
}


Measured memory_bytes: 256