akhauriyash/Code-Regression huggingface dataset:
/**
*    created: 29.06.2020 18:26:01
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pcnt(bit) __builtin_popcountll(bit)
using namespace std;
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;}
const int mod = 1000000007;
const long double pi = acos(-1.0);
const int inf = 1LL << 60;

signed main() {

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

    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = -1;
    
    for (int i = 1; i <= n-1; i++) {
        map<char,int> mp1;
        map<char,int> mp2;
        string s1 = s.substr(0,i);
        string s2 = s.substr(i,n-i+1);
        rep(j,s1.size()) mp1[s1[j]]++;
        rep(j,s2.size()) mp2[s2[j]]++;
        int cnt = 0;
        for (auto p : mp1) if (p.second > 0 && mp2[p.first] > 0) cnt++;
        chmax(ans,cnt);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main(){
    long n,ans = 0;
    cin >> n;
    long a[n],b[n],c[n],cnt=0;
    for(int i=0;i<n;i++) cin >> a[i];
    for(int i=0;i<n;i++){
        cin >> b[i];
        c[i] = a[i] - b[i];
    }
    for(int i=0;i<n;i++){
        if(c[i]<0){
            cnt += c[i];
            ans++;
        }
    }
    sort(c,c+n);
    for(int i=n-1;0<=i;i--){
        if(c[i]>0&&cnt<0){
            cnt += c[i];
            ans++;
        }
    }
    if(0<=cnt) cout << ans << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 2560
import std.stdio, std.string, std.conv, std.array;

void main()
{
	while(true) {
		string[] input = split(chomp(readln));
		int N = to!int(input[0]);
		if(N == 0) break;

		int l,r;

		for(int n=0; n<N; n++) {
			input = split(chomp(readln));
			int a = to!int(input[0]);
			int b = to!int(input[1]);

			if(a>b) l += a + b;
			if(a<b) r += a + b;
			if(a==b) { l += a; r += b; }
		}

		writefln("%d %d", l, r);
	}
			
}

Measured memory_bytes: 1804
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N;
    cin >> N;
    vector<int> A(N), B(N), C(N-1);

    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
    }
    for (int i = 0; i < N; i++) {
        cin >> B.at(i);
    }
    for (int i = 0; i < N-1; i++) {
        cin >> C.at(i);
    }

    int count = 0;

    for (int i = 0; i < N; i++) {
      count += B.at(A.at(i)-1);
      if (i == 0) ;
      else if (A.at(i) == A.at(i-1) + 1) {
          count += C.at(A.at(i-1)-1);
      }
    }

    cout << count << endl;
    
}

Measured memory_bytes: 256
import java.util.Scanner;

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


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

using namespace std;

int main()
{
    int N;
    cin>>N;
    vector<long long> A(N);
    for (long long &a: A)
        cin>>a;
    sort(A.begin(), A.end());
    auto check = [&](int p)
    {
        if (p>=N)
            return true;
        long long t = A[p];
        for (int i=0; i<N; i++)
        if (i != p)
        {
            if (A[i]>2*t)
                return false;
            t += A[i];
        }
        return true;
    };

    if (check(0))
    {
        cout<<N<<endl;
        return 0;
    }

    int b = 1;
    while (b<N)
        b *= 2;
    int ans = 0;
    for (; b>0; b/=2)
    {
        if (!check(ans+b))
            ans += b;
    }
    cout<<N-ans-1<<endl;
}


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

int main() {
  
  string A, B;
  cin >> A >> B;
  int total = 0;
  
  
  
  int a,b;
  a = atoi(A.c_str());
  b = atoi(B.c_str());
  
  string c;
  c = to_string(a);
  	
  
  for (int i = a; i <= b; i++){
    
    string c;
  	c = to_string(i);
    
    if (c.at(0) == c.at(4)){
      if (c.at(1) == c.at(3)){
        total = total + 1;
      }
    }
    
  }
 
  	cout << total << endl;
 

 }

Measured memory_bytes: 3692
import java.util.HashSet;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int N = scn.nextInt();
		HashSet<Integer> arr = new HashSet<Integer>();
		boolean yes = true;
		for (int i = 0; i < N; i++) {
			int a = scn.nextInt();
			if (arr.contains(a)) {
				yes = false;
				break;
			} else {
				arr.add(a);
			}
		}
		System.out.println(yes ? "YES" : "NO");
	}

}


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

#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define mem(x,val) memset((x),(val),sizeof(x))
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define PI acos(-1.0) 
#define N 111111

const int INF = 1 << 30 ;
typedef long long ll ;
typedef pair < int , int > pii ;

int main() {
  int n , number = 1 , pow = 0 ;
  scanf("%d",&n) ;

  while((number<<pow)<=n){
    pow++ ;

  }
  printf("%d", number<<(pow-1)) ; 
	
  return 0 ;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(1000000000)

N, A, B, C = map(int, input().split())

L = [0] * N
l = []
for _ in range(N):
    L[_] = int(input())
for _ in range(4):
    l.append(_)

X = []
ans = float('inf')


def clear(X):
    global ans
    if len(X) == N:
        Z = [0]*4
        Znum = [0]*4
        for num, i in enumerate(X):
            Znum[i] += 1
            Z[i] += L[num]
        if 0 in Znum[1:]:
            return True
        ansi = abs(A - Z[1]) + abs(B - Z[2]) + abs(C - Z[3]) + (N - Znum[0] - 3) * 10
        ans = min(ans, ansi)
        return True
    else:
        for j in range(4):
            X.append(l[j])
            clear(X)
            X.pop()


clear(X)
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <climits>

using namespace std;

int main() {
	int n;

	while( true ) {
		cin >> n;

		if(n == 0) {
			break;
		}

		vector< int > dp(n + 1, 0);

		dp[0] = 1;

		for(int i = 1; i <= n; i++) {
			for(int j = -1; j >= -3; j--) {
				if(i + j < 0) {
					continue;
				}
				dp[i] += dp[i + j];
			}
		}

		int count = dp[n] / 10;
		if(dp[n] % 10 != 0) {
			count++;
		}

		int year = count / 365;
		if(count % 365 != 0) {
			year++;
		}

		cout << year << endl;
	}
}

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

int main() {
  string s; cin >> s;
  int ans1 = 0;
  int ans2 = 0;
  
  for (int i = 0; i < s.size(); i++) {
    if (i % 2 == 0) {
      if (s[i] == '0') ans1++;
    } else {
      if (s[i] == '1') ans1++;
    }
  }
  
  for (int i = 0; i < s.size(); i++) {
    if (i % 2 == 0) {
      if (s[i] == '1') ans2++;
    } else {
      if (s[i] == '0') ans2++;
    }
  }
  
  cout << min(ans1, ans2) << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define all(x) (x).begin(), (x).end()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end());
// map<int,int> mp;

int main() {
  string S,T;
  cin >> S>>T;
  if(S==T.erase(T.size()-1)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

}

Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

#include <sstream>
#include <istream>

using namespace std;

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

int main(){
	int n;
	cin >> n;
	char s[100001];
	cin >> s;

	int num[26];
	for(int i=0;i<26;i++) num[i] = 1;

	for(int i=0;i<n;i++){
		num[s[i]-'a']++;
	}

	long long ans = 1;
	for(int i=0;i<26;i++){
		ans *= num[i];
		ans %= 1000000007;
	}
	ans--;

	cout << ans << endl;

	return 0;
}


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

long long int culc(string &s, vector<int>& plus){  
  long long int tmp = 0, res = 0;
  for(int i = 0; i < (int)s.length(); i++){
    tmp = tmp * 10 + (s[i] - '0');
    if(plus[i] == 1){
      res += tmp;
      tmp = 0;
    }
  }
  res += tmp;
  return res;
}


int main(void){
  string s;
  cin >> s;

  long long int res = 0;
  long long int le = s.length();
  vector<int> i(9, 0);

  for(i[0] = 0; i[0] < 2; i[0]++){
    for(i[1] = 0; i[1] < 2; i[1]++){
      for(i[2] = 0; i[2] < 2; i[2]++){
        for(i[3] = 0; i[3] < 2; i[3]++){
          for(i[4] = 0; i[4] < 2; i[4]++){
            for(i[5] = 0; i[5] < 2; i[5]++){
              for(i[6] = 0; i[6] < 2; i[6]++){
                for(i[7] = 0; i[7] < 2; i[7]++){
                  for(i[8] = 0; i[8] < 2; i[8]++){
                    res += culc(s, i);
                    if(le <= 9){ break; }
                  }
                  if(le <= 8){ break; }
                }
                if(le <= 7){ break; }
              }
              if(le <= 6){ break; }
            }
            if(le <= 5){ break; }
          }
          if(le <= 4){ break; }
        }
        if(le <= 3){ break; }
      }
      if(le <= 2){ break; }
    }
    if(le <= 1){ break; }
  }
  

  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin >> n;
    long long int min =10000000;
    long long int max =-10000000;
    long long int x, sum=0;
    for(int i=0;i<n;i++){
        cin >> x;
        if (min > x){
            min = x;
        }
        if (max < x){
            max = x;
        }
        sum =sum + x;
    
    }
    cout << min <<" ";
    cout << max <<" ";
    cout << sum <<endl;
    
}



Measured memory_bytes: 3100
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <map>
#include <iomanip>
#include <cmath>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;
namespace mp = boost::multiprecision;

int main()
{
    // 整数の入力
    ll H,W;
    cin >> H >> W;
    if (H == 1 || W == 1){
        cout << 1 << endl;
    }else if (H % 2 == 0 || W % 2 == 0){
        cout << H * W / 2 << endl;
    }else{
        cout << H * W / 2 + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <map>
#include <algorithm>
#include <stdio.h>
#include <set>

using namespace std;

int main() {
    int k;
    int a, b;
    cin >> k >> a >> b;
    int ans = 0;
    for(int i = a; i <= b; i++){
        if(i % k == 0){
            ans = 1;
            break;
        }
    }
    if(ans){
        cout << "OK" << endl;
    } else {
        cout << "NG" << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>

using namespace std;

int main() {
  string sa, sb, sc;
  int ap = 0, bp = 0, cp = 0;
  cin >> sa >> sb >> sc;

  char c = 'a';

  while (true) {
    if (c == 'a') {
      if (sa.size() <= ap) {
        cout << 'A' << endl;
        break;
      }
      c = sa[ap++];
    } else if (c == 'b') {
      if (sb.size() <= bp) {
        cout << 'B' << endl;
        break;
      }
      c = sb[bp++];
    } else if (c == 'c') {
      if (sc.size() <= cp) {
        cout << 'C' << endl;
        break;
      }
      c = sc[cp++];
    }
  }

  return 0;
}


Measured memory_bytes: 3104
import sys,collections as cl,bisect as bs,math
sys.setrecursionlimit(100000)
Max = sys.maxsize
def l():
    return list(map(int,input().split()))
def m():
    return map(int,input().split())
def onem():
    return int(input())
def s(x):
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa == x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x):
    return " ".join(map(str,x))

q = onem()
AAAA = [sorted(l()) for i in range(q)]

for a,b in AAAA:
    x = math.sqrt(a*b)
    y = int(x)
    if x == y:
        if a == b:
            print(y*2 -2)
        else:
            print(y*2 -3)
    else:
        if y*(y+1)< a*b:
            print(y*2-1)
        else:
            print(y*2-2)

Measured memory_bytes: 3444
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define SF scanf
#define PF printf
#define MAXN 100010
using namespace std;
typedef long long ll;
int n;
ll a,b,c,d;
ll gcd(ll x,ll y){
    if(y==0)
        return x;
    return gcd(y,x%y);
}
int main(){
    SF("%d",&n);
    while(n--){
        SF("%lld%lld%lld%lld",&a,&b,&c,&d);
        if(a<b){
            PF("No\n");
            continue;
        }
        if(b>d){
            PF("No\n");
            continue;
        }
        if(c+1>=b){
            PF("Yes\n");
            continue;
        }
        ll g=gcd(b,d);
        if((a-c-1ll)/g-(a-b)/g>0)
            PF("No\n");
        else
            PF("Yes\n");
    }
} 

Measured memory_bytes: 128
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut 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! 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")
    };
}

// x ** n % mods を求める
pub fn mod_pow(x: i64, n: i64, mods: i64) -> i64 {
    if n == 0 {
        return 1;
    }
    let mut res = mod_pow(x * x % mods, n / 2, mods);
    if n % 2 == 1 {
        res = res * x % mods;
    }
    return res;
}

// (1/n) % mods を求める
pub fn mod_inv(n: i64, mods: i64) -> i64 {
    return mod_pow(n, mods-2, mods);
}

// nCk % mods を求める
pub fn mod_comb(n: i64, k: i64, mods: i64) -> i64 {
    let sum1 = (n-k+1..n+1).fold(1, |ac, x| ac * x % mods);
    let sum2 = (1..k+1).fold(1, |ac, x| ac * x % mods);
    return sum1 * mod_inv(sum2, mods) % mods;
}


fn main() {
    input!{
        s: usize,
        w: usize,
    }
    if s > w {
        println!("safe");
    }
    else {
        println!("unsafe");
    }
}


Measured memory_bytes: 2048
using System;

    class Program
    {
        static void Main()
        {
            int num = 0;
            string searchWord = Console.ReadLine().ToLower();
            while (true)
            {
                string[] line = Console.ReadLine().Split(' ');

                foreach (string word in line)
                {
                    if (word == "END_OF_TEXT")
                        goto FINISH;
                    else if (word.ToLower() == searchWord)
                        num++;
                }
            }
            FINISH:
                Console.WriteLine(num.ToString());
        }
    }

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

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

    queue<int> w;
    int cnt = 0;
    rep(i, n){
        if(c.at(i)=='W') w.push(i);
        else{
            if(!w.empty()){
                if(c.at(w.front())!='R') cnt += 1;
                w.push(i);
                w.pop();
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 4412
#include <bits/stdc++.h>
using namespace std;
#define MAXN 1000010
vector<int> adj[MAXN];
int prefix[MAXN], visited[MAXN], carbon[MAXN];
int node, query;
class fastio {
public:
    fastio() {
        ios_base::sync_with_stdio(false);
        cout.tie(nullptr);
        cin.tie(nullptr);
    }
} __fastio;
void graph(int u, int v) {
    adj[u].push_back(v);
    adj[v].push_back(u);
}
void dfs(int u, int cost) {
    visited[u] = 1;
    //Adding the cost of parent i.e, cost and adding the total prefix sum i.e, prefix[u]
    //Accoring to problem parent cost will always be added to the child hence always adding it
    carbon[u] = prefix[u] + cost;
    for(int i : adj[u]) {
        if(visited[i] != 1) {
            dfs(i, carbon[u]);
        }
    }
}
void solve() {
    cin >> node >> query;
    for(int i=0; i<node-1; i++) {
        int u, v;
        cin >> u >> v;
        graph(u, v);
    }
    for(int i=0; i<query; i++) {
        int u, p;
        cin >> u >> p;
        //storing the total summation value of 'p' for 'u' in prefix[u]
        prefix[u] += p;
    }
    dfs(1, 0);
    for(int i=1; i<=node; i++) {
        cout << carbon[i] <<  " ";
    }
}
int main() {
  __fastio;
  solve();
  return 0;
}


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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 5e18
#define mod 1000000007

ll seg[2][(1<<19)];
ll sz;

void init(vector<ll> a){
  ll n=a.size();
  sz=1;
  while(sz<n)sz*=2;
  rep(i,sz){
    if(i<n)seg[0][i+sz-1]=a[i];
    else seg[0][i+sz-1]=INF;
  }
  rep(i,sz){
    if(i<n)seg[1][i+sz-1]=-a[i];
    else seg[1][i+sz-1]=INF;
  }
  for(ll i=sz-2;i>=0;i--){
    rep(j,2)seg[j][i]=min(seg[j][i*2+1],seg[j][i*2+2]);
  }
}

ll lquery(ll i,ll v,ll k=0,ll l=0,ll r=sz){
  if(k>=sz-1)return k-sz+1;
  ll m=(l+r)/2;
  if(l<=i&&i<m){ // left
    return lquery(i,v,k*2+1,l,m);
  }else{ // right
    if(seg[1][k*2+1]<=v)return lquery(i,v,k*2+1,l,m);
    else return lquery(i,v,k*2+2,m,r);
  }
}

ll rquery(ll i,ll v,ll k=0,ll l=0,ll r=sz){
  if(k>=sz-1)return k-sz+1;
  ll m=(l+r)/2;
  if(m<=i&&i<r){ // right
    return rquery(i,v,k*2+2,m,r);
  }else{ // left
    if(seg[0][k*2+2]<=v)return rquery(i,v,k*2+2,m,r);
    else return rquery(i,v,k*2+1,l,m);
  }
}

struct BIT{
  vector<ll> bit;
  ll size;

  void init(ll s){
    size=s;
    bit.resize(size+1);
    rep(i,size+1)bit[i]=0;
  }

  ll sum(ll i){
    ll s=0;
    while(i>0){
      (s+=bit[i])%=mod;
      i-=i&-i;
    }
    return s;
  }

  void add(ll i,ll v){
    while(i<=size){
      (bit[i]+=v)%=mod;
      i+=i&-i;
    }
  }
};

ll n;
P l[201010];
P p[201010];
vector<P> rs;

int main(){
	cin>>n;
  rep(i,n)cin>>l[i].fi>>l[i].se;
  sort(l,l+n);
  rep(i,n){
    p[i]=P(l[i].se*2e9+l[i].fi,i);
  }
  sort(p,p+n);
  rep(i,n){
    set<ll> idxs;
    ll j;
    for(j=i;j<n;j++){
      idxs.insert(p[j].se);
      if(*idxs.rbegin()==j)break;
    }
    rs.push_back(P(i,j));
    i=j;
  }
  ll res=1;
  rep(i,rs.size()){
    vector<ll> a;
    repl(j,rs[i].fi,rs[i].se+1){
      a.push_back(p[j].se);
    }
    ll m=a.size();
    ll base=*min_element(all(a));
    rep(i,m)a[i]-=base;
    init(a);
    vector<P> ls;
    rep(j,m){
      ls.push_back(P(lquery(j,-a[j]),rquery(j,a[j])));
    }
    sort(all(ls));
    BIT bit;
    bit.init(m+10);
    bit.add(1,1);
    rep(j,m){
      ll s=(mod+bit.sum(ls[j].se+2)-bit.sum(ls[j].fi))%mod;
      bit.add(ls[j].se+2,s);
    }
    (res*=(bit.sum(m+1)-bit.sum(m)+mod)%mod)%=mod;
  }
  cout<<res%mod<<endl;
	return 0;
}


Measured memory_bytes: 27904
#include <bits/stdc++.h>
#define INF 1e9+7
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
typedef long long ll;

vector<int> v;

ll cnt;
void merge(int left,int right) {
    int mid = (left+right)/2;
    int n1 = mid - left;
    int n2 = right - mid;
    vector<int> l(n1+1,INF),r(n2+1,INF);
    REP(i,n1) l[i] = v[left+i];
    REP(i,n2) r[i] = v[mid+i];
    int i = 0, j = 0;
    FOR(k,left,right) {
        if (l[i] <= r[j]) v[k] = l[i++];
        else {
            v[k] = r[j++];
            cnt += n1 - i;
        }
    }
}
void merge_sort(int left, int right) {
    if((left+1) >= right) return;
    int mid = (right-left)/2 + left;
    merge_sort(left,mid);
    merge_sort(mid,right);
    merge(left,right);
}

void solve() {
    cnt = 0;
    int n;
    cin >> n;
    v.resize(n);
    REP(i,n) cin >> v[i];
    merge_sort(0,n);
    cout << cnt << endl;
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 4320
using System;
class aoj
{
    static void Main()
    {
        string a = Console.ReadLine();
        char[] c = new char[a.Length];
        for(int i = 0; i < a.Length; i++)
        {
            if ((int)a[i] >= 97 && (int)a[i] <= 122)
            {
                int b = (int)a[i] - 32;
                c[i] = (char)b;
            }
            else
            {
                c[i] = a[i];
            }
        }
        string d = new string(c);
        Console.WriteLine(d);
    }
}

Measured memory_bytes: 8576
import java.util.*;

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

    if((a*b)%2 == 0) System.out.println("Even");
    else System.out.println("Odd");
}

}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[200005],cnt[200005]={0};
int main()
{
    int n;
    cin>>n;

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

    }
    ll ans=0;
    for(int i=1;i<=200000;i++)
        ans+=cnt[i]*(cnt[i]-1)/2;
    for(int i=1;i<=n;i++)
        cout<<ans-cnt[a[i]]+1<<'\n';
}


Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read()
{
	int out=0,fh=1;
	char jp=getchar();
	while ((jp>'9'||jp<'0')&&jp!='-')
		jp=getchar();
	if (jp=='-')
		fh=-1,jp=getchar();
	while (jp>='0'&&jp<='9')
		out=out*10+jp-'0',jp=getchar();
	return out*fh;
}
const int MAXN=1e5+10;
int t1=0,t2=0,n,k;
char buf[MAXN];
int main()
{
	n=read(),k=read();
	scanf("%s",buf);
	int ans=0;
	for(int i=1;i<n;++i)
		ans+=(buf[i]==buf[i-1]);
	for(int i=0;i<n-1 && k;++i)
	{
		if(buf[i]=='L' && buf[i+1]=='R')
			++t1;
		else if(buf[i]=='R' && buf[i+1]=='L')
			++t2;
		if(t1 && t2)
			--t1,--t2,--k,ans+=2;
	}
	if(k && t1+t2)
		++ans;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(void){
    int A[5];
    int a[5];
    int m,t;
    m=10;
    t=10;
    for(int i=0;i<5;i++){
        cin>>A[i];
        a[i]=A[i]%10;
        if(a[i]!=0 && a[i]<m){
            m=a[i];
            t=i;
            
        }
        
    }
    int ans;
    ans=0;
    for(int i=0;i<5;i++){
        
        if(i==t){
            ans=ans+A[i];
            
        }else if(a[i]==0){
            ans=ans+A[i];
        }else{
            ans=ans+10*(1+A[i]/10);
        }
    }
    cout<<ans<<endl;
    return 0;
    
}

Measured memory_bytes: 256
<?php 

fscanf(STDIN, "%d %d", $n, $k);
for ($i=1; $i <= $k; $i++) {
  // code...
  fscanf(STDIN,"%d",$num);
  $array[] = explode(' ',trim(fgets(STDIN)));
}
for($i = 1; $i<=$n; $i++){
	$default_array[] = $i;
}
$main_array = $default_array;
foreach ($default_array as $value) {
  // code...
  foreach ($array as $elements) {
    // code...
    foreach ($elements as $element) {
      // code...
      if ($element == $value) {
        // code...
        unset($main_array[$element-1]);
      }
    }
  }
}
echo count($main_array);

Measured memory_bytes: 16748
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define mem0(s) memset(s,0,sizeof(s))
#define meminf(s) memset(s,0x3f,sizeof(s))
#define mp_insert(a,b,c) mp.insert(map<pair<int,int>,int>::value_type(make_pair(a,b),c))
typedef long long ll;
typedef unsigned long long ull;
const int INF=0x3f3f3f3f,max_n=200005;
inline ll lowbit(ll x){return x&(-x);}
inline ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
inline ll min(ll a,ll b){return a<b?a:b;}
inline ll max(ll a,ll b){return a>b?a:b;}
double r,pi=acos(-1);
int n,x;
int data1[max_n];
int main()
{
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	cin>>n;
	for(int i=2;i<=n;i++)
	{
		cin>>x;
		data1[x]++;
	}
	for(int i=1;i<=n;i++)
	{
		cout<<data1[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 4360
import sys
from io import StringIO
import unittest

def resolve():
    n = int(input())
    s = list(input())

    ans = 0
    for i in range(len(s) - 1):
        left = s[0:i + 1]
        right = s[i + 1:]

        tmp_ans = len(set(left) & set(right))

        if ans < tmp_ans:
            ans = tmp_ans

    print(ans)


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """6
aabbca"""
        output = """2"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """10
aaaaaaaaaa"""
        output = """1"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """45
tgxgdqkyjzhyputjjtllptdfxocrylqfqjynmfbfucbir"""
        output = """9"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()

Measured memory_bytes: 5616
#include<bits/stdc++.h>
using namespace std;
int perm(int ara[],int n){
	int i,cnt=0,p[n],y=1,y1=1;
	for(i=0;i<n;i++){
		p[i]=i+1;
	}
	do{
		y1=0;
		for(i=0;i<n;i++){
			if(ara[i]==p[i]){
				y1++;
			}
		}
		if(y1==n){
			break;
		}
		cnt++;
	}while(next_permutation(p,p+n));
	return cnt;
}
int main()
{
	int n,i;
	cin>>n;
	int ara[n],ara1[n];
	for(i=0;i<n;i++){
		cin>>ara[i];
	}
	for(i=0;i<n;i++){
		cin>>ara1[i];
	}
	cout<<abs(perm(ara,n)-perm(ara1,n))<<endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define eb emplace_back
#define ll long long
#define nl '\n'
#define in() ( { int a ; scanf("%d",&a); a; } )
 
const int N = 3e7 + 9;
const int mod = 1e9 + 7;
//int dx[]={1,0,-1,0,1,-1,-1,1};
//int dy[]={0,1,0,-1,1,1,-1,-1};

int main()
{
    int n, i, j;
    n = in();
    vector<int> ar(n);
    ll tot = 0, ans = N;
    for (i = 0; i < n; i++){
        cin >> ar[i];
    }
    for (i = 0; i < 101; i++){
        for (j = 0; j < n; j++){
            tot += ((i - ar[j]) * (i - ar[j]));
        }
        ans = min(ans, tot);
        tot = 0;
    }
    cout << ans << nl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) cerr<<(#v)<<":";for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;
#define printVS(vs) cerr<<(#vs)<<":"<<endl;for(auto(s):(vs)){cerr<<(s)<< endl;}
#define printVV(vv) cerr<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;}
#define printP(p) cerr<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cerr<<(#vp)<<":"<<endl;for(auto(p):(vp)){cerr<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cerr << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cerr << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1ll << 60;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;

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

  int n;
  cin >> n;
  vi a(n), b(n);
  vector<TUPLE> vt;
  vector<Pii> vp;
  rep(i, n) {
    cin >> a[i] >> b[i];
    vt.emplace_back(b[i] - a[i], a[i], b[i]);
    vp.emplace_back(b[i], a[i]);
  }
  sort(all(vt));
  sort(all(vp));

  int sm = 0;
  rep(i, n) {
    // sm += std::get<1>(vt[i]);
    // if (sm > std::get<2>(vt[i])) {
    //   cout << "No" << endl;
    //   return 0;
    // }
    sm += vp[i].second;
    if (sm > vp[i].first) {
      cout << "No" << endl;
      return 0;
    };
  }
  cout << "Yes" << endl;



}


Measured memory_bytes: 13860
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;

typedef vector<int> vi;
typedef pair<int,int> ii;
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);

	int p, q, r;
	cin >> p >> q >> r;
	int ans = p + q + r - max(max(p, q), r);
	cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;

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

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int x = sc.nextInt();

        int count = 0;

        for(int i = 0; i <= a; i++){
            for(int j = 0; j <= b; j++){
                for(int k = 0; k <= c; k++){
                    if((i*500 + j*100 + k*50) == x){
                        count++;
                    }
                }
            }
        }

        System.out.println(count);
    }
}

Measured memory_bytes: 21584
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		//入力表示
		int N = sc.nextInt();
		int count = 0;
		int ans = 0;

		for (int i = 0; i < N; i++) {
			int H = sc.nextInt();

			if (ans <= H) {
				count++;
			}
			if (H > ans) {
				ans = H;
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define F first
#define S second
void YES(bool che){
    if(che)cout<<"YES\n";
    else cout<<"NO\n";
}
void Yes(bool che){
    if(che)cout<<"Yes\n";
    else cout<<"No\n";
}
ll h,w,d,q;
P x[90005];
vector<ll>m[90005];
int main(void){
   cin>>h>>w>>d;
   for(int i=0;i<h;i++){
       for(int j=0;j<w;j++){
           int a;
           cin>>a;
           a--;
           x[a]=(P(ll(i),ll(j)));
       }
   }
   for(int i=0;i<d;i++){
       m[i].push_back(0);
       ll px=x[i].S,py=x[i].F;
       for(int j=i;j<h*w;j+=d){
           m[i].push_back(m[i].back()+abs(px-x[j].S)+abs(py-x[j].F));
           px=x[j].S;
           py=x[j].F;
       }
   }
   cin>>q;
   for(int i=0;i<q;i++){
       ll l,r;
       cin>>l>>r;
       l--;
       r--;
       cout<<m[l%d][r/d+1]-m[l%d][l/d+1]<<endl;
   }
}


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

#define pb push_back
#define F first
#define S second
#define y1 dasdasfasfas
#define x1 wqdadfasfasfas
#define All(c) c.begin(), c.end()
#define SZ(A) (int((A).size()))
#define umap unordered_map
#define __ fflush(stdout)
#define FILENAME ""

typedef long long ll;
typedef long double ld;    

using namespace std;

void FREOPEN() {
	#ifdef LOCAL
		freopen(".in", "r", stdin);
		freopen("1.out", "w", stdout);
	#else
		//freopen(FILENAME".in", "r", stdin);
		//freopen(FILENAME".out", "w", stdout);
	#endif
}

inline double Time() {return (clock() * 1.0) / CLOCKS_PER_SEC; }             

const int N = 20500, inf = 1e9 * 2;

const ll MOD = 1e9 + 7ll, INF = 1e18;

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

string get_string() {
	string ret = "";
	char c;
	while ((c = getchar()) != '\n') ret += c;
	return ret;
}

int dp[N][100][2];

void add(int &x, int y) {
	x += y;
	if (x >= MOD) x -= MOD;
}

int main() {
	FREOPEN();
	string num = get_string();
	int d;
	scanf("%d ", &d);
	num = '$' + num;
	int n = SZ(num) - 1;
	dp[0][0][1] = 1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < d; j++) {
			for (int k = 0; k < (int)(num[i + 1] - '0'); k++) {
				add(dp[i + 1][(j + k) % d][0], dp[i][j][1]);
			}
			add(dp[i + 1][(j + (int)(num[i + 1] - '0')) % d][1], dp[i][j][1]);
			for (int k = 0; k < 10; k++) {
				add(dp[i + 1][(j + k) % d][0], dp[i][j][0]);
			}
		}
	}
	add(dp[n][0][1], dp[n][0][0]);
	printf("%d", (dp[n][0][1] + MOD - 1) % MOD);
	return 0;
}


Measured memory_bytes: 8448
import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
N, K = [int(x) for x in input().strip().split()]
if N == 0 or K == 1:
    print(0)
    exit()
if N >= K and (N - K) >= K:
    N -= (N - K) // K * K
if N >= K:
    N = abs(N-K)

if N >= (K / 2):
    print(K - N)
    exit()
print(N)

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

int main(){
  int N;
  cin >> N;
  int q=0;
  for(int i=0;i<100;i++){
    for(int j=0;j<100;j++){
      int t=7*i+4*j;
      if(t==N)
        ++q;
    }
  }
  if(q>0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


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

int main() {
  
  vector<int> a(5);
  int k;
  
  for ( int i = 0; i < 5; i++){
    cin >> a[i];
  }
  
  cin >> k;
  
  
  
  if ( a[4] - a[0] > k ){
    cout << ":(" << endl;
  }else{
    cout << "Yay!" << endl;
  }
  
}



Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

pub fn read_n<T: FromStr>(n: usize) -> Vec<T> {
    read_n_logic::<T>(n, vec![])
}

pub fn read_n_logic<T: FromStr>(n: usize, mut a: Vec<T>) -> Vec<T> {
    match n {
        0 => a,
        _ => {
            a.push(read::<T>());
            read_n_logic(n - 1, a)
        }
    }
}
use std::cmp::{max, min};

fn main() {
    let a: usize = read();
    let b: usize = read();
    let c: usize = read();
    let d: usize = read();

    if (a / d) + min(1, a % d) >= (c / b) + min(1, c % b) {
        println!("{}", "Yes");
    } else {
        println!("{}", "No");
    }
}


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

int main() {
    int H, W, K;
    cin >> H >> W >> K;
    vector<string> S(H);
    for(auto &e : S) cin >> e;
    int ans = 0;
    for(int i = 0; i < (1 << H); ++i) {
        bitset<10> bi(i);
        for(int j = 0; j < (1 << W); ++j) {
            bitset<10> bj(j);
            vector<string> T(S);
            for(int ii = 0; ii < H; ++ii) if(bi[ii]) {
                for(int k = 0; k < W; ++k) T[ii][k] = 'r';
            }
            for(int jj = 0; jj < W; ++jj) if(bj[jj]) {
                for(int k = 0; k < H; ++k) T[k][jj] = 'r';
            }
            int cnt = 0;
            for(int k = 0; k < H; ++k) {
                for(int l = 0; l < W; ++l) {
                    if(T[k][l] == '#') cnt++;
                }
            }
            if(cnt == K) ans++;
        }
    }
    cout << ans << '\n';
    return 0;
}


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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    string N; cin >> N;
    string M = N;
    reverse(ALL(M));
    if(N == M) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

    return 0;
}

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


hmax = 0
if n == 1:
    print('Yes')
    exit()

for i in range(n):
    if (hl[i] >= (hmax - 1)):
        hmax = max(hmax,hl[i])
        if i == n - 1:
        	print('Yes')
        	break
    else:
        print('No')
        break

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

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);

    int N, M;
    cin >> N >> M;

    if(N == M)
        cout << "Yes\n";
    else
        cout << "No\n";

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    //qut : https://atcoder.jp/contests/dp/tasks/dp_k

    private static Boolean dp[];

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

        int[] a = new int[n];

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

        dp = new Boolean[k + 1];

        System.out.println(canWin(k, a) ? "First" : "Second");
    }

    private static boolean canWin( int k, int[] a ) {

        //if no values present in DB then
        if (dp[k] == null) {

            for (int i : a) {

                //if First player consumes all the stones then no stone left for Second; obviously First wins.
                if (i == k)
                    return dp[k] = true;

                    //if current stone is less than total pile of stones
                else if (i < k) {

                    //consumes/pick stones until no stone left for Second player
                    if (!canWin(k - i, a))
                        return dp[k] = true;
                }
            }

            //THis case will run if all stone pile is consumed and none of above condition if met
            dp[k] = false;
        }
        return dp[k];
    }
}

Measured memory_bytes: 31956
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
using namespace std;
#define ll long long 
const int maxn=1010;
const int maxN=3000100;
const int dx[]={-1,0,1,0};
const int dy[]={0,1,0,-1};
int n,m;
int s1,s2,t1,t2;
char mp[maxn][maxn];
int bel[maxn][maxn],tot;
int dfsvis[maxn][maxn];
int nx,ny;
void dfs(int x,int y){
    bel[x][y]=tot; dfsvis[x][y]=1;
    for (int i=0;i<4;++i){
        nx=x+dx[i]; ny=y+dy[i];
        if (nx<=0||nx>n||ny<=0||ny>m) continue;
        if (mp[nx][ny]=='#') continue;
        if (dfsvis[nx][ny]) continue;
        dfs(nx,ny);
    }
}
vector<int> avi[maxN];
int vis[maxN],dis[maxN];
int main(){
    scanf("%d%d",&n,&m);
    scanf("%d%d",&s1,&s2);
    scanf("%d%d",&t1,&t2);
    for (int i=1;i<=n;++i){
        for (int j=1;j<=m;++j){
            mp[i][j]=getchar();
            while (mp[i][j]!='#'&&mp[i][j]!='.') mp[i][j]=getchar();
        }
    }
    for (int i=1;i<=n;++i){
        for (int j=1;j<=m;++j){
            if (mp[i][j]=='.'&&!bel[i][j]){
                ++tot; dfs(i,j);
            }
        }
    }

    /*for (int i=1;i<=n;++i){
        for (int j=1;j<=m;++j){
            cout<<bel[i][j];
        }
        cout<<"\n";
    }*/

    for (int i=1;i<=n;++i){
        for (int j=1;j<=m;++j){
            for (int k=-2;k<=2;++k){
                nx=i+k;
                if (nx<=0||nx>n) continue;
                for (int l=-2;l<=2;++l){
                    ny=j+l;
                    if (ny<=0||ny>m) continue;
                    if (mp[nx][ny]=='#'||mp[i][j]=='#') continue;
                    //cout<<bel[i][j]<<" "<<bel[nx][ny]<<endl;
                    avi[bel[i][j]].push_back(bel[nx][ny]);
                    avi[bel[nx][ny]].push_back(bel[i][j]);
                }
            }
        }
    }
    memset(vis,0,sizeof(vis));
    queue<int> q; q.push(bel[s1][s2]);
    dis[bel[s1][s2]]=0; vis[bel[s1][s2]]=1;
    while (!q.empty()){
        int u=q.front(); q.pop();
        //cout<<u<<endl;
        for (int i=0;i<avi[u].size();++i){
            int v=avi[u][i];
            if (vis[v]) continue;
            vis[v]=1; dis[v]=dis[u]+1;
            q.push(v);
            //cout<<v<<"="<<u<<"+1="<<dis[u]+1<<"\n";
        }
    }
    if (!vis[bel[t1][t2]]){
        cout<<"-1";
    }else{
        cout<<dis[bel[t1][t2]];
    }
    return 0;
}

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

