akhauriyash/Code-Regression huggingface dataset:
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val pList = readLine()!!.split(" ").map(String::toInt)
    val sortedPList = pList.sorted()

    var count = 0
    for (i in 0 until n) {
        if (pList[i] != sortedPList[i]) count += 1
    }
    if (count == 2 || count == 0) {
        println("YES")
    } else {
        println("NO")
    }
}

Measured memory_bytes: 37916
#[macro_use]
mod input {

use std;
use std::io;

const SPLIT_DELIMITER: char = ' ';

#[macro_export]
#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
pub fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
pub fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}

#[allow(dead_code)]
pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
{
    let mut v: Vec<Vec<T>> = Vec::new();

    for _ in 0..line {
        let vec_line = input_vector();
        v.push(vec_line);
    }
    v
}

#[allow(dead_code)]
pub fn input_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
{
    let mut v: Vec<T> = Vec::new();

    let s = input_line_str();
    let split_result = s.split(SPLIT_DELIMITER);
    for z in split_result {
        let buf = match z.parse() {
            Ok(r) => r,
            Err(_) => panic!("Parse Error"),
        };
        v.push(buf);
    }
    v
}

#[allow(dead_code)]
pub fn str2vec(s: &str) -> Vec<char> {
    let mut v: Vec<char> = Vec::new();
    for c in s.chars() {
        v.push(c);
    }
    v
}
}

use input::*;

fn main() {
    let (n, k): (usize, usize);
    input!(n, k);

    let v = input_vector::<usize>();
    let mut ans = 0_usize;
    let mut ans_2 = 0_usize;
    for z in 0..n {
        for y in z + 1..n {
            if v[z] > v[y] {
                ans += 1;
                ans %= 1_000_000_007;
            }
        }
    }

    ans *= k;
    ans %= 1_000_000_007;

    for z in 0..n {
        for y in 0..n {
            if v[z] > v[y] {
                ans_2 += 1;
                ans_2 %= 1_000_000_007;
            }
        }
    }

    ans_2 = ((ans_2 * k) % 1_000_000_007 * (k - 1)) % 1_000_000_007 * 500000004;
    ans_2 %= 1_000_000_007;
    p((ans + ans_2) % 1_000_000_007);
}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;(i)--)
#define rrep1(i,n) for(int i=((int)(n));i>0;(i)--)
#define sz(c) ((int)(c).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> P;
typedef pair<int, pair<int, int> > PP;
const int MAX=2e5+10;


int N,Q;
vi G[MAX];
int ct[MAX];
void input(){
	cin>>N>>Q;
	rep(_,N-1){
		int a, b;
		cin>>a>>b;
		a--;b--;
		G[a].pb(b);
		G[b].pb(a);
	}
	rep(_,Q){
		int p, x;
		cin>>p>>x;
		p--;
		ct[p]+=x;
	}
}

void dfs(int v, int r){
	rep(i,sz(G[v]))if(G[v][i]!=r){
      	int u=G[v][i];
		ct[u]+=ct[v];
		dfs(u,v);
	}
}

void solve(){
	dfs(0,-1);
	rep(i,N)cout<<ct[i]<<" ";
}

void output(){
  
}

int main(){
  input();
  solve();
  output();
}

Measured memory_bytes: 29696
#include <bits/stdc++.h> 
using namespace std;
long long solution(int pos, string s, string cad)
{
	if(pos==cad.size()-1)
	{
		s += cad[pos];
		long long suma=0;
		char array[s.size()];
		strcpy(array,s.c_str());
		char *ella=strtok(array,"+");
		while(ella)
		{
			string cambio(ella);
			long long n=atoll(cambio.c_str());
			suma+=n;
			ella=strtok(NULL,"+");
		}
		return suma;

	} else {
		return solution(pos+1,s+cad[pos]+'+',cad)+
		solution(pos+1,s+cad[pos],cad);
	}
}
main()
{
	string cad;
	cin>>cad;
	string s="";
	long long a=solution(0,s,cad);
	cout<<a<<endl;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;
int h[100010],dp[100010];
int main(){
	int i,n,ans = 0;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> h[i];
	}
	dp[n - 1] = 0;
	for(i=n - 2;i>=0;i--){
		if(h[i]>=h[i + 1]){
			dp[i] = dp[i + 1] + 1;
		}else{
			dp[i] = 0;
		}
		ans = max(ans,dp[i]);
	}
	cout << ans << endl;
}

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

bool p[1010000];

void prime() {
  fill(p, p+1010000, true);
  p[0] = false;
  p[1] = false;
  for(int i = 2; i < 1010000; i++) {
    if(p[i]) {
      for(int j = 2; i*j < 1010000; j++) {
	p[i*j] = false;
      }
    }
  }
}

int search(int n, int m) {
  vector<int> a;
  int cnt = 0;
  for(int i = n+1; ; i++) {
    if(p[i]) {
      a.push_back(i+i);
      cnt++;
      if(cnt == m+10000) {
	sort(a.begin(), a.end());
	return a[m-1];
      }
      if(p[i]) {
	for(int j = n+1; j < i; j++) {
	  if(p[j]) {
	    a.push_back(i+j);
	    cnt++;
	    if(cnt == m+10000) {
	      sort(a.begin(), a.end());
	      return a[m-1];
	    }
	  }
	}
      }
    }
  }
}

int main() {
  int n, m;
  prime();

  while(cin >> n >> m, n+m != -2) {
    int ans = search(n, m);
    cout << ans << endl;
  }
}

