akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_imports)]
use petgraph::unionfind::UnionFind;
use proconio::*;
use std::cmp::*;
use std::fs;
use std::io::*;

fn gcd(a:i64, b:i64)->i64 {
    match b {
        0 => a,
        _ => gcd(b, a%b)
    }
}

#[fastout]
fn main() {
   input! {
      k: usize,
   }
   let mut ans = 0i64;
   for a in 1..(k+1) {
       for b in 1..(k+1) {
           for c in 1..(k+1) {
               ans += gcd(a as i64, gcd(b as i64, c as i64));
           }
       }
   }
   println!("{}", ans);
}


Measured memory_bytes: 2200
def gcd(x, y):
    while y:
        x, y = y, x % y
    return x

def lcm(x, y):
    return x // gcd(x, y) * y

X, Y = map(int, input().split())
L = lcm(X, Y)
res = L - X
if (L - X) % Y != 0 and (L - X) <= 10**18:
    print(L - X)
else:
    print(-1)

Measured memory_bytes: 9088
/*input
4 5
1 2
2 3
2 4
1 4
4 3
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int long long 
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back

#define RE(i,n) for (int i = 1; i <= n; i++)
#define RED(i,n) for (int i = n; i > 0; i--)
#define REPS(i,n) for(int i = 1; (i*i) <= n; i++)
#define REP(i,n) for (int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)

#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

int raise(int a,int n,int m = MOD){
  if(n == 0)return 1;
  if(n == 1)return a;
  int x = 1;
    x *= raise(a,n/2,m);
    x %= m;
    x *= x;
    x %= m;
    if(n%2)x*= a;
    x %= m;
    return x;
}

int floor1(int n,int k){
    if(n%k == 0 || n >= 0)return n/k;
    return (n/k)-1;
}

int ceil1(int n,int k){
    return floor1(n+k-1,k);
}

const int N = 1e3+1;
vector<int> adj[N];
int n,m;
int par[N];
int dist[N];
int forb1 = 0;
int forb2 = 0;

void bfs(int s){
	queue<int> q;
	RE(i,n){
		dist[i] = INF;
		par[i] = 0;
	}
	par[s] = s;
	dist[s] = 1;
	q.push(s);
	while(!q.empty()){
		int u = q.front();
		q.pop();
		for(int v:adj[u]){
			if(u == forb1 and v == forb2)continue;
			if(par[v])continue;
			par[v] = u;
			dist[v] = dist[u]+1;
			q.push(v);
		}
	}
}

void solve(){
  	cin >> n >> m;
  	REP(i,m){
  		int a,b;cin >>a >> b;
  		adj[a].pb(b);
  	}
  	int minnans = INF;
  	int u1 = 0;
  	int v1 = 0;
  	REP(u,n){	
  		for(int v:adj[u]){
  			forb1 = u;
  			forb2 = v;
  			bfs(v);
  			if(minnans> dist[u]){
  				minnans = dist[u];
  				u1 = u;
  				v1 = v;
  			}
  		}
  	}
  	if(minnans == INF){
  		cout << -1;
  		return;
  	}
  	cout << minnans << endl;
  	forb1 = u1;
  	forb2 = v1;
  	bfs(v1);
  	int cur = u1;
  	while(1){
  		cout << cur << endl;
  		if(par[cur] == cur)break;
  		else cur = par[cur];
  	}
}

signed main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  //freopen(".in","r",stdin);freopen(".out","w",stdout);
  int t = 1;
  //cin >> t;
  while(t--){
    solve();
  }
  return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<cstring>
using namespace std;
int m,n,__,e[20000][20000],root,inf=0x3f3f3f3f;
int low[100001],num[100001],book[100001],cnt=0;
int min(int a,int b)
{
    return a<b?a:b;
}
void gd(int cur,int fa)
{
    int ez=0;
    __++;
    num[cur]=__;
    low[cur]=__;
    for(int i=1;i<=m;i++)
        {
            if(e[cur][i]==1)
                {
                    if(num[i]==0)
                    {	
                        ez++;
                        gd(i,cur);
                        low[cur]=min(low[cur],low[i]);
                        if(low[i]>num[cur])
                            {
                            	book[cur]=1;
                        		cnt++;
                            }
                    }
                else if(fa!=i)
                    low[cur]=min(low[cur],num[i]);
                }
        
        }
    return;
}
int main()
{
    int a,b;
    cin>>m>>n;
    for(int i=1;i<=n;i++)
        {
            cin>>a>>b;
            e[a][b]=1;
            e[b][a]=1;
        }
    root=1;
    gd(1,root);

    cout<<cnt<<endl;
    
    return 0;
}

Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<bitset>
#include<vector>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#define LL long long

using namespace std;

LL read()
{
	LL ans=0,f=1;
	char c=getchar();
	while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();}
	return ans*f;
}

LL a,b;

LL gcd(LL x,LL y);

int main()
{
	a=read();b=read();
	printf("%lld",a*b/gcd(a,b));
	return 0;
}

LL gcd(LL x,LL y)
{
	return !y?x:gcd(y,x%y);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N, K;
	cin >> N >> K;
	double sum = 0;
	for(int i = 1; i <= N; i++){
		int p = i, count = 0;
		while(p < K){
			p *= 2;
			count++;
		}
		double pb = 1/pow(2,count);
		sum += pb;
	}
	sum /= N;
	//printf("[%10d]\n", sum);
	cout << setprecision(12);
	cout << sum << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>

using namespace std;

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//constants
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INF = 1<<28;


int main(int argc, char **argv) {
    long long x;
    cin >> x;
    long long ans = 0;
    ans += x/11;
    ans *= 2;
    if (x%11 > 0){
        if (x%11 <= 6)
            ans++;
        else
            ans += 2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>

bool valid(intmax_t k, const std::vector<intmax_t>& h, intmax_t a, intmax_t b) {
  intmax_t m = 0;
  a -= b;
  for (auto hi: h) {
    if (hi <= b*k) continue;
    m += (hi-b*k + a-1) / a;
  }
  return m <= k;
}

int main() {
  size_t N;
  intmax_t A, B;
  scanf("%zu %jd %jd", &N, &A, &B);

  std::vector<intmax_t> h(N);
  for (auto& hi: h) scanf("%jd", &hi);

  intmax_t lb = 0;
  intmax_t ub = 1e9+1;
  while (ub-lb > 1) {
    intmax_t mid = (lb+ub) >> 1;
    (valid(mid, h, A, B)? ub:lb) = mid;
  }
  printf("%jd\n", ub);
}


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

using namespace std;
typedef long long ll;

int main() {
  ll n; cin >> n;
  vector<ll> p(n);
  for (ll j=0; j < n; ++j) cin >> p[j];
  ll count = 0;
  for (int j=1; j < n-1; ++j) {
    vector<ll> v = {p[j-1], p[j], p[j+1]};
    sort(v.begin(), v.end());
    if (v[1] == p[j]) count++;
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder_Tutorial
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            List<int> hList = Console.ReadLine().Split().Select(_ => int.Parse(_)).ToList();

            int count = 0;
            while (hList.Any(num => 0 < num))
            {
                if (hList.All(num => 0 < num))
                {
                    int min = hList.Min();
                    for (int i = 0; i < hList.Count; i++)
                        hList[i] -= min;
                    count += min;
                }
                else
                {
                    int start = 0;
                    for (int i = 1; i < hList.Count; i++)
                    {
                        if (hList[i-1] == 0 && 0 < hList[i])
                        {
                            start = i;
                            break;
                        }
                    }
                    
                    for (int i = start; i < hList.Count && hList[i] != 0; i++)
                    {
                        hList[i]--;
                    }
                    count++;
                }
            }
            Console.WriteLine(count);
        }
    }
}


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

#define mod      1e9+7;
#define INF      1e9+9;
#define ps(x,y)  fixed<<setprecision(y)<<x
# define PI 3.14159265358979323846264338327950 L
typedef long long ll;
typedef unsigned long long ull;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	int n,x;
	cin>>x>>n;
	int mini=200,a;
	int ans=200;
	unordered_set<int> us;
	for(int i=0;i<n;i++){
		cin>>a;
		us.insert(a);
	}
	if(us.count(x)==0){
		cout<<x<<endl;
		return 0;
	}
	a=1;
	while(1){
		if(us.count(x-a)==0){
			cout<<x-a<<endl;
			return 0;
		}
		if(us.count(x+a)==0){
			cout<<x+a<<endl;
			return 0;
		}
		a++;
		if(a>150)
			break;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3648
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let h: usize = input();
    let w: usize = input();
    let a: Vec<Vec<char>> = (0..h)
        .map(|_| input::<String>().chars().collect())
        .collect();
    const MOD: i64 = 1000000007;

    let mut dp = vec![vec![0i64; w + 1]; h + 1];
    dp[1][1] = 1;
    for i in 0..h {
        for j in 0..w {
            if a[i][j] == '.' {
                dp[i + 1][j + 1] += dp[i + 1][j] + dp[i][j + 1];
                dp[i + 1][j + 1] %= MOD;
            }
        }
    }

    println!("{}", dp[h][w]);
}


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

int main(void)
{
    int k, a, b;
    cin >> k;
    cin >> a >> b;
    for(int i=a; i<=b; i++)
    {
        if(i%k == 0)
        {
            cout << "OK" << endl;
            return 0;
        }
    }

    cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3636
N = int(input())
*W, = map(int, input().split())
C = {w: i for i, w in enumerate(W)}
W.sort()

ans = 0
S = []
used = [0]*N
for i in range(N):
    if used[i]:
        continue
    sq = []
    w = W[i]
    p = i; j = None
    while j != i:
        j = C[w]; w = W[j]
        used[j] = 1
        sq.append(w)
        p = j
    mi = min(sq); ln = len(sq)
    if ln >= 2:
        ans += sum(sq)
    S.append((mi, ln))
S.sort()
m, ln = S[0]
if ln >= 2:
    ans += (ln-2)*m
for mi, ln in S[1:]:
    if ln <= 2:
        continue
    ans += min(m+mi+ln*m, (ln-2)*mi)
print(ans)




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

#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define INT_MAX_HALF (INT_MAX / 2)
#define EPS (1e-10)

using namespace std;
typedef long long ll;

int main(){

    int h,w,d;
    cin >> h >> w >> d;

    int tmp;

    vector<vector<pair<int,int>>> point(d, vector<pair<int,int>>(h * w / d + 1));

    rep(i, h){
        rep(j, w){
            cin >> tmp;

            point.at(tmp % d).at(tmp % d != 0 ? tmp / d : tmp / d - 1) = (mpair(i, j));
        }
    }

    cerr << "point comp" << endl;

    vector<vector<int>> magicsum(d, vector<int>(1, 0));

    rep(i, d){
        //cerr << point.at(i).size() << endl;
        for(int j = 1; j < point.at(i).size(); j++){
            int diffy = abs(point.at(i).at(j).first - point.at(i).at(j - 1).first);
            int diffx = abs(point.at(i).at(j).second - point.at(i).at(j - 1).second);

            magicsum.at(i).pback(magicsum.at(i).at(j - 1) + diffy + diffx);
        }
    }

    cerr << "magicsum comp" << endl;

    int q;
    cin >> q;

    rep(i, q){
        int l, r;
        cin >> l >> r;

        int m = l % d;
        l = l / d;
        r = r / d;

        if(m == 0){
            l--;
            r--;
        }

        //cerr << l << " " << r << endl;
        //cerr << magicsum.at(m).at(0) << " " << magicsum.at(m).at(1) << " " << magicsum.at(m).at(2) << " " << magicsum.at(m).at(3) << endl;

        cout << magicsum.at(m).at(r) - magicsum.at(m).at(l) << endl;
    }

    return 0;
}


Measured memory_bytes: 10240
#include<bits/stdc++.h>
using namespace std;
using lli = long long;
const int mod = 1e9+7;
template< int mod >
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }

  static int get_mod() { return mod; }
};

using mint = ModInt< mod >;


int n;
mint k, res;
vector<int> a;

int main(void){
    cin >> n >> k;
    a = vector<int>(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    res = 0;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            if(a[i] > a[j]) res+=1;
        }
    }
    sort(a.begin(), a.end());
    mint cnt = 0;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            if(a[i] < a[j]) cnt+=1;
        }
    }
    res = k*res+k*(k-1)*cnt/2;
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3696
import Control.Applicative
main = do
    n <- getLine
    a <- map read . words <$> getLine
    putStrLn $ solve a
solve :: [Int] -> String
solve list = if judge tuple then "Yes" else "No"
    where tuple = count list

powerTwo :: Int -> Int -> Int
powerTwo n x = if r==0 then powerTwo (n+1) q else n
    where (q,r) = divMod x 2

count :: [Int] -> (Int,Int,Int)
count = foldl f (0,0,0)
    where f (x,y,z) n = case powerTwo 0 n of 0 -> (x+1,y,z)
                                             1 -> (x,y+1,z)
                                             _ -> (x,y,z+1)
judge :: (Int,Int,Int) -> Bool
judge (x,y,z) = if y>=1
                then x<=z
                else x<=z+1

Measured memory_bytes: 59772
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

char a[1000],b[10000],c[1000];

int main(){
	scanf("%s%s%s",a,b,c);
	int la=strlen(a);
	int lb=strlen(b);
	int lc=strlen(c);
	if (a[la-1]==b[0]&&b[lb-1]==c[0]){
		printf("YES");
	}
	else printf("NO");
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val N = sc.nextInt()
  val L = (1..N).map { sc.nextLong() }
  val maxL = L.max()!!
  val total = L.sum() - maxL
  println(if (maxL < total) "Yes" else "No")
}

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

using namespace std;

#define endl "\n"
#define F first
#define S second
#define B begin()
#define E end()
#define PB push_back
#define int long long

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;

const int maxn = 1e5;
const int OO = 1e18;
const int mod = 1e7 + 9;

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

//	freopen("name.in","r",stdin);
//	freopen("name.out","w",stdout);


    int n,m;
    cin >> n >> m;
    int h[n];
    for(int i=0;i<n;i++)
        cin >> h[i];
    vector<vi>g(n);
    while(m--)
    {
        int a,b;
        cin >> a >> b;
        a--,b--;
        g[a].PB(b);
        g[b].PB(a);
    }
        int cont=0;
    for(int i=0;i<n;i++)
    {
        bool f=1;
        for(int j=0;j<g[i].size();j++)
        {
            if(h[g[i][j]] >= h[i])
                f=0;
        }
        if(f)
            cont++;
    }
    cout << cont;
	return 0;
}


Measured memory_bytes: 9760
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}
string march = "MARCH";
int main() {
    int N;
    cin >> N;
    vector<string> S(N);
    map<char, long long> m;
    REP(i, N) { cin >> S[i]; }
    REP(i, N) {
        if(S[i][0] == 'M' or S[i][0] == 'A' or S[i][0] == 'R' or
           S[i][0] == 'C' or S[i][0] == 'H') {
            m[S[i][0]]++;
        }
    }
    long long sum = 0;
    for(int i = 0; i < 5; i++) {
        for(int j = i + 1; j < 5; j++) {
            for(int k = j + 1; k < 5; k++) {
                sum += m[march[i]] * m[march[j]] * m[march[k]];
            }
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 6144
#include <iostream>
#include <algorithm>

using namespace std;

bool data[16][16];
int ans;
int a, b;
int dx[] = {0, 1};
int dy[] = {1, 0};

void dfs(int y, int x){
  if(y == b-1 && x == a-1){
    ans++;
    return;
  }
  for(int i=0;i<2;i++){
    int ty = y + dy[i];
    int tx = x + dx[i];
    if(ty<0 || ty>=b) continue;
    if(tx<0 || tx>=a) continue;
    if(data[ty][tx]) dfs(ty, tx);
  }
}

main(){
  int n;
  while(cin >> a >> b){
    if(a == 0 && b == 0) break;
    cin >> n;
    fill(data[0], data[16], true);
    for(int i=0;i<n;i++){
      int in1, in2;
      cin >> in1 >> in2;
      data[in2-1][in1-1] = false;
    }
    ans = 0;
    dfs(0, 0);
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 868
fn main() {
	let mut s = String::new();
	use std::io::Read;
	std::io::stdin().read_to_string(&mut s).unwrap();
	let mut s = s.split_whitespace();

	let x: i64 = s.next().unwrap().parse().unwrap();
	let x = x.abs();
	let k: i64 = s.next().unwrap().parse().unwrap();
	let d: i64 = s.next().unwrap().parse().unwrap();

	let cnt = x / d;
	if cnt < k {
		let x = x - d * cnt;
		let cnt = k - cnt;
		if cnt % 2 == 0 {
			println!("{}", x);
		} else {
			println!("{}", (x - d).abs());
		}
	} else {
		println!("{}", x - d * k);
	}
}


Measured memory_bytes: 2152
#include<iostream>
#include<algorithm>
using namespace std;
int main(void)
{
	int H, W;
	while (true)
	{
		cin >> H >> W;
		if (H == 0 && W == 0)
			break;
		for (int i = 0; i < H; ++i)
		{
			for (int j = 0; j < W; ++j)
				cout << ((i + j) % 2 == 0 ? '#' : '.');
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3084
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

class union_find {
public:
vector<int> par,rank;
union_find(int n): par(n),rank(n){
   for (int i=0;i < n;i++){
      par[i]=i;
      rank[i]=0;
   }
}

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

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

bool same(int x, int y){
   return find(x) == find(y);
}
};
vector<int> ans(100010);
int main(){
      int n,q;
      cin >> n >> q;
      union_find tree(n+1);
      int id=0;
      rep(i,q){
         int c,x,y;
         cin >> c >> x >> y;
         if (c==0){
            tree.unite(x,y); 
         }
         else{
            ans[id]=tree.same(x,y);
            id++;
         }
      }
      rep(i,id){
         cout << ans[i] << endl;
      }
   return 0;
}



Measured memory_bytes: 3368
#include <bits/stdc++.h>
using namespace std;
int T;
int a[200009],F[200009];
vector<int> v[200009],x[200009];
int X[200009];
void dfs(int x)
{
    F[x]=1;
    for (int i=0; i<v[x].size(); i++)
        if(F[v[x][i]]==0) dfs(v[x][i]);
    a[T++] = x;
}

main()
{
    int n,m;
    cin >> n >> m;
    for (int i=0; i < m; i++)
    {
        int l,r,d;
        cin >> l >> r >> d;
        if(l==r)
        {
            if(d==0) continue;
            else {cout <<"No"<<endl; return 0;}
        }
        if (d==0 && l > r) swap(l,r);
        v[r].push_back(l);
        x[r].push_back(d);
    }
    for (int i = 1; i <= n; i++)
        if(F[i]==0)dfs(i);
    for (int i = 0; i < n; i++)
    {
        if(v[a[i]].size()==0) X[a[i]]=0;
        else X[a[i]]=X[v[a[i]][0]]+x[a[i]][0];
    }
    for (int i=1; i <= n; i++)
    {
        for (int j=0; j < v[i].size(); j++)
        {
            if(X[i]-X[v[i][j]]!=x[i][j])
            {
                cout <<"No"<< endl;
                return 0;
            }
        }
    }
    cout <<"Yes"<<endl;
    return 0;

}


Measured memory_bytes: 20864
#include<bits/stdc++.h>
using namespace std;
int n;
vector<int> all;
int dp[100100];
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	all.push_back(1);
	for(int i=6;i<=n;i*=6){
		all.push_back(i);
	}
	for(int i=9;i<=n;i*=9){
		all.push_back(i);
	}
	memset(dp,63,sizeof(dp));
	dp[0]=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<all.size();j++){
			if(i+all[j]<=n)
				dp[i+all[j]]=min(dp[i+all[j]],dp[i]+1);
		}
	}
	cout<<dp[n]<<endl;
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <tuple>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define repdm(i, a, b) for (ll i = (ll)(a); i > (ll)(b); i--)

int N, A, B, C;
int seq[4] = {0, 1, 2, 3};
int ANS = 100000;

int calcMP(map<int, int> m)
{
  if (m[1] == 0 || m[2] == 0 || m[3] == 0)
    return 10000;
  return abs(A - m[1]) + abs(B - m[2]) + abs(C - m[3]);
}

int dfs(int depth, int l[], map<int, int> m, int mp)
{
  if (depth == 0)
  {
    mp += calcMP(m);
    return mp;
  }

  for (auto s : seq)
  {
    int tmp = mp;
    map<int, int> mm = m;
    if (mm[s] == 0)
    {
      mm[s] = l[depth - 1];
    }
    else
    {
      mm[s] += l[depth - 1];
      if (s != 0)
        tmp += 10;
    }
    tmp = dfs(depth - 1, l, mm, tmp);
    ANS = min(ANS, tmp);
  }

  return ANS;
}

int main()
{
  cin >> N >> A >> B >> C;
  int l[N];
  rep(i, N) cin >> l[i];
  int mp = 0;

  map<int, int> m{
      {0, 0}, {1, 0}, {2, 0}, {3, 0}};

  dfs(N, l, m, mp);

  cout << ANS;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var N, K int
	fmt.Scan(&N, &K)
	D := make([]bool, 10)
	for i := 0; i < K; i++ {
		var t int
		fmt.Scan(&t)
		D[t] = true
	}
	// fmt.Println("N", N, "K", K, "D", D)
	for v := N; v <= 1000000; v++ {
		ok := true
		t := v
		for t > 0 {
			if D[t%10] {
				ok = false
				break
			} else {
				t /= 10
			}
		}
		if ok {
			fmt.Println(v)
			return
		}
	}
}


Measured memory_bytes: 512
N, K = map(int, input().split())
trees = []
for _ in range(N):
    trees.append(int(input()))
trees.sort()

min_diff = float("inf")
for i in range(N - K + 1):
    min_diff = min(min_diff, trees[i + K - 1] - trees[i])

print(min_diff)


Measured memory_bytes: 7384
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
E=[0]*(n//2)
O=[0]*(n//2)
for i in range(n):
    if i%2==0:
        O[i//2]=v[i]
    else:
        E[i//2]=v[i]
cntE=Counter(E)
cntO=Counter(O)
if cntE.most_common()[0][0]!=cntO.most_common()[0][0]:
    print(n-cntE.most_common()[0][1]-cntO.most_common()[0][1])
else:
    if len(cntE.most_common())==1 and len(cntO.most_common())==1:
        print(n//2)
    elif len(cntE.most_common())==1:
        print(n-cntE.most_common()[0][1]-cntO.most_common()[1][1])
    elif len(cntO.most_common())==1:
        print(n-cntE.most_common()[1][1]-cntO.most_common()[0][1])
    else:
        print(min(n-cntE.most_common()[0][1]-cntO.most_common()[1][1],n-cntE.most_common()[1][1]-cntO.most_common()[0][1]))

Measured memory_bytes: 19040
#include <vector>
#include <cmath>
#include <iostream>

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < m; i++) {
        if(n < 0) {
            cout << -1;
            return 0;
        }

        int x;
        cin >> x;
        n = n - x;
    }
    if(n >= 0)
        cout << n << '\n';
    else
        cout << -1;
  	return 0;
}

Measured memory_bytes: 3596
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<62)
typedef pair<ll, ll> P;
#define MOD (1000000007ll)
#define l_ength size
#define T ((ll)(2e12))

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

int main(void){
	int n,i;
	char s;
	bool flag = false;
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> s;
		if(s == 'Y'){
			flag = true;
		}
	}
	cout << ((flag)?"Four":"Three") << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int a[10],b[9],c[8],d[7],e[6],f[5],g[4],h[3],i[2],j,n,m;
    char in[11];
    
    while(scanf("%s",in)!=EOF){
        for(n=0;n<10;n++){
            a[n]=in[n]-'0';
        }
        /*
        for(n=0;n<10;n++)
        printf("%d ",a[n]);
        printf("\n");
        */
        for(n=0;n<9;n++){
            b[n]=a[n]+a[n+1];
            if(b[n]>=10)
                b[n]-=10;
        }
        for(n=0;n<8;n++){
            c[n]=b[n]+b[n+1];
            if(c[n]>=10)
                c[n]-=10;
        }
        for(n=0;n<7;n++){
            d[n]=c[n]+c[n+1];
            if(d[n]>=10)
                d[n]-=10;
        }
        for(n=0;n<6;n++){
            e[n]=d[n]+d[n+1];
            if(e[n]>=10)
                e[n]-=10;
        }
        for(n=0;n<5;n++){
            f[n]=e[n]+e[n+1];
            if(f[n]>=10)
                f[n]-=10;
        }
        for(n=0;n<4;n++){
            g[n]=f[n]+f[n+1];
            if(g[n]>=10)
                g[n]-=10;
        }
        for(n=0;n<3;n++){
            h[n]=g[n]+g[n+1];
            if(h[n]>=10)
                h[n]-=10;
        }
        for(n=0;n<2;n++){
            i[n]=h[n]+h[n+1];
            if(i[n]>=10)
                i[n]-=10;
        }
        j=i[0]+i[1];
        if(j>=10)
            j-=10;
        printf("%d\n",j);
        
    }
    return 0;
}

