akhauriyash/Code-Regression huggingface dataset:
n,k = map(int,input().split())
sss = input()

cnt = 0
state = sss[0]
x = []
if sss[0] == "0":
    x.append(0)
for s in sss:
    if s == state:
        cnt += 1
    else:
        state = s
        x.append(cnt)
        cnt = 1
x.append(cnt)
if sss[-1] == "0":
    x.append(0)
#11101010110011
#1:3 1 1 2 2
#0: 1 1 1 2

#1
#1

y = [0]
for i in range(len(x)):
    y.append(y[i] + x[i])
#:0,1,2,3,4,5,6 7, 8 ,9
#:0,3,4,5,6,7,8,10,12,14

#0,1

z = []
for i in range(k*2+1,len(y))[::2]:
    z.append(y[i] - y[i - (k*2+1)])
#print(x)
#print(y)
#print(z)
if len(x) <= k*2-1:
    print(sum(x))
else:
    print(max(z))




Measured memory_bytes: 9448
N = int(input())
A = list(map(int, input().split()))

dp = [[0] * 2 for i in range(N)]
dp[0][0] = A[0] + A[1]
dp[0][1] = -A[0] - A[1]

for i in range(1, N - 1):
    for j in range(2):
        if j == 0:
            dp[i][j] = max(dp[i-1][0] + A[i+1], dp[i-1][1] + A[i+1])
        else:
            dp[i][j] = max(dp[i-1][0] - 2 * A[i] - A[i+1], dp[i-1][1] + 2 * A[i] - A[i+1])

print(max(dp[N-2]))

Measured memory_bytes: 24816
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <math.h>
using namespace std;
typedef long long int ll;

ll mod=1e9+7;
ll innv[200200];

ll mod_pow(ll a,ll b){
	a%=mod;
	if(b==0)return 1;
	if(b==1)return a;
	ll res=mod_pow(a,b/2)%mod;
	res*=res; res%=mod;
	if(b%2)res*=a;
	return res%mod;
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<ll> a(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	innv[0]=1;
	for(ll i=1;i<=150150;i++){
		innv[i]=innv[i-1]*i%mod;
	}
	vector<ll> cnt(n+5,0);
	for(int i=1;i<=n+3;i++){
		cnt[i]=innv[n-1]*mod_pow(i,mod-2)%mod;
		(cnt[i]+=cnt[i-1])%=mod;
	}
	ll ans=0;
	for(int i=0;i<n-1;i++){
		ans+=(a[i+1]-a[i])*cnt[i+1]%mod;
		ans%=mod;
	}
	cout << ans << endl;
}

Measured memory_bytes: 2944
/*
ID: thanhvq1
LANG: C++14
PROB: namenum
*/

#pragma GCC optimize ("O2")
#include<bits/stdc++.h>
#include<unistd.h>
using namespace std;

// defines
#define int long long
typedef long long ll;
#define double long double
#define vec vector
#define vi vector<int>
#define vvi vector<vector<int>>
#define FZ(n) memset((n),0,sizeof())
#define FMO(n) memset((n),-1,sizeof(n))
#define unset unordered_set
#define ii pair<int, int>
#define vii vector<ii>
#define F first;
#define S second
#define mp make_pair
#define PB push_back
#define ALL(x) begin(x),end(x)
#define SZ(x) ((int)(x).size())
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORE(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
#define bitcount(n) __builtin_popcountll(n)
#define reset(x, y) memset(x, y, sizeof(x))
#define uni(x) (x).erase(unique(all(x)), (x).end());
#define BUG(x) cerr << #x << " = " << (x) << endl
#define chkmin(a, b) a = min(a, b)
#define chkmax(a, b) a = max(a, b)
#define max3(a, b, c) max(a, b) > max(b, c) ? max(a, b) : max(b, c)
#define min3(a, b, c) min(a, b) < min(b, c) ? min(a, b) : min(b, c)

//permanent constants
const long long ZERO = 0LL;
const long long INF64 = 1e18;
const int INF32 = 1e9;
const int MOD = 998244353; //1e9 + 7;  const ll MOD2 = (ll)MOD * (ll)MOD;
const double PI = 2.0*acos(0.0); //acos(-1.0L);
const double EPS = static_cast<double>(1e-10);
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int dx[4] = {0, 1, 0, -1}; const int dy[4] = {1, 0, -1, 0};
//const ll INF = (ll)(1e18 + 239);
const int BIG = (int)(1e9 + 239);

//random
mt19937 rnd(239); //(chrono::high_resolution_clock::now().time_since_epoch().count());

void FILEIO() {  freopen("in.txt", "r", stdin);  freopen("out.txt", "w", stdout); }
//void FILEIO() {  freopen("namenum.in", "r", stdin);  freopen("namenum.out", "w", stdout); }
void input() {   }

void solve() {
	int r; cin >> r;
	cout << 3*r*r << endl;
}

signed main() {
  ios_base::sync_with_stdio(false); cin.tie();
//  FILEIO();
//auto beginProgram = chrono::steady_clock::now();

//  int test = 0;
//  string s; getline(cin, s); int t = stoi(s);
//  while(t--)
  {
//	  cout << "Case " << ++test << ": ";
	  solve();
  }

  //auto endProgram = chrono::steady_clock::now();

  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int linerserch(int a[],int n,int key)
{
    int i = 0;
    a[n] = key;
    while(a[i] != key)
    {
        i++;
    }

    return i != n; //iとnが違うならture

}

int main()
{
    int i,n,a[10000+1],q,key,sum = 0;

    cin >> n;

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

    cin >> q;

    for(i = 0;i<q;i++)
    {
        cin >> key;
        if(linerserch(a,n,key))
        {
            sum++;
        }
    }

    cout << sum <<endl;
    return 0;
}


Measured memory_bytes: 3172
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
const int INF=1<<31;
const int SUP=0x7fffffff;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()

int a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51}; 
int main(){
	std::ios::sync_with_stdio(0);
	cin.tie(0);
	
	int k;
	cin>>k;
	
	cout<<a[k-1];

	return 0;
}


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

vector<vector<vector<int>>> edge;
vector<bool> used;
void add_edge(int u, int v, int c) {
    edge[u].push_back({v, c, (int)edge[v].size()});
    edge[v].push_back({u, 0, (int)edge[u].size()-1});
}

int dfs(int v, int t, int f) {
    if (v==t) return f;
    used[v] = true;
    for (int i = 0; i < (int)edge[v].size(); i++) {
        auto e = edge[v][i];
        if (used[e[0]] || e[1]==0) continue;
        int d = dfs(e[0], t, min(f, e[1]));
        if (d > 0) {
            edge[v][i][1] -= d;
            edge[e[0]][e[2]][1] += d;
            return d;
        }
    }
    return 0;
}

int max_flow(int s, int t) {
    int res = 0;
    int M = (int)edge.size();
    while (true) {
        used = vector<bool>(M, false);
        int f = dfs(s, t, 99999999);
        if (f == 0) break;
        else res += f;
    }
    return res;
}

int main(){
    int N;
    cin >> N;
    vector<int> a(N),b(N),c(N),d(N);
    edge.resize(N*2+2);
    for (int i = 0; i < N; i++) cin >> a[i] >> b[i];
    for (int i = 0; i < N; i++) cin >> c[i] >> d[i];
    for (int i = 0; i < N; i++) add_edge(2*N, i, 1);
    for (int i = 0; i < N; i++) add_edge(i+N, 2*N+1, 1);
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (a[i] < c[j] && b[i] < d[j]) add_edge(i, N+j, 1);
        }
    }
    
    int ans = max_flow(2*N, 2*N+1);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include<stdio.h>

int solve(int,int);

int n,a[2000];

main(){
  int q,m[2000];
  int i,p=0,res;

  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d",&a[i]);
  }

  scanf("%d",&q);
  for(i=0; i<q; i++){
    scanf("%d",&m[i]);
    res = solve(p,m[i]);
    if(res == 1) 
      printf("yes\n");
    else 
      printf("no\n");    
  }
  return 0;
}

