akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>


void rectangle(int H, int W) {

    for (int i = 0; i < H; i++) {
        if (i == 0 || i == H-1)  {
            for (int j = 0; j < W; j++) {
                printf("#");
            }
        } else {
            for (int j = 0; j < W; j++) {
                if (j == 0 || j == W-1) {
                    printf("#");
                } else {
                    printf(".");
                }
            }
        }
        printf("\n");
    }
    printf("\n");

}

int main(int argc, char const *argv[]) {

    while (1) {
        int H, W;
        scanf("%d %d", &H, &W);

        if (H == 0 && W == 0) {
            break;
        } else {
            rectangle(H, W);
        }
    }

    return 0;
}



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

using namespace std;

int h, w, k;

char mp[10][10];

int res = 0;

int visx[10], visy[10];

int cnt; 

void update() {
	int now = 0;
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			if (visx[i] || visy[j]) continue;
			if (mp[i][j] == '#') now++;
		}
	}
	if (now == k) res++;
}

bool check(int x, int y) {
	if (x >= 1 && x <= h && y >= 1 && y <= w) return true;
	return false;
}

void dfs2(int y, int ok) {
	visy[y] = ok;
	if (y == w) {
		update();
		return;
	} 
	if (y+1 <= w) dfs2(y+1, 0), dfs2(y+1, 1);
}

void dfs1(int x, int ok) {
	visx[x] = ok;
	if (x == h) {
		dfs2(1, 0);
		dfs2(1, 1);
		return;	
	}
	if (x+1 <= h) dfs1(x+1, 0), dfs1(x+1, 1);
}

int main() {
	cin >> h >> w >> k;
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			cin >> mp[i][j];
		}
	}
	dfs1(1, 0);
	dfs1(1 ,1);
	cout << res << endl;
	return 0;
}

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

#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

typedef long long LL;
template<typename T> using V = std::vector<T>;
template<typename T> using VV = std::vector<std::vector<T>>;
template<typename T> using VVV = std::vector<std::vector<std::vector<T>>>;

template<class T> inline T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> inline void print(T x) { std::cout << x << std::endl; }
template<class T> inline void print_vec(const std::vector<T> &v) { for (int i = 0; i < v.size(); ++i) {  if (i != 0) {std::cout << " ";} std::cout << v[i];} std::cout << "\n"; }
template<class T> inline bool inside(T y, T x, T H, T W) {return 0 <= y and y < H and 0 <= x and x < W; }
template<class T> inline double euclidean_distance(T y1, T x1, T y2, T x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }
template<class T> inline double manhattan_distance(T y1, T x1, T y2, T x2) { return abs(x1 - x2) + abs(y1 - y2); }

const int INF = 1L << 30;
const double EPS = 1e-9;
const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
const std::vector<int> dy4 = { 0, 1, 0, -1 }, dx4 = { 1, 0, -1, 0 };    // 4近傍（右, 下, 左, 上）
const std::vector<int> dy8 = { 0, -1, 0, 1, 1, -1, -1, 1 }, dx8 = { 1, 0, -1, 0, 1, 1, -1, -1 };

using namespace std;

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

	int N;
	cin >> N;
	vector<int> A(3 * N);
	FOR(i, 0, 3 * N) {
	    cin >> A[i];
	}

	vector<LL> left(3 * N), right(3 * N);
	priority_queue<int> pq_maxi, pq_mini;
	LL total = 0;
	FOR(i, 0, 3 * N) {
        pq_maxi.push(-A[i]);
        total += A[i];
        if (pq_maxi.size() > N) {
            total -= -pq_maxi.top();
            pq_maxi.pop();
	    }
	    left[i] = total;
	}

    total = 0;
    for (int i = 3 * N - 1; i >= 0; --i) {
        pq_mini.push(A[i]);
        total += A[i];
        if (pq_mini.size() > N) {
            total -= pq_mini.top();
            pq_mini.pop();
        }
        right[i] = total;
    }

    LL ans = -LONG_LONG_MAX;
    FOR(i, N - 1, 2 * N) {
        ans = max(ans, left[i] - right[i + 1]);
    }

    print(ans);

	return 0;
}

Measured memory_bytes: 7288
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
/*
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>


typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };
*/

using namespace std;

int main()
{
    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;

    cout << fixed << setprecision(8) << sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
}


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

int a[110];

main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	int mn=INT_MAX;
	for(int i=-100;i<=100;i++)
	{
		int sum=0;
		for(int j=0;j<n;j++)
		{
			sum+=(i-a[j])*(i-a[j]);
		}
		mn=min(mn,sum);
	}
	printf("%d",mn);
}

Measured memory_bytes: 256
/* ex2_3 KitamoriFumiya */
#include <stdio.h>
 
int main(void){
 
	int length, white, black; // length,white,blackをint型の変数として宣言
	
	scanf("%d %d", &length, &white); // length,whiteを入力
	black = length * length - white; // 黒色に塗るマスの数を計算
	printf("%d\n", black); // 黒色に塗るマスの数を出力
	
	return 0;
}

Measured memory_bytes: 128
implicit none
integer(8):: n,y,i,j
 
read(5,*) n,y
 
