akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.math.BigDecimal;

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

	int n = sc.nextInt();

	while(n!=0){
	    double[] x = new double[3];
	    double[] y = new double[3];
	    for(int i=0; i<3; i++){
		x[i] = sc.nextDouble();
		y[i] = sc.nextDouble();
	    }

	    double A1,A2,B1,B2,C1,C2,X,Y;
	    A1=2*(x[1]-x[0]);
	    B1=2*(y[1]-y[0]);
	    C1=x[0]*x[0]-x[1]*x[1]+y[0]*y[0]-y[1]*y[1];
	    A2=2*(x[2]-x[0]);
	    B2=2*(y[2]-y[0]);
	    C2=x[0]*x[0]-x[2]*x[2]+y[0]*y[0]-y[2]*y[2];
	    X=(B1*C2-B2*C1)/(A1*B2-A2*B1);
	    Y=(C1*A2-C2*A1)/(A1*B2-A2*B1);

	    double r = Math.sqrt((X-x[0])*(X-x[0])+(Y-y[0])*(Y-y[0]));
	    BigDecimal bi = new BigDecimal(String.valueOf(X));
	    X = bi.setScale(3,BigDecimal.ROUND_HALF_UP).doubleValue();
	    bi = new BigDecimal(String.valueOf(Y));
	    Y = bi.setScale(3,BigDecimal.ROUND_HALF_UP).doubleValue();
	    bi = new BigDecimal(String.valueOf(r));
	    r = bi.setScale(3,BigDecimal.ROUND_HALF_UP).doubleValue();
	    
	    System.out.printf("%.3f",X);
	    System.out.print(" ");
	    System.out.printf("%.3f",Y);
	    System.out.print(" ");
	    System.out.printf("%.3f",r);
	    System.out.println();
	    n--;
	}
    }
}

Measured memory_bytes: 0
while True:
 s = input().rstrip().split(' ')
 a = int(s[0])
 b = int(s[1])
 if a == 0 and b == 0:
  break;
 else:
  if b < a:
   print(str(b) + " " + str(a))
  else:
   print(str(a) + " " + str(b))


Measured memory_bytes: 5612
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<sstream>
#include<complex>
#include<functional>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>

using namespace std;
#define endl '\n'

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;

template<typename T = long long>
T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }

// value
int p;
int a[3000];

/* べき乗を計算 */
ll mpow(ll v, long long k) {
	ll res = 1, tmp = v;
	while (k) {
		if (k & 1) res *= tmp;
		tmp *= tmp;
		res %= p;
		tmp %= p;
		k >>= 1;
	}
	return res;
}

ll inv(ll v) { return mpow(v, p - 2); }

ll b[3000];
ll fact[3000], fact_inv[3000];

void calc() {
	fact[0] = 1;
	fact_inv[0] = 1;
	for (int i = 1; i < 3000; i++) {
		fact[i] = fact[i - 1] * i;
		fact[i] %= p;
		fact_inv[i] = inv(fact[i]);
	}
}

ll comb(ll n, ll r) {
	return (fact[n] * fact_inv[r] % p) * fact_inv[n - r] % p;
}

void solve() {

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

	calc();

	for (int j = 0; j < p; j++) {
		if (a[j] == 1) {
			ll j2 = 1;
			for (int k = 0; k < p; k++) {
				b[p - 1 - k] += (-1) * comb(p - 1, k) * j2 % p;
				b[p - 1 - k] += p; b[p - 1 - k] %= p;
				j2 *= -j; j2 += p; j2 %= p;
			}
			b[0] += 1;
		}
	}

	for (int i = 0; i < p - 1; i++) {
		cout << b[i] % p << " ";
	}

	cout << b[p - 1] % p << endl;

	return;

}

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	solve();

	return 0;

}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
typedef long long LL;
using namespace std;
int main() {
	int n;
	cin >> n;
	if ( n == 2 ) {
		LL x, y;
		cin >> x >> y;
		cout << abs ( x - y );
	} else {
		LL a[n];
		for ( int j = 0; j < n; j++ )
			cin >> a[j];
		LL sum1 = 0, sum2 = 0;
		for ( int j = 0; j < n; j++ )
			sum2 += a[j];
		LL minn = 1000000000000;
		for ( int j = 0; j < n-1; j++ ) {
			sum1 += a[j];
			sum2 -= a[j];
			minn = min ( minn, abs ( sum1 - sum2 ) );
		}
		cout << minn;
	}
}


Measured memory_bytes: 1792
n=int(input())
hlis=list(map(int,input().split()))
counter=0
ans=0
for i in range(n-1):
	if hlis[i]>=hlis[i+1]:
		counter+=1
	else:
		ans=max(ans,counter)
		counter=0
ans=max(ans,counter)
print(ans)

Measured memory_bytes: 14224
def how_many_times_divisible(n):
	ans = 0
	while n % 2 == 0:
		n /= 2
		ans += 1
	return ans
 
n = int(input())
a = map(int, input().split())
ans = min(map(how_many_times_divisible, a))
 
print(ans)

Measured memory_bytes: 38640
import bisect

n,k = map(int,input().split())
arr = list(map(int,input().split()))

arr.sort()
o_ind = bisect.bisect_left(arr,0)

minus = arr[:o_ind]
plus = arr[o_ind:]
plus.reverse()


mod = 10**9+7

canplus = True
types = -1

if (k == n and len(minus)%2==1):
    canplus = False
    types = 0
elif (k%2 == 1 and len(plus)==0):
    canplus = False

# print(canplus)

