akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
typedef long long ll;
typedef double ld;
#define vll vector<ll>
#define vvll vector< vll >
#define vld vector< ld >
#define vvld vector< vld >
#define pll pair<ll ,ll >
#define vllp vector< pll >
#define F first
#define S second
#define MAX 1000000007
     
using namespace std;

 
int main()
{

	ll n;
	cin>>n;
	ll heights[n+1]={0},ans[n+1]={0};
	for (int i =1; i <=n; ++i)
	{
		cin>>heights[i];
	}
	ans[0]=0;ans[1]=0;
	ans[2]=heights[2]-heights[1];

	for (int i=2;i<=n;++i)
	{
		if(i>2)
		ans[i]=min(ans[i-1]+abs(heights[i]-heights[i-1]),ans[i-2]+abs(heights[i]-heights[i-2]));
		else {ans[i]=ans[i-1]+abs(heights[i]-heights[i-1]);}
	}	
	cout<<ans[n]<<endl;
	return 0;
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProblemA
{
    class Program
    {
        static void Main(string[] args)
        {
            var nums = Console.ReadLine().ToCharArray().Select(x => int.Parse(x.ToString())).ToArray();
            if (nums[0] == nums[1] || nums[1] == nums[2] || nums[2] == nums[3])
                Console.WriteLine("Bad");
            else
                Console.WriteLine("Good");
        }
    }
}


Measured memory_bytes: 13268
N,K,Q=map(int,input().split())
A=[0]*N
score=[K]*N
for i in range(0,Q):
    a=int(input())
    A[a-1]+=1
        
for j in range(0,N):
    score[j]=score[j]-(Q-A[j])
    if(score[j]>0):
        print("Yes")
    else:
        print("No")
    

Measured memory_bytes: 8644
MOD = 10**9 + 7
s = input()
n = len(s)

# dp[i][r] = (最初のi桁を見て、余りがrとなるような個数)
dp = [[0] * 13 for _ in range(n + 1)]
dp[0][0] = 1

for i in range(n):
    if s[i] == '?':
        for r in range(13):
            for d in range(10):
                r1 = (r * 10 + d) % 13
                dp[i + 1][r1] += dp[i][r]
                dp[i + 1][r1] %= MOD
    else:
        for r in range(13):
            r1 = (r * 10 + int(s[i])) % 13
            dp[i + 1][r1] += dp[i][r]
            dp[i + 1][r1] %= MOD

ans = dp[n][5]
# print(*dp, sep='\n')
print(ans)


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

#define lld long long
#define pi pair<int,int>
#define pl pair<lld,lld>
#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())

lld gcd(lld a, lld b) {
    if (a < b) {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    
    return b ? gcd(b, a % b) : a;
}

vector< lld > prime_factor(lld n) {
  vector< lld > ret;
  for(lld i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret.push_back(i);
      n /= i;
    }
  }
  if(n != 1) ret.push_back(n);
  return ret;
}

int main() {
    lld A,B;
    cin >> A >> B;
    lld m = gcd(A,B);
    vector<lld> prime = prime_factor(m);
    sort(prime.begin(),prime.end());
    prime.erase(std::unique(prime.begin(), prime.end()), prime.end());
    cout << prime.size()+1 << endl;
}

Measured memory_bytes: 3616
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<(int)(n);i++)
#define N 200010

int main() {
	int n, k;
	int a[N];
	int b[N];
	int x, y, z;
	bool v;
	scanf("%d %d", &n, &k);
	f(i, n) {
		scanf("%d", &a[i]);
	}
	f(i, k) {
		f(i, n + 1)b[i] = 0;
		f(i, n) {
			x = i - a[i];
			if (x < 0)x = 0;
			b[x]++;
			x = i + a[i] + 1;
			if (x > n)x = n;
			b[x]--;
		}
		x = 0;
		f(i, n) {
			x += b[i];
			a[i] = x;
		}
		v = true;
		f(i, n) {
			if (a[i] != n) {
				v = false;
				break;
			}
		}
		if (v) {
			f(i, n - 1)printf("%d ", n);
			printf("%d\n", n);
			return 0;
		}
	}
	f(i, n - 1)printf("%d ", a[i]);
	printf("%d\n", a[n - 1]);
	return 0;
}


Measured memory_bytes: 3288
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
int main()
{
	long long a = 0, b = 0, c = 0, hairetu[1000] = { }, mi = 0, ma = 0, ansa = 0, ansb = 0, count = 1;
	
	using namespace std;

	int x = 0, y = 0, z = 0;
	std::string str, strt, str_s;
	bool okada=false;
	cin >> str >> strt;

	for (int i = 0; i <str.size(); i++) {
		if (str == strt) {
			okada = true;

			
			break;
		}
		
		str = str[str.size()-1] + str.substr(0, str.size() - 1);
		
	}
	if (okada==false) {
		cout << "No" << endl;
	}
	if (okada) {
		cout << "Yes" << endl;
	}
	}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define num 1000000007
