akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)

int main()
{
    int N;
    cin >> N;
    int A[N+10];
    rep1(i,N) cin >> A[i];
    A[0] = 0;
    A[N+1] = 0;

    int distance[N+10];
    ll sum = 0;
    rep(i,N+1)
    {
        distance[i] =  max(A[i+1] - A[i], A[i] - A[i+1]);
        sum += distance[i];
    } 
    
    rep1(i,N)
    {
        cout << sum - distance[i-1] - distance[i] + max(A[i-1]-A[i+1], A[i+1]-A[i-1]) << endl;
    }
    
}

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

int main(){
  
  int n,k;
  cin >> n >>k;
  int cnt = 1;
  
  for(int i = 0; i < n; i++){
     if(cnt > k)
       cnt += k;
     else
       cnt *= 2;
  }
    cout << cnt << endl;

}
    


Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int main(){
    int n,a,b,c,d,flag=0;
    char s[200010];
    scanf("%d %d %d %d %d",&n,&a,&b,&c,&d);
    scanf("%s",s);
    if(s[c-1]=='#'||s[d-1]=='#'){
        printf("No\n");
        return 0;
    }
    if(c>d){
        for(int i=a-1;i+2<=c-1;i++){
            if(s[i+1]=='#'&&s[i+2]=='#'){
                printf("No\n");
                return 0;
            }
            if(s[i]=='.'&&s[i+1]=='.'&&s[i+2]=='.'&&i+2>b-1&&i+2<=d){
                flag=1;
            }
        }
        if(flag==0){
            printf("No\n");
            return 0;
        }
    }
    else{
        for(int i=b-1;i+2<=d-1;i++){
            if(s[i+1]=='#'&&s[i+2]=='#'){
                printf("No\n");
                return 0;
            }
        }
        for(int i=a-1;i+2<=c-1;i++){
            if(s[i+1]=='#'&&s[i+2]=='#'){
                printf("No\n");
                return 0;
            }
        }
    }
    printf("Yes\n");
}

Measured memory_bytes: 384
while True:
	try:
		a,b,c,d,e,f=list(map(float,input().split()))
		x=float((b*f-c*e)/(b*d-a*e))
		y=float((c*d-a*f)/(b*d-a*e))
		if x==-0.000:
			x=0.000
		if y==-0.000:
			y=0.000
		print("{0:.3f} {1:.3f}".format(x,y))
	except:
		break


Measured memory_bytes: 5580
# include <cstdio>
# include <iostream>
# include <algorithm>
# include <cmath>
using namespace std;
int n,m;
int sto[12][12];
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>sto[i][j];
		}
	}
	int cnt=0;
	for(int i=1;i<n;i++){
		for(int j=i+1;j<=n;j++){
			int x=i,y=j;
			double q=0;
			for(int k=1;k<=m;k++){
				int t=sto[x][k]-sto[y][k];
				q=q+t*t;
			}
			q=sqrt(q);
			if(q==floor(q)) cnt++;
		}
	}
	cout<<cnt;
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include<algorithm>
#include <string>
#include <cmath>
#include<queue>
#define PI 3.141592653589793238
#define ll long long
using namespace std;

int main()
{
	ll int s, t, k;

	cin >> s >> t >> k;

	if (s < k) {
		if (s + t < k) {
			t = 0LL;
		} else {
			t = t - k + s;
		}
		s = 0LL;
	} else {
		s -= k;
	}

	printf("%lld %lld", s, t);

	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [0] + list(map(int, input().split())) + [0]

total = 0
for i in range(N + 1):
    total += abs(A[i + 1] - A[i])

for i in range(1, N + 1):
    if A[i - 1] <= A[i] <= A[i + 1] or A[i + 1] <= A[i] <= A[i - 1]:
        print(total)
    else:
        print(total - min(abs(A[i] - A[i - 1]), abs(A[i] - A[i + 1])) * 2)


Measured memory_bytes: 14048
// Copyright (C) 2017 __debug.

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; version 3

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; If not, see <http://www.gnu.org/licenses/>.


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/priority_queue.hpp>

#define x first
#define y second
#define MP std::make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#ifdef __linux__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif

using std::pair;
using std::vector;
using std::string;

typedef long long LL;
typedef pair<int, int> Pii;

const int oo = 0x3f3f3f3f;

template<typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, true : false; }
template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, true : false; }
string procStatus()
{
    std::ifstream t("/proc/self/status");
    return string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}
template<typename T> T read(T &x)
{
    int f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar())
        f = (ch == '-' ? -1 : 1);
    for (x = 0; isdigit(ch); ch = getchar())
        x = 10 * x + ch - '0';
    return x *= f;
}
template<typename T> void write(T x)
{
    if (x == 0) {
        putchar('0');
        return;
    }
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    static char s[20];
    int top = 0;
    for (; x; x /= 10)
        s[++top] = x % 10 + '0';
    while (top)
        putchar(s[top--]);
}
// EOT

const int MAXN = 1e5 + 5;

int N;
LL A[MAXN];

void input()
{
    read(N);
    for (int i = 1; i <= N; ++i) {
        read(A[i]);
    }
}

LL calc()
{
    LL ret = 0, add = 0;
    for (int i = 1; i <= N; ++i) {
        LL cur = A[i] + add;
        if (i & 1) {
            if (cur <= 0) {
                add += 1 - cur;
                ret += 1 - cur;
            }
        } else {
            if (cur >= 0) {
                add -= cur + 1;
                ret += cur + 1;
            }
        }
    }
    return ret;
}