do i=0,n
    do j=0,n-i
    if (10000*i+5000*j+1000*(n-i-j)==y) then
        write(6,*) i,j,n-i-j
        goto 100
 endif
 
 enddo
enddo
 
 write(6,*) -1,-1,-1
 
100 end

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
ll umin(ll a ,ll b)
{
	if(a>b)return b;return a;
}
ll dp[101][100001];
int main()
{
	ll n,w;cin >> n >> w;
	vector<ll> ww,vv;ll maxv=0;
	for(ll i=0;i<n;i++)
		{
			ll d;
			cin >> d;ww.push_back(d);cin >> d;vv.push_back(d);
				maxv+=vv[i];
		}
		for(ll i=0;i<=100;i++)
			for(ll j=0;j<=100001;j++)
				dp[i][j]=1e16;
		for(ll i=0;i<=n;i++)
		{
			for(ll j=0;j<=maxv;j++)
			{
				if(i==0 and j!=0)
					dp[i][j]=1e16;
				else if(i==0 or j==0)
					dp[i][j]=0;
				else
				{
					dp[i][j]=umin(dp[i][j],dp[i-1][j]);
					if(j-vv[i-1]>=0)
					dp[i][j]=umin(dp[i-1][j],ww[i-1]+dp[i-1][j-vv[i-1]]);
				}
			}
		}
		ll ans =0;
		for(ll i=0;i<=n;i++)
			for(ll j=0;j<=maxv;j++)
				if(dp[i][j]<=w and ans <j)
					ans=j;
				cout << ans;
	return 0;
}

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

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

  int a[N+1];

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

  int range[N];

  for(int i = 1; i<N; i++){
    range[i] = a[i+1] - a[i];
  }

  range[N] = K - a[N] + a[1];

  int max = range[1];
  for (int i = 1; i <= N; i++) {
      if (max < range[i]) {
          max = range[i];
      }
  }

  cout << K - max << endl;
}


Measured memory_bytes: 5156
from fractions import gcd

M = 10 ** 9 + 7

def xgcd(a, b):
    x0, x1 = 1, 0
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
    return x0 % M

N = int(input())
A = list(map(int, input().split()))

lcm_ = A[0]
for a in A[1:]:
    lcm_ = lcm_ * a // gcd(lcm_, a)

ans = 0
for a in A:
    m = xgcd(a, M)
    ans = ans + lcm_ * m

print(ans % M)

Measured memory_bytes: 6072
#include<bits/stdc++.h>
using namespace std;
int f[10005];
int main()
{
	for(int i=1;i<=100;i++)
	for(int j=1;j<=100;j++)
	for(int k=1;k<=100;k++)
	{
		int t=i*i+j*j+k*k+i*j+i*k+j*k;
		if(t<=10000)f[t]++;
	}
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)printf("%d\n",f[i]);
	return 0;
}


Measured memory_bytes: 3856
//Solution for aoj 0569: Illumination
#include<iostream>
#include<algorithm>
using namespace std;
int h, w, sum, roop;
int comp[101][101];
bool b[101][101], jud;
void aj(int i, int j){
	if (i % 2){
		for (int k = -1; k <= 1; k++){
			for (int l = 0; l <= 1; l++){
				if (b[i + k][j + l] && k != 0)
					sum--;
			}
		}
	}
	else{
		for (int k = -1; k <= 1; k++){
			for (int l = -1; l <= 0; l++){
				if (b[i + k][j + l] && k != 0)
					sum--;
			}
		}
	}
	if (b[i][j - 1])
		sum--;
	if (b[i][j + 1])
		sum--;
}
void aj2(int i, int j){
	if (i == 0 || j == 0 || i == h + 1 || j == w + 1){
		jud = false;
		return;
	}
	if (comp[i][j])
		return;
	comp[i][j] = roop;
	if (i % 2){
		for (int k = -1; k <= 1; k++){
			for (int l = 0; l <= 1; l++){
				if (!b[i + k][j + l] && k != 0)
					aj2(i + k, j + l);
				else if(!k){
					if (!b[i][j - 1])
						aj2(i, j - 1);
					if (!b[i][j + 1])
						aj2(i, j + 1);
					break;
				}
			}
		}
	}
	else{
		for (int k = -1; k <= 1; k++){
			for (int l = -1; l <= 0; l++){
				if (!b[i + k][j + l] && k != 0)
					aj2(i + k, j + l);
				else if(!k){
					if (!b[i][j - 1])
						aj2(i, j - 1);
					if (!b[i][j + 1])
						aj2(i, j + 1);
					break;
				}
			}
		}
	}
}
void aj3(){
	for (int k = 1; k <= h; k++){
		for (int l = 1; l <= w; l++){
			if (comp[k][l] == roop)
				b[k][l] = true;
		}
	}
}
int main(){
	cin >> w >> h;
	roop = 1;
	for (int i = 1; i <= h; i++){
		for (int j = 1; j <= w; j++){
			cin >> b[i][j];
		}
	}
	for (int i = 1; i <= h; i++){
		for (int j = 1; j <= w; j++){
			if(!b[i][j]&&!comp[i][j]){
				jud = true;
				aj2(i, j);
				if (jud == true)
					aj3();
				roop++;
			}
		}
	}
	for (int i = 1; i <= h; i++){
		for (int j = 1; j <= w; j++){
			if (b[i][j]){
				sum += 6;
				aj(i, j);
			}
		}
	}
	cout << sum << endl;
}

