akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 2e5 + 5;

map<int, int> cnt;

vector<pii> vv;

void solve(){
	int n, a;
	scanf("%d", &n);
	REP(i, 0, n) {
		scanf("%d", &a);
		cnt[a]++;
	}
	FA(it, cnt) {
		vv.pb(mp(it->_1, it->_2));
	}
	if (SZ(cnt) == 1 && cnt.find(0) != cnt.end()) {
		printf("Yes\n");
		return;
	} else if (SZ(cnt) == 2 && cnt.find(0) != cnt.end()) {
		if (vv[0]._2 * 2 == vv[1]._2) {
			printf("Yes\n");
			return;
		}
	} else if (SZ(cnt) == 3) {
		if (vv[0]._2 == vv[1]._2 && vv[1]._2 == vv[2]._2 && (vv[0]._1 ^ vv[1]._1) == vv[2]._1) {
			printf("Yes\n");
			return;
		}
	}
	printf("No\n");
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 4988
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG 
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, s, n) for (int i = s; i < n; i++)
#define all(v) v.begin(), v.end() // sort(all(array))
#define INF 1000000000
#define mod 1000000007
using namespace std;
using ll = long long;
using vi = vector<int>; //vi array(要素数, 初期値)
using vll = vector<ll>;
using pll = pair<ll, ll>;
using pii = pair<int, int>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>; //vvi table(行数, vi(列数, 初期値))
using vvc = vector<vc>;
using vvs = vector<vs>;
using vvb = vector<vb>;

int main() {
    int n; cin >> n;
    vll A(n); rep(i, n) cin >> A[i];
    ll inf = 1000000000000000000;

    if (count(all(A), 0)) {
        cout << 0 << endl;
        return 0;
    }

    ll ans = 1;
    rep(i, n) {
        if (A[i] <= inf / ans) {
        /*これまでの積にA[i]をかけても 
        オーバーフローしなければかけ算*/
            ans *= A[i];
        } else {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4028
#include<stdio.h>

long long  N,prime[1001],beki[1001];

int main(void){
    long long  i,j,k;

    scanf("%lld",&N);
    for(i = 2;i <= N;i++){
        k = 1;
        for(j = 2;j < i;j++)
            if(i % j == 0){
                k = 0;break;
            }
        prime[i] = k;
    }

    for(i = 2;i <= N;i++){
        j = i;
        while(j > 1){
            for(k = 2;k <= j;k++)
                if(prime[k] == 1)
                    if(j % k == 0){
                        j /= k;
                        beki[k]++;
                        break;
                    }
        }
    }

    j = 1;
    for(i = 1;i <= N;i++)
        j = j * (beki[i] + 1) % 1000000007;

    printf("%lld\n",j);
    return 0;
}

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second
#define setpre(x) cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ cout << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << "[LOGGER]" << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005;

/* ...o(^-^)o... */

int main(){
    int n, p; cin >> n >> p;
    string s; cin >> s;
    vector<int> vec(n);

    lint ans = 0;
    if(p == 2 || p == 5){
        rep(i, n){
            int t = s[i] - '0';
            if(t % p == 0){
                ans += i + 1;
            }
        }
        out(ans); return 0;
    }

    int q = 1;
    repr(i, n){
        int t = s[i] - '0';
        vec[i] = (t * q) % p;
        q = (10 * q) % p;
    }

    repr(i, n - 1){
        vec[i] += vec[i+1];
        vec[i] %= p;
    }

    map<int, lint> mp;
    rep(i, n){
        mp[vec[i]]++;
    }

    ans = mp[0];
    rep(k, p){
        if(mp[k] >= 2){
            ans += mp[k] * (mp[k] - 1) / 2;
        }
    }

    out(ans);
}

Measured memory_bytes: 1796
fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  val segments = Array(n, { readLine()!! })
  val baseCount = segments.sumBy { countAB(it) }
  val endsAList = (0 until n).filter { segments[it].last() == 'A' }
  val startsBList = (0 until n).filter { segments[it][0] == 'B' }
  var bonus = Math.min(endsAList.size, startsBList.size)
  if (bonus > 0 && endsAList == startsBList) {
    bonus--
  }
  println(baseCount + bonus)
}

fun countAB(s: String): Int {
  var count = 0
  for (i in 0 until s.length - 1) {
    if (s[i] == 'A' && s[i + 1] == 'B') {
      count++
    }
  }
  return count
}

Measured memory_bytes: 34376
#include<iostream>
using namespace std;
int main () {
  int N, M;
  cin >> N >> M;
  int r, l;
  l = 0;
  r = N;
  for (int i = 0; i < M; i ++) {
    int a,b;
    cin >> a >> b;
    if (l < a) l = a;
    if (r > b) r = b;
  }
  cout << max(r - l + 1, 0) << endl;
}




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

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    vector<unsigned long> L(N);
    for(auto&& i : L)cin >> i;
    unsigned long ans{0};
    for(const auto& i : L)for(const auto& j : L)for(const auto& k : L)if(i != j && j != k && i != k && 2 * max({i, j, k}) < i + j + k)++ans;
    cout << ans / 6 << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
    int a,b,c;
    cin >>a;
    cin >>b;
    cin >>c;
    if(a<b&&b<c){
        cout << "Yes"<<endl;
    }else{
        cout << "No" << endl;
    }
}


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

int main(){
  int N,count=0;
  cin >> N;
  vector<int> L(N);
  for(int i=0;i<N;i++){
    cin >> L.at(i);
  }
  for(int i=0;i<N-2;i++){
    for(int j=i+1;j<N-1;j++){
      for(int k=j+1;k<N;k++){
        if(L.at(i)!=L.at(j) && L.at(j)!=L.at(k) && L.at(k)!=L.at(i)){
         if(L.at(i)+L.at(j)>L.at(k) && L.at(j)+L.at(k)>L.at(i) && L.at(k)+L.at(i)>L.at(j)){
           count++;
         }
        }
      }
    }
  }
  cout << count << endl;
}
        
  

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

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

using namespace std;

using ll = long long;
using P = pair<int, int>;

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

  int count = 1;
  int result = 0;
  while (count < b) {
    count += a - 1;
    result++;
  }
  cout << result << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

const int INF = (1<<20), nmax = 40, abmax = 10;
int dp[nmax+1][nmax*abmax+1][nmax*abmax+1];
int a[nmax], b[nmax], c[nmax];

int main(){
    int N, Ma, Mb; cin >> N >> Ma >> Mb;
    //vector<int> a(N), b(N), c(N);
    for(int i=0; i<N; i++) cin >> a[i] >> b[i] >> c[i];

    for(int i=0; i<=N; i++) for(int j=0; j<=nmax*abmax; j++) for(int k=0; k<=nmax*abmax; k++) dp[i][j][k] = INF;
    dp[0][0][0] = 0;

    for(int i=0; i<N; i++){
        for(int ca=0; ca<=nmax*abmax; ca++){
            for(int cb=0; cb<=nmax*abmax; cb++){
                if(dp[i][ca][cb] == INF) continue;

                dp[i+1][ca][cb] = min(dp[i+1][ca][cb], dp[i][ca][cb]);
                dp[i+1][ca+a[i]][cb+b[i]] = min(dp[i+1][ca+a[i]][cb+b[i]], dp[i][ca][cb]+c[i]);
            }
        }
    }

    int ans = INF;
    for(int ca=1; ca<=abmax*nmax; ca++){
        for(int cb=1; cb<=abmax*nmax; cb++){
            if(ca*Mb == cb*Ma) ans = min(ans, dp[N][ca][cb]);
        }
    }

    if(ans == INF) ans = -1;
    cout << ans << endl;
}

Measured memory_bytes: 25984
#include<math.h>
double a,b,c,d;
double A,B,C,D,E,F,G,H,R=6378.1;
main(){
	for(;scanf("%lf%lf%lf%lf",&a,&b,&c,&d),a+1;){
		a*=M_PI/180;
		b*=M_PI/180;
		c*=M_PI/180;
		d*=M_PI/180;
		A=cos(a)*cos(b);
		B=cos(a)*sin(b);
		C=sin(a);
		D=cos(c)*cos(d);
		E=cos(c)*sin(d);
		F=sin(c);
		G=A*D+B*E+C*F;
		H=acos(G);
		printf("%.0f\n",R*H);
	}
	exit(0);
}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] ab = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            long eastNum = 0;
            long westNum = 1;
            for(int j = 1; j < ab[1]-ab[0]; j++)
            {
                eastNum += j;
            }
            Console.WriteLine(eastNum - ab[0]);
        }
    }
}
// 文字列の入力
//string s = Console.ReadLine();

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

