akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int n, m, x, ans=-1, anstmp;
  cin >> n >> m >> x;
  vector<vector<int>> a(n, vector<int>(m+1));
  vector<int> b(m, 0);
  for(int i = 0; i<n; i++){
    for(int j = 0; j<m+1; j++){
      cin >> a[i][j];
    }
  }
  for(int tmp=0; tmp<(1<<n); tmp++){
    bitset<12> s(tmp);

    anstmp=0;
    for(int i=0; i<n; i++){
      anstmp+=s[i]*a[i][0];
    }
    if(ans!=-1 and anstmp>ans)
      continue;
    
    for(int i=0; i<m; i++){
      b[i]=0;
    }
    for(int i=0; i<n; i++)
      for(int j=0; j<m; j++){
	b[j]+=s[i]*a[i][j+1];
      }
    sort(b.begin(), b.end());
    if(b[0]>=x)
      ans = anstmp;
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
  string s;
  cin >> s;
  int size = s.size();
  
  for(int i=0; i<size-1; i++){
    if(s.at(i) == s.at(i+1)){
      cout << i+1 << ' ' << i+2 << endl;
      return 0;
    }
  }
  
  for(int i=0; i<size-2; i++){
    if(s.at(i) == s.at(i+2)){
      cout << i+1 << ' ' << i+3 << endl;
      return 0;
    }
  }
  
  cout << -1 << ' ' << -1 << endl;
}

Measured memory_bytes: 512
def main():
    T1,T2 = map(int,input().split())
    A1,A2 = map(int,input().split())
    B1,B2 = map(int,input().split())

    move = T1*(A1-B1) + T2*(A2-B2)
    mid = T1*(A1-B1)

    if move==0:
        return -1

    if move*mid > 0:
        return 0

    if move < 0:
        move *= -1
    else:
        mid *= -1

    if mid%move == 0:
        return 2*(mid//move)
    else:
        return 2*(mid//move)+1

if __name__ == "__main__":
    ans = main()
    if ans==-1:
        print("infinity")
    else:
        print(ans)


Measured memory_bytes: 38384
def main():
  ## IMPORT MODULE
  #import sys

  #sys.setrecursionlimit(100000)
  #input=lambda :sys.stdin.readline().rstrip()

  #f_inf=float("inf")
  #MOD=10**9+7
  
  if 'get_ipython' in globals(): 
    ## SAMPLE INPUT
    x, y = 3, 8

  else:
    ##INPUT 
    #n = input()
    x, y = map(int, input().split())

  ## SUBMITION CODES HERE
  for i in range(101):
    for j in range(101):
        if (2*i + 4*j == y) and (i + j == x):
          exit(print("Yes"))
  print("No")
main()

Measured memory_bytes: 9112
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define PRINTALL(V)                                                            \
  for (auto v : (V)) {                                                         \
    cerr << v << " ";                                                          \
  }                                                                            \
  cerr << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
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 (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template < class T > using vec = std::vector< T >;
template < class T > void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567, INF2 = INF * INF;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int N;
  string S;
  cin >> N >> S;

  bool flg = false;
  vec< int > ans(N + 2);
  REP(j, 4) {
    ans[0] = j / 2;
    ans[1] = j % 2;
    REP(i, N) {
      ans[i + 2] = (ans[i + 1] + ans[i] + (S[i] == 'o' ? 0 : 1)) % 2;
    }
    if (ans[0] == ans[N] && ans[1] == ans[N + 1]) {
      flg = true;
      break;
    }
  }
  if (flg) {
    REP(i, N) { cout << "SW"[ans[(i + 1) % N]]; }
    cout << "\n";
  } else {
    print("-1");
  }
}

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

int main(){
    int N;
    int A;

    std::cin >> N;
    vector<int> junban(N);

    for(int i = 0; i < N; i++){
        std::cin >> A;
        junban[A-1] = i + 1;
    }

    for(int i = 0; i < N; i ++){
        std::cout << junban[i] << " ";
    }
}

Measured memory_bytes: 3744
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
    static void countingSort(int[] A, int[] B, int k) {
        final int n = B.length;
        final int[] C = new int[k + 1];

        for (int i = 0; i < n; i++) {
            C[A[i]]++;
        }

        for (int i = 1; i <= k; i++) {
            C[i] += C[i - 1];
        }

        for (int i = n - 1; i >= 0; i--) {
            B[C[A[i]] - 1] = A[i];
            C[A[i]]--;
        }
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        final int n = Integer.parseInt(in.next());
//            final int[] A = Arrays.stream(in.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        final int[] A = new int[n];
        for (int i = 0; i < n; i++) {
            A[i] = Integer.parseInt(in.next());
        }
        final int[] B = new int[n];
        final int k = 10000;

        countingSort(A, B, k);

        System.out.println(Arrays.stream(B).mapToObj(String::valueOf).collect(Collectors.joining(" ")));
    }
}



Measured memory_bytes: 291580
import std.stdio, std.algorithm, std.conv, std.array, std.range, std.string, std.math, std.typecons;

void main()
{
    auto nm = readln.split.to!(long[]);
    auto N = nm[0];
    auto M = nm[1];

    long ret;
    if (N == 1 && M == 1) {
        ret = 1;
    } else if (N == 1) {
        ret = M - 2;
    } else if (M == 1) {
        ret = N - 2;
    } else if (N == 2 || M == 2) {
        ret = 0;
    } else {
        ret = N * M - N * 2 - M * 2 + 4;
    }
    writeln(ret);
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<cassert>
#include<numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
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; }
typedef long long ll;
typedef pair<int,int> P;

const int D = 60;
const int MAX_N = 200005;
int to[D][MAX_N];

int main(){
    int n; ll k;
    cin >> n >> k;
    rep(i,n){
        cin >> to[0][i];
        to[0][i]--;
    }
    rep(i,D-1)rep(j,n){
        to[i+1][j] = to[i][to[i][j]];
    }

    int v = 0;
    for(int i = D-1; i>=0;--i){
        ll l = 1LL<<i;
        if(l<=k){
            v=to[i][v];
            k -= l;
        }
    }
    cout << v+1 << endl;
    return 0;
}

Measured memory_bytes: 50508
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<unordered_set>
#include<unordered_map>
#include<math.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod;
#define N 200010
ll n,k,a[N];
ll to[N],cost[N];
vector<ll> p[N];
int main(){
  cin>>n>>k;
  for(int i=0;i<n;i++){
      cin>>a[i];
      p[a[i]].push_back(i);
  }
  for(int i=0;i<N;i++){
      for(int j=0;j<p[i].size();j++){
	  int k=(j+1)%p[i].size();
	  to[p[i][j]]=(p[i][k]+1)%n;
	  cost[p[i][j]]=(k==0);
      }
  }
  vector<ll> c;
  ll cur=0; c.push_back(cur);
  while(1){
      cur=to[cur];
      if(cur==0)break;
      c.push_back(cur);
  }
  ll shuki=1;
  for(int i=0;i<c.size();i++){
      shuki+=cost[c[i]];
  }
  k%=shuki;
  if(k==0){
      return 0;
  }
  ll s=-1;
  for(int i=0;i<c.size();i++){
      if(k==1){
	  s=c[i];
	  //cout<<"---"<<i<<" "<<c[i]<<endl;
	  break;
      }
      k-=cost[c[i]];
  }//cout<<shuki<<" "<<s<<endl;
  //cout<<"#"<<c.size()<<endl;
  bool th[N]; for(int i=0;i<N;i++)th[i]=0;
  vector<ll> v;
  for(int i=s;i<n;i++){
      if(th[a[i]]){
	  while(v.back()!=a[i]){
	      th[v.back()]=0;
	      v.pop_back();
	  }
	  v.pop_back();
	  th[a[i]]=0;
      }
      else{
	  v.push_back(a[i]);
	  th[a[i]]=1;
      }
  }
  for(int i=0;i<v.size();i++)cout<<v[i]<<endl;
  return 0;
}


Measured memory_bytes: 20724
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).ok();
    let mut it = buf.split_whitespace();
    let n = it.next().unwrap().parse::<usize>().unwrap() - 1;
    let mut t = Vec::new();
    for _ in 0..n {
        let c = it.next().unwrap().parse::<i64>().unwrap();
        let s = it.next().unwrap().parse::<i64>().unwrap();
        let f = it.next().unwrap().parse::<i64>().unwrap();
        t.push((c, s, f));
    }
    for i in 0..n {
        let mut cur = 0;
        for j in i..n {
            cur = std::cmp::max(t[j].1, cur + t[j].2 - 1) / t[j].2 * t[j].2 + t[j].0;
        }
        println!("{}", cur);
    }
    println!("0");
}


Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
//#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define mp make_pair
#define all(x) x.begin(),x.end()
using namespace std;
int k, n, a[234536];
signed main() {
	cin >> k >> n;
	for1(i, n)cin >> a[i];
	int ans = a[n] - a[1];
	for1(i, n - 1)ans = min(ans, a[i] + k - a[i + 1]);
	cout << ans << endl;
}

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

