akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define finish(x){cout << x << endl; exit(0);}
#define ll long long

const int N = 100001;

int n, m, q, col[N], vis[N][11];
vector <int> v[N];

void go(int node, int d, int c){
    if(d < 0) return;
    if(vis[node][d]) return;
    vis[node][d] = 1;
    if(col[node] == 0) col[node] = c;
    for(auto &i : v[node]){
        go(i, d - 1, c);
    }
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    for(int i = 0 ; i < m ; i++){
        int x, y;
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    cin >> q;
    vector <int> v(q), d(q), c(q);
    for(int i = 0 ; i < q ; i++){
        cin >> v[i] >> d[i] >> c[i];
    }
    for(int i = q - 1 ; i >= 0 ; i--){
        go(v[i], d[i], c[i]);
    }
    for(int i = 1 ; i <= n ; i++){
        cout << col[i] << "\n";
    }
}


Measured memory_bytes: 12408
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define endl "\n"
using ll=long long;
using ld=long double;
using namespace std;
const ll mod= 1e9+7;
const ll INF = 1LL<<40;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll a[220000];
map<ll,ll> f;
int main(){
  ll n,ans=0;
  cin>>n;
  rep(i,0,n){cin>>a[i];f[a[i]]++;}
  for(map<ll,ll>::iterator it=f.begin();it!=f.end();it++){
    ll ff=it->second;
    ans+=ff*(ff-1)/2;
  }
  rep(i,0,n){
    ll sub=f[a[i]];
    if(sub==2)cout<<ans-1<<endl;
    else cout<<ans-sub*(sub-1)/2+(sub-1)*(sub-2)/2<<endl;
  }
}



Measured memory_bytes: 11008
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  bool a[n];
  string s="";
  set<string>sss;
  int i;
  for(i=0;i<n;i++)s+="a";
  queue<pair<string,int> >que;
  que.push(make_pair(s,0));
  while(!que.empty()){
    string tmpS = que.front().first;
    int tmp = que.front().second;
    sss.insert(tmpS);
    que.pop();
    if(tmp<n-1){
      int maxx = 0;
      for(i=0;i<=tmp;i++){
        if(maxx<(int)(tmpS[i]-'a'))maxx=(int)(tmpS[i]-'a');
      }
      for(i=0;i<=maxx+1;i++){
        string tmpp = tmpS;
        tmpp[tmp+1]='a'+i;
        que.push(make_pair(tmpp,tmp+1));

      }


    }
  }



  for(string ss : sss){
    cout<<ss<<endl;
  }
}


Measured memory_bytes: 12416
// Problem : D - Redistribution
// Contest : AtCoder - AtCoder Beginner Contest 178
// URL : https://atcoder.jp/contests/abc178/tasks/abc178_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize "trapv"//  WA to RE int!!
#include <bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORR(i,n) for(int i=n;i>=0;i--)
#define pb push_back
#define vint vector<int>
#define sint set<int>
#define mint map<int,int>
#define pint pair< int,int >
#define int long long int 
#define test int tt1234; cin>>tt1234;while(tt1234--)
#define endl "\n"
#define SI(a,n) int a[n];FOR(i,n) cin>>a[i];
#define input(a,n) int n;cin>>n; SI(a,n)
#define all(zz) zz.begin(),zz.end()
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define error(x) cerr << #x <<" is " << x << endl;
#define Error(a,b) cerr<<"( "<<#a<<" , "<<#b<<" ) = ( "<<(a)<<" , "<<(b)<<" )\n";
#define precision(x) cout<<fixed<<setprecision(x);
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define present(container, element) (container.find(element)!=container.end())
#define fint fast;test
#define set(a,x) memset(a,x,sizeof(a))
#define L(x)	((x)<<1)
#define R(x)	(((x)<<1)+1)
#define ft first
#define se second
#define MOD 1000000007
using namespace std;
template<typename... T> void rd(T&... args) { ((cin >> args), ...); }
template<typename... T> void pp(T... args) { ((cout << args << " "), ...); cout<<"\n"; }
int dp[2001];
int n;
int go(int sum)
{
	if(sum==0 || sum==3)return 1;
	if(sum<3)return 0;
	if(dp[sum]!=-1)return dp[sum];
	int ans=0;
	
	for(int i=3;i<=sum;i++)
	{
		ans=ans%MOD+go(sum-i)%MOD;
		ans=ans%MOD;
	}
	return dp[sum]=ans%MOD;
}
void solve(){
	memset(dp,-1,sizeof(dp));
	rd(n);	
	pp(go(n));
	return;	
}


int32_t main() {
    // fint{
    	fast;
    	solve();
    // }
    return 0;
}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ss second
#define ff first
#define N 100005
#define inf 1000000009
#define ll long long
#define pii pair<int,int>
#define sz(a) int(a.size())
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

ll a,b,v,w,t;

int main(){
	scanf("%lld%lld%lld%lld%lld",&a,&v,&b,&w,&t);
	if(b > a){
		if(v*t + a >= w*t + b) puts("YES");
		else puts("NO");
	}
	else {
		if(a - v*t <= b - w*t) puts("YES");
		else puts("NO");
	}
}


Measured memory_bytes: 3696
#include <stdio.h>
#include <queue>
using namespace std;

int ifield[1001][1001] = {0};

