akhauriyash/Code-Regression huggingface dataset:
/*
* @author:  codancer
* @createTime:  2020-08-22, 20:14:59
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9+7;
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define fep(i,a,b) for(int i=(a);i>=(b);i--)
#define deb(x) cerr<<#x<<" = "<<(x)<<"\n"
typedef vector<int> VI;
typedef vector<ll> VII;
typedef pair<int,int> pii;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll Rand(ll B) {
	return (ull)rng() % B;
}
const int N = 1e6+100;
set<int> G[N];
vector<int> GG[N];
int id[1003][1003];
int n,m,sx,sy,ex,ey;
char maze[1003][1003];
bool vis[1003][1003],vv[N];
int cnt=0;
int dir[4][2]={{-1,0},{1,0},{0,1},{0,-1}};


bool check(int x,int y){
	return x>=1&&x<=n&&y>=1&&y<=m;
}
void dfs(int x,int y){
	id[x][y]=cnt;
	vis[x][y]=1;
	for(int i=0;i<4;i++){
		int dx=x+dir[i][0];
		int dy=y+dir[i][1];
		if(check(dx,dy)&&maze[dx][dy]=='.'&&!vis[dx][dy]) dfs(dx,dy);
	}
}


struct node{
	int id;
	int dis;
};
int d[N];
bool operator<(node a,node b){
	return a.dis>b.dis;
}
priority_queue<node> q;
void BFS(int s){
	for(int i=1;i<=cnt;i++) d[i]=1e9,vv[i]=0;
	d[s]=0;
	q.push({s,0});
	while(!q.empty()){
		auto it=q.top();q.pop();
		int u=it.id;
		int w=it.dis;
		if(vv[u]) continue;
		vv[u]=1;

		for(int v:GG[u]){
			if(d[v]>d[u]+1){
				d[v]=d[u]+1;
				q.push({v,d[v]});
			}
		}
	}
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m>>sx>>sy>>ex>>ey;
	rep(i,1,n){
		rep(j,1,m) cin>>maze[i][j];
	}
	rep(i,1,n){
		rep(j,1,m){
			if(!vis[i][j]&&maze[i][j]=='.'){
				++cnt;
				dfs(i,j);
			}
		}
	}

	rep(i,1,n){
		rep(j,1,m){
			rep(dx,-2,2){
				rep(dy,-2,2){
					int nx=i+dx;
					int ny=j+dy;
					if(!check(nx,ny)||maze[nx][ny]=='#') continue;
					int u=id[i][j];
					int v=id[nx][ny];
					if(u==v) continue;
					G[u].insert(v);
					G[v].insert(u);
				}
			}
		}
	}

	rep(i,1,cnt){
		for(int v:G[i]) GG[i].pb(v);
	}

	BFS(id[sx][sy]);

	int ends=id[ex][ey];

	cout<<(d[ends]==1e9?-1:d[ends])<<'\n';
	
	return 0;
}

Measured memory_bytes: 116428
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds;
using namespace std;

typedef long long int lli;
#define int lli
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<lli> vli;
typedef vector<pii> vii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> OrderedSet;

const int MOD	= 1e9 + 7;
const double PI = acos(-1.0);

#define fastio			ios_base::sync_with_stdio(0);cin.tie(0)
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(c) (c).begin(),(c).end()
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define endl "\n"
#define error(x) cerr << #x << " = " << (x) << endl
#define errorp(p) cerr << #p << " = " << (p.first) << ", " << (p.second) << endl

template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template <typename T> T lcm(T a, T b){return (a*b)/gcd(a,b); }

int N;
const int MAXN = 505;
int paths[MAXN][MAXN];
int val[MAXN][MAXN];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void dfs(int x, int y){
    int z = paths[x][y] + val[x][y];

    rep(i, 4){
        int nx = x + dx[i], ny = y + dy[i];
        if(paths[nx][ny] > z){
            paths[nx][ny] = z;
            dfs(nx, ny);
        }
    }
}


signed main(){
    #ifdef DEBUG
		freopen("test", "r", stdin);
	#endif
    fastio;
    
    cin >> N;
    int n2 = N * N;
    vi perm(n2);
    rep(i, n2){
        cin >> perm[i];
        perm[i]--;
    }

    repA(i, 1, N){
        repA(j, 1, N){
            paths[i][j] = min({i - 1, j - 1, N - i, N - j});
            val[i][j] = 1;
        }
    }
    int ans = 0;
    rep(i, n2){
        int x = (perm[i] / N) + 1;
        int y = (perm[i] % N) + 1;
        ans += paths[x][y];
        val[x][y] = 0;
        dfs(x, y);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 24416
#C - Welcome to AtCoder
N,M = map(int,input().split())
S_P_list = []
for _ in range(M):
    p,s = input().split()
    S_P_list.append((int(p),s))
#Pに着目して安定ソート
S_P_list = sorted(S_P_list,key = lambda x:x[0],reverse = False)    
#ACが存在するPの集合
AC_list = list(set([i[0] for i in S_P_list if i[1] == 'AC']))
WA = 0
AC = 0
for i in range(M):
    if (S_P_list[i][0] in AC_list):
        if S_P_list[i][1] == 'AC':
            AC += 1
            AC_list.remove(S_P_list[i][0])
        else:
            WA += 1
print(AC,WA)

Measured memory_bytes: 33012
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val s = sc.next()
    println(problem101a(s))
}

fun problem101a(s: String): Int {
    var ans = 0
    s.forEach { if (it == '+') ans++ else ans-- }
    return ans
}

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

int n,k;

typedef pair<int, int> P;


void solve()
{
	vector<bool> card(n+111);	// 111 is jork  @/w/@
	fill(card.begin(), card.end(), false);
	int ans = 0;

	int in;
	for(int i = 0; i < k; i++){
		cin >> in;
		card[in] = true;
	}

	int a = 0,b = 0;
	int i;
	for(i = 1; i <= n+1; i++){
		if(card[i]){
			a++;
		}
		else if(card[0]){
			a++;
			if(card[i+1]){
				int j = 1;
				while(card[i+j+1])j++;
				
				a += j;
				ans = max(ans, a);
				//cout << ans << endl;
				
			}
			else {
				ans = max(ans, a);
			}
			a = 0;

		}
		else {
			ans = max(ans, a);
			a = 0;
		}
	}

	cout << ans << endl;

}

int main(void)
{
	while(cin >> n >> k, n | k)
		solve();
	return 0;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,nn) for(int i=0;i<nn;i++)
#define MOD 1000000007
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}


int main(){
  ll n;
  cin >> n;
  ll a[100010],b[100010],c[100010];
  FOR(i,n){
    cin >> a[i];
  }
  FOR(i,n){
    cin >> b[i];
    c[i]=a[i]-b[i];
  }
  sort(c,c+n);
  ll sum=0,v=0;
    ll cnt=0;
  FOR(i,n){
    if(c[i]<0){
      sum-=c[i];
      cnt++;
    }else{
      v+=c[i];
    }
    
  }
  reverse(c,c+n);
  if(v<sum){
    cout << -1 << endl;
    return 0;
  }

  FOR(i,n){
    if(sum>0){
      cnt++;
    }else{
      break;
    }
    sum-=c[i];
    
  }
  cout << cnt << endl;
}

Measured memory_bytes: 2560
#include<stdio.h>
#include<string.h>
int main()
{
    char a[15],b[15],c[15];
    scanf("%s %s %s",a,b,c);
    if(a[strlen(a)-1]==b[0] && b[strlen(b)-1]==c[0])
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int N,M;
const long long fish=998244353;
const int MaxN=(1<<21)-1;
long long inv[MaxN+15],fac[MaxN+15];
long long Pow(int x,int y){
	long long b=x,ans=1;
	for (int qwq=y;qwq;qwq>>=1){
		if (qwq&1) ans=(ans*1ll*b)%fish;
		b=(b*b)%fish;
	}
	return ans;
}
void Init(){
	fac[0]=1;
	for (int i=1;i<=MaxN;i++)
		fac[i]=1ll*fac[i-1]*i%fish;
	inv[MaxN]=Pow(fac[MaxN],fish-2);
	for (int i=MaxN-1;i>=0;i--)
		inv[i]=1ll*inv[i+1]*(i+1)%fish;
	//cout<<inv[2]<<endl;
}
long long C(int n,int r){
	return fac[n]*1ll*inv[r]%fish*1ll*inv[n-r]%fish;
}
long long Get_ans(int n,int a,int b){
	b=min(b,n);
	long long ans=0;
	for (int i=a%2;i<=min(min(a,b),n);i+=2)
		ans+=1ll*C((a-i)/2+n-1,n-1)%fish*C(n,i)%fish;
		//cout<<ans<<endl;
		//cout<<n<<endl;
	return ans;
}
int main(){
	Init();
	scanf("%d%d",&N,&M);
	//cout<<C(3,2)<<endl;
	long long ans=Get_ans(N,3*M,M);
	//cout<<ans<<endl;
	ans-=(Get_ans(N,M,M)-Get_ans(N-1,M,M))*1ll*N%fish;
	cout<<(ans+fish)%fish;
	return 0;
}

Measured memory_bytes: 33152
/*
String[]の初期化、整数の型がlongになっているか
関数（splitとかcontainsとか）内では"+"とかは正規表現となされるので"\\+"とする
配列のコピーはarr1=arr.clone()
HashSet<>[]はおのおの初期化した？？？？？
負の数の割り算は絶対値が小さいほうに切り捨てられるex.-1/2=0ので、ある値>kみたいな式だとバグらせやすいので注意
ある値>=kとして、切り上げた値をとるべき
toLowerCase()はアルファベット以外に対して行ってもエラーにはならない
ArrayDequeではpopとpushはStackと同じ操作になる
//import static java.lang.System.*; はしばらく使わなそう(使うとしてもexit(0)のためだけ)←return;でよさそう
最後にout.flush()またはout.close()をするのを忘れずに！
Point2D p2d=new Point2D.Double(d1,d2);
*/
//入力終了→Ctrl+D
import java.util.*;
import java.io.*;
import java.awt.*;
import java.awt.geom.Point2D;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        long w=sc.nextLong(),h=sc.nextLong();
        long x=sc.nextLong(),y=sc.nextLong();
        int c=x==w/2&&y==h/2&&w%2==0&&h%2==0?1:0;
        out.println((double) h*w/2d+" "+c);
        out.close();
    }

    static long gcd(long a, long b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    //Union Find木(0-indexed)
    static class UF {
        static int[] d;

        static void Init(int size) {
            d = new int[size];
            for (int i = 0; i < size; i++) {
                d[i] = -1;
            }
        }

        static boolean unite(int x, int y) {
            x = find(x);
            y = find(y);
            if (x == y) return false;
            if (d[x] > d[y]) {
                int t = d[y];
                d[y] = d[x];
                d[x] = t;
            }
            d[x] += d[y];
            d[y] = x;
            return true;
        }

        static boolean same(int x, int y) {
            return find(x) == find(y);
        }

        static int find(int k) {
            return d[k] < 0 ? k : (d[k] = find(d[k]));
        }

        static int size(int k) {
            return -d[find(k)];
        }
    }

    static PrintWriter out = new PrintWriter(System.out);

    static class sc {
        static Scanner s = new Scanner(System.in);

        static String next() {
            return s.next();
        }

        static String nextLine() {
            return s.nextLine();
        }

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

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

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

        static boolean hasNext() {
            return s.hasNext();
        }

        static boolean hasNextInt() {
            return s.hasNextInt();
        }

    }

}

