akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

using namespace std;

const int INF = 2147483647;

struct SegmentTree {
    int n;
    vector<int> heap;
    vector<bool> isLazy;
    
    SegmentTree(int n): n(n) {
        heap.assign(4 * n, INF);
        isLazy.assign(4 * n, true);
    }
    
    void update(int nodeId, int l, int r, int ql, int qr, int v) {
        if (qr < l || ql > r) {
            return;
        }
        else if (ql <= l && r <= qr) {
            heap[nodeId] = v;
            isLazy[nodeId] = true;
        }
        else {
            pushdown(nodeId);
            int m = l + (r - l)/2;
            update(nodeId * 2, l, m, ql, qr, v);
            update(nodeId * 2 + 1, m + 1, r, ql, qr, v);
        }
    }
    
    int query(int nodeId, int l, int r, int q) {
        if (q < l || q > r) {
            return -INF;
        }
        else if (isLazy[nodeId]) {
            return heap[nodeId];
        }
        else {
            int m = l + (r - l)/2;
            return max(query(nodeId * 2, l, m, q), query(nodeId * 2 + 1, m + 1, r, q));
        }
    }
    
    void pushdown(int nodeId) {
        //cout << "push: " << nodeId << endl;
        if (isLazy[nodeId]) {
            heap[nodeId * 2] = heap[nodeId];
            isLazy[nodeId * 2] = true;
            
            heap[nodeId * 2 + 1] = heap[nodeId];
            isLazy[nodeId * 2 + 1] = true;
            
            heap[nodeId] = -INF;
            isLazy[nodeId] = false;
        }
    }
    
};

int main() {
    int n, q;
    cin >> n >> q;
    SegmentTree st(n);
    for (int i = 0; i < q; i++) {
        int cmd;
        cin >> cmd;
        if (cmd == 0) {
            int ql, qr, v;
            cin >> ql >> qr >> v;
            st.update(1, 0, n -1, ql, qr, v);
//            for (int i = 0; i < 4 * n; i++) {
//                cout << i << ":" << st.heap[i] << endl; 
//            }
        }
        else {
            int pos;
            cin >> pos;
            cout << st.query(1, 0, n-1, pos) << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 4424
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
//if(strcmp(s[i],"AC")==0)
//if(s[l]=='#')
/*小文字判定
if((moji>= 'a') && (moji<='z')){
    printf("a\n");
    return 0;
  }
  */
//文字列中の一文字⇒数字の時は s[i]-'0'
int W_Length(char *str){
	int length = 0;
	while(*str++ != '\0')
		length++;
	return length;
}

void swap(long long int *a, long long int *b){
  int temp;
  temp=*a;
  *a=*b;
  *b=temp;
}
//swap(&a, &b)

double deg(double theta){//deg to theta
return theta*(2*3.14159265359)/360;
}

long long int cmp( const void *p, const void *q ) {
    return *(long long int*)p - *(long long int*)q;
}//ちいさい順
//qsort(a,n,sizeof(long long int),cmp);


int cmp_s(const void * left, const void * right)
{
	char *left_char = (char *)left;
  char *right_char = (char *)right;
  return strcmp(left_char, right_char);
}
//qsort(s,n,sizeof(s[0]),cmp_s);
//char s[n][11]

long long int GCD(long long int a, long long int b){
  long long int L=a,S=b;
  while(1){
    if(S>L){
      L=S+L;
      S=L-S;
      L=L-S;
    }
    if(L%S==0){
      return S;
    }
    L=L%S;
  }
  
}

long long int LCM(long long int a, long long int b){
  return a*b/(GCD(a,b));
}

int main (void)
{
	long long int n,i,tem,k,a[210000],max,j=1,count=0;
scanf("%lld",&n);
  a[0]=1;
  a[1]=2;
  a[2]=1;
  for(i=0;i<n;i++){
    a[0]=a[0]*10;
      a[1]=a[1]*9;
      a[2]=a[2]*8;
    a[0]=a[0]%1000000007;
    a[1]=a[1]%1000000007;
    a[2]=a[2]%1000000007;
  }
  tem=a[0]-a[1]+a[2];
  if(tem<0){
    tem+=1000000007;
  }
  tem=tem%1000000007;
  printf("%lld\n",tem);
return 0;
}


Measured memory_bytes: 1732
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int cnt[110];
int main()
{
	int N, K;
	cin >> N >> K;
	int ans = 0;
	for (int i = 0; i < K; i++) {
		int d; cin >> d;
		for (int j = 0; j < d; j++) {
			int A;
			cin >> A;
			cnt[A]++;
		}
	}
	for (int i = 0; i < N; i++) {
		if (cnt[i + 1] == 0) ans++;
	}
	cout << ans << endl;
}

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

int main(){
  int sx,sy,tx,ty; cin>>sx>>sy>>tx>>ty;

  int dx=tx-sx, dy=ty-sy;
  for(int i=0; i<dy; ++i)cout<<'U';
  for(int i=0; i<dx; ++i)cout<<'R';
  for(int i=0; i<dy; ++i)cout<<'D';
  for(int i=0; i<dx; ++i)cout<<'L';
  cout<<'L';
  for(int i=0; i<dy+1; ++i)cout<<'U';
  for(int i=0; i<dx+1; ++i)cout<<'R';
  cout<<'D'<<'R';
  for(int i=0; i<dy+1; ++i)cout<<'D';
  for(int i=0; i<dx+1; ++i)cout<<'L';
  cout<<'U'<<endl;
  
}


Measured memory_bytes: 256
fn main() {
	let mut s = String::new();
	use std::io::Read;
	std::io::stdin().read_to_string(&mut s).unwrap();
	let mut s = s.split_whitespace();
	let n: usize = s.next().unwrap().parse().unwrap();
	let m: usize = s.next().unwrap().parse().unwrap();
	let mut uf = UnionFind::new(n);
	for _ in 0..m {
		let a = s.next().unwrap().parse::<usize>().unwrap() - 1;
		let b = s.next().unwrap().parse::<usize>().unwrap() - 1;
		uf.unite(a, b);
	}
	let mut set = std::collections::HashSet::new();
	for i in 0..n {
		set.insert(uf.find(i));
	}
	println!("{}", set.len() - 1);
}

pub struct UnionFind {
	data: Vec<i32>,
}

impl UnionFind {
	pub fn new(n: usize) -> UnionFind {
		UnionFind { data: vec![-1; n] }
	}

	pub fn unite(&mut self, x: usize, y: usize) -> bool {
		let x = self.find(x);
		let y = self.find(y);
		if x == y {
			false
		} else {
			let (x, y) = if self.data[x] > self.data[y] {
				(y, x)
			} else {
				(x, y)
			};
			self.data[x] += self.data[y];
			self.data[y] = x as i32;
			true
		}
	}

	pub fn find(&mut self, i: usize) -> usize {
		if self.data[i] < 0 {
			i
		} else {
			let p = self.data[i] as usize;
			self.data[i] = self.find(p) as i32;
			self.data[i] as usize
		}
	}

	pub fn size(&mut self, i: usize) -> usize {
		let i = self.find(i);
		(-self.data[i]) as usize
	}
}


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

using namespace std;
 
using ll = long long;
using ull = unsigned long long;
using ldouble = long double;
 
const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s) cout << fixed << setprecision(10) << s << endl;


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

    println("ABC" << a);
}


Measured memory_bytes: 3620
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();


        String[] A = new String[ N ];
        for(int i = 0 ;i < N ; i ++){
            A[ i ] = sc.next();
        }

        String[] B = new String[ M ];
        for(int i = 0 ;i < M ; i ++){
            B[ i ] = sc.next();
        }

        boolean matchFlg = false;
        for (int i = 0; i < N - M + 1; i++) {
            for (int j = 0; j < N - M  + 1; j++) {
                if (matchFlg) {
                    break;
                }
                for (int k = 0 ; k < M; k++) {
                    if (!B[ k ].equals(A[i + k].substring(j,j + M))) {
                        matchFlg = false;
                        break;
                    }
                    matchFlg = true;
                }
            }
        }
        System.out.println(matchFlg ? "Yes" : "No");
    }
}