int main()
{
    queue<int> x,y,longth;
    int n,memlongth,ans;
    int dx1[9] = {-1,-1,-1,0,0,0,1,1,1},dy1[9] = {-1,0,1,-1,0,1,-1,0,1},dx2[3] = {1,0,1},dy2[3] = {0,1,1};
    while(1)
    {
        memlongth = 0;
        char cfield[1010][1010] = {0},N;
        scanf("%d",&n);
        if(n == 0)return 0;
        scanf("%c",&N);
        for(int i = 0; i < n; i++)
        {
            for(int j = 0; j < n + 1; j++)
            {
                ifield[j][i] = 0;
            }
        }
        for(int i = 0; i < n; i++)
        {
            for(int j = 0; j < n + 1; j++)
            {
                scanf("%c",&cfield[j][i]);
                if(cfield[j][i] == '*')
                {
                    x.push(j);
                    y.push(i);
                    longth.push(0);
                    ifield[j][i] = 9;
                }
            }
        }
        for(int i = 0; i < n; i++)
        {
            for(int j = 0; j < n; j++)
            {
                if(ifield[j][i] == 0 && (i == 0 || i == n - 1 || j == 0 || j == n - 1))
                {
                    ifield[j][i] = 1;
                    x.push(j);
                    y.push(i);
                    longth.push(1);
                    memlongth = 1;
                }
            }
        }
        while(x.size())
        {
            for(int i = 0; i < 9; i++)
            {
                if(0 <= x.front() + dx1[i] && x.front() + dx1[i] < n &&
                   0 <= y.front() + dy1[i] && y.front() + dy1[i] < n &&
                   ifield[x.front() + dx1[i]][y.front() + dy1[i]] == 0)
                {
                    ifield[x.front() + dx1[i]][y.front() + dy1[i]] = longth.front() + 1;
                    x.push(x.front() + dx1[i]);
                    y.push(y.front() + dy1[i]);
                    longth.push(longth.front() + 1);
                    memlongth = longth.front() + 1;
                }
            }
            x.pop();
            y.pop();
            longth.pop();
        }
        if(memlongth == 0)ans = 0;
        else ans = memlongth * 2 - 1;
        for(int i = 0; i < n - 1; i++)
        {
            for(int j = 0; j < n - 1; j++)
            {
                if(ifield[j][i]  == memlongth)
                {
                    for(int k = 0; k < 3; k++)
                    {
                        if(ifield[j + dx2[k]][i + dy2[k]] == memlongth);
                        else break;
                        if(k == 2)ans = memlongth * 2;
                    }
                }
            }
        }
        printf("%d\n",ans);
    }
}

Measured memory_bytes: 9640
/* 163-A.cpp
 *     Created on : Apr 19, 2020 
 *     Time       : 5:57:48 PM
 *     Author     : null_ptr
 */
#include<iostream>
#include<cmath>
#include<iomanip>

using namespace std;

const double pi=acos(-1);

int main()
{
	int n;
	cin>>n;
	cout<<setprecision(9)<<fixed<<pi*2.0*n<<'\n';
}


Measured memory_bytes: 3240
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << '\n';
#else
	#define DBG(X)
#endif

using std::cin;
using std::cout;
using std::vector;
using std::string;
using std::pair;
using std::swap;
using std::sort;
using std::lower_bound;
using std::unique;
using std::abs;

using int64 = long long int;
using pii   = pair<int, int>;
using pii64 = pair<int64, int64>;

const int NIL = -1;
const int INF = (int)2e9;
const int64 INF64 = (int64)2e18;

void init_IO() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
}

template<typename T>
std::ostream& operator<<(std::ostream& os, const vector<T>& vec) {
	os << '[';
	int fst = 1;

	for(auto& elem: vec) {
		if(fst == 0) {
			os << ' ';
		}

		os << elem;
		fst = 0;
	}

	os << ']';
	return os;
}

const int MAX_N = (int)1e6 + 777;

int a[MAX_N], n;

void solve() {
	cin >> n;

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

	int answ = -INF;

	for(int k = 1; k < (1 << n); ++k) {
		int max = a[0], max2 = -INF;

		for(int pos = k; pos > 0; pos = (pos - 1) & k) {
			if(a[pos] >= max) {
				max2 = max;
				max = a[pos];
			} else if(a[pos] > max2) {
				max2 = a[pos];
			}
		}

		//cout << k << ' ' << max << ' ' << max2 << '\n';

		if(max + max2 > answ) {
			answ = max + max2;
		}

		cout << answ << '\n';
	}
}

int main() {
	init_IO();
	solve();

	return 0;
}


Measured memory_bytes: 4096
local read = io.read

local n, m = read("n", "n")
local key_s_t = {}
if n == 1 and m == 0 then
	print(0)
	os.exit()
end
for i = 1, m do
	local s_i, c_i = read("n", "n")
	if n ~= 1 and s_i == 1 and c_i == 0 then
		print(-1)
		os.exit()
	end
	if key_s_t[s_i] and key_s_t[s_i] ~= c_i then
		print(-1)
		os.exit()
	elseif not key_s_t[s_i] then
		key_s_t[s_i] = c_i
	end
end
for i = 1, n do
	if not key_s_t[i] then
		if i == 1 then
			key_s_t[i] = 1
		else
			key_s_t[i] = 0
		end
	end
end

print(table.concat(key_s_t, ""))


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

