akhauriyash/Code-Regression huggingface dataset:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    S = ST()
    for i,s in enumerate(S,start = 1):
        if i&1:
            if s == "L":
                print("No")
                exit()
        else:
            if s == "R":
                print("No")
                exit()
    print("Yes")
if __name__ == '__main__':
    main()

Measured memory_bytes: 3700
#include <stdio.h>
#include <string.h>

int main()
{
  int N;
  int a[100000];
  
  scanf("%d\n", &N);
  for(int i=0; i<N; i++)
    scanf("%d ", &a[i]);
  
  int res = 0;
  for(int i=0; i<N; i++)
    res += a[i]-1;
  
  printf("%d\n", res);
  
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
  int c[26] = {};
  char s[4 + 1];
  scanf("%4s", s);
  for (int i = 0; i < 4; i++) {
    c[s[i] - 'A']++;
  }
  char *ans = "Yes";
  for (int i = 0; i < 26; i++) {
    if (c[i] != 0 && c[i] != 2) {
      ans = "No";
    }
  }
  puts(ans);
}


Measured memory_bytes: 128
number = input().split(" ")
A = int(number[0])
B = int(number[1])
K = int(number[2])
if A >= K:
	print(str(A-K) + " " + str(B))
elif B >= K-A:
	print("0" + " " + str(A+B-K))
else:
	print("0" + " " + "0")

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

A = list(map(int, input().split()))
B = list(map(int, input().split()))

C = [0 for i in range(N)]

ans = 0
al_C = 0

for i in range(N):
    C[i] = A[i]-B[i]
    if C[i]<0:
        ans = ans+1
        al_C = al_C-C[i]
    
C.sort()
C.reverse()

if ans==0:
    print(0)
else:
    f = 1
    
    for i in range(N):
        if C[i]<=0:
            print(-1)
            break
        else:
            al_C = al_C-C[i]
            ans = ans +1
        
        if al_C<=0:
            print(ans)
            break
    else:
        print(-1)
            


Measured memory_bytes: 18356
#include <bits/stdc++.h>
#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 ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  cout << n/3 << endl;
  return 0;
}

Measured memory_bytes: 256
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = 11;
int n;
int a[maxn];

int read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  return true;
}

void solve() {
  int res = 1, tosub = 1;
  for (int i = 0; i < n; i++) {
    res *= 3;
    if (!(a[i] & 1)) {
      tosub *= 2;
    }
  }
  res -= tosub;
  printf("%d\n", res);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 256
def main():
    N, M = map(int, input().split())
    lr = [list(map(int, list(input().split()))) for i in range(M)]
    # N, M = 4, 2
    # lr = [[1, 1], [3, 4]]
    ll = []
    rl = []
    for line in lr:
        ll.append(line[0])
        rl.append(line[1])
    diff = min(rl) - max(ll)
    if diff < 0:
        print(0)
        return
    print(diff + 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 29100
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
 
        while(true){
            String line = input.readLine();
            String [] num = line.split(" ");
            int tate = Integer.parseInt(num[0]);
            int yoko = Integer.parseInt(num[1]);
 
            if(tate == 0 && yoko == 0) break;
 
            for(int i = 0 ; i < yoko ; i++){
                sb.append("#");
            }
            sb.append("\n");
            for(int j = 0 ; j < tate-2 ; j++){
                sb.append("#");
                for(int k = 0 ; k < yoko-2 ; k++){
                    sb.append(".");
                }
                sb.append("#\n");
            }
            for(int l = 0 ; l < yoko ; l++){
                sb.append("#");
            }
 
            sb.append("\n\n");
            }
        System.out.print(sb);
    }
 
}

Measured memory_bytes: 20724
#include <stdio.h>

#define MAX 100005
#define NIL -1

//pr = 節点の親,l = 節点の最も左の子,r = 節点のすぐ右隣の兄弟//
typedef struct {
  int pr,l,r;
}node;

node T[MAX];
int n,D[MAX];

void print(int u){
  int i,ch;
  printf("node %d: parent = %d, depth = %d, ",u,T[u].pr,D[u]);
  if(T[u].pr == NIL) printf("root, ");
  else if(T[u].l == NIL) printf("leaf, ");
  else printf("internal node, ");

  printf("[");
  for(i=0,ch = T[u].l;ch != NIL;i++,ch = T[ch].r){
    if(i) printf(", ");
    printf("%d",ch);
  }
  printf("]\n");
}

void getdepth(int u,int p){
  D[u] = p;
  if(T[u].r != NIL) getdepth(T[u].r,p);
  if(T[u].l != NIL) getdepth(T[u].l,p+1);
}

int main(){
  int i,j,deg,id,ch,l,r;
  scanf("%d",&n);
  for(i=0;i<n;i++) T[i].pr = T[i].l = T[i].r = NIL;

  for(i=0;i<n;i++){
    scanf("%d%d",&id,&deg);
    for(j=0;j<deg;j++){
      scanf("%d",&ch);
      if(j == 0) T[id].l = ch;
      else T[l].r = ch;
      l = ch;
      T[ch].pr = id;
    }
  }
  for(i=0;i<n;i++){
    if(T[i].pr == NIL) r = i;
  }

  getdepth(r,0);

  for(i=0;i<n;i++) print(i);

  return 0;
}
      



Measured memory_bytes: 6540
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define REPR(i,n) for(ll i=n-1;i>=0;i--)

typedef long long ll;
#define INF 1e18

