akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.Arrays;
import java.util.Scanner;
public class Main{
	public static void main(String args[]){
    int a=0,b=0,c=0,d=0,i=0,n=0,j=0,k=0;
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    int[][][] office = new int[3][10][4];



    try{
      String line = reader.readLine();
      n = Integer.parseInt(line);
      
      for(i=0;i<n;i++){
        line = reader.readLine();
         String[] splitted = line.split(" ");
         a = Integer.parseInt(splitted[0]);
         b = Integer.parseInt(splitted[1]);
         c = Integer.parseInt(splitted[2]);
         d = Integer.parseInt(splitted[3]);
         office[b-1][c-1][a-1] += d;
      }
		}catch(Exception e){
    }

    for (i = 0; i < 4; i++){
      for (k = 0; k < 3; k++){
        for (j = 0; j < 10; j++){
          try{
            System.out.print(" " + office[k][j][i]);
            }catch(Exception e){
            }
        }
        System.out.print("\n");
      }
      if(i < 3){
        System.out.print("####################\n");
      }
      
    }
	}
}


Measured memory_bytes: 24644
import java.util.Scanner;

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

        char[] split = abcd.toCharArray();
        int[] ints = new int[split.length];
        for (int i = 0; i < split.length; i++) {
            ints[i] = Character.getNumericValue(split[i]);
        }
        int digit = ints.length;

        for (int i = 0; i < Math.pow(2, digit - 1); i++) {
            int sum = 0;
            boolean sign = true; // true: +, false: -
            StringBuilder sb = new StringBuilder();
            for (int j = 0; j < digit; j++) {
                sb.append(ints[j]);
                if (sign) sum += ints[j];
                else sum -= ints[j];
                if ((1 & i >> j) == 1) {
                    sb.append("+");
                    sign = true;
                } else if (j < digit - 1) {
                    sb.append("-");
                    sign = false;
                }
            }
            if (sum == 7) {
                sb.append("=").append(sum);
                System.out.println(sb.toString());
                break;
            }
        }
    }
}


Measured memory_bytes: 21844
#include <iostream>

using namespace std;


unsigned long long gcd(unsigned long long a,unsigned long long b) {
	unsigned long long m;
	while ((m = a % b) != 0) {
		a = b;
		b = m;
	}
	return b;
}

int main() {
	unsigned long long a,b;
	cin >> a >> b;
	cout << gcd(a,b) << endl;
	return 0;
}


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

int main(){
    int n;
    cin>>n;
    int maxv=0,minv=2e9,tmp;
    for(int i=0;i<n;i++){
        cin>>tmp;
        maxv=max(maxv,tmp);
        minv=min(minv,tmp);
    }
    cout<<maxv-minv<<endl;
    return 0;
}

Measured memory_bytes: 3544
n,m=[int(_) for _ in input().split()]
dic={}
height=[int(b) for b in input().split()][:n]
list1=[]
count=0
for j in range(n):
    dic[j+1]=height[j]
for i in range(m):
    a,b=[int(q) for q in input().split()]
    if dic[a]>dic[b]:
        
        list1.append(b)
    elif dic[b]>dic[a]:
        list1.append(a)
    else:
        list1.append(a)
        list1.append(b)
            
print(n-len(set(list1)))

Measured memory_bytes: 27988
#define _USE_MATH_DEFINES

#include <iostream>	//cin, cout
#include <vector>	//vector
#include <algorithm> //sort,min,max,count
#include <string>	//string,getline
#include <ios>		//fixed
#include <iomanip>	//setprecision
#include <utility> //swap
#include <cstdlib>	//abs(int)
#include <cmath>	//sqrt
#include <sstream>	//stringstream,getline
#include <cmath>	//ceil,M_PI
#include <numeric>	//gcd
#include <deque>	//deque

using namespace std;

int main() {

	string S;
	cin >> S;

	switch(S[0]) {
	case 'S': cout << "Cloudy" << endl; break;
	case 'C': cout << "Rainy" << endl; break;
	case 'R': cout << "Sunny" << endl; break;
	}

	return 0;

}

Measured memory_bytes: 3552
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ll n;
	cin>>n;
	vector<ll> a;
	a.assign(n,0);
	ll x;
	for(ll i=0;i<n;i++) {
		cin>>a[i];
		if(i==0) x=a[i];
		else x=x^a[i];
	}
	for(ll i=0;i<n;i++){
		cout<<(a[i]^x)<<" ";
	}
	cout<<endl;
}

Measured memory_bytes: 4776
// 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! {
    "AtCoder Beginner Contest" => "ABC",
    "AtCoder Snuke Contest" => "ASC",
    "AtCoder X Contest" => "AXC",
}

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

