akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    double x;
    while(cin >> x){
        double ans = x;
        for (int i = 0; i < 9; ++i) {
            if(i&1) x /= 3;
            else x *= 2;
            ans += x;
        }
        printf("%.10lf\n", ans);
    }
    return 0;
}


Measured memory_bytes: 3148
#include<iostream>
#include<algorithm>
#include<string>
#include<fstream>

#define SIZE 9

using namespace std;

void view(int A[],int n){
	for(int i=0;i<n;i++){
		cout<<A[i]<<endl;
	}
}

int check(int kard[]){
	int k=0;
	for(int i=0;i<SIZE;i+=3){
		if((kard[i]==kard[i+1] && kard[i+1] == kard[i+2] )||
			(kard[i]+1==kard[i+1] &&kard[i+1]==kard[i+2]-1)){
		}else if(kard[i] == kard[i+1] && kard[i+2] == kard[i+3] && kard[i+4] == kard[i+5]){
			i+=3;
		}else{
			return 0;
		}
	}
	return 1;
}

int main(){
	int kard[SIZE];
	int n;
	string color;
	int ans;

	cin>>n;
	while(n--){
		for(int i=0;i<SIZE;i++){
			cin>>kard[i];
		}
		for(int i=0;i<SIZE;i++){
			cin>>color;
			if(color == "R"){
				kard[i]	+= 10;
			}else if(color == "G"){
				kard[i]	+= 20;
			}else{
				kard[i]	+= 30;
			}
		}
		sort(kard,kard+SIZE);
		ans	= check(kard);
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1224
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    String t = sc.next();
    int count = 0;

    if(s.charAt(0) == t.charAt(0)) count++;

    if(s.charAt(1) == t.charAt(1)) count++;

    if(s.charAt(2) == t.charAt(2)) count++;

    System.out.println(count);

  }
}

Measured memory_bytes: 23252
#pragma GCC optimize("O3")
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<vector>
#include<sstream>
#include<queue>
#include <iomanip>
#include <fstream>
#include<unordered_set>
#include<stack>
#include <unordered_map>
#include<time.h>
#include <chrono>
constexpr auto INF = 9223372036854775807;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned long int ul;
typedef long int l;
#define f(i,a,b) for(l i=(l)a;i<(l)b;i+=1)
#define rf(i,a,b) for(l i=(l)a;i>=(l)b;i-=1)
#define endl '\n'
#define N 1000000007 // prime modulo value 
#define all(x) x.begin(),x.end()
#define FAST ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0)
using namespace std;
#define MAX 1000001 
l spf[MAX];
void precompute()
{
	spf[1] = 1;
	for (l i = 2; i < MAX; i++)
		spf[i] = i;

	for (l i = 4; i < MAX; i += 2)
		spf[i] = 2;

	for (l i = 3; i * i < MAX; i++)
	{
		if (spf[i] == i)
		{
			for (l j = i * i; j < MAX; j += i)
				if (spf[j] == j)
					spf[j] = i;
		}
	}
}

int main()
{
	FAST;
	string s;
	cin >> s;
	if (s == "SUN")
		cout << "7";
	else if (s == "MON")
		cout << "6";
	else if (s == "TUE")
		cout << "5";
	else if (s == "WED")
		cout << "4";
	else if (s == "THU")
		cout << "3";
	else if (s == "FRI")
		cout << "2";
	else if (s == "SAT")
		cout << "1";
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

int n, cnt[100009];
string s;
bool mk[100009];

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> s;
	n = s.length();
	for (int i = 0; i < n - 1; i++) {
		if (s[i] == 'R' && s[i + 1] == 'L') {
			mk[i] = true;
		}
	}
	int cur = 0;
	while (1) {
		while (cur < n && !mk[cur]) {
			cur++;
		}
		if (cur == n) break;
		int pR = cur, pL = cur + 1;
		int tcnt = 0;
		while (pR >= 0 && s[pR] == 'R') {
			if (tcnt % 2 == 0) cnt[cur]++;
			else cnt[cur + 1]++;
			tcnt++;
			pR--;
		}
		tcnt = 0;
		while (pL < n && s[pL] == 'L') {
			if (tcnt % 2 == 0) cnt[cur + 1]++;
			else cnt[cur]++;
			tcnt++;
			pL++;
		}
		cur++;
	}
	for (int i = 0; i < n; i++) {
		cout << cnt[i] << " ";
	}
	//system("pause");
	return 0;
}

Measured memory_bytes: 1132
#include <bits/stdc++.h>
using namespace std;
vector<long long> vals[100001],graph[100001],dpl[100001],dpr[100001];
long long n,m,cnt,num[100001],renum[100001],dp[100001],dpup[100001];

void dfs(long long curr , long long par){
	cnt += 1;
	num[curr] = cnt;
	renum[cnt] = curr;
	for(long long i : graph[curr]){
		if(i == par){
			continue;
		}
		dfs(i,curr);
	}
}

long long getans1(long long curr , long long st){
	if(curr == vals[st].size()){
		return 1;
	}
	if(dpr[st][curr] != -1){
		return dpr[st][curr];
	}
	long long ret = getans1(curr+1,st)*(vals[st][curr]+1);
	return dpr[st][curr] = ret%m;
}

long long getans2(long long curr , long long st){
	if(curr == -1){
		return 1;
	}
	if(dpl[st][curr] != -1){
		return dpl[st][curr];
	}
	long long ret = getans2(curr-1,st)*(vals[st][curr]+1);
	return dpl[st][curr] = ret%m;
}