Measured memory_bytes: 2308
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 7;
int a[maxn];
int main(){
    int n;
    scanf("%d",&n);
    for(int i = 1;i <= n;i++)
    	scanf("%d",&a[i]);
    int cnt = 1;
    int mi = a[1];
    for(int i = 2;i <= n;i++){
    	if(a[i] < mi){
    		cnt++;
    		mi = a[i];
		}
	}
	printf("%d\n",cnt);
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

typedef struct _syain {
	int id;
	long long int uriage;
}syain;

int main(void) {
	int i,n,size;
	int id;
	int j,isfound;
	long long int tanka, suuryou;
	syain S[4000+1];
	
	while(scanf("%d\n", &n) == 1) {
		if(n==0) break;
		size = 0;
		for(i=0;i<n;i++) {
			scanf("%d %lld %lld\n", &id, &tanka, &suuryou);
			
			for(j=0,isfound=0;j<size;j++) { 
				if(S[j].id == id) {
					S[j].uriage+=(tanka*suuryou);
					isfound = 1;
				}
			}
			if(isfound == 0) {
				S[size].id = id;
				S[size].uriage = tanka*suuryou;
				size++;
			}
		}
		
		for(i=0,isfound=0;i<size;i++) {
			if(S[i].uriage >= 1000000) {
				printf("%d\n", S[i].id);
				isfound = 1;
			}
		}
		
		if(isfound == 0) {
			printf("NA\n");
		}
	}
	
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int>A(N);
  for(int i=0; i<N; i++)cin >> A.at(i);
  
  int64_t ans =0;
  for(int i=0; i<N-1; i++){
    if(A.at(i)>A.at(i+1)){
      ans += A.at(i)-A.at(i+1);
      A.at(i+1)=A.at(i);
    }
  }
  
  cout << ans << endl;
}

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

int kakuketanowa(int n){
    int sum=0;
    while(n>0){
        sum += n%10;
        n=n/10;
    }
    return sum;
}

int main(){
    int n,a,b,c,sum=0;
    cin >> n >> a >> b;
    for(int i=1;i<=n;i++){
        c=kakuketanowa(i);
        if((a<=c)&&(c<=b)) sum +=i;
    }

    cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int N;
    cin >> N;
    if((N/10)%111==0 || (N%1000)%111==0) cout << "Yes" << endl;
    else cout << "No" <<endl;



}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int house[4][3][10];
    int i, j, k;
    int b, f, r, v;
    int n;
    for(i = 0; i < 4; i++) {
        for(j = 0; j < 3; j++) {
            for(k = 0; k < 10; k++) {
                house[i][j][k] = 0;
            }
        }
    }
    scanf("%d", &n);
    for(i = 0; i < n; i++) {
        scanf("%d %d %d %d", &b, &f, &r, &v);
        house[b-1][f-1][r-1] += v;
    }
    for(i = 0; i < 4; i++) {
        for(j = 0; j < 3; j++) {
            for(k = 0; k < 10; k++) {
                printf(" %d", house[i][j][k]);
            }
            printf("\n");
        }
        if(i != 3) {
            printf("####################\n");
        }
    }

    return 0;
}


Measured memory_bytes: 2100
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma warning(disable:4996)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <list>
#include <set>
#include <ctime>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

const int INF = 100000000;
const int MAX_M = 100000;



int main(int argc, char *args[]) {
	string s;
	cin >> s;
	if (s == "Sunny") {
		cout << "Cloudy" << endl;
	}
	else if (s == "Cloudy") {
		cout << "Rainy" << endl;
	}
	else {
		cout << "Sunny" << endl;
	}
}

Measured memory_bytes: 256
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#if defined(DAIJOBU)
#include "/home/ichigo/includes.hpp"
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#include <bits/stdc++.h>
#define deb(x...)
#endif
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

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

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long lint;
typedef vector<lint> vlint;
typedef vector<vlint> vvlint;
typedef pair<lint, lint> plint;
typedef double ld;

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



int main() {
    ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n, k;
	cin >> n >> k;
	cout << n - k + 1 << '\n';
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>

using namespace std;

int N, K, tmp = 0;
string S;
double ans = 0;

int main() {
	cin >> N >> K;
	if (N >= K) {
		tmp += N - K + 1;
		ans += (double)tmp;
	}
	for (int i = 1; i <= N-tmp; i++) {
		int x = i, cnt = 0;
		while (x < K) {
			x = (x << 1); cnt++;
		}
		ans += ((double)1.0) / ((double)(1 << cnt));
	}
	ans /= ((double)N);
	cout << setprecision(18) << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<set>
#include<map>
#include<time.h>
#include<cstring>
#include<iomanip>
#include<numeric>
#include<list>
#define lli long long int
#define h 10000
#define pf push_front
#define pb push_back
#define ub upper_bound
#define lb lower_bound
using namespace std;
int main() 
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL) ;
  lli a, b, c, d, x;
  cin>>a>>b>>c>>d;
  if(b<=0 && d<=0)cout<<a*c<<endl;
  else if(b<=0)
  {
  	if(c<0)cout<<c*a<<endl;
  	else if(c==0) cout<<0<<endl;
  	else cout<<b*c<<endl;
 } 
  else if(d<=0)
  {
  	if(a<0)cout<<a*c<<endl;
  	else if(a==0)cout<<0<<endl;
  	else cout<<d*a<<endl;
 } 
  else 
  {
  	x=0;
  	if(a<0 && c<0) x=a*c;
  	cout<<max((b*d),x)<<endl;
  } 
  return 0;
} 


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define F(i,a,b) for(int i=a;i<=b;i++);
#define MOD 220000000
#define N 100005

using namespace std;

