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

using ll = long long;

struct Mod
{
    static const int P = int(1e9+7);
    int k;

    Mod() = default;
    Mod(const int k) : k(k%P) {}
};

Mod operator+(const Mod a, const Mod b) { return a.k + b.k; }
Mod operator-(const Mod a) { return -a.k + Mod::P; }
Mod& operator+=(Mod& a, const Mod b) { return a = a+b; }

struct FenwickTree
{
    int N;
    vector<Mod> data;
    vector<pair<int, Mod>> modifications;

    FenwickTree(const int N) : N(N), data(N+1) {}

    void add(const int n, const Mod x, const bool track = true)
    {
        if (track) modifications.push_back({n, x});
        for (int i = n+1; i <= N; i += i & -i)
            data[i] += x;
    }

    Mod query(const int n)
    {
        Mod result(0);
        for (int i = n+1; i >= 1; i -= i & -i)
            result += data[i];
        return result;
    }

    void clear()
    {
        for (const auto m : modifications)
            add(m.first, -m.second, false);
        modifications.clear();
    }
};

int main()
{
    int N; ll A, B; cin >> N >> A >> B;

    vector<ll> S(N+1);
    S[0] = numeric_limits<ll>::min();
    for (int i = 1; i <= N; i++)
        cin >> S[i];

    const auto search = [&](const ll x)
    {
        return int(upper_bound(begin(S), end(S), x) - begin(S)) - 1;
    };

    FenwickTree X(N), Y(N);
    X.add(0, 1); Y.add(0, 1);
    for (int i = 2; i <= N; i++)
    {
        const Mod y = X.query(search(S[i]-B));
        const Mod x = Y.query(search(S[i]-A));

        if (S[i]-S[i-1] < A) X.clear();
        if (S[i]-S[i-1] < B) Y.clear();

        X.add(i-1, x);
        Y.add(i-1, y);
    }
    cout << (X.query(N-1) + Y.query(N-1)).k << endl;
}


Measured memory_bytes: 3696
#include<iostream>
#include<queue>
#include<memory>
#include<map>
#include<set>
#include<unordered_map>
#include<array>
#include<vector>
#include<algorithm>
#include<list>
#include<limits>
#include<stdio.h>
#include<math.h>
#include<string>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using lst = list<ll>;

const ll MOD = 1000000007;



int main()
{
	ll N, D, A;
	cin >> N >> D >> A;

	std::vector<std::pair<ll, ll>> E(N);
	std::list<std::pair<ll, ll>> B;

	for (ll i = 0; i < N; ++i)
	{
		cin >> E[i].first >> E[i].second;
	}
	sort(E.begin(), E.end());

	ll Damage = 0;
	ll Times = 0;
	for (ll i = 0; i < N; ++i)
	{
		ll x = E[i].first;

		while (!B.empty() && B.front().first < x)
		{
			Damage -= B.front().second;
			B.pop_front();
		}

		ll HP = E[i].second - Damage;
		
		ll t = std::max
		(
			HP / A + (HP%A != 0),
			0ll
		);
		if (HP < 0) { t = 0; }

		Damage += A*t;
		B.emplace_back(x + 2 * D, A*t);
		Times += t;
	}
	cout << Times << endl;

	return 0;
}


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

using namespace std;

#define ll long long

const ll mod  = 1e9 + 7;
const ll INF = 1e14;


void solve(){

    int n, m; cin >> n >> m;
    vector<int> ht (n);
    vector<bool> valid (n, true);
    for(int& it : ht) cin >> it;
    while(m--){
        int a, b; cin >> a >> b;
        --a, --b;
        if(ht[a] >= ht[b]) valid[b] = false;
        if(ht[a] <= ht[b]) valid[a] = false;
    }
    cout << count(valid.begin(), valid.end(), true);
}


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

    //int test; cin >> test;
    //for(int t = 1; t <= test; ++t){
        solve();    
    //}

	return 0;
}



Measured memory_bytes: 3692
#include <stdio.h>

int main(int argc, char *args[])
{
	int n;
	int 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 ) {
			printf(" ");
		}
	}

	printf("\n");

	return 0;

}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define st string
#define ve(i) vector<i>
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define each(i, n) for(auto&& i: n)

int main() {
  ll A, B, K;
  cin >> A >> B >> K;
  if(A >= K) {
    A -= K;
  }
  else if(A + B >= K) {
    B -= K - A;
    A = 0;
  }
  else {
    A = 0;
    B = 0;
  }
  cout << A << " " << B << endl;
}  

Measured memory_bytes: 256
#include <iostream>
typedef long long int ll;

int main(){
    ll a,b;
    std::cin >> a >> b;
    
    if(a>b){
        ll temp=a;
        a=b;
        b=temp;
    }
    
    if((b+a)%2==0){
        std::cout << (b+a)/2 << std::endl;
    } else {
        std::cout << "IMPOSSIBLE" << std::endl;
    }
    return 0;
}


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

int main(){
  int N;
  int happy[3][100001];
  int sumhappy[3][2];

  cin >> N;

  for(int j=0; j < 3; j++){
    happy[j][0] = sumhappy[j][0] = sumhappy[j][1] = 0;
  }

  for(int i=1; i <= N; i++){
    for(int j=0; j < 3; j++){
      cin >> happy[j][i];
    }
  }
  for(int i=1; i <= N; i++){
    for(int j=0; j < 3; j++){
      sumhappy[j][1] =
        max(sumhappy[(j+1)%3][0], sumhappy[(j+2)%3][0]) + happy[j][i];
    }
    for(int j=0; j < 3; j++) sumhappy[j][0] = sumhappy[j][1];
  }
  cout << max(sumhappy[0][1], max(sumhappy[1][1], sumhappy[2][1]));
}


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

