akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

class MainClass
{
    public static void Main(string[] args)
    {
        var input = Console.ReadLine().Split(' ');

        var A = long.Parse(input[0]);
        var B = long.Parse(input[1]);

        var count = PrimeFactors(Gcd(A, B)).Distinct().Count() + 1;

        Console.WriteLine(count);
    }

    // 最大公約数を求める
    public static long Gcd(long a, long b)
    {
        if (a < b)
            // 引数を入替えて自分を呼び出す
            return Gcd(b, a);
        while (b != 0)
        {
            var remainder = a % b;
            a = b;
            b = remainder;
        }
        return a;
    }

    // 素因数分解
    public static IEnumerable<long> PrimeFactors(long n)
    {
        long i = 2;
        long tmp = n;

        while (i * i <= n) //※1
        {
            if (tmp % i == 0)
            {
                tmp /= i;
                yield return i;
            }
            else
            {
                i++;
            }
        }
        if (tmp != 1) yield return tmp;//最後の素数も返す
    }
}




Measured memory_bytes: 13152
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
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; }

int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 998244353;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

ll dp[3003][3003];

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    dp[A][B] = 1;
    for(int h=A;h<C+1;h++)for(int w=B;w<D+1;w++){
        if(A<h)dp[h][w] += dp[h-1][w]%mod * w;
        dp[h][w] %= mod;
        if(B<w)dp[h][w] += dp[h][w-1]%mod * h;
        dp[h][w] %= mod;
        if(A < h && B < w ){
            dp[h][w] -= dp[h-1][w-1]%mod * (w-1) * (h-1);
            dp[h][w] %= mod;
        }
    }
    cout << (dp[C][D] + mod)% mod << endl;
}