struct Segtree{
	int l;
	int r;
	int size;
	int val;
	int lazytag;
}segtree[N*4+1];
int num[N];
int n,m;

inline void Build (int root,int start,int end){
	segtree[root].l=start;
	segtree[root].r=end;
	segtree[root].size=end-start+1;
	if (start==end){
		segtree[root].val=num[start];
		return;
	}
	int mid=((start+end)>>1);
	Build (root*2,start,mid);
	Build (root*2+1,mid+1,end);
	segtree[root].val=(segtree[root*2].val+segtree[root*2+1].val+MOD)%MOD;
	return;
} 

int main(){
	cin>>n;
	for (int i=1;i<=n;i++)
	 scanf ("%d",&num[i]);
	Build(1,1,n); 
	if (segtree[1].val%2==0) puts("YES");
	else puts("NO");
	return 0;
}

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

struct Card{ char suit, value; };

void bubble(struct Card A[], int N) {
  for(int i=0; i<N; i++) {
    for(int j=N-1; j>=i; j--) {
      if(A[j].value < A[j-1].value) {
        Card t = A[j]; A[j] = A[j-1]; A[j-1] = t;
      }
    }
  }
}

void selection(struct Card A[], int N) {
  for(int i=0;i<N;i++) {
    int minj = i;
    for(int j=i; j<N; j++) {
      if(A[j].value < A[minj].value) minj = j;
    }
    Card t = A[i]; A[i] = A[minj]; A[minj] = t;
  }
}

void print(struct Card A[], int N) {
  for(int i=0; i<N; i++) {
    if(i>0) cout << " ";
      cout << A[i].suit << A[i].value;
  }
  cout << endl;
}

bool isStable(struct Card C1[], struct Card C2[], int N) {
  for(int i=0; i<N; i++) {
    if(C1[i].suit != C2[i].suit) return false;
  }
  return true;
}

int main(void) {
  Card C1[100], C2[100];
  int N;

  cin >> N;
  for(int i=0;i<N; i++) {
    cin >> C1[i].suit >> C1[i].value;
  }

  for(int i=0; i<N; i++) C2[i] = C1[i];

  bubble(C1,N);
  selection(C2,N);

  print(C1,N);
  cout << "Stable" << endl;
  print(C2,N);
  if(isStable(C1,C2,N)) {
    cout << "Stable" << endl;
  } else {
    cout << "Not stable" << endl;
  }

  return 0;
}



Measured memory_bytes: 3120
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
typedef long long ll;
using namespace std;
const int inf=1e+9+7;
int main(void){
    int n,m;cin>>n>>m;
    vector<int> a(m),b(m);
    vector<vector<int>> c(m);
    rep(i,m){
        cin>>a[i]>>b[i];
        rep(j,b[i]){
            int x;cin>>x;
            c[i].push_back(x);
        }
    }
    vector<int> dp(5000,inf);
    dp[0]=0;
    rep(i,m){
        int now=0;
        rep(j,b[i]){
            now |= (1<<(c[i][j]-1));
        }
        
        rep(j,(1<<n)){
            if(dp[j|now]>dp[j]+a[i]){
                dp[j|now]=dp[j]+a[i];
            }
        }
    }
    if(dp[(1<<n)-1]==inf) dp[(1<<n)-1]=-1;
    cout<<dp[(1<<n)-1]<<endl;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long k = sc.nextLong();
		int[] a = new int[n];
		long[] b = new long[n];
		for(int i = 0 ; i < n ; i++) {
			a[i] = sc.nextInt();
		}
      int i = 1;
      int t = 1;
      
		for(; k >= 0 ; --k , ++t ,i = a[i - 1]) {
          if(b[i - 1] > 0)
				k %= (t - b[i - 1]);
          else
				b[i - 1] = t;
          if(k==0L){
				System.out.println(i);
				return;
			}
        }


	}


}



Measured memory_bytes: 61840
#include <stdio.h>


int main(){
    int A, B, ans = 0;
    scanf("%d %d", &A, &B);

    for (int i=0; i<2; i++){
    if (A > B){
        ans += A;
        A--;
    }else{
        ans += B;
        B--;  
    }
    }

    printf("%d", ans);

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	int h1, m1, h2, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;

	int t1 = 60 * h1 + m1;
	int t2 = 60 * h2 + m2;
	int ans = t2 - t1 - k;
	cout << ans << endl;

	return 0;
}


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

int main() {
  int N, P; cin >> N >> P;
  vector<int> odd, even;
  for (int i = 0; i < N; i++) {
    int A; cin >> A;
    if (A % 2 == 1) odd.push_back(A);
    else even.push_back(A);
  }
  int m = odd.size();
  int n = even.size();
  int MAX_C = 55;
  vector<vector<long long>> Com(MAX_C, vector<long long>(MAX_C));
  Com.at(0).at(0) = 1;
  for (int i = 1; i < MAX_C; i++) {
    Com.at(i).at(0) = 1;
    for (int j = 1; j <= i; j++) {
      Com.at(i).at(j) = (Com.at(i-1).at(j-1) + Com.at(i-1).at(j));
    }
  }
  long long a = 0;
  for (int i = 0; i <= n; i++) a += Com.at(n).at(i);
  long long b = 0;
  if (P == 0) {
    for (int i = 0; i <= m/2; i++) b += Com.at(m).at(2*i);
  }
  else {
    for (int i = 1; i <= (m+1)/2; i++) b += Com.at(m).at(2*i-1);
  }
  cout << a * b << endl;
}


Measured memory_bytes: 256
n,m=map(int, input().split())
h = list(map(int, input().split()))
ab = [list(map(int, input().split())) for i in range(m)]