int main(){
	cin >> n >> m;
	for(long long i = 0 ; i < n-1 ; i += 1){
		long long a,b;
		cin >> a >> b;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}
	dfs(1,1);
	for(long long i = n ; i >= 1 ; i -= 1){
		for(long long j : graph[renum[i]]){
			if(num[j] < i){
				continue;
			}
			vals[i].push_back(dp[num[j]]);
		}
		dpl[i].assign(vals[i].size(),-1);
		dpr[i].assign(vals[i].size(),-1);
		dp[i] = getans1(0,i);
	}
	dpup[num[1]] = 1;
	for(long long i = 1 ; i <= n ; i += 1){
		long long cnt = 0;
		for(long long j : graph[renum[i]]){
			if(num[j] < i){
				continue;
			}
			dpup[j] = (((getans1(cnt+1,i)*getans2(cnt-1,i))%m)*dpup[renum[i]]+1)%m;
			cnt += 1;
		}
	}
	for(long long i = 1 ; i <= n ; i += 1){
		cout << dpup[i]*dp[num[i]]%m << endl;
	}
}

Measured memory_bytes: 28800
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
using namespace std;
// 型シノニム
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
// 定数
constexpr ll INF   = 1e16;
constexpr ll INM   = 114514;
constexpr ll MOD   = 1e9 + 7;
constexpr ld EPS   = 1e-12;
constexpr ll dx[4] = {1, 0, -1, 0};
constexpr ll dy[4] = {0, 1, 0, -1};
// 便利関数
void IOS() { ios::sync_with_stdio(false), cin.tie(0); }
template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, ll t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll mod) {
	if (a > 0) return a % mod;
	if (a % mod == 0) return 0;
	ll x = -a / mod + 1;
	a += x * mod;
	return a % mod;
}
ll powm(ll a, ll b, ll m) {
	if (b == 0) {
		return 1;
	} else if (b % 2 == 0) {
		ll d = powm(a, b / 2, m);
		return (d * d) % m;
	} else {
		return (powm(a, b - 1, m) * a) % m;
	}
}
// 本体

ll dp[114514];
ll n, k;
ll gmax;

// gcd(A) = x となる集合の個数
ll rec(int x) {
	if (dp[x] != -1) {
		return dp[x];
	}
	ll ans = powm(k / x, n, MOD);
	for (int i = 2 * x; i <= k; i += x) {
		ans = mod(ans - rec(i), MOD);
	}
	return dp[x] = ans;
}

int main() {
	IOS();
	cin >> n >> k;
	ll ans = 0;
	Fill(dp, -1);
	for (int i = 1; i <= k; i++) {
		//dump(rec(i));
		ans += rec(i) * i;
		ans %= MOD;
	}
	dump(ans);
}

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

unordered_map<int,int> mp[100010];
signed main(){
    // ios::sync_with_stdio(false);
	// cin.tie(0);
    // cout << fixed << setprecision(20);

    int n,m,t;
    //cin>>n>>m>>t;
    scanf("%d %d %d",&n,&m,&t);
    vector<pair<int,pair<int,int>>> v;
    for(int i=0;i<m;i++){
        int a,b,c;
        //cin>>a>>b>>c;
        scanf("%d %d %d",&a,&b,&c);
        b--;
        v.push_back(make_pair(a,make_pair(b,c)));
    }
    //sort(v.begin(),v.end());
    pair<int,int> ans[n]={};
    ans[0].second = 1;
    int enter[n]={};
    set<int> st;

    for(int i=0;i<m;i++){
        int p = v[i].second.first;
        //cerr << v[i].first << " " << v[i].second.first << " " << v[i].second.second<<endl;
        if(v[i].second.second == 1){
            st.insert(p);
            enter[p] = v[i].first;
        }
        else{
            st.erase(p);
            for(auto j:st){
                int mini=p,ma=j;
                if(mini>ma) swap(mini,ma);
                pair<int,int> pa = make_pair(mini,ma);
                
                int k = mp[mini][ma] += v[i].first - max(enter[p],enter[j]);
                if(ans[p].first == k){
                    ans[p].second = min(ans[p].second,j);
                }
                else if(ans[p].first < k){
                    ans[p] = make_pair(k,j);
                }
                if(ans[j].first == k){
                    ans[j].second = min(ans[j].second,p);
                }
                else if(ans[j].first < k){
                    ans[j] = make_pair(k,p);
                }
            }
        }
    }
    for(auto p:st){
        for(auto j:st){
            if(p>=j) continue;
            int mini = p,ma=j;
            pair<int,int> pa = make_pair(mini,ma);
            int k = mp[mini][ma] += t - max(enter[p],enter[j]);
            if(ans[p].first == k){
                ans[p].second = min(ans[p].second,j);
            }
            else if(ans[p].first < k){
                ans[p] = make_pair(k,j);
            }
            if(ans[j].first == k){
                ans[j].second = min(ans[j].second,p);
            }
            else if(ans[j].first < k){
                ans[j] = make_pair(k,p);
            }
        }
    }
    for(auto i:ans){
        //cout << i.first << " ";
        printf("%d\n",i.second+1);
    }
}




Measured memory_bytes: 169052
import time
import copy

start_time = time.time()

#input
D = int(input())
c_list = list(map(int, input().split()))

s_grid = []
for i in range(D):
    array = list(map(int, input().strip().split(' ')))
    s_grid.append(array)

def calculate_score(d,t,last):
    score = s_grid[d][t]
    last[t] = -1
    for i in range(26):
        score -= c_list[i]*(last[i]+1)
    return score

t_list = [] #task_list
last_list = [0 for _ in range(26)]

total_score = 0
for k in range(0,D):
    X = -1  # k-日目に変える番号を探す
    p = -10**6
    for i in range(26):  # 26通り試す
        last = copy.deepcopy(last_list)
        tmp = calculate_score(k,i,last)
        if tmp > p:
            X = i
            p = tmp

    #最大のXを投入
    total_score += p
    t_list.append(X)
    last_list = [i+1 for i in last_list]
    last_list[X] = 0

    if time.time() - start_time > 1.9:
        break

for j in range(len(t_list)):
    print(int(t_list[j]) + 1)
#print(total_score)

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