int main() {
    int N;
    cin >> N;
    vector<string> grid(N);
    for (int i = 0; i < N; i++) cin >> grid[i];
    bool bexist = false;
    for (int i = 0; i < N; i++) {
        if (find(grid[i].begin(), grid[i].end(), '#') != grid[i].end()) {
            bexist = true;
            break;
        }
    }
    if (!bexist)  {
        cout << -1 << endl;
        return 0;
    }
    int prow = 0;
    for (int i = 0; i < N; i++) {
        bool check = true;
        for (int j = 0; j < N; j++) {
            if (grid[j][i] == '.') {
                check = false;
                break;
            }
        }
        if (check) prow++;
    }
    int ans = 2*N;
    for (int i = 0; i < N; i++) {
        int n = 0;
        bool check = false;
        for (int j = 0; j < N; j++) {
            if (grid[j][i] == '#') {
                check = true;
                break;
            }
        }
        if (!check) n++;
        for (int j = 0; j < N; j++) {
            if (grid[i][j] == '.') n++;
        }
        ans = min(ans, n+N-prow);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;
public class ABC132C {
    public static void Main() {
        int N, ans = 0;
        List<int> d = new List<int>();
        N = int.Parse(Console.ReadLine());
        string[] str = Console.ReadLine().Split(' ');
        for (int i = 0; i < N; i++) {
            d.Add(int.Parse(str[i]));
        }
        d.Sort();
        ans = d[N / 2] - d[N / 2 - 1];
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 19168
#include <iostream>
#include <algorithm>
using namespace std;
bool cmp(char a,char b)
{
	return a>b;
}
int main()
{
	string s,t;
	cin>>s>>t;
	sort (s.begin(),s.end());
	sort (t.begin(),t.end(),cmp);
	if (s<t)
	  cout<<"Yes"<<endl;
	else
	  cout<<"No"<<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)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const ll Inf = 1e18;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int q;
    cin >> q;
    vector<int> cnt(100010);
    vector<bool> prime(100010);
    FOR (i, 2, 100010) {
        bool ok = true;
        for (int j = 2; j * j <= i; ++j) {
            if (i % j == 0) {
                ok = false;
                break;
            }
        }
        if (ok) prime[i] = true; 
    }
    rep (i, 100010) {
        int j = (i + 1) / 2;
        if (prime[i] && prime[j]) cnt[i]++;
    }
    FOR (i, 1, 100011) cnt[i] += cnt[i - 1];
    rep (i, q) {
        int l, r;
        cin >> l >> r;
        cout << cnt[r] - cnt[l - 1] << endl;
    }
    
    return 0;
}



Measured memory_bytes: 1024
#include <stdio.h>

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

  int H, N;
  int A[100000];
  int sum = 0;
  scanf("%d %d", &H, &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", (A + i));
  }

  for (int i = 0; i < N; i++) {
    sum += A[i];
    if (sum >= H) {
      printf("Yes\n");
      return 0;
    }
  }

  printf("No\n");

  return 0;
}


Measured memory_bytes: 512
n, k = map(int, input().split())
d = []
A = []

ans = [0]*(n+1)
# print(ans)

for _ in range(k):
    d.append(input())
    A.append(list(map(int, input().split())))

# print(d)
# print(A)

for a in A:
    for _a in a:
        ans[_a] += 1

b = [1 for x in ans[1:] if x == 0]

print(sum(b))


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

/* 参考: http://drken1215.hatenablog.com/entry/2018/06/08/210000 */

const long long MAX = 2000000;
const long long MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (size_t i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(const long long n, const long long k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

/* 参考: https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a sec.3-2 */

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

// long long modchoose(const long long m, const long long n, const long long mod)
// {
//     long long res = 1;
//     for (size_t i = m + n; i >= m + n - min(m, n) + 1; i--)
//     {
//         res *= i;
//         res %= mod;
//     }
//     for (size_t i = min(m, n); i >= 2; i--)
//     {
//         res *= modinv(i, mod);
//         res %= mod;
//     }
//     return res;
// }

void solve(long long X, long long Y)
{
    long long res = 0;
    if ((-X + 2 * Y) % 3 != 0 || (2 * X - Y) % 3 != 0)
    {
        res = 0;
    }
    else
    {
        long long m = (-X + 2 * Y) / 3;
        long long n = (2 * X - Y) / 3;

        // 前処理
        COMinit();

        // 計算例
        res = COM(m + n, m);
    }

    cout << res << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long X;
    scanf("%lld", &X);
    long long Y;
    scanf("%lld", &Y);
    solve(X, Y);

    // COMinit();
    // cout << COM(10000, 5000) << endl;

    return 0;
}


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

#define rep(i, n) for(int i = 0; i < (n); i++)
using ll = long long;
constexpr ll INF = 1000000000;

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

using namespace std;
int main() {
	int n, l; cin >> n >> l;

	vector<string>s(n);
	rep(i, n)cin >> s[i];

	sort(s.begin(), s.end());
	rep(i, n) {
		cout << s[i];
	}


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int dp[40005];
int a[1005],b[1005];
signed main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);  
//  #ifndef ONLINE_JUDGE
//     freopen ("INPUT.txt" , "r" , stdin);
//     freopen ("OUTPUT.txt" , "w" , stdout);
//  #endif

// -------------------------------------Code starts here---------------------------------------------------------------------     

   int h,a;
   cin>>h>>a;
   long double x=h,y=a;
   int ans=ceil(x/y);
   cout<<ans;

// -------------------------------------Code ends here------------------------------------------------------------------
     clock_t clk;
 	clk = clock();
 
    clk = clock() - clk;
 	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
 	return 0;
 }

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

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

		if( a < b ) {
			System.out.println("a < b");
		}else if (a > b ) {
			System.out.println("a > b");
		}else if (a == b ) {
			System.out.println("a == b");
		}
	}
}


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

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

using namespace std;

typedef long long ll;
typedef long double ld;



void solve() {
	int k, a, b;
	cin >> k >> a >> b;
	if (b - a + 1 >= k) {
		cout << "OK\n";
		return;
	}
	for (int q = a; q <= b; ++q) {
		if (q % k == 0) {
			cout << "OK\n";
			return;
		}
	}
	cout << "NG\n";
}

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

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
int w,h;
char a[100][100];
int dfs(int i,int j){
    if(i==h||j==w||i<0||j<0)return 0;
    if(a[i][j]=='#')return 0;
    int s=1;
    a[i][j]='#';
    s+=dfs(i+1,j);
    s+=dfs(i-1,j);
    s+=dfs(i,j+1);
    s+=dfs(i,j-1);
    return s;
}
int main(){
    int i,j;
    while(cin>>w>>h,w!=0&&h!=0){
    //char a[h][w];
    for(i=0;i<h;i++)cin>>a[i];
    for(i=0;i<h;i++)for(j=0;j<w;j++)if(a[i][j]=='@')cout<<dfs(i,j)<<endl;
}}

Measured memory_bytes: 1184
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const ll inf = 1e18 + 9;
const ll mod = 998244353;
const double eps = 1e-8;
const double pi = acos(-1);

int n, q;
int c[500001];
int l[500001], r[500001];

int cnt[500001];
int k = 0;

void add(int v) {
    if (cnt[c[v]] == 0) k++;
    cnt[c[v]]++;
}

void del(int v) {
    cnt[c[v]]--;
    if (cnt[c[v]] == 0) k--;
}

void solve() {
    int sq = (int)sqrt(n);
    vector<pair<int, int>> qs[n/sq+1];
    for (int i = 0; i < q; i++) {
        qs[l[i]/sq].push_back(make_pair(r[i], i));
    }

    // [nl, nr)
    int nl, nr;
    int res[q];
    for (int i = 0; i <= n/sq; i++) {
        if (qs[i].size() == 0) continue;
        sort(ALL(qs[i]));
        // 初期化処理
        nl = nr = qs[i][0].first;
        memset(cnt, 0, sizeof(cnt));
        k = 0;

        for (const pair<int, int>& p : qs[i]) {
            int idx = p.second;
            while (nl > l[idx]) {
                nl--;
                add(nl);
            }
            while (nr < r[idx]) {
                add(nr);
                nr++;
            }
            while (nl < l[idx]) {
                del(nl);
                nl++;
            }

            res[idx] = k;
        }
    }

    for (int i = 0; i < q; i++) {
        cout << res[i] << endl;
    }
}

void input() {
    cin >> n >> q;
    for (int i = 0; i < n; i++) cin >> c[i];
    for (int i = 0; i < q; i++) {
        cin >> l[i] >> r[i];
        l[i]--;
    }
}

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

    input();
    solve();
}


