akhauriyash/Code-Regression huggingface dataset:
#include <cmath>
#include <complex>
#include <vector>
#include <cfloat>
#include <algorithm>
#include <iostream>
using namespace std;


///////////////////////
//二次元幾何テンプレート
//点クラス point->x,y
//直線クラス line->s,v
//
class point;
class line;
point vec_add(point vec1,point vec2);//ベクトルの足し算
point vec_sub(point vec1,point vec2);//ベクトルの引き算
double inner_product(point a,point b);//内積
double outer_product(point a,point b);//外積
bool vec_parallel(point vec1,point vec2);//ベクトルの並行判定(交差判定falseとしても使える)
bool vec_angle_right(point vec1,point vec2);//ベクトルの直行判定
bool cross_line_segment(line a,point p1,point p2);//直線と線分の交差判定
//
class point{
public:
	double x,y;
	point(){
		x=0;
		y=0;
	}
	point(double a,double b){
		x=a;
		y=b;
	}
};

//直線クラス
class line{
public:
	point s,v;
public:
	line(point a,point b){
		s=a;
		v=vec_sub(a,b);
	}
};
///////////////////////


int main(){
	point a[4];
	while(cin>>a[0].x>>a[0].y){
		for(int i=1;i<4;i++){
			cin>>a[i].x>>a[i].y;
		}
		bool f=vec_angle_right(vec_sub(a[0],a[1]),vec_sub(a[2],a[3]));
		if(f){
			cout<<"YES"<<endl;
		}else{
			cout<<"NO"<<endl;
		}
	}
}
//


//多角形(頂点を保持する)
typedef vector<point> polygon;

//ベクトルの足し算
point vec_add(point vec1,point vec2){
	point res(vec1.x+vec2.x,vec1.y+vec2.y);
	return res;
}
//ベクトルの引き算
point vec_sub(point vec1,point vec2){
	point res(vec1.x-vec2.x,vec1.y-vec2.y);
	return res;
}
//内積
double inner_product(point a,point b){
	return a.x * b.x + a.y * b.y;
}
//外積
double outer_product(point a,point b){
	return a.x * b.y - a.y * b.x;
}


//ベクトルの並行判定
bool vec_parallel(point vec1,point vec2){
	if(outer_product(vec1,vec2)==0){
		return true;
	}else{
		return false;
	}
}
//ベクトルの直交判定
bool vec_angle_right(point vec1,point vec2){
	if(inner_product(vec1,vec2)==0){
		return true;
	}else{
		return false;
	}
}

bool cross_line_segment(line l,point p1,point p2){
	p1=vec_sub(p1,l.s);
	p2=vec_sub(p2,l.s);
	if(outer_product(p1,l.v)*outer_product(p2,l.v)<0){
		return true;
	}else{
		return false;
	}
}



//

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

// header area

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

    bool flag=false;
    string ans;
    while(1){
        if(N <= 26) flag = true;

        char moji;
        if(N%26 == 0) moji = 'z';
        else moji = N % 26 -1 + 'a';

        string moji_s{moji};
        ans = moji_s + ans;

        int tmp=0;
        if(N%26 == 0) tmp = 26;
        else tmp = N % 26; 
        N -= tmp;
        N /= 26;

        if(flag) break;
    }
    cout << ans << endl;

    return 0;
}

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