int solve(int p,int t){ 
  if(t == 0) return 1;
  if(p == n) return 0;
  if(solve(p+1,t) == 1)return 1;
  if(solve(p+1,t-a[p]) == 1) return 1;
  return 0;    
}

Measured memory_bytes: 588
use proconio::{fastout, input};
struct UnionFind{
    par : Vec<usize>,
    n_tree : usize,
}

impl UnionFind{
    pub fn new(n: usize) -> Self{
        let par : Vec<usize>= (0..n).collect();
        UnionFind{
            par,
            n_tree: n,
        }
    }

    pub fn root(&mut self,x : usize) -> usize{
        if self.par[x] == x{
            return x;
        }

        self.par[x] = self.root(self.par[x]);
        self.par[x]
    }

    pub fn unite(&mut self, x: usize, y: usize){
        let rx = self.root(x);
        let ry = self.root(y);

        if rx == ry{
            return;
        }
        self.n_tree -= 1;
        self.par[rx] = ry;
    }

    pub fn same(&mut self, x: usize, y: usize) -> bool{
        self.root(x) == self.root(y)
    }

    pub fn num_tree(&self) -> usize{
        self.n_tree
    }

}

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        tu : [(usize,usize,usize);m],
    }

    let mut uf = UnionFind::new(n);

    for e in &tu{
        let x = e.0 - 1;
        let y = e.1 - 1;

        uf.unite(x, y);
    }

    println!("{}",uf.num_tree());
}


Measured memory_bytes: 6572
from collections import defaultdict
def main():
    def fcalc(cl,c):
        f = 0
        for i in cl.keys():
            if i != c:
                f += d[i-1][c-1]*cl[i]
        return f
                
    n,c = map(int,input().split())
    d = [list(map(int,input().split())) for _ in range(c)]
    color = [list(map(int,input().split())) for _ in range(n)]
    clist = [defaultdict(int),defaultdict(int),defaultdict(int)]
    for i in range(n):
        for j in range(n):
            clist[(i+j+2)%3][color[i][j]] += 1
    ans_list = []
    for i in range(1,c+1):
        f1 = fcalc(clist[0],i)
        for j in range(1,c+1):
            if i != j:
                f2 = fcalc(clist[1],j)
                for k in range(1,c+1):
                    if j != k and k != i:
                        f3 = fcalc(clist[2],k)
                        ans_list.append(f1+f2+f3)
    print(min(ans_list))
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 46684
import java.util.Scanner;
public class Main
{
	public static void main(String[] args)
    {
     	Scanner sc = new Scanner(System.in); 
      
      	String[] sep = sc.nextLine().split(" ");
      	int cir = Integer.parseInt(sep[0]);
      	int house = Integer.parseInt(sep[1]);
      	String[] sepa = sc.nextLine().split(" ");
      	int[] len = new int[house];
      	for(int i = 0; i < house; i++)
        {
          	len[i] = Integer.parseInt(sepa[i]);
        }
      	int max = len[0] + cir - len[house - 1];
      	for(int i = 0; i < house - 1; i++)
        {
         	if(max < len[i + 1] - len[i])
            {
             	max = len[i + 1] - len[i];
            }
        }
      
      	System.out.println(cir - max);
    }
}