top = [1]*n
for i in range(m):
    if h[ab[i][0]-1] < h[ab[i][1]-1]:
        top[ab[i][0]-1] = 0
    elif h[ab[i][0]-1] > h[ab[i][1]-1]:
        top[ab[i][1]-1] = 0
    else:
        top[ab[i][0]-1] = 0
        top[ab[i][1]-1] = 0

print(sum(top))


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

int main() {
  ll k, q;
  cin >> k >> q;

  vector<ll> d(k);
  for (ll i = 0; i < k; i++) {
    cin >> d[i];
  }

  for (ll i = 0; i < q; i++) {
    ll n, x, m;
    cin >> n >> x >> m;

    ll zeros = 0;
    vector<ll> dmod(k);
    for (ll j = 0; j < k; j++) {
      dmod[j] = d[j] % m;
      if (dmod[j] == 0) {
        if (j < (n - 1) % k) {
          zeros += (n - 1) / k + 1;
        } else {
          zeros += (n - 1) / k;
        }
      }
    }

    ll last = x;
    for (ll j = 0; j < k; j++) {
      if (j < (n - 1) % k) {
        last += dmod[j] * ((n - 1) / k + 1);
      } else {
        last += dmod[j] * ((n - 1) / k);
      }
    }

    ll ans = n - 1 - (last / m - x / m + zeros);
    cout << ans << endl;
  }
}

Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<algorithm>
#define LL long long
#define maxn 100005
#define INF (LL)1e16
using namespace std;
int n,m,t,x[maxn];
LL dp[maxn];
int main()
{
	scanf("%d%d%d",&n,&m,&t);
	for(int i=1;i<=n;i++) scanf("%d",&x[i]);
	sort(x+1,x+n+1);
	memset(dp,0x3f,sizeof(dp));
	dp[0]=0;
	LL mn=INF; int now=0;
	for(int i=1;i<=n;i++)
	{
		dp[i]=dp[i-1]+t+x[i]-x[i-1];
		while(2*(x[i]-x[now+1])>=t)
		{
			mn=min(mn,dp[now]-2ll*x[now+1]);
			now++;
		}
		dp[i]=min(2*x[i]+mn,dp[now]+t);
	}
	printf("%lld\n",dp[n]+m);
}


Measured memory_bytes: 1280
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), a[] = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = sc.nextInt();
		Arrays.sort(a);
		int m = a[n - 1];
		boolean sieve[] = new boolean[m + 1], taken[] = new boolean[m + 1];
		for (int i = 0; i < m + 1; i++)
			sieve[i] = true;
		for (int i = 0; i < n; i++)
			if (sieve[a[i]] && !taken[a[i]]) {
				taken[a[i]] = true;
				for (int j = a[i] * 2; j < m + 1; j = j + a[i])
					sieve[j] = false;
			}
		int ans = 0;
		for (int i = 0; i < n; i++) {
			if (i > 0 && a[i] == a[i - 1])
				continue;
			if (i < n - 1 && a[i] == a[i + 1])
				continue;
			if (sieve[a[i]])
				++ans;
		}
		System.out.println(ans);
	}
}


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

int main() {
	int n, m;
	cin >> n >> m;
	string a[n], b[m];
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < m; i++)
		cin >> b[i];
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++) {
			bool f = true;
			for (int k = 0; k < m; k++)
				for (int l = 0; l < m; l++) 
					f &= i + k < n && j + l < n && a[i + k][j + l] == b[k][l];
		if (f) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}


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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define In(vec) rep(i, n) cin>>vec[i];
#define ANS(s) cout << s << endl
#define inc(a, b) cin >> a >> b;

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vii;

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; }

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
int round_int(int a, int b) { return (a + (b - 1)) / b; }


// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

constexpr auto MAX = 100010;

// ────────────────────────────────────────────────────

int main()
{
	int n, k;
	cin >> n >> k;
	vi a(n);
	In(a);

	map<int, int> ma;
	set<int> st;

	rep(i, n)
	{
		ma[a[i]]++;
		st.insert(a[i]);
	}

	vii pairs(st.size());

	int i = 0;

	for (auto itr = st.begin(); itr != st.end(); itr++)
	{
		int tmp = *itr;
		pairs[i].first = ma[tmp];
		pairs[i].second = *itr;
		i++;
		//cout << pairs[i].first << " : " << pairs[i].second << endl;
	}

	sort(ASC(pairs));

	int cnt = 0;

	if (k >= st.size())
	{
		ANS(cnt);
	}
	else
	{
		for (int i = 0; i < (st.size() - k); i++)
		{
			//cout << pairs[i].first << " : " << pairs[i].second << endl;
			cnt += pairs[i].first;
		}
		ANS(cnt);
	}
}

Measured memory_bytes: 21376
import sys
sys.setrecursionlimit(1000000)
from functools import lru_cache

MOD = 10**9 + 7

@lru_cache(maxsize=None)
def f(n):
  if n <= 2:
    return 0
  elif n <= 5:
    return 1
  elif n <= 8:
    return n - 4
  else:
    t = 4
    for i in range(6, n-2):
      t += f(i)
    t %= MOD
    return t

S = int(input())
print(f(S))

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

#include <math.h>
#include <stdlib.h>


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

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; }