int main(){
    int a;
    cin >> a;
    string s;
    cin >> s;
    if(a >= 3200) cout << s << endl;
    else cout << "red" <<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <limits>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <unordered_map>
#include <random>
#include <cmath>
#include <complex>

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

const int INFL = (int)1e9;
const ll INFLL = (ll)1e18;
const double INFD = numeric_limits<double>::infinity();
const double PI = 3.14159265358979323846;
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loopll(i, n) for(ll i = 0; i < (ll)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopll1(i, n) for(ll i = 1; i <= (ll)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Looprll(i, n) for(ll i = (ll)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define Looprll1(i, n) for(ll i = (ll)n; i >= 1; i--)
#define Loopitr(itr, container) for(auto itr = container.begin(); itr != container.end(); itr++)
#define printv(vector) Loop(i, vector.size()) { cout << vector[i] << " "; } cout << endl;
#define rnd(d) (ll)((double)d + (d >= 0 ? 0.5 : -0.5))
#define floorsqrt(x) ((ll)sqrt((double)x) + ((ll)sqrt((double)x) * (ll)sqrt((double)x) <= (ll)x ? 0 : -1))
#define ceilsqrt(x) ((ll)sqrt((double)x) + ((ll)x <= (ll)sqrt((double)x) * (ll)sqrt((double)x) ? 0 : 1))
#define ceildiv(a, b) ((ll)a / (ll)b + ((ll)a % (ll)b == 0 ? 0 : 1))
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)

/*******************************************************/

int main() {
  int q; cin >> q;
  Loop(k, q) {
    ll a, b; cin >> a >> b;
    if (a > b) swap(a, b);
    ll ans = 0;
    if (a == b) {
      ans = (a - 1) * 2;
    }
    else {
      ll n = sqrt(a * b - 1);
      if ((n + 1) * (n + 1) < a * b) n++;
      else if (n * n >= a * b) n--;
      ll m = (a * b - 1) / n;
      if (n == m) {
        ans = 2 * (n - 1);
      }
      else {
        ans = 2 * n - 1;
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
n = int(input())
al = 'abcdefghijklmnopqrstuvwxyz'
n -= 1

a = n
cnt = 1
while a >= 26**cnt:
    a -= 26**cnt
    cnt += 1

ans = ''
for i in range(cnt):
    ans += al[n%26]
    n //= 26
    n -= 1
print(ans[::-1])

Measured memory_bytes: 9136
n=int(input())
h=list(map(int,input().split()))

dp=[int(10e8)]*n
dp[0]=0
dp[1]=abs(h[1]-h[0])
for i in range(2,n):
    dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[n-1])

Measured memory_bytes: 13980
use std::io::{self, BufRead};

fn main() {
    let stdin = io::stdin();
    let mut lines = stdin.lock().lines();
    let a = lines.next().unwrap().unwrap();
    let b = lines.next().unwrap().unwrap();

    let mut ans = "1";
    for &s in ["1", "2", "3"].iter() {
        if a != s && b != s {
            ans = s
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
fun main(args: Array<String>) {
    val x = readLine()!!.toInt()-1
    val a = IntArray(30) {0}
    for (i in a.indices) {
        a[i] = i % 7
    }
    println(when(a[x]) {
        0 -> "fri"
        1 -> "sat"
        2 -> "sun"
        3 -> "mon"
        4 -> "tue"
        5 -> "wed"
        6 -> "thu"
        else -> ""
    })
}


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

using namespace std;

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define PB push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second

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

const int MOD = 1e9+7;
const int MAX = 1e5+7;

int gcd(int a, int b){
	return (b ? gcd(b, a%b) : a);
}

int primes[1000005];

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

	int n; cin >> n;
	vi v(n); FOR(i, n) cin >> v[i];

	int g = v[0];
	FOR(i, n){
		int aux = v[i];
		for(int j = 2; j*j <= aux; j++){
			if(aux%j == 0){
				primes[j]++;
				while(aux%j == 0)
					aux/=j;
			}
		}
		if(aux > 1) primes[aux]++;
		g = gcd(g, v[i]);
	}

	bool pairwise = true;
	FOR(i, 1000005){
		if(primes[i] > 1) pairwise = false;
	}

	if(pairwise) cout << "pairwise coprime\n";
	else if(g == 1) cout << "setwise coprime\n";
	else cout << "not coprime\n";
	

	return 0;
}


Measured memory_bytes: 10944
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
const ll INF = 1LL << 58;
const ll MOD = 1000000007;
typedef vector<pii> vpii;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

signed main()
{
    //  以降 cin の入力元が 'input.txt' になる
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    int n, x;
    cin >> x >> n;
    vi A;
    int all = 0;
    A.resize(n);
    REP(i, n)
    {
        cin >> A[i];
        all += A[i];
    }
    if (all > x)
        cout << -1 << endl;
    else
        cout << x - all << endl;

    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=a;i<(b);i++)
using namespace std;
int N;

int main(){
  long long st, sa;
  cin >> N;
  REP(i,N){
    long long t, a;
    cin >> t >> a;
    if( i == 0 ){
      st = t;
      sa = a;
    }else{
      long long d = st / t;
      long long e = sa / a;
      d = max( d, e );
      FOR(k,-1,2){
	long long x = (d+k) * t;
	long long y = (d+k) * a;
	if( x >= st && y >= sa ){
	  st = x;
	  sa = y;
	  break;
	}
      }
    }
  }
  cout << st + sa << endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long[] a = new long[n+1];
    for(int i=1;i<=n;i++)a[i]=sc.nextLong();
    Arrays.sort(a);
    long sum1 = 0;
    long sum2 = 0;
    if(n%2==0){
      for(int i=n;i>=n/2+2;i--)sum1+=a[i]*2;
      sum1+=a[n/2+1];
      for(int i=1;i<=n/2-1;i++)sum1-=a[i]*2;
      sum1-=a[n/2];
    }else{
      for(int i=n;i>=n/2+3;i--)sum1+=a[i]*2;
      sum1+=a[n/2+2]+a[n/2+1];
      for(int i=n/2;i>=1;i--)sum1-=a[i]*2;
      for(int i=n;i>=n/2+2;i--)sum2+=a[i]*2;
      for(int i=1;i<=n/2-1;i++)sum2-=a[i]*2;
      sum2-=(a[n/2+1]+a[n/2]);
    }
    System.out.println(Math.max(sum1,sum2));
  }
}

Measured memory_bytes: 60100
import java.util.ArrayList;
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> list = new ArrayList<Integer>();
		
		int a,b,flag = 1;
		
		while(true){
			a = sc.nextInt();
			b = sc.nextInt();
			
			if(a == 0 && b == 0)break;
			if(flag == 0)
				System.out.println();
			flag = 0;
			
			for(int i = a; i <= b; i++){
				if(i % 400 == 0){
					list.add(i);
					continue;
				}
				else if(i % 100 == 0){
					continue;
				}
				else if(i % 4 == 0){
					list.add(i);
				}
			}
			if(list.size() == 0)
				System.out.println("NA");
			else
				for(int i = 0; i < list.size(); i++){
					System.out.println(list.get(i));
				}
			
			list.clear();
		}
		sc.close();
	}
}

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

#define pb push_back
#define rep(i, a, n) for(int (i)=a; (i)<(n); (i)++)
#define FOR(i, n) rep(i, 0, n)
#define F(n) FOR(i, n)
#define FF(n) FOR(j, n)
#define repi(i, a, n) for(int (i)=a; (i)<=(n); (i)++)
#define FORI(i, n) repi(i, 1, n)
#define FI(n) FORI(i, n)
#define FFI(n) FORI(j, n)
#define IN(x) int x; cin>>(x);
#define SIN(x) string x; cin>>x;
#define INN(x, y) int x, y; cin>>(x)>>(y);
#define INFO(a) cout<<"info "<<a<<endl
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int, int>
#define vpii vector<pair<int, int> >
#define sortv(x) sort((x).begin(), (x).end())
#define sortvd(x) sort((x).begin(), (x).end(), greater<int>())
#define lboundv(x,v) lower_bound((x).begin(),(x).end(),(v))-(x).begin();
#define uboundv(x,v) upper_bound((x).begin(),(x).end(),(v))-(x).begin();
#define ite iterator
#define fi first
#define se second
#define mems(a, v) memset((a), (v), sizeof((a)))
#define lmid(l, r) ((l)+(r)-1)/2
#define rmid(l, r) ((l)+(r))/2+1
#define mp make_pair

typedef long long ll;
typedef long double LD;

using namespace std;

int main() {
	ios::sync_with_stdio(0);
	string s[2];
	cin>>s[0]>>s[1];
	cout<<(s[0][1]==s[1][1] && s[0][0]==s[1][2] && s[0][2]==s[1][0] ? "YES":"NO")<<endl;
	return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <math.h>
#include <numeric>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<string> s;
  for(int i=0;i<n;i++){
    string tmp;
    cin >> tmp;
    s.push_back(tmp);
  }
  sort(s.begin(),s.end());
  s.erase(unique(s.begin(),s.end()),s.end());
  cout << s.size() << endl;
}

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

using namespace std;

#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define INF 1000000001
#define INFL (1LL << 60)
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>

int main() {
  int n;
  cin >> n;
  ll a[n];
  REP(i, n) cin >> a[i];
  ll b[n+1];
  b[0] = 0;
  REP(i, n) b[i+1] = b[i] + a[i];
  map<ll, ll> m;
  REP(i, n+1) m[b[i]]++;
  ll ans = 0;
  for(auto i = m.begin(); i != m.end(); ++i){
    ll x = i->second;
    ans += x*(x-1)/2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int prime(ll a){
  if(a==2){
    return 1;
  }else if(a%2==0 || a==1){
    return 0;
  }
  for(ll i=3;i*i<=a;i+=2){
    if(a%i==0)
      return 0;
  }
  return 1;
}
int main() {
  ll x;
  cin>>x;
  if(prime(x)==1){cout<<x<<endl;return 0;}
  if(x%2==0){
    ll i=0;
    while(true){
      if(prime(x+2*i+1)==1){cout<<x+2*i+1<<endl;return 0;}
      i++;
    }
  }
  else{
    ll i=0;
    while(true){
      if(prime(x+2*i)==1){cout<<x+2*i<<endl;return 0;}
      i++;
    }
  }
}

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

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

    std::vector<int> A(N);
    for (int i = 0; i < N; i ++) {
        std::cin >> A[i];
    }

    int n_swaps = 0;
    bool flag = true;
    while (flag) {
        flag = false;
        for (int j = N - 1; j >= 1; j --) {
            if (A[j] < A[j-1]) {
                std::swap(A[j], A[j-1]);
                flag = true;
                n_swaps += 1;
            }
        }
    }

    for (int i = 0; i < N; i ++) {
        if (i > 0) std::cout << " ";
        std::cout << A[i];
    }
    std::cout << std::endl;
    std::cout << n_swaps << std::endl;
}



Measured memory_bytes: 3088
#include<iostream>

using namespace std;

int main() {

	int a, b ;
	cin >> a >> b;

	if (a == b) {

		cout << "a == b" << endl;
		
	}else if (a < b) {

		cout << "a < b" <<endl;
		
	}else if (a > b){

		cout << "a > b" << endl;
		
	}

	return 0;
}


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

int dp[MAX][MAX], G[MAX][MAX]; // dp:動的計画法に使う2次元配列，G:入力に使う2次元配列

int getLargestSquare(int H, int W) {
    int maxWidth = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            dp[i][j] = (G[i][j] + 1) % 2; // dp[i][j]:G[i][j]が奇数なら0(=false)，偶数なら1(=true)
            maxWidth |= dp[i][j]; // maxWidth = maxWidth ∧ dp[i][j]
        }
    }

    for (int i = 1; i < H; i++) {
        for (int j = 1; j < W; j++) {
            if (G[i][j]) { // G[i][j]がfalse(=汚れている)とき
                dp[i][j] = 0; // dp[i][j]はfalse
            } else { // G[i][j]がtrue(=汚れていない)とき
                dp[i][j] = min(dp[i - 1][j - 1], min(dp[i - 1][j], dp[i][j - 1])) + 1; // 上，左，左上のタイルが作れる正方形より1だけ大きい正方形が作れる
                maxWidth = max(maxWidth, dp[i][j]);
            }
        }
    }

    return maxWidth * maxWidth;
}

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

    int H, W;
    scanf("%d %d", &H, &W);

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            scanf("%d", &G[i][j]);
        }
    }

    printf("%d\n", getLargestSquare(H, W));
    return 0;
}


Measured memory_bytes: 18484
from collections import defaultdict
n=int(input())
a_=list(map(int,input().split()))
a=[]
for i,ai in enumerate(a_):
      a.append([1+i,ai])
a.sort(key=lambda x:x[1],reverse=True)
dp=defaultdict(lambda:0)
dp[(0,1)]=max(a[0][1]*(n-a[0][0]),0)
dp[(1,0)]=max(a[0][1]*(a[0][0]-1),0)
for i in range(2,n+1):#i人目の幼児。a[i-1]
      for x in range(i+1):
            y=i-x
            if x==0:
                  dp[(x,y)]=dp[(x,y-1)]+a[i-1][1]*(n-a[i-1][0]-(y-1))
            elif y==0:
                  dp[(x,y)]=dp[(x-1,y)]+a[i-1][1]*(a[i-1][0]-1-(x-1))
            else:
                  dp[(x,y)]=max(dp[(x-1,y)]+a[i-1][1]*(a[i-1][0]-1-(x-1)),dp[(x,y-1)]+a[i-1][1]*(n-a[i-1][0]-(y-1)))
ans=0
for i in range(n+1):
      ans=max(ans,dp[(i,n-i)])
print(ans)


Measured memory_bytes: 315816
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2e6+3;
const int mod=998244353;
ll n,q,l,r,k;
ll num[N],all_1[N];
struct A
{
    ll l,r,num,lazy;
} a[N];
void f(int root,int k)
{
    a[root].lazy=k;
    a[root].num=(k*all_1[a[root].r-a[root].l+1])%mod;
}
void pushback(int root)
{
    int l=a[root].l;
    int r=a[root].r;
    ll mid=(l+r)>>1;
    if (a[root].lazy!=0)
    {
        f(root<<1,a[root].lazy);
        f(root<<1|1,a[root].lazy);
    }
    a[root].lazy=0;
}
void pushup(int root)
{
    a[root].num=(a[root<<1].num*num[a[root<<1|1].r-a[root<<1].r]+a[root<<1|1].num)%mod;
}
void buid(int l,int r,int root)
{
    a[root].l=l;
    a[root].r=r;
    if(l==r)
    {
        a[root].num=1;
        return ;
    }
    ll mid=(l+r)>>1;
    buid(l,mid,root<<1);
    buid(mid+1,r,root<<1|1);
    pushup(root);
}
void update(ll l,ll r,ll root,ll d)
{
    pushback(root);
    if(a[root].r<=r&&a[root].l>=l)
    {
        f(root,d);
        return ;
    }
    ll mid=(a[root].l+a[root].r)>>1;
    if(mid>=l)
    {
        update(l,r,root<<1,d);
    }
    if(mid<r)
    {
        update(l,r,root<<1|1,d);
    }
    pushup(root);
}
ll quary(ll l,ll r,ll root)
{
    pushback(root);
    if(a[root].l>=l&&a[root].r<=r)
    {
        return a[root].num;
    }
    int mid=(a[root].r+a[root].l)/2;
    ll lso=0,rso=0;
    if(mid>=l)
    {
        lso=quary(l,r,root<<1);
    }
    if(mid<r)
    {
        rso=quary(l,r,root<<1|1);
    }
    ll sum=(lso*(n-a[root<<1].r)+rso)%mod;
    return sum;
}
int main()
{
    cin>>n>>q;
    num[0]=1;
    for (int i=1; i<=n; i++)
        num[i]=(num[i-1]*10)%mod;
    all_1[1]=1;
    for (int i=2; i<=n; i++)
        all_1[i]=(all_1[i-1]*10+1)%mod;
    buid(1,n,1);
    while (q--)
    {
        cin>>l>>r>>k;
        update(l,r,1,k);
        cout<<quary(1,n,1)<<endl;
    }
    return 0;
}


Measured memory_bytes: 39496
#include <stdio.h>
int main(void){
    // Your code here!
    int a,b,c,d,n,count=0;
    
    while(scanf("%d",&n) != EOF){
        for(a=0;a<=9;a++){
            for(b=0;b<=9;b++){
                for(c=0;c<=9;c++){
                    for(d=0;d<=9;d++){
                        if(a+b+c+d==n)
                        count+=1;
                    }
                }
            }
        }
        printf("%d\n",count);
        count=0;
    }
    return 0;
}



Measured memory_bytes: 2040
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <map>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int N, A[1000][1000], ind[1000] = {};
    cin >> N;
    REP(i, N) REP(j, N - 1) {
        cin >> A[i][j];
        A[i][j]--;
    }

    int ans = 0;
    bool update, used[1000];
    while (true) {
        update = false;
        REP(i, N) used[i] = false;
        ans++;

        REP(i, N) {
            if (used[i] || ind[i] >= N - 1) continue;
            int to = A[i][ind[i]];
            if (used[to] || ind[to] >= N - 1) continue;

            if (A[to][ind[to]] == i) {
                update = true;
                ind[i]++;
                ind[to]++;
                used[i] = used[to] = true;
            }
        }
        if (!update) break;
    }
    REP(i, N) if (ind[i] < N - 1) {
        cout << -1 << endl;
        return 0;
    }
    cout << ans - 1 << endl;
    return 0;
}

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

