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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807

int input() {int a;cin>>a;return a;}

struct UnionFind{
    int ElementCount[200000],Adress[200001];
    void unite(int a ,int b) {
        if (!is_Linked(a) && !is_Linked(b)) {
            ElementCount[a] = 2;
            Adress[a] = Adress[b] = a;
        } else if (!is_Linked(a)) {
            int b_root = find(b);
            ElementCount[b_root]++;
            Adress[a] = b_root;
        } else if (!is_Linked(b)) {
            int a_root = find(a);
            ElementCount[a_root]++;
            Adress[b] = a_root;
        } else {
            int a_root = find(a),b_root = find(b);
            if (a_root != b_root) {
                ElementCount[a_root] += ElementCount[b_root];
                Adress[b_root] = a_root;
            }
        }
    }
    int find(int a) {
        if (a == Adress[a]) return Adress[a];
        else {
            Adress[a] = find(Adress[a]);
            return Adress[a];
        }
    }
    int size(int a) {
        int root = find(a);
        return ElementCount[root];
    }
    bool is_Linked(int a) {
        int root = find(a);
        if (ElementCount[root]) return true;
        else return false;
    }
    /*
     * ElementCount : 属するグループの要素数
     * Adress : rootの番号
     * unite : 併合
     * find : aのrootを返す
     * size : aのrootのElementCountを返す
     * is_Linked : aがグループに所属しているかをElementCountで判断する
     *
     * */
};


int n,ans;
vector<pair<int,int>> x,y;
vector<pair<int,pair<int,int>>> v;
UnionFind UF;

signed main() {
    cin >> n;
    rep(i,n) x.pb(mp(input(),i+1)),y.pb(mp(input(),i+1));
    sort(all(x));
    sort(all(y));
    rep11(i,n) {
        int diff = abs(x[i-1].fi - x[i].fi), i_1 = x[i-1].se, i_2 = x[i].se;
        v.pb(mp(diff,mp(i_1,i_2)));
    }
    rep11(i,n) {
        int diff = abs(y[i-1].fi - y[i].fi), i_1 = y[i-1].se, i_2 = y[i].se;
        v.pb(mp(diff,mp(i_1,i_2)));
    }
    sort(all(v));
    rep(i,v.size()) {
        int diff = v[i].fi, i_1 = v[i].se.fi, i_2 = v[i].se.se;
        if (!UF.is_Linked(i_1) || !UF.is_Linked(i_2) || UF.find(i_1) != UF.find(i_2)) {
            UF.unite(i_1,i_2);
            ans += diff;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 13152
import fractions
from functools import reduce

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


N = int(input())
A = [int(i) for i in input().split()]

m = lcm_list(A) - 1

res = 0
for a in A:
    res += m % a
print(res)


Measured memory_bytes: 5432
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
  string S;
  cin >> S;

  string val;
  int min_num = 754;
  for(int i=0; i < S.length()-2; ++i){
    val = S.substr(i, 3);
    if(min_num > abs(753 - stoi(val))){
      min_num = abs(753 - stoi(val));
    }
  }
  cout << min_num << endl;

  return 0;
}


Measured memory_bytes: 256
S=input()
N=len(S)

if N<=4 or N>=10:
    print("NO")
    exit()

li=["AKIH","KIH"]
lis=[]
ans=[]
for i in range(len(li)):
    lis.append(li[i]+"AB")
    lis.append(li[i]+"B")

for i in range(len(lis)):
    ans.append(lis[i]+"R")
    ans.append(lis[i]+"AR")
    ans.append(lis[i]+"ARA")
    ans.append(lis[i] + "RA")

if S in ans:
    print("YES")
else:
    print("NO")



Measured memory_bytes: 3064
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t N;
int32_t A, B;
int a, b, c;

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N;
	in >> A >> B;
	for (size_t i = 0; i < N; i++)
	{
		int v;
		in >> v;
		if (v <= A) {
			++a;
		}
		else if(v <= B){
			++b;
		}
		else {
			++c;
		}
	}
	out << std::min({ a,b,c }) << endl;

	return 0;
}
#endif


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
#include <set>
#define MOD 1000000007
using namespace std;

int main(){
    int a,b;
    cin >> a >> b;
    int sum=0;
    if(a>b) {
        sum+=a;
        a--;
    }
    else {
        sum +=b;
        b--;
    }
        
    if(a>b) {
        sum+=a;
        a--;
    }
    else {
        sum +=b;
        b--;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
import fractions,math,sys
from collections import Counter
n = int(input())
s = list(input())
cnt = Counter(s)
white_l = 0
black_l = 0
min = cnt['.']
for i in range(n):
    if s[i] == '#':
        black_l += 1
        cnt['#'] -= 1
    else:
        white_l += 1
        cnt['.'] -= 1
    if black_l + cnt['.'] < min:
        min = black_l + cnt['.']
print(min)



Measured memory_bytes: 7136
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

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

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

    long long res = 0;
    for (int i = 0; i < n; i++) {
        res += a[i] - a[0];
    }

    for (long long i = 1, cur = res; i < n; i++) {
        cur = cur + i * (a[i] - a[i - 1]) - (n - i) * (a[i] - a[i - 1]);

        if (res > cur) {
            res = cur;
        }
    }

    cout << res << endl;
}


Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;

import static java.lang.Integer.parseInt;

/**
 * Surrounding Area
 */
public class Main {

	static final int BLACK = 1;
	static final int WHITE = 2;
	static final int[][] HV = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int w, h;
			w = parseInt(line.substring(0, line.indexOf(' ')));
			h = parseInt(line.substring(line.indexOf(' ') + 1));
			if ((w | h) == 0) break;

			char[][] map = new char[h + 2][w + 2];
			int[][] check = new int[h + 2][w + 2];

			for (int i = 1; i <= h; i++) {
				line = br.readLine();
				for (int j = 1; j <= w; j++) {
					map[i][j] = line.charAt(j - 1);
					if (map[i][j] == 'B' || map[i][j] == 'W') {
						check[i][j] = BLACK + WHITE;
					}
				}
			}

			for (int i = 1; i <= h; i++) {
				for (int j = 1; j <= w; j++) {
					if (map[i][j] == 'B' || map[i][j] == 'W') {
						int marker = 0;
						if (map[i][j] == 'B') {
							marker = BLACK;
						} else {
							marker = WHITE;
						}
						Deque<int[]> queue = new ArrayDeque<>();
						queue.offer(new int[]{i, j});
						while (!queue.isEmpty()) {
							int[] p = queue.poll();
							for (int k = 0; k < HV.length; k++) {
								int ny = p[0] + HV[k][0];
								int nx = p[1] + HV[k][1];
								if (1 <= ny && ny <= h
										&& 1 <= nx && nx <= w
										&& map[ny][nx] == '.'
										&& (check[ny][nx] & marker) == 0) {
									queue.offer(new int[]{ny, nx});
									check[ny][nx] += marker;
								}
							}
						}
					}
				}
			}

			int black = 0;
			int white = 0;
			for (int i = 1; i <= h; i++) {
				for (int j = 1; j <= w; j++) {
					if (check[i][j] == BLACK) {
						black++;
					} else if (check[i][j] == WHITE) {
						white++;
					}
				}
			}
			System.out.println(black + " " + white);

		} //end while
	} //end main
}

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    int A, B, H;
    cin >> A >> B >> H;
    cout << (A + B) * H / 2 << endl;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef long long ll;