Measured memory_bytes: 73868
/*Template by hemnath_d(Enlightened by chamow)*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define vec vector<ll>
#define pll pair<ll,ll>
#define fastread ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fx first
#define sx second
#define inf 100000000000000
#define minf -100000000000000
#define maxi 100005

int main()
{
    fastread;
    int n,k;
    cin>>n>>k;
    int arr[n + 1];
    memset(arr, 0, sizeof(arr));
    for(int i = 0; i < k; i++) {
        int d;
        cin>>d;
        for(int j = 0; j < d; j++) {
            int snuke;
            cin>>snuke;
            arr[snuke]++;
        }
    }
    int ans = 0;
    for(int i = 1; i <= n; i++) {
        if(arr[i] == 0) {
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3652
X,Y,A,B,C=map(int,input().split())
p=list(map(lambda x:(int(x),0),input().split()))
q=list(map(lambda x:(int(x),1),input().split()))
r=list(map(lambda x:(int(x),2),input().split()))
l=p+q+r
l.sort(reverse=1)
a=0
x,y=0,0
for i in l[:X+Y]:
    if i[1]==0:
        x+=1
    elif i[1]==1:
        y+=1
    a+=i[0]
if x>X:
    k=x-X
    t=X+Y-1
    while x>X:
        if l[t][1]==0:
            a-=l[t][0]
            x-=1
        t-=1
    t=X+Y
    while k>0:
        if l[t][1]!=0:
            a+=l[t][0]
            k-=1
        t+=1
elif y>Y:
    k=y-Y
    t=X+Y-1
    while y>Y:
        if l[t][1]==1:
            a-=l[t][0]
            y-=1
        t-=1
    t=X+Y
    while k>0:
        if l[t][1]!=1:
            a+=l[t][0]
            k-=1
        t+=1
print(a)

Measured memory_bytes: 42600
import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.Maybe

readInt = fst . fromJust . BS.readInt

readIntList = map readInt . BS.words

getInt = readInt <$> BS.getLine

getIntList = readIntList <$> BS.getLine

simulate [] ds = "YES"
simulate ts [] = "NO"
simulate (t : ts) (d : ds)
  | t == d = simulate ts ds
  | t < d = "NO"
  | t > d = simulate (t : ts) ds

main = do
  n <- getInt
  ds <- getIntList
  m <- getInt
  ts <- getIntList
  let ds' = sort ds
  let ts' = sort ts
  putStrLn $ simulate ts' ds'


Measured memory_bytes: 61952
n=int(input())
a=list(map(int, input().split()))
q=int(input())
f=[0]*(100001)
s=0
for i in a:
    f[i]+=1
    s+=i
for _ in range(q):
    b,c=map(int, input().split())
    s-=f[b]*b
    f[c]+=f[b]
    s+=c*f[b]
    f[b]=0
    print(s)


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

int main(void){
  int st = 0;
  int N; cin >> N;
  bool flg = true;
  for(int i = 0; i < N; i++){
    string str; cin >> str;
    if(str == "A"){
      st++;
    }else{
      if(st <= 0){
        flg = false;
        break;
      }
      st--;
    }
  }
  if(flg == false || st != 0){
    cout << "NO" << endl;
  }else{
    cout << "YES" << endl;
  }
}



Measured memory_bytes: 3156
#include<bits/stdc++.h> 
using namespace std;
using ll = long long;

#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);

int main() {
    fast_io;
    vector<int> arr;
    int n;
    cin>>n;

    int mn=0, mx=0;
    for(int i=0;i<n;i++) {
        int num;
        cin>>num;
        arr.push_back(num);

        mn=min(mn,num);
        mx=max(mx,num);
    }

    int ans=numeric_limits<int>::max();
    for(int i=mn;i<=mx;i++) {
        int tmp=0;
        for(int j=0;j<n;j++) {
            tmp+=((pow(i-arr[j],2)));
        }
        ans=min(ans,tmp);
    }
    cout<<ans<<endl;


}




Measured memory_bytes: 3624
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };



signed main() {
	string s1, s2;

	cin >> s1 >> s2;

	cout << s2 <<s1 << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;


int tmp1, tmp2, ans;
int n;
string s;

int main() {

	cin >> n >> s;

	REP(i, 1, n - 1) {
		int cnt = 0;
		rep(j, 26) {
			bool judge1 = false;
			bool judge2 = false;
			rep(k, i) {
				if (s[k] - 'a' == j) {
					judge1 = true;
					break;
				}
			}
			REP(k, i, n) {
				if (s[k] - 'a' == j) {
					judge2 = true;
					break;
				}
			}
			if (judge1 && judge2)cnt++;
		}
		ans = max(cnt, ans);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import sys
N, M, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

z1 = max(x) + 1
z2 = min(y)

if X < z1 and z1 < Y:
    if X < z2 and z2 < Y:
        if z1 <= z2:
            print ('No War')
            sys.exit()
print ('War')


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

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

  string S;
  cin>>S;
  int N=S.size();
  for(int i=0;i<N;i++){
    if(S[i]=='?')cout<<"D";
    else cout<<S[i];
  }

  return 0;
}


Measured memory_bytes: 3748
#include <stdio.h>
int main(void){
	int a, b;
	while(1){
		scanf("%d %d", &a, &b);
		if(((1<=a)&&(a<=100))&&((1<=b)&&(b<=100))){
			break;
		}
	}
	if(a<=b){
		printf("unsafe");
	}else{
		printf("safe");
	}
	return 0;
}

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

const int MAX_N = 2 * 131072;
int o[MAX_N * 2 - 1], e[MAX_N * 2 - 1];

void update(int* arr, int n, int i, int x) {
    i += MAX_N - 1;
    arr[i] = x;
    while (i > 0) {
        i = (i - 1) / 2;
        arr[i] = std::min(arr[i * 2 + 1], arr[i * 2 + 2]);
    }
}

// minimum value of [a, b)
int query(int* arr, int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return INT_MAX;
    if (a <= l && r <= b) return arr[k];
    else {
        int vl = query(arr, a, b, k * 2 + 1, l, (l + r) / 2);
        int vr = query(arr, a, b, k * 2 + 2, (l + r) / 2, r);
        return std::min(vl, vr);
    }
}

int main() {
    int n;
    std::cin >> n;
    std::vector<int> p(n + 1), index(n + 1);
    for (int i = 0; i < 2 * MAX_N - 1; i++) o[i] = e[i] = INT_MAX;
    for (int i = 0; i < n; i++) {
        std::cin >> p[i];
        index[p[i]] = i;
        if (i % 2) update(o, MAX_N, i, p[i]);
        else update(e, MAX_N, i, p[i]);
    }

    // (minimum even-indexed value, left index, right index)
    std::priority_queue<std::tuple<int, int, int>, std::vector<std::tuple<int, int, int>>, std::greater<>> que;
    que.emplace(query(e, 0, n, 0, 0, MAX_N), 0, n);
    std::deque<int> q;

    while (!que.empty()) {
        auto curr = que.top();
        auto v = std::get<0>(curr), l = std::get<1>(curr), r = std::get<2>(curr);
        // std::cout << v << " " << l << " " << r << std::endl;
        que.pop();
        if (r - l < 2) continue;
        q.push_back(v);
        auto s = query((l % 2 ? e : o), index[v], r, 0, 0, MAX_N);
        q.push_back(s);
        // std::cout << "\t" << index[v] << " " << index[s] << std::endl;

        que.emplace(query((l % 2 ? o : e), l, index[v], 0, 0, MAX_N), l, index[v]);
        que.emplace(query((index[v] % 2 ? e : o), index[v] + 1, index[s], 0, 0, MAX_N), index[v] + 1, index[s]);
        que.emplace(query((index[s] % 2 ? e : o), index[s] + 1, r, 0, 0, MAX_N), index[s] + 1, r);
    }

    for (auto& el : q) std::cout << el << " ";
    std::cout << std::endl;

    return 0;
}

Measured memory_bytes: 10904
#include<stdio.h>
#include<stdlib.h>
#include<memory.h>
#include<math.h>

int sprInput(char *retstr, char *str, int strnum)
{
	char buf[256]={};
	int h, i, j;

	i = 0;
	for(h=0;h<strnum;h++){
		memset(buf, '\0', sizeof(buf));
		j = 0;
		if (str[i] == '\0') break;
		while(str[i] != ' ' && str[i] != '\n' && str[i] != '\0')
		{
			buf[j] = str[i];
			i++;
			j++;
		}
		i++;
	}
	memcpy(retstr, buf, sizeof(buf));

	return (retstr[0] == '\0' ? 0 : 1);
}

int main(int argc, char *argv[])
{
	int x, i = 0, y=0;
	char str[256]={};
	char buf[256]={};



	while( fgets(str, 256, stdin) != '\0'){
		i++;
		sprInput( buf, str, 1 );
		x = atoi( buf );
		sprInput( buf, str, 2 );
		y = atoi( buf );
		if( x == 0 && y == 0 ){
			break;
		}
		if( x <= y )
		{
			printf( "%d %d\n", x, y );
		}else{
			printf("%d %d\n", y , x);
		}
	}
	return 0;
}

Measured memory_bytes: 524
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main() {
  int n, m, x, y;
  cin >> n >> m >> x >> y;
  int mx = -1e9;
  int mn = 1e9;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    mx = max(mx, x);
  }
  for (int i = 0; i < m; i++) {
    int y;
    cin >> y;
    mn = min(mn, y);
  }
  for (int i = x + 1; i <= y; i++) {
    if (mx < i && i <= mn) {
      puts("No War");
      return 0;
    }
  }
  puts("War");
}


Measured memory_bytes: 256
#include <iostream>
#include <stack>
using namespace std;
const int MAX = 10;

stack<int> path;
int edge[MAX][MAX];

bool isInPath(int k){ //pathにkが含まれるかを判定
  stack<int> tmpStack;
  tmpStack = path;
  while(!(tmpStack.empty())){
    if(k == tmpStack.top()) return true;
    else tmpStack.pop();
  }
  return false;
}

int countPath(int k,int N){
  int sum = 0;
  if(path.size()==N){
    path.pop();
    return 1;
  }
  for(int i=0;i<N;i++){
    if(edge[k][i]==1 && !(isInPath(i))){
      path.push(i);
      sum += countPath(i,N);
    }
  }
  path.pop();
  return sum;
}

int main(){
  int N,M; 
  cin >> N >> M;
  
  for(int i=0;i<N;i++) //edgeの初期化
    for(int j=0;j<N;j++) edge[i][j] = 0;

  for(int i=0;i<M;i++){ //edgeの入力. ただし頂点は0からスタート
    int a,b;
    cin >> a >> b;
    edge[a-1][b-1] = 1;
    edge[b-1][a-1] = 1;
  }
  path.push(0);
  cout << countPath(0,N) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using Edge = pair<int, ll>;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<Edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

ll dp[1001000][2]{};

int main() {
	string s; cin >> s;
	s = "0" + s;
	int n = s.size();

	for (int i = 0; i <= n; ++i)
		for (int j = 0; j < 2; ++j)
			dp[i][j] = INF;

	dp[0][0] = 0;

	for (int i = 0; i < n; ++i) {
		int c = s[i] - '0'; 
		dp[i + 1][0] = min(dp[i + 1][0], dp[i][0] + c);          // 繰り下がりなし + 繰り下がりなし
		dp[i + 1][1] = min(dp[i + 1][1], dp[i][0] + c + 1);      // 繰り下がりなし + 繰り下がり発生
		dp[i + 1][0] = min(dp[i + 1][0], dp[i][1] + 10 - c);     // 繰り下がりあり + 繰り下がりさせない
		dp[i + 1][1] = min(dp[i + 1][1], dp[i][1] + 10 - c - 1); // 繰り下がりあり + 繰り下がり発生
	}
	cout << dp[n][0] << endl;

	return 0;
}

Measured memory_bytes: 16944
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int N, M;
  cin >> N;
  vector<pair<string, int>> v;
  for(int i = 0; i < N; i++) {
    string tmp;
    cin >> tmp;
    bool flag = false;
    for(int j = 0; j < v.size(); j++) {
      if(v[j].first == tmp) {
        v[j].second++;
      	flag = true;
        break;
      }
    }
    if(!flag) v.push_back(make_pair(tmp, 1));
  }
  cin >> M;
  for(int i = 0; i < M; i++) {
    string tmp;
    cin >> tmp;
    bool flag = false;
    for(int j = 0; j < v.size(); j++) {
      if(v[j].first == tmp) {
        v[j].second--;
      	flag = true;
        break;
      }
    }
    if(!flag) v.push_back(make_pair(tmp, -1));
  }
  
  int ans = 0;
  for(int i = 0; i < v.size(); i++) ans = max(ans, v[i].second);
  cout << ans << endl;
  
  return 0;
}
    
  

Measured memory_bytes: 256
string = input()
sep = [int(string[i: i+2]) for i in range(0, len(string), 2)]
if (12 >= sep[0] and sep[0] >= 1) and (12 >= sep[1] and sep[1] >= 1):
    print("AMBIGUOUS")
elif (sep[0] >= 13 or sep[0] == 0) and (sep[1] <=12 and sep[1] >= 1):
    print("YYMM")
elif(sep[0] <= 12 and sep[0] >= 1) and (sep[1] >= 13 or sep[1] == 0):
    print("MMYY")
else:
    print("NA")    


Measured memory_bytes: 3064
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int min = Integer.MAX_VALUE;
		int total = 0;
		for (int i = 1; i <= n; i++) {
		    total += sc.nextInt();
		    min = Math.min(min, total / i);
		}
		System.out.println(min);
	}
}



Measured memory_bytes: 26388
int main(void){
  int n,b,a[200000] = {0};
  int i;
  
  scanf("%d",&n);
  for(i = 0; i < n-1; i++){
    scanf("%d",&b);
    a[b-1] ++;
  }
  
  for(i = 0; i < n; i++){
   	printf("%d\n",a[i]);
  }
  
}
  
  
  
  

Measured memory_bytes: 2492
n, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)

x = 1
c = Array.new(n+1)
c[1] = 0

while k > 0
    y = a[x-1]
    
    if c[y]
        k -= 1
        k %= c[x] + 1 - c[y]
        x = a[x-1]
        while k > 0
            x = a[x-1]
            k -= 1
        end
        break
    end

    c[y] = c[x] + 1
    x = y
    k -= 1
end

puts x

Measured memory_bytes: 28984
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <functional>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr int inf = 1000000000;
constexpr ll INF = 1000000000000000000;
template <typename T> bool chmin(T &x, const T &y) {if (x > y) {x = y; return true;} return false;}
template <typename T> bool chmax(T &x, const T &y) {if (x < y) {x = y; return true;} return false;}

struct RollingHash {
    static constexpr int base1 = 1007, base2 = 2009;
    static constexpr int mod1 = 1000000007, mod2 = 1000000009;
    vector<ll> hash1, hash2, pow1, pow2;
    RollingHash (const string &S) {
        int length = SZ(S);
        hash1.assign(length + 1, 0);
        hash2.assign(length + 1, 0);
        pow1.assign(length + 1, 1);
        pow2.assign(length + 1, 1);
        rep(i, length) {
            hash1[i + 1] = (hash1[i] * base1 + S[i]) % mod1;
            hash2[i + 1] = (hash2[i] * base2 + S[i]) % mod2;
            pow1[i + 1] = pow1[i] * base1 % mod1;
            pow2[i + 1] = pow2[i] * base2 % mod2;
        }
    }
    pair<ll, ll> get(int l, int r) const {
        ll res1 = hash1[r] - hash1[l] * pow1[r - l] % mod1;
        if (res1 < 0) res1 += mod1;
        ll res2 = hash2[r] - hash2[l] * pow2[r - l] % mod2;
        if (res2 < 0) res2 += mod2;
        return pair<ll, ll>{res1, res2};
    }
};

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    
    RollingHash RH(S);
    int left = 0, right = N;
    while (right - left > 1) {
        int mid = (right + left) / 2;
        set<pair<ll, ll>> st;
        deque<pair<ll, ll>> dq;
        bool judge = false;
        rep(i, N - mid + 1) {
            auto x = RH.get(i, i + mid);
            dq.push_back(x);
            if (SZ(dq) > mid) {
                st.insert(dq.front());
                dq.pop_front();
            }
            if (st.count(x)) judge = true;
        }
        if (judge) left = mid;
        else right = mid;
    }
    cout << left << "\n";
    return 0;
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define INF 1000000000000 //10^12

int main(){
    double r;
    cin >>r;
    cout << r*2*M_PI<<endl;
}

Measured memory_bytes: 3808
#include <stdio.h>
int main(void)
{
	int A, B, C, D, P, X, Y;
	scanf("%d %d %d %d %d", &A,&B,&C,&D,&P);
	X = A * P;
	if(P<=C)Y=B;
	else{
		P=P-C;
		Y=D*P+B;
	}
	if(X < Y)
	printf("%d\n",X);
	else
	printf("%d\n",Y);
	return 0;
}


Measured memory_bytes: 2720
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <climits> 
#include <time.h>

int main()
{
 //clock_t start=clock();
    long A,B,N;
    std::cin >> A >> B >> N;
    long result=0; 
    long temp1=std::floor((double)(A*(N-1))/(double)B)-A*(std::floor((double)(N-1)/(double)B));
    long temp2=std::floor((double)(A*(N))/(double)B)-A*std::floor((double)(N)/(double)B);
    result=std::max(temp1,temp2);
    if(N>=B){
        long temp3=std::floor((double)(A*(B-1))/(double)B);
        result=std::max(result,temp3);
    }
    std::cout << result << std::endl;
    //clock_t end=clock();
//std::cout << static_cast<double>(end-start)/CLOCKS_PER_SEC * 1000.0 << std::endl;
    return 0;
}

Measured memory_bytes: 3636
#include<iostream>

#include<set>

int main(){
        std::multiset<int> st;
        int h;
        for(int i=0;i<10;i++){
                std::cin >> h;
                st.insert(h);
        }
        std::multiset<int>::reverse_iterator itr = st.rbegin();
        for(int i=0;i<3;i++){
                std::cout << *itr << std::endl;
                *itr++;
        }
        return 0;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define vsort(v) sort(v.begin(), v.end())
#define ll long long
#define rep(i, s, g) for (ll i = (s); i < (g); i++)
#define MOD 1000000007
using namespace std;

int a[12][12];

int main()
{
  //input
  ll N, M, X; 
  cin >> N >> M >> X;
  vector<int> c(N);
  for (int i = 0; i < N; i++) {
  	cin >> c[i];
    for (int j = 0; j < M; j++) {
    	cin >> a[i][j];
    }
  }
  
  int ans = MOD;
  for (int s = 0; s < (1 << N); s++) {
  	int cost = 0;
    vector<int> d(M);
    for (int i = 0; i < N; i++) {
    	if ((s >> i) & 1) {
        	cost += c[i];
          	for (int j = 0; j < M; j++) {
            	d[j] += a[i][j];
            }
        }
      	bool ok = true;
      	for (int j = 0; j < M; j++) {
        	if (d[j] < X) ok = false;
        }
      	if (ok) ans = min(ans, cost);
    }    
  }
  if (ans == MOD) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3604
#include<cstdio>
const int mod=1000000007;
int main(){
  int n,m;scanf("%d%d",&n,&m);
  if(n>m)n^=m^=n^=m;
  if(m-n>1)printf("0\n");
  else{
    int ans=1;
    for(int i=1;i<=n;++i)ans=ans*1ll*i%mod;
    for(int i=1;i<=m;++i)ans=ans*1ll*i%mod;
    if(m==n)ans=ans*2ll%mod;
    printf("%d\n",ans);
  }
  return 0;
}


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

const int mod = 1e9 + 7;

template <typename T> inline bool chmax(T &a, const T &b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> inline bool chmin(T &a, const T &b) {
    if(a <= b) return false;
    a = b;
    return true;
}

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

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

    int n, a, b;
    char s;
    cin >> n >> a >> b;
    a += b;
    rep(i, n) {
        cin >> s;
        if(s == 'a' && a > 0) {
            cout << "Yes\n";
            a--;
        } else if(s == 'b' && a > 0 && b > 0) {
            cout << "Yes\n";
            b--;
            a--;
        } else
            cout << "No\n";
    }
}

Measured memory_bytes: 640
def solve():
    N = int(input())
    cx = 0
    cy = 0
    ct = 0
    for i in range(N):
        ti,xi,yi = map(int,input().split())
        t = ti - ct
        x = abs(xi - cx)
        y = abs(yi - cy)
        if x + y > t:
            return 'No'
        if (x + y - t) % 2 != 0:
            return 'No'
        cx = xi
        cy = yi
        ct = ti
    return 'Yes'

print(solve())


Measured memory_bytes: 46312
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())

if v <= w:
    print("NO")
else:
    x = abs(a - b)
    y = x / (v - w)
    if y <= t:
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 9184
#include<stdio.h>
#include<algorithm>
using namespace std;
int n, w[110], s;
int main(){
    int i;
    while(1){
        scanf("%d",&n);
        if(!n)break;
        for(i=1;i<=n;i++)scanf("%d",&w[i]);
        sort(w+1,w+n+1);
        s=0;
        for(i=2;i<n;i++)s+=w[i];
        s/=(n-2);
        printf("%d\n",s);
    }
}

Measured memory_bytes: 1044
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#solve
def solve():
    x = II()
    print(x^1)
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 76760
#include<bits/stdc++.h>
#define INP (1LL<<50)
using namespace std;
long long int dp[100100];
int main()
{
    int a,b,c,i,j;
    cin>>a>>b;
    int s[a];
    for(i=0;i<a;i++)
        cin>>s[i];
    for(i=0;i<a;i++)
    {
        dp[i]=INP;
    }
    dp[0]=0;
    for(i=0;i<a;i++)
    {
        for(j=i+1;j<=i+b;j++)
        {
            dp[j]=min(dp[j],dp[i]+abs(s[j]-s[i]));
        }
    }
    cout<<dp[a-1]<<endl;
    return 0;
}


Measured memory_bytes: 1408
fun main(args:Array<String>) {
    val (n,m) = readLine()!!.split(" ").map { it.toInt() }
    val shopList = (1..n).map { readLine()!!.split(" ").map { it.toLong() } }.sortedBy { it[0] }

    var ans = 0L
    var count = 0L
    for(shop in shopList) {
        val buyCount = Math.min(shop[1], (m - count).toLong())
        ans += buyCount*shop[0]
        count += buyCount
        if(count >= m) {
            break
        }
    }
    println(ans)
}


Measured memory_bytes: 85660
#include <iostream>

using namespace std;

int main(void){
  int x, n;
  int ans=0;
  while(1){
    cin >> n >> x;
    if(n == 0 && x == 0)break;
    for(int i=1; i<=n; i++){
      for(int j=i+1; j<=n; j++){
        for(int k=j+1; k<=n; k++){
          if(i+j+k == x && i!=j && j!=k && k!=i){
            ans++;
          }
        }
      }
    }
    cout << ans << endl;
    ans = 0;
  }
  return 0;
}


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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};


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

  int ans = 0;
  int r = 0, w = 0;
  for(auto c : s) {
    if(c == 'R') ++r;
    else ++w;
  }
  rep(i, r) {
    if(s[i] != 'R') ++ans;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3752
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

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

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int x, y, z, k;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> x >> y >> z >> k;

  vector<ll> a(x);
  vector<ll> b(y);
  vector<ll> c(z);

  REP(i, x) cin >> a[i];
  REP(i, y) cin >> b[i];
  REP(i, z) cin >> c[i];

  vector<ll> ab(x + y);

  REP(i, x) {
    REP(j, y) {
      ab.push_back(a[i] + b[j]);
    }
  }

  sort(ab.begin(), ab.end(), greater<ll>());

  vector<ll> abc((x + y) * z);
  REP(i, min((int)ab.size(), k)) {
    REP(j, z) {
      abc.push_back(ab[i] + c[j]);
    }
  }

  sort(abc.begin(), abc.end(), greater<ll>());
  REP(i, k) {
    cout << abc[i] << endl;
  }
}


Measured memory_bytes: 72624
#include <bits/stdc++.h>
using namespace std;
#define loop(i,a,n) for (ll i=a;i<n;i++)
#define loopm(i,a,n) for (ll i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define Graph(n) vector < vector < ll > > (n,vector < ll >(0,0))
#define tr(container,it)\
for(auto it=container.begin();it!=container.end();it++)
#define SZ(x) ((int)(x).size())
typedef vector<long long> VI;
typedef long long ll;
typedef vector < vector < ll > > VII;
typedef pair<ll,ll> PII;
typedef double db;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll k,a,b;
    cin>>k>>a>>b;
    ll numa=(a/k)*k;
    ll numb=(b/k)*k;
    if(numa==a||numa<numb)
    {
        cout<<"OK";
    }
    else
        cout<<"NG";
}


Measured memory_bytes: 3640
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var swr = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(swr);
            var N = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Trim().Split(' ').Select(n => int.Parse((n))).ToArray();
            var ans = -1;
            var b = 1;
            for (int i = 0; i < N; i++)
            {

                if (a[i] == b)
                {
                    b++;
                }
            }

            if (b == 1)
            {
                ans = -1;
            }
            else
            {
                ans = N - b + 1;
            }
            Console.WriteLine(ans);
            Console.Out.Flush();
        }

    }
}

Measured memory_bytes: 35676
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<stdlib.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
using namespace std;
const long long M=1000000007ll;
long long w,h,x,y,flag;
int main()
{
	cin>>w>>h>>x>>y;
  	if(x*2==w&&y*2==h)
      flag=1;
  	cout<<w*h/2;
	if(w*h%2==1)
      printf(".500000 ");
  	else
      printf(".000000 ");
  	cout<<flag;
}


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

int main(void)
{
    string s;

    cin >> s;

    if(s[0] == 'R' && s[1] == 'R' && s[2] == 'R') cout << 3 << endl;
    else if(s[1] == 'R' && (s[0] == 'R' || s[2] == 'R')) cout << 2 << endl;
    else if(s[0] == 'R' || s[1] == 'R' || s[2] == 'R') cout << 1 << endl;
    else cout << 0 << endl;



    return 0;
}



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

int n, m;
class UnionFind{
public:
	vector<int> Parent;
	vector<int> Rank;
	UnionFind(int n){
		++n;
		Parent.resize(n, 0);
		Rank.resize(n, 0);
		for(int i=0; i<n; ++i)
			Parent[i] = i;
	}

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

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

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

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> n >> m;
	UnionFind uf(m);
	vector<int> v;
	int k, t;
	for(int i=0; i<n; ++i){
		cin >> k;
		cin >> t;
		for(int i=1; i<k; ++i){
			int u;
			cin >> u;
			uf.unite(t, u);
		}
		v.push_back(t);
	}
	set<int> s;
	for(int i=0; i<n; ++i)
		s.insert(uf.find(v[i]));
	if(s.size() == 1) cout << "YES\n";
	else cout << "NO\n";
}

Measured memory_bytes: 1660
import string
ans = []
N = int(input())

def rec(s, i):
    if len(s) == N:
        ans.append(s)
        return

    for c in string.ascii_lowercase[:i + 1]:
        if c == string.ascii_lowercase[i]:
            rec(s + c, i + 1)
        else:
            rec(s + c, i)

rec("a", 1)
for x in ans:
    print(x)

Measured memory_bytes: 13256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int startA = sc.nextInt() - 1;
        int startB = sc.nextInt() - 1;
        int goalA = sc.nextInt() - 1;
        int goalB = sc.nextInt() - 1;
        String str = sc.next();
        String str2 = str.substring(startA, Math.max(goalA, goalB));
        String str3 = str.substring(Math.max(0, startB - 1), Math.min(n - 1, goalB + 2));
        
        if (str2.contains("##")) {
            System.out.println("No");
            return;
        }
        
        if (goalA < goalB) {
            System.out.println("Yes");
        } else {
            if (str3.contains("...")) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        }
    }
}


Measured memory_bytes: 26696
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
  public static void main(String[] args) throws NumberFormatException, IOException {
    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

    String dataCount = input.readLine();
    while (input.ready()) {
      String[] dataStrArray = input.readLine().split(" ");
      final Circle circleA = new Circle(Double.parseDouble(dataStrArray[0]), Double.parseDouble(dataStrArray[1]),
          Double.parseDouble(dataStrArray[2]));
      final Circle circleB = new Circle(Double.parseDouble(dataStrArray[3]), Double.parseDouble(dataStrArray[4]),
          Double.parseDouble(dataStrArray[5]));

      System.out.println(solver(circleA, circleB));
    }
  }

  private static int solver(Circle circleA, Circle circleB) {

    final double circleDistance = getDistance(circleA.get_x(), circleA.get_y(), circleB.get_x(), circleB.get_y());

    if (circleDistance > (circleA.get_r() + circleB.get_r())) {
      return 0;
    }

    if (circleDistance >= (Math.max(circleA.get_r(), circleB.get_r()) - Math.min(circleA.get_r(), circleB.get_r()))) {
      return 1;
    }

    if (circleA.get_r() > circleB.get_r()) {
      return 2;
    }

    return -2;
  }

  private static double getDistance(Double x1, Double y1, Double x2, Double y2) {
    final double diff_X = x1 - x2;
    final double diff_Y = y1 - y2;
    final double distance = Math.sqrt(diff_X * diff_X + diff_Y * diff_Y);
    return distance;
  }

  static class Circle {
    private double x;
    private double y;
    private double r;

    private Circle(double x, double y, double r) {
      this.x = x;
      this.y = y;
      this.r = r;
    }

    public double get_x() {
      return this.x;
    }

    public double get_y() {
      return this.y;
    }

    public double get_r() {
      return this.r;
    }
  }
}

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

int main(){
  int a,b,aa,bb;
  cin >> a >> b;
  aa = a%2;
  bb = b%2;
  if (aa==0||bb==0){
    cout << "Even" << endl;
  }
  else{
    cout << "Odd" << endl;
  }
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<stack>
#include<set>
#include<map>
#include<stdio.h>
#include<functional>
#include<queue>

using ll = long long;

using namespace std;

ll mod = 1000000007;

ll n_pow(ll a, ll n) {
	if (n == 0)return 1;
	ll t = n_pow(a, n / 2);
	t *= t;
	t %= mod;
	if (n % 2 == 1)t *= a;
	return t % mod;
}

const int INF = 1001001001;
//const ll INF = 1e18;

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


double dp[305][305][305];

int n;

double rec(int i, int j, int k) {
	if (dp[i][j][k] >= 0)return dp[i][j][k];
	if (i == 0 && j == 0 && k == 0)return 0;
	double res = (double)n;
	if (i > 0)res += i * rec(i - 1, j, k);
	if (j > 0)res += j * rec(i + 1, j - 1, k);
	if (k > 0)res += k * rec(i, j + 1, k - 1);
	res /= (double)(i + j + k);
	return dp[i][j][k] = res;
}


int main() {
	cin >> n;
	vector<int>dishes(3, 0);
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		--a;
		dishes[a]++;
	}
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			for (int k = 0; k <= n; k++) {
				dp[i][j][k] = -1;
			}
		}
	}
	double ans = rec(dishes[0], dishes[1], dishes[2]);
	printf("%.10f\n", ans);
	return 0;
}

Measured memory_bytes: 219392
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

template <typename T>
void print_vec(const vector<T>& v, bool is_reverse=false, ll num=0){
  if(num == 0) num = (ll)v.size();
  cout << endl; cout << "i=  ";for(ll i=0; i<num; i++) cout << i << "   ";cout << endl;  
  cout << "    ";
  if(is_reverse) for(ll i=num-1; i>=0; i--){ cout<<v[i]; if(i!=0) cout<<"   ";}
  else for(ll i=0; i<num; i++){ cout<<v[i]; if(i!=num-1) cout<<"   ";}
  cout << endl;
}

// template <typename T>
// void print_pairvec(const vector<T> &v, ll num=0){
//   if(num == 0) num = (ll)v.size();
//   cout << endl; for(ll i=0; i<num; i++){ cout << v[i].first << " " << v[i].second << endl;}
// }
template <typename T>
void print_pairvec(const T &_pair, ll num=0){
  cout << endl; for(pair<ll, int> x: _pair){ cout << x.first << " " << x.second << endl;}
}

template <typename T>
void print_vec2(const vector<vector<T>>& v){
  cout << endl; cout << "       ";
  for(ll i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(ll i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(ll j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}

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

  if(s == "ABC") cout << "ARC" << endl;
  else cout << "ABC" << endl;
  
  return 0;
}


Measured memory_bytes: 3628
package main

import "fmt"

func main() {
	xm := make(map[int]bool)
	for i := 0; i < 4; i++ {
		var n int
		fmt.Scan(&n)
		xm[n] = true
	}

	if xm[1] && xm[9] && xm[7] && xm[4] {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 512
"use strict";

function main(input){
  const args = input.trim().split(' ');
  const a = args[0].split('').reverse()[0] == args[1][0];
  const b = args[1].split('').reverse()[0] == args[2][0];
  console.log(a && b ? "YES" : "NO");
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));  

Measured memory_bytes: 7372
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
double eps=1e-9;
int x[23];
int y[23];
double dist[23][23];
int n;
int solve(int a,int b,double s){
	if(a==(1<<n)-1)return 1;
	for(int i=0;i<n;i++){
		if(a&(1<<i))continue;
		if(s+dist[b][i]+eps>dist[n+1][i])return 0;
	}
	for(int i=0;i<n;i++){
		if(a&(1<<i))continue;
		
		if(solve(a+(1<<i),i,s+dist[b][i]))return 1;
	}
	return 0;
}
int main(){
	int a,hx,hy,dx,dy;
	while(scanf("%d%d%d%d%d",&a,&hx,&hy,&dx,&dy),a){
		n=a;
		for(int i=0;i<a;i++)scanf("%d%d",x+i,y+i);
		x[a]=hx;x[a+1]=dx;
		y[a]=hy;y[a+1]=dy;
		for(int i=0;i<a+2;i++)for(int j=0;j<a+2;j++)
			dist[i][j]=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
		if(solve(0,a,0))printf("YES\n");
		else printf("NO\n");
	}
}

Measured memory_bytes: 1016
if __name__ == "__main__":
    x,y = [int(x) for x in input().split()]
    if x < y:
        tmp = x
        x = y
        y = tmp
    a = x * y
    
    r = x % y;
    while(r!=0):
        x = y
        y = r
        r = x % y;
    
    print(int(a/y))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 1ll<<59

int main(){
  ll i,j;
  string s;
  cin>>s;
  ll l=s.size();
  ll on=0;
  for(i=0;i<l;i++) {
    if(s[i]=='1') on++;
  }
  ll tb[101010];
  ll th[101010];
  tb[0]=1;
  th[0]=1;
  for(i=1;i<101010;i++){
    tb[i]=(tb[i-1]*2)%Mod;
    th[i]=(th[i-1]*3)%Mod;
  }

  ll ans=tb[on];

  ll oo=0;
  for(i=0;i<l;i++){
    if(s[i]=='1'){
      ans+=(tb[oo]*th[l-1-i])%Mod;
      ans%=Mod;
      oo++;
    }
  }
  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 2048
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<math.h>

#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long LL;
using namespace std;

bool isprime(int p) {

	//p = sqrt(p);
	if (p % 2 == 0)return false;
	if (p <= 1)return false;
	
	int i = 3;
	while (i < p) {
		if (p%i == 0)return false;
		i++;
	}
	return true;
}

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

	while (!isprime(x)&&x>2) {
     // cout<<x<<endl;
		x++;
	}
	cout << x << endl;

	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define int long long
int mod=1e9+7;

vector<pair<int,int> > G[(int)1e5+1];

signed main(){
  int n,m;
  cin>>n>>m;
  int a,b;
  for(int i=0;i<m;i++){
    cin>>a>>b;
    a--;
    b--;
    G[a].push_back(make_pair(b,i+1));
    G[b].push_back(make_pair(a,i+1));
  }
  vector<int> used(n,0);
  vector<int> ans;
  used[a]=1;
  used[b]=1;
  ans.push_back(b);
  ans.push_back(a);

  int x=a;
  int y=b;
  while(true){
    bool fa=true;
    for(int i=0;i<G[x].size();i++){
      if(!used[G[x][i].first]){
        fa=false;
        ans.push_back(G[x][i].first);
        x=G[x][i].first;
        used[x]=1;
        break;
      }
    }
    bool fb=true;
    for(int i=0;i<G[y].size();i++){
      if(!used[G[y][i].first]){
        fb=false;
        ans.insert(ans.begin(),G[y][i].first);
        y=G[y][i].first;
        used[y]=1;
        break;
      }
    }
    if(fa&&fb)break;
  }
  cout<<ans.size()<<endl;
  for(int i=0;i<ans.size();i++){
    if(i)cout<<" ";
    cout<<ans[i]+1;
  }
  cout<<endl;
}


Measured memory_bytes: 10100
import java.util.*;
class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                int[] pasta = new int[3];
                int[] juice = new int[2];
                for(int i=0;i<3;i++){
                        pasta[i] = sc.nextInt();
                }
                for(int i=0;i<2;i++){
                        juice[i] = sc.nextInt();
                }
                int bestpasta = pasta[0];
                int bestjuice = juice[0];
                for(int i=1;i<3;i++){
                        if(bestpasta > pasta[i]){
                                bestpasta = pasta[i];
                        }
                }
                for(int i=1;i<2;i++){
                        if(bestjuice > juice[i]){
                                bestjuice = juice[i];
                        }
                }
                System.out.println(bestpasta + bestjuice - 50);
        }
}

Measured memory_bytes: 17304
#include <stdio.h>
#include <stdlib.h>
int main(void) {
    int i,j,n,ans=0,prime[1000000];
    prime[0]=0;prime[1]=0;
    for(i=2;i<1000000;i++){prime[i]=1;}
    for(i=2;i<1000000;i++){
        if(prime[i]==1){
            ans++;
            if(i<1000)for(j=i*i;j<1000000;j+=i)prime[j]=0;
        }
        prime[i]=ans;
    }
    while(scanf("%d",&n)!=EOF){printf("%d\n",prime[n]);}
    return 0;
}

Measured memory_bytes: 4928
#include<bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i,a,b) for(register sign i=(sign)(a);i<=(sign)(b);++i)
#define Fordown(i,a,b) for(register sign i=(sign)(a);i>=(sign)(b);--i)
const int N=1e3+5;
template<typename T>bool cmax(T &a,T b){return (a<b)?a=b,1:0;}
template<typename T>bool cmin(T &a,T b){return (a>b)?a=b,1:0;}
template<typename T>T read()
{
	T ans=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)&&ch!='-')ch=getchar();
	if(ch=='-')f=-1,ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch-'0'),ch=getchar();
	return ans*f;
}
template<typename T>void write(T x,char y)
{
	if(x==0)
	{
		putchar('0'),putchar(y);
		return;
	}
	if(x<0)
	{
		putchar('-');
		x=-x;
	}
	static char wr[20];
	int top=0;
	for(;x;x/=10)wr[++top]=x%10+'0';
	while(top)putchar(wr[top--]);
	putchar(y);
}
void file()
{
#ifndef ONLINE_JUDGE
	freopen("in","r",stdin);
	freopen("out","w",stdout);
#endif
}
int n,x[N],y[N];
void input()
{
	n=read<int>();
	For(i,1,n)x[i]=read<int>(),y[i]=read<int>();
}
void solve(int x,int y)
{
	Fordown(i,30,0)
	{
		int now=1<<i;
		if(x>=now)putchar('R'),x-=now;
		else if(x<=-now)putchar('L'),x+=now;
		else if(y>=now)putchar('U'),y-=now;
		else if(y<=-now)putchar('D'),y+=now;
		else
		{
			if(abs(x)>abs(y))
			{
				if(x>0)putchar('R'),x-=now;
				else putchar('L'),x+=now;
			}
			else
			{
				if(y>0)putchar('U'),y-=now;
				else putchar('D'),y+=now;
			}
		}
	}
	assert(x==0&&y==0);
}
void work()
{
	int res=abs(x[1]+y[1])&1;
	For(i,2,n)if((abs(x[i]+y[i])&1)!=res){puts("-1");return;}
	write(32-res,'\n');
	Fordown(i,30,0)write(1<<i,' ');
	if(!res)
	{
		write(1,' ');
		For(i,1,n)x[i]+=1;
	}
	cout<<endl;
	For(i,1,n)
	{
		solve(x[i],y[i]);
		if(!res)putchar('L');
		cout<<endl;
	}
}
int main()
{
//	file();
	input();
	work();
	return 0;
}


Measured memory_bytes: 256
second = False

while True:
    s = input()
    if s==0: break
    if second: print ""
    second = True
    ls = map(int, raw_input().split())
    have = {}

    have[10], have[50], have[100], have[500] = ls
    have_c = sum(ls)

    ans = {}
    ans_c = 1<<30

    for i10 in range(have[10]+1):
        for i50 in range(have[50]+1):
            for i100 in range(have[100]+1):
                for i500 in range(have[500]+1):
                    pay = i10*10 + i50*50 + i100*100 + i500*500
                    if pay < s: continue
                    pay_c = i10 + i50 + i100 + i500
                    change = pay - s
                    change_c = change/500
                    change%=500
                    change_c += change/100
                    change%=100
                    change_c += change/50
                    change%=50
                    change_c += change/10
                    t_c = have_c - pay_c + change_c
                    if ans_c > t_c:
                        ans[10], ans[50], ans[100], ans[500] = i10, i50, i100, i500
                        ans_c = t_c

    if ans[10] is not 0: print 10, ans[10]
    if ans[50] is not 0: print 50, ans[50]
    if ans[100] is not 0: print 100, ans[100]
    if ans[500] is not 0: print 500, ans[500]

Measured memory_bytes: 4304