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

//定数
const long long MOD1=1000000007;
const long long MOD2=998244353;
const long double PI=3.1415926535897932;
const long long MAXLL=9223372036854775807;
const long long INF=2305843009213693951;
const long long dx[]={0,1,0,-1,1,-1,1,-1};
const long long dy[]={1,0,-1,0,1,1,-1,-1};

//型名省略
#define ll long long
#define ull unsigned long long
#define ld long double
#define uld unsigned long double
#define pll pair<long long,long long>
#define tll(n) array<long long,(int)(n)>
#define pcc pair<char,char>
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<pair<long long,long long>>
#define vt(n) vector<array<long long,(int)(n)>>
#define umap unordered_map
#define uset unordered_set
#define Lqueue priority_queue<long long>
#define Squeue priority_queue<long long,vector<long long>,greater<long long>>
#define Fi first
#define Se second
#define mp make_pair
#define eb emplace_back

//マクロ
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rbf(a,x) for(auto& a:x)
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s);i<(long long)(n);i++)
#define bitrep(i,s,n) for(long long i=(s);i<(1LL<<(n));i++)
#define Maxe(x) *max_element((x).begin(),(x).end())
#define Mine(x) *min_element((x).begin(),(x).end())
#define Size(x) ((long long)(x).size())
#define lin(s) getline(cin,(s))
#define Ssort(v) sort((v).begin(),(v).end(),[](auto &left,auto &right){return left.second<right.second;})

//Yes,No
void Yes(bool a){cout<<(a?"Yes":"No")<<endl;}
//YES.NO
void YES(bool a){cout<<(a?"YES":"NO")<<endl;}

//MAX,MIN
template<class T,class U> auto max(T a,U b){return a>b?a:b;}
template<class T,class U> auto min(T a,U b){return a<b?a:b;}

//最大公約数,最小公倍数
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a,long long b){return a/gcd(a,b)*b;}

//累乗
template<typename t>
constexpr t mypow(t a,long long b){
    if(b==0)return 1;
    if(a==0)return 0;
    t x=1;
    while(b>0){
        if(b&1LL)x*=a;
        a*=a;
        b>>=1LL;
        }
    return x;
}
#define pow mypow

//chmin,chmax
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;}

//組み合わせ O(r)
template<typename t>
constexpr t nCr(t n,long long r){
    if(r==0)return 1;
    if(n==0)return 0;
    if(n<r)return 0;
    t x=1;
    for(long long i=1;i<=r;i++){
        x*=n-i+1;
        x/=i;
    }
    return x;
}

//main関数
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll a,b,c;
    cin>>a>>b>>c;
    cout<<max({a,b,c})-min({a,b,c})<<endl;
}

Measured memory_bytes: 3616
use std::io;
use std::collections::HashMap;

fn read_line() -> String {
    let mut line = String::new();

    io::stdin().read_line(&mut line)
        .expect("Failed to read line");
    return line;
}
fn to_i(s: &str) -> i64 {
    return s.trim().parse()
        .expect("Please type a number!");
}
fn read_nums() -> Vec<i64>
{
    let line = read_line();
    let items: Vec<&str> = line.split(' ').collect();

    let mut nums: Vec<i64> = Vec::new();

    for item in items {
        nums.push(to_i(item));
    }
    return nums;
}


fn main() {
    //println!("start");
    let l = read_line();
    let chars = l.chars().collect::<Vec<char>>();;
    
    let mut count = 0;
    for c in chars {
        if c == 'x' {
            count += 1;
            if count >7 {
                print!("NO");
                return;
            }
        }
    }

    print!("YES");
    
}   

Measured memory_bytes: 4352
import java.util.*;

class Main {

    static long dp[][] = new long[100005][3];
    static boolean vis[][] = new boolean[100005][3];

    static long solve(int a[], int b[], int c[], int n, int pos, int cur) {
        long ans = Integer.MIN_VALUE;

        if (pos == n) {
            return 0;
        }

        if (cur != -1 && vis[pos][cur]) {
            return dp[pos][cur];
        }
        if (cur != -1) {
            vis[pos][cur] = true;
        }

        for (int i = pos; i < n; i++) {
            if (cur != 0)
                ans = Math.max(ans, a[pos] + solve(a, b, c, n, pos + 1, 0));

            if (cur != 1)
                ans = Math.max(ans, b[pos] + solve(a, b, c, n, pos + 1, 1));

            if (cur != 2)
                ans = Math.max(ans, c[pos] + solve(a, b, c, n, pos + 1, 2));
        }
        if (cur != -1) {
            dp[pos][cur] = ans;
        }
        return ans;
    }

    static long solve1(int a[], int b[], int c[], int n) {

        dp[0][0] = a[0];
        dp[0][1] = b[0];
        dp[0][2] = c[0];

        for (int i = 1; i < n; i++) {
            dp[i][0] = a[i] + Math.max(dp[i - 1][1], dp[i - 1][2]);
            dp[i][1] = b[i] + Math.max(dp[i - 1][0], dp[i - 1][2]);
            dp[i][2] = c[i] + Math.max(dp[i - 1][0], dp[i - 1][1]);
        }

        return Math.max(dp[n - 1][0], Math.max(dp[n - 1][1], dp[n - 1][2]));
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        int a[] = new int[n];
        int b[] = new int[n];
        int c[] = new int[n];

        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
            c[i] = sc.nextInt();
        }

        // System.out.println(solve(a, b, c, n, 0, -1));
        System.out.println(solve1(a, b, c, n));
    }
}

Measured memory_bytes: 100784
var lines = [];

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var N = Number(lines[0]);
    var W = lines[1].split(" ").map(i => Number(i))

    
    var result = Infinity

    for (var i = 0; i < N; i++) {
        var S1 = 0; var S2 = 0;;

        for (var j = 0; j < i; j++) { S1 += W[j] }
        for (var j = i; j < N; j++) { S2 += W[j] }
        
        result = Math.min(Math.abs(S1 - S2),result)
    }
    console.log(result)
}); 

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