#include <iostream>
using namespace std;
int main() {
  int n, r;
  cin >> n >> r;
  if (n >= 10) {
    cout << r << endl;
  } else {
    cout << r + 100 * (10 - n) << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n1,n,k;
	cin>>n>>k;
	n1=n/k;
	n-=n1*k;
	n1=min(abs(n-k),n);
	cout<<n1<<endl;
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n int
	var s string
	fmt.Scan(&n)
	fmt.Scan(&s)

	c := n/2
	if s[0:c] == s[c:n] {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

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

char a[1000][1000];
int dp[1000][1000];

int main()
{
    int n;
    while(cin >> n, n){
        int ans = 0;
        for(int i = 0; i < n; ++i){
            for(int j = 0; j < n; ++j){
                cin  >> a[i][j];
                if(i == 0 || j == 0) {
                    dp[i][j] = (a[i][j] == '.');
                    ans = max(ans, dp[i][j]); 
                } else if(a[i][j] == '.'){ 
                    dp[i][j] = min(dp[i-1][j-1], min(dp[i][j-1], dp[i-1][j])) + 1;
                    ans = max(ans, dp[i][j]);
                } else dp[i][j] = 0;
            }
        }
        cout << ans << endl;
    }
}

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

#define SQ(x) ((x)* (x))
#define EPS (1e-5)

typedef struct {
    double x;
    double y;
    double r;
} CIRCLE;

double size(CIRCLE a)
{
    return (sqrt(SQ(a.x) + SQ(a.y)));
}

CIRCLE minus(CIRCLE a, CIRCLE b)
{
    CIRCLE res;
    res.x = a.x - b.x;
    res.y = a.y - b.y;
    
    return (res);
}

double scalarProduct(CIRCLE a, CIRCLE b)
{
    return (a.x * b.x + a.y * b.y);
}

double determinant(CIRCLE a, CIRCLE b)
{
    return (a.x * b.y - a.y * b.x);
}

double segmentDistance(CIRCLE a, CIRCLE b, CIRCLE c)
{
    if (scalarProduct(minus(b, a), minus(c, a)) < EPS){
        return size(minus(c, a));
    }
    if (scalarProduct(minus(a, b), minus(c, b)) < EPS){
        return size(minus(c, b));
    }
    
    return (fabs(determinant(minus(b, a), minus(c, a))) / size(minus(b, a)));
}

int inCircle(CIRCLE a, CIRCLE c)
{
    return (SQ(a.x - c.x) + SQ(a.y - c.y) - SQ(c.r) <= EPS);
}

int main(void)
{
    int n, m;
    int i, j;
    CIRCLE circ[100];
    CIRCLE t, s;
    int flag;
    
    while (1){
        scanf("%d", &n);
        
        if (n == 0){
            break;
        }
        
        for (i = 0; i < n; i++){
            scanf("%lf%lf%lf", &circ[i].x, &circ[i].y, &circ[i].r);
        }
        
        scanf("%d", &m);
        
        for (i = 0; i < m; i++){
            scanf("%lf%lf%lf%lf", &t.x, &t.y, &s.x, &s.y);
            flag = 0;
            for (j = 0; j < n; j++){
                if (inCircle(s, circ[j]) ^ inCircle(t, circ[j]) || (!(inCircle(s, circ[j]) & inCircle(t, circ[j])) && segmentDistance(s, t, circ[j]) - circ[j].r < EPS)){
                    flag |= 1;
                }
            }
            
            if (flag == 1){
                printf("Safe\n");
            }
            else {
                printf("Danger\n");
            }
        }
    }
    
    return (0);
}

Measured memory_bytes: 0
// In God We Trust


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

# define INF 1 << 31 - 1
# define pb push_back
# define fi first
# define se second

int main()
{
  string s;
  cin >> s;
  int count = 0;
  for (int i = 0; i < s.size() / 2; i++)
    if (s[i] != s[s.size() - 1 - i])
      count++;
  cout << count << endl;
}


Measured memory_bytes: 256
X = int(input())
total = 0
a = X%100
total += a//5
a = a%5
total += a//4
a = a%4
total += a//3
a = a%3
total += a//2
a = a%2
total += a
if(total*100>X):
    print(0)
else:
    print(1)

Measured memory_bytes: 3064
// Do you knOW what it feels like?

		// To be TorTured by your own MinD?
	
	// I don't wanna feel the PAIN.

// I BeG you to KILL me, pleASE...

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

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("Os")

#define F first
#define S second
#define pb push_back
#define SZ(x) (ll)(x.size())
#define all(x) x.begin(),x.end()

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

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

const ll maxn=2e3+10, lg=21, mod=924844033, inf=1e18;

ll n,k;
ll a[maxn],fac[maxn],dp[maxn][2],g[maxn][2];

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

	cin>>n>>k;
	fac[0]=1;
	for(int i=1;i<=n;i++) fac[i]=fac[i-1]*i%mod;
	dp[0][0]=1;
	for(int i=1;i<=min(n,k);i++){
		ll m=(n-i)/k;
		for(int j=1;j<=m;j++)for(int l=n;l>=0;l--){
			dp[l][0]=(dp[l][0]+dp[l][1])%mod;
			if(l) dp[l][1]=dp[l-1][0];
		}
		for(int j=0;j<=n;j++) dp[j][0]=(dp[j][0]+dp[j][1])%mod,dp[j][1]=0;
		for(int j=1;j<=m;j++)for(int l=n;l>=0;l--){
			dp[l][0]=(dp[l][0]+dp[l][1])%mod;
			if(l) dp[l][1]=dp[l-1][0];
		}
		for(int j=0;j<=n;j++) dp[j][0]=(dp[j][0]+dp[j][1])%mod,dp[j][1]=0;
	}
	ll ans=0;
	for(int i=0;i<=n;i++) ans=(ans+(i%2 ? -1:1)*dp[i][0]*fac[n-i])%mod;
	cout<<(ans+mod)%mod<<endl;

	return 0;
}








Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,e) for(int i = a;i < e;++i)
using LL = long long;
struct UnionFind {
	vector<int> data;
	UnionFind(int n) { data.assign(n, -1); }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool same(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)]; }
};