void solve()
{
    for (int i = 1; i <= N; ++i) {
        A[i] += A[i - 1];
    }
    LL ans = calc();
    for (int i = 1; i <= N; ++i) {
        A[i] = -A[i];
    }
    chkmin(ans, calc());
    printf("%lld\n", ans);
}

int main()
{
#ifdef __DEBUG
    freopen("C.in", "r", stdin);
    freopen("C.out", "w", stdout);
#endif

    input();
    solve();

    return 0;
}

// 更无柳絮因风起，惟有葵花向日倾。
//     -- 司马光《客中初夏》


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define ll long long
using namespace std;
int main(){
	ll n;
	cin>>n;
	vector<ll> a;
	a.pb(1145141919);
	for(int i=1;i<=3*n;i++){
		ll tmp;
		cin>>tmp;
		a.pb(tmp);
	}
	sort(a.begin(),a.end(),greater<ll>());
	ll ans = 0;
	for(int i=1;i<=n;i++){
		ans+= a[2*i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 6256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
const ll mod = 1000000007;
const ll INF = 9223372036854775807;
#define Sort(a) sort(a.begin(), a.end())
#define Bsort(a) sort(a.begin(), a.end(), greater<ll>())
#define Pi acos(-1)

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  vector<ll> a(3);
  cin >> a[0] >> a[1] >> a[2];
  Sort(a);
  if (a[0]==5 && a[1]==5 && a[2]==7) {
    cout << "YES" << '\n';
  }
  else {
    cout << "NO" << '\n';
  }
}

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

import bisect

mid = (a[-1]+1)//2
mid_idx = bisect.bisect_left(a, mid)

if abs(mid - a[mid_idx-1]) <= abs(a[mid_idx] - mid):
    print(a[-1], a[mid_idx-1])
else:
    print(a[-1], a[mid_idx])

Measured memory_bytes: 85712
#include<bits/stdc++.h>
#define REP(i,n) for(long long i = 0;i < n;++i)
#define FOR(i,a,b) for(long long i = a;i < b;++i)
using namespace std;
using ll = long long;
using point = pair< int,int >;

int main() {
    int i, uru;
    ll y, m, d;
    ll b, ka, t, w, ki;
    ll year, month, day;
    ll sum;
    string str;
    const int table[][13] = {{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
                             {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}};

    while (cin >> str) {
        if (str == "#") break;
        if (count(str.begin(), str.end(), '.') == 4) {
            sscanf(str.c_str(), "%lld.%lld.%lld.%lld.%lld", &b, &ka, &t, &w, &ki);

            sum = ki + w * 20 + t * 360 + ka * 7200 + b * 144000;
            for (i = 0, year = 2012, month = 12, day = 21; i < sum; ++i) {
                uru = (year % 400 == 0 || year % 100 && year % 4 == 0);
                day++;
                if (table[uru][month] < day) {
                    day = 1;
                    month++;
                }
                if (month > 12) {
                    month = 1;
                    year++;
                }
            }

            printf("%lld.%lld.%lld\n", year, month, day);
        } else {
            sscanf(str.c_str(), "%lld.%lld.%lld", &y, &m, &d);

            sum = (y - 2013) * 365 + 10;
            if (y == 2012) sum--;
            uru = (y % 400 == 0 || y % 100 && y % 4 == 0);
            for (i = 2013; i < y; ++i) {
                sum += (i % 400 == 0 || i % 100 && i % 4 == 0);
            }
            for (i = 1; i < m; ++i) {
                sum += table[uru][i];
            }
            sum += d;

            printf("%lld.%lld.%lld.%lld.%lld\n", sum / 144000 % 13, sum / 7200 % 20, sum / 360 % 20, sum / 20 % 18, sum % 20);
        }
    }

    return 0;
}




Measured memory_bytes: 3332
#include<bits/stdc++.h>
using namespace std;
const int maxm=1e5+5;
vector<int>adj[maxm];
int indegree[maxm];
int dist[maxm];
bool vis[maxm];
void max_self(int &a,int b)
{
	a=max(a,b);
}
void dfs(int a)
{
	vis[a]=1;
	for(int b:adj[a])
	{
       max_self(dist[b],dist[a]+1);
       --indegree[b];
       if(indegree[b]==0)dfs(b);
	}
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n,m;cin>>n>>m;
  int x,y;
  for(int i=0;i<m;i++)
  {
  	cin>>x>>y;
  	adj[x].push_back(y);
  	indegree[y]++;
  }
  for(int i=1;i<=n;i++)
  {
  	if(!vis[i] and indegree[i]==0)dfs(i);
  }
  int answer=0;
  for(int i=1;i<=n;i++)
  {
  	max_self(answer,dist[i]);
  }
  cout<<answer;
}

Measured memory_bytes: 9728
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9 + 7

a,b,c,d = map(int,input().split())
print(max(a*b,c*d))

Measured memory_bytes: 3316
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_imports)]
use std::collections::HashSet;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::VecDeque;
use std::cmp::{max, min};
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        N: usize,
        F: [[i64; 10]; N],
        P: [[i64; 11]; N],
    }
    let mut res = std::i64::MIN;
    for b in 1..(1 << 10) {
        let mut cc = 0;
        for i in 0..N {
            let mut c = 0;
            for j in 0..10 {
                if b >> j & 1 == 1 && F[i][j] == 1 {
                    c+=1;
                }
            }
            cc += P[i][c];
        }
        res = if res < cc {cc} else {res};
    }
    println!("{}", res)
}

