akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;
typedef complex<ld> com;
constexpr int inf = 1000000000;
constexpr ll INF = 1000000000000000000;
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	string a, b, c;
	cin >> a >> b >> c;
	ll x = a.size(); ll y = b.size(); ll z = c.size();
	vector<bool> ab(4001), bc(4001), ca(4001);
	rep(i, 4001) {
		bool flagab = true, flagbc = true, flagca = true;
		int dis = i - 2000;
		rep(j, y) {
			if (0 <= dis + j && dis + j < x) {
				if (a[dis + j] != '?'&&b[j] != '?'&&a[dis + j] != b[j]) flagab = false;
			}
		}
		rep(j, z) {
			if (0 <= dis + j && dis + j < y) {
				if (b[dis + j] != '?'&&c[j] != '?'&&b[dis + j] != c[j]) flagbc = false;
			}
		}
		rep(j, x) {
			if (0 <= dis + j && dis + j < z) {
				if (c[dis + j] != '?'&&a[j] != '?'&&c[dis + j] != a[j]) flagca = false;
			}
		}
		if (flagab) ab[i] = true;
		if (flagbc) bc[i] = true;
		if (flagca) ca[i] = true;
	}
	int ans = x + y + z;
	rep(i, 8001) {
		rep(j, 8001) {
			bool flag = true;
			if (0 <= i - 2000 && i - 2000 <= 4000 && !ab[i - 2000]) flag = false;
			if (0 <= j - i + 2000 && j - i + 2000 <= 4000 && !bc[j - i + 2000]) flag = false;
			if (0 <= 6000 - j && 6000 - j <= 4000 && !ca[6000 - j]) flag = false;
			if (flag) {
				int l = min(min(0ll, i - 4000), j - 4000);
				int r = max(max(x, i - 4000 + y), j - 4000 + z);
				chmin(ans, r - l);
			}
		}
	}
	cout << ans << '\n';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int maxi = -INF;
    int mini = INF;
    int sum = 0;
    int n; cin >> n;
    rep(_,n){
        int t; cin >> t;
        cmin(mini, t);cmax(maxi, t);sum+=t;
    }
    cout << mini << " " << maxi << " " << sum << endl;
}





Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long D = sc.nextLong();
		D= D*D;
		int count =0;
		for (int i=0;i<N;i++) {
			long X= sc.nextLong();
			long Y = sc.nextLong();
			long re = X*X+Y*Y;
			if (D>=re) {
				count ++;
			}
		}
		System.out.println(count);
	}
}


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

int main() {
    int n, d, x;
    cin >> n >> d >> x;
    int A[100];
    for (int i = 0; i < n; i++) {
        cin >> A[i];
    }

    int cnt = 0;
    for (int i = 0; i < n; i++) {
        int day = 1;
        while (day <= d) {
            cnt++;
            day += A[i];
        }
    }

    cout << x + cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(a) int((a).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
template<class T, class U> inline void add_self(T &a, U b){a += b;if (a >= mod) a -= mod;if (a < 0) a += mod;}
template<class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; }

#define _deb(x) cout<<x;
void _print() {cerr << "]\n";} template <typename T, typename... V>void _print(T t, V... v) {_deb(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
template <class T, class U> void print_m(const map<T,U> &m, int w=3){if(m.empty()){cout<<"Empty"<<endl; return;}for(auto x: m)cout<<"("<<x.first<<": "<<x.second<<"),"<<endl;cout<<endl;}
template<class T, class U>void debp(const pair<T, U> &pr, bool end_line=1){cout<<"{"<<pr.first<<" "<<pr.second<<"}"; cout<<(end_line ? "\n" : ", ");}
template <class T> void print_vp(const T &vp, int sep_line=0){if(vp.empty()){cout<<"Empty"<<endl; return;}if(!sep_line) cout<<"{ ";for(auto x: vp) debp(x,sep_line);if(!sep_line) cout<<"}\n";cout<<endl;}
template <typename T>void print(const T &v, bool show_index = false){int w = 2;if(show_index){for(int i=0; i<sz(v); i++)cout<<setw(w)<<i<<" ";cout<<endl;}for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<endl;}
template <typename T>void print_vv(const T &vv){if(sz(vv)==0) {cout<<"Empty"<<endl; return;} int w = 3;cout<<setw(w)<<" ";for(int j=0; j<sz(*vv.begin()); j++)cout<<setw(w)<<j<<" ";cout<<endl;int i = 0;for(auto &v: vv){cout<<i++<<" {";for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<"},\n";}cout<<endl;}

const int MAXN = 4e3+10;
vl fact(MAXN), inv(MAXN), finv(MAXN);

void precalc(){
    int n = MAXN;
    fact[0] = finv[0] = inv[1] = 1;
    fore(i, 2, n)
        inv[i] = (mod - (mod/i) * inv[mod%i] % mod) % mod;
    fore(i, 1, n){
        fact[i] = fact[i-1] * i % mod;
        finv[i] = finv[i-1] * inv[i] % mod;
    }
}

ll C(int n, int r){
    if(n<r || r<0) return 0;
    return fact[n] * finv[r]%mod * finv[n-r]%mod;
}

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    precalc();
    ll n;
    while(cin>>n){
        ll ans = 0;
        fore(i,1,n+1){
            add_self(ans, C(n+i-1 - 3*i, n-3*i));
        }
        cout<<ans<<"\n";
    }
    return 0;
}

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

#define sswap(x, y) { x+=y; y=x-y; x-=y; }
#define LSOne(S) ((S) & (-S))

#define EPS 1e-6
#define MOD 1000000007

#define fi first
#define se second
#define pb push_back
#define ende '\n'

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mset(x, y) memset(&x, (y), sizeof(x))

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
	int n;
	vi p;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int e; cin >> e;
		p.pb(e);
	}
	int k = 0;
	for (int i = 1; i < n-1; i++)
		if ((p[i] > min(p[i-1], p[i+1])) && (p[i] < max(p[i-1], p[i+1])))
			k++;
	cout << k << ende;
  return 0;
}


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