// 文字列配列の入力
//string[] inputStrArray = Console.ReadLine().Split(' ');

// 整数配列の入力
//long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();


Measured memory_bytes: 28236
#include <bits/stdc++.h>
using namespace std;
#define rep(i, x, n) for(long i = x; i < n; i++)
#define erep(i, x, n) for(long i = x; i <= n; i++)
#define all(a) a.begin(), a.end()
#define show(ans)  cout << ans << endl;
const long MOD = 1000000007;


int main() {long A, B, C;
cin >> A >> B >> C;
long ans = 0;
long a = A%2, b = B%2, c = C%2;
if(a != b && a != c){
    B++;
    C++;
    ans++;
}
if(b != a && b != c){
    A++;
    C++;
    ans++;
}
if(c != a && c != b){
    A++;
    B++;
    ans++;
}
vector<long> v = {A, B, C};
sort(all(v));
ans += (v[2]-v[0]+v[2]-v[1])/2;
show(ans);


  return 0;
 
}



Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  map<int, int> cnt;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    ans += cnt[i - a[i]];
    cnt[a[i] + i]++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 21116
n = int(input())
l = list(map(int, input().split()))

p = min(l)
q = max(l)

ms = []
for i in range(p, q+1):
  m = 0
  for j in range(n):
    m += (l[j]-i)**2
  ms.append(m)
print(min(ms))
  

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

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[][] activities = new int[n+1][3];
		String[] s;
		for (int i = 1; i < n+1; i++) {
			s = br.readLine().split(" ");
			for (int j = 0; j < 3; j++)
				activities[i][j] = Integer.parseInt(s[j]);
		}

		int[][] max = new int[n + 1][3];
		for (int i = 1; i < n + 1; i++) {
			max[i][0] = activities[i][0] + Math.max(max[i - 1][1], max[i - 1][2]);
			max[i][1] = activities[i][1] + Math.max(max[i - 1][0], max[i - 1][2]);
			max[i][2] = activities[i][2] + Math.max(max[i - 1][0], max[i - 1][1]);
		}

		int k = -1;
		for (int i = 0; i < 3; i++) {
			if (max[n][i] > k)
				k = max[n][i];
		}
		System.out.println(k);
	}

}


