akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char *argv[]) {
	string S;
	cin >> S;

	int a;
	for (a = 0; a < S.size() && S[a] != 'A'; a++);
	int z;
	for (z = S.size() - 1; z >= 0 && S[z] != 'Z'; z--);

	cout << z - a + 1 << endl;

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, N) for(int i = 0; i < N; i++)
#define rep2(i, N, a, b) for(int i = a; i < N; i += b)
typedef long long ll;

int main(){
	int X, N;
	cin >> X >> N;

	if (N == 0){
		cout << X << endl;
		return 0;
	}
	// map<int, int> p;
	// vector<int> p(N);
	// rep(i, N){
	// 	cin >> p.at(i);
	// 	Min = min(Min, abs());
	// rep(i, N){
	// 	int tmp;
	// 	cin >> tmp;
	// 	p[abs(X - tmp)] = tmp;
	// 	// cin >> p.at(i);
	// }

	vector<pair<int,int>> P(N);
	rep(i, N){
		int tmp;
		cin >> tmp;
		P.at(i).first = abs(X - tmp);
		P.at(i).second = tmp;
	}
	sort(P.begin(), P.end());
	// rep(i,N) cout << P.at(i).first << ": " << P.at(i).second << endl;
	if (P.at(0).first != 0){
		cout << X << endl;
		return 0;
	}
	rep2(i, N, 1, 1){
		if (i % 2 && (i / 2 + 1) != P.at(i).first){
			// if (P.at(i).first == X - (i / 2 + 1))
			// 	cout << X + (i / 2 + 1) << endl;
			// else
			// 	cout << X - (i / 2 + 1) << endl;
			cout << X - (i / 2 + 1) << endl;
			return 0;
		}
		else if (i % 2 == 0 && i / 2 != P.at(i).first){
			if (P.at(i - 1).second == X - (i / 2))
				cout << X + (i / 2) << endl;
			else
				cout << X - (i / 2) << endl;
			// i--;
			// if (P.at(i).second == X - (i / 2 + 1))
			// 	cout << X + (i / 2 + 1) << endl;
			// else
			// 	cout << X - (i / 2 + 1) << endl;
			// cout << P.at(i - 1).second + 2 * (i / 2) << endl;
			return 0;
		}
	}
	if (N % 2) cout << X - (N / 2 + 1) << endl;
	else{
		if (P.at(N - 1).second == X - (N / 2))
				cout << X + (N / 2) << endl;
		else
			cout << X - (N / 2) << endl;
	}
}

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

int main() {
  int a;
  cin >> a;
  double c = a/2;
  double b = round(c);

  if(a % 2 == 0){
      cout << c * c;
  }else{
      cout << (round(c)+1) * (round(c));
  }

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include <queue>
#include<algorithm>
#include <limits.h>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
const ll MOD = 1000000007;
    ll N,sum=0,ans=LONG_MAX,c;

int main(){
    ios_base::sync_with_stdio(false);
    cin>>N;
    ll MAX=sqrt(double(N));
    EREP(i,MAX){
      if(N%i==0){
        ll A=max((ll)i,N/(ll)i);

        ans=min(ans,ll(log10(A)+1));

      }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int count=0;
        while(true){
            int n=sc.nextInt();
            int x=sc.nextInt();
            if(n==0&&x==0){
                break;
            }
            count=0;
            for(int i=1;i<=n;i++){
                for(int j=i+1;j<=n;j++){
                    for(int k=j+1;k<=n;k++){
                        if(i+j+k==x){
                            count++;
                        }
                    }
              }   
        }
       System.out.println(count);
    }
        sc.close(); 
  }
}


Measured memory_bytes: 26752
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime> 
#include <memory.h>
#include <assert.h>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18 + 1;

int main() {
    int A, B, K;
    cin >> A >> B >> K;

    for(int i = 0; i < K; ++i) {
        if (i%2 == 0) {
            if(A%2 == 1) A -= 1;
            B += A/2;
            A /= 2;
        } else {
            if(B%2 == 1) B -= 1;
            A += B/2;
            B /= 2;
        }
    }

    cout << A << " " << B << endl;

    return 0;
}

Measured memory_bytes: 256
class Main{
    public static void main(String[] args){
    	for(int i=1;i<=9;i++){
	    	for(int j=1;j<=9;j++){
		        System.out.println(Integer.toString(i)+"x"+Integer.toString(j)+"="+Integer.toString(i*j));
	    	}
    	}
    }
}

Measured memory_bytes: 16856
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string t;
  cin >> t;
  vector<int> ans(t.size());
  int f=-1;
  for(int i = 0;i<t.size()-1;i++){
    if(t.at(i)=='R' && t.at(i+1)=='L'){
                                   ans.at(i)+=((i-f)+1)/2;
                                   ans.at(i+1)+=(i-f)/2;
      f=i;
    }
    if(t.at(i)=='L' && t.at(i+1)=='R'){
      
      ans.at(f)+=(i-f)/2;
      ans.at(f+1)+=((i-f)+1)/2;
    f=i;
    }
  }
  ans.at(f)+=(t.size()-f-1)/2;
  ans.at(f+1)+=(t.size()-f)/2;
  
  for(int i = 0;i<t.size()-1;i++){
  cout << ans.at(i) << " ";}
  cout << ans.at(t.size()-1) << endl;
}