Measured memory_bytes: 21844
/// Code By t_bone_289 (Tushar Singh)
/// An Immature Programmer.... I'm still developing !!
#include<bits/stdc++.h>
using namespace std;
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define endl '\n'
#define M 1000000007
#define error(x) cout << #x << " = " << x << endl;
#define pi 3.14159265358979323846
typedef long long ll;
typedef double d;
typedef long double ld;
ll powmod(ll base,ll exp,ll MOD){ll res=1;while(exp>0){if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return (res%MOD);}
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s1;
    string s2;
    cin>>s1>>s2;
    ll n=s1.size();
    ll m=s2.size();
    vector<vector<ll> > dp(n+1,vector<ll>(m+1,0));
    vector<vector<ll> > dp2(n+1,vector<ll>(m+1,2));
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=m;j++)
        {
            if(s1[i-1]==s2[j-1])
            {
                dp[i][j]=dp[i-1][j-1]+1;
                dp2[i][j]=0;
            }
            else
            {
                if(dp[i-1][j]>dp[i][j-1])
                {
                    dp2[i][j]=1;
                }
                else
                {
                    dp2[i][j]=-1;
                }
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    string ans="";
    ll i=n;
    ll j=m;
    while(dp2[i][j]!=2)
    {
        if(dp2[i][j]==0)
        {
            ans+=s1[i-1];
            i--;
            j--;
        }
        else if(dp2[i][j]==-1)
        {
            j--;
        }
        else
        {
            i--;
        }
    }
    reverse(ans.begin(),ans.end());
    cout<<ans;
    return 0;
}




Measured memory_bytes: 141184
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cfloat>
#include <algorithm>
#include <numeric>
#include <vector>
#include <iterator>
#include <set>
using namespace std;

const double PI=acos(-1);

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

    vector<int> h(n);
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
    int cnt = 0, prev = h[0], max = -1;
    for(int i = 1; i < n; i++){
        if(h[i] > prev){
            cnt = 0;
        }else{
            cnt++;
        }
        max = std::max(max, cnt);
        prev = h[i];
    }
    if(max == -1) cout << 0 << endl;
    else cout << max << endl;
    return 0;
}