int main(){
  vector<char> s(3);
  int count=0;
  for(int i=0;i<3;i++){
    cin >> s.at(i);
    if(s.at(i)=='1'){
      count++;
  }}
  cout << count << endl;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int p[n];
    int i;
    for(i=0;i<n;i++)cin >> p[i];
    int flag=0;
    for(i=1;i<n-1;i++)if((p[i]>p[i-1] && p[i+1]>p[i])||(p[i]>p[i+1] && p[i-1]>p[i]))flag++;
    cout << flag << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/algorithm_ext.hpp>
#include <boost/math/common_factor_rt.hpp>
using namespace std;
using namespace boost::range;
using boost::irange;
using boost::math::gcd;
using boost::math::lcm;

using ll = int64_t;
constexpr char LN = '\n';
template<class T> bool chmax(T& a, const T& b) {if(a<b){a=b;return true;}else{return false;}}
template<class T> bool chmin(T& a, const T& b) {if(b<a){a=b;return true;}else{return false;}}

#ifdef LOCAL
template<class H> void dump_(const char* s, H h) {cout<<s<<"="<<h<<LN; }
template<class H, class... T> void dump_(const char* s, H h, T... t) {for(;*s!=',';++s){cout<<*s;}cout<<"="<<h<<",";dump_(++s,t...);}
#define dump(...) dump_(#__VA_ARGS__, __VA_ARGS__)
#else
#define dump(...)
#endif

struct init_ {init_(){cin.tie(nullptr);ios::sync_with_stdio(false);}} init_;

template<class C> C scan(size_t n) {C c(n);for(auto& v:c){cin>>v;}return c;}
template<class C> C scan(size_t n, size_t m) {C vss(n);for(auto& vs:vss){vs.resize(m);for(auto& v:vs){cin>>v;}}return vss;}

template<class R> struct Joined { const R& r; const char* s; };
template<class R> Joined<R> joined(const R& r, const char* s = " ") {return{r,s};}
template<class R> ostream& operator<<(ostream& out, Joined<R> j) {bool f=true;for(const auto& v:j.r){if(f){f=false;}else{out<<j.s;}out<<v;}return out;}

template<class T> using matrix = vector<vector<T>>;
template<class T> matrix<T> make_matrix(size_t n, size_t m, const T& init = T()) {matrix<T> vss(n);for(auto& vs:vss){vs.resize(m,init);}return vss;}
template<class T> ostream& operator<<(ostream& out, Joined<matrix<T>> j) {bool a=true;for(const auto& vs:j.r){if(a){a=false;}else{out<<LN;}bool f=true;for(const auto& v:vs){if(f){f=false;}else{out<<j.s;}out << v;}}return out;}

template<class T> void show_(const T& t) {cout<<t;}
template<class T> void show_(const vector<T>& v) {cout<<joined(v);}
void show_(bool b) {cout<<(b?"Yes":"No");}
void show_(double d) {cout<<fixed<<setprecision(12)<<d;}
template<class T, class... TS> void show_(const T& t, TS... ts) {show_(t);cout<<' ';show_(ts...);}
template<class T> void show(const T& t) {show_(t);cout<<LN;}
template<class T, class... TS> void show(const T& t, TS... ts) {show_(t, ts...);cout<<LN;}

int main() {
    ll A, B;
    cin >> A >> B;
    show(lcm(A, B));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define vl vector<ll>
using namespace std;
typedef long long ll;
ll div_ceil(ll a,ll b)
{
	if(a>=0)
		return (a+b-1)/b;
	else
		return a/b;
}
ll div_floor(ll a,ll b)
{
	if(a<0)
		return (a-b+1)/b;
	else
		return a/b;
}
int main()
{
	ll n,k;
	cin>>n>>k;
	vl A(n);
	for(int i=0;i<n;i++)cin>>A[i];
	ll inf = 1e18;
	ll ri = inf,le = -inf-1;
	sort(A.begin(),A.end());
//	(le , ri]
	while(le+1<ri)
	{
		ll mid = (le+ri) >> 1;
		ll cnt = 0;
		for(int i=0;i<n;i++)
		{
			if(A[i]<0)
			{
				ll num = div_ceil(-mid,-A[i]);
				cnt+=A.begin()+i - lower_bound(A.begin(),A.begin()+i,num);
			}
			else if(A[i] == 0)
			{
				if(mid>=0)
					cnt+=i;
			}
			else
			{
				ll num = div_floor(mid,A[i]);
				cnt += upper_bound(A.begin(),A.begin()+i,num)-A.begin();
			}
		}
		if(cnt>=k)
			ri = mid;
		else
			le = mid;
	}
	cout<<ri<<endl;
    return 0;
} 

Measured memory_bytes: 1792
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int ans = 1;
		
		
		for(int i=2; i<=a; i++){
		    for(int j=2; (int)Math.pow(i, j)<=a; j++){
		        ans = Math.max((int)Math.pow(i,j),ans);
		    }
		}
		
		System.out.println(ans);
	}
}


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

