akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

main(){
  int ball_c;
  cin >> ball_c;
  vector<vector<int>> ball_r(ball_c, vector<int>(2));
  
  for(int i = 0; i < ball_c; i++){
  for(int j = 0; j < 2; j++){ 
    cin >> ball_r.at(i).at(j);
  }
  }
  
  vector<int> p_q(2);
  int ans = 0;
  int zero_c = 0;
  
  for(int i = 0; i < ball_c; i++){
  for(int j = 0; j < ball_c; j++){
    
    if(i == j ){
      continue;
    }  
    zero_c = 0;
    
    p_q.at(0)=ball_r.at(j).at(0)-ball_r.at(i).at(0);
    p_q.at(1)=ball_r.at(j).at(1)-ball_r.at(i).at(1);
    
    for(int k = 0; k < ball_c; k++){
    for(int l = 0 ; l < ball_c; l++){
      
      if(ball_r.at(k).at(0)-ball_r.at(l).at(0) == p_q.at(0)){
      if(ball_r.at(k).at(1)-ball_r.at(l).at(1) == p_q.at(1)){
        zero_c ++;
        //cout << k << " "<< l <<endl;
        break;
      }
      }
      
    }    
    }
    
    ans = max(ans,zero_c);
     
  }
  }
  
  cout << ball_c - ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <string>
#include <tuple>
#include <utility>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
  ll n; cin >> n;
  vvll edges(n, vll(n, -1));
  REP(i, n) {
    ll u, k; cin >> u >> k;
    REP(j, k) {
      ll v, c; cin >> v >> c;
      edges.at(u).at(v) = c;
    }
  }
  vll d(n, HIGHINF);
  V<bool> visited(n, false);
  d.at(0) = 0;
  REP(i, n) {
    ll now = -1;
    ll mind = HIGHINF;
    REP(j, n) {
      if (!visited.at(j) && d.at(j) < mind) {
        now = j;
        mind = d.at(j);
      }
    }
    REP(j, n) {
      if (edges.at(now).at(j) != -1 && d.at(j) > d.at(now) + edges.at(now).at(j)) {
        d.at(j) = d.at(now) + edges.at(now).at(j);
      }
    }
    visited.at(now) = true;
  }
  REP(i, n) cout << i << ' ' << d.at(i) << endl;
  return 0;
}



Measured memory_bytes: 3148
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <set>

using namespace std;

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

const ll mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;

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

int main()
{
    int h,w;cin >> h >> w;
    char f[h][w];
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> f[i][j];
        }
    }
    bool ans = true;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(f[i][j] == '#'){
                bool ok = false;
                for(int k = 0; k < 4; k++){
                    int ny = i + dx[k];
                    int nx = j + dy[k];
                    if(ny >= 0 && ny < h && nx >= 0 && nx < w){
                        if(f[i][j] == '#' && f[ny][nx] == '#'){
                            ok = true;
                        }
                    }
                }
                if(!ok){
                    ans = false;
                }
            }
        }
    }
    if(ans)cout << "Yes";
    else cout << "No";
}

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

using namespace std;

const int N = 2e5+5;

double d , s , t;

int main(){
    cin >> d >> t >> s;
    double tim = d / s;
    //cout << tim << "\n";
    if(tim <= t){
        puts("Yes");
    } else {
        puts("No");
    }
}


Measured memory_bytes: 3720
#include <algorithm>
#include <iostream>
#include <iterator>
#include <sstream>
#include <vector>

using namespace std;

