akhauriyash/Code-Regression huggingface dataset:
import Control.Applicative ((<$>))
import Control.Monad (replicateM, forM_)
import Data.List (foldl', find)

import Data.Vector (Vector, (!), (//))
import qualified Data.Vector as V

main :: IO ()
main = do
  n <- readLn
  xss <- replicateM n (map read <$> words <$> getLine)
  solve n xss

solve :: Int -> [[Int]] -> IO ()
solve n xss = do
  printStat $ foldl' dfs (Stat n 1 (V.replicate n 0) (V.replicate n 0) (V.replicate n W)) [0 .. n-1]
  where gd = foldl' (\v (i:_:ls) -> v // [(i-1, map (subtract 1) ls)]) (V.replicate n []) xss
        dfs (Stat n tm gt bt cd) i | cd ! i == B = (Stat n tm gt bt cd)
                                   | otherwise = f (Stat n (tm+1) (gt // [(i,tm)]) bt (cd // [(i,G)])) [i]
        f st [] = st
        f (Stat n tm gt bt cd) (x:st) = case find (\k -> cd ! k == W) (gd ! x) of
                                         Just j -> f (Stat n (tm+1) (gt // [(j, tm)]) bt (cd // [(j,G)])) (j:x:st)
                                         Nothing -> f (Stat n (tm+1) gt (bt // [(x, tm)]) (cd // [(x,B)])) st

data Color = W | G | B deriving (Show, Eq, Ord)

data Stat = Stat Int Int (Vector Int) (Vector Int) (Vector Color) deriving (Show)

printStat :: Stat -> IO ()
printStat (Stat n _ gt bt _) = do
  forM_ [0 .. n-1] $ \i -> do
    putStrLn . unwords $ [show (i+1), show (gt ! i), show (bt ! i)]



Measured memory_bytes: 5068
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        sc.close();
        if(a * b >= a + b && a * b >= a - b){
            System.out.println(a * b);
        }else if(a + b >= a - b && a + b >= a * b){
            System.out.println(a + b);
        }else{
            System.out.println(a - b);
        }
    }
}

Measured memory_bytes: 35688
#include<bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(v) v.begin(), v.end()

using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const double PI = 2 * acos(0);
int ans[10001];

int main() {
	int N;
	cin >> N;
	for (int i = 1; i <= N; i++) {
		if (i * i > N) break;
		for (int j = 1; j <= N; j++) {
			if (i * i + j * j + i * j > N) break;
			for (int k = 1; k <= N; k++) {
				int tmp = i * i + j * j + k * k + i * j + i * k + j * k;
				if (tmp > N) break;
				ans[tmp]++;
			}
		}
	}
	for (int i = 1; i <= N; i++) {
		cout << ans[i] << endl;
	}
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int inf = 1e9;
double pi = 3.14159265359;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, b, a) for (int i = a - 1; i >= b; i--)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

int main() {
    set<string> s;
    int n;
    cin >> n;
    rep (j, 0, n) {
        string cmd, i;
        cin >> cmd >> i;
        if (cmd[0] == 'i') {
            s.insert (i);
        } else {
            if (s.find (i) != s.end()) cout << "yes\n";
            else
                cout << "no\n";
        }
    }
}



Measured memory_bytes: 32144
# 冒泡排序
def bubble_sort(arr):
    no_swap = True
    swap_cnt = 0
    for i in range(len(arr), 0, -1):
        if not no_swap:
            break
        for j in range(0, i - 1):
            if arr[j] > arr[j + 1]:
                arr[j], arr[j + 1] = arr[j + 1], arr[j]
                swap_cnt += 1
            no_swap = True
    return swap_cnt


if __name__ == '__main__':
    N = int(input())
    arr = list(map(int, input().split()))
    cnt = bubble_sort(arr)
    print(' '.join(map(str, arr)))
    print(cnt)


Measured memory_bytes: 5596
#include "bits/stdc++.h"
using namespace std;
#define int long long
#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 FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
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;}
constexpr int INF = 1e18;

long long ten(int x) {
	return x ? ten(x - 1) * 10 : 1;
}
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
signed main(){
	IOS();
	int N;
	cin >> N;

	auto my_stoll = [&](string s) -> int {
		string t = "";
		string u = "";
		int is_comma = 0;
		REP(i, s.size()) {
			if(s[i] == '.') is_comma = true;
			else if(is_comma) {
				u += s[i];
			} else {
				t += s[i];
			}
		}
		while(u.back() == '0') u.pop_back();
		int ret = stoll(t) * ten(u.size()) + (u.size() > 0 ? stoll(u) : 0ll);
		ret *= ten(9 - u.size());
		return ret;
	};
	int ans = 0;
	vector<vector<int>>dp(60, vector<int>(60));
	REP(i, N) {
		string s;
		cin >> s;
		int x = my_stoll(s);
		int pow2 = 0, pow5 = 0;
		while(x % 2 == 0) {
			++pow2;
			x /= 2;
		}
		while(x % 5 == 0) {
			++pow5;
			x /= 5;
		}
		++dp[pow2][pow5];
		if(min(pow2, pow5) >= 9) --ans;
	}
	REP(i, 60) REP(j, 60) REP(k, 60) REP(l, 60) {
		if(i + k >= 18 && j + l >= 18) {
			ans += dp[i][j] * dp[k][l];
		}
	}
	out(ans / 2);
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define mod 1000000007
const ll INF=1LL<<60;
int main(){
	ll n,k;
	cin>>n>>k;
	ll h[n+1];
	for(ll i=0;i<n;i++)
		cin>>h[i];
	vector<ll> dp(n+1,INF);
	dp[0]=0;
	for(ll i=1;i<n;i++)
	{
		for(ll j=1;j<=k;j++)
		{
			if(i>=j)
			{
				dp[i]=min(dp[i],dp[i-j]+abs(h[i-j]-h[i]));
			}
		}
	}
	cout<<dp[n-1];


}

Measured memory_bytes: 1792
N = int(input())
nums = input().split()
end = False
result = 1
for num in nums:
  if num == "0":
    print(0)
    end = True
    break
if not end:
  nums = [int(s) for s in nums]
  for num in nums:
    result = result * num
    if 10**18< result:
      result = -1
      break
  print(result)


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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  ll n, m; cin >> n >> m;
  vll x(n), y(m);
  REP(i, n) {
    cin >> x[i];
  }
  REP(i, m) {
    cin >> y[i];
  }

  REP(i, n-1) {
    x[i] = x[i+1] - x[i];
  }

  REP(i, m-1) {
    y[i] = y[i+1] - y[i];
  }

  ll xsu = 0;
  REP(i, n-1) {
    xsu += ((i+1) * (n-1-i) % MOD) * x[i] % MOD;
    xsu %= MOD;
  }

  ll ysu = 0;
  REP(i, m-1) {
    ysu += ((i+1) * (m-1-i) % MOD) * y[i] % MOD;
    ysu %= MOD;
  }

  cout << xsu * ysu % MOD << endl;
  
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);

        int aNum = sc.nextInt();
        int bNum = sc.nextInt();

        sc.close();

        int tasizan = aNum + bNum;
        int hikizan = aNum - bNum;
        int kakezan = aNum * bNum;

        int max = tasizan;
        if (max <= hikizan) {
            max = hikizan;
        }
        if (max <= kakezan) {
            max = kakezan;
        }

        System.out.println(max);
    }
}

Measured memory_bytes: 21844
void main()
{
    long[] tmp = readln.split.to!(long[]);
    long n = tmp[0], k = tmp[1];
    long[] a = readln.split.to!(long[]);

    long mod = 10 ^^ 9 + 7;
    long[] l = new long[n], r = new long[n];
    foreach (i; 0 .. n)
    {
        foreach (j; 0 .. n)
        {
            if (a[i] > a[j])
            {
                if (i > j) ++l[i];
                else ++r[i];
            }
        }
    }

    long lsum = k * (k - 1) / 2 % mod;
    long rsum = k * (k + 1) / 2 % mod;
    long result;
    foreach (i; 0 .. n)
    {
        long total = (l[i] * lsum) % mod + (r[i] * rsum) % mod;
        total %= mod;
        result = (result + total) % mod;
    }

    result.writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 380
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}

const ll inf=10000000000;
int main(){
  int N,M;cin>>N>>M;
  
  cout<<(N*(N-1)/2)+(M*(M-1)/2)<<endl;
}
   

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

using namespace std;
using ll = long long;
using vec = vector<int>;

#define rep(i, n)  for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define Sort(a)    sort(a.begin(), a.end())
#define gSort(a)   sort(a.begin(), a.end(), greater<int>())
#define pout(n, a) cout << fixed << setprecision(n) << (a)
#define Cast(dig, n) static_cast<std::bitset<(dig)>>(n)

const int INF = 2147483647;
const ll  MOD = 1000000007;

int main() {
    int n; cin >> n;
    vector<int> x(n-1);
    for(int i = 0; i < n-1; ++i) cin >> x[i];

    // <社員番号, 部下数>
    map<int, int> ans;
    for(int i = 0; i < n; ++i) ans.emplace(i+1, 0);

    for(int i = 0; i < n-1; ++i) {
        ans[x[i]]++;
    }
    
    for(auto i : ans) {
        cout << i.second << endl;
    }
}

Measured memory_bytes: 13480
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vp;
typedef map<ll, ll> mll;
typedef map<string, ll> mstrll;
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
#define out(x) cout << (x)
#define indent() cout << '\n'
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
ll gcd(ll a, ll b){return b != 0 ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}
ll factorial(ll a){return a < 2 ? 1 : factorial(a - 1) * a;}
ll summation(ll a){return a < 1 ? 0 : (a * a + a) / 2;}
const ll INF = 1e16;
const ll MOD = 1e9 + 7;
const string ALPHABETS = "abcdefghijklmnopqrstuvwxyz";
ll dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};
//ll dx[] = {-1, 0, 1, -1, 1, -1, 0, 1}, dy[] = {-1, -1, -1, 0, 0, 1, 1, 1};
ll n, m, x, y, z, w, h;
string s, t;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> s){
        ll ans = 0, tmp = 0, cnt = 0, mx = -INF, mn = INF;
        ll a[] = {}, b[] = {}, c[] = {};
        vll v;
        each(c, s){
            if(c == 'S'){
                cnt++;
            }else{
                if(cnt){
                    cnt--, ans++;
                }
            }
        }
        print(s.size() - 2 * ans);
    }
}


Measured memory_bytes: 720
/**
 * @author      : omgursocute
 * @created     : 2020-02-23 23:09 (UTC+7)	
 * @task        : D
 */

#include <bits/stdc++.h>

using namespace std;

#define int long long
const int mod = 1e9 + 7;

int add(int a, int b) {
	int ret = a + b;
	if(ret >= mod) return ret - mod;
	else return ret;
}

int sub(int a, int b) {
	int ret = a - b;
	if(ret >= 0) return ret;
	else return ret + mod;
}

int mul(int a, int b) {
	return (a * b) % mod;
}

int powmod(int a, int b) {
	int ret = 1;
	while(b) {
		if(b & 1) ret = mul(ret, a);
		b >>= 1;
		a = mul(a, a);
	}
	return ret;
}

int divide(int a, int b) {
	return mul(a, powmod(b, mod - 2));
}

int comb(int n, int k) {
	int ret = 1;
	for(int i = 1; i <= k; i++)
		ret = mul(ret, divide(sub(add(n, 1), i), i));
	return ret;
}

template <typename T>
inline void Read(T &x) {
	bool Neg = false;
	char c;
	for(c = getchar(); c < '0' || c > '9'; c = getchar())
		if(c == '-') Neg = !Neg;
	x = c - '0';
	for(c = getchar(); c >= '0' && c <= '9'; c = getchar())
		x = x * 10 + c - '0';
	if(Neg) x = -x;
}

template <typename T>
inline void Write(T x) {
	if(x < 0)
		putchar('-'); x = -x;
	T p = 1;
	for(T temp = x / 10; temp > 0; temp /= 10)
		p *= 10;
	for(; p > 0; x %= p, p /= 10)
		putchar(x / p + '0');
}

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

	int n, a, b;
	cin >> n >> a >> b;
	int ans = sub(powmod(2, n), 1);
	ans = sub(ans, comb(n, a));
	ans = sub(ans, comb(n, b));
	cout << ans;

	return 0;
}

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