Measured memory_bytes: 23252
S=input()
N=len(S)

a=True

for i in range(N):
    if S[i]!=S[N-1-i]:
        print("No")
        a=False
        break

if a==True:
    for j in range(int((N-3)/2)+1):
        if S[j]!=S[int((N-3)/2)-j]:
            a=False
            print("No")
            break
if a==True:
    for k in range(int((N-3)/2)+1):
        if S[int((N+1)/2)+k]!=S[N-1-k]:
            a=False
            print("No")
            break
if a==True:
    print("Yes")

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

int main() {

    string a,b;

    cin >> a >> b;

    a += b;

    int x;

    stringstream  ss;

    ss << a;
    ss >> x;

    string ans = "No";

    for(int i=0; i*i <= x; i++){
        if(i*i == x){
            ans = "Yes";
            break;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//  ABC175A
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    string s;
    cin>>s;
    int ans=0;
    if(s.at(1)=='S'){
        if(s.at(0)=='R'||s.at(2)=='R') ans++;
    } else {
        ans++;
        if(s.at(0)=='R') ans++;
        if(s.at(2)=='R') ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll md = 1000000007;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
vl p, fac(2, 1), ifac(2, 1);

ll ad(ll a, ll b, ll mod = md) {
    return (a%mod + b%mod + mod) % mod;
}

ll ml(ll a, ll b, ll mod = md) {
    return ( (a%mod) * (b%mod) ) % mod;
}

ll pw(ll x, ll n, ll mod = md) {
    ll res = 1;
    x %= mod;
    while (n) {
        if (n & 1)  res = (res*x)%mod;
        n = (n >> 1);
        x = (x*x)%mod;
    }
    return res;
}

int mu(ll n) {
	int c = 1, pn = p.size();
	for(int i = 0; i < pn && p[i] * p[i] <= n; i++) {
		if(n%p[i] == 0) c = -c, n /= p[i];
		if(n%p[i] == 0) return 0;
	}
	if(n > 1) return -c;
	return c;
}

void sieveMU(ll n, vl &mu) {
    vl factor(n+1, 0);
    for(int i = 2; i * i <= n; i++) {
        if(!factor[i]) {
            for(int j = i * i; j <= n; j += i) factor[j] = i;
        }
    }
    mu[1] = 1;
    for(int i = 2; i <= n; i++) {
        if(!factor[i]) {
            mu[i] = -1;
            continue;
        }
        if((i/factor[i])%factor[i] == 0) {
            mu[i] = 0;
        } else {
            mu[i] = (-1)*mu[i/factor[i]];
        }
    }
}

void cachefact(ll lim, ll mod = md) {
    for(int i = 2; i <= lim; i++) {
        ifac.push_back((ifac[mod%i] * (mod - mod/i) % mod)%mod);
    }
    for(ll i = 2; i <= lim; i++) {
        fac.push_back((fac[i-1] * i)%mod);
        ifac[i] = (ifac[i-1] * ifac[i])%mod;
    }
}

ll C(ll n, ll r) {
    if(n < r || r < 0) return 0;
    ll ans = 1;
    for(int i = 0; i < r; i++) ans = ml(ans, n - i);
    return ml(ans, ifac[r]);
}

ll P(int n, int r) {
    if(n < r || r < 0) return 0;
    return ml(fac[n], ifac[n-r]);
}

void sieve(ll n) {
    vector<bool> prime(n+1, true);
    for(int i = 2; i*i <= n; i++) {
        if(prime[i]) {
            for(int j = i*i; j <= n; j += i) {
                prime[j] = false;
            }
        }
    }
    p.push_back(2);
    for(int i = 3; i <= n; i += 2) {
        if(prime[i]) p.push_back(i);
    }
}

ll PIE(ll n, ll k, ll f, ll mod = md) {
	if(f < 0 || k < 0 || n <= 0) return 0;
	ll ans = 0, l = min(n, k/(f+1));
	for(int i = 0; i <= l; i++) {
		ans = ad(ans, (i&1 ? -1 : 1) * ml(C(n, i), C(n - 1 + k - (f+1) * i, k - (f+1) * i)));
	}
	return ans;
}

int main() {
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    int n, k;
    cin >> n >> k;
    vl a(n);
    vvl dp(n+1, vl(k+1, 0));
    for(int i = 0; i < n; i++) {
    	cin >> a[i];
    }
    for(int i = 0; i <= a[0]; i++) {
    	dp[0][i] = 1;
    }
    for(int i = 1; i < n; i++) {
    	vl pref(k+1, 0);
    	for(int j = 0; j <= k; j++) { 
    		if(j > a[i]) {
    			pref[j] = ad(dp[i-1][j], +(j >= 1 ? pref[j-1] : 0));
    			dp[i][j] = ad(pref[j], -pref[j - a[i] - 1]);
    		} else {
    			pref[j] = ( dp[i-1][j] + (j >= 1 ? pref[j-1] : 0) ) % md;
    			dp[i][j] = pref[j];
    		}
    	}
    }
    cout << dp[n-1][k]%md << "\n";
    return 0;
}

Measured memory_bytes: 83100
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws NumberFormatException,
			IOException {
		new Main().run();
	}

	private void run() throws NumberFormatException, IOException {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		Node[] node = new Node[n];
		for (int i = 0; i < n; i++) {
			node[i] = new Node();
		}
		int l = -1;
		int x = n;
		while (x-- > 0) {
			int v = scanner.nextInt();
			int s = scanner.nextInt();
			for (int i = 0; i < s; i++) {
				int c = scanner.nextInt();
				if (i == 0)
					node[v].l = c;
				else
					node[l].r = c;
				l = c;
				node[c].p = v;
			}
		}
		int r = -1;
		for (int i = 0; i < n; i++) {
			if (node[i].p == -1) {
				r = i;
				break;
			}
		}
		rec(r, 0, node);
		StringBuilder builder = new StringBuilder();
		for (int i = 0; i < n; i++) {
			print(i, node, builder);
		}
		System.out.print(builder);
	}

	private void print(int u, Node[] T, StringBuilder builder) {
		builder.append("node ").append(u).append(": parent = ").append(T[u].p)
				.append(", depth = ").append(T[u].d).append(", ");
		if (T[u].p == -1)
			builder.append("root, ");
		else if (T[u].l == -1)
			builder.append("leaf, ");
		else
			builder.append("internal node, ");
		builder.append("[");
		boolean flag = false;
		int c = T[u].l;
		while (c != -1) {
			if (flag)
				builder.append(", ");
			builder.append(c);
			c = T[c].r;
			flag = true;
		}
		builder.append("]\n");
	}

	private void rec(int u, int p, Node[] T) {
		Deque<Integer> deque = new ArrayDeque<Integer>();
		deque.offer(u);
		while (!deque.isEmpty()) {
			int t = deque.size();
			for (int i = 0; i < t; i++) {
				int c = deque.poll();
				T[c].d = p;
				if (T[c].l != -1) {
					c = T[c].l;
					while (c != -1) {
						deque.offer(c);
						c = T[c].r;
					}
				}
			}
			p++;
		}
	}

	class Node {
		int p = -1;
		int l = -1;
		int r = -1;
		int d;
	}
}

Measured memory_bytes: 109060
// 標準入力から一行を読み取り、指定の型に変換する
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main() {
    let s: String = read();
    match s.as_str(){
        "SUN" => println!("7"),
        "MON" => println!("6"),
        "TUE" => println!("5"),
        "WED" => println!("4"),
        "THU" => println!("3"),
        "FRI" => println!("2"),
        "SAT" => println!("1"),
        _ => println!("0"),
    }
}


Measured memory_bytes: 4352
/**


１つのアルファベットが描かれた n 枚のカードの山をシャッフルします。

1回のシャッフルでは、下から h 枚のカードをまとめて取り出し、それを残ったカードの山の上に積み上げます。

カードの山は以下のように１つの文字列で与えられます。

 */

//スキャナつかうため

import java.util.Scanner;

public class Main {
	// プログラムのエントリポイント
	public static void main(String[] args) {
		// 入力ストリームの生成

		Scanner sc = new Scanner(System.in);

		//受け取る文字列、回す数の数の変数宣言
		String strmoji ;
		int intSuuji ;
		//breakされるまで処理を繰り返す
		while(true ){
			//文字列を受け取る
			strmoji = sc.next();
			//受け取った文字列がーだった場合breakする
			if(strmoji.contains("-")){
                break;
			}
			//受け取る数字の数を受け取る
			intSuuji = sc.nextInt();
			//受け取った数の回数処理を繰り返す
			for (int i = 0; i < intSuuji ; i ++){
					//シャッフルする数を受け取る
				int intMawasu = sc.nextInt();
				//strmojiの０からintmawasuの数 , intmawasuの数から文字列の最大の長さを
				//入れ替え変数にいれる
				String strirekae1 = strmoji.substring(0,intMawasu);
                String strirekae2 = strmoji.substring(intMawasu,strmoji.length());
                //分けた文字列を逆にして、strmojiに入れなおす。
                strmoji= strirekae2+strirekae1;


			}
			//結果表示
			System.out.println(strmoji);
		}
	}
}

Measured memory_bytes: 18292
import math
n, d = map(int, input().split())
a = []
ans = 0
x = 0
if d ==1:
  for i in range(n):
    a.append(int(input()))
  for i in range(n):
    for j in range(i,n):
      if math.sqrt((a[i]-a[j])**2)%1==0 and math.sqrt((a[i]-a[j])**2)!=0:
        ans += 1
else:
  for i in range(n):
    a.append(list(map(int, input().split())))
  for i in range(n):
    for j in range(i, n):
      x = 0
      for k in range(d):
        x += (a[i][k] - a[j][k]) **2
      if math.sqrt(x)%1 == 0 and math.sqrt(x) != 0:
        ans += 1
print(ans)

Measured memory_bytes: 9204
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  cout << fixed << setprecision(10);
  int n; cin >> n;
  vector<int> a(n+1), b(n);
  for(int i=0;i<n+1;++i) {
    cin >> a[i];
  }
  for(int i=0;i<n;++i) {
    cin >> b[i];
  }
  ll su = 0;
  for(int i=0;i<n;++i) {
    if(a[i] > b[i]) {
      su += b[i];
      b[i] = 0;
    } else {
      su += a[i];
      b[i] -= a[i];
    }
    if(a[i+1] > b[i]) {
      su += b[i];
      a[i+1] -= b[i];
    } else {
      su += a[i+1];
      a[i+1] = 0;
    }
  }
  cout << su << endl;
}


Measured memory_bytes: 1024
using System;

namespace ABC175A
{
    class Program
    {
        private const char V = 'R';

        static void Main(string[] args)
        {
            var S = Console.ReadLine().AsSpan();

            if (S[0] == V && S[1] == V && S[2] == V)
                Console.WriteLine(3);
            else if ((S[0] == V && S[1] == V) || (S[1] == V && S[2] == V))
                Console.WriteLine(2);
            else if (S[0] == V || S[1] == V || S[2] == V)
                Console.WriteLine(1);
            else
                Console.WriteLine(0);

        }
    }
}


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

int main() {
	string s;
	cin>>s;
	if (s[0]=='A') {
		bool flag=false;
		for (int i=1; i<s.size(); i++)
			if ('a'<=s[i] && s[i]<='z') {
				continue;
			} else if (2<=i && i<s.size()-1 && s[i]=='C') {
				if (flag) {
					cout<<"WA"<<endl;
					return 0;
				}
				flag=true;
			} else {
				cout<<"WA"<<endl;
				return 0;
			}
		if (flag==false) {
			cout<<"WA"<<endl;
			return 0;
		}
		cout<<"AC"<<endl;
		return 0;
	}
	cout<<"WA"<<endl;
	return 0;
}

Measured memory_bytes: 256
A,B,C = map(str,input().split())
a = list(A)
b = list(B)
c = list(C)
a_ = len(a)
b_ = len(b)
if a[a_-1] == b[0]:
    if b[b_-1] == c[0]:
        print("YES")
    else:
        print("NO")
else:
    print("NO")

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    int n;cin >> n;
    vector<int> a(n);
    inc(i, 0, n) cin >> a[i];
    inc(i, 0, n){
        if(i-a[i] < 0){
            cout << -1 << endl;
            return 0;
        }
    }
    dec(i, 1, n){
        if(a[i]-a[i-1] > 1){
            cout << -1 << endl;
            return 0;
        }
    }
    LL ans = a[n-1];
    dec(i, 1, n){
        if(a[i]-a[i-1] != 1){
            ans += a[i-1];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n+1;i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> vv;


int main(){
  int c11,c12,c13;
  int c21,c22,c23;
  int c31,c32,c33;
  cin >> c11 >> c12 >> c13;
  cin >> c21 >> c22 >> c23;
  cin >> c31 >> c32 >> c33;
  bool fail = 0;
  if(c22 != c21-c11+c12) fail = 1;
  if(c23 != c21-c11+c13) fail = 1;
  if(c32 != c31-c11+c12) fail = 1;
  if(c33 != c31-c11+c13) fail = 1;
  if(fail) cout << "No" << endl;
  else cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i) sort((i).begin(),(i).end(), greater<int>());
#define YES(i) cout << ((i) ? "Yes" : "No") << endl;
constexpr auto INF = 1000000000;
constexpr auto LLINF = 1LL << 62;
constexpr auto mod = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }

int main() {
    int n;
    cin >> n;
    vector<pair<ll, ll>> ab(n);
    FOR(i, n)cin >> ab[i].second >> ab[i].first;
    SORT(ab);
    bool ans = 1;
    ll now = 0;
    FOR(i, n) {
        now += ab[i].second;
        if (now > ab[i].first)ans = 0;
    }
    cout << (ans ? "Yes" : "No") << endl;
}


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

using namespace std;

#define S scanf
#define P printf
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define LL long long int
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)





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





int main()
{
    FAST();

//    freopen("input.txt","r",stdin);
//    freopen("input.txt","w",stdout);

    int i,n;
    cin >> n;
    double a[n+3];
    for(i=1;i<=n;i++)
    {
        cin >> a[i];
    }
    sort(a+1,a+n+1);
    for(i=2;i<=n;i++)
    {
        a[i]=(a[i]+a[i-1])/2;
    }
    cout << a[n];
    return 0;
}


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

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()

int main(){
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> c(n);
    vector<vector<int>> a(n, vector<int>(m, 0));
    for(int i = 0; i < n; i++){
        cin >> c[i];
        for(int j = 0; j < m; j++){
            cin >> a[i][j];
        }
    }

    //クリアできる?
    vector<int> allAb(m, 0);
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            allAb[j] += a[i][j];
        }
    }
    for(auto ab : allAb){
        if(ab < x){
            cout << -1 << endl;
            return 0;
        }
    }

    //総当り
    int ans = accumulate(c.begin(), c.end(), 0);
    for(int i = 0; i < (1 << n); i++){
        bitset<12> s(i);
        vector<int> abilities(m, 0);
        int tmp = 0;
        for(int j = 0; j < n; j++){
            if(s.test(j)){
                tmp += c[j];
                for(int k = 0; k < m; k++){
                    abilities[k] += a[j][k];
                }
            }
        }
        bool ok = true;
        for(auto ab : abilities){
            if(ab < x){
                ok = false;
            }
        }
        if(ok){
            ans = min(ans, tmp);
        }
    }

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

Measured memory_bytes: 3636
using System;
using System.Linq;

class Program
{
    static void Main()
    {
        var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var N = input[0];
        var M = input[1];

        var H = Console.ReadLine().Split().Select(int.Parse).ToArray();

        var AB = new int[N];
        for (int i = 0; i < M; i++)
        {
            input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var A = input[0];
            var B = input[1];

            AB[A - 1] = Math.Max(AB[A - 1], H[B - 1]);
            AB[B - 1] = Math.Max(AB[B - 1], H[A - 1]);
        }

        var result = 0;
        for (int i = 0; i < N; i++)
        {
            if (H[i] > AB[i])
            {
                result++;
            }
        }
        Console.WriteLine(result);
    }
}


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

vector<int> vec;

void dfs(int depth, int last, int res){ 
  //深さ、最後の数
  
  vec.push_back(res);
  
  if( depth == 10 ){ 
    return ;
  }
  
  if(last+1 <= 9){
  dfs(depth+1,last+1,10*res+last+1);
  }
  dfs(depth+1,last,10*res+last);
  if(last-1 >= 0){
  dfs(depth+1,last-1,10*res+last-1);
  }
  
  return;
} 

  

signed main(void){ 
  
  int k; cin >> k; k--;
  
  for(int i = 1; i <= 9; i++){ 
    dfs(0,i,i);
  }
  
  sort(vec.begin(),vec.end());
  
  if(false){
  for(int i = 0; i < 100; i++){ cout << vec[i] << " ";}
  cout << endl;
  cout << endl;
  
  }
  
  cout << vec[k] << endl; //index注意
  
  return 0;
} 

Measured memory_bytes: 10476
#include<stdio.h>

void swap(int *x, int *y)
{
    int temp = *x;
    *x = *y;
    *y = temp;
}

void sort(int *n1, int *n2, int *n3)
{
    if (*n1 > *n2) swap(n1, n2);
    if (*n2 > *n3) swap(n2, n3);
    if (*n1 > *n2) swap(n1, n2);
}

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

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

    printf("%d %d %d\n", a, b, c);

    return 0;
}


