akhauriyash/Code-Regression huggingface dataset:
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n,k,*a = map(int,read().split())

pos = []
neg = []
#both = []
zero = 0

for i in a:
    #if i!=0: both.append(i)
    
    if i==0: zero += 1
    elif i > 0: pos.append(i)
    else: neg.append(-i)

#print(pos,neg,zero)
MOD = 10**9+7

if n - zero < k: # ゼロが多すぎる
    print(0)
elif pos == []: # 全部ゼロ以下
    if k%2==0:
        neg.sort(reverse=True)
        ans = 1
        for i in range(k):
            ans *= neg[i]
            ans %= MOD
        print(ans)
    else:
        if zero:
            print(0)
        else: # 負のみ
            neg.sort()
            ans = -1
            for i in range(k):
                ans *= neg[i]
                ans %= MOD
            print(ans%MOD)
            
else: #正もいる
    pos.sort(reverse=True)
    neg.sort(reverse=True)
    cp = len(pos)
    cn = len(neg)
    
    i = j = 0    
    for _ in range(k):
        if i == cp:
            j += 1
        elif j == cn:
            i += 1
        else:
            if pos[i] > neg[j]:
                i += 1
            else:
                j += 1
    
    #print(cp,cn,i,j)
    if j%2 == 0:
        ans = 1
        for x in pos[:i]:
            ans *= x
            ans %= MOD
        for x in neg[:j]:
            ans *= x
            ans %= MOD
        print(ans)
            
    else:
        can_i = i and j < cn
        can_j = j and i < cp
        if not can_i and not can_j:
            if zero: print(0)
            else:
                ans = -1
                for x in pos[:i]:
                    ans *= x
                    ans %= MOD
                for x in neg[:j]:
                    ans *= x
                    ans %= MOD
                print(ans)
            exit()
                
                
        if not can_i:
            j -= 1
            i += 1
        elif not can_j:
            j += 1
            i -= 1
        else:
            if pos[i]*pos[i-1] >= neg[j]*neg[j-1]:
                j -= 1
                i += 1
            else:
                j += 1
                i -= 1

        ans = 1                
        for x in pos[:i]:
            ans *= x
            ans %= MOD
        for x in neg[:j]:
            ans *= x
            ans %= MOD
        print(ans)
            
            
            