Measured memory_bytes: 640
N, M = map(int, input().split())
aList = list(map(int, input().split()))
count = 0
numVote = 0
for a in aList:
    numVote += a
for a in aList:
    if(a >=  numVote / (4 * M)):
        count += 1

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

Measured memory_bytes: 9168
-- 1234567890
-- oooxoxoooo

dec2oct 0 = []
dec2oct n =
  let a = n `mod` 8
      b = n `div` 8
  in
    a:(dec2oct b)

oct2ans s [] = s
oct2ans s (n:ns) =
  let n' = if n <= 3
           then n
           else if n <= 4
                then n + 1
                else n + 2
      s' = s * 10 + n'
  in
    oct2ans s' ns

ans i =
  let t = reverse $ dec2oct i
  in
    oct2ans 0 t

main = do
  c <- getContents
  let i = takeWhile (/= 0) $ map read $ lines c :: [Int]
      o = map ans i
  mapM_ print o
  

Measured memory_bytes: 5516
#include <bits/stdc++.h>
  
#define INF 2000000010
#define mod7 1000000007
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL_MAX 9223372036854775807
#define INF_LL 9223372036854775
#define EPS 1e-10
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double 
 
using namespace std;

#define MAX_N 205

int N;
int L[MAX_N];

int main(){
  
  cin >> N;
  for(int i = 0; i < 2*N; i++){
    cin >> L[i];
  }

  sort(L, L+2*N);

  int ans = 0;
  for(int i = 0; i < 2*N; i += 2){
    ans += L[i];
  }

  cout << ans << endl;

  return 0;

}


Measured memory_bytes: 256
def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct

import math

def kaisa(x):
  first = math.floor(math.sqrt(x*2))
  if x*2 >= first*(first+1):
    return first
  else:
    return first-1

n = int(input())
soinsu = factorize(n) 

res = 0
for i in soinsu:
  res = res + kaisa(i[1])
print(res)

Measured memory_bytes: 63232
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=s;i<n;i++)
int main(){
    int n; cin >> n;
    vector<int> d(n);
    rep(i,n)cin >> d[i];
    int ans = 0;
    rep(i,n-1)REP(j,i+1,n)ans += d[i]*d[j];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define ARRAY_LENGTH(array) sizeof(array)/sizeof(*array)
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; }

const ll INF = 1e13;

vector<ll> fact(9);
void init_fact() {
    fact[0] = fact[1] = 1;
    for(ll i = 2; i < fact.size(); ++i) {
        fact[i] = i * fact[i - 1];
    }
}

ll N;
vector<ll> P, Q;