int main(int argc, char const *argv[]) {
  int A, B;
  cin >> A >> B;
  if (A == B) {
    cout << max(B, A) * 2 << endl;
  } else {
    cout << max(B, A) * 2 - 1 << endl;
  }
}

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

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;
    Func cin2;
    void calc()
    {
        cin = new Scanner();
        cin2 = new Func();
        string s=cin.next();
      int ans=700;
        for(int i=0;i<3;i++)if(s[i]=='o')ans+=100;
        Console.WriteLine(ans);
    }
}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Answer
{
    public void Int2DArrayAns(int[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
    public void Char2DArrayAns(char[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
}

class Func
{
    public long GCDLong(long a, long b)
    {
        while(a!=0)
        {
          long t=a;
          a=b%a;
          b= t;
        }
      
        return b;        
    }
}

Measured memory_bytes: 11092
A, B, C, X, Y = gets.split.map(&:to_i)

if A + B <= 2 * C
  puts A * X + B * Y
else
  ans = 0
  m = [X, Y].min
  x = X - m
  y = Y - m
  ans += m * 2 * C

  if A > 2 * C
    ans += x * 2 * C
  else
    ans += x * A
  end

  if B > 2 * C
    ans += y * 2 * C
  else
    ans += y * B
  end

  puts ans
end


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

char grid[105][105];
int H, W;
int memo[105][105];

bool inside (int x, int y)
{
    if (x>H || y>W || x<1 || y<1)
    {
        return false;
    }

    return true;
}

int findroute(int x, int y)
{
    if (!inside(x, y))
    {
        return 1000000000;
    }

    if (memo[x][y]!=-1)
    {
        return memo[x][y];
    }

    if (x==H && y==W)
    {
        if (grid[x][y]=='#')
        {
            return 1;
        }

        else
        {
            return 0;
        }
    }

    if (grid[x][y]=='.')
    {
        return memo[x][y]=min(findroute(x+1, y), findroute(x, y+1));
    }

    else if (grid[x][y]=='#')
    {
        return memo[x][y]=min(findroute(x+1, y)+(grid[x+1][y]=='.'), findroute(x, y+1)+(grid[x][y+1]=='.'));
    }
}

int main()
{
    memset(memo, -1, sizeof(memo));

    cin>>H>>W;

    for (int i=1; i<=H; i++)
    {
        for (int j=1; j<=W; j++)
        {
            cin>>grid[i][j];
        }
    }

    cout<<findroute(1, 1)<<endl;
}

Measured memory_bytes: 3708
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>
#include<cstdlib>
#include<ctime>


using namespace std;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const double PI = acos(-1.0);
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define all(v) v.begin(), v.end()

inline void finish() {
	cout << -1 << endl;
	exit(0);
}

template <typename T>
inline void debug(vector<T> v) {
	cout << "[";
	for (ll i = 0; i < v.size() - 1; ++i) {
		cout << v[i] << ", ";
	}
	cout << v[v.size() - 1] << "]" << endl;
}

void Main();
inline void DebugMain() {
	while (true) {
		Main();
	}
}

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

	bool debug = false;
	if (debug) {
		cout << "\x1b[41m" << "Debug Mode " << endl;
	}
	(debug) ? DebugMain() : Main();
	return 0;
}

inline void Main() {
	int X,Y;
	int ans;
	string S;
	
	cin >> S;

	if(S == "SUN"){
		ans = 7;
	
	}else if (S == "MON") {
		ans = 6;

	}
	else if (S == "TUE") {
		ans = 5;

	}
	else if (S == "WED") {
		ans =4;

	}
	else if (S == "THU") {
		ans = 3;

	}
	else if (S == "FRI") {
		ans =2;

	}
	else if (S == "SAT") {
		ans = 1;
	}

	cout << ans;
}


Measured memory_bytes: 256
N = int(input())
a = input().split()
A = [int(u) for u in a]
cur = 1000
sto = 0
for i in range(1, N):
	if A[i] > A[i - 1]:
		b = cur // A[i - 1]
		sto += b
		cur -= b * A[i - 1]
		cur += sto * A[i]
		sto = 0
	else:
		cur += sto * A[i - 1]
		sto = 0
		b = cur // A[i]
		sto += b
		cur -= b * A[i]

if not sto == 0:
	cur += sto * A[N - 1]

print(cur)


Measured memory_bytes: 9204
use strict;
use warnings;

my ($n,$d)=split(' ',<STDIN>);

my @X=();

for (my$i=0;$i<$n;$i++) {
    
    my @a = split(' ',<STDIN>);
    
    push ( @{$X[$i]}, @a );
    
}

my $flag = 0;

for (my$i=0;$i<$n;$i++) {
    
    for (my$j=$i+1;$j<$n;$j++) {

	my @a = @{$X[$i]};
	my @b = @{$X[$j]};

	my $tmp = 0;
	
	for (my$k=0;$k<$d;$k++) {
	    
	    $tmp = $tmp + ( $a[$k] - $b[$k] )**2;
	    
	}

	my $r = sqrt ( $tmp );

	if ( abs ( $r - int ( $r ) ) == 0 ) {

	    $flag = $flag + 1;
	    
	}	    
	
    }
}

print $flag;


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

/*
    参考リンク
    ACL Beginner Contest D - Flat Subsequence
      https://atcoder.jp/contests/abl/tasks/abl_d

    LIS でも大活躍！ DP の配列使いまわしテクニックを特集
      https://qiita.com/drken/items/68b8503ad4ffb469624c
*/

// 抽象化したセグメント木
template <class Monoid>
struct SegTree {
  using Func = function<Monoid(Monoid, Monoid)>;
  const Func F;
  const Monoid UNITY;
  int SIZE_R;
  vector<Monoid> dat;

  SegTree(int n, const Func f, const Monoid &unity) : F(f), UNITY(unity) {
    init(n);
  }
  void init(int n) {
    SIZE_R = 1;
    while (SIZE_R < n) SIZE_R *= 2;
    dat.assign(SIZE_R * 2, UNITY);
  }

  /* set, a is 0-indexed */
  void set(int a, const Monoid &v) { dat[a + SIZE_R] = v; }
  void build() {
    for (int k = SIZE_R - 1; k > 0; --k) dat[k] = F(dat[k * 2], dat[k * 2 + 1]);
  }

  /* update a, a is 0-indexed */
  void update(int a, const Monoid &v) {
    int k = a + SIZE_R;
    dat[k] = v;
    while (k >>= 1) dat[k] = F(dat[k * 2], dat[k * 2 + 1]);
  }

  /* get [a, b), a and b are 0-indexed */
  Monoid get(int a, int b) {
    Monoid vleft = UNITY, vright = UNITY;
    for (int left = a + SIZE_R, right = b + SIZE_R; left < right;
         left >>= 1, right >>= 1) {
      if (left & 1) vleft = F(vleft, dat[left++]);
      if (right & 1) vright = F(dat[--right], vright);
    }
    return F(vleft, vright);
  }
  inline Monoid operator[](int a) { return dat[a + SIZE_R]; }

  /* debug */
  void print() {
    for (int i = 0; i < SIZE_R; ++i) {
      cout << (*this)[i];
      if (i != SIZE_R - 1) cout << ",";
    }
    cout << endl;
  }
};

int solve(const vector<int> &a, int k) {
  int n = (int)a.size();

  // セグメント木 (区間取得を max としたもの)
  // 0 <= a[i] <=300000 なのでセグメント木について n = 300050
  SegTree<int> dp(
      300050, [](int a, int b) { return max(a, b); }, 0);

  // 更新
  int res = 0;
  rep(i, n) {
    int h1 = max(a[i] - k, 0);
    int h2 = min(a[i] + k, 300040);
    // 値取得
    int A = dp.get(h1, h2 + 1);

    // 更新
    if (dp.get(a[i], a[i] + 1) < A + 1) {
      dp.update(a[i], A + 1);
      res = max(res, A + 1);
    }
  }
  return res;
}

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  cout << solve(a, k) << endl;
}

Measured memory_bytes: 8524
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;

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;}

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    int n; cin>>n;
    vi a(n);
    rep(i,0,n)cin>>a[i];
    rep(i,0,n){
        a[i]-=i+1;
    }
    ll ans=0;
    sort(a.begin(),a.end());
    ll res;
    if(n%2){
        res=a[n/2];
    }
    else
    {
        res=(a[n/2-1]+a[n/2])/2;
    }
    rep(i,0,n){
        ans+=abs(a[i]-res);
    }
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>

using namespace std;

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

const int N_MAX = 100000;
const int H_I_MAX = 1000000000;

int N;
int H[N_MAX];

void solve() {
  int ans = 0;
  int str = 0;
  REP(i, N - 1) {
    if (H[i + 1] <= H[i]) ans = max(ans, ++str);
    else str = 0;
  }
  printf("%d\n", ans);
}

void input() {
  scanf("%d", &N);
  REP(i, N) scanf("%d", H + i);
}

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


Measured memory_bytes: 512
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanf("%d", &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
	}
	breakCount := 0
	currentI := 1

	for p := 0; p < n; p++ {
		if a[p] == currentI {
			currentI++
		} else {
			breakCount++
		}
	}
	if breakCount < n {
		fmt.Println(breakCount)
	} else {
		fmt.Println("-1")
	}
}