Measured memory_bytes: 31108
#include<bits/stdc++.h>
#define endl '\n'
#define ll long long
using namespace std;
const ll MAX_N = 2e5 + 2;
const ll MOD = 998244353;
ll fact[MAX_N];
ll fast_pow(ll num,ll st)
{
    if(st == 0) return 1;
    ll tmp = fast_pow(num,st/2)%MOD;
    tmp*=tmp;
    tmp%=MOD;
    return (tmp*(st%2==1 ? num:1)%MOD);
}
void precalc()
{
    fact[0] = 1;
    fact[1] = 1;
    for(ll i=2;i<MAX_N;i++)
    {
        fact[i] = (fact[i-1]*i)%MOD;
    }
}
ll comb(ll a, ll b)
{
    ll tmp = fact[a];
    tmp*=fast_pow(fact[b],MOD-2);
    tmp%=MOD;
    tmp*=fast_pow(fact[a-b],MOD-2);
    tmp%=MOD;
    return tmp;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,m,k;
    ll ans = 0;
    cin>>n>>m>>k;
    precalc();
    for(ll i=0; i<=k; i++)
    {
        ll tmp = comb(n-1,i);
        tmp%=MOD;
        tmp *= m;
        tmp%=MOD;
        tmp *= fast_pow(m-1,n-1-i);
        tmp%=MOD;
        ans+=tmp;
        ans%=MOD;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 5208
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define pb(a) push_back(a)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int checkDataList(int data[105][105],bool fdn[105], int fd, int p){
    int sum = 0;
    for(int i = 0; data[p][i] != -1; i++){
        sum+=fdn[data[p][i]];
    }
    if(sum == fd) return 1;
    else return 0;
}

int main(){
    int n;
    while(cin >> n, n){
        int data[105][105];
        rep(i,105) rep(j,105) data[i][j] = -1;
        rep(i,n){
            int haveData;
            cin >> haveData;
            rep(j,haveData){
                cin >> data[i][j];
            }
        }
        int flowData;
        bool flowDataNumber[105] = {0};
        cin >> flowData;
        rep(i,flowData){
            int input;
            cin >> input;
            flowDataNumber[input] = 1;
        }
        int ansCheck[2] = {0};
        rep(i,n){
            int x = checkDataList(data, flowDataNumber, flowData, i);
            ansCheck[0]+=x;
            if(x) ansCheck[1] = i + 1;
        }
        if(ansCheck[0] == 1) cout << ansCheck[1] << endl;
        else cout << -1 << endl;
    }
}

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

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

  int cnt1=0,cnt2=0;
  for(char c:s){
    if(c=='a'){
      if(cnt1<a+b){
        puts("Yes");
        cnt1++;
      }
      else puts("No");
    }
    else if(c=='b'){
      if(cnt1<a+b && cnt2<b){
        puts("Yes");
        cnt1++;
      }
      else puts("No");
      cnt2++;
    }
    else puts("No");
  }

  return 0;
}


Measured memory_bytes: 896
#include<stdio.h>
int main()
{
	int b[30],n,m, a,c,sum,i,cnt;
	while(~scanf("%d %d %d", &n, &m, &c))
	{
		cnt=0;
		for(i=0; i<m; i++)
			scanf("%d", b+i);
		while(n--)
		{
			sum = c;
			for(i=0; i<m; i++)
			{
				scanf("%d", &a);
				sum += b[i]*a;
			}
			if(sum>0)
				cnt++;
		}
		printf("%d\n", cnt);
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
const int mod=1e9+7;

int main(){
  int N;
  cin>>N;
  vector<int>A(N+1),B(N);
  for(int i=0;i<N+1;i++){
    cin>>A[i];
  }
  for(int i=0;i<N;i++){
    cin>>B[i];
  }
  int64_t sum=0;
  for(int i=0;i<N;i++){
    if(A[i]<=B[i]){
      sum+=A[i];
      int sp=B[i]-A[i];
      A[i]=0;
      if(A[i+1]<=sp){
        sum+=A[i+1];
        A[i+1]=0;
      }
      else{
        A[i+1]-=sp;
        sum+=sp;
      }
    }
    else{
      sum+=B[i];
      A[i]-=B[i];
    }
  }
  cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 3956
#include <stdio.h>

int main(void) {

	int h, w, i, ii, a;
	
	scanf("%d%d", &h, &w);

	for (a = 0; a < 1 ; a--) {
		for (i = 0; i < h; i++) {
			for (ii = 0; ii < w; ii++) {
				if (((ii % 2 == 0) && (i % 2 == 0)) || ((ii % 2 == 1) && (i % 2 == 1))) {
					printf("#");
				} else {
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
		scanf("%d%d", &h, &w);
		if ((h == 0) && (w == 0)) {
			return 0;
		}
	}
}

Measured memory_bytes: 572
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;


struct xy{
  double  x,y;
};

void koch(int n,xy p1,xy p2){
  if(n==0)return ;
xy s,t,u;
  s.x=(2*p1.x+p2.x)/3;
  s.y=(2*p1.y+p2.y)/3;
  t.x=(p1.x+2*p2.x)/3;
  t.y=(p1.y+2*p2.y)/3;
  u.x=(t.x-s.x)/2-(t.y-s.y)*(sqrt(3.0)/2)+s.x;
  u.y=(t.x-s.x)*(sqrt(3.0)/2)+(t.y-s.y)/2+s.y;

  koch(n-1,p1,s);
  printf("%f %f\n",s.x,s.y);
  koch(n-1,s,u);
  printf("%f %f\n",u.x,u.y);
  koch(n-1,u,t);
  printf("%f %f\n",t.x,t.y);
  koch(n-1,t,p2);
}


int main(){
  int n;
  cin>>n;
  xy p1,p2;
  p1.x=0,p1.y=0;
  p2.x=100,p2.y=0;
  printf("%f %f\n",p1.x,p1.y);
  koch(n,p1,p2);
  printf("%f %f\n",p2.x,p2.y);
  return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
#define REP(i, d, n) for(int i=(d); i<(n); i++)
typedef long long ll;
const int mod = 1e9 + 7;
int main() {

    int n;
    cin >> n;

	cout << 48 - n << endl;

    return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long n = in.nextLong();
            long a = in.nextLong();
            long b = in.nextLong();
            long div = n / (a + b);
            long rest = n - div * (a + b);
            long ans = a * div + Math.min(rest, a);
            out.println(ans);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}



Measured memory_bytes: 22740
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
const ll INF = 1145141919;
const ll MOD = 1000000007;
const ll M = 1000000007;
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}



vector<ll> fac(3000001); //n!(mod M)
vector<ll> ifac(3000001); //k!^{M-2} (mod M)
//a,bの範囲的にこれだけ配列を用意していけば十分

ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}

ll solve(ll X, ll Y){
    if((X + Y) % 3)return 0;
    ll a = (2 * X - Y) / 3;
    ll b = X - 2 * a;
    if(a < 0 || b < 0)return 0;
    fac[0] = 1;
    ifac[0] = 1;
    for(ll i = 0; i<=a+b+10; i++){
        fac[i+1] = fac[i]*(i+1) % M; // n!(mod M)
        ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
    }
    return comb(a + b, a);
}

int main(){


    ll X, Y;
    cin >> X >> Y;
    cout << solve(X, Y) << endl;

    return 0;
}

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

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))

typedef long long ll;

int main(void)
{
	ll H, W;
	scanf("%lld %lld", &H, &W);
	char A[H][W];

	for (ll i = 0; i < H; i++)
	{
		scanf("%s", &A[i]);
	}
	ll dp[H][W];
	for (ll i = 0; i < H; i++)
	{
		for (ll j = 0; j < W; j++)
		{
			dp[i][j] = 2000;
		}
	}

	int tmp = 2000;

	for (ll i = 0; i < H; i++)
	{
		tmp = 2000;

		for (ll j = 0; j < W; j++)
		{
			if (A[i][j] == '#')
			{
				dp[i][j] = 0;
				tmp = 1;
			}
			else
			{
				dp[i][j] = MIN(dp[i][j], tmp);
				tmp++;
			}
		}
	}
	for (ll j = 0; j < W; j++)
	{
		for (ll i = 0; i < H; i++)
		{
			if (i == 0)
			{
				continue;
			}
			dp[i][j] = MIN(dp[i][j], dp[i - 1][j] + 1);
		}
	}
	for (ll i = H - 1; i >= 0; i--)
	{
		for (ll j = W - 1; j >= 0; j--)
		{
			if (j == W - 1)
			{
				continue;
			}
			dp[i][j] = MIN(dp[i][j], dp[i][j + 1] + 1);
		}
	}

	for (ll j = W - 1; j >= 0; j--)
	{
		for (ll i = H - 1; i >= 0; i--)
		{
			if (i == H - 1)
			{
				continue;
			}
			dp[i][j] = MIN(dp[i][j], dp[i + 1][j] + 1);
		}
	}

	ll ans = 0;

	for (ll i = 0; i < H; i++)
	{
		for (ll j = 0; j < W; j++)
		{
			ans = MAX(ans, dp[i][j]);
		}
	}
/*
	for(int i = 0; i < H; i++)
	{
	    for(int j = 0; j < W; j++)
		{
	        printf("\t%lld",dp[i][j]);
	    }
	    printf("\n");
	}
*/
	printf("%lld\n", ans);

	return 0;
}


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

namespace ABC085
{
    class B
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            int[] d = new int[N];
            for (int i = 0; i < N; i++)
            {
                d[i] = int.Parse(Console.ReadLine());
            }

            d = d.OrderByDescending(x => x).Distinct().ToArray();
            Console.WriteLine(d.Count());
        }
    }
}


Measured memory_bytes: 13396
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	string s;
	cin>>s;
	int sum=0;
	int ans=0;
	for(int i=0;i<3;i++){
		if(s[i]=='A')sum++;
		if(s[i]=='B')ans++;
	} 
	if(sum==3||ans==3){
		cout<<"No"<<endl;
	}else{
		cout<<"Yes"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<math.h>
#include <string>
#define cinf(n,x,y) for(int i=0;i<(n);i++) cin >> x[i] >> y[i];
typedef long long int ll;
using namespace std;
ll mod=1e9+7;
int main(){
 	ll n,h; cin >>n>>h;
 	vector<int> a(n),b(n);
 	cinf(n,a,b);
 	int Max=-1;
 	for(int i=0;i<n;i++){
 		Max=max(Max,a[i]);
 	}
 	int cnt=0;
 	sort(b.begin(),b.end());
 	reverse(b.begin(),b.end());
 	for(int i=0;i<n;i++){
 		if(h>0&&b[i]>Max){
 			h-=b[i];
 			cnt++;
 		}
 		else break;
 	}
 	if(h>0){
 		cnt+=(h+Max-1)/Max;
 	}
 	cout << cnt << endl;
 }

Measured memory_bytes: 1024
#include<iostream>

using namespace std;

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

    int a[100][100],b[100],c[100];

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

    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            c[i] += a[i][j] * b[j]; 
        }
    }

    for(int i=0;i<n;i++)
        cout<<c[i]<<'\n';

}


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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  int N; scanf("%d", &N);
  vector<pair<int, int> > X(N);
  for (int i = 0; i < N; ++i) {
    scanf("%d", &X[i].first);
    X[i].second = i;
  }
  sort(X.begin(), X.end());
  vector<int> ans(N);
  int center = N / 2;
  for (int i = 0; i < N; ++i) {
    pair<int, int> p = X[i];
    if (i < center) {
      ans[p.second] = X[center].first;
    }
    else {
      ans[p.second] = X[center - 1].first;
    }
  }
  for (int i = 0; i < N; ++i) {
    printf("%d\n", ans[i]);
  }
  return 0;
}


