akhauriyash/Code-Regression huggingface dataset:
# abc140_a.py
# https://atcoder.jp/contests/abc140/tasks/abc140_a

# A - Password /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 100点

# 問題文
# 高橋君は 3桁のパスワードを設定しようとしています。
# 使える文字が 1以上 N以下の数字のみであるとき、設定できるパスワードが全部で何種類であるかを答えてください。

# 制約
#     1≤N≤9
#     Nは整数である。

# 入力
# 入力は以下の形式で標準入力から与えられる。
# N

# 出力
# 設定できるパスワードが何種類であるかを出力せよ。

# 入力例 1
# 2

# 出力例 1
# 8

# 設定出来るパスワードは 111, 112, 121, 122, 211, 212, 221, 222 の 8種類です。

# 入力例 2
# 1

# 出力例 2
# 1

# 使える文字が 1種類しか無い場合、パスワードは 1 種類しか設定出来ません。


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    # FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    # S = lines[0]
    N = int(lines[0])
    # N, M = list(map(int, lines[0].split()))
    # values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(N):
    #     valueses.append(list(map(int, lines[i+1].split())))

    result = N**3

    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['2']
        lines_export = [8]
    if pattern == 2:
        lines_input = ['1']
        lines_export = [1]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(1)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()


Measured memory_bytes: 9232
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <map>

//#include <bits/stdc++.h>
using namespace std;
#define print(x) cout<<(x)<<endl
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long int
#define pb push_back

int main() {
  string s, t;
  cin >> s >> t;

  rep(i, s.size()){
    if(s[i] != t[i]){
      cout << "No" << endl;
      return 0;
    }
  }
  print( "Yes");

}


Measured memory_bytes: 3624
#include<stdio.h>
#include<iostream>
using namespace std;

int main(){

int x,y,z,w,x2,y2,z2,w2;
int n;
while(1){
cin>>n;if(n==0)break;
for(int i=0;i<n;i++){
//cin>>x>>y>>z>>w;
//cin>>x2>>y2>>z2>>w2;
scanf("%d%d%d%d %d%d%d%d",&x,&y,&z,&w,&x2,&y2,&z2,&w2);
int a=0,b=0,c=0,d=0;

a=x*x2-y*y2-z*z2-w*w2;
b=x*y2+y*x2+z*w2-w*z2;
c=x*z2-y*w2+z*x2+w*y2;
d=x*w2+y*z2-z*y2+w*x2;

printf("%d %d %d %d\n",a,b,c,d);
}
}
return 0;
}

Measured memory_bytes: 1228
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef long double ld;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
ll exp(ll x,ll y){if(y==0) return 1;if(y%2 == 1) return x*exp(x,y/2)*exp(x,y/2);return exp(x,y/2) * exp(x,y/2);}
ll exp(ll x,ll y,ll modd) {if(y==0) return 1;ll t=exp(x,y/2,modd);t = t%modd;t=t*t;t=t%modd;if(y % 2 == 1) return (x*t)%modd ;return t%modd;}
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC target ("sse4")
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define cl clear() ;
#define vl vector<ll>
#define sz size()
#define len length()
#define emp empty()
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define en end()
#define ro return 0
#define eb emplace_back
#define con continue
#define ms(x) memset(x , 0ll, so x)
#define all(x) (x).be , (x).en
#define acc(x) accumulate((x).be , (x).en , 0ll)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define revn(i,a,b) for(ll i=a;i>=b;--i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vs vector<string>
#define vsi vector<pair<string,int>>
#define vll vector<pair<ll,ll> >
#define vlll vector<pair<ll,pair<ll,ll>>>
#define vlvl vector<pair<pair<ll,ll>,ll>>>
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
#define trace3(a,b,c) cerr <<"a is " << a << " b is " << b << " c is " << c << el;
#define trace4(a,b,c,d) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << el ;
#define trace5(a,b,c,d,e) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << el;
#define trace6(a,b,c,d,e,f) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << " f is " << f << el ;

ll dp[500][500], a[500], pref[500];
int n;
const ll inf = 1e18+7;
ll solve(int i, int j)
{
	if(dp[i][j]!=-1)return dp[i][j];
	if(i==j)return dp[i][j] = 0;
//	if(i>j)return dp[i][j] = inf;
	if(i+1==j) return dp[i][j] = a[i-1]+a[j-1];
	ll ans = inf;
	for(int m=i; m<j; m++)
	{
		ll temp = solve(i, m) + solve(m+1,j) + (pref[j] - pref[i-1]); 
		ans = min(ans, temp);
	}
	return dp[i][j] = ans;
}

int main()
{
    ios;
	cin>>n;
    for(int i=0;i<n;i++)
		cin>>a[i];
	
	memset(dp,-1,sizeof(dp));
	pref[0]=0;
	for(int i=1;i<=n;i++)
		pref[i] = pref[i-1]+a[i-1];
		
	cout<<solve(1,n);
	return 0;
	
	
}

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

struct THorizonalLine
{
	int Left;
	int Right;
};

int main()
{
	int w;
	cin >> w;
	int n;
	cin >> n;
	vector<int> StartingPoint(w);
	for(int i = 0; i < w; i++){
		StartingPoint[i] = i+1;
	}
	for(int i = 0; i < n; i++){
		THorizonalLine HorizonalLine;
		char Dummy;
		cin >> HorizonalLine.Left >> Dummy >> HorizonalLine.Right;
		swap(StartingPoint[HorizonalLine.Left-1], StartingPoint[HorizonalLine.Right-1]);
	}
	for(int i = 0; i < w; i++){
		cout << StartingPoint[i] << endl;
	}
	return 0;
}

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