const int64_t MOD = 998244353;
const int MAXS = 3010;
int64_t dp[MAXS];

int main() {
	int n, s;
	cin >> n >> s;
	dp[0] = 1;
	for (int i = 1; i <= s; ++i) {
		dp[i] = 0;
	}
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		for (int j = s; j >= 0; --j) {
			dp[j] = (2 * dp[j] + (j >= a ? dp[j - a] : 0)) % MOD;
		}
	}
	cout << dp[s] << endl;
	return 0;
}

Measured memory_bytes: 3184
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3e5+10;
const int mod = 1e9+7;
ll dp[N];
ll a[N];
int main() {
	int n;
	cin>>n;
	for(int i=1;i<=n;i++) {
		if(i==1||i==2) dp[i] = 0;
		else if(i==3) {
			dp[i] = 1;
		}
		else {
			dp[i] = (dp[i-3]+dp[i-1])%mod;
		}
	}
	cout<<dp[n]<<endl;
	
	return 0;
}

Measured memory_bytes: 3624
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)

	a := nextInt()
	b := nextInt()
	c := nextInt()
	d := nextInt()
	e := nextInt()

	if a == 0 {
		fmt.Println("1")
	}
	if b == 0 {
		fmt.Println("2")
	}
	if c == 0 {
		fmt.Println("3")
	}
	if d == 0 {
		fmt.Println("4")
	}
	if e == 0 {
		fmt.Println("5")
	}

}

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


