akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second

int main(){
    int N, T;
    cin >> N >> T;
    vector<pair<int, int>> CT(N);
    for(int i =0 ; i < N; i++) cin >> CT[i].fi >> CT[i].se;
    int min_c = 10000000;
    for(auto p : CT){
        if(p.se <= T) min_c = min(min_c, p.fi);
    }
    if(min_c == 10000000) puts("TLE");
    else cout << min_c << endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <cmath>
#include <algorithm>
#include <numeric>

typedef long long ll;
const ll INF = (ll)1e18 + 1;

void print() { std::cout << std::endl; }
template<typename Head> void print(Head head) { std::cout << head << std::endl; }
template<typename Head, typename... Tail> void print(Head head, Tail... tail)
{
  std::cout << head << " ";
  print(tail...);
}

int main()
{
  ll N, M;
  std::cin >> N >> M;

  ll ans = 1;
  for (ll A = 1; A * A <= M; A++) {
    if (M % A != 0) continue;
    ll B = M / A;
    if (A * N <= M) ans = std::max(ans, A);
    if (B * N <= M) ans = std::max(ans, B);
  }

  print(ans);
  return 0;
}


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

const int mod = 1000000007;

int main() {
  ll n;
  cin >> n;
  ll a, b;
  cin >> a >> b;
  ll cnt = 0;
  cnt = n / (a + b);
  n -= cnt * (a + b);
  ll ans = 0;
  if (n - a > 0) {
    ans = cnt * a + a;
  } else {
    ans = cnt * a + n;
  }
  cout << ans << endl;
}

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

using namespace std;

int main(){
    
    unsigned int a;
    vector<int> h;
    for(int i = 0; i < 3;i++){
        cin>>a;
        h.push_back(a);
    }
    
    sort(h.begin(),h.end());
    cout<<h[0];
    for(int i = 1; i < 3;i++){
        cout<<" "<<h[i];
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 3148
// Contest.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cctype>

using namespace std;


int main()
{
	string s;
	cin >> s;
	cout << count(s.begin(), s.end(), '1') << endl;
	return 0;
}



Measured memory_bytes: 256
use std::iter;

fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let v : Vec<usize> = s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect();
    let mut mat : Vec<String> = Vec::new();
    let mut ans : Vec<Vec<i32>> = Vec::new();
    let mut ans2 : Vec<String> = Vec::new();
    let h = v[0];
    let w = v[1];

    mat.push(std::iter::repeat(".").take(w+2).collect());
    ans.push(vec![0; w+2]);
    for _i in 0..h {
        let mut t = String::new();
        std::io::stdin().read_line(&mut t).ok();
        let mut pstr = ".".to_string();
        pstr.push_str(&t.trim());
        pstr.push('.');
        //println!("{}", pstr);
        mat.push(pstr);
        ans.push(vec![0; w+2]);
    }
    mat.push(iter::repeat(".").take(w+2).collect());
    ans.push(vec![0; w+2]);

    for i in 1..(h+1) {
        for j in 1..(w+1) {
            if mat[i].chars().nth(j).unwrap() == '#' {
                for k in 0..3 {
                    for l in 0..3 {
                        //println!("{} {} {} {}", k,l,i-1+k, j-1+l);
                        ans[i-1+k][j-1+l] += 1;
                    }
                }
            }
        }
    }
    for i in 1..(h+1) {
        let mut u = String::new();
        for j in 1..(w+1) {
            if mat[i].chars().nth(j).unwrap() == '#' {
                u.push('#');
            }
            else {
                u.push_str(&ans[i][j].to_string());
            }
        }
        ans2.push(u);
    }

    for i in 0..(h) {
        println!("{}", ans2[i]);
    }
}


Measured memory_bytes: 4352
// inputに入力データ全体が入る
function Main(input) {
  var a,b,c;
  a = Number(input.split('\n')[0].split(' ')[0]);
  b = Number(input.split('\n')[0].split(' ')[1]);
  c = Number(input.split('\n')[0].split(' ')[2]);
  console.log(c - (a - b) > 0 ? c - (a - b) : 0);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include <cstdio>
#include <iostream>
#include <array>
#include <vector>
#include <deque>
#include <string>
#include <algorithm>
#include <functional>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <utility>
#include <memory>
#include <valarray>
#include <climits>

using namespace std;

using ll = long long int;

#define REP(i, N) for (int i = 0; i < (N); ++i)
#define scanInt(x) int x; scanf("%d", &(x)); getchar();
#define scanLLInt(x) ll x; scanf("%lld", &(x)); getchar();
#define scanVecInt(A, N) vector<int> A(N); REP(i, N){scanf("%d", &(A[i])); getchar();}
#define scanVecLLInt(A, N) vector<ll> A(N); REP(i, N){scanf("%lld", &(A[i])); getchar();}

int main()
{
    const int A = getchar() - '0';
    const int B = getchar() - '0';
    const int C = getchar() - '0';
    const int D = getchar() - '0';
    if (A + B + C + D == 7){cout << A << '+' << B << '+' << C << '+' << D << "=7" << endl; return 0;}
    if (A + B + C - D == 7){cout << A << '+' << B << '+' << C << '-' << D << "=7" << endl; return 0;}
    if (A + B - C + D == 7){cout << A << '+' << B << '-' << C << '+' << D << "=7" << endl; return 0;}
    if (A + B - C - D == 7){cout << A << '+' << B << '-' << C << '-' << D << "=7" << endl; return 0;}
    if (A - B + C + D == 7){cout << A << '-' << B << '+' << C << '+' << D << "=7" << endl; return 0;}
    if (A - B + C - D == 7){cout << A << '-' << B << '+' << C << '-' << D << "=7" << endl; return 0;}
    if (A - B - C + D == 7){cout << A << '-' << B << '-' << C << '+' << D << "=7" << endl; return 0;}
    if (A - B - C - D == 7){cout << A << '-' << B << '-' << C << '-' << D << "=7" << endl; return 0;}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define ll  long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

ll ma=1e9+7;


int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
double a[n];
for(int i=0;i<n;i++)
    cin>>a[i];
double dp[n][n+1];
for(int i=0;i<n;i++)
    for(int j=0;j<=n;j++)
    dp[i][j]=0.0;

dp[0][0]=(1.0-a[0]);
dp[0][1]=a[0];
for(int i=1;i<n;i++){

    for(int j=0;j<=i;j++){
        dp[i][j]+=dp[i-1][j]*(1.0-a[i]);
         dp[i][j+1]+=dp[i-1][j]*a[i];


    }
}
double ans=0.0;
for(int i=n/2+1;i<=n;i++)
    ans+=dp[n-1][i];
cout<<fixed<<setprecision(10)<<ans<<endl;





}


Measured memory_bytes: 70528
// Input macro
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

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

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

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

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

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

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

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

// Test Code
macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
    "1 + 2" => "3",
    "5 - 7" => "-2",
}

fn main() {
    println!("{}", solve(&stdin!()));
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        a: i32,
        op: String,
        b: i32,
    }

    if op == "+" {
        return (a + b).to_string();
    } else {
        return (a - b).to_string();
    }
}

Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <queue>

class Baseball{
	
	//field
	int score, out_count;
	std::queue<int> runners;
public:
	Baseball();
	~Baseball(){}
	
	//関数
	void hit();
	void homerun();
	void out();
	//setter,getter
	/*
	void set_score(int s) {score = s;}
	void set_out(int o) {out_count = o;}
	*/
	int get_score() {return score;}
	int get_out() {return out_count;}
};

//コンストラクタ
Baseball::Baseball()
{
	score = 0;
	out_count = 0;
}

void Baseball::hit(){
	runners.push(1);
	if(runners.size() == 4){
		++score;
		runners.pop();
	}
}

void Baseball::homerun(){
	score += runners.size() + 1;
	while(runners.size() != 0){
		runners.pop();
	}
}

void Baseball::out(){
	++out_count;
}
//クラスのフィールドアクセス？？
//キュー以外のいい感じのライブラリ探す？
int main(){
	int inning;
	std::string event;
	std::cin >> inning;
	//inningの回数だけループ
	for(int i = 0; i < inning; ++i){
		Baseball game;
		while(game.get_out() != 3){
			std::cin >> event;
			if(event == "HIT"){
				game.hit();
			}
			else if(event == "HOMERUN"){
				game.homerun();
			}
			else if(event == "OUT"){
				game.out();
			}
		}
	std::cout << game.get_score() << std::endl;
	}
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
using namespace std;
const int N=100005,mod=1000000007;
vector<int>e[N];
long long fac[N]={1},n,k,ans=1;
long long qp(long long a,long long b)
{
	long long ans=1;
	while(b)
	{
		if(b&1)
			ans=ans*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ans;
}
long long pl(long long a,long long b)
{
	if(a<b) return 0;
	return fac[a]*qp(fac[a-b],mod-2)%mod;
}
void dfs(int u,int f)
{
	if(!f)
		ans=ans*pl(k,e[u].size()+1)%mod;
	else
		ans=ans*pl(k-2,e[u].size()-1)%mod;
	for(int i=0;i<e[u].size();i++)
		if(e[u][i]!=f)
			dfs(e[u][i],u);
}
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>k;
	for(int i=1;i<=k;i++)
		fac[i]=i*fac[i-1]%mod;
	for(int i=1;i<n;i++)
	{
		int u,v;
		cin>>u>>v;
		e[u].push_back(v);
		e[v].push_back(u);
	}
	dfs(1,0);
	cout<<ans<<endl;
	return 0;
}


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

using namespace std;

using ll = long long int;
using vi = vector<int>;
#define f(n) for(int i = 0; i < n; i++)
#define fj(n) for(int j = 0; j < n; j++)
#define fk(n) for(int k = 0; k < n; k++)
#define ci(n) cin >> n;
#define ic(n) int n; cin >> n;
#define lc(n) int n; cin >> n;
#define all(a) a.begin(), a.end()
#define pri(a, n) for(int i = 0; i < n; i++) cout << a[i] << " "; cout << "\n";
#define scl(a, n) ll a[n] = {0}; for(int i = 0; i < n; i++) cin >> a[i];
#define pb push_back
#define eb emplace_back
#define sc second
#define ft first
#define int long long
void prip(int a[], int n){f(n) cout << a[i] << ' '; cout << '\n';}

const int inf = 2e9, mxp = 10, maxn = 2e6, mod = 1e9 + 7;
int bp(int a, int n)
{
    if(n == 0) return 1;
    if(n & 1ll) return (a * bp(a, n - 1)) % mod;
    int res = bp(a, n >> 1);
    return (res * res) % mod;
}
int fc[maxn + 1], rc[maxn + 1];
int cnk(int n, int k)
{
    if(k > n) return 0;
    int ans = (fc[n] * rc[k]) % mod;
    return (ans * rc[n - k]) % mod;
}

main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    ic(n)
    int ans = 0;
    for(int l = 1; l <= n; l++) ans += l * (n - l + 1);
    f(n - 1)
    {
        ic(v) ic(u)
        if(u > v) swap(v, u);
        ans -= (u * (n - v + 1));
    }
    cout << ans;
}


Measured memory_bytes: 3684
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
#define ll unsigned long long
using namespace std;
/*
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t; cin >> t;
    while (t--) {
        ll n; cin >> n;
        vector<ll> a(n), b;// A_B(n), B_A(n);
        unordered_map<ll, ll> A, B;
        ll cost = 0, flag = 0;

        for (int i = 0; i < n; i++) {
            cin >> a[i];
            if (A.find(a[i]) == A.end()) {
                        A[a[i]] = 1;
            }
            else
                A[a[i]] += 1;
        }
        for (int i = 0; i < n; i++) {
            ll temp; cin >> temp;
            auto it = find(a.begin(), a.end(), temp);
            if (it != a.end()) {
                a.erase(remove(a.begin(), a.end(), temp), a.end());
            }
            else
                b.push_back(temp);
        }
//        auto AB = set_difference(a.begin(), a.end(), b.begin(), b.end(), A_B.begin());
//        auto BA = set_difference(b.begin(), b.end(), a.begin(), a.end(), B_A.begin());
//

        if (a.size() != b.size() || (a.size()%2 != 0 || b.size()%2 != 0)) {
            flag = 1;
        }
        ll i = 0;
        while(i<a.size()) {
            if ((count(a.begin(), a.end(), a[i]) >= 2)) {
                for (auto& ip : b) {
                    if (count(a.begin(), a.end(), ip) < count(b.begin(), b.end(), ip) && count(b.begin(), b.end(), ip) >= 2) {
                        swap(ip, a[i]);
                        cout << ip << " " << a[i] << "\n";
                        cost += min(ip, a[i]);
                        break;
                    }
                }
            }
            i++;
        }
        sort(a.begin(), a.end());
        sort(b.begin(), b.end());
        cout << "\nA\n";
        for (auto ip : a) {
            cout << ip << " ";
        }
        cout << "\nB\n";
        for (auto ip : b) {
            cout << ip << " ";
        }
        if ( ! (a==b) ) {
            flag = 1;
        }
        if(flag == 0) cout << cost << "\n";
        else cout << -1 << "\n";

 1
 4
 1 1 2 2
 3 3 4 4

    }


}
*/
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n, ans = 0; cin >> n;
    vector<int> ip(n);
    for(ll i = 0; i<n; i++) cin >> ip[i];
    for(ll i = 0; i<n; i++) {
        if ((i+1) % 2 == 1 && ip[i]%2 == 1) {
            ans++;
        }
    }
    cout << ans;
}


