akhauriyash/Code-Regression huggingface dataset:
# https://atcoder.jp/contests/abc063/submissions/5323989 参照

def func(idx, points, N, lst_s, dp):
    # base case
    if idx == N:
        if points % 10 == 0:
            return 0
        else:
            return points
    
    # check memo
    ref = dp.get((idx, points))
    if ref is not None:
        return dp[(idx, points)]
    
    # recursive
    f1 = func(idx + 1, points, N, lst_s, dp)
    f2 = func(idx + 1, points + lst_s[idx], N, lst_s, dp)
    ret = max(f1, f2)
    dp[(idx, points)] = ret

    return ret


N = int(input())
lst_s = [int(input()) for _ in range(N)]
dp = {}
ans = func(0, 0, N, lst_s, dp)
print(ans)

Measured memory_bytes: 47564
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<cctype>
#define P putchar
#define F(a,b) for(register int (a)(0);(a)<=(b);(a)++)
using namespace std;
int n,m;
inline void PF()
{
	P('-'),P(49),P(32),P('-'),P(49),P(32),P('-'),P(49);
	return;
}
signed main()
{
	scanf("%d%d",&n,&m);
	if(((n*10000)<m)||((n*1000)>m)||(m%1000)){PF();goto endreturn;};
	F(i,n){F(j,n){for(register int k(0);k<=n,(i+j+k)<=n;k++){if((!((i+j+k)-n))&&(!((((i*1000)+(j*5000)+(k*10000))-m)))){printf("%d %d %d",k,j,i);goto endreturn;}}}}
	PF();
	endreturn:return putchar(10),0;
}

Measured memory_bytes: 384
import java.util.Scanner;




public class Main {

    public static void main(String[] args) {

    	Main main=new Main();

    	main.run();

    }

    void run() {
    	Scanner sc=new Scanner(System.in);

    	int A=sc.nextInt();
    	int B=sc.nextInt();

    	int K=sc.nextInt();

    	for(int i=A;i<=Math.min(A+K-1, B);i++) {
    		System.out.println(i);
    	}

    	for(int i=(Math.max(A+K,B-K+1));i<=B;i++) {
    		System.out.println(i);
    	}



    }



}



Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int n;
int a[107];
int Max=0,Min=1000,MIN=1000000000;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		Max=max(Max,a[i]);
		Min=min(Min,a[i]);
	}
	for(int i=Min;i<=Max;i++)
	{
		int sum=0;
		for(int j=0;j<n;j++)
		{
			sum+=(a[j]-i)*(a[j]-i);
		}
		MIN=min(MIN,sum);
	}
	cout<<MIN;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>
#include<deque>
#include<queue>

using std::cout;
using std::cin;
using std::setw;
using std::setfill;
using std::string;
using std::pair;
using std::vector;
using std::queue;
using std::deque;
using std::priority_queue;
using std::next_permutation;
//using std::iota;
using std::sort;
using std::greater;
using std::max;
using std::min;

using lli = long long int;
using ulli = unsigned long long int;

#define INF 999999999;

//#define EVEL 1

#ifndef EVEL
#define dbug(X) std::cout << #X << ":" <<X<<" " ;
#define dbugf(s) std::cout << s << " ";
#define dbugln std::cout<<"\n";
#else
#define dbug(X) {}
#define dbugf(s) {}
#define dbugln {}
#endif

lli H, W;
lli map[50][50];
char in;

int main(){
	cin.tie(0);
	std::ios::sync_with_stdio(false);
	cin >> H >> W;
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
				cin >> in;
				if(in == '.') map[i][j] = 0;
				else map[i][j] = -1;
			}
	}

	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			for(int k = -1; k < 2; k++){
				for(int l = -1; l < 2; l++){
					if(map[i][j] >= 0 && 0 <= i+k && i+k < H && 0 <= j+l && j+l < W){
						if(map[i+k][j+l] < 0) map[i][j]++;
					}
				}
			}
		}
	}

	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			if(map[i][j] >= 0) cout << map[i][j];
			else cout << "#";
		}
		cout << "\n";
	}
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        int[] n = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        Console.WriteLine(
            n[0] % 3 == 0 ||
            n[1] % 3 == 0 ||
            (n[0] + n[1]) % 3 == 0 ?
            "Possible" : "Impossible");
    }
}


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

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


Measured memory_bytes: 256
import Foundation

class Scanner {
    static func readInt() -> Int {
        return Int(readLine()!)!
    }
    
    static func readIntArr() -> [Int] {
        return readLine()!.split(separator: " ").map { Int($0)! }
    }
    
    static func readM(_ n: Int) -> [[Int]] {
        var res = [[Int]]()
        for _ in 0..<n {
            res.append(readIntArr())
        }
        return res
    }
    
    static func readUknownIntMat() -> [[Int]] {
        var res = [[Int]]()
        while let line = readLine() {
            res.append(line.split(separator: " ").map { Int($0)! })
        }
        return res
    }
    
    static func readString() -> String {
        return readLine()!
    }
}

class Printer {
    static func printIntArray(_ arr: [Int]) {
        print(arr.map { String($0) }.joined(separator: " "))
    }
}

class Solution {
    func minSwaps(_ str: String) -> Int {
        var res = 0, left = 0, right = str.count-1
        let str = Array(str)
        
        //WRWWRWRR
        while left<right {
            while left < right && str[left] != "W"  {
                left += 1
            }
            while right > left && str[right] != "R" {
                right -= 1
            }
            if str[left] == "W" && str[right] == "R" {
                res += 1
            }
            left += 1
            right -= 1
        }
        return res
    }
}


let n = Scanner.readInt()
let str = Scanner.readString()
print(Solution().minSwaps(str))