//INT_MAX	2,147,483,647 = 2*1.0e9

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

    bool ans = true;

    if(S[0] != 'A') ans = false;

    int cnt = 0;
    for(int i = 2; i <= S.length()-2; i++){
        if(S[i] == 'C') cnt++;
        else if (int(S[i]-'a') > 25 || int(S[i]-'a') < 0){
            ans = false;
        }
    }


    if(cnt != 1) ans = false;

    if(int(S[1]-'a') > 25 || int(S[1]-'a') < 0) ans = false;
    if(int(S[S.length()-1]-'a') > 25 || int(S[S.length()-1]-'a') < 0) ans = false;
    

    if(ans) cout << "AC" << endl;
    else cout << "WA" << endl;

    return 0;
}


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

using namespace std;

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

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

#define loop1(i,n) for(int i=1; i<=n; i++)

#define ll long long

#define ld long double

#define pii pair<int,int>

#define pll pair<ll,ll>

#define pld pair<ld,ld>

#define pb push_back
const int MAXN = 1e5+7;
ll r[MAXN], g[MAXN],o[MAXN];
int x,y,a,b,c;
int main(){
	fastio;
	cin>>x>>y>>a>>b>>c;
	
	loop0(i,a)cin>>r[i];
	sort(r, r+a);
	
	loop0(i,b)cin>>g[i];
	sort(g, g+b);
	
	int pr = a-x;
	ll sr=0;
	for(int i=pr; i<a; i++)sr+=r[i];
	
	int pg = b-y;
	ll sg = 0;
	for(int i=pg; i<b; i++)sg+=g[i];
	
	loop0(i,c)cin>>o[i];
	sort(o, o+c);
	
	for(int i=c-1; i>=0; i--){
		if(pr==a && pg==b)break;
		
		if(pr == a){
			if(o[i] > g[pg]){sg+=o[i]-g[pg]; pg++;}
		}else if(pg == b){
			if(o[i] > r[pr]){sr+=o[i]-r[pr]; pr++;}
		}else{
			if(g[pg] < r[pr]){
				if(o[i] > g[pg]){sg+=o[i]-g[pg]; pg++;}
			}else{
				if(o[i] > r[pr]){sr+=o[i]-r[pr]; pr++;}
			}
		}
	}
	cout<<sr+sg<<endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define int long long

using namespace std;

signed main() {
  int n;
  cin>>n;
  int a[n+1], nums[n+1];
  memset(a, 0, sizeof(a));
  for(int i=1, temp; i<=n; i++){
    cin>>temp;
    nums[i]=temp;
    a[temp]++;
  }
  int ans=0;
  for(int j=1; j<=n; j++){
      ans+=(a[j]*(a[j]-1))/2;
  }
  for(int i=1; i<=n; i++){
    cout<<ans-a[nums[i]]+1<<endl;
  }
}

Measured memory_bytes: 5760
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <map>
#include<unordered_map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include<bitset>
#include<deque>
#include<string>
#include<list>
#include<iterator>
#include<sstream>
#include <algorithm>
#include <numeric>
#include <math.h>

#define user spaesk
#define pi acos(-1)
#define lli long long int
#define ld long double
#define ff first
#define ss second
#define lower(a) transform(a.begin(),a.end(),a.begin(),::tolower);

using namespace std;

typedef vector<vector<lli> > matrix ;

const int N = 3e5 + 500;
const long long mod = 1e9 + 7;
const long long cmod = 998244353 ;
const long long inf = 1LL << 61;
const int M = 1e6 + 500;
const lli ths = 1LL << 40;
const int NN = 5e3 + 6;

void solve()
{

    cout<<fixed<<setprecision(10);
    lli a, b, h, m;
    cin>>a>>b>>h>>m;
    ld a1 = 360 / 12 * h;
    a1 += ((ld)30 / 60) * m;
    ld a2 = 360 / 60 * m;
    ld ang = abs(a1 - a2);
    if(ang > 180)
        ang = 360 - ang;
    ang = pi * ang;
    ang /= 180;
    ld c = (a * a + b * b - (2 * a * b * (cos(ang))) );
    c = sqrt(c);
    cout<<c;
    cout<<"\n";
    return ;
}

/*
*/

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

    int t = 1;
//    cin>>t;
    while(t --)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 4180
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy


def main():
    n = int(input())
    alist = list(map(int, input().split()))
    if n < 3:
        print(0)
        sys.exit()

    s = list(combinations(alist, 3))
    count = 0

    for i in s:
        if not(has_duplicates(i)):
            if i[0]+i[1]>i[2] and i[1]+i[2]>i[0] and i[2]+i[0]>i[1]:
                count += 1

    print(count)

def has_duplicates(seq):
    return len(seq) != len(set(seq))


if __name__ == '__main__':
	main()


Measured memory_bytes: 21076
def d(a,b);(a[0]-b[0]).abs+(a[1]-b[1]).abs;end
n,m=gets.split.map(&:to_i)
S=n.times.map{gets.split.map(&:to_i)}
M=m.times.map{gets.split.map(&:to_i)}
puts S.map{|s|(1..m).min_by{|i|d(M[i-1],s)}}

Measured memory_bytes: 1788
import itertools
n,m,x=map(int,input().split())
C=[]
for i in range(n):
    a=list(map(int,input().split()))
    C.append(a)
pattern=[]
#toBuy=[]
for i in range(n+1):
    toBuyc=list(itertools.combinations(C,i))
    for j in range(len(toBuyc)):
    #    print(toBuyc[j])
        pattern.append(toBuyc[j])
   # print(pattern)
"""for i in range(2**n):
    toBuy=[]
    for j in range(n):
        if ((i>>j)&1):
            toBuy.append(C[j])"""
   # print(toBuy)
    #pattern.append(toBuy)
#print(pattern)
X=[0]*m #mつのアルゴリズムそれぞれの経験値
xsum=0#とりあえずはじくためのやつ
sum=0#値段
min=12000000 
check=0
for tb in pattern:#toBuyについて
    sum=0
    xsum=0
    X=[0]*m
    for c in tb:
        for j in range(len(c)):
            if j==0:
                sum+=c[j]#price
            else:
                xsum+=c[j]#経験値そうごう
                X[j-1]+=c[j]#経験値各自
    if xsum<x*m:
        continue
    else:
        for eX in X:
            if eX<x:
                check=1
        if check==1:
            check=0
            continue
        if sum<min:
            min=sum
if min==12000000:
    print(-1)
else:
    print(min)  

Measured memory_bytes: 9396
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {

	public static final int BIG_NUM = 2000000000;
	public static final int MOD = 1000000007;
	public static final long HUGE_NUM = 99999999999999999L;
	public static final double EPS = 0.000000001;

	public static final int SIZE = 1005;
	public static long dp[][];

	@SuppressWarnings("unchecked")
	public static void main(String[] args) {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Scanner scanner = new Scanner(System.in);

		char from[] = "Hoshino".toCharArray();
		char to[] = "Hoshina".toCharArray();

		int P_length = 7;
		int T_length = 0;

		try {

			int num_case = Integer.parseInt(br.readLine());

			for(int loop = 0; loop < num_case; loop++){

					String input_str = br.readLine();
					T_length = input_str.length();

					char T[] = input_str.toCharArray();

					boolean FLG = true;

					for(int i = 0; i < T_length; i++){

						if(i+P_length > T_length)break;

						FLG = true;
						for(int k = 0; k < P_length; k++){

							if(from[k] != T[i+k]){

								FLG = false;
								break;
							}
						}
						if(FLG){
							for(int k = 0; k < P_length; k++){

								T[i+k] = to[k];
							}
						}
					}

					System.out.println(T);
			}

		} catch (IOException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		}

    }
}

class UTIL{

	//最大公約数
	public static long gcd(long x,long y){

		x = Math.abs(x);
		y = Math.abs(y);

		if(x < y){

			long tmp = y;
			y = x;
			x = tmp;
		}

		if(y == 0){

			return x;
		}else{

			return gcd(y,x%y);
		}
	}

	//最小公倍数
	public static long lcm(long x,long y){

		return (x*y)/gcd(x,y);
	}

	//String→intへ変換
    public static int getNUM(String tmp_str){

        return Integer.parseInt(tmp_str);
    }

    //文字が半角数字か判定する関数
    public static boolean isNumber(String tmp_str){

        if(tmp_str == null || tmp_str.length() == 0){

            return false;
        }

        Pattern pattern = Pattern.compile("\\A[0-9]+\\z");
        Matcher matcher = pattern.matcher(tmp_str);
        return matcher.matches();
    }
}


Measured memory_bytes: 25856
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

const int32_t M = 1000000007;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, a, n) for (int i = a; i < (n); i++)
#define all(in) in.begin(), in.end()