Measured memory_bytes: 4480
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	while(n)
	{
		if(n%10==7)
		{
			cout<<"Yes";
			return 0;
		}
		n/=10;
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 3540
import java.util.Arrays;
        import java.util.Scanner;
public class Main {
    public static void main(String[] a) {
        int highest[] = new int[10];
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < 10; i++) {
            highest[i] = sc.nextInt();
        }
        Arrays.sort(highest);

        for (int k = 9; k > 6; k--) System.out.println(highest[k]);
    }
}

Measured memory_bytes: 26312
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

immutable long BASE = 31;
immutable long MOD = 10^^9 + 9;
immutable long BASE_INV = powmod(BASE, MOD-2, MOD);

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto S = readln.chomp.map!(c => to!long(c - 'a') + 1).array;

    auto P = new long[](N+1);
    P[0] = 1;
    foreach (i; 0..N) P[i+1] = P[i] * BASE % MOD;

    auto D = new bool[long][](N+1);
    int l = 0;
    int r = 0;
    long ans = 0;
    long hash = S[0];

    while (M--) {
        auto Q = readln.chomp;
        if (Q == "L--") {
            l -= 1;
            hash = hash * BASE % MOD + S[l];
            hash %= MOD;
        } else if (Q == "L++") {
            hash = (hash - S[l]) % MOD;
            hash = hash * BASE_INV % MOD;
            hash = (hash + MOD) % MOD;
            l += 1;
        } else if (Q == "R--") {
            hash = (hash - S[r] * P[r - l] % MOD) % MOD;
            hash = (hash + MOD) % MOD;
            r -= 1;
        } else {
            r += 1;
            hash = (hash + S[r] * P[r - l] % MOD) % MOD;
            hash = (hash + MOD) % MOD;
        }
        if (hash !in D[r-l+1]) {
            D[r-l+1][hash] = true;
            ans += 1;
        }
    }

    ans.writeln;
}