Measured memory_bytes: 15540
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        if ( m == n - 1) {
            System.out.println(0);
            return;
        }
        if (n < 2 * (n - m - 1)) {
            System.out.println("Impossible");
            return;
        }
        int[] weights = new int[n];
        ArrayList<LinkedList<Integer>> forest = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            weights[i] = sc.nextInt();
            forest.add(new LinkedList<Integer>());
        }
        for (int i = 0; i < m; i++) {
            int x = sc.nextInt();
            int y = sc.nextInt();
            forest.get(x).add(y);
            forest.get(y).add(x);
        }
        // DFS to find connected components
        long ans = 0;
        int count = 0;
        boolean[] visited = new boolean[n];
        PriorityQueue<Integer> remainCosts = new PriorityQueue<>();
        for (int i = 0; i < n; i++) {
            if (!visited[i]){
                List<Integer> costs = new ArrayList<>();
                Stack<Integer> stack = new Stack<Integer>();
                stack.push(i);
                while (!stack.isEmpty()) {
                    int vertex = stack.pop();
                    visited[vertex] = true;
                    costs.add(weights[vertex]);
                    LinkedList<Integer> edges = forest.get(vertex);
                    for (int edge : edges) {
                        if (!visited[edge]) {
                            stack.push(edge);
                        }
                    }
                }
                Collections.sort(costs);
                ans += costs.get(0);
                count++;
                for (int j = 1; j < costs.size(); j++) {
                    remainCosts.add(costs.get(j));
                }
            }
        }
        for (int i = count; i < 2 * (n - m - 1); i++) {
            ans += remainCosts.poll();
        }
        System.out.println(ans);
    }
}


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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double
# define ull unsigned long long

# define pb push_back
# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vld vector < ld >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < long , long >
# define pDD pair < D , D >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);
# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b));
# define mod 1000000007

# define pp(n) printf("%.10f",n);
# define line cout<<"\n";

const D pie = acos(-1);
const D hpie = asin(1);
const D qpie = atan2(1,1);
const D tpie = 2*pie;

string vow = "aeiou";

void solve( int test_case )
{
    int n,a,b;
    cin >> n >> a >> b;

    n*=a;
    cout << min(n,b);
    line
}

int main()
{

    int t = 1;
    //cin>>t;

    for ( int i=0 ; i<t ; i++ ) solve(i);
    return 0;
}


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

int main(){
	int a, b, c, o;
	cin >> a >> b >> c;
	if(b < a){
		o = a;
		a = b;
		b = o;
	}
	if(c < b){
		o = b;
		b = c;
		c = o;
	}
	if(b < a){
		o = a;
		a = b;
		b = o;
	}
	cout << a << " " << b << " " << c << endl;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int a,b;
    cin >> a >> b;
  	cout << (a+b+1)/2;
}

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




