akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#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 rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

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

    int n;
    cin >> n;
    vector<double> a(n);
    rep(i,n){
        cin >> a[i];
    }
    double sum = 0;
    rep(i,n){
        sum += 1/a[i];
    }
    printf("%.10f\n",1/sum);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()

ll N;
ll M;
vector<ll> A;

int main() {
  cin >> N >> M;
  A.resize(N);
  rep(i, N) cin >> A[i];

  sort(all(A));

  vector<ll> S(N + 1, 0);
  rep(i, N) S[i + 1] = S[i] + A[i];

  function<ll(ll)> num = [&](ll t) {
    ll res = 0;
    rep(i, N) res += distance(lower_bound(all(A), t - A[i]), A.end());
    return res;
  };

  ll l = 0, r = 1e6;
  while (r - l > 1) {
    ll m = (l + r) / 2;
    if (num(m) <= M) {
      r = m;
    } else {
      l = m;
    }
  }

  ll ans = 0;
  ll rest = M;
  rep(i, N) {
    int l = distance(lower_bound(all(A), r - A[i]), A.end());
    ans += l * A[i] + S[N] - S[N - l];
    rest -= l;
  }
  ans += rest * l;

  cout << ans << endl;

  return 0;
}


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

#define int long long

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

string a, b;