long powmod(long a, long x, long m) {
    long ret = 1;
    while (x) {
        if (x % 2) ret = ret * a % m;
        a = a * a % m;
        x /= 2;
    }
    return ret;
}



Measured memory_bytes: 70276
import java.util.*

fun main(args: Array<String>) {
    val scan = Scanner(System.`in`)
        var (a,b,c,k) = scan.nextLine().split(" ").map{ it.trim().toInt() }.toTypedArray()
        var ans : Long= 0
        if(k<=a)
        {
            ans+=k
            k-=a
        }
         else if(k<=a+b)
        {
             ans+=a
             k-=a
         }
        else if(k<=a+b+c)
        {
            ans+=a
            var z = k-(a+b)
            ans-=z
        }
    println(ans)
}


Measured memory_bytes: 38312
let readIntArray () =
    stdin.ReadLine().Split(" ") |> Array.map int

let choice ok ng bool = if bool then ok else ng

stdin.ReadLine()

()
|> readIntArray
|> Array.sortDescending
|> fun x -> (x |> Array.head) < (x |> Array.tail |> Array.sum)
|> choice "Yes" "No"
|> printfn "%s"


Measured memory_bytes: 29704
#include <iostream>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)

int main() {
	int n, c[7] = {};
	double h;
	cin >> n;
	rep(i,n) {
		cin >> h;
		int a = h<165.0?0:(h-165.0)/5+1;
		c[a]++;
	}
	rep(i,6) {
		cout << i+1 << ":";
		rep(j,c[i]) {
			cout << "*";
		}
		cout << endl;
	}
	return 0;
}

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

long long C(int k,int n)
{
    if(k==0) return 1;
    if(n==k) return 1;
    if(k>(n-k)) k=n-k;
    long long ans=1;

    for(int i=0;i<k;i++)
    {
        ans*=(n-i);
        ans/=(i+1);
    }
    return ans;
}