ll od(vector<ll> num, ll i, ll bit_flag) {
    if(i == N - 1) {
        return 1;
    }

    ll s_od = num[i];
    REP(j, num[i]) {
        if(bit_flag & (1 << j)) {
            --s_od;
        }
    }
    
    ll ans = (s_od - 1) * fact[N - i - 1];
    bit_flag |= 1 << num[i];
    return ans + od(num, i + 1, bit_flag);
}

int main() {
    init_fact();

    cin >> N;

    P.resize(N);
    Q.resize(N);
    REP(i, N) {
        cin >> P[i];
    }
    REP(i, N) {
        cin >> Q[i];
    }

    ll resP = od(P, 0, 0);
    ll resQ = od(Q, 0, 0);
    cout << abs(resP - resQ) << endl;

    return 0;
}

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

# a.append(k)

diff = []

for i in range(n):
    if i == n-1:
        diff.append(abs(a[0] + abs(a[i] - k)))
    else:
        diff.append(abs(a[i+1] - a[i]))

# print(diff)

ans = sum(diff) - max(diff)
print(ans)

Measured memory_bytes: 26444
#include<iostream>
using namespace std;
int main( )
{
    int n;
    cin>>n;
    for(int i = 0; i <= n;i += 4)
    for(int j = 0; j <= n;j += 7)
    {
        if(i+j==n && n != 0) {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
     cout<<"No"<<endl;
   return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let mut edges = HashMap::<usize, HashMap<usize, u64>>::new();
    let mut simple_edges = vec![Vec::new(); n];
    for _ in 0..n - 1 {
        let v = read_vec::<u64>();
        let a = v[0] as usize - 1;
        let b = v[1] as usize - 1;
        edges.entry(a).or_insert(HashMap::new()).insert(b, v[2]);
        edges.entry(b).or_insert(HashMap::new()).insert(a, v[2]);
        simple_edges[a].push(b);
        simple_edges[b].push(a);
    }
    let root = 0;
    let mut tree: Vec<Vec<usize>> = vec![Vec::new(); n];
    let mut parent_dict: HashMap<usize, usize> = HashMap::new();
    make_tree(root, n, &simple_edges, &mut tree, &mut parent_dict);
    let mut topological_sorted_indexes = vec![root];
    topological_dfs(root, &tree, &mut topological_sorted_indexes);

    let mut color = vec![2; n]; // 0: white, 1: black, 2: uncolored;
    color[0] = 0;
    for &idx in topological_sorted_indexes.iter() {
        if idx == 0 {
            continue;
        }
        let parent = parent_dict[&idx];
        assert!(color[parent] != 2);
        let dist = edges[&parent][&idx];

        if dist % 2 == 0 {
            color[idx] = color[parent];
        } else {
            color[idx] = 1 - color[parent];
        }
    }
    for i in 0..n {
        println!("{:?}", color[i]);
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
fn topological_dfs(cur_idx: usize, tree: &Vec<Vec<usize>>, result: &mut Vec<usize>) {
    for child_idx in tree[cur_idx].iter() {
        result.push(*child_idx);
        topological_dfs(*child_idx, tree, result);
    }
}

fn make_tree(
    cur_idx: usize,
    parent_idx: usize,
    edges: &Vec<Vec<usize>>,
    tree: &mut Vec<Vec<usize>>,
    parent_dict: &mut HashMap<usize, usize>,
) {
    for child_idx in edges[cur_idx].iter() {
        if *child_idx == parent_idx {
            continue;
        }
        tree[cur_idx].push(*child_idx);
        parent_dict.insert(*child_idx, cur_idx);
        make_tree(*child_idx, cur_idx, edges, tree, parent_dict);
    }
}


Measured memory_bytes: 121468
import sys
def 解():
    iN = int(input())
    aS = [_.rstrip() for _ in sys.stdin.readlines()]

    sABC = "abcdefghijklmnopqrstuvwxyz"
    iL = len(sABC)
    aC = [0]*iL
    for i in range(iL):
        aC[i] = aS[0].count(sABC[i])
    for s in aS[1:]:
        #b0 = True
        for i in range(iL):
            if aC[i]:
                iC = s.count(sABC[i])
                #if iC :
                #   b0 = False
                aC[i] = min(aC[i] ,iC)

        #if b0:
        #   print("")
        #   exit()

    sR = ""
    for i in range(iL):
        if aC[i]:
            sR += sABC[i] * aC[i]
    print(sR)
解()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
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;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    vector<string> T = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
    string in; cin >> in;

    cout << 7 - (find(_all(T), in) - find(_all(T), "SUN")) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define pii pair<ll, ll>
#define ll long long

using namespace std;

ll dp[110][100010];
pii niz[110];
int main()
{
	int n, weight;
	cin >> n >> weight;
	for (int i = 1; i <= n; i++)
		cin >> niz[i].first >> niz[i].second;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= weight; j++)
		{
			if (j < niz[i].first)
				dp[i][j] = dp[i - 1][j];
			else
				dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - niz[i].first] + niz[i].second);
		}
	}
	cout << dp[n][weight] << endl;
}

Measured memory_bytes: 79360
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
using ll = long long;

int main() {
	ll A,B,C;
	cin >> A >> B >> C;
	ll x;
	x = abs(A-B) + abs(B-C); 
	x = min(x, abs(A-C) + abs(C-B));
	x = min(x, abs(B-C) + abs(C-A));
	x = min(x, abs(B-A) + abs(A-C));
	x = min(x, abs(C-A) + abs(A-B));
	x = min(x, abs(C-B) + abs(B-A));
	cout << x << endl;
	return 0;
}


