akhauriyash/Code-Regression huggingface dataset:
var s,p:ansistring;
    i,j,t:longint;
    a:int64;
begin
  readln(s);
  i:=1;
  while i<=length(s) do
  begin
    if s[i]='A' then
      inc(t);
    if s[i]='B' then
      if (i<>length(s))and(s[i+1]='C') then
      begin
        inc(a,t);
        inc(i,2);
        continue;
      end
      else
        t:=0;
    if s[i]='C' then
      t:=0;
    inc(i);
  end;
  writeln(a);
end.

Measured memory_bytes: 384
#include<iostream>
#include<cmath>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
#define rep1e(i, n) for (int i = 1; i <= (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    int N;
    cin >> N;
    int a[N], b[N], c[N];
    rep(i,N) cin >> a[i] >> b[i] >> c[i];

    int dp[N][3];
    rep(i,N)rep(j,3) dp[i][j] = 0;
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];

    // dp[i][j] = 太郎くんがi日目に行動jをとったとき得る幸福度の総和の最大値
    rep1(i,N)rep(j,3) {
        if (j == 0)
            dp[i][j] = a[i] + max(dp[i-1][1], dp[i-1][2]);
        if (j == 1)
            dp[i][j] = b[i] + max(dp[i-1][0], dp[i-1][2]);
        if (j == 2)
            dp[i][j] = c[i] + max(dp[i-1][0], dp[i-1][1]);
    }

    int ans = max(dp[N-1][0], max(dp[N-1][1], dp[N-1][2]));
    cout << ans << endl;
    return 0;
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

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

::std::int64_t gcd(::std::int64_t a, ::std::int64_t b) {
	while (b != 0) {
		::std::swap(a, b);
		b = b % a;
	}
	return a;
}

int64 need[10] = {INF, 2, 5, 5, 4, 5, 6, 3, 7, 6};
bool canuse[10] = {};

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int64 N, M;
	cin >> N >> M;
	REP(i, M) {
		int32 a;
		cin >> a;
		canuse[a] = 1;
	}
	vector<int64> dp(N+1, -INF);
	dp[0] = 0;
	REP(i, N) {
		for(int32 j = 9;j >= 1;j--){
			if (!canuse[j]) continue;
			if (need[j] + i > N) continue;
			chmax(dp[need[j]+i], dp[i]+1);
		}
	}
	int32 now = N;
	string res = "";
	while(now > 0) {
		for(int32 i = 9;i >= 1;i--){
			if (!canuse[i]) continue;
			if (now - need[i] < 0) continue;
			if (dp[now-need[i]] == dp[now]-1) {
				now -= need[i];
				res += (char)('0'+i);
				break;
			}
		}
	}
	cout << res << endl;
}


Measured memory_bytes: 384
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Maybe (fromJust)
import Debug.Trace
import Data.List

solveInner :: String -> Int -> Int -> Int
solveInner [] maxX _ = maxX
solveInner (c:s) maxX accum
    = solveInner s (max maxX acc) acc
    where
        diff = if c == 'I' then 1 else -1
        acc = accum + diff

solve:: String -> Int
solve str = solveInner str 0 0

main :: IO ()
main = do
    _ <- BS.getLine
    s <- BS.unpack <$> BS.getLine
    print $ solve s


Measured memory_bytes: 380
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <unordered_map>
using namespace std;
typedef long long int ll;
typedef pair<int, ll> P;
int r, c, n;
vector<P> v[100001];
vector<P> g[100001];
int cmp[100001];
ll d[100001];
int c0;
bool nuee;
ll mn[100001];
void dfs(int x){
  cmp[x]=c0;
  for(auto p:g[x]){
    int y=p.first;
    if(cmp[y]){
      if(d[y]!=d[x]+p.second){
        nuee=1;
      }
    }else{
      d[y]=d[x]+p.second;
      mn[c0]=min(d[y], mn[c0]);
      dfs(y);
    }
  }
}
    