Measured memory_bytes: 1720
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n ;
  int a[n];
  
  for (int i = 0 ; i < n ; i++){
    cin >> a[i];
  }
  sort(a,a+n);

  int coe1[n];
  int coe2[n];

  coe1[0] = 1;
  coe2[0] = -1;

  for (int i = 1 ; i < n -1;i++ ){
    if (i % 2){
      coe1[i] = -2;
      coe2[i] = 2;
    }
    else {
      coe1[i] = 2;
      coe2[i] = -2;
    }
  }

  if (n % 2){
      coe1[n-1] = 1;
      coe2[n-1] = -1;
    }
  else {
      coe1[n-1] = -1;
      coe2[n-1] = 1;
  }

  sort(coe1,coe1+n);
  sort(coe2,coe2+n);

  long long sum1 = 0,sum2 = 0;
  
  for (int i=0 ; i < n ;i++){
    sum1 += coe1[i] * a[i];
    sum2 += coe2[i] * a[i];
  }

  long long ans = max(sum1,sum2);
 
  cout << ans <<  endl;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <stdio.h>
 
using namespace std;
 
#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(i, a) for (auto &i: (a))
#define sz(x) (int)(x).size()
#define all(v) (v).begin(), (v).end()
#define fr(i, a, b) for (int i = (a); i <= (b); ++i)