Measured memory_bytes: 3168
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <vector>

//#define PI 3.141592653589

using namespace std;



int main()
{
	for (int i=1; i<=9; i++)
	{
		for (int j=1; j<=9; j++)
		{
			cout << i << "x" << j << "=" << i*j << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1116
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define per(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define INF 2e9
#define LINF 1e18
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int a, b, t; cin >> a >> b >> t;
    int num = t/a;
    cout << num * b << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
const ull MAX=1e19;
int a[512];
ull cnt[512];
ull dp[512][512];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	for(int i=1;i<=n;++i){
		cin>>a[i];
		cnt[i]=cnt[i-1]+a[i];
	}
	for(int i=1;i<=n;++i){
		for(int j=1;j+i<=n;++j){
			dp[j][j+i]=MAX;
			for(int k=j;k+1<=j+i;++k){
				dp[j][j+i]=min(dp[j][j+i],dp[j][k]+dp[k+1][j+i]);
			}
			dp[j][j+i]+=cnt[j+i]-cnt[j-1];
		}
	}
	cout<<dp[1][n]<<endl;
	return 0;
}

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

int main() {
	long n,T,k=0,j=0;
	cin>>n>>T;
	long c[n],t[n],d[1010]={1010};
	for(int i=0;i<n;i++)cin>>c[i]>>t[i];
	
	for(int i=0;i<n;i++){
		if(t[i]<=T){
			d[j]=c[i];
			j++;
		}
	}
	sort(d,d+j);
	if(d[0]!=1010){
	cout<<d[0]<<endl;
	}
	else{
		cout<<"TLE"<<endl;
	}
	return 0;
}

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


vector<vector<long long> > G(50, vector<long long>(50, 0)); 
long long n, m;

vector<bool> visit(50, false);

void dfs(long long v){
    visit[v] = true;
    
    for(long long i = 0; i < n; i++){
        if(visit[i] == true) continue;

        if(G[v][i] == 0) continue;

        dfs(i);
    }
}

long long counter(){
    long long cnt = 0;
    for(long long i = 0; i < n; i++){
        if(visit[i] == true) cnt++;
    }
    return cnt;
}

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

    vector<long long> a(m);
    vector<long long> b(m);

    for(long long i = 0; i < m; i++){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        G[a[i]][b[i]] = 1;
        G[b[i]][a[i]] = 1;
    }

    long long ans = 0;
    for(long long i = 0; i < m; i++){
        G[a[i]][b[i]] = 0;
        G[b[i]][a[i]] = 0;

        dfs(0);
        if(counter() != n) ans++;

        G[a[i]][b[i]] = 1;
        G[b[i]][a[i]] = 1;
        visit.assign(50, false);
    }

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

Measured memory_bytes: 3656
x = int(input())
l = []
d = {}
for i in range(1000):
  b = (-1000+i)**5
  d[b] = -1000+i
for i in range(1000):
  a = i**5
  d[a] = i
  if a-x in d:
    b = d[a-x]
    a = i
    break
print(a,b)

Measured memory_bytes: 9212
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<numeric>
#include<iomanip>
#include<utility>
#include<cstdlib>
#include<typeinfo>


using namespace std;
#define INF 1000000005
int main()
{
std::string str;
std::cin >> str;
int l = str.length();
if(l > 9 || l < 5){
    std::cout << "NO" << std::endl;
} else {
    int flag = 0;
    int index = 0;
    std::string astr = "AKIHABARA";
    for (int i = 0; i <= 5; i++){
        if(i == 0 && (str[0] != astr[1] && (str[0] != astr[0] || str[1] != astr[1]))){
            flag = 1;
            break;
        } else if(i == 0 && str[0] == astr[1]){
            index++;
            continue;
        } else if(i == 0){
            index += 2;
            continue;
        }
        if(i == 1 && (str[index] != astr[2] || str[index + 1] != astr[3])){
            flag = 1;
            break;
        } else if(i == 1) {
            i++;
            index += 2;
        }
        if(i == 3 && (str[index] != astr[5] && (str[index] != astr[4] || str[index + 1] != astr[5]))){
            flag = 1;
            break;
        } else if(i == 3 && str[index] == astr[5]){
            index++;
            continue;
        } else if(i == 3){
            index += 2;
            continue;
        }
        if(i == 4 && (str[index] != astr[7] && (str[index] != astr[6] || str[index + 1] != astr[7]))){
            flag = 1;
            break;
        } else if(i == 4 && str[index] == astr[7]){
            index++;
            continue;
        } else if(i == 4){
            index += 2;
            continue;
        }
        if(i == 5){
            if(l - index > 1){
                flag = 1;
                break;
            } else if(l - index == 1){
                if(str[l - 1] != 'A'){
                    flag = 1;
                    break;
                }
            }
        }
    }
    if(flag == 0){
        std::cout << "YES" << std::endl;
    } else {
        std::cout << "NO" << std::endl;
    }
}
return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc126A
{
    class Program
    {
        static void Main(string[] args)
        {
            string N_K = Console.ReadLine();
            string S = Console.ReadLine();
            string[] inp = N_K.Split(' ');
            var N = Convert.ToInt32(inp[0]);
            var K = Convert.ToInt32(inp[1]);
            Console.WriteLine(S.Substring(0, K-1)+ S.Substring(K-1, 1).ToLower()+ S.Substring(K,N-K));
            Console.ReadKey();
        }
    }
}


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

int main() {
  int N,M;
  cin>>N>>M;
  int64_t L,P=10000000000;
  cin>>L;
  vector<vector<int64_t>> g(N,vector<int64_t>(N,300*P));
  for(int i=0;i<M;i++){
    int a,b;
    int64_t c;
    cin>>a>>b>>c;
    a--,b--;
    g.at(a).at(b)=c;
    g.at(b).at(a)=c;
  }
  for(int i=0;i<N;i++){
    g[i][i]=0;
  }
  for(int k=0;k<N;k++){
    for(int i=0;i<N;i++){
      for(int j=0;j<N;j++){
        g[i][j]=min(g[i][j],g[i][k]+g[k][j]);
      }
    }
  }
  vector<vector<int>> G(N,vector<int>(N,924));
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      if(g[i][j]<=L){
        G[i][j]=1;
      }
    }
  }
  for(int i=0;i<N;i++){
    G[i][i]=0;
  }
  for(int k=0;k<N;k++){
    for(int i=0;i<N;i++){
      for(int j=0;j<N;j++){
        G[i][j]=min(G[i][j],G[i][k]+G[k][j]);
      }
    }
  }
  int Q;
  cin>>Q;
  for(int i=0;i<Q;i++){
    int a,b;
    cin>>a>>b;
    a--,b--;
    if(G[a][b]==924){
      cout<<"-1"<<endl;
    }
    else{
      cout<<G[a][b]-1<<endl;
    }
  }
}

Measured memory_bytes: 4676
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>
#include <string>

using namespace std;

bool ans[100005] = {0};

int main()
{
    int n,m;
    long long h[100005];
    
    cin >> n >> m;
    for (int i = 0;i < n;i++){
        cin >> h[i];
    }
    
    for (int i = 0;i < m;i++){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        if (h[a] > h[b]){
            ans[b] = true;
        }
        else if (h[a] == h[b]){
            ans[a] = true;
            ans[b] = true;
        }
        else {
            ans[a] = true;
        }
    }
    
    int t = 0;
    for (int i = 0;i < n;i++){
        if (ans[i]){
            t++;
        }
    }
    
    cout << n-t << endl;
}


Measured memory_bytes: 4512
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
#include <stack>
#include <iomanip>
#include <limits>
using namespace std;
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
typedef priority_queue<ll> PQ_HIGH;
typedef priority_queue<ll,VL,greater<ll>> PQ_LOW;//昇順

int main(){
  ll n;cin>>n;
  VL a(n);
  VL p1(n);
  VL p2(n);
  set<ll> q1;
  set<ll> q2;
  REP(i,n){
    cin>>a[i];
    p1[i]=a[i]+i+1;
    p2[i]=i+1-a[i];
    q1.insert(p1[i]);
  }
  sort(p2.begin(),p2.end());
  sort(p1.begin(),p1.end());
ll ans=0;
  for (auto itr = q1.begin(); itr != q1.end(); ++itr) {
      //cout << *itr<<endl;
      auto itr1=lower_bound(ALL(p2),*itr)-p2.begin();
      auto itr2=upper_bound(ALL(p2),*itr)-p2.begin();
      auto itr12=lower_bound(ALL(p1),*itr)-p1.begin();
      auto itr22=upper_bound(ALL(p1),*itr)-p1.begin();


      //cout<<itr12-itr22<<endl;
      ans+=(itr2-itr1)*(itr22-itr12);
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 16760
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = INT64_MAX;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;
using Vi = vector<long long int>;
typedef pair<int, int> P; typedef pair<ll, ll>PLL;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i=0;i<N;i++)
auto max(auto x,auto y){if(x>y){return x;}else{return y;}}
auto min(auto x,auto y){if(x>y){return y;}else{return x;}}
template<class T>bool chmax(T &former, const T &b) { if (former<=b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<=former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
typedef vector<vector<ll> > matrix;
void princ(auto x){cout<<x<<" ";}; void print(auto x){cout<<x<<"\n";};
///////////////////////////////////////////////////////////////////////////////////

ll n,m;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    cin>>n>>m;
    ll ans = 1;
    Vi v;
    for(ll i = 1;i*i <= m;i++){
        if(m%i == 0){
            v.pb(i); v.pb(m/i);
        }
    }
    sort(all(v));
    rep(i,v.size()){
        if(v[i]*n <=m)ans = v[i];
        else break;
    }
    print(ans);
    return 0;    
}

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

import bisect

def readInts():
  return [int(s) for s in input().split(" ")]

def main():
  s = input()
  t = input()

  appears = {}
  for i, c in enumerate(s):
    if not c in appears:
      appears[c] = []
    appears[c].append(i)

  rep = 0
  cur = 0
  for c in t:
    if c not in appears:
      cur = -1
      break

    if c == s[cur]:
      cur += 1
    else:
      i = bisect.bisect(appears[c], cur)
      if i == len(appears[c]):
        rep += 1
        cur = appears[c][0] + 1
      else:
        cur = appears[c][i] + 1

    if cur == len(s):
      rep += 1
      cur = 0

  if cur < 0:
    print(-1)
  else:
    print(rep * len(s) + cur)

if __name__ == "__main__":
  main()


Measured memory_bytes: 7540
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v)) os<<*i<<(i==end(v)-1?"":" "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
    is>>p.first>>p.second; return is; }
template <class T> bool chmax(T &a,const T &b) {if(a<b) {a=b;return 1;} return 0;}
template <class T> bool chmin(T &a,const T &b) {if(b<a) {a=b;return 1;} return 0;}
template <class T> using heap = priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int n;
    cin>>n;
    int ans=1;
    REP(i,sqrt(n)+1) {
        if(i*i<=n) chmax(ans,i*i);
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

#define ll long long



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

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

	int count = 0;

	for (int t = 0; t < n - 1; t++)
	{
		for (int i = t + 1; i < n; i++)
		{
			int cur = 0;

			for (int j = 0; j < d; j++)
			{
				cur += pow(matrix[t][j] - matrix[i][j], 2);
			}
			int root = sqrt(cur);
			if (root * root == cur)
			{
				count++;
			}

		}
	}
	cout << count << endl;
}

Measured memory_bytes: 768
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <queue>
#include <math.h>
using namespace std;
#define N 10000000000000

int main(){
    int n;
    cin>>n;
    vector<int> num;
    for (int i=0; i<n; i++){
        int a;
        cin>>a;
        num.push_back(a);
    }
    long long count=0;
    sort(num.begin(), num.end());
    for (int i=0; i<n-2; i++){
        for (int j=i+1; j<n-1; j++){
            for (int k=j+1; k<n; k++){
                if (num[i]+num[j]>num[k]) count+=1;
                else break;
            }
        }
    }
    cout<<count<<endl;
}

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

const int INF = INT_MAX;
const int MAXN = 5000;
const int B = 100;
const int BNUM = MAXN / B;

int n, m;
pair<int, int> ps[MAXN];
int x[MAXN], y[MAXN];
vector<int> bucket[BNUM];

int main() {
  while(scanf("%d%d", &n, &m) != EOF) {
    for(int i = 0; i < n; ++i) {
      scanf("%d%d", &ps[i].first, &ps[i].second);
    }
    sort(ps, ps+n);
    fill(bucket, bucket + BNUM, vector<int>());
    for(int i = 0; i < n; ++i) {
      x[i] = ps[i].first;
      y[i] = ps[i].second;
      bucket[i/B].push_back(y[i]);
    }
    for(int b = 0; b < BNUM; ++b) {
      sort(bucket[b].begin(), bucket[b].end());
    }
    while(m--) {
      int s, t, u, v; 
      scanf("%d%d%d%d", &s, &t, &u, &v);
      int l = lower_bound(x, x+n, s) - x;
      int r = upper_bound(x, x+n, u) - x;
      int res = 0;
      while(l < r && l % B != 0) {
        res += (t <= y[l] && y[l] <= v);
        ++l;
      }
      while(l < r && r % B != 0) {
        --r;
        res += (t <= y[r] && y[r] <= v);
      }
      while(l < r) {
        int b = l / B;
        res += upper_bound(bucket[b].begin(), bucket[b].end(), v)
          - lower_bound(bucket[b].begin(), bucket[b].end(), t);
        l += B;
      }
      printf("%d\n", res);
    }
  }
  return 0;
}

Measured memory_bytes: 1316
N = int(input())
tot = 0
perf = 0
for i in range(N-1):
    pair = [int(x) for x in input().split()]
    pair.sort()
    tot += pair[0]*(N+1-pair[1])
    perf += (i+1)*(N-1-i)

print(N*(N+1)//2 + perf - tot)


Measured memory_bytes: 79940
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n)repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
typedef pair<int,int> P;
typedef pair<int, P> PP;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define fi first
#define se second
const int inf = 1e9+7;
int mod = 1e9+7;

int a[100000];
signed main(){
	int n;
	scanf("%lld", &n);
	rep(i,n)scanf("%lld", &a[i]);
	int mx = 2, mn = 2, f = 1;
	drep(i,n-1,0){
		if(a[i] > mx)f = 0;
		mx = a[i]*(mx/a[i]+1)-1;
		mn = a[i]*((a[i]+mn-1)/a[i]);
		if(mn > mx)f = 0;
		//printf("%lld %lld\n", mn, mx);
	}
	if(f)printf("%lld %lld\n", mn, mx);
	else printf("-1\n");
	return 0;
}


Measured memory_bytes: 1024
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    X = [list(map(int,input().split())) for _ in range(N-1)]
    Q,K = map(int,input().split())
    Y = [list(map(int,input().split())) for _ in range(Q)]

    tree = [[] for _ in range(N)]
    dif = [10**15 for _ in range(N)]
    dif[K-1] = 0
    for i in range(N-1):
        tree[X[i][0]-1].append((X[i][1]-1,X[i][2]))
        tree[X[i][1]-1].append((X[i][0]-1,X[i][2]))

    queue = [K-1]
    while queue:
        a = queue.pop()
        for i in tree[a]:
            s,t = i[0],i[1]
            if dif[s] == 10**15:
                dif[s] = dif[a]+t
                queue.append(s)

    for i in range(Q):
        print(dif[Y[i][0]-1]+dif[Y[i][1]-1])

if __name__ == "__main__":
    main()

Measured memory_bytes: 87516
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define INF 1LL<<62

int N, K;
int H[300];

int dp[300][300];

signed main() {
  cin >> N >> K;
  for (int i=0; i<N; i++) cin >> H[i];

  dp[0][0] = H[0];

  for(int r=1; r < N; r++) dp[r][0] = H[r];
  for(int ncol=1; ncol < N; ncol++) dp[0][ncol] = INF;

  for(int r=1; r < N; r++) for(int ncol=1; ncol < N-K; ncol++) {
    int v = INF;
    for (int i=0; i<r; i++) v = min(v, dp[i][ncol-1] + max(0LL, H[r] - H[i]));
    dp[r][ncol] = v;
  }

  int ans = INF;
  for (int i=0; i<N; i++) ans = min(ans, dp[i][N-K-1]);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 896
h, w, K = map(int, input().split())
a = []
g = 0
for i in range(h):
    a.append(input())
for i in range(2**h):
    b = h-1
    c = []
    while i > 0:
        if i%2 == 1:
            c.append(b)
        i //= 2
        b -= 1
    for j in range(2**w):
        d = w-1
        e = []
        while j > 0:
            if j%2 == 1:
                e.append(d)
            j //= 2
            d -= 1
        f = 0
        for k in c:
            for l in e:
                if a[k][l] == "#":
                    f += 1
        if f == K:
            g += 1
print(g)

Measured memory_bytes: 9136
//author : Yogi79

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

int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   
   long n;
   cin>>n;
   int a[n+1][3];

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

   long dp[n+1][3];
   for(int i=0;i<n+1;i++)
    fill(dp[i],dp[i]+3,0);

    for(int i=1;i<n+1;i++)
    {
        for(int j=0;j<3;j++)
        {
            for(int k=0;k<3;k++)
            {
              if(k != j)
                {
                    dp[i][k] = max(dp[i][k], dp[i-1][j] + a[i][k]);
                }
            }
        }
    }

cout<<max(dp[n][0],max(dp[n][1],dp[n][2]));
}

Measured memory_bytes: 3840
N, M = map(int, input().split())  # N人の人に聞く, M種類の食べ物の好きかどうか

menew = set(range(1, M+1))  # 食べ物の番号

for i in range(N):
    k, *a = map(int, input().split())
    menew = menew & set(a)

print(len(menew))


Measured memory_bytes: 2940
/***************************************************************
Esse é um problema parecido com o problema da mochila.
Usando o código do exercício anterior
***************************************************************/
#include <bits/stdc++.h>

using namespace std;

int main(){
    int n=0, q=0;

    cin >> n;
    
    int matrix[n][3], resp[n][3];
    
    for (int i = 0; i < n; i++){
        for (int j = 0; j < 3; j++){
            cin >> matrix[i][j];
            resp[i][j]=-1;
        }
    }

    resp[0][0]=matrix[0][0];
    resp[0][1]=matrix[0][1];
    resp[0][2]=matrix[0][2];
    for (int i = 0; i < n; i++){
        for (int j = 0; j < 3; j++){
                for(int k=0; k<3; k++){
                    if (j==k){
                        continue;
                    }else{
                    
                    q=max(resp[i+1][k], resp[i][j]+matrix[i+1][k]);
                    }
                    // cout << "k: " << k << " j: " << j << endl;
                resp[i+1][k]=q;
                }
                // cout << "To no j" << endl;
        }
        // cout << "To no i" << endl;
    }
    
    
    // for (int i = 0; i < n; i++){
    //     for (int j = 0; j < 3; j++){
    //         cout << resp[i][j] << " ";  
    //     }
    //     cout << endl;
    // }

    //Não funciona, tem que imprimir o valor máximo na n-linha
    //cout << resp[n-1][2] << endl;
    int resposta=0;
    if(resp[n-1][0] >=resp[n-1][1] && resp[n-1][0] >=resp[n-1][2]){
        resposta = resp[n-1][0];
    }else if(resp[n-1][1] >=resp[n-1][0] && resp[n-1][1] >=resp[n-1][2]){
        resposta = resp[n-1][1];
    }else if(resp[n-1][2] >=resp[n-1][0] && resp[n-1][2] >=resp[n-1][1]){
        resposta = resp[n-1][2];
    }
    cout << resposta << endl;
    

}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+7;
char s[maxn];
int pre[maxn],lst[maxn],nxt[maxn];
vector<int> ans;
int main()
{
	int n,m;scanf("%d%d",&n,&m);
	scanf("%s",s);int flag=1;
	int last=0;
	for(int i=0;i<=n;i++)
	{
		if(s[i]=='1') pre[i]=pre[i-1]+1,last=i;
		else pre[i]=0;
		if(pre[i]>=m) flag=0;
		lst[i]=last;
	}
	if(flag==0)
	{
		cout<<-1<<endl;
		return 0;
	}
	int next=n;
	for(int i=n;i>=0;i--)
	{
		if(s[i]=='0') next=i;
		nxt[i]=next;
	}
	//for(int i=0;i<=n;i++)
	//{
	//	cout<<nxt[i]<<" ";
	//}
	//cout<<endl;
	int now=n;
	while(now>=0)
	{
		if(lst[now]==0)
		{
			while(now>=m)
			{
				ans.push_back(m);now-=m;
			}
			if(now)
			ans.push_back(now);
			now=0;
			break;
		}
		if(now>=m&&s[now-m]=='1')
		{
			int tmp=nxt[now-m];
			ans.push_back(now-tmp);
			now=tmp;
		}
		else
		{
			if(now>=m)
			{
				ans.push_back(m);
				now-=m;
			}
			else 
			{
				ans.push_back(now);
				now=0;break;
			}
		}
	}
	for(int i=ans.size()-1;i>=0;i--)
	{
		cout<<ans[i]<<" ";
	}
	cout<<endl;
	return 0;
}

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

using namespace std;

#define INF 1010001000
#define EPS 1e-10
#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef pair<int, int> i_i;
typedef long long int llong;
typedef pair<llong, llong> ll_ll;
typedef struct edge {int f, t;}Edge;


int main()
{
    int n;
    while (cin >> n, n) {
        vector<vector<bool> > key(n+1, vector<bool>(n+1, false));
        rep(i, n) {
            int k;
            cin >> k;
            rep(j, k) {
                int a;
                cin >> a;
                key[i+1][a] = true;
            }
        }
        int k;
        cin >> k;
        vector<bool> ch(n+1, true);
        rep(i, k) {
            int a;
            cin >> a;
            rep(j, n+1) {
                if (!(key[j][a] && ch[j])) {
                    ch[j] = false;
                }
            }
        }
        int ret = 0;
        rep(i, n+1) {
            if (ch[i] && !ret) {
                ret = i;
            } else if (ch[i] && ret) {
                ret = -1;
            }
        }
        if (!ret) {
            ret = -1;
        }
        cout << ret << endl;
    }

    return 0;
}

Measured memory_bytes: 3188
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

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

        int N = sc.nextInt();
        int[] u = new int[N - 1];
        int[] v = new int[N - 1];
        int[] w = new int[N - 1];
        for (int i = 0; i < N - 1; ++i) {
            u[i] = sc.nextInt() - 1;
            v[i] = sc.nextInt() - 1;
            w[i] = sc.nextInt();
        }

        System.out.println(solve(u, v, w));

        sc.close();
    }

    static String solve(int[] u, int[] v, int[] w) {
        int N = u.length + 1;

        @SuppressWarnings("unchecked")
        List<Integer>[] edgeList = new List[N];
        for (int i = 0; i < edgeList.length; ++i) {
            edgeList[i] = new ArrayList<>();
        }

        for (int i = 0; i < N - 1; ++i) {
            edgeList[u[i]].add(i);
            edgeList[v[i]].add(i);
        }

        int[] colors = new int[N];
        Arrays.fill(colors, -1);

        search(colors, u, v, w, edgeList, 0, 0);

        return Arrays.stream(colors).mapToObj(String::valueOf).collect(Collectors.joining("\n"));
    }

    static void search(int[] colors, int[] u, int[] v, int[] w, List<Integer>[] edgeList, int node, long distance) {
        colors[node] = (int) (distance % 2);

        for (int edge : edgeList[node]) {
            int adj = (u[edge] == node) ? v[edge] : u[edge];
            if (colors[adj] == -1) {
                search(colors, u, v, w, edgeList, adj, distance + w[edge]);
            }
        }
    }
}