int main()
{
	cin>>r>>c>>n;
  for(int i=0; i<n; i++){
    int x, y; ll a; cin>>x>>y>>a;
    v[x].push_back(P(y, a));
  }
  for(int i=1; i<=r; i++){
    for(int j=1; j<v[i].size(); j++){
      int y1=v[i][j-1].first, y2=v[i][j].first;
      ll a1=v[i][j-1].second, a2=v[i][j].second;
      g[y1].push_back(P(y2, a2-a1));
      g[y2].push_back(P(y1, a1-a2));
    }
  }
  for(int i=1; i<=c; i++){
    if(cmp[i]==0){
      c0++;
      dfs(i);
      if(nuee){
        cout<<"No"<<endl;
        return 0;
      }
    }
  }
  for(int i=1; i<=r; i++){
    if(v[i].empty()) continue;
    int y=v[i][0].first; ll a=v[i][0].second;
    if(a-d[y]+mn[cmp[y]]<0){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
const int P = 1e9 + 7;
using namespace std;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin >> n;
	vector<long long> a;
	a.resize(n);
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	vector<int> sum;
	sum.resize(60);
	long long ans = 0;
	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < 60; ++j) {
			if(a[i] >> j & 1) {
				ans = (ans + (1LL << j) % P * (i - sum[j])) % P;
			} else {
				ans = (ans + (1LL << j) % P * sum[j]) % P;
			}
			sum[j] += a[i] >> j & 1;
		}
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 2560
#coding: utf-8
import bisect

n, q = map(int, raw_input().split())
s = raw_input()
i_list = []
i = -1
while True:
    i = s.find("AC", i+1)
    if(i == -1): break
    i_list.append(i)
for i in range(q):
    a, b = map(int, raw_input().split())
    a = bisect.bisect_left(i_list, a-1)
    b = bisect.bisect_left(i_list, b-1)
    print(b-a)
    


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

using namespace std;

int main(void){
  int N, M;
  cin >> N >> M;
  int a[M], b[M];
  int perm[N];
  int i, j;
  for(i=1; i<=M; i++)
    cin >> a[i] >> b[i];

  //順列を生成するための配列
  for(i=1; i<=N; i++)
    perm[i] = i;

  //グラフ宣言．N*Nの隣接行列で表現する
  //要素がない場所は-1にしておく
  vector<vector<int>> graph(N+1, vector<int>(N+1, -1));

  //グラフの生成
  for(i=1; i<=M; i++){
    graph[a[i]][b[i]] = b[i];
    graph[b[i]][a[i]] = a[i];
  }

 
 int ans = 0;
 do{
   //順列に沿って道があるかをみていく
   for(i=1; i<=N-1; i++){
     //道がない(初期化-1のままである)ならば次の順列へ
     if(graph[ perm[i] ][ perm[i+1] ] == -1)
     break;
   }

   //上の探索において順列に沿って最後まで辿れたとき
   if(i == N)
     ans++;
 }while(next_permutation(perm+2, perm+N+1));
 
 cout << ans << endl;
 
  return 0;
}


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

vector<vector<int>> grid_bfs(vector<string> &s, char start, const string &wall = "#") {
  const int vx[] = {0, 1, 0, -1}, vy[] = {1, 0, -1, 0};
  vector< vector< int > > min_cost(s.size(), vector< int >(s[0].size(), -1));
  queue< pair< int, int > > que;
  for(int i = 0; i < s.size(); i++) {
    for(int j = 0; j < s[i].size(); j++) {
      if(s[i][j] == start) {
        que.emplace(i, j);
        min_cost[i][j] = 0;
      }
    }
  }
  while(!que.empty()) {
    auto p = que.front();
    que.pop();
    for(int i = 0; i < 4; i++) {
      int ny = p.first + vy[i], nx = p.second + vx[i];
      if(nx < 0 || ny < 0 || nx >= s[0].size() || ny >= s.size()) continue;
      if(min_cost[ny][nx] != -1) continue;
      if(wall.find(s[ny][nx]) != string::npos) continue;
      min_cost[ny][nx] = min_cost[p.first][p.second] + 1;
      que.emplace(ny, nx);
    }
  }
  return min_cost;
}

int main() {
    int h, w, wall = 0;
    cin >> h >> w;
    vector<string> v(h);
    vector<vector<int>> dist;
    for(int i = 0; i < h; ++i) cin >> v[i];
    for(int i = 0; i < h; ++i) {
        for(int j = 0; j < w; ++j) if(v[i][j] == '#') wall++;
    }
    v[0][0] = 's';
    dist = grid_bfs(v, 's');
    if(dist[h-1][w-1] == -1) cout << -1 << '\n';
    else cout << (h*w - wall - dist[h-1][w-1] - 1) << '\n';

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define maxn 2010
#define INF 0x7fffffff
template <typename T>inline T read()
{
    register T sum=0;
    register char cc=getchar();
    int sym=1;
    while(cc!='-'&&(cc>'9'||cc<'0'))cc=getchar();
    if(cc=='-')sym=-1,cc=getchar();
    sum=sum*10+cc-'0';
    cc=getchar();
    while(cc>='0'&&cc<='9')sum=sum*10+cc-'0',cc=getchar();
    return sym*sum;
}
template <typename T>inline T read(T &a)
{
    a=read<T>();
    return a;
}
template <typename T,typename... Others> inline void read(T& a, Others&... b)
{
    a=read(a);
	read(b...);
}
struct Edge
{
	int v;
	Edge *next;
	Edge(int a=0,Edge *b=NULL)
	{
		v=a;
		next=b;
	}
}*head[maxn];
int n,ans=INF,a[maxn],f[maxn],g[maxn];
char str[maxn];
void dfs(int k,int fa)
{
	f[k]=a[k];
	g[k]=0;
	for(Edge *i=head[k];i!=NULL;i=i->next)
		if(i->v!=fa)
		{
			dfs(i->v,k);
			f[k]+=f[i->v];
			g[k]+=g[i->v]+f[i->v];
		}
}
int dp(int k,int fa)
{
	int mx=0;
	for(Edge *i=head[k];i!=NULL;i=i->next)
		if(i->v!=fa)
			if(g[i->v]>=g[mx])
				mx=i->v;
	if(!mx)return 0;
	int t=dp(mx,k)+f[mx],o=g[k]-g[mx]-f[mx];
	if(o>=t)
		return g[k]&1;
	return t-o;
}
int main()
{
	read(n);
	scanf("%s",str+1);
	for(int i=1;i<=n;i++)
		a[i]=str[i]-'0';
	for(int i=1;i<n;i++)
	{
		int x,y;
		read(x,y);
		head[x]=new Edge(y,head[x]);
		head[y]=new Edge(x,head[y]);
	}
	for(int i=1;i<=n;i++)
	{
		dfs(i,0);
		if(dp(i,0)==0)
			ans=min(ans,g[i]>>1);
	}
	if(ans!=INF)printf("%d\n",ans);
	else puts("-1");
    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
 
int main(void) {
 
	// ?????????????????\???
	int input;
	scanf("%d", &input);

	// ??????????????°
	int num = 1;
	
	// ????????????(??\?????????????????¨?????????)
	while(input != 0) {

		printf("Case %d: %d\n", num, input);
		
		num++;
		
		scanf("%d", &input);
	}
	return 0;
}

Measured memory_bytes: 1796
use std::io::*;
use std::str::FromStr;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::HashSet;
use std::cmp;
use std::f64::consts;

fn main() {
    let n: i64 = read();
    let mut vec: Vec<i64> = (0..n).map(|_| read()).collect();
    let mut sorted_vec: Vec<i64> = vec.clone();
    sorted_vec.sort();

    let middle_index = (n / 2 - 1) as usize;
    let middle: i64 = sorted_vec[middle_index];

    for &i in vec.iter() {
        let mut ans_index = 0;
        if i <= middle {
            ans_index = middle_index + 1;
        } else {
            ans_index = middle_index;
        }
        println!("{}", sorted_vec[ans_index]);
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// 最大公約数
fn gcd(a: i32, b: i32) -> i32 {
    match b {
        0 => a,
        _ => gcd(b, a % b)
    }
}

// 最小公倍数
fn lcm(a: i32, b: i32) -> i32 {
    a * b / gcd(a, b)
}

// 階乗
fn kaijou(n: i32)->i32 {
    if n == 1 {
        return n;
    }
    return n * kaijou(n-1);
}

Measured memory_bytes: 10364
H,W=map(int,input().split())

MAP=[["." for i in range (W)]for i in range(H)]
LIST=[0]*(10**6+100)

l=0
r=0
for i in range(H):
    A=list(input())
    for j in range(W):
        if(A[j]=="#"):
            MAP[i][j]="#"
            LIST[r]=(i,j,0)
            r+=1

while(True):
    T=LIST[l]
    i=T[0]
    j=T[1]
    if(i>0):
        if(MAP[i-1][j]=="."):
            MAP[i-1][j]="#"
            LIST[r]=(i-1,j,T[2]+1)
            r+=1  
    if(i+1<H):
        if(MAP[i+1][j]=="."):
            MAP[i+1][j]="#"
            LIST[r]=(i+1,j,T[2]+1)
            r+=1  
    if(j>0):
        if(MAP[i][j-1]=="."):
            MAP[i][j-1]="#"
            LIST[r]=(i,j-1,T[2]+1)
            r+=1  
    if(j+1<W):
        if(MAP[i][j+1]=="."):
            MAP[i][j+1]="#"
            LIST[r]=(i,j+1,T[2]+1)
            r+=1
    l+=1
    if(r<=l):
        print(LIST[r-1][2])
        exit()  



Measured memory_bytes: 164828
#B - Popular Vote
N,M= map(int, input().split())
A =list(map(int, input().split()))
tmp = 0
for i in range(N):
    if A[i] >= (sum(A)/(4*M)):
        tmp += 1
    else:
        pass

if tmp >= M:
    print("Yes")
else:
    print("No")

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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
  }*/

signed main(){
  string s;
  cin >> s;
  int n = s.size();

  rep(i, 0, n){
    if(i%2 == 0){
      if(s[i] == 'L'){
        cout << "No" << endl;
        return 0;
      }
    }else{
      if(s[i] == 'R'){
        cout << "No" << endl;
        return 0;
      }
    }
  }

  cout << "Yes" << endl;

  return 0;
}


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

#define faster  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define sq(x)   (x)*(x)
#define PI      acos(-1.0)
#define all(x) x.begin(),x.end()
#define nl      '\n'

typedef long long int ll;
typedef unsigned long long int  llu;

int main()
{
    ll a,b,d,c=0;
    cin>>a>>b>>d;
    for(int i=a; i<=b; i++)
    {
        if(i%d==0)
            c++;
    }
    cout<<c<<nl;
    return 0;
}


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

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] d = new int[n];
		for(int i=0; i<n; i++){
			d[i] = sc.nextInt();
		}
		int m = sc.nextInt();
		int[] t = new int[m];
		for(int i=0; i<m; i++){
			t[i] = sc.nextInt();
		}
		sc.close();
		
		Arrays.sort(d);
		Arrays.sort(t);
		
		int pos = 0;
		for(int i=0; i<n; i++){
			if(t[pos] == d[i]){
				pos++;
			}
			if(pos==m){
				System.out.println("YES");
				return;
			}
		}
		System.out.println("NO");
	}
}

Measured memory_bytes: 92692
#include <bits/stdc++.h>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin>>n;
  vector<int> cnt(n+1);
  FOR(x,1,101)FOR(y,1,101)FOR(z,1,101) {
    int g = x*x + y*y + z*z + x*y + y*z + z*x;
    if (g <= n) ++cnt[g];
  }
  FOR(i,1,n+1) {
    cout<<cnt[i]<<"\n";
  }
  return 0;
}


Measured memory_bytes: 3596
#import<bits/stdc++.h>
using namespace std;
typedef struct{int x;int y;int c;}M;
M g[200000];
int a,b,i,j,l,n,w,c[100005],p[100005],v[100005];
queue<int>z;
int Q(M a,M b){return a.x<b.x;}
main()
{
for(scanf("%d",&n);l<n-1;l++)
{
scanf("%d%d%d",&g[l].x,&g[l].y,&g[l].c);g[l+n-1].x=g[l].y,g[l+n-1].y=g[l].x,g[l+n-1].c=g[l].c;
}
sort(g,g+n+n-2,Q);
for(;g[++i].x;)if(g[i].x>g[i-1].x)c[g[i].x]=i;c[n+1]=2*n-2;
for(z.push(1);z.size();z.pop())for(v[a=z.front()]=1,j=c[a];j<c[a+1];j++)
if(v[g[j].y]<1)z.push(g[j].y),p[g[j].y]=g[j].c%2?!p[a]:p[a];
for(i=0;i++<n;)printf("%d\n",p[i]);
}

Measured memory_bytes: 3968
N, M = map(int, input().split())

class UF:
    def __init__(self, num):
        self.parent = [i for i in range(num + 1)]
        self.rank = [1] * (num + 1)

    def unite(self, x, y):
        xpar = self.find(x)
        ypar = self.find(y)
        if xpar == ypar:
            return
        if self.rank[xpar] == self.rank[ypar]:
            self.parent[ypar] = self.parent[xpar]
            self.rank[xpar] += 1
        elif self.rank[xpar] > self.rank[ypar]:
            self.parent[ypar] = self.parent[xpar]
        else:
            self.parent[xpar] = self.parent[ypar]

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            par = self.find(self.parent[x])
            self.parent[x] = par
            return par

groups = UF(N)

for i in range(M):
    a, b = map(int, input().split())
    groups.unite(a, b)

counts = {i:0 for i in range(N+1)}

for i in range(N+1):
    counts[groups.find(i)] += 1

print(max(counts.values()))

Measured memory_bytes: 39372
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,r;
    cin>>n>>r;
    if(n>=10){
        cout<< r<<endl;
    }else{
        cout<< r+(100*(10-n))<<endl;
    }
    return 0;


}



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

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

    int n, k, x, y;
    cin >> n;
    cin >> k;
    cin >> x;
    cin >> y;
    
    
    ll ans;
    if(n <= k){
        ans = n * x;
    }else{
        ans = k * x + (n-k) * y;
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import numpy as np
def cumsum(x):
    return list(np.cumsum(x))

def cumsum_number(N,K,x):
    ans=[0]*(N-K+1)
    number_cumsum = cumsum(x)
    number_cumsum.insert(0,0)
    for i in range(N-K+1):
        ans[i]=number_cumsum[i+K]-number_cumsum[i]
    return ans
"""
int #整数
float #小数

#for
for name in fruits: #fruitの頭から操作
    print(name)

#リスト
list0 = [] #リスト生成
list0 = [1,2,3,4] #初期化
list0 = [0]*10 #[0,0,0,0,0,0,0,0,0,0]
list1= [i for i in range(10)] #>>> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
list1 = list(map(int, input().split()))　# 複数の入力をリストに入れる
number=[int(input()) for i in range(int(input()))] #複数行の入力をリストに
list1 = list1 + [6, 7, 8] #リストの追加
list2.append(34) #リストの追加　最後に（）内が足される
list.insert(3,10) #リストの追加　任意の位置（追加したい位置,追加したい値）
len(list4) #リストの要素数
max(sa) #list saの最小値
list5.count(2) #リスト(文字列も可）内の2の数
list1.sort() #並び替え小さい順
list1.sort(reverse=True)  #並び替え大きい順
set(list1) #list1内の重複している要素を削除し、小さい順に並べる
sum([2,3,   ,3]) #リストの合計

abs(a) #aの絶対値
max(a,b) min(a,b) #最大値　最小値
text1 = text1.replace("34","test") #text1内の"34"を"test"に書き換える(文字列内の文字を入れ替える)

exit(0) #強制終了

cumsum(リスト) #累積和をリストで返す
cumsum_number(N,K,x) #N個の数が含まれるリストx内のK個からなる部分和をリストで返す
"""
X=int(input())
for i in range(1,1001):
    for j in range(1,1001):
        if (360*i)%(X*j)==0:
            ans=360*i//X
            print(ans)
            exit(0)


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

#define FOR(i,a,b)  for(ll (i)=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll (i)=a;(i)>=(b);--(i))
#define REP(i,n)    FOR(i,0,n)
#define RREP(i,n)   RFOR(i,n,0)
#define ALL(v)      (v).begin(),(v).end()
#define BIT(n)      (1LL<<(n))
#define IN(x,l,r)   ((l)<=(x)&&(x)<=(r))
#define LEN(s)      (string(s)).length()
#define NPOS        string::npos
#define SHOW(x)     cout<<#x<<" = "<<x<<endl
#define SORT(v)     sort(ALL(v))
#define SZ(v)       (ll)(v).size()
#define UNIQ(v)     SORT(v);(v).erase(unique(ALL(v)),(v).end())
#define PERM(v)     for(bool p=1;p;p=next_permutation(ALL(v)))
#define PQ(T)       priority_queue<T,vector<T>,greater<T>>

template<class T>string join(const vector<T>& v,string d=" ")
{stringstream s;REP(i,SZ(v))s<<d<<v[i];return s.str().substr(LEN(d));}

template<class T>ostream& operator<<(ostream& s,const vector<T>& v)
{s<<"{";if(SZ(v))s<<join(v,", ");s<<"}";return s;}

template<class T>bool contain(const string& s,const T& v)
{return s.find(v)!=NPOS;}

template<class T,class U>string& replace(string& s,const T& f,const U& t)
{for(auto p=s.find(f);p!=NPOS;p=s.find(f,p+LEN(t)))s.replace(p,LEN(f),t);}

const ll INF = 1e15;
const ll MOD = 1e9+7;
const double EPS = 1e-10;

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

int main() {
    ll num5 = 0, num7 = 0;
    REP(i, 3)  {
        ll x; cin >> x;
        if (x == 5) num5++;
        if (x == 7) num7++;
    }
    
    if (num5 == 2 and num7 == 1) cout << "YES" << endl;
    else cout << "NO" << endl;
    
    return 0;
}

Measured memory_bytes: 256
/*******************************************************
	  File name : applePie.cpp
	Author name : Omkar
	       Date : Sat Mar 21 16:08:09 IST 2020
********************************************************/

#include <iostream>
using namespace std ;

int main ( )
{
    long int A,P;
    cin>> A >> P;
    cout << (A*3+P)/2;
	return 0;
}


Measured memory_bytes: 256
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Abdulhamid Han
//Bismillahirrahmanirrahim
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long int lo;
typedef pair< int,int > PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;

int n,m,b[li],a[li],k,flag,t;
int cev;
string s;
vector<int> v;

int main(void){
	cin>>s;
	if(s[0]==s[1]){cout<<"Bad\n";return 0;}
	if(s[1]==s[2]){cout<<"Bad\n";return 0;}
	if(s[2]==s[3]){cout<<"Bad\n";return 0;}
	cout<<"Good\n";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){

	int n;
	int ans;

	while(1){
		ans = 0;
		cin >> n;
		if(n == 0) break;

		while(1){
			if(n == 1) break;

			if(n % 2 == 1){
				n = n * 3 + 1;
				ans++;
			}else if(n % 2 == 0){
				n = n / 2;
				ans++;
			}
		}

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

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

int main() {
    int A, B, C, D, E, F;
    int water = 0;
    int sugar = 0;
    double nodo = -1;
    cin >> A >> B >> C >> D >> E >> F;

    for(int a=0; a<101; a++){
        for(int b=0; b<101; b++){
            for(int c=0; c<101; c++){
                for(int d=0; d<101; d++){
                    if(a==0 && b==0 && c==0 && d==0){
                        continue;
                    }
                    if((A*a + B*b)*100 + C*c + D*d > F || C*c+D*d > (A*a + B*b)*E){
                        continue;
                    }
                    if((double)(C*c+D*d)/((A*a+B*b)*100+C*c+D*d) > nodo){
                        water = (A*a+B*b)*100;
                        sugar = (C*c+D*d);
                        nodo = (double)sugar/(water + sugar);
                    }
                }
            }
        }
    }

    cout << water+sugar << ' ' << sugar << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <assert.h>
#include <algorithm>

long long in[100002];
long long n, a, b;

bool valid(long long t) {
  long long need = 0;
  for (int i = 0; i < n; i++) {
    // printf("%d %d\n", i, (int)ceil(double(in[i] - b * t) / (a - b)));
    need += std::max((int)ceil(double(in[i] - b * t) / (a - b)), 0);
  }
  // printf("need %d\n", need);

  return need <= t;
}

int main() {
  scanf("%lld %lld %lld", &n, &a, &b);

  for (int i = 0; i < n; i++) {
    scanf("%lld", &in[i]);
  }

  long long ans = -1;
  long long left = 0, right = 1e9;
  while (left <= right) {
    long long mid = (left + right) >> 1;
    // printf("%d %d %d\n", left, right, mid);

    if (valid(mid)) {
      right = mid - 1;
      ans = mid;
    } else {
      left = mid + 1;
    }
  }
  assert(ans != -1);
  printf("%lld\n", ans);

  return 0;
}


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

#define MAX 100
void push(int);
int pop();
int isEmpty();
int isFull();

int top,S[MAX];


void push(int s){
  if(isFull() == 1){
    fprintf(stderr, "エラー\n");
    exit(8);
  }
  else S[++top]=s;
}

int pop(){
  if(isEmpty() == 0){
    fprintf(stderr, "エラー\n");
    exit(8);
  }
  else{
  top--;
  return S[top+1];
  }
}

int isFull(){
  if(top>=MAX-1)return 0;
  else return 0;
}

int isEmpty(){
  if(top==0)return 0;
  else return 1;
}


int main(){
  char s[100];
  int hozon;
  
  
  while( scanf("%s",s)!=EOF){

    if(s[0]=='+'){
      push(pop()+pop());
    }
    else if(s[0]=='-'){
      hozon=pop();
      push(pop()-hozon);
    }
    else if(s[0]=='*'){
      push(pop()*pop());
    }
    else push(atoi(s));
  }
  printf("%d\n",pop());
	

  return 0;
}




Measured memory_bytes: 2144
import sys
from itertools import accumulate

input = sys.stdin.readline


def main():
    N = int(input())
    A = list(map(int, input().split()))

    cumsum_A = list(accumulate(A))
    sum_A = sum(A)

    ans = float("inf")
    for i in range(N - 1):
        cost = abs((sum_A - cumsum_A[i]) - cumsum_A[i])
        if cost < ans:
            ans = cost

    print(ans)


if __name__ == "__main__":
    main()


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

int main(){
  int n, k, q, a;
  string ans;
  cin >> n >> k >> q;
  vector<int> point(n);
  
  for(int i = 0; i < q; i++) {
    cin >> a;
    point.at(a-1)++;
  }
  
  for(int i = 0; i < n; i++){
    ans = (q - point.at(i)) < k ? "Yes" : "No";
    cout << ans << endl;
  }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define ll long long
#define INF 999999999

const ll mod = 1e9+7;

int main(){
	int d, n;
	cin >> d >> n;
	if (n != 100){
		cout << n * pow(100, d) << endl;
	} else {
		if (d == 0){
			cout << 101 << endl;
		} else if (d == 1){
			cout << 10100 << endl;
		} else {cout << 1010000 << endl;}
	}
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <iostream>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <chrono>
#include <random>
#include <time.h>
#include <iomanip>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define mt make_tuple
#define tii tuple<int,int,int>
#define pq priority_queue<ll>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vecbl vector<bool>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
string stin(){string s;cin>>s;return s;}

ll func(int n,vector<pll> a){
    a.resize(n);
    vecll vl(n),vr(n);
    ll tmpR,tmpL;
    tmpL=-1;
    tmpR=1000000010;
    rep(i,n){
        tmpL=max(tmpL,a[i].first);
        tmpR=min(tmpR,-a[i].second);
        vl[i]=max(tmpR-tmpL+1,(ll)0);
    }
    
    tmpL=-1;
    tmpR=1000000010;
    rep3(i,n-1,0){
        tmpL=max(tmpL,a[i].first);
        tmpR=min(tmpR,-a[i].second);
        vr[i]=max(tmpR-tmpL+1,(ll)0);
    }
    ll ans=0;
    rep(i,n-1){
       // cout<<vl[i]<<" "<<vr[i+1]<<endl;
        ans=max(vl[i]+vr[i+1],ans);
    }
    return ans;
}
int main(){
    int n=in();
    vector<pll> a(n);
    rep(i,n){
        ll x=lin()-1,y=lin()-1;
        a[i]=mp(x,-y);
    }
    sort(ALL(a));
    ll ans=0;
    ans=func(n,a);
    int p=-1,q=-1;
    ll t=1000000010,s=-1;
    rep(i,n){
        if(-a[i].second<t){
            q=(int)i;
            t=-a[i].second;
        }
        if(a[i].first>s){
            p=(int)i;
            s=a[i].first;
        }
    }
   // cout<<p<<" "<<q<<endl;
    rep(i,n){
        if(i==p||i==q)continue;
        ans=max(max(-a[i].second-a[i].first+1,0ll)+max(-a[q].second-a[p].first+1,0ll),ans);
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 4992
<?php
//error_reporting(0);
$N = trim(fgets(STDIN));
//list($A,$B) = explode(" ",trim(fgets(STDIN)));
//$v = explode(" ",trim(fgets(STDIN)));

if ($N==1) {
  printf("Hello World\n");
  exit;
}
$A = trim(fgets(STDIN));
$B = trim(fgets(STDIN));
printf("%d\n",$A+$B);


Measured memory_bytes: 3828
import numpy as np

a, b, h, m = map(int, input().split())

h_th_1 = list(range(1, 61, 1))  # 後で半分
m_th = list(range(6, 361, 6))

if m != 0:
    th = ((h_th_1[m - 1] / 2) + 30 * (h) - m_th[m - 1])
    th = abs(min(th, 360 - th))
    # print((h_th_1[m - 1] / 2) + 30 * (h))
    # print(th, "theta")

else:
    th = abs(min(360 - (30 * h), (30 * h) - 360))

ans = np.sqrt(a ** 2 + b ** 2 - (2 * a * b) * np.cos(np.radians(th)))
print(ans)

Measured memory_bytes: 27216
from collections import deque
N,M=map(int,input().split())
tree=[[] for _ in range(N)]
colornum=[-1]*N
for i in range(M):
    x,y,z=map(int,input().split())
    tree[x-1].append(y-1)
    tree[y - 1].append(x - 1)
#print(tree)
for i in range(N):
    d=deque()
    if colornum[i]==-1:
        d.append(i)
        colorid = i
    else:
        colorid=colornum[i]
    while len(d)>0:
        v=d.popleft()
        colornum[v]=colorid
        for j in tree[v]:
            if colornum[j]==-1:
                d.append(j)
print(len(set(colornum)))

Measured memory_bytes: 73632
import Foundation

let input_line: String = readLine()!
let split: [String] = input_line.components(separatedBy: " ")

let n = Int(split[0])!
let m = Int(split[1])!

var maxs: [Int] = Array(repeating: 0, count: n)

var nArray: [Int] = []

let input_line2: String = readLine()!
let split2: [String] = input_line2.components(separatedBy: " ")
for i in 0..<n {
    nArray.append(Int(split2[i])!)
}

for _ in 0..<m {
    let input_line3: String = readLine()!
    let split3: [String] = input_line3.components(separatedBy: " ")
    let a = Int(split3[0])! - 1
    let b = Int(split3[1])! - 1
    maxs[a] = max(maxs[a], nArray[b])
    maxs[b] = max(maxs[b], nArray[a])
}

var ans = 0

var i = 0
for max in maxs {
    if max < nArray[i] {
        ans += 1
    }
    i += 1
}

print(ans)


Measured memory_bytes: 19280
#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    N, K = MI()

    counter = cl.Counter()

    for i in range(1, N + 1):
        amari = i % K
        counter.update({amari: 1})

    pairs = []

    for i in range(K):
        if (i * 2) % K == 0:
            pairs.append(i)

    ans = 0

    for pair in pairs:
        count = counter[pair]
        ans += count ** 3

    print(ans)


main()


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

int main() {
	int n;
	cin >> n;
	int x = n;
	cout << n << ":";
   	for(int i = 2; i<= sqrt(x)+1; i++) {
		while(n%i == 0) {
			cout << " " << i;
			n/=i;
		}
	}
	
	if(n != 1) {
		cout << " " << n;
	}
	cout << endl;
	
	return 0;
}	



Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
  
int main(void){
    int a, b, c;
    cin >> a >> b >> c;
    
    if(a+b>=c){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
}
    return 0;
}

Measured memory_bytes: 3548
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define INF 1e9

//precalculate vertices with indegree 0 and outdegree 0;
//our answer path starts from one of them
//dp[i] longest path from dp[i]--> dp[i] = 1 + dp[v],v is s.t. {i-v edges}
vector<int> adj[100000];
vector<int> ind;
vector<int> out;
vector<int> dp;
int v,e;
int top(int i){
	if(out[i]==0) return dp[i] = 0;
	if(dp[i]==-1){
		for(int j:adj[i]){
			dp[i] = max(dp[i],top(j)+1);
		}
	} 
	return dp[i];
}

int main(){
	cin>>v>>e;
	// adj = vector<vector<bool> >(v,vector<bool>(v,0));
	ind = vector<int>(v,0);
	out = vector<int>(v,0);
	dp = vector<int>(v,-1);
	for(int i=0;i<e;i++){
		int a,b;cin>>a>>b;
		adj[a-1].push_back(b-1);
		ind[b-1]++;
		out[a-1]++;
	}
	int ans=0;
	for(int i=0;i<v;i++){
		if(ind[i]==0){
			ans = max(ans,top(i));
		}
	}
	// for(int i=0;i<v;i++) cout<<dp[i]<<endl;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 14356
#include<bits/stdc++.h>
using namespace         std;
#define                 int long long
#define                 pb push_back
#define                 mp make_pair
#define st(arr,a)       memset(arr,a,sizeof arr)
#define                 nl cout<<endl
#define                 real signed
#define                 endl '\n'              
#define bitcount(x)     __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i,a,b)     for(int i=a;i<=b;i++)
#define rfor(i,a,b)     for(int i=a;i>=b;i--)
#define all(x)          x.begin() , x.end()
#define pi pair<int,int>
#define X first
#define Y second
#define N 314159
#define  vi vector<int>
#define  v  vector

int n;
int arr[N];
signed main() 
{
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 
    cin>>n;
    forn(i,1,n)cin>>arr[i];
    int ans1=0;
    while(1)
    {
        int ct = 0,pr=0;
        forn(i,1,n)
        {
            if(ct%2==0)
            {
                if(arr[i]+pr >= 0)ans1+=arr[i]+pr+1,pr=-1;
                else pr+=arr[i];
            }
            else 
            {
                if(arr[i]+pr <= 0)ans1+=1-(arr[i]+pr),pr=1;
                else pr+=arr[i];
            }
            //cout<<pr<<" ";
            ct++;
        }
        break;
    }
    
    int ct = 1,pr=0,ans=0;
        forn(i,1,n)
        {
            if(ct%2==0)
            {
                if(arr[i]+pr >= 0)ans+=arr[i]+pr+1,pr=-1;
                else pr+=arr[i];
            }
            else 
            {
                if(arr[i]+pr <= 0)ans+=1-(arr[i]+pr),pr=1;
                else pr+=arr[i];
            }
            ct++;
        }
        

    cout<<min(ans1,ans);


     return 0;

}

//       g++ -g c.cpp ; ./a.exe

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX = 200000;

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

	int maxv = -2000000000; // ???????°??????????????????????????¨????
	int minv = R[0];

	for ( int i = 1; i < n; ++i)
	{
		maxv = max(maxv, R[i] - minv); // ?????§????????´??°
		minv = min(minv, R[i]);        // ???????????§???????°?????????????????????????
	}

	cout << maxv << endl;

	return 0;
}

Measured memory_bytes: 3852
#include <stdio.h>

int main(void){
    int A,B,C,N;
    scanf("%d %d %d",&A ,&B ,&C);
    if(A*C<=B){
        printf("%d",C);
    }
    if(A*C>B){
        N=B/A;
        printf("%d",N);
    }
}


Measured memory_bytes: 128
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String x = sc.next();
    if(x.equals("A")){
      System.out.print("T");
    }else if(x.equals("T")){
      System.out.print("A");
    }else if(x.equals("C")){
      System.out.print("G");
    }else if(x.equals("G")){
      System.out.print("C");
    }
  }
}

Measured memory_bytes: 20820
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		int count_5=0,count_7=0;
		Scanner scan =new Scanner(System.in);
		
		for(int i=0;i<3;i++)
		{
			int num=scan.nextInt();
			if(num==5) count_5++;
			if(num==7) count_7++;
		}

		if(count_5==2 && count_7==1) System.out.println("YES");
		else System.out.println("NO");

	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define MODNum 1000000007
#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    int N, ans;
    cin >> N;
    REP(int,i,0,3){
        if ( N % 10 == 7 ){
            cout << "Yes" << endl;
            return 0;
        }
        N /= 10;
    }
    cout << "No" << endl;
    return 0;
}


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

int main(){
  int N;
  int t[110000],x[110000],y[110000];
  cin >> N;
  t[0] = x[0] = y[0] = 0;
  for (int i = 0; i < N; ++i) cin >> t[i+1] >> x[i+1] >> y[i+1];
  bool can = true;
  for(int i=0;i<N;i++){
    int dt = t[i+1] - t[i];
    int dist = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]);
    if (dt < dist) can = false;
    if (dist % 2 != dt % 2) can = false;  
  }
  if (can) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 1408
from sys import stdin

n = int(stdin.readline().rstrip())
t,a = [int(x) for x in stdin.readline().rstrip().split()]
li = list(map(int,stdin.readline().rstrip().split()))
lin = []

for i in li:
    lin.append(abs(a-(t-i*0.006)))

print(lin.index(min(lin))+1)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;
const int INF = 1001001001;
const ll MAXV = 1e18;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }

  ll ans = 1;
  rep(i, n) {
    if (MAXV / ans < a[i]) {
      cout << -1 << endl;
      return 0;
    }
    ans *= a[i];
  }

  cout << ans << endl;
}

Measured memory_bytes: 4060
// 2020-09-27 16:52:34
// clang-format off
#include <bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
#include <atcoder/convolution>
// #include <atcoder/dsu>
// #include <atcoder/fenwicktree>
// #include <atcoder/lazysegtree>
// #include <atcoder/math>
// #include <atcoder/maxflow>
// #include <atcoder/mincostflow>
#include <atcoder/modint>
// #include <atcoder/scc>
// #include <atcoder/segtree>
// #include <atcoder/string>
// #include <atcoder/twosat>
// #include <atcoder/all>
using namespace atcoder;

// clang-format on
using mint = modint998244353;
const int MX = 100010;
mint f[MX + 10], fi[MX + 10], df[MX + 10];
mint com(int n, int k) { return f[n] * fi[n - k] * fi[k]; }
void init() {
  f[0] = f[1] = fi[0] = fi[1] = df[0] = df[1] = 1;
  REP(i, 2, MX) {
    f[i] = f[i - 1] * i;
    fi[i] = f[i].inv();
    df[i] = df[i - 2] * i;
  }
}
void answer() {
  init();
  int n;
  cin >> n;
  deque<vector<mint> > freq;
  {
    map<int, int> mp;
    rep(i, 2 * n) {
      int h;
      cin >> h;
      mp[h]++;
    }
    for (auto [k, v] : mp) {
      freq.emplace_back(vector<mint>());
      freq.back().emplace_back(1);
      for (int i = 1; 2 * i <= v; i++) {
        freq.back().emplace_back(com(v, 2 * i) * df[2 * i - 1]);
      }
    }
  }
  while (freq.size() > 1) {
    deque<vector<mint> > p;
    swap(freq, p);
    while (p.size() > 1) {
      auto a = p.front();
      p.pop_front();
      auto b = p.front();
      p.pop_front();
      freq.emplace_back(convolution(a, b));
    }
    if (p.size() == 1) freq.emplace_back(p.back());
  }
  freq[0].resize(n + 1, 0);
  mint ans = 0;
  repc(i, n) {
    mint cur = 1;
    if (i < n) cur = df[2 * (n - i) - 1];
    cur *= freq[0][i];
    if (i % 2) cur = -cur;
    ans += cur;
  }
  cout << ans.val() << '\n';
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

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

int main(void){
  char b;
  cin >> b;
  if(b == 'A')
    cout << "T" << "\n";
  if(b == 'T')
    cout << "A" << "\n";
  if(b == 'C')
    cout << "G" << "\n";
  if(b == 'G')
    cout << "C" << "\n";
  return 0;
}


Measured memory_bytes: 3640
function Main(input) {
  var input = input.split(" ").map(val => parseInt(val, 10));
  var a = input[0];
  var b = input[1];

  var result = 0;

  for(var i=0;i< 2;i++){
    if( a > b) {
      result = result + a;
      a = a - 1;
    } else {
      result = result + b;
      b = b - 1;
    }
  }
console.log(result);

}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <queue>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

struct edge {
	int from,to;
	int cost;

	edge(int t,int c) : to(t),cost(c) {}
	edge(int f,int t,int c) : from(f),to(t),cost(c) {}

	bool operator<(const edge &e) const {
		return cost < e.cost;
	}
};

vector<edge> G[100005];
int d[100005], d2[100005], cnt[100005];

void dijkstra(int s) {
	priority_queue<P, vector<P>, greater<P> > que;
	rep(i, 100005) d[i] = INF;
	
	que.push(mp(0, s));
	d[s] = 0;

	while(que.size()) {
		P p = que.top(); que.pop();
		int cost = p.first;
		int v = p.second;

		if(d[v] < cost) continue;

		rep(i, G[v].size()) {
			edge e = G[v][i];
			if(d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(mp(d[e.to], e.to));
			}
		}
	}
}

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

	int s, t;
	cin >> s >> t;
	s--; t--;

	rep(i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;

		G[a].push_back(edge(b, 1));
		G[b].push_back(edge(a, 1));
	}

	dijkstra(s);
	rep(i, n) d2[i] = d[i];

	dijkstra(t);
	rep(i, n) swap(d[i], d2[i]);

	memset(cnt, 0, sizeof(cnt));
	rep(i, n) {
		if(d2[i] == INF) continue;
		cnt[d2[i]]++;
	}

	ll ans = 0;
	rep(i, n) {
		if(d[i] == INF || d2[i] == INF) continue;
		int x = d[t] - 2 - d[i];

		if(x >= 0) {
			ans += cnt[x];
		}
	}

	cout << ans << endl;

	return 0;
}

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

long long INF = 1e18;

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

    tmp = a;
    a = b;
    b = tmp;

    tmp = a;
    a = c;
    c = tmp;
    cout << a << " " << b << " " << c << endl;

    return 0;
}


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

int main() {
  int w, h;
  string line;
  string result;
  
  cin >> h >> w;

  for(int i = 0; i < h; i++) {
    cin >> line;
    result += line + "\n";
    result += line + "\n";
  }
  cout << result;
  return 0;
}


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

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  vector<int> ans;
  for (int i = 1; i <= min(a, b); i++) {
    if (a % i == 0 && b % i == 0) {
      ans.emplace_back(i);
    }
  }
  reverse(ans.begin(), ans.end());
  cout << ans[k - 1] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <map> // pair
using namespace std;
int main(){
  int A,B,C;
  cin>>A>>B>>C;
  string ans = "No";
  if(A!=B&&B==C){
    ans ="Yes";
  }else if(A!=B&&A==C){
    ans ="Yes";
  }else if(C!=A&&A==B){
    ans ="Yes";
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

int main() {
    int k, t;
    cin >> k >> t;
    vi a(t);
    int sum = 0;
    for (int i = 0; i < t; ++i) {
        cin >> a[i];
        sum += a[i];
    }
    int ret = 0;
    for (int i = 0; i < t; ++i) {
        ret += max(0, a[i] - 1 - (sum - a[i]));
    }
    cout << ret << "\n";

    return 0;
}

Measured memory_bytes: 256
// D.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;

bool compare_by_b(pair<int, int>a, pair<int, int>b) {
    if (a.second != b.second) {
        return a.second < b.second;
    }
    else {
        return a.first < b.first;
    }
}

int main()
{
    int n;

    cin >> n;

    pair<int, int>p;

    vector<pair<int, int>>v;

    for (int i = 0; i < n; i++) {
        cin >> p.first >> p.second;

        v.push_back(p);
    }

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

    long long time = 0;
    bool ok = true;
    for (int i = 0; i < n; i++) {
        time += v[i].first;
        if (time > v[i].second) {
            ok = false;
            break;
        }
    }

    if (ok) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;



}



Measured memory_bytes: 5236
#include "bits/stdc++.h"
#define double long double
#define int long long
#define mii map<int,int>
#define pii pair<int,int>
#define low lower_bound
#define upp upper_bound
#define mod 1000000007 //10^9+7
#define inf 10000000000000000 //10^16
#define rep(i,n) for(int i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define vsort(vec) sort(all(vec))
#define vrever(vec) reverse(all(vec));
#define vunsort(vec) vsort(vec); vrever(vec);
#define bisea binary_search
#define cend cout<<endl;
#define F first
#define S second
using namespace std;
signed main() {
	int x,y;
	cin>>x>>y;
	int a=y/x;
	int cnt=1;
	while(a!=1) {
		a/=2;
		cnt++;
	}
	cout<<cnt<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P,P> PP;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(2e5 + 5);
const double EPS = 1e-10;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()


int main() {
    int n;
    while(cin >> n, n){
        int m, cnt = 0, len = 0;
        string s;
        cin >> m >> s;
        s.push_back('#');
        REP(i,m+1){
            if(len%2==0 && s[i]=='I'){
                len++;
            }
            else if(len%2==1 && s[i]=='O'){
                len++;
            }
            else if(len > 0){
                cnt += max(0, (len-1)/2 - n + 1);
                len = 0;
                if(s[i]=='I')len++;
            }
        }
        cout << cnt << endl;
    }
    return 0;
}



Measured memory_bytes: 3912
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

ll func(int n) {
  ll ret = 1;
  for (int i = 2; i <= n; i++) {
    ret *= i;
  }
  return ret;
}

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> town(n);
  for (int i = 0; i < n; i++) {
    cin >> town[i].first >> town[i].second;
  }
  sort(all(town));
  double ans = 0;
  do {
    double dist = 0;
    for (int i = 1; i < n; i++) {
      dist += sqrt(pow((town[i].first - town[i - 1].first), 2) +
                   pow((town[i].second - town[i - 1].second), 2));
    }
    ans += dist;
  } while (next_permutation(all(town)));
  cout << fixed << setprecision(10) << ans / func(n) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

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

int main(){
  int i,j,k=0;
  int N,K;
  scanf("%d %d",&N,&K);
  int A[N];
  int tmp;
  for(i=0;i<N;i++)
    A[i]=0;
  
  for(i=0;i<N;i++){
    scanf("%d ",&tmp);
    A[tmp-1]++;
  }
  
  qsort(A, sizeof(A) / sizeof(int), sizeof(int), asc);
  
  for(i=0;i<N-K;i++)
    k+=A[i];
  
  printf("%d\n",k);
  return 0;
}

Measured memory_bytes: 1788