typedef long long ll;
typedef long double ld;
#define pi 3.14159265359;
#define inf (1 << 21);
#define mod 1000000007;

int main() {
    ll N; cin >> N;
    ll Nsave = N;
    ll n = (ll)sqrt(N);
    vector<int> cnt(n);
    for (int i = 2; i < n; i++) {
        while (N % i == 0) {
            cnt.at(i)++;
            N /= i;
        }
    }
    bool prime = true;//最終的なNが素数かどうかを判定
    for (int i = 2; i < n; i++) {
        if (N % i == 0) {
            prime = false;
        }
    }
    ll ans;
    if (N == Nsave) {
        if (N == 1) {
            ans = 0;
        }
        else {
            ans = 1;
        }
    }
    else {
        if (prime && N != 1) {
            ans = 1;
        }
        else {
            ans = 0;
        }
        for (int i = 2; i < cnt.size(); i++) {
            int k = 1;
            while (cnt.at(i) - k >= 0) {
                ans++;
                cnt.at(i) -= k;
                k++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7232
/*
h s, d't skp th si tll i's sved
 * ABC141 E
 * ABC145 D
*/
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int main()
{
int n;
cin>>n;
double k=(double)n/100;
int f=k;
if(f%2==1)
{
f--;
}
int ans=f/2-1;
cout<<9-ans<<endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
int main(){
  int64_t N;
  int64_t A;
  // blue
  int64_t B;
  //red
  int64_t answer;
  cin >> N >> A >> B;

  int64_t sum;
  sum = A + B;
  int64_t count;
  //syou

  count = N/sum;
  int64_t amari;
  amari = N%sum;
  if (amari <= A){
    answer = count*A + amari;
  }
  if (amari > A){
    answer = count*A + A;
  }
  cout << answer << endl;
  return 0;
}

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

int solve(int a, int b, int c) {

    int t=0;
    int cnt=0;

    for (int i=0; i<100000; ++i) {

        if (t <= c and c <= t+a) {
            return 60 * cnt + c;
        }

        if (t + a >= 60) {
            if (0 <= c and c <= (t+a)%60) {
                return 60 * cnt + c;
            }
        }

        t = ( t + a + b );
        if (t >= 60) {
            cnt++;
            t %= 60;
        }
    }

    return -1;

}

int main() {
    int a, b, c;
    cin >> a >> b >> c;

    cout << solve(a, b, c) << endl;
}

Measured memory_bytes: 3096
#include <iostream>

int main(){
  int n;
  std::string s;
  std::cin >> n;
  std::cin >> s;

  int diff = 0;
  for(int i = 0; i < n; ++i){
    if(s[i] == 'R')
      ++diff;
    else
      --diff;
  }

  std::cout << (diff > 0 ? "Yes" : "No") << std::endl;

  return 0;
}

Measured memory_bytes: 256
#pragma region Template
#include <bits/stdc++.h>
#ifdef _DEBUG
#include "../../../debug_print.hpp"
#else
#define debug(...)
#endif
#define sort_(a) sort(a.begin(), a.end())
#define rsort(a) sort(a.rbegin(), a.rend())
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; 0 <= i; i--)
#define for_(i, start, end) for (int i = start; i < end; i++)
#define rfor(i, start, end) for (int i = start - 1; 0 <= i; i--)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using namespace std;
constexpr int INF32       = 1'050'000'000;
constexpr long long INF64 = 4'000'000'000'000'000'000;
constexpr int MOD7        = 1'000'000'007;
constexpr int MOD53       = 998'244'353;
constexpr double PI       = 3.14159265358979323846;
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;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
void scan() {}
template <class H, class... T> void scan(H &&head, T &&... args) {
    std::cin >> head;
    scan(std::forward<T>(args)...);
}
template <class T> void scan(std::vector<T> &v) {
    for (auto &&i : v) {
        scan(i);
    }
}
#pragma endregion Template

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

    int D, G;
    scan(D, G);
    vector<pair<int, int>> v(D);
    rep(i, D) scan(v[i].first, v[i].second);
    int ans = INF32;

    for (int bit = 0; bit < (1 << D); bit++) {
        int sum   = 0;
        int count = 0;
        for (int i = 0; i < D; i++) {
            int point = (i + 1) * 100;
            if (bit & (1 << i)) {
                count += v[i].first;
                sum += point * v[i].first + v[i].second;
            }
        }
        if (sum < G) {
            rrep(i, D) {
                int point = (i + 1) * 100;
                int diff  = G - sum;
                if (!(bit & (1 << i))) {
                    int cnt =
                        min(v[i].first - 1, (int)ceil((double)diff / point));
                    sum += point * cnt;
                    count += cnt;
                }
                if (G <= sum)
                    break;
            }
        }
        if (G <= sum) {
            chmin(ans, count);
        }
    }
    print(ans);

    return 0;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <cmath>
#include <limits>
#include <tuple>
#include <queue>
#include <stack>
#include <bitset>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(c) c.begin(), c.end()

int main()
{
	int N, K;
	cin >> N >> K;
	vector<int> A(N);
	rep(i, N) {
		cin >> A[i];
	}
	rep(i, N-K) {
		if (A[i] < A[K+i]) {
			cout << "Yes" << endl;
		} else {
			cout << "No" << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 4032
N=int(input())
ans = []
def same(c):
    if len(c)==N:
        ans.append(c)
        return
    else:
        for i in range(ord('a'),ord('a')+len(list(set(list(c))))+1):
            same(c+chr(i))

same('a')
for i in ans:
    print(i)

Measured memory_bytes: 12648
N = int(input())
a_list = [int(input()) for _ in range(N)]
split_a_list = []

pre = -1
for i, a in enumerate(a_list):
    if a == 0:
        split_a_list.append(sum(a_list[pre + 1:i]))
        pre = i
else:
    split_a_list.append(sum(a_list[pre + 1:N]))
ans = 0
for s in split_a_list:
    ans += s // 2
print(ans)


Measured memory_bytes: 7884
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;
const int MAX_ROW = 1e5; 
const int MAX_COL = 60;

struct BitMatrix {
  int H, W;
  bitset<MAX_COL> val[MAX_ROW];
  BitMatrix(int m , int n) : H(m), W(n) {}
  inline bitset<MAX_COL>& operator [] (int i) {return val[i];}
};

int GaussJordan(BitMatrix &A, bool is_extended = false) {
  int rank = 0;
  rep(col,A.W) {
    if(is_extended and col == A.W-1) break;
    int piv = -1;
    for (int row = rank; row < A.H; row++) {
      if(A[row][col]) {
        piv = row;
        break;
      }
    }
    if(piv == -1) continue;
    swap(A[piv],A[rank]);
    rep(row,A.H) if(row != rank and A[row][col]) A[row] ^= A[rank];
    rank++;
  }
  return rank;
}

int main() {
  int n;
  cin >> n;
  ll a[n];
  rep(i,n) cin >> a[i];
  vector<ll> bit(60);
  rep(i,n) rep(j,60) if(a[i] & ((ll)1<<j)) bit[j]++;
  ll ans = 0;
  rep(i,60) {
    if(bit[i] % 2) {
      ans += ((ll)1<<i);
      rep(j,n) if(a[j] & ((ll)1<<i)) a[j] ^= ((ll)1<<i);
    }
  }
  BitMatrix bm(n,60);
  rep(i,n) {
    rep(j,60) {
      if(a[i] & ((ll)1<<(59-j))) bm[i][j] = 1;
      else bm[i][j] = 0;
    }
  }
  int rank = GaussJordan(bm,false);
  ll val = 0;
  rep(i,rank) rep(j,60) val ^= ((ll)1<<(59-j)) * bm[i][j];
  ans += 2*val;
  cout << ans << endl;
}


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

n = int(input())
li = list(map(int,input().split()))
li_srtd = sorted(li)

if li_srtd[n // 2] == li_srtd[n // 2 - 1]:
    print(0)
else:
    print(li_srtd[n // 2] - li_srtd[n // 2 - 1])

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ff first
#define ss second
#define free1 freopen("input.txt", "r", stdin)
#define free2 freopen("output.txt", "w", stdout)
#define mp make_pair
#define pb push_back
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

//template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, long long m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m;}
long long mod=1000000007;

int main()
{
	
	
	int n;
	cin>>n;
	vector<int> v(n);
	for(int i=0;i<n;i++)
		cin>>v[i];
	long long temp=pow(3,n);

	int odd=0;
	int even=0;
	for(int i=0;i<n;i++)
	{
		if(v[i]%2==0)
		{
			even++;
		}
		else
			odd++;
	}

   int t=pow(2,even);
   cout<<temp-t;


	return 0;
}

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

lcm = 1
from fractions import gcd
for i in range(n):
    lcm *= a[i] // gcd(a[i], lcm)

ans = 0
for i in a:
    ans += lcm // i

print(ans % (10**9+7))

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

int main() {
    vector<vector<int>> dp(10, vector<int>(10));
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        string s = to_string(i);
        int high = s.front() - '0';
        int low = s.back() - '0';
        if (low == 0) continue;
        dp[low][high]++;

    }
    int res = 0;
    for (int i = 1; i < 10; i++) {
        for (int j = 1; j < 10; j++) {
            res = res + dp[i][j] * dp[j][i];
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8

colors_1 = [int(x) for x in input()]
colors_2 = colors_1.copy()

count_1 = 0
count_2 = 0

for (i, c) in enumerate(colors_1):
    if i == 0:
        continue
    else:
        if colors_1[i-1] == c:
            colors_1[i] = int(not c)
            count_1 += 1

for (i, c) in enumerate(colors_2):
    if i == 0:
        colors_2[i] = int(not c)
        count_2 += 1
    else:
        if colors_2[i-1] == c:
            colors_2[i] = int(not c)
            count_2 += 1

print(min(count_1, count_2))


Measured memory_bytes: 4760
n,m= map(int, input().split())
h = list(map(int, input().split()))
t = [0]*(n+1)
ans = 0
for i in range(m):
  a,b = map(int, input().split())
  if h[a-1]==h[b-1]:
    t[b]+=1
    t[a]+=1
  elif h[a-1]>h[b-1]:
    t[b]+=1
  elif h[a-1]<h[b-1]:
    t[a]+=1

for i in range(1,n+1):
  if t[i] == 0:
    ans +=1
print(ans)

Measured memory_bytes: 86256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll inf=1744174417441744;
ll par[200005]={0};
ll dp[200005]={0};
int main(){
  vector<P> vec;
  ll n;
  cin>>n;
  for(int i=0;i<n;i++){
    ll x,d;
    cin>>x>>d;
    vec.push_back(P(x,d));
  }
  sort(vec.begin(),vec.end());
  vector<P> v2;
  for(int i=0;i<n;i++) v2.push_back(P(vec[i].first+vec[i].second,i));
  sort(v2.begin(),v2.end());
  ll rpos=n-1;
  multiset<ll> ms;
  for(int i=n-1;i>=0;i--){
    while(rpos!=-1&&v2[rpos].first>vec[i].first){
      ms.insert(v2[rpos].second);
      rpos--;
    }
    if(ms.find(i)!=ms.end()) ms.erase(i);
    if(!ms.empty()) par[i]=*ms.rbegin();
    else par[i]=n;
  }
  const ll mod=998244353;
  for(int i=0;i<=n;i++) dp[i]=1;
  for(int i=n-1;i>=0;i--){
    dp[i]++;
    dp[par[i]]*=dp[i];
    dp[par[i]]%=mod;
  }
  cout<<dp[n]<<endl;
}


Measured memory_bytes: 14444
#![doc = " # Bundled libraries"]
#![doc = ""]
#![doc = " ## `kyopro_lib` (private)"]
#![doc = ""]
#![doc = " ### Modules"]
#![doc = ""]
#![doc = " - `::__kyopro_lib::unionfind` → `$crate::unionfind`"]
#[allow(unused_imports)]
use itertools::Itertools;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
fn main() {
    input! { n : usize , q : usize , tuv : [(i32 , usize , usize) ; q] , }
    let mut uf = unionfind::UnionFind::new(n);
    for (t, u, v) in tuv {
        if t == 0 {
            uf.unite(u, v);
        } else {
            println!("{}", if uf.is_same(u, v) { 1 } else { 0 });
        }
    }
}
pub mod unionfind {
    struct Node {
        parent: usize,
        size: usize,
    }
    pub struct UnionFind {
        node: Vec<Node>,
    }
    impl UnionFind {
        pub fn new(n: usize) -> Self {
            Self {
                node: (0..n).map(|i| Node { parent: i, size: 1 }).collect(),
            }
        }
        pub fn root(&mut self, i: usize) -> usize {
            if self.node[i].parent == i {
                return i;
            }
            let r = self.root(self.node[i].parent);
            self.node[i].parent = r;
            r
        }
        pub fn unite(&mut self, i: usize, j: usize) -> bool {
            let i = self.root(i);
            let j = self.root(j);
            if i == j {
                false
            } else {
                self.node[i].parent = j;
                self.node[j].size += std::mem::replace(&mut self.node[i].size, 0);
                true
            }
        }
        pub fn size(&mut self, i: usize) -> usize {
            let r = self.root(i);
            self.node[r].size
        }
        pub fn is_same(&mut self, i: usize, j: usize) -> bool {
            self.root(i) == self.root(j)
        }
    }
}


Measured memory_bytes: 10820
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
vector<int> e[60];
long long dis[60][2510];
const long long inf = (1ll<<50);
int u[60][2510];
int c[60], d[60];
struct abc{
    int x, y;
    long long v;
    bool operator < (const abc &a) const {
        return v > a.v;
    }
};
priority_queue<abc> que;
void push(int x, int y, long long v) {
    abc t;
    t.x = x; t.y = y; t.v = v;
    que.push(t);
}
void update(int x, int y, long long val) {
    if (dis[x][y] > val) {
        dis[x][y] = val;
        push(x, y, val);
    }
}
int main() {
    int n, m, s, x, y, p, q;
    scanf("%d%d%d", &n, &m, &s);
    for (int i = 0; i < m; i++) {
        scanf("%d%d%d%d", &x, &y, &p, &q);
        e[x].push_back(y);
        e[x].push_back(p);
        e[x].push_back(q);
        e[y].push_back(x);
        e[y].push_back(p);
        e[y].push_back(q);
    }
    for (int i = 1; i <= n; i++) {
        scanf("%d%d", &c[i], &d[i]);
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= n*50; j++) {
            dis[i][j] = inf;
            u[i][j] = 0;
        }
    }
    dis[1][min(s, n*50)] = 0;
    push(1, min(s, n*50), 0);
    while(1) {
        if (!que.size()) break;
        abc t = que.top();
        que.pop();
        x = t.x; y = t.y;
        if (u[x][y]) continue;
        u[x][y] = 1;
        update(x, min(n*50, y+c[x]), dis[x][y] + d[x]);
        for (int i = 0; i < (int)e[x].size(); i += 3) {
            int yy = e[x][i]; p = e[x][i+1]; q = e[x][i+2];
            if (p <= y) {
                update(yy, y-p, dis[x][y]+q);
            }
        }
    }
    for (int i = 2; i <= n; i++) {
        long long r = inf;
        for (int j = 0; j <= n * 50; j++) {
            r = min(r, dis[i][j]);
        }
        printf("%lld\n", r);
    }
    return 0;
}


Measured memory_bytes: 6236
import java.util.Scanner;

public class Main {
	public static void main (String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		if (a == 1) a = 14;
		if (b == 1) b = 14;
		
		if (a > b) System.out.println("Alice");
		else if (a == b) System.out.println("Draw");
		else System.out.println("Bob");
	}
} 

Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;
using vl  = vector<ll>;
using vvl = vector<vl>;
using vb  = vector<bool>;

#define rng(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define DEBUG(x) cerr<<__LINE__<<": "<<#x<<" = "<<x<<"\n"

int N, M, ans;
vb used;
vl color;
vvl edges;
bool ok;

void init() {
    ans = 1e9;
    ok = true;
    cin >> N >> M;
    edges.assign(N, vl(N, 1));
    used.assign(N, false);
    color.assign(N, -1);
    rep(i,N) edges[i][i] = 0;
    rep(i,M) {
        int a, b; cin >> a >> b;
        a--; b--;
        edges[a][b] = edges[b][a] = 0;
    }
}

void coloring(int node, int c, vl &st) {
    if (used[node]) {
        if (color[node] != c) ok = false;
        return;
    }
    DEBUG(node);
    used[node] = true;
    color[node] = c;
    st[c]++;
    for (int to = 0; to < N; ++to) {
        if (edges[node][to] == 0) continue;
        coloring(to, 1-c, st);
    }
}

void solve() {
    set<pll> dp;
    dp.insert(pll(0,0));
    rep(i,N) {
        if (used[i]) continue;
        vl st(2,0);
        coloring(i, 0, st);
        set<pll> ndp;
        for (auto it : dp) {
            int s = it.first, t = it.second;
            ndp.insert(pll(s+st[0], t+st[1]));
            ndp.insert(pll(s+st[1], t+st[0]));
        }
        dp = ndp;
    }
    for (auto it : dp) {
        int s = it.first, t = it.second;
        ans = min(ans, s*(s-1)/2 + t*(t-1)/2);
    }
}

void output() {
    if (ok) {
        cout << ans << endl;
    } else {
        cout << -1 << endl;
    }
}

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


Measured memory_bytes: 4224
def abc043_d():
    s = str(input())
    n = len(s)
    ans = (-1, -1)
    if n == 2:
        if s[0] == s[1]:
            ans = (1, 2)
    else:
        for i in range(n-2):
            if len(set(s[i:i+3])) < 3:
                ans = (i+1, i+3)
                break
    print(*ans, sep=' ')

if __name__ == '__main__':
    abc043_d()

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

using namespace std;

#define int long long
#define pb push_back
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a)-1;i>=(b);i++)
#define RREP(i, n) FOR(i, n, 0);

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

signed main () {
  cin.tie(0);
  cout << setprecision(10);

  int t; cin >> t;
  REP(i, t) {
    int a, b, c, d; cin >> a >> b >> c >> d;

    if(a < b || b > d) {
      cout << "No" << endl;
      continue;
    }

    if(c >= b) {
      cout << "Yes" << endl;
      continue;
    }

    int g = gcd(b, d);
    int ma = b - g + (a % g);

    if(ma > c) {
      cout << "No" << endl;
    } else {
      cout << "Yes" << endl;
    }
  }
}


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;

int main(){
    ll n;
    cin >> n;
    map<string,int> mp;
    rep(i,n){
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        mp[s]++;
    }
    ll ans =0;
    for(auto& p : mp){
        int s = p.second;
        ans += (ll)s*(s-1)/2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define MOD 1000000007

int main(){
  int x,y;
  cin>>x>>y;
  int ans=INT_MAX;
  for(int i=0;i<2;i++){
    for(int j=0;j<2;j++){
      int a=i?-x:x, b=j?-y:y;
      if(a<=b) ans=min(ans,i+j+b-a);
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}



struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};

int main() {
    int n,q;
    cin >> n >> q;
    UnionFind uf(n);
    rep(i,q) {
        int com,x,y;
        cin >> com >> x >> y;
        
        if(com == 0) {
            uf.unite(x,y);
        }
        if(com == 1) {
            if(uf.same(x,y)) cout << 1 << endl;
            else cout << 0 << endl;
        }
    }
}


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

#define PB push_back
#define P push
#define rep(m,n) for(int i = m ; i <= n ; i++)
#define rev(m,n) for(int i = n ; i >= m ; i--)
typedef long long ll;

int main()
{
	int n,m;
	cin>>n>>m;
	
	priority_queue<int> q;
	int num;
	rep(1,n){cin>>num;q.P(num);};
	rep(1,m){num = q.top()/2;q.pop();q.P(num);};
	ll sum = 0;
	rep(0,n-1){num = q.top();q.pop();sum+=num;};
	cout << sum << '\n';
		
	return 0;
}

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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  ll n;
  while (cin >> n && n) {
    ll sum = 1;
    for (ll i = 2; i * i <= n; ++i) {
      if (n % i == 0) {
        sum += i;
        if (i != n / i) sum += n / i;
      }
    }
    if (n == 1) {
      cout << "deficient number" << endl;
    } else if (n == sum) {
      cout << "perfect number" << endl;
    } else if (n > sum) {
      cout << "deficient number" << endl;
    } else {
      cout << "abundant number" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3008
#include <iostream>


void matrix_multiple(int A[100][100], int B[100][100],
                     int n, int m, int l, long int C[100][100]) {
  for (int i = 0; i < n; i ++) {
    for (int j = 0; j < l; j ++) {
      for (int k = 0; k < m; k ++) {
        C[i][j] += A[i][k] * B[k][j];
      }
    }
  }
}


int main() {
  int n, m, l;
  int A[100][100], B[100][100];
  long int C[100][100] = {0};
  char deli = ' ';

  std::cin >> n >> m >> l;
  for (int i = 0; i < n; i ++) {
    for (int j = 0; j < m; j ++) {
      std::cin >> A[i][j];
    }
  }

  for (int i = 0; i < m; i ++) {
    for (int j = 0; j < l; j ++) {
      std::cin >> B[i][j];
    }
  }

  matrix_multiple(A, B, n, m, l, C);

  for (int i = 0; i < n; i ++) {
    for (int j = 0; j < l - 1; j ++) {
      std::cout << C[i][j] << deli;
    }
    std::cout << C[i][l-1] << std::endl;
  }

  return 0;
}



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

#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  int n,m;
  cin >> n >> m;
  vector<LL> v(m+1);
  v[m]=n+1;
  for(int i=0;i<m;i++){
    cin >> v[i];
  }
  int h=v[0]-1;
  vector<LL> d(m),rui(m+1);
  for(int i=0;i<m;i++){
    d[i]=v[i+1]-v[i];
  }
  sort(all(d));
  rui[m]=0;
  for(int i=m-1;i>=0;i--){
    rui[i]=rui[i+1]+d[i];
  }
  // for(int i=0;i<m;i++){
  //   cout << d[i] << " ";
  // }
  // cout << endl;
  // for(int i=0;i<m;i++){
  //   cout << rui[i] << " ";
  // }
  // cout << endl;
  int q;
  cin >> q;
  LL k;
  for(int t=0;t<q;t++){
    cin >> k;
    LL l=0,r=IINF,mid;
    while(r-l>1){
      mid=(l+r)/2;
      int idx=distance(d.begin(),lower_bound(all(d),mid));
      // cout << mid SP idx SP rui[idx]-mid*(m-idx)+h << endl;
      if(rui[idx]-mid*(m-idx)+h<=k){
        r=mid;
      }else{
        l=mid;
      }
    }
    if(r==IINF){
      cout << -1 << endl;
    }else{
      cout << r << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 5200
import Control.Applicative
import Control.Monad
import Data.List
import Data.Array

main = do
  n <- (read::String -> Int) <$> getLine
  values <- array (1, n) . zip [1..n] . map (read::String -> Int) . words <$> getLine
  costs <- array (1, n) . zip [1..n] . map (read::String -> Int) . words <$> getLine
  let results = calc n values costs
  print $ maximum results
 

calc::Int -> Array Int Int -> Array Int Int -> [Int]
calc n values costs = do
  set <- filterM (const [True, False]) [1..n]
  let vsum = foldl (\acc i -> acc + values ! i) 0 set
      csum = foldl (\acc i -> acc + costs ! i) 0 set
  return $ vsum - csum


Measured memory_bytes: 67068
/* AOJ 0062
 *
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0062
 *
 */

#include <stdio.h>

#define DEBUG 0

int f(int* xs, int len){
    int ys[10];
    int i;
    if(DEBUG){
        for(i=0; i<len; i++){
            printf("%d,", xs[i]);
        }
        printf("\n", xs[i]);
    }
    if(len==1){
        return xs[0];
    }else{
        for(i=0; i<len-1; i++){
            ys[i]=(xs[i]+xs[i+1])%10;
        }
        return f(ys, len -1);
    }
}

int main(){
    char buf[11];
    int i;
    int xs[10];

    while(scanf("%s", buf)==1){
        if(DEBUG)
            printf("==> %s\n", buf);

        for(i=0; i<10; i++){
            xs[i]= buf[i]-'0';
        }
        printf("%d\n", f(xs, 10));
    }

    return 0;
}

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

int main(){
  string S;
  cin>>S;
  if(S[0]=='Y'&&S[1]=='A'&&S[2]=='K'&&S[3]=='I'){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
a = list(map(int, input().split()))

intra_inv = 0
for i in range(n):
    for j in range(i + 1, n):
        if a[i] > a[j]:
            intra_inv += 1

inter_inv = 0
for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            inter_inv += 1

total_inv = k * intra_inv + k * (k - 1) // 2 * inter_inv
dst = int(total_inv % (10**9 + 7))
print(dst)


Measured memory_bytes: 3188
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
//typedef pair<int,int> P;
//priority_queue<int> pque;
//priority_queue<int, vector<int>, greater<int>> pque;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 1000000000;//10^9
ll MOD  = 1000000007;


int main(void){
    int N,M;
    cin >> N >> M;
    vector<vector<char>> A(N, vector<char>(N));
    vector<vector<char>> B(M, vector<char>(M));
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            cin >> A.at(i).at(j);
        }
    }
    for(int i = 0; i < M; i++){
        for(int j = 0; j < M; j++){
            cin >> B.at(i).at(j);
        }
    }
    bool OK = 0;
    for(int i = 0; i <= N-M; i++){
        for(int j = 0; j <= N-M; j++){
            bool ok = 1;
            for(int a = 0; a < M; a++){
                for(int b = 0; b < M; b++){
                    if(A.at(i+a).at(j+b) != B.at(a).at(b)){
                        ok = 0;
                    }
                }
            }
            if(ok){
                OK = 1;
            }
            
            
        }
    }
    
    if(OK){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S, T;
const ll MOD = 998244353;
const ll INF = 1LL << 50;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

vec a_in(100010);
int main() {
    cin>>N>>M;
    rep(i,N) cin>>a_in[i];
    a_in[N] = INF;
    class union_find{
            vector<long> parent, tree_size, min_ele;
        public:
            union_find(unsigned long _n) : parent(_n), tree_size(_n, 1), min_ele(_n){
                for(unsigned long i = 0; i < _n; ++i)parent[i] = i;
                for(unsigned long i = 0; i < _n; ++i)min_ele[i] = a_in[i];
            }
            ll find(ll x){
                while(parent[x] != x)x = parent[x] = parent[parent[x]];
                return x;
            }
            void merge(ll a, ll b){
                a = find(a);
                b = find(b);
    	        if(a==b) return;
                if(tree_size[a] < tree_size[b])swap(a, b);
                tree_size[a] += tree_size[b];
                parent[b] = a;
                min_ele[a] = min(min_ele[a], min_ele[b]);
                return;
            }
    	    bool same(ll a, ll b){
    	        a = find(a);
    	        b = find(b);
    	        return a == b;
    	    }
    	    ll mini(ll a){
                return min_ele[find(a)];
            }
    }uf(N+1);
    //uf.mergeのように使う
    //ufはMAX_N+1でとるか、代入時に0-indexedにする
    multiset<ll> mset;
    rep(i,N) mset.insert(a_in[i]);
    rep(i,M){
        cin>>A>>B;
        uf.merge(A, B);
    }
    //cout<<uf.mini(6)<<endl;
    vec minis(0);
    ll ans = 0;
    rep(i,N){
        if(!uf.same(i,N)){
            minis.push_back(uf.mini(i));
            mset.erase(mset.lower_bound(uf.mini(i)));
            ans += uf.mini(i);
            uf.merge(i,N);
        }
    }
    if(N/2 < N - 1 - M){
        cout<<"Impossible"<<endl;
    }else if(minis.size() == 1){
        cout<<0<<endl;
    }else{
        auto ite = mset.begin();
        rep(i,N - M - 2) ans += *ite++;
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 9220
/*Whose woods these are I think I know.
His house is in the village though;
He will not see me stopping here
To watch his woods fill up with snow.

My little horse must think it queer
To stop without a farmhouse near
Between the woods and frozen lake
The darkest evening of the year.

He gives his harness bells a shake
To ask if there is some mistake.
The only other sound’s the sweep
Of easy wind and downy flake.

The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007
const int maxn= 100010;
vector<vector<pair<int, lli> > > v;
vector<lli> wt;
void dfs(int node, int pre, lli weight)
{
    if(wt[node]!=-1)
        return;
    wt[node]=weight;
    for(auto i: v[node])
    {
        if(i.fi!=pre)
            dfs(i.fi,node,i.se+weight);
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n=0,x=0,y=0;lli w=0ll;
    cin>>n;
    v.resize(n+1);
    wt.resize(n+1,-1);
    for(int i=0;i+1<n;++i)
    {
        cin>>x>>y>>w;
        v[x].pb({y,w});
        v[y].pb({x,w});
    }
    dfs(1,-1,0);
    for(int i=1;i<=n;++i)
    {
        cout<<wt[i]%2<<endl;
    }
}

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

int main()
{
    string str;
    int maxx=0;
    cin>>str;
    for(int i=0;i<str.length();){
        if(str[i]=='A'||str[i]=='C'||str[i]=='G'||str[i]=='T'){
            int cnt=0;
            while(str[i]=='A'||str[i]=='C'||str[i]=='G'||str[i]=='T'){
                cnt++;
                i++;
                if(i>=str.length())break;
            }
            maxx=max(maxx,cnt);
            continue;
        }
        else i++;
    }
    cout<<maxx<<endl;
}


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

int main(){
  int a;
  string s;
  cin >> a >> s;
  if(a<3200){
    cout << "red" << endl;
  }
  else{
    cout << s << endl;
  }
  
  return 0;
}

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

  public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String[] arr = br.readLine().split(" ");
        int[] A = new int[n];
        for (int i = 0; i < n; i++){
          A[i] = Integer.parseInt(arr[i]);
        }
        insertionSort(A, n);
    }
    
    static void insertionSort(int[] A, int n){
      printArray(A);
      for (int i = 1; i < n; i++){
        int v = A[i];
        int j = i - 1;
        while (j >= 0 && A[j] > v){
          swap(A, j+1, j);
          j--;
        }
        A[j+1] = v;
        printArray(A);
      }
    }
    
    static void swap(int[] A, int i, int j){
      int tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
    }
    
    static void printArray(int[] A){
      StringBuilder sb = new StringBuilder();
      for (int i = 0; i < A.length; i++){
        sb.append(String.valueOf(A[i]));
        if (i != A.length - 1){
          sb.append(" ");
        }
      }
      System.out.println(sb.toString());
    }
  }

Measured memory_bytes: 27428
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
using ll = long long;

bool c[10][10];
int main(){
  int h,w,k;
  cin >> h >> w >> k;

  for(int i=0;i<h;i++){
    string temp;
    cin >> temp;
    for(int j=0;j<w;j++){
      if(temp[j]=='#') c[i][j] = true;
      else  c[i][j] = false;
    }
  }

  bool c_copy[10][10];
  int ans = 0;
  for(int bit_i=0;bit_i<(1<<h);bit_i++){
    for(int bit_j=0;bit_j<(1<<w);bit_j++){
      for(int y=0;y<h;y++){
        for(int x=0;x<w;x++){
          c_copy[y][x] = c[y][x];
        }
      }
      for(int i=0;i<h;i++){
        if(bit_i & (1<<i))
          for(int x=0;x<w;x++){
            c_copy[i][x] = false;
          }
      }

      for(int j=0;j<w;j++){
        if(bit_j & (1<<j))
          for(int y=0;y<h;y++){
            c_copy[y][j] = false;
          }
      }

      int cnt = 0;
      for(int y=0;y<h;y++){
        for(int x=0;x<w;x++){
          if(c_copy[y][x]) cnt++;
        }
      }
      if(cnt==k){
         ans++;
      }

    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
int main(){
    int n,x;
    cin >> n >> x;
    ll a[n];
    for(int i=0; i<n; i++) cin >> a[i];
    ll cnt=0;
    if(a[0]>x) cnt+=a[0]-x,a[0]-=a[0]-x;
    for(int i=0; i<n-1; i++){
        if(a[i]+a[i+1]>x){
            cnt += a[i]+a[i+1]-x;
            a[i+1]-=a[i]+a[i+1]-x;
        }
    }
    cout << cnt << endl;
}


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

long long MOD = 1e9 + 7;

int main() {
    // cout << setprecision(15) << MOD << endl;

    long long n, k;
    cin >> n >> k;

    long long ans = 0;
    
    for(long long i = k; i <= n + 1; i++) {
        // cout << ((i * n) % MOD - (i * (i - 1)) % MOD + 1) % MOD << endl;
        ans = ans + ((i * n) - (i * (i - 1)) + 1) % MOD;
    }
    
    ans = ans % MOD;
    if(ans < 0) ans += MOD;

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

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

template<typename T>
void cout_vec(vector<T> &vec){
    for(int i=0; i<vec.size(); i++){
        if (i!=0){
            cout << ' ';
        }
        cout << vec[i];
    }
    cout << endl;
}

void dfs(int s, int node, vector<int> &ans, vector<int> &route, vector<vector<int>> &edge, vector<int> &used){
    if(used[node]==1){
        //cout_vec(route);
        if(node==s && (int)route.size()<(int)ans.size()){
            ans=vector<int>((int)route.size(),0);
            copy(route.begin(),route.end(),ans.begin());
        }
        return;
    }

    used[node]=1;
    route.push_back(node);
    for(auto e:edge[node]){
        dfs(s,e,ans,route,edge,used);
    }
    route.pop_back();
    return;
}

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

    vector<vector<int>> edge(N,vector<int>(0));
    for(int i=0; i<M; i++){
        int a, b;
        cin >> a >> b;
        a--;b--;
        edge[a].push_back(b);
    }

    vector<int> ans(N+1,0);
    for(int i=0; i<N; i++){
        vector<int> used(N,0);
        vector<int> route(0);
        dfs(i, i, ans, route, edge, used);
    }
    if((int)ans.size()<=N){
        cout << (int)ans.size() << endl;
        for(auto a:ans){
            cout << a+1 << endl;
        }
    }else{
        cout << -1 << endl;
    }
}

Measured memory_bytes: 384
#include<stdio.h>

#define MAX 3000

int main(void)
{
  int a[2][MAX];
  int i,j,t;

  for(j=0;j<MAX;j++)
    {
      scanf("%d %d",&a[0][j],&a[1][j]);
      if((a[0][j]==0)&&(a[1][j]==0))
	break;
    }

  for(i=0;i<j;i++)
    {
      if(a[0][i]>a[1][i])
	{
	  t=a[0][i];
	  a[0][i]=a[1][i];
	  a[1][i]=t;
	}
      printf("%d %d\n",a[0][i],a[1][i]);
    }
}




Measured memory_bytes: 2036
import numpy as np

H, W = map(int, input().split())
grid = np.array([list(input()) for i in range(H)]) == '.'
L = np.zeros((H, W), dtype=int)
R = np.zeros((H, W), dtype=int)
U = np.zeros((H, W), dtype=int)
D = np.zeros((H, W), dtype=int)
for i in range(1, H):
    U[i] = (U[i-1] + 1) * grid[i-1]
for i in reversed(range(H-1)):
    D[i] = (D[i+1] + 1) * grid[i+1]
for i in range(1, W):
    L[:, i] = (L[:, i-1] + 1) * grid[:, i-1]
for i in reversed(range(W-1)):
    R[:, i] = (R[:, i+1] + 1) * grid[:, i+1]
print(((U + D + L + R) * grid).max() + 1)


Measured memory_bytes: 219804