Measured memory_bytes: 256
h, w, x = map(int, input().split())
matrix = []
total = 0
row = []
col = [0] * w
for _ in range(h):
  c = input()
  cnt = 0
  for i in range(w):
    if c[i] == '#':
      cnt += 1
      col[i] += 1
  total += cnt
  row.append(cnt)
  matrix.append(c)

ans = 0
for k in range(2**h):
  for l in range(2**w):
    state = total
    r_lst = []
    c_lst = []
    for i in range(h):
      if k & (1 << i) == 2**i:
        state -= row[i]
        r_lst.append(i)
    for j in range(w):
      if l & (1 << j) == 2**j:
        state -= col[j]
        c_lst.append(j)
    for p in r_lst:
      for q in c_lst:
        if matrix[p][q] == '#':
          state += 1
    if state == x:
      ans += 1
print(ans)


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

int main() {
	std::ios::sync_with_stdio(false);
	int n;
	cin >> n;
	int a[100003];
	a[0] = 0;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	ll s[100003];
	s[0] = 0;
	for(int i = 1; i < n+1; i++) {
		s[i] = s[i-1] + abs(a[i] - a[i-1]);
	}

	s[n+1] = s[n] + abs(a[n]); 
	// for(int i = 0; i < n + 2; i++) {
	// 	cout << s[i] << " ";
	// }

	for(int i = 1; i <= n; i++) {
		cout << s[n+1] + abs(a[i + 1] - a[i - 1]) - (abs(a[i] - a[i - 1]) + abs(a[i + 1] - a[i]) ); 
		cout << endl;
	}

	
	
	return 0;
}

Measured memory_bytes: 2432
#include <stdio.h>

int main(void)
{
	int n;		//Value N.
	int i;

	scanf("%d", &n);
	i = 1;
	while(i <= n)
	{
		if(i % 3 == 0 || i % 10 == 3 || i / 10 % 10 == 3 || i / 100  % 10 == 3 || i / 1000 % 10 == 3)
			printf(" %d", i);
		i++;
	}
	printf("\n");

	return (0);
}



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

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> P;
typedef map<int,int> mp;

const int MOD = 1e9 + 7;


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

    ll n;
    cin >> n;
    vector<string> vs(n);

    string s;
    rep(i, n){
        cin >> s;
        sort(all(s));
        vs[i] = s;
    }

    sort(all(vs));
    ll ans = 0, cnt = 1;
    rep(i, n-1){
        if(vs[i] == vs[i+1]){
            cnt++;
        }else{
            ans += cnt * (cnt - 1) / 2;
            cnt = 1;
        }
    }
    ans += cnt * (cnt - 1) / 2;
    cout << ans << endl;

    return 0;
}



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

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

    long long cnt =0;
    long long ans = 0;
    int ids = 1;
    int flg =false;
    for(int i=0; i<s.length(); i++){
        if(s.at(i)=='W'){
            ans += (i+1) - ids;
            ids++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3716
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define files(name) name!=""?freopen(name".in","r",stdin),freopen(name".out","w",stdout):0
#define all(a) a.begin(),a.end()
#define len(a) (int)(a.size())
#define elif else if
#define mp make_pair
#define pb push_back
#define fir first
#define sec second

using namespace std;
#define int long long

typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long double ld;
typedef long long ll;

const int arr=2e5+10;
const int ar=2e3+10;
const ld pi=acos(-1);
const ld eps=1e-10;
const ll md=1e9+7;

///---program start---///

int bpow(int a,int n)
{
    int res=1;
    while (n){
        if (n&1){
            res=res*a%md;
        }
        n/=2;
        a=a*a%md;
    }
    return res;
}

int f[arr];
int rf[arr];

int C(int n,int k)
{
    return f[n]*rf[k]%md*rf[n-k]%md;
}

int ways(int n,int m)
{
    return C(n+m-2,n-1);
}

int ways(int x1,int y1,int x2,int y2)
{
    return ways(x2-x1+1,y2-y1+1);
}

main()
{
    #ifdef Barik
        files("barik");
        freopen("debug.txt","w",stderr);
    #endif

    f[0]=1;
    for (int i=1;i<arr;i++){
        f[i]=f[i-1]*i%md;
    }
    rf[arr-1]=bpow(f[arr-1],md-2);
    for (int i=arr-2;i>=0;i--){
        rf[i]=rf[i+1]*(i+1)%md;
    }

    int n,m,a,b;
    cin>>n>>m>>a>>b;
    int ans=ways(n,m);
    for (int j=1;j<=b;j++){
        int cur=ways(1,1,n-a,j)*ways(n-a+1,j,n,m)%md;
//        cout<<cur<<"\n";
        ans-=cur;
        if (ans<0){
            ans+=md;
        }
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
    // Write Your Code Below
   string a;
   cin >> a;
   cout << a[0]<< a.size()-2 << a[a.size()-1] << endl;
}


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

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);


    ll n,m;
    cin>>n>>m;
    ll a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    ll low = -1, up = 1e15;
    while(up-low>1){
        ll mid = (up+low)/2;
        ll cnt = 0;
        for(int i=0;i<n;i++){
            cnt += a+n - lower_bound(a,a+n,mid-a[i]);
            //cerr << mid << " " << i << " " << cnt << endl;
        }
        if(cnt >= m) low = mid;
        else up = mid;
    }
    cerr << low << endl;
    ll ans = 0;
    ll cnt = 0;
    for(int i=0;i<n;i++){
        ll ret = (a+n - upper_bound(a,a+n,low-a[i]));
        ans += a[i] * ret *2;
        cnt += ret;
    }
    cerr << cnt << endl;
    ans += low * (m-cnt);
    cout << ans << endl;
    
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
int main(void)
{
    int n,a=0,b=0,ab=0,o=0;
    char t[100];
    while(scanf("%d,%s",&n ,t) != EOF){
        if(strcmp(t,"AB")==0){
            ab++;
        }else if(strcmp(t,"A")==0){
            a++;
        }else if(strcmp(t,"B")==0){
            b++;
        }else{
            o++;
        }
    }
	printf("%d\n%d\n%d\n%d\n" ,a,b,ab,o);
	return 0;
}

Measured memory_bytes: 592
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main()
{
    // スペース区切りの整数の入力
    int N;
    cin >> N;
	string buff = "";

	if(N==0){
		buff ="0";
	}

	while (N!=0){
		if (N%2 != 0){
			buff = "1" + buff;
			N --;
		}else{
			buff = "0" + buff;
		}
		N /= -2; 
	}

	cout << buff << endl;


}

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

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

  int N;
  cin >> N;
  int A[N], sum[N];
  cin >> A[0];
  sum[0] = A[0];
  for(int i=1;i<N;i++){
    cin >> A[i];
    sum[i] = sum[i-1] + A[i];
  }

  int ans = INF;
  for(int i=0;i<N;i++){
    ans = min(ans, abs((sum[N-1] - sum[i])- sum[i] ));
  }

  cout << ans << endl;

}

Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main(void) {
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;

    if((a + b) > c * 2) {
        int sum = 0;
        if(x > y){
            sum += c * 2 * y;
            if(a > c * 2){
                sum += (x - y) * (c*2);
            }
            else{
                sum += (x - y) * a;
            }
            cout << sum << endl;
            return 0;
        }
        else{
            sum += c * 2 * x;
            if( b > c * 2 ){
                sum += (y - x) * (c*2);
            }
            else{
                sum += (y - x) * b;
            }
            cout << sum << endl;
            return 0;
        }
    }

    else{
        cout << a * x + b * y << endl;
        return 0;
    }
}


Measured memory_bytes: 256
x, n = map(int, input().split())
if n != 0:
    p = set(map(int, input().split()))
    nums = set([])
    for i in range(0, 102):
        nums.add(i)
    rest = nums.difference(p)
    minVal = 1000
    for j in rest:
        if abs(x - j) < abs(x - minVal):
            minVal = j
        else:
            pass
    print(minVal)
else:
    print(x)


Measured memory_bytes: 9196
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(){
    
    ll N, M;
    cin >> N >> M;
    ll path[9][9] = {};
    for(ll i = 0; i < M; i++){
        ll a, b;
        cin >> a >> b;
        path[a][b] = 1;
        path[b][a] = 1;
    }
    ll ans = 0;
    vector<ll>v;
    for(ll i = 1; i <= N; i++)v.push_back(i);
    do{
        ll flg = 1;
        if(v[0] != 1)flg = 0;
        for(ll i = 1; i < N; i++){
            if(path[v[i - 1]][v[i]] == 0)flg = 0;
        }
        if(flg)ans++;
    }while(next_permutation(v.begin(), v.end()));
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int, input().split()))
cnt=0
ans=[]