int main(){
	string s;
	cin>>s;
	int old=-1;
	REP(i,3){
		if(old==s[i] || old==-1){
			old=s[i];
		}else{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include<vector>
#include <algorithm>
#include <cmath>
#include <limits>
#include <string.h>
using namespace std;

typedef long long ll;
typedef vector<int> VI;
#define rep(i,n) for(int i=0;i<(n);++i)

//example rep(i,n) cin >> h[i];

int main (){

int n,k,q;
 
  cin>>n;


// cout<<"Hellow worldy yes"<<endl;
 
  k=n*n;;
  
  cout<<k<<endl;

  //sort(vec.begin(),vec.end());
  //reverse(vec.begin(),vec.end());

  
 return 0; 
}


Measured memory_bytes: 256
// READ & UNDERSTAND
// ll, int overflow, array bounds
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN

#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

ll INF=LLONG_MAX;

int const mxn=1e5+5;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	string s;
	cin >> s;
	int n=s.length();
	int cnt=0;
	for(int i=0; i<n; i++){
		if(s[i]=='0')cnt--;
		else cnt++;
	}
	cout << n-abs(cnt) << endl;
}	


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int a[200000];
int n;
int main() {
    ios_base::sync_with_stdio(0);
    cin >> n;
    for (int i=1;i<=n;i++) cin >> a[i];
    int ans=0;
    for (int i=1;i<=n;i++)
        if (a[a[i]]==i) ans++;
    cout << ans/2 << "\n";
    return 0;
}


Measured memory_bytes: 640
import java.util.*;
public class Main{

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int V=sc.nextInt();
		int E=sc.nextInt();
		Set<Integer> fst=new HashSet<>();
		
		Set<Integer> lst=new HashSet<>();
		for (int i = 0; i <E; i++) {
			int u=sc.nextInt();
			int v=sc.nextInt();
			if(u==1)
				fst.add(v);
			if(v==V)
				lst.add(u);				
		}
		for (Integer i : fst) {
			if(lst.contains(i))
			{
				System.out.println("POSSIBLE");
				return;
			}
		}
		System.out.println("IMPOSSIBLE");
	}

}


Measured memory_bytes: 109832
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
#define pb(n,m) n.push_back(m)
#define fix(n) cout<<fixed<<setprecision(n);
using namespace std;
//using bint=boost::multiprecision::cpp_int;
typedef long long ll;
typedef unsigned long long ull;

int main(){
  int n,m; cin>>n>>m;
  vector<int> a(n);
  rep(i,0,n) cin>>a[i];
  sort(all(a));
  int c=0;
  rep(i,0,m) c+=a[i];
  co(c);
  return 0;
}

Measured memory_bytes: 3632
#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 ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define mp make_pair
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using ll = long long;
using namespace std;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

string S;
map<char,ll> name;
int N;
string def = "MARCH";

int main(){
    cin >> N;
    rep(i,N){
        cin >> S;
        name[S[0]]++;
    } 
    ll ans = 0;
    rep(i,5) rep(j,5) rep(k,5) if(i < j && j < k) ans += name[def[i]]*name[def[j]]*name[def[k]];
    cout << ans << '\n';
}

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

vector<pair<ll, int>> prime_factorization(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 main() {
	ll a, b;
	cin >> a >> b;
	auto p = prime_factorization(a);
	auto q = prime_factorization(b);
	ll ans = 1;
	set<ll> s;
	for(auto t: p) {
		s.insert(t.first);
	}
	for(auto t: q) {
		if(s.count(t.first)) {
			ans++;
		}
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main(){
	
	int a, b, n;
	int ab, ab2;
	int c;
	
	while (scanf("%d %d %d", &a, &b, &n) != EOF){
		c = ab = ab2 = 0;
		
		if (a / b != 0){
			a %= b;
		}
		
		for (int i = 0; i < n; i++){
			if (a / b == 0){
				a *= 10;
			}
			ab = a / b;
			ab2 = a % b;
			
			c += ab;
			a = ab2;
		}
		
		printf("%d\n", c);
	}
}

Measured memory_bytes: 1024
#include<algorithm>
#include<bitset>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<queue>
#include<set>
#include<string>
#include<time.h>
#include<tuple>
#include<utility>
#include<vector>

using namespace std;
const long mod = 1000000007;

int main() {
	 
	string S; cin >> S;
	long slen = S.length();

	long dp[14][100009] = {};

	if (S[0] == '?') for (int i = 0; i <= 9; i++) dp[i][0]++;
	else dp[(int)S[0] - (int)'0'][0]++;

	for (int i = 1; i < slen; i++) {
		if (S[i] != '?') for (int m = 0; m < 13; m++) {dp[((m * 10) + ((int)S[i] - (int)'0')) % 13][i] += dp[m][i - 1];
		dp[((m * 10) + ((int)S[i] - (int)'0')) % 13][i] %= mod;
        }else {
			for (int p = 0; p <= 9; p++) for (int m = 0; m < 13; m++) {dp[(m * 10 + p) % 13][i] += dp[m][i - 1];
                                                                       dp[(m * 10 + p) % 13][i] %= mod;
                                                                      }
		}
	}

	cout << dp[5][slen - 1] << endl;

}

Measured memory_bytes: 11392
a, b, c, x, y = map(int, input().split())
ans = []

for i in range(max(x+1, y+1)):
    tmp = c*i*2
    if i < x:
        tmp += a*(x-i)
    if i < y:
        tmp += b*(y-i)
    ans.append(tmp)

print(min(ans))

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

using namespace std;

vector<int> weights, values;
vector<vector<long long int>> dp(105, vector<long long int>(100005, -1));

//dp[n][w] = maximum sum of values when there are n items and capacity w
long long int solve(int n, int w)
{
    if(dp[n][w] != -1)
        return(dp[n][w]);
    if(n == 0)
        return(0);
    if(w - weights[n] < 0)
        return(dp[n][w] = solve(n-1, w));
    return(dp[n][w] = max(solve(n-1, w), values[n] + solve(n-1, w-weights[n])));
}

int main()
{
    int n, w, ele1, ele2;
    long long int ans;
    cin >> n >> w;
    weights.push_back(-1), values.push_back(-1);
    for(int i=0;i<n;i++)
    {
        cin >> ele1 >> ele2;
        weights.push_back(ele1), values.push_back(ele2);
    }
    ans = solve(n, w);
    cout << ans << endl;
    return(0);
}

Measured memory_bytes: 84592
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,N-1,0)
#define RREPS(i,n) RFOR(i,N,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#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;
}

struct UnionFind {
    public:
    vector<int> par;
    UnionFind(int n){
        par=vector<int>(n,-1);
    }
    int root(int x){
        if(par[x]<0)return x;
    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);
        par[x]+=par[y];
        par[y]=x;
        return true;
    }
    int size(int x){
        return -par[root(x)];
    }
};
const int INF=1e18;
const int MOD=1e9+7;
const int pi=acos(-1.0);
const int MAX_N=1e5;
vector<int>Graph[MAX_N];
vector<int>ans(MAX_N);
vector<bool>isvisit(MAX_N,false);

signed main(){
    int N,M;cin>>N>>M;
    UnionFind uf(N);
    map<int,int> next;
    
    REP(i,M){
        int  a,b;cin>>a>>b;a--;b--;
        uf.merge(a,b);
      	Graph[a].pb(b);
      	Graph[b].pb(a);
    }
    REP(i,N){
        if(!uf.issame(0,i)){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    vector<int> dist(N, -1); // 全頂点を「未訪問」に初期化
    queue<int> que;

    // 初期条件 (頂点 0 を初期ノードとする)
    dist[0] = 0;
    que.push(0); // 0 を橙色頂点にする

    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        int v = que.front(); // キューから先頭頂点を取り出す
        que.pop();
        for (int nv : Graph[v]) {
            if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない
            dist[nv] = dist[v] + 1;
            ans[nv]=v+1;
            que.push(nv);
        }
    }
    for(int i=1;i<N;i++)cout<<ans[i]<<endl;
}

Measured memory_bytes: 14616
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  int n,m,x,a,b;
  a=0;
  b=0;
  cin>>n>>m>>x;
  int p[m];
  rep(i,m){
    cin>>p[i];
    if(p[i]<x){
      a++;
    }else{
      b++;
    }
  }
  cout<<min(a,b)<<endl;
}


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

int main()
{
  int n, sum = 0;
  bool flag = true;
  cin >> n;
  vector<int> A(n);
  for (int i = 0; i < n; i++)
  {
    cin >> A.at(i);
  }

  while (flag)
  {
    for (int i = 0; i < n; i++)
    {
      if (A.at(i) % 2 == 1)
      {
        flag = false;
        break;
      }
      A.at(i) /= 2;
    }
    if (flag)
      sum++;
  }
  cout << sum << endl;
}


Measured memory_bytes: 3624
{-# LANGUAGE ScopedTypeVariables #-}
main :: IO ()
main = do
  s <- getLine
  let [a,b]::[Int] = map read $ words s
  if a > b
     then
       putStrLn "a > b"
       else
         if a < b
            then
              putStrLn "a < b"
            else
              putStrLn "a == b"

Measured memory_bytes: 3624
use std::collections::{HashMap, HashSet};

fn main() {
    let mut input = String::new();
    let _ = std::io::stdin().read_line(&mut input).unwrap();
    let mut input = input
        .trim()
        .split_whitespace()
        .map(|x| x.parse::<usize>().unwrap());

    let n = input.next().unwrap();
    let m = input.next().unwrap();

    let mut routes: HashMap<usize, HashMap<usize, usize>> = (0..n)
        .into_iter()
        .map(|node| (node, HashMap::new()))
        .collect();
    let mut unused_routes: HashSet<(usize, usize)> = HashSet::new();

    for _ in 0..m {
        let mut input = String::new();
        let _ = std::io::stdin().read_line(&mut input).unwrap();
        let mut input = input
            .trim()
            .split_whitespace()
            .map(|x| x.parse::<usize>().unwrap());
        let a = input.next().unwrap() - 1;
        let b = input.next().unwrap() - 1;
        let cost = input.next().unwrap();
        if let Some(x) = routes.get_mut(&a) {
            x.insert(b, cost);
        }
        if let Some(x) = routes.get_mut(&b) {
            x.insert(a, cost);
        }
        unused_routes.insert((a, b));
    }
    // println!("{:?}", routes);

    let mut graph: Vec<Vec<Option<usize>>> = (0..n)
        .into_iter()
        .map(|node| {
            (0..n)
                .into_iter()
                .map(|i| routes.get(&node).unwrap().get(&i).map(|x| *x))
                .collect()
        })
        .collect();
    // println!("{:?}", graph);

    let next = warshall_floyd(&mut graph);
    // println!("{:?}", graph);
    // println!("{:?}", next);

    for s in 0..n {
        for e in 0..n {
            if s != e {
                if let Some((_, route)) = shortest_path(&graph, &next, s, e) {
                    for items in route.windows(2) {
                        unused_routes.remove(&(items[0], items[1]));
                        unused_routes.remove(&(items[1], items[0]));
                    }
                }
            }
        }
    }
    println!("{}", unused_routes.len());
}

fn warshall_floyd(dist: &mut Vec<Vec<Option<usize>>>) -> Vec<Vec<usize>> {
    let n = dist.len();
    let mut next = vec![];

    for _ in 0..n {
        next.push((0..n).map(|j| j).collect::<Vec<usize>>());
    }

    for k in 0..n {
        for i in 0..n {
            for j in 0..n {
                if let (Some(dik), Some(dkj)) = (dist[i][k], dist[k][j]) {
                    if dist[i][j].is_none() || dist[i][j].unwrap() > dik + dkj {
                        dist[i][j] = Some(dik + dkj);
                        next[i][j] = next[i][k];
                    }
                }
            }
        }
    }
    next
}

fn shortest_path(
    dist: &Vec<Vec<Option<usize>>>,
    next: &Vec<Vec<usize>>,
    start: usize,
    goal: usize,
) -> Option<(usize, Vec<usize>)> {
    if dist[start][goal].is_none() {
        return None;
    }

    let mut path = vec![start];
    let mut node = start;
    while node != goal {
        path.push(next[node][goal]);
        node = next[node][goal];
    }
    Some((dist[start][goal].unwrap(), path))
}

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

struct Node {
  int val;
  Node* left;
  Node* right;

  Node(int v, Node* l, Node* r)
    : val(v), left(l), right(r) {}

  string toString() {
    string ns = to_string(this->val);
    string ls = (this->left != nullptr) ? this->left->toString() : "";
    string rs = (this->right != nullptr) ? this->right->toString() : "";
    return "(" + ls + ")[" + ns + "](" + rs + ")";
  }
};

Node* parseTree(string s) {
  if (s == "") return nullptr;

  // left = [1, leftIdx - 2]
  int depth = 1;
  int leftIdx = 1;
  while (depth) {
    if (s[leftIdx] == '(') ++depth;
    if (s[leftIdx] == ')') --depth;
    ++leftIdx;
  }
  string leftVal = s.substr(1, leftIdx - 2);

  // num = [leftIdx + 1, numIdx - 2]
  int numIdx = leftIdx + 1;
  while (s[numIdx] != '(') ++numIdx;
  int numVal = stoi(s.substr(leftIdx + 1, numIdx - leftIdx - 2));

  // right = [numIdx + 1, s.length() - 2]
  string rightVal = s.substr(numIdx + 1, s.length() - numIdx - 2);

  // s = "(<left>)[num](<right>)"
  auto left = parseTree(leftVal);
  auto right = parseTree(rightVal);
  return new Node(numVal, left, right);
}

Node* composeTree(Node* a, Node* b) {
  Node* left = nullptr;
  Node* right = nullptr;

  int sum = a->val + b->val;
  if (a->left != nullptr && b->left != nullptr) {
    left = composeTree(a->left, b->left);
  }
  if (a->right != nullptr && b->right != nullptr) {
    right = composeTree(a->right, b->right);
  }
  return new Node(sum, left, right);
}

int main() {
  string A; cin >> A;
  string B; cin >> B;
  auto TA = parseTree(A);
  auto TB = parseTree(B);
  cout << composeTree(TA, TB)->toString() << endl;
  return 0;
}



Measured memory_bytes: 3420
""" AtCoder """

H, W = map(int, input().split())

a = [input() for _ in range(H)]

ans = []
ans = []
ans_len = 0

for i in range(H):
    if a[i].count('#') != 0:
        ans.append(a[i])
        ans_len += 1

for t in range(W):
    for i in range(W):
        check = True
        for j in range(ans_len):
            if ans[j][i] == '#':
                check = False
                break
        if check:
            tmp = ans
            ans = []
            for j in range(ans_len):
                ans.append(tmp[j][:i] + tmp[j][i+1:])
            W -= 1
            break

for i in range(ans_len):
    print(ans[i])


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

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

#define end '\n'
#define fi first
#define se second
#define sz(x) (int)(x.size())
#define all(x) x.begin(), x.end()
#define rep(i,a,b) for(int i=a;i<=b;i++)

#define L(x) (x<<1)
#define R(x) ((x<<1)+1)

const int maxN = 200010;

int main() {
	//fast input/output c++
	ios_base::sync_with_stdio(0), cin.tie(NULL);

	string s;
	cin >> s;

	if(s[2] == s[3] and s[4] == s[5]) {
		cout << "Yes\n";
	} else {
		cout << "No\n";
	}
	
	return 0;
}


Measured memory_bytes: 256
n =int(input())
a = list(map(int,input().split()))

a.sort()

for i in range(0,n//2):
    if a[2*i] <= 0 and a[2*i+1] <=0:
        a[2*i] *= -1
        a[2*i+1] *= -1
    elif a[2*i] <= 0 and a[2*i+1] >=0:
        if abs(a[2*i]) > abs(a[2*i+1]):
            a[2*i] *= -1
            a[2*i+1] *= -1
    else:
        break
print(sum(a))

Measured memory_bytes: 14492
let S = Array(readLine()!)
if S[0] == "R" {
    if S[1] == "R" {
        print(S[2] == "R" ? 3 : 2)
    } else {
        print(1)
    }
} else {
    if S[1] == "R" {
        print(S[2] == "R" ? 2 : 1)
    } else {
        print(S[2] == "R" ? 1 : 0)
    }
}


Measured memory_bytes: 7804
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;
int n,k,v[2005][11],dp[2005][11],a,b,ret;vector<int>x[11];
int main(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&a,&b);
		x[b].push_back(a);
	}
	for(int i=1;i<=10;i++) { sort(x[i].begin(),x[i].end()); reverse(x[i].begin(),x[i].end());}
	for(int i=1;i<=10;i++){
		for(int j=0;j<x[i].size();j++){
			v[j+1][i]=v[j][i]+x[i][j];
		}
	}
	for(int i=0;i<=n;i++)for(int j=0;j<=10;j++) dp[i][j]=-1000000000;
	dp[0][0]=0;
	for(int i=1;i<=10;i++){
		for(int a=1;a<=n;a++) dp[a][i]=dp[a][i-1];
		for(int j=n;j>=1;j--){
			for(int k=1;k<=min(j,(int)x[i].size());k++){
				dp[j][i]=max(dp[j][i],dp[j-k][i-1]+v[k][i]+k*(k-1));
			}
		}
		ret=max(ret,dp[k][i]);
	}
	printf("%d\n",ret);
}

Measured memory_bytes: 1240
from sys import stdin
import math

n = int(stdin.readline().rstrip())
p_lst = [int(x) for x in stdin.readline().rstrip().split()]
count = 0

for i in range(1, n-1):
  ma = max(p_lst[i-1], p_lst[i], p_lst[i+1])
  mi = min(p_lst[i-1], p_lst[i], p_lst[i+1])
  if p_lst[i] != ma and p_lst[i] != mi:
    count += 1
    
print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;

int h,w,x;
char s[1000][1000];
bool visited [1000][1000];
pair<int,int> start,goal;
queue<pair<int,pair<int,int>>> q;
vector<pair<int,int>> ino;

int main(){
  int a,b,c,d;cin>>a>>b>>c>>d;
  //int a[3];cin>>a[0]>>a[1]>>a[2];sort(a,a+3);
  /*if(a[2]==a[1]+a[0]){
    cout<<"Yes";
  }else{
    cout<<"No";
  }*/
  cout << (1+a)*a/2;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main {
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int n = sc.nextInt();
    ArrayList<Integer> pList = new ArrayList<Integer>();
    for (int i=0; i<n; i++) {
      pList.add(sc.nextInt());
    }
    // Arrays.sort(pList);
    
    int number;
    for (int i=0; ; i++) {
      number = x - i;
      if (!pList.contains(number)) {
        System.out.println(number);
        return;
      }
      number = x + i;
      if (!pList.contains(number)) {
        System.out.println(number);
        return;
      }
    }
  }
}


Measured memory_bytes: 35872
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	int N,K,X,Y;
	public void solve() {
		N = nextInt();
		K = nextInt();
		X = nextInt();
		Y = nextInt();

		int ans = Math.min(N, K) * X;
		ans += Math.max(N - K, 0) * Y;
		out.println(ans);
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 8020
#include <iostream>
#include <bits/stdc++.h>
#define pb push_back
#define ob pop_back
#define xx first
#define yy second
#define dob double
#define int long long int
#define gcd __gcd
#define f(i,m,x) for(int i = 0 ; i , m ; i+= x);
#define ss size()
using namespace std;
const long long M = 998244353 , maxn = 2e5 + 10 ;

int ans , n , m , k , x , y , q , ma[maxn * 4];

pair < int , int > p[maxn];

void upd(int pos , int val , int id = 1 , int l = 0 , int r = maxn){
	if(r - l < 2){
		ma[id] = max(val , ma[id]);
		return ;
	}

	int mid = (l + r) >> 1;
	if(pos < mid)
		upd(pos , val , id * 2 , l , mid);
	else
		upd(pos , val , id * 2 + 1 , mid , r );
	ma[id] = max(ma[id * 2] , ma[id * 2 + 1]); 
}

int get(int s , int e , int id = 1 , int l = 0 , int r = maxn){
	if(s >= r || l >= e){
		return 0;
	}
	if(s <= l && r <= e){
		return ma[id];
	}

	int mid = (l + r) >> 1;
	return max(get(s , e , id * 2 , l , mid ) , get(s , e , id * 2 + 1 , mid , r ));
}

int32_t main(){

      ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);


      cin >> n ;

      for(int i = 0 ; i < n ; i ++){
      	cin >> p[i].xx;
      }

      for(int i = 0 ; i < n ; i ++){
      	cin >> p[i].yy;
      }

      for(int i = 0 ; i < n ; i ++ ){
      	ans = get( 0 , p[i].xx);
      	upd(p[i].xx , ans + p[i].yy);
      }

      ans = ma[1];

      cout << ans;

     	

	return 0;
}

Measured memory_bytes: 8448
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

int main(){
    int n,m;
    cin>>n>>m;
    
    vector<bool> v(n,false);
    v[0] = true;
    vector<int> num(n,1);
    rep(i,m){
        int a,b;
        cin>>a>>b;
        a--,b--;
        
        num[a]--, num[b]++;
        v[b] = v[b] | v[a];
        if(num[a]==0)v[a] = false;
    }
    
    int sum = 0;
    rep(i,n)if(v[i]==1)sum++;
    cout<<sum<<endl;
}

Measured memory_bytes: 640
import java.io.*;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(
			new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String S[] = br.readLine().split(" ");
		int q = Integer.parseInt(br.readLine());
		String T[] = br.readLine().split(" ");
		int count = 0;
		for (int i = 0; i < q; i++) {
			if (binarysarch(S, T[i]) != -1) count++;
		}
		System.out.println(count);
	}
	public static int binarysarch(String[] S, String x) {
		int lx = 0, rx = S.length - 1;
		while (lx <= rx) {
			int c = (lx + rx) / 2;
			if (Integer.parseInt(S[c]) == Integer.parseInt(x)) {
				return c;
			} else if (Integer.parseInt(S[c]) < Integer.parseInt(x)) {
				lx = c + 1;
			} else {
				rx = c - 1;
			}
		}
		return -1;
	}
}

