akhauriyash/Code-Regression huggingface dataset:
// ---------- begin chmin, chmax ----------
trait ChangeMinMax {
    fn chmin(&mut self, x: Self) -> bool;
    fn chmax(&mut self, x: Self) -> bool;
}

impl<T: PartialOrd> ChangeMinMax for T {
    fn chmin(&mut self, x: Self) -> bool {
        *self > x && {
            *self = x;
            true
        }
    }
    fn chmax(&mut self, x: Self) -> bool {
        *self < x && {
            *self = x;
            true
        }
    }
}
// ---------- end chmin, chmax ----------

use proconio::*;

fn run() {
    input! {
        n: usize,
        a: u64,
        b: u64,
        p: [usize; n],
    }
    let inf = 10u64.pow(9) * 5000 + 1;
    let mut dp = vec![inf; n + 1];
    dp[0] = 0;
    for p in p {
        let mut next = vec![inf; n + 1];
        next[p].chmin(*dp[..=p].iter().min().unwrap());
        for (next, dp) in next.iter_mut().zip(dp.iter()).take(p) {
            next.chmin(*dp + a);
        }
        for (next, dp) in next.iter_mut().zip(dp.iter()).skip(p + 1) {
            next.chmin(*dp + b);
        }
        dp = next;
    }
    let ans = dp.into_iter().min().unwrap();
    println!("{}", ans);
}

fn main() {
    run();
}


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

using namespace std;

int ans;
int n;
int grid[2][105];

void dfs(int x, int y, int have){
  if(x >= 2 || y >= n) return;
  if(x == 1 && y == n-1){
    have += grid[x][y];
    ans = max(have, ans);
    return;
  }
  have += grid[x][y];
  dfs(x+1, y, have);
  dfs(x, y+1, have);
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for(int i=0; i<2; i++){
    for(int j=0; j<n; j++){
      cin >> grid[i][j];
    }
  }
  dfs(0, 0, 0);
  cout << ans << endl;
  return 0;
}


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

int main()
{
  int N ;
  cin>>N ;
  int a[N] ;
  for(int i=0;i<N;i++) cin>>a[i] ;
  
  int sum=0 ;
  for(int i=0;i<N;i++){
    for(int j=0;;j++){
      if((a[i]%2)!=0){
        sum+=j ;
        break ;
      }else a[i]=a[i]/2 ;
    }
  }
  cout<<sum<<endl ;
  
  return 0 ;
}

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

int64_t gcd(int64_t m,int64_t n)
{
  if(m<n)
    std::swap(m,n);
  
  while(true)
  {
    int r=m%n;
    if(r==0)
      return n;
    m=n;
    n=r;
  }
}

int64_t lcm(int64_t m,int64_t n)
{
  return m*n/gcd(m,n);
}

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

  int64_t A,B,C,D;
  std::cin>>A>>B>>C>>D;

  auto f=[=](int64_t n)->int64_t
  {
    int64_t begin=A%n==0?A:(A/n+1)*n;
    if(begin>B)
      return 0;
    int64_t end=B%n==0?B:B/n*n;
    int64_t num=(end-begin)/n+1;

    return num;
  };

  int64_t numC=f(C);
  int64_t numD=f(D);
  int64_t numCD=f(lcm(C,D));

  int64_t result=(B-A+1)-(numC+numD-numCD);

  std::cout<<result<<std::endl;

  return 0;
}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//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())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code

