akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

main()
{
  int N,i,count,j,k=0;
  scanf("%d",&N);
  for(i=1; i<=N; i=i+2)
    {
      count=0;
      for(j=1; j<=i; j++)
        if(i%j==0)
          count++;
      if(count==8)
        k++;
    }
  printf("%d\n",k);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>

//#define int long long

using namespace std;

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

	for (int i = 1; i < 10; i++) {
		for (int k = 1; k < 10; k++) {
			if (i * k == N) {
				cout << "Yes" << endl;
				return;
			}
		}
	}
	cout << "No" << endl;
}

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

/*
void sample()
{
	vector<int> v;
	sort(v.begin(), v.end());
	sort(v.begin(), v.end(), greater<int>());

}
*/



Measured memory_bytes: 256
"use strict";
    
const main = arg => {
    arg = arg.split("\n");
    const N  = Number(arg[0].split(" ")[0]);
    const Q  = arg[0].split(" ")[1];
    const S  = arg[1];
    //const lr = arg.split("\n").slice(2, N + 1);
    let dp = new Array(N).fill(0);
    let cnt = 0;
    
    for(let i in dp) {
        if(S[i] === "A" && S[parseInt(i)+1] === "C") {
            cnt++;
        }
        
        dp[parseInt(i)+1] = cnt;
    }

    for(let i=0; i<Q; i++) {
        let lr = arg[i+2].split(" ");
        let l = lr[0];
        let r = lr[1];
        
        console.log(dp[r-1]-dp[l-1]);
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 38620
n,m=[int(i) for i in input().split()]
bulbs=[]
ans=0
for i in range(m):
    a=[int(i) for i in input().split()]
    bulbs.append(a[1:])
p=[int(i) for i in input().split()]
config=[]

for i in range(2**n):
    state=[]
    for j in range(n):
        if(((i)&(1<<j))):
            state.append(1)
        else:
            state.append(0)
    config.append(state)
for i in range(len(config)):
    tot=0
    for j in range(len(bulbs)):
        ct=0
        for k in range(len(bulbs[j])):
            if(config[i][bulbs[j][k]-1]==1):
                ct+=1
        if(ct%2==p[j]):
            tot+=1
    if(tot==m):
        ans+=1
print(ans)


Measured memory_bytes: 3188
import java.util.Scanner;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int[] list = {sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt()};

		if(list[0] >= list[2]+list[4] && list[1]>= list[3]+list[4] && list[2]-list[4] >=0 && list[3]-list[4] >=0){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 26424
X = int(input())
if X >=400 and X <= 599:
    print(8)
elif X >=600 and X <= 799:
    print(7)
elif X >=800 and X <= 999:
    print(6)
elif X >=1000 and X <= 1199:
    print(5)
elif X >=1200 and X <= 1399:
    print(4)
elif X >=1400 and X <= 1599:
    print(3)
elif X >=1600 and X <= 1799:
    print(2)
elif X >=1800 and X <= 1999:
    print(1)


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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

template<typename T>
constexpr T inf = static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) + 7;
constexpr llong mod = 1e9+7;

int main() {
  llong N, K;
  vector<llong> A;

  cin >> N >> K;
  A.resize(N);
  for (auto &in: A) {
    cin >> in;
  }

  llong ans = 0;
  for (int i = 0; i < N; ++i) {
    llong all_sum = 0, sum = 0;
    for (int j = 0; j < N; ++j) {
      all_sum += A[j] < A[i];
      if (j > i) {
        sum += A[j] < A[i];
      }
    }

    ans = (ans + (sum * K % mod) + (all_sum * (K * (K - 1) / 2 % mod))% mod) % mod;
  }

  cout << ans << endl;

  return 0;
}

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

using namespace std;

typedef long long ll;

int main(int argc, const char *argv[]) {
  int n;
  ll T, now = 0, ans = 0;
  cin >> n >> T;
  for (int i = 0; i < n; i++) {
    ll t;
    cin >> t;
    if (t > now + T) {
      ans += T;
    } else {
      ans += t - now;
    }
    now = t;
  }
  cout << ans + T << endl;
  return 0;
}


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

int main(){
  int w,n,i,j;
  int f,t;
  int value[31];
  for(i=1;i<31;i++){
    value[i]=i;
  }
  string str;
  cin >> w >> n;
  for(i=0;i<n;i++){
    cin >> str;
    if(str[1]==','){
      f = str[0] - '0';
      if(str.size()==3) t = str[2] - '0';
      else t = (str[2] - '0') * 10 + str[3] - '0';
    }else{
      f = (str[0] - '0') * 10 +  str[1] - '0';
      if(str.size()==4) t = str[3] - '0';
      else t = (str[3] - '0') * 10 + str[4] - '0';
    }
    int buf=value[f];
    value[f]=value[t];
    value[t]=buf;
  }
  for(i=1;i<w+1;i++){
    cout << value[i] << endl;
  }
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;

//int n;//頂点数
int parent[100010];//iの親parent[i]を格納する配列
int my_rank[100010];//iを根とする部分木の高さみたいな量?
void init(int n){
    for(int i=0;i<n;i++){
        parent[i]=i;
        my_rank[i]=0;
    }
}
int root(int x){
    if(parent[x]==x)return x;
    else return root(parent[x]);
}
void unite(int x,int y){
    x=root(x);
    y=root(y);
    if(x==y)return ;
    if(my_rank[x]<my_rank[y])parent[x]=y;
    else{
        parent[y]=x;
        if(my_rank[x]==my_rank[y])my_rank[x]++;
    }
}
bool same(int x,int y){
    return root(x)==root(y);
}
struct edge {int u,v,cost;};
bool comp(const edge& e1,const edge& e2){
    return e1.cost<e2.cost;
}

vector <edge> edges;
long long kruskal(){
    sort(edges.begin(),edges.end(),comp);
    //init(n);
    long long res=0;
    REP(i,edges.size()){
        edge e=edges[i];
        if(!same(e.u,e.v)){
            unite(e.u,e.v);
            res += (long long)e.cost;
        }
    }
    return res;
}

int main(){
  int n;
  cin>>n;
  int x,y;
  vector<pair<int,int>> xs,ys;
  REP(i,n){
    cin>>x>>y;
    xs.push_back(make_pair(x,i));
    ys.push_back(make_pair(y,i));
  }
  
  sort(xs.begin(),xs.end());
  sort(ys.begin(),ys.end());
  
  REP(i,n-1){
    edge e;
    e.u = xs[i].second;
    e.v = xs[i+1].second;
    e.cost = xs[i+1].first - xs[i].first;
    edges.push_back(e);
  }
  REP(i,n-1){
    edge e;
    e.u = ys[i].second;
    e.v = ys[i+1].second;
    e.cost = ys[i+1].first - ys[i].first;
    edges.push_back(e);
  }
  
  long long ans;
  init(n);
  ans = kruskal();
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 7016
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using namespace std;
using ll = long long;
using Edge = pair<int,long long>;
using Graph = vector<vector<Edge>>;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
 
 
int main(){
    double a,b,x;
    cin >> a >> b >> x;
    if(2*x/(a*b) <= a) pr(90-180*atan(2*x/(a*b*b))/M_PI);
    else pr(90-180*atan(a*a/(2*(a*b-x/a)))/M_PI);
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cstdlib>
#define mod 1000000007
#define ll long long
#define N 310
using namespace std;
ll f[N][N][N];
int head[N],nxt[N<<1],x[N<<1],to[N<<1],cnt;
void add(int r,int l,int lim)
{
	nxt[++cnt]=head[r];
	to[cnt]=l;
	x[cnt]=lim;
	head[r]=cnt;
}
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int l,r,x;
		scanf("%d%d%d",&l,&r,&x);
		add(r,l,x);
	}
	f[1][0][0]=1;
	for(int r=1;r<=n;r++)
	{
		for(int o=head[r];o;o=nxt[o])
		{
			int l=to[o];
			for(int i=0;i<r;i++)
				for(int j=0;j<=max(0,i-1);j++)
				{
 					if(x[o]==1 && l<=i) f[r][i][j]=0;
 					if(x[o]==2 && (i<l || l<=j)) f[r][i][j]=0;
					if(x[o]==3 && j<l) f[r][i][j]=0;
                }
		}
		for(int l=0;l<r;l++)
			for(int i=0;i<=max(0,l-1);i++)
			if(f[r][l][i])
			{
				f[r+1][l][i]=(f[r+1][l][i]+f[r][l][i])%mod;
				f[r+1][r][i]=(f[r+1][r][i]+f[r][l][i])%mod;
				f[r+1][r][l]=(f[r+1][r][l]+f[r][l][i])%mod;
			}
	}
	ll ans=0;
	for(int i=0;i<n;i++)
		for(int j=0;j<=max(0,i-1);j++)
		ans=(ans+f[n][i][j])%mod;
    printf("%lld\n",ans*3%mod);
	return 0;
}


Measured memory_bytes: 225664
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<bool> ds(N, false), dg(N, false);
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        if (a == 0) {
            ds[b] = true;
        }
        if (b == N - 1) {
            dg[a] = true;
        }
    };

    bool flag = false;
    rep(i, N) {
        if (dg[i] && ds[i]) flag = true; 
    }

    cout << (flag == false ? "IMPOSSIBLE" : "POSSIBLE") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;
using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;
const int INF=1<<30,MOD=1000000007;const ll LINF=1ll<<60;
#define _ol3(_1,_2,_3,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,v.size())
#define all(v) (v).begin(),(v).end()
#define bit(n) (1ll<<(n))
#define clamp(n,mi,ma) max(min(n,ma),mi)
#define uniq(v) sort(all(v));v.erase(unique(all(v)),v.end())
#define pb push_back
#define F first
#define S second
#define endl '\n'
#ifndef LOCAL
struct ostdmy{template<class T>ostdmy&operator<<(const T&t){return*this;}};ostdmy cer_;
#define cerr cer_
#endif
#define cho(n,a,b) cout<<((n)?a:b)<<endl
#define YES(n) cho(n,"YES","NO")
#define Yes(n) cho(n,"Yes","No")
#define Poss(n) cho(n,"Possible","Impossible")
template<class T>bool chmax(T&a,const T&b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T&a,const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>ostream&operator<<(ostream&o,const vector<T>&v){for(const T&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>ostream&operator<<(ostream&o,const set<T>&v){for(const T&i:v)o<<i<<' ';return o;}
int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    int n,x;
    cin>>n>>x;
    vi m(n);
    cin>>m;
    int mi=INF;
    REP(i,n){
        x-=m[i];
        chmin(mi,m[i]);
    }
    int ans=n;
    ans+=x/mi;
    cout<<ans<<endl;
    return 0;
}

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

int main(){
  //N:参加人数, K:初期ポイント, Q:正解の回数, A:正解者
  int N,K,Q;
  cin >> N >> K >> Q;
  vector<int> A(Q);
  vector<int> point(N,K-Q);
  
  for(int i=0; i<Q ;i++){
    cin >> A.at(i);
	point.at(A.at(i)-1)+=1;      
  }
  
  for(int j=0; j<N;j++){
    if(point.at(j)<=0){
      cout << "No" <<endl;
    }
    else{
      cout <<"Yes" << endl;
    }    
  }  
  
}

Measured memory_bytes: 1408
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

LL gcd(LL a, LL b)
{
	if (a < b) std::swap(a, b);
	LL r = a % b;
	while (r != 0)
	{
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}

LL lcm(LL a, LL b)
{
	return a / gcd(a, b) * b;
}

int main()
{
	LL A, B;
	in >> A >> B;
	out << lcm(A, B) << std::endl;
}


Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
ll const INF = 1LL << 60;
ll const MAX_N = 100000;
ll const MOD = 1000000007;
ll const MAX_V = 10000;
ll const MAX_E = 10000;

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

    cout << N / 3 << endl;

    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<cmath>
using namespace std;
int main(){
  double d,x,y,ans;
  int cnt=0,n;
  cin>>n>>d;
  for(int i=0;i<n;i++){
    cin>>x>>y;
    ans=sqrt(pow(x,2)+pow(y,2));
    if(ans<=d){
      cnt++;
    }
  }
  cout<<cnt<<endl;
  return 0;
}


Measured memory_bytes: 3840
#include <iostream>
using namespace std;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)

int main()
{
    int N;
    cin >> N;
    long long ret = 0;
    FOR(i, 1, N + 1) ret += 1LL * i * (N / i) * (N / i + 1) / 2;
    cout << ret << '\n';
}


Measured memory_bytes: 3620
#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

N = int(read())


def divisor(N):
    x = np.arange(1, 10 ** 6 + 1, dtype=np.int64)
    div = set(x[N % x == 0])
    return div | set(N // x for x in div)


cand = divisor(N) | divisor(N - 1)


def test(N, K):
    if K == 1:
        return False
    while N % K == 0:
        N //= K
    return N % K == 1


answer = sum(test(N, d) for d in cand)
print(answer)


Measured memory_bytes: 38056
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath> 
using namespace std;
int main(){
	long long n,m;
	while(scanf("%d%d",&n,&m)==2){
		long long sum;
		sum = (n-2)*(m-2);
		if(sum< 0) cout<<-sum<<endl;
		else cout<<sum<<endl; 
	}
} 

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

using namespace std;

struct edge {
    int from;
    int to;
    int weight;
};

int main() {
    const auto INF = numeric_limits<int>::max();

    int V, E, r;
    cin >> V >> E >> r;

    vector<edge> edges;
    for (int i = 0; i < E; ++i) {
        int s, t, d;
        cin >> s >> t >> d;

        edges.push_back(edge{s, t, d});
    }

    // Bellman-Ford algorithm
    vector<int> d(V, INF);
    d[r] = 0;
    for (auto i = 0; i < V; ++i) {
        for (auto& e : edges) {
            // cerr << ": " << e.from << " " << e.to << " " << e.weight << endl;
            if (d[e.from] != INF && d[e.from] + e.weight < d[e.to]) {
                d[e.to] = d[e.from] + e.weight;
            }
        }
    }
    for (auto& e : edges) {
        if (d[e.from] != INF && d[e.from] + e.weight < d[e.to]) {
            cout << "NEGATIVE CYCLE" << endl;
            return 0;
        }
    }

    for (auto x : d) {
        if (x == INF) {
            cout << "INF" << endl;
        } else {
            cout << x << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3168
from collections import deque

N = int(input())
A = list(map(int, input().split()))
ans = deque([])

for i in range(1, N+1):
    if i % 2 == N % 2:
        ans.appendleft(A[i-1])
    else:
        ans.append(A[i-1])
print(*ans)


Measured memory_bytes: 25416
#include <iostream>

int main() {
	int k, s;
	std::cin >> k >> s;

	int count = 0;
	for (int x = 0; x <= k; ++x)
		for (int y = 0; y <= k && x + y <= s; ++y)
			if (s - x - y <= k)
				++count;

	std::cout << count << std::endl;
}

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

using namespace std;
int dp[1000000+20],n,A[200000+20];

int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>A[i];
    }
    sort(A+1,A+n+1);
    for(int i=1;i<=n;i++)
    {
        if(A[i]==A[i-1])
        {
			dp[A[i]]=1;
        }
    }

    int count=0;
    for(int i=1;i<=n;i++)
    {
        if(!dp[A[i]])
            count++;
        if(A[i]!=A[i-1])
        {
            for(int j=2*A[i];j<=1000000;j+=A[i])
            {     
                dp[j]=1;
            }
        }
    }

    cout<<count<<"\n";

    return 0;
}


Measured memory_bytes: 8324
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

int main(){
  int a,b;
  cin >> a >> b;
  if(a%2==1 && b%2==1){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif
using namespace std;
int main() {
  int a,b;
  cin >> a >> b;

  if (a > 12) {
    cout << b;
  } else if (a > 5) {
    cout << b/2;
  } else {
    cout << 0;
  }

  return 0;
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
for (int i = 0; i < N; i++) {
cin >> list[i];
}
// for文
for (int i = 0; i < N; i++) {
}
//配列
vector<int> list;
list.at(i)
vector<vector<int>> list(10, vector<int>(10));
sort(all(list));
sort(all(list), greater<int>());
  //配列の内容表示
dout << "====listの内容====\n";
for (int i = 0; i < N; i++) dout << list[i] << endl;
dout << "====ここまで====\n";
*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const int MOD = 1000000007;
int H,W;
vector<vector<char>> s;
vector<vector<ll>> d;
int di[4] = {1,-1,0,0};
int dj[4] = {0,0,1,-1};
//(1,1)がstartで(H,W)がゴール
//なるべくたくさんのますを黒くする
//つまりなるべく少ない白います目をとおるとよい
int bfs(){
    queue<p> q;
    q.push(p(0,0));
    d[0][0] = 0;
    while(q.size()){
        p now = q.front();q.pop();
        if(now.first == H-1 and now.second == W -1)  return d[H-1][W-1];
        REP(i,4){
            int ni = now.first + di[i];
            int nj = now.second + dj[i];
            if( 0<=ni and ni<H and 0<= nj and nj<W){
                //範囲内
                if(s[ni][nj] == '.' and d[ni][nj] == INF){
                    d[ni][nj] = d[now.first][now.second]+1LL;
                    q.push(p(ni,nj));
                }
            }
        }

    }
    return -1;
}

int main(){
    cin>>H>>W;
    s.resize(H);d.resize(H);
    REP(i,H){
        s[i].resize(W);d[i].resize(W);
    }
    ll white_cnt = 0;
    REP(i,H){
        REP(j,W){
            cin>>s[i][j];
            d[i][j] = INF;
            if(s[i][j] == '.'){
                white_cnt++;
            }
        }
    }
    ll res = bfs();
    if(res==-1){
        cout<<"-1"<<endl;
        return 0;
    }
    cout<<white_cnt-res-1<<endl;
    return 0;
}

Measured memory_bytes: 256
/// Zhupengfei 2018
/// Hereby declare: this program is in public domain.

/// Solution for problem: SoundHound B

#include <bits/stdc++.h>

#ifdef LOCAL
#pragma GCC poison printf // To avoid fastio problems
#pragma GCC poison scanf
#endif

using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	string s;
	int w;
	cin>>s>>w;
	for(int i=0;i<s.size();i+=w) {
		cout<<s[i];
	}
	cout<<endl;

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
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; }

int main() {
  int N;
  cin >> N;
  int ans = 0;
  while (N) {
    if (N%10 == 2)
      ans++;
    N /= 10;
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
	int n,k,i,x,y;
	cin>>n>>k;
	set<int> s;
	
	while(k--)
	{
		cin>>x;
		while(x--){
			cin>>y;
			s.insert(y);
		}
	}
	
	cout<<n-s.size()<<endl;
	return 0;
}

Measured memory_bytes: 3640
import sys
import math
import collections
sys.setrecursionlimit(10000)

mod = 10**9 + 7

n, k = map(int, input().split())
dic = collections.defaultdict(int)
for i in range(n):
    a, b = map(int, input().split())
    dic[a] += b
ls = []
for key in dic.keys():
    ls.append(key)
ls.sort()
for i in range(len(ls)):
    val = dic[ls[i]]
    if val >= k:
        print(ls[i])
        exit(0)
    else:
        k -= val


Measured memory_bytes: 55384
import java.io.IOException;
import java.util.NoSuchElementException;

import java.io.InputStream;

@SuppressWarnings("unchecked")
public class Main {
    public static void main(String[] args) throws IOException {
        FastScanner fs = new FastScanner();

        final int N = fs.nextInt();

        int sum = 0;

        for (int i = 0; i < N; i++) sum += fs.nextInt() - 1;

        System.out.println(sum);
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
        if (hasNextByte()) return buffer[ptr++];
        else return -1;
    }
    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
        while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
        return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if(b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 21332
import bisect
N = int(input())
A = sorted(list(map(int, input().split())))
B = list(map(int, input().split()))
C = sorted(list(map(int, input().split())))
ans = 0
for b in B:
    i = bisect.bisect_left(A, b)
    j = N - bisect.bisect_right(C, b)
    ans += i * j
print(ans)

Measured memory_bytes: 23744
N = int(input())
A = list(map(int, input().split()))
count = 0

while True:
  i = 0
  flag = 0
  while i < N:
    if A[i]%2 == 1:
      flag = 1
    else:
      A[i] = A[i]/2
    i += 1
  if flag == 1:
     print(count)
     break
  count += 1
      

Measured memory_bytes: 3060
n = int(input())

in_list = [int(input()) for _ in range(n)]
min_val = in_list[0]
max_sub = -1e9

for i in range(1, n):
    if in_list[i] - min_val > max_sub:
        max_sub = in_list[i] - min_val

    if in_list[i] < min_val:
        min_val = in_list[i]

print(max_sub)


Measured memory_bytes: 13628
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int n;

int solve(string& s, string& t) {
  if (s == t) return n;
  int k{};
  for (int i = 0; i < n; ++i) {
    for (; k < n; k++) {
      if (s[i] != t[k])
        break;
    }
  }
  // cout << k << endl;
  if (k == 0 && s.back() ==  t.front()) {
    ++k;
  }
  return n * 2 - k;
}

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


Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main{
 
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		
		Scanner sc=new Scanner(System.in);
		
		long N_absolute=Math.abs(sc.nextLong());
		long K_absolute=Math.abs(sc.nextLong());
		long result=N_absolute;
		long hiki=0;

		result=N_absolute%K_absolute;
	
		if(result==0) {
			System.out.println(result);
		}else {
			hiki=result-K_absolute;
			hiki=Math.abs(hiki);
			if(result>hiki) {
				System.out.println(hiki);
			}else {
				System.out.println(result);
			}
		}
	
	}
}

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

int main() {
  string s;cin>>s;
  rep(i,26) {
    char c = 'a'+i;
    bool flg=false;
    rep(j,s.size()) {
      if (s[j]==c) {flg=true;break;}
    }
    if (flg) continue;
    else {
      cout<<c;return 0;
    }
  }
  cout << "None";
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rt "\n"
#define sp " "
#define test1 cout << "test1" << endl;
#define test2 cout << "test2" << endl;
#define fixprecision(n) fixed; cout << setprecision(n)
#define kyopro ios::sync_with_stdio(false);cin.tie(NULL);
#define MOD 1000000007
#define rep(i, s, N) for(ll i{s}; i < N; i++)
#define iikCe Cuto&
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

int main(){
  kyopro;
  ll A, B, C, D;
  cin >> A >> B >> C >> D;
  ll Cs = C, Ds = D;
  ll r, tmp;
  if(C < D){
    tmp = C;
    C = D;
    D = tmp;
  }
  r = C % D;
  while(r != 0){
    C = D;
    D = r;
    r = C % D;
  }
  ll waru = Cs * Ds / D;
  ll sum = B - A + 1 - B / Cs - B / Ds + (A-1) / Cs + (A-1) / Ds + B / waru - (A-1) / waru;
  cout << sum << rt;
}

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

int main() {
    int n;
    cin >> n;
    string c;
    bool result = false;
    for (int i=0; i<n; i++) {
        cin >> c;
        if(c == "Y") {
            result = true;
            break;
        }
    }
    if(result) {
        cout << "Four" << endl;
    } else {
        cout << "Three" << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <cmath>
#include <vector>
#include<cstdio>
#include <iterator>
#include <sstream>
#include <algorithm>
#include <map>
#include <numeric>
#include <stack>
#include <queue>
using namespace std;
typedef long long ll;
#define len(str) (int)(str.length())
int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int a = 0; a < N; a++)
	{
		cin >> A[a];
	}
	int temp = 0;
	for (int a = N-1; a >=0; a--)
	{
		if (a%2==0) {
			temp += A[a];
		}
		else {
			temp -= A[a];
		}
	}
	int x = temp / 2;
	for (int a = 0; a < N; a++)
	{
		cout << x*2;
		if (a==N-1) {
			cout << endl;
		}
		else {
			cout << " ";
		}
		x = A[a] - x;
	}

}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) {}
    void init(int n) { par.assign(n, -1);}
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
main(){
    int N,M;
    cin >> N >> M;
    UnionFind uf(N);
    rep(i,0,M){
        int x,y,z;
        cin >> x >> y >> z;
        uf.merge(x-1, y-1);
    }
    set<int> st;
    rep(i,0,N)st.insert(uf.root(i));
    cout << st.size() << endl;
}

Measured memory_bytes: 5376
//Self-control leads to consistency.
#include <bits/stdc++.h> 
using namespace std; 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000
#define MOD 1000000007
#define pb push_back
#define ve vector<ll>
#define dos pair<ll,ll>
#define vedos vector<dos>
#define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define EPS 0.000001
struct greateri
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};
void setIO(string s) {
  ios_base::sync_with_stdio(0); cin.tie(0); 
  freopen((s+".in").c_str(),"r",stdin);
  freopen((s+".out").c_str(),"w",stdout);
}
int main()
{
  //flash;
  ll n;
  cin>>n;
  string in;
  cin>>in;
  ve pos;
  for (ll i = sz(in)-1; i >= 0; --i)
  {
    if(in[i]=='R')pos.pb(i);
  }
  ll ans=0;
  ll index=0;
  for (ll i = 0; i < sz(in); ++i)
  {
    if(index==sz(pos))break;
    if(in[i]=='W' && pos[index]>i){
      swap(in[i],in[pos[index]]);
      ans++;
      index++;
    }
    else if(in[i]=='W')break;
  }
  reverse(all(in));
  bool ka=0;
  for (ll i = 0; i < sz(in); ++i)
  {
    if(in[i]=='R'){
      ka=1;
    }
    if(ka && in[i]=='W')ans++;
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 5396
#include<iostream>
using namespace std;
int n,t,s,f,sum;
int main(){
  while(cin>>t&&t){
    cin>>n;
    sum=0;
    for(int i=0;i<n;i++){
      cin>>s>>f;
      sum+=(f-s);
    }
    if(sum>=t){
      cout<<"OK"<<endl;
    }else{
      cout<<t-sum<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1160
// in the name of Allah

#include <bits/stdc++.h>

#define endl '\n'
#define sz(x) ((int) (x.size()))

using namespace std;

int a[10];

bool okay(int m) {
	while(m) {
		if(a[m%10]) return 0;
		m /= 10;
	}
	return 1;
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, k, t;
	cin >> n >> k;
	memset(a, 0, sizeof a);
	for(int i=0; i<k; i++) {
		cin >> t;
		a[t] = 1;
	}
	for(int i=n; ; i++) {
		if(okay(i)) {
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

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


#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

void pre(){


}

void solve(){


}
int cnt[10009];
int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
	pre();
	int n;cin>>n;
	int k;cin>>k;
	string s;cin>>s;
	string ans = s;
	string t = s;
	reverse(all(t));
	s = s+t;
	rep(i,n) ans = min(ans,s.substr(i,n));
	char c = 'z';
	trav(i,s) c=min(c,i);
	int gg = 0;
	rep(i,n){
		if(ans[i]==c) gg++;
		else break;
	}
	if(k>14||(1<<(k-1))*gg>=n) {
		cout<<string(n,c);
		return 0;
	}
	string pre = string((1<<(k-1))*gg,c);
	int l = n-sz(pre);
	ans = pre+ans.substr(gg,l);
	cout<<ans;
	return 0;
}



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

int dfs(int index,vector<int> &dp,vector<vector<int>> &adj){
    if(dp[index] != 0) return dp[index];
    int temp=1;
    // vis[index]=true;
    for(auto j :adj[index]){
        temp = max(temp,1+dfs(j,dp,adj));
    }
    // vis[index]=false;
    dp[index] = temp;
    return dp[index];
}

int main()
{
  int a,b,n,e;
  cin >> n >> e;
  vector<vector<int>> adj(n+1);
  for(int i=0;i<e;i++){
      cin >> a >> b;
      adj[a].push_back(b);
  }
  vector<int> dp(n+1,0);
//   vector<bool> vis(n+1,false)
  for(int i=1;i<dp.size();i++){
      if(dp[i]==0) dfs(i,dp,adj);
  } 
  int mm=0;
  for(int i=0;i<dp.size();i++){
      mm=max(mm,dp[i]);
  }
  cout << mm-1 << endl;
  return 0;
}

Measured memory_bytes: 8832
const main = stdin => {
  const input = stdin.trim().split('\n')

  if (input[4] - input[0] <= input[5]) {
    console.log('Yay!');
  } else {
    console.log(':(')
  }

}
// 標準入力
main(require("fs").readFileSync("/dev/stdin", "utf8"))


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

int main(){
	int a,b,c,num=0;
	scanf("%d %d %d",&a,&b,&c);
	for(int i=a;i<=b;i++){
		if(i%c==0)num++;
	}
	printf("%d",num);
	return 0;
} 

Measured memory_bytes: 1708
import java.util.Scanner;

// https://atcoder.jp/contests/abc085/tasks/abc085_c
public class Main {

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

		int n = scanner.nextInt();
		int y = scanner.nextInt();

		// 10000a+5000b+1000c=y
		boolean flag = true;
		loop: for(int a=0;a<=n;a++){
			for(int b=0;b<=n-a;b++) {
				int c = n-a-b;
				if(10000*a+5000*b+1000*c==y) {
					System.out.println(a+" "+b+" "+c);
					flag = false;
					break loop;
				}
			}
		}

		if(flag) {
			System.out.println(-1+" "+-1+" "+-1);
		}
		scanner.close();
	}
}

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

#define for(i, a, b) for(ll (i)=a;(i)<(b);++(i))
#define rep(i, n)    for(i, 0, n)

const ll inf = 1e15;
const ll mod = 1e9+7;

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

ll pow(ll x, ll n, ll acc = 1) {
    if (n == 0) return acc;
    
    if (n % 2 == 0) return pow(x * x, n >> 1, acc);
    else            return pow(x, n - 1, acc * x);
}

ll mpow(ll x, ll n, ll acc = 1) {
    if (n == 0) return acc;
    
    if (n % 2 == 0) return mpow(x * x % mod, n >> 1, acc);
    else            return mpow(x, n - 1, acc * x % mod);
}

int main() {
    ll N;
    cin >> N;
    
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    
    vector<ll> num(N, 0);
    rep(i, N) num[A[i]]++;
    
    bool ok = true;
    if (N & 1 && num[0] != 1 ) ok = false;
    for(i, 1, N) if (num[i] != 2 and num[i] != 0) ok = false;
    
    cout << (ok ? mpow(2, N / 2) : 0) << endl;
    
    return 0;
}


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

#define MAX 255

int parent(int i) { return i / 2; }
int left(int i) { return 2 * i; }
int right(int i) { return 2 * i + 1; }

int main() {
	int n, A[MAX];
	cin >> n;
	for (int i = 1; i < n + 1; i++) {
		cin >> A[i];
	}

	for (int i = 1; i < n + 1; i++) {
		cout << "node " << i << ": ";
		cout << "key = " << A[i] << ", ";
		if (parent(i) > 0)cout << "parent key = " << A[parent(i)] << ", ";
		if (left(i) < n + 1)cout << "left key = " << A[left(i)] << ", ";
		if (right(i) < n + 1)cout << "right key = " << A[right(i)] << ", ";
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 3084
/*\
 * ...
 * ......
 * In the name of ALLAH
 * ......
 * ...
\*/

#include <bits/stdc++.h>

using namespace std;
#define Size(x) ((int)(x).size())
#define pb push_back
#define LD_OUT setprecision(12) << fixed
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
const int INF = 1e9 + 10 , MN = 2e5 + 10 , LG = 222;
const ll BIG = 1000ll*1000*1000*1000*1000*1000 + 10;

int n , nxt[MN];
string s;
ll Nx[LG] , Ny[LG] , X[33][LG] , Y[33][LG];
int ps[33][MN];

void prep()
{
	int cur = 0;
	for(int i=1;i<n;++i){
		while(cur && s[i] != s[cur]) cur = nxt[cur];
		cur += (s[i] == s[cur]);
		nxt[i+1] = cur;
	}
	Nx[0] = n - nxt[n] , Ny[0] = nxt[n];
	for(int i=0;i<Nx[0];++i)
		X[s[i]-'a'][0]++;
	for(int i=Nx[0];i<n;++i)
		Y[s[i]-'a'][0]++;
	for(int i=1;i<LG;++i){
		Nx[i] = Nx[i-1] + Ny[i-1];
		Nx[i] = min(Nx[i] , BIG);
		Ny[i] = Nx[i-1];
		for(int j=0;j<26;++j){
			X[j][i] = X[j][i-1] + Y[j][i-1];
			Y[j][i] = X[j][i-1];
			X[j][i] = min(X[j][i] , BIG);
		}
	}
	for(int i=0;i<n;++i)
		for(int j=0;j<26;++j)
			ps[j][i+1] = ps[j][i] + (s[i]-'a' == j);
}

ll get(ll val,int c)
{
	for(int i=LG-1;~i;--i)
		if(Nx[i] <= val) return min(BIG , X[c][i] + get(val - Nx[i] , c));
	return ps[c][val];
}

int main()
{
	ios_base :: sync_with_stdio(false) ,cin.tie(0) , cout.tie(0);
	cin>>s;
	n = Size(s)/2;
	prep();

	ll l , r;
	cin >> l >> r;
	for(int c=0;c<26;++c) cout << get(r , c) - get(l-1 , c) << ' ';
	cout << '\n';
	return 0;
}


Measured memory_bytes: 22420
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//}

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

int dp[1010][1010];
int bingo[3][3];
bool flag[3][3];
int I[100][20];

int main() {
	int n;
	cin >> n;
	vector<int>v(n);
	rep(i, n) {
		cin >> v[i];
	}
	vector<pair<int, int>>box(101010), box2(101010);
	rep(i, n) {
		if (i % 2 == 0)box[v[i]].first++;
		else box2[v[i]].first++;
	}
	rep(i, n) {
		if (i % 2 == 0)box[v[i]].second = v[i];
		else box2[v[i]].second = v[i];
	}
	sort(box.begin(), box.end(), greater<pair<int,int>>());
	sort(box2.begin(), box2.end(), greater<pair<int, int>>());
	ll ans = 0;
	if (box[0].second != box2[0].second) {
		ans += n - box[0].first - box2[0].first;
	}
	else {
		ll mx = max(box[0].first + box2[1].first, box[1].first + box2[0].first);
		ans += n - mx;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2176
import java.util.Scanner;

public class Main {
	static int N;
	static int A;
	static int B;
	static int C;
	static int l[];
	static int min = Integer.MAX_VALUE;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		A = sc.nextInt();
		B = sc.nextInt();
		C = sc.nextInt();
		l = new int[N];
		for (int i = 0; i < N; i++) {
			l[i] = sc.nextInt();
		}
		dfs(0,0,0,0,0);
		System.out.println(min);
	}
	public static void dfs(int a,int b, int c,int i,int cost) {
		if (i==N) {
			if (a==0 || b==0 || c==0) {
				return;
			}
			cost += Math.abs(a-A) + Math.abs(b-B) + Math.abs(c-C) -30;
			min = Math.min(min, cost);
			return;
		}
		dfs(a,b,c,i+1,cost);
		dfs(a+l[i],b,c,i+1,cost+10);
		dfs(a,b+l[i],c,i+1,cost+10);
		dfs(a,b,c+l[i],i+1,cost+10);
	}
}

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

int main(){
	
	double a, b, c;
	double s, l, h;
	
	scanf("%lf %lf %lf", &a, &b, &c);
	
	h = b*sin(c*M_PI/180);
	s = a * h / 2;
	l = a + b + sqrt(a*a + b*b - 2*a*b*cos(c*M_PI/180));
	
	
	printf("%f\n%f\n%f", s, l, h);
	
    return 0;

}

Measured memory_bytes: 648
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
 
const int N = 1e5;
VI e[N];
int cmp[N];
 
void dfs(int now, int c){
    cmp[now] = c;
    for (int next : e[now]){
        if (cmp[next] == c) continue;
        dfs(next, c);
    }
}
 
int main() {
    ll n, m;
    cin >> n >> m;
    REP(i,m){
        int u, v;
        scanf("%d %d", &u, &v);
        u--;
        v--;
        e[u].push_back(v);
        e[v].push_back(u);
    }
    dfs(0, 1);
    dfs(1, 2);
 
    ll one = 0, two = 0;
    REP(i,n){
        if (cmp[i] == 1) one++;
        if (cmp[i] == 2) two++;
    }
    ll emp = n - one - two;
 
    cout << max((one + emp) * (one + emp - 1) / 2 + two * (two - 1) / 2, one * (one - 1) / 2 + (two + emp) * (two + emp - 1) / 2) - m << endl;
 
    return 0;
}

Measured memory_bytes: 9216
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

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

    vector<P> v;

    rep(i,n){
        int x, l;
        cin >> x >> l;
        v.push_back(P(x + l, x - l));
    }

    sort(v.begin(), v.end());

    int ans = 0;

    int now = -1001001001;

    rep(i,n){
        if(now <= v[i].second){
            ans++;
            now = v[i].first;
        }
    }

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


Measured memory_bytes: 1400
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int ma=sc.nextInt();
		int mb=sc.nextInt();

		int a[] = new int[n];
		int b[] = new int[n];
		int c[] = new int[n];
		for(int i=0; i<n; i++) {
			a[i]=sc.nextInt();
			b[i]=sc.nextInt();
			c[i]=sc.nextInt();
		}
		int dp[][][] = new int[n+1][400+1][400+1];

		int max = 100*40+5;
		for(int i=0; i<=n; i++) {
			for(int j=0; j<=400; j++) {
				for(int k=0; k<=400; k++) {
					dp[i][j][k]=max;
				}
			}
		}
		dp[0][0][0]=0;

		for(int i=0; i<n; i++) {
			for(int j=0; j<=400; j++) {
				for(int k=0; k<=400; k++) {
					if(dp[i][j][k] == max) continue;
					dp[i+1][j][k] = Math.min(dp[i+1][j][k], dp[i][j][k]);
					dp[i+1][j+a[i]][k+b[i]] = Math.min(dp[i+1][j+a[i]][k+b[i]], dp[i][j][k]+c[i]);
					/*dp[i][j][k] = dp[i-1][j][k];
					if(j-a[i-1]>=0 && k-b[i-1]>=0 && dp[i-1][j-a[i-1]][k-b[i-1]]!=max) {
						dp[i][j][k] = Math.min(dp[i][j][k], dp[i-1][j-a[i-1]][k-b[i-1]] + c[i-1]);
					}
					*/
				}
			}
		}

		int ans = 100*40+5;
		for(int i=1; i<=400; i++) {
			for(int j=1; j<=400; j++) {
				if(dp[n][i][j] != max) {
					if(i*mb == j*ma) {
						ans = Math.min(ans, dp[n][i][j]);
					}
				}
			}
		}
		if(ans == max) {
			System.out.println(-1);
		}else {
			System.out.println(ans);
		}
		sc.close();
	}


}


Measured memory_bytes: 69528
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

int main() {
    int N;
    scanf("%d", &N);
    int ans = 0;
    for (int i = 0; i < N; i++) {
        int A, K;
        scanf("%d %d", &A, &K);
        int cur_ans = 0;
        while (1) {
            int cnt = A / K;
            if (cnt == 0) break;
            if ((A % K) == 0) {
                cur_ans = A / K;
                break;
            }
            A = A - (A / K) - 1;
        }
        ans ^= cur_ans;
    }
    if (ans) puts("Takahashi");
    else puts("Aoki");
    return 0;
}


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

int main(){
    int n, m, x;
    cin >> n >> m >> x;
    vector<vector<int>> a(n, vector<int>(m));
    vector<int> c(n);
    for(int i = 0; i < n; i++){
        cin >> c[i];
        for(int j = 0; j < m; j++)cin >> a[i][j];
    }
    int ans = 12345678;
    int all = 1<<n;
    for(int mask = 0; mask < all; mask++){
        vector<int> level(m);
        int cost = 0;
        for(int i = 0; i < n; i++){
            if((mask>>i)&1){
                cost += c[i];
                for(int j = 0; j < m; j++){
                    level[j] += a[i][j];
                }
            }
        }
        bool ok = true;
        for(int j = 0; j < m; j++){
            if(level[j] < x) ok = false;
        }
        if(ok) ans = min(ans,cost);
    }
    if(ans == 12345678) cout << -1 << endl;
    else cout << ans << endl;
}


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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] array = line.split(" ");

		Arrays.sort(array);
		System.out.println(array[0] + " " + array[1] + " " + array[2]);
	}

}

Measured memory_bytes: 26296
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        Solver solverObj = new Solver();
        System.out.println(solverObj.solve(s));
    }
}

class Solver {
    public int solve(String s){
        int max = 0;

        int left = 0;
        for(int i=0;i<s.length();i++){
             char c = s.charAt(i);
             if(c == 'R'){
                 max = Math.max(max, i - left + 1);
             } else {
                 left = i + 1;
             }
        }
        return max;
    }
}


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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if(a == b || a == c || b == c){
    if(a != b || b != c || c != a ){
      cout << "Yes" << "\n";
    }else{
      cout << "No" << "\n";
   }
  }else{
      cout << "No" << "\n";
   }
  return 0;
}

Measured memory_bytes: 256