Measured memory_bytes: 1756
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int n, d;
    cin >> n >> d;

    cout << ceil((double)n/(double)(d*2+1));
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int wmax = sc.nextInt();
        long[] w = new long[n];
        long[] v = new long[n];
        for (int i = 0; i < n; i++) {
            w[i] = sc.nextLong();
            v[i] = sc.nextLong();
        }

        long[][] dp = new long[n + 1][wmax + 1];
        for (int i = 1; i <= n; i++) {
            for (int wsum = 0; wsum <= wmax; wsum++) {
                if (wsum - w[i - 1] >= 0) {
                    dp[i][wsum] =
                        Math.max(dp[i][wsum], dp[i - 1][wsum - (int) w[i - 1]] + v[i - 1]);
                }
                dp[i][wsum] = Math.max(dp[i][wsum], dp[i - 1][wsum]);
            }
        }
        System.out.println(dp[n][wmax]);
    }
}


Measured memory_bytes: 125908
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


# rstrip().decode('utf-8')
# INF=float("inf")
# MOD=10**9+7
# sys.setrecursionlimit(2147483647)
# import math
#import numpy as np
# import operator
# import bisect
# from heapq import heapify,heappop,heappush
# from math import gcd
# from fractions import gcd
# from collections import deque
# from collections import defaultdict
# from collections import Counter
# from itertools import accumulate
# from itertools import groupby
# from itertools import permutations
# from itertools import combinations
# from scipy.sparse import csr_matrix
# from scipy.sparse.csgraph import floyd_warshall
# from scipy.sparse.csgraph import csgraph_from_dense
# from scipy.sparse.csgraph import dijkstra
# map(int,input().split())