int main(){
  ll a,b;
  cin>>a>>b;
  if(a>0)cout<<"Positive"<<endl;
  else if(a<=0&&b>=0)cout<<"Zero"<<endl;
  else {
    if((b-a+1)%2==0)cout<<"Positive"<<endl;
    else cout<<"Negative"<<endl;
  }
}

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

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

int main(){
    long long n,m;
    cin >> n >> m;
    int a[m],b[m];
    for(int i=0;i<m;i++){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }
    UnionFind uf(n);
    long long cur=n*(n-1)/2;
    vector<long long> res;
    for(int i=0;i<m;i++){
        res.push_back(cur);
        int x=a[m-1-i],y=b[m-1-i];
        if(uf.issame(x,y)) continue;
        
        long long n1=uf.size(x),n2=uf.size(y);
        cur-=n1*n2;
        uf.merge(x,y);
    }
    reverse(res.begin(),res.end());
    for(int i=0;i<res.size();i++){
        cout << res[i] << endl;
    }
}

Measured memory_bytes: 3444
#include <iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<algorithm>

using namespace std;

int main() {
	int i, j;
	int N;
	int V[100];
	int C[100];
	int sum_value[100];//X
	int sum_cost[100];//Y
	int result=0;//X-Y

	cin >> N;
	for (i = 0; i < N; ++i) {
		cin >> V[i];
	}
	for (i = 0; i < N; ++i) {
		cin >> C[i];
	}

	for (i = 0; i < N; ++i) {
		if (C[i] < V[i]) {
			result = result + (V[i] - C[i]);
		}
	}
	cout << result << endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#define REP(i,e,s) for(register int i=e; i<=s; i++)
#define DREP(i,e,s) for(register int i=e; i>=s; i--)
#define DE(...) fprintf(stderr,__VA_ARGS__)
#define DEBUG(a) DE("DEBUG: %d\n",a)
#define file(a)	freopen(a".in","r",stdin);freopen(a".out","w",stdout)
using namespace std;

int read() {
	int x=0,f=1,ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

const int MAXM=2e5+10;

int a[MAXM];

int main() {
	int n=read();
	REP(i,2,n) a[read()]++;
	REP(i,1,n) printf("%d\n",a[i]);
	return 0;
}



Measured memory_bytes: 4356
N = gets.to_i
i = 1
C = Array.new(10, 0).map{Array.new(10, 0)}

N.times do 
    C[(i.to_s)[0].to_i][(i.to_s)[-1].to_i] += 1
    i += 1
end

sum = 0
for i in (0..9)
    for j in (0..9)
        sum += C[i][j] * C[j][i]
    end
end

puts sum



Measured memory_bytes: 1788
n = int(input())
p = list(map(int, input().split()))

asce = [i for i in range(1, n+1)]
dif = []

for j in range(0, n):
    if p[j] != asce[j]:
        dif.append(j)

if len(dif) == 2:
    if p[dif[1]] == asce[dif[0]] and p[dif[0]] == asce[dif[1]]:
        print("YES")
    else:
        print("NO")
else:
    if len(dif) == 0:
        print("YES")
    else:
        print("NO")


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


int main(void)
{
	int N, M, K;
	cin >> N >> M >> K;
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= M; j++) {
			int black = (M-j)*i + (N-i)*j;
			if (black == K) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}


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

using namespace std;
typedef long long ll;

ll dp[150][4][2];

int main(){
    string s;
    ll K;
    cin >> s;
    cin >> K;
    dp[0][0][0] = 1;
    for(int i=0;i<s.size();i++){
        for(int j=0;j<=K;j++){
            for(int k=0;k<2;k++){
                ll sd = s[i] - '0';
                for(int d=0;d<10;d++){
                    int dk = k;
                    int dj = j;
                    if(d != 0) dj++;
                    if(dj > K) continue;
                    if(k==0){
                        if(sd < d) continue;
                        if(sd > d) dk++;
                    }
                    dp[i+1][dj][dk] += dp[i][j][k];
                }
            }
        }
    }
    cout << dp[s.size()][K][0] + dp[s.size()][K][1] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());

typedef long long ll;

int main(){
  int n;
  cin >> n;
  map<char,int> mp;
  rep(i,n){
    char c;
    cin >> c;
    mp[c] ++;
  }
  if(mp.size() == 3) cout << "Three" << endl;
  else cout << "Four" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main ()
{
  int a;
  cin>>a;
  if(a%10==2 || a%10==4 || a%10==5 || a%10==7 || a%10==9)
    cout<<"hon"<<endl;
  else if(a%10==3)
    cout<<"bon"<<endl;
  else
    cout<<"pon"<<endl;
  return 0;
}



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

#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  LL n;
  cin >> n;
  LL a=1;
  for(int i=0;1;i++){
    if(a>=n){
      cout << i << endl;
      return 0;
    }
    a*=3;
  }
  return 0;
}



Measured memory_bytes: 3100
from numpy import array
from numpy.linalg import norm
n,d=map(int,input().split())
X = [list(map(int,input().split())) for i in range(n)]
ans = 0
for i in range(n-1):
  for j in range(i+1,n):
    if norm(array(X[i])-array(X[j])).is_integer():
      ans += 1
print(ans)

Measured memory_bytes: 27280
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        var nk = Input.ar;
        var ar = Input.ar;
        var gcd = ar[0];
        for (var i = 1; i < nk[0]; i++)
            gcd = Calculation.GCD(gcd, ar[i]);
        WriteLine(ar.Max() >= nk[1] && nk[1] % gcd == 0 ? "POSSIBLE" : "IMPOSSIBLE");
    }
}