using namespace std;

int main() {
  int N, A, B;
  
  cin >> N >> A >> B;
  
  int A1 = N * A;
  
  if (A1 < B) {
    cout << A1 << endl;
  }
  else {
    cout << B << endl;
  }
}

Measured memory_bytes: 256
import sys

# S = input()
# N, M = map(int, input().split())
# nums = list(map(int, input().split()))
# nums_2d = [list(map(int, input().split())) for _ in range(N)]


def main():
    S = input()

    odd = ["R", "U", "D"]
    even = ['L', 'U', 'D']

    easy = True
    for i, s in enumerate(S):
        if i %2 == 1:
            if s not in even:
                easy = False
        else:
            if s not in odd:
                easy = False

    print(['No', 'Yes'][easy])


if __name__ == '__main__':
    main()


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

using namespace std;

vector<char> c = {'z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y'};

int main (void) {
    long long N;
    cin >> N;

    string ans_r;
    while ( N > 0 ) {
        ans_r.push_back(c.at(N%26));
        N = (N-1) / 26;
    }

    int len = ans_r.size();
    for ( int i = len-1; i >= 0; i-- ) {
        cout << ans_r.at(i);
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3600
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,a[200010],dp[200010]={},sum[200010]={};
    cin>>n;
    rep(i,n){
        cin>>a[i];
    }
    dp[0]=1;
    dp[1]=1;
    sum[a[0]]++;
    rep2(i,1,n){
        dp[i+1]=dp[i];
        if(a[i]==a[i-1]) continue;
        dp[i+1]+=sum[a[i]];
        sum[a[i]]+=dp[i];
        sum[a[i]]%=MOD;
        dp[i+1]%=MOD;
    }
    cout<<dp[n]<<endl;
    return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
const int mx=123456;
#define ll long long
#define p push_back
#define ff first
#define ss second
ll n,k,cnt,y,cnt1 ;
string s;
int main(){
    cin>>s;
    cin>>k;
    for(int i=0;i<s.size();i++){
        if(s[i]=='1'){
            cnt1++;
        }
        else{
            y=i;
            break;
        }
    }
    if(cnt1>=k){
        cout<<1;
    }
    else{
        cout<<s[y]-48;
    }
    return 0;
}



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

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

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define vuni(v) v.erase(unique(v.begin(), v.end()), v.end());
#define mins(m, s) m.insert(make_pair(s, 1));
#define mfin(m, s) m.find(s) != m.end()

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl

const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9 + 7;

int main() {
    int n, x, t;
    cin >> n >> x >> t;
    int ans = 0;
    while(n > 0) {
        n -= x;
        ans += t;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#sを最高のパターンにして，tを最悪のパターンにすればいい
#continueで強制的に次のループへ
s = list(input())
t = list(input())
condition = 0

s.sort()
t.sort()
t.reverse()

if len(s)  == len(t):
    length = len(s)
    pattern = -1
elif len(s) < len(t):
    length = len(s)
    pattern = 0
else:#sのほうが長い時 pattern = 1
    length = len(t)
    pattern = 1

if pattern == -1:
    for i in range(length):
        if s[i] == t[i]:
            continue
        elif s[i] < t[i]:
            print("Yes")
            condition =1
            break
        else:
            print("No")
            condition =1
            break
    if condition == 0:
        print("No")
elif pattern == 0:
    for i in range(length):
        if s[i] == t[i]:
            continue
        elif s[i] < t[i]:
            print("Yes")
            condition =1
            break
        else:
            print("No")
            condition =1
            break
    
    if condition == 0:
        print("Yes")
elif pattern == 1:
    for i in range(length):
        if s[i] == t[i]:
            continue
        elif s[i] < t[i]:
            print("Yes")
            condition =1
            break
        else:
            print("No")
            condition =1
            break
            
    if condition == 0:
        print("No")
        
    



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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9 + 9;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int mina = INF;
  int maxa = -1;

  rep(i, n) {
    cin >> a[i];
    mina = min(mina, a[i]);
    maxa = max(maxa, a[i]);
  }

  int ans = maxa - mina;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<long long,long long>
#define lg length()
#define pb push_back
ifstream in("file.in");
ofstream out("file.out");
#define MAXN 100005
#define INF 1e9+5
#define int long long
#define LINF 1000000000000000005

int n,x,y,k[100005],r,v[100005],t[100005],ans,f;

vector <int> g[100005];

void DFS(int nod){
    v[nod]=1;
    int cnt1=0,cnt0=0;
    for(int i : g[nod]){
        if(!v[i]){
            DFS(i);
            if(!t[i]) cnt0++;
            else cnt1++;
        }
    }
    if(cnt1 && !cnt0) t[nod]=0;
    else if(cnt0==1) t[nod]=1;
    else if(cnt0>1) f=1;
}

int32_t main(){
    ios_base :: sync_with_stdio(0);
    cin >> n;
    for(int i=1;i<n;i++){
        cin >> x >> y;
        g[x].pb(y); g[y].pb(x);
        k[x]++; k[y]++;
    }
    DFS(1);
    if(f || !t[1]) cout << "First";
    else cout << "Second";
}


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

using namespace std ;

#define sz(v) (int)v.size()
#define ll long long
#define all(v)  v.begin() , v.end()
#define rall(v)  v.rbegin() , v.rend()
#define pf push_front
#define pb push_back
#define fast FastInputOutput() ;
#define Clear( container , value ) memset( container , value , sizeof container )
#define PI acos( -1.0 )
#define forn( t , v , be , n ) for( t v = be ; v < n ; v++ )
#define fore( x , j ) for( auto x : j )
#define se second
#define fr first
//#define c_b fflush(stdin);

const ll Long_max = numeric_limits < ll > :: max() ;
const int Int_max = numeric_limits < int > :: max() ;

void File_input( string pathIn ) {
    freopen( pathIn.c_str(), "r", stdin ) ;
}

void File_output( string pathOut ) {
    freopen( pathOut.c_str(), "w", stdout ) ;
}

int msg() {
    srand( time( 0 ) ) ;
    vector < string > st = {
        "Wish everyone high ratings!",
        "Good luck!",
        "Have fun!",
        "Please, read all the problems!",
        "Go Go fight!"
    } ;
    cerr << st[ rand() % sz( st ) ] ;
    return 0 ;
}

void FastInputOutput() {
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}

string a , b ;
string res(){
if( a == b ) return "EQUAL";
if( sz( a ) != sz( b ) ) return ( sz( a ) > sz( b ) ) ? "GREATER" : "LESS" ;
return ( a > b ) ? "GREATER" : "LESS" ;
}
int main() {
   cin >> a >> b ;
   cout << res() ;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<ll,pair<ll,ll>> pii;
typedef pair<ll,ll> pi;
typedef vector<ll> vl;

#define matrix vector<vector<ll>>
#define llmax LLONG_MAX
#define llmin LLONG_MIN
#define rep(i,n) for(ll (i)=0;(i)<n;++(i))
#define crep(i,m,n) for(ll (i)=m;(i)<n;++(i))
#define zero(a) memset((a),0,sizeof((a)))
#define minus(a) memset((a),-1,sizeof((a)));
#define sq(a) ((a)*(a))
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define ff first
#define ss second

ll global=0;

// return nCr value
long long C(int n, int r) {
    if(r>n) return 0;
    if(r > n - r) r = n - r; // because C(n, r) == C(n, n - r)
    long long ans = 1;
    int i;
    for(i = 1; i <= r; i++) {
        ans *= n - r + i;
        ans /= i;
    }
    return ans;
}

// return whether number is prime or not
vector<ll> sieve(ll n){
    vector<ll> is_prime(n+1, true);
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i <= n; i++) {
        if (is_prime[i] && (long long)i * i <= n) {
            for (int j = i * i; j <= n; j += i)
                is_prime[j] = false;
        }
    }
    return is_prime;
}


void test_case();
int main(){
    ios::sync_with_stdio(0);    
    cin.tie(0); cout.tie(0);
    ll t=1;
    // cin >> t;
    for(ll T=0;T<t;T++){
        test_case();
    }
    //**************************************************************************//
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

void test_case(){
    ll n;scanf("%lld",&n);
    vector<ll>a(n);
    rep(i,n)scanf("%lld",&a[i]);
    vector<vector<ll>>dp(n+5, vector<ll>(n+5));
    for(ll L = n-1; L>=0 ; --L){
        for(ll R = L; R<=n-1; ++R){
            if(L==R){
                dp[L][R] = a[L];
            }
            else{
                dp[L][R] = max(a[L]-dp[L+1][R], a[R]-dp[L][R-1]);
            }
        }
    }
    cout<<dp[0][n-1];
}


Measured memory_bytes: 73988
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; ++i)
using ll = long long;
const ll MOD = 1000000007;//998244353;
const int MAX = 1e5;
int dp[3][MAX+1];
int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   int n; cin >> n;
   rep(i,n){
      int a, b, c; cin >> a >> b >> c;
      dp[0][i+1] = max(dp[1][i]+a, dp[2][i]+a);
      dp[1][i+1] = max(dp[0][i]+b, dp[2][i]+b);
      dp[2][i+1] = max(dp[0][i]+c, dp[1][i]+c);
   }
   cout << max(max(dp[0][n], dp[1][n]),dp[2][n]);
}

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

int main ()
{
	int n,i,j,k,mod2=0,mod4=0,gg=0;
	int a[100005];
	cin>>n;
	for(i=0; i<n; i++)
	{
		cin>>a[i];
		if(a[i]%4==0)
			mod4++;
		else if(a[i]%2==0)
			mod2++;
		else
			gg++;
	}
	if(mod4>=gg)
		cout<<"Yes"<<endl;
	else //mod4 < gg
	{
		if(mod2 == 0)
		{
			if(mod4+1>=gg)
				cout<<"Yes";
			else
				cout<<"No";
		}
		else//？？？？？？？？？？？？？？？ 
		{
			if( 2 * mod4 + mod2 < n )
				cout<<"No";
			else
				cout<<"Yes";
		}
	}

	return 0;
}
/*分类讨论下。
显然，任意数和 4 的倍数相乘，其结果仍是 4 的倍数；
显然，若存在任意数量 2 的倍数，两两之间乘起来就是 4 的倍数；
如果存在一个数既不是 4 的倍数，也不是 2 的倍数（即因子里没有 2 ）：
放在 2 的倍数旁边，一定不符合要求；
放在 4 的倍数旁边，两两相乘一定是 4 的倍数。
因此符合要求的排列一定是，所有 2 的倍数相邻排在一起，
所有 4 的倍数和剩下的数相间排列，这
些剩下的元素个数不能超过 4 的倍数的数量，不
然所有 4 的倍数都被包起来了。*/



Measured memory_bytes: 768
// Branch on Condition- Sorting Three Numbers
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_2_C
using System;
using System.Linq;

namespace NTL_2_C {
	class Program {
		public Program() {}
		
		public static void Main() {
			new Program().Calc();
		}
		
		void Calc() {
			var str = Input.Split(' ')
			                .ToArray();
            Array.Sort(str);
			Output(string.Join(" ", str));
		}
		
		String Input {
			get {
				return Console.ReadLine();
			}
		}
		
		void Output(String str) {
			Console.WriteLine(str);
		}
	}
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl




typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e6 + 5;


int n,a,b;
ll v[maxn];

ll C[55][55];

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



    for (int i=0; i<=50; i++) {
	C[i][0]=C[i][i]=1;
	for (int j=1; j<i; j++) {
	    C[i][j]=C[i-1][j]+C[i-1][j-1];
	}
    }
    assert(C[4][2]==6);



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

    sort(v,v+n);
    reverse(v,v+n);



    double maxavg=0;
    for (int i=0; i<a; i++) {
	maxavg+=v[i];
    }

    maxavg/=a;

    int acount=0;
    int aslots=0;
    
    for (int i=0; i<n; i++) {
	if (v[i]==v[a-1]) {
	    acount++;
	    if (i<a) {
		aslots++;
	    }
	}
    }


    ll res = 0;

    if (aslots == a) {
	for (int j=a; j<=b; j++) {
	    res += C[acount][j];
	}
    } else {
	res=C[acount][aslots];
    }

    cout<<fixed<<setprecision(9)<<maxavg<<endl<<res<<endl;  

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=1000005;
const int mod=1e9+7;
long long fac[maxn];
long long inv[maxn];
long long san[maxn];
long long two[maxn];
void pre()
{
    fac[0]=fac[1]=1;
    inv[1]=1;san[1]=3;san[0]=1;
    two[0]=1;two[1]=2;
    for(int i=2;i<maxn;i++)
    {
        two[i]=two[i-1]*2%mod;
        san[i]=san[i-1]*3%mod;
        fac[i]=fac[i-1]*i%mod;
        inv[i]=(mod-mod/i)*inv[mod%i]%mod;
    }
    inv[0]=1;
    for(int i=2;i<maxn;i++)
        inv[i]=inv[i-1]*inv[i]%mod;
}
int getc(int a,int b)
{
    if(b<0||b>a) return 0;
    //printf("sss %lld %lld %d\n",fac[a],inv[b],b);
    return fac[a]*inv[b]%mod*inv[a-b]%mod;
}

int main()
{
    int n,m,k;
    pre();
    scanf("%d%d%d",&n,&m,&k);
    int tot=n+m+k;
    if(m>k) swap(m,k);
    long long ans=san[tot-n];
    long long tmp=1;
    for(int i=n+1;i<=tot;i++)
    {
        tmp=tmp*2%mod;
        if(i-n>m){
            tmp=tmp-getc(i-n-1,m);
            if(tmp<0) tmp+=mod;
        }
        if(i-n>k){
            tmp=tmp-getc(i-n-1,k);
            if(tmp<0) tmp+=mod;
        }
        ans=ans+san[tot-i]*getc(i-1,n-1)%mod*tmp%mod;
        //printf("%lld %lld %lld\n",ans,tmp,getc(i-1,n-1));
    }
    printf("%lld\n",ans%mod);
    return 0;
}


Measured memory_bytes: 31488
#include <vector>
#include <map>
#include <queue>
#include <iostream>
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<vector<int>> G(N);
    vector<pair<int, int>> vp;
    for (int i = 1; i < N; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
        vp.emplace_back(a, b);
    }

    int K = 0;
    map<pair<int, int>, int> I;
    vector<int> cs(N, 0); // color of edge between its parent

    vector<int> used(N, 0);
    queue<int> que;
    used[0] = 1;
    que.emplace(0);
    while (!que.empty()) {
        int v = que.front(); que.pop();
        if (K < (int)G[v].size()) K = G[v].size();
        int cur = 1;
        for (int u : G[v]) {
            if (used[u]) continue;
            if (cur == cs[v]) cur++;
            cs[u] = I[make_pair(u, v)] = I[make_pair(v, u)] = cur++;
            used[u] = 1;
            que.emplace(u);
        }
    }

    cout << K << endl;
    for (auto p : vp) cout << I[p] << endl;
    return 0;
}

Measured memory_bytes: 22884
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, k = list(map(int, readline().split()))
    ab = [list(map(int, readline().split())) for _ in range(n)]
    ab.sort()
    t = 0
    for a, b in ab:
        t += b
        if t >= k:
            print(a)
            exit()


if __name__ == '__main__':
    solve()


Measured memory_bytes: 54108
#include<bits/stdc++.h>
using namespace std;
char s[100000],t[100000];
int main(void){
	int n,cnt[30];
	int i,j;
	cin>>n;
	for(i=0;i<n;i++) cin>>s[i];
	for(i=0;i<n;i++) cin>>t[i];
	for(i=0;i<30;i++) cnt[i]=0;
	cnt[s[0]-97]++;
	
	for(i=1;i<n-1;i++){
		if(cnt[t[i]-97]!=0){
			cnt[s[i]-97]+=cnt[t[i]-97];
			if(cnt[s[i]-97]%1000000007!=0){
				cnt[s[i]-97]%=1000000007;
			}
		}
	}
	printf("%d\n",cnt[t[n-1]-97]);
	/*for(j=0;j<30;j++) printf("%c ",j+97);
	printf("\n");
	for(j=0;j<30;j++) printf("%d ",cnt[j]);
	printf("\n");*/
	return 0;
}


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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
template<class T, class S> inline pair<T, S> mp(T x, S y){ return make_pair(x, y); }
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

static const int    INF = 1000000000;
static const ll     MOD = 1000000007LL;
static const double EPS = 1E-12;

const int MAX_N = 1555;
const int MAX_M = 1555;
int h[MAX_N + 1];
int w[MAX_N + 1];
int N, M;

int main()
{
  while(cin >> N >> M, N){
    rep(i, N) cin >> h[i + 1];
    rep(i, M) cin >> w[i + 1];

    rep(i, N) h[i + 1] += h[i];
    rep(i, M) w[i + 1] += w[i];

    vi l, r;
    rep(i, N + 1) rep(j, i) l.pb(h[i] - h[j]);
    rep(i, M + 1) rep(j, i) r.pb(w[i] - w[j]);
    sort(ALL(r));

    int res = 0;
    vrep(v, l) res += upper_bound(ALL(r), *v) - lower_bound(ALL(r), *v);

    cout << res << endl;
  }

  return 0;
}

Measured memory_bytes: 20084
import java.util.*;
import java.lang.Math;

public class Main {
  
  public static int kp(int num) {
    if(num != 1) return num + kp(num-1);
    else return 1;
  }
  public static int km(int num) {
    if(num != 1) return num * km(num-1);
    else return 1;
  }
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int x[] = new int[n];
    int y[] = new int[n];
    double dis = 0;
    double dstack;
    double num;
    
    num = (n-1)/(double)kp(n-1);
      
    for(int i = 0;i < n;i++){
    	x[i] = sc.nextInt();
      	y[i] = sc.nextInt();
    }
    
    for(int i = 0;i < n; i++){
      for(int j = i+1;j < n;j++){
        dstack = Math.pow(x[i]-x[j],2) + Math.pow(y[i]-y[j],2);
        dis += Math.sqrt(dstack);
      }   	
    }
    
    dis *= num; 
    
    System.out.println(dis);
  }
}


Measured memory_bytes: 35808
tst = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
A = [list(map(int, input().split())) for j in range(3)]
N = int(input())
b = [int(input()) for i in range(N)]
for i in b:
    for j in range(3):
        for k in range(3):
            if A[j][k] == i:
                tst[j][k] = 1

if sum(tst[0]) == 3 or \
        sum(tst[1]) == 3 or \
        sum(tst[2]) == 3 or \
        tst[0][0] + tst[1][0] + tst[2][0] == 3 or \
        tst[0][1] + tst[1][1] + tst[2][1] == 3 or \
        tst[0][2] + tst[1][2] + tst[2][2] == 3 or \
        tst[0][0] + tst[1][1] + tst[2][2] == 3 or \
        tst[0][2] + tst[1][1] + tst[2][0] == 3:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
#include <stdio.h>


int main(void){

        int r=0,g=0,b=0;
        int ng = 0;
        long n;

        scanf("%ld",&n);
        char s[n];
        scanf("%s",&s);

        for(int i=0;i<n;i++){           //1つ目の条件を満たしているr*g*bを求められるようにカウントしとく
                if(s[i]=='R'){
                        r++;
                }else if(s[i]=='G'){
                        g++;
                }else{
                        b++;
                }   
        }   

        int k;

        for(int i=0;i<n;i++){                   //i固定
                for(int j=i+1;j<n;j++){         //j固定
                        k = j+(j-i);            //ngのものを計算するためにkをngの条件に設定
                        if(k>=n){               //kがnを超えるものは初めに取り除く
                                continue;
                        }   
                        if((s[i] != s[j]) && (s[j] != s[k]) &&(s[k] != s[i])){//二つ目の条件違反してるけど1つ>目の条件満たしているもの
                                ng++;
                        }   
                }   
        }   

printf("%ld\n",r*g*b-ng);
}



Measured memory_bytes: 1708
#pragma GCC optimize("O2")

#include <bits/stdc++.h>
#ifdef DEBUG
    #include "debug.hpp"
#endif

using namespace std;

#define all(c) (c).begin(), (c).end()
#define traverse(c, it) for(auto it = (c).begin(); it != (c).end(); it++)
#define rep(i, N) for(int i = 0; i < (N); i++)
#define rep1(i, N) for(int i = 1; i <= (N); i++)
#define rep2(i, s, e) for(int i = (s); i <= (e); i++)
#define rep3(i, s, e, d) for(int i = (s); (d) >= 0 ? i <= (e) : i >= (e); i += (d))
#define pb push_back


#ifdef DEBUG
    #define debug(x...) {dbg::depth++; string dbg_vals = dbg::to_string(x); dbg::depth--; dbg::fprint(__func__, __LINE__, #x, dbg_vals);}
    #define light_debug(x) {dbg::light = 1; dbg::dout << __func__ << ":" << __LINE__ << "  " << #x << " = " << x << endl; dbg::light = 0;}
#else
    #define debug(x...)
    #define light_debug(x) 
#endif

template<typename T>
T& ckmin(T& a, T b){ return a = a > b ? b : a; }

template<typename T>
T& ckmax(T& a, T b){ return a = a < b ? b : a; }

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

namespace ioUtils {

    char vector_delimiter = ' ';

    template<typename T>
    istream& operator >>(istream&, vector<T>&);

    template<typename... Ts>
    istream& operator >>(istream& is, pair<Ts...>& p){
        is >> p.first >> p.second;
        return is;
    }

    template<typename T> 
    istream& operator >>(istream& is, vector<T>& v){
        for(auto& e : v) is >> e;
	       return is;
    }

    template<typename T>
    ostream& operator <<(ostream&, vector<T>&);

    template<typename... Ts>
    ostream& operator <<(ostream& os, pair<Ts...>& p){
        os << p.first << " " << p.second;
        return os;
    }

    template<typename T>
    ostream& operator <<(ostream& os, vector<T>& v){
        for(auto&& e : v) os << e << vector_delimiter;
        return os;   
    }   
}

using namespace ioUtils;


int N, W;
vector<pii> a;

ll dp[100][100001];
bool ch[100][100001];

ll rec(int i, int v){
	if(i == N) return v == 0 ? 0 : INT32_MAX;
	if(ch[i][v]) return dp[i][v];
	ch[i][v] = 1;
	dp[i][v] = rec(i + 1, v);
	if(a[i].second <= v)
		ckmin(dp[i][v], a[i].first + rec(i + 1, v - a[i].second));
	return dp[i][v];
}	

signed main(){

    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    #ifdef DEBUG
        freopen("debug", "w", stderr);
    #endif
    
    cin >> N >> W;
    a.resize(N);
    cin >> a;

    rep3(i, 100000, 0, -1)
    	if(rec(0, i) <= W){
    		cout << i << '\n';
    		break;
    	}

    #ifdef DEBUG
        dbg::dout << "\nExecution time: " << clock() << "ms\n";
    #endif

    return 0;
}


Measured memory_bytes: 91300
#include <bits/stdc++.h>
using namespace std;
 
  int main() {
  int N ; //団体の数
  cin >>N;
  int x=0; //入場者数

  int l,r ; //団体はlからrの席まで続けて座る。rが多いほう
  //団体の数の回数だけlからrまで座っている人数を数える r-l+1で求められるか
  for(int i = 0;i<N;i++)
 {
  //団体の座った席の番号の入力受付
  cin >>l >>r;
  x+=r-l+1;  //入場者数に加えていく
 }

  cout << x <<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

const int mod = 1000000007;
class mint {
    long long x;
public:
    mint(long long x=0) : x((x%mod+mod)%mod) {}
    mint operator-() const { 
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }
 
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};
 
struct combination {
  vector<mint> fact, bfact;
  combination(int n, int k):fact(k+1),bfact(k+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= k; ++i) fact[i] = fact[i-1]*i;
    bfact[0] = 1;
    for (int i = n; i >= n-k+1; --i) bfact[n-i+1] = bfact[n-i]*i;
  }
  mint operator()(int k) {
    //if (k < 0 || k > n) return 0;
    return bfact[k]*fact[k].inv();
  }
};


int main(){
    ll N,a,b;
    cin >> N >> a >> b;
    mint sum = 2;
    sum = sum.pow(N);
    combination comb(N,min(N,200010LL));
    sum -= 1;

    cout << sum - comb(a) - comb(b) << endl;
}

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

#define INF 2147483647
#define LINF 9223372036854775807
#define MOD 1000000007
#define MOD2 998244353

template<class T,class U>bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U>bool chmin(T &a, const U &b){if(b<a){a=b;return 1;}return 0;}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;
typedef long double ld;

typedef pair<int,int> P;
typedef pair<int,P> iP;
typedef pair<P,P> PP;

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

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

std::chrono::system_clock::time_point start;
std::chrono::system_clock::time_point owari;

double TimeLeft(){
    owari = std::chrono::system_clock::now();
    double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(owari-start).count();
    return elapsed;
}



int d=365;
int c[26]={};
int s[365][26]={};


struct sl{
    ll score=0;
    vector<int> arr;
    sl(){
        arr.resize(365);
    }
};


ll sigk(ll n){
    return n*(n+1)/2;
}

ll calcScore(sl old){

    ll ret = 0;
    rep(i,d){
        old.score += s[i][ old.arr[i] ];
        ret += s[i][ old.arr[i] ];
    }

    int lastheld[365]={};
    rep1(i,1,d+1){

        int today = old.arr[ i-1 ];
        int dur = i - lastheld[today];

        old.score -= sigk(dur-1)*c[today];
        ret -= sigk(dur-1)*c[today];
        lastheld[today] = i;
    }

    return ret;
}

int main(){

    start = std::chrono::system_clock::now(); //Timer start
    clock_t stt = clock();
    std::random_device rnd;

    bool flag=false;
    ll ans=0,sum=0;

    cin>>d;

    rep(i,26){
        cin>>c[i];
    }

    sl old;
    rep(i,d){
        int Conf=0,Tp=-1;
        rep(j,26){
            cin>>s[i][j];
            if(chmax(Conf,s[i][j]))Tp=j;
        }
        old.arr[i]=Tp;
    }

    old.score = calcScore(old);

    start = std::chrono::system_clock::now(); //Timer start
    stt = clock();

    clock_t now;
    while(1){
        sl nw = old;

        int cd = rnd()%d;
        int cT = rnd()%26;
        while(nw.arr[cd] == cT)cT = rnd()%26;

        nw.arr[cd] = cT;
        nw.score = calcScore(nw);

        if(nw.score > old.score)old = nw;


        now = clock();
        //cout<<fixed<<setprecision(6)<<(double)(now - stt)/CLOCKS_PER_SEC<<endl;
        if((double)(now - stt)/CLOCKS_PER_SEC > 1.95)break;
    }

    ln;
    for(int ai:old.arr)cout<< ai+1 <<endl;

    //cout <<fixed<<setprecision(16)<< << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;

    return 0;
}


Measured memory_bytes: 3696
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
[n,w]=i2()
a=[]
dp=[[-1 for j in range(100400)]for i in range(n+1)]
dp[0][0]=0
for i in range(n):
 a.append(i2())
b=a[0][0]
c=0
for i in range(1,n+1):
 for j in range(100400):
   dp[i][j]=max(dp[i][j],dp[i-1][j])
   k1=j//1000
   k2=j%1000
   if k1*b+k2<=w and j-1000-a[i-1][0]+b>=0 and dp[i-1][j-1000-a[i-1][0]+b]>=0:
     if dp[i][j]<dp[i-1][j-1000-a[i-1][0]+b]+a[i-1][1]:
        dp[i][j]=dp[i-1][j-1000-a[i-1][0]+b]+a[i-1][1]

   if c<dp[i][j]:
     c=dp[i][j]
     
print(c)

Measured memory_bytes: 173192
import java.util.Scanner;
 
public class Main{
	public static void main(String[] args){
    	
      Scanner scan = new Scanner(System.in);
      String a = scan.next();
      if (a.charAt(0) == a.charAt(1) || a.charAt(1) == a.charAt(2) || a.charAt(2) == a.charAt(3)){
        System.out.print("Bad");
      }else{
        System.out.print("Good");
      }
    }
}

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

long long GCD(long long X, long long Y){
  while(X % Y != 0){
    long long Z = X % Y;
    X = max(Y, Z);
    Y = min(Y, Z);
  }
  return Y;
}

int main(){
  long long x, y;
  cin >> x >> y;
  long long X = max(x, y);
  long long Y = min(x, y);
  long long ans = GCD(x, y);
  cout << ans << endl;
}


Measured memory_bytes: 3112
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    int n, m; std::cin >> n >> m;
    std::map<int, int> cnt;
    for (int i = 0; i < m; i++) {
        int a, b; std::cin >> a >> b;
        cnt[a]++; cnt[b]++;
    }
    bool even = true;
    for (auto &p : cnt) {
        even &= ~p.second & 1;
    }
    std::cout << (even ? "YES" : "NO") << std::endl;
    return 0;
}


Measured memory_bytes: 4352
#include <stdio.h>

int main(void) {
	/*
    西暦年が 4 で割り切れる年であること。
    ただし、100 で割り切れる年はうるう年としない。
    しかし、400 で割り切れる年はうるう年である。
	*/
	int s, e;
	int i, f, b;
	
	b = 0;
	while(scanf("%d %d\n", &s, &e) == 2) {
		if(s == 0 && e == 0) break;
		
		if(b) printf("\n");
		
		f = 0;
		for(i=s;i<=e;i++) {
			if(i%400==0) {
				printf("%d\n", i);
				f = 1;
			} else if(i%100==0) {
				continue;
			} else if(i%4==0) {
				printf("%d\n", i);
				f = 1;
			}
		}
		
		if(!f) printf("NA\n");
		b = 1;
	}
	
	return 0;
}

Measured memory_bytes: 616
from itertools import accumulate
import sys
def LI(): return [int(x) for x in sys.stdin.readline().split()]

def solve():
    n,q = LI()
    a = LI()
    X = LI()
    for x in X:
        ans = 0
        l = 0
        s = 0
        for r in range(n+1):
            while s > x:
                s -= a[l]
                l += 1
            ans += r-l
            if r < n:
                s += a[r]
        print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 16892
#include<bits/stdc++.h>
#define rep(i, n) for(i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007
#define PI 3.14159265359
 
int main(){
  ll X, A, B, i, j;
  
  cin >> X;
  
  for (ll A = -120; A <= 120; A++){
    for(ll B = -120; B <= 120; B++){
      if(pow(A, 5) - pow(B, 5) == X){
        cout << A << " " << B << endl;
        return 0;
      }
    }
  }
  
  return 0;
}

Measured memory_bytes: 4068
import sys
for x in sys.stdin.readlines():
    a=float(x.rstrip())
    s=[0.0]*10
    s[0]=a
    for i in range(1,10):
        if i%2 != 0: s[i]=s[i-1]*2.0
        else:        s[i]=s[i-1]/3.0
    print sum(s)

Measured memory_bytes: 4248
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>

using namespace std;
 
int main() {
    double n;cin>>n;
    for(int i = 0;i<50000;i++){
    	double k = i;
        int a = i*1.08;
        if(a == n){
          cout<<i;
          return 0;
        }   
    }
    cout<<":(";
    return 0;
}

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

int main() {
  int D;
  cin >> D;
  
  vector<int> c(27), tmp(27);
  vector<vector<int>> s(D+1 , vector<int>(27));
  for (int i = 1; i <= 26; i++)  cin >> c.at(i);
  for (int i = 1; i <= D; i++)  for(int j = 1; j <= 26; j++)  {
    cin >> s.at(i).at(j);
  }
  
  vector<int> last(27);
  for (int i = 1; i <= 26; i++) last.at(i) = 0;
  
  vector<int> t(D+1);
  for (int i = 1; i <= D; i++)  cin >> t.at(i);
  
  int M;
  cin >> M;
  
  vector<int> dd(M+1), qq(M+1);
  for (int i = 1; i <= M; i++) cin >> dd.at(i) >> qq.at(i);
  
  int sf = 0;
  
  for (int k = 1; k <= M; k++) {
    int oldsf = sf;
    sf = 0;
    for (int i = 1; i <= 26; i++) last.at(i) = 0;
    
    t.at(dd.at(k)) = qq.at(k);
    
    for (int i = 1; i <= D; i++) {
      sf += s.at(i).at(t.at(i));
      last.at(t.at(i)) = i;

      for (int j = 1; j <= 26; j++) {
        sf -=c.at(j)*(i-last.at(j));
      }

    }
    cout << sf << endl;
  }
}

Measured memory_bytes: 3808