for i in a:
  ch=i
  while True:
    if ch ==0:
      break
    if ch%2 ==0:
      cnt+=1
      ch=ch/2
    else:
      break
  if cnt==0:
   ans.append(cnt)
   break
  else:
   ans.append(cnt)
   cnt=0
print(min(ans))

Measured memory_bytes: 3060
#ifndef _MSC_VER
#include <bits/stdc++.h>
#endif // ! _MSC_VER

using namespace std;

typedef unsigned int uint;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<uint, uint> Pos;

static const uint m_max = 100001;
static const uint mod = 1000000007;

// bool m[m_max+2][m_max+2];
// uint c[m_max+2][m_max+2];

const uint dx[] = { 2, 1, 0, 1 };
const uint dy[] = { 1, 2, 1, 0 };

// int mwA[1001];
// int mwB[1001];
int dp[3002][3002];

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

	// constract
	dp[0][0] = 0;
	for (unsigned int i = 0; i < s.length(); i++) {
		for (unsigned int j = 0; j < t.length(); j++) {
			if (s[i] == t[j]) dp[i+1][j+1] = dp[i][j] + 1;
			else dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
		}
	}

// #define TMP1
	// debug
#ifdef TMP1
	cerr << "    , ";
	for (unsigned int j = 0; j < t.length(); j++)
		cerr << t[j] << ", ";
	cerr << "\n";
	for (unsigned int i = 0; i <= s.length(); i++) {
		if (i == 0) cerr << " : ";
		else cerr << s[i-1] << ": ";
		for (unsigned int j = 0; j <= t.length(); j++)
			cerr << dp[i][j] << ", ";
		cerr << "\n";
	}
#endif

#define TMP2
	// make output
	string ans(dp[s.length()][t.length()], '\0');
	unsigned int i = s.length();
	unsigned int j = t.length();
	while (dp[i][j] > 0) {
		--i; --j;
#ifdef TMP2
		cerr << "i:" << i;
#endif
#ifdef TMP2
		cerr << "\n  j:" << j;
		cerr << ":" << dp[i+1][j+1] << "," << dp[i][j+1] << "," << dp[i+1][j] << "," << dp[i][j];
#endif
		while (dp[i+1][j+1] == dp[i+1][j])
			--j;

		while (dp[i+1][j+1] == dp[i][j+1])
			--i;

#ifdef TMP2
		cerr << "[" << s[i] << "]";
#endif
		ans[dp[i][j]] = s[i];
#ifdef TMP2
		cerr << "\n";
#endif
	}

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



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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; int k; cin>>n>>k;
    ll m=1, ans=0;
    while(m<=n){
        m*=k;
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<int>vec(n);
  rep(i, n){
    cin >> vec.at(i);
  }
  sort(vec.rbegin(),vec. rend());
  int a = 0, b = 0;
  rep(i, n){
    if(i%2==0) a += vec.at(i);
    else b += vec.at(i);
  }
  cout << a - b << endl;




}



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