//#define num 998244353
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define inarr(i,a,n,A) for(ll i=a;i<n;i++) { cin>>A[i]; }
#define vll vector<long long>
#define pii pair <int,int>
#define pll pair<long long, long long>
#define vpii vector< pair <int,int>>
#define vpll vector< pair<long long, long long>>
#define max(a,b) ((a>b)?a:b)
#define min(a,b) ((a>b)?b:a)
#define max3(a,b,c) ((a>b)?(a>c)?a:c:(b>c)?b:c)
#define min3(a,b,c) ((a<b)?(a<c)?a:c:(b<c)?b:c)
#define avg(a,b) ((a)+(b))/2
#define pb push_back
#define pob pop_back
#define sf int flag=0     //Remember semicolon
#define assmin(a,b) if(b<=a) { a=b; }
#define assmax(a,b) if(b>=a) { a=b; }
#define f first
#define s second
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
#define all(x) x.begin(), x.end()
#define M_PI 3.14159265358979323846
#define epsilon (double)(0.00000000001)
typedef long long ll;
ll mod(ll a, ll b)
{
	if(a%b<0)
	{
		return a%b + b;
	}
	return a%b;
}
 
 
ll mod_exp(ll a, ll b, ll c)
{
	ll res=1;
	a=a%c;
	while(b>0)
	{
		if(b%2==1)
		{
			res=(res*a)%c;
		}
		b/=2;
		a=(a*a)%c;
	}
	return res;
}
ll mymod(ll a,ll b)
{
    return ((a%b)+b)%b;
}
bool prime[200001];
void SieveOfEratosthenes() 
{ 
    memset(prime, true, sizeof(prime)); 
    prime[1]=false;
    for (int p=2; p*p<=200000; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=200000; i += p) 
                prime[i] = false; 
        } 
    } 
    return;
}
ll powe[200005];
void power()
{
    powe[0]=1;
    REP(i,1,200005)
    {
        powe[i]=mymod(2*powe[i-1],num);
    }
}
ll gcdExtended(ll,ll,ll *,ll *);
ll modInverse(ll a, ll m) 
{ 
    ll x, y; 
    ll g = gcdExtended(a, m, &x, &y); 
        ll res = (x%m + m) % m;
        return res;
} 
ll gcdExtended(ll a, ll b, ll *x, ll *y) 
{ 
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
    ll x1, y1; 
    ll gcd = gcdExtended(b%a, a, &x1, &y1); 
    *x = y1 - (b/a) * x1; 
    *y = x1; 
    return gcd; 
}
ll n; 
struct node
{
	vll adj;
    ll dist;
   // ll max_depth;
    ll cwgd;
};
ll facto[200005], pre[200005];
ll nCr(ll n, ll r)
{
    ll a=facto[n];
    a = mymod(a*modInverse(facto[r],num),num);
    a = mymod(a*modInverse(facto[n-r],num),num);
    return a;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    pre[0]=0;
    REP(i,1,200005)
    {
        pre[i] = i+pre[i-1];
    }
    facto[0]=1;
    REP(i,1,200005)
    {
        facto[i] = i*facto[i-1];
        facto[i] = mymod(facto[i],num);
    }
    ll n,k;
    cin>>n>>k;
    ll ans = 0;
    REP(i,k,n+2)
    {   
        ll up = pre[n] - pre[n-i];
        ll down = pre[i-1];
       // cout<<up<<" "<<down<<endl;
        ans+=up-down+1;
        ans=mymod(ans,num);
    }
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 6780
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace September9
{
    class Program
    {
        static void Main(string[] args)
        {
            string strInp = Console.ReadLine();

            for (int i = 0; i < strInp.Length; i++) {
                if (strInp.Substring(i, 1) == "9") {
                    Console.WriteLine("Yes");
                    return; // 処理を抜ける
                }
            }
            // todo 終了処理
            Console.WriteLine("No");

            // for debug
            return;
        }
    }
}


Measured memory_bytes: 11092
#include<iostream>
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    int s=0;
    int aa=a;
    s+=a;
    a--;
    s+=a;
    int m=max(aa+b,s);
    s=0;
    a=aa;
    aa=b;
    s+=b;
    b--;
    s+=b;
    int mm=max(aa+a,s);
    cout<<max(m,mm)<<endl;
    return 0;
}


Measured memory_bytes: 256
import 'dart:io';

main(List<String> args) {
  List ABCD = stdin.readLineSync().split(" ").map((x) => int.parse(x)).toList();
  var A = ABCD[0];
  var B = ABCD[1];
  var C = ABCD[2];
  var D = ABCD[3];
  var c = C - A;
  var d = D - B;
  List<List<int>> dp =
      List.generate(c + 1, (_) => List.generate(d + 1, (_) => 0));

  var mod = 998244353;
  dp[0][0] = 1;
  for (var i = 0; i < c + 1; i++) {
    for (var j = 0; j < d + 1; j++) {
      if (i > 0 && j > 0) {
        if (i == j && i == 1) {
          dp[i][j] -= (A + i - 1) * (B + j - 1);
        } else {
          var tmp = dp[i - 1][j - 1];
          tmp *= (A + i - 1) * (B + j - 1);
          dp[i][j] -= tmp;
        }
      }
      dp[i][j] %= mod;
      if (i < c) dp[i + 1][j] = dp[i][j] * (B + j);
      if (j < d) dp[i][j + 1] += dp[i][j] * (A + i);
    }
  }
  print(dp[c][d]);
  //print(dp);
}


Measured memory_bytes: 115592
a = list(map(int,list(input())))
r =[1,0]
n = 0
def change(n):
  if n == 0 :
    return 1
  else :
    return 0
if len(a) == 1 :
  print(0)
else :
  for i in range(1,len(a)):
    if a[i-1] == a[i] :
      n = change(n)
    r[n] +=1
  print(min(r))

Measured memory_bytes: 4652
import java.util.*;
import java.io.*;

public class Main {

    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        
        HashSet<String> set = new HashSet();
        
        int N = in.nextInt();
        in.nextLine();
        int ans = 0;
        
        for(int i = 0; i < N; i++) {
            String s = in.nextLine();

            if(!set.contains(s)) {
                set.add(s);
                ans++;
            }
        }
        
        System.out.println(ans);
    }
    

        
}


Measured memory_bytes: 79460
import java.util.Scanner;
import java.util.Arrays;

public class Main{
public static void main(String[] args){
Scanner scan=new Scanner(System.in);
int l=scan.nextInt();
int r=scan.nextInt();
int d=scan.nextInt();

int i=0;
int sum=0;
for(i=l;i<r+1;i++){
    if(i%d==0){
        sum=sum+1;
    }
}

System.out.println(sum);


}
}

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

int main() {
  int A, B, R;
  char op;
  
  cin >> A >> op >> B;
  
  if(op == '+') {
    R = A + B;
  }
  
  else {
    R = A - B;
  }
  cout << R << endl;
}


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

const int N = 305; 