fn solve(src: &str) -> String {
    input! {
        source = src,
        s: [String; 3],
    }

    let mut ans = String::new();
    
    for word in s.iter() {
        ans.push(word.chars().nth(0).unwrap());
    }

    ans
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
bool isprime(int x){
	for(int i=2;i*i<=x;++i)if(x%i==0)return 0;
	return 1;
}
char S[100010];
int main(){
#ifdef XZZSB
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n=gi(),k=gi(),r=gi(),s=gi(),p=gi(),ans=0;
	scanf("%s",S+1);
	for(int i=1;i<=k;++i)
		for(int j=i;j<=n;j+=k){
			if(j>k&&S[j]==S[j-k])S[j]='*';
			else{
				if(S[j]=='r')ans+=p;
				else if(S[j]=='p')ans+=s;
				else ans+=r;
			}
		}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
int main()
{
  int a,b;
  char str;
  while(1)
  {
    scanf("%d %c %d",&a,&str,&b);
    if(str=='+')printf("%d\n",a+b);
    else if(str=='-')printf("%d\n",a-b);
    else if(str=='*')printf("%d\n",a*b);
    else if(str=='/')printf("%d\n",a/b);
    else if(str=='?')break;
  }
  return 0;
}



Measured memory_bytes: 2120
N=int(input())
A=list(map(int,input().split()))
if sum(A)%(N*(N+1)//2)!=0:
    print('NO')
    exit()
ALL=sum(A)//(N*(N+1)//2)
X=[0]*N
if (A[N-1]-A[0]+ALL)%N!=0:
    print('NO')
    exit()
elif (A[N-1]-A[0]+ALL)//N<0:
    print('NO')
    exit()
for i in range(1,N):
    if (A[i-1]-A[i]+ALL)%N!=0:
        print('NO')
        exit()
    elif (A[i-1]-A[i]+ALL)//N<0:
        print('NO')
        exit()
print('YES')

Measured memory_bytes: 15060
#include<bits/stdc++.h>
#define int long long

using namespace std;

int32_t main()
{
    int n, k, t=0;
    cin>>n>>k;
    if(n==k || n==0)
    {
        cout<<0<<endl;
        return 0;
    }
    if(n>k)
        n=n%k;
    if(n<k)
        t=abs(n-k);
    if(t<n)
        cout<<t<<endl;
    else cout<<n<<endl;
}


Measured memory_bytes: 256
N = int(input())
data = [19,
 29,
 59,
 79,
 89,
 109,
 139,
 149,
 179,
 199,
 229,
 239,
 269,
 349,
 359,
 379,
 389,
 409,
 419,
 439,
 449,
 479,
 499,
 509,
 569,
 599,
 619,
 659,
 709,
 719,
 739,
 769,
 809,
 829,
 839,
 859,
 919,
 929,
 1009,
 1019,
 1039,
 1049,
 1069,
 1109,
 1129,
 1229,
 1249,
 1259,
 1279,
 1289,
 1319,
 1399,
 1409,
 1429,
 1439]
res =''
for i in range(N):
    res += str(data[i])
    res += ' '
print(res[:-1])

Measured memory_bytes: 3064
#include<stdio.h>

#define min(a,b) ((a)<(b)?(a):(b))
#define INF 2000000000
int main(){
	int n,i,j;
	long w,wv[2][102]={{0}};
	scanf("%d%ld",&n,&w);
	for(i=1;i<=n;i++)scanf("%ld%ld",&wv[0][i],&wv[1][i]);
	long long dp[102][100002]={{0}};
	for(i=0;i<=100000;i++){
		for(j=0;j<=100;j++){
			dp[j][i]=INF;
		}
	}
	dp[0][0]=0;
	for(i=0;i<=100000;i++){
		for(j=0;j<=n;j++){
			if(i>=wv[1][j])dp[j+1][i]=min(dp[j][i],dp[j][i-wv[1][j]]+wv[0][j]);
			else dp[j+1][i]=dp[j][i];
		}
	}
	long long ans=0;
	for(i=0;i<=100000;i++){
		if(dp[n+1][i]<=w){
			ans=i;
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 79872
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

int main()
{
	int h, w, n; cin >> h >> w >> n;
	int sr, sc; cin >> sr >> sc;
	string s, t; cin >> s >> t;

	int lpos = 0;
	int rpos = w + 1;
	int upos = 0;
	int dpos = h + 1;
	//cout << lpos << " " << rpos << " " << upos << " " << dpos << endl;

	FOR_DW(i, n - 1, 0) {
		if (i != n - 1) {
			switch (t[i]) {
			case 'U':
				if (dpos <= h) dpos++;
				break;
			case 'D':
				if (1 < upos) upos--;
				break;
			case 'L':
				if (rpos <= w) rpos++;
				break;
			case 'R':
				if (1 < lpos) lpos--;
				break;
			}
		}
		switch (s[i]) {
		case 'U': upos++; break;
		case 'D': dpos--; break;
		case 'L': lpos++; break;
		case 'R': rpos--; break;
		}

		//cout << rpos << " " << lpos << " " << dpos << " " << upos << endl;

		if (rpos <= 1 || w <= lpos || dpos <= 1 || h <= upos) {
			cout << "NO" << endl;
			return 0;
		}
		if (rpos - 1 <= lpos || dpos - 1 <= upos) {
			cout << "NO" << endl;
			return 0;
		}
	}

	if (sr <= upos || dpos <= sr || sc <= lpos || rpos <= sc) {
		cout << "NO" << endl;
	}
	else {
		cout << "YES" << endl;
	}

	return 0;
}

Measured memory_bytes: 776
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
using i64 = int64_t;
using namespace std;
int main() {
    int N;
    cin >> N;
    vector<i64> A(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    i64 x = 0;
    for(int i = 0; i < N; i++) {
        x += A[i] * (i % 2 == 0 ? 1 : -1);
    }
    x /= 2;
    cout << x * 2;
    for(int i = 0; i < N - 1; i++) {
        cout << " " << (A[i] - x) * 2;
        x = A[i] - x;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(void){
  ll q,h,s,d,n;
  cin >> q >> h >> s >> d >> n;
  if(h>q*2)h=q*2;
  if(s>h*2)s=h*2;
  if(d>s*2)d=s*2;
  cout << n/2*d+n%2*s;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,b) for(int i=1;i<=b;i++)
#define drep(i,b) for(int i=b;i>=1;i--)
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define pr pair<int,int>
#define ff first
#define ss second
#define int long long
#define endl '\n'
using namespace std;
const int N=2e5+5;
const int mod=1e9+7;
int n,m,k,t,x,y,z;

int poww(int x,int k) {
    if(k==0) return 1;
    int t=poww(x,k/2);
    if(k&1) return t*t*x;
    else return t*t;
}

void solve(int sum=0) {
    cin>>n;
    Rep(i,-200,200) Rep(j,-200,200) {
        if(poww(i,5)-poww(j,5)==n) {
            cout<<i<<' '<<j<<endl;
            return ;
        }
    }
}

#undef int
int main() {
    ios::sync_with_stdio(false);
    //int T;cin>>T;
    //while(T--)
        solve();
}


Measured memory_bytes: 3640
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	r := bufio.NewReader(os.Stdin)
	var n, m int
	var k int64
	fmt.Fscan(r, &n, &m, &k)
	a := make([]int64, n+1)
	b := make([]int64, m+1)
	for i := 0; i < n; i++ {
		var tmp int64
		fmt.Fscan(r, &tmp)
		a[i+1] = a[i] + tmp
	}
	for i := 0; i < m; i++ {
		var tmp int64
		fmt.Fscan(r, &tmp)
		b[i+1] = b[i] + tmp
	}
	var ans int
	j := m
	for i := 0; i <= n; i++ {
		if a[i] > k {
			break
		}
		for b[j] > k-a[i]{
			j--
		}
		if i+j > ans {
			ans = i + j
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 8516
//ProblemB.cpp

#include <iostream>

static std::istream & ip = std::cin;
static std::ostream & op = std::cout;

#if OJ_MYPC
#include <ojio.h>
#endif

#ifndef OPENOJIO
#define OPENOJIO
#endif

#if 1 || DEFINE
/***************************************************************/
typedef unsigned long long u64;
typedef long long s64;

typedef unsigned uint;

#define ABS(x) ((x) > 0 ? (x) : -(x))

#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define MAX(x, y) ((x) > (y) ? (x) : (y))

#define MIN3(x, y, z) MIN(x, MIN(y, z))
#define MAX3(x, y, z) MAX(x, MAX(y, z))

#define FillZero(arr) memset(arr, 0, sizeof(arr));

/***************************************************************/
#endif //1 || DEFINE

#include <string>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#include <stack>
#include <utility>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <cstdio>

//001
//op << setfill('0') << setw(3) << setiosflags(ios::right) << 1;

//op << fixed << setprecision(20);

using namespace std;

//ProblemB.cpp

#define MAXN 100003

int main(int argc, char* argv[])
{
	OPENOJIO;

	int n;
	int a[MAXN];

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

	int rst = 0;

	bool used[MAXN];
	for (int i = 1; i <= n; ++i)
		used[i] = false;

	for (int i = 1; i <= n; ++i) {
		if (used[i]) continue;

		if (i == a[a[i]]) {
			++rst;
			used[i] = used[a[i]] = true;
		}
	}

	op << rst << endl;

	return 0;
}
/***************************************************************/


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1'000'000'007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define rep(i, n) for(ll i=0; i<(ll)(n); i++)
#define repd(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a-1; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define rALL(x) x.rbegin(), x.rend()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

vector<vector<pair<ll, ll>>> g;
vector<ll> color;
void dfs(ll v, ll p=-1, ll c=0){
    color[v] = c;
    for(auto x: g[v]){
        if(x.first==p) continue;
        if(0<=color[x.first]) continue;
        ll nc = c;
        if(x.second%2) nc = 1-nc;
        dfs(x.first, v, nc);
    }
}
int main(){
    ll n;   cin >> n;
    g.resize(n), color.assign(n, -1);
    rep(i, n-1){
        ll a, b, c;    cin >> a >> b >> c;
        a--, b--;
        g[a].emplace_back(b, c);
        g[b].emplace_back(a, c);
    }
    dfs(0);
    rep(i, n) cout << color[i] << endl;
    
}


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

void printArray(int A[], int N){
    
    for(int i=0; i<N; i++){
        cout << A[i];
        if(i<N-1) cout << " ";
    }
    
    cout << endl;
    
}

void flip(int* a, int* b){
    int tmp = *a;
    *a = *b;
    *b = tmp;
}

void selectionSort(int A[], int N){
    
    int flip_count = 0;
    
    for(int i=0; i<N; i++){
        int minj = i;
        for(int j=i; j<N; j++){
            if( A[j] < A[minj] ){
                minj = j;
            }
        }
        if( i != minj ){
            flip(&A[i], &A[minj]);
            flip_count++;
        }
    }
    
    printArray(A, N);
    cout << flip_count << endl;
    
}

int main(int argc, const char * argv[]) {
    
    int N;
    cin >> N;
    
    int A[N];
    for(int i=0; i<N; i++){
        cin >> A[i];
    }
    
    selectionSort(A, N);
    
    return 0;
}



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

using namespace std;
typedef long long ll;

int main() {
    ll h; cin >> h;
    ll ans = 0;
    ll n = 1;
    while (h > 0) {
        h /= 2;
        ans += n;
        n *= 2;
    }
    cout << ans << endl;
}


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

int main(){
    int N;
    cin >> N;
    int p[N],q[N];
    rep(i,N){
        cin >> p[i];
    }
    rep(i,N){
        cin >> q[i];
    }
    int m[N];
    rep(i,N) m[i]=i+1;

    int a,b,count=0;
    do{
        int p_match = memcmp(p, m, sizeof(m));
        int q_match = memcmp(q, m, sizeof(m));
        
        if(p_match==0){
            a = count;
        }
        if(q_match==0){
            b = count;
        }
        count++;
    }while(next_permutation(m, m+N));

    cout << abs(a-b) << endl;
    return 0;
}

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

int main(){
  int a[4];
  for(int i=0;i<4;i++){
    cin >> a[i];
  }
  int left = a[0] + a[1];
  int right = a[2] + a[3];
  if(left>right)cout << "Left" << endl;
  else if(left<right)cout << "Right" << endl;
  else cout << "Balanced" << endl;
  return 0;
}

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


#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());



struct DisjointSet {
    vector<int> par;
    vector<int> rak; // number of the vertices

    void init(int n) {
      par.resize(n);
      rak.resize(n);
      for(int i=0; i<n; i++) {
        par[i] = i;
        rak[i] = 1;
      }
    }

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

    void unite(int x, int y) {
      x = find(x);
      y = find(y);
      if (x==y) return;
      if (rak[x] < rak[y]) {
        rak[y] += rak[x];
        par[x] = y;
      } else {
        rak[x] += rak[y];
        par[y] = x;
      }
    }

    bool same(int x, int y) {
      return find(x) == find(y);
    }
};


class ADisjointSetUnion {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      DisjointSet dsu;
      int n; cin >> n;
      int q; cin >> q;
      dsu.init(n);
      while(q--) {
        int t, u, v; cin >> t >> u >> v;
        if (t == 0) {
          dsu.unite(u, v);
        } else {
          if (dsu.same(u, v)) {
            cout << 1 << '\n';
          } else {
            cout << 0 << '\n';
          }
        }
      }
    }
};

signed main() {
  ADisjointSetUnion solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 4776
#include <bits/stdc++.h>
using namespace std;
 
const int Max = 30;
const int NIL = -1;
int n, id, r, l, p, root;
struct Node
{
    int parent, right, left;
};
Node T[Max];
int D[Max], H[Max];
void setDepth(int u, int d)
{
    if(u==NIL) return;
    D[u] = d;
    setDepth(T[u].left, d+1);
    setDepth(T[u].right, d+1);
}
int setHeight(int u)
{
    int h1 = 0, h2 = 0;
    if(T[u].left!=NIL)
        h1 = setHeight(T[u].left)+1;
    if(T[u].right!=NIL)
        h2 = setHeight(T[u].right)+1;
    return H[u] = max(h1, h2);
}
int getSibling(int u)
{
    int p = T[u].parent;
    if(p==NIL)
        return NIL;
    if(T[p].left!=u && T[p].left!=NIL)
        return T[p].left;
    else if(T[p].right!=u && T[p].right!=NIL)
        return T[p].right;
    return NIL;
}
void print(int u)
{
    printf("node %d: ", u);
    printf("parent = %d, ", T[u].parent);
    printf("sibling = %d, ", getSibling(u));
    int deg = 0;
    if(T[u].left!=NIL) deg++;
    if(T[u].right!=NIL) deg++;
    printf("degree = %d, ", deg);
    printf("depth = %d, ", D[u]);
    printf("height = %d, ", H[u]);
    if(T[u].parent==NIL)
        printf("root\n");
    else if(T[u].left==NIL && T[u].right==NIL)
        printf("leaf\n");
    else
        printf("internal node\n");
}
int main()
{
    cin >> n;
    for(int i=0; i<n; i++)
    {
        T[i].right = T[i].left = T[i].parent = NIL;
    }
    for(int i=0; i<n; i++)
    {
        cin >> id >> l >> r;
        T[id].left = l;
        T[id].right = r;
        if(l!=-1)
        {
            T[l].parent = id;
        }
        if(r!=-1)
        {
            T[r].parent = id;
        }
    }
    for(int i=0; i<n; i++)
    {
        if(T[i].parent==NIL)
        {
            root = i;
            break;
        }
    }
    setDepth(root, 0);
    setHeight(root);
    for(int i=0; i<n; i++)
        print(i);
    return 0;
}


Measured memory_bytes: 3164
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-8;

int main() {
	for (;;) {
		int N; cin >> N;
		if (N == 0) break;
		vector<double> x(N), y(N);
		for (int i = 0; i < N; i++)
			cin >> x[i] >> y[i];
		int maxi = 1;
		for (int i = 0; i < N; i++)
			for (int j = 0; j < N; j++) {
				if (i == j) continue;
				double dx = x[j] - x[i], dy = y[j] - y[i];
				double d = sqrt(dx * dx + dy * dy);
				if (d > 2) continue;
				double h = sqrt(1 - d * d / 4);
				double ox = x[i] + dx / 2 - dy / d * h;
				double oy = y[i] + dy / 2 + dx / d * h;
				int cnt = 0;
				for (int k = 0; k < N; k++) {
					double dx = x[k] - ox, dy = y[k] - oy;
					double d = sqrt(dx * dx + dy * dy);
					if (d <= 1 + EPS) cnt++;
				}
				maxi = max(maxi, cnt);
			}
		cout << maxi << endl;
	}
}

Measured memory_bytes: 1244
#include<iostream>
using namespace std;
int a,b,cnt;
char c;
main(){
    cin>>a>>b;
    for(int i=0;i<a;i++){
        for(int j=0;j<b;j++){
            cin>>c;
            if(c=='#')cnt++;
        }
    }
    cout<<(cnt==a+b-1 ? "Possible" : "Impossible")<<endl;
}

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

using namespace std;

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define fst first
#define snd second
#define SZ(u) ((int) (u).size())
#define ALL(u) (u).begin(), (u).end()

inline void proc_status()
{
    ifstream t("/proc/self/status");
    cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline T read()
{
	register T sum(0), fg(1);
	register char ch(getchar());
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') fg = -1;
	for(;  isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) - '0' + ch;
	return sum * fg;
}

typedef long long LL;
typedef long double LD;
typedef pair<int, int> pii;

const int MAXN = (int) 2e3;

int n, K, Q;

int A[MAXN + 5];

inline void input()
{
	n = read<int>(), K = read<int>(), Q = read<int>();
	for(int i = 1; i <= n; ++i) A[i] = read<int>();
}

inline void solve()
{
	static pii a[MAXN + 5];

	for(int i = 1; i <= n; ++i) a[i] = mp(A[i], i);

	int ans = INT_MAX;
	sort(a + 1, a + n + 1);
	for(int i = 1; i <= n; ++i)
	{
		static int id[MAXN + 5], size[MAXN + 5], cnt;

		cnt = 0;
		for(int j = 1; j <= n; ++j) id[j] = 0;
		for(int j = 1; j <= n; ++j) if(A[j] >= a[i].fst) ++size[id[j] = id[j - 1] ? id[j - 1] : (size[++cnt] = 0, cnt)];

		int mx = 0, res = Q;
		for(int j = i; j <= n && res; ++j)
			if(size[id[a[j].snd]] >= K)
			{
				--size[id[a[j].snd]], --res;
				mx = a[j].fst;
			}
		if(res == 0) chkmin(ans, mx - a[i].fst);
	}
	printf("%d\n", ans);
}

int main()
{
//	freopen("E.in", "r", stdin);
//	freopen("E.out", "w", stdout);

	input();
	solve();

	return 0;
}



Measured memory_bytes: 256
//Minor Change
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <map>
#include <stdio.h>
#include <string.h>
#include <initializer_list>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <queue>
#include <set>
using namespace std;
const int INF = 1 << 29;
int main ()
{
    string  S,T;
    cin >> S >> T;
    int ans = 0;
    for (int i = 0; i < S.length(); i++) {
        if (S[i] != T[i]) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3492
# include <stdio.h>
#include <stdlib.h>
int main()
{
	int a,b;
	scanf("%d",&a);
	char z;
	z = getchar();
	char c;
	c = getchar();
	char x;
	x = getchar();
	scanf("%d", &b);
	int e, f;
	if (c==43)
	{
		e = a + b;
		printf("%d\n", e);
	}
	if (c==45)
	{
		f = a - b;
		printf("%d\n", f);
	}
	system("pause");
}


Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1e9+1;

/*
mの約数で、m/x>=nを満たす最大のx
*/

std::vector<int> enum_div(int n)//nの約数を列挙
{
	std::vector<int> ret;
	for(int i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i!=1 && i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}


void solve(){
    int n, m;
    cin >> n >> m;
    //int thres = ceil(sqrt(m));
    int thres = m;
    int ans=1;
    vector<int> v = enum_div(m);
    //if(n==1) ans = m;
    int s = v.size();
    /*
    for(int i=s-1; i>=0; i--){
        int x=v[i];
        if(m/x>=n){
            ans = x;
            break;
        }
    }
    */
    for(int i=n; i<=m/2+1; i++){
        if(m%i==0){
            ans = m/i;
            break;
        }
    }
    cout << ans << endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}


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

namespace ConsoleApp5
{
    class Program
    {

        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            String S = Console.ReadLine();
            String[] line = S.Split(' ');

            int[] P = new int[N];           
            for(int i=0; i<N; i++)
            {
                P[i] = int.Parse(line[i]);
            }

            int min = N + 1;
            int ans = 0;

            for(int i=0; i<N; i++)
            {
                if(P[i] <= min)
                {
                    min = P[i];
                    ans++;
                }

            }

            Console.WriteLine(ans);
       



        }
    }
}

Measured memory_bytes: 33540
#include<iostream>
using namespace std;
int main() {
	int A, B, C;
	cin >> A >> B >> C;
	if (A == B ||  B == C || A == C) {
		if (A == B && B == C) {
			cout << "No" << endl;
		}else{
			cout << "Yes" << endl; 
		}
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

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

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = 1e9 + 7;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, k;
    cin >> n >> k;

    cout << (n % k == 0 ? 0 : 1) << endl;
}


Measured memory_bytes: 256
def solve():
  N = int(input())
  A = list(map(int, input().split()))
  B = [abs(a) for a in A]
  ans = sum(B)
  under = [a for a in A if a<0]
  if len(under)%2==1:
    ans -= min(B)*2
  return ans
print(solve())

Measured memory_bytes: 20080
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(1000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
a=list(map(int,input().split()))
uv=[list(map(int,input().split())) for i in range(n-1)]
edge=defaultdict(list)
for i in range(n-1):
    u,v=uv[i]
    edge[u].append(v)
    edge[v].append(u)
# print(edge)

itta=[0]*(n+1)
# lislist=[0]*(n+1)

def dfs(now,lis):
    stk=0
    if a[now-1]>lis[-1]:
        lis.append(a[now-1])
        stk="pop"
    else:
        tmp=bisect.bisect_left(lis, a[now-1])
        stk=[tmp,lis[tmp]]
        lis[tmp]=a[now-1]
    
    # print(now,lis)
    itta[now]=len(lis)
    for i in edge[now]:
        if itta[i]==0:
            dfs(i,lis)
    
    if stk=="pop":
        lis.pop()
    else:
        lis[stk[0]]=stk[1]

dfs(1,[float('inf')])

# print(itta)
for i in range(n):
    print(itta[i+1])

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

int main(){
    int table[101] = {0};
    int n, tmp;
    
    while(cin >> n){
        table[n]++;
    }
    
    for(int i = 1;i <= 100;i++){
        if(table[i] > tmp){
            tmp = table[i];
        }
    }
   
    for(int i = 1;i <= 100;i++){
        if(tmp == table[i]){
            cout << i << endl;
        }
    }
          
    return 0;
}

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

#define FAST ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define REP(i,a,n) for (ll i=a;i<n;i++)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define show(x) cout<<(x)<<endl
#define UM unordered_map
#define PB push_back
#define V vector
#define EPS 1e-8
typedef unsigned long ul;
typedef long long ll;
typedef string str;
/*FIN*/

ll power(ll x, ll n, ll m) {
	if(x==0) return 0;
	if(n==0) return 1;
	ll y;
	if(n&1) {
		y = x%m;
		y = (y*power(x,n-1,m) % m) % m;
	} else {
		y = power(x,n>>1,m);
		y = (y*y)%m;
	}
	return ((y+m) % m);
}

int main() {
	FAST;
	ll n;
	str x;
	cin>>n;
	cin>>x;
	ll b=0;
	REP(i,0,n) b+=(x[i]=='1');
	if(b > 1) {
	ll num1=0, num2=0;
	reverse(ALL(x));
	REP(i,0,n) {
		if(x[i]=='1') {
			num1 = (num1 + power(2,i,b+1))%(b+1);
			num2 = (num2 + power(2,i,b-1))%(b-1);
		}
	}
	ll dp[n+1];
	dp[0]=0;
	dp[1]=1;
	REP(i,2,n+1) {
		ll j = __builtin_popcountll(i);
		dp[i] = 1 + dp[i%j];
	}
	REP(i,0,n) {
		ll m = n-i-1;
		if(x[m]=='0')
			show(1+dp[(num1+power(2,m,b+1))%(b+1)]);
		else
			show(1+dp[(num2-power(2,m,b-1)+b-1)%(b-1)]);
	}
	} else if(b==1) {
	ll num1 = (x[n-1]=='1');
	REP(i,0,n-1) {
		if(x[i]=='1') show(0);
		else show(1+num1);
	}
	show(x[n-1]=='1'?0:2);
	} else {
		REP(i,0,n) show(1);
	}
	return 0;
}


Measured memory_bytes: 5336
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] a) {
		BufferedReader br;
		br = new BufferedReader(new InputStreamReader(System.in));
		int[] num = new int[2];
		String str;
		try {
			while ((str = br.readLine()) != null) {

				String[] array = str.split(" ");
				for (int h = 0; h < array.length / 2; h++) {
					for (int i = 0; i < 2; i++) {
						num[i] = Integer.parseInt(array[i + h * 2]);
					}
					int answer = (int) Math.log10(num[0] + num[1]) + 1;
					System.out.println(answer);
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		}

	}
}

Measured memory_bytes: 24564
n=int(input())
a=list()
for i in range (n):
    a.append(int(input()))
new_a_reverse=sorted(a,reverse=True)
max=new_a_reverse[0]
max2=new_a_reverse[1]
for i in a:
    if(i==max):
        print(max2)
    else:
        print(max)


Measured memory_bytes: 14112
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

vector<bool> diff;
vector<vector<pair<ll, ll>>> net;
vector<bool> visited;
vector<bool> used;

bool dfs(ll cur){
    visited.at(cur) = true;
    ll tmp = 0;
    for(const auto edge : net.at(cur)){
        const ll nxt = edge.first;
        const ll eid = edge.second;
        if(visited.at(nxt)){ continue; }
        if(dfs(nxt)){
            used.at(eid) = true;
            tmp += 1;
        }
    }
    return (diff.at(cur) + tmp) % 2;
}

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

    vector<pair<ll, ll>> ab;
    ab.emplace_back(0, 0);
    REP(i, n){
        ll ai, bi;
        cin >> ai >> bi;
        ab.emplace_back(ai, bi);
    }
    ab.emplace_back(ll(1e9) + 1, 0);
    assert(ab.size() == n + 2);
    sort(ab.begin(), ab.end());

    diff.resize(n + 1);
    REP(i, n + 1){
        if(ab.at(i).second != ab.at(i + 1).second){
            diff.at(i) = true;
        }else{
            diff.at(i) = false;
        }
    }

    net.resize(n + 1);
    REP(i, m){
        ll li, ri;
        cin >> li >> ri;
        ll lidx = lower_bound(
            ab.begin(), ab.end(), make_pair(li, 0LL)) - ab.begin();
        ll ridx = upper_bound(
            ab.begin(), ab.end(), make_pair(ri, 1LL)) - ab.begin();
        assert(lidx <= ridx);
        assert(ridx <= n + 1);
        assert(lidx >= 1);
        lidx--; ridx--;
        net.at(lidx).emplace_back(ridx, i);
        net.at(ridx).emplace_back(lidx, i);
    }

    visited.resize(diff.size());
    fill(visited.begin(), visited.end(), false);
    used.resize(m);
    fill(used.begin(), used.end(), false);

    REP(i, n + 1){
        if(visited.at(i)){ continue; }
        if(dfs(i)){
            cout << -1 << endl;
            return 0;
        }
    }

    ll num = accumulate(used.begin(), used.end(), 0LL);
    cout << num << endl;
    REP(i, used.size()){
        if(used.at(i)){
            cout << i + 1;
            num--;
            if(num > 0){
                cout << ' ';
            }else if(num == 0){
                cout << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 20592
# coding: utf-8
# Your code here!

S = input()

list = []
for s in S : 
    if s not in list : 
        list.append(s)

cnt = 0        
for s in S : 
    if s == list[0] : 
        cnt += 1
        
if len(list) == 2 and cnt == 2 : 
    print("Yes")
else : 
    print("No")

Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <cstring>

using Graph = std::vector<std::vector<uint32_t>>;

int32_t dp[100100];
Graph G;

uint32_t rec(uint32_t v) {
  if (dp[v] != -1) return dp[v];

  uint32_t ret = 0;
  for (auto &nv: G[v]) {
    ret = std::max(ret, rec(nv) + 1);
  }

  return dp[v] = ret;
}

int main() {
  //std::memset(dp, -1, 100100);

  uint32_t N, M;

  std::cin >> N >> M;
  G.resize(N);

  for (uint32_t i = 0; i < M; i++) {
    uint32_t x, y;
    std::cin >> x >> y;
    G[x - 1].push_back(y - 1);
  }

  for (int v = 0; v < N; ++v) dp[v] = -1;

  uint32_t ret = 0;
  for (uint32_t i = 0; i < N; i++) {
    ret = std::max(rec(i), ret);
  }

  std::cout << ret << std::endl;

  return 0;
}

Measured memory_bytes: 8192
import sys
sys.setrecursionlimit(2147483647)
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
input = lambda:sys.stdin.readline().rstrip()
from functools import cmp_to_key
def resolve():
    n = int(input())
    first, second, third = [], [], []
    for _ in range(n):
        balance = min_balance = 0
        for c in input():
            if c == '(':
                balance += 1
            else:
                balance -= 1
            min_balance = min(min_balance, balance)
        if min_balance == 0:
            first.append((min_balance, balance))
        elif balance > 0:
            second.append((min_balance, balance))
        else:
            third.append((min_balance, balance))

    now = 0
    # first は何も考えず足せば良い
    for min_balance, balance in first:
        now += balance

    # second は min_balance の大きい方から足せば良い
    second.sort(reverse = 1)
    for min_balance, balance in second:
        if now + min_balance < 0:
            print("No")
            return
        now += balance

    # third は sort を工夫
    def cmp(s1, s2):
        m1, b1 = s1
        m2, b2 = s2
        return -1 if min(m1, b1 + m2) > min(m2, b2 + m1) else 1

    third.sort(key = cmp_to_key(cmp))
    for min_balance, balance in third:
        if now + min_balance < 0:
            print("No")
            return
        now += balance

    print("Yes" if now == 0 else "No")
resolve()

Measured memory_bytes: 176768
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using st=string;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
#define mp make_pair
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
st abc="abcdefghijklmnopqrstuvwxyz";
st ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

int main() {
    ll n,m,k;
    cin >> n >> m >> k;
    vl a(n),b(m);
    vl sa(n+1),sb(m+1);
    sa[0]=0,sb[0]=0;
    rep(i,n){
        cin >> a[i];
        sa[i+1]=sa[i]+a[i];
    }
    rep(i,m){
        cin >> b[i];
        sb[i+1]=sb[i]+b[i];
    }
    ll mx=m;
    ll ans=0;
    rep(i,n+1){
        ll t=k-sa[i];
        if(t<0){
            continue;
        }
        while(sb[mx]>t){
            mx--;
        }
        ans=max(ans,i+mx);
    }
    cout << ans << endl;
}

Measured memory_bytes: 9596
#include <cstdio>
#include <algorithm>
using namespace std;
int n, x, b[500029];
int main() {
	scanf("%d", &n);
	int r = 1, sum = 0;
	for (int i = 0; i < n; i++) {
		scanf("%d", &x);
		if (b[0]) puts("No");
		else if (x >= 500020) puts("Yes");
		else {
			while (b[r]) r++;
			if (r <= x) {
				puts("Yes");
				int z = x; b[z]++, sum++;
				while (b[z] == 2) b[z] = 0, b[--z]++, sum--;
				r = min(r, z + 1);
			}
			else {
				if (sum == x) puts("Yes"), b[0] = 1;
				else puts("No");
			}
		}
	}
	return 0;
}

Measured memory_bytes: 4580
#include <iostream>

int main(void)
{
    int a, b;
    int result;
    char c;
    while (true) {
        std::cin >> a;
        std::cin >> c;
        std::cin >> b;
        if (c == '?') {
            break;
        }
        if (c == '+') {
            result = a + b;
        } else if (c == '-') {
            result = a - b;
        } else if (c == '*') {
            result = a * b;
        } else if (c == '/') {
            result = (int)(a / b);
        } 
        std::cout<< result <<std::endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)     for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = m; i < (int)(n); i++)
#define MOD 1000000007
#define Graph vector<vector<int>>

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

  vector<int> Li;

  rep(i,N){
    int tmpLn;
    cin >> tmpLn;
    Li.push_back(tmpLn);
  }

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

  int ans = 0;
  rep2(i,1,N){
    rep2(j,i+1,N){
        int b = Li.at(i);
        int c = Li.at(j);
        vector<int>::iterator position;
        int idx_lower;
        
        position = upper_bound(Li.begin(), Li.end(), c-b);
        auto minidx = distance(Li.begin(), position);
        if(minidx >= i) continue;
        ans += i - minidx;
    }
  }

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



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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define pb push_back
#define mp make_pair
#define IN freopen("C.in","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG printf("Hi\n")
#define i64 long long int
#define ui64 unsigned long long int
#define eps (1e-6)
#define xx first
#define yy second
#define ln 17
#define off 2

#define sq(x) ((x)*(x))

#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace __gnu_pbds;
using namespace std ;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<int,int> pii;

#define log 20
#define mod 1000000007LL
#define INF 1000000000
#define maxn 200005

vector <int> g[maxn] ;
int dp[maxn] ;

void dfs(int u, int par)
{
    int cnt[25] ;
    memset(cnt,0,sizeof(cnt)) ;

    for(int i=0 ; i<g[u].size() ; i++)
    {
        int v = g[u][i] ;
        if(v==par) continue ;
        dfs(v,u) ;

        for(int j=0 ; j<20 ; j++)
        {
            if( (dp[v]&(1<<j)) ) cnt[j]++ ;
        }
    }
    int myCol = 0;
    for(int i=20-1 ; i>=0 ; i--)
    {
        if(cnt[i]>1)
        {
            myCol = i+1 ;
            break ;
        }
    }
    while(cnt[myCol]) myCol++ ;
    dp[u] |= (1<<myCol) ;
    for(int i=myCol+1 ; i<20 ; i++)
    {
        if(cnt[i]) dp[u] |= (1<<i) ;
    }
}

int main()
{
    int n ;

    scanf("%d",&n) ;

    for(int i=1 ; i<n ; i++)
    {
        int u , v ;
        scanf("%d %d",&u,&v) ;
        g[u].pb(v) ; g[v].pb(u) ;
    }

    dfs(1,0) ;

    int ans = 0 ;
    while( dp[1] > 0 )
    {
        dp[1] /= 2 ;
        ans++ ;
    }

    printf("%d\n",ans-1) ;

    return 0 ;
}


Measured memory_bytes: 25452
import sys
s=input()
n=len(s)
s1=s
s1_rev=s1[::-1]

s2=s
s2=s2[:(n-1)//2]
s2_rev=s2[::-1]

s3=s
s3=s3[((n+3)//2)-1:]
s3_rev=s3[::-1]

if s != s1_rev:
    print('No')
    sys.exit(0)
if s2 != s2_rev:
    print('No')
    sys.exit(0)
if s3 != s3_rev:
    print('No')
    sys.exit(0)

print('Yes')

Measured memory_bytes: 3064
//----AUTHOR:kkdrummer----/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include<ext/rope>
using namespace __gnu_cxx;
using namespace __gnu_pbds;
using namespace std;
typedef    long long   ll;
typedef    long double   ld;
typedef    complex<ld>   P;
#define    X   real()
#define    Y   imag()
ld restant(P p){return abs(p);}
//polar(x,y) mag=l,arg=y
//typedef    unordered_set<ll>   usll;
//typedef    unordered_multiset<ll>   umsll;
typedef    multiset<ll>   msll;
typedef    set<ll>   sll;
typedef    vector<ll>   vll;
typedef    pair<ll,ll>   pll;
typedef    vector<pair<ll,ll> >   vpll;
typedef    priority_queue<ll>   pqll;
typedef    vector<int>   vi;
typedef    set<int>   si;
typedef    multiset<int>   msi;
//typedef    unordered_multiset<int>   umsi;
//typedef    unordered_set<int>   usi;
typedef     pair<int,int>   pi;
typedef    vector<pair<int,int> >   vpi;
typedef    vector<pair<double,double> >   vpd;
typedef    pair<double,double>   pd;
typedef    priority_queue<int>   pqi;
typedef    tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>   ind_set;
typedef    tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>   ind_setll;
#define    in   insert
#define    fi   first
#define    se   second
#define    pb   push_back
#define    mp   make_pair
#define    be   begin
#define    en   end
#define    itr   iterator
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define    mo   1000000007
#define    inf   1000000000000000001
#define    ninf   -1000000000000000001
#define    ima   1000000001
#define    imi   -1000000001
#define    oncnt    __builtin_popcount
#define    zerobegin   __builtin_clz
#define    zeroend   __builtin_ctz
#define    parity   __builtin_parity
#define all(x) x.be(),x.en()
#define    eps   1e-9
const    ld   PI=3.14159265359;
inline ll modpow(ll x,ll n){if(n==0)return 1;if(n==1)return(x%mo);ll u=(modpow(x,n/2));u=(u*u)%mo;if(n%2!=0)u=(u*x%mo)%mo;return u;}
inline ll modinv(ll x){return modpow(x,mo-2);}
inline ll mmul(ll a,ll b){    if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll madd(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a+b>=mo)return(a+b)%mo;return(a+b);}
inline ll msub(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;return((a-b+mo)%mo);}
inline ll mdiv(ll a,ll bb){if(a>=mo)a=a%mo;ll b=modinv(bb);if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll gcd(ll a,ll b){return __gcd(a,b);}

int main()
{
io
int testcases=1;//cin>>testcases;
while(testcases--)
{	
int n;
cin>>n;
cout<<((n)*(n+1))/2;

}return 0;}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>
#include <bitset>

using namespace std;

typedef long long ll;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  int n;
  cin >> n;
  vector <int> a(3 * n);
  for (int i = 0; i < 3 * n; ++i) cin >> a[i];
  sort(a.begin(), a.end());
  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    a.pop_back();
    ans += a.back();
    a.pop_back();
  }
  cout << ans << '\n';
}


Measured memory_bytes: 1408
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double N = Double.parseDouble(sc.next());
		ArrayList<Double> list = new ArrayList<>();
		for(int i = 0; i< N; i++) {
			list.add(Double.parseDouble(sc.next()));
		}
		sc.close();

		double sum = 0;
		for(int i = 0; i< N; i++) {
			sum += 1 / list.get(i);
		}
		double ans = 1 / sum;
		System.out.println(ans);
	}

}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX_N = 201010;

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

ll dx[4] = { 0,0,-1,1 };
ll dy[4] = { -1,1,0,0 };
ll ans[110][110];
bool flag[2][110];
using edge = struct { ll to;ll cost; };
vector<edge>tree[101010];
ll depth[101010];

void dfs(ll v, ll p, ll d) {
	depth[v] = d;
	for (auto nv : tree[v]) {
		if (nv.to == p)continue;
		dfs(nv.to, v, d + nv.cost);
	}
}

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	ll n;
	cin >> n;
	rep(i, n-1) {
		ll a, b, c;
		cin >> a >> b >> c;
		a--, b--;
		tree[a].push_back({ b,c });
		tree[b].push_back({ a,c });
	}
	ll q, k;
	cin >> q >> k;
	k--;
	dfs(k, -1, 0);
	rep(i, q) {
		ll x, y;
		cin >> x >> y;
		x--, y--;
		cout << depth[x] + depth[y] << endl;
	}
	return 0;
}


Measured memory_bytes: 16168