public class Input
{
    public static string read => ReadLine();
    public  static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
    public  static int num => ToInt32(read);
    public  
static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
    public  static long numL => ToInt64(read);
    public static int[][] twodim(int num)
        => Enumerable.Repeat(0, num).Select(v => ar).ToArray();
    public static long[][] twodimL(int num)
        => Enumerable.Repeat(0, num).Select(v => arL).ToArray();
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}

public class Calculation
{
    public static int LCM(int num1, int num2)
    {
        return num1 / GCD(num1, num2) * num2;
    }

    public static long LCM(long num1, long num2)
    {
        return num1 / GCD(num1, num2) * num2;
    }

    public static int GCD(int num1, int num2)
    {
        return num1 < num2 ? GCD(num2, num1) :
            num2 > 0 ? GCD(num2, num1 % num2) : num1;
    }

    public static long GCD(long num1, long num2)
    {
        return num1 < num2 ? GCD(num2, num1) :
            num2 > 0 ? GCD(num2, num1 % num2) : num1;
    }

    public static long[] Ncr(int num1)
    {
        if (num1 == 0) return new[] { 0L };
        var ncr = new long[num1 + 2];
        ncr[1] = 1;
        for(var i = 0; i < ncr.Length - 2; i++)
        {
            var tmp = new long[num1 + 2];
            tmp[num1 + 1] = 1;
            for (var j = 1; j <= ncr.Length - 2; j++)
                tmp[j] = (ncr[j] + ncr[j - 1]) % Input.MOD;
            ncr = tmp;
        }
        return ncr;
    }

    public static long Ncr(int num1, int num2)
        => Ncr(num1)[num2 + 1];
}


Measured memory_bytes: 18528
<?php
    $input1 = explode(" ",fgets(STDIN));
    $input2 = explode(" ",fgets(STDIN));
    
    $num = $input1[0];
    // 移動距離＊疲労度
    $dataA = $input1[1];
    // ワープ１回の疲労度
    $dataB = $input1[2];
    // 疲労度の合計
    $count = 0;

    for($i=1;$i<$num;$i++) {
        if( ($input2[$i]-$input2[$i-1]) * $dataA < $dataB) {
            $count = $count + ($input2[$i]-$input2[$i-1]) * $dataA;
        }else{
            $count = $count + $dataB;
        }
    }
    echo $count;
?>



Measured memory_bytes: 22136
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
using ll = long long;
#define pi 3.1415926

int a[3];

int main(){
    int a, b;
    cin >> a >> b;
    if(a >= 13)
        cout << b;
    else if(a >= 6 && a <= 12)
        cout << b/2;
    else
        cout << "0";     
}

    

	


Measured memory_bytes: 256
list_input = list(map(int, input()))

len_val = len(list_input)
ans_a = []
ans_b = []

a_count = 0
b_count = 0

for i in range(len_val):

    ans_a.append(i%2)
    ans_b.append((i+1)%2)

for i in range(len_val):
    if ans_a[i] == list_input[i]:
        b_count += 1
    else:
        a_count += 1

if a_count >= b_count:
    print(b_count)
else:
    print(a_count)


Measured memory_bytes: 5516
import           Control.Monad
import           Data.Array.ST
import           Data.Array.Unboxed    (UArray)
import qualified Data.Array.Unboxed    as U
import qualified Data.ByteString.Char8 as BS
import           Data.Char
import           Data.List

getAsInt :: IO [Int]
getAsInt =  unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

getAsIntLine :: Int -> IO [[Int]]
getAsIntLine n = replicateM n getAsInt

getAsIntArray2D :: Int -> Int -> IO (UArray (Int,Int) Int)
getAsIntArray2D n m = U.listArray ((1,1),(n,m)) . concat <$> getAsIntLine n

main :: IO ()
main = do
  n <- readLn
  abcs <- getAsIntArray2D n 3
  let solve = solve1
      result = solve abcs n
  print $ maximum $ map (\x -> result U.! (n,x)) [1..3]