using namespace std;

int n, a[N][N]; 

int main() {
	
	long long sum=0; 
	bool kill=0; 
	
	scanf("%d", &n);
	for(int i=1; i<=n; ++i)
		for(int j=1; j<=n; ++j) scanf("%d", &a[i][j]);
	
	for(int i=1; i<=n; ++i)
		for(int j=1; j<=n; ++j) {
			bool tmpKill = 0; 
			for(int k=1; k<=n; ++k) {
				if(k == i || k == j) continue; 
				if(a[i][j] > a[i][k] + a[k][j]) kill=1; 
				if(a[i][j] == a[i][k] + a[k][j]) tmpKill = 1; 
			}
			if(!tmpKill) sum += a[i][j]; 
		}
	
	if(kill) printf("-1\n");
	else printf("%lld\n", sum/2); 
	
	return 0; 
	
}

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;
        PrintWriter pw = new PrintWriter(System.out);
        
        try {
            st = new StringTokenizer(br.readLine());
            int x = Integer.parseInt(st.nextToken());
            int y = Integer.parseInt(st.nextToken());
            if(x*2 <= y && x*4 >= y && y%2 == 0) {
                pw.print("Yes");
            }
            else pw.print("No");

        }
        finally {
            pw.flush();
            pw.close();
        }
    }
}


Measured memory_bytes: 32688
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<cmath>
#include<limits>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvll vector<vector<long long>>
#define vvc vector<vector<char>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define sysp system("PAUSE")
#define pno cout << "no" << endl
#define pyes cout << "yes" << endl
#define pYes cout << "Yes" << endl
#define pNo cout << "No" << endl
using namespace std;


int main() {
    int X; cin >> X;
    X /= 200;
    cout << 10 - X << endl;
}

Measured memory_bytes: 3616
#include <iostream>
#include <stack>

int main(void){
	std::stack<int> st;
	int num;

	while(std::cin >> num){
		if(num != 0){
			st.push(num);
		}else{
			std::cout << st.top() << std::endl;
			st.pop();
		}
	}
	return 0;
}

Measured memory_bytes: 1200
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include <fstream>
#include <time.h>
#include <iterator>
#include<random>



#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()
using namespace std;
int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 500050;


vector<int>G[101];
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N; cin >> N;
	int K; cin >> K;
	if (K > ((N - 1)*(N - 2) / 2)) {
		print(-1);
		return 0;
	}
	FOR(i,1, N) {
		G[0].pb(i);
	}
	int ans = N - 1;
	int rem = ((N - 1)*(N - 2) / 2) - K;
	FOR(i, 1, N - 1) {
		FOR(j, i + 1, N) {
			if (rem == 0)goto END;
			G[i].pb(j);
			ans++;
			rem--;
		}
	}
END:;
	print(ans);
	REP(i, N) {
		REP(j, G[i].size()) {
			pe(i + 1); print(G[i][j] + 1);
		}
	}
}


Measured memory_bytes: 384
#include<stdio.h>
int main()
{
int W,H,x,y,r;
scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
if(x+r<=W && y+r<=H && 0<=x-r && 0<=y-r)
{
printf("Yes\n");
}
else
{
printf("No\n");
}
return 0;
}