ll a[50],b[50];
int main(){
	int n;scanf("%d",&n);
	rep(i,n)scanf("%lld",&a[i]);
	ll cnt=0;
	while(1){
		bool flag=true;
		rep(i,n){
			ll d=a[i]+(cnt-b[i])-b[i]*n;
			if(d>=n){
				flag=false;
				b[i]+=(d-n+1)/n+!!((d-n+1)%n);
				cnt+=(d-n+1)/n+!!((d-n+1)%n);
			}
		}
		if(flag)break;
	}
	printf("%lld\n",cnt);
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include <time.h>
typedef long long llint;

llint min2(llint a,llint b){
    return a>=b?b:a;
}

int main(void){
    llint n,i,odd=0,end=0;
    char s[200000];
    scanf("%s",s);
    n=strlen(s);
    for(i=0;i<n;i++){
        if(i%2==0){
            if(s[i]=='0') odd++;
            if(s[i]=='1') end++;
        }else{
            if(s[i]=='1') odd++;
            if(s[i]=='0') end++;
        }
    }
    // printf("%lld",end);
    printf("%lld\n",min2(odd,end));
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define sz(x) ((int)(x).size())
typedef long long ll;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

const int inf = 1 << 30;
const ll INF = 1LL << 60;

vector<ll> enumerate_num(ll x){
    vector<ll> res;
    for(ll i = 1; i * i <= x; i++){
        if (x % i == 0){
            res.push_back(i);
            if (i * i != x) res.push_back(x / i);
        }
    }
    sort(all(res));
    return res;
}

int main(){
    ll n;
    cin >> n;
    ll ans = 0;
    auto res = enumerate_num(n);
    for(int i = 1; i < sz(res); i++){
        ll x = res[i]-1;
        if ((n / x) == (n % x)) ans += x;
    }
    view(ans);
    return 0;
}

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

#define ZERO(a) memset(a,0,sizeof(a))
template<int MV> class SCC {
public:
	vector<vector<int> > SC; int NV, GR[MV], rev[MV];
private:
	vector<int> E[MV], RE[MV], NUM; int vis[MV];
public:
	void init(int NV) { this->NV = NV; for (int i = 0; i<MV; i++) { E[i].clear(); RE[i].clear(); } }
	void add_edge(int x, int y) { E[x].push_back(y); RE[y].push_back(x); }
	void dfs(int cu) { vis[cu] = 1; for (int i = 0; i<E[cu].size(); i++) if (!vis[E[cu][i]]) dfs(E[cu][i]); NUM.push_back(cu); }
	void revdfs(int cu, int ind) {
		int i; vis[cu] = 1; GR[cu] = ind; SC[ind].push_back(cu); rev[cu] = ind;
		rep(i, 0, RE[cu].size()) if (!vis[RE[cu][i]]) revdfs(RE[cu][i], ind);
	}
	void scc() {
		int c = 0; SC.clear(); SC.resize(MV); NUM.clear();
		ZERO(vis); for (int i = 0; i<NV; i++) if (!vis[i]) dfs(i);
		ZERO(vis); for (int i = NUM.size() - 1; i >= 0; i--) if (!vis[NUM[i]]) {
			SC[c].clear(); revdfs(NUM[i], c); sort(SC[c].begin(), SC[c].end()); c++;
		}
		SC.resize(c);
	}
};

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

	int VN, EN; cin >> VN >> EN;
	SCC<10101> scc;
	scc.init(VN);
	rep(i, 0, EN)
	{
		int s, t; cin >> s >> t;
		scc.add_edge(s, t);
	}
	scc.scc();

	int Q; cin >> Q;
	rep(i, 0, Q)
	{
		int u, v; cin >> u >> v;
		if (scc.GR[u] == scc.GR[v])
			printf("1\n");
		else
			printf("0\n");
	}
}

Measured memory_bytes: 4804
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;
 
#define INF (INT32_MAX)
//#define MOD (1000000000+7)
#define MAX 9
 
int N, M;
int A[MAX];
 
int num[9] = { 2, 5, 5, 4, 5, 6, 3, 7, 6 };


int main() {
	cin >> N >> M;
	int dp[N+1];

	//A[]に数字を格納していく
	for( int i = 0; i < M; i++ ) {
		cin >> A[i];
	}
 	
 	//dpのN個の配列要素に-INFを代入
	for( int i = 0; i <= N; i++ ) {
		dp[i] = -INF;
	}
	dp[0] = 0;
	for( int i = 1; i <= N; i++ ) {
		for( int j = 0; j < M; j++ ) {
			int a = A[j] - 1; 
			int n = num[a];
			if( i - n >= 0 ) {
				dp[i] = max( dp[i], dp[i - n] + 1 );
			}
		}
	}
	int d = dp[N];
	sort( A, A + M, greater<int>() );
	string ans;
	for( int i = 0; i < d; i++ ) {
		for( int j = 0; j < M; j++ ) {
			int a = A[j] - 1;
			int n = num[a];
			if( N - n >= 0 && dp[N - n] == dp[N] - 1 ) {
				ans += (char)(A[j] + '0');
				N -= n;
				break;
			}
		}
	}
 
	cout << ans << endl;
 
	return 0;
}


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

using namespace std;

#define vec vector
#define ALL(x) (x).begin(), (x).end()

typedef unsigned int ui;
typedef long long ll;
typedef long double ld;
typedef pair< int, int > pii;
typedef pair< long long, long long > pll;

const int inf = 1e9;
const ll inf64 = 1e18;

int main() {

#ifdef debug
    freopen("input.txt", "r", stdin);
#endif

    int n, m;

    cin >> n >> m;

    ll res = 0;

    if(n == 1) {
        if(m == 1) {
            res++;
        }else {
            res += m - 2;
        }
    }else {
        if(m == 1) {
            res += n - 2;
        }else {
            res += 1ll * (n - 2) * (m - 2);
        }
    }

    cout << res << "\n";

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lln long long int
#define llu unsigned lln
#define sc(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define scd(n) scanf("%lf",&n);
#define pf(res) printf("%d\n",res);
#define pfl(res) printf("%lld\n",res);
#define pfd(res) printf("%lf\n",res);
#define pb(n) push_back(n);
#define maxii 100005
using namespace std;
typedef pair<int,int> pii;
typedef pair<lln,lln> pll;
vector<int> vi;
vector<lln> vl;
vector<vector<pair<int, int> > > vii;
//vector<pii> vii;
vector<pll> vll;
//vii.clear();
//vii.resize(n + 1);


int arr[maxii];
int arr2[maxii];
bool check[maxii];
bool check2[1000][1000];
int n,m;
int x[]={1,-1,0,0};
int y[]={0,0,-1,1};
int x2[]={1,-1,0,0,1,-1,1,-1};
int y2[]={0,0,-1,1,1,-1,-1,1};
int bx[]={0,0,1,-1,-1,1,1,-1};
int by[]={1,-1,0,0,-1,-1,1,1};
int kx[] = {1,1,2,2,-1,-1,-2,-2};
int ky[] = {2,-2,1,-1,2,-2,1,-1};

bool isvisited(int xx,int yy)
{
    if(xx<1 || yy<1 || xx>n ||yy>m)
    {
        return false;
    }
    else if(check2[xx][yy]==true)
    {
        return false;
    }
    else return true;
}
int gcd(int a,int b)
{
    if(b==0){
      return a;
     }
    return gcd(b,a%b);
}
int lcm(int a,int b)
{
    int res=(a*b)/gcd(a,b);
    return res;
}
int po(int a,int b)
{
    int res=1;
    while(b)
    {
        if(b%2!=0)
        {
            res*=a;
            b--;
        }
        else
        {
            a*=a;
            b/=2;
        }
    }
    return res;
}

lln modMul(lln  a, lln b,lln mod){
    lln ans = 0;
    a = a % mod;
    while (b > 0){
        if ( b % 2 )ans = (ans%mod+ a%mod) % mod;
        a = (a%mod * 2%mod) % mod;
        b /= 2;
    }
    return ans % mod;
}
lln powerMod(lln a,lln b,lln mod){
	if(b==0)return 1LL%mod;
	lln x=powerMod( a,b/2,mod );
	x = ( x%mod * x%mod ) % mod;
	if( b%2==1 )x = ( x%mod * a%mod ) % mod;
	return x%mod;
}

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n;
    sc(n)
    for(int i=0;i<n;i++)
    {
        cout<<"ACL";
    }


}






Measured memory_bytes: 3640
import math
def C(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n, a, b = map(int, input().split())
l = sorted(list(map(int, input().split())), reverse=True)
print(sum(l[:a])/a)
if l.count(l[a-1]) > 1:
    ans = 0
    x = l[a-1]
    y = l[:a].count(x)
    z = l.count(x)
    if l[0] != x:
        print(C(z, y))
    else:
        ans = 0
        for i in range(a, min(b, z)+1):
            ans += C(z, i)
        print(ans)
else:
    print(1)

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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

int euclid(int a, int b)
{
    if (a < b)
        euclid(b, a);
    if (b == 0)
        return a;
    int r;
    while ((r = a % b))
    {
        a = b;
        b = r;
    }
    return b;
}

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    int n;
    int a[100];
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];

    sort(a, a + n, greater<int>());

    int suma = 0, sumb = 0;
    for (int i = 0; i < n; i++)
    {
        if (i % 2 == 0)
            suma += a[i];
        else
        {
            sumb += a[i];
        }
    }
    cout << suma - sumb << endl;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var N int
	fmt.Scan(&N)
	V := make([]int, N)
	for i := range V {
		fmt.Scan(&V[i])
	}
	sort.Ints(V)

	ans := float64(V[0]+V[1]) / 2
	for i := 2; i < N; i++ {
		ans = (ans + float64(V[i])) / 2
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
l,r = map(int,input().split())
a = l % 2019
b = r % 2019
ans = 2019
if l // 2019 == r // 2019:
    for i in range(a,b):
        for j in range(i+1,b+1):
            ans = min(ans,i*j%2019)
    print(ans)
else:
    print(0)

Measured memory_bytes: 41324
#include <bits/stdc++.h>
using namespace std;
int main() {
    string n;
    cin >> n;
    int s = 0;
    for (int i = 0; i < n.length(); i++)
        s = s + n[i] - 48;
    if (s % 9 == 0) cout << "Yes";
    else cout << "No";
}

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

#define int long long
#define pb push_back
#define ff first
#define ss second

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int j;
    int x[5];
    for(int i=0;i<5;i++)
    {
        cin>>x[i];
        if(x[i]==0)
        {
            j=i;
        }
    }
    cout<<j+1;
}

Measured memory_bytes: 3596
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


def neg_pos(neg: list, pos: list):
    cur = neg[0]
    path = []
    for posi in pos[1:]:
        path.append((cur, posi))
        cur -= posi

    neg[0] = cur
    cur = pos[0]

    for negi in neg:
        path.append((cur, negi))
        cur -= negi

    print(cur)
    for pathi in path:
        print(*pathi)

    return


def neg_only(neg: list):
    cur = neg[0]
    path = []
    for negi in neg[1:]:
        path.append((cur, negi))
        cur -= negi

    print(cur)
    for pathi in path:
        print(*pathi)

    return

def pos_only(pos: list):
    cur = pos[0]
    path = []
    for posi in pos[1:-1]:
        path.append((cur, posi))
        cur -= posi

    path.append((pos[-1], cur))
    cur = pos[-1] - cur

    print(cur)
    for pathi in path:
        print(*pathi)

    return


n = ni()
a = list(li())

neg = []
pos = []

for ai in a:
    if ai < 0:
        neg.append(ai)
    else:
        pos.append(ai)

neg.sort(reverse=True)
pos.sort()


if len(neg) == 0:
    pos_only(pos)

elif len(pos) == 0:
    neg_only(neg)

else:
    neg_pos(neg, pos)


Measured memory_bytes: 20944
n,m,q=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(q)]
ans=0
for i1 in range(1,m+1):
  for i2 in range(i1,m+1):
    for i3 in range(i2,m+1):
      for i4 in range(i3,m+1):
        for i5 in range(i4,m+1):
          for i6 in range(i5,m+1):
            for i7 in range(i6,m+1):
              for i8 in range(i7,m+1):
                for i9 in range(i8,m+1):
                  for i10 in range(i9,m+1):
                    tmp=0
                    arrs=[0,i1,i2,i3,i4,i5,i6,i7,i8,i9,i10]
                    for a,b,c,d in arr:
                      if arrs[b]-arrs[a]==c:
                        tmp+=d
                    ans=max(ans,tmp)