solve1 :: UArray (Int,Int) Int -> Int -> UArray (Int,Int) Int
solve1 abcs n = runSTUArray $ do
  dp <- newArray ((1,1),(n,3)) 0
  writeArray dp (1,1) $ abcs U.! (1,1)
  writeArray dp (1,2) $ abcs U.! (1,2)
  writeArray dp (1,3) $ abcs U.! (1,3)
  forM_ [2..n] $ \x -> do
    a <- readArray dp (x-1,1)
    b <- readArray dp (x-1,2)
    c <- readArray dp (x-1,3)

    writeArray dp (x,1) (abcs U.! (x,1) + max b c)
    writeArray dp (x,2) (abcs U.! (x,2) + max c a)
    writeArray dp (x,3) (abcs U.! (x,3) + max a b)

  return dp


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

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> A(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> A.at(i).at(j);
    }
  }
  vector<bool> B1(H, true);
  for (int i = 0; i < H; i++) {
    bool b = 1;
    for (int j = 0; j < W; j++) {
      if (A.at(i).at(j) == '#') b = 0;
    }
    if (b) B1.at(i) = false;
  }
  vector<bool> B2(W, true);
  for (int i = 0; i < W; i++) {
    bool b = 1;
    for (int j = 0; j < H; j++) {
      if (A.at(j).at(i) == '#') b = 0;
    }
    if (b) B2.at(i) = false;
  }
  for (int i = 0; i < H; i++) {
    if (!B1.at(i)) continue;
    for (int j = 0; j < W; j++) {
      if (!B2.at(j)) continue;
      cout << A.at(i).at(j);
    }
    cout << "\n";
  }
}

Measured memory_bytes: 256
from itertools import *
from fractions import gcd
import sys


#################### library ####################

def factorize_naive(n):
	def f(n, p0):
		if n == 1:
			return ()
		
		for p in takewhile(lambda p: p * p <= n, count(p0)):
			if n % p == 0:
				return (p,) + f(n / p, p)
		else:
			return (n,)
	
	return list((k, len(list(v))) for k, v in groupby(f(n, 2)))


#################### naive ####################


#################### process ####################

def read_input():
	[n, m] = map(int, raw_input().split())
	return (n, m)

def proc():
	n, m = read_input()
	d = gcd(n, m)
	fs = factorize_naive(d)
	return len(fs) + 1


#################### main ####################

print proc()


Measured memory_bytes: 34664
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] p = new int[n+1];
        for(int i = 1; i <= n; i++) {
            p[i] = sc.nextInt();
        }
        UnionFind uf = new UnionFind(n+1);
        for(int i = 0; i < m; i++) {
            int x = sc.nextInt();
            int y = sc.nextInt();
            uf.unite(x, y);
        }
        int count = 0;
        for(int i = 1; i <= n; i++) {
            if (uf.same(p[i], i)) count++;
        }
        System.out.println(count);
    }

    public static class UnionFind {
        int[] parents, sizes;

        UnionFind(int n) {
            parents = new int[n];
            sizes = new int[n];
            for(int i = 0; i < n; i++) {
                parents[i] = i;
                sizes[i] = 1;
            }
        }

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

        public void unite(int x, int y) {
            x = find(x);
            y = find(y);
            if (x == y) return;
            if (sizes[x] < sizes[y]) {
                int temp = x;
                x = y;
                y = temp;
            }
            parents[y] = x;
            sizes[x] += sizes[y];
        }

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

        public int size(int x) {
            return sizes[find(x)];
        }
    }
}


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

using namespace std;

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

    vector <int> s;
    int sl = 0;

    for (int i = 11; i <= 55555; i += 5){
        bool flag = true;
        int count = 0;
        for (int j = 1; j * j <= i; j++){
            if (i % j == 0){
                if (j * j == i){
                    count ++;
                }else{
                    count += 2;
                }
            }
            if (count > 2){
                flag = false;
                break;
            }
        }
        if (flag == true){
            s.push_back(i);
        }
    }

    for (int i = 0; i < N; i++){
        cout << s[i] << " ";
    }
    cout << endl;
    
    return 0;
}

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


int main(){
	int n,d[100],count=1;

	cin>>n;
	for(int i=0;i<n;i++)cin>>d[i];

	sort(d,d+n);
	for(int i=0;i<n-1;i++){
		if(d[i]!=d[i+1])count++;
	}
	cout<<count<<endl;
}

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

int main(){
    using namespace std;
    constexpr unsigned long MOD = 1000000007;
    unsigned long N, K;
    cin >> N >> K;
    unsigned long B{min(K, static_cast<unsigned long>(pow(K / log(log(K + 2)), 2.0L / 3) + 1))};
    vector<unsigned long> phi_small(B + 1);
    for(unsigned long i{0}; i <= B; ++i)phi_small[i] = i;
    vector sieve(B + 1, 1UL);
    for(unsigned long p{2}; p <= B; ++p)if(sieve[p])for(unsigned long i{B / p}; i; --i){
        sieve[i * p] = 0;
        phi_small[i * p] -= phi_small[i];
    }
    partial_sum(phi_small.begin(), phi_small.end(), phi_small.begin());
    vector<unsigned long> phi_large(K / B + 1);
    const auto& phi_sum = [&B, &K, &phi_small, &phi_large](unsigned long i){
        if(i <= B)return phi_small[i];
        return phi_large[K / i];
    };
    for(unsigned long i{K / B}; i; --i){
        auto t = K / i;
        phi_large[i] = t * (t + 1) / 2;
        for(unsigned long k{t}; k > 1;){
            phi_large[i] -= phi_sum(t / k) * (k - t / (t / k + 1));
            k = t / (t / k + 1);
        }
    }
    const auto& modpow = [&N](unsigned long a, unsigned long b) -> unsigned long {
        unsigned long r{b % MOD}, n{N};
        while(n){
            if(n & 1)(r *= a) %= MOD;
            (a *= a) %= MOD;
            n >>= 1;
        }
        return r;
    };
    unsigned long ans{0};
    for(unsigned long i{K}; i; ){
        ans += modpow(K / i, phi_sum(i) - phi_sum(K / (K / i + 1)));
        i = K / (K / i + 1);
    }
    cout << ans % MOD << endl;
    return 0;
}

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

int main(void){
    double x1,y1,x2,y2,l;
    scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
    l=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
    printf("%lf\n",l);
    return 0;
}