Measured memory_bytes: 46652
#include <iostream>
#include <bits/stdc++.h>
#define pb push_back
#define ob pop_back
#define xx first
#define yy second
#define dob double
#define int long long int
#define ss size()
using namespace std;
const int M=1e9+7,maxn=1e5+10;
std::vector<int> adj[maxn];
std::vector<int> kids[maxn];
std::vector<int> hv[maxn];
int ans,n,k,m,x,y,q,par[maxn],h[maxn],a[maxn],b[maxn],c[maxn];
bool mark[maxn];

int dfs(int v){
    mark[v]=1;
    for(int i=0;i<adj[v].ss;i++)
        if(!mark[adj[v][i]]){
            par[adj[v][i]]=v;
            h[adj[v][i]]=(h[v]+1);
            hv[h[adj[v][i]]].pb(adj[v][i]);
            kids[v].pb(adj[v][i]);
            dfs(adj[v][i]);
        }
}
int32_t main(){
    cin>>n;
    for(int i=0;i<n-1;i++){
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    dfs(1);
    hv[0].pb(1);
    for(int i=1;i<=n;i++)
        k=max(k,h[i]);
    /*cout<<k;*/
    for(int i=0;i<hv[k].ss;i++){
        int u=hv[k][i];
        a[u]=1;
        b[u]=1;
        c[u]=2;
    }

    for(int i=k-1;i>-1;i--){
        for(int j=0;j<hv[i].ss;j++){
            int u=hv[i][j];
            a[u]=1;b[u]=1;
            for(int g=0;g<kids[u].ss;g++){
                int ug=kids[u][g];
                a[u]=(a[u]*b[ug])%M;
                b[u]=(b[u]*(a[ug]+b[ug])%M);
            }
            c[u]=(a[u]+b[u])%M;
        }
    }
    for(int i=1;i<=n;i++)
        cerr<<i<<" "<<"a="<<a[i]<<" "<<"b="<<b[i]<<" "<<"c="<<c[i]<<endl;;
    cout<<c[1]%M;
    return 0;
}


Measured memory_bytes: 25856
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
table = [0] * N
res = 1
mod = 10 ** 9 + 7
def no():
  print(0)
  exit(0)
for i in range(N):
  if a[i] >= N: no()
  table[a[i]] += 1
if table[0] != N % 2: no()
for i in range((N + 1) % 2, N, 2):
  if table[i] != 2:
    if i != 0: no()
  res *= table[i]
  res %= mod
print(res)

Measured memory_bytes: 52900
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

n, k = na()
h = [ni() for i in range(n)]
h.sort()
ans = min([h[i + k - 1] - h[i] for i in range(n - k + 1)])
print(ans)

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

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

    int a, b;
    map<int, int> d;

    while (cin >> a >> b) {
        if (a == 0 && b == 0) {
            bool OK = true;
            for (auto it=d.begin(); it!=d.end(); ++it) {
                if ((it->first == 1 && it->second % 2 == 0) ||
                    (it->first == 2 && it->second % 2 == 0) ||
                    (it->first >= 3 && it->second % 2 == 1)) {
                    OK = false;
                    break;
                }
            }
            cout << (OK ? "OK" : "NG") << endl;

            d.clear();
            continue;
        }
        d[a] ++;
        d[b] ++;
    }

    return 0;
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define ll long long
#define ld long double
#define pii pair <int,int>
#define pll pair <ll,ll>
#define pil pair <int,ll>
#define pli pair <ll,int>
#define ull unsigned long long
#define pdd pair <double,double>
#define pb push_back
#define mp make_pair
#define puu pair<ull,ull>
#define pvv pair<vector<int>, vector<int> >
#define _bp __builtin_popcount
#define ptt pair <Tree*,Tree*>
#define all(v) v.begin(),v.end()
#define en "\n"
//const long double pi = acos(-1);
void boos()
{
     ios_base :: sync_with_stdio(false);
     cin.tie(0);
     cout.tie(0);
}
void file()
{
   freopen("max.in","r",stdin);
   freopen("max.out","w",stdout);
}
const ll INF = 1e9 + 7;
const ll INF1 = 998244353;
const ll LLINF = (ll)1e18;
const ll INTmx = (int)1e9;
const ld EPS = (ld)1e-9;
const int N = 3e5 + 100;
int main()
{
    //file();
    boos();
    int a,b;
    cin >> a >> b;
    int ans = 0,tek = 1;
    while(tek < b)
    {
    	tek += a - 1;
    	ans++;
	}
	cout << ans;
}

Measured memory_bytes: 256
program bbb
implicit none
 
integer :: i, j
integer,dimension(1000000) :: a
 
read*, a(1)
  
do i=2,1000000
if(mod(a(i-1),2)==0) then
a(i)=a(i-1)/2
else
a(i)=3*a(i-1)+1
end if
 do j=1,i-1
 if(a(i)==a(j)) then
 write(*,'(i0)') i
 return
 end if
 end do
end do
 
end program

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

#define bigmod 1000000007

char peta[1010][1010];
int memo[1010][1010];

int main() {
	int h, w;
	scanf("%d %d\n", &h, &w);
	for (int i = 0; i < h; i++)
		scanf("%s\n", peta[i]);
	memset(memo, 0, sizeof memo);
	for (int i = 1; i <= h; i++)
		for (int j = 1; j <= w; j++) {
			if ((i == 1) && (j == 1))
				memo[i][j] = 1;
			else if (peta[i - 1][j - 1] == '.')
				memo[i][j] = (memo[i - 1][j] + memo[i][j - 1]) % bigmod;
			else
				memo[i][j] = 0;
		}
	printf("%d\n", memo[h][w]);
	return 0;
}

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

int main(){
  int64_t N;
  cin >> N;
  string alp="abcdefghijklmnopqrstuvwxyz";
  string ans="";
  
  std::string str[15];
  
  int64_t curN=N;
  int i=0;
  while(curN>0){
    int64_t syou = (curN-1)/26;
    int amari = (curN-1)%26;
    curN = syou;
    str[i] = alp.at(amari);
    i++;
  }
  for(int j=0;j<i;i--){
    ans+=str[i-1];
  }
  cout<<ans<<endl;
}

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

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

  ll x, k, d, ans;
  cin >> x >> k >> d;

  ll y=abs(x);

  if(y/d<k){
    ll z=min(y%d, abs(y%d-d));
    if(z==y%d){
      ans=abs(z-((k-y/d)%2)*d);
    }
    else{
      z=y%d-d;
      ans=abs(z+((k-x/d-1)%2)*d);
    }
  }
  else ans=abs(abs(x)-d*k);

  cout << ans << endl;

  return 0;
}

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