int main()
{
    int n,p;
    while(~scanf("%d%d",&n,&p))
    {
        long long ans=0;
        int ji=0,ou=0;
        for(int i=0;i<n;i++)
        {
            int t;scanf("%d",&t);
            if(t&1) ji++;
            else ou++;
        }
        if(p)
        {
            for(int i=0;i<=ou;i++)
            {
                for(int j=1;j<=ji;j+=2)
                {
                    ans+=(C(i,ou)*C(j,ji));
                }
            }
        }
        else
        {
            for(int i=0;i<=ou;i++)
            {
                for(int j=0;j<=ji;j+=2)
                    ans+=(C(i,ou)*C(j,ji));
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


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

int main()
{
  int n, m, x, y, mx, my;
  cin >> n >> m >> mx >> my;
  for (int i = 0; i < n; i++)
  {
    cin >> x;
    mx = max(mx, x);
  }
  for (int i = 0; i < m; i++)
  {
    cin >> y;
    my = min(my, y);
  }
  cout << (mx < my ? "No War" : "War") << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;

signed main(){
    cin.tie(0); 
    ios::sync_with_stdio(false);
    int n;
    int x[110];
    int temp;
    int ans = 1000000007;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> x[i];
    }
    for(int i=1;i<=100;i++){
        temp = 0;
        for(int j=0;j<n;j++){
            temp += abs(i - x[j]) * abs(i - x[j]);
        }
        ans = min(ans,temp);
    }
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 256
use std::collections::VecDeque;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    process();
}

fn process() {
    let n = read::<usize>();
    let mut nodes: Vec<Vec<usize>> = Vec::<Vec<usize>>::with_capacity(n);
    unsafe {
        nodes.set_len(n);
    }
    for i in 0..n {
        nodes[i] = Vec::new();
    }

    for _i in 0..n - 1 {
        let ab = read_vec::<usize>();
        let a = ab[0] - 1;
        let b = ab[1] - 1;
        nodes[a].push(b);
        nodes[b].push(a);
    }

    let d = get_diameter(&nodes);
    if d % 3 == 1 {
        println!("Second");
    } else {
        println!("First");
    }
}

fn get_diameter(nodes: &Vec<Vec<usize>>) -> u32 {
    let (s, _dist_s) = get_fathrest(0, nodes);
    let (_t, dist_t) = get_fathrest(s, nodes);
    return dist_t;
}

fn get_fathrest(v: usize, nodes: &Vec<Vec<usize>>) -> (usize, u32) {
    let mut queue: VecDeque<usize> = VecDeque::new();
    let mut visited = vec![0u32; nodes.len()];
    let mut distance = vec![0u32; nodes.len()];
    let mut last_node = v;

    visited[v] = 1;
    queue.push_back(v);

    while let Some(s) = queue.pop_front() {
        last_node = s;
        for t in &nodes[s] {
            if visited[*t] != 0 {
                continue;
            }
            visited[*t] = 1;
            distance[*t] = distance[s] + 1;
            queue.push_back(*t);
        }
    }
    return (last_node, distance[last_node]);
}

Measured memory_bytes: 24828
#include "bits/stdc++.h"
using namespace std;

#define fi first
#define se second
#define pb push_back
#define int long long
#define all(x) (x).begin(), (x).end()

using LL = long long;
using LD = long double;
using pii = pair<int, int>;
using vii = vector<pii>;

const int INF = 1e18;
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;

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

    int n, k;
    cin >> n >> k;

    vector<int> dig;
    while (n) {
        dig.pb(n % k);
        n /= k;
    }

    cout << dig.size() << "\n";
}

Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = True

n, a, b = MAP()
print(abs(a - b) // 2 if not (a - b) % 2 else abs(a - b) // 2 + min(min(a, b) - 1, n - max(a, b)) + 1)

Measured memory_bytes: 61548
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

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

int main(){
	double r, g;
	cin >> r >> g;
	cout << 2 * g - r << endl;



    return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	sum := 0.0
	for i := 0; i < N; i++ {
		A, B := sc.NextFloat(), sc.Next()
		if B == "JPY" {
			sum += A
		} else {
			sum += A * 380000.0
		}
	}
	fmt.Println(sum)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int main(){
  string str;
  int A[4];
  cin >> str;
  for(int i=0;i<4;i++) A[i] = str[i] - '0';

  for(int x=0;x<8;x++){
    int sum = A[0];
    for(int i=0;i<3;i++){
      if(x&(1<<i)) sum += A[i+1];
      else sum -= A[i+1];
    }
    if(sum==7){
      cout << A[0];
      for(int i=0;i<3;i++){
        if(x&(1<<i)){
          cout << '+';
        }else{
          cout << '-';
        }
        cout << A[i+1];
      }
      cout << '=' << 7 <<endl; 
      break;
    }
  }

  return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> d(N);
  for (int i = 0; i < N; ++i)
    cin >> d[i];
  int ans = 0;
  for (int i = 0; i < N; ++i)
    for (int j = i + 1; j < N; ++j)
      ans += d[i] * d[j];
  cout << ans << endl;
}

Measured memory_bytes: 256
def main():
    n, m = [int(i) for i in input().split()]
    a = [int(i) for i in input().split()]
    a = sorted(a)[::-1]
    th = sum(a) / float(4*m)
    if a[m-1] >= th:
        print('Yes')
    else:
        print('No')
        

if __name__ == '__main__':
    main()



Measured memory_bytes: 2940
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;

long long cnt;
int l;
int A[1000000];
int n;
vector<int> G;

void insertionSort(int A[], int n, int g){
	for (int i = g; i < n; i++){
		int v = A[i];
		int j = i - g;
		while ( j >= 0 && A[j] > v){
			A[j + g] = A[j];
			j -= g;
			cnt++;
		}
		A[j + g] = v;
	}
}

void shellSort(int A[], int n){
	for (int h = 1; ; ){
		if (h > n) break;
		G.push_back(h);
		h = 3 * h + 1;
	}
	for (int i = G.size() - 1; i >= 0; i--){
		insertionSort(A, n, G[i]);
	}
}

int main(){
	cin >> n;
	for (int i = 0; i < n; i++) scanf("%d", &A[i]);
	cnt = 0;

	shellSort(A, n);

	cout << G.size() << endl;
	for (int i = G.size() - 1; i >= 0; i--){
		printf("%d", G[i]);
		if (i) printf(" ");
	}
	printf("\n");
	printf("%d\n", cnt);
	for (int i = 0; i < n; i++) printf("%d\n", A[i]);

	return 0;
}

Measured memory_bytes: 5196
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H,W,h,w;
  int different_1,different_2;
  cin >> H>>W>>h>>w;
  different_1 = H - h;
  different_2 = W - w;
  cout << different_1 * different_2 << endl;
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL){
    x = x->left;
  }
  return x;
}

Node treeMaximum(Node x){
  while(x->right != NIL){
    x = x->right;
  }
  return x;
}

 Node treeSearch(Node u, int k){
  while(u!=NIL && k!=u->key)
    {
      if(k < u->key) u=u->left;
      else u=u->right;
    }
  return u;
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right != NIL) return treeMinimum(x->right);
  y = x->parent;
  while( y != NIL && x == y->right ){
    x = y;
    y = y->parent;
  }
  return y; 
}

void treeDelete(Node z){
  Node y; 
  Node x; 
  if( z->left == NIL || z->right == NIL ) y = z;
  else y = treeSuccessor(z);
  if( y->left != NIL ) x = y->left;
  else x = y->right;
  if( x != NIL ) x->parent = y->parent;
  if( y->parent == NIL ) root = x;
  else if( y == y->parent->left ) y->parent->left = x;
  else y->parent->right = x;
  if( y != z ) z->key = y->key;
  }

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  while(x != NIL){
    y = x; 
    if( z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;
  if(y == NIL) root = z;
  else if(z->key < y->key) y->left = z; 
  else y->right = z;  
}

void inorder(Node u){
  if(u != NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}
void preorder(Node u){
  if(u != NIL) {
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }
}


int main(){
  int n, i, x, t;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      if(com[0]=='f')
	{
	  scanf("%d",&x);
	  Node a=treeSearch(root,x);
	  if(a!=NIL) printf("yes\n");
	  else printf("no\n");
	}
    }
    else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    }
    else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
      }
  }

  return 0;
}



Measured memory_bytes: 20612
#ifdef __LOCAL
  #define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b) {if(a<b) {a=b; return true;} return false;}