print(ans)

Measured memory_bytes: 9252
from collections import deque


def main():
    H, W = map(int, input().split())
    Ch, Cw = map(int, input().split())
    Dh, Dw = map(int, input().split())
    S = [list(input()) for _ in range(H)]
    d = [[-1 for _ in range(W)] for _ in range(H)]

    q = deque([])
    q.appendleft((0, Ch - 1, Cw - 1))

    while len(q):
        worp_count, x, y = q.popleft()

        if d[x][y] != -1:
            continue
        d[x][y] = worp_count

        for i, j in ((a, b) for a in range(-2, 3) for b in range(-2, 3)):
            nx = x + i
            ny = y + j
            if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == '.':
                if i == 0 and j == 0:
                    continue
                elif abs(i) + abs(j) == 1:
                    q.appendleft((worp_count, nx, ny))
                else:
                    q.append((worp_count + 1, nx, ny))

    print(d[Dh - 1][Dw - 1])


if __name__ == "__main__":
    main()


Measured memory_bytes: 243912
#include <bits/stdc++.h>
#define repq(i,a,n) for(int i=a; i<=n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
long long dp[20][1010];
int main() {
    int n, s;
    memset(dp, 0, sizeof(dp)); dp[0][0] = 1;
    repq(i,1,100) repr(j,15,0) repq(k,0,1000) {
        if(k - i < 0) continue;
        if(j != 0) dp[j][k] += dp[j-1][k-i];
    }
    while(std::cin >> n >> s, n || s)
        std::cout << dp[n][s] + dp[n-1][s] << std::endl;
    return 0;
}