int const N = 3000, md = 1e9 + 7, i2 = md - md / 2;
int bd[N + 1][N + 1], gd[N + 1][N + 1], x[N + 1];

int main(){
	int i2 = md - md / 2;
	int n, q;
	scanf("%d%d", &n, &q);
	f(i, 1, n + 1)scanf("%d", x + i);
	f(i, 1, n + 1)f(j, i + 1, n + 1)bd[i][j] = x[i] > x[j];
	f(i, 1, n + 1)f(j, i + 1, n + 1)gd[i][j] = x[i] < x[j];
	f(i, 0, q){
		int a, b;
		scanf("%d%d", &a, &b);
		if (a > b)swap(a, b);
		f(i, 1, a)bd[i][a] = bd[i][b] = (ll)(bd[i][a] + bd[i][b]) * i2 % md;
		f(i, 1, a)gd[i][a] = gd[i][b] = (ll)(gd[i][a] + gd[i][b]) * i2 % md;
		f(i, a + 1, b){
			int ab = bd[a][i], ag = gd[a][i], bb = bd[i][b], bg = gd[i][b];
			bd[a][i] = (ll)(ab + bg) * i2 % md;
			gd[a][i] = (ll)(ag + bb) * i2 % md;
			bd[i][b] = (ll)(bb + ag) * i2 % md;
			gd[i][b] = (ll)(bg + ab) * i2 % md;
		}
		f(i, b + 1, n + 1)bd[a][i] = bd[b][i] = (ll)(bd[a][i] + bd[b][i]) * i2 % md;
		f(i, b + 1, n + 1)gd[a][i] = gd[b][i] = (ll)(gd[a][i] + gd[b][i]) * i2 % md;
		bd[a][b] = gd[a][b] = (ll)(bd[a][b] + gd[a][b]) * i2 % md;
	}
	int an = 0;
	f(i, 1, n + 1)f(j, i + 1, n + 1)if ((an += bd[i][j])>= md)an -= md;
	f(i, 0, q)if ((an <<= 1) >= md)an -= md;
	printf("%d\n", an);
}