template <class T>
string sprint_arr(const vector<T> &arr) {
  stringstream ss;
  for (auto t : arr) {
    ss << t << " ";
  }
  return ss.str();
}

typedef long double LD;
typedef long long LL;
typedef pair<LL, LL> pll;
typedef pair<int32_t, int32_t> pii;
typedef vector<int32_t> vi;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.precision(10);
  cout << fixed;
  cerr << setw(3);

  int32_t n, k;
  cin >> n >> k;

  vector<vector<int32_t>> dp(2, vector<int32_t>(k + 2, 0));
  // vector<vector<int32_t>> f(2, vector<int32_t>(k + 1, 0));

  rep(i, n) {
    int32_t a;
    cin >> a;
    if (i == 0) {
      rep(j, k + 1) {
        dp[0][j + 1] = j <= a ? j + 1 : dp[0][j];
        // f[0][j] = j <= a ? 1 : 0;
      }
    } else {
      dp[i % 2][1] = 1;
      // f[i % 2][0] = 1;
      loop(j, 1, k + 1) {
        dp[i % 2][j + 1] = (((dp[(i + 1) % 2][j + 1] +
                           (M - dp[(i + 1) % 2][j - min(a, j)])) % M + dp[i % 2][j])) % M;
        // f[i % 2][j] = 0;
        // loop(l, max(0, j - a), j + 1) { f[i % 2][j] += f[(i + 1) % 2][l]; }
      }
    }
    // cerr << "f :   " << sprint_arr(f[i % 2]) << endl;
    // cerr << "dp: " << sprint_arr(dp[i % 2]) << endl;
  }
  cout << (dp[(n + 1) % 2][k + 1]  + (M - dp[(n + 1) % 2][k])) % M;
}

Measured memory_bytes: 1408
#include <stdio.h>

int main(){
	int w,h;
	
	while(1){
		scanf("%d", &h);
		scanf("%d", &w);
		
		if(w == 0 && h == 0)
			return 0;
		
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++)
				printf("#");
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 1000
// Problem : A - Takahashikun, The Strider
// Contest : AtCoder - AtCoder Grand Contest 046
// URL : https://atcoder.jp/contests/agc046/tasks/agc046_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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


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

    long x;
    cin >> x;
    long y = 0;
    y += x;
    long count = 1;
    while (y != 0) {
        y = (y + x) % 360;
        count++;
    }
    cout << count << "\n";
    
    return 0;
}


Measured memory_bytes: 3644
MOD = 998244353
MAX = 510000
fac = [1,1] # factorial
finv = [1,1] # inverse of factorial
inv = [None, 1] # inverse