int main()
{
  int k;
  string s;
  cin >> k >> s;
  if (s.size() <= k)
  {
    cout << s << endl;
  }
  else
  {
    s = s.substr(0, k);
    s += "...";
    cout << s << endl;
  }
  return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
    using namespace std;
    const int N(507);
    int a[N], ans[N * N], cnt[N];
    int main() {
    	int n;
    	scanf("%d", &n);
    	for(int i(1); i <= n; i++) {
    		scanf("%d", &a[i]);
    	}
    	vector<pair<int, int> > vec;
    	vector<int> v1;
    	for(int i(1); i <= n; i++) {
    		int tmp(-a[i]);
    		for(int j(1); j < i; j++) {
    			vec.push_back(make_pair(tmp, i));
    		}
    		ans[a[i]] = i;
    	}
    	sort(vec.begin(), vec.end());
    	reverse(vec.begin(), vec.end());
    	int p(0), p1(0);
    	for(int i(1); i <= n * n; i++) {
    		if(ans[i]) {
    			for(int j(ans[i] + 1); j <= n; j++)
    				v1.push_back(ans[i]);
    		}else {
    			if(p < (int)vec.size()) {
    				ans[i] = vec[p].second;
    				p++;
    			}else if(p1 < v1.size()) {
    				ans[i] = v1[p1];
    				p1++;	
    			}else {
    				printf("No\n");
    				return 0;
    			}
    		}
    	}
    	for(int j(1); j <= n * n; j++) {
    		cnt[ans[j]] ++;
    		if(cnt[ans[j]] == ans[j]) {
    			if(j != a[ans[j]]) {
    				printf("No\n");
    				return 0;
    			}
    		}
    	}
    	for(int i(1); i <= n; i++)
    		if(cnt[i] != n) {
    			printf("No\n");
    			return 0;
    		}
    	printf("Yes\n");
    	for(int i(1); i <= n * n; i++) {
    		printf("%d%c", ans[i], i == n * n ? '\n' : ' ');
    	}
    }


Measured memory_bytes: 4084
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int left_zero = 0;
        int right_zero = 0;
        int double_zero = 0;
        long left_sum = 0;
        long right_sum = 0;
        ArrayList<int[]> l_r = new ArrayList<int[]>();
        ArrayList<int[]> ll = new ArrayList<int[]>();
        ArrayList<int[]> rr = new ArrayList<int[]>();
        for (int i=0;i<N;i++) {
            String S = sc.next();
            int len = S.length();
            char[] c = S.toCharArray();
            int left = 0;
            int right = 0;
            for (int j=0;j<len;j++) {
                if (c[j] == '(') {
                    left++;
                } else { // c[i] == ')'
                    if (left>0) left--;
                    else right++;
                }
            }
            if (left == 0 && right == 0) double_zero++;
            else if (left == 0) left_zero++;
            else if (right == 0) right_zero++;
            left_sum += left;
            right_sum += right;
            // System.out.println("left, right: "+left+" "+right);
            int[] tmp = {left, right};
            l_r.add(tmp);
            if (left-right >=0 ) ll.add(tmp);
            if (right-left >=0 ) rr.add(tmp);
        }

        boolean fff = true;
        if (left_sum != right_sum) fff = false;
        int left_tmp = 0;
        Collections.sort(ll, (o1, o2)->Integer.compare(o1[1], o2[1]));
        for (int i=0;i<ll.size();i++) {
            left_tmp -= ll.get(i)[1];
            if (left_tmp < 0) fff = false;
            left_tmp += ll.get(i)[0];
        }

        int right_tmp = 0;
        Collections.sort(rr, (o1, o2)->Integer.compare(o1[0], o2[0]));
        for (int i=0;i<rr.size();i++) {
            right_tmp -= rr.get(i)[0];
            if (right_tmp < 0) fff = false;
            right_tmp += rr.get(i)[1];
        }


        if (fff) System.out.println("Yes");
        else System.out.println("No");
        // System.out.println("left_sum, right_sum: "+left_sum+" "+right_sum);
        // System.out.println(left_zero+" "+right_zero+" "+double_zero);

        // if (N == 1) {
        //     if (double_zero == 1) System.out.println("Yes");
        //     else System.out.println("No");
        //     return;
        // }

        // if ((left_sum == right_sum) && (
        //     double_zero >= 2 ||
        //     (left_zero >= 1 && right_zero >= 1) ||
        //     (left_zero >= 1 && double_zero >= 1) ||
        //     (double_zero >= 1 && right_zero >= 1))
        //     ) {
        //     System.out.println("Yes");
        // } else {
        //     System.out.println("No");
        // }
    }
}

Measured memory_bytes: 110436
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>
#define vecb vector<bool>
#define vecd vector<double>
template <typename T>
T lcm(T a, T b)
{
	return a / __gcd(a, b) * b;
}

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

Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -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);
    int N,M,X;
    cin >> N >> M >> X;
    vector<int> cost(N);
    vector<vector<int>> G(N,vector<int> (M));
    for(int i=0; i<N; i++){
        cin >> cost[i];
        for(int j=0; j<M; j++){
            cin >> G[i][j];
        }
    }
    int ans = inf;
    for(int bit=0; bit<(1<<N); bit++){
        vector<int> sum(M,0);
        int suzu = 0;
        for(int j=0; j<N; j++){
            if(bit & (1LL<<j)){
                suzu += cost[j];
                for(int k=0; k<M; k++){
                    sum[k] += G[j][k];
                }
            }
        }
        bool can = true;
        for(int i=0; i<M; i++){
            if(X > sum[i]) can = false;
        }
        if(can){
            chmin(ans,suzu);
        }
    }
    if(ans == inf){
        cout << -1 << enld;
    }else{
        cout << ans << enld;
    }
    return 0;
}


Measured memory_bytes: 3648
use std::io;
use std::str::FromStr;
use std::collections::HashSet;