Measured memory_bytes: 70144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define N 312345
char s[N];
int t[N];
set<int> x[3];
bool u[N]={};
int tb[3][2] = {
	{1, 2},
	{0, 2},
	{0, 1},
};
int z[N];
int cnt[8]={};

int main(){
	int n; scanf("%d%s", &n, s);
	REP(i, 3*n){
		if(s[i] == 'R'){
			t[i] = 0;
		} else if(s[i] == 'G'){
			t[i] = 1;
		} else {
			t[i] = 2;
		}
		x[t[i]].emplace(i);
	}
	REP(i, 3*n){
		if(u[i]) continue;
		int a = t[i];
		int b = tb[a][0], c = tb[a][1];
		if(*x[b].upper_bound(i) > *x[c].upper_bound(i)) swap(b, c);
		int j = *x[b].upper_bound(i), k = *x[c].upper_bound(j);
		z[i] = 0;
		z[j] = 1<<a;
		z[k] =(1<<a)|(1<<b);
		DEBUG("%d %d %d\n", i, j, k);
		u[i]=u[j]=u[k]=true;
		x[a].erase(x[a].find(i));
		x[b].erase(x[b].find(j));
		x[c].erase(x[c].find(k));
	}
	ll ans = 1;
	cnt[0]=n;
	REP(ii, 8) DEBUG("%d ", cnt[ii]); DEBUG("\n");
	REP(i, 3*n){
		int zz = z[i];
		ans=ans * cnt[zz] % 998244353LL;
		cnt[zz]--;
		zz |= 1<<t[i];
		cnt[zz]++;
		REP(ii, 8) DEBUG("%d ", cnt[ii]); DEBUG("\n");
	}
	printf("%lld\n", ans);
}