void solve();

signed main () {
    clock_t beg = clock();
    cout << fixed << setprecision(15);
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    #endif 
    int t = 1; 
    // cin >> t;    
    int tt = t;
    while (t--) {
        // cout << "Case #" << tt - t << ": "; 
        solve();
    }
    cerr << "\nExecution time: " << (clock() - beg) / 1000 << '\n';
    return 0;
}
void solve() {  
    long double a, b;
    cin >> a >> b;
    cout << (int) (a * b);
}       
    

Measured memory_bytes: 3748
import java.util.*;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
	int pre = sc.nextInt();
    int total = pre;
    for (int i = 0; i < N-2; i++) {
      int cur = sc.nextInt();
      total += Math.min(pre, cur);
      pre = cur;
    }
    total += pre;
    System.out.println(total);
  }
}

Measured memory_bytes: 21332
#B
S = input()
flag = False
if S == S[::-1]:
    if S[:(len(S)-1)//2] == S[:(len(S)-1)//2][::-1]:
        if S[(len(S)+3)//2-1:] == S[(len(S)+3)//2-1:][::-1]:
            flag = True
if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
// #define INPUT_OUTPUT { \
//     freopen("input.txt","r",stdin); \
//     freopen("output.txt","w",stdout); \
// }
void solve(){
    int x,y,z;
    cin >> x >> y >> z ;
    swap(x,y);
    swap(x,z);
    cout << x << " " << y << " " << z ; 
}
int main(){
    // INPUT_OUTPUT ;
    int t = 1 ;
    //cin >> t ;
    while(t--) solve() ; 
    return 0 ;
}




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

#define NREP() for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define IPT(t, x) t ipt; cin >> ipt; x.push_back(ipt);
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
ll n, cnt, ans, tmp, sum, a, b, c, d, k, m, h, w, q, x, y;
string s, t;

int main() {
    ll s;
    cin >> k >> s;
    ans = 0;
    for (int i = 0; i <= k; ++i) {
        for (int j = 0; j <= k; ++j) {
            int l = s - i - j;
            if (0 <= l && k >= l && i + j + l == s) ans++;
        }
    }

    MSG(ans)
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3123;
double pi[MAXN], dp[MAXN];
int main() {
    int n, m, k;
    scanf("%d", &n);
    for (int i = 1; i<=n; ++i) {
        scanf("%lf", pi+i);
    }
    for (int i = n+1>>1; i<=n; ++i) dp[i] = 1.;
    for (int i = 1; i<=n; ++i) {
        for (int h = 0; h<=n-i; ++h) {
            dp[h] = pi[i]*dp[h+1]+(1.-pi[i])*dp[h];
        }
    }
    printf("%.9lf\n", dp[0]); 
}


Measured memory_bytes: 256
def Get_leafs_list(T, p):
    l = p.l
    ans = []
    while(T[l].r != -1):
        ans.append(T[l].r)
        l = T[l].r
    return ans

def rec(T,node, p):
    T[node].d = p
    if(T[node].r != -1):
        rec(T,T[node].r, p)
    if(T[node].l != -1):
        rec(T,T[node].l, p+1)


class Node():
    def __init__(self,i):
        self.p = -1
        self.l = -1
        self.r = -1
        self.d = 0
        self.n = i

    def Get_leafs_list(self,T):
        l = self.l
        if l != -1:
            ans = [l]
        else:
            ans = []
        while(T[l].r != -1):
            ans.append(T[l].r)
            l = T[l].r
        return ans


    def print_ans(self):
        print("node",self.n, end=": ")
        print("parent =",self.p, end=", ")
        print('depth =',self.d, end=", ")
        if self.l == -1 and self.p != -1:
            print('leaf, []')
            return
        else:
            if self.p == -1:
                print("root",end=", ")
            else :
                print("internal node",end=", ")
            ans = self.Get_leafs_list(T)
            print(ans)
T = []
n = int(input())
for i in range(0,n):
    T.append(Node(i))

for i in range(0,n):
    data = [int(x) for x in input().split()]
    k = data[0]
    if(data[1] != 0):   # node has leafs
        for j in range(0,data[1]):  #leafs
            if j == 0:
                T[k].l = data[2]
            else:
                T[l].r = data[2+j]
            l = data[2+j]
            T[l].p = data[0]
#get root 
for x in range(0,n):
    if(T[x].p == -1):
        root = x
        break
try:
    rec(T,root,0)

except:
    for i in range(1,n):
        T[i].d = 1

for x in T:
    x.print_ans()

Measured memory_bytes: 48980
#include<iostream>
#include<vector>
#include<string>
#define N 50001
using namespace std;

int main() {
	vector<bool>sosuu(N, true);
	sosuu[0] = sosuu[1] = false;
	for (int b = 2; b < N; b++) {
		if (sosuu[b]) {
			for (int c = b * 2; c < N; c += b)sosuu[c] = false;
		}
	}
	int d;
	while (cin >> d) {
		d++;
		int s = 0;
		for (int e = 2; e <= d; e++) {
			if (sosuu[e] && sosuu[d - e])s++;
		}
		cout << s << endl;
	}
}

Measured memory_bytes: 3084
/* C++14 (Clang 3.8.0) for AtCoder */

#include <iostream>
#include <vector>
#include <string>
// #include <cmath>
// #include <math.h>
// #include <map>
// #include <algorithm>

namespace AtCoder {
	using Str = std::vector<std::string>;
	using Num = std::vector<int>;
	using BigNum = std::vector<long long>;
	using DecNum = std::vector<double>;

	class InputData {
	public:
		void getInput(void);
		void skipInput(void);
		Str getStr(void);
		Num getNum(void);
		BigNum getBigNum(void);
		DecNum getDecNum(void);
	private:
		Str str;
		Num num;
		BigNum bNum;
		DecNum dNum;
	};
	Str AtCoder::InputData::getStr(void) {
		return this->str;
	}
	Num AtCoder::InputData::getNum(void) {
		return this->num;
	}
	BigNum AtCoder::InputData::getBigNum(void) {
		return this->bNum;
	}
	DecNum AtCoder::InputData::getDecNum(void) {
		return this->dNum;
	}
	void AtCoder::InputData::skipInput(void) {
		std::string buf = "";
		std::getline(std::cin, buf);
	}
	void AtCoder::InputData::getInput(void) {
		this->str.clear();
		this->num.clear();
		this->bNum.clear();
		this->dNum.clear();

		std::string buf = "", row = "";
		std::getline(std::cin, buf);
		for (unsigned int i = 0; i < buf.size(); i++) {
			if (' ' == buf[i]) {
				this->str.push_back(row);
				this->num.push_back(std::atoi(row.c_str()));
				this->bNum.push_back(std::atoll(row.c_str()));
				row = "";
			} else {
				row += buf[i];
			}
		}
		this->str.push_back(row);
		this->num.push_back(std::atoi(row.c_str()));
		this->bNum.push_back(std::atoll(row.c_str()));
		this->dNum.push_back(std::atof(row.c_str()));
	}

	class Ans {
	public:
		void showResult(void);
		void increment(void);
		void increment(long long);
		void decrement(void);
		void decrement(long long);
		long long getResult(void);
	private:
		long long result;
	};
	void Ans::showResult(void) {
		printf("%lld\n", this->result);
	}
	void AtCoder::Ans::increment(void) {
		this->result++;
	}
	void AtCoder::Ans::increment(long long value) {
		this->result += value;
	}
	void AtCoder::Ans::decrement(void) {
		this->result--;
	}
	void AtCoder::Ans::decrement(long long value) {
		this->result -= value;
	}
	long long AtCoder::Ans::getResult(void) {
		return this->result;
	}

	void exp(std::string* str,  Str* newStr) {
		std::string pre = *str;
		newStr->clear();
		for (unsigned int i = 0; i < pre.length(); i++) {
			newStr->push_back(pre.substr(i, 1));
		}
	}
}

int main(void) {

	AtCoder::InputData* data = new AtCoder::InputData();
	// data->skipInput();
	data->getInput();

	AtCoder::Str str = data->getStr();
	AtCoder::Str nstr;

	AtCoder::exp(&str[0], &nstr);

	if ("s" == nstr[nstr.size() - 1]) {
		printf("%ses\n", str[0].c_str());
	} else {
		printf("%ss\n", str[0].c_str());
	}


	delete(data);

	return 0;
}


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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

typedef long long LL;
typedef pair<int, int> pii;

const int INTINF = 1e9;
const LL LLINF = 1e18;

void solve()
{
    int N;
    cin >> N;
    vector<LL> A(N);
    REP0(i, N)
    {
        cin >> A[i];
        A[i] -= (i + 1);
    }
    sort(A.begin(), A.end());

    LL cost = 0;
    LL b = (N % 2 == 1 ? A[N / 2] : (A[N / 2 - 1] + A[N / 2]) / 2);
    REP0(i, N)
    {
        cost += abs(A[i] - b);
    }

    cout << cost << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}

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

#define PB          push_back
#define PF          push_front
#define MP          make_pair
#define FI          first
#define SE          second
#define SIZE( A )   int( ( A ).size( ) )
#define ALL( A )    ( A ).begin( ), ( A ).end( )
#define ALLR( A )   ( A ).rbegin( ), ( A ).rend( )

using namespace std;

typedef long long           ll;
typedef unsigned long long  ull;
typedef long double         lf;
typedef pair< int, int >    pii;
typedef pair< ll, ll >      pll;
typedef vector< bool >      vb;
typedef vector< lf >        vd;
typedef vector< ll >        vll;
typedef vector< int >       vi;
typedef vector< pii >       vpii;

const int MAXN = int( 1e5 )+10;
const int MOD  = int( 360 );
const int oo   = INT_MAX;
const lf EPS = 1e-9;
const lf PI = acos(-1.0);

struct pt {
  lf x, y;
  pt( ) { }
  pt( lf x, lf y ) : x( x ), y ( y ) { }
};

inline lf x( pt P ) { return P.x; }
inline lf y( pt P ) { return P.y; }

istream& operator >> ( istream& in, pt& p ) {
  lf x,y; in >> x >> y;
  p = pt(x,y); return in;
}

ostream& operator << ( ostream& out, const pt& p ) {
  out << double(p.x) << " " << double(p.y);
  return out;
}

pt operator + ( const pt& A, const pt& B ) {
  return pt( x(A)+x(B), y(A)+y(B) );
}

pt operator - ( const pt& A, const pt& B ) {
  return pt( x(A)-x(B), y(A)-y(B) );
}

pt operator * ( const lf& B, const pt& A ) {
  return pt( x(A)*B, y(A)*B );
}

pt operator * ( const pt& A, const lf& B ) {
  return pt( x(A)*B, y(A)*B  );
}

pt operator * ( const pt& A, const pt& B ) {
  return pt( x(A)*x(B)-y(A)*y(B), x(A)*y(B)+y(A)*x(B) );
}

pt operator / ( const pt& A, const lf& B ) {
  return pt( x(A)/B, y(A)/B );
}

inline lf dot( pt A, pt B ) {
  return x(A)*x(B) + y(A)*y(B);
}

inline lf cross( pt A, pt B ) {
  return x(A)*y(B) - y(A)*x(B);
}

inline lf norm( pt A ) {
  return x(A)*x(A) + y(A)*y(A);
}

inline lf abs( pt A ) {
  return sqrt( norm(A) );
}

inline pt exp( pt A ) {
  return pt( exp( x(A) )*cos( y(A) ), exp( x(A) )*sin( y(A) ) ) ;
}

inline bool same ( lf a, lf b ) {
  return a+EPS > b && b+EPS > a;
}

inline bool samePt ( pt A, pt B ) {
  return same ( x(A), x(B) ) && same ( y(A), y(B) );
}

inline pt rot ( pt p, lf ang ) { return p * exp ( pt(0,1) * ang ); }

pt c,p,p1,p2;
lf r;

int main( ) {

  #ifdef LOCAL
    freopen( "input", "r", stdin );
    //freopen( "output", "w", stdout );
  #else
    //freopen( "input", "r", stdin );
    //freopen( "output", "w", stdout );
    ios_base::sync_with_stdio( 0 );
    cin.tie( 0 );
  #endif
  cout << fixed << setprecision(8);
  while( cin >> p >> c >> r ) {
    lf d = abs( c-p );
    lf b = acos(r/d);
    pt u = (p-c)/d;
    p1 = c + rot( u, b )*r;
    p2 = c + rot( u, -b )*r;
    if( x(p1) > x(p2)+EPS ) swap( p1, p2 );
    if( same( p1.x, p2.x ) ) {
      if( y(p1) > y(p2)+EPS ) swap( p1, p2 );
    }
    cout << p1 << '\n' << p2 << '\n';
  }
  return 0;
}

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

namespace Atcoder00
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b;
            int[] inputintArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            a = inputintArray[0];
            b = inputintArray[1];
            Console.WriteLine(a * b);
        }
    }
}