int main() {

	int N;
	cin >> N;
	vector<LL> H(N);
	for (int i = 0; i < N; ++i) {
		cin >> H[i];
	}
	UnionFind uf(N);
	FOR(i, 0, N - 1) {
		if (H[i] >= H[i + 1]) {
			uf.unionSet(i, i + 1);
		}
	}
	int ans = 0;

	FOR(i, 0, N) {
		ans = max(ans, uf.size(i));
	}
	cout << ans-1 << endl;

}




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

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

  bool flag = false;

  while(flag == false){
    c = c-b;
    if(c <= 0){
      cout << "Yes" << endl;
      break;
    }

    a = a-d;
    if(a <= 0){
      cout << "No" << endl;
      break;
    }
  }
}


Measured memory_bytes: 3620
import math

n = int(input())

cnt = 0

def make_prime_list_2(num):
    if num < 2:
        return []

    # 0のものは素数じゃないとする
    prime_list = [i for i in range(num + 1)]
    prime_list[1] = 0 # 1は素数ではない
    num_sqrt = math.sqrt(num)

    for prime in prime_list:
        if prime == 0:
            continue
        if prime > num_sqrt:
            break

        for non_prime in range(2 * prime, num, prime):
            prime_list[non_prime] = 0

    return [prime for prime in prime_list if prime != 0]

def search_divisor_num_1(num):
    if num < 0:
        return None
    elif num == 1:
        return 1
    else:
        num_sqrt = math.floor(math.sqrt(num))
        prime_list = make_prime_list_2(num_sqrt)

        divisor_num = 1
        for prime in prime_list:
            count = 1
            while num % prime == 0:
                num //= prime
                count += 1
            divisor_num *= count

        if num != 1:
            divisor_num *= 2

        return divisor_num

for i in range(n+1):
    if i%2==1 and search_divisor_num_1(i) == 8:
        cnt += 1

print(cnt)

Measured memory_bytes: 3064
def is_prime(n):
    if n < 2:
        return 0

    if n == 2:
        return 1

    if n % 2 == 0:
        return 0

    i = 3
    while i * i <= n:
        if n % i == 0:
            return 0
        i += 2

    return 1