int main(int argc, char const* argv[])
{
	int n;
	string s;
	cin >> n >> s;
	int num_change = 0;
	int ans = INT32_MAX;
	for (int i = 1; i < n; i++) {
		if (s[i] == 'E') {
			num_change++;
		}
	}
	ans = num_change;
	for (int i = 1; i < n; i++) {
		if (s[i-1] == 'W') {
			num_change++;
		}
		if (s[i] == 'E') {
			num_change--;
		}
		ans = min(num_change,ans);
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
    int k,x;
    cin >> k >> x;
    for(int i = x-k+1; i <= x+k-1; i++){
        cout << i;
        if(i == x+k-1){
            cout << endl;
        }else{
            cout << " ";
        }
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include<stack>
#include <functional>
#include <queue>
#include <regex>

using namespace std;

constexpr int MOD = 1000000007;
constexpr int INF = 1050000000;

#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl

#define Tof(x) (x) ? Yes : No
#define TOF(x) (x) ? YES : NO
#define tof(x) (x) ? yes : no

using ll = long long;


/*vectorの要素を全部確認するやつだよ。


for (vector<int>::iterator itr = ans.begin(); itr != ans.end(); ++itr) {
	cout << *itr << " ";
}


*/


/*for文でx,yを上下左右確認するやつだよ。

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


for (int i = 0; i < 4; i++) {
	int ny = y + dy[i];
	int nx = x + dx[i];
}
*/

/*繰り返し二乗法だよ。modもとってくれるよ。n^kをmodで割った余りでやってくれるよ。

ll POW_MOD(ll n, ll k, ll mod) {
	ll r = 1;

	for (; k > 0; k >>= 1) {
		if (k & 1) {
			r = (r * n) % mod;
		}
		n = (n * n) % mod;
	}
	return r;
}


*/

/*2重for文書くのめんどくなった時用だよ。

for (int i = 0; i < h; i++) {
	for (int j = 0; j < w; j++) {

	}
}

*/

int main(void) {
	int n, k; cin >> n >> k;

	cout << n - k + 1 << endl;















}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
 
public class  Main{
	public static void main(String[] args) throws Exception{
		MScanner sc=new MScanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		HashSet<Integer>nums=new HashSet<Integer>();
		nums.add(1);
		nums.add(2);
		nums.add(3);
		nums.remove(sc.nextInt());
		nums.remove(sc.nextInt());
		int z=0;
		
		for(int i:nums) {
			z=i;break;
		}
		pw.println(z);
		pw.flush();
	}
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] takearr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] takearrl(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public Integer[] takearrobj(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public Long[] takearrlobj(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

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

using namespace std;

int main(){
        ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(17);
	int a, b, c;
	cin >> a >> b >> c;
	cout << ((b - a == c - b) ? "YES\n" : "NO\n");	
	return 0;
}


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

int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int res = 0;
  for (int a = 0; a <= A; ++a) {
    for (int b = 0; b <= B; ++b) {
      for (int c = 0; c <= C; ++c) {
        int total = 500*a + 100*b + 50*c; // 合計金額
        if (total == X) ++res; // 合計金額が X に一致したら答えをインクリメント
      }
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstdlib>
#define INF 100000000
#define _INF -100000000
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> P;

string s;

bool unbalance(char a, char b, char c) {
	if (a == b || b == c || c == a) return true;
	else return false;
}

int main() {
	cin >> s;
	if (s.size() == 2) {
		if (s[0] == s[1]) cout << "1 2" << endl;
		else cout << "-1 -1" << endl;
	}
	else {
		bool judge = false;
		Loop(i, s.size() - 2) {
			if (unbalance(s[i], s[i + 1], s[i + 2])) {
				cout << i + 1<< " " << i + 3 << endl;
				judge = true;
				break;
			}
		}
		if (!judge) cout << "-1 -1" << endl;
	}
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<math.h>
#include<string>
#include<algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;

int main(){
    char a[5];
    int b=0;
    rep(i,4){
        cin>>a[i];
        if(a[i] == '2')++b;
    }
    cout<<b;
}

Measured memory_bytes: 256
sList, tList = input(), input()

dp = [[0] * (len(tList) + 1) for _ in range(len(sList)+1)]


# 横方向で回す
for i, s in enumerate(sList, start=1):
    for j, t in enumerate(tList, start=1):
        dp[i][j] = max([dp[i][j - 1], dp[i-1][j],
                        dp[i-1][j-1] + 1 if s == t else 0])
m = dp[i][j]
ans = ""
# traceback
cnt = 0
while i + j != 0:
    if dp[i - 1][j - 1] == m - 1 and tList[j-1] == sList[i-1]:
        ans = tList[j-1] + ans
        i -= 1
        j -= 1
        m -= 1
    else:
        if dp[i - 1][j] == m:
            i -= 1
        elif dp[i][j-1] == m:
            j -= 1
    cnt += 1
print(ans)


Measured memory_bytes: 113628
#from scipy.special import comb
#from math import factorial
 
S = input()
S1 = S[:int((len(S)-1)/2)]
S2 = S[int((len(S)+1)/2):]

if S == S[::-1]:
  if S1 == S1[::-1]:
    if S2 == S2[::-1]:
      print("Yes")
    else:
      print("No")
  else:
    print("No")
else:
  print("No")

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

int main() {
    int64_t q;
    cin >> q;
    vector<pair<int64_t, int64_t>> ab(q);
    for (auto& e : ab) cin >> e.first >> e.second;

    for (auto& e : ab) {
        double d = 2.0 * sqrt(e.first * e.second);
        if ((int64_t) d == d) {
            d -= 2;
            if (e.first != e.second) d--;
        } else {
            d = (int64_t) d - 2;
        }

        cout << (int64_t) d << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll      long long int
#define pii     pair<ll,ll>
#define vi      vector<ll>
#define mp      make_pair
#define pb      push_back
#define F       first
#define S       second
#define pf(n)   printf("%lld\n",n)
#define sf(n)   scanf("%lld",&n)
#define fast    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(x)  x.begin(),x.end()
#define ms(n,i) memset(n,i,sizeof n)
#define sz(x)   (ll)x.size()
#define pi      3.141592653589793238
#define hell    1000000007
#define hell2   1000000009
#define endl    '\n'
#define inf     1e18
#define N       100005

int main()
{
    ll n;
    cin>>n;
    ll i,j,k;
    vi a(n),dp(n);
    for(i=0;i<n;i++)
        cin>>a[i],dp[i]=inf;
    dp[0]=0;
    for(i=1;i<n;i++){
        if(i>1)dp[i]=min(dp[i],dp[i-2]+abs(a[i-2]-a[i]));
        dp[i]=min(dp[i],dp[i-1]+abs(a[i-1]-a[i]));
    }
    cout<<dp[n-1]<<endl;
}

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

struct UF{
    int par[200000];
    int rank[200000];
    
    void init(int n){
        for(int i=0;i<n;i++){
            par[i]=i;
            rank[i]=0;
        }
    }
    
    int find(int x){
        if(par[x]==x)return x;
        return par[x]=find(par[x]);
    }
    
    void unite(int x, int y){
        x=find(x);
        y=find(y);
        if(x!=y){
            if(rank[x]<rank[y]){
                par[x]=y;
            }else{
                par[y]=x;
                if(rank[x]==rank[y])rank[x]++;
            }
        }
    }
    
    bool same(int x, int y){
        return find(x)==find(y);
    }
};

int main(void){
    int n,m,a[52],b[52],c=0;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>a[i]>>b[i];
        a[i]--;
        b[i]--;
    }
    for(int i=0;i<m;i++){
        UF u;
        u.init(n);
        for(int j=0;j<m;j++){
            if(j!=i){
                u.unite(a[j],b[j]);
            }
        }
        bool f=false;
        for(int j=1;j<n;j++){
            if(!u.same(0,j))f=true;
        }
        if(f)c++;
    }
    cout<<c<<endl;
}


Measured memory_bytes: 256
n=int(input())
data=list(map(int,input().split()))

min=max=sum=data[0]
for i in range(1,n):
    if data[i]<min:
        min=data[i]
    if data[i]>max:
        max=data[i]
    
    sum+=data[i]


print(min,max,sum)


Measured memory_bytes: 6596
n,m=list(map(int,input().split()))
wa=[0 for _ in range(n)]
ac=[False for _ in range(n)]
for _ in range(m):
    p,s=input().split()
    p=int(p)-1
    if ac[p]:
        continue
    if s=="AC":
        ac[p]=True
    else:
        wa[p]+=1
ans=0
for i in range(n):
    if ac[i]:
        ans+=wa[i]
print(sum(ac),ans)


Measured memory_bytes: 4656
// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


void solve(std::string s, std::string t){
    int ans = MOD;
    for(int i = 0; i + t.size() <= s.size(); ++i){
        string k = s.substr(i, t.size());
        int cnt = 0;
        for(int j = 0; j < t.size(); ++j)
            cnt += (k[j] != t[j]);
        chmin(ans, cnt);
    }
    cout << ans << endl;
}


signed main(){
    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    solve(S, T);
    return 0;
}


Measured memory_bytes: 3616
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

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

    vector<ll> a(n),b(n);

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

    vector<pair<ll,ll>> v;
    for(int i = 0; i < n; i++){
        v.push_back(make_pair(a[i]+b[i],i));
    }

    sort(v.begin(),v.end(),greater<pair<ll,ll>>());

    ll asum = 0;
    ll bsum = 0;

    bool flag = true;

    for(int i = 0; i < n; i++){
        if(flag){
            asum += a[v[i].second];
        }else{
            bsum += b[v[i].second];
        }
        flag = !flag;
    }

    cout << asum - bsum << endl;
    
    return 0;
}

Measured memory_bytes: 3956
#include <cstdio>
#include <algorithm>
#include <functional>

typedef long long i64;

const int N = 300000 + 10;

int n, a[N];

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= 3 * n; ++i) scanf("%d", &a[i]);
  std::sort(a + 1, a + 3 * n + 1, std::greater<int>());
  i64 ans = 0;
  for (int i = 2, j = n; j--; i += 2) ans += a[i];
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <math.h>

using namespace std;

long long solve_odd(long long n) {
	int a[200000], b[200000];
	for (int i = 0; i < n; i++)
		cin >> a[i] >> b[i];
	sort(a, a + n);
	sort(b, b + n, greater<int>());
	cout << b[n / 2] - a[n / 2] + 1 << endl;
	return 0;
}

long long solve_even(long long n) {
	int a[200000], b[200000];
	for (int i = 0; i < n; i++)
		cin >> a[i] >> b[i];
	sort(a, a + n);
	sort(b, b + n, greater<int>());
	cout << b[n / 2] - a[n / 2] + b[n / 2 - 1] - a[n / 2 - 1] + 1 << endl;

	return 0;
}

int main() {
	long long n; cin >> n;
	if (n % 2 == 0)
		solve_even(n);
	else
		solve_odd(n);

	return 0;
}

Measured memory_bytes: 5164
#include <stack>
#include <queue>
#include <cstdio>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
 
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n0,n) for(int i=n0;i<n;i++)
#define Com(i,j,n) for(int i=0;i<n-1;i++)for(int j=i+1;j<n;j++)
#define INF (1<<29)
#define test cout << "test" << endl;
#define NNN_MAX 100010
typedef pair<int,int> P;

float abs(int a, int b){
	if(a>b) return a-b;
	else return b-a;
}

int main (){

	int NNN;
	cin >>NNN;
	int temp;
	vector <int> a;
	bool po[NNN];
	rep(i,NNN){
		cin >> temp;
		a.push_back(temp);
		po[i]=true;
	}
	if(NNN==2){
		cout << a[0] << " " << a[1] << endl;
		return 0;
	}
	//NNN>2

	sort(a.begin(),a.end(),greater<int>());
	int max=a[0];

	unique(a.begin(),a.end());
	if(a.size()==1){
		cout << a[0] <<" " << a[0] << endl;
	}

	//maxの半分に一番近い数字を探そう
	int temp1,temp2;
	int pointer=0;
	int halfmax = (max+max%2)/2;


	//最初に真ん中にポインターを置く
	pointer=(a.size()-a.size()%2)/2; 

	int count =1;
	//終了条件 = abs(a[pointer-1],max/2)
	while(1){
		
		//po[pointer]=false;
		//丁度半分、0にきちゃった、上から2番めのところまで来ちゃった
		if(a[pointer]==halfmax){
			break;
		}
		if(pointer <= 0){
			if(abs(halfmax,a[0])>=abs(halfmax,a[1])){
				pointer =1;
				break;
			}
			else {
				pointer =0;
				break;
			}
		}
		if(pointer == a.size()-1){
			if(abs(halfmax,a[pointer])>=abs(halfmax,a[pointer-1])){
				pointer --;
				break;
			}
			else {
				break;
			}
		}

		//前後が今よりも悪くなる＝今が最適
		if(abs(a[pointer],halfmax)<=abs(a[pointer-1],halfmax) && abs(a[pointer],halfmax)<=abs(a[pointer+1],halfmax)){
			break;
		}

		if(a[pointer] < halfmax){
			count ++;
			pointer = pointer - floor(a.size()/pow(2,count))-2;
		}
		if(a[pointer] > halfmax){
			count ++;
			pointer = pointer + floor(a.size()/pow(2,count))+1;
		}



	}

	cout << a[0] << " " << a[pointer] << endl;

	return 0;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
#define Rint register int
#define MP make_pair
#define fi first
#define se second
#define PB push_back
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const int G = 5, N = 1 << 19, mod = 200003;
const double PI = acos(-1);
template<typename T>
void read(T &x){
	int ch = getchar(); x = 0; bool f = false;
	for(;ch < '0' || ch > '9';ch = getchar()) f |= ch == '-';
	for(;ch >= '0' && ch <= '9';ch = getchar()) x = x * 10 + ch - '0';
	if(f) x = -x;
}
void qmo(int &x){x += (x >> 31) & mod;}
int ksm(int a, int b){
	int res = 1;
	for(;b;b >>= 1, a = (LL) a * a % mod) if(b & 1) res = (LL) res * a % mod;
	return res;
}
template<typename T>
inline bool chmax(T &a, const T &b){if(a < b) return a = b, 1; return 0;}
template<typename T>
inline bool chmin(T &a, const T &b){if(a > b) return a = b, 1; return 0;}
int n, a[mod], pre[mod], rev[N], lim; LL ans, b[mod];
struct comp {
	double x, y;
	comp(double _x = 0, double _y = 0): x(_x), y(_y){}
	comp operator + (const comp &o) const {return comp(x + o.x, y + o.y);}
	comp operator - (const comp &o) const {return comp(x - o.x, y - o.y);}
	comp operator * (const comp &o) const {return comp(x * o.x - y * o.y, x * o.y + y * o.x);}
	comp operator * (const double &o) const {return comp(x * o, y * o);}
	comp operator / (const double &o) const {return comp(x / o, y / o);}
	comp operator = (const comp &o){x = o.x; y = o.y; return *this;}
	comp operator ~ () const {return comp(x, -y);}
} w[2][N], A[N];
void calrev(int len){
	int L = -1; lim = 1;
	while(lim <= len){++ L; lim <<= 1;}
	for(Rint i = 0;i < lim;++ i) rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << L);
	for(Rint mid = 1;mid < lim;mid <<= 1){
		w[0][mid] = w[1][mid] = 1;
		for(Rint i = 1;i < mid;++ i) w[0][mid + i] = comp(cos(PI / mid * i), sin(PI / mid * i));
		for(Rint i = 1;i < mid;++ i) w[1][mid + i] = ~w[0][mid + i];
	}
}
void FFT(comp *A, int op){
	for(Rint i = 0;i < lim;++ i)
		if(i < rev[i]) swap(A[i], A[rev[i]]);
	for(Rint mid = 1;mid < lim;mid <<= 1)
		for(Rint j = 0;j < lim;j += mid << 1)
			for(Rint k = 0;k < mid;++ k){
				comp y = w[op][mid + k] * A[j + k + mid];
				A[j + k + mid] = A[j + k] - y; A[j + k] = A[j + k] + y;
			}
	if(op) for(Rint i = 0;i < lim;++ i) A[i] = A[i] / lim;
}
int main(){
	for(Rint i = 0, x = 1;i < mod - 1;++ i, x = x * G % mod) pre[x] = i;
	read(n);
	for(Rint i = 1, x;i <= n;++ i){
		read(a[i]); if(a[i]) ++ b[pre[a[i]]];
	}
	calrev(mod-2<<1);
	for(Rint i = 0;i < mod - 1;++ i) A[i].x = b[i], b[i] = 0;
	FFT(A, 0);
	for(Rint i = 0;i < lim;++ i)
		A[i] = A[i] * A[i];
	FFT(A, 1);
	for(Rint i = 0;i < lim;++ i)
		b[i % (mod - 1)] += (LL) (A[i].x + 0.5);
	for(Rint i = 0, x = 1;i < mod - 1;++ i, x = x * G % mod) ans += b[i] * x;
	for(Rint i = 1;i <= n;++ i) ans -= (LL) a[i] * a[i] % mod;
	printf("%lld\n", ans >> 1);
}

Measured memory_bytes: 33808
#include <iostream>
#define N 1000000 
using  namespace std;

int main(void){
	bool isprime[N+1];
	for(int i=0;i<=N;i++)
		isprime[i]=true;
	isprime[0]=isprime[1]=false;
	for(int i=2;i<=N;i++)
		if(isprime[i])
			for(int j=2*i;j<=N;j+=i)
				isprime[j]=false;
	bool budget[N+1];
	int n,m;
	while(cin >> n>>m,n|m){
		for(int i=0;i<=m;i++)
			budget[i]=false;
		int tmp;
		budget[0]=true;
		for(int i=0;i<n;i++){
			cin >> tmp;
			for(int j=0;j<=m;j++)
				if(budget[j]&&(j+tmp)<=m)
					budget[j+tmp]=true;
		}
		int MAX=0;
		for(int i=m;i>0;i--){
			if(budget[i]&isprime[i]){
				MAX=i;break;
			}
		}
		if(MAX)
			cout << MAX << endl;
		else
			cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 3112
//{{{
#include <bits/stdc++.h>
using namespace std;
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop,~))(__VA_ARGS__)
#define loop(n) rep2(_loop_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define repN(a) repX a
#define repX(a0,a1,a2,x,...) x
#define foreach(x,a) for(auto &x:a)
typedef long long ll;
const int MOD = 1e9+7;
//}}}

int main(){
  int A, B, X;
  cin >> A >> B >> X;
  bool ans = (A <= X && X <= A + B);
  puts(ans ? "YES" : "NO");
  return 0;
}


Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


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

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll;
typedef vector<vector<long long> > vvll;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i,n) _rep2((i),0,(n))
#define _rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define fi first
#define se second
#define mkp make_pair
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

vvint vv;
bool f = false;
vint c;


void dfs(int x, int e, int p){
	if(c[x]>=0){
		if(c[x]!=e) f=true;
		return;
	}
	c[x] = e;
	for(int y: vv[x]){
		if(y == p) continue;
		dfs(y, 1-e, x);
	}
}

void mainmain(){
	int n,m;
	cin>>n>>m;
	vv = vvint(n);
	c = vint(n,-1);
	rep(i,m){
		int a,b;
		cin>>a>>b;
		a--,b--;
		vv[a].PB(b);
		vv[b].PB(a);
	}
	dfs(0,0,-1);
	if(f){
		ll cnt = 1LL*n*(n-1)/2;
		cout<<cnt-m<<endl;
	}
	else{
		ll a = 0;
		ll b = 0;
		rep(i,n){
			if(c[i]==1) a++;
			else b++;
		}
		// assert(0);
		// cout<<a<<" "<<b<<endl;
		ll cnt = a*b;
		cout<<cnt-m<<endl;
	}
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

Measured memory_bytes: 6784
#include <iostream>
#include <stdio.h>

void print_array(int n, int* a)
{
    for (int i = 0; i < n; i++) {
        std::cout << a[i];
        if (i != n - 1) {
            std::cout << " ";
        }
    }
    std::cout << std::endl;
}


int main()
{
    int number;
    std::cin >> number;

    int array[number];
    for (int i = 0; i < number; i++) {
        std::cin >> array[i];
    }

    for (int i = 1; i < number; i++) {
        print_array(number, array);
        int key = array[i];
        int j = i - 1;
        while (j >= 0 && array[j] > key) {
            array[j + 1] = array[j];
            j--;
        }
        array[j + 1] = key;
    }
    print_array(number, array);
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ios                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define fill(x, v) memset(x, v, sizeof(x))
const ll mod = 1000000007;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1)
{
    cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args)
{
    const char *comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
/*
std::cout << std::setprecision(9) << f << '\n';//3.141590000;
map<char,int>::reverse_iterator rit;
*/
// --------dsu-- --------

//-----------------------------

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    int f = 0;
    int ans = 0;
    while (1)
    {
        if (f == 0)
        {
            c -= b;
            if (c <= 0)
            {
                ans = 1;
                break;
            }
        }
        else
        {
            a -= d;
            if (a <= 0)
            {
                ans = 2;
                break;
            }
        }

        f = 1 - f;
        if (ans == 1 || ans == 2)
            break;
    }
    if (ans == 1)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > > 
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N , K ;
    cin >> N >> K ;
    
    ll idx = -1;
    rep(i, N){
        ll inp; cin >> inp;
        if(inp == 1) idx = i;
    }
    
    ll l = idx;
    ll r = (N-1) - idx;
    
    
    ll ans = (l / (K-1)) + (r / (K-1));
    l %= (K-1);
    r %= (K-1);

    cerr << "l" << l << endl;
    cerr << "r" << r << endl;
    cerr << "ans" << ans << endl;
    if((l + r) != 0) {
        if( (l+r) <= (K-1)) ans ++;
        else ans += 2;
    }
    
    cout << ans << endl;
    
    
    
    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 256
//Toll Gates

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a / __gcd(a, b) * b
#define range(a) (a).begin(),(a).end()
const int inf = 2147483647;

int main (){
    int N,M,X;cin>>N>>M>>X;
    vector<int> A(M);
    rep(i,0,M)cin>>A[i];
    int a=0,b=0;
    rep(i,0,M){
        if(A[i]<X)a++;
        else b++;
    }
    cout << min(a,b) << endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
A = LIST(N)
A2 = sorted(A)

# 元の列とソート済それぞれの位置の偶奇を集める
A_mod = {}
A2_mod = {}
for i in range(N):
    A_mod[A[i]] = i % 2
    A2_mod[A2[i]] = i % 2

cnt = 0
for k, v in A_mod.items():
    # 位置の偶奇の合わない所は操作1を使うことになる
    if v != A2_mod[k]:
        cnt += 1
print(cnt//2)


Measured memory_bytes: 24396
import java.util.Scanner;

public class Main {
	
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		String str1 = sc.next();
		String str2 = sc.next();
		String str3 = sc.next();
		
		String str2f = str2.substring(0, 1);
		str3 = str3.substring(0, 1);
		
		if(str1.endsWith(str2f) && str2.endsWith(str3)){
			System.out.println("YES");
		}
		else{
			System.out.println("NO");
		}
	  }
	}

Measured memory_bytes: 23892
#include <iostream>
#include <vector>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
using namespace  std;

const double cos60 = cos(M_PI / 3);
const double sin60 = sin(M_PI / 3);

struct StPnt
{
  double m_nx;
  double m_ny;

  StPnt() :
    m_nx(0), m_ny(0)
  { }
  StPnt(double nx, double ny) :
    m_nx(nx), m_ny(ny)
  { }

  ~StPnt() { }
};

void fnInput(int &rnRcSiz)
{
  cin >> rnRcSiz;
}

void fnKochCrv( const StPnt &cnroPnt1, const StPnt &cnroPnt2, vector<StPnt> &rvoRtnPnt)
{
  rvoRtnPnt[0] = cnroPnt1;
  rvoRtnPnt[1].m_nx = (2 * cnroPnt1.m_nx + cnroPnt2.m_nx) / 3;
  rvoRtnPnt[1].m_ny = (2 * cnroPnt1.m_ny + cnroPnt2.m_ny) / 3;
  rvoRtnPnt[3].m_nx = (cnroPnt1.m_nx + 2 * cnroPnt2.m_nx) / 3;
  rvoRtnPnt[3].m_ny = (cnroPnt1.m_ny + 2 * cnroPnt2.m_ny) / 3;

  rvoRtnPnt[2].m_nx =  (rvoRtnPnt[3].m_nx - rvoRtnPnt[1].m_nx) * cos60 
                     - (rvoRtnPnt[3].m_ny - rvoRtnPnt[1].m_ny) * sin60 + rvoRtnPnt[1].m_nx;
  rvoRtnPnt[2].m_ny =  (rvoRtnPnt[3].m_nx - rvoRtnPnt[1].m_nx) * sin60 
                     + (rvoRtnPnt[3].m_ny - rvoRtnPnt[1].m_ny) * cos60 + rvoRtnPnt[1].m_ny;

  rvoRtnPnt[4] = cnroPnt2;
}

void fnKochCtl(int nRcSiz, vector<vector<StPnt>> &rvvoPnt)
{
  StPnt oPntB(0.0, 0.0);
  StPnt oPntE(100.0, 0.0);

  rvvoPnt.resize(7);
  rvvoPnt[0].clear();
  rvvoPnt[0].push_back(oPntB);
  rvvoPnt[0].push_back(oPntE);

  for (int nRc = 0; nRc < nRcSiz; nRc++)
  {
    rvvoPnt[nRc + 1].clear();
    rvvoPnt[nRc + 1].push_back(oPntB);
    for (int i = 0; i < rvvoPnt[nRc].size() - 1; i++)
    {
      StPnt oPnt1 = rvvoPnt[nRc][i];
      StPnt oPnt2 = rvvoPnt[nRc][i + 1];
      vector<StPnt> voRtnPnt(5);

      fnKochCrv(oPnt1, oPnt2, voRtnPnt);
      for (int j = 1; j < 5; j++)
        rvvoPnt[nRc + 1].push_back(voRtnPnt[j]);
    }
  }
}

void fnResult(int nRcSiz, const vector<vector<StPnt>> &cnrvvoPnt)
{
  for (int i = 0; i < cnrvvoPnt[nRcSiz].size(); i++)
    cout << cnrvvoPnt[nRcSiz][i].m_nx << " " << cnrvvoPnt[nRcSiz][i].m_ny << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(8);

  int nRcSiz;
  vector<vector<StPnt>> vvoPnt;

  fnInput(nRcSiz);
  fnKochCtl(nRcSiz, vvoPnt);

  fnResult(nRcSiz, vvoPnt);

  return 0;
}

Measured memory_bytes: 1392
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define EPS (1e-15)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define bet(x, a, b) (a) <= (x) && (x) < (b)
typedef long long ll;
typedef unsigned long long ull;

int A[100000];
int B[100000];

int main()
{
	int N, ans = 0;
	ll lack = 0;
	priority_queue<int> pq;

	cin >> N;
	rep(i, N) cin >> A[i];
	rep(i, N) cin >> B[i];

	rep(i, N) {
		if (A[i] < B[i]) {
			ans++;
			lack += B[i] - A[i];
		}
		else {
			pq.push(A[i] - B[i]);
		}
	}

	while (!pq.empty() && lack > 0) {
		lack -= pq.top(); pq.pop();
		ans++;
	}

	if (lack > 0) ans = -1;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1660
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func main() {
	sc.Split(bufio.ScanWords)
	N := getInt()
	x := make([]int, N)
	y := make([]int, N)
	for i := 0; i < N; i++ {
		x[i] = getInt()
		y[i] = x[i]
	}
	sort.Ints(x)

	for i := 0; i < N; i++ {
		if y[i] < x[N/2] {
			out(x[N/2])
		} else {
			out(x[N/2-1])
		}
	}
}


Measured memory_bytes: 10132
import java.util.Scanner;
    
    public class Main{
    public static void main(String args[]){
    	int N = 0;
    	int S=0;
    	int E=0;
    	int W=0;
        String st;
        char[] D = new char[10001];
    Scanner scan = new Scanner(System.in);
    
    st = scan.next();
    D = st.toCharArray();
    
    for(int i=0;i<st.length();i++){
    	switch(D[i]){
    	case 'N':
    		N++;
    		break;
    	case 'S':
    		S++;
    		break;
    	case 'E':
    		E++;
    		break;
    	case 'W':
    		W++;
    		break;
    	}
    }
    	
    	if(N>0 && S>0){
    		if(E*W==0 && E+W>0){
    			System.out.println("No");
    			return;
    		}else{
    			System.out.println("Yes");
    			return;
    		}
    	}
    	
    	if(E>0 && W>0){
    		if(N*S==0 && N+S>0){
    			System.out.println("No");
    			return;
    		}else{
    			System.out.println("Yes");
    			return;
    		}
    	}
    	System.out.println("No");
    		
    }
    
}

Measured memory_bytes: 9940
N = int(input())
A = input().split()


count = 0
while True:
    flag = True
    for i in range(N):
        Ai = int(A[i])
        if Ai % 2 != 0:
            flag = False
            break
        A[i] = Ai / 2
        
    if flag == False:
        break
    count += 1

print(count)
    
        


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

#define int long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#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;}

struct BIT{
    int N;
    vint dat;
    void init(int n){
        N=n;
        dat.resize(N+1);
    }
    void add(int k,int x){
        for(k++;k<=N;k+=k&-k)dat[k]+=x;
    }
    int sum(int k){
        int ret=0;
        for(k++;k;k-=k&-k)ret+=dat[k];
        return ret;
    }
};

int N,C;
int type[100000],t[100000],p[100000];

int sum[100000];

signed main(){
    cin>>N>>C;
    rep(i,C){
        cin>>type[i]>>t[i];
        if(type[i]==0)cin>>p[i],t[i]--;
    }

    vector<pint>vec;
    rep(i,N)vec.pb(pint(0,-i));

    rep(i,C){
        if(type[i]==0){
            sum[t[i]]+=p[i];
            vec.pb(pint(sum[t[i]],-t[i]));
        }
    }

    sort(all(vec));
    vec.erase(unique(all(vec)),vec.end());

    BIT bit;bit.init(vec.size()+114);
    rep(i,N){
        bit.add(i,1);
    }

    memset(sum,0,sizeof(sum));
    rep(i,C){
        if(type[i]==0){
            int l=lower_bound(all(vec),pint(sum[t[i]],-t[i]))-vec.begin();
            bit.add(l,-1);
            sum[t[i]]+=p[i];
            l=lower_bound(all(vec),pint(sum[t[i]],-t[i]))-vec.begin();
            bit.add(l,1);
        }
        else{
            int lb=-1,ub=vec.size();
            t[i]=N-t[i]+1;
            while(ub-lb>1){
                int mid=(ub+lb)/2;
                if(bit.sum(mid)<t[i])lb=mid;
                else ub=mid;
            }
            cout<<-vec[ub].se+1<<" "<<vec[ub].fi<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 10612
#include <stdio.h>
int main(void){
    int a, b, c, d, i, j;
    int p[1000];
	scanf("%d%d", &a, &b);
	c = 0;
	for(i = 0; i < a; i++){
		scanf("%d", &p[i]);
	}
	for(i = 0; i < a - 1; i++){
		for(j = i + 1; j < a; j++){
			if(p[i] >= p[j]){
				d = p[i];
				p[i] = p[j];
				p[j] = d;
			}
		}
	}
	for(i = 0; i < b; i++){
		c = c + p[i];
	}
	printf("%d\n", c);
    
}


Measured memory_bytes: 1704
N, M = [int(_) for _ in input().split()]

Lmax, Rmin = 1, N
for i in range(M):
     L, R = [int(_) for _ in input().split()]
     Lmax = max(Lmax, L)
     Rmin = min(Rmin, R)

print(max(0, Rmin - Lmax + 1))


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

int main() {
  long long A, B;

  cin>>A>>B;
  if(A%2!=B%2){
    cout << "IMPOSSIBLE" << endl;
  }else{
   cout << (A + B) / 2 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define ALL(n) begin(n),end(n)
#define IN(a, x, b) (a<=x && x<b)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
template<class T> inline T CHMAX(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T & a, const T b) { return a = (a > b) ? b : a; }

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
const long long MOD = 1000000007;

int main(void){
    ll a;
    ll b;
    ll x;
    cin >> a >> b >> x;

    ll tmp1 = b/x;
    ll tmp2 = (a-1)/x;
    if(b == 0){
        cout << "1" << endl;
    }else if(a == 0){
        cout << tmp1+1 << endl;
    }else{
        cout << tmp1-tmp2 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	scanf("%d",&n);
	double sum=0;
	for(int i=0;i<n;i++){
		double a;
		scanf("%lf",&a);
		sum=sum+(1/a);
	}
	printf("%lf",1/sum);
}

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++)
int in(){int x; scanf("%d",&x); return x;}
// static const int MAX = 10000;


int main() {
  int N = in(), M = in(), K, a, ans = 0;
  vector<int> count(30, 0);

  rep(i, N){
    K = in();
    rep(j, K){
      a = in();
      count[a-1]++;
    }
  }

  rep(i, M){
    if(count[i] == N) ans++;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#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 SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b?gcd(b,a%b):a;} //最小公倍数

// デフォルト変数定義
int n,m,a,b,c,d,x,y,z;
string s,t;
//

signed main() {
  RAPID;
  IN3(a,b,c);
  Yes(c>=a&&c<=b);
}

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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

const int MAX = 1e9;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int h, n; cin >> h >> n;
    vector<int> a(n), b(n);
    int maxA = 0;
    for(int i = 0; i< n; i++){
        cin >> a[i] >> b[i];
        maxA = max(a[i], maxA);
    }

    vector<vector<int>> dp(n+1, vector<int>(h+maxA, MAX));
    for(int i = 0; i <= n; i++) dp[i][0]=0;

    for(int i = 0; i < n; i++){
        for(int j = 0; j < h+maxA; j++){
            dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
            if(j >= a[i]) dp[i+1][j] = min(dp[i+1][j], dp[i+1][j-a[i]] + b[i]);
        }
    }

    int ans = MAX;
    for(int j = h; j < h+maxA; j++) ans = min(ans, dp[n][j]);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 44160
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <set>
using namespace std;

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

const int KN = 305;

int n, m, a[KN][KN], pos[KN][KN], cnt[KN];

set<pii> S[KN];

bool check(int mid) {
	for (int i = 1; i <= n; ++i) {
		S[i].clear();
		for (int j = 1; j <= m; ++j) 
			S[i].insert(make_pair(j, a[i][j]));
	}
	int idx;
	for (int k = 1; k < m; ++k) {
		bool can = true;
		memset(cnt, 0x00, sizeof cnt);
		for (int i = 1; i <= n; ++i)
			++cnt[S[i].begin()->second];
		for (int i = 1; i <= m; ++i)
			if (cnt[i] > mid)
				can = false, idx = i;
		if (can)
			return true;
		for (int i = 1; i <= n; ++i)
			S[i].erase(make_pair(pos[i][idx], idx));
	}
	return false;
}

int main() {
	ios::sync_with_stdio(false);
	cin >> n >> m;
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j) {
			cin >> a[i][j];
			pos[i][a[i][j]] = j;
		}
	int low = 0, high = n, ans = high;
	while (low <= high) {
		int mid = (low + high) >> 1;
		if (check(mid))
			ans = mid, high = mid - 1;
		else low = mid + 1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5248
#include <iostream>
#define int long long
using namespace std;

int mod = 1000000007;
int n, k;
int a[2000];

signed main() {
	int i, j;
	
	cin >> n >> k;
	for (i = 0; i < n; i++) cin >> a[i];
	
	int x = 0;
	for (i = 0; i < n; i++) {
		for (j = i + 1; j < n; j++) {
			if (a[i] > a[j]) {
				x++;
			}
		}
	}
	
	int y = 0;
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			if (a[i] > a[j]) {
				y++;
			}
		}
	}
	
	int ans = k * x + (k * (k - 1) / 2) % mod * y;
	cout << ans % mod << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
using namespace std;
using i32 = int32_t;
using i64 = int64_t;
constexpr i32 INF = 1 << 30;

int main()
{
  i32 x, a, b;
  cin >> x >> a >> b;
  cout << (abs(x - a) > abs(x - b) ? 'B' : 'A');
  return 0;
}


Measured memory_bytes: 3588