Measured memory_bytes: 1860
#include <bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
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; }

struct edge { int to; int cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int MOD = 1e9+7;
const double EPS = 1.0e-12;
const double PI = acos(-1.0);
 
const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

ll dp[110][100010];

int main(){
	int n,W;
	cin >> n >> W;
	vi w(n),v(n);
	rep(i,n) cin >> w[i] >> v[i];
	rep(i,110) rep(j,100010) dp[i][j] = 1e18;
	dp[0][0] = 0;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 100010; j++){
			chmin(dp[i+1][j],dp[i][j]);
			if(j+v[i] < 100010) chmin(dp[i+1][j+v[i]],dp[i][j]+w[i]);
		}
	}
	
	int ans = 0;
	for(int j = 0; j < 100010; j++) if(dp[n][j] <= W) ans = j;
	cout << ans << endl;

	return 0;
}

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, k, s;
  while (cin >> n >> k >> s, n) {
    if (k > n) {
      cout << "0\n";
      continue;
    }
    s -= k;
    vector<int> a(n);
    fill(end(a) - k, end(a), 1);
    int res = 0;
    do {
      int sum = 0;
      for (int i = 0; i < n; ++i) {
        if (a[i]) {
          sum += i;
        }
      }
      res += sum == s;
    } while (next_permutation(begin(a), end(a)));
    cout << res << '\n';
  }
}



Measured memory_bytes: 3100
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>

#ifdef _MSC_VER
#include <agents.h>
#endif

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define X first
#define Y second

using namespace std;

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

int main(){
	int n;
	while (cin >> n, n){
		string s;
		cin >> s;

		rep(i, n){
			string res;
			char c = '0';
			int run = 0;
			rep(j, s.size()){
				if (s[j] == c){
					++run;
				}
				else{
					if (run){
						res += to_string(run)+c;
					}
					c = s[j];
					run = 1;
				}
			}
			if (run){
				res += to_string(run) + c;
			}
			s = res;
		}
		cout << s << endl;
	}


	return 0;
}

Measured memory_bytes: 1368
'''
自宅用PCでの解答
'''
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7
# mod = 998244353
dir = [(-1,0),(0,-1),(1,0),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"
INF = 1<<32-1
# INF = 10**18

def main():
    n = int(ipt())
    cnt = 0
    for i in range(n):
        a,b = map(int,ipt().split())
        if a == b:
            if cnt == 2:
                print("Yes")
                exit()
            else:
                cnt += 1
        else:
            cnt = 0
    print("No")

    return None

if __name__ == '__main__':
    main()


Measured memory_bytes: 68788
import bisect

n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
a =sorted(a)
b =sorted(b)
c =sorted(c)

ans = 0
for i in range(n):
    in_a = bisect.bisect_left(a,b[i])
    in_c = bisect.bisect_right(c,b[i])
    ans += (in_a)*(n-in_c)


print(ans)


Measured memory_bytes: 107108
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <ctime>
#include <map>
#include <stack>
#include <sstream>

using namespace std;

int main(void)
{
	string s;
	string res;

	cin >> s;

	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] == '0' || s[i] == '1')
		{
			res.push_back(s[i]);
		}
		else
		{
			if (res.size() > 0)
			{
				res.pop_back();
			}
		}
	}

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public final class Main {

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final int n = Integer.parseInt(in.nextLine());
        int[] arr = new int[n];
        int totalXor = 0;
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
            totalXor ^= arr[i];
        }
        in.nextLine();
        for (int i = 0; i < n; i++) {
            System.out.print((totalXor ^ arr[i]) + " ");
        }
        System.out.println();
    }
}


Measured memory_bytes: 62852
import itertools
X, Y=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
MOD = 10**9 + 7
if (X+Y)%3 != 0:
    print(0)
else:

    n = int((2*Y-X)/3)
    m = int((2*X-Y)/3)

    # print(f"n:{n}, m:{m}")

    if n<0 or m<0:
        print(0)
    else:
        ret = 1
        for i in range(m):
            ret = ret * ((X+Y)//3 - i) % MOD * pow(i + 1, MOD-2, MOD) % MOD
        print(ret)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
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; }
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main () {
  int n = in();
  set<int> st;
  rep(i,n) {
    st.insert(in());
  }
  if (st.size() == n) 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 all(x) (x).begin(),(x).end()
#define pb push_back
typedef long long ll;
const int INF = 1000000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 1000000007ll;


int main(){
	ll s,c;
	std::cin >> s>>c;
	if(2*s>=c)std::cout << c/2 << std::endl;
	else std::cout << (c-2*s)/4 + s<< std::endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

const ll MOD = 1e9 + 7;

ll power(ll x, ll e) {
  ll v = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) {
      v = v * x % MOD;
    }
    x = x * x % MOD;
  }
  return v;
}

ll inverse(ll x) {
  return power(x, MOD - 2);
}

vector<ll> fact, factInv;
void initFact(int N) {
  fact.resize(N + 1);
  factInv.resize(N + 1);
  fact[0] = 1;
  for (int i = 1; i <= N; i++) {
    fact[i] = fact[i - 1] * i % MOD;
  }
  factInv[N] = inverse(fact[N]);
  for (int i = N - 1; i >= 0; i--) {
    factInv[i] = factInv[i + 1] * (i + 1) % MOD;
  }
}