int main() {
        int n;
        scanf("%d", &n);
        vector<int> a(n);
        bool ng = false;
        rep(i, n) {
                scanf("%d", &a[i]);
                if (a[i] > i) {
                        ng = true;
                }
        }
        auto no = [&]() {
                printf("-1\n");
                return 0;
        };
        if (ng) {
                return no();
        }
        rep(i, n - 1) {
                if (a[i] + 1 < a[i + 1]) {
                        return no();
                }
        }
        long long ans = 0;
        rep(i, n) {
                if (i != n - 1 && a[i + 1] == a[i] + 1) {
                        continue;
                }
                ans += a[i];
        }
        printf("%lld\n", ans);
        return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

ll a[120];

int main(){
	int n; scanf("%d", &n);
	REP(i, n) scanf("%lld", a+i);
	ll ans = 0;
	REP(i, n){
		FOR(j, i+1, n){
			ans += a[i] * a[j];
		}
	}
	printf("%lld\n", ans);
}


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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
ostream &operator<<(ostream &os, pair<ll, ll>&p){
  return os << p.first << " " << p.second;
}  
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n,k;cin>>n>>k;
  vector<ll>x(n),y(n);
  rep(i,0,n)cin>>x[i]>>y[i];
  res=LLONG_MAX;
  rep(i,0,n)rep(j,i+1,n){
    ll xl=min(x[i],x[j]);
    ll xr=max(x[i],x[j]);
    vector<ll>v;
    rep(o,0,n){
      if(x[o]>=xl&&x[o]<=xr)v.PB(y[o]);
    }
    sort(ALL(v));
    rep(i,0,n){
      if(i+k>v.size())break;
      chmin(res,(xr-xl)*(v[i+k-1]-v[i]));
    }
  }
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 256
N, C = map(int, input().split())
x = []
v = []
for _ in range(N):
    xi, vi = map(int, input().split())
    x.append(xi)
    v.append(vi)
vsp = [0] * (N + 1)
vsn = [0] * (N + 1)
dprp = [0] * (N + 1)
dprn = [0] * (N + 1)
dpsp = [0] * (N + 1)
dpsn = [0] * (N + 1)
for i in range(N):
    vsp[i + 1] = vsp[i] + v[i]
    vsn[i + 1] = vsn[i] + v[N - 1 - i]
    dprp[i + 1] = max(dprp[i], vsp[i + 1] - 2 * x[i])
    dpsp[i + 1] = max(dpsp[i], vsp[i + 1] - x[i])
    dprn[i + 1] = max(dprn[i], vsn[i + 1] - 2 * (C - x[N - 1 - i]))
    dpsn[i + 1] = max(dpsn[i], vsn[i + 1] - (C - x[N - 1 - i]))
ans = max(max(dprp[i] + dpsn[N - i], dprn[i] + dpsp[N - i])
          for i in range(N + 1))
print(ans)


Measured memory_bytes: 33128
#include<iostream>
#include<vector>
#include<string>

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

int main() {
	string s,t;
	int cnt = 0;

	while (cin >> t){
		s += t;
	}
	
	for (int j = 0; j < 26; j++) {
		for (int i = 0; i < s.size(); i++) {
			if (s[i] == 'A' + j || s[i] == 'a' + j) {
				cnt++;

	 		}
		}
		printf("%c : %d\n", 'a' + j, cnt);
		cnt = 0;
	}
	return 0;
}


Measured memory_bytes: 3336
#include <iostream>

#define REP(i, a, b) for ( int i = (a); i < (b); i++ )
#define REVREP(i, a, b) for ( int i = (a); i >= (b); i--)
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)
#define PRINT_ARRAY(name, i) printf("the value of "#name"[%d] is %d\n", (i), name[(i)])
#define DEBUG_ARRAY(name, begin, end) REP(i, begin, end) PRINT_ARRAY(name, i)

using namespace std;

int main(void) {

	char s[8];
    scanf("%s", s);
    
    if (s[0] == 'S') puts("Cloudy");
    else if (s[0] == 'C') puts("Rainy");
    else puts("Sunny");

	return 0;
}


Measured memory_bytes: 256