Measured memory_bytes: 47004
mod = 10**9+7
def prime(n,p):
    iteral = 0
    while n%p == 0:
        n //= p
        iteral += 1
    return iteral,n
def modpow(a,n):#二乗
    if n==0:
        return 1
    elif n==1:
        return a%mod
    elif n%2==0:
        return (modpow(a,n/2)**2)%mod
    else:
        return (a*modpow(a,n-1))%mod
def modfact(l,r):#階乗
    fact=1
    for i in range(l-r+1):
        fact=fact*(r+i)%mod
    return fact
def comb(n,x):#組み合わせ
    S=modfact(n,n-x+1)
    fact=modfact(x,1)
    T=modpow(fact,mod-2)
    return S*T%mod

def sieve(N):#エラトステネスの篩
    prime = [0]*(N+1)
    isprime = [True]*(N+1)
    isprime[0]=isprime[1] = False
    num = 0
    for p in range(2,N+1):
        if isprime[p]:
            prime[num] = p
            num += 1
            for j in range(2*p,N+1,p):
                isprime[j] = False
    prime.sort()
    prime.reverse()
    for k in range(N-1):
        if prime[k+1] == 0:
            end = k
            break
    return prime[:end+1]
def main():
    N,M = map(int,input().split())
    b = {}
    for i in reversed(sieve(int(M**0.5)+10)):
        if M%i==0:
            num,M = prime(M,i)
            b[i] = num
    if M > 1:
        b[M] = 1
    ans = 1
    for num in b:
        ans *= comb(b[num]+N-1,b[num])
        ans %= mod
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 3700
smallAndLarge a b k
    | a + (k - 1) < b - (k - 1) = [a..a+(k-1)] ++ [b-(k-1)..b]
    | otherwise     = [a..b]

main :: IO ()
main = do
    [a, b, k] <- map read . words <$> getLine
    mapM_ print $ smallAndLarge a b k

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
  string s;
  cin>>s;
  ll a,b,c,d;
  a = s[0]-'0';
  b = s[1]-'0';
  c = s[2]-'0';
  d = s[3]-'0';
  ll temp1 = a*10 + b;
  ll temp2 = c*10 + d;
  if(temp1 <= 12 && temp2 <= 12 && temp1 > 0 && temp2 > 0){
  	cout<<"AMBIGUOUS";
  }
  else if(temp1 <= 12 && temp1 > 0){
  	cout<<"MMYY";
  }
  else if(temp2 <= 12 && temp2 > 0){
  	cout<<"YYMM";
  }
  else cout<<"NA";
}

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

int main(){
  int a,b;
  cin >> a >> b;
  int x = max(a,b);
  int y = min(a,b);
  int tmp;
  while (y != 0){
    tmp = y;
    y = x % y;
    x = tmp;
  }
  cout << x << endl;
}


Measured memory_bytes: 3096
import java.util.Scanner;

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

            if(op.equals("+")){
                System.out.println(a+b);
            }else if(op.equals("-")){
                System.out.println(a-b);
            }else if(op.equals("*")){
                System.out.println(a*b);
            }else if(op.equals("/")){
                System.out.println(a/b);
            }else if(op.equals("?")){
                break;
            }
        }
    }
}


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

#define countof(a) (sizeof(a)/sizeof(*a))

#define vi std::vector<int>
#define vvi std::vector<std::vector<int> >
#define vpi std::vector<pi >
#define pi std::pair<int,int>
#define fi first
#define se second
#define all(n) n.begin(), n.end()

#define FROMTO(var, from, to) for (int var = (from), var##down = ((int)(to)) < ((int)(from));var##down ? (var >= (int)(to)) : (var <= (int)(to));var##down ? var-- : var++)
#define UPTO(var, from, to)   for (int var = (from); var <= ((int)(to)); var++)
#define DOWNTO(var, from, to) for (int var = (from); var >= ((int)(to)); var--)
#define FOR(var, to)		  UPTO(var, 0, (to)-1)
#define DOWN(var, from)	   DOWNTO(var, (from)-1, 0)

#define INIT(var, val) FOR(i,countof(var)) var[i] = val
#define INPUT(var) FOR(i,countof(var)) std::cin >> var[i]
#define INPUT1(var) FOR(i,countof(var)) std::cin >> var[i], var[i]--

#define SORT(v) qsort(v,countof(v),sizeof(*v),int_less)
#define SORTT(v) qsort(v,countof(v),sizeof(*v),int_greater)
#define QSORT(v,b) qsort(v,countof(v),sizeof(*v),b)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

static const int MOD = 1000000007;
static const int INF = ((1<<30)-1);
static const s64 LINF = ((1LL << 62)-1);

struct Comb {
	std::vector<std::vector<s64> > a;
	Comb(int n) { // O(n^2)
		a.resize(n+1);
		FOR(i,n+1) {
			a[i].resize(i+1, 1);
			UPTO(j,1,i-1) a[i][j] = a[i-1][j] + a[i-1][j];
		}
	}
	s64 ncr(int n, int r) {
		assert(n >= 0);
		assert(n <= (int)a.size());
		assert(r >= 0);
		assert(r <= n);
		return a[n][r];
	}
};