Measured memory_bytes: 5632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double db;
#define fi first
#define se second
#define pi pair<ll,ll>
#define pii pair<ll,pi>
#define pb push_back
#define mk make_pair
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int l, r, d;
	cin >> l >> r >> d;
	int ans = 0;
	for (int i = l; i <= r; i++) {
		if (i % d == 0)ans++;
	}
	cout << ans << endl;




}

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

using ll = long long;
const int INF = 1e9;

int main() {
    string s;
    int x, y, k[2] = {0, 0};
    cin >> s >> x >> y;
    s += "T";
    vector<vector<vector<bool>>> xy(2, vector<vector<bool>>(2, vector<bool>(8001, false)));
    xy[0][0][0] = true;
    xy[0][1][0] = true;
    int d = 0, c = 0, p = 0;
    while (s[p] == 'F') p++;
    for (int i = p;  i < s.size(); i++) {
        if (s[i] == 'F') {
            c++;
            continue;
        }
        rep(j, 8001) xy[1 - k[d]][d][j] = false;
        rep(j, 8001) {
            if (xy[k[d]][d][j]) {
                xy[1 - k[d]][d][j + c] = true;
                xy[1 - k[d]][d][abs(j - c)] = true;
            }
        }
        k[d] = 1 - k[d];
        c = 0;
        d = 1 - d;
    }
    if (xy[k[0]][0][abs(x - p)] && xy[k[1]][1][abs(y)]) cout << "Yes" << endl;
    else cout << "No" << endl;
    /*
    rep(i, 2) {
        rep(j, 2) {
            rep(k, 10) {
                cout << xy[j][i][k];
            }
            cout << endl;
        }
        cout << endl;
    }
    rep(i, 2) cout << k[i];
    cout << endl;
    */
}

Measured memory_bytes: 256
#encoding: utf-8

$map = []
$vis = [false] * 100
$depth = [-1] * 100

def build_map
  $n = gets.rstrip.to_i
  $map = []
  $n.times { $map << [0] * $n}
  (1..$n).each do |node|
    arr = gets.rstrip.split(/\s/).map(&:to_i)
    u, k = arr[0], arr[1]
    node = arr[2..-1]
    node.each { |v| $map[u - 1][v - 1] = 1}
  end
end

def bfs(x)
  $depth[x] = 0
  que = [x]
  while not que.empty?
    u, que = que.first, que.drop(1)
    $map[u].each_with_index do |node, idx|
      if node == 1 and $depth[idx] < 0
        $depth[idx] = $depth[u] + 1
        que << idx
      end
    end
  end
end

def solve
  build_map
  bfs(0)