Measured memory_bytes: 2068
/*
g++ -std=c++14 -O2 -Wall a.cpp -o a && a
*/

//  io
#include <iostream>
//#include <fineam> //http://www.cplusplus.com/reference/fineam/fineam/
//#include <cstdio>
#include <iomanip> //http://www.cplusplus.com/reference/iomanip/
#include <limits>
//  util
#include <string>
#include <cstring>
#include <algorithm>
//#include <utility>
//#include <functional> //http://www.cplusplus.com/reference/functional/
//#include <cstdlib>
#include <cmath>
//#include <complex>
//#include <random>
//#include <bitset>
//  containers https://en.cppreference.com/w/cpp/container
#include <vector>
#include <queue>
#include <set>
//#include <map>
//#include <unordered_set>
//#include <unordered_map>
//  time
//#include <ctime>
//#include <chrono>
//                  https://en.cppreference.com/w/cpp/header/chrono
//                  http://www.cplusplus.com/reference/chrono/

using namespace std;
typedef vector<int> arri;
typedef vector<float> arrf;
typedef pair<int, int> pairi;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 0x7fffffffffffffff;
const ll infneg = -0x7fffffffffffffff;

//file input routed to stdinout
/*
std::ifineam inFile("input.txt");
std::ofineam outFile("output.txt");
std::cin.rdbuf(inFile.rdbuf());
std::cout.rdbuf(outFile.rdbuf());
*/

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

    int n;
    cin >> n;

    double odd = 0;
    for (int i = 1; i <= n; i++)
    {
        if (i % 2)
        {
            odd++;
        }
    }
    cout << odd / n;
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