int main() {
    int w, h, x, y, r;

    cin >> w >> h >> x >> y >> r;
    if (x - r < 0 || y - r < 0 ||
        x + r > w || y + r > h) {
        cout << "No" << endl;
    }
    else {
        cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <vector>
#include <numeric>
#include<string>

using namespace std;

#define ll long long
#define rep(cnt,a,n) for(ll cnt=a;cnt<n+a;cnt++) //aから始めてn回ループ
#define vector2(type,name,a,b) vector<vector<type>> name(a, vector<type>(b))
#define PI 3.141592653589793



int main() {
    vector<ll> x(5);
    rep(cnt, 0, 5) {
        cin >> x[cnt];
    }
    //sort(x.begin(), x.end());
    rep(cnt, 0, 5) {
        if (x[cnt] == 0) {
            cout << cnt+1 << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 3548
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, n) cin >> a[i];

    set<int> s;
    REP(i, 1 << n) {
        int sum = 0;
        REP(j, n) if ((i >> j) & 1 == 1) sum += a[j];
        s.emplace(sum);
    }
    int q;
    cin >> q;
    int m;
    while (q--) {
        cin >> m;
        cout << (s.count(m) ? "yes" : "no") << endl;
    }
}




Measured memory_bytes: 3232
#include <bits/stdc++.h>
#define ll long long
#define M 1000000007 
#define MM 998244353
using namespace std;
 
int main()
{
	long long int n;

	cin >> n;

	long long int ans = n-1;

	for (long long int i = 1; i*i <= n; i++)
	{
		if (n%i == 0)
		{
			ans = min (ans, i + n/i -2);
		}
	}

	cout << ans;

  	return 0;
}

Measured memory_bytes: 3644
H, W = map(int, input().split(' '))
N = int(input())
A = list(map(int, input().split(' ')))

# A = [10, 5, 5, 3, 2]
# H, W = 5, 5

def get_position(H, W):
    for i in range(H):
        if i % 2 == 0:
            for j in range(W):
                yield i, j
        else:
            for j in range(W-1, -1, -1):
                yield i, j


buf = [['' for _ in range(W)] for _ in range(H)]
positions = get_position(H, W)
for c, a in enumerate(A):
    for _ in range(a):
        i, j = positions.__next__()
        # print(i, j)
        buf[i][j] = str(c+1)

for b in buf:
    print(' '.join(b))

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

int main()
{
	int n;
	scanf("%d", &n);
	std::vector<long long> a[32];
	for (int i = 0; i < n; i++)
	{
		long long tmp{};
		scanf("%lld", &tmp);
		int digit{};
		while (!(((long long)1 << digit) & tmp)) digit++;
		a[digit].push_back(tmp);
	}
	int count{};
	for (int i = 0; i < 32; i++)
	{
		auto& v = a[i];
		std::vector<bool> used(v.size());
		std::sort(v.begin(), v.end(), std::greater<long long>());
		for (unsigned int j = 0; j < v.size(); j++)
		{
			if (used[j]) continue;
			used[j] = true;
			
			long long sum_candidate{1};
			for (; sum_candidate <= v[j]; sum_candidate <<= 1);
			long long candidate{sum_candidate - v[j]};

			unsigned int left{j}, right{v.size() - 1};
			while (left + 1 < right)
			{
				auto mid{(left + right) / 2};
				if (v[mid] <= candidate) right = mid;
				else left = mid;
			}
			if (v[right] != candidate || used[right]) continue;
			used[right] = true;
			v[right]++;
			count++;
		}
	}
	printf("%d\n", count);

	return 0;
}

Measured memory_bytes: 2424
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <unordered_map>
#include <algorithm>

using namespace std;

int main()
{
  int N;
  cin >> N;
  vector<pair<int,int>> A(N);
  for (int i=0;i<N;i++) {
    int x, y;
    cin >> x >> y;
    A[i] = make_pair(x, y);
  }
  map<pair<int, int>, int> diffMap;
  sort(A.begin(), A.end(), greater<pair<int, int>>());
  for (int i=0; i<N-1; i++) {
    for (int j=i+1; j<N; j++) {
      int dx = A[i].first - A[j].first;
      int dy = A[i].second - A[j].second;
      auto pii = make_pair(dx, dy);
      if (diffMap.count(pii)) {
        diffMap[pii] = diffMap[pii] + 1;
      } else
      {
        diffMap.insert(make_pair(pii, 1));
      }
    }
  }
  int maxCount = 0;
  for (auto itr = diffMap.begin(); itr != diffMap.end(); itr++)
  {
    // printf("%d %d count:%d\n", itr->first.first, itr->first.second, itr->second);
    if (itr->second > maxCount) {
      maxCount = itr->second;
    }
  }
  cout << N - maxCount << endl;
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <sstream>
#include <vector>
#include <cassert>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <tuple>
#include <regex>
#include <map>

using namespace std;
using ull = unsigned long long;

// 0から引数の数字までXORする
ull f(ull x) {
	if (x % 4 == 0) { // x = 0, 4, 8, 12...
		return 0 ^ x;
	} else if (x % 4 == 1) { // 1, 5, 9, 13...
		return 1;
	} else if (x % 4 == 2) { // 2, 6, 10, 14...
		return 1 ^ x;
	} else { // 3, 7, 11, 15...
		return 0;
	}
}

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

	const ull answer = f(A - 1) ^ f(B);

	cout << answer << endl;

	return 0;

}



Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
using namespace std;
int main(){
  int N,K;
  cin>>N>>K;
  int d[100];
  int A[100][100];
  int o[101];
  for(int i=0;i<=N;i++){
    o[i]=0;
  }
  for(int i=0;i<K;i++){
    cin>>d[i];
    for(int j=0;j<d[i];j++){
      cin>>A[i][j];
      o[A[i][j]]++;
    }
  }
  int num=0;
  for(int i=1;i<=N;i++){
    if(o[i]==0) num++;
  }
  cout<<num<<endl;
  return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll a,b;
    cin>>a>>b;
    string str1,str2;
    for(ll i=1;i<=b;i++)
        str1+=to_string(a);
    for(ll i=1;i<=a;i++)
        str2+=to_string(b);
    cout<<min(str1,str2)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  vector<vector<int>> a(3,vector<int>(3));
  for(int i=0;i<3;i++)
  {
    for(int j=0;j<3;j++)
    {
      cin>>a[i][j];
    }
  }
  int n;
  cin>>n;
  vector<int> v(n);
  for(int i=0;i<n;i++)
  {
    cin>>v[i];
    for(int j=0;j<3;j++)
    {
      for(int k=0;k<3;k++)
      {
        if(a[j][k]==v[i])
          a[j][k]=0;
      }
    }
  }
  for(int i=0;i<3;i++)
  {
    if(a[i][0]==0 && a[i][1]==0 && a[i][2]==0)
    {
      cout<<"Yes";
      return 0;
    }
  }
  for(int i=0;i<3;i++)
  {
    if(a[0][i]==0 && a[1][i]==0 && a[2][i]==0)
    {
      cout<<"Yes";
      return 0;
    }
  }
  if(a[0][0]==0 && a[1][1]==0 && a[2][2]==0)
  {
    cout<<"Yes";
    return 0;
  }
  if(a[0][2]==0 && a[1][1]==0 && a[2][0]==0)
  {
    cout<<"Yes";
    return 0;
  }
  cout<<"No";
  return 0;
}

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

int main()
{
	int n;
	cin>>n;
	bool b[n][n];
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			cin>>b[i][j];
		}
	}
	long long tot=pow(2,n);
	long long ans[tot];
	for(int i=0;i<tot;i++)
	ans[i]=0;
	long long mod=1e9+7;
	ans[0]=1;
	for(int i=0;i<tot-1;i++)
	{
		if(ans[tot]==0)
		continue;
		int p=0;
		for(int j=0;j<n;j++)
		{
			if((i>>j) & 1 ==1)
			p++;
		}
	//	cout<<p<<"*";
		for(int j=0;j<n;j++)
		{
			if(((i>>j) & 1)==0 && b[p][j]==1)
			{
				//cout<<"#"<<" ";
				ans[i+(1<<j)]=(ans[i+(1<<j)]+ans[i])%mod;
			}
		}
	}
	cout<<ans[tot-1];
	//for(int i=0;i<tot;i++)
	//cout<<ans[i]<<" ";
	return 0;
}

Measured memory_bytes: 16640
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int maxn = 500+10;
LL a[maxn];
LL b[maxn];
LL ans = 1;
int n,k;

void update(LL x){
    LL ss=0,sss=0;
    vector<int>s;
    for(int i=1;i<=n;i++)s.push_back(a[i]%x),sss+=x-a[i]%x;
    sort(s.begin(),s.end());
    ss=s[0],sss-=x-s[0];
    for(int i=1;i<s.size();i++){
        if(ss+s[i]>k)break;
        ss+=s[i],sss-=x-s[i];
    }
     if(ss<=k&&sss<=k)ans=max(ans,x);
}
int main(void)
{
    cin>>n>>k;
    LL sum = 0;
    for(int i = 1;i <= n; ++i)
        cin>>a[i],sum += a[i];
    // cout<<sum<<endl;
    for(LL i = 2;i*i <= sum; ++i){
        if(sum % i == 0){
            update(i);
            update(sum/i);
        }
    }
    update(sum);

    cout<<ans<<endl;

    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int N,X,l;
    int D=0;
    int K=1;
    scanf("%d %d",&N,&X);
    for (int i=0; i<N;i++ ) {
        scanf("%d",&l);
        D+=l;
        if(D<=X){
            K++;
        }
    }
    
    printf("%d\n",K);
    
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define FOR(I,X,Y) for(int I=X;I<Y;I++)
#define REP(I,X,Y) for(int I=Y-1;I>=X;I--)
#define INF 1000000007
using namespace std;

struct edge {
  int x;
  int y;
  int weight;
  bool operator<(const edge& another) const {
    return weight < another.weight;
  }
  bool operator>(const edge& another) const {
    return weight > another.weight;
  }
};

vector<int> data(100010,-1);

int root(int x){
  if(data[x] == -1)return x;
  else return data[x] = root(data[x]);
}

bool same(int x,int y){
  if(root(x) == root(y))return 1;
  else return 0;
}

int unite(int x,int y){
  if(!same(x,y))data[root(x)] = y;
  return 0;
}

vector<edge> Kruskal(vector<edge> E){
  vector<edge> answer;
  priority_queue<edge,vector<edge>,greater<edge> > pque;
  for(int i = 0;i < data.size();i++)data[i] = -1;
  for(int i = 0;i < E.size();i++)pque.push(E[i]);
  while(pque.size()){
    if(!same(pque.top().x,pque.top().y)){
      answer.push_back(pque.top());
      unite(pque.top().x,pque.top().y);
    }
    pque.pop();
  }
  return answer;
}

int main(){
  int N,x,y;
  long long ans = 0;
  cin >> N;
  vector<tuple<int,int,int>> v1,v2;//x,y,num;
  FOR(i,1,N+1){
    cin >> x >> y;
    v1.push_back(make_tuple(x,y,i));
    v2.push_back(make_tuple(y,x,i));
  }
  sort(v1.begin(),v1.end());
  vector<edge> E;
  FOR(i,0,v1.size()-1){
    edge e;
    e.x = get<2>(v1[i]);
    e.y = get<2>(v1[i+1]);
    e.weight = get<0>(v1[i+1]) - get<0>(v1[i]);
    E.push_back(e);
  }
  sort(v2.begin(),v2.end());
  FOR(i,0,v2.size()-1){
    edge e;
    e.x = get<2>(v2[i]);
    e.y = get<2>(v2[i+1]);
    e.weight = get<0>(v2[i+1]) - get<0>(v2[i]);
    E.push_back(e);
  }
  vector<edge> mintree = Kruskal(E);
  for(auto x:mintree)ans += x.weight;
  cout << ans << endl;
}


Measured memory_bytes: 13736
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<string>
#include<complex>
#include<algorithm>
#include<vector>
#include<math.h>
#include<set>
#include<map>

int main()
{
	int x, a, b;
	scanf("%d%d%d", &x, &a, &b);
	if (b <= a) printf("delicious\n");
	else if (b <= a + x) printf("safe\n");
	else printf("dangerous\n");

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

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

    string s, t;
    cin >> s >> t;
    int ans = 1e9;
    for (int i = 0; i < s.size(); i++) {
        int cur = 0, cnt = 0;
        while (cur != t.size()) {
            if (s[i + cur] == t[cur])
                cnt++;
            cur++;
        }

        ans = min(ans, (int)t.size() - cnt);
        if (i == s.size() - t.size())
            break;
    }

    cout << ans << endl;
}

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

typedef long long int ll;
ll powk(ll a, ll n = 2){
    ll r = 1;
    for(ll i = 0;i < n;i++){
        r *= a;
    }

    return r;
}

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

    ll ans = a[0];

    for(ll i = 1;i < n;i++){
        ans = __gcd(ans, a[i]);
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

vector <ll> numList, leftG, rightG;

ll gcd(ll a, ll b) {
    if(a < b) gcd(b, a);
    ll r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

ll lcm(ll a, ll b) {
    return a*gcd(a,b) * b;
}
int main() {
    

    ll n;
    cin >> n;
    ll tmpG = 0;
    for (ll i=0;i<n;i++){
        ll tmp;
        cin >> tmp;
        numList.push_back(tmp);
        if(i==0){
            tmpG = tmp;
        }else{
            tmpG = gcd(tmp, tmpG);
        }
        leftG.push_back(tmpG);
    }
    reverse(numList.begin(), numList.end());
    for (ll i=0;i<n;i++){
        if(i==0){
            tmpG = numList[i];
        }else{
            tmpG = gcd(tmpG, numList[i]);
        }
        rightG.push_back(tmpG);
    }
    reverse(rightG.begin(), rightG.end());
    ll ans = 0;
    for(ll i=0;i<n;i++){
        ll tmp;
        if(i==0){
            ans = rightG[i+1];
            continue;
        }else if(i==n-1){
            tmp = leftG[i-1];
        }else{
            tmp = gcd(rightG[i+1], leftG[i-1]);
        }
        if(ans < tmp){
            ans = tmp;
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 3308
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <map>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
template<class T>using vv = vector<vector<T>>;

#define in(v) v; cin >> v;
// #define rep(i,n) for(int i=0;i<(n);++i)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

#define rrep(i,n) for(int i=(n);i>=0;--i)
const int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};
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;}

// debug
template<class T>ostream& operator<<(ostream& os,const vector<T>& vec){os<<"{";for(size_t i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
ostream& operator<<(ostream& os,const vector<char>&v){for(size_t i=0;i<v.size();++i)os<<v[i];return os;}
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>& rhs){os<<"("<<rhs.first<<", "<<rhs.second<<")";return os;}


#ifdef LOCAL
void debug() {cerr << "\n";}
template<class First> void debug(const First& first) {cerr<<first<<"\n";}
template<class First, class... Rest> void debug(const First& first, const Rest&... rest) {cerr<<first<<",";debug(rest...);}
#else
#define debug(...) 42
#endif

int main() {
  int in(N);
  string in(S);

  map<char, int> m;
  m['R'] = 0; m['G'] = 1; m['B'] = 2;
  vv<int> count(3, vi(N+1, 0));

  rep(i, N) {
    count[0][i+1] = count[0][i];
    count[1][i+1] = count[1][i];
    count[2][i+1] = count[2][i];
    ++count[m[S[i]]][i+1];
  }
  ll ans = 0;
  rep(i, N) {
    rep(k, i+2, N) {
      if (S[i] == S[k])
        continue;
      int rest = 3 - m[S[i]] - m[S[k]];
      if ((k-i) % 2 != 0) {
        ans += count[rest][k] - count[rest][i];
      } else {
        ans += count[rest][k] - count[rest][i];
        if (m[S[(i+k)/2]] == rest)
          --ans;
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3680
import java.util.*;
import java.io.*;
import java.math.BigInteger; 

 public class Main{
// taking inputs
static BufferedReader s1;
static BufferedWriter out;
static String read() throws IOException{String line="";while(line.length()==0){line=s1.readLine();continue;}return line;}
static int int_v (String s1){return Integer.parseInt(s1);}
static long long_v(String s1){return Long.parseLong(s1);}
static int[] int_arr() throws IOException{String[] a=read().split(" ");int[] b=new int[a.length];for(int i=0;i<a.length;i++){b[i]=int_v(a[i]);}return b;}
static long[] long_arr() throws IOException{String[] a=read().split(" ");long[] b=new long[a.length];for(int i=0;i<a.length;i++){b[i]=long_v(a[i]);}return b;}
static void assign(){s1=new BufferedReader(new InputStreamReader(System.in));out=new BufferedWriter(new OutputStreamWriter(System.out));}
// ends

//......................................@uthor_Alx..............................................


//  (Binary lifting)LCS implementation <O(NlogN,logN)>...<preprocessing,query>
//static int l,time;
//static int[][] f; // f[n][l]..
//static int[] tin, tout;
//static List<Integer>[] adj;
/*	return tin[u]<=tin[v]&&tout[u]>=tout[v]; 
}
static void dfs(int u, int p){
	tin[u]=time++;
	f[u][0]=p;
	for(int i=1;i<=l;i++){
		f[u][i]= f[f[u][i-1]][i-1];
	}

	for(int v: adj[u]){
		if(v!=p) dfs(v,u);
	}
	tout[u]=time++;
}
static int lca(int u, int v){
	if(ok(u,v)){return u;}
	if(ok(v,u)){return v;}

	for(int i=l;i>=0;i--){
		if(!ok(f[u][i],v)){
			u=f[u][i];
		}
	}
	return f[u][0];
}*/

public static void main(String[] args) throws  IOException{
	        		  assign();
              int[] arr=int_arr();
              int n=arr[0],x=arr[1],y=arr[2];
              Map<Integer,Integer> map=new HashMap<>();
              for(int i=1;i<=n;i++){
              	for(int j=i+1;j<=n;j++){
              		int k1=Math.abs(i-x)+Math.abs(y-j)+1;
              		int k2=Math.abs(i-j);
              		int k3=Math.min(k1,k2);
              		map.put(k3,map.getOrDefault(k3,0)+1);
              	}
              }
              for(int i=1;i<n;i++){
              	int xx= map.get(i)!=null? map.get(i):0;
              	out.write(xx+"\n");
              }
              
              out.flush();
	        		 
	        	}
	       
	          
	        }

	    

	
  





Measured memory_bytes: 59860
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
#define MOD 1000000007ll // prime
// How to devide :
// ModInt a(6ll);
// ModInt b(2ll);
// a *= b.exp(MOD-2ll);  -> a/=b;  result: a = 3
struct ModInt{
	ll val;
	ModInt():val(0ll){}
	ModInt(ll v):val(((v%MOD)+MOD)%MOD){}
	ModInt exp(ll y)const{
		if(!y)return ModInt(1ll);
		ModInt a = exp(y/2ll);
		a *= a;
		if(y&1)a*=(*this);
		return a;
	}
	bool operator==(const ModInt& x)const{return val==x.val;}
	inline bool operator!=(const ModInt& x)const{return !(*this==x);}
	bool operator<(const ModInt& x)const{return val<x.val;}
	bool operator>(const ModInt& x)const{return val>x.val;}
	inline bool operator>=(const ModInt& x)const{return !(*this<x);}
	inline bool operator<=(const ModInt& x)const{return !(*this>x);}
	ModInt& operator+=(const ModInt& x){if((val+=x.val)>=MOD)val-=MOD;return *this;}
	ModInt& operator-=(const ModInt& x){if((val+=MOD-x.val)>=MOD)val-=MOD;return *this;}
	ModInt& operator*=(const ModInt& x){(val*=x.val)%=MOD;return *this;}
	ModInt operator+(const ModInt& x)const{return ModInt(*this)+=x;}
	ModInt operator-(const ModInt& x)const{return ModInt(*this)-=x;}
	ModInt operator*(const ModInt& x)const{return ModInt(*this)*=x;}
};
istream& operator>>(istream&i,ModInt&x){i>>x.val;return i;}
ostream& operator<<(ostream&o,const ModInt&x){o<<x.val;return o;}
int n,m;
int x[100100],y[100100];
ModInt X,Y;
int main(){
	scanf("%d %d",&n,&m);
	for(int i=0;i<n;i++)scanf("%d",&x[i]);
	for(int i=0;i<m;i++)scanf("%d",&y[i]);
	int s = 1-n;
	for(int i=0;i<n;i++){
		X += ModInt(x[i])*ModInt(s);
		s += 2;
	}
	s = 1-m;
	for(int i=0;i<m;i++){
		Y += ModInt(y[i])*ModInt(s);
		s += 2;
	}
	cout << X*Y << endl;
    return 0;
}


Measured memory_bytes: 1024
MOD = 10 ** 9 + 7
ONE = '1'.freeze

def nCk(n, k)
  res = 1
  i = k
  j = 1
  while i > 0
    res = res * (n - i + 1)
    res %= MOD
    j *= i
    j %= MOD
    i -= 1
  end
  res *= inv(j)
  res %= MOD
  res
end

def repeated_nCk(n, k)
  # 仕切りのイメージで
  nCk(n + k - 1, n - 1) % MOD
end

def inv(x)
  res = 1
  beki = x
  (MOD - 2).to_s(2).reverse.chars do |digest|
    res = (beki * res) % MOD if digest == ONE
    beki = (beki * beki) % MOD
  end
  res
end

n, k = gets.split.map(&:to_i)
combinations = nCk(n - 1, 2)
ans = []
if k > combinations
  puts -1
else
  (2..n).each do |i|
    ans << [1, i]
  end
  deduction = combinations - k
  (2..n).to_a.combination(2).each do |a, b|
    break if deduction == 0
    ans << [a, b]
    deduction -= 1
  end
  puts ans.size
  ans.each { |a, b| puts "#{a} #{b}"}
end


Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E18;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);



int main(){fastio
    ll x;cin>>x;
    cout<<1-x<<endl;
    

    return 0;
}





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

using namespace std;

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

	int N, T, S;
	cin >> N >> T >> S;

	vector<int> A(N);
	vector<int> B(N);
	vector<int> dp(T+1, 0);

	for (int i = 0; i < N; i++){
		cin >> A[i] >> B[i];
	}

	int ans = 0;
	for (int n = 0; n <N; n++){
		for (int t = T-B[n]; t >= 0; t--){
			if (t < S && S < t+B[n]) continue;
			dp[t+B[n]] = max(dp[t]+A[n], dp[t+B[n]]);
			ans = max(ans, dp[t+B[n]]);
		}
	}

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

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

#define ALL(a) (a).begin(), (a).end()
#define llong long long

using namespace std;

list<pair<int,int>> tape; //first := ide, second len;

void Write(int ide, int len){
	auto itr = tape.begin();
	while(len > 0){
		while(itr->first != -1)itr++;
		if(itr->second <= len){
			len -= itr->second;
			itr->first = ide;
		}
		else{
			int nokori = itr->second - len;
			*itr = {-1, nokori};
			itr = tape.insert(itr, {ide, len});
			len = 0;
		}
	}
}

void Delete(int ide){
	for(auto itr = tape.begin(); itr != tape.end(); ++itr){
		if(itr->first == ide)itr->first = -1;
	}
}

int Ref(int sec){
	sec++;
	auto ret = tape.end();
	for(auto itr = tape.begin(); itr != tape.end(); ++itr){
		sec -= itr->second;
		if(sec <= 0){
			ret = itr;
			break;
		}
	}
	if(ret == tape.end())return -1;
	return ret->first;
}

signed main(){
	while(true){
		tape = list<pair<int,int>>(1, {-1,(int)1e9});
		int n;cin >> n;
		if(n == 0)break;
		for(int i = 0; i < n; i++){
//			for(auto e : tape)cout << e.first << ":" << e.second << " ";cerr << endl;
			char ope; cin >> ope;
			switch(ope){
				case 'W':{
					int ide, len; cin >> ide >> len;
					Write(ide, len);
				}
					break;
				case 'D':{
					int ide;cin >> ide;
					Delete(ide);
				}
					break;
				case 'R':{
					int sec;cin >> sec;
					cout << Ref(sec) << endl;
				}
					break;
			}
		}
		cout << endl;
	}



	return 0;
}




Measured memory_bytes: 3220
#include <iostream>
int main(){
    auto R = 0;
    auto G = 0;
    auto B = 0;
    auto N = 0;
    int num =0;
    std::cin >> R >> G >> B >> N;
    for(int i=0;i<=N/R;i++){
        if(R*i>N){
            break;
        }
        for(int j=0;j<=N/G;j++){
            if(R*i+G*j>N){
                break;
            }
            int kari = N-R*i-G*j;
            if(kari>=0&&kari%B ==0){
                num++;
            }
        }
    }
    std::cout << num;
}



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

int main(){
  vector<string> D = {"SUN","MON","TUE","WED","THU","FRI","SAT"}; 
  string S;
  cin >> S;
  int ans=0;
  rep(i,7){
    if(D[i]==S) ans = 7-i;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define endl '\n'
#define eps 1e-6
#define oo 1e7+5

using namespace std;

typedef long long int ll;
typedef unsigned long long ull;
typedef vector<pair<int,pair<int,int>>> dirgraph;
typedef vector<vector<int>> graph;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n;
	cin>>n;

	map<string,ll> mp;

	for(int i=1;i<n+1;i++)
	{
		string s=to_string(i);
		char first=s[0];
		char last=s[s.length()-1];
		s.clear();
		s+=first;
		s+=last;
		mp[s]++;
	}

	map<string,ll>::iterator it=mp.begin();
	ll ans=0;

	for(;it!=mp.end();it++)
	{
		string ab="";
		string ba="";
		ab+=it->first;
		ba+=ab[1];
		ba+=ab[0];
		ans+=mp[ab]*mp[ba];
	}
	cout<<ans<<endl;

	return 0;
}

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

ll DIV = (ll)1e9+7;

int main(void) {
   int N;
   cin>>N;
   string s1,s2;
   cin>>s1;
   cin>>s2;
   vector<ll> pat;
   rep(i,N) {
      if (s1[i] == s2[i]) pat.push_back(0);
      else {
         pat.push_back(1);
         i++;
      }
   }
   ll ans = 1;
   for (int i = 0; i < (int)pat.size();i++) {
      // cout<<pat[i]<<endl;
      if (i == 0 && !pat[i]) ans *=3;
      else if (i == 0 && pat[i]) ans *= 6;
      else if (pat[i-1] && pat[i]) ans *= 3;
      else if (pat[i-1] && !pat[i]) ans *= 1;
      else if (!pat[i-1] && pat[i]) ans *= 2;
      else if (!pat[i-1] && !pat[i]) ans *= 2;
      ans = ans %DIV;
   }
   cout<<ans<<endl;


   return 0;
}

Measured memory_bytes: 256
N = int(input())
H = list(map(int,input().split()))
ans = "Yes"
for i in range(1,N):
    if H[-i]+1 == H[-(i+1)]:
        H[-(i+1)] = H[-(i+1)]-1
    elif H[-i]+1 < H[-(i+1)]:
        ans ="No"
        break
print(ans)

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

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll int mystoi(string s){
	ll int rst = 0;
	for(int i = s.size()-1; i > -1; i--){
		rst += ((int)s[i]-'0')*pow(10,s.size()-i-1);
	}
	return rst;
}
int main(){
	string s;
	cin >> s;
	int len = s.size()-1;
	ll int ans = mystoi(s);
	FOR(i,1,1 << len){
		ll int tmp = 0;
		string tmpstr = "";
		REP(j,s.size()){
			tmpstr += s[j];
			if(j != s.size()-1 && ((i >> (len - 1- j)) & 1)){
				tmp += mystoi(tmpstr);
				tmpstr = "";
			}
		}
		tmp += mystoi(tmpstr);
		ans += tmp;
	}	
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define reg register
#define ll long long
inline ll read()
{
	ll x=0,w=0;char ch=getchar();
	while(!isdigit(ch))w|=ch=='-',ch=getchar();
	while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return w?-x:x;
}
struct op{ll x,y,a;}b[100000];
inline bool com(op x,op y){return x.a>y.a;}
ll n,tot,ans;
ll dis[305][305],a[305][305];
int main()
{
    n=read();
    for(reg int i=1;i<=n;++i)
        for(reg int j=1;j<=n;++j)
            a[i][j]=read(),dis[i][j]=a[i][j];
    for(reg int k=1;k<=n;++k)
        for(reg int i=1;i<=n;++i)
            for(reg int j=1;j<=n;++j)
                if(dis[i][j]>dis[i][k]+dis[k][j])
                    dis[i][j]=dis[i][k]+dis[k][j];
    reg int fl=0;
    for(reg int i=1;i<=n;++i)
        for(reg int j=1;j<=n;++j)
            if(dis[i][j]!=a[i][j])
                fl=1;
    if(fl==1){puts("-1");return 0;}
    for(reg int i=1;i<=n;++i)
        for(reg int j=1;j<i;++j)
            b[++tot]=(op){i,j,a[i][j]};
    sort(b+1,b+1+tot,com);
    reg int x,y;
    for(reg int i=1;i<=tot;++i)
    {
        x=b[i].x,y=b[i].y;fl=0;
        for(reg int j=1;j<=n;++j)
        {
            if(j==x)continue;if(j==y)continue;
            if(dis[x][j]+dis[j][y]==dis[x][y])
            {fl=1;break;}
        }
        if(fl==0)ans+=dis[x][y];
    }printf("%lld\n",ans);
	return 0;
}


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

int main()
{
    int n;
    cin >> n;
    int c = 0;
    int min;
    cin >> min;
    int r;
    cin >> r;
    int profit = r - min;
    if(r < min) min = r;
    for(int i = 2; i < n; ++i){
        cin >> r;
        if(r - min > profit){
            profit = r - min;
        }
        if(r < min) min = r;
    }
    cout << profit << endl;
    return 0;
}

Measured memory_bytes: 3096
N = int(input())
D = [[0 for j in range(2)] for i in range(N)]
c, t = 0, 0

for i in range(N):
    D[i][0], D[i][1] = map(int, input().split())
    if D[i][0] == D[i][1]:
        c += 1
    else:
        c = 0
    if c == 3:
        t = 1
if t == 1:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9132
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>>s;
  int c=0;
  if(s[0]=='R' && s[1]=='R' && s[2]=='R')
    c=3;
  else if(s[0]=='R' && s[1]=='R' || s[1]=='R' && s[2]=='R')
    c=2;
  else if(s[0]=='R' || s[1]=='R' ||s[2]=='R')
    c=1;
  else
    c=0;
  cout<<c<<endl;
}
      

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

int main() {
    long long N;
    cin >> N;
    long long cost[5];
    for (int i=0; i<5; i++) cin >> cost[i];
    long long min_ = cost[0];
    for (int i=1; i<5; i++)
        if (cost[i] < min_) min_ = cost[i];

    long long res = 0;
    res += (N + (min_ - 1)) / min_;
    res += 4;
    cout << res << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
        int N;
        int min, max,a;
        min = 1010;
        max = -1;
        cin>>N;
        for(int i=0;i<N;i++){
                cin>>a;
                if(min>a)
                        min = a;
                if(max<a)
                        max = a;
        }
        cout<<max-min<<endl;

}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         sort(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve() {
  ll n, m; cin >> n >> m;

  if (n == 1 && m == 1) outl(1);
  else if (n == 1 && m != 1) outl(m - 2);
  else if (n != 1 && m == 1) outl(n - 2);
  else outl((n - 2) * (m - 2));
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


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

int main() {
    int N; cin>>N;
    vector<int>a(N);
    rep(i,N)cin>>a[i];
    map<int,int>mp;
    int i=0;
    int cnt=0;
    mp[1]++;
    if(a[0]==2){
        cout<<1<<endl;
        return 0;
    }
    while(1){
        cnt++;
        mp[a[i]]++;
        if(mp[a[i]]>=2){
            cout<<-1<<endl;
            return 0;
        }
        i=a[i]-1;
        if(a[i]==2){
            cout<<cnt+1<<endl;
            return 0;
        }
        }
    }

Measured memory_bytes: 5376
#include "bits/stdc++.h"
using namespace std;
int main()

{
   int a,b;
   cin >> a >> b;

   int x;
   x = a - b;

   if (x % 2 == 0){
       int y;
       y = x / 2;

       int z,c;

       if (y > 0){
           z = a + y;
           c = b + y;
           cout << min (z, c) << endl;
       }

       else if (y < 0){
           z = a - y;
           c = b - y;
           cout << min (z, c) << endl;
       }  
   }

   else {
       cout << "IMPOSSIBLE" << endl;
   }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws java.io.IOException {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            char[] in = sc.next().toCharArray();
            System.out.println(joi(in));
            System.out.println(ioi(in));
        }
    }

    public static int joi(char[] in) {
        int ans = 0;
        char buf = '0';
        for (int i = 0; i < in.length; i++) {
            switch (in[i]) {
            case 'J':
                buf = in[i];
                break;
            case 'O':
                if (buf == 'J') {
                    buf = 'O';
                } else
                    buf = '0';
                break;
            case 'I':
                if (buf == 'O') {
                    buf = '0';
                    ans++;
                } else
                    buf = '0';
                break;
            default:
                buf = '0';
            }
        }
        return ans;
    }

    public static int ioi(char[] in) {
        int ans = 0;
        char buf = '0';
        for (int i = 0; i < in.length; i++) {
            switch (in[i]) {
            case 'I':
                if (buf == 'O') {
                    buf = 'I';
                    ans++;
                }
                buf = in[i];
                break;
            case 'O':
                if (buf == 'I') {
                    buf = 'O';
                } else
                    buf = '0';
                break;
            default:
                buf = '0';
            }
        }
        return ans;
    }
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
#define ll long long
#define N 100010
using namespace std;
int n,a[N];
ll s[N],ans,no=1;
int main(){
	cin>>n;
	for (int i=0;i<=n;i++)cin>>a[i];
	for (int i=n;i>=0;i--)s[i]=s[i+1]+a[i];
	for (int i=0;i<=n;i++){
		ans+=no;
		no=no-a[i];
		if (no<0){puts("-1");return 0;}
		no=min(no*2,s[i+1]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4804
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;


ll a[55];
int n;

void print1(ll mx){
    int idx;
    rep(i, n) if (a[i] == mx) idx = i + 1;
    rep(i, n) cout << idx << " " << i + 1 << endl;
    rep(i, n-1) cout << i + 1 << " " << i + 2 << endl;
}

void print2(ll mn){
    int idx;
    rep(i, n) if (a[i] == mn) idx = i + 1;
    rep(i, n) cout << idx << " " << i + 1 << endl;
    rrep(i, n-1) cout << i + 2 << " " << i + 1 << endl;
}

int main(){
    cin >> n;
    ll mx = -LINF, mn = LINF;
    rep(i, n) {
        cin >> a[i];
        mx = max(mx, a[i]);
        mn = min(mn, a[i]);
    }

    cout << 2 * n - 1 << endl;

    if (abs(mx) >= abs(mn)){
        print1(mx);
    }
    else if (abs(mn) > abs(mx)){
        print2(mn);
    }

    return 0;
}


Measured memory_bytes: 3636