ll choose(int n, int k) {
  if (k > n) {
    return 0;
  } else {
    return fact[n] * factInv[k] % MOD * factInv[n - k] % MOD;
  }
}

ll f(ll N, ll M) {
  ll res = (N - 1);
  res = res * N % MOD;
  res = res * (N + 1) % MOD;
  res = res * inverse(6) % MOD;
  res = res * M % MOD * M % MOD;
  return res;
}

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  initFact(2000010);
  int N, M, K;
  while (cin >> N >> M >> K) {
    ll res = (f(N, M) + f(M, N)) % MOD;
    res = res * choose(N * M - 2, K - 2) % MOD;
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 31488
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const int INF = 1e18+10;

/*--------------------------------------------------------------------*/


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

  vi yaku;
  for(int i=1;i*i<=m;i++){
    if(m%i==0){
      yaku.pb(i);
      if(i*i!=m) yaku.pb(m/i);
    }
  }
  sort(all(yaku));

  // rep(i,yaku.size()) cout<<yaku[i]<<endl;
  int mx=0;
  for(int g:yaku){
    int z=m-g*n;
    if(z<0) continue;
    if(z%g==0) mx=g;
    // printf("%d:%d\n",g,z);
  }
  cout<<mx<<endl;
  return 0;
}


Measured memory_bytes: 3600
#include "bits/stdc++.h"

using namespace std;
const int dx[] = { -1,0,1,0 };
const int dy[] = { 0,-1,0,1 };
const int ddx[] = { 0,1,1,  0,2, 1,-1,-2, 2, 2, -2,-2,1,-1,1,-1,2,2,-2,-2 };
const int ddy[] = { 2,1,-1,-2,0, 1, 1, 0,2, -2,  2,-2,2,2, -2,-2, 1,-1,1,-1 };


int main() {
	int H, W;
	cin >> H >> W;
	int ch, cw, dh, dw;
	cin >> ch >> cw >> dh >> dw;
	ch--; cw--; dh--; dw--;
	vector<string> S(H);
	for (int n = 0; n < H; ++n) {
		cin >> S[n];
	}

	vector<vector<int>> D(H, vector<int>(W, 1e9));//回数
	deque<pair<int, int>> q;
	q.push_front(make_pair(ch, cw));
	D[ch][cw] = 0;

	while (!q.empty()) {
		int x = q.front().first;
		int y = q.front().second;
		q.pop_front();
		//範囲内かつ0を4セット
		for (int l = 0; l < 4; ++l) {
			int x1 = x + dx[l];
			int y1 = y + dy[l];
			if ((0 <= x1) && (H > x1) && (0 <= y1) && (W > y1) && ('.' == S[x1][y1])) {
				if (D[x1][y1] > D[x][y]) {
					D[x1][y1] = D[x][y];
					q.push_front(make_pair(x1, y1));
				}
			}
		}
		//範囲内かつ0を20セット
		for (int l = 0; l < 20; ++l) {
			int x1 = x + ddx[l];
			int y1 = y + ddy[l];
			if ((0 <= x1) && (H > x1) && (0 <= y1) && (W > y1) && ('.' == S[x1][y1])) {
				if (D[x1][y1] > D[x][y] + 1) {
					D[x1][y1] = D[x][y] + 1;
					q.push_back(make_pair(x1, y1));
				}
			}
		}
	}
	if (1e9 == D[dh][dw]) {
		cout << -1 << endl;
	}
	else {
		cout << D[dh][dw] << endl;
	}
	return 0;
}

Measured memory_bytes: 9448
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,w = list(map(int, input().split()))
wv = [None]*n
for i in range(n):
    wv[i] = tuple(map(int, input().split()))
w0 = wv[0][0]
wv = [(item[0]-w0, item[1]) for item in wv]
ans = 0
def sub(k):
    W = w - k*w0
    m = min(W, sum(item[0] for item in wv))
    dp = [[[0]*(k+1) for _ in range(m+1)] for _ in range(n+1)]
    for i in range(1,n+1):
        iw, iv = wv[i-1]
        for j in range(m+1):
            for kk in range(1,k+1):
                if j>=iw:
                    dp[i][j][kk] = max(dp[i-1][j][kk], dp[i-1][j-iw][kk-1]+iv)
                else:
                    dp[i][j][kk] = dp[i-1][j][kk]
#     print(k, dp)
    return max(dp[n][j][kk] for j in range(m+1) for kk in range(k+1))