Measured memory_bytes: 58900
#include<iostream>
using namespace std;
int inSort(int A[],int n,int g){
  int i,j,v;
  int cnt=0;
  for(i=g;i<n;i++){
    v=A[i];
    j=i-g;
    while(j>=0 && A[j]>v){
      A[j+g]=A[j];
      j-=g;
      ++cnt;
    }
    A[j+g]=v;
  }
  return cnt;
}
void shSort(int A[],int n){
  int i,j,k,l,G[20];

  int m=0; for(i=1;i<=n;i=i*3+1) G[m++]=i;

  int c=0; for(i=m-1;0<=i;i--) c+=inSort(A,n,G[i]);

  cout<<m<<endl;
  cout<<G[m-1];  for(i=m-2;0<=i;i--) cout<<' '<<G[i];  cout<<endl;
  cout<<c<<endl;
  for(i=0;i<n;i++) cout<<A[i]<<endl;
}
int main(){
  int i,n,A[1000000];
  cin>>n;
  for(i=0;i<n;i++) cin>>A[i];
  shSort(A,n);
  return 0;
}

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

using namespace std;

int main()
{
    long long x, answer = 0, balance = 100;
    cin >> x;
    while(true)
    {
        if(balance >= x)
        {
            cout << answer;
            break;
        }
        balance += balance / 100;
        answer++;
    }
    return 0;
}


Measured memory_bytes: 3624
#define _USE_MAT_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <stack>
#include <deque>
#include <numeric>
#include <functional>
using namespace std;