Measured memory_bytes: 1808
n, m = map(int, input().split())
a = {int(input()) for _ in range(m)}

s = [1]*(n+1)

if 1 in a:
    s[1] = 0

for i in range(n-1):
    if i+2 in a:
        s[i+2] = 0
        continue
    s[i+2] = (s[i+1] + s[i]) % (10**9+7)
    
print(s[-1])

Measured memory_bytes: 11884
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
#define debug(x) std::cout << #x << ": " << x << '\n';

const int N = 1e5+7, LG = 20;
int a[N];
int r[LG][N];

signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(20); 
    #endif

    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    int L;
    cin >> L;
    r[0][n - 1] = r[0][n] = n;
    int ptr = 0;
    for (int i = 0; i + 1 < n; ++i) {
        while (ptr + 1 < n && a[ptr + 1] <= a[i] + L) {
            ptr++;
        }   
        assert(ptr > i);
        r[0][i] = ptr;
    }   

    for (int p = 1; p < LG; ++p)
        for (int i = 0; i <= n; ++i)
            r[p][i] = r[p - 1][r[p - 1][i]];

    int q;
    cin >> q;
    while (q--) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        if (b < a)
            swap(a, b);
        int ans = 0;
        for (int p = LG - 1; p >= 0; --p) {
            if (r[p][a] < b) {
                a = r[p][a];
                ans += 1 << p;
            }   
        }   
        cout << ans + 1 << endl;
    }   

}


Measured memory_bytes: 19888
#include <bits/stdc++.h> 
using namespace std;
int main() {
  int H, N;
  int sum = 0;
  cin >> H >> N;
  int A[N - 1];
  for (int i = 0; i < N; i++){
    cin >> A[i];
    sum += A[i];
  }
  if (sum >= H){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }

  return 0;
}

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

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

using namespace std;

struct state{
	int a,b,c;
//	state(){}
	state(int a,int b,int c):a(a),b(b),c(c){}
	bool operator< (const state& x)const{ return make_tuple(a,b,c)< make_tuple(x.a,x.b,x.c); }
	bool operator==(const state& x)const{ return make_tuple(a,b,c)==make_tuple(x.a,x.b,x.c); }
};

random_device seed_gen;
mt19937 rng(seed_gen());

int main(){
	int n,a0,b0,c0; cin>>n>>a0>>b0>>c0;
	vector<string> s(n);
	rep(i,n) cin>>s[i];

	vector<vector<state>> S(n+1);
	S[n].emplace_back(0,0,0);
	for(int i=n-1;i>=0;i--){
		vector<state> tmp;

		rep(j,S[i+1].size()){
			int a=S[i+1][j].a,b=S[i+1][j].b,c=S[i+1][j].c;
			if(s[i]=="AB"){
				tmp.emplace_back(a+1,b,c);
				tmp.emplace_back(a,b+1,c);
				if(b>0) tmp.emplace_back(a+1,b-1,c);
				if(a>0) tmp.emplace_back(a-1,b+1,c);
			}
			else if(s[i]=="BC"){
				tmp.emplace_back(a,b+1,c);
				tmp.emplace_back(a,b,c+1);
				if(c>0) tmp.emplace_back(a,b+1,c-1);
				if(b>0) tmp.emplace_back(a,b-1,c+1);
			}
			else{
				tmp.emplace_back(a+1,b,c);
				tmp.emplace_back(a,b,c+1);
				if(c>0) tmp.emplace_back(a+1,b,c-1);
				if(a>0) tmp.emplace_back(a-1,b,c+1);
			}
		}

		sort(tmp.begin(),tmp.end());
		tmp.erase(unique(tmp.begin(),tmp.end()),tmp.end());

		rep(j,tmp.size()){
			bool ok=true;
			rep(k,tmp.size()) if(j!=k && tmp[k].a<=tmp[j].a && tmp[k].b<=tmp[j].b && tmp[k].c<=tmp[j].c) ok=false;
			if(ok) S[i].emplace_back(tmp[j]);
		}
	}

	auto check=[&](int a,int b,int c,int i){
		rep(j,S[i].size()){
			if(a>=S[i][j].a && b>=S[i][j].b && c>=S[i][j].c) return true;
		}
		return false;
	};

	if(!check(a0,b0,c0,0)) return puts("No"),0;

	puts("Yes");
	rep(i,n){
		if(s[i]=="AB"){
			a0++; b0--;
			if(check(a0,b0,c0,i+1)){ puts("A"); continue; }
			a0--; b0++;
			b0++; a0--;
			if(check(a0,b0,c0,i+1)){ puts("B"); continue; }
			b0--; a0++;
		}
		else if(s[i]=="BC"){
			b0++; c0--;
			if(check(a0,b0,c0,i+1)){ puts("B"); continue; }
			b0--; c0++;
			c0++; b0--;
			if(check(a0,b0,c0,i+1)){ puts("C"); continue; }
			c0--; b0++;
		}
		else{
			a0++; c0--;
			if(check(a0,b0,c0,i+1)){ puts("A"); continue; }
			a0--; c0++;
			c0++; a0--;
			if(check(a0,b0,c0,i+1)){ puts("C"); continue; }
			c0--; a0++;
		}
	}

	return 0;
}


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

int main(){
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;

    transform(s1.begin(), s1.end(), s1.begin(), ::toupper);
    transform(s2.begin(), s2.end(), s2.begin(), ::toupper);
    transform(s3.begin(), s3.end(), s3.begin(), ::toupper);
   
    cout << s1[0] << s2[0] << s3[0] << endl;
}

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

using namespace std;

int n, d1, d2;
vector<pair<int, int> > v[2], a[2];