Measured memory_bytes: 4352
while 1:
    a, l = input().split()
    if a=='0' and l == '0':break
    l = int(l)
    a = ''.join(a.zfill(l))
    a_lst = [a]
    while 1:
        a = ''.join(sorted(a))
        a_r = ''.join(reversed(a))
        a = str(int(a_r) - int(a)).zfill(l)
        if a in a_lst:
            j = a_lst.index(a)
            print('%d %d %d' % (j, int(a), len(a_lst) - j))
            break
        a_lst.append(a)

Measured memory_bytes: 6724
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val k = sc.nextInt()
    val c = sc.nextInt()
    val s = sc.nextLine()
    val dp1 = Array(n) { 0 }
    dp1[0] = if (s[0] == 'o') 1 else 0
    for (i in 1 until n) {
        if (s[i] == 'x') {
            dp1[i] = dp1[i - 1]
        } else if (i - c - 1 < 0) {
            dp1[i] = 1
        } else {
            dp1[i] = dp1[i - c - 1] + 1
        }
    }
    val dp2 = Array(n) { 0 }
    dp2[n - 1] = if (s[n - 1] == 'o') 1 else 0
    for (i in n - 2 downTo 0) {
        if (s[i] == 'x') {
            dp2[i] = dp2[i + 1]
        } else if (i + c + 1 >= n) {
            dp2[i] = 1
        } else {
            dp2[i] = dp2[i + c + 1] + 1
        }
    }
    for (i in 0 until n) {
        val v1 = if (i == 0) 0 else dp1[i - 1]
        val v2 = if (i == n - 1) 0 else dp2[i + 1]
        if (s[i] == 'o' && v1 + v2 == k - 1) {
            println(i + 1)
        }
    }
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


Measured memory_bytes: 48420
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<functional>
#include<numeric>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))

#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int main(){
  string str;
  int cnt[128] = { 0 };
  cin >> str;
  
  FOR(it, str) cnt[*it]++;

  int ans = min(cnt['K'], min(cnt['U'], min(cnt['P'], cnt['C'])));

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 0
n = int(input())
p = [int(x) for x in input().split()]

ans = 0
for i in range(n):
    if p[i] == i+1:
        if i+1 < n:
            p[i],p[i+1] = p[i+1],p[i]
        ans += 1
print(ans)    


Measured memory_bytes: 13880
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
#define fast() ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define digit(N) cout << fixed << setprecision((N))

string s, t = "";

int main()
{
    cin >> s;

    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] == '1')
            t.push_back('1');
        else if (s[i] == '0')
            t.push_back('0');
        else
        {
            if (t == "")
                continue;
            else
                t.erase(t.begin() + (int)t.size() - 1);
        }
    }
    cout << t << "\n";
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define bit(n,m)(((n)>>(m))&1)
#define min(p,q)((p)<(q)?(p):(q))

ll a[20];
ll s[110];
ll ans[1<<15];
int main(){
	int n,m;
	while(scanf("%d%d",&n,&m),n){
		rep(i,0,n)scanf("%lld",a+i);
		rep(i,0,m)scanf("%lld",s+i);
		rep(i,1,1<<n)ans[i]=1e9;
		rep(i,1,1<<n){
			//もらうDP
			ll sum=0;
			rep(k,0,n)if(bit(i,k))sum+=a[k];
			rep(k,0,n)if(bit(i,k)){
				int be=i^(1<<k);
				ll temp=0;
				rep(x,0,m)if(sum-a[k]<=s[x]&&s[x]<sum)temp+=min(llabs(s[x]-(sum-a[k])),llabs(s[x]-sum));
				ans[i]=min(ans[i],ans[be]+temp);
			}
		}
		ll sum=0;
		rep(k,0,n)sum+=a[k];
		ll temp=0;
		rep(x,0,m)if(sum<=s[x])temp+=llabs(s[x]-sum);
		printf("%lld\n",ans[(1<<n)-1]+temp);
	}
}


Measured memory_bytes: 2060
#include<stdio.h>

int parent(int);
int left(int);
int right(int);

int main(){
  int n,i,A[100000];
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
  }
  for(i=1;i<=n;i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(parent(i)>=1) printf("parent key = %d, ",A[parent(i)]);
    if(left(i)<=n) printf("left key = %d, ",A[left(i)]);
    if(right(i)<=n) printf("right key = %d, ",A[right(i)]);
    printf("\n");
  }
  return 0;
}

int parent(int i){
  return i/2;
}

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

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



Measured memory_bytes: 2108
#include<iostream>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<map>
#include<set>
#include<fstream>
#include<sstream>
#include<queue>
#include<iterator>
#include<stack>

using namespace std;

typedef long long ll;
typedef short int si;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<pli> vpli;

#define st first
#define nd second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REV(a) reverse((a).begin(),(a).end())
#define SORT(a) sort((a).begin(),(a).end())
#define inf (int)1e9
#define linf (ll)1e18
#define mod (int)1e8

int n,a[100000],b[100000],c[100000];
ll ans=0;
int main() {
		ios::sync_with_stdio(false);
		cin>>n;
		FOR(i,0,n)cin>>a[i];
		sort(a,a+n);
		FOR(i,0,n)cin>>b[i];
		FOR(i,0,n)cin>>c[i];
		sort(c,c+n);
		FOR(i,0,n){
				ll j,k;
				j=lower_bound(a,a+n,b[i])-a;
				k=upper_bound(c,c+n,b[i])-c;
				k=n-k;
				ans+=j*k;
		}
		cout<<ans<<endl;
		





		return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int N,M,x; cin>>N>>M;
	multiset<int> A;
	for (int i=0; i<N; i++)
		cin>>x, A.insert(x);
	vector<ii> v(M);
	for (int i=0; i<M; i++)
		cin>>v[i].second>>v[i].first;
	sort(v.rbegin(),v.rend());
	int iter=0;
	for (int i=0; i<M; i++) {
		for (int j=0; j<v[i].second; j++) {
			if(iter==N)
				break;
			A.insert(v[i].first); iter++;
		}
	}
	ll ret=0;
	while(N--) {
		int cur=*A.rbegin();
		ret+=cur; A.erase(A.find(cur));
	}
	cout<<ret<<"\n";
	return 0;
}