fn input_tuple() -> (usize, usize) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<usize> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn input_vec() -> Vec<usize> {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.split_whitespace().map(|s| s.parse().unwrap()).collect()
}

fn main() {
    let (n, k) = input_tuple();
    let a_vec = input_vec();
    let mut visited: HashSet<usize> = HashSet::new();
    let mut idx = 0;
    let mut first_visited = vec![0usize; n as usize];    
    let mut l = 0usize;
    let mut left = 0usize;
    let mut flag = true;
    for i in 0..k {
        // println!("{}", idx);
        // println!("{:?}", visited);
        // println!("{:?}", first_visited);
        if visited.contains(&idx) {
            l = i - first_visited[idx];
            left = k - i;
            flag = false;
            break;
        }
        first_visited[idx] = i;
        visited.insert(idx);
        idx = a_vec[idx] as usize - 1;
    }
    if flag {
        println!("{}", idx + 1);
    } else {
        let num = left % l;
        for _ in 0..num {
            idx = a_vec[idx] as usize - 1;
        }
        println!("{}", idx + 1);
    }
}


Measured memory_bytes: 9648
import java.util.*;
 
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
 
        long N = sc.nextInt();
        
        if(String.valueOf(N).contains("7")) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
        
    }
}

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

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,int> plli;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>=0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()

const ll mod = 1e9 + 7;
const ll INF = 1<<30;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double pi = 3.141592653589793;

int n,c;
int a[405],b[405];
ll dp[405][405];
ll su[405][405];
ll pm[405][405];

ll powmod(ll n,ll k,ll mod){
    if (k==0) return 1;
    else if (k%2==0){
        ll tmp=powmod(n,k/2,mod);
        return tmp*tmp%mod;
    }
    else return powmod(n,k-1,mod)*n%mod;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> c;
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,405)rep(j,405){
        pm[i][j]=powmod(i,j,mod);
    }
    rep(i,n)rep(j,c+1)rep2(k,a[i],b[i]+1){
        su[i][j]+=pm[k][j];
        su[i][j]=su[i][j]%mod;
    }
    dp[0][0]=1;
    rep(i,n)rep(j,c+1)rep(k,j+1){
        dp[i+1][j]+=(dp[i][j-k]*su[i][k])%mod;
        dp[i+1][j]=dp[i+1][j]%mod;
    }
    cout << dp[n][c]%mod << endl;
    return 0;
}


Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mxn= 5e5+5;
// check for forloop
// intialize variable
// overflow
// go for easy solution
#define mod 1000000007
ll INF = 1000000000000000005LL;
#define endl '\n'
void rishabh(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
int main(){
    rishabh();
    int n;
    cin>>n;
    while(n--)cout<<"ACL";
}

Measured memory_bytes: 3604
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static Scanner scanner;
	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    String s=gs();
	    String t=gs();
	    String u=gs();
        //int a=gi();

	    String a = "" +s.charAt(0)+t.charAt(1)+u.charAt(2);
        System.out.println(a);
//        if ((n%500) <= a) {
//        	System.out.print("Yes");
//        }else {
//        	System.out.print("No");
//        }


	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}
	
	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 39028
def f(n,x,i):
    if n == 0:
        if i != 0:
            if x/i == m:
                return 1
        return 0
    if memo[n-1][i][x] != -1 :
        return memo[n-1][i][x]
    memo[n-1][i][x] = f(n-1,x,i)+f(n-1,x+a[n-1],i+1)
    return memo[n-1][i][x]

n, m= map(int,input().split())
a = list(map(int,input().split()))
memo = [[[-1 for _ in range(sum(a)+1)]for i in range(n)]for i in range(n)]
print(f(n,0,0))

Measured memory_bytes: 54388
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	int height[n+1];
	for(int i=0; i<n; i++)
	{
		cin>>height[i];
	}
	vector<int> dp(n+2, 1e9);
	dp[0]=0;
	for(int i=0; i<=n; i++)
	{
		for(int j=i+1; j<=i+k; j++) //iterate over the next i+k
		{
			if(j<n)
			{
				dp[j] = min(dp[j] , dp[i] + abs(height[i] - height[j]));
			}
		}
	}
	cout<<dp[n-1];
	
}


Measured memory_bytes: 4032
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
#include <string>
#define pb push_back
#define f first
#define s second
#define mp make_pair
#define fors(i, a, b) for(int i = a; i < b; i++)
#define fori(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pair<int, int> > vpi;
typedef vector<pair<string, int> > vpsi;
typedef map<string, int> msi;
int main()
{
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    vi v(n);
    int sum = 0;
    fori(i,m)
    {
        cin >> v[i];
        sum += v[i];
    }
    if(sum > n)
    {
        cout << -1 << endl;
    } else {
        cout << n-sum << endl;
    }
    return 0;
}

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

using namespace std;

string str;
int var;
int pos;

bool formula() {
  pos++;
  if(str[pos]=='T') return true;
  if(str[pos]=='F') return false;
  if(isalpha(str[pos])) return bool(var>>(str[pos]-'a') & 1);
  if(str[pos]=='-') return !formula();
  if(str[pos]=='(') {
    int f1=formula();
    pos++;
    char op = str[pos];
    if(op=='-')pos++;
    int f2=formula();
    pos++;
    if(op=='*') return f1&&f2;
    if(op=='+') return f1||f2;
    if(op=='-') return f1<=f2;
  }
}