A = [is_prime(i) for i in range(1 + 10 ** 5)]
S = [A[i] & A[(i + 1) // 2] for i in range(1 + 10 ** 5)]
T = [0] * (1 + 10 ** 5)
T[0] = S[0]
for i in range(1, 1 + 10 ** 5):
    T[i] = T[i - 1] + S[i]
Q = int(input())
for _ in range(Q):
    l, r = map(int, input().split())
    print(T[r] - T[l - 1])


Measured memory_bytes: 55164
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <stack>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

char str[1000];
int main() {
  while (fgets(str, 999, stdin), str[0] != '.') {
    stack<int> st;
    int len = strlen(str);
    bool ok = true;
    REP(i, len) {
      if (str[i] == '(') { st.push('('); }
      else if (str[i] == '[') { st.push('['); }
      else if (str[i] == ')') {
        if (st.empty() || st.top() != '(') { ok = false; break; }
        st.pop();
      } else if (str[i] == ']') {
        if (st.empty() || st.top() != '[') { ok = false; break; }
        st.pop();
      }
    }
    if (!st.empty()) { ok = false; }
    puts(ok ? "yes" : "no");
  }
}

Measured memory_bytes: 0
unittest
{
	assert( [ "5 3", "3 1 4", "1 5 9", "2 6 5", "3 5 8", "9 7 9" ].solve == 56 );
	assert( [ "5 3", "1 -2 3", "-4 5 -6", "7 -8 -9", "-10 11 -12", "13 -14 15" ].solve == 54 );
	assert( [ "10 5", "10 -80 21", "23 8 38", "-94 28 11", "-26 -2 18", "-69 72 79", "-26 -86 -54", "-72 -50 59", "21 65 -32", "40 -94 87", "-62 18 82" ].solve == 638 );
	assert( [ "3 2", "2000000000 -9000000000 4000000000", "7000000000 -5000000000 3000000000", "6000000000 -1000000000 8000000000" ].solve == 30000000000 );
}



import std.algorithm;
import std.conv;
import std.format;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = 0L;
	auto m = 0L;
	input.front.formattedRead!"%s %s"( n, m );
	auto xyzs = new long[ 3 ][ n ];
	foreach( ref xyz; xyzs )
	{
		input.popFront;
		xyz = input.front.split.to!( long[] );
	}
	
	// 綺麗さ、おいしさ、人気度ごとにプラスとマイナスのどっちを取るかを全ケース試す
	auto ans = 0L;
	ans = max( ans, solve2( m, xyzs, [  1L,  1L,  1L ] ) );
	ans = max( ans, solve2( m, xyzs, [  1L,  1L, -1L ] ) );
	ans = max( ans, solve2( m, xyzs, [  1L, -1L,  1L ] ) );
	ans = max( ans, solve2( m, xyzs, [  1L, -1L, -1L ] ) );
	ans = max( ans, solve2( m, xyzs, [ -1L,  1L,  1L ] ) );
	ans = max( ans, solve2( m, xyzs, [ -1L,  1L, -1L ] ) );
	ans = max( ans, solve2( m, xyzs, [ -1L, -1L,  1L ] ) );
	ans = max( ans, solve2( m, xyzs, [ -1L, -1L, -1L ] ) );
	return ans;
}

auto solve2( long m, long[ 3 ][] xyzs, long[ 3 ] ss )
{
	auto ts = new long[ xyzs.length ];
	foreach( ref t, xyz; lockstep( ts, xyzs ) )
	{
		t = ss[ 0 ] * xyz[ 0 ] + ss[ 1 ] * xyz[ 1 ] + ss[ 2 ] * xyz[ 2 ];
	}
	return ts.sort!( ( a, b ) => b < a ).take( m ).sum;
}


Measured memory_bytes: 3292
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
#include <set>
#include <map>
using namespace std;


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

	vector<int32_t> matrix(M);
	for (int32_t i = 0; i < M; i++) {
		int32_t k;
		cin >> k;
		matrix[i] = 0;
		for (int32_t j = 0; j < k; j++) {
			int32_t s;
			cin >> s;
			s--;
			matrix[i] |= 1 << s;
		}
	}

	vector<int32_t> p(M);
	for (int32_t i = 0; i < M; i++) {
		cin >> p[i];
	}

	int32_t res = 0;
	for (int32_t switch_state = 0; switch_state < (1 << N); switch_state++) {
		bool found = true;
		for (int32_t light = 0; light < M; light++) {
			int32_t cnt_on = 0;
			for (int32_t i = 0; i < N; i++) {
				if ((matrix[light] & (1 << i)) && (switch_state & (1 << i))) {
					cnt_on++;
				}
			}
			if (cnt_on % 2 != p[light]) {
				found = false;
				break;
			}
		}
		if (found)
			res++;
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

"""
参考：http://arc061.contest.atcoder.jp/data/arc/061/editorial.pdf
・各点が影響を与える9か所の正方形をメモしておく。
"""

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

H, W, N = MAP()
# その黒い点が含まれる正方形の左上座標を持っておく
xy = []
for i in range(N):
    a, b = MAP()
    a -= 1
    b -= 1
    for j in range(3):
        for k in range(3):
            # 3*3の正方形を作れない座標は除く
            if 0 <= a-j < H-2 and 0 <= b-k < W-2:
                xy.append((a-j, b-k))
# 各座標の出現数を集計
c = Counter(xy)
# 0以外はこの集計結果から集められる
ans = [0] * 10
for k, v in c.items():
    ans[v] += 1
# 黒い点が0個の正方形の数 = 候補となりうる全正方形の数 - 黒い点が1個でも出現した正方形の数
ans[0] = (H-2)*(W-2) - len(c)

for num in ans:
    print(num)


Measured memory_bytes: 157328
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bitset>
#include <math.h>
#include <iomanip>
#include <queue>
#define inp(X) cin >> X
#define out(X) cout << X << endl
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
using namespace std;

typedef long long int ll;
#define MOD 1000000007
#define INF 1000000001

ll gcd(ll x, ll y){
	if(y==0) return x;
	return gcd(y,x%y);
}

bool bfs(vector<vector<int>> g, vector<int> &dist, int sv)
{
	queue<int> q;
	q.push(sv);
	dist[sv]=0;
	while(!q.empty()){
		int now = q.front(); q.pop();
		for(auto v : g[now]){
			if(dist[v]!=-1) continue;
			dist[v] = dist[now]+1;
			q.push(v);
		}
	}
}

int main(void) {
	int n,l; cin >> n >> l ;
	int sum = (2*l+(n-1))*n/2;
	if(l>=0) sum -= l;
	else if(l<0 && n+l-1<0) sum -= n+l-1;
	out(sum);
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
#define ld long double
int main(){
  int n,h,w;
  cin>>n>>h>>w;
  cout<<(n-h+1)*(n-w+1)<<endl;
}

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

const ll mod = 1000000007;
const double eps = 1e-8;

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

template<typename A, size_t N, typename T>
void st_fill(A (&arr)[N], const T &val){ fill((T*)arr, (T*)(arr+N), val); }

int dp[101][100001];

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

    st_fill(dp, (int)1e9+1);
    dp[0][0] = 0;

    for (int i=1; i<=N; ++i) {
        int w, v;
        cin >> w >> v;

        for (int j=100000; j>=0; --j) {
            dp[i][j] = dp[i-1][j];
            if (j-v >= 0) dp[i][j] = min(dp[i][j], dp[i-1][j-v] + w);
        }
    }

    int max_v = 0;
    for (int i=0; i<100001; ++i) {
        if (dp[N][i] <= W) {
            max_v = i;
        }
    }
    cout << max_v << endl;
    
    return 0;
}

Measured memory_bytes: 39808
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr

typedef long long ll;

using namespace std;
//using namespace boost::multiprecision;

int main(){

    int n;
    cin >> n;

    vector<vector<pair<ll,ll>>> edge(n + 1);

    rep(i,n - 1){
        ll u,v,w;
        cin >> u >> v >> w;

        edge[u].pback(mpair(v,w));
        edge[v].pback(mpair(u,w));
    }

    vector<ll> len(n + 1, LLONG_MAX);

    priority_queue<pair<ll,ll>, vector<pair<ll,ll>>, greater<pair<ll,ll>>> pq;

    pq.push(mpair(0, 1));

    while(!pq.empty()){

        ll tmp_len = pq.top().first;
        ll node = pq.top().second;

        if(len[node] > tmp_len){
            len[node] = tmp_len;

            rep(i, edge[node].size()){
                ll next_node = edge[node][i].first;
                ll next_len = edge[node][i].second;
                
                pq.push(mpair(next_len + tmp_len, next_node));
            }
        }

        pq.pop();
    }

    for(int i = 1; i <= n; i++){
        //cerr << len[i] << " ";
        cout << len[i] % 2 << endl;
    }
    
    return 0;
}

Measured memory_bytes: 9216
#include <cstdlib>
#include <iostream>
#include <map>
#include <utility>
#include <vector>
using namespace std;

#define operation(x, y) \
{\
	if(house[y][x] >= 0 && !((visited >> house[y][x]) & 1)) {	\
		can_pass[y][x] = true;									\
		res += dfs(x, y, (visited | (1 << house[y][x])));		\
		can_pass[y][x] = false;									\
		break;													\
	}\
	if(!can_pass[y][x])\
		break;\
}

int w, h, num;
int sx, sy;
map<pair<short, int>, int> memo;
vector<vector<bool> > can_pass;
vector<vector<short> > house;

int dfs(int x, int y, int visited = 0) {
	if(visited == (1 << num) - 1)
		if(x == sx || y == sy)
			return 1;
		else
			return 0;

	if(memo.count(make_pair(house[y][x], visited)))
		return memo[make_pair(house[y][x], visited)];

	int res = 0;
	for(int i = x + 1; i < w; ++i)
		operation(i, y)

	for(int i = x - 1; i >= 0; --i)
		operation(i, y)

	for(int i = y + 1; i < h; ++i)
		operation(x, i)

	for(int i = y - 1; i >= 0; --i)
		operation(x, i)

	if(__builtin_popcount(visited) < 15)
		memo[make_pair(house[y][x], visited)] = res;
			
	return res;
}


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

	while(cin >> w >> h, w) {
		can_pass.clear();
		can_pass.resize(h, vector<bool>(w, false));
		house.clear();
		house.resize(h, vector<short>(w, -1));

		num = 0;
		for(int i = 0; i < h; ++i) {
			for(int j = 0; j < w; ++j) {
				int in;
				cin >> in;

				if(in == 1) {
					house[i][j] = num++;
				}

				else {
					can_pass[i][j] = true;
					if(in == 2) {
						sx = j;
						sy = i;
					}
				}
			}
		}

		memo.clear();
		cout << dfs(sx, sy) << endl;
	}


	return EXIT_SUCCESS;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

struct edge { ll to, d; };
vector<vector<edge>> adj;
vector<vector<ll>> result;
bool conflict = false;

void dfs(ll n=0, ll p=-1, ll mode=0) {
  for (auto x: adj[n]) {
    if (conflict) return;
    if (result[x.to][1-mode]!=LLINF) {
      if (result[x.to][1-mode] != x.d - result[n][mode]) {
        conflict = true;
        return;
      }
      else continue;
    }
    result[x.to][1-mode] = x.d - result[n][mode];
    dfs(x.to,n,1-mode);
  }
}

int main() {
  int n, m; cin >> n >> m;
  adj.resize(n);
  rep(i,m) {
    ll u, v, s; cin >> u >> v >> s; u--; v--;
    adj[u].push_back({v,s});
    adj[v].push_back({u,s});
  }

  result.resize(n,vector<ll>(2,LLINF));
  result[0][0] = 0;
  dfs();
  // rep(i,n) cout << result[i][0] << " " << result[i][1] << endl;

  if (conflict) {
    cout << 0 << endl;
  }
  else if (result[0][1]!=LLINF) {
    ll diff = result[0][0]-result[0][1];
    ll sum = result[0][0]+result[0][1];
    if (diff%2!=0||sum<=0) cout << 0 << endl;
    else {
      bool ok = true;
      rep(i,n) {
        ll diff2 = result[i][0]-result[i][1];
        ll sum2 = result[i][0]+result[i][1];
        if (diff2!=diff||sum2<=0) ok = false;
      }
      ll result = ok ? 1 : 0;
      cout << result << endl;
    }
  }
  else {
    ll ma = LLINF, mi = 1;
    bool ok = true;
    rep(i,n) {
      if (result[i][0]!=LLINF) mi = max(mi,max((ll)0,-1*result[i][0]+1));
      else {
        if (result[i][1]<=1) { ok = false; break; }
        ma = min(ma,result[i][1]-1);
      }
    }
    if (!ok) cout << 0 << endl;
    else {
      ll result = max((ll)0,ma-mi+1);
      cout << result << endl;
      // cout << mi << "~" << ma << endl;
    }
  }
  return 0;
}

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


int main(){
  long long n, ans[55];

  cin >> n;

  int cnt = 0;
  bool f;
  for(int i = 2; cnt < n ; i += 5){
    f = true;
    for(int k=2; k<sqrt(i); ++k){
      if(i%k == 0){
	f = false;
	break;
      }
    }
    
    if(!f)continue;
    
    ans[cnt++] = i;
  }

  for(int i=0; i<n; ++i){
    cout << ans[i];
    if(i != n-1) cout << " ";
  }
  cout << endl;
  
  return 0;
}


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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    vector<int> a(3);
    cin >> a[0] >> a[1] >> a[2];
    sort(a.begin(), a.end());
    if(a[0] == 5 and a[1] == 5 and a[2] == 7){
        cout << "YES" << endl;
    }else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import Counter

def main():
    n = int(input())
    a = list(map(int, input().split()))
    counter = Counter(a)
    yield sum(1 for v in counter.values() if v%2==1)
    evens = sum(1 for v in counter.values() if v%2==0)
    if evens % 2 == 0:
        yield evens
    else:
        yield evens - 1


print(sum(main()))



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

using namespace std;

int main(void){
    int N, Y;
    cin >> N >> Y;
    Y /= 1000;

    for(int x=0;x<=2000;x++){
        for(int y=0;y<=2000;y++){
            if(9*x+4*y == Y-N){
                int z = N - x - y;
                if(z >= 0 && 10*x+5*y+z == Y){
                    cout << x << " " << y << " " << z << endl;
                    return 0;
                }
            }
        }
    }

    cout << "-1 -1 -1" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long n,p,a,b[2];
int main(){
  cin>>n>>p;
  for(int i=0;i<n;++i){
    cin>>a;
    b[a%2]++;
  }
  cout << (b[1]?(long long)1<<(n-1):p?0:(long long)1<<n) << endl;
  return 0;
}

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

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline T gcd(T m, T n) {
  if (n == 0)
    return m;
  else
    return gcd(n, abs(m) % abs(n));
}

#define IOS ios::sync_with_stdio(false), cin.tie(nullptr)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greater<int>()
#define MAX(a) *max_element(all(a))

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vc = vector<char>;
using vs = vector<string>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vvi;

const int INF = 1001001001;
const int MOD = 1000000007;
const long long INFL = (1LL << 60);
const double EPS = 1e-9;

int main() {
  IOS;
  constexpr char endl = '\n';

  int N, K;
  cin >> N >> K;
  vi a(N, 0);
  rep(i, K) {
    int d;
    cin >> d;
    rep(j, d) {
      int idx;
      cin >> idx, idx--;
      a[idx]++;
    }
  }

  int res = 0;
  rep(i, N) if (!a[i]) res++;

  cout << res << endl;
}


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

using ll_t = long long;
const int MAXN = (int)2e5;

int a[MAXN], f[MAXN];

ll_t min_op_num(int n, ll_t limit) {
  ll_t res = 0;
  for (int i = 0; i < n; ++i) {
    ll_t cur = limit / f[i];
    res += std::max((ll_t)a[i] - cur, (ll_t)0);
  }
  return res;
}

ll_t solve(int n, ll_t k) {
  std::sort(f, f + n, [](int x, int y) {return x > y;});
  std::sort(a, a + n);
  
  ll_t l = -1, r = (ll_t)a[0] * f[0];
  for (int i = 1; i < n; ++i) {
    if ((ll_t)a[i] * f[i] > r) {
      r = (ll_t)a[i] * f[i];
    }
  }
  while (r - l > 1) {
    ll_t mid = (l + r) >> 1;
    if (min_op_num(n, mid) > k) l = mid;
    else r = mid;
  }
  return r;
}

int main() {
  int n;
  ll_t k;
  std::cin >> n >> k;
  for (int i = 0; i < n; ++i) std::cin >> a[i];
  for (int i = 0; i < n; ++i) std::cin >> f[i];
  std::cout << solve(n, k) << std::endl;
  return 0;
}


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

int main()
{
	int N;
	int X, Y, Z;
	cin >> N; 
	cin >> X;
	vector<int> a(X,0);
	for (int i = 0; i < X; i++)
		cin >> a[i];

	cin >> Y;
	vector<int> b(Y,0);
	for (int i = 0; i < Y; i++)
		cin >> b[i];

	cin >> Z;
	vector<int> c(Z,0);
	for (int i = 0; i < Z; i++)
		cin >> c[i];

	int conf = 0;
	int i = 0;
	int j = 0;
	int k = 0;
	bool fnd = false;
	for (int i = 0; i < Y; i++) {
		for (int j = 0; j < Z; j++) {
			if (b[i] == c[j]) {
				fnd = true;
				b.erase(b.begin() + i);
				i--;
				Y--;
				c.erase(c.begin() + j);
				j--;
				Z--;
				conf++;

			}
		}
	}
	for (int i = 0; i < X; i++) {
		for (int j = 0; j < Z; j++) {
			if (a[i] == c[j]) {
				c.erase(c.begin() + j);
				j--;
				Z--;
			}
		}
	}
	cout << conf + c.size() << endl;
	int m;
	cin >> m;
	return 0;

}

Measured memory_bytes: 3160
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>
#include <tuple>
#include <set>
#include <functional>

using namespace std;

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

    int z = 0, o = 0;
    
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '0') o++;
        else z++;
    }

    if (o == 0 || z == 0) cout << 0 << endl;
    else cout << min(o, z) * 2 << endl;

    return 0;
}


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