int main(){
	scanf("%d%d%d", &n, &d1, &d2);
	int x = 0, y;
	while(d1 / (1 << (2 * x)) % 4 == 0) x++;
	y = d1 / (1 << (2 * x)) % 4;
	x = 1 << x;
	for(int i = 0;i < n * 2;i++){
		for(int j = 0;j < n * 2;j++){
			int ii = i / x, jj = j / x;
			if(y == 1){
				v[(ii + jj) & 1].push_back({i, j});
			}else if(y == 2){
				v[ii & 1].push_back({i, j});
			}else{
				v[0].push_back({i, j});
			}
		}
	}
	if(v[0].size() < v[1].size()) swap(v[0], v[1]);
	x = 0;
	while(d2 / (1 << (2 * x)) % 4 == 0) x++;
	y = d2 / (1 << (2 * x)) % 4;
	x = 1 << x;
	for(int k = 0;k < v[0].size();k++){
		int i = v[0][k].first, j = v[0][k].second;
		int ii = i / x, jj = j / x;
		if(y == 1){
			a[(ii + jj) & 1].push_back({i, j});
		}else if(y == 2){
			a[ii & 1].push_back({i, j});
		}else{
			a[0].push_back({i, j});
		}
	}
	if(a[0].size() < a[1].size()) swap(a[0], a[1]);
	for(int i = 1;i <= n * n;i++) printf("%d %d\n", a[0].back().first, a[0].back().second), a[0].pop_back();
}


Measured memory_bytes: 9192
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+100;
ll a[maxn];
ll dp[maxn];
const int mod=998244353;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n,m,d;
    cin>>n>>m>>d;
    if(d==0){
        double ans=1.0*(m-1)/n;
        cout<<fixed<<setprecision(8)<<ans<<endl;
    }
    else{
        double ans=1.0*(m-1)*2*(n-d)/(n*n);
        cout<<fixed<<setprecision(8)<<ans<<endl;
    }
	return 0;
}


Measured memory_bytes: 256
import scala.annotation.tailrec
object Main extends App {

  import scala.io.StdIn._
  import scala.math._

  val n = readLine.trim.toInt
  val apples = Array.tabulate(n){_ ⇒ readLine.trim.toLong}
  println(
    if (apples.count(l ⇒ l % 2 == 1) > 0) "first" else "second"
  )
  implicit class Extension[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}

Measured memory_bytes: 35828
// Problem : A - Sheep and Wolves
// Contest : AtCoder - AtCoder Beginner Contest 164
// URL : https://atcoder.jp/contests/abc164/tasks/abc164_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define endl "\n"
#define lb "lower_bound"
#define ub "upper_bound"
#define bs "binary_search"

int dif(int a,int b){if(a > b)return a - b;else return b - a;}
int min(int a,int b){if(a > b)return b;else return a;}
int max(int a,int b){if(a > b)return a;else return b;}
int gcd(int a,int b){if(a == 0)return b;else return (a%b,b);}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);
    int s,w;
    cin>>s>>w;
    if(s <= w)
    cout<<"unsafe";
    else cout<<"safe";
	return 0;
}


Measured memory_bytes: 3668
import java.util.Scanner;

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

        long ans = 0;

        if (k == 0) {
            System.out.println(n * n);
            sc.close();
            return;
        }

        for (long b = k+1; b <= n; b++) {
            long p = n / b;
            long r = n - p * b;
//            long r = n % b;
            ans += p * Math.max(0, b - k);
            ans += Math.max(0, r - k + 1);
        }

        System.out.println(ans);
        sc.close();
    }

}


Measured memory_bytes: 21972
#include <iostream>
int main(){
	int p[3], j[2];
	int pmin = 2000, jmin = 2000;
	for (int i = 0; i < 3; i++) {
		std::cin >> p[i];
		if (p[i] < pmin) {
			pmin = p[i];
		}
	}
	for (int i = 0; i < 2; i++) {
		std::cin >> j[i];
		if (j[i] < jmin) {
			jmin = j[i];
		}
	}
	std::cout << jmin + pmin - 50 << std::endl;

	return 0;
}

Measured memory_bytes: 3096
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;

const int MAXN=1e5+5;
const int INF=0x3f3f3f3f;

int n,m;
int mn[MAXN],mx[MAXN],p[MAXN];
bool flag=1;
vector<int> a[MAXN];

bool check(int x,int y,int val){
	if(y==INF)
		return 1;
	if(x>val||y<val)
		return 0;
	if((val-x)%2)
		return 0;
	return 1;
}
void dfs(int x,int f){
	for(int i=0;i<(int)a[x].size();i++){
		int u=a[x][i];
		if(u==f)
			continue;
		dfs(u,x);
		if(mn[u]==-INF)
			continue;
		if(mn[x]==-INF){
			mn[x]=mn[u]-1;
			mx[x]=mx[u]+1;
		}
		else{
			if(mx[x]%2==mx[u]%2)
				flag=0;
			mx[x]=min(mx[x],mx[u]+1);
			mn[x]=max(mn[x],mn[u]-1);
		}
	}
	if(p[x]!=-1){
		if(check(mn[x],mx[x],p[x])==0)
			flag=0;
		mn[x]=mx[x]=p[x];
	}
}

void dfs1(int x,int f,int minv,int maxv){
	if(maxv!=INF){
		if(mx[x]==INF){
			mx[x]=maxv+1;
			mn[x]=minv-1;
		}
		else{
			if(maxv%2==mx[x]%2)
				flag=0;
			if(p[x]!=-1){
				if(check(mn[x],mx[x],p[x])==0)
					flag=0;
			}
			else{
				mn[x]=max(mn[x],minv-1);
				mx[x]=min(mx[x],maxv+1);
			}
		}
	}
	for(int i=0;i<(int)a[x].size();i++){
		int u=a[x][i];
		if(u==f)
			continue;
		dfs1(u,x,mn[x],mx[x]);
	}
	if(mn[x]>mx[x])
		flag=0;
}

