akhauriyash/Code-Regression huggingface dataset:
fun main() = Thread(null, ::abc173c, "(^o^)", 128 * 1024 * 1024).apply { start() }.join()

@OptIn(ExperimentalStdlibApi::class)
fun abc173c() {
    val (h, w, k) = readLine()!!.split(' ').map { it.toInt() }
    val grid = Array(h) { readLine()!!.map { it == '#' }.toBooleanArray() }

    var answer = 0

    searchAllPatterns(arrayOf(false, true), h) { chooseHorizontal ->
        searchAllPatterns(arrayOf(false, true), w) { chooseVertical ->
            var count = 0
            for (y in 0 until h) for (x in 0 until w) {
                if (chooseHorizontal[y] && chooseVertical[x] && grid[y][x]) count++
            }
            if (count == k) answer++
        }
    }

    println(answer)
}

@Suppress("SameParameterValue")
private inline fun <reified T> searchAllPatterns(patterns: Array<T>, length: Int, action: (Array<T>) -> Unit) {
    val patternSize = patterns.size
    val pow = (1..length).fold(1L) { acc: Long, _: Int -> acc * patternSize }
    val allPatterns = if (pow in 1..Int.MAX_VALUE) pow.toInt() else error("$pow is too large!")
    for (i in 0 until allPatterns) {
        val array = Array(length) { patterns[0] }
        var div = 1
        for (j in 0 until length) {
            array[length - j - 1] = patterns[(i / div) % patternSize]
            div *= patternSize
        }
        action(array)
    }
}


Measured memory_bytes: 39712
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);

		int k = s.nextInt();
		int a = s.nextInt();
		int b = s.nextInt();
		int flag = 0;

		for (int i = 1; k * i <= 1000; i++) {
			if(k * i >= a && k * i <= b) {
				flag++;
			}
		}

		if(flag != 0) {
			System.out.println("OK");
		} else {
			System.out.println("NG");
		}

		s.close();

	}
}


Measured memory_bytes: 35768
#include "bits/stdc++.h"

#define REP(i, a, b) for (int i = (a); i <= (b); ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define FORV(a, A) for (auto &a : A)

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

const ll MAX = 1000000;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit()
{
   fac[0] = fac[1] = 1;
   finv[0] = finv[1] = 1;
   inv[1] = 1;
   for (ll i = 2; i < MAX; i++)
   {
      fac[i] = fac[i - 1] * i % MOD;
      inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
      finv[i] = finv[i - 1] * inv[i] % MOD;
   }
}