Measured memory_bytes: 17280
#include <stdio.h>
int main(void){
    // ((ΣN)² - ΣN²) / 2 を計算する
    int a, N;
    int i = 0, nSum = 0, squareSum = 0;
    scanf("%d", &N);
    while(i < N){
        scanf("%d", &a);
        nSum += a;
        squareSum += a * a;
        i++;
    }
    printf("%d\n", (nSum * nSum - squareSum) / 2);
}

Measured memory_bytes: 128
N = int(input())
S = input()

t = [S[0]]
p = S[0]
r = 1
for i in range(1, N):
  if S[i] == p:
    r += 1
    if r < 4:
      t.append(S[i])
  else:
    r = 1
    t.append(S[i])
T = ''.join(t)

result = 0
for i in range(10):
  a = T.find(str(i))
  if a == -1:
    continue
  for j in range(10):
    b = T.find(str(j), a + 1)
    if b == -1:
      continue
    for k in range(10):
      if T.find(str(k), b + 1) != -1:
        result += 1
print(result)

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

int cmp(int a, int b)
{
	return a > b;
}
int main()
{
	int n, k;
	cin >> n >> k;
	int a[100] = {0};
	for(int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n, cmp);
	int sum = 0;
	for(int i = 0; i < k; i++)
		sum += a[i];
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main{
  public static void main(String[]args){
    Scanner sc =  new Scanner(System.in);
    long N = Long.parseLong(sc.nextLine());
    long min = N;
    for(int i = 0; i < 5; i++){
      long n = Long.parseLong(sc.nextLine());
      if(n < min){
        min = n;
      }
    }
    
    long ans = 0;
    if(min == N){
      ans = 5;
    }else{
      ans = N/min + 4;
      if(N%min != 0){
        ans++;
      }
    }
    System.out.println(ans);
  }
}

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

typedef long long LL;
const LL mod=1000000007;
#define MAX 10000
#define NIL -1
const double PI  = acos(-1.0);
const int INF = 1e9 + 7;
//-------------------------------------------

int a[MAX][MAX];
LL dp[MAX];
LL sum1 = 0, sum2 = 0;

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    cin >> N;

    REP(i, 2){
        REP(j, N){
            cin >> a[i][j];
        }
    }


    memset(dp, 0, sizeof(dp));

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

        sum1 += a[0][i];

        sum2 = 0;
        for( int j = i; j < N; j++){
            sum2 += a[1][j];
        }
        dp[i] = sum1 + sum2;
        //dump(dp[i]);
    }

    LL maxi = 0;

    REP(i, N){

        if( N == 1) maxi = dp[0];

        else{
            maxi = max(dp[i], maxi);
        }
    }

    cout << maxi << endl;

    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>