Measured memory_bytes: 19476
#include <iostream>

char evaluation(int, int, int);

int main (){
  auto print = [](auto grade){ std::cout << grade << std::endl; };

  int m, f, r;

  std::cin >> m >> f >> r;

  while ((m!=-1)||(f!=-1)||(r!=-1))
    {
      print(evaluation(m, f, r));
      std::cin >> m >> f >> r;
    }
}

char evaluation (int m, int f, int r)
{
  if ((m==-1)||(f==-1)) return 'F';
  else if ((m+f)>=80) return 'A';
  else if ((m+f)>=65) return 'B';
  else if ((m+f)>=50) return 'C';
  else if ((m+f)>=30)
    {
      if (r>=50) return 'C';
      else return 'D';
    }
  else return 'F';
}



Measured memory_bytes: 3076
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <algorithm>

int main() {

	std::vector<int> A, B, C;
	int N;

	scanf("%d", &N);
	A.resize(N);
	B.resize(N);
	C.resize(N);

	for (int i = 0; i < N; i++) scanf("%d", &A[i]);
	for (int i = 0; i < N; i++) scanf("%d", &B[i]);
	for (int i = 0; i < N; i++) scanf("%d", &C[i]);

	std::sort(A.begin(), A.end());
	std::sort(B.begin(), B.end());
	std::sort(C.begin(), C.end());

	long long int ans = 0;

	std::vector<long long int> twothree(N + 1);

	for (int i = 0; i < N; i++) {
		twothree[i] = C.end() - std::lower_bound(C.begin(), C.end(), B[i] + 1);
	}

	for (int i = N - 1; i > 0; i--) {
		twothree[i - 1] += twothree[i];
	}

	for (int i = 0; i < N; i++) {
		ans += twothree[std::lower_bound(B.begin(), B.end(), A[i] + 1) - B.begin()];
	}


	printf("%lld", ans);

	return 0;
}

Measured memory_bytes: 2176
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<algorithm>
// #include<bits/stdc++.h>
#define INF 0x7f7f7f7f //2139062143
#define INF1 0x3f3f3f3f //1061109567
#define INF2 2147483647
#define llINF 9223372036854775807
#define pi 3.141592653589793//23846264338327950254
#define ft first
#define sd second
#define pb push_back
#define ll long long
#define vec vector<ll>
#define mat vector<vector<ll>>
//cout<<fixed<<setprecision(6)<<
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
//ifstream f1("/Users/wangzichao/Documents/wzc.in");
//ofstream f2("/Users/wangzichao/Documents/wzc.out");
//ios::sync_with_stdio(false);
//cin.tie(0);cout.tie(0);
using namespace std;
#define local
#ifdef local
#endif
const ll maxn=6e5+7;
const double eps=1e-10;
// const ll mod=1e9+7;
#define STDIN freopen("in.txt","r",stdin); freopen("out.txt","w",stdout);//************************************
#define Quick ios::sync_with_stdio(false);cin.tie(NULL);
#define int ll