Measured memory_bytes: 584
#include<iostream>
using namespace std;
int mas[17][17];
int dx[2]={0,1};
int dy[2]={1,0};
int sx,sy;
int w,h,cnt;
void dfs(int x,int y);
int main(){
  int n;
  int a,b;

  while(1){
    cin >> w >> h;
    if(w==0&&h==0) break;
    for(int i=1;i<h+1;i++){
      for(int j=1;j<w+1;j++){
	mas[i][j]=0;
      }
    }

      cin >> n;
    for(int i=0;i<n;i++){
      cin>>a>>b;
      mas[b][a]=1;
    }
    cnt=0;
    sx=1;
    sy=1;
    dfs(sx,sy);
    cout<<cnt<<endl;
  }
}
void dfs(int x,int y){
  if(y==h && x==w){
    cnt++;
    return;
  }
  for(int i=0;i<2;i++){
    int nextx=x+dx[i];
    int nexty=y+dy[i];
    if(0<nextx && nextx<=w && 0<nexty && nexty<=h && mas[nexty][nextx]==0){
      dfs(nextx,nexty);
    }
  }
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
long long a[100000],n,K,dp[100000];
int main()
{
	cin>>n>>K;
	for (long long i=0;i<n;i++)
	  scanf("%I64d",a+i);
	dp[1]=abs(a[1]-a[0]);
	for (long long i=2;i<n;i++)
	{
	  long long k=1e18;
	  for (int j=1;j<=K&&i-j>=0;j++)
	    k=min(k,dp[i-j]+abs(a[i]-a[i-j]));
	  dp[i]=k;
    }
	cout<<dp[n-1]<<endl;
	return 0;
}

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

ll N;
ll A[101010], B[101010];
ll d[101010];

int main()
{
    cin >> N;
    ll suma = 0;
    rep(i, 0, N)
    {
        cin >> A[i];
        suma += A[i];
    }
    ll sumb = 0;
    rep(i, 0, N)
    {
        cin >> B[i];
        sumb += B[i];
        d[i] = A[i] - B[i];
    }
    if (suma < sumb)
    {
        cout << -1 << endl;
        return 0;
    }

    ll cnt = 0;
    ll sum = 0;
    rep(i, 0, N)
    {
        if (A[i] < B[i])
        {
            cnt++;
            sum += B[i] - A[i];
        }
    }
    sort(d, d + N);
    reverse(d, d + N);
    rep(i, 0, N)
    {
        if (sum <= 0)
        {
            break;
        }
        sum -= d[i];
        cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <string>

using namespace std;

typedef long long int ll;

int main(int argc, char* argv[]) {
	string s;
	cin >> s;

	if (s[2] == s[3] && s[4] == s[5]) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
long long d[200010]={1};
int mbk(long long a,int n,int m){return n?(mbk((a*a)%m,n/2,m)*(n%2?a:1))%m:1;}
int inv(int a,int m){return mbk((long long)a,m-2,m);}
int aCb(int a,int b,int m){return d[a]*inv(d[b],m)%m*inv(d[a-b],m)%m;}
int main(){
  int h,w,a,b,M=1e9+7,s=0,i;
  for(i=0;i<200000;i++)d[i+1]=(d[i]*(i+1LL))%M;
  scanf("%d %d %d %d",&h,&w,&a,&b);
  for(i=0;i<h-a;i++)s=(s+(1LL*aCb(i+b-1,i,M)*aCb(w-b+h-i-2,w-b-1,M))%M)%M;
  printf("%d\n",s);
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <atcoder/dsu>
#define pb push_back
#define SZ(x) ((int)(x.size()))
#define FOR(i,s,n) for (ll i = (s); (i) < (n); ++i)
#define FORD(i,s,l) for (ll i = (s); (i) >= l; --i)
#define F first
#define S second
#define TC int __tc; cin >> __tc; FOR(case_num,1,__tc+1)
#define TEST(x,i) ((x)&(1ll<<(i)))
#define SET(x,i) ((x)|(1ll<<(i)))
#define FLIP(x,i) ((x)^(1ll<<(i)))
#define CLEAR(x,i) ((x)&~(1ll<<(i)))
const double pi = 4 * atan(1);
using namespace std;
using namespace atcoder;
typedef long long ll;

template <typename T> void printvec(const vector<T>& v) {
	for(int i = 0; i < SZ(v); i++) {
		if (i) cout << " ";
		cout << v[i];
	}
	cout << "\n";
}

inline ll floorDiv(ll x, ll y) {
	ll d = x / y;
	ll r = x % y;
	return r ? (d - ((x < 0) ^ (y < 0))) : d;
}

ll ceilDiv(ll x, ll y) {
	return -floorDiv(-x,y);
}

bool predicate(ll mid) {
	return mid>10;
}

ll bin_search(ll lo, ll hi) {
	int sign = lo < hi ? 1 : -1;
	lo*=sign;
	hi*=sign;
	hi++;
	while(lo < hi) {
		ll mid = floorDiv(lo+hi,2);
		if (!predicate(sign*mid)) {
			lo = mid+1;
		} else {
			hi = mid;
		}
	}
	return sign*lo;
}
const ll MOD = 1000000007;
const int MAXN = 200005;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n, m;
	cin >> n >> m;
	
	dsu uf(n);
	while(m--) {
		int a, b;
		cin >> a >> b;
		a--;b--;
		uf.merge(a,b);
	}
	
	cout << uf.groups().size()-1 << "\n";
	
}


Measured memory_bytes: 8892
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    getLine
    as <- getIntList
    bs <- getIntList
    let d = zipWith (-) as bs
        p = sum $ filter (> 0) d
        m = sum $ map ((`div` 2) . (*(-1))) $ filter (< 0) d
    putStrLn $ if m >= p then "Yes" else "No"

Measured memory_bytes: 1660
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const LL maxn = 100000+100;
int a[maxn];
int vis[maxn];
int main()
{
    LL n;
    cin>>n;
    LL ans=n/11*2;
    int mod=11;
    n%=mod;
    if(n>=1&&n<=6)ans++;
    else if(n>=7&&n<=10)ans+=2;
    cout<<ans;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner input = new Scanner(System.in);
        int W = input.nextInt();
        int H = input.nextInt();
        int x = input.nextInt();
        int y = input.nextInt();
        int r = input.nextInt();
        if (((x + r) <= W) && ((x - r) >= 0) && ((y + r) <= H) &&((y - r) >= 0))
            System.out.println("Yes");
        else
            System.out.println("No");
    }
}


Measured memory_bytes: 26420
N, W = list(map(int, input().split()))
Bs = []
for i in range(N):
    Bs.append(tuple(map(int, input().split())))

dp = [[0 for _ in range(W + 1)] for _ in range(N)]
for i in range(Bs[N - 1][0], W + 1):
    dp[N - 1][i] = Bs[N - 1][1]
for i in range(N - 2, -1, -1):
    for j in range(W + 1):
        dp[i][j] = max(dp[i + 1][j], (dp[i + 1][j - Bs[i][0]] + Bs[i][1]) if j >= Bs[i][0] else 0)

print(dp[0][W])

Measured memory_bytes: 171528
#include<stdio.h>
#include<algorithm>
using namespace std;
const int mod=1000000007;
void inc(int&a,int b){(a+=b)%=mod;}
struct pr{
	int l,r;
	pr(int a=0,int b=0){l=a;r=b;}
}p[100010];
bool operator<(pr a,pr b){return a.l==b.l?a.r>b.r:a.l<b.l;}
bool operator==(pr a,pr b){return a.l==b.l&&a.r==b.r;}
int x[100010],y[100010],ys[100010],s[100010],M,N;
int lowbit(int x){return x&-x;}
void add(int x,int v){
	while(x<=N){
		inc(s[x],v);
		x+=lowbit(x);
	}
}
int query(int x){
	int res=0;
	while(x){
		inc(res,s[x]);
		x-=lowbit(x);
	}
	return res;
}
int main(){
	int n,m,M,i,j,s,t;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++)scanf("%d",x+i);
	for(i=1;i<=m;i++)scanf("%d",y+i);
	for(i=1;i<=n;i++){
		if(x[i]>y[1]&&x[i]<y[m]){
			j=lower_bound(y+1,y+m+1,x[i])-y;
			p[++M]=pr(x[i]-y[j-1],y[j]-x[i]);
			ys[++N]=y[j]-x[i];
		}
	}
	sort(ys+1,ys+N+1);
	N=unique(ys+1,ys+N+1)-ys;
	sort(p+1,p+M+1);
	M=unique(p+1,p+M+1)-p-1;
	add(1,1);
	s=1;
	for(i=1;i<=M;i++){
		j=lower_bound(ys+1,ys+N,p[i].r)-ys;
		t=query(j);
		inc(s,t);
		add(j+1,t);
	}
	printf("%d",s);
}

Measured memory_bytes: 2176
#include <iostream>
#include <utility>
#include <algorithm>

using namespace std;
typedef pair<int, int> P;

int h, w, n;\
P edge[200005];
int perm[200005];

int getPerm(int i, bool upFlag, int num)
{
	if(!upFlag) i = (2*w)-i-1;
	i += num;
	i %= (2*w);
	if(i >= w) i = (2*w)-i-1;
	return i;
}

void swap(int a, int b)
{
	int tmp = perm[a];
	perm[a] = perm[b];
	perm[b] = tmp;
}

int main(void)
{
	cin >> h >> w >> n;
	for(int i = 0; i < n; i++){
		cin >> edge[i].first >> edge[i].second;
	}
	sort(edge, edge+n);
	reverse(edge, edge+n);
	
	for(int i = 0; i < w; i++){
		perm[i] = getPerm(i, !(i%2), h);
	}
	
	int a, b;
	for(int i = 0; i < n; i++){
		a = getPerm(edge[i].second-1, !((edge[i].first+edge[i].second-1)%2), edge[i].first-1);
		b = getPerm(edge[i].second, !((edge[i].first+edge[i].second)%2), edge[i].first-1);
		swap(a, b);
	}
	
	for(int i = 0 ; i < w; i++){
		cout << perm[i]+1 << endl;
	}
	return 0;
}

Measured memory_bytes: 5380
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;

int main()
{
    multiset<string> strs;
    int N, L;
    cin >> N >> L;
    for (int i = 0; i < N; ++i)
    {
        string Si;
        cin >> Si;
        strs.insert(Si);
    }
    for (const string &str : strs)
        cout << str;
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e9;
const ll MOD = 1e9 + 7;


int main(){
    int h, w;
    cin >> h >> w;
    int ans = 0;

    vector<vector<char>> m(h, vector<char>(w));
    vector<vector<int>> dist(h, vector<int>(w, INF));
    rep(i, h){
        rep(j, w){
            cin >> m[i][j];
            if(m[i][j] == '.') ans++;
        }
    }

    auto isIN = [&](int y, int x){
        return (0<=y&&y<h && 0<=x&&x<w);
    };

    int sy = 0, sx = 0;
    int dy[] = {0, 0, -1, 1};
    int dx[] = {1, -1, 0, 0};
    using P = pair<int, int>;
    queue<P> que;
    que.push({sy, sx});
    dist[sy][sx] = 1;
    while(que.size() != 0){
        P p = que.front();
        que.pop();
        rep(i, 4){
            int ny = p.first + dy[i];
            int nx = p.second + dx[i];
            if(isIN(ny, nx) && m[ny][nx] == '.' && dist[ny][nx] > dist[p.first][p.second]+1){
                dist[ny][nx] = dist[p.first][p.second] + 1;
                que.push({ny, nx});
            }
        }
    }

    if(dist[h-1][w-1] == INF) cout << -1 << endl;
    else cout << ans-dist[h-1][w-1] << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 10000
#define NIL -1

struct Node { int p, l, r; };
struct Node T[MAX];
int n;

/* 先行順巡回 */
void preParse(int u) {
  if ( u == NIL ) return;
  printf(" %d", u);
  preParse(T[u].l);
  preParse(T[u].r);
}

/* 中間順巡回 */
void inParse(int u) {
  if ( u == NIL ) return;
  inParse(T[u].l);
  printf(" %d", u);
  inParse(T[u].r);
}

/* 後行順巡回 */
void postParse(int u) {
  if ( u == NIL ) return;
  postParse(T[u].l);
  postParse(T[u].r);
  printf(" %d", u);
}

int main() {
  int i, v, l, r, root;

  scanf("%d", &n);
  for( i = 0; i < n; i++ )
    T[i].p = NIL;

  for ( i = 0; i < n; i++ ) {
    scanf("%d %d %d", &v, &l, &r);
    T[v].l = l;
    T[v].r = r;
    if ( l != NIL ) T[l].p = v;
    if ( r != NIL ) T[r].p = v;
  }

  for ( i = 0; i < n; i++ ) if ( T[i].p == NIL ) root = i;

  printf("Preorder\n");
  preParse(root);
  printf("\n");
  printf("Inorder\n");
  inParse(root);
  printf("\n");
  printf("Postorder\n");
  postParse(root);
  printf("\n");

  return 0;
}


Measured memory_bytes: 2100
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
using namespace std;
#define ll long long
int main(){
    ll r;
    cin >> r;
    cout << 3*r*r;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int b1,b2,b3,b;
	scanf("%d %d %d",&b1,&b2,&b3);
	b=b1*4+b2*2+b3;
	if(b==4 || b==2 || b==0)	{
		printf("Close\n");
	}
	else {
		printf("Open\n");
	}
	return 0;
}


Measured memory_bytes: 584
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>

#define REP(n) for(int i = 0;i < n;i++)
#define LLREP(n) for(long long int  i = 0;i < n;i++)
typedef long long int ll;
using namespace std;
#define MAX_A 101
int main(){


    string s;
    cin >> s;
    int ans = 0;
    int s_len = s.length();

    for(int i = 0;i < s.length()-1;i++){

        if(s[i] != s[i+1]){
            ans++;
        }
    }

    cout << ans << endl;




    return 0;
}

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

int main() {
    int N;
    cin >> N;
    string s;
    cin >> s;
    int all = s.size();
    int cnt = 0;
    for (int i=0; i<s.size(); i++) {
        if (s.at(i) == 'R') cnt++;
    }
    int blue = all - cnt;
    if (cnt > blue) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
A.sort()
M = A[0]
X = [A[0]]
pos = N
for i in range(N):
  if A[i] >= 0:
    pos = i
    break
if pos == 0:
  for i in range(1, N - 1):
    M -= A[i]
    X.append(M)
  S = M
  M = A[N-1] - M
  print(M)
  for i in range(N - 2):
    print(X[i], A[i+1])
  print(A[N - 1], S)
elif 1 <= pos <= N - 1:
  M = sum(abs(_) for _ in A)
  print(M)
  L = A[0]
  for j in range(pos, N - 1):
    print(L, A[j])
    L -= A[j]
  R = A[N - 1]
  print(R, L)
  R -= L
  for j in range(1, pos):
    print(R, A[j])
    R -= A[j]
elif pos == N:
  print(A[N-1] - sum(A[i] for i in range(N-1)))
  R = A[N - 1]
  for i in range(N-1):
    print(R, A[i])
    R -= A[i]

Measured memory_bytes: 14060
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)
	N, K, Q := getInt(), getInt(), getInt()
	a := make([]int, N)
	for i := 0; i < Q; i++ {
		x := getInt() - 1
		a[x]++
	}
	for i := 0; i < N; i++ {
		if K+a[i]-Q <= 0 {
			out("No")
		} else {
			out("Yes")
		}
	}
}


Measured memory_bytes: 3204
#include <bits/stdc++.h>
#define MOD 1000000007
typedef long long int ll;
using namespace std;

int main()
{
    int n;
    cin >> n;
    int ans = 0;
    if(n == 1e5) cout << 9e4+9e2+9 << endl;
    else if(n>=1e4){
        ans = n-1e4+1+9e2+9;
        cout << ans << endl;
    }
    else if(n>=1e3) cout << 909 << endl;
    else if(n>=1e2){
        ans = n-1e2+10;
        cout << ans << endl;
    }
    else if(n>=10) cout << 9 << endl;
    else cout << n << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 1e18
typedef long long ll;
typedef pair<int, int> P;

int main(){
  int a,b,c,d,e;
  cin>>a>>b>>c>>d>>e;
  if(a==0) cout<<1<<endl;
  if(b==0) cout<<2<<endl;
  if(c==0) cout<<3<<endl;
  if(d==0) cout<<4<<endl;
  if(e==0) cout<<5<<endl;
  return 0;
}

Measured memory_bytes: 3568
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>

using namespace std;

int dp[1000001];
int kind[31];


const int MAX_SIZE = 10000;
const int MAX_PRIME = 1000000;


int prime[MAX_PRIME+1];
bool isPrime[MAX_PRIME+1];
int p;

void erats(){
	// primeXgðú»
	fill(isPrime,isPrime+MAX_PRIME,true);
	p = 0;
	isPrime[0] = isPrime[1] = false;

	for(int i = 2; i <= MAX_PRIME; i++){
		if(isPrime[i]){
			prime[p++] = i;
		}
		else
			continue;

		// Óé¢É©¯é
		for(int j = 2*i; j <= MAX_PRIME; j+=i){
			isPrime[j] = false;
		}
	}
}


int main(){

	int n;
	int x;
	erats();
	while(cin>>n>>x&&!(n==0&&x==0)){
		for(int i = 0; i < n; i++){
			cin>>kind[i];
		}
		// eàzÌ¥¢ûª½íÞ é©ðßé
		fill(dp,dp+1000001,0);
		dp[0]=1;
		int maxCost=-1;

		//for(int j = 0; j < n; j++){
		//	for(int i = kind[j]; i <= x; i++){
		//		dp[i]+=dp[i-kind[j]];
		//	}
		//}

		for(int i = 1; i <= x; i++){
			dp[i]=0;
			for(int j = 0; j < n; j++){
				if(i-kind[j]>=0){
					dp[i]+=dp[i-kind[j]];
				}
			}
			//if(dp[i]>=1&&(isPrime[i])){
			//	maxCost=max(i,maxCost);
			//}
		}
		for(int i = 0; i <= x; i++){
			if(dp[i]&&isPrime[i])
				maxCost=i;
		}


		if(maxCost==-1)
			cout<<"NA"<<endl;
		else
			cout<<maxCost<<endl;
	}

	return 0;
}

Measured memory_bytes: 6060
#include <stdlib.h>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <iostream>
#include <set>
#include <cstring>

using namespace std;


long long int calc(long long int n) { 
   return (n*(n-1))/2;
} 

int n;
long long int res = 0;
long long int cnt = 0;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin>>n;

    for(int i=1;i<=n;i++) {
        cnt = n/i;
        res+=i*(calc(cnt+1));
    }

    cout<<res<<endl;
    
    return 0;
}

Measured memory_bytes: 3656
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();
		int c = sc.nextInt();

		boolean flag = false;

		if (a == b && b != c) {
			flag = true;
		} else if (b == c && c != a) {
			flag = true;
		} else if (c == a && a != b) {
			flag = true;
		}

		if (flag) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}

}


Measured memory_bytes: 35736
#include <stdio.h>
#include <stdlib.h>

int main()
{ int n,m,a,b,c,t;
  while(~scanf("%d %d",&n,&m))
  {  a=n+m;
     b=n-m;
     c=n*m;
     if(a<b)
        a=b;
     if(a<c)
     a=c;
    printf("%d\n",a);

  }
    return 0;
}

Measured memory_bytes: 128
import java.util.*; import java.io.*; import java.math.*;
public class Main{
	//Don't have to see. start------------------------------------------
	static class InputIterator{
		ArrayList<String> inputLine = new ArrayList<String>(1024);
		int index = 0; int max; String read;
		InputIterator(){
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try{
				while((read = br.readLine()) != null){
					inputLine.add(read);
				}
			}catch(IOException e){}
			max = inputLine.size();
		}
		boolean hasNext(){return (index < max);}
		String next(){
			if(hasNext()){
				return inputLine.get(index++);
			}else{
				throw new IndexOutOfBoundsException("There is no more input");
			}
		}
	}
	static HashMap<Integer, String> CONVSTR = new HashMap<Integer, String>();
	static InputIterator ii = new InputIterator();//This class cannot be used in reactive problem.
	static PrintWriter out = new PrintWriter(System.out);
	static void flush(){out.flush();}
	static void myout(Object t){out.println(t);}
	static void myerr(Object t){System.err.print("debug:");System.err.println(t);}
	static String next(){return ii.next();}
	static boolean hasNext(){return ii.hasNext();}
	static int nextInt(){return Integer.parseInt(next());}
	static long nextLong(){return Long.parseLong(next());}
	static double nextDouble(){return Double.parseDouble(next());}
	static ArrayList<String> nextStrArray(){return myconv(next(), 8);}
	static ArrayList<String> nextCharArray(){return myconv(next(), 0);}
	static ArrayList<Integer> nextIntArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Integer> ret = new ArrayList<Integer>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Integer.parseInt(input.get(i)));
		}
		return ret;
	}
	static ArrayList<Long> nextLongArray(){
		ArrayList<String> input = nextStrArray(); ArrayList<Long> ret = new ArrayList<Long>(input.size());
		for(int i = 0; i < input.size(); i++){
			ret.add(Long.parseLong(input.get(i)));
		}
		return ret;
	}
	static String myconv(Object list, int no){//only join
		String joinString = CONVSTR.get(no);
		if(list instanceof String[]){
			return String.join(joinString, (String[])list);
		}else if(list instanceof ArrayList){
			return String.join(joinString, (ArrayList)list);
		}else{
			throw new ClassCastException("Don't join");
		}
	}
	static ArrayList<String> myconv(String str, int no){//only split
		String splitString = CONVSTR.get(no);
		return new ArrayList<String>(Arrays.asList(str.split(splitString)));
	}
	public static void main(String[] args){
		CONVSTR.put(8, " "); CONVSTR.put(9, "\n"); CONVSTR.put(0, "");
		solve();flush();
	}
	//Don't have to see. end------------------------------------------
	static void solve(){//Here is the main function
		ArrayList<String> one = nextStrArray();
		String S = one.get(0);
		String T = one.get(1);
		ArrayList<Integer> two = nextIntArray();
		int A = two.get(0);
		int B = two.get(1);
		String U = next();
		if(S.equals(U)){
			A--;
		}else{
			B--;
		}
		myout(A + " " + B);
	}
	//Method addition frame start



	//Method addition frame end
}