#define ll long long
#define ull unsigned long long
#define pb push_back
#define pii pair<int, int>
#define sz size()

#define int ll

vector<int> st;

void update(int node, int l, int r, int i, int val)
{
	if(l>r or l>i or r<i)
		return;

	if(l==r and l==i)
	{
		st[node] = val;
		return;
	}

	int mid = (l+r)/2;
	update(2*node+1, l, mid, i, val);
	update(2*node+2, mid+1, r, i, val);

	st[node] = max(st[2*node+1], st[2*node+2]);
}

int query(int node, int l, int r, int i, int j)
{
	if(l>r or l>j or r<i)
		return 0;

	if(i<=l and r<=j)
		return st[node];

	int mid = (l+r)/2;

	int q1 = query(2*node+1, l, mid, i, j);
	int q2 = query(2*node+2, mid+1, r, i, j);

	return max(q1,q2);
}

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>void __f(const char* name, Arg1&& arg1){cout<<name<<" : "<<arg1<<"\n";}
template <typename Arg1, typename... Args>void __f(const char* names, Arg1&& arg1, Args&&... args)
{const char* comma=strchr(names+1,',');cout.write(names,comma-names)<<" : "<<arg1<<" , ";__f(comma+1, args...);} 
#define traceloop(x,a) { cerr<<#a<<": "; for(ll ix=0;ix<x;ix++) cerr<<a[ix]<<" "; cerr<<endl; }