int main() {
  
  while(cin >> str) {
    if(str == "#") break;
    bool ok = true;
    for(var=0; var<(1<<11);var++) {
      pos = -1; int f=formula();
      pos++;
      if(f != formula()) { ok = false; break; }
    }
    if(ok) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  
  return 0;
}

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

dp1 = [0]*(n-1)
dp2 = [0]*(n-1)
dp1[0]= a[0]
dp2[0]= sum(a[1:])
m = abs(dp1[0]-dp2[0])


for i in range(1,n-1):
    dp1[i] = dp1[i-1]+a[i]
    dp2[i] = dp2[i-1]-a[i]
    tm = abs(dp1[i]-dp2[i])
    if tm < m:
        m = tm

print(m)

Measured memory_bytes: 28556
#include <iostream> 
#include <cstdio> 
#include <cstdlib> 
#include <cstring> 
#include <cmath> 
#include <algorithm> 
using namespace std; 
inline int gi() { 
    register int data = 0, w = 1; 
    register char ch = 0; 
    while (!isdigit(ch) && ch != '-') ch = getchar(); 
    if (ch == '-') w = -1, ch = getchar(); 
    while (isdigit(ch)) data = 10 * data + ch - '0', ch = getchar(); 
    return w * data; 
}
typedef long long ll; 
const int MAX_N = 2e5 + 5; 
struct Graph { int to, next, cost; } e[MAX_N << 1]; int fir[MAX_N], e_cnt; 
void clearGraph() { memset(fir, -1, sizeof(fir)); e_cnt = 0; } 
void Add_Edge(int u, int v, int w) { e[e_cnt] = (Graph){v, fir[u], w}, fir[u] = e_cnt++; } 
int N, w[MAX_N]; 
int Root, Rmx, Siz, size[MAX_N]; 
bool used[MAX_N];
struct Edge { int u, v; ll w; } a[MAX_N * 20]; int cnt = 0; 
bool operator < (const Edge &l, const Edge &r) { return l.w < r.w; } 
void getRoot(int x, int f) { 
	int mx = 0; size[x] = 1; 
	for (int i = fir[x]; ~i; i = e[i].next) { 
		int v = e[i].to; if (v == f || used[v]) continue;
		getRoot(v, x);
		size[x] += size[v], mx = max(mx, size[v]); 
	} 
	mx = max(Siz - size[x], mx); 
	if (mx < Rmx) Root = x, Rmx = mx; 
} 
pair<ll, int> stk[MAX_N];
int top; 
void getDis(int x, int f, ll ds) {
	stk[++top] = make_pair(ds, x); 
	for (int i = fir[x]; ~i; i = e[i].next) { 
		int v = e[i].to; if (v == f || used[v]) continue; 
		getDis(v, x, ds + e[i].cost); 
	} 
} 
void Div(int x) { 
	used[x] = 1, top = 0; 
	getDis(x, 0, 0); 
	for (int i = 1; i <= top; i++) (stk + i)->first += w[(stk + i)->second]; 
	pair<ll, int> *mn = min_element(&stk[1], &stk[top + 1]); 
	ll ds = mn->first; int u = mn->second; 
	for (int i = 1; i <= top; i++) { 
		int v = (stk + i)->second; 
		if (v != u) 
			a[++cnt] = (Edge){u, v, (stk + i)->first + ds}; 
	}
	for (int i = fir[x]; ~i; i = e[i].next) { 
		int v = e[i].to; if (used[v]) continue; 
		Root = 0, Rmx = Siz = size[v]; 
		getRoot(v, x); 
		Div(Root); 
	} 
} 
int pa[MAX_N]; 
int getf(int x) { return x == pa[x] ? x : pa[x] = getf(pa[x]); }

int main () { 
	clearGraph(); 
	N = gi(); for (int i = 1; i <= N; i++) w[i] = gi();
	for (int i = 1; i < N; i++) { 
		int u = gi(), v = gi(), w = gi(); 
		Add_Edge(u, v, w), Add_Edge(v, u, w); 
	} 
	Siz = Rmx = N; 
	getRoot(1, 0); 
	Div(Root); 
	sort(&a[1], &a[cnt + 1]); 
	for (int i = 1; i <= N; i++) pa[i] = i; 
	ll ans = 0; 
	for (int i = 1; i <= cnt; i++) { 
		int u = getf(a[i].u), v = getf(a[i].v); 
		if (u == v) continue; 
		ans += a[i].w; pa[u] = v; 
	} 
	printf("%lld\n", ans); 
    return 0; 
} 

Measured memory_bytes: 74112
card = Array.new(3) { Array.new(3) }
bingo = Array.new(3) { Array.new(3, false) }

3.times do |i|
  a1, a2, a3 = gets.split.map(&:to_i)
  card[i][0] = a1
  card[i][1] = a2
  card[i][2] = a3
end

# p card

N = gets.to_i

N.times do |i|
  b = gets.to_i
  card.each_with_index do |c, i|
    c.each_with_index do |a, j|
      if a == b
        bingo[i][j] = true
      end
    end
  end
end

# p bingo

ok = false
3.times do |i|
  is_bingo = bingo[i][0] == true && bingo[i][1] == true && bingo[i][2] == true
  if is_bingo
    ok = true
    break
  end
end

if ok
  puts "Yes"
  exit
end

3.times do |i|
  is_bingo = bingo[0][i] == true && bingo[1][i] == true && bingo[2][i] == true
  if is_bingo
    ok = true
    break
  end
end

if ok
  puts "Yes"
  exit
end

ok = bingo[0][0] == true && bingo[1][1] == true && bingo[2][2] == true
if ok
  puts "Yes"
  exit
end

ok = bingo[0][2] == true && bingo[1][1] == true && bingo[2][0] == true


if ok
  puts "Yes"
else
  puts "No"
end


Measured memory_bytes: 1788
/*This Code Is Nude*/
#include <bits/stdc++.h>
 
#define pb push_back
#define ll long long
#define int long long
#define max(a,b) max((long long) a , (long long) b)
#define min(a,b) min((long long) a , (long long) b)

using namespace std;

const int inf = 1e12 + 10; 
const int maxn = 2e5 + 10;
const int mod = 1e9 + 7;
 
bool mark [maxn];
vector<int>adj[maxn];

int32_t main(){
	ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	double r;
	cin >> r;
	double ans = 0;
	for(int i = 0 ; i < r*2 ; i++)
		ans += 3.14;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 8492
N = int(input())
R = []
for _ in range(N):
    x, L = map(int, input().split())
    R.append([x - L, x + L])

R.sort(key=lambda x: x[1])

ans = 1
for i in range(N):
    if (i == 0):
        first = R[0][1]
        continue

    if first <= R[i][0]:
        first = R[i][1]
        ans += 1

print(ans)


Measured memory_bytes: 25200
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N,ans=0;
  cin>>N;
  for(int i=1;i<=N/i-1;i++)
    if(N%i==0 && N/i-1>i)
      ans+=N/i-1;
  cout<<ans<<endl;
}

Measured memory_bytes: 3620
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy


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


class SegmentTree:

    def __init__(self, n, fn=lambda x, y: min(x, y), unity=(1 << 31) - 1):
        self.n = 1
        while self.n < n:
            self.n *= 2

        self.arr = [unity] * (2 * self.n - 1)
        self.fn = fn
        self.unity = unity

    def update(self, i, x):
        k = self.n + i
        self.arr[k] = x

        while k > 0:
            k >>= 1
            self.arr[k] = self.fn(self.arr[2 * k], self.arr[2 * k + 1])

    def query(self, l, r):
        l += self.n
        r += self.n
        lres, rres = self.unity, self.unity
        while l < r:
            # lが奇数ならば、dat[l]を加算
            if l & 1:
                lres = self.fn(lres, self.arr[l])
                l += 1

            # rが奇数ならば、dat[r-1]を加算
            if r & 1:
                r -= 1
                rres = self.fn(rres, self.arr[r])

            # 木をのぼる
            l >>= 1
            r >>= 1

        return self.fn(lres, rres)




    def __str__(self):
        return self.arr[0: 2 * self.n].__str__()


N, K = map(int, input().split())
MAX = 300000

st = SegmentTree(MAX + 10, fn=lambda x, y: max(x, y), unity=0)
ans = 0

while N > 0:
    A = int(input())
    minimum, maximum = max(A - K, 0), min(A + K, MAX)
    x = st.query(minimum, maximum + 1) + 1
    ans = max(ans, x)
    st.update(A, x)
    N -= 1

print(ans)


Measured memory_bytes: 82672
#!/usr/bin/env python3
import sys
import functools
INF = float("inf")


def solve(p: int, a: "List[int]"):
    N = p+1
    MOD = p

    inv = [0]*N
    inv[1] = 1
    for i in range(2, N):
        inv[i] = -inv[MOD % i]*(MOD//i) % MOD

    b = [0]*p
    for ai, av in enumerate(a):
        if av == 0:
            continue

        c = 1
        d = 1
        for i in range(p-1, -1, -1):
            b[i] += - c * d
            b[i] %= p
            c = c * i * inv[p-i] % p
            d = -d*ai % p
        b[0] += 1
        b[0] %= p
    print(*b, sep=" ")
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    p = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(p-1-0+1)]  # type: "List[int]"
    solve(p, a)


if __name__ == '__main__':
    main()


Measured memory_bytes: 42992
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;

int main(){
  int N,temp,sum;
  vector<int> A;

  cin>>N;
  A.resize(N);

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

  sort(A.begin(),A.end());

  for(int i=0;i<N;i++){
    if(A[i]%2==1){
      temp=A[i];
      break;
    }
  }

  sum=accumulate(A.begin(),A.end(),0);
  if(sum%2==1){
    sum-=temp;
    sum=sum/2;
    cout<<sum<<endl;
  }
  else{
    sum=sum/2;
    cout<<sum<<endl;
  }

  return 0;
}



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

int main()
{
    ll N;
    cin >> N;

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

    ll ans = 0;
    map<ll, int> mp;
    for (int j = 0; j < N; j++)
    {
        int sa = j - a[j];
        int wa = a[j] + j;

        ans += mp[sa];
        mp[wa]++;
    }

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

Measured memory_bytes: 27948
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <unordered_map>
#include <complex>
#include <algorithm>

using namespace std;
using i64 = int_fast64_t;
using u64 = uint_fast64_t;
using i32 = int_fast32_t;
using u32 = uint_fast32_t;

#define int i64

template<class T>
inline bool chmin(T &a, T b) { if(a > b) {a = b; return true;} return false; }
template <class T>
inline bool chmax(T &a, T b) { if(a < b) {a = b; return true;} return false; }
const int INF = 1LL << 60;

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

	if(a == b && a != c) cout << "Yes" << endl;
	else if(a == c && a != b) cout << "Yes" << endl;
	else if(b == c && a != b) 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<(n); i++)
typedef long long ll;

int main(){
	int a,b,c; cin>>a>>b>>c;
	if(a+b+c==17) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR if(DEBUG) cerr
#define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
#define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i)
#define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j)
#define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int N;
  cin>>N;
  Int cnt[10][10] = {};
  for(Int i=1;i<=N;i++){
    string s = to_string(i);
    Int a = s[0] - '0';
    Int b = s[s.size()-1] - '0';
    cnt[a][b]++;
  }

  Int ans = 0;
  for(Int i=0;i<10;i++)
    for(Int j=0;j<10;j++) ans += cnt[i][j] * cnt[j][i];
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
import math
a, b, c = map(float, input().split())
s = a * b * math.sin(c/180 * math.pi) / 2
l = math.sqrt(a*a + b*b -2*a*b*math.cos(c/180 * math.pi)) + a +b
h = b * math.sin(c/180 * math.pi)
print(s)
print(l)
print(h)


Measured memory_bytes: 5692
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>
#include <cassert>

using namespace std;
typedef long long ll;

int main(){
   int N,K;
   cin >> N >> K;
   vector<int> P(N,0);
   for (int i = 0; i < N; i++)
   {
      cin >> P[i];
   }
   int ans = N-K+1;
   int cnt = 0;
   priority_queue<pair<int,int>> ma;
   priority_queue<pair<int,int>> mi;
   bool ok = true;
   for(int i = 0 ; i <K; i++){
      if(i!=0&&P[i]< P[i-1]) ok=false;
      ma.push(make_pair(P[i],i));
      mi.push(make_pair(-P[i],i));
   }   
   if(ok)cnt++;
   for(int i = 1; i+K <=N; i++){
      pair<int,int> pi = mi.top();
      pair<int,int> pa = ma.top();
      //cout << pi.first <<" " << pi.second << endl;
      //cout << pa.first <<" " << pa.second << endl;
      if(pi.second == i-1 && pa.first<P[i+K-1]){
         //cout << i-1 <<"&"<<i << endl;
         ans--;
      }
      else{
         ok=true;
         for(int j=0;j<K-1;j++){
            if(P[i+j]>P[i+j+1]){
               ok=false;
               break;
            }
         }
         if(ok)cnt++;
      }
      ma.push(make_pair(P[i+K-1],i+K-1));
      mi.push(make_pair(-P[i+K-1],i+K-1));
      while(mi.top().second<=i-1) mi.pop();
      while(ma.top().second<=i-1) ma.pop();
   }
   cout <<ans-max(0,cnt-1)<<endl;
   return 0;
}


Measured memory_bytes: 7340
#include<iostream>
using namespace std;
int main(){
	long long int n = 0;
long long int number;
 cin>>number;
if(number==1 or number == 2){
	if(number==1){
		cout << 4;
	}
	else{
		cout << 4;
	}
}
 else{
 while(number!=4){
 	n+=1;
 if(number%2==1)
 number=number*3+1;
 else
 number=number/2;
 }
 cout << n+4;
}
 return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,l,ans,minn=114514;
int main()
{
    cin>>n>>l;
    for(int i=1;i<=n;i++){
        int a=l+i-1;
        ans+=a;
        if(abs(a)<abs(minn))minn=a;
    }
    cout<<ans-minn<<endl;
}

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

using namespace std;

int n,k,pos,x,cnt=0,mmin=1<<27;
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++) 
	{
		scanf("%d",&x);
		if(mmin>x) mmin=x,pos=i;
	}
	n-=k;cnt++;
	if(n%(k-1)==0) cnt+=n/(k-1);
	else cnt+=n/(k-1)+1;
	printf("%d",cnt);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main()
{
 ll n;
 cin>>n;
 ll ans=n*(n-1)/2;

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

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

int main(){
    int K,A,B;
    cin>> K >> A >> B;
    if(A<= B/K*K && B/K*K <=B){
        cout << "OK" << endl;
    }
    else{
        cout <<"NG" << endl;
    }
    
}


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

int main() {
	int N, ans=0;
	cin >> N;
	vector<int> A1(N), A2(N), sum1(N + 1, 0), sum2(N + 2, 0);
	for (int i = 0; i < N; i++) {
		cin >> A1[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> A2[i];
	}

	for (int i = 0; i < N; i++) {
		sum1[i + 1] = sum1[i];
		sum1[i + 1] += A1[i];
		sum2[i + 1] = sum2[i];
		sum2[i + 1] += A2[i];
	}
	for (int i = 1; i <= N; i++) {
		int tmp = sum1[i] + sum2[N] - sum2[i - 1];
		ans = max(ans, tmp);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
sx,sy,tx,ty=gets.split.map &:to_i
puts "U"*(ty-sy)+"R"*(tx-sx)+"D"*(ty-sy)+"L"*(tx-sx+1)+"U"*(ty-sy+1)+"R"*(tx-sx+1)+"D"+"R"+"D"*(ty-sy+1)+"L"*(tx-sx+1)+"U"

Measured memory_bytes: 3836
#include<bits/stdc++.h>
using namespace std;
     
#define ll long long
#define loop(i,a,n) for(ll i=a;i<n;++i)
#define revloop(i,a,b) for(ll i=a;i>=b;--i)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF 1000000000000000000
#define MOD 1000000007

ll power(ll a,ll b,ll mod)
{
    ll ans=1;
    while(b>0)
    {
        if (b%2==1)
            ans=((ans%mod)*(a%mod))%mod;;
        a=((a%mod)*(a%mod))%mod;
        b=b/2;
    }
    return ans;
}

void func()
{
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll cnt=0;
    loop(i,0,n){
        if(s[i]=='1') cnt++;
    }
    ll b[2]={0};
    revloop(i,n-1,0){
        if(cnt-1<=0) break;
        if(s[i]=='1'){
            b[0]+=power(2,n-1-i,cnt-1);
            b[0]%=(cnt-1);
        }
    }
    revloop(i,n-1,0){
        if(s[i]=='1'){
            b[1]+=power(2,n-1-i,cnt+1);
            b[1]%=(cnt+1);
        }
    }
    loop(i,0,n){
            if(s[i]=='0'){
                ll y=b[1];
                y+=power(2,n-1-i,cnt+1);
                y%=(cnt+1);
                ll t=y;
                ll ans=1;
                while(t>0){
                    ll r=t;
                    ll cnt1=0;
                    while(r>0){
                        cnt1+=(r%2);
                        r=r/2;
                    }
                    t=t%cnt1;
                    ans++;
                }
                cout<<ans<<"\n";
        }
        else{
            if((cnt-1)<=0){
                cout<<0<<"\n";
                continue;
            }
            ll y=b[0];
            y=(y-power(2,n-1-i,cnt-1)+ (cnt-1)) %(cnt-1);
            ll t=y;
            ll ans=1;
            while(t>0){
                ll r=t;
                ll cnt1=0;
                while(r>0){
                    cnt1+=(r%2);
                    r=r/2;
                }
                t=t%cnt1;
                ans++;
            }
            cout<<ans<<"\n";
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w" , stdout);
    #endif
 
    ll t=1;
    //cin>>t;
    while(t--)
    {
        func();
    }
}

Measured memory_bytes: 3772
#include<iostream>
#include<stdio.h>
using namespace std;

int* threeSort(int* arr)
{
    if(arr[0]>=arr[1] && arr[0]>=arr[2])
        swap(arr[0], arr[2]);
    else if(arr[1]>=arr[0] && arr[1]>=arr[2])
        swap(arr[1], arr[2]);

    if(arr[0]>=arr[1])
        swap(arr[0], arr[1]);
    return arr;
}

int main()
{
    int total=0;
    int* arr=new int[3];
    scanf("%d %d %d", &arr[0], &arr[1], &arr[2]);
    arr=threeSort(arr);

    if(arr[0]%2==0 && arr[1]%2==0 && arr[2]%2==0)
    {
        total=(arr[2]-arr[0])/2 + (arr[2]-arr[1])/2;
    }
    else if(arr[0]%2!=0 && arr[1]%2!=0 && arr[2]%2!=0)
    {
        total=(arr[2]-arr[0])/2 + (arr[2]-arr[1])/2;
    }
    else if(arr[0]%2==0 && arr[1]%2==0 && arr[2]%2!=0)
    {
        ++arr[0];
        ++arr[1];
        total=(arr[2]-arr[0])/2 + (arr[2]-arr[1])/2 + 1;
    }
    else if(arr[0]%2!=0 && arr[1]%2!=0 && arr[2]%2==0)
    {
        ++arr[0];
        ++arr[1];
        total=(arr[2]-arr[0])/2 + (arr[2]-arr[1])/2 + 1;
    }
    else if(arr[0]%2==0 && arr[1]%2!=0 && arr[2]%2==0)
    {
        ++arr[0];
        ++arr[2];
        total=(arr[2]-arr[0])/2 + (arr[2]-arr[1])/2 + 1;
    }
    else if(arr[0]%2!=0 && arr[1]%2==0 && arr[2]%2!=0)
    {
        ++arr[0];
        ++arr[2];
        total=(arr[2]-arr[0])/2 + (arr[2]-arr[1])/2 + 1;
    }
    else if(arr[0]%2!=0 && arr[1]%2==0 && arr[2]%2==0)
    {
        ++arr[1];
        ++arr[2];
        total=(arr[2]-arr[0])/2 + (arr[2]-arr[1])/2 + 1;
    }
    else if(arr[0]%2==0 && arr[1]%2!=0 && arr[2]%2!=0)
    {
        ++arr[1];
        ++arr[2];
        total=(arr[2]-arr[0])/2 + (arr[2]-arr[1])/2 + 1;
    }

    printf("%d\n", total);

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>

using namespace std;

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

long long int INF = 3e18;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←


#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl


ll mod = 1000000007;
ll rui(ll number1,ll number2){
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}

ll n,m,num,sum,a,b,c,d,e,f,g,h,i,j,k,w,ok,ng,l,ans,q;
ll x[500005],y[500005],z[500005];
ll p[500005],ran[500005],size[500005];
char s[500005],t[500005];
bool flag,dame;

ll find(ll x){
	if(p[x]==x){
		return x;
	}else{
		return p[x] = find(p[x]);
	}
}
void unite(ll x,ll y){
	x = find(x);
	y = find(y);
	if(x==y)return;
	if(ran[x]<ran[y]){
		ans -= size[p[x]] * size[p[y]];
		size[y] = size[p[x]] + size[p[y]];
		p[x]=y;
	}else{
		ans -= size[p[x]] * size[p[y]];
		size[x] = size[p[x]] + size[p[y]];
		p[y]=x;
		if(ran[x]==ran[y])ran[x]++;
	}
}

int main(){
    cin >> n >> m;
	for(i=0;i<m;i++){
		cin >> x[i] >> y[i];
		x[i]--;
		y[i]--;
	}
	for(i=0;i<n;i++){
		p[i] = i;
		size[i] = 1;
	}
	ans = n * (n - 1) / 2;
	z[m-1] = n * (n - 1) / 2;
	for(i=m-2;i>=0;i--){
		unite(x[i+1],y[i+1]);
		z[i] = ans;
	}
	for(i=0;i<m;i++){
		p(z[i]);
	}

	return 0;
}

Measured memory_bytes: 37632
H,W=map(int,input().split())
A=[]
A.append([0 for i in range(W+1)])
for i in range(H):
    a=[0]+list(map(int,input().split()))
    A.append(a)
B=[]
B.append([0 for i in range(W+1)])
for i in range(H):
    b=[0]+list(map(int,input().split()))
    B.append(b)
C=[[0 for i in range(W+1)]for j in range(H+1)]
for i in range(H+1):
    for j in range(W+1):
        C[i][j]=abs(A[i][j]-B[i][j])
        
ST=1<<80*160+1

dp=[[0 for i in range(W+1)]for j in range(H+1)]
dp[0][1]=ST
for i in range(1,H+1):
    for j in range(1,W+1):
        dp[i][j] |= (dp[i-1][j]<<C[i][j]) |(dp[i-1][j]>>C[i][j])
        dp[i][j] |= (dp[i][j-1]<<C[i][j]) |(dp[i][j-1]>>C[i][j])
#print(bin(dp[-1][-1]>>7))
ANS=list(bin(dp[-1][-1]>>80*160+1))[::-1]
#print(ANS)
for i in range(len(ANS)):
    if ANS[i]=="1":
        print(i)
        exit()


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

int N, M;

string id(int a) {
  int t = a, c = 0;
  while (t > 0) {
    c ++;
    t /= 10;
  }
  string res = "";
  for (int i = 0; i < 6 - c; i ++) res += '0';
  res += to_string(a);
  return res;
}

int main() {
  cin >> N >> M;
  vector<int> p(M), y(M), v[100001];
  for (int i = 0; i < M; i ++) {
    cin >> p[i] >> y[i];
    v[p[i]].push_back(y[i]);
  }
  for (int i = 1; i <= N; i ++) sort(v[i].begin(), v[i].end());

  for (int i = 0; i < M; i ++) {
    int t = lower_bound(v[p[i]].begin(), v[p[i]].end(), y[i]) - v[p[i]].begin() + 1;
    cout << id(p[i]) << id(t) << endl;
  }
}


Measured memory_bytes: 7808
#include <iostream>
#include <list>

#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;

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

  list<int> a;
  rep(i, n) {
    int t;
    cin >> t;
    a.push_back(t);
  }

  bool found = false;
  list<int>::iterator it = a.begin();
  while(it != a.end()) {
    int s = *it;
    list<int>::iterator it2 = it;
    ++it2;
    while(it2 != a.end()) {
      int t = s + *it2;
      if(t % 2 == 0) {
	a.erase(it);
	*it2 = t;
	it = a.begin();
	found = true;
	break;
      }
      ++it2;
    }
    if(found)
      found = false;
    else
      ++it;
  }

  if(a.size() == 1) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <numeric>
#include <queue>
#include <cstdio>
#include <cstring>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define mrep(i,n) for(ll i=n;i>=0;--i)
#define all(a) (a).begin(),(a).end()
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define pl pair<ll,ll>
#define inf 1001001001001001000
#define mod 1000000007
//#define mod 998244353
#define pi 3.1415926535
using namespace std;
struct __INIT{
    __INIT(){
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout<<fixed<<setprecision(15);
    }
}__init;

int main(){
    ll n;
    cin>>n;
    vl a(n);
    rep(i,n) cin>>a[i];
    sort(all(a));
    ll sum = 0;
    ll cnt = n-1;
    for(ll i = 0;i<n-1;i++){
        if(i == 0) sum += a[cnt--];
        else{
            sum += a[cnt];
            if(i%2 == 0) cnt--;
        }
    }
    
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 4780
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define bit(n,k) (((ll)n>>(ll)k)&1) /*nのk bit目*/
#define pb push_back
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
//const ll MOD=998244353LL;
//const ll MOD=1777777777LL;
//const ll MAX_V=114514LL;
//const ll MAX = 500010LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx={-1,-1,-1,0,0,1,1,1};
vl dy={1,-1,0,1,-1,1,0,-1};




int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  cout << fixed << setprecision(10);
  /*--------------------------------*/
  ll a,v,b,w,t;cin>>a>>v>>b>>w>>t;
  ll sp=v-w;
  ll d=abs(a-b);
  if(sp*t>=d){
    cout<<"YES"<<endl;
  }
  else {
    cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 3652
import numpy as np
N = int(input())

forward = np.zeros(100, dtype=int)
backward = np.zeros(100, dtype=int)

for i in range(1, N+1):
    top, bottom = int(str(i)[0]), i % 10
    forward[top * 10 + bottom] += 1
    backward[bottom * 10 + top] += 1
    
res = (forward * backward).sum()
print(res)

Measured memory_bytes: 12500
A, B, K = [int(i) for i in input().split()]

S = set()
for i in range(A, A+K):
    if i > B:
        break
    S.add(i)
for i in range(B-K+1, B+1):
    if i < A:
        break
    S.add(i)
for i in sorted(S):
    print(i)

Measured memory_bytes: 3060
#include <iostream>
#include <cstring>
#include <fstream>
#include <vector>
#include <algorithm>
#include <string>
#include <limits>
#include <map>
#include <numeric>
#include <cmath>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <stack>

typedef long long li;
using namespace std;

li max(li a, li b) {
    return a > b ? a : b;
}

li max(li a, li b, li c) {
    return max(a, max(b, c));
}

li max(li a, li b, li c, li d) {
    return max(a, max(b, max(c, d)));
}

li max(li a, li b, li c, li d, li e) {
    return max(a, max(b, max(c, max(d, e))));
}


li pow_mod(li n, li e, li mod)
{
    li r = 1;
    
    while(e > 0)
    {
        if(e & 1)
            r *= n;
            r %= mod;
        
        n *= n;
        n %= mod;
        e >>= 1;
    }
    
    return r;
}

double solve(int n, unordered_map<int, double> & m) {
    double maxV = 0.0;
    
    if (m.count(n)) return m[n];
    if (n == 0) return 0.0;
    
    for (int i = 1; i <= n; i++) {
        maxV = max(maxV, solve(n - i, m)+ (double)i / (double)n);
    }
    
    return m[n] = maxV;
}

int solve(vector<int> & v, int n) {
    if (n < 0) return 0;
    vector<int> a, b;
    int minV = 0;
    
    for (int num: v) {
        if (num & (1 << n)) a.push_back(num);
        else b.push_back(num);
    }
    
    
    if (a.size() && b.size()) minV += (1 << n);
    
    if (a.size() && b.size()) minV += min(solve(a, n - 1), solve(b, n - 1));
    else if (a.size()) minV += solve(a, n - 1);
    else if (b.size()) minV += solve(b, n - 1);
    
    return minV;
    
}

int main() {
//    ifstream fin("read.txt");
    int h, n, num;
    
    cin >> h >> n;

    for (int i = 0; i < n; i++) {
    	cin >> num;
    	h -= num;
    }

    if (h <= 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}




Measured memory_bytes: 256