long long COM(ll n, ll k)
{
   if (n < k)
      return 0;
   if (n < 0 || k < 0)
      return 0;
   return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

void Main()
{
   int N, M;
   cin >> N >> M;
   COMinit();

   ll ans = 1;
   ll cal;
   ll a, x, now = 0;
   REP(i, 0, M - 1)
   {
      cin >> a;
      if (a == now - 1)
         continue;
      if (a == now)
      {
         cout << 0 << endl;
         return;
      }
      cal = 0;
      REP(i, 0, (a - now - 1) / 2)
      {
         cal += COM(a - now - 1 - i, i);
      }
      cal %= MOD;
      ans = (ans * cal) % MOD;
      now = a + 1;
   }
   cal = 0;
   REP(i, 0, (N - now) / 2)
   {
      cal += COM(N - now - i, i);
   }
   cal %= MOD;
   ans = (ans * cal) % MOD;
   cout << ans << endl;
}

int main()
{
   std::cin.tie(nullptr);
   std::ios_base::sync_with_stdio(false);
   std::cout << std::fixed << std::setprecision(15);
   Main();
   return 0;
}

Measured memory_bytes: 23680
func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func main() {
    let line = readInts()
    let n = line[0]
    let r = line[1]
    
    if n >= 10 {
        print(r)
    } else {
        print(r + 100 * (10 - n))
    }
}

main()


Measured memory_bytes: 8264
#include <iostream>
using namespace std;
int n, m, u, v, w, s, a[105][105], b[105][105];
int main() {
	int i, j, k;
	cin>>n>>m;
	for(i=1; i<=n; i++) for(j=1; j<=n; j++) a[i][j] = 1e9;
	while(m--) {
		cin>>u>>v>>w;
		a[u][v] = a[v][u] = b[u][v] = b[v][u] = w;
	}
	for(k=1; k<=n; k++) for(i=1; i<=n; i++) for(j=1; j<=n; j++)
		a[i][j] = min(a[i][j], a[i][k] + a[k][j]);
	for(i=1; i<=n; i++) for(j=i+1; j<=n; j++) s += a[i][j] < b[i][j];
	cout<<s;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main() {
	
	int N;
	int H[100010];
	cin >> N;
	for (int i = 0; i < N; i++) cin >> H[i];

	int max = 0;
	int count = 0;

	for (int i = 0; i < N - 1; i++)
	{
		if (H[i] >= H[i + 1])
		{
			count++;
			if (max < count) max = count;

		}
		else
		{
			if (max < count) max = count;
			count = 0;
		}
	}

	cout << max << endl;

	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>

int main(){

  int i, j, k, n, key;

  scanf("%d", &n);

  int a[n];

  for(i=0;i<=n-1;i++){

    scanf("%d", &a[i]);

  }

  for(i=0;i<=n-1;i++){

    if(i==0) printf("%d",a[i]);

    else printf(" %d", a[i]);

  }printf("\n");

  for(i=1;i<=n-1;i++){

    key=a[i];

    j=i-1;

    while(j>=0 && a[j]>key){

      a[j+1] = a[j];

      j--;

    }

    a[j+1] = key;

    for(k=0;k<=n-1;k++){

      if(k==0) printf("%d",a[k]);

      else printf(" %d", a[k]);

    }printf("\n");

  }

  return 0;

}



Measured memory_bytes: 2044
# include <iostream>
using namespace std;
const int N=16;
struct node
{
	int x,y,z;
}a[N];
int n,m,s;
void work (void)
{
	int i,j,p,q,u,t,f;
	for (i=0;i<1<<n;i++)
	{
		f=0;
		p=i;
		q=0;
		t=0;
		for (j=n;j>=1;j--)
		{
			if (p%2==1)
			{
				t+=a[j].z;
				q+=a[j].x;
			}
			p/=2;
		}
		j=n;
		p=i;
		if (t<m)
		while (j>=1)
		{
			if (p%2==0)
			{
				u=t+a[j].x*j*100;
				if (u<m)
				{
					t=u;
					q+=a[j].x;
				}
		   else
		        {
		        	q+=(m-t+(j-1)*100)/(j*100);
		        	f=1;
		        	break;
				}
			}
			p/=2;
			j--;
		}
   else f=1;
        if (f==1)
        if (q<s)
        s=q;
	}
	cout<<s;
}
int main (void)
{
	int i;
	s=1000000000;
	cin>>n>>m;
	for (i=1;i<=n;i++)
	{
		cin>>a[i].x>>a[i].y;
		a[i].z=a[i].x*i*100+a[i].y;
	}
	work ();
	return 0;
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


A = LS2()
N = len(A)

from collections import defaultdict

d = defaultdict(int)
for i in range(N):
    d[A[i]] += 1


ans = 0
for key in d.keys():
    ans += d[key]*(N-d[key])

ans //= 2
ans += 1
print(ans)


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

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

	ll a,b,c,d,e,f;
	int i,k;
	ll ans=-1e18;
	int ctr=0;
	vector<ll> gv(10);

	cin >> a >> b >> c >> d;

	gv[0]=a*c;
	gv[1]=a*d;
	gv[2]=b*c;
	gv[3]=b*d;

	rep(i,4){
		ans=max(ans,gv[i]);
	}
	cout << ans << endl;

	return 0;
}



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

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

    int cnt = 0;
    for (int i = 0; i < 4; i++) {
        if (S[i] == '+') {
            cnt++;
        }
        else if (S[i] == '-') {
            cnt--;
        }
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

class D
{
    static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        var A = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var B = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var C = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        int add = 0;
        for(int i = 0; i < N-1; i++)
        {
            if (A[i]+1 == A[i + 1])
                add += C[A[i]-1];
        }
        int sum = B.Sum();
        Console.WriteLine(sum+add);
        
    }
}


Measured memory_bytes: 13396
def main():
    H, W, N = map(int, input().split())
    C = {}
    for _ in range(N):
        a, b = map(int, input().split())
        for x in range(max(2, a - 1), min(H, a + 2)):
            for y in range(max(2, b - 1), min(W, b + 2)):
                C[(x, y)] = C.get((x, y), 0) + 1
    D = list(C.values())
    print((H - 2) * (W - 2) - len(C))
    for j in range(1, 10):
        print(D.count(j))

main()


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


int main() {
  string N;
  cin >> N;
  string ans = "abcdefghijklmnopqrstuvwxyz";

string res="0";
sort(ans.begin(), ans.end(), greater<int>());
for (int i=0; i<26;i++){
  if(N.find(ans[i])==std::string::npos){
    res=ans[i];
  }
}

if (res=="0"){
  res = "None";
}
  cout << res << endl;
}



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

#define rep(i,n)  for(int i=0;i<n;++i)
#define sc1(a)  scanf("%d",&a)

int main(){
    int mod=1000000007;
    int n,ans=0;
    sc1(n);
    int v[n],c[n];
    rep(i,n) sc1(v[i]);
    rep(i,n) sc1(c[i]);
    rep(i,n) if (v[i]>c[i]) ans+=v[i]-c[i];
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 3832
// Header {{{
#include <bits/stdc++.h>

using namespace std;
template<typename T>
using reversed_priority_queue = std::priority_queue<T, std::vector<T>, std::greater<T> >;
typedef unsigned long long int ull;
typedef long long int ll;
#define rep(i,a,b) for (ll i=(a); i<(b); i++)
typedef pair<ll,ll> PLL;
// }}}

signed main() {
    ll n;
    cin>>n;
    ll n2 = 0, n4 = 0;
    rep(i,0,n){
        ll a;
        cin>>a;
        if(a%4==0)
            n4++;
        else if(a%2==0)
            n2++;
    }
    if (n2>0)
        n -= n2-1;
    if(n4 >= (n/2)){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>

using namespace std;

int main(void) {
  int N, K;
  int m;
  
  cin >> N >> K;
  
  if (K > (N - 1) * (N - 2) / 2) {
    cout << -1 << endl;
  } else {
    m = N - 1 + (N - 1) * (N - 2) / 2 - K;
    cout << m << endl;
    for (int i = 0; i < N - 1; i++) {
      cout << 1 << " " << i + 2 << endl;
    }
    int r = (N - 1) * (N - 2) / 2 - K;
    
    for (int u = 2; u < N && r > 0; u++) {
      for (int v = u + 1; v <= N && r > 0; v++) {
        cout << u << " " << v << endl;
        r--;
      }
    }
  }
  return 0;
}

  

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue> //priority_queue
#include <map>
#include <set> //multiset set<int,greater<int>>大到小
#include <vector>// vector<int>().swap(v);清空释放内存
#include <stack>
#include <cmath> // auto &Name : STLName  Name.
#include <utility>
#include <sstream>
#include <string>//__builtin_popcount(ans);//获取某个数二进制位1的个数
#define mod 1000000007
#define mod9 998244353
typedef unsigned long long ull;
typedef long long ll;
typedef double db;
typedef long double ld;
const db eps=1e-10;
const int INF = 0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
#define rep(i,be,en) for (int i=be;i<=en;i++)
#define per(i,be,en) for (int i=en;i>=be;i--)
using namespace std;
const int N=1e6+7;

int t,n,m,k=0,fl=0;
db a;
int main(){
    scanf("%lf",&a);
    printf("%.3lf\n",2*3.1415*a);

    return 0;
}

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

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
#define all(v) (v).begin(), (v).end()
#define sz(v) (int) (v).size()

int main(int argc, char* argv[]) {
  ios::sync_with_stdio(0); cin.tie(0);
  int n;
  cin >> n;
  vector dp(n + 1, vector<int>(3, 0));
  dp[0][0] = dp[0][1] = dp[0][2] = 0;
  for (int i = 1; i <= n; i++) {
    vector<int> b(3);
    for (int j = 0; j < 3; j++)
      cin >> b[j];
    for (int j = 0; j < 3; j++) 
      for (int k = 0; k < 3; k++) 
        if (j != k)
          dp[i][j] = max(dp[i][j], dp[i - 1][k] + b[j]);
  }   
  cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << '\n';
  return 0;
}

Measured memory_bytes: 8708
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <string>
#include <math.h>
#include <vector>
#include <cstdlib>
#include <queue>
#include <iomanip> //小数点以下を表示させる(setprecision())

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'

//DP法
template <class T>
inline bool chmin(T &a, T b) //change minimum
{
        if (a > b)
        {
                a = b;
                return true;
        }
        return false;
}
template <class T>
inline bool chmax(T &a, T b) //change max
{
        if (a < b)
        {
                a = b;
                return true;
        }
        return false;
}

typedef long long ll; //64bit型
using namespace std;

// const long long INF = 1LL << 60; //無限大の値
int INF = 1000000;

ll high_gcd(ll a, ll b)
{

        return b ? high_gcd(b, a % b) : a;
}

ll kosuu(ll a, ll b, ll c)
{
        ll d = (a + c - 1) / c;
        ll e = b / c;

        ll ans = e - d + 1;

        return ans;
}

int main()
{

        ll A, B, C, D;
        cin >> A >> B >> C >> D;

        if (C < D)
        {
                swap(C, D);
        }

        ll gcd = high_gcd(C, D);
        ll lcm = C / gcd * D;

        ll ans = B - A + 1;

        ll kazu = 0;

        kazu = kosuu(A, B, C);
        ans -= kazu;

        kazu = kosuu(A, B, D);
        ans -= kazu;

        kazu = kosuu(A, B, lcm);
        ans += kazu;
        cout << ans << endl;

        return 0;
}


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

int N;
vector<int> a;
vector<int> a2;
//Binary Indexed Treeを用いる
//最大で200000までしかいかない
int bit[200001];
//bitを足す時はLSBが小さい方から大きい方へ
void add(int a, int w){
    for (int x = a; x<200001; x += x & -x) bit[x] += w;
}
//和を求める時は、LSBが大きい方から小さい方へ
int sum(int a){
    int ret = 0;
    for (int x = a; x>0; x -= x & -x) ret += bit[x];
    return ret;
}

//x以上の要素がaの半数より多く存在するときture
bool check(int x){
    //bitを初期化
    for (int i = 0; i<200001; i++) bit[i] = 0;
    //x以上とx未満を1と−1に置き換え
    vector<int> a3(N);
    for (int i = 0; i<N; i++){
        if (a2[i]>=x) a3[i] = 1;
        else a3[i] = -1;
    }
    //累積和
    //BITでは0以下の数を扱えないので、はじめに10^5を足しておけばよい
    vector<int> acc(N+1);
    acc[0] = 100000;
    for (int i = 1; i<N+1; i++) acc[i] = 0;
    for (int i = 0; i<N; i++) acc[i+1] = a3[i] + acc[i];
    
    long long ans = 0;
    for (int i = 0; i<N+1; i++){
        ans += sum(acc[i]);
        add(acc[i],1);
    }
    //ansがNの半数より大きいならtrue
    if (ans*2 >= (long long)N*(N+1)/2) return true;
    else return false;
}

//checkを満たす最小の整数を返す
int binarysearch(){
    int ng = N;
    int ok = -1;
    while (abs(ok-ng)>1){
        int mid = (ok+ng)/2;
        if (check(a[mid])) ok = mid;
        else ng = mid;
    }
    return ok;
}

int main(){
    cin >> N;
    vector<int> raw_a(N);
    for (int i = 0; i<N; i++){
        cin >> raw_a[i];
    }
    a = raw_a;
    a2 = raw_a;
    sort(a.begin(),a.end());
    
    cout << a[binarysearch()] << endl;
    
}


Measured memory_bytes: 3040
#include <bits/stdc++.h>
using namespace std;
long n,k,x,y;
int main()
{
    cin>>n>>k>>x>>y;
    if(n<=k)
    {
        cout<<n*x;
    }
    if(n>k)
    {
        cout<<x*k+(n-k)*y;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int A = sc.nextInt();
      int B = sc.nextInt();
      int i;
      for(i=1;i<=1000;i++){
        if(Math.floor(i*0.08)==A && Math.floor(i*0.1)==B){
          System.out.println(i);
          return;
        }
      }
        System.out.print("-1");
    }
}


Measured memory_bytes: 35672
N = int(input())
A = list(map(int, input().split()))

total = 0
total = abs(A[0])
total += abs(A[N - 1])
for i in range(1, N):
    total += abs(A[i - 1] - A[i])

amounts = [0] * N
for i in range(N):
    left = 0
    right = 0
    if i > 0:
        left = A[i - 1]
    if i < N - 1:
        right = A[i + 1]
    amounts[i] = total + abs(left - right) - (abs(left - A[i]) + abs(A[i] - right))

for i in range(N):
    print(amounts[i])


Measured memory_bytes: 14172
N = int(input())
s = input()
# 左側のWの数と右側のEの数を数える (和が小さいのが答え)
# min = 3 * 10**5
# 毎回list_aとかの中身を計算させているのが良くない
# (一回計算したらわかる話)
list_a_cnt = 0
list_b_cnt = 0
list_a = list(s[0:0])
#print("list_a",list_a)
list_b = list(s[0:])
#print("list_b",list_b)
list_b_cnt = list_b.count('E')
min = list_a_cnt + list_b_cnt
for i in range(N):
    if s[i] == "W":
        list_a_cnt += 1
    elif s[i] == "E":
        list_b_cnt -= 1
    #print(s[0:i],s[i:])
    #print(list_a_cnt,list_b_cnt)
    if list_a_cnt + list_b_cnt < min:
        min = list_a_cnt + list_b_cnt
print(min)


Measured memory_bytes: 5920
N, M, X, Y = map(int, raw_input().split(' '))
Xs = sorted(map(int, raw_input().split(' ')) + [X])
Ys = sorted(map(int, raw_input().split(' ')) + [Y])

if max(Xs) < min(Ys):
    print 'No War'
else:
    print 'War'

Measured memory_bytes: 2568
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[8] = {-1,0,1,0,-1,1,1,-1};
int dx[8] = {0,1,0,-1,1,1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 2100;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,x,y;
    cin>>n>>x>>y;
    x--;y--;
    int res[d5];
    fill(res,res+d5,0);
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            int d=min({abs(j-i),abs(x-i)+1+abs(y-j),abs(y-i)+1+abs(x-j)});
            res[d]++;
        }
    }
    for(int i=1;i<n;i++){
        cout<<res[i]<<endl;
    }
}

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

int main() {
    int N;
    cin >> N;
    long A[N], x = 0;
    rep(i, N) {
        cin >> A[i];
        x += A[i];
    }

    for (int i = 1; i < N; i += 2) {
        x -= 2 * A[i];
    }
    cout << x;
    rep(i, N-1) {
        x = 2 * A[i] - x;
        cout << " " << x;
    }
    puts("");
}

Measured memory_bytes: 2048
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    void solve() {
        string s;
        cin >> s;
        if (s[0] == s[1] && s[1] == s[2]) {
            cout << "No" << endl;
        } else {
            cout << "Yes" << endl;
        }
    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 888
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;

namespace atcorder
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            int len = s.Length;
            if(s.Substring(len - 1, 1) == "2" || s.Substring(len - 1, 1) == "4" || s.Substring(len - 1, 1) == "5" || s.Substring(len - 1, 1) == "7" || s.Substring(len - 1, 1) == "9")
            {
                Console.WriteLine("hon");
            }
            if (s.Substring(len - 1, 1) == "0" || s.Substring(len - 1, 1) == "1"|| s.Substring(len - 1, 1) == "6" || s.Substring(len - 1, 1) == "8")
            {
                Console.WriteLine("pon");
            }
            if (s.Substring(len - 1, 1) == "3")
            {
                Console.WriteLine("bon");
            }
        }
    }
}

//文字配列の取得
//string[] strArray = Console.ReadLine().Split(' ').ToArray();
//string S = strArray[0];
//string T = strArray[1];

//文字列の取得
//string s = Console.ReadLine();

//数字配列の取得
//int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
//int H = intArray[0];
//int W = intArray[1];

//数字の取得
//int N = int.Parse(Console.ReadLine());

//リスト型(int)の取得
//List<int> A = new List<int>(Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray());

//出力
//Console.WriteLine(ans);
//Console.WriteLine("Yes");
//Console.WriteLine("No");
//Console.WriteLine(cnt);



Measured memory_bytes: 25868
MAXN = 1005
MAXV = (MAXN * (MAXN - 1)) // 2
to = [[] for _ in range(MAXV)]
ID = [[-1] * MAXN for _ in range(MAXN)]

def toID(i, j):
    if i > j:
        i, j = j, i
    return ID[i][j]

visited = [False] * MAXV
calculated = [False] * MAXV
dp = [0] * MAXV
def dfs(v):
    if visited[v]: #すでに訪れたことがある時
        if not calculated[v]: #計算されたことがない時 = ループがある
            return -1
        return dp[v]
    visited[v] = True
    dp[v] = 1
    for u in to[v]:
        res = dfs(u)
        if res == -1:
            return -1
        dp[v] = max(dp[v], res + 1)
    calculated[v] = True
    return dp[v]

def main():
    N = int(input())
    a = [list(map(lambda x: int(x) - 1, input().split())) for _ in range(N)]

    V = 0 #頂点の数
    for i in range(N - 1):
        for j in range(i + 1, N):
            ID[i][j] = V
            V += 1
    
    for i in range(N):
        for j in range(N - 1):
            a[i][j] = toID(i, a[i][j]) #対戦相手で管理していたのを試合番号に変える
        for j in range(N - 2):
            to[a[i][j + 1]].append(a[i][j])
    
    # import numpy as np
    # print (np.array(to))
    # print (np.array(ID))

    ans = 0
    for i in range(V):
        res = dfs(i)
        if res == -1:
            print (-1)
            return 0
        ans = max(ans, res)
    print (ans)
    return 0

if __name__ == '__main__':
    main()

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

//--------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

//--------------------------------------------
const double EPS = 1e-14;
const double PI  = acos(-1.0);

//--------------------------------------------

int main(){
  int n;
  int a;

  scanf("%d",&n);

  int x = 0;
  int y = 0;
  REP (i, n) {
    scanf("%d",&a);
    if (a % 4 != 0 && a % 2 == 0) {
      x++;
    } else if (a % 4 == 0) {
      y++;
    }
  }

  if (2 * y + 1 >= n || n - x <= 2 * y) printf("Yes\n");
  else printf("No\n");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
double x1,x2,x3;
double pi=3.141592653589793;

int main(){
	cin>>x1>>x2>>x3;
	x3/=x1;
	double base=180.0/pi;
	if(x3>=x1*x2) {
		cout<<0<<endl;
		return 0;
	}
	if(x3>x1*x2/2) {
		x3-=2*x3-x1*x2;
		printf("%.10lf\n",atan(2*x3/(x1*x1))*base);
	}
	else {
		
		printf("%.10lf\n",atan(x2*x2/(2*x3))*base);
	}
	return 0;
}

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

int a[1000010];
int i=1;
int F(int n);
int main()
{
  int s;
  scanf("%d",&s);
  a[1]=s;
  printf("%d\n",F(a[1]));
  return 0;
}
int F(int n)
{
    if(n<=4 && n!=3){
        return i+3;
    }
    i++;
    if(n%2==0){
        a[i]=n/2;
    }else{
        a[i]=3*n+1;
    }
    return a[i+1]=F(a[i]);
}

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

using namespace std;

int main(void) {
    string S;

    cin >> S;

    if (S.at(2) == S.at(3) && S.at(4) == S.at(5)) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <stdio.h>
#include <numeric>
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	//freopen("input.txt", "rt", stdin);
	//freopen("out.txt", "wt", stdout);
	int x, k;
	cin >> k >> x;
	for (int i = x - k + 1; i < x; ++i) {
		cout << i << " ";
	}
	cout << x;
	for (int i = x + 1; i < x + k; ++i) {
		cout <<" "<< i;
	}
	cout << endl;

	/*int n, m, k;
	cin >> n >> m >> k;
	vector <tuple<int, int, int>> edges(m);
	for (int i = 0; i < m; ++i) {
		int x, y, w;
		cin >> x >> y >> w;
		if (x > y) swap(x, y);
		edges[i] = make_tuple(w, x, y);
	}
	sort(edges.begin(), edges.end());
	vector <tuple<int, int, int>> paths;
	int curmin = get<0>(edges[0]);
	int ind = 0;
	int cnt = 0;
	while (get<0>(edges[ind]) == curmin && cnt < k) {
		paths.push_back(edges[ind]);
		++ind;
		++cnt;
	}
	while (cnt < k) {
		curmin = get<0>(edges[ind]);
		bool added = false;
		for (int i = 0; i < paths.size(); ++i)
			for (int j = i + 1; j < paths.size(); ++j) {
				int xi = get<1>(paths[i]);
			}

	}*/
	/*int n, m;
	cin >> n >> m;
	vector<vector<int>> graph(n);
	vector<int> powers(n);
	for (int i = 0; i < m; ++i) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		graph[a].push_back(b);
		graph[b].push_back(a);
		++powers[a];
		++powers[b];
	}
	vector<pair<int, int>> sorted(n);
	for (int i = 0; i < n; ++i) {
		sorted[i].first = powers[i];
		sorted[i].second = i;
	}
	sort(sorted.begin(), sorted.end());
	if (m % 2) {
		cout << -1 << endl;
		return 0;
	}*/
	//cout << get<0>(paths[k - 1]);
	return 0;
}


Measured memory_bytes: 256
def solve():
    k, a = read()
    result = think(k, a)
    write(result)


def read():
    n, k = read_int(2)
    return k, read_int(n)


def read_int(n):
    return list(map(lambda x: int(x), read_line().split(' ')))[:n]


def read_float(n):
    return list(map(lambda x: float(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(k, a):
    mode = 10 ** 9 + 7
    n = len(a)

    # dp[i][j], means ways to count, for from 0th to ith child, candies num is j
    # dp[i][j] = sum(dp[i - 1][j - k]), which k is 0 to a[i]
    dp = [[0 for x in range(k + 1)] for y in range(n)]
    dp[0][0] = 1

    accumulated_a = [0 for x in range(n)]
    accumulated_a[0] = a[0]
    for i in range(1, n):
        accumulated_a[i] = accumulated_a[i - 1] + a[i]

    if accumulated_a[n - 1] < k:
        return 0

    accumulated_dp = [0] * (k + 2)

    # accum[0] = 0
    # accum[1] = dp[i][0]
    # accum[2] = dp[i][0] + dp[i][1]
    # accum[k] = dp[i][0] + dp[i][1] + ... + dp[i][k - 1]
    # accum[k + 1] = dp[i][0] + dp[i][1] + ... + dp[i][k]

    for i in range(n):
        for j in range(min(accumulated_a[i] + 1, k + 1)):
            if i == 0 and j == 0:
                continue
            if i == 0:
                if j <= a[i]:
                    dp[i][j] = 1
            else:
                # add (dp[i - 1][j - a[i]] to dp[i - 1][a[i]])
                dp[i][j] += accumulated_dp[j + 1] - accumulated_dp[max(j - a[i], 0)]
                dp[i][j] %= mode

        for y in range(k + 1):
            accumulated_dp[y + 1] = accumulated_dp[y] + dp[i][y]

    return dp[n - 1][k]


def write(result):
    print(result)


if __name__ == '__main__':
    solve()

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

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

    stringstream ss;ss<<n;string s=ss.str();
    int sum=0;
    rep(i,s.size())sum+=s[i]-'0';
    if(n%sum==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}


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

using namespace std;

// 戻り値は交換回数
int selection_sort(vector<int> &arr, int num) {
    int exchange = 0;
    for (int i = 0; i < num; i++) {
        int min_j = i;
        for (int j = i; j < num; j++) {
            if (arr[j] < arr[min_j]) {
                min_j = j;
            }
        }
        if (min_j != i) {
            int v = arr[i];
            arr[i] = arr[min_j];
            arr[min_j] = v;
            exchange++;
        }
    }
    return exchange;
}

int main() {

    int num;
    cin >> num;

    vector<int> arr(num);
    for (int i = 0; i < num; i++) {
        cin >> arr[i];
    }

    int exchange = selection_sort(arr, num);

    for (int i = 0; i < num; i++) {
        cout << arr[i];
        if (i != num - 1) {
            cout << " ";
        } else {
            cout << endl;
        }
    }
    cout << exchange << endl;

    return 0;
}



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

bool check(string S){
  if(S[0]!='A') return false;
  int C=0;
  for (int i = 2 ; i < S.length()-1; i++) {
    if(S[i]=='C'){
      C++;
    }
  }
  if(C!=1) return false;
  int upper=0;
  for (int i = 0; i < S.length(); i++) {
    if(S[i]>='A'&&S[i]<='Z'){
      upper++;
    }
  }
  if(upper!=2) return false;
  return true;
}

int main(){
  string S;
  cin >> S;
  if(check(S)){
    cout << "AC" << endl;
  } else {
    cout << "WA" << endl;
  }
}

Measured memory_bytes: 256
/**
 *    Author: "Robin Singh" !!
 *    rob_in_1
**/

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

#define dbg( args...) { vector<string> _v = split( #args, ','); err( _v.begin(), args); cerr << '\n'; }
vector<string> split( const string& s, char c) { vector<string> v; stringstream ss( s); string x; 
while ( getline( ss, x, c)) v.emplace_back(x); return move(v); }
void err( vector<string>::iterator it) { } 
template<typename T, typename... Args>
void err( vector<string>::iterator it, T a, Args... args) {
cerr << it -> substr( ( *it)[0] == ' ', it -> length()) << " = " << a << '\t'; err( ++it, args...); }

#define int long long
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
#define ff first
#define ss second
#define MP make_pair
#define szz(v) ((int)(v).size())  
#define fr(i, j, k) for(int i = j; i < k; i++)     
#define bk(i, j, k) for(int i = j-1; i >= k; i--)
#define mem(ptr, val)  memset(ptr, val, sizeof ptr)
#define sbit(n)  __builtin_popcount(n)
#define nl "\n"

typedef long double ld;
typedef pair<int, int> pii;
typedef vector <int> vi;
typedef vector < pair<int,int> > vpii;
const long double eps = 1e-9;
const int mod = 1e9+7;

pii dir[8] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1}, {1, 1}, {-1, -1} , {-1, 1}, {1, -1} };

//*********************************!Template Ends Here!**********************************//

const int nn = 2e5+5;
int a[nn], dp[nn][10];

void robin(){
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i];

    // D   S  T   U    or   D  T   S   U  (editorial) 

    dp[0][0] = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 5; j++){

            if(j > 0) dp[i][j] = min(dp[i][j], dp[i][j-1]);
            int here = 0;
            if(j == 0 || j == 4) here = a[i+1];
            else if(j == 2){
                here = (a[i+1] % 2 ? 0 : 1);
            }
            else{
                here = (a[i+1] % 2);
                if(! a[i+1]) here = 2;                  // ---->       // as it lies in the even range, so we have to remove 2 that will be generated
                                                       //  <----
            }                                         // any distance(a[i]) can be traversed for an ear by running b/w two consecutive points i-1 to i

            dp[i+1][j] =  dp[i][j] + here;
        }
    }

    int ans = 1e18;
    for(int j = 0; j < 5; j++) ans = min(ans, dp[n][j]);
    cout << ans;
}

int32_t main(){
    // freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int T = 1;
    // cin >> T;
    for(int tc = 1; tc <= T; tc++){
        // cout << "Case #" << tc << ": ";
        robin();
    }
    return 0;
}

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

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

    string str = to_string(N);
    bool flag = false;

    for(int i=0; i<str.length(); i++){
        if(str[i] == '7') flag = true;
    }
    
    if(flag){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

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


int main(){
ios::sync_with_stdio(0);
cin.tie(0);
string s;
cin>>s;
int count=0;
for (size_t i = 0; i < 3; i++)
{
  if(s[i]=='R')
  count++;

}
if(count>=3)
cout<<count;
else if(count==2)
  {
    if(s[0]=='S' || s[2]=='S')
    {
      cout<<count;
    }
    else
    {
      cout<<1;
    }
    
  }
else 
{
  cout<<count;
}




return 0;
}

 


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

int main() {
  int A, B, C, X;
  int count =0;
  cin >> A >> B >> C >> X;
  
  for (int i=0; i<A+1; i++){
    for (int j=0; j<B+1; j++){
      for (int k=0; k<C+1; k++){
        if (500*i + 100*j + 50*k == X){
          count++;
        }
      }
    }
  }
    cout << count << endl;
        
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<ll> vel;
typedef vector<str> ves;
#define REP(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, b) REP(i, 0, b)

int main() {
    ll N, M;
    cin >> N >> M;
    vel A(M);
    rep(i, M) {
        cin >> A.at(i);
    }
    ll count = 0;
    rep(i, M) {
        count += A.at(i);
    }
    if(count > N) {
        cout << -1 << endl;
    }
    else {
        cout << N - count << endl;
    }
}

Measured memory_bytes: 3672
#include <stdio.h>

int main(void)
{
	int a,b,c,x;
	scanf("%d%d%d",&a,&b,&c);
	if(a>b){
	x=a;
	a=b;
	b=x;
	}
	if(b>c){
	x=b;
	b=c;
	c=x;
	}
	if(a>b){
	x=a;
	a=b;
	b=x;
	}
	printf("%d %d %d\n",a,b,c);
}


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

int asc(const void *a, const void *b) {
  return *(int *)a - *(int *)b;
}

int main() {
	string s, t;
	cin >> s >> t;
	sort(s.begin(), s.end());
	sort(t.begin(), t.end());
	reverse(t.begin(), t.end());
	if(s<t) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 768
def is_prime(x):
    if x == 2:
        return True
    if x < 2 or x % 2 == 0:
        return False
    for i in range(3, int(x ** .5) + 1, 2):
        if x % i == 0:
            return False
    return True
n = int(input())
print(sum(is_prime(int(input())) for _ in range(n)))


Measured memory_bytes: 5688
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <utility>
using namespace std;
using ll = long long;

ll gcd(ll a, ll b){
  if(a < b) return gcd(b, a);

  if(b == 0) return a;
  else return gcd(b, a % b);
}

bool solve(ll a, ll b, ll c, ll d){
  if(a < b) return false;
  if(b > d) return false;
  if(c >= b) return true;

  ll g = gcd(b, d);
  ll tm = b - g + (a % g);

  return tm <= c;
}

int main(){
  int t; cin >> t;
  for(int i=0; i<t; i++){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    if(solve(a, b, c, d)){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 256
import sys

def solve():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    maxGCD = 1
    for gcd in range(1, M):
        if gcd * gcd > M: break
        else:
            if M % gcd == 0:
                other = M // gcd
                if gcd >= N: maxGCD = max(other, maxGCD)
                if other >= N: maxGCD = max(gcd, maxGCD)
    print(maxGCD)

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define int long long
typedef long long ll;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

signed main() {
  string S;
  cin >> S;
  set<char> s;

  for (auto c : S)
    s.insert(c);

  if (len(s) == 2)
    cout << "Yes\n";

  else
    cout << "No\n";
}

Measured memory_bytes: 256
from heapq import *

R = lambda: map(int, input().split())
n, m = R()
c = [[] for _ in range(m)]
for _ in range(n):
    a, b = R()
    if a <= m:
        heappush(c[m - a], -b)
r=0
for i in range(m - 1, -1, -1):
    if c[i]:
        r -= heappop(c[i])
        if i:
            f = len(c[i]) > len(c[i - 1])
            h, g = (c[i], c[i - 1]) if f else (c[i - 1], c[i])
            for x in g:
                heappush(h, x)
            if f:
                c[i - 1] = c[i]       
print(r)


Measured memory_bytes: 17604
// ALDS1_6_A
#include <iostream>
#include <vector>
using namespace std;

void CountingSort(vector<int> &A, vector<int> &B, int k){
	vector<int> C;
	for(int i=0;i<=k;i++)
		C.push_back(0);

	for(int j=1;j<A.size();j++)
		C[A[j]]++;

	for(int i=1;i<=k;i++)
		C[i] += C[i-1];

	for(int j=A.size()-1;j>0;j--){
		B[C[A[j]]] = A[j];
		C[A[j]]--;
	}
}

int main(){
	int n, num, max = 0;
	vector<int> A, B;

	cin>>n;
	A.resize(n+1);
	B.resize(n+1);

	for(int i=1;i<=n;i++){
		cin>>num;
		A[i] = num;

		if(num > max)
			max = num;
	}
	
	CountingSort(A, B, max);
	for(int i=1;i<=n;i++){
		if(i != 1)
			cout<<" ";

		cout<<B[i];
	}
	cout<<endl;

	return 0;
}

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

typedef long long ll;

const int MAXN = 1e2 + 5;

int N;
vector <int> E[MAXN];
int dist[MAXN];
int mx[MAXN];

void add(int a, int b) {
	E[a].push_back(b);
	E[b].push_back(a);
}

void remove(int a, int b) {
	vector <int> nxt;
	for (auto it : E[a])
		if (it != b)
			nxt.push_back(it);
	E[a] = nxt;
}

void load() {
	scanf("%d", &N);
	for (int i = 1; i < N; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		add(a, b);
	}
}

int dfs(int x, int p) {
	int res = 0;
	for (auto it : E[x])
		if (it != p)
			res = max(res, dfs(it, x) + 1);
	return res;
}

void go(int x, int p, int d) {
	int ch = 0;
	for (auto it : E[x])
		if (it != p) {
			go(it, x, d + 1);
			ch++;
		}
	mx[d] = max(mx[d], ch);
}

ll calc(int root) {
	memset(mx, 0, sizeof mx);
	go(root, 0, 0);
	ll res = 1;
	for (int i = 0; i < MAXN; i++)
		if (mx[i])
			res *= mx[i];
	return res;
}

ll add_root(int a, int b) {
	remove(a, b);
	remove(b, a);
	add(N + 1, a);
	add(N + 1, b);
	ll res = calc(N + 1);
	remove(N + 1, a);
	remove(N + 1, b);
	remove(a, N + 1);
	remove(b, N + 1);
	add(a, b);
	return res;
}

void solve() {
	for (int i = 1; i <= N; i++)
		dist[i] = dfs(i, 0);
	
	int mn = *min_element(dist + 1, dist + N + 1);
	vector <int> centre;
	for (int i = 1; i <= N; i++)
		if (dist[i] == mn)
			centre.push_back(i);
	
	assert(centre.size() <= 2);
	
	ll sol = LLONG_MAX;
	if (centre.size() == 1) {
		sol = min(sol, calc(centre[0]));
		vector <int> adj = E[centre[0]];
		for (auto it : adj)
			sol = min(sol, add_root(centre[0], it));
	}
	else
		sol = min(sol, add_root(centre[0], centre[1]));
	
	printf("%d %lld\n", mn + (centre.size() == 1), sol);
}

int main() {
	load();
	solve();
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
const int MAX_NUM = 1001;
int main(){
	int n;
	cin >> n;
	vector<int> div(MAX_NUM,0);
	REP(i,n){
		int a;
		cin >> a;
		int def_a = a;
		vector<int> tmp(a+1,0);
		for(int j = 2;j*j<=def_a;j++){
			while(!(a%j)){
				a /= j;
				tmp[j]++;
				if(tmp[j] > div[j])div[j] = tmp[j];
			}
		}
		if(a!=1){
			tmp[a]++;
			if(tmp[a]>div[a])div[a] = tmp[a];
		}
	}
	int ans = 1;
	REP(i,MAX_NUM){
		while(div[i]){
			ans *= i;
			div[i]--;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3112
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include<climits>
using namespace std;

#define ll long long
#define tc                int T;cin>>T;while(T--)
int main()
{
	int n, c, b, k ; cin >> n >> k;
  vector<int> a(n);
	for (int& e : a)cin >> e;
	vector<int> dp(n, INT_MAX);
	dp[0] = 0;
	for (int i = 0; i < n; ++i) {
		for (int e = i + 1; e <= i + k; ++e) {
			if (e < n)
				if ((dp[i] + abs(a[e] - a[i])) < dp[e])
					dp[e] = dp[i] + abs(a[e] - a[i]);
		}
	}
	cout << dp[n - 1] << '\n';
	return 0;
}


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

bool isLeap(int y){
  if(y%400==0)return true;
  if(y%100==0)return false;
  if(y%4==0)return true;
  return false;
}

int main(){
  int a,b;
  bool line=false;
  while(cin >> a >> b, a||b){
    if(line)cout << endl;
    line = true;

    bool f=false;
    for(int i=a;i<=b;i++)
      if(isLeap(i)){
	cout << i << endl;
	f=true;
      }
    if(!f)cout << "NA\n";
  }
}

Measured memory_bytes: 1160
#include <boost/algorithm/string/join.hpp>
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;
using namespace boost;

typedef int64_t INT;

void NearPoint(const vector<INT>&vec, INT n, INT res[2])
{
    res[0]=-1;
    res[1]=-1;

    auto it = lower_bound(vec.begin(), vec.end(), n);
    if(it!=vec.end())
    {
        res[0] = *it;
    }
    if(it!=vec.begin())
    {
        res[1] = *(it-1);
    }
}
struct S
{
    int type;
    INT pos;
};
void Resolve(istream &is, ostream &os) {
    INT A, B, Q;
    is >> A >> B >> Q;
    vector<INT> As;
    vector<INT> Bs;
    As.resize(A);
    Bs.resize(B);
    for(INT i = 0;i < A;i++)
    {
        INT n;
        is >> n;
        As[i] = n;
    }
    for(INT i = 0;i < B;i++)
    {
        INT n;
        is >> n;
        Bs[i] = n;
    }

    for(INT i = 0;i < Q;i++)
    {
        INT n;
        is >> n;

        INT res[2];
        vector<S> nears;
        vector<S> Anears;
        vector<S> Bnears;
        NearPoint(As, n, res);
        if(res[0]!=-1){
            nears.push_back(S{1, res[0]});
            Anears.push_back(S{1, res[0]});
        }
        if(res[1]!=-1){
             nears.push_back(S{1, res[1]});
            Anears.push_back(S{1, res[1]});
        }

        NearPoint(Bs, n, res);
        if(res[0]!=-1){
             nears.push_back(S{2, res[0]});
            Bnears.push_back(S{2, res[0]});
        }
        if(res[1]!=-1) {
            nears.push_back(S{2, res[1]});
            Bnears.push_back(S{2, res[1]});
        }
        nears.push_back(S{0, n});
        sort(nears.begin(), nears.end(), [](auto a, auto b){return a.pos<b.pos;});
        auto it = lower_bound(nears.begin(), nears.end(), S{0, n}, [](auto a, auto b){return a.pos<b.pos;});

        vector<S> ns;
        if(it != nears.begin())
        {
            ns.push_back(*(it-1));
        }
        if(it+1 != nears.end())
        {
            ns.push_back(*(it+1));
        }

        INT dis = INT64_MAX;
        for(auto nn: ns)
        {
            if(nn.type==1)
            {
                for(auto b: Bnears)
                {
                    dis = min(abs(nn.pos - n) + abs(nn.pos - b.pos), dis);
                }
            }else{
                for(auto a: Anears)
                {
                    dis = min(abs(nn.pos - n) + abs(nn.pos - a.pos), dis);
                }
            }
        }
        os << dis << '\n';
    }
}

#if !TEST
int main() { cin.tie(0); ios::sync_with_stdio(false); Resolve(cin, cout); cout.flush(); return 0;}
#endif


Measured memory_bytes: 2944
#include<iostream>
using namespace std;
bool num[1000001];
int main(){
  for(int i=2; i<=1000; i++)
    if(!num[i])
      for(int j=i*i; j<1000001; j+=i)
	num[j] = true;
  int n;
  while(cin >>n){
    int ans = 0;
    for(int i=2; i<=n; i++)
      if(!num[i]) ans++;
    cout <<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 2132
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  string S;
  cin>>S;
  if(S.at(0)==S.at(1)&&S.at(1)==S.at(2)){
    cout<<"No"<<endl;
  }
  else{
    cout<<"Yes"<<endl;
  }
 
}

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

using namespace std;

int main()
{
  int i,j,k;
  int H,W,K;
  int ans;
  int black;
  scanf("%d %d %d",&H,&W,&K);
  char S[H+1][W+1];
  for(i=0;i<H;i++){
    scanf("%s",S[i]);
  }
  
  ans = 0;
  black = 0;
  for(int temp=0;temp<(1<<H);temp++){
    for(int temp2=0;temp2<(1<<W);temp2++){
      for(i=0;i<H;i++){
        for(j=0;j<W;j++){
          if( !(temp2&(1<<j)) && !(temp&(1<<i)) && S[i][j]=='#' ){
            black += 1;
          }
        }
      }
        if( black == K ){
          ans++;
        }
        black = 0;      
    }
  }

  cout << ans << endl;
  return 0;
}


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

namespace ABC043A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int s = 0;

            for (int i = 1; i <= n; i++)
            {
                s += i;
            }
            Console.WriteLine(s);
            Console.ReadKey();
        }

    }
}


Measured memory_bytes: 13140
#include<iostream>
#include<cstdio>
#include<queue>
#include<map>
using namespace std;
queue<pair<string,int> > Q;
 
void Sw(string st,int x)
{
    int i;
    int pos,npos;
    int d[4]={-3,3,-1,1};
    string st1;
     
    for(i=0;i<=8;i++)
    {
        if(st[i]=='0')
        {
            pos=i;
            break;
        }
    }
    for(i=0;i<=3;i++)
    {
        st1=st;
        if(i==2 && pos%3==0) continue;
        if(i==3 && pos%3==2) continue;
        npos=pos+d[i];
        if(npos>=9 || npos<=-1) continue;
        swap(st1[pos],st1[npos]);
        Q.push(pair<string,int>(st1,x+1));
    }
}
 
int main()
{
    string puzzle="";
    string goal="123456780";
    map<string,bool> M;
    int i,x;
    string P;
     
    for(i=0;i<=8;i++)
    {
        cin >> x;
        puzzle+='0'+x;
    }
    Q.push(pair<string,int>(puzzle,0));
    while(1)
    {
        pair<string,int> p=Q.front();
        Q.pop();
        P=p.first;
        x=p.second;
        if(P==goal)
        {
            cout << x << endl;
            break;
        }
        if(M[P]) continue;
        else M[P]=1;
        Sw(P,x);
    }
    return 0;
}


Measured memory_bytes: 24492