int dp[100010];
const int INF = 110000;
int main(void) {
  dp[0] = 0;
  for (int n = 1; n <= 100000; n++) {
    dp[n] = INF;
    int power = 1;
    while (power <= n) {
      dp[n] = min(dp[n], dp[n - power] + 1);
      power *= 6;
    }
    power = 1;
    while (power <= n) {
      dp[n] = min(dp[n], dp[n - power] + 1);
      power *= 9;
    }
}

  int N;
  cin >> N;
  cout << dp[N] << endl;
  
  return 0;
}

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

int tm[1000];
int x[1000],y[1000];

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

	while(n--){
		int N,X,Y;
		double sx,sy;
		cin>>N>>X>>Y>>sx>>sy;

		for(int i=0;i<N;i++) cin>>x[i]>>y[i];

		vector<int> t[N];
		for(int i=0;i<N-1;i++){
			for(int j=i+1;j<N;j++){
				if((x[j]-x[i])*(x[j]-x[i]) + (y[j]-y[i])*(y[j]-y[i]) <= 2500){
					t[i].push_back(j);
					t[j].push_back(i);
				}
			}
		}
		vector<int> v;
		for(int i=0;i<N;i++) tm[i] = -999999999;

		int ans = 0;
		for(int i=0;i<N;i++){
			if((sx-x[i])*(sx-x[i]) + (sy-y[i])*(sy-y[i]) <= 100){
				v.push_back(i);
				ans = tm[i] = X;
			}
		}

		int loop = 10000;
		while(!v.empty() && loop>0){
			vector<int> nv;
			for(int i=0;i<v.size();i++){
				int from = v[i];
				for(int j=0;j<t[from].size();j++){
					int to = t[from][j];

					if(tm[from] - Y > tm[to]){
						nv.push_back(to);
						ans = tm[to] = tm[from] + X;
					}
				}
			}

			v = nv;
			loop--;
		}

		if(loop == 0)
			cout<<"You're always welcome!\n";
		else
			cout<<ans<<endl;
	}

	return 0;
}

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

int a[12][12];

int main() {
  int n,m,x;
  cin>>n>>m>>x;
  vector<int> c(n);

  rep(i,n){
    cin>>c[i];
    rep(j,m){
      cin>>a[i][j];
    }
  }
  
  int ans = INF;
  rep(s,1<<n){
    int cost=0;
    vector<int> d(m); 
    rep(i,n){
      if(s>>i&1){ 
        cost+=c[i];
        rep(j,m) d[j]+=a[i][j];
      }
    }
    bool ok=true;
    rep(j,m) if(d[j]<x) ok=false;
    if(ok) ans = min(ans,cost);
  }
  if(ans == INF) cout<<-1<<endl;
  else cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3604
import math
A, B, H, M = list(map(int, input().split()))

tan_kakudo = (360 / 12 * H) + (360 / 12 / 60 * M) 
tyo_kakudo = (360 / 60 * M)
diff_kakudo = abs(tan_kakudo - tyo_kakudo)
if diff_kakudo >= 180:
    diff_kakudo = 360 - diff_kakudo
ans = math.sqrt((A ** 2) + (B ** 2) - (2 * A * B * math.cos(math.radians(diff_kakudo))))
print(ans)

Measured memory_bytes: 9516
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

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

ll gcd(ll a, ll b){
    if(a<b) swap(a,b);
    if(a%b == 0) return b;
    else return gcd(b,a%b);
}

int main(){
    ll n; cin >> n;
    vector<ll> a(n);
    rep(i,n){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    vector<bool> dob(n,1);
    rep(i,n-1){
        if(a[i] == a[i+1]){
            dob[i] = 0;
            dob[i+1]=0;
        }
    }
    ll amax = a[n-1]+1;
    vector<ll> dp(amax,0);
    rep(i,n){
        ll x = a[i];
        if(dp[x] == 0){
            for(int j = 1; j*x <= amax; j++){
                dp[j*x]++;
            }
        } else dp[x]++;
    }
    ll ans = 0;
    rep(i,n){
        if(dob[i] && dp[a[i]] == 1){
            ans++;
        }
    }
    // rep(i,n){
    //     cout << i << ": "<< a[i] << endl;
    // }
    // rep(i,amax){
    //     cout << i << ": " << dp[i] << endl;
    // }
    cout << ans << endl;
}

Measured memory_bytes: 12700
//#pragma comment(linker, "/STACK:102400000,102400000")
//#include <initializer_list>
#include <fstream>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <cassert>
//#include <unordered_map>
//#include <unordered_set>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define eps 1e-8
#define LL_INF 0x3fffffffffffffff
#define INF 0x3f3f3f3f
#define mem(a, b) memset(a, b, sizeof(a))
#define pper(i,n,m) for(int i = n;i >= m; i--)
#define repp(i, n, m) for (int i = n; i <= m; i++)
#define rep(i, n, m) for (int i = n; i < m; i++)
#define sa(n) scanf("%d", &(n))
#define slla(n) scanf("%lld", &(n))
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define DE(val) cout<<#val<<": "<<val<<endl;
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); repp(i,1,___T)

const int dx44[5] = { 0,-1,-1,1,1 };
const int dy44[5] = { 0,-1,1,-1,1 };

const int dx4[5] = { 0,-1,0,1,0 };
const int dy4[5] = { 0,0,1,0,-1 };
const int dx8[9] = { 0,-1,0,1,0,1,1,-1,-1 };
const int dy8[9] = { 0,0,1,0,-1,1,-1,1,-1 };
const int maxn = 5e5 + 5;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;
ll po(ll a, ll b, ll mod) { ll res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1)res = res*a%mod; a = a*a%mod; }return res; }
ll gcd(ll a, ll b) { if (a == 0) { return b; } else { return gcd(b%a, a); } }
void YES() { puts("YES"); exit(0); }
void Yes() { puts("Yes");}// exit(0); }
void NO() { puts("NO"); exit(0); }
void No() { puts("No");}// exit(0); }
void one() { puts("-1"); exit(0); }

