akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ALL(a)  (a).begin(),(a).end()

int main(){
    string n;
    cin >> n;
    for(int i = 0; i < n.length(); ++i){
        if(n[i]=='9')n[i]='1';
        else if(n[i]=='1')n[i]='9';
    }
    cout << n << endl;
}

Measured memory_bytes: 256
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#include<bits/stdc++.h>
using namespace std;

#if defined(DAIJOBU)
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}

int grid[4][12];

int main(){
	//FIO
	
	int m, f, r;
	while(cin >> m >> f >> r){
		if(m == -1 && f == -1 && r == -1)break;
		if(m == -1 || f == -1)puts("F");
		else if(m + f >= 80)puts("A");
		else if(m + f >= 65 && m + f < 80)puts("B");
		else if(m + f >= 50 && m + f < 65)puts("C");
		else if(m + f >= 30 && m + f < 50){
			if(r >= 50)puts("C");
			else puts("D");
		}
		else if(m + f < 30)puts("F");
	}
	return 0;
}



Measured memory_bytes: 3092
#include<stdio.h>
int main()
{
	int n,sum=0;
	scanf("%d",&n);
	int t = n;
	while(n){
		sum=sum+n%10;
		n=n/10;
	}
	if(t%sum==0)
	printf("Yes");
	else
	printf("No");
	return 0;
}

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

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();

		if(n*a < b)
			System.out.println(n*a);
		else
			System.out.println(b);
	}
}


Measured memory_bytes: 21972
from collections import defaultdict
N = int(input())
S = [input() for _ in range(N)]
d = defaultdict(int)
for s in S:
    d[s] += 1

print('AC x {}'.format(d['AC']))
print('WA x {}'.format(d['WA']))
print('TLE x {}'.format(d['TLE']))
print('RE x {}'.format(d['RE']))