#define gc(c) (c)=getchar()
int ri() {
	int c,s=0,r=0;
	for(;;){gc(c);if(c=='-'){s=1;break;}if(c>='0'&&c<='9'){r=c-'0';break;}}
	for(;;){gc(c);if(c<'0'||c>'9')break;r*=10;r+=c-'0';}
	if(s)r=-r;
	return r;
}
s64 rs64() {
	s64 r = 0;
	int c,s = 0;
	for(;;){gc(c);if(c=='-'){s=1;break;}if(c>='0'&&c<='9'){r=c-'0';break;}}
	for(;;){gc(c);if(c<'0'||c>'9')break;r*=10;r+=c-'0';}
	if(s)r=-r;
	return r;
}

int int_less(const void *a, const void *b) {
	return (*(const int*)a - *(const int*)b);
}
int int_greater(const void *a, const void *b) {
	return (*(const int*)b - *(const int*)a);
}
std::string operator*(const std::string &s, int n){ std::string res; FOR(i,n) res += s; return res; }

template<class T> std::ostream& operator<<(std::ostream& os, std::vector<T> a) { for (auto i : a) os << i << " "; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, std::set<T> a) { for (auto i : a) os << i << " "; return os; }
template<class A, class B> std::ostream& operator<<(std::ostream&os, std::pair<A,B> a) { os << a.fi << "," << a.se; return os; }


int main() {
	s64 n = rs64();
	int sqt = sqrt(n);
	std::set<s64> sho;
	for (int i = 1; i <= sqt; i++) {
		sho.insert(i);
		sho.insert(n / i);
	}
	s64 res = 0;
	for (auto i : sho) {
		if ((n - i) % i) continue;
		if (i >= (n - i) / i)continue;
		res += (n - i) / i;
	}
	std::cout << res << std::endl;
	
	
	return 0;
}


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