template<typename T> bool chmin(T &a,T b) {if(a>b) {a=b; return true;} return false;}
#define itn int
#define fi first
#define se second
#define intmax numeric_limits<int>::max()
#define llmax numeric_limits<ll>::max()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>=1;i--)
#define all(vec) vec.begin(),vec.end()
#define sortt(vec) sort((vec).begin(),(vec).end())
#define rsort(vec) sort((vec).rbegin(), (vec).rend())
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;
const ll lnf=1ll<<60;

itn cnt1[100010];
itn cnt2[100010];
itn scnt1[100010];
itn scnt2[100010];

int main(){
  string ss,tt; cin >> ss >> tt;
  rep(i,ss.size()){
    if(ss[i]=='A') cnt1[i]++;
    else cnt1[i]+=2;
  }
  rep(i,ss.size()) scnt1[i+1]=scnt1[i]+cnt1[i];
  rep(i,tt.size()){
    if(tt[i]=='A') cnt2[i]++;
    else cnt2[i]+=2;
  }
  rep(i,tt.size()) scnt2[i+1]=scnt2[i]+cnt2[i];
  vector<string> ans;
  ll T; cin >> T;
  while(T--){
    itn a,b,c,d;
    cin >> a >> b >> c >> d;
    a--; b--; c--; d--;
    if((scnt1[b+1]-scnt1[a])%3==(scnt2[d+1]-scnt2[c])%3) ans.push_back("YES");
    else ans.push_back("NO");
  }
  for(auto v:ans) cout << v << endl;
}

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

using namespace std;

int main() {
  int ct = 0;
  int a[3];

  scanf("%d", &ct);
  for(int i = 0; i < ct; i++) {
    scanf("%d %d %d", &a[0], &a[1], &a[2]);
    sort(a, a + 3);
    printf("%s\n", a[2] * a[2] == a[0] * a[0] + a[1] * a[1] ? "YES" : "NO");
  }
  return 0;
}

Measured memory_bytes: 1184
#include <stdio.h>
int z[9999],r[9999];
int f(int a,int b){
	printf("? %d %d\n",a,b);
	fflush(stdout);
	char c[2];
	scanf("%s",c);
	return *c=='Y';
}
int main(){
	int a,b,c=0,h,i;
	scanf("%d%d",&a,&b);
	if(a<=b){puts("Impossible");return 0;}
	for(i=a+=b;~--i;)!c||f(i,z[c-1])?(z[c++]=i):c--;
	for(h=*z,i=a;~--i;)r[i]=f(h,i);
	for(printf("! "),i=0;i<a;)printf("%d",r[i++]);
	puts("");
}

Measured memory_bytes: 816
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;

#define REP(i,N) for(int i = 0; i < N; i++)