def comb_init():
	for i in range(2, MAX):
		fac.append(fac[i-1] * i % MOD)
		inv.append(MOD - inv[MOD % i] * (MOD//i) % MOD)
		finv.append(finv[i-1] * inv[i] % MOD)

def inverse_mod(a):
	""" Calculate inverse of the integer in a modulo MOD """
	return pow(a, MOD-2, MOD)

def comb_mod(n, r):
	""" Calculate nCr modulo MOD. """
	if n < r: return 0
	if n < 0 or r < 0: return 0
	return fac[n]* (finv[r]*finv[n-r] % MOD) % MOD

def solve(n, m, k):
	ans = 0
	for k in range(K+1):
		ans = (ans + m*(comb_mod(n-1,k)*pow(m-1, n-k-1, MOD) % MOD) % MOD) % MOD
	return ans

comb_init()
N, M, K = map(int, input().split())
print(solve(N, M, K))


Measured memory_bytes: 69576
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define en "\n"
#define pair <int, int> pii
#define all(x) x.begin(),x.end()
#define loop(i,q,n) for(int i=q;i<n;i++)
#define dloop(i,a,b) for(int i=a;i>=b;i--)
#define speed ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL)
const ld PI = 3.14159265358979323;
const ll mod = 1e9+7;
const int N=1000001;
//******************************************************************************             
int gcd(int a,int b)
{
	if(b==0)return a;
	else return gcd(b,a%b);
}
int main()
{
	speed;
	int n;
	cin>>n;
    int abc[n][3];
	loop(i,0,n)loop(j,0,3)cin>>abc[i][j];
	int dp[n][3];
	loop(i,0,3)dp[0][i]=abc[0][i];
	loop(i,1,n)loop(j,0,3)
	{
	    int &ans=dp[i][j];
	    ans=0;
	    ans=abc[i][j]+max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3]);
	}
	cout<<*max_element(dp[n-1],dp[n-1]+3);
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    int x;
    cin >> x;
    x++;
    while(--x){
        for(int i=2; i*i<=x; i++){
            int a=x;
            while(a%i==0){
                a/=i;
            }
            if(a==1){
                print(x);
                return;
            }
        }
    }
    print(1);
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

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


int main()
{
  int a,b,x,y;
  cin>>a>>b>>x>>y;
  cout << fixed << setprecision(6) << double(a)*double(b)/2 << " " << (x+x==a && y+y==b) <<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#define rep(i, n) for(int i=0; i<n; i++)
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
    int x; cin >> x;
    if(x) cout << 0 << endl;
    else cout << 1 << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,j,n) for(int i=(j);i<(n);i++)
const int INF = 1e9 + 3;
using namespace std;
 
int dp[102][1<<15];
int w[1<<15];
 
int main(){
  int n,m;
  while(cin>>n>>m,n){
    vector<int> s(n),d(m);
    REP(i,n)cin>>s[i];
    REP(i,m)cin>>d[i];
    sort(s.begin(),s.end());
    sort(d.begin(),d.end());
		fill(w,w+(1<<n),0);
    REP(bit,1<<n){
      REP(j,n){
        if(bit&(1<<j)){
          w[bit]+=s[j];
        }
      }
    }
		fill(dp[1],dp[102],INF);
    FOR(i,1,m+1){//position at demand
      REP(bit,1<<n){
        dp[i][bit] = min(dp[i][bit],dp[i-1][bit] + abs(w[bit]-d[i-1]));
        REP(k,n){
          if(bit&(1<<k)){
            dp[i][bit] = min(dp[i][bit],dp[i][bit^(1<<k)]);
          }
        }
      }
    }
    int ans = INF;
    REP(i,1<<n){
      ans = min(ans,dp[m][i]);
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 16144
#include <cstdio>
using namespace std;
char s[100005];
int main(){
	int i;
	unsigned long long x, y;
	
	scanf("%Ilu %llu", &x, &y);
	i=0;
	while(x<=y and x<(x<<1)){
		x<<=1;
		i++;
	}
	printf("%d", i);
	return 0;
}

Measured memory_bytes: 128
a, b, c = map(int, input().split())
s = [a, b, c]
s.sort()
if (s[2] * 2 - s[0] - s[1]) % 2 == 0:
    print((3 * s[2] - sum(s)) // 2)
else:
    print((3 * s[2] + 3 - sum(s)) // 2)



Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

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

    int n;
    cin >> n;

    vs32 p(n + 1);
    rep (i, n)
    {
        cin >> p[i] >> p[i + 1];
    }

    vector< vs32 > dp(n + 1, vs32(n + 1, 0));
    for (int l = 2; l <= n; ++l)
    {
        for (int i = 1; i <= n  - l + 1; ++i)
        {
            dp[i][i] = 0;
            int j = i + l - 1;
            dp[i][j] = 1e9;
            for (int k = i; k < j; ++k)
            {
                dp[i][j] = MIN(dp[i][j], dp[i][k] + dp[k + 1][j] + p[i - 1] * p[k] * p[j]);
            }
        }
    }

    cout << dp[1][n] << "\n";
    return 0;
}



Measured memory_bytes: 3188
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  std::string s; std::cin >> s;
  int da[4], db[4];
  da[1] = db[0] = da[3] = db[3] = -1;
  da[0] = db[1] = 1;
  int ma = 0, mb = 0;
  int a[2] = {-1, 0}, b[2] = {-1, 0};
  for(int i = 0; i < s.size(); ++i) {
    char c = s[i];
    ma += da[c&3]; if(ma < 0) ma = 0;
    mb += db[c&3]; if(mb < 0) mb = 0;
    a[i&1] = std::max(a[i&1], ma);
    b[i&1] = std::max(b[i&1], mb);
  }
  ma = std::max(a[0], a[1]); if(a[0] == a[1]) ++ma;
  mb = std::max(b[0], b[1]); if(b[0] == b[1]) ++mb;
  fin(std::max(ma, mb));
  return 0;
}


Measured memory_bytes: 4772
#include <iostream>
using namespace std;
int main(void){
    // Here your code !
    int x,y;
    while(true){
        cin >> x >> y;
        if(x==0 && y==0)return 0;
        
        if(x<y){
            cout << x << " " << y << endl;
        }else{
            cout << y << " " << x << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int main ()
{
    int a,x[5],i,b;
    memset(x,0,sizeof(x));
    cin>>a>>b;
    x[a]=1;
    x[b]=1;
    for( i=1;i<=3;i++)
    {
        if(x[i]==0)
        {
            cout<<i<<endl;
        }
    }
    return 0;
}



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

typedef pair<int, int> P;


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

    rep(i, s.size()) {
        if(s[i] == t[i]) continue;
        else {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
using namespace std;

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main(){
  string s;
  cin >> s;
  if (s[5] == '0' && s[6] <= '4'){
    cout << "Heisei\n";
  }
  else{
    cout << "TBD\n";
  }
  return 0;
}

Measured memory_bytes: 256
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD;
	auto K = RD;
	long ans = 1;
	foreach (i; 0..N)
	{
		if (ans <= K)
			ans *= 2;
		else
			ans += K;
	}

	writeln(ans);
	stdout.flush();
	debug readln();
}

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

int mvx[] = {0, 1, 0, -1};
int mvy[] = {1, 0, -1, 0};
int INF = 1e9;

int main(){
  int h, w; cin >> h >> w;
  P c, d; cin >> c.first >> c.second >> d.first >> d.second;
  c.first--; c.second--; d.first--; d.second--;
  char s[h][w];
  rep(i, h) rep(j, w) cin >> s[i][j];

  int dist[h][w];
  rep(i, h) rep(j, w) dist[i][j] = INF;
  dist[c.first][c.second] = 0;

  deque<P> q;
  q.emplace_back(c.first, c.second);

  while(!q.empty()){
    P now = q.front(); q.pop_front();
    int dis = dist[now.first][now.second];
    rep(i, 4){
      int nx = now.first + mvx[i], ny = now.second + mvy[i];
      if(nx < 0 || nx >= h || ny < 0 || ny >= w || s[nx][ny] == '#' || dist[nx][ny] <= dis) continue;
      dist[nx][ny] = dis;
      q.emplace_front(nx, ny);
    }
    for(int i = -2; i <= 2; i++){
      for(int j = -2; j <= 2; j++){
        int nx = now.first + i, ny = now.second + j;
        if(nx < 0 || nx >= h || ny < 0 || ny >= w || s[nx][ny] == '#' || dist[nx][ny] <= dis + 1) continue;
        dist[nx][ny] = dis + 1;
        q.emplace_back(nx, ny);
      }
    }
  }

  cout << (dist[d.first][d.second] == INF ? -1 : dist[d.first][d.second]) << endl;

  return 0;
}


Measured memory_bytes: 8516
#include<iostream>
#include<string>
#include<vector>
typedef std::pair<char,char> p;

int main(){
	while(1){
		int n;
		std::cin>>n;
		if(n==0)break;
		std::vector<p> vec(n);
		for(int i=0;i<n;i++){
			std::cin>>vec[i].first>>vec[i].second;
		}
		std::string ans;
		int m;
		std::cin >> m;
		for(int i=0;i<m;i++){
			char c;
			std::cin>>c;
			bool f=true;
			for(int j=0;j<n;j++){
				if(vec[j].first == c){
					ans.push_back(vec[j].second);
					f=false;
				}
			}
			if(f)ans.push_back(c);
		}
		std::cout<<ans<<std::endl;
	}

	return 0;
}

Measured memory_bytes: 1332
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<utility>

#define lli long long
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define rep0(i,j) for(int i=0;i<j;i++)
#define rep1(i,j) for(int i=1;i<=j;i++)
#define rep0d(i,j) for(int i=j-1;i>=0;i--)
#define MAX 1000000007

using namespace std;


int main() {
	int n,a=0;
	cin>>n;
	vector<int> vec(n);
	rep0(i,n)cin >> vec[i];
	rep1(i,n-2)if(vec[i-1]<vec[i]&&vec[i]<vec[i+1]||vec[i-1]>vec[i]&&vec[i]>vec[i+1])a++;
		cout<< a;
	
}

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

class A {
	
	A() {
		Scanner cin = new Scanner(System.in);
		int A = cin.nextInt();
		int B = cin.nextInt();
		int C = cin.nextInt();
		int D = cin.nextInt();
		int value = Math.max(A*B, C*D);
		System.out.println(value);
	}
	
}


Measured memory_bytes: 9044
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(c,i) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	int w,h;
	cin>>w>>h;
	vi amida(w+1);
	rep(i,amida.size())
		amida[i]=i;
	rep(i,h){
		int a,b;
		scanf("%d,%d",&a,&b);
		swap(amida[a],amida[b]);
	}
	repi(i,1,amida.size())
		cout<<amida[i]<<endl;
	
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define repr(i,k,n) for(int i = (k); i < (n); i++)
#define rep(i,n) repr(i,0,n)
#define ALL(a) begin(a),end(a)
const int INF = 114514810;
const int MOD = 1000000007;
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N=0;
	string S;
	cin >> S;
	rep(i,4){
		if (S[i]=='+'){
			N++;
		}else{
			N--;
		}
	}
	cout << N << endl;
}

Measured memory_bytes: 256