char x[maxn];
void solve()
{
    scanf("%s",x+1);
    int len = strlen(x + 1);
    int le = 1;
    int ri = len;
    int ans = 0;
    while(le<ri)
    {
        if(x[le]==x[ri])
        {
            le++;
            ri--;
        }
        else
        {
            if(x[le]=='x')
            {
                le++;
                ans++;
            }
            else if(x[ri]=='x')
            {
                ri--;
                ans++;
            }
            else
            {
                printf("-1\n");
                return;
            }
        }
    }
    printf("%d\n", ans);

}

int main()
{

    solve();
    // system("pause");
    return 0;
}

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

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

    for (int i = 0; i < N; i++) {
        cout << ans.at(i) << " ";
    }
    cout << endl;
}

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


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

	int H, W;
	cin >> H >> W;
	int ans = INF;
	if(H % 3 == 0 || W % 3 == 0){
		cout << 0 << endl;
		return 0;
	}
	else{
		ans = min(H, W);
	}
	int a, b;
	if(H % 2 == 1){
		a = H/2;
		b = a+1;
	}
	else {
		a = H/2;
		b = H/2;
	}
	for(int i=1;i<W;i++){
		int z, x, c;
		z = a * (W-i);
		x = b * (W-i);
		c = H * i;
		ans = min(ans, max({z, x, c}) - min({z, x, c}));
	}
	swap(H, W);
		if(H % 2 == 1){
		a = H/2;
		b = a+1;
	}
	else {
		a = H/2;
		b = H/2;
	}
	for(int i=1;i<W;i++){
		int z, x, c;
		z = a * (W-i);
		x = b * (W-i);
		c = H * i;
		ans = min(ans, max({z, x, c}) - min({z, x, c}));
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.*;

class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] div = str.split(" ");
		int a = Integer.parseInt(div[0]);
		int b = Integer.parseInt(div[1]);
		int c = Integer.parseInt(div[2]);
		if (a < b && b < c){
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 17084
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner in = new Scanner(System.in);
        
        int n = in.nextInt() - 1, firstNUM = in.nextInt();
        int MAX = firstNUM, MIN = firstNUM;
        long SUM = firstNUM;

        for(int i = 0; i < n; i++){
            int ai = Integer.parseInt(in.next());
            if(ai > MAX)MAX = ai;
            else if(ai < MIN) MIN = ai;

            SUM += ai;
        }

        System.out.printf("%d %d ", MIN, MAX);
        System.out.println(SUM);
    }
}


Measured memory_bytes: 41620
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <string>
#include <utility>
#include <map>
using namespace std;
#define rep(i,n) for(int i=1;i<=(int)(n);i++)
#define Rep(i,n) for(int i=0;i<=(int)(n-1);i++)
typedef long long ll;
typedef pair<int,int> pint;
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};
int inf=2020000000;

int A[3];
int ans[3];

int main() {
	cin>>A[0]>>A[1]>>A[2];
	sort(A,A+3);
	Rep(i,3) ans[i]=0;
	ans[0]=A[2]+A[1]-2*A[0];
	ans[1]=A[2]-A[1];
	if((A[1]-A[0])%2==0) ans[1]+=(A[1]-A[0])/2;
	else{
		ans[1]+=(A[1]-A[0])/2 + 2;
	}
	if((A[1]-A[0])%2==0) ans[2]+=(A[2]-A[0])/2;
		else{
			ans[2]+=(A[2]-A[0])/2 + 2;
		}
	if((A[2]-A[0])%2==0) ans[2]+=(A[2]-A[1])/2;
			else{
				ans[2]+=(A[2]-A[1])/2 + 2;
			}
	sort(ans,ans+3);
	
	cout<<ans[0]<<endl;


	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String r = scanner.next();
        String g = scanner.next();
        String b = scanner.next();
        int rgb = Integer.parseInt(r+g+b);

        if (rgb % 4 == 0) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
int main()
{   int n;
    cin>>n;
    string a;
    cin>>a;
    for(int i=0;i<a.length();i++)
    {
        int temp=(int)(a[i]-'A');
        temp=(temp+n)%26;
        a[i]=(char)(temp+65);
        cout<<a[i];
    }
   
 
   
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
 
int main() {
    char c;
    cin >> c;
    vector<char> a={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
    rep(i,25){
        if(c==a.at(i)) cout << a.at(i+1) << endl;
    }
}


Measured memory_bytes: 256