x,y = na()

for i in range(x+1):
    a = i*2+(x-i)*4
    if a == y:
        print('Yes')
        exit()

print('No')

Measured memory_bytes: 9196
using System;
using System.Collections.Generic;
using System.Linq;
class Tree
{
    private int[] p; //頂点iの親がp[i-1]
    public Tree(int n) //コンストラクタ
    {
        p = new int[n];
        for (int i = 0; i < n; i++) p[i] = i + 1;
    }
    public int GetParent(int a) //aの親を返す
    {
        return p[a - 1];
    }
    public void SetParent(int a, int b) //aの親をbに設定
    {
        p[a - 1] = b;
    }
    public int root(int a) //aのrootを求め、aの親にする
    {
        if (p[a - 1] == a) return a;
        return (p[a - 1] = root(p[a - 1]));
    }
    public bool IsSameSet(int a, int b) //aとbが同一グループに属するか
    {
        return root(a) == root(b);
    }
    public void unite(int a, int b) //aとbを同一グループにまとめる
    {
        p[root(a) - 1] = root(b);
    }
}
class Program
{
    static void Main()
    {
        string[] s = Console.ReadLine().Split(' ');
        int n, q;
        n = int.Parse(s[0]);
        q = int.Parse(s[1]);
        Tree t = new Tree(n);
        for (int i = 0; i < q; i++)
        {
            s = Console.ReadLine().Split(' ');
            int c, x, y;
            c = int.Parse(s[0]);
            x = int.Parse(s[1]) + 1;
            y = int.Parse(s[2]) + 1;
            if (c == 0)
                t.unite(x, y);
            else
                Console.WriteLine(t.IsSameSet(x, y) ? 1 : 0);
        }
    }
}