int main()
{
  int N, i, j, x=0, minj;
  char A[36][2], C[36][2], a[2];

  scanf("%d",&N);
  for(j = 0 ; j < N ; j++){
    scanf("%s",A[j]);
  }

  for(j = 0 ; j < N ; j++){
    strcpy(C[j],A[j]);
  }
  
  for(i = 0 ; i < N-1 ; i++){
    for(j = N-1 ; j > i ; j--){
      if(A[j][1] < A[j-1][1]){
	a[0] = A[j][0];
	a[1] = A[j][1];
	A[j][0] = A[j-1][0];
	A[j][1] = A[j-1][1];
	A[j-1][0] = a[0];
	A[j-1][1] = a[1];
      }
    }
  }

  for(i = 0 ; i <= N-1 ; i++){
    for(j = 0 ; j < 2 ; j++){
      printf("%c",A[i][j]);
    }
    if(i < N-1){
    printf(" ");
    }
  }
  printf("\n");
  printf("Stable\n");
  
  for(i = 0 ; i < N-1 ; i++){
    minj = i;
    for(j = i ; j <= N-1 ; j++){
      if(C[j][1] < C[minj][1]){
	minj = j;
      }
    }
    a[0] = C[i][0];
    a[1] = C[i][1];
    C[i][0] = C[minj][0];
    C[i][1] = C[minj][1];
    C[minj][0] = a[0];
    C[minj][1] = a[1];
  }

  for(i = 0 ; i <= N-1 ; i++){
    for(j = 0 ; j < 2 ; j++){
      printf("%c",C[i][j]);
    }
    if(i < N-1){
    printf(" ");
    }
  }
  printf("\n");
  
  for(i = 0 ; i <= N-1 ; i++){
    for(j = 0 ; j < 2 ; j++){
      if(A[i][j] != C[i][j]){
	x = 1;
      }
    }
  }
  if(x == 0){
    printf("Stable\n");
  }
  else {
    printf("Not stable\n");
  }
 
  return 0;
}