def main():
	N, K = map(int, input().split())
	ans=0
	for i in range(1,N+1):
		a=0
		while i*(2**a)<K:
			a+=1
		ans+=(1/2**a)/N
	print(ans)
	
	
	
	
	
	
	
	
if __name__ == '__main__':
	main()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int n,q;
    cin>>n>>q;
    vector<pair<int,pair<int,int>>> v(2*n);
    for(int i=0;i<n;i++){
        int s,t,x;
        cin>>s>>t>>x;
        v[2*i]={s-x,{1,x}};
        v[2*i+1]={t-x,{-1,x}};
    }
    sort(v.begin(),v.end());
    int d[q];
    for(int i=0;i<q;i++){
        cin>>d[i];
    }
    int ans[q];
    memset(ans,-1,sizeof(ans));
    multiset<int> eve;
    int t=0;
    for(int i=0;i<q;i++){
        while(t<2*n&&v[t].first<=d[i]){
            if(v[t].second.first==1){
                eve.insert(v[t].second.second);
            }
            else{
                auto it=eve.lower_bound(v[t].second.second);
                eve.erase(it);
            }
            ++t;
        }
        if(eve.size()){
            ans[i]=*eve.begin();
        }
    }
    for(int i=0;i<q;i++){
        cout<<ans[i]<<endl;
    }
}