Measured memory_bytes: 83044
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
#define gg(u) for(int &i=cur[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
typedef long long ll;
const int N=1e5+5;
ll f[N],g[N],sum,res;int a[N],b[N],c[N],id[N],x,y,z,n,sz;
priority_queue<int,vector<int>,greater<int> >q;
inline bool cmp(const int &x,const int &y){return a[x]-b[x]>a[y]-b[y];}
inline void ins(R int x){sum+=x,q.push(x),++sz;}
inline void del(){sum-=q.top(),q.pop(),--sz;}
int main(){
//	freopen("testdata.in","r",stdin);
	scanf("%d%d%d",&x,&y,&z),n=x+y+z;
	fp(i,1,n){
		scanf("%d%d%d",&a[i],&b[i],&c[i]);
		a[i]-=c[i],b[i]-=c[i],id[i]=i;
	}
	sort(id+1,id+1+n,cmp);
	sum=sz=0;while(!q.empty())q.pop();
	fp(i,1,n){
		ins(a[id[i]]);
		while(sz>x)del();
		if(sz==x)f[i]=sum;
	}
	sum=sz=0;while(!q.empty())q.pop();
	fd(i,n,1){
		ins(b[id[i]]);
		while(sz>y)del();
		if(sz==y)g[i]=sum;
	}
	res=-1e18;
	fp(i,x,n-y)cmax(res,f[i]+g[i+1]);
	fp(i,1,n)res+=c[i];
	printf("%lld\n",res);
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
int a[100005];
int b[100005];
int main()
{
    //freopen("t5.in","r",stdin);
   //freopen("t5.out","w",stdout);
    int i,j,n,m,q;
    string x;
    cin>>n>>m>>q;
    int a1,b1,c;
    int maxn=99999999;
    int m1=99999999;
    int m2=99999999;
    for(i=1;i<=n;i++){scanf("%d",&a[i]);m1=min(m1,a[i]);}
    for(i=1;i<=m;i++){scanf("%d",&b[i]);m2=min(m2,b[i]);}
    maxn=m1+m2;
    while(q--)
    {
       scanf("%d%d%d",&a1,&b1,&c);
       maxn=min(maxn,a[a1]+b[b1]-c);
    }
    cout<<maxn<<endl;
    return 0;
}


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

int get_gcd(int a, int b){
        int r = a % b;
        if (r == 0){
            return b;
        }
        else {
            return get_gcd(b, r);
        }
}

int main(){
    int a, b, gcd;
    cin >> a >> b;
    if (a >= b){
        gcd = get_gcd(a, b);
    }
    else{
        gcd = get_gcd(b, a);
    }
    
    long  lcm = (long) a * (b/gcd);
    cout << lcm << endl;

} 

Measured memory_bytes: 256
import java.util.*;

//update 2020/1/1 23:01

public class Main{

  static Scanner sc = new Scanner(System.in);
  static StringBuilder sb = new StringBuilder();

  public static void main(String[] args) {

    int n = nextInt();
    int m = nextInt();

    long[][] h = new long[n][2];

    for(int i=0;i<n;i++){
      h[i][0] = nextInt();
    }

    for(int i=0;i<m;i++){
      int a = nextInt();
      int b = nextInt();
      if(h[a-1][0]>=h[b-1][0]){ //aの方が高いなら
        h[b-1][1]++;           //bはだめ
      }
      if(h[b-1][0]>=h[a-1][0]){ //bの方が高いなら
        h[a-1][1]++;           //aはだめ
      }
    }


    int ans = 0;
    for(int i=0;i<n;i++){
      if(h[i][1]==0){
        ans++;
      }
    }



    System.out.println(ans);

  }

  static int lcm(int a,int b){
    return a*b*gcd(a,b);
  }

  static int gcd(int a,int b){
    if(a%b!=0){
      return gcd(b,a%b);
    }
    else{
      return b;
    }
  }

  /*
    static String toSmall(String s){
      char c = s.charAt(0);
      //if(Character.isUpperCase(c)){
      if(c<=90){
        c += 32;
      }
      return String.valueOf(c);
    }
    static String toBig(String s){
      char c = s.charAt(0);
      //if(Character.isLowerCase(c)){
      if(c>=97){
        c -= 32;
      }
      return String.valueOf(c);
    }
  */

  static String toSmall(String s){
    return s.toLowerCase();
  }

  static String toBig(String s){
    return s.toUpperCase();
  }

  static String next(){
    return sc.next();
  }

  static int nextInt(){
    return Integer.parseInt(sc.next());
  }

  static long nextLong(){
    return Long.parseLong(sc.next());
  }

  static double nextDouble(){
    return Double.parseDouble(sc.next());
  }

  static String[] splitString(String s){
    return s.split("");
  }

  static char[] splitChar(String s){
    return s.toCharArray();
  }

  static int charToInt(char a){
    return a - 48;
  }

////////////////////////////////////////////
  public static int max(int[] a){
    int lng = a.length;
    int max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
  public static long max(long[] a){
    int lng = a.length;
    long max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
////////////////////////////////////////////

////////////////////////////////////////////
  public static int min(int[] a){
    int lng = a.length;
    int min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
  public static long min(long[] a){
    int lng = a.length;
    long min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
////////////////////////////////////////////

}


Measured memory_bytes: 63548
import sys
from itertools import accumulate
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり


class BIT:
    def __init__(self,init_value):
        self.n = len(init_value)
        self.tree = [0]*(self.n+1)
        for i in range(1,self.n+1):
            x = init_value[i-1]
            while i <= self.n:
                self.tree[i] += x
                i += i & (-i)

    def update(self,i,x):  # i(1-index)番目の値を+x
        while i <= self.n:
            self.tree[i] += x
            i += i & (-i)
        return

    def query(self,i):  # 1番目からi(1-index)番目までの和を返す
        res = 0
        while i > 0:
            res += self.tree[i]
            i -= i & (-i)
        return res


N = I()
A = LI()


def f(x):  # A[l:r+1] の中央値が x 以上になる (l,r) の個数が、全体の半分以上あるか
    B = [0] + [1 if A[i] >= x else -1 for i in range(N)]
    B = list(accumulate(B))
    B = [b+N+1 for b in B]  # 全て正になるように補正
    # Bi <= Bj たる (i,j) の個数を数える
    bit = BIT([0]*(2*N+2))
    count = 0
    for i in range(N+1):
        b = B[i]
        count += bit.query(b)
        bit.update(b,1)
    if count >= (N*(N+1)+3)//4:
        return True
    return False


ok = 1
ng = 10**9+1
while ok+1 < ng:
    mid = (ok+ng)//2
    if f(mid):
        ok = mid
    else:
        ng = mid

print(ok)


Measured memory_bytes: 182776
/*
NAME:
 ___   _      _   ___  
/ __| /_\    /_\ |   \ 
\__ \/ _ \  / _ \| |) |
|___/_/ \_\/_/ \_\___/ 
 
lang: 
  ___   _      _   
 / __)_| |_  _| |_ 
( (__(_   _)(_   _)
 \___) |_|    |_|  
 
*/
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>
 
using namespace std;
 
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
 
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(),x.end()
 
typedef long long ll;
typedef long l;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<l> vl;
typedef vector<ll> vll;
 
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};
 
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }
 
void solve(){
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++) cin>>a[i];
	int ans=0;
	int lower=a[0];
	for(int i=1;i<n;i++){
		if(a[i]<lower){
			ans++;
			lower=a[i];
		}
	}
	cout<<ans+1<<endl;
	
}
 
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
 
	solve();
 
	return 0;
} 


Measured memory_bytes: 1024
import java.util.*;

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=0;
    
    if(((A==1)||(A==2))&&((B==1)||(B==2))){
      C=3;
    }
    if(((A==1)||(A==3))&&((B==1)||(B==3))){
      C=2;
    }
    if(((A==3)||(A==2))&&((B==3)||(B==2))){
      C=1;
    }
    
    System.out.println(C);
  }
}

Measured memory_bytes: 22608
use proconio::input;

fn main() {
    input! {
        a: String,
        b: String,
    };
    if a.len() > b.len() {
        println!("GREATER");
    } else if a.len() < b.len() {
        println!("LESS");
    } else {
        if a > b {
            println!("GREATER");
        } else if a < b {
            println!("LESS");
        } else {
            println!("EQUAL");
        }
    }
}


Measured memory_bytes: 2128
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		String ans = "No";

		for(int i = 1; i < 10; i++) {
			if(num % i == 0 && num < i *10) {
				ans = "Yes";
				break;
			}
		}

		System.out.println(ans);
	}
}




Measured memory_bytes: 21844
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

template<typename T>
T power(T x, long long n){
    if(n == 0) return 1;
    if(n == 1) return x;
    T tmp = power(x, n/2);
    if(n%2 == 0) return tmp * tmp;
    else return tmp * tmp * x;
}

ll N, M, D;
double ans = 0;
double f(double N, double D){
    if(D == 0) return N;
    else return (N-D)*2;
}

signed main(){
    cin >> N >> M >> D;
    ans = (double)(M-1)*f(N,D)/N/N;
    cout << fixed << setprecision(16) << ans << endl;
}