int main(){
	memset(p,-1,sizeof p);
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		mn[i]=-INF;
		mx[i]=INF;
	}
	int u,v;
	for(int i=1;i<n;i++){
		scanf("%d%d",&u,&v);
		a[u].push_back(v);
		a[v].push_back(u);
	}
	scanf("%d",&m);
	for(int i=1;i<=m;i++){
		scanf("%d%d",&u,&v);
		p[u]=v;
	}
	dfs(1,0);
	dfs1(1,0,-INF,INF);
	if(flag){
        puts("Yes");
		for(int i=1;i<=n;i++)
			printf("%d\n",mx[i]);
	}
	else puts("No");
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n - 1);
  for(int i = 0; i < n - 1; i++) {
    cin >> a.at(i);
  }
  vector<int> ans(n);
  for(int i = 0; i < n - 1; i++) {
    ans.at(a.at(i) - 1)++;
  }
  for(int i = 0; i < n; i++) {
    cout << ans.at(i) << endl;
  }
}

Measured memory_bytes: 4844
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    int n;
    cin >> n;
    __uint128_t ans = 1;
    vector a(n,0LL);
    for (int i=0; i<n; i++) cin >> a[i];

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

    for (int i=0; i<n; i++) {
        ans *= a[i];
        if (ans > 1000000000000000000LL) {
            ans = -1;
            break;
        }
    }

    cout << (int64)ans << endl;
}

Measured memory_bytes: 3612
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>

#include <utility>
using std::pair;
#include <string>
using std::string;
#include <vector>
using std::vector;
#include <map>
using std::map;
#include <unordered_map>
using std::unordered_map;
#include <set>
using std::set;
#include <unordered_set>
using std::unordered_set;
#include <deque>
using std::deque;
#include <queue>
using std::priority_queue;
#include <bitset>
using std::bitset;

using std::cin;
using std::cout;
using std::endl;


inline void print(const vector<int> & V) {
    for (auto v:V) printf("%d ",v);
    printf("\n");
}

int main() {
    int N,M;
    cin >> N >> M;
    vector<vector<int>> S(M);
    for (auto & s:S) {
        int t;
        cin >> t;
        while (t--) {
            int ss;
            cin >> ss;
            s.push_back(ss-1);
        }
    }
    vector<int> P(M);
    for (auto & p:P) cin >> p;

    int ret = 0;
    int p2 = 1;
    int NN = N;
    while (NN--) p2 *= 2;
    for (int i=0;i<p2;++i) {
        bitset<10> bs(i);
        int idx = 0;
        bool fail = false;
        for (auto & s:S) {
            int t = 0;
            for (auto & ss:s) t+=(int)bs[ss];
            if (t%2!=P[idx++]) { fail = true; break;}
        }
        ret += !fail;
    }

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

	return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,l,i;
string a;
vector<string>b;
set<string>::iterator it;
cin>>n>>l;
for(i=0;i<n;i++){
cin>>a;
b.push_back(a);
}
sort(b.begin(),b.end());
for(i=0;i<n;i++){
cout<<b[i];
}
cout<<endl;


}

Measured memory_bytes: 256
#include <stdio.h>