Measured memory_bytes: 10368
#include<iostream>
#include<queue>
#include<utility>
#include<cstring>
using namespace std;
#define INF 10000000
#define rep(i,s,t) for(int i=s;i<=(t);i++)
#define MP(a,b) make_pair(a,b)
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int h,w,n;
char m[1002][1002];

int bfs(int s){
	static int d[1002][1002];
	queue<pair<int,int> > q;
	pair<int,int> a,b;
	rep(i,1,h)rep(j,1,w)
		if(m[i][j]=='0'+s){
			d[i][j]=0;
			q.push(MP(i,j));
		}
		else d[i][j]=INF;
	while(1){
		a = q.front();
		q.pop();
		rep(k,0,3){
			b = MP(a.first+dy[k],a.second+dx[k]);
			if(m[b.first][b.second]=='X')continue;
			if(d[a.first][a.second]+1 < d[b.first][b.second]){
				d[b.first][b.second] = d[a.first][a.second]+1;
				if(m[b.first][b.second]=='0'+s+1)return d[b.first][b.second];
				q.push(b);
			}
		}
	}
	return -1;
}
int main(){
	cin>>h>>w>>n;
	memset(m,'X',sizeof(m));
	rep(i,1,h)rep(j,1,w){
		cin>>m[i][j];
		if(m[i][j]=='S')m[i][j]='0';
	}
	int ans=0;
	rep(i,0,n-1)ans += bfs(i);
	cout<<ans<<endl;
}

Measured memory_bytes: 6116
#include <bits/stdc++.h>
#define REP(i, n) for (int i=0, i##_len=(n); i<i##_len; ++i)
#define FOR(i, a, b) for (int i=(a); i<(b); ++i)
using ll = long long;
using namespace std;