Measured memory_bytes: 3768
#include<iostream>
    using namespace std;
    int main()
    {
        int a, b;
        string s, t, u;
        cin >> s >> t;
        cin >> a >> b;
        cin >> u;
        int r=1;
        for (int i = 0; i < s.length(); i++) {
            if (s[i] == u[i]) {
                r = 1;
            }
            else {
                r = 0;
            }
        }
        if (r) {
            int y = a - 1;
            cout << y<<" "<<b;
        }
        else {
            int y = b - 1;
            cout << a<< " "<<y ;
        }
        return 0;
    }

Measured memory_bytes: 256
#include <iostream>
#include <string> 
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
map<string,int> s; 
vector<string> ans;
int main(){
	int n;
	cin>>n;
	while(n--){
		string a;
		cin>>a;
		s[a]++;
	}
	auto it=s.begin();
	int max0=0;
	while(it!=s.end()){
		if(it->second>max0) max0=it->second;
		it++;
	}
	it=s.begin();
	while(it!=s.end()){
		if(it->second==max0) ans.push_back(it->first);
		it++; 
	}
	sort(ans.begin(),ans.end());
	for(auto it=ans.begin();it!=ans.end();it++)
		cout<<*it<<endl;
	return 0;
} 

Measured memory_bytes: 26868
import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """5 1
00010"""
        output = """4"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """14 2
11101010110011"""
        output = """8"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """1 1