end

solve

(0..$n - 1).each do |node|
  puts "#{node + 1} #{$depth[node]}"
end

Measured memory_bytes: 6200
#include <iostream>
#include <algorithm>

constexpr int MAX_N = 1000;
constexpr int MAX_M = 1000000;

int N, M;
long long v[MAX_N], c[MAX_N];
long long dp[MAX_M + 1];

int main(){

	std::cin >> N >> M;

	for(int i = 0; i < N; ++i){
		std::cin >> v[i] >> c[i];
	}

	for(int i = 0; i < M; ++i){
		dp[i] = -1;
	}
	dp[0] = 0;

	for(int i = 0; i < N; ++i){
		for(int j = M; j >= 0; --j){
			if(j - c[i] >= 0 && dp[j - c[i]] != -1){
				dp[j] = std::max(dp[j], dp[j - c[i]] + v[i]);
			}
		}
	}

	long long ans = 0;
	for(int i = 0; i <= M; ++i){
		ans = std::max(ans, dp[i]);
	}

	std::cout << ans << std::endl;

	return 0;
}



Measured memory_bytes: 3204
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>

 
#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s
 
typedef long long ll;
 
using namespace std;


ll modd = 1000*1000*1000+7;

int main()   {


    ios_base::sync_with_stdio(false);

    cout.precision(17);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int> rand_gen(0, modd);   // rand_gen(rng) gets the rand no

//    auto start = chrono::steady_clock::now()

//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readint(h); readint(w); readint(m);
        vector<int> verticals(w), horizontals(h);
        vector<pair<int,int>> targets;
        forr(i,0,m) {
            readint(hh); readint(ww); hh--; ww--;
            targets.push_back(make_pair(hh,ww));
            verticals[ww]++; horizontals[hh]++;
        }
        int max_w = 0, max_h = 0;
        for(auto x : verticals) { max_w = max(max_w, x); }
        for(auto y : horizontals) { max_h = max(max_h, y); }
        set<int> w_cand, h_cand;
        forr(i,0,w) {
            if (verticals[i]==max_w) {  w_cand.insert(i); }
        }
        forr(i,0,h) {
            if (horizontals[i]==max_h) {  h_cand.insert(i); }
        }
        int addition = 0;
        int total = 0;
        for(auto p : targets) {
            if ((set_map_includes(h_cand, p.first)) && (set_map_includes(w_cand, p.second))) {
                total++;
            }
        }
        if (total == h_cand.size() * w_cand.size()) {
            addition = -1;
        }

        cout << max_w + max_h + addition << endl;

    }

//    auto end = chrono::steady_clock::now();
//    cerr << chrono::duration_cast<chrono::milliseconds>(end - start).count() << endl;

    return 0;
}

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