for k in range(1, w//w0+1):
    if k>n:
        break
    ans = max(ans, sub(k))
print(ans)

Measured memory_bytes: 144192
#include <bits/stdc++.h>
using namespace std;
#include<algorithm>
int main() {
	int N;
	string A, B, C;
	cin >> N >> A >> B >> C;
	int ans = 0;
	for (int i = 0; i < N; i++) {
		if (A[i] == B[i] && A[i] == C[i])continue;
		else if (A[i] == B[i] || B[i] == C[i] || C[i] == A[i])ans++;
		else ans += 2;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	// 整数の入力
	int a, b, s;
	cin >> a >> b;
	// 文字列の入力
	if (a == b) s = a + b;
	else if (a > b) s = a + a - 1;
	else s = b + b - 1;
	
	// 出力
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
N  = int(input())

plans = []

for _ in range(N):
  a, b, c = map(int, input().split())
  plans.append((a, b, c))
  
memo = [[0] * (N + 1) for _ in range(3)]

for day, plan in enumerate(plans, 1):
  memo[0][day] = max(memo[1][day - 1], memo[2][day - 1]) + plan[0]
  memo[1][day] = max(memo[0][day - 1], memo[2][day - 1]) + plan[1]
  memo[2][day] = max(memo[0][day - 1], memo[1][day - 1]) + plan[2]
    
print(max(memo[0][N], memo[1][N], memo[2][N]))


Measured memory_bytes: 32408
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
using namespace std;
int father[500005],p[500005];
int n,m,a,b,x,y;
int find(int x){
	if(x!=father[x])father[x]=find(father[x]);
	return father[x];
}
void unionn(int x,int y){
	father[find(x)]=find(y);
}
int main(){
     scanf("%d%d",&n,&m);
     for(int i=1;i<=n;i++)father[i]=i;
     for(int i=1;i<=n;i++)scanf("%d",&p[i]);
     for(int i=1;i<=m;i++){
     	scanf("%d%d",&x,&y);
     	unionn(x,y);
	 }
	 int ans=0;
	 for(int i=1;i<=n;i++){
	 	if(find(i)==find(p[i]))ans++;
	 }
	 cout<<ans; 
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
    return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

char str[200005];

int main()
{
    scanf("%s",&str);
    int n=strlen(str),x=0;
    for(int i=0;i<n;i++)x=(x+str[i]-48)%9;
    puts(x?"No":"Yes");
    return 0;
}

Measured memory_bytes: 3356
n, m = map(int, raw_input().strip().split())
a = map(int, raw_input().strip().split())

total = sum(a)
cnt = 0

for i in xrange(n):
    if 4 * m * a[i] >= total: cnt += 1

if cnt >= m:
    print "Yes"
else:
    print "No"


Measured memory_bytes: 27884
#include <bits/stdc++.h>
 
#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        200005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<pii>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>
 
using namespace std;
 
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
 
int power(int a,int n)
{
    a %= mod;
    if(n == 1)return a;
    if(n == 0)return 1;
    if(n%2)return (a*(power((a*a)%mod,n/2)%mod))%mod;
    return power((a*a)%mod,n/2)%mod;
}

const int inf = (int) 1e18;
 
int inverse(int x){
    return power(x,mod-2)%mod;//little fermat....
}


void solve(){
    int n,m;
    cin >> n >> m;
    set<int>pows;
    vector<int>v(n+5);
    FOR(i,1,n+1){
        cin >> v[i];
        int x = v[i],p = 0;
        while((x%2) == 0)x /= 2,p++;
        pows.insert(p);
    }
    if(sz(pows) > 1){cout << "0\n";return ;}
    FOR(i,1,n+1)v[i] /= 2;
    if(n == 1){
        cout << (m/v[1]+1)/2 << "\n";return ;
    }
    int l = (v[1]*v[2])/__gcd(v[1],v[2]);
    FOR(i,3,n+1){
        if(v[i]/__gcd(v[i],l) > ceil((1.0l*m)/(1.0l*l))){cout << "0\n";return ;}
        l = (l*v[i])/__gcd(v[i],l);
    }
    cout << (m/l+1)/2 << "\n";
}

signed main()   
{
    showoff;
    int T = 1;
    //cin >> T;
    FOR(t,1,T+1){
       solve();
    }
    return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ...


Measured memory_bytes: 1024
#include <stdio.h>

int main(void)
{
	int N;
	int s[101];
	
	scanf("%d", &N);
	for(int i = 0; i < N; i++){
		scanf("%d", &s[i]);
	}
	
	int sum = 0, min = 101;
	for(int i = 0; i < N; i++){
		sum += s[i];
		if(min > s[i] && s[i] % 10){
			min = s[i];
		}
	}
	
	int ans;
	if(sum % 10) ans = sum;
	else if(min == 101) ans = 0;
	else ans = sum - min;
	
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
#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--)

using E = tuple<int, int>;
vector<vector<E>> edge;
vector<int> dp1, dp2;

void dfs1(int node, int parent)
{
    dp1[node] = 0;
    for (E e : edge[node]) {
        int v, w;
        tie(v, w) = e;
        if (v != parent) {
            dfs1(v, node);
            dp1[node] = max(dp1[node], dp1[v] + w);
        }
    }
}

void dfs2(int node, int parent, int other)
{
    dp2[node] = max(dp1[node], other);

    int n = edge[node].size();
    vector<int> lmax(n + 1), rmax(n + 1);
    lmax[0] = rmax[n] = 0;
    rep(i, n)
    {
        int v, w;
        tie(v, w) = edge[node][i];
        lmax[i + 1] = rmax[i] = (v == parent ? 0 : dp1[v] + w);
    }

    rep(i, n)
    {
        lmax[i + 1] = max(lmax[i + 1], lmax[i]);
        rmax[n - (i + 1)] = max(rmax[n - (i + 1)], rmax[n - i]);
    }

    rep(i, n)
    {
        int v, w;
        tie(v, w) = edge[node][i];
        if (v != parent) {
            dfs2(v, node, w + max(other, max(lmax[i], rmax[i + 1])));
        }
    }
}

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

    edge.resize(n);
    rep(i, n - 1)
    {
        int a, b, c;
        cin >> a >> b >> c;
        edge[a].push_back(E(b, c));
        edge[b].push_back(E(a, c));
    }

    dp1.resize(n);
    dfs1(0, 0);

    dp2.resize(n);
    dfs2(0, 0, 0);

    rep(i, n)
    {
        cout << dp2[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 4876
n,a,b=map(int, input().split())
x=list(map(int, input().split()))

ans=0
for i in range(n-1):
    if (x[i+1]-x[i])*a<b:
        ans+=(x[i+1]-x[i])*a
    else:
        ans+=b
print(ans)


Measured memory_bytes: 20124
#include<bits/stdc++.h>
using namespace std;
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

int main(){
    int K, a=0, b=0;
    cin >> K;
    long long cnt = 0;
    for(int i = 1; i <= K; i++){
        for(int j = 1; j <= K; j++){
            for(int k = 1; k <= K; k++){
                a = gcd(i, j);
                b = gcd(a, k);
                cnt += b;
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3632
#include <stdio.h>

int main() {
    int n = 0;
    int max = 0;
    int list[1000];
    
    if( scanf("%d %d", &n, &max)) {
        
        for(int i = 0; i < n; ++i) {
            if (scanf("%d", &list[i])) {
                
            }
        }
        
        int total = 0;
        for( int i = 0; i < n; ++i) {
            total += list[i];
        }
        
        int answer = n;
        int min = 100000;
        
        for(int i = 0; i < n; ++i) {
            if (min > list[i] ) {
                min = list[i];
            }
        }
        
        int less = max - total;
        int remain = less / min;
        
        answer += remain;
        
        printf("%d\n", answer);
    }
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define forn(i,n) for(ll (i) = 0 ; (i) < (n) ; ++(i))
#define for1(i,n) for(ll (i) = 1 ; (i) <= (n) ; ++(i))
#define vll vector<ll>
#define pll pair<ll ,ll >
#define vpll vector< pll >
#define mp make_pair
#define pb push_back
const ll MOD=1e9+7;
//#define endl "\n"
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define deb1(args...) do {cerr << #args << " : "; dbg,args; cerr << "\n";} while(0)

ll extended_GCD(ll a , ll b , ll &x , ll &y){
    if(a == 0){
        x = 0;
        y = 1;
        return b;
    }
    ll x1 , y1;
    ll gcd = extended_GCD(b%a , a , x1 , y1);
    x = y1 - (b/a)*x1; 
    y = x1;
    return gcd;
}
ll modinv(ll a , ll mod = MOD){
    ll x , y;
    extended_GCD(a , mod , x , y);
    if(x < 0) x += mod;
    return x;
}
ll power(ll a, ll b, ll m = MOD) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
ll binomialCoeff(ll n,ll k) 
{ 
    ll res = 1; 
    if ( k > n - k ) 
        k = n - k; 

    for (  ll i = 0; i < k; ++i) 
    { 
        res = (res* (n - i))%MOD; 
        res = (res* modinv(i + 1))%MOD; 
    } 
    return res; 
} 

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // #endif
    ll t=1;
    // cin>>t;
    while(t--){
        ll n,x,c=0,sum=0;
        cin>>n;
        vector<vll>a(n,vll(3));
        vector<vll>ans(n,vll(3));
        forn(i,n)   cin>>a[i][0]>>a[i][1]>>a[i][2];
        ans[0]=vll(all(a[0]));
        forn(i,n-1){
            forn(j,3){
                ans[i+1][j]=a[i+1][j]+max(ans[i][(j+1)%3],ans[i][(j+2)%3]);
            }
        }
        cout<<*max_element(all(ans[n-1]))<<endl;        
    }
    // #ifndef ONLINE_JUDGE
    //     cout<<endl<<"Time Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec"<<endl;
    // #endif
}

Measured memory_bytes: 11264
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 100005;

int main() {
    int n; cin >> n;
    vector<P> red(n), blue(n);
    vector<bool> check(n,false);
    rep(i,n) {
        int x, y; cin >> x >> y;
        red[i] = P(y,x);
    }
    rep(i,n) {
        int x, y; cin >> x >> y;
        blue[i] = P(x,y);
    }
    sort(all(blue));
    sort(all(red));
    int ct = 0;
    for (auto &p: blue) {
        int index = lower_bound(all(red),P(p.second,-inf))-red.begin();
        for (int i = index-1; i >= 0; i--) {
            if (red[i].second >= p.first) continue;
            if (!check[i]) {
                check[i] = true;
                // cout << endl;
                // cout << p.first << " " << p.second << endl;
                // cout << red[i].second << " " << red[i].first << endl;
                ct++;
                break;
            }
        }
    }
    cout << ct << endl;
}

Measured memory_bytes: 256
S = input()
Ans = 0
sr = 0

for i in range(1,4):
  if S[i-1] == 'S':
    sr = 0
  else:
    sr += 1
    if sr > Ans:
      #copyつけなくていい理由を後で検証
      Ans = sr
    
print(Ans)


Measured memory_bytes: 9024
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  ll n,m;
  cin >> n >> m;
  ll a[n];
  rep(i,n) R a[i];
  sort(a,a+n);
  ll ans=MAXL;
  rep(i,n) {
    if(i+m-1<n) ans=min(ans,abs(a[i]-a[i+m-1]));
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


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

int main() {
  string s,t;
  cin>>s>>t;
  int n=s.size();
  bool f=true;
  for(int i=0;i<n;i++){
    if(s.at(i)!=t.at(i)){
        f=false;
        break;
    }
  }
  if(f==true){
  cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
    }
}



Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#define swap(type, x, y) do{type t = x; x = y; y = t;} while(0)

using namespace std;

void quick(int a[], int left, int right){
  int pl = left;
  int pr = right;
  int x = a[(pl + pr) / 2];
  do{
    while(x > a[pl])pl++;
    while(x < a[pr])pr--;
    if(pl <= pr){
      swap(int, a[pl], a[pr]);
      pl++;
      pr--;
    }
  }while(pl <= pr);
  if(left < pr)  quick(a, left, pr);
  if(pl < right) quick(a, pl, right);
}

int main(){
  int N;
  cin >> N;
  int num[N];
  int i, j;

  // 入力
  for(i = 0; i < N; i++){
    cin >> num[i];
  }
  // ソート
  quick(num, 0, N - 1);

  // 異値の個数をカウント
  i = 0;
  int hz, cnt, result = 0;
  while(i < N){
    hz = num[i];
    cnt = 0;
    while(i < N && num[i] == hz){
      cnt++;
      i++;
    }
    result += cnt % 2;
  }
  cout << result << endl;
}

Measured memory_bytes: 640
N = int(input())

# ここで、七五三数とは以下の条件を満たす正の整数です。
# 十進法で表記したとき、数字 7, 5, 3 がそれぞれ 1 回以上現れ、これら以外の数字は現れない。


def dfs(s):
    if int(s) > N:
        return 0

    ret = 1 if all(s.count(c) > 0 for c in '753') else 0

    for c in '753':
        ret += dfs(s + c)
    return ret


print(dfs('0'))

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    ll x; cin >> x;
    ll ans = 0;
    if(x >= 11){
        ll tmp = x%11;
        ans += (x/11)*2;
        if(tmp > 6) ans += 2;
        else if(tmp>0) ans++;
    }else if(x>6){
        ans += 2;
    }else{
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3608
def gcd(a, b):
    big = max(a, b)
    small = min(a, b)
    
    r = small
    while small != 0:
        r = big % small
        big = small
        small = r
    
    return big

def main():
    n, *t = map(int, open(0).read().split())
    
    r = t[0]
    for i in range(1, n):
        num = gcd(r, t[i])
        r = num * (r // num) * (t[i] // num)
        
    print(r)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
require 'prime'
require 'pp'

q = gets.to_i
primes = Prime.each(100000)

primes_2017 = primes.select { |p| Prime.prime?((p + 1) / 2) }
p_reversed = primes_2017.reverse

q.times do
    l, r = gets.strip.split.map(&:to_i)
    lower = primes_2017.bsearch_index { |p| p >= l }
    upper = p_reversed.bsearch_index { |p| p <= r }
    if lower == nil || upper == nil
        puts 0
    else
        puts (primes_2017.size - upper - 1) - lower + 1
    end
end


Measured memory_bytes: 3128
import sys
X,K,D=map(int,input().split())
Xa=abs(X)
Da=abs(D)
one=Xa//Da

if K < one:
    print(Xa-Da*K)
    sys.exit()


guki=(K-one)%2

if guki==0:
    print(abs(Xa-Da*one))
else:
    print(abs(Xa-Da*(one+1)))

Measured memory_bytes: 9148
#include<stdio.h>
int main(void){
    int a,b,c,i,j;
    j=0;
    scanf("%d %d %d",&a,&b,&c);
    for(i=a;i<=b;i++){
        if(c%i==0){
            j++;
        }
    }
    printf("%d\n",j);
    return 0;
}



Measured memory_bytes: 2060
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

struct Edge{
    int u, v;
    int64_t cost;
    
    Edge() = default;
    Edge(int u, int v, int64_t cost) : u(u), v(v), cost(cost) {}

    bool operator<(const Edge& other) const{
        return cost < other.cost;
    }
};

struct UnionFind{
    int sz;     // vertex number
    vector<int> par;
    vector<int> rank;

    UnionFind(int n) : sz(n) {
        par.resize(sz);
        rank.assign(sz, 0);
        for(int i = 0; i < sz; ++i){
            par[i] = i;
        }
    }

    int find(int x){
        if(par[x] == x) return x;
        else    return par[x] = find(par[x]);
    }

    bool same(int x, int y){
        return find(x) == find(y);
    }

    void unite(int x, int y){
        x = find(x), y = find(y);
        if(x == y)  return;
        if(rank[x] < rank[y])   par[x] = y;
        else{
            par[y] = x;
            if(rank[x] == rank[y])  ++rank[x];
        }
    }
};

// クラスカル法を適用してグラフの最小全域木を求める
template<typename T>
T Kruskal(vector<Edge> &es, int VertexNumber){
    T res = 0;    
    sort(es.begin(), es.end());
    int sz = es.size();
    UnionFind tree(VertexNumber);
    for(int i = 0; i < sz; ++i){
        if(!tree.same(es[i].u, es[i].v)){
            tree.unite(es[i].u, es[i].v);
            res += es[i].cost;
        }
    }
    return res;
}

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

    int n;
    cin >> n;
    vector<P> xp, yp;
    for(int i = 0; i < n; ++i){
        int x, y;
        cin >> x >> y;
        xp.emplace_back(x, i);
        yp.emplace_back(y, i);
    }
    sort(xp.begin(), xp.end());
    sort(yp.begin(), yp.end());
    vector<Edge> es;
    for(int i = 0; i + 1 < n; ++i){
        int c = xp[i + 1].first - xp[i].first;
        es.emplace_back(xp[i].second, xp[i + 1].second, c);
        c = yp[i + 1].first - yp[i].first;
        es.emplace_back(yp[i].second, yp[i + 1].second, c);
    }
    UnionFind uf(n);
    int64_t ans = Kruskal<int64_t>(es, n);
    cout << ans << endl;
}

Measured memory_bytes: 9488
import numpy as np
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))

def do():
    n=INT()
    a=np.array(LIST())
    ans=0
    mod=10**9+7
    for i in range(70):
        digit=np.sum((a>>i)&1)
        ans+=pow(2,i,mod)*(((n-digit)*digit)%mod)%mod
        ans=ans%mod
    
    print(ans)



if __name__=='__main__':
    do()

Measured memory_bytes: 68804
import sys
n = int(input())
l = [[int(i) for i in input().split()] for i in range(n)] 
l = sorted(l, key=lambda x: x[1])  #[1]に注目してソート
t=0

for i in range(n):
    t+=l[i][0]
    if t > l[i][1]:
        print("No")
        sys.exit()
print("Yes")

Measured memory_bytes: 42712
#include <stdio.h>

int main(void)
{
	int a, b, c, d;
	int p;
	int com_x, com_y;
	
	scanf("%d %d %d %d %d", &a, &b, &c, &d, &p);
	
	com_x = a * p;
	
	if (c > p){
		com_y = b;
	}
	else if (c < p){
		com_y = b + (p - c) * d;
	}
	
	if (com_x < com_y){
		printf("%d\n", com_x);
	}
	else {
		printf("%d\n", com_y);
	}
	
	return (0);
}

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

int main() {
    const int MAX = 10000001;
    bool isPrime[MAX];
    fill_n(isPrime, MAX, true);
    isPrime[0] = isPrime[1] = false;
    for (int i = 4; i < MAX; i += 2) {
        isPrime[i] = false;
    }
    for (int i = 3; i * i <= MAX; i += 2) {
        if (isPrime[i]) {
            for (int j = 2 * i; j < MAX; j += i) {
                isPrime[j] = false;
            }
        }
    }
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }
        if (n % 2 == 0) {
            n--;
        }
        for (int i = n; i > 8; i -= 2) {
            if (isPrime[i] && isPrime[i - 2] && isPrime[i - 6] && isPrime[i - 8]) {
                cout << i << endl;
                break;
            }
        }
    }
}

Measured memory_bytes: 10000
#include<bits/stdc++.h>
using namespace std;
#define ALL(A) A.begin(),A.end()
const long long mod=1000000007;
int main(){
    int n;
    cin>>n;
    string s[n];int l[n];
    for(int i=0;i<n;i++){
    cin>>s[i];l[i]=s[i].size();l[i]--;
    }
    int ans=0,la=0,fb=0,lafb=0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<l[i];j++)
        {
            if(s[i][j]=='A'&&s[i][j+1]=='B')
            ans++;
        }
        if(s[i][0]=='B'&&s[i][l[i]]=='A')
        lafb++;
        else if(s[i][0]=='B')
        fb++;
        else if(s[i][l[i]]=='A')
        la++;
    }
    if(lafb>0&&fb==0&&la==0)
    {
        ans+=(lafb-1);cout<<ans<<endl;return 0;
    }
    while(lafb>0&&la>0&&fb>0)
    {
        ans+=2;lafb--;la--;fb--;
    }
    if(lafb==0)
    {
        while(la>0&&fb>0)
        {
            ans++;la--;fb--;
        }
    }
    else
    {
        int t=min(la,fb);
        while(t>0&&lafb>0)
        {
            ans++;t--;lafb--;
        }
        ans+=(lafb);
    }
    
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include<bitset>

using namespace std;
#define loop(i,n) for(int i = 0; i < (n); ++i)
#define loops(i,f,n) for(int i = (f); i < (n); ++i)
#define INF 9999999
#define lint long long int
#define VEC vector<int>
#define VEC2 vector<vector<int>>

int main()
{
	int a, c;
	char b;
	while (cin >> a >> b >> c)
	{
		if (b == '?')break;
		switch (b)
		{
		case '+':
			cout << a + c << endl;
			break;
		case '-':
			cout << a - c << endl;
			break;
		case '*':
			cout << a*c << endl;
			break;
		case '/':
			cout << a / c << endl;
			break;
		}
	}
}


Measured memory_bytes: 3116