Measured memory_bytes: 36844
import sys
from bisect import *
from collections import *
from copy import deepcopy
from heapq import *
from itertools import *
from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline


def gcd(a, b):
    while b:
        a, b = b, a%b
    return a

def divisor(n):
    ass = []
    for i in range(1,int(n**0.5)+1):
        if n%i == 0:
            ass.append(i)
            if i**2 == n:
                continue
            ass.append(n//i)
    ass.sort()
    return ass

def main():
    """ main """
    A,B = map(int, input().split())
    ds = divisor(gcd(A,B))
    if len(ds) == 1:
        print(1)
        return 0
    ds = ds[1:]
    dp = [1]*len(ds)
    for i in range(len(ds)):
        if dp[i]:
            for j in range(i+1,len(ds)):
                if ds[j]%ds[i] == 0:
                    dp[j] = 0
    ans = 1
    for d in dp:
        if d == 1: ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3956
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstring>

char S[5];
int main()
{
	scanf("%s",S);
	int len=strlen(S);
	if(len==2) printf("%s",S);
	else if(len==3) printf("%c%c%c",S[2],S[1],S[0]);
	return 0;
}

Measured memory_bytes: 256
object Main extends App {
	val N = scala.io.StdIn.readInt
	val a = scala.io.StdIn.readLine.split(" ").map(_.toInt).filter(_%2 == 0)

	val even = a.size
	val cond = a.filter(z => z%3 == 0 || z%5 ==0)
	
	if(even == cond.size) println("APPROVED")
	else println("DENIED")
}

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

int main()  {
   int a;
   int rm = 10;
   int arg = -1;
   vector<int> tmp(5);
   for (int i =0; i < 5; ++i){
        cin  >>  a; 
        tmp[i]  = a;
        int trm = a % 10;
        if (trm > 0 & trm  < rm) {
           arg = i;
           rm = trm;
        } 
   }
   int ret = 0;
   for (int i =0; i < 5; ++i){
          a = tmp[i];
         if (i == arg) {
               ret += a; 
         }  else {
               int trm = a % 10;
               int keta = a /10;
              if (trm > 0) keta += 1;
              ret += keta*10;
         } 
    }
   cout << ret << endl;
   

}


Measured memory_bytes: 256
#!/usr/bin/env python3

n, a, b = map(int, input().split())
mod = 10**9 + 7
a = min(a, n-a)
b = min(b, n-b)
com = [1] * (max(a, b) + 1)
for i in range(1,len(com)):
    com[i] = (com[i-1] * pow(i, mod-2, mod) * (n-i+1)) % mod
print((pow(2, n, mod) + mod - 1 - com[a] - com[b]) % mod)

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

int a[MAXN],b[MAXN],cnt[MAXN];
int fa[MAXN],size[MAXN],ans;

int fi(int now){
    if(fa[now]==now)    return now;
    return fa[now]=fi(fa[now]);
}

void con(int x,int y){
    int fx=fi(x),fy=fi(y);
    if(fx==fy)  return ;
    ans+=size[fx]*size[fy];
    fa[fx]=fy,size[fy]+=size[fx];
}

signed main(){
    int n,m,qwq;
    cin>>n>>m;  qwq=(n-1)*n/2;
    for(int i=1;i<=n;i++)   fa[i]=i,size[i]=1;
    for(int i=1;i<=m;i++)
        scanf("%lld%lld",&a[i],&b[i]);
    for(int i=m;i;i--)
        cnt[i]=qwq-ans,con(a[i],b[i]);
    for(int i=1;i<=m;i++)
        printf("%lld\n",cnt[i]);
    return 0;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 25000001;
ll n, a[2][3], DP[N];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(i, 0, 2)FOR(j, 0, 3) cin >> a[i][j];
  FOR(i, 0, 2){
    FOR(j, 0, 3){
      ll c = a[0][j], d = a[1][j]-a[0][j];
      if(d<=0) continue;
      FOR(k, 0, n-c+1) maxs(DP[k+c], DP[k]+d);
    }
    ll ma = 0;
    FOR(j, 0, n+1) maxs(ma, DP[j]);
    fill(DP, DP+n+1, 0);
    n += ma;
    swap(a[0], a[1]);
  }
  cout << n << endl;
}

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

using namespace std;

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

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int m,d;

int main(){
    cin>>m>>d;
    int ans = 0;
    FOR(i,1,m+1)FOR(j,1,d+1){
        int a = j/10;
        int b = j%10;
        if(a<=1 || b<=1)continue;
        if(a*b==i)ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
n=int(input())
x=list(map(int,input().split()))
t=max(x)
lsum=[]
for i in range(1,t+1):
  sum_x=0
  
  for x_ in x:
    sum_x+=(x_-i)**2
  lsum.append(sum_x)
  
#print(lsum)
print(min(lsum))

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

const int maxn=100000;

int ans=0;

vector<int> a[15];
int b[15];

bool f(int s,int k)
{
    int cnt=0;
    for(auto t:a[k])
        if((s>>t)&1)
            ++cnt;
    if(cnt%2==b[k])
        return true;
    return false;
}

int main()
{
    int n,m;
    cin>>n>>m;

    for(int i=0;i<m;++i)
    {
        int k;
        cin>>k;
        while(k--)
        {
            int t;
            cin>>t;
            a[i].push_back(t-1);
        }
    }
    for(int i=0;i<m;++i)
    {
        int t;
        cin>>t;
        b[i]=t;
    }

    int ans=0;
    for(int i=0;i<1<<n;++i)
    {
        bool flag=1;
        for(int j=0;j<m;++j)
        {
            if(f(i,j)==false)
            {
                flag=0;
                break;
            }
        }
        if(flag)
            ++ans;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
def main():
    from bisect import bisect_left

    x = int(input())

    cands = [1]
    for b in range(2, x + 1):
        for p in range(2, x + 1):
            pw = b ** p
            if pw > x: break
            cands.append(pw)

    cands.sort()

    i = bisect_left(cands, x)
    if i == len(cands) or x < cands[i]:
        i -= 1
    print(cands[i])


if __name__ == '__main__':
    main()

# import sys
# input = sys.stdin.readline
# 
# sys.setrecursionlimit(10 ** 7)
# 
# (int(x)-1 for x in input().split())
# rstrip()
#
# def binary_search(*, ok, ng, func):
#     while abs(ok - ng) > 1:
#         mid = (ok + ng) // 2
#         if func(mid):
#             ok = mid
#         else:
#             ng = mid
#     return ok


Measured memory_bytes: 3060
using System;
class Program
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int N = int.Parse(input[0]);
        int M = int.Parse(input[1]);
        if (N > M)
        {
            Console.WriteLine(0);
            return;
        }
        string[] input1 = Console.ReadLine().Split(' ');
        int[] X = new int[M];
        for(int i = 0; i < M; i++)
        {
            X[i] = int.Parse(input1[i]);
        }
        Array.Sort(X);
        int[] d = new int[M - 1];
        for(int i = 0; i < M - 1; i++)
        {
            d[i] = X[i + 1] - X[i]; 
        }
        Array.Sort(d);
        int sum = 0;
        for (int i = M - 2; i > M - N - 1; i--)
        {
            sum += d[i];
        }
        Console.WriteLine(X[M - 1] - X[0] - sum);
    }
}

Measured memory_bytes: 17504
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int h, w, k;
    std::cin >> h >> w >> k;
    std::vector<std::string> b(h);
    std::vector<int> left(h, -1), right(h, -1), cnt(h);
    for (int i = 0; i < h; i++) {
        std::cin >> b[i];
        for (int j = 0; j < w; j++) {
            if (b[i][j] == '#') {
                right[i] = j;
                if (left[i] < 0) left[i] = j;
                cnt[i]++;
            }
        }
    }

    std::vector<std::vector<int>> ret(h, std::vector<int>(w));
    int a = 1;
    for (int i = 0; i < h; i++) {
        if (!cnt[i]) continue;
        for (int j = 0; j < w; j++) {
            ret[i][j] = a;
            if (b[i][j] == '#' && j != right[i]) a++;
        }
        a++;
    }

    int from = 0;
    for (int i = 0; i < h; i++) {
        if (!cnt[i]) continue;
        for (int j = from; j < i; j++) {
            for (int k = 0; k < w; k++) ret[j][k] = ret[i][k];
        }
        from = i + 1;
    }

    for (int i = from; i < h; i++) {
        for (int j = 0; j < w; j++) ret[i][j] = ret[from - 1][j];
    }

    for (auto &v : ret) {
        for (auto e : v) std::cout << e << " ";
        std::cout << std::endl;
    }

    return 0;
}


Measured memory_bytes: 1280
from math import *

A,B,h,m = map(int,input().split())

if h>11:h-=12
s=l=.0
l=m*6
s=30*(h+(m/60))
if l<s:l,s=s,l
if l-s>180:d=360-l+s
else:d=l-s
c = cos(radians(d))

ans = sqrt(A**2+B**2-2*A*B*c)

print(ans)

Measured memory_bytes: 9588
S = str(input())
Q = int(input())
 
hanten = 0
front = ""
end = ""
 
for i in range(Q):
    query=list(map(str,input().split()))
    if query[0]=="1":
        hanten+=1
        hanten=hanten%2
    else:
        if query[1]=="1":
            if hanten==0:
                front=query[2]+front
            else:
                end=end+query[2]
        else:
            if hanten==0:
                end=end+query[2]
            else:
                front=query[2]+front
ans=front+S+end
if hanten==1:
    ans=ans[::-1]
print(ans)

Measured memory_bytes: 4420