int main(){
  int n, x, ans = 0;
  int d[101] = {0};
  
  cin >> n;
  
  for ( int i = 0; i < n; i++ ){
    cin >> x;
    if ( d[x] == 0 ){
      d[x] = 1;
      ans ++;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
import io.{StdIn => in}
import scala.collection.{mutable => mu}

object Main extends App {
  import MapHelper._
  val map = mu.HashMap.empty[Long, Long]

  val Array(n, m) = in.readLine.split(" ").map(_.toInt)

  in.readLine.split(" ").map(_.toLong).foreach {
    map.addOrUpdate(_, 1)
  }

  Iterator.continually(in.readLine)
    .take(m)
    .map(_.split(" ").map(_.toLong))
    .foreach { e => map.addOrUpdate(e(1), e(0)) }

  val entries = map.iterator.toArray.sortBy(_._1)(Ordering[Long].reverse)

  def rec(acc: Long, cnt: Long, i:Int): Long = {
    val k = entries(i)._1
    val v = entries(i)._2
    if(cnt + v >= n) acc + k * (n - cnt)
    else rec(acc + (k * v), cnt + v, i + 1)
  }

  val ans = rec(0, 0, 0)
  println(ans)

  object MapHelper {
    implicit class AddOrUpdate[A](map:mu.HashMap[Long,Long]) {
      def addOrUpdate(key:Long, value:Long):mu.HashMap[Long,Long] =
      {
        if(map.contains(key)) map(key) += value
        else map += (key -> value)
        map
      }
    }
  }
}

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

using ll = long long;

const long long MOD = 1e9+7;

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

    //sum[i+1][j] i番目以降の各桁のbitのsum
    vector<vector<ll>> sum(n + 1, vector<ll>(64));
    for (int i = n - 1; i >= 1; i--) {
        for (int j = 0; j < 64; j++) {
            sum.at(i).at(j) += sum.at(i + 1).at(j);
            if (a.at(i) & (1ll << j)) sum.at(i).at(j)++;
        }
    }
    
    ll res = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 64; j++) {
            if (a.at(i) & (1ll << j)) {
                res += (1ll << j) % MOD * ((n - i - 1) - sum.at(i + 1).at(j)) % MOD;
            }
            else {
                res += (1ll << j) % MOD * (sum.at(i + 1).at(j)) % MOD;
            }
            res %= MOD;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 164352
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)
#define REPO(i, n) for (ll i = 1; i <= n; i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(), n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll n;
int main() {
    cin >> n;
    vector<ll> s(n);
    ll ans = 0;
    REP(i,n){
        cin >> s[i];
        if (i % 2 == 0 and s[i] % 2 == 1) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
n = int(input())

A=[[[0 for _ in range(10)] for _ in range(3)] for _ in range(4)]
#0??§?????????
#[[[0 0 0 0 0 0 0 0 0 0],
#  [0 0 0 0 0 0 0 0 0 0],
#  [0 0 0 0 0 0 0 0 0 0]],
# [[0 0 0 0 0 0 0 0 0 0],
#  [0 0 0 0 0 0 0 0 0 0],
#  [0 0 0 0 0 0 0 0 0 0]],
# [[0 0 0 0 0 0 0 0 0 0],  
#  [0 0 0 0 0 0 0 0 0 0],
#  [0 0 0 0 0 0 0 0 0 0]],
# [[0 0 0 0 0 0 0 0 0 0],
#  [0 0 0 0 0 0 0 0 0 0],
#  [0 0 0 0 0 0 0 0 0 0]]]

#?£?    Building = b
#???    Floor    = f
#???    Room     = r
#??°    Number   = num
for i in range(n):
	b,f,r,num = input().strip().split()
	A[int(b)-1][int(f)-1][int(r)-1]+=int(num)

for i in range(4):
	for j in range(3):
		print('',' '.join(map(str,A[i][j])))
	if i!=3:
		print('#'*20)

Measured memory_bytes: 7760
#include<stdio.h>
main(){
	int W,H;
	int i,j;

	while(1){
	scanf("%d %d",&W,&H);
	if(W == 0 && H == 0) break;
	for(i=1;i<=W;i++){
		for(j=1;j<=H;j++){
			if((i+j)%2 == 0){
				printf("#");
			}
			else{
				printf(".");
			}
		}
		printf("\n");
	}
	printf("\n");
	}

	return 0;
}

Measured memory_bytes: 1000
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
	int X;
	cin >> X;
	vector<int> Xlist;
	for (int i = 1; i <= 100; i++) {
		for (int j = 2; j <= 100; j++) {
			int ans = (int)pow(i, j);
			if (ans <= X) {
				Xlist.push_back(ans);
			}
			else {
				break;
			}
		}
	}
	sort(Xlist.begin(), Xlist.end(), greater<int>());

	cout << Xlist[0] << endl;
	return 0;
}


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

int main()
{
	int i = 0, j = 0, n;
	for (int k = 1; k <= 3; k++)
	{
		cin >> n;
		if (n == 5)
			i++;
		else if (n == 7)
			j++;
	}
	if (i == 2 && j == 1)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	//system("pause");
}

Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		try (Scanner sc = new Scanner(System.in);) {
			
			int n = sc.nextInt();
			
			Deque<Integer> deque = new ArrayDeque<>();
			
			for(int i = 0; i < n; i++) {
				deque.push(sc.nextInt());
			}
			
			StringBuilder sb = new StringBuilder();
			
			for(int i = 0; i < n; i++) {
				sb.append(deque.pop());
				if(i < n - 1) {
					sb.append(" ");
				}
			}
			
			System.out.println(sb.toString());
		}
	}
}


Measured memory_bytes: 26256
#include "bits/stdc++.h"
using namespace std;

int x,y,z,ans;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>x>>y>>z;
	ans = x / (y + z);
	if(ans * (y + z) + z > x)
		cout<<ans-1;
	else
		cout<<ans;
	return 0;
}

Measured memory_bytes: 256
def getinputdata():

    array_result = []    
    array_result.append(input().split(" "))

    flg = True

    try:
        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:

        return array_result

arr_data = getinputdata()

#0 or 1 or 2
d = int(arr_data[0][0])

#1<=n<=100
n = int(arr_data[0][1])


if d==0 and n%100!=0:
    
    print(n)
    
elif d==0 and n%100==0:
    
    print(n+1)
    
elif d==1 and n%100!=0:
    
    print(n*100)
    
elif d==1 and n%100==0:
    
    print(n*100+100)
    
    
elif d==2 and n%100!=0:
    
    print(n*10000)
    
elif d==2 and n%100==0:
    
    print(n*10000+10000)
    

Measured memory_bytes: 3064
e=enumerate
n,a=open(0)
d=[0]+[-1e18]*2000
for j,(a,i)in e(sorted((-int(a),i)for i,a in e(a.split()))):d=[max(t-a*(~i-j+k+int(n)),d[k-1]-a*abs(~i+k))for k,t in e(d)]
print(max(d))