1"""
        output = """1"""
        self.assertIO(input, output)

def resolve():
    (N,K) = (int(i) for i in input().split())
    S=input()
    l=[]
    flg=False
    if S[0]=='0':
        l.append([0,0])
    for i in range(len(S)):
        if flg==True and S[i]=='0':
            l[-1].append(i)
            flg=False
        if flg==False and S[i]=='1':
            l.append([i])
            flg=True
    if S[-1]=='0':
        l.append([len(S),len(S)])
    else:
        l[-1].append(len(S))
    if K>=len(l)-1:
        print(len(S))
        return()

    print(max( [ l[i+K][1]-l[i][0] for i in range(len(l)-K)] ) )
       

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 59244
//In The Name of Allah
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 400 + 10;
const ll mod = 1e9 + 7;

ll a[N], b[N], pre[N][N], dp[N][N];

ll Pow(ll a, ll b){
    ll res = 1;
    for (; b; b = b >> 1)
        res = res * (b & 1 ? a : 1) % mod, a = a * a % mod;
    return res;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll n, c;
    cin >> n >> c;
    for (ll i = 1; i <= n; i ++)
        cin >> a[i], a[i] --;
    for (ll i = 1; i <= n; i ++)
        cin >> b[i];
    for (ll i = 1; i < N; i ++)
        for (ll j = 0; j < N; j ++)
            pre[i][j] = (pre[i - 1][j] + Pow(i, j)) % mod;
    for (ll i = 0; i <= c; i ++)
        dp[1][i] = (pre[b[1]][i] - pre[a[1]][i]) % mod;
    for (ll i = 2; i <= n; i ++)
        for (ll j = 0; j <= c; j ++)
            for (ll k = 0; k <= j; k ++)
                dp[i][j] = (dp[i][j] + (pre[b[i]][k] - pre[a[i]][k]) % mod * dp[i - 1][j - k] % mod) % mod;
    cout << (dp[n][c] + mod) % mod;
    return 0;
}

Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
long long n,times=1,upper;
string s;
int main()
{
	cin>>n;
	while(1)
	{
		upper=0;
		for(long long i=1;i<=times*26;i*=26)upper+=i;
		if(upper>n)break;
		times*=26;
	}
	for(long long i=1;i<=times;i*=26)n-=i;
	while(times>1)
	{
		long long neww=n/times;
		s=s+(char)(neww+'a');
		n-=times*neww;
		times/=26;
	}
	s=s+(char)(n+'a');
	cout<<s;
	return 0;
}

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

#define endl '\n'
#define ll long long
#define re register
#define pb(x) push_back(x)
#define ce(x) cout << x << '\n';

using db = long double;
using pll = pair < ll, ll >;

#define rep(i,x,n,inc) for(i=x ; i<n ; i+=inc)
#define repr(i,x,n,inc) for( i=x ; i>n ; i+=inc)
#define all(a)      (a).begin(),(a).end()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define hell 1000000007
const db pi = acos(-1);
const long long infl = LLONG_MAX;

ll power(ll x, ll y, ll p=hell) 
{ 
    ll res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or 
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
} 
  
// Returns n^(-1) mod p 
ll modInverse(ll n, ll p=hell) 
{ 
    return power(n, p-2, p); 
} 
  
// Returns nCr % p using Fermat's little 
// theorem. 
ll nCrModPFermat(ll n, ll r, ll p=hell) 
{ 
   if (r==0) 
      return 1; 
    ll fac[n+1]; 
    fac[0] = 1; 
    for (int i=1 ; i<=n; i++) 
        fac[i] = fac[i-1]*i%p; 
  
    return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 
} 
int32_t main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

ll t,i,x,j,y,z,k,n;

cin>>x>>y;
z=x+y;
if(z%3){
	return cout<<0,0;
}
ll a,b;
a=2*z/3,b=z/3;
if(max(x,y)>a)return cout<<0,0;

ce(nCrModPFermat(z/3,y-z/3)%hell)
}
//151840682

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

const int N=4010,mod=998244353;
char s[N];
istream& operator >> (istream&in,bitset<N>&a){
	in>>s;int n=strlen(s);a.reset();
	for(int i=0;i<n;++i)a[n-i-1]=s[i]&1;
	return in;
}
int ans,n;
bitset<N>X,Y,A,B;
int len(const bitset<N>&a){for(int i=N-1;i>=0;--i)if(a[i])return i;return -1;}
void rem(bitset<N>&a,const bitset<N>&b){
	int j=len(b);
	for(int i=N-1;i>=j;--i)if(a[i])a^=b<<(i-j);
}


int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>X;
	for(int i=1;i<=n;++i){
		cin>>A;
		for(;B.any();swap(A,B))rem(A,B);
		swap(A,B);
	}
	int L=len(B);
	for(int i=N-1;i>=L;--i)
		ans=(ans*2+X[i])%mod;
	rem(Y=X,B);
	for(int i=L-1;i>=0;--i)
		if(Y[i]){
			if(!X[i])--ans;
			break;
		}
	cout<<(ans+1)%mod<<'\n';
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mpair make_pair
#define pm(first, second) pb(mpair(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()
#define reall(X) (X).rbegin(), (X).rend()
#define divcel(a, b) (((a) + ((b) - 1)) / (b))

int main(){

    int a, b;
    cin >> a >> b;
    cout << max(a + b, max(a - b, a * b));    

    return 0;
}

Measured memory_bytes: 256
str = list(input())
s = []
for i in str:
    s.append(int(i))

for i in range(len(s)):
    if i == 0:
        if s[i] == s[i+1]:
            print("Bad")
            exit(0)
    elif i == 3:
        if s[i] == s[i-1]:
            print("Bad")
            exit(0)
    else:
        if s[i] == s[i+1]: 
            print("Bad")
            exit(0)
        elif s[i] == s[i-1]:
            print("Bad")
            exit(0)
print("Good")

    


Measured memory_bytes: 3064
# -*- coding: utf-8 -*-

import sys
sys.setrecursionlimit(10**7)

def search(values,hp,vp,item):
	if not (0<=hp<len(values)): return
	if not (0<=vp<len(values[hp])): return
	if item!=values[hp][vp]: return
	values[hp][vp]=True
	search(values,hp-1,vp,item)
	search(values,hp+1,vp,item)
	search(values,hp,vp-1,item)
	search(values,hp,vp+1,item)

def solve(values):
	count,valid_items=0,set(['@','#','*'])
	for i in range(len(values)):
		for j in range(len(values[i])):
			if values[i][j] in valid_items:
				search(values,i,j,values[i][j])
				count+=1
	return count

def main():
	line,values=input().strip(),list()
	while line!='0 0':
		H,W = list(map(int,line.split(' ')))
		value = list()
		for _ in range(H):
			value.append(list(x for x in input().strip()))
		values.append(value)
		line = input().strip()
	for value in values:
		print(solve(value))

if __name__=='__main__':
	main()

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

int main() {
  int n;
  cin >> n;
  vector<vector<ll>> A(n, vector<ll>(n));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) cin >> A[i][j];
  }

  set<pair<int, int>> no_way;

  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (i == k || j == k || i == j) continue;

        if (A[i][j] > A[i][k] + A[k][j]) {
          cout << -1 << endl;
          return 0;
        }
        else if (A[i][j] == A[i][k] + A[k][j]) {
          no_way.insert({i, j});
        }
      }
    }
  }


  ll ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (!no_way.count({i, j})) ans += A[i][j];
    }
  }

  cout << ans / 2 << endl;

  return 0;
}

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

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<pii> vpii;

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    string s;
    cin >> s;

    if (s == "Sunny") {
        cout << "Cloudy" << endl;
    } else if (s == "Cloudy") {
        cout << "Rainy" << endl;
    } else {
        cout << "Sunny" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define set_null(a,n) memset(a,0,sizeof(a))
#define pi acos(-1)
#define ll long long int
#define fr(a,b) for(int p=a;p<b;p++)
#define modulo 1000000007

int main()
{
    int n,m;
    cin>>n>>m;
    ll sum=0;

    for(int i=0;i<m;i++)
    {
        int x;
        cin>>x;
        sum+=x;
    }
    if(sum<=n)
    {
        cout<<n-sum<<endl;
    }
    else{
        cout<<-1<<endl;
    }

    return 0;
}



Measured memory_bytes: 3676
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 5005

ll K,Q;
ll D[SIZE],work[SIZE];
ll COUNT[SIZE];


int main(){

	scanf("%lld %lld",&K,&Q);

	for(int i = 0; i < K; i++){

		scanf("%lld",&D[i]);
	}

	ll n,x,m;

	for(int loop = 0; loop < Q; loop++){

		scanf("%lld %lld %lld",&n,&x,&m);

		ll tmp = x%m;
		ll minus = 0;

		for(int i = 0; i < K; i++){

			work[i] = D[i]%m;

			COUNT[i] = (n-1)/K;
			if((n-1)%K >= i+1){

				COUNT[i]++;
			}

			tmp += work[i]*COUNT[i];

			if(work[i] == 0){

				minus += COUNT[i];
			}
		}

		printf("%lld\n",(n-1)-minus-tmp/m);
	}

	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define MOD 1000000007
#define Nmax 805
#define pii pair<int,int>
using namespace std;

int h, w, k, x, y,mn[Nmax][Nmax], ans;
char mat[Nmax][Nmax];
int dx[] = {0,1,-1,0};
int dy[] = {1,0,0,-1};

bool OK(int x, int y, bool free){
    if (x > h || y > w || x <= 0 || y <= 0) return 0;
    if (mat[x][y] == '#' && !free) return 0;
    return 1;
}

vector<pii> Q;
void prec(){
    Q.push_back({x,y});
    mn[x][y] = 1;
    for (int i=0;i<Q.size();i++){
        if (Q[i].first == 1 || Q[i].first == h || Q[i].second == 1 || Q[i].second == w){
            cout << 1 << '\n';
            exit(0);
        }
        for (int j=0;j<4;j++){
            int X = Q[i].first + dx[j];
            int Y = Q[i].second + dy[j];
            if (OK(X,Y,0)){
                if ((mn[X][Y] == 0 || mn[X][Y] > mn[Q[i].first][Q[i].second] + 1) && mn[Q[i].first][Q[i].second] + 1 <= k + 1){
                    Q.push_back({X,Y});
                    mn[X][Y] = mn[Q[i].first][Q[i].second] + 1;
                }
            }
        }
    }
}

int OK(){
    vector<pii> H;
    memset(mn,0,sizeof(mn));
    for (auto it : Q){
        H.push_back(it);
        mn[it.first][it.second] = 1;
    }
    for (int i=0;i<H.size();i++){
        if (H[i].first==1 || H[i].second == 1 || H[i].first == h || H[i].second == w){
            return ((mn[H[i].first][H[i].second] + k-2) / k) + 1;
        }
        for (int j=0;j<4;j++){
            int X = H[i].first + dx[j];
            int Y = H[i].second + dy[j];
            if (OK(X,Y,1)){
                if (mn[X][Y] == 0 || mn[X][Y] > mn[H[i].first][H[i].second] + 1){
                    H.push_back({X,Y});
                    mn[X][Y] = mn[H[i].first][H[i].second] + 1;
                }
            }
        }
    }
}

int main()
{
    cin >> h >> w >> k;
    for (int i=1;i<=h;i++){
        cin >> mat[i] + 1;
        for (int j=1;j<=w;j++){
            if (mat[i][j] == 'S'){
                x = i;
                y = j;
            }
        }
    }

    prec();
    cout << OK();
    return 0;
}


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

using namespace std;
typedef long long ll;

ll calc_string_formula(string formula) {
    vector<ll> num;
    int lead_index = 0;
    for(int i = 0; i < formula.size(); i++) {
        if(i == formula.size() - 1) {
            string _num_str = formula.substr(lead_index, i - lead_index + 1);
            num.push_back(atoll(_num_str.c_str()));
            break;
        }

        char current = formula[i];

        if(current == '+') {
            string _num_str = formula.substr(lead_index, i - lead_index);
            num.push_back(atoll(_num_str.c_str()));
            lead_index = i + 1;
        }        
    }

    return accumulate(num.begin(), num.end(), 0LL);
}

int main(void) {
    string S;
    cin >> S;

    int S_length = S.size();

    vector<ll> values;

    for(int bit = 0; bit < (1 << S_length - 1); bit++) {
        string formula = S.substr(0, 1);

        for(int i = 0; i < S_length - 1; i++) {
            if(bit & (1 << i)) {
                formula += "+";
            }
            formula += S.substr(i + 1, 1);
        }

        //cout << "bit" << bit << " formula : " << formula << endl;

        values.push_back(calc_string_formula(formula));
    }

    cout << accumulate(values.begin(), values.end(), 0LL) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+10;
int n,m,add_s,add_t,ans,pos_s=1,pos_t=1;
char s[N],t[N];
signed main(){
	scanf("%lld %lld",&n,&m);
	scanf("%s",s+1);
	scanf("%s",t+1);
	add_s=m/__gcd(n,m);
	add_t=n/__gcd(n,m);
	ans=m*n/__gcd(n,m);
	for(int i=0;i<=n/add_t;i++){
		if(s[1+i*add_t]!=t[1+i*add_s]){
			printf("-1\n");
			return 0;
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 384
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        
        while (in.hasNextLine()) {
            int N = in.nextInt();
            int M = in.nextInt();
            if (N == 0 && M == 0) break;
            
            int[] arr = new int[N];
            int max = -99;
            
            for (int m = 0; m < M; m++) {
                for (int n = 0; n < N; n++) {
                    arr[n] += in.nextInt();
                    if (m == M - 1) {
                        max = Math.max(max, arr[n]);
                    }
                }
            }
            
            System.out.println(max);
        }
    }
}



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

using namespace std;
using ll = long long;

using Field = vector<vector<int>>;
using Graph = vector<vector<int>>;
using VI = vector<int>;
using VC = vector<char>;
using PI = pair<int, int>;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(x) x.begin(), x.end()

const long long INF = 1LL<<60;
const int mod = 1000000007;

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 N;
struct Infant{
    ll act;
    int x;
};
vector<Infant> A;

vector<vector<ll>> dp(2010, vector<ll>(2010, 0));


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

    cin >> N;
    A.resize(N);
    REP(i, N) {
        ll a; cin >> a;
        A.at(i).act = a;
        A.at(i).x = i;
    }

    deque<int> deq;

    REP(i, N) {
        deq.push_back(i);
    }

    sort(ALL(A), [] (Infant la, Infant ra) {return la.act > ra.act;});

    ll ans = 0;

    REP(i, N) {
        for (int j = 0; i + j < N; j++) {
            ll act = A.at(i + j).act;
            int x = A.at(i + j).x;

            chmax(dp.at(i + 1).at(j), dp.at(i).at(j) + act * (x - i));
            chmax(dp.at(i).at(j + 1), dp.at(i).at(j) + act * ((N - 1 - j) - x));
        }      
    }

    REP(i, N) {
        chmax(ans, dp.at(i).at(N - i));
    }

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

Measured memory_bytes: 35340
#include <algorithm>

#include <bitset>

#include <complex>

#include <deque>

#include <exception>

#include <fstream>

#include <functional>

#include <iomanip>

#include <ios>

#include <iosfwd>

#include <iostream>

#include <istream>

#include <iterator>

#include <limits>

#include <list>

#include <locale>

#include <map>

#include <memory>

#include <new>

#include <numeric>

#include <ostream>

#include <queue>

#include <set>

#include <sstream>

#include <stack>

#include <stdexcept>

#include <streambuf>

#include <string>

#include <typeinfo>

#include <utility>

#include <valarray>

#include <vector>



#if __cplusplus >= 201103L

#include <array>

#include <atomic>

#include <chrono>

#include <condition_variable>

#include <forward_list>

#include <future>

#include <initializer_list>

#include <mutex>

#include <random>

#include <ratio>

#include <regex>

#include <scoped_allocator>

#include <system_error>

#include <thread>

#include <tuple>

#include <typeindex>

#include <type_traits>

#include <unordered_map>

#include <unordered_set>

#endif
using namespace std;

int main(){
	string o,e;
	cin >> o >> e;
	int s = o.size();

	if (s == e.size()) {
		for (int i = 0;i < s;i++) {
			cout << o[i] << e[i];
		}
		cout << endl;
	}
	else {
		for (int i = 0;i < s - 1;i++) {
			cout << o[i] << e[i];
		}
		cout << o[s-1] << endl;
	}
	
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

int main()
{
	int X, Y;

	cin >> X >> Y;
	
	bool find = false;
	int total_l;
	int total_r;

	rep(i, X)
	{
		total_l = 2 * i + 4 * (X - i);
		total_r = 2 * (X - i) + 4 * i;

		if ( total_l == Y || total_r == Y) 
		{
			find = true;
			break;
		}
	}

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

	return 0;
}

Measured memory_bytes: 3620
# K   : 青
# N-K : 赤
MOD=10**9+7
M=10**6
fac=[1]*M
ifac=[1]*M
inv=[1]*M
for i in range(2,M):
    fac[i]=i*fac[i-1]%MOD
    inv[i]=MOD-(MOD//i)*inv[MOD%i]%MOD
    ifac[i]=inv[i]*ifac[i-1]%MOD

def comb(n,k):
    if n<0 or n-k<0 or k<0:
        return 0
    return fac[n]*ifac[n-k]%MOD*ifac[k]%MOD

N,K=map(int,input().split())
R=N-K
ans=[]
for i in range(1,K+1):
    v=comb((K-i)+i-1,(K-i))*comb((R-(i-1))+i,i)%MOD
    ans.append(v)
print(*ans,sep="\n")


Measured memory_bytes: 127796
using System;
using System.Collections.Generic;
namespace I_am_the_brown_coder{
    class Inonoa{
        static void Main(){
            string[] nabcd = Console.ReadLine().Split();
            int n = int.Parse(nabcd[0]);
            int a = int.Parse(nabcd[1]); 
            int b = int.Parse(nabcd[2]); 
            int c = int.Parse(nabcd[3]); 
            int d = int.Parse(nabcd[4]); 

            char[] s = Console.ReadLine().ToCharArray();
            bool[] isRock = new bool[n];
            for(int i=0;i<n;i++){
                if(s[i]=='#'){
                    isRock[i] = true;
                }
            }

            bool canJump = false;

            // 抜く判定:[b-2]から[d-2]のどこかから始まる三マスの空白があるか
            // 一人で行けるか判定:[a]からmax([c-3],[d-3])までの間のマスで始まるニマス以上の岩はあるか？
            int mx;
            if(c>d){
                mx = c;
            }else{
                mx = d;
                canJump = true;
            }

            for(int i=a;i<mx-1;i++){
                if((!canJump)&&i>b-3&&i<d-1){
                    if((!isRock[i])&&(!isRock[i+1])&&(!isRock[i+2])){
                        canJump = true;
                    }
                }
                if(isRock[i]&&isRock[i+1]){
                    Console.WriteLine("No");
                    return;
                }
            }

            if(canJump){
                Console.WriteLine("Yes");
                return;
            }
            Console.WriteLine("No");
        }
    }
}

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


int main(){
    string S;
    cin>>S;
    long ans=0;

    for(long bit=0;bit<(1<<S.size());bit++){
        long s=0;
        for(int i=0;i<S.size();i++){
            if(bit&(1<<i)){
                s=s*10+(S[i]-'0');
                if(i==S.size()-1)ans+=s;
            }
            else{
                ans+=s;
                s=0;
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
package main

import (
  "fmt"
)

func main() {
  var n, a int
  fmt.Scanf("%d", &n)
  fmt.Scanf("%d", &a)
  
  ans := "Yes"
  if (n % 500) - a > 0 {
    ans = "No"
  }
  fmt.Printf("%s\n", ans)
}

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

int main() {
    int n, W;
    cin >> n >> W;
    vector<int> val[4];
    ll w0;
    for (int i = 0; i < n; i++) {
        if (i == 0) {
            int v;
            cin >> w0 >> v;
            val[0].push_back(v);
        } else {
            int w, v;
            cin >> w >> v;
            val[w - w0].push_back(v);
        }
    }

    for (int i = 0; i < 4; i++) {
        sort(val[i].rbegin(), val[i].rend());
    }

    ll sum[4][101];
    for (int i = 0; i < 4; i++) {
        sum[i][0] = 0;
        for (int j = 1; j <= val[i].size(); j++) {
            sum[i][j] = sum[i][j - 1] + val[i].at(j - 1);
        }
    }

    ll ans = 0;
    for (int i = 0; i <= val[0].size(); i++) {
        for (int j = 0; j <= val[1].size(); j++) {
            for (int k = 0; k <= val[2].size(); k++) {
                for (int l = 0; l <= val[3].size(); l++) {
                    if (w0 * i + (w0 + 1) * j + (w0 + 2) * k + (w0 + 3) * l <= W) {
                        ans = max(ans, sum[0][i] + sum[1][j] + sum[2][k] + sum[3][l]);
                    }
                }
            }
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define FOR(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)

using namespace std;

int main() {
    int x, y;
    cin >> x >> y;
    int dat[] = { 1,3,1,2,1,2,1,1,2,1,2,1 };
    if (dat[x - 1] == dat[y - 1])
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

template<class Type> Type igcd(Type x,Type y){return (y==0)?x:igcd(y,x%y);}
template<class Type> Type ilcm(Type x,Type y){return x/igcd(x,y)*y;}

int main(){
	llong k;
	cin>>k;
	
	llong ans=0;
	REP(i,k)REP(j,k)REP(l,k){
		ans+=igcd(igcd(i+1,j+1),l+1);
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 3612
import java.util.*;

public class Main {

  public static void main(String[] args){
    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};
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    System.out.println(a[k-1]);
  }
}



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

typedef struct {
	double x, y, z, r;
} Coord;

typedef struct {
	int parent, rank;
} Node;

typedef struct {
	int from, to;
	double weight;
} Edge;

Coord coord[ 100 ];
Node node[ 100 ];
Edge edge[ 4950 ];

int compare( const void *a, const void *b ) {
	double at = (*(Edge *)a).weight, bt = (*(Edge *)b).weight;

	if ( at < bt )
		return -1;
	if ( at > bt )
		return 1;
	return 0;
}

int find( int x ) {
	if ( node[ x ].parent == x )
		return x;
	else
		return node[ x ].parent = find( node[ x ].parent );
}

void unite( int x, int y ) {
	int xRoot = find( x ), yRoot = find( y );

	if ( node[ xRoot ].rank < node[ yRoot ].rank )
		node[ xRoot ].parent = yRoot;
	else {
		node[ yRoot ].parent = xRoot;
		if ( node[ xRoot ].rank == node[ yRoot ].rank )
			node[ xRoot ].rank++;
	}
}

double kruskal( int v, int e ) {
	int i;
	double sum;

	qsort( edge, e, sizeof(Edge), &compare );

	for ( i = 0; i < v; i++ ) {
		node[ i ].parent = i;
		node[ i ].rank = 0;
	}

	sum = 0.0;
	for ( i = 0; i < e; i++ )
		if ( find( edge[ i ].from ) != find( edge[ i ].to ) ) {
			unite( edge[ i ].from, edge[ i ].to );
			sum += edge[ i ].weight;
		}

	return sum;
}

int main( void ) {
	int i, j;
	int n, cnt;

	while ( scanf( "%d", &n ), n ) {
		for ( i = 0; i < n; i++ )
			scanf( "%lf %lf %lf %lf", &coord[ i ].x, &coord[ i ].y, &coord[ i ].z, &coord[ i ].r );

		cnt = 0;
		for ( i = 0; i < n; i++ )
			for ( j = i + 1; j < n; j++ ) {
				edge[ cnt ].from = i;
				edge[ cnt ].to = j;
				edge[ cnt ].weight = fmax( sqrt( ( coord[ i ].x - coord[ j ].x ) * ( coord[ i ].x - coord[ j ].x ) + ( coord[ i ].y - coord[ j ].y ) * ( coord[ i ].y - coord[ j ].y ) + ( coord[ i ].z - coord[ j ].z ) * ( coord[ i ].z - coord[ j ].z ) ) - coord[ i ].r - coord[ j ].r, 0.0 );
				cnt++;
			}

		printf( "%.3f\n", kruskal( n, n * ( n - 1 ) / 2 ) );
	}

	return 0;
}

Measured memory_bytes: 868
#include <bits/stdc++.h>
using namespace std;
map<pair<int,int>,int>mp;
long long ans[10];
int main()
{
	long long h,w,n;
	cin>>h>>w>>n;
	for(int i=0;i<n;i++)
	{
		int a,b;
		cin>>a>>b;
		for(int x=-2;x<1;x++)for(int y=-2;y<1;y++)
		{
			int xx=a+x,yy=b+y;
			if(xx<1||xx>h-2||yy<1||yy>w-2)continue;
			mp[make_pair(xx,yy)]++;
		}
	}
	for(map<pair<int,int>,int>::iterator it=mp.begin();it!=mp.end();it++)ans[it->second]++;
	long long sum=0ll;
	for(int i=1;i<10;i++)sum+=ans[i];
	ans[0]=(h-2)*(w-2)-sum;
	for(int i=0;i<10;i++)cout<<ans[i]<<endl;
	return 0;
}

Measured memory_bytes: 56448
n, a, b = [int(i) for i in input().split()]
mod = 10**9 + 7
 
total = pow(2, n, mod) - 1
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)
def combination(n, r, mod=10**9+7):
    #r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res
 
at = combination(n,a)
bt = combination(n,b)
 
result = total - at - bt
result %= mod
if result < 0:
  result += mod
print(result)

Measured memory_bytes: 40812
#include <iostream>
#include <climits>
#include <algorithm>
#include <cstdlib>  // abs() for integer
#include <vector>
#include <tuple>

using namespace std;

long long N, X[1009], Y[1009], H[1009];
vector <tuple<long long, long long, long long>>vec;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
//    ダメだったやつ
//    int n;
//    cin >> n;
//    int x_c[n], y_c[n], height[n];
//
//    for(int i=0; i<n; i++){
//        cin >> x_c[i] >> y_c[i] >> height[i];
//    }
//
//    int c_x, c_y, trueheight = 100000;
//    bool flag = true;
//    for(int x=0; x<=100; x++){
//        for(int y=0; y<=100; y++){
//            int tmp_1;
//            int tmp_2;
//            for(int i=0; i<n-1; i++){
//                tmp_1 = height[i] + abs(x_c[i] - x) + abs(y_c[i] - y);
//                tmp_2 = height[i+1] + abs(x_c[i+1] - x) + abs(y_c[i+1] - y);
//                if(tmp_1 != tmp_2) {
//                    break;
//                }
//            }
//            if(trueheight > tmp_1){
//                c_x = x;
//                c_y = y;
//                trueheight = tmp_1;
//            }
//        }
//    }
//    cout << c_x << ' ' << c_y << ' ' << trueheight << '\n';

    cin >> N;
    tuple<long long, long long, long long>G = make_tuple(-1, -1, -1);

    for (int i=1; i<=N; i++){
        cin >> X[i] >> Y[i] >> H[i];
        if(H[i] >= 1) G = make_tuple(X[i], Y[i], H[i]);
    }
    for(int i=0; i<=100; i++){
        for(int j=0; j<=100; j++) {
            long long V = get<2>(G) + abs(get<0>(G) - i) + abs(get<1>(G) - j);
            V = max(V, 1LL);
            bool flag = true;
            for (int k = 1; k <= N; k++) {
                long long VV = V - abs(X[k] - i) - abs(Y[k] - j);
                VV = max(VV, 0LL);
                if (H[k] != VV) flag = false;
            }
            if(flag == true)
            vec.push_back(make_tuple(i, j, V));
        }
    }
    if(vec.size() == 1){
        cout << get<0>(vec[0]) << " " << get<1>(vec[0]) << " " << get<2>(vec[0]) << endl;
    }
    return 0;
}

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

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

int main(){
    int n;
    string s[10010];
    cin>>n;
    rep(i,n) cin>>s[i];
    int cnt=0;

    int ca=0,cb=0,cc=0;
    rep(i,n){
        rep(j,s[i].size()-1){
            if(s[i][j]=='A' && s[i][j+1]=='B') cnt++;
        }
    }
    rep(i,n){
        if(s[i][0]=='B' && s[i][s[i].size()-1]=='A') cc++;
        else if(s[i][0]=='B') cb++;
        else if(s[i][s[i].size()-1]=='A') ca++;
    }
    if(cc==0) cout<<cnt+min(ca,cb)<<endl;
    else if(ca!=0 && cb!=0) cout<<cnt+cc+min(ca,cb)<<endl;
    else if(ca==0 && cb==0) cout<<cnt+cc-1<<endl;
    else cout<<cnt+cc<<endl;
}

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

int main(){
  int N,K;
  string s;
  cin >> N >> K >> s;
  
  if(s.at(K-1)=='A') s.at(K-1)='a';
  else if(s.at(K-1)=='B') s.at(K-1)='b';
  else s.at(K-1)='c';
  
  cout << s << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		ArrayList<String> result=new ArrayList<String>();
		
		while (true) {
			int n = sc.nextInt();
			if(n==0)break;
			int[][] card = new int[2][n];
			int p0 = 0;
			int p1 = 0;

			for (int i = 0; i < n; i++) {
				card[0][i] = sc.nextInt();
				card[1][i] = sc.nextInt();

				if (card[0][i] > card[1][i]) p0 += card[0][i] + card[1][i];
				else if (card[0][i] < card[1][i]) p1 += card[0][i] + card[1][i];
				else {
					p0 += card[0][i];
					p1 += card[1][i];
				}
			}
			result.add(p0+" "+p1);
		}
		
		for(String str:result)System.out.println(str);
		
	}
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

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

	ll X, A;
	ll ans = 0;

	cin >> X >> A;

	if (X < A) ans = 0;
	else ans = 10;

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < n; ++i)
#define FORR(i, m, n) for (ll i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin >> n;
    vector<int> a(n);
    int mi=inf,mx=0;
    REP(i,n){
        cin >> a[i];
        chmin(mi,a[i]);
        chmax(mx,a[i]);
    }
    if(mx-mi==0){
        if(mi==n-1||mi*2<=n){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }
    else if(mx-mi==1){
        int u=0,v=0;
        REP(i,n){
            (a[i]==mi?u:v)++;
        }
        if(mx>u&&u+2*(mx-u)<=n){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x, y, z) max((x), max((y), (z)))
#define tmin(x, y, z) min((x), min((y), (z)))
ll MM = 1000000000; ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true;} return false;}
const ll INF = 1LL << 60;
using Graph = vector<vector<ll>>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//cout << fixed << setprecision(10);

int field[100][100];
ll w, h;


void dfs(ll y, ll x){
    field[y][x] = 0;
    rep(i, 8){
        ll ny = y + ddy[i], nx = x + ddx[i];
        if(0 <= ny && ny < h && 0 <= nx && nx < w && field[ny][nx]){
            dfs(ny, nx);
        }
    }
}


int main(){
    vector<ll> res;
    while(1){
        cin >> w >> h;
        if(!w && !h) break;
        rep(hi, h){
            rep(wi, w){
                cin >> field[hi][wi];
            }
        }

        ll ans = 0;
        rep(hi, h){
            rep(wi, w){
                if(field[hi][wi]){
                    dfs(hi, wi);
                    ans++;
                }
            }
        }

        // cout << ans << endl;
        res.push_back(ans);
    }

    rep(i, res.size()) cout << res[i] << endl;
return 0;
}


Measured memory_bytes: 3196