Measured memory_bytes: 3244
from itertools import permutations
from math import sqrt, pow, factorial
 
# 座標 a から b の距離を求める
def calc(a, b):
    x1, y1 = a
    x2, y2 = b
    return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2))
 
 
n = int(input())
xy = []
for i in range(n):
    xy.append(list(map(int, input().split())))
 
ans = 0
for order in permutations(range(n)):
    tmp = 0
    for i in range(1, n):
        tmp += calc(xy[order[i]], xy[order[i - 1]])
    ans += tmp
ans /= factorial(n)
 
print(ans)

Measured memory_bytes: 41168
import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = (n%1000);
		if(a!=0)
			a=1000-a;
//		String s = sc.next();
//		int arr[] = new int[n];
//		for(int i=0;i<n;i++) {
//			arr[i] = sc.nextInt();
//		}
		System.out.println(a);
		sc.close();

	}
}


Measured memory_bytes: 35704
#include<stdio.h>
#include<string.h>
 
int w, h, xs, ys, xg, yg, board[105][105], start_color;
 
int dfs(int x, int y){
  int i;
  if(board[x][y] != start_color)return 0;
  if(x == xg && y == yg)return 1;
  board[x][y] = 0;
  int xi[] = {0, 1, 0, -1}, yi[] = {1, 0, -1, 0};
  for(i = 0;i < 4;i++)
    if(dfs(x + xi[i], y + yi[i]))
      return 1;
 
  return 0;
}
 
int main(){
  int n, c, d, x, y, i, j;
  while(1){
    memset(board, 0, sizeof(board));
    scanf("%d%d", &w, &h);
    if(w == 0 && h == 0)return 0;
    scanf("%d%d", &xs, &ys);
    scanf("%d%d", &xg, &yg);
    scanf("%d", &n);
    while(n--){
      scanf("%d%d%d%d", &c, &d, &x, &y);
      if(d == 1){
    for(i = x;i < x + 2;i++)
      for(j = y;j < y + 4;j++)
        board[i][j] = c;
      }
      if(d == 0){
    for(i = x;i < x + 4;i++)
      for(j = y;j < y + 2;j++)
        board[i][j] = c;
      }
    }
    start_color = board[xs][ys];
    if(start_color != 0 && dfs(xs, ys))
      puts("OK");
    else
      puts("NG");
  }
}