// dp[i] = max(dp[i-2] + a[i], dp[i - 1]) // i&1 = 1

// dp[i] = max(dp[i-2] + a[i], dp[i-1])	//i & 1 = 0

const int N = 2e5 + 10;

ll presum[N];
int a[N];
ll dp[N];
signed main()
{
	//STDIN
	Quick
	int n;cin >> n;
	for (int i = 1; i <=n; i++) cin >> a[i];
	for (int i = 1; i <= n; i++) if (i&1) presum[i] += presum[i-1]+a[i]; else presum[i] += presum[i-1];
	dp[2] = max(a[1], a[2]);
	for (int i = 3; i <= n; i++)
	{
		if (i&1) dp[i] = max(dp[i-2] + a[i], dp[i-1]);
		else dp[i] = max(dp[i-2] + a[i], presum[i-1]);
	}
	cout << dp[n] << endl;
}

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

using namespace std;

//const int mod = 1000000007;
//#define long long uint32_t

int  main()
{    
    
	ios_base::sync_with_stdio(false);

    int t;
    cin>>t;
    int n=t;
    vector<pair<int,int>> v;
    while(t--){
        int a,b;
        cin>>a>>b;
        v.push_back({a,b});
    }
    int cnt=0,flag=0;
    for(int i=0;i<n;i++){
        if(v[i].first == v[i].second){
            cnt++;
        
        if(cnt>=3) { flag=1; break;}
        }
        else cnt=0;
    }
    if(flag) cout<<"Yes";
    else cout<<"No";
   
    return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
ll n;
vector<pair<ll,ll> >v(200005);
int  main()
{
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> v[i].second >> v[i].first;
    }
    while(v.size() > n)
        v.pop_back();
    sort(v.begin(), v.end());
    ll cur;
    for(int i = 0; i < n; i++){
        if(cur + v[i].second > v[i].first)
            return cout << "No", 0;
        cur += v[i].second;
    }
    cout << "Yes" << endl;
    return 0;

}


Measured memory_bytes: 3328
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(X: int):
    print(YES if X >= 30 else NO)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    solve(X)

if __name__ == '__main__':
    main()


Measured memory_bytes: 81408
#include<bits/stdc++.h>
 
using namespace std;
typedef unsigned long long int ll;
const ll hell = 100005; 

bool comp( vector<ll> a, vector<ll> b )
{
    return a[0]<b[0];
}
ll binpow(ll a,ll b) 
{
    ll res = 1;
    while (b > 0)
    {
        if (b & 1)
            res*=a;
        a*=a;
        b >>= 1;
    }
    return res;
}
int main()
{   
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s,t, a,b, c,d;
    cin>>s;
    t=s;
    reverse(t.begin(),t.end());
    if(s==t)
    {
        a=s.substr(0,(s.length()-1)/2);
        c=a;
        reverse(c.begin(),c.end());
        b=s.substr((s.length()+1)/2,(s.length()-1)/2);
        d=b;
        reverse(d.begin(),d.end());
        //cout<<a<<endl<<b;
        if(a==c && b==d)
        {
           cout<<"Yes";
            exit(0);
        }
        else
        {
            cout<<"No";
            exit(0);
        }
    }
    else
        cout<<"No";
    return 0;
}


Measured memory_bytes: 256
n, m = gets.chomp.split(" ").map(&:to_i)

if n == 1 and m == 1
  puts(1)
  exit
end
if n == 1
  puts(m-2)
  exit
end
if m == 1
  puts(n-2)
  exit
end
n = n-2
m = m-2
puts(n*m)


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;