Measured memory_bytes: 1024
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    int n,me=0,cu=0; cin>>n;
    string s; cin>>s;
    rep(i,n){
        if(s[i]=='(') cu++;
        else cu--;
        me=min(me,cu);
    }
    rep(i,-me) cout<<"(";
    cout<<s;
    rep(i,cu-me) cout<<")";
    cout<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    static int n;
    static int[] a;
    static int[] b;
    static int[] c;
    static int[] dpB;
    static int[] dpA;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        a = new int[n];
        b = new int[n];
        c = new int[n];

        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            b[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            c[i] = sc.nextInt();
        }

        Arrays.sort(a);
        Arrays.sort(b);
        Arrays.sort(c);

        //a[]の中でb[i]の値よりも小さいのが何個あるか
        //c[]の中でb[i]の値よりも大きいのが何個あるか
        //２分探索
        long countA = 0;
        long countB = 0;
        long ans = 0;
        for (int i = 0; i < n; i++) {
            countA = binarySearch(b[i] - 0.1, a);
            if (countA < 0) continue;
            countB = n - binarySearch(b[i] + 0.1, c);
            if (countB < 0) continue;
            ans += countA * countB;
        }
        System.out.println(ans);
    }
    //２分探索
    static int binarySearch (double key, int[] array) {
        int left = -1;
        int right = array.length;
        while (right - left > 1) {
            int mid = (left + right)/2;
            if (array[mid] >= key) {
                right = mid;
            } else {
                left = mid;
            }
        }
        return right;
    }
}



Measured memory_bytes: 92760
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define f first
#define s second

using namespace std;

typedef long long ll;

ostream& operator << (ostream &os, vector <int> &v) {
    for (int i : v)
        os << i << " ";
    os << "\n";
    return os;
}

const int MAXN = 3001;

int dp[MAXN][MAXN];

main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    string s, t;
    cin >> s >> t;
    for (int i = 0; i < s.size(); ++i)
        for (int j = 0; j < t.size(); ++j)
            if (s[i] == t[j])
                dp[i + 1][j + 1] = dp[i][j] + 1;
            else
                dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
    string ans = "";
    int i = s.size(), j =  t.size();

//    for (int i = 0; i <= s.size(); ++i)
//        for (int j = 0; j <= t.size(); ++j)
//            cout << dp[i][j] << " \n"[j == t.size()];

    while (i && j) {
        if (i && dp[i][j] == dp[i - 1][j]) {
            --i;
            continue;
        }
        if (j && dp[i][j] == dp[i][j - 1]) {
            --j;
            continue;
        }
        ans = s[i - 1] + ans;
        --i;
        --j;
    }
    cout << ans << "\n";
    return 0;
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = (int)(n); i >= 0; i--)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define repmr(i, m, n) for(int i = (int)(n); i >= (int)(m); i--)
#define all(x) (x).begin(),(x).end()
#define inf 2e9

using namespace std;
typedef long long int lli;
typedef long long ll;

int n,q;
vector<vector<int>> tree(200000, vector<int>());

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

    cout << max(a*b,c*d) << endl;
}


Measured memory_bytes: 4992
s=input()
s1=s
k=int(input())
ans1=0
ans2=0
for i in range(len(s)-1):
  if s1[i]==s1[i+1]:
    s1=s1[:(i+1)]+'0'+s1[(i+2):]
    ans1+=1