int
main(int argc, char *argv[])
{
  int a, b, ans;
  char op;
  scanf("%d %c %d", &a, &op, &b);

  op == '+' ? (ans = a + b) : (ans = a - b);
  
  printf("%d\n", ans);
  
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

__attribute__((constructor))
void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main() {
    int W, H;
    char c;
    cin >> W >> H >> c;

    rep(h, H) {
        rep(w, W) {
            if (
                (w == 0 && h == 0) || 
                (w == 0 && h == H - 1) || 
                (w == W - 1 && h == 0) || 
                (w == W - 1 && h == H - 1)
            ) {
                cout << '+';
            } else if (w == 0 || w == W - 1) {
                cout << '|';
            } else if (h == 0 || h == H - 1) {
                cout << '-';
            } else {
                if((W / 2 ) == w && (H / 2) == h) {
                    cout << c;
                } else {
                    cout << '.';
                }
            }
        }
        cout << endl;
    }
}



Measured memory_bytes: 3192
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int a,b,c,d=0,e=0;
signed main(){
	cin>>a>>b>>c;
	if(b>=c){
		cout<<"delicious"<<endl;
	}else if(c-b<=a){
		cout<<"safe"<<endl;
	}else{
		cout<<"dangerous"<<endl;
	}
}

Measured memory_bytes: 256
import java.util.Scanner ;
public class Main{
public static void main(String[]args){

    Scanner sc = new Scanner(System.in);

    while(true) {
        int H = sc.nextInt();
        int W = sc.nextInt();
        if(H == 0 && W == 0){
            break;
        }
      
        for(int i=0;i<H/2;i++){
for(int j=0;j<W/2;j++){
    System.out.printf("#.");
    
  }
  if(W%2 == 1){
    System.out.printf("#");   
    }
    System.out.printf("\n");
for(int j=0;j<W/2;j++){
    System.out.printf(".#");
}
    if(W%2 == 1){
        System.out.printf(".");   
        }
   
    System.out.printf("\n");
    }
    if(H%2 == 1){
        for(int j=0;j<W/2;j++){
        
 System.out.printf("#.");
        }
 if(W%2 == 1){
    System.out.printf("#");   
    }
    System.out.printf("\n");
    }
    System.out.printf("\n");
    }
    
    }
    }



Measured memory_bytes: 56080
N, K = map(int, input().split())
S = input()

def solve():
    global K, S
    concat_S = S[:]
    while 'LL' in concat_S:
        concat_S = concat_S.replace('LL', 'L')
    while 'RR' in concat_S:
        concat_S = concat_S.replace('RR', 'R')

    ans = len(S) - len(concat_S)
    if len(concat_S) >= 4:
        # 2個ずつ消す
        num_rm = min(K, (len(concat_S)-2)//2)
        K -= num_rm
        ans += num_rm * 2
        len_concat_S = len(S) - ans

        if K:
            if len_concat_S == 3:
                ans += 2
            elif len_concat_S == 2:
                ans += 1
        print(ans)
        return
    if K:
        if len(concat_S) == 3:
            ans += 2
        elif len(concat_S) == 2:
            ans += 1
        
    print(ans)
    return

if __name__ == "__main__":
    solve()

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

int main(){
	int n,k;cin >> n >> k;
	double ans = 0;
	for(int i = 1;i <= n;i++){
		double s = 1;
		int t = i;
		while(t < k){
			s *= 1 / 2.0;
			t <<= 1;
		}
		ans += s * (1.0 / n);
	}
	printf("%.12f", ans);
}
// make pair, tuple
// make pair, tuple
// 
// __gcd(int, int);
// lcm = a * b / __gcd(a, b);
// 
// bool isPrime(int n){
//       if(n <= 1)return false;
//       if(n <= 3)return true;
//       if(n % 2 == 0 || n % 3 == 0)return false;
//       for(int i = 5;i * i <= n;i += 6){
//             if(n % i == 0 || n % (i + 2) == 0)return false;
//       }
//       return true;
// }
// int countSubString(string s, string temp){
//       int ans = 0;
//       size_t f = s.find(temp);
//       while(f != string::npos){
//             ans++;
//             f = s.find(temp, f + 1);
//       }
//       return ans;
// }
// 
// #Count leading & trailing zero of an integer bits
// __builtin_clz(n);
// __builtin_clzll(n);
//
// #Count 1s bits of an integer
// __builtin_popcount(n);
// __builtin_popcountll(n);
//
// #Error checking
// assert(n == 3);
// 
// #Error Printing
// cerr << "Some thing";

// #binary exponentiation
// long long binpow(long long a, long long b) {
//     long long res = 1;
//     while (b > 0) {
//         if (b & 1)
//             res = res * a;
//         a = a * a;
//         b >>= 1;
//     }
//     return res;
// }


Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
typedef long long ll;

int main()
{

    ll x,money=100;
    int ans=0;
    scanf("%lld",&x);

    for(int i=1;money<x;i++)
    {
        money=money*1.01;
        ans=ans+1;
    }

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

    return 0;
}

Measured memory_bytes: 1728
#include <algorithm>
#include <cstdio>

using namespace std;

int main() {
  int input[5];
  scanf(
      "%d %d %d %d %d",
      input, input + 1, input + 2, input + 3, input + 4);
  sort(input, input + 5, [](int a, int b) { return a > b; });
  printf(
      "%d %d %d %d %d\n",
      input[0], input[1], input[2], input[3], input[4]);

  return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;


const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

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;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()

int main(){
    int N,A;
    ll ANS=1;
    cin>>N;
    bool c=(N%2==0);
    bool X=false;
    map<int,int> mp;
    rep(i,N){
        cin>>A;
        if(c){
            if(A%2==0)X=true;
        }else{
            if(A%2==1)X=true;
        }
        mp[A]++;
        if(mp[A]>2)X=true;
        if(X){
            cout<<0<<endl;
            return 0;
        }
    }
    
    for(auto x:mp){
        if(x.first==0){
            if(x.second!=1)X=true;
        }else if(x.second!=2){
            X=true;
        }else{
            ANS*=2;
            ANS%=INF;
        }
        if(X){
            cout<<0<<endl;
            return 0;
        }
    }
    cout<<ANS<<endl;

    return 0;
}

//a=97,z=122

Measured memory_bytes: 2560
N = int(input())
F = [list(map(int, input().split())) for i in range(N)]
P = [list(map(int, input().split())) for i in range(N)]

def ev(lst):
    ret = 0
    for i in range(N):
        cnt = sum([1 if F[i][j] * lst[j] == 1 else 0 for j in range(10)])
        ret += P[i][cnt]
    return ret

NEG_INF = -100000000000000000000

def dfs(acc):
    if len(acc) == 10:
        if acc.count(1) == 0:
            return NEG_INF
        return ev(acc)

    lazy = max(dfs(acc + [0]), dfs(acc + [1]))
    return lazy

ans = dfs([])
print(ans)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
inline bool chmin (int& a, int b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
class low_link_tree {
	int n;
	int tmr = 0;
	int rt = 0;
	vector<int> ord;
	vector<int> low;
	set<int> atc;
	set<pair<int, int>> bdg;
	vector<vector<int>> grh;
public:
	low_link_tree (
		vector<vector<int>> const& grh
	)
	: n(grh.size())
	, ord(n, -1)
	, low(n, -1)
	, grh(grh)
	{
		dfs(0, 0);
	}
	void dfs (
		int crr
	,	int prt
	) {
		int cnt = 0;
		ord[crr] = low[crr] = tmr++;
		for (int nxt : grh[crr]) {
			if (ord[nxt] == -1) {
				cnt++;
				dfs(nxt, crr);
				chmin(low[crr], low[nxt]);
				if (crr != rt && ord[crr] <= low[nxt]) atc.insert(crr);
				if (ord[crr] < low[nxt]) bdg.emplace(min(crr, nxt), max(crr, nxt));
			}
			if (nxt != prt) chmin(low[crr], ord[nxt]);
		}
		if (crr == rt && cnt > 1) atc.insert(crr);
	}
	auto const &order() {return ord;}
	auto const &low_link() {return low;}
	auto const &articulation_points() {return atc;}
	auto const &bridges() {return bdg;}
};
int main() {
	int n, m;
	cin >> n >> m;
	vector<vector<int>> grh(n);
	for (int i = 0; i < m; i++) {
		int s, t;
		cin >> s >> t;
		grh[s].push_back(t);
		grh[t].push_back(s);
	}
	auto atc = low_link_tree(grh).articulation_points();
	for (auto it = atc.begin(); it != atc.end(); it++) {
		cout << *it << '\n';
	}
	cout << flush;
	return 0;
}


Measured memory_bytes: 4916