Measured memory_bytes: 592
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-9;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	cin >> N;
	vector<int>x(N);
	vector<int>y(N);
	int xl = MOD, xr = -MOD, yl = MOD, yr = -MOD;
	for (int i = 0; i < N; i++) {
		cin >> x[i] >> y[i];
		x[i] <<= 1, y[i] <<= 1;
		x[i] += 400000000;
		y[i] += 100000000;
		int X, Y;
		tie(X, Y) = make_pair(x[i] + y[i], x[i] - y[i]);
		xl = min(xl, X);
		xr = max(xr, X);
		yl = min(yl, Y);
		yr = max(yr, Y);
		
	}
	int xmid = (xl + xr) / 2;
	int ymid = (yl + yr) / 2;
	int ans = MOD;
	int len = 100;
	for (int i = xmid - len; i <= xmid + len; i++) {
		for (int j = ymid - len; j <= ymid + len; j++) {
			if (abs(i - j) % 2)continue;
			int w = (i + j) / 2;
			int h = i - w;
			if (w % 20 && h % 20)continue;
			int box = 0;
			for (int k = 0; k < N; k++) {
				if ((w+1000000000) / 20 == (x[k]+1000000000) / 20) {
					if (h == y[k])box = max(box, abs(w - x[k]));
					else box = max(box, abs(h - y[k]) + min(40 - (w % 20 + x[k] % 20), (w % 20 + x[k] % 20)));
				}
				else if ((h+1000000000) / 20 == (y[k]+1000000000) / 20) {
					if (w == x[k])box = max(box, abs(h - y[k]));
					else box = max(box, abs(w - x[k]) + min(40 - (h % 20 + y[k] % 20), (h % 20 + y[k] % 20)));
				}
				else {
					box = max(box, abs(h - y[k]) + abs(w - x[k]));
				}
			}
			//cout << w << " " << h << " " << box << endl;
			ans = min(ans, box);
		}
	}
	cout << ans / 2;
	if (ans & 1)cout << "." << 5;
	cout << endl;
}


Measured memory_bytes: 3272
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <vector>
#include <map>

using namespace std;
typedef long long ll;



ll ans,mx,mn=1e8,sum,cnt;
int main(){
	ll n;
	cin>>n;
	map<string,ll> mp;
	for(int i=0; i<n; i++){
		string s;
		cin>>s;
		mp[s]++;
	}
	for(auto i : mp){
		ans = max(ans,i.second);
	}
	for(auto i:mp){
		if(i.second==ans) cout<<i.first<<endl;
	}
}

Measured memory_bytes: 25216