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

using namespace std;

class UnionFind {
 private:
  std::vector<int> parent;

 public:
  UnionFind(int n) : parent(n, -1) {}

  int root(int x) {
    if (parent[x] < 0) return x;
    return parent[x] = root(parent[x]);
  }

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

  int size(int x) { return -parent[root(x)]; }

  bool unite(int x, int y) {
    int rx = root(x), ry = root(y);
    if (rx == ry) return false;
    if (parent[rx] > parent[ry]) std::swap(rx, ry);
    parent[rx] += parent[ry];
    parent[ry] = rx;
    return true;
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, M;
  cin >> N >> M;
  vector<int> A(N);
  for (auto&& e : A) {
    cin >> e;
  }
  UnionFind uf(N);
  for (int i = 0; i < M; i++) {
    int u, v;
    cin >> u >> v;
    uf.unite(u, v);
  }
  map<int, priority_queue<int, vector<int>, greater<int>>> mp;
  for (int i = 0; i < N; i++) {
    mp[uf.root(i)].push(A[i]);
  }
  if (2 * ((int)mp.size() - 1) > N) {
    cout << "Impossible" << '\n';
    return 0;
  }
  if ((int)mp.size() == 1) {
    cout << 0 << '\n';
    return 0;
  }
  int64_t res = 0;
  for (auto&& [k, v] : mp) {
    res += v.top();
    v.pop();
  }
  priority_queue<int, vector<int>, greater<int>> que;
  for (auto&& [k, v] : mp) {
    while (!v.empty()) {
      que.push(v.top());
      v.pop();
    }
  }
  for (int i = 0; i < (int)mp.size() - 2; i++) {
    res += que.top();
    que.pop();
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 15048
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, _s, n) for(int i = _s, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;

#define repi(itr, ds) for(auto itr = ds.begin(); itr != ds.end(); itr++)
// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for(T &x : vec) is >> x;
  return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "{";
  for(int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  }
  os << "}\n   ";
  return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
  os << "{";
  repi(itr, map_var) {
    os << *itr;
    itr++;
    if(itr != map_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
  os << "{";
  repi(itr, set_var) {
    os << *itr;
    itr++;
    if(itr != set_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}

#define DUMPOUT cerr

void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
  DUMPOUT << head;
  if(sizeof...(Tail) > 0) {
    DUMPOUT << ", ";
  }
  dump_func(std::move(tail)...);
}
#ifdef DEBUG_
#define DEB
#define dump(...)                                                             \
  DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                             \
          << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
          << "    ",                                                          \
      dump_func(__VA_ARGS__)
#else
#define DEB if(false)
#define dump(...)
#endif

typedef long long int ll;

int main() {
  string S;
  cin >> S;
  string ans = "Sunny";
  if(S == "Sunny") {
    ans = "Cloudy";
  } else if(S == "Cloudy") {
    ans = "Rainy";
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
/*
--------------              |   /
      |                     |  /
      |                     | /
      |             *       |/          |    |         ------            *
      |                     |           |    |        /      \
      |             |       |\          |    |       |       |\          |
   \  |             |       | \         |    |       |       | \         |
    \ |             |       |  \        |    |        \     /   \        |
     V              |       |   \        \__/|         -----     \       |
*/
#include <bits/stdc++.h>
using namespace std;

#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
#define mem(i,j) memset(i,j,sizeof (i));
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define lowbit(x) ((x)&(-(x)))
#define siz(v) (long long)(v).size()
typedef int64_t ll;
typedef uint64_t ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
const double EPS  = 1e-8;
const int INF     = 0x3F3F3F3F;
const ll LINF     = 4611686018427387903;
const int MOD     = 1e9+7;
const int MAXN    = 2e5+9;
/*-----------------------------------------------------------------------------------------------------*/

signed main() {
	EmiliaMyWife

	int h, w, mx, ans=INF;
	cin >> h >> w >> mx;
	vector<string> arr(h);
	for(int i = 0; i < h; i++) cin >> arr[i];
	for(int i = 0; i < (1<<(h-1)); i++) {
		int cur = 0;
		vector<pii> bs;
		int it = 0;
		for(int j = 0; j < h; j++) {
			if((1<<j)&i) {
				bs.pb(mp(it, j));
				it=j+1;
			}
		}
		bs.pb(mp(it, h-1));
		vector<int> cnt(bs.size());
		for(int j = 0; j < w; j++) {
			int nd = 0, unvalid=0;
			for(int k = 0; k < bs.size(); k++) {
				int www=0;
				for(int z = bs[k].F; z <= bs[k].S; z++) {
					if(arr[z][j]=='1') cnt[k]++, www++;
				}
				if(www>mx) unvalid=1;
				if(cnt[k] > mx) nd=1;
			}
			if(unvalid) {
				cur=INF;
				break;
			}
			if(nd) {
				cur++;
				for(int k = 0; k< bs.size(); k++) {
					cnt[k]=0;
					for(int z = bs[k].F; z <= bs[k].S; z++) {
						if(arr[z][j]=='1') cnt[k]++;
					}
				}
			}
		}
		ans=min(ans, cur+__builtin_popcount(i));
	}
	cout << ans;

	return 0;
}


Measured memory_bytes: 256
def main():
    x = int(input())
    for a in range(10**4):
        a5 = a**5
        tar = a5 - x
        if 0 <= tar:
            L, R = 0, 10**5
            while L+1 < R:
                P = (L+R)//2
                p5 = P**5
                if p5 <= tar:
                    L = P
                else:
                    R = P
            if L**5 == tar:
                print(a, L)
                break
        else:
            L, R = -(10**5), 0
            while L+1 < R:
                P = (L+R)//2
                p5 = P**5
                if p5 <= tar:
                    L = P
                else:
                    R = P
            if L**5 == tar:
                print(a, L)
                break

if __name__ == "__main__":
    main()

Measured memory_bytes: 9164
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

signed main() {
	int N, x;
	cin >> N >> x;

	vector<int> a(N), b;
	rep(i, N) cin >> a[i];

	b = a;

	int ret = LLONG_MAX;
	rep(i, N) {
		int cost = x * i;
		rep(j, N) cost += b[j];
		ret = min(ret, cost);

		vector<int> c = b;
		c[0] = min(b[0], b[N - 1]);
		REP(j, 1, N - 1) c[j] = min(b[j], b[j - 1]);
		b = c;
	}

	cout << ret << endl;
}


Measured memory_bytes: 256
using System;

namespace ABC052B
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = Int32.Parse(Console.ReadLine());
            string s = Console.ReadLine();
            int cur = 0;
            int res = 0;

            foreach (char c in s.ToCharArray())
            {
                if(c == 'I')
                {
                    cur++;
                    if(res < cur) { res++; }
                }
                else
                {
                    cur--;
                }
            }

            Console.WriteLine(res);
        }
    }
}


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

int main() {
    string s;
    getline(cin,s);
    for (int i = 0; i < s.size(); i++) {
        if(islower(s[i])){
            s[i] = toupper(s[i]);
        }else if(isupper(s[i])){
            s[i] = tolower(s[i]);
        }
    }
    cout << s << endl;
    return 0;
}



Measured memory_bytes: 3176
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int k, x;
    cin >> k >> x;

    for (int pos = x - k + 1; pos < x + k; pos++) {
        cout << pos << ' ';
    }

    return 0;
}

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

int minimum(int a,int b)
{
    return a<b?a:b;
}
int findmin(int n,int arr[])
{
    int min[n];
    min[n-1]=0;
    min[n-2]=abs(arr[n-1]-arr[n-2]);
    for(int i=n-3;i>=0;i--)
    {
        min[i]=minimum(min[i+1]+abs(arr[i]-arr[i+1]),min[i+2]+abs(arr[i]-arr[i+2]));
    }
    return min[0];
}
int main()
{
    int n;
    cin>>n;
    int arr[n];
    {
        for(int i=0;i<n;i++)
        {
            cin>>arr[i];
        }
    }
    int ans;
    ans=findmin(n,arr);
    cout<<ans;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int N=510;
int a[N][N];

int main(){
	int n,m,q;scanf("%d%d%d",&n,&m,&q);
	for(int i=1,x,y;i<=m;++i) scanf("%d%d",&x,&y),a[x][y]++;
	for(int i=1;i<=n;++i)
	 for(int j=1;j<=n;++j)
	 	a[i][j]+=a[i][j-1];
	for(int i=1,x,y;i<=q;++i){
		int ans=0;
		scanf("%d%d",&x,&y);
		for(int i=x;i<=y;++i) ans+=a[i][y];
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1920
N,M = map(int,input().rstrip().split(" "))
ans = [False for _ in range(N + 1)]
balls = [1 for _ in range(N + 1)]
ans[1] = True
for i in range(M):
  q = list(map(int,input().rstrip().split(" ")))
  if ans[q[0]] == True:
    ans[q[1]] = True
  balls[q[0]] -= 1
  if balls[q[0]] == 0: ans[q[0]] = False
  balls[q[1]] += 1
ansi = 0
for i in range(N + 1):
  if ans[i]: ansi += 1
print(ansi)

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

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

fn switch_number(n1: &mut i32, n2: &mut i32) {
    let tmp = *n1;
    *n1 = *n2;
    *n2 = tmp;
}

fn main() {
    let mut A: i32 = read();
    let mut B: i32 = read();
    let mut C: i32 = read();
    switch_number(&mut A, &mut B);
    switch_number(&mut A, &mut C);
    println!("{} {} {}", A, B, C);
}


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

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 1010;
const int mod = 1e9 + 7;

int n;

int main()
{
    cin >> n;

    int res = 1;
    for(int i = 1; i <= n; i++)
        res = (LL)res * i % mod;

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >>N;
  vector<int> A;
  for(int i=0; i<N; i++){
    int a;
    cin >>a;
    A.push_back(a);
  }
  sort(A.begin(), A.end());
  long long ans=1, count=0;
  for(int i=N-1; i>0; i--){
    if(A[i]==A[i-1]){
      if(count==0){
        ans*=A[i];
        A[i]=0, A[i-1]=0;
        count++;
        continue;
      }
      else{
        ans*=A[i];
        count++;
        break;
      }
    }
  }
  if(count!=2) ans=0;
  cout <<ans <<endl;
}


Measured memory_bytes: 892
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

bool memo[80][80][12800];

int main()
{
	LL H, W;
	in >> H >> W;
	std::vector<std::vector<LL>>A(H, std::vector<LL>(W)), B(H, std::vector<LL>(W));
	rep(i, H) rep(j, W) in >> A[i][j];
	rep(i, H) rep(j, W) in >> B[i][j];

	memset(memo, false, sizeof(memo));
	memo[0][0][std::abs(A[0][0] - B[0][0])] = true;
	rep(i, H)
	{
		rep(j, W)
		{
			rep(k, 12800)
			{
				if (memo[i][j][k])
				{
					if (i + 1 < H)
					{
						memo[i + 1][j][k + std::abs(A[i + 1][j] - B[i + 1][j])] = true;
						memo[i + 1][j][std::abs(k - std::abs(A[i + 1][j] - B[i + 1][j]))] = true;
					}
					if (j + 1 < W)
					{
						memo[i][j + 1][k + std::abs(A[i][j + 1] - B[i][j + 1])] = true;
						memo[i][j + 1][std::abs(k - std::abs(A[i][j + 1] - B[i][j + 1]))] = true;
					}
				}
			}
		}
	}

	rep(k, 12800)
	{
		if (memo[H - 1][W - 1][k])
		{
			out << k << std::endl;
			return 0;
		}
	}
}


Measured memory_bytes: 80384
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long N,T;
  long long t[N];
  cin >> N >> T;
  for(int i=0; i<N; i++){
    cin >> t[i];
  }
  long long ans = 0;
  for(int i=0; i<N-1; i++){
    if(t[i+1] - t[i] < T){
      ans += t[i+1] - t[i];
    }else{
      ans += T;
    }
  }
  cout << ans + T << endl;
  return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;

int main() {
    int a, b;
    cin >> a >> b;
    if (a*b % 2 == 0) {
        cout << "Even" << endl;
    } else cout << "Odd" << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

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

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
int gcd(int a, int b)
{
	if (a%b == 0)return b;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main()
{
	int n; cin >> n;
	string s; cin >> s;
	vector<ll> alp(26);
	rep(i, n)++alp[s[i] - 'a'];
	ll res = 1;
	int MOD = 1e9 + 7;
	rep(i, 26)
	{
		res *= (alp[i] + 1);
		res %= MOD;
	}
	cout << res - 1 << endl;
}

Measured memory_bytes: 512
import java.util.*;
import java.io.*;

public class Main
{
	public static void main(String [] Args)
	{
		Scanner in = new Scanner(System.in);
		String s=in.next();
		int n=s.length();
		long m=1000000007l;
		long [][] ans = new long [n+1][13];
		ans[0][0]=1;
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<13;j++)
			{
				if(s.charAt(i)=='?')
				{
					for(int k=0;k<10;k++)
					{
						ans[i+1][(10*j+k)%13]=(ans[i+1][(10*j+k)%13]+ans[i][j])%m;
					}
				}
				else
				{
					ans[i+1][(10*j+(s.charAt(i)-'0'))%13]=(ans[i+1][(10*j+(s.charAt(i)-'0'))%13]+ans[i][j])%m;
				}
			}
		}
		System.out.println(ans[n][5]);
	}
}
	

Measured memory_bytes: 39116
#include <iostream>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <sstream>
#include <vector>
#include <map>
#include <fstream>
using namespace std;

typedef long long int ll;

const int N = 10;

bool Visit[N];

void dfs(int n, int x, string str, ll &ans);

int main()
{
	string S;

	cin >> S;

	ll ans = 0;
	dfs(S.length(), 0, S, ans);

	ans += stoll(S);

	cout << ans << endl;

	return 0;
}

void dfs(int n, int x, string str, ll &ans)
{
	string str2 = "";
	if (x >= n) {
		return;
	}
	else {
		if (x > 0) {
			for (int i = 0; i < n; i++) {
				str2 += str[i];
				if (Visit[i]) {
					ans += stoll(str2);
					str2 = "";
				}
			}
			ans += stoll(str2);
			str2 = "";
		}

		for (int i = x; i < n - 1; i++) {
			if (!Visit[i]) {
				Visit[i] = true;
				dfs(n, i + 1, str, ans);
				Visit[i] = false;
			}
		}
	}
}

Measured memory_bytes: 256
/*************************************************************************
    > File Name: test.cpp
    > Author: Akira 
    > Mail: qaq.febr2.qaq@gmail.com 
 ************************************************************************/

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <ctime>
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
#define MST(a,b) memset(a,b,sizeof(a))
#define CLR(a) MST(a,0)
#define Sqr(a) ((a)*(a))
using namespace std;

#define MaxN 100001
#define MaxM MaxN*10
#define INF 0x3f3f3f3f
#define bug cout<<88888888<<endl;
#define MIN(x,y) (x<y?x:y)
#define MAX(x,y) (x>y?x:y)

int N;
int A[MaxN];

int main()
{
    int odd = 0;
    int even = 0;
    scanf("%d", &N);
    for(int i=0;i<N;i++)
    {
        scanf("%d", &A[i]);
        if(A[i]&1) odd++;
    }
    if(odd&1) printf("NO\n");
    else printf("YES\n");
    
    //system("pause");
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
 
int main() {
  int N, min=1000, max=-1, dis=10000000000000;
  cin >> N;
  int x[N];
  for(int i=0; i<N; i++) {
     cin >> x[i];
     if(x[i] > max) {
       max=x[i]; 
     }
     if(x[i] < min) {
       min=x[i]; 
     }
  }
  for(int j=min; j<=max; j++) {
    int sum=0;
    for(int i=0; i<N; i++) {
      sum+= (x[i]-j)*(x[i]-j);    
    }
    if(sum<dis) {
      dis=sum; 
    }
  }
  cout << dis << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}

int main(){
  
  long long n;
  cin>>n;
  long long p[n];//pの要素は相異なる
  long long place[n+1];
  for(long long i=0;i<n;i++){
    cin>>p[i];
    place[p[i]] = i;
  }
  //vector<long long> left(n,-1);
  //vector<long long> right(n,n) ;
  
  set<long long> s;
  s.insert(-1);
  s.insert(n);
  long long ans = 0;
  long long l,r;
  long long ll,rr;
  for(long long i=n;i>=1;i--){//二番目に大きな値としてiをとる区間の数を調べる
    auto itr_r = s.lower_bound(place[i]);
    r = *itr_r;
    auto itr_l = itr_r;
    --itr_l;
    l = *itr_l;
    //left[place[i]] = l;
    //right[place[i]] = r;
    if(r!=n && l!=-1){
      auto itr_rr = itr_r;
      rr = *(++itr_rr);
      ans += i*(place[i]-l)*(rr-r);
      auto itr_ll = itr_l;
      ll = *(--itr_ll);
      ans += i*(l-ll)*(r-place[i]);
    }else if(r != n){
      auto itr_rr = itr_r;
      rr = *(++itr_rr);
      ans += i*(place[i]-l)*(rr-r);
    }else if(l != -1){
      auto itr_ll = itr_l;
      ll = *(--itr_ll);
      ans += i*(l-ll)*(r-place[i]);
    }else{
      ;
    }
    s.insert(place[i]);
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 6528
from bisect import bisect_right
A, B, Q = map(int, input().split())
INF = 10 ** 18
s = [-INF] + [int(input()) for i in range(A)] + [INF]
t = [-INF] + [int(input()) for i in range(B)] + [INF]
xs = [int(input()) for i in range(Q)]
for x in xs:
    b, d = bisect_right(s, x), bisect_right(t, x)
    res = INF
    for S in [s[b - 1], s[b]]:
        for T in [t[d - 1], t[d]]:
            d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
            res = min(res, d1, d2)
    print(res)


Measured memory_bytes: 16128
#pragma GCC optimize("Ofast")
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <functional>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
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; }
// ---------------------------------------------------------------------------

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string S;
    cin >> S;
    set<char> se;
    for(int i=0; i<S.size(); i++){
      if(se.count(S[i])){
        cout << "no\n";
        return 0;
      }
      se.emplace(S[i]);
    }
    cout << "yes\n";
    return 0;
}

Measured memory_bytes: 3636
def jikan(now_t,i):
    if i==n:
        return now_t
    else:
        if now_t<=s[i]:
            now_t = s[i]
        else:
            tmp1 = now_t//f[i]
            if now_t%f[i]!=0:
                now_t = (tmp1+1)*f[i]
        tmp = jikan(now_t+c[i],i+1)
        return tmp

n = int(input())
c,s,f = [0],[0],[0]
for i in range(n-1):
    ci,si,fi = map(int,input().split())
    c.append(ci)
    s.append(si)
    f.append(fi)
#print(c,s,f)
for i in range(1,n+1):
    print(jikan(0,i))


Measured memory_bytes: 9276
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int n, p = 1, t = 0;
    cin >> n;
    vector<int> a(n + 1), f(n + 1, 1);
    for (int i = 1; i <= n; ++i) cin >> a.at(i);
    while (f.at(p)) {
        f.at(p) = 0;
        p = a.at(p);
        ++t;
        if (p == 2) {
            cout << t << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 1024
using System;

public class P
{
    public int min { get; set; }
    public int L { get; set; }
    public int r { get; set; }
    public int Ln { get; set; }
    public int rn { get; set; }
}

public class hello
{
    public static void Main()
    {
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            var ps = new P[n];
            var child = new bool[n];
            for (int i = 0; i < n; i++)
            {
                string[] line = Console.ReadLine().Trim().Split(' ');
                var a = int.Parse(line[0]);
                var b = int.Parse(line[1]);
                var c = int.Parse(line[2]);
                var d = int.Parse(line[3]);
                var abgcd = Gcd(a, b);
                a /= abgcd;
                b /= abgcd;
                if (c == 0 && d == 0)
                    ps[i] = new P { min = a + b };
                else
                {
                    ps[i] = new P { L = a, r = b, Ln = c - 1, rn = d - 1 };
                    if (c != 0) child[c - 1] = true;
                    if (d != 0) child[d - 1] = true;
                }
            }
            var parent = 0;
            for (int i = 0; i < n; i++)
                if (!child[i]) { parent = i; break; }
            var ans = getAns(ps, parent);
            Console.WriteLine(ans);
        }
    }
    static int getAns(P[] ps, int t)
    {
        var w = ps[t];
        if (w.min > 0) return w.min;
        if (w.Ln != -1 && w.rn != -1)
        {
            var a1 = getAns(ps, w.Ln);
            var a2 = getAns(ps, w.rn);
            var x = w.r * a2;
            var y = w.L * a1;
            var ww = Gcd(x, y);
            x /= ww;
            y /= ww;
            return x * a1 + y * a2;
        }
        if (w.rn != -1)
        {
            var tww = getAns(ps, w.rn);
            var a = w.r * tww;
            var y = w.L;
            var ww = Gcd(a, y);
            a /= ww;
            y /= ww;
            return a + y * tww;
        }
        if (w.Ln != -1)
        {
            var tww = getAns(ps, w.Ln);
            var a = w.L * tww;
            var y = w.r;
            var ww = Gcd(a, y);
            a /= ww;
            y /= ww;
            return a + y * tww;
        }
        return 0;
    }
    static int Gcd(int a, int b)
    {
        if (a < b) return Gcd(b, a);
        while (b != 0)
        {
            var w = a % b;
            a = b;
            b = w;
        }
        return a;
    }
}



Measured memory_bytes: 13840
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;


int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * (b / gcd(a,b)); }

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

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

    if (S[0] != T[0]) {
        cout << -1 << endl;
        return 0;
    }

    int l = lcm(N, M);

    int i = 0;
    int n = l / N;
    int m = l / M;
    while (m * i < N && n * i < M) {
        if (S[m*i] != T[n*i]) {
            cout << -1 << endl;
            return 0;
        }
        i++;
    }

    cout << l << endl;

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <cctype>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, std::less<>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef unsigned long long uint64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//*/998244353;
const int base = 2187;
const double eps = 1e-9;
const int N = 300'000;
const int LOGN = 19;

int n, m, k;

int64 pw(int64 a, int64 b) {
  int64 res = 1;
  for (; b; b >>= 1) {
    if (b & 1) {
      res *= a;
      res %= mod;
    }
    a *= a;
    a %= mod;
  }
  return res;
}

int64 inv(int64 a) {
  return pw(a, mod - 2);
}

int64 C(int n, int a) {
  int64 res = n;
  for (int i = 2; i <= a; ++i) {
    res *= (n - i + 1);
    res %= mod;
    res *= inv(i);
    res %= mod;
  }
  return res;
}

void solve(int) {
  cin >> n >> k;
  int64 ans = 1, l = 1, r = 1;
  for (int i = 1; i < min(k + 1, n); ++i) {
    l *= (n - i + 1) * inv(i) % mod;
    r *= (n - i) * inv(i) % mod;
    l %= mod;
    r %= mod;
    ans += l * r % mod;
    ans %= mod;
  }
  cout << ans << '\n';
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int ans;
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	if (a>0) ans=1;
	else
	{
		if (b>=0) ans=3;
		else
		{
			if ((abs(a)-abs(b))%2==1) ans=1;
			else ans=2;
		}
	}
	if (ans==1) printf("Positive");
	if (ans==2) printf("Negative");
	if (ans==3) printf("Zero");
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int	main(void)
{
	int n,a,min=1000001,max=-1000001,i;
	long sum=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a);
		min=(a<min ? a : min);
		max=(a>max ? a : max);
		sum+=a;
	}
	printf("%d %d %ld\n",min,max,sum);
	return	0;
}

Measured memory_bytes: 600
s = input()

c = 0
if s.count(s[0]) == 2:
    for i in range(4):
        if s.count(s[i]) == 2:
            c += 1
        else:
            pass
    if c == 4:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+20;
const ll mod=1e9+7;
//ÌâÒâ:¸ø³ömÌõÆ½ÐÐÓÚxÖáµÄÖ±Ïß:yi ,nÌõÆ½ÐÐÓÚyÖáµÄÖ±Ïßxi,n,m<=1e5,ÇóËÄÔª×é(i,j,k,l)×é³É²»Í¬µÄ¾ØÐÎÃæ»ýÖ®ºÍ,i,j<=n,k,l<=m; 
//¶Ôx,y sortºó ans=segma,segma(xj-xi)*(yl-yk)
//ans=segma(xj-xi)*segma(yl-yk)
//n<=1e5,ÈçºÎ¿ìËÙµÃµ½segma(xj-xi),¼ÆËãxkµÄ¹±Ï× xk¼ÓÁËk-1´Î ±»¼õÁËn-k´Î segma(xj-xi)=segma((k-1)xk-(n-k)xk)  
ll x[N],y[N];
int main()
{
	ll n,m;
	while(cin>>n>>m)
	{
		for(int i=1;i<=n;i++)
			scanf("%lld",&x[i]);	
		for(int i=1;i<=m;i++)
			scanf("%lld",&y[i]);
		ll ans=0,s1=0,s2=0;
		for(ll i=1;i<=n;i++)
		{
			s1=s1+(i-1)*x[i];
			s1=s1-(n-i)*x[i];
			s1=(s1+mod)%mod;
		}
		for(ll i=1;i<=m;i++)
		{
			s2=s2+(i-1)*y[i];
			s2=s2-(m-i)*y[i];
			s2=(s2+mod)%mod;
		}
		ans=(s1*s2)%mod;
		cout<<ans<<endl;
	}	
	return 0;
}

Measured memory_bytes: 1792
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
a.sort()
def gcd(x,y):
    if y==0:
        return x
    else:
        return gcd(y,x%y)
ans=a[0]
for i in a:
    ans=gcd(ans,i)

if k%ans==0 and max(a)>=k:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")






Measured memory_bytes: 14252
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <list>
using namespace std;

bool checkChar(char c){
    if(c == 'A' || c == 'T' || c == 'G' || c == 'C'){
        return true;
    }
    else{
        return false;
    }
}

int main(){

    string s;
    cin >> s;

    int ans = 0;
    int temp = 0;
    for(int i=0; i<s.length(); i++){
        temp = 0;
        if(checkChar(s[i]) == false){
            continue;
        }
        else{
            temp = 1;
            if(ans < temp){
                ans = temp;
            }
        }
        for(int j=i+1; j<s.length(); j++){
            if(checkChar(s[j]) == true){
                temp++;
                if(ans < temp){
                    ans = temp;
                }
                if(j == s.length() - 1){
                    break;
                }
            }
            else{
                break;
            }
        }
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int n,a[100];
    int i;
    
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    
    for(i=n-1;i>=0;i--){
        printf("%d",a[i]);
        if(i!=0){
            putchar(' ');
        }
    }
    
    putchar('\n');
    
    return 0;
}


Measured memory_bytes: 2100
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N,ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// x,yの最大公約数
ll gcd(ll x, ll y) {
	ll r;
	while (x%y) {
		r = x % y;
		x = y;
		y = r;
	}
	return y;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//円周率
const double PI = 3.14159265358979323846;

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

	if (c <= a) {
		if (d <= a)cout << 0 << endl;
		else if (d >= a && d <= b)cout << d - a << endl;
		else cout << b - a << endl;
	}
	else if (c > a && c <= b) {
		if (d <= b) cout << d - c << endl;
		else cout << b - c << endl;
	}
	else cout << 0 << endl;
}

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

#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;

using namespace std;



void oneCase() {
    vector<char> dg(4);
    for (auto& el : dg) {
        cin >> el;
    }
    for (int i = 0; i < 8; ++i) {
        string res;
        res += dg[0];
        int s = dg[0] - 48;
        for (int j = 0; j < 3; ++j) {
            if (i & (1 << j)) {
                s += dg[j + 1] - 48;
                res += "+";
                res += dg[j + 1];
            } else {
                s -= dg[j + 1] - 48;
                res += "-";
                res += dg[j + 1];
            }
        }
        if (s == 7) {
            cout << res + "=7\n";
            return;
        }
    }
}

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

    int t = 1;
//    cin >> t;
    while (t--) {
       oneCase();
    }

    return 0;
}


Measured memory_bytes: 256
from sys import stdin

N = int(stdin.readline().rstrip())
D = [int(x) for x in stdin.readline().rstrip().split()]

if D[0] > 0:
    print(0)
    exit()
D.sort()

ans = 1
mod = 998244353
b = 1

temp = 1
for i in range(1, N):
    if D[i] == 0:
        print(0)
        exit()
    if D[i] - D[i - 1] > 1:
        print(0)
        exit()
    if D[i] != D[i - 1]:
        b = temp
        temp = 1
    else:
        temp += 1
    ans *= b
    ans %= mod

print(ans % mod)


Measured memory_bytes: 52848
#include <iostream>
#include <string>
using namespace std;
int main(){
   string S;
   cin >> S;
   if(S[5]!='1' && S[6] == '1'){
     cout << "Heisei" << endl;
   }
   else if(S[5]!='1' && S[6] == '2'){
     cout << "Heisei" << endl;
   }
   else if(S[5]!='1' && S[6] == '3'){
     cout << "Heisei" << endl;
   }
   else if(S[5]!='1' && S[6] == '4'){
     cout << "Heisei" << endl;
   }
   else
   cout << "TBD" << endl;



}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)

using namespace std;

/////////////////////////////////////////////////////

ll N;
ll X[1010],Y[1010];
vector<ll> dv,cdv;

ll i, j, k;

void no(){
    printf("-1\n");
    exit(0);
}


int main(){
    scanf("%lld",&N);
    fornum(i,0,N){
        scanf("%lld%lld",&X[i],&Y[i]);
    }
    ll od = abs(X[0] + Y[0]) % 2;
    ll mx = 0;
    fornum(i,0,N){
        if (abs(X[i] + Y[i]) % 2 != od)
        {
            no();
        }
        mx = max(mx, abs(Y[i]) + abs(X[i]));
    }
    dv.push_back(1);
    if(od==1){
        dv.push_back(1);
    }
    ll smm;
    for (smm = 1; smm < mx;smm*=2){
        dv.push_back(smm);
    }
    dv.push_back(smm);
    smm *= 2;

    printf("%d\n", dv.size());
    fornum(i,0,dv.size()){
        printf("%lld ", dv[i]);
    }

    cdv.resize(dv.size());
    cdv[0] = cdv[1] = 1;
    fornum(i,0,N){
        ll mnn = min(abs(X[i]), abs(Y[i]));
        ll df = smm - abs(X[i]) - abs(Y[i]) - od;
        df /= 2;
        ll xy = 0;
        if(abs(X[i])>abs(Y[i])){
            xy = 1;
        }

        fornum(j,1+od,dv.size()){
            if(dv[j]&df){
                cdv[j] = -dv[j];
            }else{
                cdv[j] = dv[j];
            }
        }

        ll a = (od && mnn % 2 ? mnn + 1 : mnn), ans = 0;
        fornum(j,od,dv.size()){
            if(a&dv[j]){
                a -= cdv[j];
                ans |= 1ll << j;
            }
        }
        if(xy){
            ans = ~ans;
        }
        if(od){
            ans |= 1;
            cdv[0] = -dv[0];
            if(Y[i]%2){
                ans ^= 1;
            }
        }

        printf("\n");
        fornum(j,0,dv.size()){
            if(X[i]==0&&Y[i]==0){
                if(j!=dv.size()-1){
                    printf("R");
                }else{
                    printf("L");
                }
                continue;
            }
            if(ans&(1ll<<j)){
                if(X[i]*cdv[j]>0){
                    printf("R");
                }else{
                    printf("L");
                }
            }else{
                if(Y[i]*cdv[j]>0){
                    printf("U");
                }else{
                    printf("D");
                }
            }
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;

int next(int c){
	printf("%d\n",c);
	fflush(stdout);
	string S;
	cin>>S;
	int a;
	if(S=="Vacant")a=0;
	if(S=="Male")a=1;
	if(S=="Female")a=2;
	return a;
}

int main(void){
	int N,l,r,c=0,m[100010]={};
	string S;
	scanf("%d",&N);
	l=0;r=N-1;
	
	m[l] = next(l);
	if(m[l]==0)return 0;
	m[r] = next(r);
	if(m[r]==0)return 0;

	rep(i,20){
		c=(l+r)/2;
		m[c] = next(c);
		if(m[c]==0)break;
		if(m[c]==m[l] ^ abs(c-l)%2==0){//[c+1,r]
			r=c;
		}else{//[l,c-1]
			l=c;
		}
	}
	return 0;
}

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

					using namespace std;
					typedef long long ll;
					ll a, b, c, n;
					int main()
					{
                      cin >> n >> a >> b;
                      c = (n/(a+b)) * a;
                      if(n % (a+b) > a)
                        c += a;
                      else c += n % (a+b);
                      cout << c;
					}

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

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


Measured memory_bytes: 256
N,M=map(int, input().split())
sw=[[0]*N for m in range(M)]
for m in range(M):
    ks=list(map(int, input().split()))
    for i in ks[1:]:
        sw[m][i-1]=1
p=list(map(int, input().split()))
from itertools import product
ans=0
for x in product((0,1),repeat=N):
    a=1
    for m in range(M):
        s=0
        for i in range(N):
            s+=sw[m][i]*x[i]
        if s%2!=p[m]:
            a=0
            break
    ans+=a
print(ans)

Measured memory_bytes: 3188
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define Rep(i,a,n)for(int i=(int)(a);i<(int)(n);i++)
#define rep(i,n)Rep(i,0,n)
typedef long long ll;
typedef long double ld;
#define Ma(x,y) ((x)>(y)?(x):(y))
#define mi(x,y) ((x)<(y)?(x):(y))
#define N 100002

int main() {
	int n, m, h[N], a, b, good[N] = { 0 },ans=0;
	scanf("%d %d", &n, &m);
	Rep(i,1,n+1)scanf("%d", &h[i]);
	Rep(i,1,m+1) {
		scanf("%d %d", &a, &b);
		if (h[a] > h[b])good[b]--;
		else if (h[a] < h[b])good[a]--;
		else { good[a]--; good[b]--; }
	}
	Rep(i, 1, n + 1) {if (good[i] == 0)ans++; }
	printf("%d", ans);
}

Measured memory_bytes: 2464
#include<stdio.h>

int main(void)
{
    int a;
    int b;

    scanf("%d%d",&a,&b);

    if (a < b) {
        printf("a < b\n");
    }
    else if (a > b){
        printf("a > b\n");
    }
    else {
        printf("a == b\n");
    }
    
    return 0;
}

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

int main(){
  int a;
  cin>>a;
  if(a==25){
    cout<<"Christmas"<<endl;
  }else if(a==24){
    cout<<"Christmas Eve"<<endl;
  }else if(a==23){
    cout<<"Christmas Eve Eve"<<endl;
  }else{
    cout<<"Christmas Eve Eve Eve"<<endl;
  }
}


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

int h,w,n;
vector<vector<pair<int,int>>> v(4);


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

    

    cin>>h>>w>>n;

    for(int i=1;i<=n;i++){
        int x1,x2,y2,y1;

        cin>>x1>>y1>>x2>>y2;

        if(((x1==0 || x1==h) || (y1==0 || y1==w)) && ((x2==0 || x2==h) || (y2==0 || y2==w))){
            if(x1==0){
                v[0].push_back(make_pair(y1,i));
            }
            else if(y1==w){
                v[1].push_back(make_pair(x1,i));
            }
            else if(x1==h){
                v[2].push_back(make_pair(y1,i));
            }
            else v[3].push_back(make_pair(x1,i));

            if(x2==0){
                v[0].push_back(make_pair(y2,i));
            }
            else if(y2==w){
                v[1].push_back(make_pair(x2,i));
            }
            else if(x2==h){
                v[2].push_back(make_pair(y2,i));
            }
            else v[3].push_back(make_pair(x2,i));
        }
        
    }
    
    sort(v[0].begin(),v[0].end());
    sort(v[1].begin(),v[1].end());
    sort(v[2].begin(),v[2].end(),greater<pair<int,int>>());
    sort(v[3].begin(),v[3].end(),greater<pair<int,int>>());

    vector<int> st;
    for(int i=0;i<4;i++){
        for(auto j:v[i]){
            st.push_back(j.second);
        }
    }
    int cnt=1;
    int dep[100010]={};
    for(auto i:st){
        //cerr<<i<<endl;
        if(dep[i]==0){
            dep[i]=cnt;
            cnt++;
        }
        else{
            cnt--;
            if(dep[i]!=cnt){
                cout<<"NO"<<endl;
                return 0;
            }
        }
    }
    
    cout<<"YES"<<endl;

}

Measured memory_bytes: 4180
//Bismillahir Rahmanir Rahim

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {

    int n, m, c;
    cin>>n>>m>>c;
    int arr1[m], arr2[m], p, sum=0, cnt=0;
    for(int i=0; i<m; i++) cin>>arr1[i];
    while(n--){
        for(int i=0; i<m; i++){
            cin>>arr2[i];
            p=arr2[i]*arr1[i];
            sum+=p;

        }
        if(sum+c>0) cnt++;
        sum=0;
    }
    cout<<cnt;



}



Measured memory_bytes: 3640
n = int(input())
a = input()
x = []
x.extend([int(i) for i in a])

# 1,2,3 を0,1,2として考えてもよい(差は変わらないから)
# もし1と0だけだったら簡単そう
# 2は012を210にする効果しかない 1 or 0,2 と考えたら同値
# 1が混ざっている条件で最後の答えが2になることはあり得ない->2を0と考えてよい
if 2 in x:
    flag = True
    x = [1 if i == 2 else 0 for i in x]
else:
    flag = False
    x = [1 if i == 3 else 0 for i in x]
c=0
n=len(x)
n_b=bin(n-1)
if x[0]==1:
    c+=1
for i in range(1,n-1):
    tmp_nck = int((n-1) == (i | (n-1-i)))
    if x[i] == 1:
        c+=tmp_nck
if x[n-1]==1:
    c+=1
if flag:
    print(c%2)
else:
    if c%2 == 1:
        print(2)
    else:
        print(0)



Measured memory_bytes: 22460
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod=1e9+7;
ll mod_pow(ll a,ll b){
  ll res=1;
  for(int i=0;i<60;i++){
    if(b>>i&1){
      res=res*a%mod;
    }
    a=a*a%mod;
  }
  return res;
}

int main(){
  ll m,n;
  cin>>m>>n;
  cout<<mod_pow(m,n)<<endl;
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>

using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;

    int x, dist = 0;
    for (int i = 0; i < n; i++) {
        cin >> x;
        dist += min(2*x, 2*(k-x));
    }

    cout << dist << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    int a,b;

    scanf("%d %d",&a,&b);

    if(a<b){
        printf("a < b\n");
    }
    else if(a>b){
        printf("a > b\n");
    }
    else{
        printf("a == b\n");
    }
    return 0;
}

Measured memory_bytes: 580
#include <algorithm>
#include <iostream>
#include <queue>
#include <cmath>
#include <set>
#include <iomanip>
#include <vector>
using namespace std;
typedef long long ll;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
#define INF 100000000
#define MAX_V 100001
#define MOD 1000000007
typedef vector<vector<int> > Graph;
typedef long double ld;

int main(){
    int a,b,c,d,e,f;cin>>a>>b>>c>>d>>e>>f;
    vector<vector<int>> dp(3001,vector<int>(3001,0));
    dp[0][0]=1;
    int s_max=(int)((double)f/100*e);
    for(int i=0;i<f+1;i++){
        for(int j=0;j<s_max+1;j++){
            if(i-100*a>=0) dp[i][j]=max(dp[i-100*a][j],dp[i][j]);
            if(i-100*b>=0) dp[i][j]=max(dp[i-100*b][j],dp[i][j]);
            if(i-c>=0&&j-c>=0) dp[i][j]=max(dp[i-c][j-c],dp[i][j]);
            if(i-d>=0&&j-d>=0) dp[i][j]=max(dp[i-d][j-d],dp[i][j]);
        }
    }
    ld ans=0;
    ld MAX=(ld)e/(100.0+e);
    int m_sum,m_s;
    for(int i=0;i<f+1;i++){
        for(int j=0;j<f/100*e+1;j++){
            if(dp[i][j]==1){
                ld s=(ld)j/(ld)i;
                if(s>=ans){
                    if(s>MAX) continue;
                    ans=s;
                    m_sum=i;
                    m_s=j;
                }
            }
        }
    }
    cout<<m_sum<<' '<<m_s<<endl;
}

Measured memory_bytes: 35584
import sys
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def g(x):
    if x <= 0:
        return 0
    tmp = x
    n = 0
    while tmp > 0:
        tmp //= 2
        n += 1
    l = [0]*n
    for i in range(n):
        if i==0:
            l[i] = 1 if x%4==1 or x%4==2 else 0
        else:
            l[i] = max(x%(1<<(i+1))-(1<<i)+1, 0)%2
    return sum(l[i]*(2**i) for i in range(n))


def main():
    A, B = mi()
    print(g(B)^g(A-1))

if __name__ == '__main__':
    main()


Measured memory_bytes: 62204
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N, S;
  cin >> N >> S;

  int x=-1, y=-1,z=-1;
  int i,j,k;
  int cnt = 0;
  int res;
  for(i = 0; i*10000 <=S && i <= N; i++){
    for(j = 0; 5000*j + 10000*i <= S && i + j <= N; j++){
      res = S - 10000*i - 5000*j;
      k = res / 1000;
      if(res % 1000 == 0 && i + j + k == N){
        x = i;
        y = j;
        z = k;
      } else {
        continue;
      }
    }
  }

  cout << x << " " << y << " " << z << endl;

}



Measured memory_bytes: 256