int main(){
  string s;cin >> s;
  sort(s.begin(),s.end());
  if(s=="abc") cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	int k,sum=0;
	cin>>k;
	for(int i=1;i<k;i+=2){
		sum+=k-i;
	}
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cassert>
#include <cmath>
#include <map>

using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

int const nmax = 200000;
int v[5 + nmax];
std::map<int,int> frec;
void increment(int pos, int lim) {
  frec[pos]++;
  if(0 < pos) {
    if(frec[pos] == lim) {
      frec[pos] = 0;
      increment(pos - 1, lim);
    }
  }
}
int solve(int n, int k) {
  frec.clear();
  
  for(int i = 1;i <= n; i++) {
    if(v[i - 1] < v[i])
      continue;
    else {
      std::map<int,int>::iterator it = frec.lower_bound(v[i] + 1);
      if(k == 1)
        return 0;
      while(it != frec.end())
        frec.erase(it++);
      increment(v[i], k);
    }
    if(0 < frec[0])
      return 0;
  }
  return 1;

}

int binarysearch(int from, int to, int n) {
  
  if(from < to) {
    int mid = (from + to) / 2;
    if(solve(n, mid))
      return binarysearch(from, mid, n);
    else
      return binarysearch(mid + 1, to, n);
  } else
    return from;
}

int main() {
  std::ios::sync_with_stdio(0);
  std::cin.tie(0);
  int n;
  std::cin >> n;
  for(int i = 1; i <= n; i++) 
    std::cin >> v[i];
  std::cout << binarysearch(1, n, n);
  return 0;
}


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

int findSumOfDigits(int n){
  auto sum = 0;
  while(n > 0){
    sum += n % 10;
    n /= 10;
  }
  return sum;
}


int main(){
  int n, a, b;
  cin >> n >> a >> b;
  auto sum = 0;
  auto total = 0;

  for(auto i = 1; i <= n; i++){
    sum = findSumOfDigits(i);
    if(a <= sum && sum <= b) total += i;
  }

  cout << total << endl;

  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

char a, b, c;

int main()
{
    int n;
    string s;
    cin >> n >> s;
    for (int i = 0; i < n; i++)
    {
        if (s[i] == 'R')
            a++;
        else
            b++;
    }
    cout << (a > b ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
n = int(input())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
cl = list(map(int, input().split()))

ans = 0
precur = -1
for i in range(0, n):
    cur = al[i] - 1
    ans += bl[cur]
    if precur != -1 and precur + 1 == cur:
        ans += cl[precur]
    precur = cur
print(ans)


Measured memory_bytes: 3064
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	s := nextString()
	if s[0] == s[1] || s[1] == s[2] || s[2] == s[3] {
		fmt.Println("Bad")
	} else {
		fmt.Println("Good")
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define per(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#ifdef LOCAL
#define debug(x) cerr << '[' << #x << " = " << (x) << "]\n"
#else
#define debug(x)
#endif
const int maxn=3000;
double dp[maxn][maxn];
double p[maxn];
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;cin>>n;
	rep(i,0,n)cin>>p[i];
	dp[0][0]=1;
	rep(i,1,n+1){
		rep(j,0,i+1){
			if(j-1>=0)dp[i-j][j]+=dp[i-j][j-1]*(1-p[i-1]);
			if(i-j-1>=0)dp[i-j][j]+=dp[i-j-1][j]*(p[i-1]);
		}
	}
	// rep(i,0,n+1){
	// 	rep(j,0,n+1){
	// 		cout<<dp[i][j]<<' ';
	// 	}
	// 	cout<<'\n';
	// }
	double ans=0;
	rep(j,n/2+1,n+1){
		ans+=dp[j][n-j];
	}
	cout.precision(12);
	cout<<ans<<'\n';
}

Measured memory_bytes: 49924
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<sstream>
#include<complex>
#include<functional>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>

using namespace std;
#define endl '\n'
#define eb emplace_back
#define fst first
#define scd second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl

constexpr int MOD = 1000000007;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

// value
int N;
int u[100010], v[10010], w[10010];
pair<int, int> tree[10010];
int flag[10010];

template<class Abel> struct UnionFind {
	vector<int> par;
	vector<int> rank;
	vector<Abel> diff_weight;

	UnionFind(int n = 1, Abel SUM_UNITY = 0) {
		init(n, SUM_UNITY);
	}

	void init(int n = 1, Abel SUM_UNITY = 0) {
		par.resize(n); rank.resize(n); diff_weight.resize(n);
		for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
	}

	int root(int x) {
		if (par[x] == x) {
			return x;
		}
		else {
			int r = root(par[x]);
			diff_weight[x] += diff_weight[par[x]];
			return par[x] = r;
		}
	}

	Abel weight(int x) {
		root(x);
		return diff_weight[x];
	}

	bool issame(int x, int y) {
		return root(x) == root(y);
	}

	bool merge(int x, int y, Abel w) {
		w += weight(x); w -= weight(y);
		x = root(x); y = root(y);
		if (x == y) return false;
		if (rank[x] < rank[y]) swap(x, y), w = -w;
		if (rank[x] == rank[y]) ++rank[x];
		par[y] = x;
		diff_weight[y] = w;
		return true;
	}

	Abel diff(int x, int y) {
		return weight(y) - weight(x);
	}
};

void solve() {

	cin >> N;
	UnionFind<int> tree(N);
	for (int i = 0; i < N - 1; i++) {
		cin >> u[i] >> v[i] >> w[i];

		u[i]--; v[i]--;

		tree.merge(u[i], v[i], w[i]);

	}

	for (int i = 0; i < N; i++) {
		if (tree.weight(i) % 2 == 0) cout << 0 << endl;
		else cout << 1 << endl;
	}



	return;

}

int main() {

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

	solve();

	return 0;

}

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

typedef  long long ll;

int main(){
	
	int a,b,c;
  	cin >> a >> b>>c;
  	if(a<c&&b>c){
    	cout << "Yes" << endl;
    }else if(a>c&&b<c){
    	cout << "Yes" << endl;
    }else{
    	cout <<"No" << endl;
    }




  	
  
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
using namespace std;

typedef long long ll;

const int Maxl = 26;

string s;
int freq[Maxl];
ll res = 1;

int main()
{
	cin >> s;
	for (int i = 0; i < s.length(); i++)
		freq[s[i] - 'a']++;
	for (int i = 0; i < Maxl; i++)
		for (int j = i + 1; j < Maxl; j++)
			res += ll(freq[i]) * freq[j];
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>

int main()
{
	int i,j,n, m,a[50],b[50],c[50],d[50],min,x,y,answer;

	scanf("%d%d", &n, &m);

	for (i = 0; i < n; i++)
		scanf("%d%d", &a[i], &b[i]);

	for (i = 0; i < m; i++)
		scanf("%d%d", &c[i], &d[i]);

	for (i = 0; i < n; i++)
	{
		min = -1;
		for (j = 0; j < m; j++)
		{
			if (a[i]>c[j])
				x = a[i] - c[j];
			else
				x = c[j] - a[i];

			if (b[i]>d[j])
				y = b[i] - d[j];
			else
				y = d[j] - b[i];

			if (min == -1 || min > x + y)
			{
				min = x + y;
				answer = j+1;
			}
		}
		printf("%d\n", answer);
	}

	return 0;
}

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

using P = pair<ll, char>;

void print_vector(vector<P>& a){
    REP(i, a.size()){
        cout << a.at(i).second << a.at(i).first;
        if(i + 1 < a.size()){
            cout << ' ';
        }
    }
    cout << endl;
}

void bubble_sort(vector<P>& a){
    bool flag = true;
    for(ll i = 0; flag; ++i){
        flag = false;
        for(ll j = a.size() - 1; j > i; --j){
            if(a.at(j).first < a.at(j - 1).first){
                swap(a.at(j), a.at(j - 1));
                flag = true;
            }
        }
    }
}

void selection_sort(vector<P>& a){
    ll count = 0;
    for(ll i = 0; i < a.size(); ++i){
        ll minj = i;
        for(ll j = i + 1; j < a.size(); ++j){
            if(a.at(j).first < a.at(minj).first){
                minj = j;
            }
        }
        swap(a.at(i), a.at(minj));
    }
}

int main(){
    ll n;
    cin >> n;
    vector<P> a(n), b(n);
    REP(i, n){
        string card;
        cin >> card;
        a.at(i) = make_pair(
            card.at(1) - '0',
            card.at(0)
        );
    }
    copy(a.begin(), a.end(), b.begin());

    bubble_sort(a);
    selection_sort(b);
    print_vector(a);
    cout << "Stable" << endl;
    print_vector(b);
    REP(i, n){
        if(a.at(i) != b.at(i)){
            cout << "Not stable" << endl;
            return 0;
        }
    }
    cout << "Stable" << endl;

    return 0;
}



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

using namespace std;

#define MAX_N 3005

int n, y[MAX_N];
long long ps[MAX_N], dp[MAX_N][MAX_N];

long long f_imp(int, int);

long long f(int fr, int to)
{
	if (dp[fr][to] == 0)
		dp[fr][to] = f_imp(fr, to) + 1;
	return dp[fr][to] - 1;
}

long long f_imp(int fr, int to)
{
	if (fr == to)
		return y[fr];
	return max(ps[to] - ps[fr] - f(fr + 1, to) + y[fr], ps[to - 1] - ps[fr - 1] - f(fr, to - 1) + y[to]);
}

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		scanf("%d", y + i);
	}
	for (int i = 1; i <= n; i++)
	{
		ps[i] = ps[i - 1] + y[i];
	}
	long long x = f(1, n);
	long long y = ps[n] - ps[0] - x;
	printf("%lld\n", x - y);
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	vector<int>ve(1e5+1,0),vo(1e5+1,0);
	for(int i=0;i<n;++i){
		int v; cin>>v;
		if(i&1)++vo.at(v);
		else ++ve.at(v);
	}
	int me=max_element(ve.begin(),ve.end())-ve.begin();
	int mo=max_element(vo.begin(),vo.end())-vo.begin();
	sort(ve.begin(),ve.end()); sort(vo.begin(),vo.end());
	int mx;
	if(me==mo)mx=max(ve.back()+*(vo.end()-2),vo.back()+*(ve.end()-2));
	else mx=ve.back()+vo.back();
	cout<<accumulate(ve.begin(),ve.end(),0)+accumulate(vo.begin(),vo.end(),0)-mx<<"\n"s;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 1e9 + 7;
const int INF = 2e18;

template< typename T >
struct edge {
    int src, to;
    T cost;

    edge(int to, T cost) : src(-1), to(to), cost(cost) {}

    edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

    edge &operator=(const int &x) {
        to = x;
        return *this;
    }

    operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

template< typename T >
vector< T > dijkstra(WeightedGraph< T > &g, int s) {
    const auto INF = numeric_limits< T >::max();
    vector< T > dist(g.size(), INF);

    using Pi = pair< T, int >;
    priority_queue< Pi, vector< Pi >, greater< Pi > > que;
    dist[s] = 0;
    que.emplace(dist[s], s);
    while(!que.empty()) {
        T cost;
        int idx;
        tie(cost, idx) = que.top();
        que.pop();
        if(dist[idx] < cost) continue;
        for(auto &e : g[idx]) {
            auto next_cost = cost + e.cost;
            if(dist[e.to] <= next_cost) continue;
            dist[e.to] = next_cost;
            que.emplace(dist[e.to], e.to);
        }
    }
    return dist;
}


signed main() {
    int N, M;
    cin >> N >> M;
    WeightedGraph<int> G(N + 1);
    for (int i = 0; i < M; i++) {
        int L, R, C;
        cin >> L >> R >> C;
        G[L].emplace_back(R, C);
    }
    for (int i = N; i > 1; i--) {
        G[i].emplace_back(i - 1, 0);
    }
    auto dist = dijkstra(G, 1);
    cout << (dist[N] >= INF ? -1 : dist[N]) << endl;
}

Measured memory_bytes: 10748
#include"bits/stdc++.h"

std::vector<int> to[200005];
std::vector<int> ans;

void dfs(int v, int p = -1) {
  for (int u : to[v]) {
    if (u == p) continue;
    ans[u] += ans[v];
    dfs(u, v);
  }
}

void Main() {
  int n, q;
  std::cin >> n >> q;

  for (int i = 0; i < n - 1; i++) {
    int a, b;
    std::cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }

  ans.resize(n);
  for (int i = 0; i < q; i++) {
    int p, x;
    std::cin >> p >> x;
    --p;
    ans[p] += x;
  }
  dfs(0);

  for (int a: ans) {
    std::cout << a << std::endl;
  }
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}

Measured memory_bytes: 23552
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+9;
const ll mod = 998244353;
inline int read(){
    int X=0;char ch=0;
    while(!isdigit(ch)) ch=getchar();
    while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
    return X;
}
ll inv(ll a){
    ll d=1, n = mod-2;
    while(n){
        if(n&1) d = d * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return d;
}
ll gcd(ll a,ll b){
    return b? gcd(b, a%b): a;
}
int n,m;
ll h[1234][1234];
ll fac[N];
ll C(int n, int m){
    return fac[n] * inv(fac[m]) % mod * inv(fac[n-m]) % mod;
}
int main() {
    n=read(), m=read();
    if(n>m) swap(n,m);
    fac[0] = 1;
    for(int i=1; i<=n+m+n; i++) fac[i] = fac[i-1] * i % mod;
    ll ans=0;
    for(int i = 1; i <= n; i++) ans = (ans + C(i*2 ,i) * C(n+m-i-i, n-i) %mod) %mod;
    ans = ((ll)m + ans * inv(C(n+m, n)) % mod * inv(2) % mod) % mod;
    printf("%lld\n", ans);
}

Measured memory_bytes: 12544
#![allow(non_snake_case, unused_imports)]

// Input macros
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} }; ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => { let mut $var = read_value!($next, $t); input_inner!{$next $($r)*} }; }
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, [ $t:tt ]) => { { let len = read_value!($next, usize); (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() } }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,VecDeque,BinaryHeap};

// Functions

// Main
fn main(){

    input!{
        N: usize,
    }

    println!("{}", N/3);
}


Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<deque>
#include<sstream>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<bitset>
#include<time.h>
#include<cstdlib>
using namespace std;
#define ll long long
#define inf (999999999)
#define fi first
#define se second
#define MOD 1e9+7
#define PI acos(-1.0)
//--------------------------------------------------------------------------------------------------//
int n;
int a[1234567];
ll s[1234567];
int main() {
	cin >> n;
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	s[0] = a[0];
	for (int i = 1; i < n; i++) {
		s[i] = s[i - 1] + a[i];
	}
	ll ans = 1e18;
	for (int i = 0; i < n-1; i++) {
		//cout << s[i] << endl;
		//cout << sum - s[i] << endl;
		ans = min(ans, abs(s[i] - (sum - s[i])));
	}
	cout << ans << endl;
}

Measured memory_bytes: 5888
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int x1 = scan.nextInt();
		int y1 = scan.nextInt();
		int x2 = scan.nextInt();
		int y2 = scan.nextInt();
		
		int X = x2 - x1;
		int Y = y2 - y1;
		
		int x3 = x2 - Y;
		int y3 = y2 + X;
		int x4 = x3 - X;
		int y4 = y3 - Y;
		
		System.out.println(x3 + " " + y3 + " " + x4 + " " + y4);
		
	}
}


Measured memory_bytes: 23892
N,M = [int(i) for i in input().split()]
big = []
small = []
flag = 0

for i in range(N):
    a = input()
    big.append(a)
for i in range(M):
    a = input()
    small.append(a)

for i in range(0,N-M+1):
    for j in range(0,N-M+1):
        if big[i][j] == small[0][0]:
            count = 0
            for k in range(M):
                for l in range(M):
                    # if big[i+k][j+l] != small[k][l]:
                    #     continue
                    # else:
                    #     if k == M-1 and l == M-1:
                    #         flag = 1
                    #         break
                    if big[i+k][j+l] == small[k][l]:
                        count += 1
                    if k == M-1 and l == M-1 and count == M * M:
                        flag = 1

if flag == 1:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>

typedef long long ll;

// Output
template<class T, class S> std::ostream& operator << (std::ostream& os, std::pair<T, S> p)
{
  return os << "(" << p.first << " " << p.second << ")";
}

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  //os << v[0]; for (ll i = 1; i < (ll)v.size(); i++){ os << " " << v[i]; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::map< T, S > m)
{
  ll i = 0; for (auto p : m){ os << " [" << i << "]" << p.first << "->" << p.second; i++;}
  return os;
}

template<class T> std::ostream& operator <<(std::ostream& os, std::vector< std::vector<T> > vv)
{
  for (auto& vec : vv){ os << vec; }
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

int main()
{
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
  std::ios::sync_with_stdio(false);

  ll A, B;
  std::cin >> A >> B;

  ll ans = std::max(0LL, A - 2 * B);
  print(ans);
  return 0;
}


Measured memory_bytes: 256
n, *ABCD = map(int, open(0).read().split())
AB = sorted([(a, b) for a, b in zip(ABCD[:2*n:2], ABCD[1:2*n:2])], key=lambda x:-x[1])
CD = sorted([(c, d) for c, d in zip(ABCD[2*n::2], ABCD[2*n+1::2])])

for c, d in CD:
    for i in range(len(AB)):
        a, b = AB[i]
        if a < c and b < d:
            _ = AB.pop(i)
            break
print(n-len(AB))

Measured memory_bytes: 3064