int main()
{
    int N, K;
    string S;
    cin >> N;
    cin >> S;
    cin >> K;
    --K;

    REP(i, N)
    {
        cout << (S[i] == S[K] ? S[K] : '*');
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include<string>
#include<cmath>
#include<stack>
#include <vector>
#include<queue>
#include <random>
using namespace std;



int main() {
	int min,max,ans=0;
	cin >> min >> max;
	for (int a = 0; a <= 9; a++) {
		for (int b = 0; b <= 9; b++) {
			for (int c = 0; c <= 9; c++) {
				if (a * 10001 + b * 1010 + c * 100<=max&& a * 10001 + b * 1010 + c * 100 >=min) {
					ans++;
					}
			}
		}
	}
	cout << ans<<endl;
	return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
typedef vector<ll> vl;
#define rp(i, f, t) for (int i = f; i < t; i++)
#define pr(i, f, t) for (int i = t - 1; i >= f; i--)
#define ca(n, a) rp(ca_i, 0, n) cout << a[ca_i] << ((ca_i == n - 1) ? "\n" : " ")
#define za(n, a) rp(za_i, 0, n) a[za_i] = 0
#define be(a) a.begin(), a.end()
#define ce(a) cout << (a) << endl
int main()
{
    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll r = 0, g = 0, b = 0;
    rp(i, 0, n)
    {
        if (s[i] == 'R')
            r++;
        if (s[i] == 'G')
            g++;
        if (s[i] == 'B')
            b++;
    }
    ll ans = r * g * b;
    rp(i, 0, n)
    {
        rp(j, 0, i)
        {
            if (i - j - 1 >= 0 && i + j + 1 <= n - 1 && s[i] != s[i - j - 1] && s[i - j - 1] != s[i + j + 1] && s[i + j + 1] != s[i])
            {
                ans--;
            }
        }
    }
    ce(ans);
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){
    long n,ans=0; cin>>n;
    ans+=(n-1)/11*2;
    if(0<n%11 and n%11<7) ans+=1;
    else ans+=2;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import sys,heapq,math,resource
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

def setrlim():
  sys.setrecursionlimit(250000)
  soft,hard = resource.getrlimit(RLIMIT_STACK)
  # setrlimit works on ubuntu (and atcoder), but not on WSL
  #resource.setrlimit(RLIMIT_STACK, (128*1024*1024,hard))

n,m = inm()
jobsByDay = [ [] for i in range(m+1) ]
for i in range(n):
    a,b = inm()
    if a <= m:
        jobsByDay[a].append(-b)

sum = 0
hp = []
for d in range(1,m+1):
    for x in jobsByDay[d]:
        heapq.heappush(hp, x)
    if len(hp)>0:
        sum += -heapq.heappop(hp)

print(sum)


Measured memory_bytes: 17916
#include<stdio.h>
int main(){
  int r,d,x,result;
  scanf("%d%d%d",&r,&d,&x);
  result=x;
  for(int i=0;i<10;i++){
    result=result*r-d;
    printf("%d\n",result);
  }
  return 0;
}

Measured memory_bytes: 128
int main() {
    //変数の宣言
    int m, f, r; //中間、期末、再試験
    
    //入力〜
    while (1) {
        scanf("%d %d %d", &m, &f, &r);
        
        if (m == -1 && f == -1 && r == -1) { //入力終了
            break;
        }
        
        if (m == -1 || f == -1) {
            printf("F\n");
        }else if (m+f >= 80) {
            printf("A\n");
        }else if (m+f >= 65) {
                printf("B\n");
        }else if (m+f >= 50) {
                printf("C\n");
        }else if (m+f >= 30) {
            if (r >= 50) {
                printf("C\n");
            }else{
                printf("D\n");
            }
        }else{
            printf("F\n");
        }
    }
    
    
    return 0;
}



Measured memory_bytes: 2048
#include <stdio.h>

int main (int argc, const char * argv[]) {
    int data[10];
	int i,j;
	int cache;
	
	for (i=0; i<10; i++) {
		scanf("%d", &data[i]);
	}
	
	for (i=0; i<10; i++) {
		for (j=i; j<10; j++) {
			if (data[i] < data[j]) {
				cache = data[i];
				data[i] = data[j];
				data[j] = cache;
			}
		}
	}
	
	for (i=0; i<3; i++) {
		printf("%d\n", data[i]);
	}
	
    return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int flag[100],n,k,x;
int check(int x){
	while (x){
		if (flag[x%10])return 0;
		x/=10;
	}
	return 1;
}
int main(){
	scanf("%d%d",&n,&k);
	while (k--)scanf("%d",&x),flag[x]=1;
	while (!check(n))n++;
	printf("%d\n",n);
}

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

using i64 = int_fast64_t;
using f64 = double;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

i64 n, a, b, c;
vector<string> ss;
vector<char> ans;
set<tuple<i64, i64, i64, i64>> dp;

bool dfs(i64 depth, i64 x, i64 y, i64 z) {
    if (dp.find({ depth, x, y, z }) != dp.end()) return false;
    if (x < 0 || y < 0 || z < 0) return false;
    if (depth == n) return true;

    i64 na, nb, nc;
    if (ss[depth] == "AB") {
        na = x + 1, nb = y - 1, nc = z;
    } else if (ss[depth] == "AC") {
        na = x + 1, nb = y, nc = z - 1;
    } else {
        na = x, nb = y + 1, nc = z - 1;
    }

    ans.push_back(ss[depth][0]);
    if (dfs(depth + 1, na, nb, nc)) return true;
    ans.pop_back();

    if (ss[depth] == "AB") {
        na = x - 1, nb = y + 1, nc = z;
    } else if (ss[depth] == "AC") {
        na = x - 1, nb = y, nc = z + 1;
    } else {
        na = x, nb = y - 1, nc = z + 1;
    }

    ans.push_back(ss[depth][1]);
    if (dfs(depth + 1, na, nb, nc)) return true;
    ans.pop_back();

    dp.emplace(depth, x, y, z);
    return false;
}

void solve() {
    cin >> n >> a >> b >> c;
    ss.resize(n);
    for (auto& e : ss) cin >> e;

    if (dfs(0, a, b, c)) {
        cout << "Yes" << endl;
        for (auto& e : ans) cout << e << endl;
    } else {
        cout << "No" << endl;
    }
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


Measured memory_bytes: 15000
N = int(input())
M = 26
tmp = N
out = ''
while tmp > 0:
    res = tmp % M
    if res == 0:
        c = "z"
        tmp -= 26
    else:
        c = chr(ord('a') + tmp % M - 1)
    out = str(c) + out
    tmp = int(tmp/M)
print(out)


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

int main() {
	int N;
	cin >> N;
	char S[100];
	int i;
	for (i = 0; i < N; i++) {
		cin >> S[i];
	}
	int y = 0;
	for (i = 0; i < N; i++) {
		if (S[i] == 'Y') {
			y++;
			break;
		}
	}
	if (y > 0) {
		cout << "Four";
	}
	else {
		cout << "Three";
	}
}


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

map<pair<int, int>, int> m;
int an[10];

int main() {
	int h, w, n;
	scanf("%d%d%d", &h, &w, &n);
	while (n--) {
		int a, b;
		scanf("%d%d", &a, &b);
		f(i, 0, 3)f(j, 0, 3) {
			int x = a - i, y = b - j;
			if (x <= 0 || x + 2 > h || y <= 0 || y + 2 > w)continue;
			++m[make_pair(x, y)];
		}
	}
	printf("%lld\n", (ll)(w - 2)*(h - 2) - m.size());
	for (map<pair<int, int>, int>::iterator it = m.begin(); it != m.end(); ++it)++an[it->second];
	f(i, 1, 10)printf("%d\n", an[i]);
}

Measured memory_bytes: 56448
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}
template<typename T>vector<T> & cset(vector<T> &A,T e=T()){for(auto &I:A){I=e;} return A;}


int main(){
  ll n;
  cin>>n;
  vector<ll> A(n+1),B(n);
  cin>>A>>B;
  ll ans=0;
  for(int i=0;i<n;i++){
    ans+=min(A[i],B[i]);
    B[i]-=min(A[i],B[i]);
    ans+=min(A[i+1],B[i]);
    A[i+1]-=min(A[i+1],B[i]);
  }
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 1792
// dile a la jardinera que traigo flores

#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define sz(x) int(x.size())
#define all(v) (v).begin(),(v).end()
#define trace(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define FER(i,a,b) for(int i = int(a); i < int(b); ++i)
#define IFR(i,a,b) for(int i = int(a); i >= int(b); i--)
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;


int main(){	
	fastio;
	int n;cin>>n;
	if(n==22)cout<<"Christmas Eve Eve Eve"<<endl;
	if(n==23)cout<<"Christmas Eve Eve"<<endl;
	if(n==24)cout<<"Christmas Eve"<<endl;
	if(n==25)cout<<"Christmas"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;

void solve() {
  int n;
  cin >> n;
  vll a(n);
  rep(i,n) cin >> a[i];
  string s;
  cin >> s;
  vll basis;
  bool ok = true;
  per(i,n) {
    ll v = a[i];
    for(auto x : basis) v = min(v,v^x);
    if(v) {
      if(s[i]=='1') {
        cout << 1 << endl;
        return;
      }
      basis.push_back(v);
    }
  }
  cout << 0 << endl;
  return;
}

int main() {
  int T;
  cin >> T;
  rep(_,T) solve();
  return 0;
}

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

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

int MOD = 1e9 + 7;
ll INF = 1e18;

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

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

    bool flag=true;
    for(int i=0; i<n; i++){
        int dt=t[i+1]-t[i], dx=abs(x[i+1]-x[i]), dy=abs(y[i+1]-y[i]);

        int remainder=0;
        if(dt % 2 == 1) remainder=1;

        if(!(dx + dy <= dt && (dx + dy) % 2 == remainder)){
            flag=false;
        }
    }

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

Measured memory_bytes: 1408
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>

typedef char                SINT8;
typedef unsigned char       UINT8;
typedef short               SINT16;
typedef unsigned short      UINT16;
typedef int                 SINT32;
typedef unsigned int        UINT32;
typedef long long           SINT64;
typedef unsigned long long  UINT64;
typedef double              DOUBLE;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define rep(i,a,b) for(int (i)=int(a);(i)<int(b);(i)++)

#define INF 1000000001
#define MOD 1000000007
#define INF64 1000000000000000001

#define F first
#define S second

#define Pii pair<SINT32,SINT32>
#define Pll pair<SINT64,SINT64>


using namespace std;

int main() {

	string s;
	cin >> s;

	SINT8 c;
	c = s[0];

	cout << c;
	cout << s.length()-2;

	c = s[s.length()-1];

	cout << c;

	return 0;
}

//	sort(DATA.begin(),DATA.end());
//	sort(DATA.begin(),DATA.end(),std::greater<SINT32>());
//	__gcd(ANS,DATA[i]);

//	// DATA.emplace_back(BUF);	//後ろに追加

//  DATA.erase(std::unique(DATA.begin(), DATA.end()), DATA.end());	//ソート後に使用

//	DATA.insert(DATA.begin() + X, 0);	//X番目の要素に0を挿入


//	vector<vector<SINT32>> DP(N,vector<SINT32>(3));	//2次元配列

/*
	SINT32 M = 3;
	vector<pair<SINT32,SINT32>> DATA2(M);
	for (SINT32 i = 0; i < M; i++) {
		cin >> DATA2[i].first;
		cin >> DATA2[i].second;
	}
	sort(DATA2.begin(),DATA2.end());
	cout << DATA2[0].first << endl;
	cout << DATA2[0].second << endl;
*/

// 	vector<pair<int,pair<int,int>>> DATA(M);
//	cin >> DATA[i].first;
//	cin >> DATA[i].second.first;
//	cin >> DATA[i].second.second;


//		APOSI = lower_bound(ADATA.begin(),ADATA.end(),QDATA[i]) - ADATA.begin();	//key以上を探す
//		BPOSI = lower_bound(BDATA.begin(),BDATA.end(),QDATA[i]) - BDATA.begin();


/* 文字列回転
	string N;
	cin >> N;
	N = N[N.length()-1] + N.substr(0,N.length()-1);
*/
/* 文字列合成
	string N,M;
	cin >> N >> M;
	SINT64 ans = 0;
	ans = stoi(N+M);
*/

/*
//ワーシャルフロイド
vector<vector<SINT32>> dist(N,vector<SINT32>(N));
rep(i,0,N) {
	rep(j,0,N) {
		if (i != j) {
			dist[i][j] = INF;
		}
	}
}
rep(k,0,N) {
	rep(i,0,N) {
		rep(j,0,N) {
			dist[i][j] = MIN(dist[i][j], dist[i][k]+dist[k][j]);
		}
	}
}
*/



/* SET コンテナ
	set<SINT32> DATA;
	for (SINT32 i = 0; i < N; i++) {
		SINT32 buf;
		cin >> buf;
		DATA.insert(buf);
	}

	//全表示
    set<string>::iterator it; //  イテレータを用意
    for(it = DATA.begin(); it != DATA.end(); it++) {
        cout << *it << endl;
    }

	//N番目を一部表示
	set<string>::iterator it; //  イテレータを用意
	it = DATA.begin();
	rep (i,0,N) {
		it++;
	}
	cout << *it << endl;
*/

/* map
	map<string,SINT32> mp;
	SINT32 N = 0;
	SINT32 mx = 0;

	cin >> N;
	for (SINT32 i = 0; i < N; i++) {
		string s;
		cin >> s;
		mp[s]++;
	}
	for(auto it=mp.begin();it!=mp.end();it++) {
		mx=max(mx,it->second);
	}
*/

/*
	//順列全表示
	//sortしてからでないと全列挙にならない
	sort(DATA.begin(),DATA.end());
	do {
		cout << buf << endl;
		rep(i,0,R) {
			cout << DATA[i] << " ";
		}
		cout << endl;

    } while (next_permutation(DATA.begin(),DATA.end()));
*/

Measured memory_bytes: 256
package main

import "fmt"

var par []int

func root(x int) int {
	if par[x] == x {
		return x
	}
	par[x] = root(par[x])
	return par[x]
}

func unite(x, y int) {
	rx := root(x)
	ry := root(y)
	if rx != ry {
		par[rx] = ry
	}
}

func same(x, y int) bool {
	return root(x) == root(y)
}

func newUnionFind(n int) {
	par = make([]int, n)
	for i := range par {
		par[i] = i
	}
}

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	ps := make([]int, n)
	for i := range ps {
		fmt.Scan(&ps[i])
		ps[i]--
	}
	newUnionFind(n)

	for i := 0; i < m; i++ {
		var x, y int
		fmt.Scan(&x, &y)
		unite(x-1, y-1)
	}

	var cnt int
	for i := 0; i < n; i++ {
		if same(i, ps[i]) {
			cnt++
		}
	}

	fmt.Println(cnt)
}


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

#define rep(i, n) for(int i=0; i < n; i++)
#define REP(i, n, m) for(int i=n; i < m; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;

ll mod=1000000007;

const ll INF = 1LL << 60;

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

int n;

ll getsad(ll x,vector<ll> y){
  ll sad=0;
  rep(i,y.size()){
    sad+=(ll)abs(y[i]-x);
  }
  return sad;
}

int main() {
  cin >> n;
  ll sum=0;
  vector<ll> a(n);
  rep(i,n){
    cin >> a[i];
    a[i]-=(i+1);sum+=a[i];
  }
  sort(ALL(a));
  ll center=a[n/2];
  cout << getsad(center,a);
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define forn(i,a,b) for(int i =a;i<b;i++)
#define fi first
#define se second
#define fast ios_base::sync_with_stdio(false);
using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;


void solve(){
	int n;
	cin >> n;
	int a[n];
	map<int,vector<int> > f;
	for(int i =0;i<n;i++){
		cin >> a[i];
		int key= i+1 - a[i];
		f[key].pb(i+1);
	}
	ll count = 0;
	for(int i =0;i<n;i++){
		int check = i+1 + a[i];
		if(f.find(check)!=f.end()){
			ll b = upper_bound(f[check].begin(),f[check].end(),i+1) - f[check].begin();
			ll size = f[check].size();
			count+=size-b;
			// cout << count << endl;
			// count+=(size-1-terms);
		}
	}
	cout << count << endl;
}

int main(){
	fast;
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif

	// int t;cin >> t;while(t--)
		solve();
}

Measured memory_bytes: 24424
def solve(n, x, m):
    result = [x]
    checked = [0] * m
    checked[x] = 1
    while len(result) < n:
        x = x * x % m
        if checked[x] > 0:
            break
        result.append(x)
        checked[x] = len(result)
    else:
        return sum(result)

    l = len(result)
    i = checked[x]
    before_len = i - 1
    loop_len = l - i + 1
    loop_sum = sum(result[before_len:])
    d, e = divmod(n - before_len, loop_len)
    ans = sum(result[:before_len]) + loop_sum * d + sum(result[before_len:before_len + e])
    return ans


n, x, m = map(int, input().split())

print(solve(n, x, m))


Measured memory_bytes: 13636
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
// #define LOCAL
const int MAXN=2e5+10;
const ll MOD=1e9+7;
ll _gcd(ll a,ll b){if(b==0)return a;return _gcd(b,a%b);}
ll gcd(ll a,ll b){a=abs(a),b=abs(b);if(a<b)swap(a,b);return _gcd(a,b);}
ll qpow(ll a,ll n){ll rt=1;while(n){if(n&1)rt=(rt*a)%MOD;a=a*a%MOD;n>>=1;}return rt;}
ll factor[MAXN];
void cal_factor(){factor[0]=1;for(int u=1;u<MAXN;u++){factor[u]=(factor[u-1]*u)%MOD;}}
ll C(ll n,ll k){return factor[n]*qpow(factor[n-k],MOD-2)%MOD*qpow(factor[k],MOD-2)%MOD;}
ll Cnk(ll n,ll k)
{
    ll up=1,dn=1;
    for(ll t=n;t>n-k;t--)up=up*t%MOD;
    for(ll t=1;t<=k;t++){
        dn=dn*t%MOD;
    }
    return up*qpow(dn,MOD-2)%MOD;
}
void solve()
{
    ll n,a,b;
    cin>>n>>a>>b;
    ll ans=qpow(2,n)-1;
    ans=(ans-Cnk(n,a)+MOD)%MOD;
    ans=(ans-Cnk(n,b)+MOD)%MOD;
    cout<<ans;
}
int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif
    solve();
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
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; }
using ll = long long;
using P = pair<ll, ll>;
const long double PI = acos(-1.0L);
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

int n;

int main() {
    cin >> n;
    vector<ll> avec(n, 0);
    for(int i = 0; i < n; ++i) cin >> avec[i];
    avec.emplace_back(-1);

    // 頭から確認していく
    bool flg = true;
    ll sum = 0;
    if(avec[0] != 0) flg = false;
    else {
        for(int i = 0; i < n; ++i) {
            if(avec[i] < avec[i+1]) {
                if(abs(avec[i]-avec[i+1]) == 1) {
                    // 正常
                }else flg = false;
            }else {
                sum += avec[i];
            }
        }
    }

    if(flg) cout << sum << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 6412
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<int, int>;
using PL = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) {cout << (expr ? "Yes" : "No") << "\n";}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  lint N;
  cin >> N;
  vector<lint> X(N);
  vector<lint> Y(N);
  vector<lint> P(N);
  REP(i, N) cin >> X[i] >> Y[i] >> P[i];
  vector<vector<lint>> xd(N, vector<lint>(1<<N));
  REP(i, N) REP(bit, 1<<N) {
    xd[i][bit] = abs(X[i]) * P[i];
    REP(j, N) if(bit>>j&1) xd[i][bit] = min(xd[i][bit], abs(X[i] - X[j]) * P[i]);
  }
  vector<vector<lint>> yd(N, vector<lint>(1<<N));
  REP(i, N) REP(bit, 1<<N) {
    yd[i][bit] = abs(Y[i]) * P[i];
    REP(j, N) if(bit>>j&1) yd[i][bit] = min(yd[i][bit], abs(Y[i] - Y[j]) * P[i]);
  }
  vector<lint> ans(N+1, 1e18);
  vector<lint> pow3(N+1);
  REP(i, N+1) pow3[i] = pow(3LL, i);
  REP(bit, pow3[N]) {
    lint cnt = 0;
    lint xbit = 0;
    lint ybit = 0;
    lint bittmp = bit;
    REP(i, N) {
      lint t = bittmp % 3;
      if(t == 1) {
        cnt++;
        xbit += 1<<i;
      } else if(t == 2) {
        cnt++;
        ybit += 1<<i;
      }
      bittmp /= 3;
    }
    lint sum = 0;
    REP(i, N) sum += min(xd[i][xbit], yd[i][ybit]);
    ans[cnt] = min(ans[cnt], sum);
  }
  REP(i, N+1) cout << ans[i] << "\n";
}

Measured memory_bytes: 11200
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,M=MI()
    PS=[ST().split() for _ in range(M)]
    AC=set()
    WA=defaultdict(int)
    pena = 0
    for p,s in PS:
        if p in AC:
            continue
        if s == "AC":
            AC.add(p)
            pena += WA[p]
        else:
            WA[p]+=1
    print(len(AC), pena)
    

if __name__ == '__main__':
    main()

Measured memory_bytes: 102744
#include <bits/stdc++.h>
 
using namespace std;
 
#define endl '\n'
#define fi first
#define se second
#define SET(p,k) memset(p, k, sizeof(p));
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;

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

	string a, b;

	cin >> a >> b;

	sort(a.begin(), a.end());
	sort(b.begin(), b.end(), greater<char>());

	if (a < b)
		cout << "Yes";
	else 
		cout << "No";
	cout << endl;

	return 0;
}

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


signed main(){
    int a, b;

    std::cin >> a >> b;

    cout.precision(6);
    std::cout << int(a / b) << " " << a % b << " " << fixed << double(a) / double(b) << std::endl;

    return 0;
}


Measured memory_bytes: 3284
from heapq import heapify,heappush,heappop
from math import ceil
n,m,*a=map(int,open(0).read().split())
if n==1:
	print(a[0]//(2**m))
	exit()
a=[(-1)*x for x in a]
heapify(a)
x=heappop(a)
while m:
	y=heappop(a)
	while x<=y and m:
		x=ceil(x/2)
		m-=1
	heappush(a,x)
	x=y
heappush(a,x)
print((-1)*sum(a))


Measured memory_bytes: 14180
#include <bits/stdc++.h>
#define ll long long

using namespace std;

ll a,b,dp[51][51][2500];
vector<int>vec;
ll solve(int x,int y,int sum){
    if(x==a){
        if(y!=0 && sum%y==0){
            if(sum/y==b) {
                return 1;
            }
            return 0;
        }
        return 0;
    }
    ll &cur=dp[x][y][sum];
    if(cur!=-1)
        return cur;
    cur=0;
    cur+=solve(x+1,y+1,sum+vec[x])+solve(x+1,y,sum);
    return cur;
}
int main() {
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
    memset(dp,-1,sizeof(dp));
    cin>>a>>b;
    for(int i=0;i<a;i++){
        int d;
        cin>>d;
        vec.push_back(d);
    }
    cout<<solve(0,0,0);
}

Measured memory_bytes: 51072
s = input()
f_half = s[:int((len(s) - 1) / 2)]
l_half = s[int((len(s) + 3) / 2 - 1):]

if s == s[::-1] and f_half == f_half[::-1] and l_half == l_half[::-1]:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forin(in, n) for(int i=0; i<n; i++) cin>>in[i]
#define forout(out, n) for(int i=0; i<n; i++) cout<<out[i]<<endl
#define rep(i, n) for(int i=0; i<(n); i++)

int main(){
    ll x, k, d; cin>> x >> k >> d;
    x=abs(x);
    ll straight = min(k, x/d);
    k -= straight;
    x -= straight * d;

    if(k % 2 == 0){
        cout<< x << endl;
    }else{
        cout<< d-x << endl;
    }
}


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

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n)  FOR(i, 0, n)
#define ASC(c) sort((c).begin(), (c).end())
#define DESC(c) sort((c).begin(), (c).end(), greater<int>())

#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
  int a, b, t; cin >> a >> b >> t;
  cout << (t / a) * b << endl;
}


Measured memory_bytes: 256
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
n=int(input())
X,Y,H=[],[],[]
for i in range(n):
    x,y,h=map(int,input().split())
    X.append(x)
    Y.append(y)
    H.append(h)
    if h>0:
        k=i
for x in range(101):
    for y in range(101):
        h=H[k]+abs(X[k]-x)+abs(Y[k]-y)
        if all([max(h-abs(xi-x)-abs(yi-y),0)==hi for xi,yi,hi in zip(X,Y,H)]):
            print(x,y,h)
            exit()

Measured memory_bytes: 3064