int main(){
    int n;
    cin>>n;
    ll a[220000];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int right=0;//[left,right)を調べるしゃくとり法
    ll ans=0;
    ll sum=0;
    //ll xsum=0;
    for(int left=0;left<n;left++){
        while(right<n&&((sum^a[right])==(sum+a[right]))){
            sum+=a[right];
            right++;
        }
        ans+=right-left;
        if (left == right) ++right;
        else {
            sum -= a[left]; // a[left] を削除 (sum ^= a[left] でも OK)
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

map<ll, ll> prime_factorization(ll n){
  map<ll, ll> ans;
  ll a = 2;
  while(n >= a*a){
    if(n % a == 0){
      ans[a]++;
      n /= a;
    }else{
      a++;
    }
  }
  ans[n]++;

  return ans;
}

int main(){
  int n;
  cin >> n;
  map<ll, ll> pr;
  rep2(i, 2, n+1){
    auto m = prime_factorization(i);
    for(auto p : m){
      pr[p.first] += p.second;
    }
  }
  // for(auto p : pr){
  //   cerr << p.first << " " << p.second << endl;
  // }
  vector<int> pn(5, 0);
  for(auto p : pr){
    if(p.second >= 74) pn.at(4)++;
    else if(p.second >= 24) pn.at(3)++;
    else if(p.second >= 14) pn.at(2)++;
    else if(p.second >= 4) pn.at(1)++;
    else if(p.second >= 2) pn.at(0)++;
  }
  rrep(i, 4) pn.at(i) += pn.at(i+1);
  // rep(i, 4) cerr << pn.at(i) << " ";
  // cerr << endl;
  int ans = 0;
  ans += pn.at(1) * (pn.at(1)-1) * (pn.at(0)-2)/2;
  ans += pn.at(3) * (pn.at(0) - 1);
  ans += pn.at(2) * (pn.at(1) - 1);
  ans += pn.at(4);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import qualified Data.Vector.Unboxed as V
import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.Maybe

main = do
  (_, k) <- readIntPair
  ps <- readIntList
  print . sum . take k . sort $ ps

getInt :: IO Int
getInt = readLn

second :: (b -> c) -> (a, b) -> (a, c)
second f (a, b) = (a, f b)

readInt :: BS.ByteString -> Maybe (Int, BS.ByteString)
readInt = fmap (second BS.tail) . BS.readInt

readIntVec :: Int -> IO (V.Vector Int)
readIntVec n = V.unfoldrN n readInt <$> BS.getLine

readIntList :: IO [Int]
readIntList = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readIntPair :: IO (Int, Int)
readIntPair = do
  v <- readIntVec 2
  return (v V.! 0, v V.! 1)


Measured memory_bytes: 4584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct Node
{
    int v;
    ll cost;
};
static const int MAXN = 1e5 + 10;
static const ll OO = 1e15;
vector<Node> s[MAXN];
ll dis[MAXN];
bool vis[MAXN];
struct buf
{
	operator int()
	{
		int x = 0 , y = 0 , c = getchar();
		while(c < 48)
			y = c == 45 , c = getchar();
		while(c > 47)
			x = (x << 1) + (x << 3) + (c - 48) , c = getchar();
		return y ? -x : x;
	}
}read;
void Init()
{
    for(int i = 0 ; i < MAXN ; ++i)
    {
        dis[i] = OO;
    }
}
struct cmp
{
    bool operator () (Node a , Node b)
    {
        return a.cost > b.cost; ///small top
    }
};

void Dijkstra(int st , int ed)
{
    priority_queue <Node , vector <Node> , cmp> qu;
    dis[st] = 0;
    Node ac;
    ac.v = st;
    ac.cost = 0;
    qu.push(ac);
    while(!qu.empty())
    {
        ac = qu.top();
        qu.pop();
        int u = ac.v;
        vis[u] = 1;
        ll uc = ac.cost;
        if(dis[u] < uc)
        {
            continue;
        }
        int si = s[u].size();
        for(int i = 0 ; i < si ; ++i)
        {
            int v = s[u][i].v;
            ll co = s[u][i].cost;
            if(dis[v] > dis[u] + co)
            {
                Node temp;
                dis[v] = dis[u] + co;
                temp.v = v;
                temp.cost = dis[v];
                qu.push(temp);
            }
        }
    }
}
int main()
{
    Init();
    int n;
    scanf("%d" , &n);
    for(int i = 1 ; i < n ; ++i)
    {
        int a , b;
        int c;
        a = read;b=read;c=read;
        s[a].push_back({b , c});
        s[b].push_back({a , c});
    }
    int q , k;
    scanf("%d%d" , &q , &k);
    for(int i = 1 ; i <= n ; ++i)
    {
        if(k == i || vis[i])
            continue;
        Dijkstra(k , i);
    }
    while(q--)
    {
        int a , b;
        scanf("%d%d" , &a , &b);
        printf("%lld\n" , dis[a] + dis[b]);
    }
}


Measured memory_bytes: 11120
//
// Created by kota_ on 2020/01/06.
//
#include <stdio.h>
#include <stdlib.h>

void maxHeapify(int *A, int H, int i);
int left(int i);
int right(int i);
void buildMaxHeap(int *A, int H);

int main(){
    int i, H, *A;
    scanf("%d", &H);
    A = malloc(sizeof(int) * H);
    for(i = 0; i < H; i++){
        scanf("%d", &A[i]);
    }
    buildMaxHeap(A, H);
    for(i = 0; i < H; i++){
        printf(" %d", A[i]);
    }
    printf("\n");
    free(A);
    return 0;
}

int left(int i){
    return 2 * i + 1;
}

int right(int i){
    return 2 * (i + 1) ;
}

void maxHeapify(int *A, int H, int i){
    int l, r, largest, tmp;
    l = left(i);
    r = right(i);
    if(l < H && A[l] > A[i]){
        largest = l;
    }
    else{
        largest = i;
    }
    if(r < H && A[r] > A[largest]){
        largest = r;
    }
    if(largest != i){
        tmp = A[i];
        A[i] = A[largest];
        A[largest] = tmp;
        maxHeapify(A, H, largest);
    }
}


void buildMaxHeap(int *A, int H) {
    int i;
    for(i = H / 2; i >= 0; i--){
        maxHeapify(A, H, i);
    }
}



Measured memory_bytes: 3340
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <algorithm>
#include <deque>
#include <cstdio>

#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)
typedef long long ll;

using namespace std;

int main(){
    deque<int> bs;
    int n;
    cin >> n;
    int r = (n - 1) % 2;
    rep(i, n){
        int a;
        cin >> a;
        if(i % 2 == r){
            bs.push_front(a);
        }else{
            bs.push_back(a);
        }
    }
    cout << bs[0];
    for(int i = 1; i < n; i++){
        cout << " " << bs[i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 2944
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

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

  int n, c, k;
  cin >> n >> c >> k;
  int t[n];
  for(int i = 0; i < n; i++){
    cin >> t[i];
  }

  sort(t, t + n);
  int i = 0;
  int count = 0;
  while(i < n){
    int j = distance(t + i, upper_bound(t + i, t + n, t[i] + k));
    i += min(c, j);
    ++count;
  }

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 640
(d,g),*a=$<.map{|s|s.split.map &:to_i};p (0...1<<d).map{|b|s=n=e=0;a.map{|p,c|e+=100;b&1>0?(n+=p;s+=p*e+c):(P=p;E=e);b/=2};P ? g-s<=P*E ? [0,(g-s-1)/E+1].max+n:1e4:n}.min

Measured memory_bytes: 2300
/**
 * 参考：https://qiita.com/ytanto/items/caf7bf0ba287da81b20f#%E7%AC%AC10%E5%95%8F-abc-086-c---traveling
 * input例
 * 2
 * 3 1 2
 * 6 1 1
 */
function main(input) {
	//配列に分割
	const args = input.split('\n');
	//0番目の回数を取得
	const N = parseInt(args[0], 10);
	//N以外の　連続数字の配列を取得
	const nums = args.slice(1, N + 1);//slice https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/slice
	//配列をメソッド内部で全てチェックできる
	const isValid = nums.every((n) => {//every https://qiita.com/i_am_master_yoda/items/224ff73443b4566ec8e8 
		//3文字をそれぞれに分割
        var ns = n.split(' ');
        var t = parseInt(ns[0], 10),
            x = parseInt(ns[1], 10),
			y = parseInt(ns[2], 10);
		//x,yの合計値を算出
        var sum = x + y;
		
		/**　チェック事項
		 * 1. 移動回数（t）がsum以上であるか→合計値の場合必ず到達できないため
		 * 2. 移動回数と合計値の偶奇が同じである事。
		 *	  → 条件1が満たせるという事は、たどり着けるという前提。
		 *		同じ場所に止まり続けるためには、行って戻ってくる必要があるため移動が偶数回必要になる。
		 * 　　 tが奇数=>最短での移動が奇数=>x + yは奇数  
		 * 　　 tが偶数=>最短での移動が偶数=>x + yは奇数 
		 * 			ex)5 1 2 の場合、最短で3回の移動で到達できる。残り移動回数が2であり、偶数なので行って戻ってくる事ができる
		 * 			ex)6 1 2 の場合、最短で3回の移動で到達できる。残り移動回数が3であり、奇数なので行って戻ってくる事ができない
		 * 		よって、 ((t % 2) === (sum % 2))の条件式となる
		 */
        return (t >= sum) && ((t % 2) === (sum % 2));
    });

    if (isValid) {
        console.log('Yes');
    } else {
        console.log('No');
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

#define ff first
#define ss second
#define endl '\n'

int k;
const ll MOD = 1e9 + 7;

const int MAX = 1e5;
vector<int> adj[MAX];
bool visited[MAX];

ll dfs (int root, bool is_child_of_root) {
	visited[root] = 1;
	ll ans = 1, factor = k - 2ll + is_child_of_root;

	for (int child : adj[root]) {
		if (!visited[child]) {
			ans = (ans * factor--) % MOD;
			ans = (ans * dfs(child, 0)) % MOD;
		}
	}

	return ans;
}

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

	int n;
	cin >> n >> k;

	for (int i = 0, u, v; i < n-1; ++i) {
		cin >> u >> v; --u; --v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	for (int root = 0; root < n; ++root) {
		if (adj[root].size() >= k) {
			cout << 0 << endl;
			return 0;
		}
	}

	ll ans = (k * dfs(0, 1)) % MOD;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 13808
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF (long long) 1e18//1234567890987654321
#define INF 1234567890l
#define pb push_back
#define ins insert
#define f first
#define s second	
#define db 0
#define EPS (1e-7)    //0.0000001 the value
#define PI (acos(-1))
#define MAXN 300006
#define MAXK 26
#define MAXX 15000006
#define ll long long int
#define ld long double
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
#define FOR(ii, ss, ee) for(ll ii = ss; ii < ee; ii++)
#define space " "
#define cbr cout << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define bg(ms) (*ms.begin())
#define ed(ms) (*prev(ms.end(), 1))
#define addedge(a, b, c, v) v[(a)].pb(pi((b), (c))); v[(b)].pb(pi((a), (c)))
#define ph push
#define btinpct(x) __builtin_popcountll(x)
#define p2(x) (1LL<<(x))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
ll n, m, ans;
struct ufds_
{
	ll p[MAXN], sz[MAXN];
	void init() { for(ll i = 1; i <= n; i++) p[i] = i,sz[i]=1; }
	void merge(ll x, ll y) { x=find(x),y=find(y); sz[y] += sz[x]; p[find(x)] = find(y); }
	ll find(ll x) { return (p[x] == x) ? x : p[x]=find(p[x]); }
	bool same(ll a, ll b) { return find(a) == find(b); }
} ufds;
ll f(ll x) { return x*(x-1)/2; }
pi edges[MAXN];
int main()
{
	FAST
	cin >> n >> m;
	FOR(i,0,m)
	{
		cin >> edges[i].f >> edges[i].s;
	}
	ufds.init(); vector <ll> anss;
	for(ll i = m-1; i >= 0; i--)
	{
		ll x = edges[i].f, y=edges[i].s;
		if(ufds.same(x,y)) { anss.pb(f(n)-ans);/*cout << f(n) - ans << "\n";*/ }
		else
		{
			// cout << f(n) - ans << "\n";
			anss.pb(f(n)-ans);
			ans += (ufds.sz[ufds.find(x)] * ufds.sz[ufds.find(y)]);
			ufds.merge(x,y);
			// cerr << "ans: " << ans << "\n";
		}
	}
	reverse(all(anss));
	for(auto i : anss) cout << i << "\n";
}


Measured memory_bytes: 7924
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)
#define EPS 10e-8
#define MAX_N 1000
#define MAX_N2 1000000

using namespace std;
typedef pair<int, int> ipair;
llong modulo(llong left, llong right) { return (left % right + right) % right; }

int N, A[MAX_N][MAX_N - 1];
vector<int> adj_list[MAX_N2];

int visited[MAX_N2];
int cur_time;

bool dfs(int node, vector<int> *out) {
    bool res = true;
    visited[node] = cur_time;

    for(int i = 0; i < adj_list[node].size(); ++i) {
        int next = adj_list[node][i];

        if(!visited[next])
            res &= dfs(next, out);
        else if(visited[next] == cur_time)
            return false;
    }

    out->push_back(node);
    visited[node] = 1;
    return res;
}

vector<int> tsort() {
    bool is_acyclic = true;
    vector<int> res;
    cur_time = 2;

    for(int i = 0; i < N; ++i)
        if(!visited[i]) {
            is_acyclic &= dfs(i, &res);
            ++cur_time;
        }

    if(is_acyclic) {
        //閉路なし=>トポロジカルソートの結果を返す
        reverse(res.begin(), res.end());
        return res;
    } else {
        //閉路あり=>空のvectorを返す
        return vector<int>();
    }
}

int longest[MAX_N2];
int longest_path(int node) {
    longest[node] = 1;

    for(int i = 0; i < adj_list[node].size(); ++i) {
        int next = adj_list[node][i];
        if(!longest[next])
            longest_path(next);
        longest[node] = max(longest[node], 1 + longest[next]);
    }
    return longest[node];
}

int solve() {
    for(int i = 0; i < N; ++i)
        for(int j = 0; j < N - 2; ++j) {
            int p1_g1 = min(i,  A[i][j] - 1);
            int p1_g2 = min(i,  A[i][j + 1] - 1);
            int p2_g1 = max(i,  A[i][j] - 1);
            int p2_g2 = max(i,  A[i][j + 1] - 1);

            if(p2_g1 > p1_g1) p2_g1--;
            if(p2_g2 > p1_g2) p2_g2--;

            adj_list[p1_g1 * (N - 1) + p2_g1].push_back(p1_g2 * (N - 1) + p2_g2);
        }

    bool is_acyclic = tsort().size() != 0;
    if(!is_acyclic) return -1;

    //日数=最長路を求める
    int res = 1;
    for(int i = 0; i < N * (N - 1); ++i)
        if(!longest[i])
            res = max(res, longest_path(i));

    return res;
}

int main() {
    cin >> N;
    for(int i = 0; i < N; ++i)
        for(int j = 0; j < N - 1; ++j)
            cin >> A[i][j];
    
    int res = solve();
    cout << res << endl;
}

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

// 1-indexed
template <class T, class E>
struct SegmentTreeLaze {
  // a,b:T c,d:E e:E(unit)
  // g(f(a,b),c) = f(g(a,c),g(b,c))
  // g(g(a,c),d) = g(a,h(c,d))
  // g(a,e) = a
  typedef function<T(T, T)> F;
  typedef function<T(T, E)> G;
  typedef function<E(E, E)> H;
  int n, height;
  F f;
  G g;
  H h;
  T tunit;
  E eunit;
  vector<T> dat;
  vector<E> laz;
  SegmentTreeLaze(){};
  SegmentTreeLaze(int newn, F f, G g, H h, T nt, E ne)
      : f(f), g(g), h(h), tunit(nt), eunit(ne) {
    init(newn);
  }
  void init(int newn) {
    n = 1, height = 0;
    while(n < newn) n <<= 1, ++height;
    dat.assign(n << 1, tunit);
    laz.assign(n << 1, eunit);
  }

  inline T reflect(int k) {
    return laz[k] == eunit ? dat[k] : g(dat[k], laz[k]);
  }

  inline void eval(int k) {
    if(laz[k] == eunit) return;
    laz[k << 1] = h(laz[k << 1], laz[k]);
    laz[(k << 1) | 1] = h(laz[(k << 1) | 1], laz[k]);
    dat[k] = reflect(k);
    laz[k] = eunit;
  }

  inline void thrust(int k) {
    for(int i = height; i; --i) eval(k >> i);
  }

  void recalc(int k) {
    while(k >>= 1)
      dat[k] = f(reflect(k << 1), reflect((k << 1) | 1));
  }
  // [a,b)
  void update(int a, int b, E newdata) {
    thrust(a += n);
    thrust(b += n - 1);
    for(int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
      if(l & 1) laz[l] = h(laz[l], newdata), l++;
      if(r & 1) --r, laz[r] = h(laz[r], newdata);
    }
    recalc(a);
    recalc(b);
  }

  void set_val(int k, T newdata) {
    thrust(k += n);
    dat[k] = newdata;
    laz[k] = eunit;
    recalc(k);
  }

  // [a,b)
  T query(int a, int b) {
    thrust(a += n);
    thrust(b += n - 1);
    T vl = tunit, vr = tunit;
    for(int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
      if(l & 1) vl = f(vl, reflect(l++));
      if(r & 1) vr = f(reflect(--r), vr);
    }
    return f(vl, vr);
  }
};

struct data {
  long long l, r, a;
};

long long n, m;
map<long long, vector<data>> mp;

long long solve();

int main() {
  cin >> n >> m;
  for(int i = 0; i < m; ++i) {
    long long l, r, a;
    cin >> l >> r >> a;
    mp[r].push_back({l, r, a});
  }

  cout << solve() << endl;
  return 0;
}

long long solve() {
  auto f = [](long long l, long long r) {
    return max(l, r);
  };
  auto g = [](long long l, long long r) { return l + r; };
  auto h = [](long long l, long long r) { return l + r; };
  SegmentTreeLaze<long long, long long> dp(n, f, g, h, 0,
                                           0);
  for(int i = 1; i <= n; ++i) {
    dp.update(i - 1, i, dp.query(0, i));
    long long mpsize = mp[i].size();
    for(int j = 0; j < mpsize; ++j)
      dp.update(mp[i][j].l - 1, i, mp[i][j].a);
  }
  return dp.query(0, n);
}


Measured memory_bytes: 31596
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;

int main() {
  ll k, a, b;
  cin >> k >> a >> b;
  ll ans;
  if (b - a <= 2 || k - a <= 0) { // ビスケットを交換しない場合
    ans = k + 1;    
  } else {         // ビスケットを交換する場合
    // ビスケットの数を最初にAにしておけば、あとはビスケットを叩く操作は必要ない
    // (ビスケットを叩くよりも交換したほうがたくさん増える)
    ans = a;      
    k -= a - 1;

    // (b - a) はビスケットの交換を行ったあとの差分
    // (k / 2) はビスケットA枚 -> 1円 -> ビスケットBとなるので、これはk / 2回操作可能
    ans += (b - a) * (k / 2); 
    if (k % 2 == 1) ans++;  // 奇数のときは１回操作が余る
  }

  cout << ans << endl;
}

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

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

  ll ans = a * c;
  if (a*d > ans) ans = a*d;
  if (b*c > ans) ans = b*c;
  if (b*d > ans) ans = b*d;

  cout << ans << endl;

  return 0;
}



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

int main(){
  int n,minmin=1e9,count=0;
  cin >> n;
  vector<int> v(n);
  r(i,n){
    cin >> v[i];
    if(v[i]<minmin){
      minmin=v[i];
      count++;
    }
  }
  cout<<count<<endl;
}

Measured memory_bytes: 1024
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {
    static final int MOD = 1000000007;
    static final int INF = 1 << 30;
    static final int ALF = 26;

    Main() {
        Scanner sc = new Scanner(System.in);
        long ans = 0;
        long X = sc.nextLong();
        long yen = 100;
        for(int i=1;true;i++){
            yen *= 1.01;
            if(yen>=X){
                System.out.println(i);
                return;
            }
            //System.out.println(yen);
        }
    }

    public static void main(String[] args) {
        new Main();
    }
}


Measured memory_bytes: 35808
#include <bits/stdc++.h>
using namespace std;typedef long long ll;typedef string str;
typedef vector<str> vst;typedef vector<ll> vll;
ll mod = 1000000007, INF = 10000000000000000;
ll gcd(ll a, ll b){if(b==0){return a;}return gcd(b, a%b);}
int main(){
  int n,d;
  cin>>n>>d;
  
  cout<<(n-1)/(2*d+1)+1<<endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (q, h, s, d) = readLine()!!.split(" ").map(String::toLong)
    val n = readLine()!!.toInt()

    val result = if (n % 2 == 0) {
        longArrayOf(n * (q * 4), n * (h * 2), n * s, n * d / 2).min()!!
    } else {
        val tn = n - 1
        longArrayOf(tn * (q * 4), tn * (h * 2), tn * s, tn * d / 2).min()!! + longArrayOf((q * 4), (h * 2), s).min()!!
    }
    println(result)
}




Measured memory_bytes: 37608
#include<bits/stdc++.h>
using namespace std;
typedef complex<double> P;
typedef vector<P> vec;

double eps=1e-5;

bool eq(double a,double b){return (b-a<eps&&a-b<eps);}
double dot(P a,P b){return real(b*conj(a));}
double cross(P a,P b){return imag(b*conj(a));}
P project(P a,P b,P c){b-=a;c-=a;return a+b*real(c/b);}
P reflect(P a,P b,P c){b-=a;c-=a;return a+conj(c/b)*b;}
int ccw(P a,P b,P c){
  b-=a,c-=a,a=c*conj(b);
  if(a.imag()>eps)return 1;//ccw
  if(a.imag()<-eps)return -1;//cw
  if(a.real()<-eps)return 2;//ob
  if(abs(b)+eps<abs(c))return -2;//of
  return 0;//os
}

//segment ab , point c
double dist(P a,P b,P c){
  if(dot(b-a,c-a)<0)return abs(c-a);
  if(dot(a-b,c-b)<0)return abs(c-b);
  return abs(cross(b-a,c-a))/abs(b-a);
}

bool isintersect(P a,P b,P c,P d){
  return ((ccw(a,b,c)*ccw(a,b,d)<=0)&&(ccw(c,d,a)*ccw(c,d,b)<=0));
}

//segment ab , segment cd
P intersect(P a,P b,P c,P d){
  a-=d;b-=d;c-=d;
  return d+a+(b-a)*imag(a/c)/imag(a/c-b/c);
}

double dist(P a,P b,P c,P d){
  if(isintersect(a,b,c,d))return 0;
  double ab=min(dist(a,b,c),dist(a,b,d));
  double cd=min(dist(c,d,a),dist(c,d,b));
  return min(ab,cd);
}

double calcArea(vec &t){
  double res=0;
  int n=t.size();
  for(int i=0;i<n;i++)res+=cross(t[i],t[(i+1==n?0:i+1)]);
  return abs(res/2.0);
}


double Arg(P a,P b,P c){
  b-=a,c-=a;
  double res=acos( max(-1.0,min(1.0,dot(b,c)/abs(b)/abs(c))) );
  if(cross(b,c)<0)res*=-1.0;
  return res;
}

int inPolygon(vec &t,P p){
  int n=t.size();
  double sum=0;
  for(int i=0;i<n;i++){
    P a=t[i],b=t[(i+1==n?0:i+1)];
    if( ccw(a,b,p) == 0 )return 1;
    sum+= Arg(p,a,b);
  }
  if( abs(sum) < eps )return 0;
  else  return 2;
}

int main(){
  int n;
  cin>>n;
  vec t;
  double x,y;
  for(int i=0;i<n;i++){
    cin>>x>>y;
    t.push_back(P(x,y));
  }
  int q;
  cin>>q;
  while(q--){
    cin>>x>>y;
    cout<<inPolygon(t,P(x,y))<<endl;
  }

  return 0;
}

Measured memory_bytes: 1320
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

#include <functional>

template< typename T, typename S >
struct LazySegmentTree{
    int n;
    vector<T> data;
    vector<S> lazy;
    T te;
    S se;

    inline void merge_functions(S& lazy,S& val){
        //lazy+=val;
        //lazy=val;
        chmin(lazy,val);
    }
    inline void operate(T& data,S& val,int len){
        //data+=val*len;
        //data=val*len;
        //data+=val;
        chmin(data,val);
    }
    inline T merge_values(T& x,T& y){
        //return x+y;
        return min(x,y);
        //return max(x,y);
    }

    LazySegmentTree(){}
    LazySegmentTree(int sz,T te,S se):te(te),se(se){
        n=1;
        while(n<sz) n*=2;
        data.resize(2*n-1,te);
        lazy.resize(2*n-1,se);
    }

    void build(const vector<T> &A){
        for(int k=0;k<int(A.size());k++) data[k+n-1]=A[k];
        for(int k=n-2;k>=0;k--) data[k]=merge_values(data[2*k+1],data[2*k+2]);
    }

    void eval(int k,int l,int r){
        if(lazy[k]==se) return;
        operate(data[k],lazy[k],r-l);
        if(r-l>1){
            merge_functions(lazy[2*k+1],lazy[k]);
            merge_functions(lazy[2*k+2],lazy[k]);
        }
        lazy[k]=se;
    }

    void update(int a,int b,S val,int k=0,int l=0,int r=-1){
        if(r<0) r=n;
        eval(k,l,r);
        if(b<=l||r<=a) return;
        if(a<=l&&r<=b){
            merge_functions(lazy[k],val);
            eval(k,l,r);
        }else{
            update(a,b,val,2*k+1,l,(l+r)/2);
            update(a,b,val,2*k+2,(l+r)/2,r);
            data[k]=merge_values(data[2*k+1],data[2*k+2]);
        }
    }

    T query(int a,int b,int k=0,int l=0,int r=-1){
        if(r<0) r=n;
        eval(k,l,r);
        if(b<=l||r<=a) return te;
        if(a<=l&&r<=b) return data[k];

        T vl=query(a,b,2*k+1,l,(l+r)/2);
        T vr=query(a,b,2*k+2,(l+r)/2,r);
        return merge_values(vl,vr);
    }

    T get(int p){
        return query(p,p+1);
    }
};

/*
  LazySegmentTree<ll,ll> seg(N,te,se);
  vector<ll> init(N,0);
  seg.build(init);
*/

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

  ll N,Q;
  cin>>N>>Q;

  LazySegmentTree<int,int> tate(N+1,N,N);
  tate.build(vector<int> (N+1,N));
  LazySegmentTree<int,int> yoko(N+1,N,N);
  yoko.build(vector<int> (N+1,N));

  ll ans=(N-2)*(N-2);
  rep(q,Q){
    int T,X;
    cin>>T>>X;
    if(T==1){
      int tar=yoko.get(X);
      ans-=max(0,tar-2);
      tate.update(2,tar,X);
    }else{
      int tar=tate.get(X);
      ans-=max(0,tar-2);
      yoko.update(2,tar,X);
    }
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 12176
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long n,m;
	cin>>n>>m;
	pair<long long,long long> a[n],b[m];
	for(long long i=0;i<n;i++)
	  cin>>a[i].first>>a[i].second;
	for(long long i=0;i<m;i++)
	  cin>>b[i].first>>b[i].second;
	for(long long i=0;i<n;i++){
		vector<pair<long long,long long> > vc;
		for(long long j=0;j<m;j++){
			long long d=abs(a[i].first-b[j].first)+abs(a[i].second-b[j].second);
			vc.push_back(make_pair(d,j+1));
		}
		sort(vc.begin(),vc.end());
		cout<<vc[0].second<<endl;;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<string>
#include<utility>
#include<array>
#include<set>
#include <numeric>
#include <stdio.h>
#include <map>
#include <iomanip>
#include <sstream>
//#include <boost/math/common_factor_rt.hpp>
#include<fstream>
#define EPS (1e-7)
using namespace std;
#define ll long long



class Employee {
public:
	int id;
	int parent;
	vector<int> children;
	int salary;

	Employee() {
		
	}

	Employee(int num, int nparent) {
		id = num;
		parent = nparent;
		salary = -1;
	}



};



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



int main() {
	int A, B;
	cin >> A >> B;
	int ans;
	for (int i = 0; i < B; i++)
	{
		int kuti = i * A - (i - 1);
		if (kuti >= B) {
			ans = i;
			break;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
def dfs(n):
    ret = 0
    if n > N:
        return ret
    s = str(n)
    if '3' in s and '5' in s and '7' in s:
        ret = 1
    for c in '753':
        ret += dfs(int(s+c))
    return ret

N = int(input())
print(dfs(0))


Measured memory_bytes: 3060
//In the name of Allah
#include <bits/stdc++.h>
using namespace std;

typedef long long ll; 
typedef pair<int,int> pii; 

const int maxN = 200 * 100 + 10; 
int a[maxN], b[maxN], c[maxN];
int d[maxN];

int main() { 
	ios::sync_with_stdio(false); cin.tie(0); 
	int n; cin >> n; 
	for( int i =0 ; i < n ; i++ ) { 
		cin >> c[i]; 
		c[i]--; 
		d[c[i]] = i; 
	}

	int val = 2;
	for( int i = 0 ; i < n-1 ; i++ ) 
		if( d[i] < d[i+1] ) 
			a[i+1] += val*abs(d[i]-d[i+1]);
		else
			b[i] += val*abs(d[i]-d[i+1]);

	a[0] ++; 
	for( int i = 1 ; i < n ; i++ ) 
		a[i] += a[i-1] + 1; 
	b[n-1]++; 
	for( int i = n - 2 ; i >= 0 ; i-- ) 
		b[i] += b[i+1] + 1; 
	for( int i = 0 ; i < n ; i++ ) cout << a[i] << " " ; 
	cout << endl;
	for( int i = 0 ; i < n ; i++ ) cout << b[i] << " " ; 
	cout << endl;
}



Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
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; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

struct Edge {
  int to, id;
  Edge(int to, int id): to(to), id(id) {}
};

vector<Edge> graph[55];
vector<int> es;

bool dfs(int v, int vt, int p = -1){
  if(v == vt){
    es = vector<int>();
    return true;
  }
  for(auto u : graph[v]){
    if(u.to == p) continue;
    if(dfs(u.to, vt, v)){
      es.emplace_back(u.id);
      return true;
    }
  }
  return false;
}

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

  REP(i, N-1){
    int u, v;
    cin >> u >> v;
    u--; v--;
    graph[u].emplace_back(v, i);
    graph[v].emplace_back(u, i);
  }
  
  int M;
  cin >> M;

  vector<int> eset(M);
  REP(i, M){
    int u, v;
    cin >> u >> v;
    u--; v--;

    dfs(u, v);
    for(auto e : es){
      eset[i] |= (1ll << e);
    }
  }

  int ans = 0;
  REP(bit, (1<<M)){
    int mask = 0;
    REP(i, M) if((bit >> i)&1) mask |= eset[i];

    int white = __builtin_popcountll(mask);
    int now = 1ll << (N-1-white);

    if(__builtin_popcountll(bit)%2 == 0) ans += now;
    else ans -= now;
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#define debug(...) \
    { cerr << "# " << __VA_ARGS__ << "\n"; }
#else
#define debug(...)
#define FPEN
#endif
const int maxn = 200009;
typedef long long i64;
typedef pair<i64, i64> pi64;
typedef pair<int, int> pi;
const i64 MOD = 119 << 23 | 1;
class {
   public:
    void solve() {
        i64 n;
        cin >> n;
        cout << gao(n) << '\n';
    }
    i64 gao(i64 a) {
        if (a == 1)
            return 1;
        else
            return 2 * gao(a / 2) + 1;
    }
} NSPACE;
int main() {
    FPEN;
    ios_base::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    NSPACE.solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long>> v(60);
const long long mod = 1000000007;

long long pow2[60];

int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        long long a;
        cin>>a;
        for(int j=0;j<60;j++){
            if(a&(1ll<<j))
                v[j].first++;
            else
                v[j].second++;
        }
    }
    pow2[0] = 1;
    for(int i=1;i<60;i++)
        pow2[i] = 2*pow2[i-1]%mod;
    long long ans = 0;
    for(int i=0;i<60;i++){
        ans = (ans + pow2[i]*v[i].first%mod*v[i].second%mod)%mod;
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;int c;
    if( s=="SSR" || s=="RSR" || s=="RSS" || s=="SRS")
        c = 1;
    if(s == "RRR")
        c = 3;
    if(s== "SSS")
        c=0;
    if(s=="RRS" || s=="SRR")
        c = 2;
    cout<<c<<endl;}






Measured memory_bytes: 3620
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}

  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N,M=get_i
A=get_i
accum_sum=array(N+1,0)
N.times do|i|
    accum_sum[i+1]=(accum_sum[i]+A[i])%M
end
kind=Hash.new(0)
accum_sum.each do|v|
  kind[v]+=1
end
ans=0
kind.each do|k,v|
  ans+=v*(v-1)/2
end
puts ans

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef pair<pii, pii> piipii;

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define eb emplace_back
int a[100005];
int main(){
    int n;
    scanf("%d", &n);
    for(int i=1;i<=n;i++) scanf("%d", &a[i]);
    ll ans = 1e18;
    for(int j=0;j<2;j++){
        ll res = 0, sum = 0;
        for(int i=1;i<=n;i++){
            sum += a[i];
            if(i%2 == j){
                if(sum > 0) continue;
                res += abs(sum) + 1;
                sum = 1;
            }
            else{
                if(sum < 0) continue;
                res += abs(sum) + 1;
                sum = -1;
            }
        }
        ans = min(ans, res);
    }
    printf("%lld\n", ans);
}

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

int min_mod(int L, int R) {
  int p = 2019;
  int l = L % p, r = R % p;
  
  int min = p - 1;
  int prod;
  
  for (int i = l; i <= r - 1; i++) {
    for (int j = i + 1; j <= r; j++) {
      prod = (i * j) % p;
//      printf("(%d * %d) mod %d = %d\n", i, j, p, prod);
      if (min > prod) min = prod;
    }
  }
  
  return min;
}

int main() {
  int L, R;
  cin >> L >> R;
  int p = 2019;
  int ans;
  
  if (L % p == 0 || R % p == 0) {
//    printf("%d or %d is a multiple of %d\n", L, R, p);
    ans = 0;
  } else if (L / p < R / p) {
//    printf("L / p = %d, R / p = %d\n", L / p, R / p);
    ans = 0;
  } else {
    ans = min_mod(L, R);
  }
  
  cout << ans;
}

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

int A, B, K;
vector<int> R;

int main() {
  cin >> A >> B >> K;
  K = min(K, B - A + 1);
  for(int i = 0; i < K; ++i) {
    R.push_back(A + i); R.push_back(B - i);
  }
  sort(R.begin(), R.end());
  R.erase(unique(R.begin(), R.end()), R.end());
  for(int a : R) cout << a << endl;
  return 0;
}


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



void solve(){
    int a,b,c;
    cin >> a >> b >> c;
    cout <<  (a+b)*c/2 << endl;
}

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

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#undef __DEBUG__
//#define __DEBUG__

#define MAX_N 999999


typedef struct _node{
	int val;
	struct _node *next;
}node_t;
node_t *head=NULL;
node_t *malloc_node(int val)
{
	node_t *n;
	n=(node_t*)malloc(sizeof(node_t));
	n->val=val; n->next=NULL;
	return n;
}
void push_node(int val)
{
    if(head==NULL){ 
    	head=malloc_node(val);
    	return;
    }
	node_t *n;
	for(n=head;n->next!=NULL;n=n->next);
	n->next=malloc_node(val);	
}

int is_even(int n){ return (n%2==0)?1:0; }

char* flg_is_prime;
int* primes;

void renew_primes(int n)
{
    flg_is_prime=(char*)malloc(sizeof(char)*MAX_N);
    memset(flg_is_prime, 1, sizeof(char)*MAX_N);
    int sqrt_n=(int)ceil(sqrt((double)n));
    int i,j;
    for(i=2;i<=sqrt_n;i++){
    	if(!flg_is_prime[i]){ continue; }
        for(j=i+1;j<=n;j++){
            if(flg_is_prime[j] && j%i==0){
                flg_is_prime[j]=0;
            }
        }
    }
	
	primes=(int*)malloc(sizeof(int)*MAX_N);
	int cnt=0;
	for(i=2;i<=n;i++){
		if(flg_is_prime[i]){ cnt++; }
		primes[i]=cnt;
	}
}


int main(void)
{
    FILE *fpin;
#ifdef __DEBUG__
    fpin=fopen("input.txt","r");
#else
    fpin=stdin;
#endif
	int max=0;
    while(!feof(fpin)){
        int n;
        fscanf(fpin,"%d\n",&n);
    	push_node(n);
    	if(max<n){ max=n; }
    }
	renew_primes(max);
	node_t *n;
	for(n=head;n!=NULL;n=n->next){
		printf("%d\n", primes[n->val]); 
	}
	
	return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define DUMP(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<": "<<(x)<<" (L"<<__LINE__<<")"<<endl
using namespace std;
using vint = vector<int>;
using vdouble = vector<double>;
using vstring = vector<string>;
using ll = long long;
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int main() {
    int N; cin >> N;
    int X = N;
    int fx = 0;
    while(N > 0) {
        fx += N % 10;
        N /= 10;
    }
    if(X % fx == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256