signed main() {
    cin >> a >> b;
    int x = stoi(a + b);
    for (int i = 1; i < 1000; i++) {
        if (x == i * i) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
#include<queue>
using namespace std;
const int N=500005;
int n,K,i,j,k,l,a[N],mn[N*5],head[N],adj[N*2],nxt[N*2],d[N],ans[N];
priority_queue<int,vector<int>,greater<int> > q;
void addedge(int u,int v)
{
	adj[++l]=v;
	nxt[l]=head[u];
	head[u]=l;
	++d[v];
}
void built(int o,int l,int r)
{
	mn[o]=1<<30;
	if(l==r)
		return;
	int mid=l+r>>1;
	built(o<<1,l,mid);
	built(o<<1|1,mid+1,r);
}
void update(int o,int l,int r,int x,int y)
{
	if(l==r)
	{
		mn[o]=min(mn[o],y);
		return;
	}
	int mid=l+r>>1;
	if(x<=mid)
		update(o<<1,l,mid,x,y);
	else
		update(o<<1|1,mid+1,r,x,y);
	mn[o]=min(mn[o<<1],mn[o<<1|1]);
}
int query(int o,int l,int r,int x,int y)
{
	if(l>=x&&r<=y)
		return mn[o];
	int mid=l+r>>1,rtn=1<<30;
	if(x<=mid)
		rtn=query(o<<1,l,mid,x,y);
	if(y>mid)
		rtn=min(rtn,query(o<<1|1,mid+1,r,x,y));
	return rtn;
}
int main()
{
	scanf("%d%d",&n,&K);
	for(i=1;i<=n;++i)
	{
		scanf("%d",&j);
		a[j]=i;
	}
	built(1,1,n);
	for(i=n;i>=1;--i)
	{
		j=query(1,1,n,a[i],min(n,a[i]+K-1));
		if(j<(1<<30))
			addedge(a[i],a[j]);
		j=query(1,1,n,max(1,a[i]-K+1),a[i]);
		if(j<(1<<30))
			addedge(a[i],a[j]);
		update(1,1,n,a[i],i);
	}
	for(i=1;i<=n;++i)
		if(!d[i])
			q.push(i);
	k=0;
	while(!q.empty())
	{
		i=q.top();
		q.pop();
		ans[i]=++k;
		for(j=head[i];j;j=nxt[j])
		{
			--d[adj[j]];
			if(!d[adj[j]])
				q.push(adj[j]);
		}
	}
	for(i=1;i<=n;++i)
		printf("%d\n",ans[i]);
	return 0;
}


Measured memory_bytes: 25588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF 2 << 29
#define MOD 1000000007
#define Yes(f) puts((f)? "Yes" : "No")
#define YES(f) puts((f)? "YES" : "NO")
int gcd(int a, int b) {
	if (b != 0)return gcd(b, a % b);
	return a;
}
int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}

using Graph = vector<vector<int>>;

int main(){
	int n; cin >> n; 
	string s; cin >> s;
	int ans = 0;
	rep(i, n - 2){
		if(s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
n, k, q = map(int, input().split())
l = [0] * n
x = k - q
for i in range(q):
    a = int(input())
    l[a - 1] +=  1
for i in range(n):
    if x + l[i] > 0:
        print("Yes")
    else:
        print("No")
    x = k - q

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

using namespace std;

using ll = long long;

const long long MOD = 1e9 + 7;
const int INF = 1e9 + 7;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> ans(26, 100);
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        vector<int> tmp(26, 0);
        for (char c : s) ++tmp[c - 'a'];
        for (int i = 0; i < 26; ++i) ans[i] = min(ans[i], tmp[i]);
    }
    for (int i = 0; i < 26; ++i) {
        for (int j = 0; j < ans[i]; ++j) {
            cout << (char)('a' + i);
        }
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
using ll = long long;
using namespace std;

int main()
{
	string S;
	int sum = 0;
	cin >> S;
	for (int i = 0; i < S.size(); i++){
		sum += S[i] - '0';
	}
	if (sum % 9 == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

}



Measured memory_bytes: 3324
module Main where

import Control.Applicative
import Numeric
import Data.Char
import Data.List
import Data.Ord

main :: IO ()
main = do
  {cs <- getContents
  ; putStr $ unlines
           $ map showCharCount
           $ mergeCharCounts
           $ charCounts
           $ alphas cs
  }

alphas :: String -> String
alphas = map toLower . filter isAlpha

charCounts :: String -> [(Char, Int)]
charCounts = map count . group . sort

count :: String -> (Char, Int)
count s = (head s, length s) 

initCharCounts :: [(Char, Int)]
initCharCounts = zip ['a' .. 'z'] (repeat 0)

mergeCharCounts :: [(Char, Int)] -> [(Char, Int)]
mergeCharCounts = merge initCharCounts

merge :: [(Char, Int)] -> [(Char, Int)] -> [(Char, Int)]
merge [] [] = []
merge xs [] = xs
merge (x:xs) (y:ys) = case (comparing fst) x y of
  LT -> x : merge xs (y:ys)
  EQ -> y : merge xs ys
  _  -> error "Henn!"

showCharCount :: (Char, Int) -> String
showCharCount (c, n) = [c] ++ " : " ++ show n

--

getInts :: IO [Int]
getInts = map read . words <$> getLine

putInts :: [Int] -> IO ()
putInts = putStrLn  .  unwords .  map show

getDoubles :: IO [Double]
getDoubles = map read . words <$> getLine

putDoubles :: [Double] -> IO ()
putDoubles = putStrLn . unwords . map showDouble

showDouble :: Double -> String
showDouble d = showFFloat Nothing d ""



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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n - 1);
  for (int i = 0; i < n - 1; i++)
    cin >> a[i];
  vector<int> res(n);
  res[0] = a[0];
  for (int i = 1; i < n - 1; i++) {
    res[i] = a[i];
    if (res[i] > a[i - 1])
      res[i] = a[i - 1]; 
  }
  res[n - 1] = a[n - 2];
  int ans = accumulate(res.begin(), res.end(), 0);
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3640
import java.util.Scanner;
public class Main {
	@SuppressWarnings({ "resource"})
	public static void main(String[] args) {
		Scanner scanner=new Scanner(System.in);
		int[] point=new int[5];
		int tmp=0,total=0;
		for(int i=0;i<5;i++){
			point[i]=scanner.nextInt();
			}
		for(int j=0;j<4;j++) {
			for(int i=0;i<4;i++) {
				if((point[i]%10<point[i+1]%10)||(point[i+1]%10==0)) {
					tmp=point[i];
					point[i]=point[i+1];
					point[i+1]=tmp;
				}

			}
		}
		for(int i=0;i<4;i++) {
			total+=point[i];
			if(point[i]%10!=0) {
				total+=10-(point[i]%10);
			}
		}
		total+=point[4];
System.out.println(total);
	}
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  for(int i=1;i<=N;i++){
    int X=i*108/100;
    if(X==N){
      cout<<i<<endl;
      return 0;
    }
  }
  cout<<":("<<endl;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func min(nums ...int64) int64 {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int64(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int64) int64 {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int64(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func nextLong() int64 {
	sc.Scan()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func nextString() string {
	sc.Scan()
	s := sc.Text()
	return s
}

func nextByte() byte {
	sc.Scan()
	s := sc.Bytes()
	return s[0]
}

var N, M, ANS int
var SW []int
var LS [][]int

func main() {
	sc.Split(bufio.ScanWords)
	//ans := 1
	N = nextInt()
	M = nextInt()
	LS = make([][]int, M)
	for i := 0; i < M; i++ {
		con := nextInt()
		LS[i] = make([]int, con)
		for j := 0; j < con; j++ {
			LS[i][j] = nextInt()
		}
	}
	SW = make([]int, M)
	for i := 0; i < M; i++ {
		SW[i] = nextInt()
	}
	DP := make([]bool, N)
	solve(DP, 0)
	DP[0] = true
	solve(DP, 0)
	fmt.Println(ANS)
}

func solve(DP []bool, depth int) {
	if depth >= N-1 {
		for i := 0; i < M; i++ {
			COUNT := count(DP, LS[i])
			if COUNT%2 != SW[i] {
				return
			}
		}
		ANS++
		return
	}
	depth++
	DP[depth] = false
	solve(DP, depth)
	DP[depth] = true
	solve(DP, depth)
}

func count(DP []bool, l []int) int {
	var c int
	for _, v := range l {
		if DP[v-1] {
			c++
		}
	}
	return c
}


Measured memory_bytes: 1784
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); }
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 10;
const int MOD = 1000000007;

int main() {
	int N, M;
	cin >> N >> M;
	vvi d(N, vi(N, INF)), e(N, vi(N, INF));
	int a, b, c;
	REP(i, M) {
		cin >> a >> b >> c;
		a--;
		b--;
		d[a][b] = d[b][a] = e[a][b] = e[b][a] = c;
	}

	REP(k, N) {
		REP(i, N) {
			REP(j, N) {
				if (d[i][k] + d[k][j] < d[i][j]) {
					d[i][j] = d[i][k] + d[k][j];
				}
			}
		}
	}

	int ans = 0;
	REP(i, N) {
		REP(j, N) {
			if (e[i][j] != INF && d[i][j] < e[i][j]) {
				ans++;
			}
		}
	}
	cout << ans/2 << endl;
	return 0;
}

Measured memory_bytes: 384
/*
* @author:  codancer
* @createTime:  2020-06-22, 08:57:59
*/
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define fep(i,a,b) for(int i=(a);i>=(b);i--)
typedef vector<int> VI;
typedef vector<ll> VII;
typedef pair<int,int> pii;
int main(){
	ll n;
	cin>>n;
	string ans="";
	while(n){
		if(n%26==0){
			ans+='z';
			--n;
		}else{
			ans+=char('a'+n%26-1);
		}
		n/=26;
	}
	reverse(ans.begin(),ans.end());
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3596
#include<cstdio>
using namespace std;
const int N=4003;
int st[N],i,j,k,n,m,g,A,B;
bool p[N];
char c;

inline char getc()
{
	#define VV 10000000
	static char s[VV],*l=s,*r=s;
	if (l==r)
		l=s,r=s+fread(s,1,VV,stdin);
	return l==r?0:*l++;
}

int read(){ int z=0; do c=getchar(); while (c<'0'||c>'9'); while (c>='0'&&c<='9') z*=10,z+=c-'0',c=getchar(); return z; }

void ask(int x,int y)
{
	printf("? %d %d\n",x,y);
	fflush(stdout);
}

bool check()
{
	do c=getchar(); while (c!='Y'&&c!='N');
	return c=='Y';
}

int main()
{
	A=read(),B=read();
	if (A<=B)
	{
		puts("Impossible");
		return 0;
	}
	n=A+B;
	for (i=0;i<n;++i)
		if (g)
		{
			ask(st[g],i);
			if (check())
				st[++g]=i;
			else
				--g;
		}
		else
			st[++g]=i;
	for (i=0;i<n;++i)
		ask(st[g],i),p[i]=check();
	printf("! ");
	for (i=0;i<n;++i)
		putchar('0'+p[i]);
	putchar(10);
	return 0;
}

Measured memory_bytes: 632
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		scan.close();

		if(400<=x && x<=599) {
			System.out.println(8);
		}else if(600<=x && x<=799) {
			System.out.println(7);
		}else if(800<=x && x<=999) {
			System.out.println(6);
		}else if(1000<=x && x<=1199) {
			System.out.println(5);
		}else if(1200<=x && x<=1399) {
			System.out.println(4);
		}else if(1400<=x && x<=1599) {
			System.out.println(3);
		}else if(1600<=x && x<=1799) {
			System.out.println(2);
		}else if(1800<=x && x<=1999) {
			System.out.println(1);
		}

	}

}


Measured memory_bytes: 35716
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    A = LI()
    A_abs = [abs(i) for i in A]

    if len([i for i in A if i < 0]) % 2 == 1:
        ans = sum(A_abs) - 2 * min(A_abs)
    else:
        ans = sum(A_abs)

    print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 21368
N = int(input())
tmp = input().split(" ")

als = []


for t in tmp:
    als.append(int(t))

als.sort(reverse = True)

rec_w = 0
prev = 0
for a in als:
    if rec_w:
        #2つ目の辺を探す
        if a == prev:
            print(a*rec_w)
            exit()
        else:
            prev = a
    else:
        if a == prev:
            rec_w = a
            prev = 0
        else:
            prev = a

print(0)


Measured memory_bytes: 14636
#include<bits/stdc++.h>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#define endl  "\n"
#define ll long long
#define int long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cin.exceptions(cin.failbit);cout.tie(NULL);
using namespace std;
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;
}
int32_t main()
{
	ll a[5];
	ll x=0;
	for(ll i=0;i<5;i++)
	{
		cin >> a[i];
		if(a[i]==0)
		{
			x=i;
		}
	}
	cout << x+1;
}


Measured memory_bytes: 3632
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define double long double
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	cin >> K;
	vector< int > ans;
	rep(i, 10) ans.push_back(i);
	for (int d = 1; d <= 9; d++) {
		int c = 0;
		rep(_, 3e4) {
			int c2 = c;
			int tmp = 0;
			int d2 = d;
			bool f = true;
			while (1) {
				tmp += d2;
				ans.push_back(tmp);
				tmp *= 10;
				d2 += c2 % 3 - 1;
				if (d2 < 0 || d2 > 9) {
					f = false;
					break;
				}
				if (c2 == 0)
					break;
				c2 /= 3;
			}

			c++;
		}
	}

	sort(ans.begin(), ans.end());
	ans.erase(unique(ans.begin(), ans.end()), ans.end());
	//cout << ans;
	cout << ans[K] << endl;
	return 0;
}

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

vector<int> sieve(int n) {
  vector<int> prime(n);
  for(int i=2; i<n; i++) prime[i]=i;
  for(int i=2; i*i<n; i++) {
    if(prime[i])  {
      for(int j=i*i; j<n; j+=i) prime[j]=0;
    }
  }

  return prime;
}

int main() {
  int n;
  vector<int> prime;
  prime = sieve(10001);

  while(cin >> n) {
    int count=0;
    for(int i=1; i<=n; i++) {
      if(prime[i]!=0 && prime[n-i+1]!=0) count++;
    }
    cout << count <<endl;
  }
  return 0; 
}


Measured memory_bytes: 1288
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
#include <math.h>
#include <queue>
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    int cnt=0;
    rep(i,n) {
        cin >> a[i+1];
        if ((i+1)%2==0) continue;
        if ((i+1)%2==1) {
            if(a[i+1]%2==1) cnt++;
        }
    }
    cout << cnt << endl;
}

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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const long long MOD = 1000000007LL;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

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

    lint w, h;
    cin >> w >> h;

    vector< LLP > pq(w + h);
    rep(i, w){
        cin >> pq[i].first;
        pq[i].second = 0;
    }
    REP(i, w, w + h){
        cin >> pq[i].first;
        pq[i].second = 1;
    }
    SORT(pq);

    lint ans = 0;
    rep(i, w + h){
        if(pq[i].second == 0){
            ans += max(pq[i].first * (h + 1LL), 0LL);
            --w;
        }else{
            ans += max(pq[i].first * (w + 1LL), 0LL);
            --h;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3456
import sys

lines = [list(map(int,line.split())) for line in sys.stdin]
r,c = lines[0]

lines = lines[1:]
for i,row in enumerate(lines):
    lines[i].append(sum(row))

lines.append([])
for i in range(c+1):
    s = 0
    for j in range(r):
        s+=lines[j][i]
    lines[-1].append(s)

for l in lines:
    print(" ".join(map(str,l)))

Measured memory_bytes: 7860
#include <stdio.h>
int main()
{
    int n, x;
    scanf("%d",&n);
    x = n;
    printf("%d:",n);
    for(int i = 2; i*i <= x; i ++)
    {
            while(n % i == 0)
            {
                printf(" %d",i);
                n /= i;
            }
    }
    if(n!=1) printf(" %d",n);
    puts("");
    return 0;
}


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

struct Card
{
	char suit, value;
};

int selection_sort(Card A[], int n);
void trace(Card A[], int n);
void bubble_sort(Card A[], int n);
bool is_stable(Card A[], Card B[], int n);



int main(int argc, char *argv[])
{
	Card C1[100], C2[100];
	int n;
	cin >> n;
	
	for (int i = 0; i < n; i++)
	{
		cin >> C1[i].suit >> C1[i].value;
		C2[i] = C1[i];
	}
	
	bubble_sort(C1, n);
	trace(C1, n);
	cout << "Stable" <<endl;
	
	selection_sort(C2, n);
	trace(C2, n);
	if (is_stable(C1, C2, n))
		cout << "Stable" << endl;
	else
		cout << "Not stable" << endl;
	return 0;
}


int selection_sort(Card A[], int n)
{
	int sw = 0;
	for (int i = 0; i < n; i++)
	{
		int min = i;
		for (int j = i+1; j < n; j++)
		{
			if (A[j].value < A[min].value)
				min = j;
		}
		if (min != i)
		{
	    	swap(A[i], A[min]);
    		sw++;		    
		}

	} 
	return sw;
} 

void trace(Card A[], int n)
{
	for (int i = 0; i < n; i++)
	{
		if (i) cout << ' ';
		cout << A[i].suit << A[i].value; 
	}
	cout << endl;
}

void bubble_sort(Card A[], int n)
{
	for (int i = 0; i < n; i++)
	{
		for (int j = n-1; j > i; j--)
		{
			if (A[j].value < A[j-1].value)
				swap(A[j], A[j-1]);
		}
	}
}


bool is_stable(Card A[], Card B[], int n)
{
	bool flag = true;
	for (int i = 0; i < n; i++)
	{
		if (A[i].suit != B[i].suit) flag = false;
	}
	return flag;
} 


Measured memory_bytes: 3120
#include <iostream>
#include <string>
#include <math.h>
#include <map>
#include <stdio.h>
#include <ctype.h>
#include <algorithm>
#include <stdlib.h>
#include <stack>
#include <queue>
#include <bitset>
#include <memory.h>

using namespace std;



int sosuu(int x){
    for(int i=2; i<=sqrt(x); i++){
        if(x%i==0)return 0;
    }
    return 1;
}


int main() {
    
    int x;
    while(cin>>x){
        int p;
        int m;
        p=x+1;
        m=x-1;
        
        while(1){
            if(sosuu(m)==1){
                cout<<m<<" ";
                break;
            }else{
                m--;
            }
        }
        
        while(1){
            if(sosuu(p)==1){
                cout<<p<<endl;
                break;
            }else{
                p++;
            }
        }

    }
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	int64 nn, minm, maxm;
	cin >> nn;
	vector<int64> aa(nn), bb(nn);
	for(int64 ii = 0;ii < nn;ii++)
	{
		cin >> aa[ii] >> bb[ii];
	}
	sort(aa.begin(), aa.end());
	sort(bb.begin(), bb.end());
	if(nn % 2 == 1)
	{
		minm = aa[nn / 2];
		maxm = bb[nn / 2];
	}
	else
	{
		minm = aa[nn / 2 - 1] + aa[nn / 2];
		maxm = bb[nn / 2 - 1] + bb[nn / 2];
	}
	cout << (maxm - minm + 1) << endl;
	return 0;
}


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

int main()
{

    int n;
    scanf("%d",&n);
    n=n%10;
    if(n==2||n==4||n==5||n==7||n==9)
    {
        printf("hon\n");
    }
    else if(n==0||n==1||n==6||n==8)
    {
        printf("pon\n");
    }
    else
    {
        printf("bon\n");
    }


    return 0;
}

Measured memory_bytes: 1664
#include<iostream>
#include<algorithm>	
#include<string>
#include<math.h>
#include <vector>
using namespace std;
int main() {
	string S;
	int N = 0;
	int a = 0;
	int A[1000] = { 0 };
	int b = 0;
	int c = 0;
	int p = 0;
	int sum = 0;
	int ans = 0;
	int h = 0;
	int m = 0;
	int s = 0;

	cin >> a >> b >> c;
	c = c - (a - b);
	if (c < 0) {
		cout << 0;
	}
	else {
		cout << c;
	}
}


Measured memory_bytes: 256
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <random>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <ctype.h>

using namespace std;

#define _CRT_SECURE_NO_WARNINGS
#define REP(i, n) for(int i=0; i<(n); i++)
#define LLREP(i,n) for(LL i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define SORT(x) sort(ALL(x))
#define REVE(x) reverse(ALL(x))
#define MP make_pair
#define PB push_back
#define INF INT_MAX

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef vector<vector<bool>> VVB;
typedef pair<int, int> PII;
typedef vector<pair<int, int>> VPII;
typedef queue<int> QI;
typedef long long LL;

LL sum(string s) {
	LL ans = 0, x = 0;
	REP(i, SZ(s)) {
		if (s[i] == '+') {
			ans += x;
			x = 0;
		}
		else {
			x = x * 10 + (s[i] - '0');
		}
	}
	return ans + x;
}
int main() {
	string s; cin >> s;
	LL  ans = 0;
	for (int bit = 0; bit < (1 << SZ(s) - 1); bit++) {
		string t;
		t.PB(s[0]);
		REP(i, SZ(s) - 1) {
			if (bit&(1 << i))t.PB('+');
			t.PB(s[i + 1]);
		}
		ans += sum(t);
	}
	cout << ans << endl;
}

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

typedef long long ll;

const int Maxn = 100005;

map <ll, ll> M;
int n, q;
ll qi[Maxn];
ll res[Maxn];

void Add(ll key, ll val)
{
    if (key == 0 || val == 0) return;
    auto it = M.find(key);
    if (it == M.end()) M.insert(make_pair(key, val));
    else it->second += val;
}

int main()
{
    scanf("%d %d", &n, &q);
    qi[0] = n;
    for (int i = 1; i <= q; i++)
        scanf("%lld", &qi[i]);
    M[qi[q]] = 1;
    for (int i = q; i >= 0; i--) {
        auto it = M.end();
        while (it != M.begin()) {
            it--;
            if (it->first <= qi[i]) break;
            Add(qi[i], ll(it->first) / qi[i] * it->second);
            Add(it->first % qi[i], it->second);
            M.erase(it++);
        }
    }
    for (auto it: M)
        res[it.first] = it.second;
    for (int i = n - 1; i >= 1; i--)
        res[i] += res[i + 1];
    for (int i = 1; i <= n; i++)
        printf("%lld\n", res[i]);
    return 0;
}


Measured memory_bytes: 9344
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct node{
    struct node *prev;
    struct node *next;
    long key;
}Node;

Node *First;

void init(){
    First = (Node *)malloc(sizeof(Node));
    First->prev = First;
    First->next = First;
    First->key = -1;
}


void Insert(long x){
    Node *NewNode;
    NewNode = (Node *)malloc(sizeof(Node));
    NewNode->key = x;
    NewNode->next = First->next;
    NewNode->prev = First;
    NewNode->next->prev = NewNode;
    NewNode->prev->next = NewNode;
}

void DeleteFirst(void){
    Node *deleteP;
    deleteP = First->next;
    deleteP->next->prev = deleteP->prev;
    First->next = deleteP->next;
    free(deleteP);
}

void DeleteLast(void){
    Node *deleteP;
    deleteP = First->prev;
    deleteP->prev->next = deleteP->next;
    First->prev = deleteP->prev;
    free(deleteP);
}

void Delete(long x){
    Node *cur;
    cur = First->next;
    for (;;){
        if (cur->key == x){
            cur->prev->next = cur->next;
            cur->next->prev = cur->prev;
            free(cur);
            break;
        }
        if (cur->key == -1){
            break;
        }
        cur = cur->next;
    }
}


int main(void){
    int n;
    char command[20];
    long x;
    int i;
    Node *printNode;

    init();
    
    scanf("%d", &n);
    for (i = 0; i < n; i++){
        scanf(" %s %ld", command, &x);
        
        if (strcmp(command, "insert") == 0){
            Insert(x);
        }
        if (strcmp(command, "delete") == 0){
            Delete(x);
        }
        if (strcmp(command, "deleteFirst") == 0){
            DeleteFirst();
        }
        if (strcmp(command, "deleteLast") == 0){
            DeleteLast();
        }
    }
    printNode = First->next;

    while (printNode->next->key != -1){
        printf("%ld ", printNode->key);
        printNode = printNode->next;
    }

    printf("%ld\n", printNode->key);

    return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<int> A(N), B(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> B[i];
  }
  vector<int> c1, c2;
  for (int i = 0; i < N; i++) {
    if (A[i] > B[i]) {
      c2.emplace_back(A[i] - B[i]);
    } else if (A[i] < B[i]) {
      c1.emplace_back(B[i] - A[i]);
    }
  }
  int idx = 0;
  for (int i = 0; i < (int)c2.size(); i++) {
    while (idx < (int)c1.size() && c2[i] > 0) {
      if (c1[idx] >= 2 * c2[i]) {
        c1[idx] -= 2 * c2[i];
        c2[i] = 0;
      } else {
        c2[i] -= c1[idx] / 2;
        c1[idx++] %= 2;
      }
    }
  }
  for (int i = 0; i < (int)c2.size(); i++) {
    if (c2[i] != 0) {
      cout << "No" << '\n';
      return 0;
    }
  }
  cout << "Yes" << '\n';
  return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;
 
public class Main { //クラス名はMain
    public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
      int N = in.nextInt();
       if (N%2 == 1)
            System.out.println(N/2+1);
       else
            System.out.println(N/2);
    }
}

Measured memory_bytes: 23124
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define sz(a) ((int)a.size())
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;

class UnionFind {
	VI par;
public:
	UnionFind(int n) :par(n, -1) {}
	int root(int x) {
		return par[x] == -1 ? x : par[x] = root(par[x]);
	}
	bool same(int x, int y) {
		return root(x) == root(y);
	}
	bool unite(int x, int y) {
		x = root(x); y = root(y);
		if (x == y)return false;
		par[x] = y;
		return true;
	}
};

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

	int n, q;
	cin >> n >> q;
	UnionFind uf(n);
	rep(_, q) {
		int com, x, y;
		cin >> com >> x >> y;

		if (com == 0) {
			uf.unite(x, y);
		} else {
			cout << uf.same(x, y) << endl;
		}
	}

}


Measured memory_bytes: 3264
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
using ll = long long;
using graph = std::vector<std::vector<std::pair<ll,ll>>>;

using namespace std;

int main() {
    ll N,M;
    cin >> N >> M;
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b,c;
        cin >> a >> b >>c;
        a--;b--;
        G[a].push_back(make_pair(b,c));
        G[b].push_back(make_pair(a,c));
    }
    ll dist[N][N];
    for (int xi = 0; xi < N; ++xi) {
        for (int yi = 0; yi < N; ++yi) {
            if(yi == xi){
                dist[yi][xi] = 0;
            }else{
                dist[yi][xi] = 1ll << 50;
            }
        }
    }
    for (int i = 0; i < G.size(); ++i) {
        for (int j = 0; j < G[i].size(); ++j) {
            dist[i][G[i][j].first] = G[i][j].second;
            dist[G[i][j].first][i] = G[i][j].second;
        }
    }
    for (int k = 0; k < N; ++k) {
        for (int i = 0; i <N; ++i) {
            for (int j = 0; j < N; ++j) {
                if(dist[i][j] > dist[i][k] + dist[k][j]){
                    dist[i][j] = dist[i][k] + dist[k][j];
                    dist[j][i] = dist[i][k] + dist[k][j];
                }
            }
        }
    }
    ll count = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < G[i].size(); ++j) {
            bool judge = false;
            for (int k = 0; k < N; ++k) {
                if(dist[k][i] + G[i][j].second == dist[k][G[i][j].first]){
                    judge = true;
                }
            }
            if(!judge){
                count++;
            }
        }
    }
    cout << count/2 << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define per(i,n) for (int i = (n)-1; i >=0; --i)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vv = vector<vi>;

int main(){
    string s;cin>>s;
    string t;
    while(s.size()){
        if(s.size()<5)break;
        
        t = s.substr(s.size()-5,5);
        if(t=="dream" || t=="erase"){
            rep(i,5)s.pop_back();
            continue;
        }
        
        if(s.size()<6)break;
        t = s.substr(s.size()-6,6);
        if(t=="eraser"){
            rep(i,6)s.pop_back();
            continue;
        }
        
        
        if(s.size()<7)break;
        t = s.substr(s.size()-7,7);
        if(t=="dreamer"){
            rep(i,7)s.pop_back();
            continue;
        }
        
        break;
    }
    
    puts(s.size()==0?"YES":"NO");
    
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;


int main() {
    double a, b, h, m;
    cin >> a >> b >> h >> m;

    double theta1 = 30 * h + 0.5 * m;
    double theta2 = 6 * m;
    double x = max(theta1, theta2) - min(theta1, theta2);
    double y = 360 - x;
    double theta = min(x, y);

    const double PI=3.14159265358979323846;
    theta = 2 * PI * theta / 360;

    double ans = pow(a, 2) + pow(b, 2) - 2 * a * b * cos(theta);
    ans = pow(ans, 0.5);
    cout << fixed << setprecision(10);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4324
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#define mod 1000000007
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
    return x*f;
}
inline void write(int x)
{
    if(x<0)putchar('-'),x=-x;
    if(x>9)write(x/10);
    putchar(x%10+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
inline int power(int a,int b)
{
	int ans=1;
	while(b)
	{
		if(b&1)ans=1LL*ans*a%mod;
		a=1LL*a*a%mod;
		b>>=1;
	}return ans;
}
int fac[200010],inv[200010];
inline int C(int m,int n){return 1LL*fac[m]*inv[n]%mod*inv[m-n]%mod;}
long long u1,u2;
inline int getval(int n){return (1LL*n*n%mod*(n+1)%mod*u1%mod-1LL*n*(n+1)%mod*(2*n+1)%mod*u2%mod+mod)%mod;}
int main()
{
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    int n=read(),m=read(),k=read();
    fac[0]=1;
    for(int i=1;i<=n*m;i++)fac[i]=1LL*fac[i-1]*i%mod;inv[n*m]=power(fac[n*m],mod-2);
    for(int i=n*m;i>=1;i--)inv[i-1]=1LL*inv[i]*i%mod;
    u1=power(2,mod-2),u2=power(6,mod-2);
    pr2(1LL*C(n*m-2,k-2)*(1LL*m*m%mod*getval(n)%mod+1LL*n*n%mod*getval(m)%mod)%mod);
   	return 0;
}

Measured memory_bytes: 1664
package main

import (
        "fmt"
)

func EvenOrOdd(a int, b int) string {
        var result string
        if a*b%2 == 0 {
                result = "Even"
        } else {
                result = "Odd"
        }

        return result
}




func main() {
        var a int
        var b int
        fmt.Scan(&a)
        fmt.Scan(&b)
        defer fmt.Println(EvenOrOdd(a,b))
}

Measured memory_bytes: 512
#include<stdio.h>
int main()
{
    int a, b, c, x;
    scanf("%d%d%d%d", &a, &b, &c, &x);
    int i, j;
    if (x % 100 == 50 && c == 0)
    {
        printf("0\n");
        return 0;
    }
    if (x % 100 == 50 && c >= 1)
    {
        x = x - 50;
        c--;
    }
    int k, n, ans = 0;
    for (i = 0; i <= a; i++)
    {
        k = x - (500 * i);
        if (k < 0)
            break;
        for (j = 0; j <= b; j++)
        {
            n = k - (100 * j);
            if (n < 0)
                break;
            if (n <= (50 * c))
                ans++;
        }
    }
    printf("%d\n", ans);
    return 0;

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

template<typename T>
struct Dinic {
    struct Edge {
        int to, cap, rev;
    };
    const int V;
    static constexpr T INF = numeric_limits<T>::max();
    // graph[from][num] := fromから出るnum番目の辺
    vector<vector<Edge>> graph;
    Dinic(const int V) :
        V(V)
        {
            graph.resize(V);
        }
    void addEdge(const int from, const int to, const int cap) {
        graph[from].emplace_back((Edge){to, cap, (int)graph[to].size()});
        graph[to].emplace_back((Edge){from, 0, (int)graph[from].size() - 1});
    }
    T flow(const int start, const int goal) {
        T ans = 0;
        vector<int> level(V);
        while(bfs(start, goal, level)) {
            vector<int> checked(V);
            while(true) {
                T fmax = dfs(start, goal, level, checked, INF);
                if(fmax <= 0) break;
                ans += fmax;
            }
        }
        return ans;
    }
    bool bfs(const int start, const int goal, vector<int> &level) {
        for(int i = 0; i < V; ++i) level[i] = -1;
        queue<int> que;
        level[start] = 0;
        que.push(start);
        while(que.size() and level[goal] == -1) {
            int from = que.front();
            que.pop();
            for(Edge e : graph[from]) {
                if(e.cap > 0 and level[e.to] == -1) {
                    level[e.to] = level[from] + 1;
                    que.push(e.to);
                }
            }
        }
        return level[goal] != -1;
    }
    T dfs(const int from, const int goal, vector<int> &level, vector<int> &checked, T fmax) {
        if(from == goal) return fmax;
        for(int &id = checked[from]; id < (int)graph[from].size(); ++id) {
            Edge &e = graph[from][id];
            if(level[e.to] <= level[from]) continue;
            if(e.cap <= 0) continue;
            T f = dfs(e.to, goal, level, checked, min(e.cap, fmax));
            if(f <= 0) continue;
            e.cap -= f;
            graph[e.to][e.rev].cap += f;
            return f;
        }
        return 0;
    }
};

int main() {
    int m, n;
    while(cin>>m>>n&&m>0){
        int b[m]; rep(i,m) cin>>b[i];
        int r[n]; rep(i,n) cin>>r[i];
        int V = m + n + 2;
        const int start = m + n;
        const int goal = start + 1;
        Dinic<int> dinic(V);
        for(int i=0;i<m;i++){
            for(int j=0;j<n;j++){
                if(__gcd(b[i],r[j])!=1){
                    dinic.addEdge(i, m+j, 1);
                }
            }
        }
        for(int i=0;i<m;i++) dinic.addEdge(start, i, 1);
        for(int j=0;j<n;j++) dinic.addEdge(m+j, goal, 1);
        cout << dinic.flow(start, goal) << endl;
    }
    return 0;
}



Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define forinc(i,a,b) for(int i=a;i<=b;++i)
#define fordec(i,a,b) for(int i=a;i>=b;--i)
#define forv(v,a) for(auto &v:a)
#define fi first
#define se second
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define all(a) a.begin(),a.end()
int re(){int x=0; char c; bool neg=false;while(c!='-'&&(c<'0'||'9'<c)) c=getchar();if (c=='-'){neg=true; c=getchar();}while ('0'<=c && c<='9'){x=x*10+c-'0';c=getchar();}if (neg) x=-x;return x;}
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int ran(int l, int r) {return l+rng()%(r-l+1);}
typedef long long ll;
const int N=100010;
int n,m,s;
int a[N],c[N],f[110][N];
int main()
{
    //freopen("knapsack2.inp","r",stdin);
    cin>>n>>m;
    forinc(i,1,n) cin>>a[i]>>c[i],s+=c[i];
    memset(f,127,sizeof(f)); int lim=f[0][0]; f[0][0]=0;
    forinc(i,0,n-1) forinc(j,0,s) if (f[i][j]<lim)
    {
        f[i+1][j]=min(f[i+1][j],f[i][j]);
        if (f[i][j]+a[i+1]<=m) f[i+1][j+c[i+1]]=min(f[i+1][j+c[i+1]],f[i][j]+a[i+1]);
    }
    fordec(j,s,0) if (f[n][j]<lim) {cout<<j; return 0;}
}


Measured memory_bytes: 43264
arr=Array[]
loop{
  arr.clear
  h,w=STDIN.gets.split.map(&:to_i)

  if h==0 && w==0 then
    break
  end

  
  w.times{
    arr.push('#')
  }
  h.times{
    puts arr.join
  }
  puts ('')
}

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

int main()
{
	string str;
	unsigned int k;

	cin >> str >> k;

	int cur = 0;

	while (k > 0) {
		if (cur == str.size() - 1) {
			k %= 'z' - 'a' + 1;
			if ('z' - str[cur] + 1 <= k) {
				k -= 'z' - str[cur] + 1;
				str[cur] = 'a';
			}
			str[cur] += k;
			k -= k;
		}
		else {
			if (str[cur] == 'a') {
				cur++;
			}
			else if ('z' - str[cur] + 1 <= k) {
				k -= 'z' - str[cur] + 1;
				str[cur] = 'a';
				cur++;
			}
			else {
				cur++;
			}
		}
	}

	cout << str << endl;

	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef double Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<int,string> tp;
//typedef vector<tp> vt;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e9;
const ll INF=2e18;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
struct UnionFind{
    vector<int> data;
    UnionFind(int size) : data(size, -1) {}
    bool unionSet(int x,int y){
        x=root(x);y=root(y);
        if(x==y)return 0;
        if(data[y]<data[x])swap(x,y);
        data[x]+=data[y],data[y]=x;
        return 1;
    }
    bool findSet(int x,int y){
        return root(x)==root(y);
    }
    int root(int x){
        return data[x]<0 ? x : data[x]=root(data[x]);
    }
    int size(int x){
        return -data[root(x)];
    }
};
class KRK{//c++11
	public:
	struct edge{
		int from,to,cost;
	};
	vector<edge>G;
	int n;
	KRK(int size){
		n=size;
	}
	void add_edge(int a,int b,int c){
		edge e={a,b,c};
		G.pb(e);
	}
	int krk(){
		int sum=0;
		sort(all(G),[](edge a,edge b){
			return a.cost<b.cost;
		});
		UnionFind uf(n);
		int co=0;
		rep(i,G.size()){
			edge e=G[i];
			if(!uf.findSet(e.from,e.to)){
				sum+=e.cost;
				co++;
				if(co==n/2)cout<<e.cost<<endl;
				uf.unionSet(e.from,e.to);
			}
		}
		return sum;
	}
};
int main(){
	int n,m;
	while(cin>>n>>m,n){
		KRK krk(n);
		while(m--){
			int a,b,c;
			cin>>a>>b>>c;
			a--;b--;
			krk.add_edge(a,b,c);
		}
		krk.krk();
	}
}

Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	string s;
	cin>>s;
	if(s[0]==s[1]||s[1]==s[2]||s[2]==s[3])cout<<"Bad"<<endl;
	else cout<<"Good"<<endl;

	return 0;
}


Measured memory_bytes: 764
#include<iostream>
#include<string>
int main(){
    int N;
    std::cin >> N;
    std::string ans="Three";
    for(int i=0; i<N; i++){
        std::string S;
        std::cin >> S ;
        if(S=="Y"){
            ans="Four";
        }
    }
    std::cout << ans << std::endl;
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

int n, m;
const int N = 5e5 + 10;
const int mod = 1e9 + 7;
ll fac[N], inv[N];

ll power(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b & 1) {
            res = res * a % mod;
        }
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}

void init() {
    fac[0] = 1;
    for (int i = 1; i < N; ++i) {
        fac[i] = fac[i - 1] * i % mod;
    }
    inv[N - 1] = power(fac[N - 1], mod - 2);
    for (int i = N - 2; i >= 0; --i) {
        inv[i] = inv[i + 1] * (i + 1) % mod;
    }
}

ll C(ll a, ll b) {
    return fac[a] * inv[b] % mod * inv[a - b] % mod;
}

int main() {
    init();
    cin >> n >> m;
    ll res = C(m, n) * fac[n] % mod; // A(m, n)
    for (int i = 1; i <= n; ++i) {
        int flag = i % 2 ? -1 : 1;
        ll v = C(n, i) * C(m - i, n - i) % mod;
        v = v * fac[n - i] % mod;
        res = (res + v * flag) % mod;
    }
    while (res < 0) res += mod;
    res = res * C(m, n) % mod * fac[n] % mod;
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 11472
import java.util.*;

public class Main{

    public static void main(String args[]){

        // スキャナーの宣言
        Scanner sc = new Scanner(System.in);
        // 整数の入力
		int n = sc.nextInt();
        // スペース区切りの整数の入力
        int k = sc.nextInt();
        double answer = 0.0;
        for(int i = 1; i < n + 1; i++){
            if(i < k){
                answer += 1.0 / n * Math.pow(1.0 / 2.0, (Math.ceil(Math.log(((double)k / i)) / Math.log(2))));
                //System.out.println(Math.ceil(Math.log(k / i) / Math.log(2)) + " " + ((double)k / i));
            }else{
                answer += 1.0 / n;
                //System.out.println(answer);
                //answer += 1.0 / n * (n - k);
                //break;
            }
        }

        // 出力
        System.out.println(answer);

    }

}

Measured memory_bytes: 22836