//100で割れる回数を確かめる関数
int func(int X){
  if(X%100!=0){
    return 0;
  }
  return func(X/100)+1;
}

int main(){
  int D,N;
  cin >> D >> N;
  int count=0;
  for(int i=1;;i++){
    if(func(i)==D){
      count++;
    }
    if(count==N){
      cout << i << endl;
      break;
    }
  }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep0(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<string, int, int> TU;

int main()
{
    int A;
    cin >> A;
    vector<int> input(A);
    int sum = 0;
    int max = 0;
    rep0(i,A){
        cin >> input[i];
        if(max<input[i]){
            max = input[i];
        }
        sum+=input[i];
    }
    cout << sum-max/2;
}


Measured memory_bytes: 3516
#include<bits/stdc++.h>
using namespace std;
int n;
string title[55];
int tim[55];
int main()
{
    cin>>n;
    for(int i=1;i<=n;++i)
    {
        cin>>title[i]>>tim[i];
    }
    string s;
    cin>>s;
    bool flag = 0;
    int ans = 0;
    for(int i=1;i<=n;++i)
    {
        if(flag)ans += tim[i];
        if(title[i]==s)flag=1;
    }
    cout<<ans<<endl;
}

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

using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define allr(v)				((v).rbegin()), ((v).rend())
#define sz(v)				((int)((v).size()))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
#define ll long long
#define pb					push_back
#define fIO ios_base::sync_with_stdio(0);cin.tie(0);

const ll oo = 1e8;
const double pi = 3.1415926535897;


const double EPS = (1e-7);
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}


typedef vector<int>                vi;
typedef vector<pair<int,int>>      vii;
typedef vector<ll>                 vll;
typedef vector<double>             vd;
typedef vector< vi >               vvi;
typedef vector< vd >               vvd;
typedef vector<string>             vs;
typedef pair<int, int>             pii;

/**
    * PLEASEEE READDD PROBLEEEM CARFULLY ****
    * Always check for OVERFLOW ll vs int
    * Always check for array bounds
    * Check for function return
    * READ OUTPUT SECTION AGAIN!!!
**/

struct edge{
    int from, to, w;

    edge(){}
    edge(int x, int y, int we): from(x), to(y), w(we){}

    bool operator < (const edge &rhs) const{
        return w > rhs.w;
    }

};

const int N = 1e5 + 5;

int par[N];
int grpSz[N];
vi adj[N], adjB[N];
ll ans[N] = {};
int vis[N];

int get(int nd) {
    return par[nd] == nd ? nd : par[nd] = get(par[nd]);
}

void unite(int x, int y) {
    int p1 = get(x), p2 = get(y);

    if(p1 == p2) return;

    grpSz[p1] += grpSz[p2];
    par[p2] = p1;
}

void dfs(int nd) {
    vis[nd] = 1;

    for(auto ch : adjB[nd]) {
        if(get(ch) == get(nd)) ans[nd]--;
        if(!vis[ch]) dfs(ch);
    }
}

void dfs2(int nd) {
    vis[nd] = 1;

    for(auto ch : adj[nd]) {
        ans[nd]--;

        if(!vis[ch]) dfs2(ch);
    }
}

int main(){
    fIO

    int n, m, k;
    cin >> n >> m >> k;

    for(int i = 0; i < n; i++) {
        par[i] = i;
        grpSz[i] = 1;
    }

    int x, y;
    for(int i = 0; i < m; i++) {
        cin >> x >> y;
        x--; y--;

        adj[x].pb(y);
        adj[y].pb(x);
        unite(x, y);
    }

    for(int i = 0; i < n; i++) get(i);

    for(int i = 0; i < k; i++){
        cin >> x >> y;
        x--; y--;

        adjB[x].pb(y);
        adjB[y].pb(x);
    }

    for(int i = 0; i < n; i++) {
        ans[i] = grpSz[get(i)] - 1;
        //cout << ans[i] << " ";
    }
    //cout << "\n";
    for(int i = 0; i < n; i++) {
        if(vis[i]) continue;

        dfs(i);
    }

    memset(vis, 0, sizeof(vis));
    for(int i = 0; i < n; i++) {
        if(vis[i]) continue;

        dfs2(i);
    }


    for(int i = 0; i < n; i++) cout << ans[i] << " ";
}








Measured memory_bytes: 14968
/*
ID: wangjun30
LANG: C++11
TASK:
*/
#include<iostream>
#include<algorithm>
#include<array>
#include<unordered_map>
#include<map>
#include<set>
#include<list>
#include<unordered_set>
#include<vector>
#include<bitset>
#include<queue>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<climits>
//#include<fstream>
#define int long long
using namespace std;
//ifstream cin(".in");
//ofstream cout(".out");
int gcd(int a,int b){
	int r=a%b;
	while(r!=0){
		a=b;
		b=r;
		r=a%b;
	}
	return b;
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int n;
	cin>>n;
	int ans=0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			for(int k=1;k<=n;k++)
				ans+=gcd(gcd(i,j),k);
	cout<<ans;
	return 0;
}

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

int main(){
  ll n, a, b;
  cin >> n >> a >> b; 
  if(b < a || (n == 1 && a != b)) cout << 0 << endl;
  else {
    ll ans = (b-a)*(n-2)+1;
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,n) for(int i = 0;i < (int)(n);i++)
#define RREP(i,n) for(int i = (int)n-1;i >= 0;i--)
#define FOR(i,s,n) for(int i = s;i < (int)n;i++)
#define RFOR(i,s,n) for(int i = (int)n-1;i >= s;i--)
#define ALL(a) a.begin(),a.end()
#define IN(a, x, b) (a<=x && x<b)
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a = b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a = b;return true;}return false;}
template<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void OUT(T t){cout<<t<<"\n";}
template<class T,class... Ts>inline void OUT(T t,Ts... ts){cout<<t<<" ";OUT(ts...);}
template<typename T=int>vector<T>mv(size_t a){return vector<T>(a);}
template<typename T=int,typename... Ts>auto mv(size_t a,Ts... ts){return vector<decltype(mv<T>(ts...))>(a,mv<T>(ts...));}
template<typename T,typename V>typename enable_if<is_class<T>::value==0>::type FILL(T&t,const V&v){t=v;}
template<typename T,typename V>typename enable_if<is_class<T>::value!=0>::type FILL(T&t,const V&v){for(auto &e:t)FILL(e,v);}
constexpr long long INF = 1e18;