Measured memory_bytes: 636
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);
//cin.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll beki(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k%2==1){
            ret*=now;
            ret%=mod;
        }
        now*=now;
        now%=mod;
        k/=2;
    }
    return ret;
}
ll gyaku(ll n){
    return beki(n,mod-2);
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;cin>>n;
    ll a,b,c,d;cin>>a>>b>>c>>d;
    ll dp[n+1][n+1];
    rep(i,0,n+1)rep(j,0,n+1)dp[i][j]=0;
    dp[a-1][0]=1;
    ll nck[1001][1001];
    rep(i,0,1001)nck[i][0]=1;
    rep(i,0,1001)nck[i][i]=1;
  ll gya[1001];
  rep(i,1,1001)gya[i]=gyaku(i);
    rep(i,1,1001){
        rep(j,1,i){
            nck[i][j]=nck[i-1][j-1]+nck[i-1][j];
            nck[i][j]%=mod;
        }
    }
    rep(i,a-1,b){
        int t=0;
        rep(j,0,n+1){
            dp[i+1][j]+=dp[i][j];
            dp[i+1][j]%=mod;
            if(t==1)continue;
            ll sum=1;
            ll now=n-j;
            rep(k,0,c){
                if(now<0){
                    sum=-1;
                    break;
                }
                sum*=nck[now][i+1];
                sum%=mod;
                sum*=gya[k+1];
                sum%=mod;
                now-=i+1;
                
            }
            if(sum==-1){
                t=1;
                continue;
            }
            rep(k,c,d+1){
                if(j+(i+1)*k>n)break;
                dp[i+1][j+(i+1)*k]+=dp[i][j]*sum;
                dp[i+1][j+(i+1)*k]%=mod;
                sum*=nck[n-(j+(i+1)*k)][i+1];
                sum%=mod;
                sum*=gya[k+1];
                sum%=mod;
            }
            
        }
    }
    cout<<dp[b][n]<<endl;
    
}



Measured memory_bytes: 15872
TB = [63, 6, 91, 79, 102, 109, 125, 39, 127, 111]

def to_radix(k, v)
  return [] if v == 0
  [v % k] + to_radix(k, v / k)
end

def solve(from, to)
  val = (from == -1 ? TB[to] : (TB[from] ^ TB[to])) + 128
  to_radix(2, val).map(&:to_s)[0..-2].reverse.join
end

loop do
  from = -1
  n = gets.to_i
  break if n == -1
  n.times do
    to = gets.to_i
    puts solve(from, to)
    from = to
  end  
end

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

int main(){
    int n;
    while(cin >> n && n > 0){
        bool left = false , right = false, f = false;
        int cnt = 0;
        for(int i = 0; i < n; i++){
            string s;
            cin >> s;
            if(s == "lu") left = true;
            if(s == "ru") right = true;
            if(s == "ld") left = false;
            if(s == "rd") right = false;
            if(f == false && right == true && left == true){
                cnt++;
                f = true;
            }
            else if(f == true && right == false && left == false){
                cnt++;
                f = false;
            }
        }
        cout << cnt << endl;
    }
    return 0;
}




Measured memory_bytes: 3128
#include<stdio.h>

int main()
{
	int N,A[111],min=1000000000,max=-1,i;
	scanf("%d",&N);
	
	for(i=0; i<N; i++){
		scanf("%d",&A[i]);
		if(max<A[i])
			max=A[i];
		
		if(min>A[i])
			min=A[i];
	}
	
	printf("%d\n",max-min);
	return 0;
}

Measured memory_bytes: 128
#include"iostream"
#include"cmath"
#include"vector"
#include"algorithm"
#include"list"
#include"set"
#include"unordered_set"
#include"map"
#include"unordered_map"
#include"queue"
#include"string"
#include"cstring"
#include"iomanip"
using namespace std;
typedef long long ll;
const int maxn=3*(1e5)+10;
ll num[maxn];
ll ans1[maxn/3],ans2[maxn/3];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    priority_queue<ll,vector<ll>,greater<ll> > rec;
    int n;cin>>n;
    for(int i=1;i<=3*n;++i)
        cin>>num[i];
    ll sum1=0;
    for(int i=1;i<=n;++i)
    {
        rec.emplace(num[i]);
        sum1+=num[i];
    }
    ans1[0]=sum1;
    for(int i=n+1;i<=2*n;++i)
    {
        ll temp=rec.top();
        if(num[i]>temp)
        {
            rec.pop();rec.emplace(num[i]);
            sum1+=num[i]-temp;
        }
        ans1[i-n]=sum1;
    }
    ll sum2=0;
    priority_queue<ll>rig;
    for(int i=3*n;i>2*n;--i)
    {
        rig.emplace(num[i]);
        sum2+=num[i];
    }
    ans2[n]=sum2;
    for(int i=2*n;i>n;--i)
    {
        ll temp=rig.top();
        if(num[i]<temp)
        {
            rig.pop();rig.emplace(num[i]);
            sum2+=num[i]-temp;
        }
        ans2[i-n-1]=sum2;
    }
    ll m=- 1e18;
    for(int i=0;i<=n;++i)
    {
        m=max(m,ans1[i]-ans2[i]);
    }
    cout<<m<<'\n';
}