int main() {
    int N;
    cin >> N;
    long long ans = 0;
    vector<int>A(N+2);
    A[0] = A[N + 1] = 0;
    for (int i = 1; i <= N; i++) {
        cin >> A[i];
        ans += abs(A[i] - A[i - 1]);
    }
    ans += abs(A[N]);

    for (int i = 1; i <= N; i++) {
        cout << ans - abs(A[i] - A[i - 1]) - abs(A[i] - A[i + 1]) + abs(A[i + 1] - A[i - 1]) << endl;
    }

    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int t[++N], x[N], y[N];
  t[0] = 0;
  x[0] = 0;
  y[0] = 0;
  for (int i = 1; i < N; i++) {
    cin >> t[i] >> x[i] >> y[i];
  }
  for (int i = 1; i < N; i++) {
    if (t[i]-t[i-1] < abs(x[i]-x[i-1])+abs(y[i]-y[i-1]) || (t[i]-t[i-1]-abs(x[i]-x[i-1])-abs(y[i]-y[i-1]))%2) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
}

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

int main()
{
    int p[100], s[100];

    int x, y, i = 0;
    char period;
    while( cin >> x >> period >> y )
    {
        if( x == 0 && y == 0 )
            break;
        p[i] = x;
        s[i] = y;
        i++;
    }

    for( int j = 0; j < i - 1; j++ )
    {
        for( int k = j + 1; k < i; k++ )
        {
            if( s[j] < s[k] )
            {
                int temp = s[j];
                s[j] = s[k];
                s[k] = temp;

                temp = p[j];
                p[j] = p[k];
                p[k] = temp;
            }
        }
    }

    int change = -1, h = 0;
    for( int j = 0; j < i; j++ )
    {
        if( s[j] != change )
        {
            change = s[j];
            h++;
        }
        s[j] = h;
    }

    int q;
    while( cin >> q )
    {
        for( int j = 0; j < i; j++ )
        {
            if( p[j] == q )
                cout << s[j] << endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 3020
(* O(n) *)
let n = Scanf.scanf " %d" @@ (+) 0
let a_s = Array.init n @@ fun _ -> Scanf.scanf " %d" @@ (+) 0
let oc = ref 0
let _ =
  Array.iter (fun a -> if a mod 2 = 1 then incr oc) a_s;
  print_endline @@ if !oc mod 2 = 0 then "YES" else "NO"

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

using namespace std; 

#define pb push_back
#define fi first
#define se second
#define all(vec) vec.begin(),vec.end()
#define f(i,a,b) for(int i=a;i<b;i++)
#define fr(i,a,b) for(int i=a;i>=b;i--)
#define fp(i,a,b,p) for(int i=a;i<b;i+=p)
#define SZ(x) (int)x.size()

typedef  vector<string> vs;
typedef  vector<int> vi;
typedef  vector<long long> vl;

const long long MOD = 1e9 + 7;


int main(){

	
	#ifdef LOCAL
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	#endif

	int n,m;

	cin >> n  >> m; 

	vector<string> v(n);

	vector<vector<int>> dp(n+1);

	f(i,0,n+1){
		f(j,0,m+1){
			dp[i].pb(0);
		}
	}


	f(i,0,n){
		cin >> v[i];
	}

	dp[1][1] = 1;

	f(i,0,n){
		f(j,0,m){
			
			if(i==0 && j==0) continue;

			if(v[i][j]!='#'){
				dp[i+1][j+1] = (dp[i][j+1] + dp[i+1][j])% MOD;
			}
		}
	}

	/*f(i,0,n+1){
		f(j,0,m+1){
			cout << dp[i][j] <<" ";
		}
		cout << endl;
	}*/

	cout << (dp[n][m]) % MOD << endl;

}

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

int main(){
    ll n, k;
    cin>>n>>k;

    ll ans=0;
    ll num=1;
    while(true){
        if(n/num==0) break;
        ans++;
        num*=k;
    }

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

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

public class P
{
    public int v { get; set; }
    public int w { get; set; }
    public string t { get; set; }
    public long d { get; set; }
    public string s { get; set; }
}

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var ps = new P[n];
        for (int i = 0; i < n; i++)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var v = int.Parse(line[0]);
            var w = int.Parse(line[1]);
            var d = long.Parse(line[3]);
            ps[i] = new P { v = v, w = w, t = line[2], d = d, s = line[4] };
        }
        foreach (var x in ps.OrderBy(y => y.v).ThenBy(y => y.w).ThenBy(y => y.t).ThenBy(y => y.d).ThenBy(y => y.s))
            Console.WriteLine("{0} {1} {2} {3} {4}", x.v, x.w, x.t, x.d, x.s);
    }
}




Measured memory_bytes: 47136
#gcdは3.4.3だとfractionsにある
from fractions import gcd
import math

from math import factorial as f

from math import ceil,floor,sqrt


import bisect
import re
import heapq


from copy import deepcopy
import itertools

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

yes = "Yes"
no = "No"

def main():
    s = list(input())
    n = len(s)
    srev = list(reversed(s))
    if not s == srev:
        print(no)
        exit()
    if not s[:(n-1)//2] == srev[1+(n-1)//2:]:
        print(no)
        exit()
    if not srev[:(n-1)//2] == s[1+(n-1)//2:]:
        print(no)
        exit()
    print(yes)



main()





Measured memory_bytes: 5112
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<pair<ll,ll>> vp;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define reep(i,n) for(ll i = n; i >-1; i--)
#define deb(variable) cout<<#variable<<"="<<variable<<endl
#define MMOD(i) ((i%MOD)+MOD)%MOD;
#define vec(i,j) vector<vector<ll>>(i,vector<ll>(j,0))
const ll INF=99999999999999999;
const ll MOD=1000000007;
const ll MAX_N=500010;
ll a,b,c,d,e,x,y,z,k,m,n,l,q,t,ans=0;
vl v,v1,v2,kaijo,gysku;//v1,v
vp p,p2,pa;
string s;
ll solve(void){
    a=0;
    b=0;
    rep(i,k){
        if(s[i]=='x')a++;
    }
 
    if(a>7) return 0;
    else return 1;
}
int main(){
    cin>>s;

k=s.length();
 
 
    if(solve()==0){
        cout<<"NO";
    }
    else{
        cout<<"YES";
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;
constexpr long long int INF = std::numeric_limits<long long int>::max();
#define int long long int

void solve() {
  // int x;
  // cout << endl;
}

signed main() {
  int A, B, C;
  cin >> A >> B >> C;

  int ans = 0;
  if (A % 2 == B % 2 && B % 2 == C % 2) {
    // skip
  } else if (A % 2 == B % 2) {
    ans++;
    A++;
    B++;
  } else if (B % 2 == C % 2) {
    ans++;
    B++;
    C++;
  } else {
    ans++;
    A++;
    C++;
  }

  int m = max(A, max(B, C));
  ans += (m - A) / 2;
  ans += (m - B) / 2;
  ans += (m - C) / 2;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.time.*;
import java.time.format.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      String str = sc.next();
      DateTimeFormatter f = 
        DateTimeFormatter.ofPattern("yyyy/MM/dd");
      LocalDate d =
        LocalDate.parse(str,f);
      LocalDate reiwa =
        LocalDate.parse("2019/04/30",f);
      if(d.isAfter(reiwa))
        System.out.println("TBD");
      else System.out.println("Heisei");
    }
}


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

using namespace std;

string s,t;
int len_s,len_t;
const int inf = (int)1e9;

int memo[3005][3005];
bool check[3005][3005];

int dp(int pos1,int pos2){
    if(pos1==len_s||pos2==len_t) return 0;

    if(check[pos1][pos2])
        return memo[pos1][pos2];

    int op1=-inf;
    int op2=-inf;

    if(s[pos1]==t[pos2]){
        op1=1+dp(pos1+1,pos2+1);
    }
    else {
        op1 = dp(pos1 + 1, pos2);
        op2 = dp(pos1, pos2 + 1);
    }

    memo[pos1][pos2]=max(op1,op2);
    check[pos1][pos2]=true;

    return memo[pos1][pos2];

}

int main() {
    cin>> s >> t;
    len_s=s.size();
    len_t=t.size();

    dp(0,0);

    string ans;

    int i = 0, j = 0;
    while (i < len_s && j < len_t)
    {
        if (s[i] == t[j]) {
            ans+= s[i]; 
            i++;
            j++;  
        }
        else if (memo[i+1][j] > memo[i][j+1]) i++;
        else j++;
    }

    cout << ans<<endl;

    return 0;
}

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

const int MOD=1e9+7;
int main()
{
    int H,W;
    cin>>H>>W;
    char arr[H+1][W+1];
    for(int i=1;i<=H;i++)
    {
        for(int j=1;j<=W;j++)
        {
            cin>>arr[i][j];
        }
    }
    int dp[H+1][W+1];
    for(int i=0;i<=H;i++)
    dp[i][0]=0;
    for(int i=0;i<=W;i++)
    dp[0][i]=0;
    dp[1][1]=1;
    for(int i=1;i<=H;i++)
    {
        for(int j=1;j<=W;j++)
        {
            if(i==1 && j==1)
            continue;
            if(arr[i][j]=='.')
            dp[i][j]=(dp[i-1][j]+dp[i][j-1])%MOD;
            else
            dp[i][j]=0;
        }
    }
    cout<<dp[H][W]<<"\n";
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int a,b,c;
    cin>>a>>b>>c;
    if((a==b&&a!=c)||(a==c&&a!=b)||(b==c&&b!=a)){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
#ab = [tuple(map(int, input().split())) for _ in range(n)]
from collections import Counter
from collections import defaultdict
_,_ = map(int, input().split())
a = list(map(int, input().split()))

benefit, min = defaultdict(int), 0
for i in range(len(a)):
    if i == 0 or a[i] <= min:
        min = a[i]
    else:
        benefit[a[i]-min] += 1
print(benefit[max(benefit)])
exit(0)


Measured memory_bytes: 20960
from sys import stdin
import itertools

if __name__ == "__main__":
  N = int(input())
  S = input().strip()
  
  nums = "".join([str(i) for i in range(10)])
  
  cnt = 0
  
  for ds in itertools.product(nums, repeat=3):
    invalid = False
    last_index = -1
    for d in ds:
      last_index = S.find(d, last_index+1)
      if last_index < 0:
        invalid = True
        break
      
    if not invalid:
      cnt += 1
    
  print(cnt)


Measured memory_bytes: 3060
#!python3.8
# -*- coding: utf-8 -*-
# abc166/abc166_d
import sys
import math

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    X = i2n()
    for A in range(0, X+1):
        B_5 = A**5 - X
        if B_5 == 0:
            print(A, 0)
            return
        if B_5 > 0:
            B = int(B_5**0.2)
        else:
            B = int(-1 * (-B_5)**0.2)
        if B**5 == B_5:
            print(A, B)
            return
    return

main()


Measured memory_bytes: 9496
import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val n = scanner.nextInt()
    val d = scanner.nextInt()
    var sum = 0
    var count = 0
    while(sum < n){
        sum += 2*d+1
        count++
    }
    println(count)
}

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

using namespace std;


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


int main(){

  int c[300]={};

  int h,w;

  cin>>h>>w;

  string s[100];
  
  for(int i=0;i<h;i++)cin>>s[i];

  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++){
      c[s[i][j]]++;
    }

  h%4,w%4;
  int ans=1;

  
  
  if(h%2==0&&w%2==0){
    for(int i='a';i<='z';i++)
      if(c[i]%4)ans=0;
  }
  else if(h%2&&w%2){
    int t=0,p=0;
    for(int i='a';i<='z';i++)
      if(c[i]%4){

	if(c[i]%4==1)t++;
	if(c[i]%4==2)p++;
	if(c[i]%4==3)t++,p++;

      }
    ans=0;
    if(2*p<h+w&&t==1)ans=1;
  }
  else {
    int t=0,p=0;

    if(w%2==0)h=w;
    
    for(int i='a';i<='z';i++)
      if(c[i]%4){

	if(c[i]%4==1)t++;
	if(c[i]%4==2)p++;
	if(c[i]%4==3)t++,p++;

      }
    ans=0;
    if(2*p<=h&&t==0)ans=1;



  }
  if(ans)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
using namespace std;
int main(){
#define int long long
	int n;
	cin >> n;
	int x[110], y[110], h[110];
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i] >> h[i];
	}
	for (int i = 0; i <= 100; i++) {
		for (int j = 0; j <= 100; j++) {
			int t = 1000000000000000000;
			for (int k = 0; k < n; k++) {
				if (h[k] != 0) {
					t = h[k] + abs(i - x[k]) + abs(j - y[k]);
					break;
				}
			}
			bool b = true;
			if (t == 0) {
				continue;
			}
			else {
				for (int k = 0; k < n; k++) {
					if (h[k] == 0) {
						if (h[k] + abs(i - x[k]) + abs(j - y[k]) < t) {
							b = false;
						}
					}
					else {
						if (h[k] + abs(i - x[k]) + abs(j - y[k]) != t) {
							b = false;
						}
					}
				}
			}
			if (b == true) {
				cout << i << " " << j << " " << t << endl;
				return 0;
			}
		}
	}
	return 0;
}



Measured memory_bytes: 3608
S=input()
lens=len(S)
half=lens//2
haha=half//2
if lens%2==0:
    if S[:half]==S[half:]:
        if half%2==0:
            if S[:haha]==S[haha:half][::-1]:
                print('Yes')
            else:
                print('No')
        else:
            if S[:haha]==S[haha+1:half][::-1]:
                print('Yes')
            else:
                print('No')
    
else:
    if S[:half]==S[half+1:]:
        if half%2==0:
            if S[:haha]==S[haha:half][::-1]:
                print('Yes')
            else:
                print('No')
        else:
            if S[:haha]==S[haha+1:half][::-1]:
                print('Yes')
            else:
                print('No')
    else:
        print('No')

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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n;
	cin>>n;
	ll a[n];
	ll g;
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
		
	}
	long double ans = 0;
	for(ll i=0;i<n;i++)
	{
		ans+=(1.0/a[i]);
	}
	ans=1/ans;
	
	cout<<setprecision(13)<<fixed<<ans;
}

Measured memory_bytes: 256
import java.util.*;


public class Main {
    public static void main(String[] args) {
        // 自分の得意な言語で
        // Let's チャレンジ！！

        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        int num = Integer.parseInt(line);
        
        line = sc.nextLine();
        String[] lines = line.split(" ", 0);

        int[] nagasa = new int[num];
        for (int i = 0; i < num; i++) {
            nagasa[i] = Integer.parseInt(lines[i]);
        }
        
        if (num < 3) {
            System.out.println("0");
            return;
        }

        int count = 0;
        for (int i = 0; i < num - 2; i++) {
            for (int j = i + 1; j < num; j++) {
                for (int k = j + 1; k < num; k++) {
                    if (nagasa[i] != nagasa[j] && nagasa[i] != nagasa[k] && nagasa[j] != nagasa[k]) {
                        if (nagasa[i] + nagasa[j] > nagasa[k] && nagasa[i] + nagasa[k] > nagasa[j] && nagasa[k] + nagasa[j] > nagasa[i]) {
                            count++;
                        }
                    }
                }
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 36600
#include <bits/stdc++.h>
using namespace std;
#define REP(i, t) for(int i = 0; i < t; i++)

int main()
{
    string s;
    cin >> s;
    for (int i = 0; i < s.length(); i += 2) cout << s[i];

    return 0;
}


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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define scint(x) scanf("%d", &x)
#define sclng(x) scanf("%ld", &x)
typedef long long ll;

ll N, ans = 0;

void dfs(ll x, int a, int b, int c){
    if(x > N){
        return;
    }
    if(a == 1 && b == 1 && c == 1){
        ans++;
    }
    dfs(10 * x + 3, 1, b, c);
    dfs(10 * x + 5, a, 1, c);
    dfs(10 * x + 7, a, b, 1);
}

int main(){
    scanf("%lld", &N);
    dfs(0, 0, 0, 0);
    printf("%lld\n", ans);
    return 0;
}

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


int main(void) {
    using namespace std;

    long n;
    cin >> n;
    
    vector<long> a(n);
    for(auto &x: a) cin >> x;

    long ma=-1e9, mi = 1e9;
    for(auto &x: a) {
        ma = max(ma, x);
        mi = min(mi, x);
    }
    long mai, mii;
    mai = find(a.begin(), a.end(), ma) - a.begin();
    mii = find(a.begin(), a.end(), mi) - a.begin();

    vector<pair<long, long>> r;

    if(abs(mi) < ma) {
        for(int i=1; i<n; i++) {
            r.push_back({i+1, mai+1});
            r.push_back({i+1, mai+1});
            mai = i;
        }
        goto RES;
    }

    else {
        // all neg
        for(int i=n-2; i>=0; i--) {
            r.push_back({i+1, mii+1});
            r.push_back({i+1, mii+1});
            mii = i;
        }
        goto RES;
    }

RES:
    cout << r.size() << endl;
    for(auto &t: r)
        cout << t.second << ' ' << t.first << endl;

    return 0;
}


Measured memory_bytes: 256
//{{{
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printw) FUNC(printwe) FUNC(printb) FUNC(printbe) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

struct Graph{
    struct Edge{
        int cost, from, dest;
        Edge(int cost, int dest): cost(cost), from(-1), dest(dest){ }
        Edge(int cost, int from, int dest): cost(cost), from(from), dest(dest){ }
        // bool operator == (const Edge& e) const { return cost == e.cost; }
        // bool operator < (const Edge& e) const { return cost < e.cost; }
        // bool operator == (const Edge& e) const { return from == e.from && dest == e.dest; }
        ostream& operator >> (ostream& out) const {
            return out << '(' << cost << ':' << from << ' ' << dest << ')';
        }
    };
    struct Node{
        vector<Edge> edges;
        int color = 0;
    };
    vector<Node> nodes;
    Graph(int num): nodes(num){ }
    int id(Node* n){ return n - &nodes[0]; }
    int id(Node& n){ return &n - &nodes[0]; }
    // void print(){ for(auto& node : nodes){ prints(id(node), node.outEdges); } }
    void add1Edge(int from, int dest, int cost = 1){
        nodes[from].edges.emplace_back(cost, dest);
    }
    void add2Edge2(int from, int dest, int cost = 1){
        add1Edge(from, dest, cost);
        add1Edge(dest, from, cost);
    }
    void dfs(int idx, int from = -1, int color = 0){
        printde(idx, color);
        nodes[idx].color = color;
        for(auto e : nodes[idx].edges){
            if(e.dest == from){ continue; }
            dfs(e.dest, idx, color ^ (e.cost & 1));
        }
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    Graph g(n);
    for(int i = 0; i < n - 1; i++){
        int u, v, w;
        cin >> u >> v >> w;
        u--; v--;
        g.add2Edge2(u, v, w);
    }
    g.dfs(0);
    for(int i = 0; i < n; i++){
        cout << g.nodes[i].color << '\n';
    }
}


Measured memory_bytes: 9344
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);

        final int n = scanner.nextInt();
        final int l = scanner.nextInt();

        final int first = l;
        final int last = l + n - 1;
        final int sum = n * (2 * l + (n - 1)) / 2;

        if (first <= 0 && last >= 0) {
            System.out.println(sum);
        } else {
            if (Math.abs(first) < Math.abs(last)) {
                System.out.println(sum - first);
            } else {
                System.out.println(sum - last);
            }
        }
    }
}

Measured memory_bytes: 24916
#include <bits/stdc++.h>
#include <math.h>
#define ll long long
using namespace std;

int main() {
  ll N,K,sum=0;
  cin>>N>>K;
  ll H[N];
  for(int i=0;i<N;i++) cin>>H[i];
  sort(H,H+N);
  reverse(H,H+N);
  for(int i=K;i<N;i++) sum+=H[i];
  cout<<sum<<endl;
}	


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
    
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldb;
    
#define MOD 1000000007
#define MIN 18446744073709551615
#define ff first
#define ss second
#define pub push_back
#define pob pop_back
#define vii vector<int>
#define pii pair<int,int>
#define vpii vector<pii>
#define sz(x) (x.size())
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int T=1;
	//cin>>T;
	while(T--)
	{
		int n;
		cin>>n;
		cout<<(1000-(n%1000))%1000;
	}
	return 0;
}

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

const int INF = 1001001001;

int main(){
	int n;cin >> n;
	if(n%2==0){
		cout << n/2;
	}else{
		cout << n/2+1;
	}

	return 0;
}

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

void f(double n,double m){
  double ans=1e9;

  for(double i=0;i<n;i++){
    double j=n-i;
    double res=abs(sqrt(i*i+j*j)-m);
    ans=min(ans,res);
  }

  printf("%.10lf\n",ans);
} 

main(){
  double n,m;
  while(true){
    cin>>n>>m;
    if(n==0) break;
    f(n,m);
  }

}



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

int main() {
    int N,A,B;
    string S;
    cin >> N >> A >> B >> S;

    int toppa = 0,kaigai=1;
    vector<bool> isToppa(N,false);
    for(int i=0;i<N;i++){
        if(toppa<A+B){
            if(S[i]=='a'){
                toppa++; isToppa[i]=true;
            }else if(S[i]=='b'&&kaigai<=B){
                toppa++; isToppa[i]=true; kaigai++;
            }
        }
    }

    for(const auto& i:isToppa){
        if(i) cout << "Yes" << endl;
        else cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 896
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

ll power(ll x, ll y)
{
    ll ans = 1;
    while (y)
    {
        if (y & 1)
            ans = (ans * x) % MOD;
        x = (x * x) % MOD;
        y >>= 1;
    }
    return ans;
}

int main(void)
{
    string l;

    ll ans = 0;
    ll n = 0;

    cin >> l;

    for (int i = 0; i < l.size(); i++)
    {
        int d = l[i] - '0';
        ll len = l.size() - i - 1;

        if (d == 1)
        {
            ans += (power(2, n) * power(3, len)) % MOD;
            ans %= MOD;
            n++;
        }
    }

    ans += power(2, n);
    ans %= MOD;

    cout << ans << endl;
}

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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const int MC = (1<<26);
string S;
int b[MC];

int main(){
	cin >> S;
	fill(b,b+MC,(int)S.size());
	int mask = 0;
	for(auto c : S){
		mask ^= (1<<(c-'a'));
		++b[mask];
		repp(i,0,26){
			if(mask == (1<<i)) b[mask] = min(b[mask],1);
			b[mask] = min(b[mask],b[mask^(1<<i)]+1);
		}
		if(mask == 0) b[mask] = min(b[mask],1);
	}
	cout << b[mask] << endl;
	return 0;
}


Measured memory_bytes: 262660
// Last Change: 04/19/2019 23:42:36.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

int main() {
  int N;
  cin >> N;
  if (N == 1) {
    cout << "Hello World" << endl;
  } else {
    int A, B;
    cin >> A >> B;
    cout << A + B << endl;
  }

  //NS::LoopUntilZeroInpput();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long int ctr=0;
unordered_map<long long int,bool>visited;
unordered_map<long long int ,list<long long int >>m;
void dfs(long long int node)
{
    ctr++;
    visited[node]=true;
    for(auto x:m[node])
    {
        if(!visited[x])
        {
            dfs(x);
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long int n,M;
    cin>>n>>M;
     
    while(M--)
    {
        long long int a,b;
        cin>>a>>b;
      
        m[a].push_back(b);
        m[b].push_back(a);
 
    }
    long long int ans=0;
    
    for(long long int i=1;i<=n;i++)
    {
        visited[i]=false;
    }
 
    for(long long int i=1;i<=n;i++)
    {
        ctr=0;
        if(!visited[i])
        {
            dfs(i);
            ans=max(ans,ctr);
            
        }
    }
    cout<<ans;
    return 0;
} 


Measured memory_bytes: 50956
#include <cstdio>
#include <algorithm>

const int N = 100000 + 10;

int n, c, k, t[N];

int main() {
  scanf("%d%d%d", &n, &c, &k);
  for (int i = 1; i <= n; ++i) scanf("%d", &t[i]);
  std::sort(t + 1, t + n + 1);
  int ans = 0;
  for (int i = 1; i <= n;) {
    int temp = t[i] + k;
    for (int j = c; j-- && i <= n && t[i] <= temp;) ++i;
    ++ans;
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

int main(){
    int a, b, c, d, inicio, fim, tempo;
    scanf("%d %d %d %d", &a, &b, &c, &d);
    if (a >= c)
        inicio = a;
    else if (c > a)
        inicio = c;
    if (b <= d)
        fim = b;
    else if (d < b)
        fim = d;
    tempo = fim-inicio;
    if (tempo <= 0)
        printf("%d\n", 0);
    else
        printf("%d\n", tempo);
    return 0;
}


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

using namespace std;

class UnionFind {
 public:
  vector<int> parent;

  UnionFind(int n) : parent(n, -1) {}

  int root(int x) {
    if (parent[x] < 0) return x;
    return parent[x] = root(parent[x]);
  }

  bool issame(int x, int y) { return root(x) == root(y); }

  int size(int x) { return -parent[root(x)]; }

  bool unite(int x, int y) {
    int rx = root(x), ry = root(y);
    if (rx == ry) return false;
    if (parent[rx] > parent[ry]) swap(rx, ry);
    parent[rx] += parent[ry];
    parent[ry] = rx;
    return true;
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M, K;
  cin >> N >> M >> K;
  UnionFind uf(N);
  vector<int> res(N, 0);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    res[a]--, res[b]--;
    uf.unite(a, b);
  }
  for (int i = 0; i < K; i++) {
    int c, d;
    cin >> c >> d;
    c--, d--;
    if (uf.issame(c, d)) res[c]--, res[d]--;
  }
  for (int i = 0; i < N; i++) {
    cout << res[i] + uf.size(i) - 1 << (i == N - 1 ? '\n' : ' ');
  }
  return 0;
}


Measured memory_bytes: 1664
from math import factorial

N, K = map(int, input().split())
mod = 10**9 + 7

def cmb(n, r):
    if n >= r:
        return int(factorial(n) // (factorial(r) * factorial(n-r)))
    else:
        return 0

for i in range(1, K+1):
    print(cmb(N-K+1, i) * cmb(K-1, i-1) % mod)

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

int main() {
    int n;
    cin >> n;
    vector<pair<int, int>> abs(n);
    rep(i, n) cin >> abs[i].first >> abs[i].second;

    sort(abs.begin(), abs.end());
    cout << abs[n - 1].first + abs[n - 1].second << endl;
}


Measured memory_bytes: 3988
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define endl "\n"
using ll=long long;
using ld=long double;
using namespace std;
const ll mod= 1e9+7;
const ll INF = 1LL<<40;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }


ll n,a,b,ans=0;

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}


int main(){
  cin>>n>>a>>b;
  ll tmp=1;
  ll xx=n%10;
  rep(i,0,n/10){
    tmp=(tmp*1024)%mod;
  }
  rep(i,0,xx)tmp=(tmp*2)%mod;
  ll k1=1,k2=1;
  rep(i,0,a){
    k1=(k1*(n-i))%mod;
    k2=(k2*(i+1))%mod;
  }
  ll k3=k1*modinv(k2,mod)%mod;

  ll j1=1,j2=1;
  rep(i,0,b){
    j1=(j1*(n-i))%mod;
    j2=(j2*(i+1))%mod;
  }
  ll j3=j1*modinv(j2,mod)%mod;
  ll sub=(k3+j3+1)%mod;
  tmp-=sub;
  if(tmp<0)tmp+=1e9+7;
  cout<<tmp;
}

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

int compare(const void *a,const void *b){
    if(*(int *)a>*(int *)b)return 1;
    return -1;
}
int main()
{   int a,b,x,y,n,m,k,c;
    scanf("%d%d",&n,&x);
    int l[n+1],d[n+1],ans=1;
    l[0]=0;
    d[0]=0;
    for(int i=1;i<n+1;i++){
        scanf("%d",&l[i]);
        d[i]=d[i-1]+l[i];
        if(d[i]<=x)ans++;
    }
    printf("%d",ans);

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define reps(i,s,n) for (int i = s; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
#define per(i,n) for (int i = n - 1; i >= 0; --i)
#define per1(i,n) for (int i = n; i >= 1; --i)
#define all(c) begin(c),end(c)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline T intceil(T a, T b) { return (a + (b - 1)) / b; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const long long MOD = 1e9+7;
#define precout() cout << std::fixed << std::setprecision(20);
const string alphabet = "abcdefghijklmnopqrstuvwxyz";
const int dy[4] = { 0, 1, 0, -1 };
const int dx[4] = { 1, 0, -1, 0 };
// if(nextH >= 0 && nextH < H && nextW >= 0 && nextW < W)
static const long double pi = acos(-1.0);
typedef complex<ld> cd;

ll dp[105][4][2];

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

    string N; cin >> N;
    int n = N.size();
    int K; cin >> K;
    dp[0][0][0] = 1;

    rep(i, n) {
        rep(j, K + 1) {
            rep(k, 2) {
                int nd = N[i] - '0';
                rep(d, 10) {
                    if((j + (d != 0)) > K) continue; // 非0がKを超えてしまう
                    if(!k && d > nd) continue;

                    dp[i + 1][j + (d != 0)][k || d < nd] += dp[i][j][k];
                }
            }
        }
    }

    ll ans = dp[n][K][0] + dp[n][K][1];
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

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

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

    int X, N;
    cin >> X >> N;

    vi p(N);
    rep(i, N) cin >> p[i];
    sort(all(p));

    int ans = 1000;

    reple(i, -100, 200)
    {
        if (binary_search(all(p), i)) continue;

        if (abs(X - i) < abs(X - ans)) ans = i;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
using namespace std;
int main(){
	int a,b,c,x,n=0;
	cin>>a>>b>>c>>x;
	for(int A=0;A<=a;A++)
		for(int B=0;B<=b;B++)
			for(int C=0;C<=c;C++){
				if(A*500+B*100+C*50==x) n++;
			}
	cout<<n;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
    int N,A,B,c,d,i,z;

    scanf("%d%d%d",&N,&A,&B);
    d=0;
    for(i=0;i<=N;i++){
        c=0;z=i;
        for(int j=0;j<5;j++){
            c+=z%10;
            z/=10;
        }
        if((c>=A)&&(c<=B)) d+=i;
    }
    printf("%d\n",d);
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#define maxn 100010
using namespace std;
typedef long long ll;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,m;
struct P{
    int to,op;
};
vector<P>e[maxn];
int cnt[3];
int col[maxn],vis[maxn],flag;
int nxt(int x,int op)
{
    return (x+op+3)%3;
}
ll ans;
int sum;
void dfs(int x,int co)
{
    vis[x]=1;
    col[x]=co;
    cnt[co]++;
    for(int i=0;i<e[x].size();i++)
    {
        sum++;
        int v=e[x][i].to;
        if(vis[v])
        {
            if(col[v]!=nxt(co,e[x][i].op))  flag=1;
        }
        else{
            dfs(v,nxt(co,e[x][i].op));
        }
    }
}
int main()
{
    n=read();m=read();
    for(int i=1;i<=m;i++)
    {
        int q=read(),w=read();
        e[q].push_back((P){w,1});
        e[w].push_back((P){q,-1});
    }
    for(int i=1;i<=n;i++)
    {
        if(!vis[i])
        {
            cnt[0]=cnt[1]=cnt[2]=0;
            flag=0;sum=0;
            dfs(i,0);
            sum/=2;
            if(flag)
            {
                ans+=1ll*(cnt[0]+cnt[1]+cnt[2])*(cnt[0]+cnt[1]+cnt[2]);
            }
            else{
                if((!cnt[0])||(!cnt[1])||(!cnt[2]))  ans+=sum;
                else         ans+=1ll*cnt[0]*cnt[1]+1ll*cnt[1]*cnt[2]+1ll*cnt[2]*cnt[0];
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 11136
n = int(input())
*h, = map(int, input().split())

ans = "Yes"
for i in reversed(range(len(h)-1)):
    d = h[i+1] - h[i]
    if d == -1:
        h[i] -= 1
    elif d < -1:
        ans = "No"

print(ans)


Measured memory_bytes: 14224
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using node = tuple<int, int, int>;
const int inf = numeric_limits<int>::max()/3;
const ll mod = 1e9+7;

int main(void){
  int n;
  cin >> n;
  vector<int> a(n);
  vector< P > ans;
  int abs_max = 0;
  for(int i = 0;i < n;++i){
    cin >> a[i];
    if(abs(a[i]) > abs(a[abs_max]))
      abs_max = i;
  }
  if(a[abs_max] >= 0){
    for(int i = 0;i < n;++i){
      if(a[i] < 0){
        ans.push_back(P(abs_max+1,i+1));
      }
    }
    for(int i = 1;i < n;++i){
      ans.push_back(P(i,i+1));
    }
  }else{
    for(int i = 0;i < n;++i){
      if(a[i] > 0){
        ans.push_back(P(abs_max+1,i+1));
      }
    }
    for(int i = n-1;i > 0;--i){
      ans.push_back(P(i+1,i));
    }
  }
  cout << (int)ans.size() << endl;
  for(auto p :ans){
    cout << p.first << " " << p.second << endl;
  }
  return 0;
}


Measured memory_bytes: 256