if s1[0]==s1[-1]:
  s1=s1+'0'+s[1:]
  ans2+=1
  k-=1
  for i in range(len(s),len(s1)-1):
    if s1[i]==s1[i+1]:
      s1=s1[:(i+1)]+'0'+s1[(i+2):]
      ans2+=1 
  if s1[0]==s1[-1]:
    ans=ans1+ans2*k
  else:
    ans=(ans1+ans2)*(k//2)+ans1
else:
  ans=ans1*k
print(ans)
      

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxN = 1e3+5;
int dp[maxN][maxN];
int s1, s2, t1, t2;
int w,h;
vector<string> maze;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
int dis[maxN][maxN];
void bfs(int s1, int s2)
{
    for(int i = 0 ; i < h; ++i)
        for(int j = 0; j < w; ++j)
            dis[i][j] = INF;
    deque<pair<int, int>> qq;
    qq.push_front({s1, s2});
    dis[s1][s2] = 0;
    
    while(!qq.empty())
    {
        int xx = qq.front().first;
        int yy = qq.front().second; 
        qq.pop_front();
        int d = dis[xx][yy];
        for(int j = 0; j < 4; ++j)
        {
            int tempX = xx + dx[j];  
            int tempY = yy + dy[j];
            
            if(tempX >= h || tempX < 0) continue;
            if(tempY >= w || tempY < 0) continue;
            if(maze[tempX][tempY] == '#') continue;
            if(dis[tempX][tempY] <= d) continue;
            dis[tempX][tempY] = d;
            qq.push_front({tempX, tempY});
        }
        
        // 5x5 ways 
        
        for(int di = -2; di <= 2; ++di)
        {
            for(int dj = -2; dj <= 2; ++dj)
            {
                int tempX = xx + di;
                int tempY = yy + dj;
                
                if(tempX >= h || tempX < 0) continue;
                if(tempY >= w || tempY < 0) continue;
                if(maze[tempX][tempY] == '#') continue;
                if(dis[tempX][tempY] <= d + 1) continue;
                dis[tempX][tempY] = d+1;
                qq.push_back({tempX, tempY});
            }
        }
    }
}
int main() {
	cin >> h >> w;
	cin >> s1 >> s2;
	cin >> t1 >> t2;
	int ans;
	for(int i = 0; i < h; ++i)
	{
	    string s;
	    cin >> s;
	    maze.push_back(s);
	}
	--s1, --s2, --t1, --t2;
	bfs(s1, s2);
	ans = dis[t1][t2];
	if(ans == INF)
	    ans = -1;
	cout << ans;
	return 0;
}


Measured memory_bytes: 8664
fn main() {
    let sc = std::io::stdin();
    let mut sc = Scanner { reader: sc.lock() };
    let k: usize = sc.read();
    let n: usize = sc.read();
    if k % 2 == 0 {
        assert_eq!(k % 2, 0);
        print!("{}", k / 2);
        for _ in 1..n {
            print!(" {}", k);
        }
        println!();
    } else {
        let mut ans = vec![(k + 1) / 2; n];
        let elimination = (n - 1 + 1) / 2;
        for _ in 0..elimination {
            let len = ans.len();
            let last = ans[len - 1];
            if last == 1 {
                ans.pop();
            } else {
                ans[len - 1] -= 1;
                while ans.len() < n {
                    ans.push(k);
                }
            }
        }

        for i in 0..ans.len() {
            if i > 0 {
                print!(" ");
            }
            print!("{}", ans[i]);
        }
        println!();
    }
}

pub struct Scanner<R> {
    reader: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 10492
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 10000000000
using namespace std;
using ll = long long;
int main()
{
    int n;
    cin >> n;
    vector<int> x(n);
    rep(i,n){
        cin >> x[i];
    }
    sort(x.begin(), x.end());
    int ans = 100000000, tmp;
    for (int i = 1; i <= 100;i++)
    {
        tmp = 0;
        rep(j,n){
            tmp += (x[j] - i)*(x[j] - i);
        }
        ans = min(ans, tmp);
    }
    cout << ans << endl;
}

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

#define pb push_back
#define ll long long

using namespace std;

const int N = 1e6 + 10;

ll l, r;

int ans;

int main() {
 cin >> l >> r;
 while (l <= r) {
  ans++;
  l += l;
 }
 cout << ans;
 return 0;
}



Measured memory_bytes: 256
/****************************************

	LostMartian

****************************************/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <utility>
#include <climits>
#include <numeric>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <cassert>
using namespace std;
typedef long long ll;
#define rep(i,m,n) for(ll i=m; i<n; i++)
#define repr(i,m,n) for(ll i=m; i>=n; i--)
#define vll vector<ll >
#define vvl vector<vector<ll > >
#define pi pair<ll, ll >
#define pb push_back
#define mk make_pair
#define sz size()
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define d(x) cout<<"Value of "#x" = "<<x<<"\n";
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define LOCAL #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
int main()
{
	clock_t z = clock();
	FAST
	//LOCAL
	ll n;
	cin >> n;
	ll arr[n];
	ll x = 0;
	for (ll i = 0; i < n; i++)
	{
		cin >> arr[i];
		x = x ^ arr[i];
	}
	for (ll i = 0; i < n; i++)
	{
		ll val = x ^ arr[i];
		cout << val << " ";
	}


	debug("Total Time: %.3f\n", (double)(clock() - z) / CLOCKS_PER_SEC);
	return 0;
}


Measured memory_bytes: 5356
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll n,m;
	cin>>n>>m;
	ll p[m],y[m];
	vector<ll>py[100001];
	for(int i=0;i<m;i++)cin>>p[i]>>y[i];


	for(int i=0;i<m;i++)py[p[i]].push_back(y[i]);
	for(int i=0;i<n;i++)sort(py[i+1].begin(),py[i+1].end());
	for(int i=0;i<m;i++){
		printf ("%012lld\n",ll(p[i])*1000000+ int(lower_bound(py[p[i]].begin(),py[p[i]].end(),y[i])-py[p[i]].begin())+1);
	}

/*	for(int i=0;i<m;i++){
		printf("%lld\n",*lower_bound(py[p[i]].begin(),py[p[i]].end(),y[i]));
	}*/
	//	for(int i=0;i<m;i++)num[y[i]]=i;
	//sort(y,y+m);
	 /*for( vector<ll>::iterator i=begin(py);i!=end(py);++i) {
	      std::cout << i << std::endl;
	   }*/
}


Measured memory_bytes: 8576
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = str(input().rstrip('\n'))
    b = str(input().rstrip('\n'))
    c = str(input().rstrip('\n'))
    cnt = 0
    for i in range(n):
        s = collections.Counter([a[i], b[i], c[i]])
        if len(s) == 3:
            cnt += 2
        elif len(s) == 2:
            cnt += 1
    print(cnt)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38384
#include <iostream>
#include <vector>

using namespace std;

template<typename T>
struct BIT {
  std::vector<T> node;
  BIT(int n) : node(n+1, 0) {}
  void add(int idx, T w) {
    for (int i = idx; i < node.size()-1; i |= (i + 1)) {
      node[i] += w;
    }
  }
  T sum(int r) {
    T ret = 0;
    for (int i = r-1; i >= 0; i = ((i & (i+1)) - 1)) {
      ret += node[i];
    }
    return ret;
  }
  T sum(int l, int r) {
    return sum(r) - sum(l);
  }
};

int main() {
  int n, q; cin >> n >> q;
  BIT<int> tree(n);

  while (q--) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com == 0) { tree.add(x-1, y); }
    if (com == 1) {
      x--; y--;
      cout << tree.sum(x, y+1) << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0 ; i < (int)(n) ; i++)
typedef long long ll;
////////////////////////////////////////////////
int main(){
    string s;
    int n;
    cin >> n >> s;
    int ans = 0;
    rep(i, n) {
        string x, y, t;
        int cnt = 0;
        t=s;
        y=t.substr(i);
        x=t.erase(i);
        rep(j,i){
            if (x.find(x.at(j))==j && y.find(x.at(j))!=-1) cnt++;
        }
        ans = max(ans, cnt);
    }
    cout << ans <<endl;

}

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

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

    int ans = 0;
    for (int i = 0; i < n; i++)
        ans += 2 * min(x[i] - 0, k - x[i]);

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
<?php

$rec = 0;
$dia = 0;
while (TRUE) {
    fscanf(STDIN, '%d,%d,%d', $e1, $e2, $di);
    if (feof(STDIN)) {
        break;
    }
    if ($e1 * $e1 + $e2 * $e2 === $di * $di) {
        $rec++;
    }
    if ($e1 === $e2) {
        $dia++;
    }
}

echo $rec . PHP_EOL;
echo $dia . PHP_EOL;

Measured memory_bytes: 6580
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n; cin >> n;
    vector<int> b(n-1);
    for(int i=0;i<n-1;i++) cin >> b[i];
    
    int ans = b[0]+b[n-2];
    for(int i=0;i<n-2;i++) ans += min(b[i], b[i+1]);
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;

int main()
{
    int n;
    cin >> n;
    vector<pair<ll, ll>> v(n), w(4);
    rep(i, n) cin >> v[i].first >> v[i].second;
    w[0] = v[0];
    w[1] = v[0];
    w[2] = v[0];
    w[3] = v[0];
    rep(i, n)
    {
        rep(j, 4)
        {
            ll x = (j & 1) ? 1 : -1;
            ll y = (j & 2) ? 1 : -1;
            if (x * w[j].first + y * w[j].second > x * v[i].first + y * v[i].second)
            {
                w[j] = v[i];
            }
        }
    }
    ll ans = 0;
    rep(i, n)
    {
        rep(j, 4)
        {
            chmax(ans, llabs(v[i].first - w[j].first) + llabs(v[i].second - w[j].second));
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6400
import java.util.HashSet;
import java.util.Objects;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args) {
        Scanner stdin = new Scanner(System.in);
        int a = stdin.nextInt();
        int b = stdin.nextInt();
        int c = stdin.nextInt();

        Tuple tuple = new Tuple(a, b, c);
        Set<Tuple> tuples = new HashSet<>();
        while (tuple.x % 2 == 0 && tuple.y % 2 == 0 && tuple.z % 2 == 0) {
            if (tuples.contains(tuple)) {
                System.out.println(-1);
                System.exit(0);
            }

            tuples.add(tuple);
            tuple = new Tuple(tuple.y / 2 + tuple.z / 2, tuple.z / 2 + tuple.x / 2, tuple.x / 2 + tuple.y / 2);
        }
        System.out.println(tuples.size());
    }

    private static final class Tuple {
        private int x;
        private int y;
        private int z;

        public Tuple(int x, int y, int z) {
            this.x = x;
            this.y = y;
            this.z = z;
        }

        @Override
        public int hashCode() {
            return Objects.hash(x, y, z);
        }

        @Override
        public boolean equals(Object obj) {
            if (obj == null || !(obj instanceof Tuple)) {
                return false;
            }

            Tuple that = (Tuple) obj;
            return this.x == that.x && this.y == that.y && this.z == that.z;
        }
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define rep(i, s, N) for(ll i{s}; i < N; i++)
#define rem(i, N, s) for(ll i{N}; i > s; i--)
using namespace std;using ll = long long int;using ld = long double;using P = pair<ll,ll>;const int MOD = (int)1e9+7;const string rt = "\n";const string sp = " ";/* 最大公約数 */template<typename T> T gcd(T a, T b){return b != 0 ? gcd(b, a % b) : a;}/* UnionFind */template<typename T> struct UnionFind{vector<T> par;UnionFind(T n) : par(n, -1){}void init(T n){par.assign(n, -1);}T root(T x){if (par[x] < 0) return x;else return par[x] = root(par[x]);}bool issame(T x, T y){return root(x) == root(y);}bool merge(T x, T y){x = root(x); y = root(y);if(x == y) return false;if(par[x] > par[y]) swap(x, y);par[x] += par[y];par[y] = x;return true;}int size(int x) {return -par[root(x)];}};/* コンビネーション */template<typename T> ll combpm(T N_, T C_) {const int NUM_=400001;static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];if (fact[0]==0) {inv[1]=fact[0]=factr[0]=1;for (int i=2;i<=NUM_;++i) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%MOD, factr[i]=factr[i-1]*inv[i]%MOD;}if(C_<0 || C_>N_) return 0;return factr[C_]*fact[N_]%MOD*factr[N_-C_]%MOD;}/* 多次元ベクター */template<class T>vector<T> mvec(size_t a){return vector<T>(a);}template<class T, class... Ts>auto mvec(size_t a, Ts... ts){return vector<decltype(mvec<T>(ts...))>(a, mvec<T>(ts...));}/* テスト関数 */void test(ll n){cout << "test" << n << endl;}/* 小数点以下 */void fixsp(ll n){cout << fixed << setprecision(n);}void defsp(ll n){cout << defaultfloat << setprecision(n);}/* 重み付きUnionFind */struct WUnionFind {vector<int> par;vector<int> rank;WUnionFind(int n = 1) {init(n);}void init(int n = 1) {par.resize(n); rank.resize(n);for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;}int root(int x) {if (par[x] == x) {return x;}else {int r = root(par[x]);return par[x] = r;}}bool issame(int x, int y) {return root(x) == root(y);}bool merge(int x, int y) {x = root(x); y = root(y);if (x == y) return false;if (rank[x] < rank[y]) swap(x, y);if (rank[x] == rank[y]) ++rank[x];par[y] = x;return true;}};/* IO高速化 */void fastio(){ios::sync_with_stdio(false);cin.tie(NULL);}
/* ここからコード開始 */

int main(){
  fastio;
  ll N;
  cin >> N;
  ll max1{}, max2{}, loc1{}, loc2{};
  rep(i, 0, N){
    ll x;
    cin >> x;
    if(x >= max1){
      loc2 = loc1;
      loc1 = i;
      max2 = max1;
      max1 = x;
    }
    else if(x >= max2){
      loc2 = i;
      max2 = x;
    }
  }
  rep(i, 0, N){
    if(loc1 == i){
      cout << max2 << rt;
    }
    else{
      cout << max1 << rt;
    }
  }
}

Measured memory_bytes: 1664
n = int(input())
A = list(map(int, input().split()))
B = [0] * n
j = n // 2
k = 1 if n % 2 == 1 else -1
for i in range(n):
    B[j] = A[i]
    j += k * (i + 1)
    k = -k
for i in range(n):
    print(str(B[i]) + ' ', end='')
print()


Measured memory_bytes: 30984
#include<bits/stdc++.h>
using namespace std;
#define T top()
#define E end()
#define PS push
#define Q queue
#define PP pop()
#define L0 (LL)0
#define V vector
#define ST stack
#define FI first
#define MAX 4e18
#define MIN -MAX
#define DQ deque
#define RE rend()
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define SE second
#define DL double
#define G getline
#define IN insert
#define endl "\n"
#define EM empty()
#define EE emplace
#define RB rbegin()
#define MD 1000000007
#define PSB push_back
#define PI acos(-1.00)
#define PPB pop_back()
#define PSF push_front
#define ub upper_bound
#define lb lower_bound
#define PPF pop_front()
#define EB emplace_back
#define LL long long int
#define PQ priority_queue
#define N cout<<"NO"<<endl
#define Y cout<<"YES"<<endl
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)
#define UOSMOY v.C;w.C;ww.C;uu.C;uo.C;vo.C;vu.C;ab.C;bc.C;cc.C;uuu.C;a.C;b.C;c.C;u.C
V<LL>v;
V<LL>w,ab,bc;
set<LL>uo;
map<LL,LL>ww,cc,u;
V<pair<LL,LL> >uu;
map<LL,V<LL> >uuu;
map<pair<LL,LL>,LL> vo;
map<pair<LL,LL>,LL> vu;
map<LL,pair<LL,pair<LL,LL > > > vs;
LL dxx[]= {-1,0,1,0};
LL dyy[]= {0,1,0,-1};
LL dx[]= {2,1,-1,-2,-2,-1,1,2};
LL dy[]= {1,2,2,1,-1,-2,-2,-1};
int main()
{
//  BRR;
//  file;
    FAST;
    char ch;
    string a,b,c;
    DL x,y,d,e,f,g,h;
    LL n,m,i,j,k,p,q,o,l,s,tt=1,t,z,aa,r=0;
//    cin>>tt;
    for(LL mau=1;mau<=tt;mau++)
    {
        UOSMOY;
        cin>>n>>m>>p>>q;
        l=n*q;
        l=max(l,n*p);
        l=max(l,m*q);
        l=max(l,m*p);
        cout<<l<<endl;
    }
    return 0;
    //IN
    //AL
}


Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int h, w, s;
char a;
int main() {
	cin>>h>>w;
	s = h+w-1;
	h *= w;
	while(h--) cin>>a, s -= a=='#';
	cout<<(s ? "Imp":"P")<<"ossible";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>

typedef long long ll;
const ll mod = 1e9+7;
const ll INF = 1e12;

int main(int argc, char* argv[])
{
  ll N;
  std::cin >> N;
  std::vector< ll > va(N, 0);
  std::map< ll, ll > mm;

  ll ans = 0;
  for (ll i = 0; i < N; i++) {
    std::cin >> va[i];
    mm[va[i]]++;
    if (mm[va[i]] > 2) {
      ans = -INF;
    }
  }

  if (N % 2 == 0) {
    if (mm[0] >= 1) {
      ans = -INF;
    }
  } else {
    if (mm[0] >= 2) {
      ans = -INF;
    }
  }

  for (ll i = N % 2 + 1; i < N - 1; i +=2) {
    if (mm[i] != 2) {
      ans = -INF;
    }
  }

  if (ans == -INF) {
    std::cout << 0 << std::endl;
    return 0;
  }

  ans = 1;
  for (ll i = 1; i <= N/2; i++) {
    ans *= 2;
    ans %= mod;
  }

  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 6144
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		
		final String word = sc.next();
		
		int count = 0;
		while(true){
			final String txt = sc.next();
			
			if("END_OF_TEXT".equals(txt)){
				break;
			}else if(word.equalsIgnoreCase(txt)){
				count++;
			}
		}
		
		System.out.println(count);
	}

}

Measured memory_bytes: 18032
n = int(input())
As = []
for _ in range(2):
    r = [int(s) for s in input().split()]
    As.append(r)
ss = []
for i in range(2):
    r = [0]
    s = 0
    for j in range(n):
            a = As[i][j]
            s += a
            r.append(s)
    ss.append(r)
ans = 0
for i in range(1, n + 1):
    ans = max(ans, ss[0][i] + ss[1][n] - ss[1][i - 1])
print(ans)

Measured memory_bytes: 3188
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a[110],b[110];
	int as,bs=0;
	int at[110],bt[110]={0};
	for(int i=1;i<=n;i++){
		cin>>a[i];
		as+=a[i];
		at[i]=as;
	}
	for(int i=1;i<=n;i++){
		cin>>b[i];
		bs+=b[i];
		bt[i]=bs;
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		int res=at[i]+bs-bt[i-1];
		if(res>ans){
			ans=res;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>
#include <cstdio>
#include <iomanip>
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define queint queue<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>//大きい順
#define pqg priority_queue<int,vec,greater<int>>//小さい順
#define pb push_back
#define vec vector<int>
#define vecvec vector<vector<int>>
#define vecll vector<ll>
#define vecvecll vector<vector<ll>>
#define bs binary_search
#define All(c) (c).begin(),(c).end()
#define mp make_pair
using namespace std;
int in(){int x;scanf("%d",&x);return x;}
string stin(){string s;cin>>s;return s;}
ll lin(){ll x;scanf("%lld",&x);return x;}
int main(){
    int n=in();
    ll sum=0,ans=0;
    rep(i,n){
        int x=in();
        if(x==0){
            ans+=sum/2;
            sum=0;
        }else{
            sum+=x;
        }
    }
    cout<<ans+sum/2<<endl;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main(void)
{
	int n, m, a, b;
	
	while (scanf("%d %d", &n, &m), n != 0 || m != 0){
		bool fr[512][512] = {false};
		for (int i = 0; i < m; i++){
			scanf("%d %d", &a, &b);
			fr[a][b] = true;
			fr[b][a] = true;
		}
		
		bool cm[512] = {false};
		for (int i = 2; i <= n; i++){
			if (fr[1][i]){
				cm[i] = true;
				for (int j = 2; j <= n; j++){
					if (fr[i][j]){
						cm[j] = true;
					}
				}
			}
		}
		
		int ct = 0;
		for (int i = 2; i <= n; i++){
			if (cm[i]){
				ct++;
			}
		}
					
		printf("%d\n", ct);
	}
	return (0);
}

Measured memory_bytes: 1292
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

int main(){
  int n,i,j,no;
  int count;
  double half;

  while(1){
    cin >> n;
    if(n == 0)break;
    long long values[n];
    half=n/2.0;
    count=1;
    no=0;
    // cout << "half="<< half << endl;
    for(i=0;i<n;i++){
      cin >> values[i];
    }
    if(n == 1){
      cout << values[0] << endl; 
      continue;
    }

     sort(values,values+n);

    for(i=1;i<n;i++){
      //   cout  <<"values[i] =" << values[i] << endl; 
      //    cout << "values[i-1] = " << values[i-1] << endl;
    
      if(values[i] == values[i-1])count++;
      else{
	if(count>half){
	  cout<< values[i] << endl;
	  count = 1;
	  break;  
	}
	count = 1;	
      }
      if(count > half){
	cout << values[i] << endl;
	break;
      }
      if(i == n-1){
        cout << "NO COLOR" << endl;
      } 
    }
  } 
  return 0;
}

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

sx,sy,tx,ty = map(int,input().split())

route = []

y = ty - sy
x = tx - sx

route += ["U"] * y
route += ["R"] * x
route += ["D"] * y
route += ["L"] * x
route += ["L"]
route += ["U"] * (y + 1)
route += ["R"] * (x + 1)
route += ["D","R"]
route += ["D"] * (y + 1)
route += ["L"] * (x + 1)
route += ["U"]

print("".join(route))


Measured memory_bytes: 3188
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

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

using namespace std;

typedef pair<int, int> P;

class ETwoCurrencies {
public:
    vector<int> it, ic;
    vector<vector<tuple<int, int, int>>> G;

    void dfs(int v, int p) {

    }

    void solve(std::istream& cin, std::ostream& cout) {
        int N, M, S;
        cin >> N >> M >> S;
        G.resize(N);
        int sum = 0;
        REP(i, M) {
            int u, v, a, b;
            cin >> u >> v >> a >> b;
            u--, v--;
            G[u].emplace_back(v, a, b);
            G[v].emplace_back(u, a, b);
            sum += a;
        }
        vector<int> C(N), D(N);
        REP(i, N) {
            cin >> C[i] >> D[i];
        }

        if (S > sum) {
            S = sum;
        }
        priority_queue<pair<int, P>, vector<pair<int, P>>, greater<>> pq;
        vector<vector<int>> dist(N, vector<int>(sum + 1, INF));
        dist[0][S] = 0;
        pq.push({0, {0, S}});
        while (!pq.empty()) {
            auto[cost, vv] = pq.top();
            auto[from, money] = vv;
            pq.pop();
            if (dist[from][money] < cost) continue;
            for (auto v : G[from]) {
                auto[to, a, b] = v;
                if (money - a < 0) continue;
                if (cost + b < dist[to][money - a]) {
                    dist[to][money - a] = cost + b;
                    pq.push({dist[to][money - a], {to, money - a}});
                }
            }
            int newmoney = money + C[from];
            if (newmoney > sum) newmoney = sum;
            if (cost + D[from] < dist[from][newmoney]) {
                dist[from][newmoney] = cost + D[from];
                pq.push({dist[from][newmoney], {from, newmoney}});
            }
        }
        FOR(i, 1, N - 1) {
            int res = INF;
            FOR(j, 0, sum) {
                res = min(res, dist[i][j]);
            }
            cout << res << endl;
        }
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    ETwoCurrencies solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 7408
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<algorithm>
#include<climits>
using namespace std;

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

	vector<int> h(N);
	for(int i=0; i<N; i++)
		cin >> h[i];

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

	int ret = INT_MAX;
	for(int i=0; i<=N-K; i++)
		ret = min(ret, h[i+K-1]-h[i]);

	cout << ret << endl;

	return 0;
}


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

#define MAXN 200013
#define EPS 1e-12
#define FST first
#define SCD second
#define INF 0x3f3f3f3f
#define PREV(x) (((x)==1)?n:((x)-1))
#define NEXT(x) (((x)==n)?1:((x)+1))
#define LOG(x) tb[(UI(x) * (UI)263572066) >> 27]

using namespace std;

typedef unsigned int UI;
typedef long long LL;
typedef pair<int, int> PA;

const UI tb[32] = {13, 0, 27, 1, 28, 18, 23, 2, 29, 21, 19, 12, 24, 9, 14, 3, 30, 26, 17, 22, 20, 11, 8, 13, 25, 16, 10, 7, 15, 6, 5, 4};

int n, m, tot;


int main() {
#ifndef ONLINE_JUDGE
	// freopen("in.txt", "r", stdin);
#else
	// freopen("distance.in", "r", stdin);
	// freopen("distance.out", "w", stdout);
#endif
	int T = 1;
	for (int ci=1;ci<=T;++ci) {
		char s[100];
		scanf("%s",s);
		n = strlen(s);
		for (int i=0;i<n-1;++i) {
			if (*(s+i)=='A'&&*(s+1+i)=='C') {
				puts("Yes");
				return 0;
			}
		}
		puts("No");
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

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

	long long a;
	vector<long long> dists = {0};

	for (int i = 0; i < n; i++) {
		cin >> a;
		dists.emplace_back(dists.back() + a);
	}

	long long total = dists.back();

	long long diff_min = total;
	for (auto x: dists) {
		auto diff = abs(total - x - x);
		// printf("x: %10lld, diff: %10lld\n", x, diff);

		if (diff < diff_min) {
			diff_min = diff;
		}
	}

	long long ans = diff_min;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
 
int main(void){
 
 string N;
 
 cin >> N;
 if(N.at(0)==N.at(1) && N.at(1)==N.at(2)){
     cout << "No" << endl;
 }else{
     
     cout << "Yes" << endl;
     
 }
 
}

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

int main(){
  int n,ans=0;cin>>n;
  vector<int> a(n,0);
  REP(i,n) cin>>a.at(i);
  for(int i=n-1;i>=0;i-=2) cout<<a.at(i)<<" ";
  for(int i=(n%2?1:0);i<n;i+=2) cout<<a.at(i)<<" ";
}

Measured memory_bytes: 2944
s = input()
k = int(input())
st = set()
m = min(k, len(s))
t = sorted(list(set(list(s))))[:k]
for i in range(len(s)):
    if s[i] in t:
        for j in range(i + 1, i + 6):
            st.add(s[i:j])
l = sorted(list(st))
print(l[k - 1])


Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
#include <numeric>
using namespace std;

// m > n >= 0
template <class T>
T gcd(T m, T n)
{
    if (n == 0)
        return m;
    return gcd(n, m % n);
}

int halfNtimes(int n, int count)
{
    if (n % 2 == 0)
    {
        n /= 2;
        return halfNtimes(n, count + 1);
    }
    else
        return count;
}

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(n);

    cin >> a[0];
    int memo = halfNtimes(a[0], 0);
    int ans;
    bool exsist = true;
    for (int i = 1; i < n; i++)
    {
        int b;
        cin >> b;
        if (halfNtimes(b, 0) != memo)
        {
            exsist = false;
            break;
        }
        a[i] = b;
    }

    if (exsist)
    {
        long long t = accumulate(a.begin(), a.end(), 2, [m](long long acc, long long i) {
            long long g;
            if (acc > i)
                g = gcd(acc, i);
            else
                g = gcd(i, acc);
            long long lcm = acc * i / (2 * g);
            if (lcm > m)
                return (long long)0;
            return lcm;
        });
        if (t != 0)
        {
            int count = 0;
            int unit = t;
            while (t <= m)
            {
                count++;
                t += unit * 2;
            }
            ans = count;
        }
        else
            ans = 0;
    }
    else
        ans = 0;

    cout << ans << endl;

    return 0;
}

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

const int N = 3005;
int n, l, r;
pair<long long, long long> a[N];
long long f[N][N];

long long F(int i, int j)
{
    if (i > j)
    {
        return 0;
    }
    if (f[i][j] != -1)
    {
        return f[i][j];
    }
    int now = j - i + 1;
    long long ans = 0;
    ans = max(F(i, j - 1) + abs(a[now].second - j) * a[now].first, F(i + 1, j) + abs(a[now].second - i) * (a[now].first));
    return f[i][j] = ans;
}
bool cmp(pair<long long, long long> x, pair<long long, long long> y)
{
    return (x.first != y.first ? x.first < y.first : x.second < y.second);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(a + 1, a + n + 1, cmp);
    memset(f, -1, sizeof(f));
    long long ans = 0;
    cout << F(1, n);
    return 0;
}


Measured memory_bytes: 74332
R1=range(-2,3)
R2=range(-1,2)
A1=[(x,y) for x in R1 for y in R1 if 3<x**2+y**2<6]
A2=[(x,y) for x in R2 for y in R2]
def fi(): return map(int,raw_input().split(" "))
def f(p,i):
  x,y=p
  A=[A1,A2][i>0]
  return set([(x+dx,y+dy) for dx,dy in A if 0<=x+dx<10 and 0<=y+dy<10])

while 1:
  xf,yf=fi()
  if yf==xf==0: break
  raw_input()
  tmp=fi()
  PA=zip(tmp[0::2],tmp[1::2])
  FA=set([(xf,yf)])
  for ps in PA:
    SA=f(ps,1)
    tmp=set([])
    for pf in FA: tmp=tmp|(SA&f(pf,0))
    FA=tmp
  print ["NA","OK"][len(FA)>0]

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

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> L(n);
    copy_n(istream_iterator<int>(cin), n, L.begin());
    sort(L.begin(), L.end());

    int64_t ans = 0;
    for (int i = 0; i < n; i++){
        for (int j = i + 1; j < n; j++){
            auto l = lower_bound(L.begin() + j + 1, L.end(), L[j] - L[i] + 1);
            auto r = lower_bound(L.begin() + j + 1, L.end(), L[i] + L[j]);
            ans += r - l;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define INF 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define req(i, j, n) for(int i = j; i <= (int)(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int pw2(int n){
  int t=1;
  while(t<=n){
    t*=2;}
  return t;
}

int main() {
  int n;
  cin>>n;
  
  map<int, int> nu;
  
  for(int i=1;i<=n;i++){
   int a;
    cin>>a;
    if(nu.find(a)==nu.end())
      nu[a]=0;
    ++nu[a];
  }
  
 
  
  
  int ans=0;
  for(auto itr=nu.rbegin();itr!=nu.rend();itr++){
    int b=itr->first;
    int p=pw2(b)-b;
    
    
    if(b==p){
      ans+=nu[b]/2;}
    else{
      if(nu.find(p) == nu.end())continue;
      ans+=min(nu[b], nu[p]);
      nu[p]-=min(nu[b], nu[p]);
    }
  }
  
  cout<<ans<<endl;
  
  
  
  
  
  


}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
#define int long long
#define F first
#define S second
using namespace std;
const int maxN = 1e5 + 13;
int n, sz[maxN], ans, mn = 1e9 + 13, e, cen;
bool f = 0;
vector<pair<int, int>> adj[maxN];
void dfs (int x, int par) {
    sz[x] = 1;
    for (auto a : adj[x]) {
	int v = a.F, w = a.S;
	if (v != par) {
	    dfs(v, x);
	    ans += 2 * min(sz[v], n - sz[v]) * w;
	    //cout << 2 * min(sz[v], n - sz[v]) * w << endl;
	    if (sz[v] == n / 2 && n % 2 == 0) {
		e = w;
		f = 1;
	    }
	    sz[x] += sz[v];
	}
    }
}

void d(int v, int p){
    sz[v] = 1;
    for(auto a : adj[v]){
	int u = a.F;
	if(u != p){
	    d(u, v);
	    sz[v] += sz[u];
	}
    }
}

void fnd_cen(int v){
    d(v, v);
    int root = v, p = -1;
    bool found = true;
    while(found){
	found = false;
	for(auto a : adj[v]){
	    int u = a.F;
	    if(u != p && sz[u] > sz[root] / 2){
		p = v;
		v = u;
		found = true;
		break;
	    }
	}
    }
    cen = v;
}

int32_t main () {
    cin >> n;
    for (int i = 0; i < n - 1; i++) {
	int a, b, w;
	cin >> a >> b >> w;
	adj[a].push_back({b, w});
	adj[b].push_back({a, w});
    }
    dfs(1, 1);
    if (f)
	cout << ans - e << endl;
    else {
	fnd_cen(1);
	for (auto a : adj[cen])
	    mn = min(mn, a.S);
	cout << ans - mn << endl;
    }
    
}
	


Measured memory_bytes: 13952
#include <bits/stdc++.h>
#define ll          long long int
#define PI          acos(-1)
#define read        freopen("in.txt","r",stdin)
#define uu          first
#define vv          second
#define write       freopen("out.txt","w",stdout)
#define pii         pair<int,int>
#define pll         pair<ll,ll>
#define INF         1e9
#define EPS         1e-8
#define MAX         1000006
#define MOD         1000000007
#define fastRead    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
    

vector<int>edg[MAX];
int n , m;


int main()
{
    fastRead;
    cin>>n>>m;
    for(int i =0 ; i < n ; i++ ) {
        int a , b;
        cin>>a>>b;
        
        edg[a].push_back(b);
    }
    
    priority_queue<int>pq;
    
    int ans = 0;
    
    for(int i = m-1 ; i>=0 ; i-- ) {
        
        
        int gap = m - i;
        
        for(auto x : edg[gap]) pq.push(x);
//        cout<<gap<<" "<<pq.size()<<endl;
        
        if( !pq.empty() ) {
            ans += pq.top();
            pq.pop();
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define pb emplace_back
#define ll long long
#define ld long double

const int INF = 2e9 + 1;
const ll INFLL = 1e18 + 1;
const int mod = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto &c : a) cin >> c;
    ll dp[n][5][2];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 5; j++) {
            dp[i][j][0] = dp[i][j][1] = -INFLL;
        }
    }
    dp[0][2][0] = 0;
    dp[0][3][1] = a[0];
    vector<int> d = {-2, -1, 0, 1, 2};
    for (int i = 1; i < n; i++) {
        for (int j1 = 0; j1 < 5; j1++) {
            /// i / 2 + d[j1] + (0, 1)
            int delta = (i / 2 + d[j1]) - (i + 1) / 2;
            if (delta >= -2 && delta <= 2) dp[i][delta + 2][0] = max({dp[i][delta + 2][0], dp[i - 1][j1][0], dp[i - 1][j1][1]});
            delta++;
            if (delta < -2 || delta > 2) continue;
            dp[i][delta + 2][1] = max(dp[i][delta + 2][1], dp[i - 1][j1][0] + a[i]);
        }
    }
    cout << max(dp[n - 1][2][0], dp[n - 1][2][1]);
    return 0;
}



Measured memory_bytes: 19568
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define REP(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define INF 10000000
#define ll long long

using namespace std;

typedef pair<int, int> P;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

char str[8002];
vector<int> v, w;
int x, y;
bool xb, yb;
bool dp[8000][10000];

bool f(vector<int> v, int n, int sum){
    rep(j, sum) dp[0][j] = false;
    dp[0][0] = true;

    REP(i, n){
        REP(j, sum+1){
            if(j >= v[i]) dp[i+1][j] = dp[i][j] || dp[i][j - v[i]];
            else dp[i+1][j] = dp[i][j];
        }
    }

    return dp[n][sum];
}

int main(){
    REP(i, 8002) str[i] = 'S';

    scanf("%s", str);

    scanf("%d%d", &x, &y);

    bool b = true;
    int i = 0;
    int tmp = 0;

    bool update=false;
    while(true){
        if(str[i] == 'F'){
            ++tmp;
            update = true;
        } else {
            break;
        }
        ++i;
    }

    if(update){
        b = false;
        ++i;
    }

    x -= tmp;

    tmp = 0;

    while(true){
        if(str[i] == 'S') break;
        if(str[i] == 'F'){
            ++tmp;
        } else {
            if(tmp != 0){
                if(b){
                    v.push_back(tmp);
                    b = false;
                } else {
                    w.push_back(tmp);
                    b = true;
                }
            } else {
                if(b) b = false;
                else b = true;
            }
            tmp = 0;
        }

        ++i;
    }

    int n = v.size();
    int m = w.size();

    int sum = 0;

    if(n == 0){
        if(x == 0) xb = true;
        else xb = false;
    } else {
        REP(i, n) sum -= v[i];
        sum = x - sum;

        if(sum % 2 != 0){
            xb = false;
        } else {
            sum /= 2;
            if(f(v, n, sum)) xb = true;
            else xb = false;
        }
    }

    sum = 0;

    if(m == 0){
        if(y == 0) yb = true;
        else yb = false;
    } else {
        REP(i, m) sum -= w[i];
        sum = y - sum;

        if(sum % 2 != 0){
            yb = false;
        } else {
            sum /= 2;
            if(f(w, m, sum)) yb = true;
            else yb = false;
        }
    }

    if(xb && yb) printf("Yes\n");
    else printf("No\n");

	return 0;
}

Measured memory_bytes: 26240