Measured memory_bytes: 9552
import sys
fastinput=sys.stdin.readline
n=int(fastinput())
ai=[int(i) for i in fastinput().split()]
#プラス始まり
goukei=0
sousa=0
for k,a in enumerate(ai):
    goukei+=a
    if not k%2:#even:plus
        if goukei<=0:
            sousa+=1-goukei
            goukei=1
    else:#odd:minus
        if goukei>=0:
            sousa+=goukei+1
            goukei=-1
ans1=sousa
#マイナス始まり
goukei=0
sousa=0
for k,a in enumerate(ai):
    goukei+=a
    if k%2:#odd:plus
        if goukei<=0:
            sousa+=1-goukei
            goukei=1
    else:#even:minus
        if goukei>=0:
            sousa+=goukei+1
            goukei=-1
ans2=sousa
print(min(ans1,ans2))

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

int main() {
  long long int n, m;
  cin >> n >> m;
  for (long long int i=int(m/n); i>0; i--) {
    if (m%i==0 && (m/i)>=n) {
      cout << i;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 256
x, y = map(int, input().split())

def func(x,y):
    if y % 2 == 1:
        return False
    if 4*x < y:
        return False
    if y < 2*x:
        return False
    else:
        return True
    
if func(x,y):
    print("Yes")
else:
    print("No")

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

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

int main(void)
{
    int a,b; cin>>a>>b;
    int d=a/b,r=a%b;
    double f=(double)a/b;
    printf("%d %d %.5f\n",d,r,f);
    return 0;
} 


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

int main() {
  int N;
  cin >> N;
  bool j = true;
  
  for(int i = 0; i < N; i++){
    string S;
    cin >> S;
    if(S == "Y"){
      cout << "Four" << endl;
      j = false;
      break;
    }
  }
  if(j){
    cout << "Three" << endl;
  }
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000009
const int INF = 1LL<<30;

int N,K;
ll A[1010];
ll sm[1010];

int main() {
    cin>>N>>K;
    rep(i,N) cin>>A[i];

    sm[0]=A[0];
    for(int i=1;i<N;i++) sm[i]=sm[i-1]+A[i];

    vector<ll> v;
    for(int l=0;l<N;l++){
        for(int r=l;r<N;r++){
            ll tot=sm[r];
            if(l) tot-=sm[l-1];
            v.push_back(tot);
        }
    }

    int n=v.size();
    vector<int> ok(n,1);

    ll ans=0;
    for(int d=60;d>=0;d--){
        ll msk=1LL<<d;
        int cnt=0;
        rep(i,n){
            if(v[i] & msk && ok[i]) cnt++;
        }
        if(K<=cnt){
            ans+=msk;
            rep(i,n){
                if(!(v[i] & msk) && ok[i]) ok[i]=0;
            }
        }
    }

    cout<<ans<<endl;
}

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

int main(void)
{
    char str[200000];
    int i, a, z;
    gets(str);
    for (i = 0; i < strlen(str); i++) {
        if (str[i] == 'A') {
            a = i;
            break;
        }
    }
    for (i = strlen(str) + 1; i > 0; i--) {
        if (str[i] == 'Z') {
            z = i;
            break;
        }
        
    }

    printf("%d", z - a + 1);

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int INF = 10000;
int R, C;
int sx, sy, gx, gy;
vector<int> move_x = {0, 0, 1, -1};
vector<int> move_y = {1, -1, 0, 0};
typedef pair <int, int> P;

void bfs(vector<vector<int>>& Time, vector<vector<char>>& MAP){
    queue<P> que;
    que.push(P(sx, sy));
    Time.at(sx).at(sy) = 0;
    
    int prex, prey;
    while (que.size()){
        P p = que.front(); que.pop();
        if (p.first == gx && p.second == gy){
            return;
        }
        for (int i = 0; i < 4; i++){
            prex = p.first + move_x.at(i); prey = p.second + move_y.at(i);
            if (prex >= 0 && prey >= 0 && prex < R && prey < C && MAP.at(prex).at(prey) != '#' && Time.at(prex).at(prey) == INF){
                que.push(P(prex, prey));
                Time.at(prex).at(prey) = Time.at(p.first).at(p.second) + 1;
            }
        }        
    }
}

int main(){
    cin >> R >> C;
    char temp;
    sx = 0; sy = 0; gx = R - 1; gy = C - 1;
    vector<vector<char>> MAP(R, vector<char>(C));
    vector<vector<int>> Time(R, vector<int>(C));
    int cnt = 0;
    for (int i = 0; i < R; i++){
        for (int j = 0; j < C; j++){
            cin >> temp;
            MAP.at(i).at(j) = temp; 
            Time.at(i).at(j) = INF;
            if (temp == '.'){
              cnt++;
            }
        }
    }

    bfs(Time, MAP);
    if (Time.at(gx).at(gy) == INF){
      cout << -1 << endl;
    }else{
      cout << cnt - Time.at(gx).at(gy) - 1 << endl; 
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++) cin>>a[i];
  vector<vector<ll>> dp(n,vector<ll>(5));
  dp[0][0]=dp[0][4]=a[0];
  dp[0][1]=dp[0][3]=(a[0]==0?2:a[0]%2==0?0:1);
  dp[0][2]=(a[0]%2==0?1:0);
  for(int i=1;i<n;i++){
    dp[i][0]=dp[i-1][0]+a[i];
    dp[i][1]=min(dp[i-1][0],dp[i-1][1])+(a[i]==0?2:a[i]%2==0?0:1);
    dp[i][2]=min({dp[i-1][0],dp[i-1][1],dp[i-1][2]})+(a[i]%2==0?1:0);
    dp[i][3]=min({dp[i-1][0],dp[i-1][1],dp[i-1][2],dp[i-1][3]})+(a[i]==0?2:a[i]%2==0?0:1);
    dp[i][4]=min({dp[i-1][0],dp[i-1][1],dp[i-1][2],dp[i-1][3],dp[i-1][4]})+a[i];
  }
  cout<<min({dp[n-1][0],dp[n-1][1],dp[n-1][2],dp[n-1][3],dp[n-1][4]});
}

Measured memory_bytes: 15104
//*-- ILSH --*//
#include <bits/stdc++.h>
using namespace std; 
typedef long long int ll;
#define pb push_back 
#define pop pop_back
#define mp make_pair
#define ve vector
#define vii vector < int >
#define vll vector < ll > 
#define pii pair < int , int >
#define pll pair < ll , ll >
#define vpi vector < pii >
#define vpl vector < pll >
#define viii vector < vii >
#define vlll vector < vll >
#define fi first
#define sz size 
#define len length 
#define se second 
//const ll mod=998244353;
const ll mod = 1000000000+7;
const ll N=200000+6;
const ll inf=1e17;
ll powm(ll a,ll b){a=a%mod;ll res=1;while(b){if(b&1)res=(res*a)%mod;a=(a*a)%mod;b>>=1;}return (res%mod);}
ll modInverse(ll a,ll m){ll m0=m;ll y=0,x=1;if(m == 1)return 0;while(a> 1){ll q=a/m;ll t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=m0;return x;}  
void solve() {
	int n,k;
	cin>>n;
	ll arr[n][3];
	for ( int i=0;i<n;i++)
		cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
	for (int i=1;i<n;i++) {
		arr[i][0]=arr[i][0]+max( arr[i-1][1],arr[i-1][2]);
		arr[i][1]=arr[i][1]+max( arr[i-1][0],arr[i-1][2]);
		arr[i][2]=arr[i][2]+max( arr[i-1][0],arr[i-1][1]);
	}
	cout<<max( max( arr[n-1][0],arr[n-1][1]),arr[n-1][2])<<'\n';

}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while ( t-- )
    	solve();    
}

Measured memory_bytes: 2560
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

ans=0

for i in range(n):
    ans+=b[a[i]-1]
    if i>0 and a[i-1]+1==a[i]:
        ans+=c[a[i-1]-1]
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <unordered_map>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <stack>
#include <set>
#pragma GCC optimize(3 , "Ofast" , "inline")
using namespace std ;
#define ios ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0)
#define x first
#define y second
typedef long long ll ;
const double esp = 1e-6 , pi = acos(-1) ;
typedef pair<int , int> PII ;
const int N = 1e6 + 10 , INF = 0x3f3f3f3f , mod = 1e9 + 7;
ll in()
{
  ll x = 0 , f = 1 ;
  char ch = getchar() ;
  while(!isdigit(ch)) {if(ch == '-') f = -1 ; ch = getchar() ;}
  while(isdigit(ch)) x = x * 10 + ch - 48 , ch = getchar() ;
  return x * f ;
}
int main()
{
  int l = in() , r = in() , d = in() ;
  cout << (r / d - (l - 1) / d) << endl ;
  return 0 ;
}
/*
*/


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

template <typename T>
inline void read(T &x) {
  x = 0; char c = getchar();
  for(; !isdigit(c); c = getchar());
  for(;  isdigit(c); c = getchar())
    x = x * 10 + c - '0';
}

const int N = 2e5 + 50;
const int mod = 1e9 + 7;

# define pb push_back
# define row(x) ((x) <= n ? 1 : 0)
# define inv(x) (mul(ifac[(x)], fac[(x) - 1]))

int n, x, y, ans = 1, idx, dp[N], fac[N], ifac[N];
int arr[N], vl[N], fa[N], dfn[N], loop[N];
vector<int> g[N], E;

inline void add(int &a, int b) {
  a += b; if(a >= mod) a -= mod;
}
inline int mul(int a, int b) {
  return (LL) a * b % mod;
}
inline int Pow(int a, int b) {
  int r = 1;
  for(; b; b >>= 1, a = mul(a, a))
    if(b & 1) r = mul(r, a);  
  return r;
}
void pre() {
  fac[0] = 1;
  for(int i = 1; i <= 2 * n; ++i)
    fac[i] = mul(fac[i - 1], i);
  ifac[2 * n] = Pow(fac[2 * n], mod - 2);
  for(int i = 2 * n - 1; ~i; --i)
    ifac[i] = mul(ifac[i + 1], i + 1);
}
namespace jud {
  int cntn, cnte, vis[N];
  
  void dfs(int u) {
    vis[u] = 1;
    ++cntn;
    cnte += g[u].size();
    for(auto v : g[u]) {
      if(vis[v]) continue;
      dfs(v);
    }
  }
  void main(int u) {
    cntn = cnte = 0;
    dfs(u);
    cnte >>= 1;
    if(cntn != cnte) {
      puts("0");
      exit(0);
    }
  }
}
void dfs(int u) {
  static int icnt = 0;
  E.pb(u);
  dfn[u] = ++icnt;
  for(auto v : g[u]) {
    if(v == fa[u]) continue;
    if(!dfn[v]) {
      fa[v] = u;
      dfs(v);
    } else {
      if(dfn[u] > dfn[v]) continue;
      loop[++idx] = v;
      for(int i = v; i != u; i = fa[i])
        loop[++idx] = fa[i];
    }
  }
}
void Dfs(int u, int fa = 0) {
  for(auto v : g[u]) {
    if(v == fa || vl[v]) continue;
    Dfs(v, u);
    dp[v] = 1;
    for(auto x : g[v]) {
      if(x > u) continue;
      dp[v] += dp[x];
    }
  }
}
void calc(int u) {
  if(dp[arr[u]]) return ;
  int v = arr[u], res = 1;
  for(auto x : g[v]) {
    if(vl[x] || x > u) continue;
    res += dp[x];
  }
  if(arr[v] < u) {
    calc(v);
    res += dp[arr[v]];
  } 
  return (void) (dp[v] = res);
}
int doit(int step) {
  int res = 1;
  loop[0] = loop[idx];
  loop[idx + 1] = loop[1];
  int s = (step > 0) ? 1 : idx;
  for(; s && s <= idx; s += step) 
    arr[loop[s]] = loop[s + step];
  for(int i = 1; i <= idx; ++i) dp[loop[i]] = 0;
  for(int i = 1; i <= idx; ++i)
    calc(loop[i]);
  for(auto node : E) 
    res = mul(res, inv(dp[node]));
  return res;
}
int solve(int U) {
  jud :: main(U);
  E.clear();
  idx = 0, dfs(U);
  for(int i = 1; i <= idx; ++i) 
    vl[loop[i]] = 1;
  for(int i = 1; i <= idx; ++i)
    Dfs(loop[i]); 
  //for(int i = 1; i <= idx; ++i)
  //   cout << loop[i] << ' '; puts("");
  int ans = doit(1) + doit(-1);
  if(ans >= mod) ans -= mod;
  return ans;
}

int main() {
  read(n);
  pre();
  for(int i = 1; i <= 2 * n; ++i) {
    read(x), read(y);
    g[x].pb(y + n);
    g[y + n].pb(x);
  }
  for(int i = 1; i <= n; ++i)
    if(!jud :: vis[i]) ans = mul(ans, solve(i));
  printf("%d\n", mul(ans, fac[2 * n]));
  return 0;
}

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

int main() {
    long long n, c, k;
    cin >> n >> c >> k;
    vector<int> t(n);
    for(int i = 0; i < n; ++i) cin >> t[i];
    
    sort(t.begin(), t.end());
    //for(int i = 0; i < n; ++i) cout << " " << t[i];
    //cout << endl;
    int res = 0;
    for(int i = 0; i < n;) {
        int num = 0;
        for(int j = i; t[j] <= t[i] + k; ++j) {
            if(num == c) {
                //cout << "break" << endl;
                break;
            }
            //cout << t[i] + k << endl;
            //cout << "now" << t[j] << endl;
            
            ++num;
        }
        i += num;
        //cout << "i = " << i << endl;
        ++res;
    }
    
    cout << res << endl;
}


Measured memory_bytes: 640
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <queue>
# define MOD 1000000000+7
# define INF 1000000000
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;
unsigned long long int a = 0, b = 0, c = 0, d = 0, e = 0, ans = 0, x = 0, y = 0, z = 0, N = 0, m = 0, maxy = 0, mini = 9999, counter = 0, endp = 0, checker = 0;

std::vector <long long int> vec{}, vecsec{}, vecth{};
long long int iremono[100010], koware[100001];
long long  int iremono2[100001], check[100001], xpo[10000001], ypo[10000001], hei[1000001];
std::vector<std::string>kinds{}, kaku{};
char maze[1000][1000];
int sx, sy;
int gx, gy;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
bool okada = false, okada2 = false;
long long int dp[4][100003] ,ire[4][100003];
std::string input[103],one,two,three;
char re;

int H, W;//はんい
bool qw = false, er = false, ty = false, ui = false;
std::string code;
int main() {
	cin >>N>> a>>b;
	cout << min(N*a, b) << endl;
}



Measured memory_bytes: 2304
#include <stdio.h>
 
int main(void){
    char t[1001]={};
    char h[1001]={};
    int j=0,n=0,t_score = 0,h_score = 0;
 
    scanf("%d", &n);
    while(n--){
        scanf("%s %s",t,h);
        while(t[j] != '\0' || h[j] != '\0'){
        if(t[j] - 'a' > h[j] - 'a'){
            t_score += 3;
            j=0;
            break;
        }
        else if(t[j] - 'a' < h[j] - 'a'){
            h_score += 3;
            j=0;
            break;
        }
        else j++;
        }
        if(j != 0){
            t_score += 1;
            h_score += 1;
            j=0;
        }
    }
    printf("%d %d\n", t_score,h_score);
    return 0;
}


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

#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define forn(i,n) for(ll i=0;i<n;i++)
#define fore(i,a,b) for(ll i=a;i<=b;i++)
#define ford(i,n) for(ll i=n-1;i>=0;i--)
#define fi first
#define se second
#define endl "\n"
#define all(a) a.begin(),a.end()
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PI 3.14159265

/******************************************************************************************************/
void file(){
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
}
/******************************************************************************************************/

const ll nax=2e5+1,mod=1e9+7;



int main(){

    sync
   // file();
    

    int n;
    cin>>n;
    double x;
    double ans = 0;
    forn(i,n){
        cin>>x;
        ans+=(1.0/x);
    }
    cout<<fixed<<setprecision(10)<<1.0/ans<<endl;

    

  return 0;
}

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

long long int a[100005]={0}, b[100005]={0};

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

    long long int ans = 0;
    for(int i=n-1;i>=0;--i){
        ans += ((a[i] + ans) % b[i] == 0 ? 0 : b[i] - (a[i] + ans) % b[i]);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;


public class Main
{
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		
		for(; scanner.hasNext();)
		{
			int[] a = new int[2];
			a[0] = scanner.nextInt();
			a[1] = scanner.nextInt();
			
			int b = scanner.nextInt();
			
			boolean[] use_card = new boolean[10];
			for(int i=0; i<10; i++)
			{
				int j = i+1;
				if(j==a[0] || j==a[1] || j==b)
				{
					use_card[i] = true;
				}
				else
				{
					use_card[i] = false;
				}
			}
			
			int cnt = 0;
			for(int i=0; i<10; i++)
			{
				if(!use_card[i] && a[0]+a[1]+i+1<=20)
				{
					cnt++;
				}
			}
			
			System.out.println(cnt<4 ? "NO" : "YES");
		}
	}
}

Measured memory_bytes: 26160
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x,y,z,k;
    cin>>x>>y>>z>>k;
    vector<ll> a(x);
    vector<ll> b(y);
    vector<ll> c(z);

    REP(i,x) cin>>a[i];
    REP(i,y) cin>>b[i];
    REP(i,z) cin>>c[i];

    VRSORT(c);
    vector<ll> ab;
    REP(i,x) REP(j,y) ab.push_back(a[i]+b[j]);
    
    VRSORT(ab);
    vector<ll> ans;

    for(int i=0;i<min(k,(int)ab.size());i++){
        REP(j,z) ans.push_back(ab[i]+c[j]);
    }
    VRSORT(ans);
    REP(i,k) cout<<ans[i]<<endl;
}


Measured memory_bytes: 43368
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

const int inf = INT_MAX;
const int MOD = 1000000007;
const long long INF = LLONG_MAX;
const long long MINF = LLONG_MIN;

// -------------------------------------------------------

ll N;
ll a[301010];
ll csum[101010], rcsum[101010];

int main() {
  cin >> N;
  repe(i, 1, 3 * N) { cin >> a[i]; }

  priority_queue<int, vector<int>, greater<int>> que;
  ll sum = 0;
  repe(i, 1, N) {
    que.push(a[i]);
    sum += a[i];
  }

  csum[0] = sum;
  repe(i, 1, N) {
    ll mi = que.top();
    ll na = a[N + i];
    if (na > mi) {
      csum[i] = csum[i - 1] + na - mi;
      que.pop();
      que.push(na);
    } else {
      csum[i] = csum[i - 1];
    }
  }

  priority_queue<int> rque;
  ll rsum = 0;
  rep(i, 0, N) {
    rque.push(a[3 * N - i]);
    rsum += a[3 * N - i];
  }

  rcsum[N] = rsum;
  repe(i, 1, N) {
    ll ma = rque.top();
    ll na = a[2 * N + 1 - i];
    if (na < ma) {
      rcsum[N - i] = rcsum[N - i + 1] - ma + na;
      rque.pop();
      rque.push(na);
    } else {
      rcsum[N - i] = rcsum[N - i + 1];
    }
  }

  ll ans = MINF;
  repe(i, 0, N) { chmax(ans, csum[i] - rcsum[i]); }
  cout << ans;
}


Measured memory_bytes: 8060