Measured memory_bytes: 5876
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
	int a, b;
	cin >> a >> b;

	if (b < a)
	{
		cout << a - 1 << endl;
	}
	else
	{
		cout << a << endl;
	}

	return 0;
}

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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int count = 0;
    while(a % 2 == 0 && b % 2 == 0 && c % 2 == 0){
        int aa, bb, cc;
        aa = a;
        bb = b;
        cc = c;
        a = bb / 2 + cc / 2;
        b = aa / 2 + cc / 2;
        c = aa / 2 + bb / 2;
        count++;
        if(count > 1e8){
            count = -1;
          	a = 1;
            break;
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<string>
#include<cctype>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
        for(;;){
                int m,f,r;
                scanf("%d %d %d",&m,&f,&r);
                if(m+f+r==-3){
                        break;
                }else{
                        if(m==-1 || f==-1 || m+f<30){
                                printf("F\n");
                        }else if(m+f>=80){
                                printf("A\n");
                        }else if(m+f>=65){
                                printf("B\n");
                        }else if(m+f>=50 || r>=50){
                                printf("C\n");
                        }else{
                                printf("D\n");
                        }
                }
        }
        return 0;
}

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

int main()
{
	vector<int> range;
	for (int i = 0; i < 5; i++)
	{
		int a;
		cin >> a;
		range.push_back(a);
	}

	int k = 0;
	cin >> k;
	int min = *std::min_element(range.begin(), range.end());
	int max = *std::max_element(range.begin(), range.end());


	cout << (((max - min) <= k) ? "Yay!" : ":(") << "\n";

	return 0;
}

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

  int result = 0;
  void jad(double a[],int size);
int main(){
  int size = 0;

  scanf("%d",&size);
  double num[size];
  for (int i = 0;i<size;i++){
      scanf("%lf",&num[i]);
  }
  jad(num,size);
  printf("%d",(int)result);
  return 0;
}
void jad(double a[],int size){
  for (int i = 0; i < size; i++){
    if (fmod(a[i],2) != 0){
      return;
    }
  }
  for (int i = 0; i < size; i++){
    a[i] /= 2;
  }
  result++;
  jad(a,size);
}


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

int main() {
  int R;
  cin >> R;
  
  if (R < 1200){
    cout << "ABC" << endl;
  }
  else if (1200<= R && R < 2800){
    cout << "ARC" << endl;
  }
  else {
    cout << "AGC" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    long n;
    long SUM=0;
    long MAX,min;
    cin >> n;
    long A[10000];
    for(int i=0;i<n;i++){
        cin >> A[i];
    }
    
    MAX=A[0];
    min=A[0];
    
    for(int i=0;i<n;i++){
        if(MAX<A[i])MAX=A[i];
    }
    
    for(int i=0;i<n;i++){
        if(min>A[i])min=A[i];
    }
    
    for(int i=0;i<n;i++){
        SUM = SUM+A[i];
    }
    
    cout << min << " " << MAX << " " << SUM << endl;
}


Measured memory_bytes: 3168
#include<stdio.h>
#include<math.h>
#define PI acos(-1.0)

int main()
{
    int A, B, H, M;
    double deg1, deg2, deg, dist;

    scanf("%d %d %d %d", &A, &B, &H, &M);

    deg1 = 30*(double)H + 0.5*(double)M;
    deg2 = 30*(double)M/5;
    deg = deg1 - deg2;
    deg = PI/180 * deg;

    dist = sqrt((double)A*(double)A + (double)B*(double)B - cos(deg)*2*(double)A*(double)B);

    printf("%.20lf", dist);
    return 0;
}


Measured memory_bytes: 2496
#include <bits/stdc++.h>
#include <cstdlib>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;
const int MOD = 1000000007;

long long mod(long long val, long long m) {
  long long res = val % m;
  if (res < 0) res += m;
  return res;
}

bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

int main() {
  ll N,cnt=0,d1,d2;
  cin >> N;
  string ans="No";
  
  rep(i,N) {
    cin >> d1 >> d2;
    if(d1==d2) {
      cnt++;
      if(cnt==3) ans="Yes";
    }
    else cnt=0;
  }
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3612
#include<iostream>
using namespace std;
int main(){
	int M,N,count=0;
	char seat[101][103]={},seat2[101][103]={};
	cin>>M>>N;
	for(int y=0;y<M;y++){
		cin >> seat[y];
		for(int x=1;x<=N;x++){
			seat2[y][x]=seat[y][x-1];
		}
	}
	for(int x=0;x<N;x++){
		if(seat[0][x]=='x'){
				for(int i=0;i<=1;i++){
					for(int j=x;j<=x+2;j++){
						seat2[i][j]='a';
					}
				}
			}
	}
	for(int y=1;y<M;y++){
		for(int x=0;x<N;x++){
			if(seat[y][x]=='x'){
				for(int i=y-1;i<=y+1;i++){
					for(int j=x;j<=x+2;j++){
						seat2[i][j]='a';
					}
				}
			}
			if(seat[y][x]=='o'){
				for(int j=x;j<=x+2;j++){
					seat2[y][j]='a';
				}
			}
		}
	}
		for(int y=1;y<M;y++){
		for(int x=1;x<=N;x++){
			if(seat2[y][x]=='-')	count++;
		}
	}
	cout<<count<<"\n";
	return 0;
}

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

using namespace std;
int ax[100015];
int n;

int main()
{
    scanf("%d",&n);
    int i,a;
    for(i=1;i<=n;i++){
        scanf("%d",&ax[i]);
    }
    int res=0;
    for(i=1;i<=n;i++){
        if(ax[i]==i){
            res++;
            i++;
        }
    }
    printf("%d",res);
    return 0;
}


Measured memory_bytes: 640
A, B, C, D = map(int, input().split())
imos = [0 for i in range(102)]
imos[A] += 1
imos[B] -= 1
imos[C] += 1
imos[D] -= 1
for i in range(1, 101):
    imos[i] += imos[i - 1]
cnt = 0
for i in range(101):
    if imos[i] == 2:
        cnt += 1
print(cnt)



Measured memory_bytes: 3060
#include <iostream>
#include <vector>

int main(){
    int n, l;
    std::cin >> n >> l;

    int sum = 0;
    for(int i = 0; i < n; ++i){
        sum += l + i;
    }

    int buf;
    if(l <= 0 && 0 <= l + n - 1){
        buf = 0;
    }else if(l + n - 1 < 0){
        buf = l + n - 1;
    }else if(0 < l){
        buf = l;
    }

    std::cout << sum - buf << std::endl;

    return 0;
}


Measured memory_bytes: 888
N,A,B=map(int,input().split())

c=A+B

b=0

if int(N/c)>0:
  b=(int(N/c)*A)
  if N%c>A:
    b+=A
  else:
    b+=N%c
else:
  if N<A:
    b=N
  else:
    b=A

print(b)


Measured memory_bytes: 38384
package main

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

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

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

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func main() {
	sc := NewScanner()
	N, M := sc.nextInt(), sc.nextInt()
	S := make([][]bool, M)
	for i := 0; i < M; i++ {
		s := make([]bool, N)
		k := sc.nextInt()
		for j := 0; j < k; j++ {
			s[sc.nextInt()-1] = true
		}
		S[i] = s
	}
	P := sc.nextIntSlice(M)
	ans := 0
	for bit := 0; bit < 1<<uint(N); bit++ {
		switches := make([]bool, N)
		for i := 0; i < N; i++ {
			if 1<<uint(i)&bit > 0 {
				switches[i] = true
			}
		}
		ok := true
		for i, s := range S {
			onCount := 0
			for j, v := range s {
				if v && switches[j] {
					onCount++
				}
			}
			if onCount%2 != P[i] {
				ok = false
			}
		}
		if ok {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,h;
    cin>>n;
    cin>>h;
    int minh=h-1;
    bool ans=true;
    for(int i=1;i<n;i++){
        cin>>h;
        if(minh>h){
            ans=false;
            break;
        }else{
            minh=max(minh,h-1);
        }
    }
    if(ans)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
using namespace std;

int main(){
	int n;
	while(scanf("%d", &n),n){
		vector<int> h(n+1);
		vector<int>::iterator it;
		for(int i = 0; i < n+1; i++) scanf("%d", &h[i]);
		for(int i = 0; i < n+1; i++){
			vector<int> tmp;
			tmp = h;
			it = tmp.erase(tmp.begin()+i);
			int dif = tmp[1]-tmp[0];
			bool ok = true;
			for(int j = 1; j < n; j++){
				if(tmp[j]-tmp[j-1]!=dif){
					ok = false;
					break;
				}
			}
			if(ok){
				printf("%d\n", h[i]);
				break;
			}
		}
	}
}

Measured memory_bytes: 1056
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<cassert>
#include<queue>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	sort(A.begin(), A.end());
	cout << A[N-1] - A[0] << endl;
	return 0;
}


Measured memory_bytes: 256
//
// ABC163A
// URL : https://atcoder.jp/contests/abc162/tasks/abc163_a
// 
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;

namespace AtCoder
{
    class ABC163A
    {
        static void Main(string[] args)
        {
            preprocess();


            // 整数の入力
            long r = long.Parse(Console.ReadLine());

            var ans = r * 2.0 * Math.PI;

            Console.WriteLine(ans.ToString());
            Console.Out.Flush();
        }

        //---------------------------------------------------------------------------------
        /// <summary>
        /// 
        /// </summary>
        public static void preprocess()
        {
            //出力高速化
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
        }


        /// <summary>
        /// 与えられた数が素数かどうかを計算する
        /// </summary>
        /// <param name="num">対象数</param>
        /// <returns>true:素数, false:素数ではない(合成数)</returns>
        public static bool isPrime(int num)
        {
            if (num < 2) return false;
            else if (num == 2) return true;
            else if (num % 2 == 0) return false;

            double sqrtNum = Math.Sqrt(num);
            for (int i = 3; i <= sqrtNum; i += 2)
            {
                if (num % i == 0)
                {
                    return false;
                }
            }
            return true;
        }

        /// <summary>
        /// 順列mPnを計算する
        /// </summary>
        /// <param name="m"></param>
        /// <param name="n"></param>
        /// <returns></returns>
        public static long Permutation(long m, long n)
        {
            long ret = 1;
            for(var i = 0; i < n; ++i)
            {
                ret *= m - i;
            }
            return ret;
        }
        /// <summary>
        /// 組み合わせmCnを計算する
        /// </summary>
        /// <param name="m"></param>
        /// <param name="n"></param>
        /// <returns></returns>
        public static long Combination(long m, long n)
        {
            if(m == n || n == 0)
            {
                return 1;
            }
            long ans = 1;
            for(var i = 0; i <= n; ++i)
            {
                ans *= (m - i + 1) / i;
            }
            return ans;
        }

        static long Gcd(long m, long n)
        {
            if (n == 0) return m;
            return Gcd(n, m % n);
        }

        static long Lcm(long m, long n)
        {
            var gcd = Gcd(m, n);
            //return (m * n) / gcd;
            return m / gcd * n;//桁あふれ対策
        }
    }
}



Measured memory_bytes: 27596
//#include "stdafx.h"
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <functional>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define	BitSetV(Val,Bit)		((Val) |= (Bit))			
#define	BitTstV(Val,Bit)		((Val) & (Bit))				
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define MAX_DWORD				(0xFFFFFFFF)
#define	MAX_SDWORD				((SDWORD)0x7FFFFFFF)
#define	MIN_SDWORD				((SDWORD)0x80000000)
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define	MIN_QWORD				((QWORD)0x0000000000000000)
#define	MAX_SQWORD				((SQWORD)0x7FFFFFFFFFFFFFFF)
#define	MIN_SQWORD				((SQWORD)0x8000000000000000)
#define M_PI					3.14159265358979323846

typedef long					SDWORD;
typedef long long				SQWORD;
typedef unsigned long			DWORD;
typedef unsigned long long int	QWORD;
typedef long long ll;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
#define N_MAX	(200 * 1000)
#define K_MAX	(10)
#define M_MAX	(10)
#define Q_MAX	(10)
#define H_MAX	(1000)
#define W_MAX	(1000)

int main()
{
	int H, W;
	int h, w;
	cin >> H >> W >> h >> w;

	cout << (H - h) * (W - w) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	unsigned long long N, A, B;
	unsigned long long min_v, max_v;
	unsigned long long ans = 0;
	cin >> N >> A >> B;

	if (N == 1)
	{
		if (A == B)
			ans = 1;
	}
	else if (A <= B)
	{
		if (N == 2)
			ans = 1;
		else
		{
			min_v = A * (N - 1) + B;
			max_v = A + B * (N - 1);

			ans = max_v - min_v + 1;
		}
	}
	
	cout << ans << endl;

	return 0;
}


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

int main()
{
    int n, k;
    cin >> n >> k;
    long int cnt = 0;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    sort(h.rbegin(), h.rend());
    for (int i = k; i < n; i++)
        cnt += h[i];
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()

int N;

int main() {
  cin >> N;

  int ans = 0;
  char g = '0';
  rep(i, N) {
    char c;
    cin >> c;
    if (c != g) {
      ans++;
      g = c;
    }
  }

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


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <functional>
#include <set>
#include <numeric>
#include <stack>
#include <utility>
#include <time.h>
#include <iterator>
//#include "util.h"

using namespace std;
typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;

//呪文
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { cout << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { cout << "{ }"; return ostr; } cout << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { cout << ", " << *itr; } cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { cout << "{ }"; return ostr; }	cout << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { cout << "{ }"; return ostr; } cout << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _KTy, typename _Ty> istream& operator >> (istream& istr, pair<_KTy, _Ty>& m) { cin >> m.first >> m.second; return istr; }
template <typename _Ty> istream& operator >> (istream& istr, vector<_Ty>& v) { for (size_t i = 0; i < v.size(); i++) cin >> v[i]; return istr; }
ll modpow(ll n, ll p, ll m) { ll result = 1; while (p > 0) { if (p & 1) result = (result * n) % m; p >>= 1; n = (n * n) % m; } return result; }
#define PI 3.14159265358979323846
#define EPS 1e-8
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(), (x).end()
#define fake false



int main() {
	int N;
	cin >> N;
	vint button(N + 1, 0);
	for (int i = 1; i <= N; i++) cin >> button[i];
	
	vector<bool> pushed(N + 1, false);
	int cnt = 0;
	int pos = 1;
	while (true) {
		//push
		cnt++;
		if (pushed[pos]) {
			cnt = -1;
			break;
		}
		pushed[pos] = true;
		pos = button[pos];
		if (pos == 2) break;
	}
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <algorithm>
#include <vector>
#include <tuple>
#include <map>
using namespace std;
using P=pair<int,int>;
int main(){
    int N,M;
    cin>>N>>M;
    int m[10]={10,2,5,5,4,5,6,3,7,6};
    int b[10]={};
    map<int,int> Mp;
    for(int i=0;i<M;i++){
        int A;
        cin>>A;
        b[A]=1;
        Mp[m[A]]=max(Mp[m[A]],A);
    }
    int best[50]={};
    for(int i=1;i<1000000;i++){
        int n=i;
        int sum=0;
        bool flag=true;
        while(n){
            if(b[n%10]){
                sum+=m[n%10];
                n/=10;
            }else{
                flag=false;
                break;
            }
        }
        if(flag) best[sum]=max(best[sum],i);
    }
    vector<P> V;
    for(auto p:Mp) V.push_back(p);
    int len=N/V[0].first;
    N-=len*V[0].first;
    if(N){
        N+=min(len,6)*V[0].first;
        len-=min(len,6);
        string s1=to_string(best[N]);
        string s2=string(len,'0'+V[0].second);
        string pre,suf;
        for(auto c:s1){
            if(c>('0'+V[0].second)){
                pre+=c;
            }else{
                suf+=c;
            }
        }
        cout<<pre<<s2<<suf<<endl;
        return 0;
    }else{
        cout<<string(len,'0'+V[0].second)<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 1e3 + 5;
int p[maxn];
int main()
{
	ios::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
	{
		cin >> p[i];
	}
	sort(p + 1, p + n + 1);
	int ans = 0;
	for (int i = 1; i <= k; i++)
		ans += p[i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<cctype>
#include<cstdio>
using namespace std;

int main() {
	char ch;
	while (1) {
		scanf("%c", &ch);
		if (ch == '\n') break;
		else if (islower(ch)) {
			ch = toupper(ch); cout << ch;
		}
		else if (isupper(ch)) {
			ch = tolower(ch); cout << ch;
		}
		else cout << ch;
		
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 3132