Measured memory_bytes: 77560
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int n, q, x;
int main() {
	cin >> n >> q;
	vector<int> v;
	for (int i = 1; i <= 2 * n; i++) v.push_back(i);
	while (q--) {
		cin >> x;
		vector<int> w;
		if (x != 0) {
			for (int i = x; i < 2 * n; i++) w.push_back(v[i]);
			for (int i = 0; i < x; i++) w.push_back(v[i]);
		}
		else {
			for (int i = 0; i < n; i++) {
				w.push_back(v[i]);
				w.push_back(v[i + n]);
			}
		}
		v = w;
	}
	for (int i = 0; i < 2 * n; i++) cout << v[i] << endl;
	return 0;
}

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

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

    int N;
    int len[5] = {5, 7, 5, 7, 7};
    while (cin >> N, N) {
        vector<int> w(N);
        for (int i = 0; i < N; i++) {
            string s; cin >> s;
            w[i] = s.size();
        }

        for (int i = 0; i < N; i++) {
            int pos = 0;
            bool flag = true;
            for (int j = 0; j < 5; j++) {
                int n = 0;
                while (i+pos < N && n < len[j]) {
                    n += w[i+pos];
                    pos++;
                }
                if (n != len[j]) {
                    flag = false;
                    break;
                }
            }
            if (flag) {
                cout << i+1 << endl;
                break;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 3172
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
const ll MOD=1e9+7;
ll f[605][305][305];
int n,a[605],flag[605];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=2*n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]!=-1)flag[a[i]]=1;
	}
	int cnt=0;
	for(int i=1;i<=2*n;i+=2)
	{
		if(a[i]!=-1&&a[i+1]!=-1)
		  flag[a[i]]=flag[a[i+1]]=2;
		if(a[i]==-1&&a[i+1]==-1)
		  cnt++;
	}
	f[2*n+1][0][0]=1;
	for(int i=2*n;i>=1;i--)
	{
		for(int x=0;x<=n;x++)
		for(int y=0;y<=n;y++)
		{
			if(f[i+1][x][y]==0)continue;
			f[i+1][x][y]%=MOD;
			if(flag[i]==2)f[i][x][y]=f[i+1][x][y];
			else if(flag[i]==1)
			{
				if(x)f[i][x-1][y]+=f[i+1][x][y];
				f[i][x][y+1]+=f[i+1][x][y];
			}
			else
			{
				if(x)f[i][x-1][y]+=f[i+1][x][y];
				f[i][x+1][y]+=f[i+1][x][y];
				if(y)f[i][x][y-1]+=f[i+1][x][y]*y;
			}
		}
	}
	ll ans=f[1][0][0]%MOD;
	while(cnt)
	{
		ans=ans*cnt%MOD;
		cnt--;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 437760
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

int n;

int main() {
	cin >> n;
	
	cout << n * n << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

class PartParsistentUnionFind{
    typedef pair<int,int> pii;
private:
    vector<int> par;
    vector<int> time;
    vector<vector<pii>> size;
    int now;
public:
    PartParsistentUnionFind(){}
    PartParsistentUnionFind(int N){init(N);}
    void init(int N){
        par.clear(); time.clear(); size.clear();
        par.assign(N,0);
        time.resize(N,INT_MAX);
        size.assign(N,vector<pii>(1,{0,1}));
        now = 0;
    }
    int find(int x,int T = INT_MAX){
        if(T == INT_MAX) T = now;
        if(time[x] > T) return x;
        else return find(par[x],T);
    }
    bool unite(int x,int y){
        now++;
        //cout << x << "," << y << " : ";
        x = find(x,now); y = find(y,now);
        //cout << x << "," << y << endl;
        if(x == y) return false;
        if(par[x] < par[y]) swap(x,y);
        par[x] += par[y];
        par[y] = x;
        time[y] = now;
        size[x].push_back({now,par[x]});
        return true;
    }
    int Getnow(){ return now; }
    int Getsize(int x,int T = INT_MAX){
        if(T == INT_MAX) T = now;
        int ret = 0;
        x = find(x,T);
        ret = (int)(upper_bound(size[x].begin(),size[x].end(),pii(T,INT_MAX)) - size[x].begin());
        return ret;
    }
    bool same(int x,int y,int T = INT_MAX){
        if(T == INT_MAX) T = now;
        return find(x,T) == find(y,T);
    }
};

void solve2(){
    int n,q; cin >> n >> q;
    PartParsistentUnionFind PPUF(n);
    while(q--){
        int com; cin >> com;
        int x,y; cin >> x >> y;
        if(com == 0){
            PPUF.unite(x, y);
      //      cout << x << " : " << PPUF.Getsize(x) << endl;
        }else{
            cout << PPUF.same(x,y) << endl;
        }
    }
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    //   solve1();
    solve2();
    return 0;
}



Measured memory_bytes: 3828
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  for(int i = 1; i <= 50000; i++) {
    if(n <= i*1.08 && i*1.08 < n+1) {
      cout << i << endl;
      return 0;
    }
  }
  cout << ":(" << endl;
  return 0;
}

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


int main()  {
    ll N,K,S,val=1e9;
    cin>>N>>K>>S;
    for(ll i=0;i<N;i++)
    {
        if(i<K)
            cout<<S<<" ";
        else
        {
            if(S<1e9)
                cout<<S+1<<" ";
            else
                cout<<"1 ";
        }
    }
    return 0;
}


Measured memory_bytes: 3556
#include<bits/stdc++.h>
using namespace std;
int a[10],sum;
char c;
int main(){
    while(cin>>c&&c!='\0'){
        if(c=='0') a[sum++]=0;
        else if(c=='1') a[sum++]=1;
        else{
            if(sum) sum--;
        }
    }
    if(sum){
        for(int i=0;i<sum;i++) printf("%d",a[i]);
        printf("\n"); 
    }
}

Measured memory_bytes: 256
#include<cstdio>
int main()
{
	long long int N,M;
	while (scanf("%lld %lld",&N,&M)==2)
	{
		if (N==0)printf("%lld\n",M/4);
		else if (M/N>=2)printf("%lld\n",N+(M-2*N)/4);
		else printf("%lld\n",M/2);
	}
	return 0;
}


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

using namespace std;

template< class T >
struct ConvexHullTrickAddQueryMonotone
{
  deque< pair< T, T > > L;
  int isdec;

  ConvexHullTrickAddQueryMonotone() : isdec(-1) {}

  inline T getX(const pair< T, T > &a, const T &x)
  {
    return (a.first * x + a.second);
  }

  inline bool check(const pair< T, T > &a, const pair< T, T > &b, const pair< T, T > &c)
  {
    return ((__int128_t) (b.first - a.first) * (c.second - b.second) >= (__int128_t) (b.second - a.second) * (c.first - b.first));
  }

  inline bool empty() { return (L.empty()); }

  void add(T a, T b)
  {
    pair< T, T > line(a, b);

    if(!L.empty() && L.back().first == a) {
      line.second = min(line.second, L.back().second);
      L.pop_back();
    }
    while(L.size() >= 2 && check(L[L.size() - 2], L.back(), line)) L.pop_back();
    L.emplace_back(line);

  }

  T getMinimumQuery(T x)
  {
    int low = -1, high = (int) L.size() - 1;
    while(high - low > 1) {
      int mid = (low + high) >> 1;
      if((getX(L[mid], x) >= getX(L[mid + 1], x))) low = mid;
      else high = mid;
    }
    return (getX(L[high], x));
  }

  T getMinimumQueryMonotone(T x)
  {
    while(L.size() >= 2 && getX(L[0], x) >= getX(L[1], x)) {
      L.pop_front();
    }
    return (getX(L[0], x));
  }

};

using int64 = long long;

int main()
{
  int64 N, A;
  cin >> N >> A;

  if(N == 1) {
    cout << 1 << endl;
  } else if(N <= A) {
    cout << N << endl;
  } else {
    ConvexHullTrickAddQueryMonotone< int64 > cht;
    cht.add(-1, 0);
    for(int64 j = A;; j++) {
      if(-cht.getMinimumQuery(j) >= N) {
        cout << j << endl;
        return (0);
      }
      auto val = -cht.getMinimumQueryMonotone(j - A);
      cht.add(-val, val * j);
    }
  }
}

Measured memory_bytes: 32772
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define ft first
#define sd second
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin, (x).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
typedef pair<double,double> pdd;
typedef pair<long long,long long> pll;
// scanf("%d %d %d %d",&w,&b,&d,&s); %lld
// printf("%d\n" ,points);
// const double PI=acos(-1);

int main(){
    int n,x,ind,rta=1;
    cin >> n >> x;
    int arr[n],prefix[n];
    for(int i=0;i<n;i++){
        cin >> arr[i];
    }
    prefix[0]=arr[0];
    for(int i=1;i<n;i++){
        prefix[i]=arr[i]+prefix[i-1];
    }
    rta+=upper_bound(prefix,prefix+n,x)-prefix;
    cout << rta << endl;
    return 0;
}


Measured memory_bytes: 3588
local mce, mfl, msq, mmi, mma = math.ceil, math.floor, math.sqrt, math.min, math.max
local n, m = io.read("*n", "*n", "*l")
local s, t = {}, {}
local str = io.read()
local ti = 0
local mod = 1000000007
for v in str:gmatch("%d+") do
  ti = ti + 1
  s[ti] = tonumber(v)
end
ti = 0
str = io.read()
for v in str:gmatch("%d+") do
  ti = ti + 1
  t[ti] = tonumber(v)
end
local cnt, sum = {}, {}
for i = 1, n * m do
  cnt[i], sum[i] = 0, 0
end
-- m = 1
if s[1] == t[1] then cnt[1] = 1 end
sum[1] = cnt[1]
for i = 2, n do
  if s[i] == t[1] then
    cnt[i] = 1
  end
  sum[i] = cnt[i] + sum[i - 1]
end

for i_m = 2, m do
  if s[1] == t[i_m] then
    cnt[n * (i_m - 1) + 1] = 1
  end
  sum[n * (i_m - 1) + 1] = (sum[n * (i_m - 2) + 1] + cnt[n * (i_m - 1) + 1]) % mod
  for i_n = 2, n do
    local pos = n * (i_m - 1) + i_n
    if s[i_n] == t[i_m] then
      cnt[pos] = sum[pos - n - 1] + 1
    end
    sum[pos] = (cnt[pos] + sum[pos - n] + sum[pos - 1] - sum[pos - n - 1]) % mod
  end
end
local ret = (sum[n * m] + 1) % mod
print(ret)


Measured memory_bytes: 67824
#include <iostream>
#include <vector>
#include <utility>
#include <stack>
using namespace std;
typedef pair<int, int> P;

vector<P> link[3000];
int dist[3000];
int n, m, p;

bool canGo(int i, int j)
{
    stack<int> s;
    s.push(i);
    int used[n] = {};
    while (!s.empty())
    {
        int u = s.top();
        if (u == j)
            return true;
        s.pop();
        for (P p : link[u])
        {
            if (used[p.first])
                continue;
            s.push(p.first);
            used[p.first] = 1;
        }
    }
    return false;
}

bool bellmanFord()
{
    for (int i = 0; i < n - 1; i++)
    {
        for (int j = 0; j < n; j++)
        {
            for (P p : link[j])
            {
                dist[p.first] = min(dist[p.first], dist[j] + p.second);
            }
        }
    }

    for (int i = 0; i < n; i++)
    {
        for (P p : link[i])
        {
            if (dist[p.first] > dist[i] + p.second)
            {
                if (!canGo(i, n - 1))
                    continue;
                if (!canGo(0, i))
                    continue;
                return false;
            }
        }
    }
    return true;
}

int main()
{
    cin >> n >> m >> p;
    for (int i = 0; i < m; i++)
    {
        int a, b, c;
        cin >> a >> b >> c;
        link[a - 1].push_back(P(b - 1, -(c - p)));
    }

    for (int i = 0; i < n; i++)
        dist[i] = 1e9;
    dist[0] = 0;

    bool flag = bellmanFord();
    if (flag)
        cout << max(0, -dist[n - 1]) << endl;
    else
        cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    int mx = (n - 1) * (n - 2) / 2;
    if (k > mx)
        return cout << -1, 0;

    int m = n - 1 + mx - k;
    cout << m << '\n';
    for (int i = 2; i <= n; ++i)
        cout << 1 << ' ' << i << '\n';

    int nr = mx - k, cnt = 0;
    for (int i = 2; i <= n && cnt < nr; ++i)
        for (int j = i + 1; j <= n && cnt < nr; ++j)
            cout << i << ' ' << j << '\n', cnt++;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<vector>
#include<map>
#include<queue>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
#define debug(x) cout << #x << " = " << x << endl;
typedef long long LL;
int main()
{
    long long num[10];
    long long Min = 1e16;
    for(int i = 0; i < 6; i++){
        scanf("%lld", &num[i]);
        if(i > 0) Min = min(Min, num[i]);
    }
    long long ans = ceil(1.0 * num[0] / Min) + 4;
    printf("%lld\n", ans);
    return 0;
}
    

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int a, b;
  cin >> a >> b;
  int k;
  if((a+b) % 2 == 0){
    k = (a+b)/2;
  }
  else k = 0;
  
  if(k != 0) cout << k;
  else cout << "IMPOSSIBLE";
}

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

using ll = long long;
const ll MOD = 998244353;

int main() {
    int N;
    cin >> N;
    vector<ll> A(N + 1, 1e9 + 1), B(N + 1, 1e9 + 2), C(N + 1, 1e9 + 3);
    vector<ll> s(N + 1, 0), t(N + 1, 0);
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];
    rep(i, N) cin >> C[i];
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());
    ll i = 0;
    rep(j, N) {
        while (A[i] < B[j]) i++;
        s[j + 1] = i;
    }
    i = 0;
    ll k = 0;
    rep(j, N) {
        while (B[i] < C[j]) {
            i++;
            k += s[i];
        }
        t[j + 1] = t[j] + k;
    }
    cout << t[N] << endl;
    /*
    rep(i, N + 1) {
        cout << s[i] << " " << t[i] << endl;
    }
    rep(i, N + 1) {
        cout << A[i] << " " << B[i] << " " << C[i] << endl;
    }
    */
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