int main()
{
    long long x;
    cin >> x;
    for(long long i = 0; i < 200; ++i)
    {
        for(long long j = 0; j < 200; ++j)
        {
            if(x == i*i*i*i*i-j*j*j*j*j)
            {
                cout << i << " " << j << endl;
                return 0;
            }
            if(x == i*i*i*i*i+j*j*j*j*j)
            {
                j *= -1;
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3644
s = input()
ans = 0
for i in range(len(s)):
  for j in range(i+1,len(s)+1):
    t = s[i:j].replace('A','')
    t = t.replace('C','')
    t = t.replace('G','')
    t = t.replace('T','')
    if t == '':
      ans = max(j-i,ans)
print(ans)

Measured memory_bytes: 9008
n = int(input())
al = list(map(int,input().split()))
bl = list(map(int,input().split()))

def bubble_sort(lst):
    a = 0
    for i in range(len(lst)-1):
        for j in range(len(lst)-1, i, -1):
            if lst[j-1] > lst[j]:
                tmp = lst[j]
                lst[j] = lst[j-1]
                lst[j-1] = tmp
                a += 1
    return a

anss = float("inf")
for i in range(2 ** n):
    bits = [0] * n
    for j in range(n):
        if ((i >> j) & 1):
            bits[j] = 1
    even_odd = [[], []]
    for idx, bit in enumerate(bits):
        if bit == 0:
            even_odd[(idx + bit) % 2].append((al[idx], idx))
        else:
            even_odd[(idx + bit) % 2].append((bl[idx], idx))
    if len(even_odd[0]) - len(even_odd[1]) != n % 2:
        continue
    aal = sorted(even_odd[0])
    bbl = sorted(even_odd[1])
    goto = []
    now = 0
    for k in range(n):
        if k % 2 == 0:
            tmp, idx = aal.pop(0)
            if now <= tmp:
                goto+= [idx]
                now = tmp
            else:
                break
        else:
            tmp, idx = bbl.pop(0)
            if now <= tmp:
                goto+= [idx]
                now = tmp
            else:
                break
    else:
        ans = bubble_sort(goto)
        anss = min(anss, ans)

if anss == float('inf'):
    print(-1)
else:
    print(anss)

Measured memory_bytes: 55004
#include <iostream>
#include <vector>
#include <tuple>
#include <utility>
using namespace std;
const int LEFT = 1;
const int RIGHT = 0;

int main() {
  int N, L;
  while(cin >> N >> L, N || L) {
    vector< tuple<int, int> > tup;
    for(int i=0; i<N; i++) {
      char c; int pos;
      cin >> c >> pos;
      tup.emplace_back(c == 'L', pos);
    }

    int step = 0, ans = -1;
    while(1) {
      step++;

      
      int ansL = -1, ansR = -1;
      vector<int> cnt(L+1);
      for(int i=0; i<N; i++) {
        int dir, pos; tie(dir, pos) = tup[i];
        // fprintf(stderr, "step = %d, index = %d, dir = %d, pos = %d\n", step, i, dir, pos);
        if(pos == 0 or pos == L) continue;
        if(dir == LEFT) pos--;
        else pos++;

        if(1 <= pos and pos < L) {
          cnt[pos]++;
        }
        else if(pos == 0) {
          ansL = i+1;
        }
        else if(pos == L) {
          ansR = i+1;
        }

        tup[i] = tuple<int, int>(dir, pos);
      }

      bool rem = false;
      for(int i=0; i<N; i++) {
        int dir, pos; tie(dir, pos) = tup[i];
        if(pos == 0 or pos == L) continue;

        rem = true;
        if(cnt[pos] > 1) {
          dir = 1 - dir;
        }

        tup[i] = tuple<int, int>(dir, pos);
      }

      if(ansR > 0) ans = ansR;
      if(ansL > 0) ans = ansL;
      if(!rem) break;
    }
    cout << step << " " << ans << endl;
  }
  return 0;
}



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

int main(){
	int n;
	cin>>n;
	vector<string> v(n);
	for (int i = 0; i<n; i++){
		cin>>v[i];
	}
	sort(v.begin(),v.end());
	vector<pair<int,string>> maxc;
	int prevcnt = 0;
	string prevval = v[0];
	for (string s : v){
		if (s==prevval){
			prevcnt++;
		} else {
			maxc.push_back({-prevcnt,prevval});
			prevval=s;
			prevcnt=1;
		}
	}
	maxc.push_back({-prevcnt,prevval});
	sort(maxc.begin(),maxc.end());

	for (auto p : maxc){
		if (p.first!=maxc[0].first){
			break;
		}
		cout<<p.second<<endl;
	}
	return 0;
}

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

int main(){
    int K,count = 0;
    cin >> K;
    for(int i = 1; i <= K; i++){
        for(int j = 1; j <= K; j++){
            for (int k = 1; k <= K; k++){
                count += __gcd(i,__gcd(j,k));
            }
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 3632
from itertools import permutations
import math
n = int(input())
xy = [list(map(int,input().split())) for _ in range(n)]

sum = 0
for i in permutations(xy,2):
    sum = sum + math.sqrt( (abs(i[0][0] - i[1][0]))**2 + (abs(i[0][1] - i[1][1]))**2 )
print(sum/n)

Measured memory_bytes: 3064
s = list(map(int, input()))
sum = 0

for i in range(len(s)):
    if len(s) == 1:
        sum = 0
        break
    if i % 2 == 0:
        if s[i] != s[0]:
            sum += 1
    else:
        if s[i] == s[0]:
            sum += 1
print(sum)

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

using namespace std;
typedef pair<int,int> pii;

char board[8][8];

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

int mami_dfs(int x,int y,int cnt,int idx){
  int nx=x+dx[idx],ny=y+dy[idx];
  if(0<=nx && nx<=7 && 0<=ny &&ny<=7 && board[nx][ny]=='x'){
    cnt++;
    return mami_dfs(nx,ny,cnt,idx);
  }
  else if(0<=nx && nx<=7 && 0<=ny &&ny<=7 && board[nx][ny]=='o'){
    return cnt;
  }
  else if(0<=nx && nx<=7 && 0<=ny &&ny<=7 && board[nx][ny]=='.'){
    return 0;
  }
  return 0;
}

int magi_dfs(int x,int y,int cnt,int idx){
  int nx=x+dx[idx],ny=y+dy[idx];
  if(0<=nx && nx<=7 && 0<=ny &&ny<=7 && board[nx][ny]=='o'){
    cnt++;
    return magi_dfs(nx,ny,cnt,idx);
  }
  else if(0<=nx && nx<=7 && 0<=ny &&ny<=7 && board[nx][ny]=='x'){
    return cnt;
  }
  else if(0<=nx && nx<=7 && 0<=ny &&ny<=7 && board[nx][ny]=='.'){
    return 0;
  }
  return 0;
}

int mami_count(int x,int y){//(x,y)??????????????¨?????????????????°
  int res=0;
  for(int i=0;i<8;i++) res+=mami_dfs(x,y,0,i);
  return res;
}

int magi_count(int x,int y){//(x,y)??????????????¨?????????????????°
  int res=0;
  for(int i=0;i<8;i++) res+=magi_dfs(x,y,0,i);
  return res;
}

int mami_solve(){//???????????????????????¶???
  int ma=-1,x,y;
  for(int i=0;i<8;i++)for(int j=0;j<8;j++){
    if(board[i][j]=='.' && mami_count(i,j)>ma){
      ma=mami_count(i,j);
      x=i;y=j;
    }
  }//?????§?????????????????´???
  if(ma<1) return false;
  board[x][y]='o';
  for(int i=0;i<8;i++){
    int tmp=mami_dfs(x,y,0,i);
    for(int j=1;j<=tmp;j++){
      board[x+dx[i]*j][y+dy[i]*j]='o';
    }
  }
  return true;
}

bool magi_solve(){//???????????????????????¶???
  int ma=-1,x,y;
  for(int i=7;i>=0;i--)for(int j=7;j>=0;j--){
    if(board[i][j]=='.'&&magi_count(i,j)>ma){
      ma=magi_count(i,j);
      x=i;y=j;
    }
  }//?????§?????????????????´???
  if(ma<1) return false;
  board[x][y]='x';
  for(int i=0;i<8;i++){
    int tmp=magi_dfs(x,y,0,i);
    for(int j=1;j<=tmp;j++){
      board[x+dx[i]*j][y+dy[i]*j]='x';
    }
  }
  return true;
}

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

  for(int i=0;i<8;i++)for(int j=0;j<8;j++) cin>> board[i][j];
  bool mami_flag=true,magi_flag=true;
  while(mami_flag || magi_flag){
    mami_flag=mami_solve();
    magi_flag=magi_solve();
  //  cout<<mami_flag<<" "<<magi_flag<<endl;
  }
  for(int i=0;i<8;i++){
    for(int j=0;j<8;j++){
      cout<< board[i][j];
    }
    cout<<endl;
  }
}

Measured memory_bytes: 3188
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include <complex>
using namespace std;



#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const double EPS = 1e-8;
const int MOD = 1000 * 1000 * 1000 + 7;
const int MAX = 2*1000 * 100 + 47;
const int LEN = 20;
const int ALP = 128;

int DP[MAX];
int main()
{
    //freopen("in.txt", "r", stdin);
    int n;
    scanf("%d", &n);
    int p = -1;
    LL ans = 0;
    FOR(i, 0, n) {
        int x;
        scanf("%d", &x);
        if (x > p+1) {
            cout << -1 << endl;
            return 0;
        }
        if(p !=-1)ans += x == p+1 ? 1 : x;
        p = x;
    }
    cout << ans << endl;
    
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>
#include<deque>
#include<list>


using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;
const int BIG_INT = 1000000000;

int gcd(int a, int b) {
	if (a > b) {
		swap(a, b);
	}
	if (a == 0) {
		return b;
	}

	return gcd(b%a, a);
}

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

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

	sort(a.begin(), a.end());

	int g = a[0];
	for (int i = 1;i < n; i++) {
		g = gcd(g, a[i]);
	}

	string ans = "IMPOSSIBLE";

	for (int i = 0; i < n;i++) {
		if (a[i] >= k && (a[i] - k) % g == 0) {
			ans = "POSSIBLE";
			break;
		}
	}

	cout << ans << endl;
}



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

int main(){

    int a, b;
    char op;
    while(1){
        cin >> a >> op >> b;
        if(op == '?'){
            break;
        }
        else if(op == '+'){
            cout << a + b << endl;
        }
        else if(op == '-'){
            cout << a - b << endl;
        }
        else if(op == '*'){
            cout << a * b << endl;
        }
        else if(op == '/'){
            cout << a / b << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3100
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <list>
#include <cmath>
#include <stack>
#include <deque>
#include <iomanip>

using namespace std;
typedef long long ll;
using Pll = pair<ll,ll>;

const ll INF = 1LL<<60;
const ll MOD = 1000000007;

//cout << fixed << setprecision(10);

int main() {
    ll N,M;
    cin >> N >> M;

    priority_queue<ll> q;

    ll ans = 0;
    
    for(int i=0;i<N;i++){
        ll a;
        cin >> a;
        q.push(a);
        ans += a;
    }

    while(M>0){
        ll a = q.top();
        q.pop();
        M--;
        q.push(a/2);
        ans -= (a/2 + a%2);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1400
import numpy as np
from collections import Counter
from scipy.misc import comb
N = int(input())
A = list(map(int, input().split()))

total = 0
answers = np.array([0] * (N + 1), dtype=np.int64)
for number, appearance in Counter(A).items():
    flat = comb(appearance, 2, exact=True)
    minus_one = comb(appearance - 1, 2, exact=True)
    total += flat
    answers[number] = minus_one - flat
answers += total

print(*answers[A], sep="\n")


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

int main(){ 
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i,n) cin >> h[i];
  sort(h.begin(), h.end(), greater<int>());
  ll res = 0;
  for (int i = k; i < n; i++) {
    res += h[i];
  }
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
typedef struct{
  int num;
  char name[10];
  int p;
}R;

int main(void){
  int i,j,N;
  R temp,rest[100];
  scanf("%d",&N);
  for(i=0;i<N;i++){
    rest[i].num = i+1;
    scanf("%s %d",rest[i].name,&rest[i].p);
  }
  for(j=0;j<N;j++){
    for(i=0;i<N-1;i++){
      if(strcmp(rest[i].name,rest[i+1].name) == 0){
        if(rest[i].p < rest[i+1].p){
          temp = rest[i];
          rest[i] = rest[i+1];
          rest[i+1] = temp;
        }
      }else if(strcmp(rest[i].name,rest[i+1].name) > 0){
        temp = rest[i];
          rest[i] = rest[i+1];
          rest[i+1] = temp;
      }
    }
  }
  for(i=0;i<N;i++)
    printf("%d\n",rest[i].num);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
  string a,b,c;
  cin>>a>>b>>c;
  if(a.at(a.size()-1)==b.at(0)&&b.at(b.size()-1)==c.at(0))
    cout<<"YES"<<endl;
  else
    cout<<"NO"<<endl;
}


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

int main() {
        int a,b,d,r;
        double f;
        cin >>a>>b;
        d=a/b;
        r=a%b;
        f=1.00000*a/b;
        printf("%d %d %.5lf\n", d, r, f);
}



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

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

    string str;
    cin>>str;


    for(int i=0; i<str.length(); i++){
        char ch = str[i];

        ch = (ch + n);
        if(ch>90)
            ch = ch - 26;

        str[i] = ch;
    }

    cout<<str;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define YES {cout<<"YES"<<'\n';}
#define NO {cout<<"NO"<<'\n';}
#define Yes {cout<<"Yes"<<'\n';}
#define No {cout<<"No"<<'\n';}
#define yes {cout<<"yes"<<'\n';}
#define no {cout<<"no"<<'\n';}
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) {cout << n << '\n';}
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    int a,b,c,d; cin >> a >> b >> c >> d;
    out(a*b-b*c-a*d+c*d);

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static int w, h;
	static int[]amida;
	public static void main(String[] args) {
		while(read()){
			solve();
		}
	}
	static boolean read(){
		if(!sc.hasNext())return false;
		w = sc.nextInt(); h = sc.nextInt();
		amida = new int[w+1];
		String line;
		String[] devide = new String[2];
		for(int i = 1; i < w+1; i++)
			amida[i] = i;
		for(int i = 0; i < h; i++){
			line = sc.next();
			devide = line.split(",");
			int exIndex1 = Integer.parseInt(devide[0]);
			int exIndex2 = Integer.parseInt(devide[1]);
			int temp = amida[exIndex1];
			amida[exIndex1] = amida[exIndex2];
			amida[exIndex2] = temp;
		}
		return true;
	}
	static void solve(){
		for(int i = 1; i < w+1; i++){
			System.out.println(amida[i]);
		}
	}

}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  bool flag=true;
  cin>>s;
  for(int i=0;i<s.length()-1;i++)
  {
    if(s[i]==s[i+1])
    {
       cout<<"Bad"<<endl;
      return 0;
    }
  }
  cout<<"Good"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int n;
    cin>>n;
    int s[100005];
    for(int i=0;i<n;i++)
        scanf("%d",&s[i]);
    s[0]-=1;
    int ans=s[0];
    int flag=0;
    for(int i=1;i<n;i++)
    {
        if(s[i]<ans)
        {
            flag=1;
            break;
        }
        else if(s[i]>ans)
        {
            s[i]-=1;
            ans=s[i];
        }
    }
    if(flag==0)
        puts("Yes");
    else puts("No");
    return 0;
}


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

#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;

constexpr int MOD = 1000000007;

ll calc(ll h) {
    if (h == 1) { return 1; }
    return 1 + 2 * calc(h / 2);
}

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

    ll h;
    cin >> h;
    cout << calc(h) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define rall(x) (x).rbegin(), (x).rend()
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;
const int mod = 1e9 + 7;

int main(){
    ll n,a,b; cin >> n >> a >> b;
    cout << min(n*a,b) << endl;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
  var N int
  fmt.Scan(&N)
  for i := 1; i < 10; i++{
    if N%i == 0{
      n := N/i
      for j := 1;j < 10; j++{
        if n%j == 0 && n/j == 1{
          fmt.Println("Yes")
          return
        }
      }
    } 
  }
  fmt.Println("No")
}


Measured memory_bytes: 512
from math import factorial
from itertools import product

S = input()
N = int(S)
m = len(S)
K = int(input())

# 0でない数字がちょうどK個でK桁のものを数える
product_K = product(['1', '2', '3', '4', '5', '6', '7', '8', '9'], repeat=K)
product_K = [int(''.join(x)) for x in product_K]
ans = len([x for x in product_K if x <= N])

if m > K:
    # K+1桁からlen(N)-1桁までを数える
    for i in range(1, m-K):
        ans += 9**K * factorial(i+K-1)//factorial(i)//factorial(K-1)
    
    # Nと同じ桁数で条件を満たすものを数える
    zero_n = m-K
    non_zero_n = K
    for i in range(m):
        l = int(S[i])
        if l == 0:
            zero_n -= 1
            continue
        if i > 0 and zero_n > 0:
            ans += 9**non_zero_n\
                * factorial(zero_n-1 + non_zero_n)\
                //factorial(zero_n-1)\
                //factorial(non_zero_n)
        non_zero_n -= 1
        ans += len([x for x in range(1, l)])\
                * 9**non_zero_n\
                * factorial(zero_n + non_zero_n)\
                //factorial(zero_n)\
                //factorial(non_zero_n)
        
        if non_zero_n <= 0:
            ans += 1
            break
print(ans)



Measured memory_bytes: 9076
while True:
    n = int(input())
    if n == 0:
        break
    L = []
    for _ in range(n):
        s, p, q, r = [int(x) for x in input().split()]
        c = p*4 + q*9 + r*4
        L.append((s,p,q,r,c))
    lp,lq,lr,lc = [int(x) for x in input().split()]
    
    M = []
    for s, p, q, r, c in L:
        if p <= lp and q <= lq and r <=lr and c <=lc:
            M.append(s)
    #M.sort()
    
    if len(M) > 0:
        print(*M, sep="\n")
    else:
        print("NA")
        
        


Measured memory_bytes: 5860
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define INF (INT_MAX / 4)
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
#define TIMER_S(start) chrono::system_clock::time_point start = chrono::system_clock::now();
#define TIMER_E(end) chrono::system_clock::time_point end = chrono::system_clock::now();
#define TIME(start, end) cout << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count()) << "ms" << "\n";
/* clang-format on */

int main() {
  ll l, r;
  cin >> l >> r;
  ll ans = 2020 * 2020;
  if (r - l > 2 * 2019) {
    cout << 0 << "\n";
    return 0;
  }
  for (ll i = l; i < r; i++) {
    if (i % 2019 == 0) {
      cout << 0 << "\n";
      return 0;
    }
    for (ll j = i + 1; j <= r; j++) {
      if (j % 2019 == 0) {
        cout << 0 << "\n";
        return 0;
      }

      ans = min(ans, (i * j) % 2019);
    }
  }
  cout << ans << "\n";
  return 0;
}


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

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

using namespace std;
using ll = long long;

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

    int n;
    cin >> n;
    printf("%d\n", !n);

    return 0;
}

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

int main(){
  int A,B;
  cin>>A>>B;
  if(A%3==0||B%3==0||(A+B)%3==0){
    cout<<"Possible"<<endl;
  }
  else{
    cout<<"Impossible"<<endl;
  }
}

Measured memory_bytes: 256
N, L = tuple(map(int, input().split()))

lis = []

for n in range(N):
  lis.append(input())
  j = n
  if not n == 0:
    while lis[j-1]>lis[j] and j>0:
      lis[j-1:j+1] = [lis[j], lis[j-1]]
      j -= 1

ans = ''
      
for e in lis:
  ans += e
  
print(ans)

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static int allBlack;
        static int allWhite;

        static void Main(string[] args)
        {
            //[summary]C - Stones
            int n = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();

            //全部を黒(または白)に統一するケース
            allBlack = s.Count(x => x == '.');
            allWhite = n - allBlack;

            //最初は白で、途中から全部黒になるケース
            //(白の個数を左から1コずつ増やしていく)
            var halfways = CountHalfways(s, n).ToList();

            var counts = new List<int>(halfways);
            counts.Add(allBlack);
            counts.Add(allWhite);

            Console.WriteLine(counts.Min());
        }

        static IEnumerable<int> CountHalfways(string s, int n)
        {
            int changed = allBlack;

            if (s[0] == '.')
            {
                changed--;
            }
            else
            {
                changed++;
            }

            yield return changed;

            for (int i = 1; i < s.Length - 1; i++)
            {
                if (s[i] == '.')
                {
                    changed--;
                }
                else
                {
                    changed++;
                }

                yield return changed;
            }
        }
    }
}

Measured memory_bytes: 17248
package main

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

func abs(f float64) float64 {
	if f < 0 {
		return -f
	}
	return f
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	sc.Scan()
	t, _ := strconv.Atoi(sc.Text())
	sc.Scan()
	a, _ := strconv.Atoi(sc.Text())
	maxDiff := 1000000.0
	var ans int
	for i := 0; i < n; i++ {
		sc.Scan()
		h, _ := strconv.Atoi(sc.Text())
		if abs(float64(a)-(float64(t)-float64(h)*0.006)) < maxDiff {
			maxDiff = abs(float64(a) - (float64(t) - float64(h)*0.006))
			ans = i + 1
		}
	}
	fmt.Println(ans)
}

Measured memory_bytes: 640
import math

K = int(input())

ans = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        gcd_ij = math.gcd(i, j)
        for l in range(1, K+1):
            ans += math.gcd(gcd_ij, l)

print(ans)


Measured memory_bytes: 9112
#include <iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main() {
	int N, K;
	cin >> N >> K;

	int ans = 0;
	for (int i = 0;i < N;i++) {
		int x;
		cin >> x;
		int dist_min = min(K - x, x);
		ans += dist_min;
	}
	cout << 2*ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>

using namespace std;


int main()
{
    long long x, k, d;
    cin >> x >> k >> d;
    long long m;

    if (llabs(x) / d < k) {
        m = llabs(x) % d;
        if ((k - (x / d)) % 2 != 0) {
            m = llabs(m - d);
        }
    }
    else {
        m = llabs(x) - k * d;
    }

    
    cout << m;


    return 0;
}



Measured memory_bytes: 3552
use std::io;
use std::cmp;


/// https://beta.atcoder.jp/contests/abc076/tasks/abc076_b
fn main() {
    let n = read_one::<usize>();
    let k = read_one::<usize>();
    let mut ans = 1;
    for _ in 0..n {
        ans = cmp::min(ans * 2, ans + k);
    }
    println!("{}", ans);
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
package main

import (
	"fmt"
	"time"
)

const (
	yyyymmdd = "2006/01/02"
)

func main() {
	var dateS, res string
	_, _ = fmt.Scan(&dateS)
	res = solveA(dateS)
	fmt.Println(res)
}

func solveA(dateS string) string {

	t1, _ := time.Parse(yyyymmdd, dateS)
	t2, _ := time.Parse(yyyymmdd, "2019/04/30")

	if t1.Unix() <= t2.Unix() {
		return "Heisei"
	} else {
		return "TBD"
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define EPS 1e-10
#define setNil(x) memset((x),0,sizeof(x))
#define setINF(x) memset((x),63,sizeof(x))
#define setNegINF(x) memset((x),192,sizeof(x)) //NegINF=-INF-1
#define setNeg1(x) memset((x),255,sizeof(x))
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int n,m,d;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>m>>d;
	if(d)cout<<fixed<<setprecision(10)<<1.0*(m-1)*(min(2*d,n)+2*max(n-2*d,0))/n/n<<endl;
	else cout<<fixed<<setprecision(10)<<1.0*(m-1)/n<<endl;
	return 0;
}

Measured memory_bytes: 256