int main(){
    // string strs[50];
    int alphabets[50][26] = {};//alphabets[i][j]は文字列iには'a'+jが入っている文字列を表す
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        string tmp;
        cin >> tmp;
        for(int j = 0; j < tmp.size(); j++){
            alphabets[i][tmp[j]-'a']++;
        }
        // cout << endl;
    }
    for(int i = 0; i < 26; i++){
        int min = 999;
        for(int j = 0; j < n; j++){
            if(alphabets[j][i] < min) min = alphabets[j][i];
        }
        char tmp = 'a' + i;
        for(int j = 0; j < min; j++){
            cout << tmp;
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
#define No cout<<"No"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
    int n;
    cin>>n;
    int h[n];
    bool flag=true;
    int b;
    rep(i,n){
        cin>>h[i];
    }
    for(int i=1;i<n;i++){
        if(h[i-1]==h[i]){
            continue;
        }
        else{
            h[i]--;
        }
        if(h[i-1]>h[i]){
            cout<<"No"<<endl;return 0;   
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}


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

constexpr long long MOD = 1'000'000'007;

int power(long long n, long long r){
	long long ans = 1;
	
	while(r) {
		if(r&1) ans *= n;
		
		r >>= 1;
		
		n *= n;
		
		n %= MOD;
		ans %= MOD;
	}
	
	return ans;
}

int main(){
	
	int n, k;
	int ans = 0;
	
	cin>>n>>k;
	
	ans = power(k, n);
	
	cout<<ans<<endl;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
#define FOR(i, n) for(int i = 1; i<=n; i++)
#define F0R(i, n) for(int i = 0; i<n; i++)
#define mp make_pair
#define pb push_back
#define f first
#define s second


//var 
int a, b;
const double oe = 0.08;

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

	cin >> a >> b;
	b *= 10;
	for(int i = b; i/10 == b/10; i++){
		if(floor((double)i * oe) == a){
			cout << i << endl;
			return 0;
		}
	}

	cout << -1 << endl;

	cout.flush();
	return 0;
}

Measured memory_bytes: 3644
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.lang.StringBuilder;
public class Main {
    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        try {
            String a = br.readLine();
            String[] arr = br.readLine().split(" ");
            for(int i=arr.length-1; i>=0; i--){
                sb.append(arr[i]);
                if(i!=0) {
                    sb.append(" ");
                }
            }
        }catch(IOException e) {
            e.printStackTrace();
        }
        System.out.println(new String(sb));
    }
}


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

const int N = 3e5 + 5;
int a[N];
int n;

int main() {

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

	sort(a, a + n);
	bool flag = false;
	for (int i = n - 1; cnt; i--) {
		if (flag)
			ans += a[i];
		cnt -= flag;
		flag ^= 1;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1408
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<iterator>
#include<cmath>
#include<string>
#include<algorithm>
#include<sstream>
#include<queue>
#include<list>
#include<deque>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<chrono>


/*  auto start = high_resolution_clock::now();
auto stop = high_resolution_clock::now();
auto duration = duration_cast<milliseconds>(stop - start);
pr(duration.count());    */


#define FastIO      ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define pb          push_back
#define siz         100009
#define mp          make_pair
#define ll          long long int
#define fileout     freopen("output.txt","w",stdout)
#define filein      freopen("input.txt","r",stdin)
#define pi          acos(-1.0)
#define all(x)      x.begin(),x.end()
#define ull		    unsigned long long int
#define m(a)	    memset(a,0,sizeof(a))
#define f(i,n)	    for(ll i=0;i<n;i++)
#define sc(a)	    scanf("%lld",&a)
#define pr(a)	    printf("%lld\n",a)
const ll inf = 5000000000000000;
ll in = 1000000000000000000;
using namespace std;

int main()
{
	FastIO;
	ll a,b,d, co, t, i, j, k, n,r;
	string s;
	char tmp;
	cin >> a >> s;
	map<char, ll>m;
	f(i, a)
	{
		m[s[i]]++;
	}
	co = 0;
	ll mi = a;
	for (i = 0; i < a; i++)
	{
		if (i && s[i-1]=='W')
		{
			co++;
		}
		if (s[i] == 'E')
			m['E']--;
		mi = min(mi, co + m['E']);
	}
	cout << mi << endl;
	return 0;
}

Measured memory_bytes: 720
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <utility>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <climits>
#include <numeric>
#include<stdio.h>
#include <queue>
#include <iomanip>
#include <float.h>
#include <set>
#include<functional>
#include <stack>
#include <time.h>
using namespace std;
int  gcd(int a, int b) {
	if (a < b) gcd(b, a);
	int r;
	while ((r = a%b)) {
		a = b;
		b = r;
	}
	return b;
}
long long lcm(long long a, long long b) {
	return a / gcd(a, b) * b;
}
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
long long mod = 1e9 + 7;
signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	int a[1003];
	int b[1003];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < m; i++) {
		cin >> b[i];
	}
	sort(a, a + n);
	sort(b, b + m);
	long long ans = 1;
	int as = n - 1;
	int bs = m - 1;
	int ketteigyou = 0;
	int ketteiretu = 0;
	int ketteizumi = 0;
	for (int now = n*m; now >= 1; now--) {
		long long tmp = 1;
		int judge1, judge2;
		if (as < 0|| now != a[as])judge1 = 0;
		else judge1 = 1;
		if (bs < 0|| now != b[bs])judge2 = 0;
		else judge2 = 1;
		if ((!judge1) && (!judge2)) {
			tmp = ketteigyou*ketteiretu - (n*m - now);
		}
		if (judge1&&judge2) {
			tmp = 1;
			as -= 1;
			bs -= 1;
			ketteigyou += 1;
			ketteiretu += 1;
		}
		if (judge1&&(!judge2)) {
			tmp =ketteiretu;
			as -= 1;
			ketteigyou += 1;
		}
		if ((!judge1)&&judge2) {
			tmp = ketteigyou;
			bs -= 1;
			ketteiretu += 1;
		}
		if (tmp <= 0) { ans = 0; break; }
		else {
			tmp %= mod;
			ans *= tmp;
			ans %= mod;
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
def runLength(str):
    """文字列strをランレングス圧縮して返す関数
    ex: "0000111101" => [(0,4), (1,4), (0,1), (1,1)]
    """
    res = []
    data, count = str[0], 1
    for i in range(1, len(str)):
        if str[i] == data:
            count += 1
        else:
            res.append((data, count))
            data, count = str[i], 1
    res.append((data, count))
    return res


S = input()
print(len(runLength(S)) - 1)


Measured memory_bytes: 10356
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <numeric>

/* debug macros */
#ifdef WAFDAYO
#define DBG_LINE() {std::cerr<<"\e[2m[L"<<__LINE__<<"]\e[m ";}
#define DBG_PRINT(s,t,u) {std::cerr<<(s)<<" \e[2m=\e[m \e[1m"<<(t)<<"\e[m"<<(u);}
#define SELECT_7TH(x1,x2,x3,x4,x5,x6,x7,...) x7
#define dbg1(x1) DBG_PRINT(#x1,x1,std::endl)
#define dbg2(x1,x2) DBG_PRINT(#x1,x1,", ")dbg1(x2)
#define dbg3(x1,x2,x3) DBG_PRINT(#x1,x1,", ")dbg2(x2,x3)
#define dbg4(x1,x2,x3,x4) DBG_PRINT(#x1,x1,", ")dbg3(x2,x3,x4)
#define dbg5(x1,x2,x3,x4,x5) DBG_PRINT(#x1,x1,", ")dbg4(x2,x3,x4,x5)
#define dbg6(x1,x2,x3,x4,x5,x6) DBG_PRINT(#x1,x1,", ")dbg5(x2,x3,x4,x5,x6)
#define dbg(...) DBG_LINE()\
SELECT_7TH(__VA_ARGS__,dbg6,dbg5,dbg4,dbg3,dbg2,dbg1)(__VA_ARGS__)
#else
#define dbg(...) {}
#endif

/* utility functions */
struct read_item{read_item(){};
template<class T>operator T(){T t;std::cin>>t;return t;}};
char splf(int i,int n){return(i+1<n)?' ':'\n';};
template<bool up>
struct _RI{int i;_RI(int a):i(a){}
int operator*(){return i;}void operator++(){i+=(up?1:-1);}
bool operator!=(const _RI& r){return up?i<r.i:i>=r.i;}};
template<bool up>
struct _RX{_RI<up> x,y;_RI<up> begin(){return x;}_RI<up> end(){return y;}
_RX(int a,int b):x(up?a:(a-1)),y(b){}_RX(int a):_RX(up?0:a,up?a:0){}};
typedef _RX<true> range;
typedef _RX<false> revrange;

/* types and constants */
typedef int64_t i64;
typedef uint64_t u64;
// const i64 inf = (i64)1.05e18;
// const int inf = (int)1.05e9;

using namespace std;

int main() {

	const int A = read_item();
	const int B = read_item();
	const int M = read_item();
	vector<int> as(A), bs(B);
	int min_a = 1e6, min_b = 1e6;
	for(auto i : range(A)) {
		as[i] = read_item();
		min_a = min(min_a, as[i]);
	}
	for(auto i : range(B)) {
		bs[i] = read_item();
		min_b = min(min_b, bs[i]);
	}

	int ans = min_a + min_b;
	for(auto i : range(M)) {
		int x = read_item();
		int y = read_item();
		x -= 1;
		y -= 1;
		int c = read_item();
		int a = as[x] + bs[y] - c;
		ans = min(ans, a);
	}

	printf("%d\n", ans);

	return 0;
}

/* wafdayo~~~ */


Measured memory_bytes: 1024
#include<cstdio>
#include<iostream>
#include<ctype.h>
#include<string>
using namespace std;
int main(){
	int R;
	cin >> R;
	if(R < 1200){
		cout << "ABC" << endl;
	}
	else if(R >= 1200 && R < 2800){
		cout << "ARC" << endl;
	}
	else{
		cout << "AGC" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

N, K = map(int, input().split())
ans = 0
for i in range(1, N + 1):
    x = i
    cnt = 0
    while i < K:
        i *= 2
        cnt += 1
    ans += (1 / N) * (1 / (2 ** cnt))
print(ans)

# def my_pow(base, n, mod):
#     if n == 0:
#         return 1
#     x = base
#     y = 1
#     while n > 1:
#         if n % 2 == 0:
#             x *= x
#             n //= 2
#         else:
#             y *= x
#             n -= 1
#         x %= mod
#         y %= mod
#     return x * y % mod

Measured memory_bytes: 9472
N = int(input())
h = list(map(int, input().split()))
if sum(h) == 0:
    print(0)
    exit()
ans = 0
flag = False
while True:
    if h[0] == 0:
        flag = True
    for i in range(N):
        if h[i] == 0 and flag == True:
            continue
        elif h[i] == 0 and flag == False:
            break
        h[i] -= 1
        flag = False
    ans += 1
    if sum(h) == 0:
        break
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

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


        int r = sc.nextInt();
        int d = sc.nextInt();
        int x = sc.nextInt();

        int xx = x;

        for (int i = 0; i < 10; i++) {
            xx = r*xx-d;
            System.out.println(xx);
        }

        sc.close();
    }
}


Measured memory_bytes: 22740
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    while(cin >> n, n){
        array<array<int, 21>, 21> v{};
        for (int i = 0; i < n; ++i) {
            int a, b;
            cin >> a >> b;
            v[b][a]++;
        }
        v[10][10] = 0;
        int m;
        cin >> m;
        string s = "NESW";
        int dy[] {1, 0, -1, 0}, dx[] {0, 1, 0, -1};
        int y = 10, x = 10;
        for (int i = 0; i < m; ++i) {
            char c; int w;
            cin >> c >> w;
            for (int cc = 0; cc < 4; ++cc) {
                if(s[cc] == c){
                    for (int j = 0; j < w; ++j) {
                        y += dy[cc], x += dx[cc];
                        v[y][x] = 0;
                    }
                }
            }
        }
        int ans = 0;
        for (int i = 0; i <= 20; ++i) {
            for (int j = 0; j <= 20; ++j) {
                if(v[i][j]) ans++;
            }
        }
        puts(ans ? "No" : "Yes");
    }
    return 0;
}



Measured memory_bytes: 2976
#include <iostream>
using namespace std;
int main() {
    int a = 0;  //前部分の数字
    int b = 0;  //後ろ部分の数字
    string pos; //郵便番号
    bool ans = true;    //条件にあっているかどうか

    cin >> a >> b >> pos;

    for (int i = 0; i < a; ++i) {
        if (pos[i] == '-'){
            ans = false;
        }
    }
    if(pos[a] != '-'){
        ans = false;
    }
    for (int j = a + 1; j < a+b+1; ++j) {
        if (pos[j] == '-'){
            ans = false;
        }
    }

    if (ans == true){
        cout << "Yes";
    } else {
        cout << "No";
    }
    return 0;
}

Measured memory_bytes: 256