Measured memory_bytes: 78352
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long ll;

int main() {
	ll N;
	ll ans = 0;
	cin >> N;
	vector<ll> A(N), B(N), B2(N);
	rep(i, 0, N) cin >> A[i];
	rep(i, 0, N) cin >> B[i];

	rep(i, 0, 29) {
		ll T = pow(2, i);
		rep(j, 0, N) B2[j] = B[j] % (2*T);
		sort(all(B2));
		ll cnt = 0;
		rep(j, 0, N) {
			ll a = A[j] % (2*T);
			cnt += lower_bound(all(B2), 2*T-a) - lower_bound(all(B2), T-a);
			cnt += lower_bound(all(B2), 4*T-a) - lower_bound(all(B2), 3*T-a);
		}
		if (cnt % 2 == 1) {
			ans += T;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4992
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main() {

    int a, b;
    scanf("%d%d", &a, &b);

    int maxdata = a + b;

    if (maxdata < a - b) {
        maxdata = a - b;
    }

    if (maxdata < a * b) {
        maxdata = a*b;
    }

    printf("%d", maxdata);

    return 0;


}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (ll i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)
#define MAX (100000)
#define pii pair<int, int>

/////////////////////////////////////////////////////////

class XY{
public:
  ll x, y;
  XY() {x = y = 0;}
  XY(ll u, ll v) {x = u; y = v;}
};

template<typename T1, typename T2>
void chmin(T1 &a, T2 b) {if(a > b) a = b;}
template<typename T1, typename T2>
void chmax(T1 &a, T2 b) {if(a < b) a = b;}

template<typename T1, typename T2>
ll mypow(T1 a, T2 n){
  if(n == 0) return 1;
  if(n == 1) return a;
  if(n % 2) return a * mypow(a, n - 1);
  ll tmp = mypow(a, n / 2);
  return tmp * tmp;
}

template<typename T>
int BS(vector<T> V, int left, int right, T key){
  int mid = (left + right) / 2;
  if(V[mid] <= key) left = mid;
  else right = mid;
  if(right - mid == 1) return left;
  else return BS(V, left, right, key);
}

ll comb(ll n, ll r){
	ll res = 1;
  rep(i, 0, r){
    res *= n - i;
    res /= i + 1;
  }
  return res;
}

template<typename T>
T euclid(T a, T b){
  if(b == 0) return a;
  else return euclid(b, a % b);
}

/////////////////////////////////////////////////////////

void Main() {
  string S; cin >> S;
  string res;
  if(S[0] == 'S') res = "Cloudy";
  else if(S[0] == 'C') res = "Rainy";
  else res = "Sunny";
  cout << res << endl;
}

/////////////////////////////////////////////////////////

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << std::fixed << std::setprecision(15);

  Main();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,a[100005],lhj=0,ma=-1;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++) {
		cin>>a[i];
		ma=max(a[i],ma);
		if(a[i]<=ma-2&&i!=1){
			cout<<"No";
			return 0;
		}
		else if(a[i-1]==a[i]+1&&i!=1){
			if(lhj==0) lhj=1;
			else{
				cout<<"No";
				return 0;
			}
		}
		else if(a[i-1]<=a[i]) lhj=0;
	}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 640
N,M=map(int,input().split())
ans = 0
if M%2==0:
    x=M//2
    if N>=x:
        print(x)
        exit()
    else:
        ans+=N
        y=M-N*2
        z=y//4
        ans+=z
else:
    x=M//2
    if N>=x:
        print(x)
        exit()
    else:
        ans+=N
        y=M-N*2
        z=y//4
        ans+=z
print(ans)

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

using namespace std;

#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define mem(a) memset(a, 0, sizeof(a))
#define sqr(x) ((x) * (x))

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

const int mn = 1e5 + 5;
const int mod = 1e9 + 7;
#define P mod

int n,q;
int d[mn];

bool judge(){
    int even=0;
    for(int i=1;i<=4;i++){
        if (d[i]%2) even++;
        if (d[i]==0) return 0;
    }
    return even==2||even==0;
}

int main() {
#ifdef LOCAL
    freopen("../1.txt", "r", stdin);
#endif
    for(int i=1;i<=3;i++){
        int u,v;
        scanf("%d%d",&u,&v);
        d[u]++,d[v]++;
    }
    if (judge()) puts("YES");
    else puts("NO");


    return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
P = list(map(int, input().split()))
M = sum(P[0:K])
m = M
for i in range(0, N-K):
  m = m - P[i] + P[i+K]
  if m >= M:
    M = m
print((M+K)/2.0)

Measured memory_bytes: 24548
#include<bits/stdc++.h>
using namespace std;
int n;
double num,x,p; 
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>p;
		num+=p;
		x=max(x,p);
	}
	cout<<num-x/2;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef  long long int ll;
int main(){
	 ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
int n;
cin >> n;
string arr[n];
for (int i=0;i<n;i++){
	cin >> arr[i];
}
int a=1;
unordered_map<string,int> st;
for(int i=0;i<n;i++){
st[arr[i]]=0;
}
for(int i=0;i<n;i++){
	st[arr[i]]++;
}
int a1=st.size();
int k=st[arr[0]] ;
for(auto itr=st.begin();itr!=st.end();++itr){
	if(itr->second>k){
	k=itr->second;
}
}
vector <string> v;
for(auto itr=st.begin();itr!=st.end();++itr){
if(itr->second==k){
v.push_back(itr->first);
}
}
sort(v.begin(),v.end());
for(auto x:v){
	cout << x << endl;
}
}




Measured memory_bytes: 26948
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE BangPatterns#-}
{-# OPTIONS_GHC -O2 #-}

import GHC.TypeLits

import Data.Int
import Data.Proxy
import qualified Data.Map.Lazy as Map
import Data.List
import Data.Bits
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.Array.IArray as Array
import Data.Array.MArray
import Data.Array.ST
--import Data.Monoid
--import Data.Semigroup

import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Control.Monad.Primitive
import Control.Monad.State

import Debug.Trace




getInts :: IO [Int]
getInts = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

main :: IO ()
main = do
  a <- getInts
  print $ sum a - maximum a


Measured memory_bytes: 380
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

int N,M; vector<pair<int, int> > intv[200200];

const int Z = 1 << 18;

struct node{
	node(){sum = mx = 0;}
	node(long long x){
		sum = mx = x;
		if (mx < 0) mx = 0;
	}
	long long sum, mx;
	
	node operator +(node t){
		node r(0);
		r.sum = sum + t.sum;
		r.mx = mx;
		if (r.mx < sum + t.mx)
			r.mx = sum + t.mx;
		return r;
	}
}IT[Z*2];

node out(int x, int y)
{
	x += Z; y += Z;

	node l, r;
	while (x < y){
		if (x & 1) l = l + IT[x++];
		if (~y & 1) r = IT[y--] + r;
		x /= 2; y /= 2;
	} if (x == y) l = l + IT[x];
	return l + r;
}

void in(int x, long long p)
{
	x += Z;
	p += IT[x].sum;
	IT[x] = node(p);
	x /= 2;
	while (x){
		IT[x] = IT[x*2] + IT[x*2+1];
		x /= 2;
	}
}

int main()
{
	scanf ("%d %d",&N,&M);
	for (int i=0;i<M;i++){
		int l,r,a;
		scanf ("%d %d %d",&l,&r,&a);
		intv[r].push_back({l,a});
	}

	for (int i=1;i<=N;i++){
		auto r = out(0,i-1);
		in(i,r.mx);
		in(i+1,-r.mx);
		for (auto &p : intv[i]){
			in(p.first, p.second);
			in(i+1, -p.second);
		}
	}

	printf ("%lld\n",out(0,N).mx);

	return 0;
}


Measured memory_bytes: 19328