signed main()
{
	ios::sync_with_stdio(0);

	int i, j, k, n;

	cin>>n;
	int h[n], b[n];
	for(i=0;i<n;++i)
		cin>>h[i];
	for(i=0;i<n;++i)
		cin>>b[i];

	const int maxh = 2e5 + 10;
	st.resize(4 * maxh);

	int ans = 0;
	
	ll temp;
	for(i=0;i<n;++i)
	{
		int x = query(0, 0, maxh-1, 0, h[i]);
		temp = b[i] + x;
		update(0, 0, maxh-1, h[i], temp);
		//trace(x, temp);
		ans = max(ans, temp);
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define until(x) while(!(x))
#define unless(x) if(!(x))
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define pc __builtin_popcount

map<string,int> mp;

int32_t main(){
	int n;
	cin>>n;
	string s;
	int mx = 0;
	for(int i=1;i<=n;i++){
		cin>>s;
		mp[s]++;
		mx = max(mx,mp[s]);
	}
	set<string> se;
	for(auto x: mp){
		string t = x.first;
		if(x.second == mx){
			se.insert(t);
		}
	}
	for(auto x:se){
		cout<<x<<"\n";
	}
}


Measured memory_bytes: 34560
import java.util.Scanner;
//import java.lang.Math;

class Main{
	public static void main(String[] arg){
	

		
		Scanner sc = new Scanner(System.in);
		int[] dice=new int[6];
		for(int i=0;i<6;i++){dice[i]=sc.nextInt();}
        int[][] str = new int[100][4];
        
        
        
        str[dice[0]][0]=dice[1];
        str[dice[0]][1]=dice[2];
        str[dice[0]][2]=dice[4];
        str[dice[0]][3]=dice[3];
        
        str[dice[1]][0]=dice[0];
        str[dice[1]][1]=dice[3];
        str[dice[1]][2]=dice[5];
        str[dice[1]][3]=dice[2];
        
        
        str[dice[2]][0]=dice[0];
        str[dice[2]][1]=dice[1];
        str[dice[2]][2]=dice[5];
        str[dice[2]][3]=dice[4];
        
        str[dice[3]][0]=dice[0];
        str[dice[3]][1]=dice[4];
        str[dice[3]][2]=dice[5];
        str[dice[3]][3]=dice[1];
        
        str[dice[4]][0]=dice[0];
        str[dice[4]][1]=dice[2];
        str[dice[4]][2]=dice[5];
        str[dice[4]][3]=dice[3];
        
        str[dice[5]][0]=dice[1];
        str[dice[5]][1]=dice[3];
        str[dice[5]][2]=dice[4];
        str[dice[5]][3]=dice[2];
       /*
         str[dice[5]][4]=dice[2];
        
        str[dice[4]][0]=dice[2];
        str[dice[1]][5]=dice[2];
        str[dice[0]][1]=dice[2];
        
        str[dice[5]][2]=dice[1];
        str[dice[3]][5]=dice[1];
        str[dice[2]][0]=dice[1];
        str[dice[0]][3]=dice[1];
        
        str[dice[4]][3]=dice[0];
        str[dice[3]][0]=dice[0];
        str[dice[2]][4]=dice[0];
        str[dice[1]][2]=dice[0];
        
        str[dice[5]][1]=dice[3];
        str[dice[4]][5]=dice[3];
        str[dice[1]][0]=dice[3];
        str[dice[0]][4]=dice[3];
        
        str[dice[5]][3]=dice[4];
        str[dice[3]][0]=dice[4];
        str[dice[2]][5]=dice[4];
        str[dice[0]][2]=dice[4];
        
        str[dice[4]][2]=dice[5];
        str[dice[3]][4]=dice[5];
        str[dice[2]][1]=dice[5];
        str[dice[1]][3]=dice[5];
        
         */
        int sum=sc.nextInt();
        
        for(int i=0;i<sum;i++){
        	
        	int a=sc.nextInt();
        	int b=sc.nextInt();
        	for(int j=0;j<4;j++){
        		if(str[a][j]==b){
        			System.out.println(str[a][(j+1)%4]);
        			break;
        		}
        	}
        }
       }}


Measured memory_bytes: 26432
max2 = lambda x,y: x if x > y else y
min2 = lambda x,y: x if x < y else y

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

from collections import defaultdict

def solve(U,R,D,L):

    def helper(U,R):
        A = defaultdict(list)
        B = defaultdict(list)
        for x,y in U:
            A[x+y].append(x)
        for x,y in R:
            B[x+y].append(x)
        m = 1000000
        for d,r in A.items():
            l = B[d]
            j = 0
            for li in l:
                while j < len(r) and li > r[j]:
                    j += 1
                if j == len(r):
                    break
                m = min2(m, r[j]-li)
        return m

    def helper2(U,D):
        A = defaultdict(list)
        B = defaultdict(list)
        for x,y in U:
            A[x].append(y)
        for x,y in D:
            B[x].append(y)
        m = 100000000
        for d,l in A.items():
            l.sort()
            r = B[d]
            r.sort()
            j = 0
            for li in l:
                while j < len(r) and li > r[j]:
                    j += 1
                if j == len(r):
                    break
                m = min2(m, r[j]-li)
        return m



    U.sort()
    R.sort()
    D.sort()
    L.sort()
    m = helper(U,R)
    A,B = [(-x,y) for x,y in U], [(-x,y) for x,y in L]
    A.reverse()
    B.reverse()
    m = min2(helper(A,B), m)
    A,B = [(x,-y) for x,y in D], [(x,-y) for x,y in R]
    m = min2(helper(A,B), m)
    A,B = [(-x,-y) for x,y in D], [(-x,-y) for x,y in L]
    A.reverse()
    B.reverse()
    m = min2(helper(A,B), m)
    m *= 10
    m = min2(helper2(U,D)*5, m)
    A,B = [(y,x) for x,y in L], [(y,x) for x,y in R]
    m = min2(helper2(B,A)*5, m)

    return m if m < 10000000 else 'SAFE'



if __name__ == '__main__':
    N = int(readline())

    t = iter(read().split())

    U,R,D,L = [],[],[],[]
    for x,y,u in zip(t,t,t):
        p = (int(x),int(y))
        u = u.decode('utf8')
        if u == 'U':
            U.append(p)
        elif u == 'R':
            R.append(p)
        elif u == 'D':
            D.append(p)
        else:
            L.append(p)

    print(solve(U,R,D,L))

Measured memory_bytes: 205912
#include <stdio.h>
#include <string.h>

int main(void)
{
    int n, i;
    scanf("%d", &n);
    for(i = 0; i < n; i++){
        char done[1024][73];
        char org[73];
        int num = 0, len, j;

        scanf("%s", org);
        len = strlen(org);

        for(j = 1; j < len; j++){
            int k;
            char first[2][72], second[2][72];
            for(k = 0; k < j; k++){
                first[0][k] = first[1][j - 1 - k] = org[k];
            }
            first[0][k] = first[1][k] = '\0';
            for(k = j; k < len; k++){
                second[0][k - j] = second[1][len -1 - k] = org[k];
            }
            second[0][len - j] = second[1][len - j] = '\0';
            //printf("first: %s, rev: %s\n", first[0], first[1]);
            //printf("second: %s, rev: %s\n", second[0], second[1]);

            int l;
            for(k = 0; k < 2; k++){
                for(l = 0; l < 2; l++){
                    int m;
                    char temp[73];
                    strcpy(temp, first[k]);
                    strcat(temp, second[l]);
                    for(m = 0; m < num; m++)
                        if(strcmp(temp, done[m]) == 0)
                            break;
                    if(m == num){
                        strcpy(done[num], temp);
                        num++;
                    }
                    strcpy(temp, second[l]);
                    strcat(temp, first[k]);
                    for(m = 0; m < num; m++)
                        if(strcmp(temp, done[m]) == 0)
                            break;
                    if(m == num){
                        strcpy(done[num], temp);
                        num++;
                    }
                }
            }
        }
        //for(j = 0; j < num; j++)
        //    printf("%s\n", done[j]);

        printf("%d\n", num);
    }
    return 0;
}

Measured memory_bytes: 664
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define PI 3.1415926535897932384626
#define boost ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MOD 1000000007
#define forn(i,n) for(int i=0;i<n;i++)
int main()
{
       boost;
       string s;
       cin>>s;int ans=0;
       forn(i,s.size())
       {
             if(s[i]=='o')
             ans++;
       }
       cout<<700+(100*ans)<<endl;
}    

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

class Program
{
    public static void Main()
    {
        string []input=Console.ReadLine().Split();
        string[] temp = Console.ReadLine().Split();
        int a = int.Parse(temp[0]);
        int b = int.Parse(temp[1]);
        string ans = Console.ReadLine();
        if (input[0] == ans) { Console.Write(a-1); Console.Write(" "); Console.Write(b); }
        else { Console.Write(a); Console.Write(" "); Console.Write(b-1); }
    }
}

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

int main() {
    string s;
    cin >> s;
    char c = s.at(0);
    if (c != s.at(1) || c != s.at(2)) {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
# xor battle


def is_included(base, X):
    base.sort(reverse=True)
    V = X
    for x in base:
        V = min(V, V ^ x)
    return V


def solve():
    N = int(input())
    a = list(map(int, input().split()))[::-1]
    player = input()[::-1]
    basement = [0]
    for i in range(N):
        v = a[i]
        K = is_included(basement, v)
        if player[i] == "0":
            if K == 0:
                pass
            else:
                basement.append(K)
        else:
            if K == 0:
                pass
            else:
                return 1

    return 0


def main():
    T = int(input())
    for i in range(T):
        A = solve()
        print(A)
    return


if __name__ == "__main__":
    main()

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

template <typename T>
class Nullable {
	T* _value{ nullptr };
	Nullable() {};
	Nullable(T *own_ptr) :_value{ own_ptr } {}
public:
	~Nullable() { delete _value; }
	static Nullable make_nullable(const T &value) {
		return Nullable(new T(value));
	}
	static Nullable make_null() {
		return Nullable();
	}
	const T &value() const {
		return *_value;
	}
	bool operator==(const void *ptr) const {
		return _value == ptr;
	}
};
template<typename T>
bool operator==(const void *ptr, Nullable<T> &nullable) {
	return nullable == ptr;
}
class Weighted_union_find_tree {
	struct Pair {
		Weighted_union_find_tree *ptr;
		int differ;
	};
	Weighted_union_find_tree *_parent{ nullptr };
	int _diff{ 0 };
	Pair parent() {
		if (_parent == nullptr)
			return Pair{ this, 0 };
		else
		{
			auto prev = _parent->parent();
			_parent = prev.ptr;
			_diff += prev.differ;
			return Pair{ _parent, _diff };
		}
	};
public:
	void set_relate(Weighted_union_find_tree &greater, int weight) {
		if (is_related(greater)) return;
		auto other_pos = greater.parent();
		other_pos.ptr->_parent = this;
		other_pos.ptr->_diff = weight - other_pos.differ;
	};
	bool is_related(Weighted_union_find_tree &other) {
		return parent().ptr == other.parent().ptr;
	};
	Nullable<int> diff(Weighted_union_find_tree &other) {
		if (!is_related(other)) return Nullable<int>::make_null();
		auto pos = parent();
		auto other_pos = other.parent();
		return Nullable<int>::make_nullable(other_pos.differ - pos.differ);
	};
};
int main() {
	int n, q;
	std::cin >> n >> q;
	std::vector<Weighted_union_find_tree> uft(n);
	int query, x, y, z;
	for (auto i = 0; i < q; ++i) {
		std::cin >> query;
		switch (query) {
		case 0: std::cin >> x >> y >> z;
			uft[x].set_relate(uft[y], z); break;
		default: std::cin >> x >> y;
			auto nullable = uft[x].diff(uft[y]);
			if (nullable == nullptr) {
				std::cout << '?' << std::endl;
			}
			else {
				std::cout << nullable.value() << std::endl;
			}
		}
	}
}


Measured memory_bytes: 4352
//#include <boost/multiprecision/cpp_dec_float.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
#include <bitset>
#include <iomanip>
using namespace std;
//namespace mp = boost::multiprecision;
//using llll = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
//using Real = mp::number<mp::cpp_dec_float<1024>>;
using ll = long long;
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);

int main(){
  //cout<<fixed<<setprecision(10);
  ll n,ans=0;
  set<ll>st;
  ll z;
  cin>>n;
  for(ll i=0;i<n;i++){
    cin>>z;
    st.insert(z);
  }
  if(st.size()==n)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}


Measured memory_bytes: 9600
x, y, _, _, _ = gets.split.map(&:to_i)
p = gets.split.map(&:to_i).sort.reverse
q = gets.split.map(&:to_i).sort.reverse
r = gets.split.map(&:to_i).sort.reverse

pp = p[0...x]
qq = q[0...y]
ans = pp.inject(:+) + qq.inject(:+)
r.each_with_index do |rr, i|
    break if i >= x + y
    if pp.size == 0
        pp = [10 ** 9]
    end
    if qq.size == 0
        qq = [10 ** 9]
    end
    if pp[-1] > qq[-1]
        if rr > qq[-1]
            ans += rr - qq[-1]
            qq.pop
        else
            break
        end
    else
        if rr > pp[-1]
            ans += rr - pp[-1]
            pp.pop
        else
            break
        end
    end
end

puts ans

Measured memory_bytes: 25440
#include<bits/stdc++.h>
#define PI 2.0*acos(0.0)
#define ll              long long int
#define gcd(a,b)        __gcd(a,b)
#define lcm(a,b)        ((a)*(b))/gcd(a,b)
#define MOD             1000000007
#define mx              123456789
using namespace std;
int main()
{
    ll n, k;
    cin>>n>>k;
    cout<<min(n%k, abs(n%k-k))<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits//stdc++.h>
using namespace std;
int in(void){int x;cin>>x;return x;}
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
#define ll long long int
long long int dx[4]={1,0,-1,0};
long long int dy[4]={0,1,0,-1};
int main() {
	int n;
	cin>>n;
	int x[n];
	int max=0;
	int sum=0;
	rep(i,0,n){
		cin>>x[i];
		if(max<x[i])max=x[i];
		sum+=x[i];
	}
	if(sum-max>max)cout<<"Yes";
	else cout<<"No";
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <bitset>
using namespace std;
using ll = long long;

int main(){
        ll i,N,s=0;
        cin >> N;
        vector<ll> a(N);
        for(i=0;i<N;++i){
                cin >> a.at(i);
                s ^= a.at(i);
        }
        for(i=0;i<N;++i) cout << (ll)(s^a.at(i)) << " ";
        cout << endl;
        return 0;
}

Measured memory_bytes: 4824
#include <iostream>
#include <cstring>
 
using namespace std;
 
#define DELICIOUS 100
#define DONUTS DELICIOUS
 
int D, O, N, U, T, S;
 
int e[110], c[110], h[110], a[110];
 
int dp1[110][110], dp2[10010], dp3[110][110];
 
int main() {
    cin >> S >> T >> U >> N >> O >> D;
     
    for (int i=0; i<T; i++) cin >> e[i] >> c[i];
    for (int i=0; i<N; i++) cin >> h[i] >> a[i];
     
    memset(dp1, -1, sizeof(dp1));
    dp1[0][0] = 0;
    for (int i=0; i<T; i++) {
        for (int j=i; j>=0; j--) {
            for (int k=0; k<=S; k++) {
                if (dp1[j][k] < 0) continue;
                if (k+e[i]<= S) dp1[j+1][k+e[i]] = max(dp1[j+1][k+e[i]], dp1[j][k] + c[i]);
            }
        }
    }
     
    memset(dp2, 0, sizeof(dp2));
    for (int i=0; i<N; i++) {
        for (int j=0; j<=DONUTS * U; j++) {
            if (j + a[i] <= DONUTS * U) dp2[j + a[i]] = max(dp2[j + a[i]], dp2[j] + h[i]);
        }
    }
     
    memset(dp3, -1, sizeof(dp3));
    dp3[0][S] = 0;
    for (int i=0; i<D; i++) {
        for (int j=0; j<=S; j++) {
            if (dp3[i][j] < 0) continue;
            for (int k=0; k<=j; k++) {
                if (dp1[U][k] < 0) continue;
                int nxj = min(j-k+O, S);
                dp3[i+1][nxj] = max(dp3[i+1][nxj], dp3[i][j] + dp2[ dp1[U][k] ]);
            }
        }
    }
     
    int ans = -1;
    for (int i=0; i<=S; i++) ans = max(ans, dp3[D][i]);
    cout << ans << endl;
     
    return 0;
}

Measured memory_bytes: 1308
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
const int INF=0x3f3f3f3f,maxn=1e5+5;
int n,m;
struct work
{
    int day,money;
}p[maxn];
bool cmp(work u,work v)
{
    return u.day<v.day;
}
int main()
{
	int i,j,k,ans=0;
	cin>>n>>m;
	for(i=0;i<n;i++)
       cin>>p[i].day>>p[i].money;
   	sort(p,p+n,cmp);
	priority_queue<int>que;
    int pos=0;
    for(i=1;i<=m;i++)
    {
        while(p[pos].day<=i&&pos<n)
            que.push(p[pos++].money);
        if(!que.empty())
            ans+=que.top(),que.pop();
	}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1660
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    X, A, B = map(int, readline().split())

    if B <= A:
        print('delicious')
    elif B <= A + X:
        print('safe')
    else:
        print('dangerous')

    return


if __name__ == '__main__':
    main()


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  vector<int> v(3);

  cin >> v[0] >> v[1] >> v[2];
  sort(v.begin(), v.end());

  cout << v[0] << " " << v[2] << endl;
}




Measured memory_bytes: 3168
//I_love_coding...
//I_will_win
//I_can_win
//I_must_win
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
/*
1)Substring : 
string s;
	cin>>s;
	string s1 = s.substr(1,4);
    cout<<s1<<"\n";

2)Vector-with-pairs : - 
 vector< pair <ll,ll> > v; 
   
    v.push_back( make_pair(x,y) );
    
    
    sort(v.begin(),v.end(),compare);
    
    cout<<v[i].first<<" "<<v[i].second<<"\n";
    
    bool compare(const pair<ll,ll>&p1, const pair<ll,ll>&p2)
{
    if(p1.first < p2.first) return true;
        if(p1.first == p2.first) return p1.second < p2.second;
        return false;
}



3)Binary-search-on-normal-vector :-
 
vector<ll> a1;
auto mg = upper_bound(a1.begin(),a1.end(),100);
auto kf = mg - a1.begin();
ll ram=kf;//returns__the index of number slightly greater than 100 in array/.
		  //cout<<ram<<"\n";
ll lol = a1[ram] ; 

4)Binary-Search-on-vectors-of-vectors....
///vector<vector<ll>> a1;
//a1[x].push_back(y); //RAM-RAM!!!!

auto mg = upper_bound(a1[i].begin(),a1[i].end(),100);
		  auto kf = mg - a1[i].begin();
		  ll ram=kf;
		  //cout<<ram<<"\n";
		  ll lol = a1[i][ram] ; //returns__the index of number slightly greater than 100 in array"i"/.
		  //cout<<ram<<"\n";
5)Binary-exponentiation:-->
calculates : x^n%M
long long int me(long long int x,long long int n,long long int M)
{
 long long int result=1;
    while(n>0)
    {
        if(n%2==1)
            result=(result*x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}


calculates : (1/(a^b))%M;
ll modInverse(ll A,ll B,ll M)
{
    ll k=B*(M-2);
    return me(A,k,M);
}



6)Calculating factorial and inverse factorial : 
vector<ll> fact;
vector<ll> invfact;
void computefactorial(ll n,ll p)
{
    fact.resize(n+1); 
    invfact.resize(n+1);
    fact[0]=1;
    for(ll i=1;i<=n;i++)
    {
        fact[i]=i*fact[i-1];
        fact[i]%=p;
    }
    invfact[n]=modInverse(fact[n],1,p);
    for(ll i=n-1;i>=0;i--){
        invfact[i]=(i+1)*invfact[i+1];
        invfact[i]%=p;
    }
}

7)Computing nCr

ll nCr(ll n, ll r, ll p) 
{ 
return (  ((fact[n]*invfact[r])%p) * (invfact[n-r]%p) ) % p; 
}


8)Binary-format-of-the-given-number :- 



for (int i = 31; i >= 0; i--) 
{ 
        int k = n >> i; 
        if (k & 1) 
            cout << "1"; 
        else
            cout << "0"; 
} 


*/
int main()
{
	ios_base::sync_with_stdio(false) ; 
	cin.tie(NULL);
        cout.tie(NULL);
        ll x;
        cin>>x;
        map<ll,pair<ll,ll>> a1;
        	ll i=-500;
        	while(i<=500)
        	{
        		
        		ll x=i*i*i*i*i;
        	
        			//cout<<x;
        		//cout<<"\n";
        		ll j=-500;
        		while(j<=500)
        		{
        	ll y = j*j*j*j*j;		
        			
        	ll gm = x - y ; 
        	
        	
        			if(gm>=1)
        			{pair<ll,ll> ram ;
        			ram.first = i ;
        			ram.second = j ;
        				a1[gm]=ram ;
        				
        			}
        			
        			j++;
        		}
        		
        		i++;
        	}
        		
       pair<ll,ll> seeta ; 
       seeta=a1[x];
       cout<<seeta.first<<" "<<seeta.second ;  				
	return 0;
}

/*

31250000000000

*/

Measured memory_bytes: 19312
al = ["a","b","c","d","e","f","g","h","i","j","k","l","m", "n","o","p","q","r","s","t","u","v","w","x","y","z"]
N = int(input())
ans = ""
i = 0
while N > 0:
    r = N%26
    if r == 0:
        r = 26
    ans = al[r-1] + ans
    N = int((N - r) / 26)
print(ans)

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

using namespace std;


int main(){
	
	string s;
	
	cin >> s;
	
	string ans = "";  
	
	
	for(int i=0;i<s.size();i++){
		
		if(s[i]=='1') ans+='9';
		if(s[i]=='9') ans+='1';
	}
	
	cout << ans << endl;

	
    return 0;
}


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

int main()
{
    string line;
    cin >> line;

    int mask_size = line.size() - 1;
    ll total_sum = 0;

    for (ll mask=0; mask < (1 << mask_size); ++mask) {
        ll formula_sum = 0;

        int last_split = 0;
        for (int st=0; st<mask_size; ++st) {
            if ((mask & (1 << st)) != 0) {
                ll partial_val = stoll(line.substr(last_split, 1+st-last_split));
                formula_sum += partial_val;
                last_split = st + 1;
            }
        }

        ll partial_val = stoll(line.substr(last_split, line.size() - last_split));
        formula_sum += partial_val;
        total_sum += formula_sum;
    }
    cout << total_sum << endl;
}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    a = [int(input()) for _ in range(n)]
    b = sorted(a)
    res = b[-1]
    if b[-2] == res:
        for _ in range(n):
            print(res)
    else:
        for i in a:
            if i==res:
                print(b[-2])
            else:
                print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 14468
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000


struct unionfind{
	vector<int> data;
	vector<int> size;
	unionfind(int n){
		for(int i=0;i<n;i++){
			data.push_back(i);
			size.push_back(1);
		}
	}
	
	int find(int x){
		if(data[x]==x)return x;
		return data[x]=find(data[x]);
	}
	
	bool unite(int x,int y){
		x=find(x);y=find(y);
		if(x==y)return false;
		if(size[x]>size[y])swap(x,y);
		data[x]=y;
		size[y]+=size[x];
		return true;
	}
	
	bool check(int x,int y){
		return (find(x)==find(y));
	}
	
	int get_size(int x){
		int X = find(x);
		return size[X];
	}
};


int main(){
	
	int N;
	cin>>N;
	vector<int> cnt(1000001,0);
	vector<int> A(N);
	
	for(int i=0;i<N;i++){
		scanf("%d",&A[i]);
		cnt[A[i]]++;
	}
	
	bool f = true;
	for(int i=2;i<=1000000;i++){
		int c = 0;
		for(int j=i;j<=1000000;j+=i){
			c+=cnt[j];
		}
		if(c>=2){
			f=false;
			break;
		}
	}
	
	if(f){
		cout<<"pairwise coprime"<<endl;
		return 0;
	}
	
	
	int g = A[0];
	for(int i=0;i<N;i++){
		g = gcd(g,A[i]);
	}
	
	if(g==1)cout<<"setwise coprime"<<endl;
	else cout<<"not coprime"<<endl;
	
	return 0;
}


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

int main()
{

    int x, n;
    cin >> x >> n;
    if (n == 0)
    {
        cout << x << endl;
        return 0;
    }
    vector<int> p(n);

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

    vector<bool> b(101, true);

    for (int i = 0; i < n; ++i)
    {
        b[p[i]] = false;
    }

    int sub = 110000;
    int ans = 10000;

    for (int i = -1; i <= 200; ++i)
    {
        // cout << i << " " << b[i] << endl;
        if (i <= 0  ||101<=i || b[i])
        {
            int ab = abs(x - i);

            if (ab == sub)
            {
                if (i < ans)
                {
                    ans = i;
                    //              sub = ab;
                }
            }
            else if (ab < sub)
            {
                ans = i;
                sub = ab;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3592
parseInt(x) = parse(Int,x)
parseMap(x::Array{SubString{String}, 1}) = map(parseInt, x)
function main()
  a,b,c = map(parseInt, split(readline()))
  if a+b <c-1
    println(Int64(b + a+b+1))
  else
    println(Int64(b + c))
  end
end
main()

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

int main(){
  string S;
  cin>>S;
  int out=0;
  if(S[0]!='A')out++;
  if((int)S[1]<97||(int)S[1]>122)out++;
  int c=0;
  for(int i=2;i<S.size()-1;i++){
    if(S[i]=='C')c++;
    else if((int)S[i]<97||(int)S[i]>122)out++;
  }
  if((int)S[S.size()-1]<97||(int)S[S.size()-1]>122)out++;
  if(c!=1||out)cout<<"WA"<<endl;
  else cout<<"AC"<<endl;
}


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

using namespace std;
using ll = long long;

int main(){
    ll X,Y;
    cin >> X >> Y;

    ll lim = Y/X;
    int num = 0;
    while(lim > 0){
        lim /= 2;
        num++;
    }
    cout << num << endl;
}

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

int culc (int x, int y, int z) {
    int n = x * x + y * y + z * z + x * y + y * z + z * x;
    return n;
}

int main() {
    int N;
    cin >> N;
    vector<int> ans(100100);

    rep(x, 100) {
        rep(y, 100) {
            rep(z, 100) {
                int add = culc(x, y, z);
                ans[add - 1] += 1;
            }
        }
    }

    for(int i = 0; i < N; i++) cout << ans[i] << endl;
}

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

int main() {
  int h, w;
  cin >> h >> w;
  vector <string> s(h + 2, "");
  for (int i = 0; i <= w + 1; i++) {
	  s[0]     += '#';
	  s[h + 1] += '#';
	}
  for (int i = 1; i <= h; i++) {
	  cin >> s[i];
	  s[i] = '#' + s[i] + '#';
	}
  vector <vector <int> > r1(h + 2, vector <int>(w + 2, 0));
  vector <vector <int> > r2(h + 2, vector <int>(w + 2, 0));
  vector <vector <int> > c1(h + 2, vector <int>(w + 2, 0));
  vector <vector <int> > c2(h + 2, vector <int>(w + 2, 0));
  for (int i = 1; i <= h; i++) {
	  for (int j = 1; j <= w; j++) {
		  if (s[i][j] == '#') {
			  r1[i][j] = 0;
			  c1[i][j] = 0;
			} else {
			  r1[i][j] = r1[i][j - 1] + 1;
			  c1[i][j] = c1[i - 1][j] + 1;
			}
		}
	}
  for (int i = h; i >= 1; i--) {
	  for (int j = w; j >= 1; j--) {
		  if (s[i][j] == '#') {
			  r2[i][j] = 0;
			  c2[i][j] = 0;
			} else {
			  r2[i][j] = r2[i][j + 1] + 1;
			  c2[i][j] = c2[i + 1][j] + 1;
			}
		}
	}
  int ans = 0;
  for (int i = 1; i <= h; i++) {
	  for (int j = 1; j <= w; j++) {
		  ans = max(ans, r1[i][j] + r2[i][j] + c1[i][j] + c2[i][j] - 3);
		}
	}
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 71040
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;
using System.Runtime.InteropServices.ComTypes;
using System.Xml.Schema;
using System.ComponentModel.DataAnnotations;
using System.Security.Cryptography;
using System.Drawing;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var (M, K) = Slice2<long>();
            var upper = (int)Pow(2, M);
            if (upper <= K)
            {
                WriteLine(-1);
                return;
            }
            if (M == 1)
            {
                if (K == 0)
                    WriteLine("0 0 1 1");
                else
                    WriteLine(-1);
                return;
            }
            var nums = new List<long>((int)upper);
            for (var i = 0; i < upper; ++i)
                if (i != K) nums.Add(i);
            Write($"{K} ");
            foreach (var n in nums)
                Write($"{n} ");
            Write($"{K} ");
            nums.Reverse();
            foreach (var n in nums)
                Write($"{n} ");
        }

        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
        static public (T a, T b, T c, T d) Slice4<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)),
            (T)Convert.ChangeType(t[3], typeof(T)));
        }
    }
}

Measured memory_bytes: 45424
sub gcd {
    my($a, $b) = @_;
    ($a > $b) and ($a, $b) = ($b, $a);

    while ($a) {
        ($a, $b) = ($b % $a, $a);
    }
    return $b;
}
chomp($_=<>);
($a, $b, $c) = split(' ');
$d = gcd($a, $b);
if (gcd($d, $c) == $d || $d == 0) {
    print "YES\n";
} else {
    print "NO\n";
}


Measured memory_bytes: 512
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;

public class Main {

	static PrintWriter out;
	static InputReader ir;

	static void solve() {
		out.println((int)Math.max(ir.nextInt()*ir.nextInt(),ir.nextInt()*ir.nextInt()));
	}

	public static void main(String[] args) throws Exception {
		ir = new InputReader(System.in);
		out = new PrintWriter(System.out);
		solve();
		out.flush();
	}

	static class InputReader {

		private InputStream in;
		private byte[] buffer = new byte[1024];
		private int curbuf;
		private int lenbuf;

		public InputReader(InputStream in) {
			this.in = in;
			this.curbuf = this.lenbuf = 0;
		}

		public boolean hasNextByte() {
			if (curbuf >= lenbuf) {
				curbuf = 0;
				try {
					lenbuf = in.read(buffer);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return false;
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[curbuf++];
			else
				return -1;
		}

		private boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		private void skip() {
			while (hasNextByte() && isSpaceChar(buffer[curbuf]))
				curbuf++;
		}

		public boolean hasNext() {
			skip();
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (!isSpaceChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public int nextInt() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public char[][] nextCharMap(int n, int m) {
			char[][] map = new char[n][m];
			for (int i = 0; i < n; i++)
				map[i] = next().toCharArray();
			return map;
		}
	}
}

Measured memory_bytes: 21460
N = gets.to_i
count = 0

(1..N).each { |a|
  (1..N).each { |b|
    break if a*b > N 
    c = N-(a*b)
    next if c < 1
    if a*b+c == N
#      puts "a:#{a} b:#{b} c:#{c}"
      count += 1
    end
  }
}

puts count
    
  



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

int main() {
    string S, T;
    int q;
    cin >> S >> T >> q;
    int s[100010], r[100010];
    s[0]=r[0]=0;
    for(int i=0; i<S.size(); ++i) s[i+1]=s[i]+(S[i]=='A' ? 1 : 2);
    for(int i=0; i<T.size(); ++i) r[i+1]=r[i]+(T[i]=='A' ? 1 : 2);
    for(int t=0; t<q; ++t){
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        cout << ((s[b]-s[a-1]-r[d]+r[c-1])%3==0 ? "YES" : "NO") << endl;
    }
	return 0;
}


Measured memory_bytes: 1792
def getN():
    return int(input())


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


def getList():
    return list(map(int, input().split()))


from collections import defaultdict, deque, Counter
from sys import exit
import math
import copy
from bisect import bisect_left, bisect_right
from heapq import *
import sys

# sys.setrecursionlimit(1000000)
INF = 10 ** 17
MOD = 1000000007

from fractions import *


def inverse(f):
    # return Fraction(f.denominator,f.numerator)
    return 1 / f


def combmod(n, k, mod=MOD):
    ret = 1
    for i in range(n - k + 1, n + 1):
        ret *= i
        ret %= mod

    for i in range(1, k + 1):
        ret *= pow(i, mod - 2, mod)
        ret %= mod

    return ret

MOD = 10 ** 9 + 7
class WeightedUnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        # 根への距離を管理
        self.weight = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            y = self.find(self.par[x])
            # 親への重みを追加しながら根まで走査
            self.weight[x] += self.weight[self.par[x]]
            self.par[x] = y
            return y

    # 併合
    def union(self, x, y, w):
        rx = self.find(x)
        ry = self.find(y)
        # xの木の高さ < yの木の高さ
        if self.rank[rx] < self.rank[ry]:
            self.par[rx] = ry
            self.weight[rx] = w - self.weight[x] + self.weight[y]
        # xの木の高さ ≧ yの木の高さ
        else:
            self.par[ry] = rx
            self.weight[ry] = -w - self.weight[y] + self.weight[x]
            # 木の高さが同じだった場合の処理
            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1

    # 同じ集合に属するか
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # xからyへのコスト
    def diff(self, x, y):
        return self.weight[x] - self.weight[y]
def solve():
    n, m = getList()
    uf = WeightedUnionFind(n+1)
    for i in range(m):
        l, r, d = getList()
        if uf.same(l, r):
            if abs(uf.weight[l] - uf.weight[r]) != d:
                print("No")
                return
        else:
            uf.union(l, r, d)
    print("Yes")
def main():
    n = getN()
    for _ in range(n):
        solve()


if __name__ == "__main__":
    solve()

Measured memory_bytes: 124444
a,b=map(int,input().split())

def yaku(n):
  l=[]
  m=n
  for i in range(1,int((n)**(1/2))+1):
    if m%i==0:
      l.append(i)
      if m//i!=i:
        l.append(m//i)
  return l

def gcd(n,m):
  a=max(n,m)
  b=min(n,m)
  while b!=0:
    a,b=b,a%b
  return a

def prime(n):
  for i in range(2,int((n)**(1/2))+1):
    if n%i==0:
      return False
  return True

num=gcd(a,b)

l0=yaku(num)

num1=max(l0)

cd=yaku(num1)

pr=[]

for i in cd:
  if i==1:
    pr.append(i)
  else:
    if prime(i):
      pr.append(i)

print(len(pr))

Measured memory_bytes: 3500
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
using namespace __gnu_pbds;
typedef tree<pair<ll,pair<ll,ll> >, null_type, less<pair<ll,pair<ll,ll> > >, rb_tree_tag, tree_order_statistics_node_update>ordered_set;
#define me BOSS
#define bug() cout<<"AIkahne aise"<<endl
#define PI acos(-1)
/* Precode Start Here *\
     Sieve
void sieve()
{
    for(ll i=3; i<=2000; i+=2)
    {
        for(ll j=i*i; j<=4000000; j+=i)
            A[j]=1;
    }
    v.push_back(2);
    for(ll i=3; i<=4000000; i+=2)
        if(A[i]==0)
            v.push_back(i);
}

     Power Function Modulo P

ll modPow(ll a, ll x, ll p) {
    //calculates a^x mod p in logarithmic time.
    long res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}


   factorial

ll fact(ll n)
{
    ll ans=1;
    for(ll i=1;i<=n;i++)
    {
        ans=(ans*i)%mod;
    }
    return ans;
}
     Calculating nCr using Fermats law Theorem

ll modInverse(ll a, ll p) {
    //calculates the modular multiplicative of a mod m.
    //(assuming p is prime).
    return modPow(a, p-2, p);
}


ll modBinomial(ll n, ll k, ll p) {
// calculates C(n,k) mod p (assuming p is prime).

    ll numerator = 1; // n * (n-1) * ... * (n-k+1)
    for (ll i=0; i<k; i++) {
        numerator = (numerator * (n-i) ) % p;
    }

    ll denominator = 1; // k!
    for (ll i=1; i<=k; i++) {
        denominator = (denominator * i) % p;
    }

    // numerator / denominator mod p.
    return ( numerator* modInverse(denominator,p) ) % p;
}
     num of divisor and euler totient

ll phi[1000001],mark[1000001],divi[1000001];;
void divisorPhi(ll n)
{
    for(int i=1;i<=n;i++)
        phi[i]=i;
    for(int i=2;i<=n;i++)
    {
        if(!mark[i])
        {
            for(int j=i;j<=n;j+=i)
            {
                mark[j]=1;
                phi[j]*=(1-1/(double)i);
            }
        }
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=i;j<=n;j+=i)
            divi[j]++;
    }
}
/* Precode Ends */
#define mod 1000000007
ll A[5000001],B[5000001];
vector<ll>v;
map<ll,ll>myMap;
set<ll>mySet;
vector<pair<ll,ll> >vp;
priority_queue<ll> pq;
priority_queue<ll, vector<ll>, std::greater<ll> > first;
ll po(ll a,ll n)
{
    ll ans=1;
    for(int i=1; i<=n; i++)
        ans*=a;
    return ans;
}

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

    ll n,sum=0,ans=0;
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>A[i];
        sum+=A[i];
    }
    sum%=mod;
    for(int i=1; i<n; i++)
    {
        sum=(sum-A[i]+mod)%mod;
        ans+=(sum*A[i])%mod;
        ans%=mod;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 5148