Measured memory_bytes: 16896
#include <bits/stdc++.h>
using namespace std;
int main () {
    int a;
    int b;
    cin >> a >> b;
    if (a == 1) a = 100;
    if (b == 1) b = 100;
    if (a == b) puts("Draw");
    else if (a > b) puts("Alice");
    else puts("Bob");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 3000005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	string s;
	cin>>s;
	if(s[s.length()-1]=='s'){
		s+='e';
		s+='s';
	}
	else{
		s+='s';
	}
	cout<<s;
	return 0;
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
int main() {
    string s;
    cin>>s;
    int sum=0;
    for(int i=0;i<s.size();i++) {
        sum+=s[i]-'0';
        if(sum%9==0) {
            sum=0;
        }
    }
    if(sum%9==0) {
        cout<<"Yes"<<endl;
    }
    else {
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3752
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <math.h> // sqrt
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <iomanip> // setprecision
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<long long>;
using pii = pair<int, int>;
using psi = pair<string, int>;

bool check(int sum) {
    int n = floor(sqrt(sum));
    if (n * n == sum) {
        return true;
    }
    else {
        return false;
    }
}

int main() {
    int N, D;
    cin >> N >> D;
    vector<vi> data(N, vi(D));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < D; j++) {
            cin >> data[i][j];
        }
    }
    int ans = 0;
    for (int i = 0; i < N - 1; i++) {
        for (int j = i + 1; j < N; j++) {
            int sum = 0;
            for (int k = 0; k < D; k++) {
                sum += (data[i][k] - data[j][k]) * (data[i][k] - data[j][k]);
            }
            if (check(sum)) {
                ans++;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3612
n, m = map(int, input().split())
cnt = {}
y_p = {}
ans = [1 for i in range(n)]
y_ = []

for i in range(m):
  p, y = map(int, input().split())
  y_.append(y)
  cnt[i] = [p, y]
  y_p[y] = p
y_.sort()

for i in y_:
  p = y_p[i]
  y_p[i] = ans[p-1]
  ans[p-1] += 1

for i in range(m):
  p = cnt[i][0]
  y = cnt[i][1]
  print(str(p*1000000 + y_p[y]).zfill(12))

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

int main()

{
    string s;
    cin >> s;
    int count = 0;
    if (s[0] != 'A')
    {
        cout << "WA";
        return 0;
    }
    else
    {
        for (int i = 1; i < s.size(); i++)
        {
            if (s[i] == 'C')
            {
                if (2 <= i && i <= s.size() - 2)
                {
                    count += 1;
                }
            }
            else
            {

                if (97 > int(s[i]) || int(s[i]) > 122)
                {
                    cout << "WA";
                    return 0;
                }
            }
        }
        if (count == 1)
        {
            cout << "AC";
        }
        else
        {
            cout << "WA";
        }
    }

    return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
 
#define INF 1000000007
#define LINF 1000000000000000007
 
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> P;


int a,b,c;

int main(){
	cin >> a >> b >>c;
	
	cout << (a+b < c ? "No" : "Yes") << endl;
	
	return 0;
}

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

#define PI 3.141592653589793238
#define INF 1050000000

using namespace std;



//cout << fixed << setprecision(15) << << endl;
//cout << << endl;

int main() {

	int n,m;

	cin >> n>>m;

	
	cout << (n-1)*(m-1) << endl;

	return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>

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


int main() {

	int N,M,X,Y;
	int x[123], y[123];

	scanf("%d%d%d%d", &N, &M, &X, &Y);

	rep(i, N) scanf("%d", &x[i]);
	rep(i, M) scanf("%d", &y[i]);

	bool nw = false;

	for (int Z = X + 1; Z <= Y; ++Z) {
		bool nwz = true;
		rep(i, N) if (x[i] >= Z) nwz = false;
		rep(i, M) if (y[i] < Z) nwz = false;
		nw |= nwz;
	}

	printf("%sWar\n", nw ? "No " : "");

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std; 
map< string,int >mp;
char temp1[12],a[200000][10];

int n,temp,flag=0,i,k=0,sum=0,j,max11[200000];


int main(){

	cin>>n;
	for(i=0;i<n;i++){
		cin>>a[i];
		mp[a[i]]++;
		if(mp[a[i]]>1){
			i--;
			n--;
		}
	    
	}
	int mx = 0;
	for(auto a : mp)
		mx = max(mx, a.second);
	for(auto a :mp){
		if(mx == a.second)
			cout << a.first << "\n";
	}
}

Measured memory_bytes: 27776
import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    #n,m,k=list(map(int, readline().strip().split()))
    #arr=list(map(int, readline().strip().split()))
    #n=int(readline().strip())
    s=input()
    print("vowel" if s in ["a","i","u","e","o"] else "consonant" )

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまでコピぺえ 
### ----------------

Measured memory_bytes: 5616
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long LL;
const int N=2e5;
int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
int head[N],nxt[N];
int st[N],f[N];
inline void dfs(int k) {
	int i,len=0;
	for (i=head[k];i;i=nxt[i])
		dfs(i);
	for (i=head[k];i;i=nxt[i]) st[++len]=f[i];
	sort(st+1,st+1+len);
	for (i=1;i<=len;i++)
		f[k]=max(f[k],st[i]+1+len-i);
}
int main()
{
	int n=gi(),i,k;
	for (i=2;i<=n;i++) nxt[i]=head[k=gi()],head[k]=i;
	dfs(1);
	cout<<f[1]<<endl;
	return 0;
}


Measured memory_bytes: 3200
#include<iostream>
#include<string>
#include<vector>
#include<algorithm> // sort

using namespace std;

void Main()
{
    int N;
    string S;
    cin >> N >> S;

    if (S.size() % 2) {
        cout << "No" << endl;
        return;
    }

    int mid = S.size() / 2;
    for (int i = 0; i < mid; i++) {
        if (S[i] != S[i + mid]) {
            cout << "No" << endl;
            return;
        }
    }

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

int main()
{
    Main();
    return 0;
}


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

int main(){
	int n;
	static bool c[1000000]={true};
	static int t[1000000];t[0] = 0;
	for(int i = 2;i < 1000000;i++){
		if(!c[i]){
		for(int j = 2;i*j < 1000000;j++){
			c[i*j] = true;
		}
		}
		t[i]=t[i-1]+!c[i];
	}
	for(int n;cin>>n;n++){
		cout << t[n] << endl;
	}
	return 0;
}

Measured memory_bytes: 7960
#include <stdio.h>
int main(void){
    int n;
    scanf("%d",&n);
    int a[n-1],ans[200000]={0};
    for(int i=0; i<n-1; i++){
        scanf("%d",&a[i]);
        ans[a[i]-1]++;
    }
    for(int i=0; i<n-1; i++){
        printf("%d\n",ans[i]);
    }
    printf("0");
}


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

int main() {
	string A;
	string B;
	cin >> A >> B;
	if (A.size() > B.size()) {
		cout << "GREATER" << endl;
	}
	else if (A.size() < B.size()) {
		cout << "LESS" << endl;
	}
	else if (A > B) {
		cout << "GREATER" << endl;
	}
	else if (A < B) {
		cout << "LESS" << endl;
	}
	else {
		cout << "EQUAL" << endl;
	}
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int a,b,W;
  scanf("%d %d %d",&W,&a,&b);
  if((a+W >= b && a+W <= b+W) || (a >= b && b+W >= a))
    printf("0\n");
  else
    printf("%d\n", b-a-W > a-b-W ? (a-b-W > 0 ? a-b-W : b-a-W) :(b-a-W>0 ? b-a-W : a-b-W));
  return 0;
}


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

int main(){
    ll H,W;
    cin >> H >> W;
    if(H == 1 || W == 1){
        cout << 1 << endl;
    }else if(H*W%2 == 0){
        cout << H*W/2 << endl;
    }else{
        cout << H*W/2+1 << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include<list>
#include<bitset>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<functional>
#include<string>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<utility>
#include<fstream>
#include<sstream>
#include<cmath>
#include<stack>
#include<assert.h>
using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define SZ(V) (int )V.size()
#define FORN(i, n) for(i = 0; i < n; i++)
#define FORAB(i, a, b) for(i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  ((B) <= (A) && (A) <= (C))

typedef pair<int,int> PII;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<PII > VP;

#define AIN(A, B, C) assert(IN(A, B, C))

//typedef int LL;
//typedef long long int LL;
//typedef __int64 LL;

int A[100005];
int B[100005];
set<int> S;

int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &A[i]);
		B[i] = A[i];
	}

	for (int i = 0; i < n; i += 2) S.insert(A[i]);
	sort(B, B + n);
	int ans = 0;
	for (int i = 0; i < n; i += 2) {
		int z = B[i];
		if (S.find(z) == S.end()) ans++;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
  int b[n];
  for(int i=0;i<n;i++)
    b[a[i]-1]=i+1;
  for(int i=0;i<n;i++)
    cout<<b[i]<<" ";
}

Measured memory_bytes: 1536
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define DEB 0

/*
real	0m2.093s  --> 
real	0m2.000s
*/
const int dx[] = {1,0,-1,0}; //r,d,l,u
const int dy[] = {0,1,0,-1};

int w,h,sx,sy,home,last;
int field[16][16];
int num[16][16];
int hS[25],hx[25],hy[25],edge[25][4][25]; //[src][dir][dest]
map<int,int> msi;

inline bool isnotgoal(int s){
  return (((last&s)) == last);
}
inline bool isnot(int s){
  rep(i,home)if( !(s&(1<<i)) ){
    if( (hS[i]&s)==hS[i] ) return true;
  }
  return false;
}
inline bool inside(int x, int y){
  return (x<0 || y<0 || x>=w || y>=h);
}

int dfs(int S){
  int src = S&((1<<5)-1);
  int x = hx[src];
  int y = hy[src];
  int s = S>>5;

  if( (1<<home)-1 == s ){ //âÎÉßêé
    return 1;
  }
  if( isnotgoal(s) ){ //³ïÉßé½ßÌÆðÁïµ½©Ç¤©
    return 0;
  }
  map<int,int>::iterator it = msi.lower_bound(S);
  if( it!=msi.end() && it->first == S ){ //ùÉÊÁ½óÔ
    return it->second;
  }

  // v[gªu¯È¢ÆÌL³
  if( s>0 && ((s&(s-1))!=0) && isnot(s&~(1<<src)) ){
    return 0;
  }
  
  int ret = 0;
  rep(k,4){
    for(int j=0; edge[src][k][j]!=-1; j++){
      int dest = edge[src][k][j];
      int nx = hx[dest];
      int ny = hy[dest];
      if( field[ny][nx]==1 ){
	field[ny][nx] = 0;
	ret += dfs(((s|(1<<dest))<<5)|dest);
	field[ny][nx] = 1;
	break;
      }
    }
  }
  //if( it!=msi.end() )--it;
  msi.insert(it, make_pair(S,ret));
  return ret;
}

int main(){

  while(scanf("%d%d",&w,&h),w|h){
    msi.clear();
    memset(num,-1,sizeof(num));
    memset(edge,-1,sizeof(edge));
    memset(hS,0,sizeof(hS));
    home = last = 0;
    rep(i,h){
      rep(j,w){
	scanf("%d",&field[i][j]);
	if( field[i][j]==2 ){
	  sx=j; sy=i;
	}
	if( field[i][j]==1 ){
	  hx[home]=j; hy[home]=i;
	  num[i][j] = home;
	  home++;
	}
      }
    }
    hx[home] = sx;
    hy[home] = sy;

    // other homes
    rep(i,home){
      rep(k,4){
	int sz = 0;
	for(int j=1; j<20; j++){
	  int tx = hx[i] + dx[k]*j;
	  int ty = hy[i] + dy[k]*j;
	  if( inside(tx,ty) ) break;
	  if( field[ty][tx]==1 ){
	    hS[i] |= (1<<num[ty][tx]);
	    edge[i][k][sz++] = num[ty][tx];
	  }
	}
      }
    }

    //last homes
    rep(k,4){
      int sz = 0;
      for(int i=1; i<20; i++){
	int tx = sx + dx[k]*i;
	int ty = sy + dy[k]*i;
	if( inside(tx,ty) )break;
	if( field[ty][tx]==1 ){
	  last |= (1<<num[ty][tx]);
	  edge[home][k][sz++] = num[ty][tx];
	}
      }
    }
    printf("%d\n",dfs(home));
  }
  

  return 0;
}

Measured memory_bytes: 27000
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
  double xa1,ya1,xa2,ya2,xb1,yb1,xb2,yb2;
  for(;cin>>xa1>>ya1>>xa2>>ya2>>xb1>>yb1>>xb2>>yb2;)
    if(min(xa2,xb2)<max(xa1,xb1)||
       min(ya2,yb2)<max(ya1,yb1)
       )
	cout<<"NO"<<endl;
      else
	cout<<"YES"<<endl;
  
}

Measured memory_bytes: 1216
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <set>
#include <iostream>
#include <map>
#include <functional>
#include <cstdlib>
#include <numeric>
#include <queue>
#include <complex>
#include <sstream>
#include <stack>

using namespace std;

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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef complex<double> Point;

int main()
{
	int answers[64];
	int dp[64][8][4][4];
	
	rep(i, 51){
		answers[i] = 1<<29;
		rep(j, 5) rep(k, 4) rep(l, 3){
			int ans = i+j+k+l ? 1<<29 : 0;
			if(2<=i && j)
				ans = min(ans, dp[i-2][j-1][k][l] + 380);
			if(10<=i && !j)
				ans = min(ans, dp[i-10][0][k][l] + 1520);
			if(3<=i && k)
				ans = min(ans, dp[i-3][j][k-1][l] + 550);
			if(12<=i && !k)
				ans = min(ans, dp[i-12][j][0][l] + 1870);
			if(5<=i && l)
				ans = min(ans, dp[i-5][j][k][l-1] + 850);
			if(15<=i && !l)
				ans = min(ans, dp[i-15][j][k][0] + 2244);
			dp[i][j][k][l] = ans;
			answers[i] = min(answers[i], ans);
		}
	}
	
	int weight;
	while(scanf("%d", &weight), weight){
		printf("%d\n", answers[weight/100]);
	}
	
	return 0;
}

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

using namespace std;

int a[200010];
vector<int> G[200010];

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

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

    for (int i = 0; i < m; ++i) {
        int x,y;
        cin >> x >> y;
        G[x].push_back(y);
        G[y].push_back(x);
    }

    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        bool flag = 1;
        for (int j: G[i]) {
            flag &= a[i] > a[j];
        }
        ans += flag;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 11444
// C - Candies
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int N; cin>>N;
	int A[N+1],B[N+1]; A[0]=0,B[0]=0;
	rp(i, 1, N+1){ cin>>A[i]; A[i] += A[i-1]; }
	rp(i, 1, N+1){ cin>>B[i]; B[i] += B[i-1]; }
	int ans = 0;
	rp(i, 1, N+1) ans = max(ans, A[i]+B[N]-B[i-1]);
	cout<< ans <<endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
h = list(map(int, input().split()))

dp = [float('inf') for _ in range(N)]
dp[0] = 0

for i in range(N):
    for j in range(1, K+1):
        if i - j >= 0:
            if dp[i - j] + abs(h[i] - h[i - j]) < dp[i]:
                dp[i] = dp[i - j] + abs(h[i] - h[i - j])
print(dp[N-1])


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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>istream &operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
//template <typename T, typename S>ostream &operator<<(ostream &os, pair<T, S> &p) {os << p.first << " " << p.second;return os;}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T, class U>bool chmin(T& a, U b) { if (a > b) { a = b; return true; }return false; }
template <class T, class U>bool chmax(T& a, U b) { if (a < b) { a = b; return true; }return false; }

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	string S; cin >> S;
	bool f = false;
	rep(i, 1, S.size()) {
		if (S[i - 1] == S[i]) {
			f = true;
		}
	}
	if (f) {
		cout << "Bad" << endl;
	}
	else {
		cout << "Good" << endl;
	}
	return 0;
}


Measured memory_bytes: 256