void solve(long long H, long long W, long long A, long long B)
{
    char ans[H][W];

    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            if (i + 1 <= B)
            {
                if (j + 1 <= A)
                {
                    ans[i][j] = '0';
                }
                else
                {
                    ans[i][j] = '1';
                }
            }
            else
            {
                if (j + 1 <= A)
                {
                    ans[i][j] = '1';
                }
                else
                {
                    ans[i][j] = '0';
                }
            }
        }
    }

    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            cout << ans[i][j];
        }

        cout << endl;
    }
}

int main()
{
    long long H;
    scanf("%lld", &H);
    long long W;
    scanf("%lld", &W);
    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    solve(H, W, A, B);
    return 0;
}


Measured memory_bytes: 2176
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        List<int> list = new List<int>();
        
        for (int i = 0; i < n; i++){
            list.Add(int.Parse(Console.ReadLine()));
        }

        Console.WriteLine(
            list.GroupBy(x => x)
            .Select(x => x.Count())
            .Where(x => x % 2 == 1)
            .Count());
    }
}


Measured memory_bytes: 29548
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
p = 10**9+7
dp = [8,2,0]

for i in range(n-1):
    pd = dp
    dp = [(pd[0]*8)%p, (pd[0]*2+pd[1]*9)%p, (pd[1]+pd[2]*10)%p]

print(dp[-1])

Measured memory_bytes: 67588
#include<bits/stdc++.h>
using namespace std;
int x;
int main() {
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "a", stdout);
    // #endif
    cin >> x;
    puts((x >= 30) ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 3632