if canplus:
    if k % 2 == 0:
        ans = 1
        phead = 0
        mhead = 0

        for i in range(k // 2):
            tp1 = 1e-20
            tp2 = 1e-20
            if phead + 1 < len(plus):
                tp1 = plus[phead] * plus[phead + 1]

            if mhead + 1 < len(minus):
                tp2 = minus[mhead] * minus[mhead + 1]

            if tp1 < tp2:
                ans *= tp2
                ans %= mod
                mhead += 2
            else:
                ans *= tp1
                ans %= mod
                phead += 2
    else:
        if len(plus) > 0:
            ans = plus[0]
            phead = 1
            mhead = 0

            for i in range(k // 2):
                tp1 = 1e-20
                tp2 = 1e-20

                flag = False
                if phead + 1 < len(plus):
                    tp1 = plus[phead] * plus[phead + 1]

                if mhead + 1 < len(minus):
                    tp2 = minus[mhead] * minus[mhead + 1]


                if tp1 < tp2:
                    ans *= tp2
                    ans %= mod
                    mhead += 2
                else:
                    ans *= tp1
                    ans %= mod
                    phead += 2

    print(int(ans))
else:
    ans = 1
    if types == 0:
        for i in range(k):
            ans *= arr[i]
            ans %= mod

    else:
        minus.reverse()
        for i in range(k):
            ans *= minus[i]
            ans %= mod

    print(int(ans))





Measured memory_bytes: 94124
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int N, K;
vector<int> u, v;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main()
{
    ll a, b, c;
    cin >> a >> b >> c;
    ll ans = 0;
    if (a + b >= c)
        ans = b + c;
    else
        ans = a + 2 * b + 1;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>           // printf(), scanf()
#include <cmath>            // sqrt()

#define MAX_N 80000
using namespace std;

class Point
{
public:
	double x, y;

	Point(double x = 0, double y = 0): x(x), y(y) {}
	Point operator - (Point p) { return Point(x - p.x, y - p.y); }
};

typedef Point Vector;

Point qs[MAX_N];
int n;

double
dot(Vector a, Vector b)
{
	return a.x * b.x + a.y * b.y;
}

double
cross(Vector a, Vector b)
{
	return a.x * b.y - a.y * b.x;
}

double
dist(Vector a, Vector b)
{
	return dot(a - b, a - b);
}

bool cmp_func(const Point &l, const Point &r)
{
	return l.x != r.x ? l.x < r.x : l.y < r.y;
}

double
solve()
{
	int i = 0, j = 0; // ?????????????????????????????????
	// x ??????????????????????????????????±???????
	for (int k = 0; k < n; ++k)
	{
		if (!cmp_func(qs[i], qs[k]))
			i = k;

		if (cmp_func(qs[j], qs[k]))
			j = k;
	}

	double res = 0;
	int si = i, sj = j;
	while (i != sj || j != si) // ????????? 180 ??????????????????
	{
		double t = dist(qs[i], qs[j]);
		if (t > res)
			res = t;

		// ??? i-(i+1) ?????????????????¨??? j-(j+1) ???????????????????????????????????????????????????
		if (cross(qs[(i + 1) % n] - qs[i], qs[(j + 1) % n] - qs[j]) < 0)
			i = (i + 1) % n; // ??? i-(i+1) ??????????????????????????????
		else
			j = (j + 1) % n; // ??? j-(j+1) ??????????????????????????????
	}

	return sqrt(res);
}

int
main(int argc, char** argv)
{

	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
		scanf("%lf %lf", &qs[i].x, &qs[i].y);

	printf("%.12f\n", solve());
	return 0;
}

Measured memory_bytes: 3996
#include<iostream>
#include<math.h>
using namespace std;

int main(){
    int n;
    cin >> n;
    int m = n;
    int d,sum=0;
    for(int i=0;i<=8;i++){
        /*if(n<pow(10,i)){
            break;
        }*/
        d = n%10;
        sum += d;
        n = n/10;
    }
    
    if(m%sum==0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3572
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: str):
    if N.__contains__('9'):
        print(YES)
    else:
        print(NO)

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = str(next(tokens))  # type: str
    solve(N)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <stdio.h>
int main(void)
{
	float a, b;
	
	while (scanf("%f %f", &a, &b) != EOF){
		if(a < 35.5 && b < 71){
			printf("AAA\n");
		}
		else if(a < 37.5 && b < 77) {
			printf("AA\n");
		}
		else if(a < 40 && b < 83) {
			printf("A\n");
		}
		else if(a < 43 && b < 89) {
			printf("B\n");
		}
		else if(a < 50 && b < 105) {
			printf("C\n");
		}
		else if(a < 55 && b < 116) {
			printf("D\n");
		}
		else if(a < 70 && b < 148) {
			printf("E\n");
		}
		else {
			printf("NA\n");
		}
	}
	
	return (0);
}

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

using ll = long long;

#define reps(i,s,n) for(int (i) = (n); (i) < (s); (i)++)
#define rep(i,n) reps(i,0,n)

int main()
{
	string str;
	cin >> str;
	
	cout << "ABC" << str << endl;	

	return 0;
}


Measured memory_bytes: 256
def makelist(n, m):
    return [[False for _ in range(m)] for _ in range(n)]

A = [0]*3
for i in range(3):
    row = list(map(int, input().split()))
    A[i] = row

N = int(input())
bingo = makelist(3, 3)
for _ in range(N):
    b = int(input())
    for y in range(3):
        for x in range(3):
            if A[y][x] == b:
                bingo[y][x] = True

ans = "No"
yes = "Yes"
for y in range(3):
    if all(bingo[y]):
        ans = yes

for x in range(3):
    res = True
    for y in range(3):
        res = res and bingo[y][x]
    if res:
        ans = yes

if bingo[1][1]:
    if (bingo[0][0] and bingo[2][2]) or (bingo[0][2] and bingo[2][0]):
        ans = yes

print(ans)


Measured memory_bytes: 3064
/*..........AAKASH GOYAL............*/
/*............DAIICT................*/
#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;

// typedef  long long int ll;
// typedef long double   ld;

#define    int                      long long int
#define    f(i,j,n)                 for(int i = j; i <= n; i++)
#define    r(i,n,j)                 for(int i = n; i >= j; i--)
#define    mod                      1000000007
#define    speed                    ios_base::sync_with_stdio(false);
#define    upp                      cin.tie(NULL);
#define    pb                       push_back
#define    mp                       make_pair
#define    T                        int tt; cin >> tt; while(tt--)
#define    ff                       first
#define    ss                       second
#define    all(container)           container.begin() , container.end()
#define    sz(container)            (int)container.size()
#define    pii                      pair <int , int>
#define    pll                      pair <long long int , long long int>
#define    ppl                      pair <int , pii>
#define    sp(x)                    setprecision(x)

int32_t main()
{
    speed upp
    int n,k,s;
    cin>>n>>k>>s;
    f(i,1,k)
        cout<<s<<" ";
    if(s==1000000000)
        f(i,k+1,n)
            cout<<1<<" ";
    else
        f(i,k+1,n)
            cout<<1000000000<<" ";
}


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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int ans;
	if (a == b) ans = c;
	if (a == c) ans = b;
	if (c == b) ans = a;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3604
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val a = sc.nextInt()
    val b = sc.nextInt()
    println(problem109a(a, b))
}

fun problem109a(a: Int, b: Int): String {
    return if (a * b % 2 != 0) "Yes" else "No"
}

Measured memory_bytes: 27560
#include <iostream>
#include <string>
using namespace std;
 
#define endl "\n"
#define int long long
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
#define mem(a,b) memset((a),(b),sizeof (a))
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF long long(1e18)
#define MOD 1000000007


void solve(){
	string s;
	cin>>s;
	if(s[2]==s[3]&&s[4]==s[5]) 
	cout<<"Yes"<<endl; 
	else cout<<"No"<<endl;  
}

int32_t main(){
    int t=1;
    while(t--)
        solve();
    return 0;
}




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

int gcd(int n, int m) {return (m == 0? n : gcd(m, n % m));}

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

  int w, h, c;
  cin >> w >> h >> c;

  int g = gcd(w, h);
  cout << (h / g) * (w / g) * c << endl;
}


Measured memory_bytes: 3200
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    A = [I() for _ in range(N)]
    
    A_first = max(A)
    A_second = 0
    if A.count(A_first) >= 2:
        A_second = A_first
    else:
        for i in A:
            if i != A_first:
                A_second = max(i, A_second)

    for i in A:
        if i == A_first:
            print(A_second)
        else:
            print(A_first)

if __name__ == '__main__':
    resolve()


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

struct Z {
    int h;
    int w;
    int c;
};

int main()
{
    int H,W,h,w;
    int inf = 1 << 30;
    cin >> H >> W;
    vector<string> A(H);
    vector<vector<int>> B(H, vector<int>(W,inf));
    for (h = 0; h < H; ++h) {
        cin >> A[h];
    }

    deque<Z> q;
    for (h = 0; h < H; ++h) {
        for (w = 0; w < W; ++w) {
            if (A[h][w] == '#') {
                Z z;
                z.h = h;
                z.w = w;
                z.c = 0;
                q.push_back(z);
                B[h][w] = 0;
            }
        }
    }

    int ans = 0;
    while (!q.empty()) {
        Z z;
        z = q.front();
        q.pop_front();

        if ((z.h > 0) && (A[z.h-1][z.w] == '.')) {
            if (B[z.h-1][z.w] > z.c+1) {
                Z z2;
                z2.h = z.h - 1;
                z2.w = z.w;
                z2.c = z.c + 1;
                B[z2.h][z2.w] = z2.c;
                q.push_back(z2);
                ans = max(ans, z2.c);
            }
        }
        if ((z.w > 0) && (A[z.h][z.w-1] == '.')) {
            if (B[z.h][z.w-1] > z.c+1) {
                Z z2;
                z2.h = z.h;
                z2.w = z.w - 1;
                z2.c = z.c + 1;
                B[z2.h][z2.w] = z2.c;
                q.push_back(z2);
                ans = max(ans, z2.c);
            }
        }
        if ((z.h < H-1) && (A[z.h+1][z.w] == '.')) {
            if (B[z.h+1][z.w] > z.c+1) {
                Z z2;
                z2.h = z.h + 1;
                z2.w = z.w;
                z2.c = z.c + 1;
                B[z2.h][z2.w] = z2.c;
                q.push_back(z2);
                ans = max(ans, z2.c);
            }
        }
        if ((z.w < W-1) && (A[z.h][z.w+1] == '.')) {
            if (B[z.h][z.w+1] > z.c+1) {
                Z z2;
                z2.h = z.h;
                z2.w = z.w + 1;
                z2.c = z.c + 1;
                B[z2.h][z2.w] = z2.c;
                q.push_back(z2);
                ans = max(ans, z2.c);
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 17296
//libraries
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//namespace
using namespace std;
using namespace __gnu_pbds;

//typedef
//typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<long long> vll;

//define
#define i(X) cin>>X;
#define ol(X) cout<<X<<endl;
#define os(X) cout<<X<<" ";
#define inpv(a,n) vector<ll> a(n); for(ll i=0;i<n;i++){cin>>a[i];}
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define line cout<<"\n";
#define pbp(a,b) push_back(make_pair(a,b));
#define iniv(A,n,p) vector<ll> A(n,p);
#define vst(A) sort(A.begin(),A.end());
#define rvst(A) sort(A.rbegin(),A.rend());
#define forin(i,a,b) for(ll i=a;i<=b;i++)
#define forde(i,a,b) for(ll i=a;i>=b;i--)
#define fio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const long long inf=(long long)1e18;
long long MOD=(long long)(1e9+7);
ll mod=MOD;

ll power(ll x,ll y)
{
    if (y == 0)
        return 1;
    ll p = power(x, y/2) % MOD;
    p = (p * p) % MOD;

    return (y%2 == 0)? p : (x * p) % MOD;
}

int main() 
{
	// #ifndef ONLINE_JUDGE
    //    freopen ("input.txt" , "r" , stdin);
	// 	// freopen ("OUTPUT.txt" , "w" , stdout);
	// #endif
	fio;
	ll testcase=1;
	//cin>>testcase;
	while(testcase--)
	{
		string s;
		cin>>s;
		ll ans=0;
		for(auto c:s)
		{
			ans+=c-'0';
		}
		string z=(ans%9)==0?"Yes":"No";
		ol(z);
	}
}

Measured memory_bytes: 3760
N, K = map(int, input().split())

def sumLR(l, r):
	return (l+r)*(r-l+1)//2

mod = 10**9 + 7
count = 0

for n in range(K, N+2):
	max = sumLR(N-n+1, N)
	min = sumLR(0, n-1)
	count += max - min + 1
	count %= mod
print(count)

Measured memory_bytes: 9116
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
        //MyDebugger.Test(process, "../TextFile2.txt");
        //MyDebugger.MakeTestCase("../TextFile2.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var spl   = input.ReadLine().Split(' ');
        var a     = int.Parse(spl[0]);
        var b     = int.Parse(spl[1]);

        var ary = ToIntArray(input.ReadLine(), b);

        return ary.Sum() >= a ? "Yes" : "No";
    }

    static int[] ToIntArray(string strs, int n) {
        var ret = new int[n];
        var spl =strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = int.Parse(spl[i]);
        return ret;
    }
}

Measured memory_bytes: 16480
#include <bits/stdc++.h>
using namespace std;
int main(){
	int x,y;
	
	while(1){
		cin>>x>>y;
		if(x==0&&y==0){
			break;
			}
		if(x>y){
		cout<<y<<" "<<x<<endl;
			}
		if(x<y){
		cout<<x<<" "<<y<<endl;
			}
		if(x==y){
		cout<<x<<" "<<y<<endl;
			}
		}
	}
	



Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const ll MOD=1e9+7;

ll add(int x, int y){return (x+y)%MOD;}
ll mlt(int x, int y){return (x*y)%MOD;}


ll c_cum[200010];
ll dp[200010];

int main(){
  int N;cin>>N;
  vi C;
  for (int i=0;i<N;++i){
    int c;cin>>c;C.push_back(c);
  }

  memset(c_cum, 0, sizeof(c_cum));
  memset(dp, 0, sizeof(dp));

  dp[0]=1;c_cum[C[0]]=1;
  if(N==1){cout << 1 << endl;return 0;}

  for (int i=1;i<N;++i){
    if(C[i-1]!=C[i]){
      c_cum[C[i]]=add(c_cum[C[i]], dp[i-1]);
    }
    dp[i]=c_cum[C[i]];
  }

  cout << dp[N-1] << endl;
  return 0;
}

Measured memory_bytes: 4340
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    static long mod = 1000000007;
    static long[] j = new long[200005];
    static long[] j_ = new long[200005];

    static long pow(long a, long b) {
        if (b == 0) {
            return 1;
        }
        if (b % 2 == 0) {
            return pow(a * a % mod, b / 2);
        } else {
            return pow(a * a % mod, b / 2) % mod * a % mod;
        }
    }

    static class node implements Comparable<node> {
        int x;
        int y;

        @Override
        public int compareTo(node o) {
            if (x == o.x) {
                return Integer.compare(y, o.y);
            }
            return Integer.compare(x, o.x);
        }
    }

    static long c(int a, int b) {
        return j[a] * j_[b] % mod * j_[a - b] % mod;
    }

    public static void main(String[] aaaa) {
        Scanner scanner = new Scanner(System.in);
        int h = scanner.nextInt();
        int w = scanner.nextInt();
        int n = scanner.nextInt();


        j[0] = 1;
        j_[0] = 1;
        for (int i = 1; i < j.length; i++) {
            j[i] = j[i - 1] * i % mod;
            j_[i] = pow(j[i], mod - 2);
        }
        node[] nodes = new node[3005];
        for (int i = 0; i < n; i++) {
            nodes[i] = new node();
            nodes[i].x = scanner.nextInt();
            nodes[i].y = scanner.nextInt();
        }
        Arrays.sort(nodes, 0, n);

        long[] dp = new long[3005];
        for (int i = 0; i < n; i++) {
            dp[i] = c(nodes[i].x + nodes[i].y - 2, nodes[i].x - 1);
            for (int k = 0; k < i; k++) {
                if (nodes[k].x <= nodes[i].x && nodes[k].y <= nodes[i].y) {
                    dp[i] -= dp[k] * c(nodes[i].x + nodes[i].y - nodes[k].x - nodes[k].y, nodes[i].x - nodes[k].x);
                }
                dp[i] %= mod;
            }
//            System.out.println("dp " + i + " " + dp[i]);
        }
        long sum = c(h + w - 2, h - 1);
        for (int i = 0; i < n; i++) {
            sum -= dp[i] * c(h + w - nodes[i].x - nodes[i].y, h - nodes[i].x);
            sum %= mod;
        }
        System.out.println((sum + mod) % mod);


    }
}


Measured memory_bytes: 32948
#include<stdio.h>
int main(void)
{
	int a,b,c,l=0,x=0;
	scanf("%d %d %d", &a, &b, &c);
	while(x<c)
	{
		l++;
		x+=a;
		if(l%7==0)
		x+=b;
	}
	printf("%d\n", l);
	
	return 0;
}


Measured memory_bytes: 2108
n = int(input())
s = list(map(int,input().split()))
ans = -1000000000000000
dp = [{} for _ in range(n)]
dp[0][1] = s[0]
dp[1][1] = s[1]
if n >= 3:
    dp[2][1] = s[2]
for i in range(n):
    for x in dp[i].keys():
        y = dp[i][x]
        if x == n//2:
            ans = max(ans,y)
        else:
            if (n-(i+2)+1)//2 >= n//2-(x+1) and i+2 <= n-1:
                if x+1 in dp[i+2].keys():
                    dp[i+2][x+1] = max(dp[i+2][x+1],dp[i][x] + s[i+2])
                else:
                    dp[i+2][x+1] = dp[i][x] + s[i+2]
            if (n-(i+3)+1)//2 >= n//2-(x+1) and i+3 <= n-1:
                if x+1 in dp[i+3].keys():
                    dp[i+3][x+1] = max(dp[i+3][x+1],dp[i][x] + s[i+3])
                else:
                    dp[i+3][x+1] = dp[i][x] + s[i+3]
            if (n-(i+4)+1)//2 >= n//2-(x+1) and i+4 <= n-1:
                if x+1 in dp[i+4].keys():
                    dp[i+4][x+1] = max(dp[i+4][x+1],dp[i][x]+s[i+4])
                else:
                    dp[i+4][x+1] = dp[i][x]+s[i+4]
print(ans)


Measured memory_bytes: 149796
#include <stdio.h>
int main(void){
	int a,b;
	scanf("%d%d",&a, &b);
	if(a < b){
		printf("a < b\n");
	}

	else if(a > b){
		printf("a > b\n");
	}

	else{
		printf("a == b\n");
	}

	return 0;


}

Measured memory_bytes: 580
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

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

  cout << (N + 1) / 2 << endl;
  return 0;
}

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

int main()
{
    int n;
    cin>>n;
    set<int> nums;
    bool dis = true;
    int a;
    for(int i=0;i<n;++i){
        cin>>a;
        if(nums.find(a) != nums.end()){
            dis = false;
        }else{
            nums.insert(a);
        }
    }
    if(dis)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
//#define int long long

signed main(){
    int h, w;
    cin >> h >> w;
    vector<vector<char>> field(h, vector<char>(w));
    rep(i,h)rep(j,w) cin >> field[i][j];
    vector<int> print_row, print_column;
    
    rep(i,h){
        bool ignore = true;
        rep(j,w){
            if(field[i][j]=='#'){
                ignore = false;
                break;
            }
        }
        if(ignore) continue;
        print_column.emplace_back(i);
    }
    
    rep(i,w){
        bool ignore = true;
        rep(j,h){
            if(field[j][i]=='#'){
                ignore = false;
                break;
            }
        }
        if(ignore) continue;
        print_row.emplace_back(i);
    }
    
    for(int i : print_column){
        for(int j : print_row){
            cout << field[i][j];
        }
        cout << endl;
    }
}

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

int N,K;
string S[20];
int nxt[20][6][20];
int idx[20][20];
int R;
int dp[1<<16][16][6];

string PERM(string pre,int j){
  while(j>0){
    next_permutation(all(pre));
    j--;
  }
  return pre;
}

string res;

int dfs(int T,int i,int j){
  if(T==((1<<N)-1))return 1;
  if(dp[T][i][j]!=-1)return dp[T][i][j];
  rep(ni,N){
    if(((T>>ni)&1)==1)continue;
    if(nxt[i][j][ni]==-1)continue;
    if(dfs((T|(1<<ni)),ni,nxt[i][j][ni])==1){
      string tmp;
      tmp+='A'+ni;
      res=tmp+res;
      return dp[T][i][j]=1;
    }
  }
  return dp[T][i][j]=0;
}

int main(){
  cin>>N>>K;
  memset(idx,-1,sizeof(idx));
  memset(nxt,-1,sizeof(nxt));
  rep(i,N){
    cin>>S[i];
    rep(j,S[i].size())idx[i][S[i][j]-'A']=j;
  }
  R=1;
  rep(i,N-K)R=R*(i+1);

  rep(i,N)rep(j,R){
    string crt=S[i];
    reverse(all(crt));
    string tmp;
    rep(k,N)if(idx[i][k]==-1)tmp+='A'+k;
    sort(all(tmp));
    crt+=PERM(tmp,j);

    rep(k,N){
      if(k==i)continue;
      int pre=-100;
      bool ok=true;
      string rest;
      rep(l,N){
        if(idx[k][crt[l]-'A']==-1){
          rest+=crt[l];
        }else{
          if(pre>idx[k][crt[l]-'A'])ok=false;
          else pre=idx[k][crt[l]-'A'];
        }
      }
      if(ok){
        tmp=rest;
        sort(all(tmp));
        rep(nj,R)if(PERM(tmp,nj)==rest)nxt[i][j][k]=nj;
      }
    }
  }

  string ans="ZZ";
  rep(i,N){
    rep(j,R){
      memset(dp,-1,sizeof(dp));
      res.clear();
      if(dfs(1<<i,i,j)==1){
        string tmp;
        tmp+='A'+i;
        minch(ans,tmp+res);
      }
    }
  }

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




Measured memory_bytes: 27832
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

#define rep(a, b, c) for(int a = b; a < c; a++)

using namespace std;

class Filed {
public:
    int h;
    int m;

    void set(int h, int m);
};

void Filed::set(int h, int m) {
    this->h = h;
    this->m = m;
}
Filed filed[100][100];

const int saikoro[][4] = {
        {},
        {5, 3, 2, 4},
        {3, 6, 4, 1},
        {5, 6, 2, 1},
        {1, 2, 6, 5},
        {3, 1, 4, 6},
        {5, 4, 2, 3}
};

void put(int t, int f, int x, int y) {
    int h = filed[x][y].h;
    if (h == 0) {
        filed[x][y].set(h + 1, t);
        return;
    }
    int saikoro_index;
    rep(i, 0, 4) {
        if (saikoro[t][i] == f) {
            saikoro_index = i;
            break;
        }
    }
    int next_x, next_y, next_t, next_f;
    int roll_m = 0;
    rep(i, 0, 4) {
        int index = (i + saikoro_index) % 4;
        int m = saikoro[t][index];
        if (m <= 3 || m < roll_m) {
            continue;
        }
        switch(i) {
            case 0:
                if (filed[x][y - 1].h < h) {
                    next_x = x;
                    next_y = y - 1;
                    next_t = saikoro[t][(index + 2) % 4];
                    next_f = t;
                    roll_m = m;
                }
                break;
            case 1:
                if (filed[x - 1][y].h < h) {
                    next_x = x - 1;
                    next_y = y;
                    next_t = saikoro[t][(index + 2) % 4];
                    next_f = f;
                    roll_m = m;
                }
                break;
            case 2:
                if (filed[x][y + 1].h < h) {
                    next_x = x;
                    next_y = y + 1;
                    next_t = saikoro[t][(index + 2) % 4];
                    next_f = 7 - t;
                    roll_m = m;
                }
                break;
            case 3:
                if (filed[x + 1][y].h < h) {
                    next_x = x + 1;
                    next_y = y;
                    next_t = saikoro[t][(index + 2) % 4];
                    next_f = f;
                    roll_m = m;
                }
                break;
        }
    }
    if (roll_m == 0) {
        filed[x][y].set(h + 1, t);
        return;
    }
    put(next_t, next_f, next_x, next_y);
}


int main() {
    while (true) {
        int N;
        cin >> N;
        if (N == 0) {
            break;
        }
        rep(i, 0, 100) {
            rep(j, 0, 100) {
                filed[i][j].set(0, 0);
            }
        }
        rep(i, 0, N) {
            int T, F;
            cin >> T >> F;
            put(T, F, 50, 50);
        }
        vector<int> counter(7, 0);
        rep(i, 0, 100) {
            rep(j, 0, 100) {
                if (filed[i][j].m != 0) {
                    counter[filed[i][j].m]++;
                }
            }
        }
        rep(i, 0, 6) {
            cout << counter[i + 1];
            if (i != 5) {
                cout << " ";
            }
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1272
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
#include<stdio.h>
#include<cmath>
#include<limits>
#include<iomanip>

using namespace std;
 
template <class T> using V = vector<T>;
 
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 long long INF = 1LL << 60;
 
using ll = long long;
using db = long double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;
using graph = V<V<int>>;
using pq = priority_queue<ll>;


 
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>=(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
#define pb(a) push_back(a);
  
 

ll sum(ll n) {
ll m=0;
  while(n){
    m+=n%10;
    n/=10;
  }
  return m;
}
 
 
const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void Comuse() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
 
#define comuse Comuse()
 
ll combi(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
 
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}




 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 

signed main(){
  ll a,b;
  	cin>>a>>b;
  if(a>9||b>9){
    cout<<-1<<endl;
  }
  else{
    cout<<a*b<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// for(long long i = 0;i < num; i++){}
int main() {
    //
    long long x;
    long long cnt = 0;

    cin >> x;

    if (x % 11 == 0) cout << x / 11 * 2;
    else if (x % 11 <= 6) cout << x / 11 *2+1;
    else cout << x / 11 *2+2;
    //
}


Measured memory_bytes: 3640
#include<stdio.h> 
#define it register int
#define ct const int
#define il inline 
const int N=1000005;
int n;
il int gcd(ct a,ct b){return !b?a:gcd(b,a%b);}
int main(){ 
	scanf("%d",&n),printf("%d\n",360/gcd(n,360));
	return 0;
}


Measured memory_bytes: 1736
using System;
using System.Linq;
using System.Collections.Generic;
class c
{
    static void Main()
    {
        var inp = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
        var a = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
        var bc = new List<Tuple<long, long>>();
        for (int i = 0; i < inp[1]; i++)
        {
            var line = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
            bc.Add(new Tuple<long, long>(line[0], line[1]));
        }
        var dic = new Dictionary<long, int>();
        for (int i = 0; i < inp[0]; i++)
        {
            dic[a[i]] = 0;
        }
        for (int i = 0; i < inp[1]; i++)
        {
            dic[bc[i].Item2] = 0;
        }
        for (int i = 0; i < inp[0]; i++)
        {
            dic[a[i]]++;
        }
        for (int i = 0; i < inp[1]; i++)
        {
            dic[bc[i].Item2] += (int)bc[i].Item1;
        }
        dic = dic.OrderByDescending(f => f.Key).ToDictionary(f => f.Key, f => f.Value);
        long ans = 0;
        long remain = inp[0];
        var value = dic.Keys.ToArray();
        var count = dic.Values.ToArray();
        for (int i = 0; i < dic.Count(); i++)
        {
            if (remain >= count[i])
            {
                ans += value[i] * count[i];
                remain -= count[i];
            }
            else
            {
                ans += value[i] * remain;
                break;
            }
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 53964
#include<iostream>
using namespace std;
int main(){
	int n,x,a=0;
	for(;;){
		cin>>n>>x;
		if(n==0 && x==0){
			break;
		}

		for(int i=1;i<=n;i++){
			for(int j=i+1;j<=n;j++){
				for(int k=j+1;k<=n;k++){

					if(x==(i+j+k)){
						a++;
					}

				}
			}
		}

		cout<<a<<endl;
		a=0;
	}
	return 0;
}


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

int main(){
    int n, m;
    cin >> n >> m;
    int ans = 1;
    for(int i = 1; i*i <= m; i++){
        if(m % i == 0){
            int coans;
            if(i >= n && m/i >= n){
                coans = (i > m/i) ? i : m/i;
            }else if(i >= n){
                coans = m/i;
            }else if(m/i >= n){
                coans = i;
            }else{
                coans = 1;
            }
            if(ans < coans) ans = coans;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, n) for (int i = (a); i < (n); ++i)
using namespace std;
using ll = long long;
using uint = unsigned int;
const ll mod = (ll)1e9 + 7;


int main() {
  string s, t;
  cin >> s >> t;
  int count = 0;
  rep(i,s.size()) {
    if (s[i] != t[i]) count++;
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 3916
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring> 

using namespace std;

int cnt, a[101] = {0};

int fanc(int n);

int main(){
	int n;
	while(1){
		cin >> n;
		if(n == 0) break;
		cnt = 0;
		string str;
		for(int i = 0; i < n; i++){
			cin >> str;
			if(str == "lu") a[i] = 1;
			else if(str == "ld") a[i] = 2;
			else if(str == "ru") a[i] = 3;
			else if(str == "rd") a[i] = 4;
		}
		cnt = fanc(0);
		cout << cnt << endl;
		for(int i = 0; i < 101; i++){
			a[i] = 0;
		}
	}
	return 0;
}

int fanc(int i)
{
	if(a[i] == 0 || a[i+1] == 0) return 0;
	else if(a[i] % 2 == a[i+1] % 2) return 1 + (fanc(i + 2));
	else return fanc(i + 1);
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
using namespace std;
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define pb push_back
#define F first
#define S second

#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define int long long
#define ll long long
const int M=1e9+7;

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

int expo(int x, int y) {int res=1;x=x%M;while(y>0){if(y&1)res=(1ll*res*x)%M;
	y=y>>1;x=(1ll*x*x)%M;} return res;}
	

signed main(){
	gearup;
	int t = 1;
	//cin >> t;
	while(t--){
		int n;
		cin >> n;
		int a[n], ans = 0;
		map<int, int> mp;
		for(int i = 0 ; i < n ; i++){
			cin >> a[i];
			mp[a[i]]++;	
		}
		for(auto it : mp){
			int temp = it.S;
			ans += (temp * (temp - 1) / 2);
		}
		for(int i = 0 ; i < n ; i++){
			cout << ans -  mp[a[i]] + 1 << "\n";	
		}
	}
	return 0;
}

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

int asc(const void *a, const void *b) {
  		return *(int *)a - *(int *)b;
}

int main(void)
{
	
	int N;
	int A=0;
	scanf("%d",&N);
	int a[N];
	for(int i=0;i<N;i++){
		scanf("%d",&a[i]);
	}
	int i=0;
	qsort(a, N , sizeof(int) , asc);
	for(int i=0;i<N-1;i++){
		if(a[i]==a[i+1]){
			A=1;
		}
	}
	if(A==1){
		printf("NO");
	}else{
		printf("YES");
	}
}

Measured memory_bytes: 1788
#include<stdio.h>
int main(void)
{
  int x,n,s,ans;
  int min = 200000, i = 0;
  scanf("%d",&n);
  scanf("%d",&x);
  min = x;
  ans = -10000000000;
  for ( i = 1 ; i < n; i++){
  scanf("%d",&x);
  s = x - min;
  if(min > x){
   min = x;
  }if(ans < s){
     ans = s;
   }
}
   printf("%d\n",ans);

  return 0;
}

Measured memory_bytes: 1840
def main():
    N = int(input())

    x = (N // 11) * 2
    if N % 11 == 0:
        ans = x
    elif N <= 11 * (N // 11) + 6:
        ans = x + 1
    else:
        ans = x + 2

    print(ans)



if __name__ == "__main__":
    main()

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

int main(){
  int N, i, j;
  scanf("%d", &N);
  for(i = 1; i <= 9; i++){
    for(j = 1; j <= 9; j++){
      if(N == i * j){
        printf("Yes\n");
        return 0;
      }
    }
  }
  printf("No\n");
  return 0;
}

Measured memory_bytes: 256
s=int(input())
a=[s]
b=0
f=False
for i in range(10**6):
	if a[i]%2 == 0:
		a.append(a[i]//2)
	else:
		a.append(a[i]*3+1)
	for j in range(i):
		if a[i]==a[j]:
			b=i+1
			f=True
			break
	if f:
		break
print(b)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
        using namespace std;
        #define tani_nachi_ke  ios_base::sync_with_stdio(false); cin.tie(NULL);
        #define M_PI 3.14159265358979323846
        #define data data_
        #define ff first
        #define ss second
        #define pb push_back
        #define ll long long
        #define ld long double

        int const N = 100009;
        long long mod = 1e9 + 7;
        long long fact[N];


        long long mod_power(long long base,long long n,long long mod)
        {
            long long res=1;
            base%=mod;
            while(n>0)
            {
            if(n&1)res=(res*base)%mod;
            base=(base*base)%mod;
            n/=2;
            }
            return res%mod;
        }

        long long ncr(long long n,long long r)
        {
            if(r > n)
                return 0;
            long long ans = fact[n];
            ans = (ans * mod_power(fact[n-r],mod-2,mod))%mod;
            ans = (ans * mod_power(fact[r],mod-2,mod))%mod;
            return ans;
        }
        int main()
        {
            tani_nachi_ke  

            fact[0] = 1;
            fact[1] = 1;
            for(long long i = 2; i < N; i++)
                fact[i] = (fact[i-1] * i)%mod;
            long long n,k;
            cin >> n >> k;
            long long a[n+1],ans = 0;
            for(int i = 1; i <= n; i++)
            {
                cin >> a[i];
            }
            sort(a+1,a+n+1);
            for(int i = 1; i <= n; i++)
            {
                ans += (a[i] * ncr(i-1,k-1))%mod;
                ans %= mod;
                ans -= (a[i] * ncr(n-i,k-1))%mod;
                ans += mod;
                ans %= mod;
            }
            cout << ans << '\n';




           return 0;
        }

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
struct p
{
    int l;
    int r;
}a[1000000];
bool cmp(p xx,p yy)
{
    return xx.l>yy.l;
}

int main()
{
    int n,h,wsq=0;;
    int c=0;
    cin>>n>>h;
    for(int i=1;i<=n;i++)
    {
        cin>>a[c++].l;
        a[c].r=1;
        cin>>a[c++].l;
    }
    sort(a,a+c,cmp);
    for(int i=0;i<c;i++)
    {
        if(a[i].r==1)
        {
            wsq++;
            h-=a[i].l;
            if(h<=0)
            {
                cout<<wsq<<endl;
                return 0;
            }
        }
        else if(a[i].r!=1)
        {
            if(h%a[i].l==0) 
			wsq+=h/a[i].l;
            else 
			wsq+=h/a[i].l+1;
            cout<<wsq<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 1792
def count_attack(monsters, count, memo)
  return count if monsters.empty?

  new_monsters = monsters.map do |h|
    count += 1
    new_h = h / 2
    if memo[new_h]
      count += memo[new_h] * 2
      next
    end

    [new_h] * 2
  end.flatten.compact

  count_attack(new_monsters, count, memo)
end

hp = gets.to_i
hp_availables = [hp]
memo = { 1 => 1 }

if hp > 1
  while hp > 1
    hp /= 2
    hp_availables.unshift(hp) if hp > 1
  end
  
  hp_availables.each do |h|
    count = count_attack([h], 0, memo)
    memo[h] = count
  end
end

puts memo[hp_availables.last]


Measured memory_bytes: 3836
// IO library
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// contancer library
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

using ll = long long;
using ld = long double;

template <class T>
ostream& operator<<(ostream& os, vector<T> v) {
    os << "[";
    for (auto vv : v) os << vv << ",";
    return os << "]";
}

template <class T>
ostream& operator<<(ostream& os, set<T> v) {
    os << "{";
    for (auto vv : v) os << vv << ",";
    return os << "}";
}

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

template <class K, class T>
ostream& operator<<(ostream& os, map<K, T> v) {
    os << "{";
    for (auto vv : v) os << vv << ",";
    return os << "}";
}

template <class T>
ostream& operator<<(ostream& os, queue<T> q) {
    os << "[";
    while (!q.empty()) {
        os << q.front() << ",";
        q.pop();
    }
    return os << "]";
}

template <class T>
ostream& operator<<(ostream& os, priority_queue<T> q) {
    os << "{";
    while (!q.empty()) {
        os << q.top() << ",";
        q.pop();
    }
    return os << "}";
}

const ll MOD = 1000000007;
// const ll MOD = 998244353;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const ld PI = acos(-1);
// const ld EPS = 1e-10;
// mt19937 mt(ll(time(0)));

template <class T>
vector<T> Vec(size_t l, T v) { return vector<T>(l, v); }

template <class T, class... Ts>
auto Vec(size_t l, Ts... ts) {
    return vector<decltype(Vec<T>(ts...))>(l, Vec<T>(ts...));
}

template <typename T>
inline T sq(T a) { return a * a; }

template <typename T>
inline T iceil(T n, T d) { return (n + d - 1) / d; }

template <typename T>
T gcd(T a, T b) {
    while (b > 0) {
        a %= b;
        swap(a, b);
    }
    return a;
}

template <typename T, typename U>
T ipow(T b, U n) {
    T ret = 1;
    while (n > 0) {
        if (n & 1) ret *= b;
        n >>= 1;
        b *= b;
    }
    return ret;
}

template <typename T, typename U>
T mpow(T b, U n) {
    T ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * b % MOD;
        n >>= 1;
        b = b * b % MOD;
    }
    return ret;
}

int main() {
    int N;
    cin >> N;
    vector<int> C(N);
    for (auto& c : C) cin >> c;

    vector<set<int>> pos(200010);
    for (int i = 0; i < N; ++i) {
        pos[C[i]].insert(i);
    }

    vector<ll> dp(N + 1, 0);
    dp[0] = 1;
    for (int i = 0; i < N; ++i) {
        // iの石を選ばない場合
        dp[i + 1] += dp[i];
        dp[i + 1] %= MOD;

        // iの石を選ぶ場合
        auto itr = pos[C[i]].upper_bound(i);
        if (itr != pos[C[i]].end() && *itr - i > 1) {
            dp[*itr] += dp[i];
            dp[*itr] %= MOD;
        }
    }

    cout << dp[N] << endl;
    return 0;
}


Measured memory_bytes: 21376
def scanner(S,h,w,H,W):
    count=0
    if S[h][w]=='#':
        return('#')
    if h==0:
        h1=0
    else:
        h1=1
    if h==H-1:
        h2=0
    else:
        h2=1
    if w==0:
        w1=0
    else:
        w1=1
    if w==W-1:
        w2=0
    else:
        w2=1
    for height in range(h-h1,h+h2+1):
        for width in range(w-w1,w+w2+1):
            if S[height][width]=='#':
                count+=1
    return(count)

H,W=map(int,input().split())
S=[list(input())for i in range(H)]
for h in range(H):
    ans=''
    for w in range(W):
        ans+=str(scanner(S,h,w,H,W))
    print(ans)

Measured memory_bytes: 3064
s=input()
k=int(input())
f=lambda x:(123-ord(x))%26 #cost to "a"
g=lambda x:chr((ord(x)-97+k)%26+97)

b=[]
for i in s:
  cost=f(i)
  if cost<=k:
    b.append("a")
    k-=cost
  else:
    b.append(i)
if k:b[-1]=g(b[-1])
print("".join(b))


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

int mod = 1000000007;
int64_t large = 9223372036854775807;
double PI = 3.141592653589793;

int64_t ketasu(int64_t N)
{
    int64_t d = 0;
    while (N != 0)
    {
        N /= 10;
        d++;
    }
    return d;
}

int main()
{
    int64_t N;
    cin >> N;
    int64_t ans = mod;
    for (int64_t i = 1; i * i <= N; i++)
    {
        if (N % i == 0)
            ans = min(ans, max(ketasu(i), ketasu(N / i)));
    }
    cout << ans;
}

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

#define ALL(a) (a).begin(), (a).end()
#define llong long long

using namespace std;

signed main(){
	int n,k; cin >> n >> k;
	string s; cin >> s;
	s[k-1] = (char)(s[k-1]-'A'+'a');
	cout << s << endl;

	return 0;
}



Measured memory_bytes: 256
A,B,C,D=map(int,input().split())
if A%D==0:
    k=int(A/D)
else:
    k=int(A/D)+1

if C%B==0:
    l=int(C/B)
else:
    l=int(C/B)+1


if l<=k:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9184