Measured memory_bytes: 28192
#include <bits/stdc++.h>
using namespace std;
 
int main () {
  int N, K, Q;
  cin >> N >> K >> Q;
  vector<int> memo(N, 0);
  for (int i = 0; i < Q; i++) {
    int A;
    cin >> A;
    memo.at(A - 1)++;
  }
  for (int i = 0; i < N; i++) {
    if (K - Q + memo.at(i) > 0) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 3788
#include<stdio.h>
#include<string.h>
#define LEN 100005

/* プロセスを表す構造体 */
typedef struct pp {
  char name[100];
  int t;
} P;

P Q[LEN];
int head, tail, n;

void enqueue(P x) {
  Q[tail] = x;
  tail = (tail + 1) % LEN;
}

P dequeue() {
  P x = Q[head];
  head = (head + 1) % LEN;
  return x;
}

int min(int a, int b) { return a < b ? a : b; }  /* 最小値を返す */

int main() {
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  /* 全てのプロセスをキューに順番に追加する */
  for ( i = 1; i <= n; i++ ) {
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head = 1; tail = n + 1;

  /* シミュレーション */
  while ( head != tail ) {
    u = dequeue();
    c = min(q, u.t);  /* q または必要な時間 u.t だけ処理を行う */
    u.t -= c;  /* 残りの必要時間を計算 */
    elaps += c;  /* 経過時間を計算 */
    if ( u.t > 0 ) enqueue(u);  /* 処理が完了していなければキューに追加 */
    else printf("%s %d\n", u.name, elaps);
  }

  return 0;
}


Measured memory_bytes: 11860
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define mp(a,b) make_pair((a),(b))
#define eq ==

typedef long long ll;
typedef complex<double> point;
typedef pair<int,int> pii;

// →↑←↓
const int dx[] = {1,0,-1,0};
const int dy[] = {0,-1,0,1};


const double EPS = 1e-9;

int main(){
    cout << fixed << setprecision(10);
    while(true){
        int n,w;
        cin >> n >> w;
        if(n == 0 and w == 0) break;
        vector<int> v(n);
        for(int i=0;i<n;i++) cin >> v[i];

        int nw = *max_element(all(v))/w + 1;
        vector<int> cnt(nw);
        for(int i=0;i<n;i++){
            cnt[v[i]/w]++;
        }
        int maxn = *max_element(all(cnt));
        double ret = 0;
        for(int i=0;i<nw;i++){
            ret += 1.0*cnt[i]/maxn * (1.0*(nw-i-1)/(nw-1));
        }
        ret += 0.01;

        cout << ret << endl;
    }
    return 0;
}

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

const ll MX = 1e18;

int main(){
	int n;
	cin >> n;
	ll ans = 1;
	bool ng = false;

	rep(i, n){
		ll a;
		cin >> a;
		if(a == 0){
			cout << 0 << endl;
			return 0;
		}
		if(ng || (MX+1)/ans < a ||ans*a > MX) ng = true;
		ans *= a;
	}
	if(ng) cout << -1 << endl;
	else cout << ans << endl;
	return 0;
}

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

typedef long long ll;
typedef long double ld;

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

    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;

    cout << char(s1[0] - 32) << char(s2[0] - 32) << char(s3[0] - 32) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int A,B,C,X,YenA,YenB,YenC,Pattern=0;//YenA,B,Cは使う硬貨の枚数
  scanf("%d %d %d %d",&A,&B,&C,&X);    //Patternは組み合わせの総数
  for(YenA=0;YenA<=A;YenA++)
  {
    for(YenB=0;YenB<=B;YenB++)
    {
      for(YenC=0;YenC<=C;YenC++)
      {
       if(YenA*500+YenB*100+YenC*50==X)
       {
        Pattern++; 
       }
      }
    }
  }
    printf("%d\n",Pattern);
 return 0; 
}

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

template<class T>
using vec = std::vector<T>;

int rec(int S, int N, int K, int money, vec<int> &a, vec<int> &b)
{
    if (__builtin_popcount(S) == K) {
        return money;
    }
    
    int res = 0;
    for (int i = 0; i < N; i++) {
        if (S >> i & 1) continue;
        int m = std::min(b[i], money);
        res = std::max(res,
                  rec(S | (1 << i), N, K, money - m, a, b) + a[i] * m);
    }
    return res;
}

int main()
{
    int N, M, K;
    std::cin >> N >> M >> K;
    
    vec<int> a(N), b(N);
    for (int i = 0; i < N; i++) {
        std::cin >> a[i];
    }
    
    for (int i = 0; i < N; i++) {
        std::cin >> b[i];
    }
    
    std::cout << rec(0, N, K, M, a, b) << std::endl;
    return 0;
}

Measured memory_bytes: 3076
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <tuple>

#define DEBUG(x) cout<<#x<<": "<<x<<endl

using namespace std;

string calc(long long N){

	string s = "";
	if( N == 0) return s+='0';


	long long d = 1;
	while(d <= N){
		long long c = ((N+1)/(2*d)) * d;
		long long r = (N+1) % (2*d);
		if( r > d ){
			c += r - d;
		}
		if(c % 2 == 0){
			s += '0';
		} else {
			s += '1';
		}
		d *= 2;
	}

	return s;
}

int main(){

	long long A, B;
	string As, Bs;

	cin >> A >> B;

	As = calc(A-1);
	Bs = calc(B);

	string ans;

	for(int i = 0; i < As.size(); i++){
		if(As[i] == Bs[i]) Bs[i] = '0';
		else Bs[i] = '1';
	}

	long long a = 0, x = 1;
	for(int i = 0; i < Bs.size(); i++){
		if(Bs[i] == '1') a += x;
		x *= 2;
	}

	cout << a << endl;

	return 0;
}


Measured memory_bytes: 256
from itertools import product as p
n=input()

ans=0

for j in range(1,len(n)+1):
  for i in p(["3","5","7"],repeat=j):
    s="".join(i)
    t=int(s)
    if "3" in s and "5" in s and "7" in s and t<=int(n):
      ans+=1

print(ans)

Measured memory_bytes: 44528
import numpy as np

N,M,X = list(map(int, input().split()))
books = np.array([list(map(int, input().split())) for i in range(N)])

borders = np.ones(M+1) * X
borders[0] = 0
maxi = 2 ** N

init_cost = 10**8
cost = init_cost
for i in range(1,maxi):
    bits = [j for j in range(N) if (i >> j &1)]
    res = sum(books[bits])

    if np.all(np.where(res[1:] >= X, True, False)):
        cost = min(res[0],cost)

if cost == init_cost:
    print(-1)
else:
    print(cost)


Measured memory_bytes: 27404