signed main(){
	int N,K;
	cin>>N>>K;
	auto f =[&](int x)->bool{
		int sum = x;
		int num = 0;
		while(x){
			if(++num==N)break;
			sum+=x/2;
			x/=2;
		}
		return K >= sum;
	};
	int l = -1, r = 1e18 + 1;
	while(r - l > 1){
		int c = (l + r) / 2;
		if(f(c)) l = c;
		else r = c;
	}
	cout << l << endl;
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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 (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    string s,t;
    cin>>s>>t;
    cout<<t<<s<<endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int n;
    cin >> n;
    int odd = 0;
    for(int i = 0;i < n;i++)
    {
        int a;
        cin >> a;
        if(a % 2 == 1)
        {
            odd++;
        }
    }
    if(odd % 2 == 0)
    {
        cout << "YES\n";
    }
    else
    {
        cout << "NO\n";
    }
    
    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 ll long long
const long long INF = 1LL<<60;
const long long mod = 1e9 + 7;

int main(){
    int N, T;
    cin >> N >> T;
    int c[1010], t[1010];
    REP(i, N){
        cin >> c[i] >> t[i];
    }
    int ans = 1010;
    REP(i,N){
        if(t[i] <= T) ans = min(ans, c[i]);
    }
    if(ans == 1010) cout << "TLE" << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <complex>
using namespace std;

#define X real()
#define Y imag()
#define EPS 1e-8
#define EQ(x, y) (abs((x)-(y)) < EPS)

typedef complex<double> Point;

struct Circle {
  Point c;
  double r;
};

int n;
Circle cs[100000];

vector<Point> CrossPointCC(Circle a, Circle b) {
  vector<Point> ret;
  double d = abs(b.c-a.c);
  double rc = (d*d + a.r*a.r - b.r*b.r) / (2*d);
  double dfr = a.r*a.r - rc*rc;
  if (EQ(dfr, 0.0)) dfr = 0.0;
  else if (dfr < 0.0) return ret;

  double rs = sqrt(dfr);

  Point sgn = (b.c-a.c) / d;
  ret.push_back(a.c + sgn * Point(rc, rs));
  if (dfr > 0.0) {
    ret.push_back(b.c + sgn * Point(rc, -rs));
  }
  return ret;
}

int main() {
  while (1) {
    scanf("%d", &n);
    if (n == 0) return 0;
    
    for (int i=0; i<n; i++) {
      double x, y;
      scanf("%lf,%lf", &x, &y);
      cs[i] = {Point(x, y), 1.0};
    }

    vector<Point> candidates;
    for (int i=0; i<n; i++) {
      for (int j=i+1; j<n; j++) {
        vector<Point> ps = CrossPointCC(cs[i], cs[j]);
        candidates.insert(candidates.end(), ps.begin(), ps.end());
      }
    }

    int ans = 1;
    for (int i=0; i<candidates.size(); i++) {
      Point p = candidates[i];
      if (p.X < 0.0 || p.X > 10.0) continue;
      if (p.Y < 0.0 || p.Y > 10.0) continue;

      int cnt = 0;
      for (int i=0; i<n; i++) {
        if (abs(cs[i].c-p) < 1.0+EPS) cnt++;
      }

      ans = max(ans, cnt);
    }

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

Measured memory_bytes: 5092